remove redundant strcmp wrappers

main
Allen Webster 2026-02-26 15:14:34 -08:00
parent af182961cc
commit 405b88268c
2 changed files with 19 additions and 45 deletions

View File

@ -224,9 +224,7 @@ const struct wl_shm_listener shm_listener = {
}; };
static void static void
init_wl_display_callback(void *user_data, init_wl_display_callback(void *user_data, struct wl_callback *callback, uint32_t time){
struct wl_callback *callback,
uint32_t time){
struct libdecor *context = user_data; struct libdecor *context = user_data;
ctx.init_done = true; ctx.init_done = true;
@ -247,29 +245,24 @@ const struct wl_callback_listener init_wl_display_callback_listener = {
init_wl_display_callback init_wl_display_callback
}; };
static void static void
seat_capabilities(void *data, struct wl_seat *wl_seat, uint32_t capabilities){ seat_capabilities(void *data, struct wl_seat *wl_seat, uint32_t capabilities){
struct seat *seat = data; struct seat *seat = data;
if ((capabilities & WL_SEAT_CAPABILITY_POINTER) && if ((capabilities & WL_SEAT_CAPABILITY_POINTER) && !seat->wl_pointer){
!seat->wl_pointer) {
seat->wl_pointer = wl_seat_get_pointer(wl_seat); seat->wl_pointer = wl_seat_get_pointer(wl_seat);
wl_pointer_add_listener(seat->wl_pointer, wl_pointer_add_listener(seat->wl_pointer, &pointer_listener, seat);
&pointer_listener, seat); }
} else if (!(capabilities & WL_SEAT_CAPABILITY_POINTER) && else if (!(capabilities & WL_SEAT_CAPABILITY_POINTER) && seat->wl_pointer){
seat->wl_pointer) {
wl_pointer_release(seat->wl_pointer); wl_pointer_release(seat->wl_pointer);
seat->wl_pointer = NULL; seat->wl_pointer = NULL;
} }
if ((capabilities & WL_SEAT_CAPABILITY_TOUCH) && if ((capabilities & WL_SEAT_CAPABILITY_TOUCH) && !seat->wl_touch){
!seat->wl_touch) {
seat->wl_touch = wl_seat_get_touch(wl_seat); seat->wl_touch = wl_seat_get_touch(wl_seat);
wl_touch_add_listener(seat->wl_touch, wl_touch_add_listener(seat->wl_touch, &touch_listener, seat);
&touch_listener, seat); }
} else if (!(capabilities & WL_SEAT_CAPABILITY_TOUCH) && else if (!(capabilities & WL_SEAT_CAPABILITY_TOUCH) && seat->wl_touch) {
seat->wl_touch) {
wl_touch_release(seat->wl_touch); wl_touch_release(seat->wl_touch);
seat->wl_touch = NULL; seat->wl_touch = NULL;
} }
@ -653,12 +646,6 @@ LIBDECOR_WINDOW_STATE_MAXIMIZED | LIBDECOR_WINDOW_STATE_FULLSCREEN |
LIBDECOR_WINDOW_STATE_TILED_LEFT | LIBDECOR_WINDOW_STATE_TILED_RIGHT | LIBDECOR_WINDOW_STATE_TILED_LEFT | LIBDECOR_WINDOW_STATE_TILED_RIGHT |
LIBDECOR_WINDOW_STATE_TILED_TOP | LIBDECOR_WINDOW_STATE_TILED_BOTTOM; LIBDECOR_WINDOW_STATE_TILED_TOP | LIBDECOR_WINDOW_STATE_TILED_BOTTOM;
static bool
streql(const char *str1, const char *str2)
{
return (str1 && str2) && (strcmp(str1, str2) == 0);
}
static void static void
do_map(struct libdecor_frame *frame); do_map(struct libdecor_frame *frame);
@ -1274,7 +1261,7 @@ libdecor_frame_set_title(struct libdecor_frame *frame,
{ {
struct libdecor_frame_private *frame_priv = frame->priv; struct libdecor_frame_private *frame_priv = frame->priv;
if (!streql(frame_priv->state.title, title)) { if (!STREQL(frame_priv->state.title, title)) {
free(frame_priv->state.title); free(frame_priv->state.title);
frame_priv->state.title = strdup(title); frame_priv->state.title = strdup(title);
@ -2326,19 +2313,6 @@ get_header_focus(const GtkHeaderBar *header_bar, const int x, const int y)
return elem_none; return elem_none;
} }
static bool
streq(const char *str1,
const char *str2)
{
if (!str1 && !str2)
return true;
if (str1 && str2)
return strcmp(str1, str2) == 0;
return false;
}
static bool static bool
own_proxy(struct wl_proxy *proxy) own_proxy(struct wl_proxy *proxy)
{ {
@ -3513,7 +3487,7 @@ libdecor_plugin_gtk_frame_property_changed(struct libdecor_frame *frame)
if (!GTK_IS_WIDGET(frame_gtk->header)) return; if (!GTK_IS_WIDGET(frame_gtk->header)) return;
new_title = libdecor_frame_get_title(frame); new_title = libdecor_frame_get_title(frame);
if (!streq(frame_gtk->title, new_title)) if (!STREQL(frame_gtk->title, new_title))
redraw_needed = true; redraw_needed = true;
free(frame_gtk->title); free(frame_gtk->title);
frame_gtk->title = NULL; frame_gtk->title = NULL;
@ -3646,7 +3620,7 @@ libdecor_plugin_gtk_frame_popup_grab(struct libdecor_frame *frame,
struct seat *seat; struct seat *seat;
wl_list_for_each(seat, &ctx.seat_list, link) { wl_list_for_each(seat, &ctx.seat_list, link) {
if (streq(seat->name, seat_name)) { if (STREQL(seat->name, seat_name)) {
if (seat->grabbed) { if (seat->grabbed) {
fprintf(stderr, "libdecor-WARNING: Application " fprintf(stderr, "libdecor-WARNING: Application "
"tried to grab seat twice\n"); "tried to grab seat twice\n");
@ -3670,7 +3644,7 @@ libdecor_plugin_gtk_frame_popup_ungrab(struct libdecor_frame *frame,
struct seat *seat; struct seat *seat;
wl_list_for_each(seat, &ctx.seat_list, link) { wl_list_for_each(seat, &ctx.seat_list, link) {
if (streq(seat->name, seat_name)) { if (STREQL(seat->name, seat_name)) {
if (!seat->grabbed) { if (!seat->grabbed) {
fprintf(stderr, "libdecor-WARNING: Application " fprintf(stderr, "libdecor-WARNING: Application "
"tried to ungrab seat twice\n"); "tried to ungrab seat twice\n");
@ -4617,8 +4591,7 @@ get_setting_sync(DBusConnection *const connection,
DBusMessage *message; DBusMessage *message;
DBusMessage *reply; DBusMessage *reply;
message = dbus_message_new_method_call( message = dbus_message_new_method_call("org.freedesktop.portal.Desktop",
"org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop", "/org/freedesktop/portal/desktop",
"org.freedesktop.portal.Settings", "org.freedesktop.portal.Settings",
"Read"); "Read");
@ -4633,8 +4606,7 @@ get_setting_sync(DBusConnection *const connection,
dbus_error_init(&error); dbus_error_init(&error);
reply = dbus_connection_send_with_reply_and_block( reply = dbus_connection_send_with_reply_and_block(connection,
connection,
message, message,
DBUS_TIMEOUT_USE_DEFAULT, DBUS_TIMEOUT_USE_DEFAULT,
&error); &error);

View File

@ -56,6 +56,9 @@
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
#define STREQL(a,b) (((a)==0 && (b)==0) || \
((a)!=0 && (b)!=0 && strcmp((a),(b))==0))
// libdecor.h // libdecor.h
struct libdecor_frame; struct libdecor_frame;
@ -568,7 +571,6 @@ typedef struct Ctx{
EGLContext egl_context; EGLContext egl_context;
EGLSurface egl_surface; EGLSurface egl_surface;
int has_cached_config; int has_cached_config;
struct libdecor_configuration cached_config; struct libdecor_configuration cached_config;
} Ctx; } Ctx;