From ec22e350122abe023c9f045f158ad874e22ae6b9 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Thu, 23 Apr 2026 21:14:31 +0200 Subject: [PATCH] gdk,gtk: fix warnings and harden GFileInfo attribute handling --- gdk/gdkoffscreenwindow.c | 13 ------ gdk/x11/gdkasync.c | 96 +++++++++++++++++++++++++++++++++++++--- gdk/x11/gdkinput-xfree.c | 2 - gtk/gtkfilesystemmodel.c | 18 ++++++-- gtk/gtkpathbar.c | 11 ++++- gtk/queryimmodules.c | 6 +-- 6 files changed, 118 insertions(+), 28 deletions(-) diff --git a/gdk/gdkoffscreenwindow.c b/gdk/gdkoffscreenwindow.c index 9ed5d45ef..ee727b366 100644 --- a/gdk/gdkoffscreenwindow.c +++ b/gdk/gdkoffscreenwindow.c @@ -959,9 +959,6 @@ gdk_offscreen_window_move_resize (GdkWindow *window, gint height) { GdkWindowObject *private = (GdkWindowObject *)window; - GdkOffscreenWindow *offscreen; - - offscreen = GDK_OFFSCREEN_WINDOW (private->impl); if (!with_move) { @@ -994,18 +991,8 @@ gdk_offscreen_window_show (GdkWindow *window, static void gdk_offscreen_window_hide (GdkWindow *window) { - GdkWindowObject *private; - GdkOffscreenWindow *offscreen; - GdkDisplay *display; - g_return_if_fail (window != NULL); - private = (GdkWindowObject*) window; - offscreen = GDK_OFFSCREEN_WINDOW (private->impl); - - /* May need to break grabs on children */ - display = gdk_drawable_get_display (window); - /* TODO: This needs updating to the new grab world */ #if 0 if (display->pointer_grab.window != NULL) diff --git a/gdk/x11/gdkasync.c b/gdk/x11/gdkasync.c index e412ed2f7..f865c0087 100644 --- a/gdk/x11/gdkasync.c +++ b/gdk/x11/gdkasync.c @@ -156,7 +156,12 @@ send_event_handler (Display *dpy, else if (dpy->last_request_read == state->get_input_focus_req) { xGetInputFocusReply replbuf; - xGetInputFocusReply *repl; + G_GNUC_UNUSED xGetInputFocusReply *repl; + + /* If this still causes trouble on some toolchains, remove the + * 'repl' variable entirely and cast the _XGetAsyncReply() call + * to (void) instead. + */ if (rep->generic.type != X_Error) { @@ -167,6 +172,13 @@ send_event_handler (Display *dpy, _XGetAsyncReply(dpy, (char *)&replbuf, rep, buf, len, (sizeof(xGetInputFocusReply) - sizeof(xReply)) >> 2, True); + /* + * Fallback variant if G_GNUC_UNUSED causes problems: + * + * (void) _XGetAsyncReply(dpy, (char *)&replbuf, rep, buf, len, + * (sizeof(xGetInputFocusReply) - sizeof(xReply)) >> 2, + * True); + */ } if (state->callback) @@ -275,9 +287,25 @@ _gdk_x11_send_client_message_async (GdkDisplay *display, * XSync (dpy, 0) */ { - xReq *req; + G_GNUC_UNUSED xReq *req; + + /* Keep the GetInputFocus roundtrip for the conservative variant. + * If this code ever causes trouble, try commenting out the + * GetEmptyReq() call first and keep only the request number + * assignment below. + */ GetEmptyReq(GetInputFocus, req); + + /* + * Fallback variant if the extra roundtrip causes problems: + * + * state->get_input_focus_req = dpy->request; + * return; + * + * or, more locally, comment out the GetEmptyReq() line above and + * leave only the assignment below. + */ state->get_input_focus_req = dpy->request; } @@ -309,7 +337,12 @@ set_input_focus_handler (Display *dpy, if (dpy->last_request_read == state->get_input_focus_req) { xGetInputFocusReply replbuf; - xGetInputFocusReply *repl; + G_GNUC_UNUSED xGetInputFocusReply *repl; + + /* If this still causes trouble on some toolchains, remove the + * 'repl' variable entirely and cast the _XGetAsyncReply() call + * to (void) instead. + */ if (rep->generic.type != X_Error) { @@ -320,6 +353,13 @@ set_input_focus_handler (Display *dpy, _XGetAsyncReply(dpy, (char *)&replbuf, rep, buf, len, (sizeof(xGetInputFocusReply) - sizeof(xReply)) >> 2, True); + /* + * Fallback variant if G_GNUC_UNUSED causes problems: + * + * (void) _XGetAsyncReply(dpy, (char *)&replbuf, rep, buf, len, + * (sizeof(xGetInputFocusReply) - sizeof(xReply)) >> 2, + * True); + */ } DeqAsyncHandler(state->dpy, &state->async); @@ -368,9 +408,25 @@ _gdk_x11_set_input_focus_safe (GdkDisplay *display, * XSync (dpy, 0) */ { - xReq *req; + G_GNUC_UNUSED xReq *req; + + /* Keep the GetInputFocus roundtrip for the conservative variant. + * If this code ever causes trouble, try commenting out the + * GetEmptyReq() call first and keep only the request number + * assignment below. + */ GetEmptyReq(GetInputFocus, req); + + /* + * Fallback variant if the extra roundtrip causes problems: + * + * state->get_input_focus_req = dpy->request; + * return; + * + * or, more locally, comment out the GetEmptyReq() line above and + * leave only the assignment below. + */ state->get_input_focus_req = dpy->request; } @@ -778,7 +834,12 @@ roundtrip_handler (Display *dpy, if (dpy->last_request_read == state->get_input_focus_req) { xGetInputFocusReply replbuf; - xGetInputFocusReply *repl; + G_GNUC_UNUSED xGetInputFocusReply *repl; + + /* If this still causes trouble on some toolchains, remove the + * 'repl' variable entirely and cast the _XGetAsyncReply() call + * to (void) instead. + */ if (rep->generic.type != X_Error) { @@ -789,6 +850,13 @@ roundtrip_handler (Display *dpy, _XGetAsyncReply(dpy, (char *)&replbuf, rep, buf, len, (sizeof(xGetInputFocusReply) - sizeof(xReply)) >> 2, True); + /* + * Fallback variant if G_GNUC_UNUSED causes problems: + * + * (void) _XGetAsyncReply(dpy, (char *)&replbuf, rep, buf, len, + * (sizeof(xGetInputFocusReply) - sizeof(xReply)) >> 2, + * True); + */ } @@ -831,9 +899,25 @@ _gdk_x11_roundtrip_async (GdkDisplay *display, * XSync (dpy, 0) */ { - xReq *req; + G_GNUC_UNUSED xReq *req; + + /* Keep the GetInputFocus roundtrip for the conservative variant. + * If this code ever causes trouble, try commenting out the + * GetEmptyReq() call first and keep only the request number + * assignment below. + */ GetEmptyReq(GetInputFocus, req); + + /* + * Fallback variant if the extra roundtrip causes problems: + * + * state->get_input_focus_req = dpy->request; + * return; + * + * or, more locally, comment out the GetEmptyReq() line above and + * leave only the assignment below. + */ state->get_input_focus_req = dpy->request; } diff --git a/gdk/x11/gdkinput-xfree.c b/gdk/x11/gdkinput-xfree.c index 566a0c0f7..ba75f5626 100644 --- a/gdk/x11/gdkinput-xfree.c +++ b/gdk/x11/gdkinput-xfree.c @@ -168,7 +168,6 @@ _gdk_input_crossing_event (GdkWindow *window, gboolean enter) { GdkDisplay *display = GDK_WINDOW_DISPLAY (window); - GdkDisplayX11 *display_impl = GDK_DISPLAY_X11 (display); GdkWindowObject *priv = (GdkWindowObject *)window; GdkInputWindow *input_window; gint root_x, root_y; @@ -268,7 +267,6 @@ _gdk_input_other_event (GdkEvent *event, GdkEventType event_type; int x, y; GdkDisplay *display = GDK_WINDOW_DISPLAY (event_window); - GdkDisplayX11 *display_impl = GDK_DISPLAY_X11 (display); /* This is a sort of a hack, as there isn't any XDeviceAnyEvent - but it's potentially faster than scanning through the types of diff --git a/gtk/gtkfilesystemmodel.c b/gtk/gtkfilesystemmodel.c index 43d0d6407..da185f37f 100644 --- a/gtk/gtkfilesystemmodel.c +++ b/gtk/gtkfilesystemmodel.c @@ -449,9 +449,20 @@ node_should_be_visible (GtkFileSystemModel *model, guint id, gboolean filtered_o if (node->info == NULL) return FALSE; - if (!model->show_hidden && - (g_file_info_get_is_hidden (node->info) || g_file_info_get_is_backup (node->info))) - return FALSE; + if (!model->show_hidden) + { + gboolean is_hidden = FALSE; + gboolean is_backup = FALSE; + + if (g_file_info_has_attribute (node->info, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN)) + is_hidden = g_file_info_get_is_hidden (node->info); + + if (g_file_info_has_attribute (node->info, G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP)) + is_backup = g_file_info_get_is_backup (node->info); + + if (is_hidden || is_backup) + return FALSE; + } if (_gtk_file_info_consider_as_directory (node->info)) { @@ -1952,6 +1963,7 @@ _gtk_file_system_model_update_file (GtkFileSystemModel *model, node = get_node (model, id); + old_info = node->info; node->info = g_object_ref (info); if (old_info) diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c index 2813c8e94..bbf60115e 100644 --- a/gtk/gtkpathbar.c +++ b/gtk/gtkpathbar.c @@ -1641,6 +1641,8 @@ gtk_path_bar_get_info_callback (GCancellable *cancellable, ButtonData *button_data; const gchar *display_name; gboolean is_hidden; + gboolean info_is_hidden = FALSE; + gboolean info_is_backup = FALSE; if (cancellable != file_info->path_bar->get_info_cancellable) { @@ -1659,7 +1661,14 @@ gtk_path_bar_get_info_callback (GCancellable *cancellable, } display_name = g_file_info_get_display_name (info); - is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info); + + if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN)) + info_is_hidden = g_file_info_get_is_hidden (info); + + if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP)) + info_is_backup = g_file_info_get_is_backup (info); + + is_hidden = info_is_hidden || info_is_backup; gtk_widget_push_composite_child (); button_data = make_directory_button (file_info->path_bar, display_name, diff --git a/gtk/queryimmodules.c b/gtk/queryimmodules.c index 4baebbb77..d20637e10 100644 --- a/gtk/queryimmodules.c +++ b/gtk/queryimmodules.c @@ -159,9 +159,9 @@ query_module (const char *dir, const char *name, GString *contents) { void (*list) (const GtkIMContextInfo ***contexts, guint *n_contexts); - void (*init) (GTypeModule *type_module); - void (*exit) (void); - GtkIMContext *(*create) (const gchar *context_id); + G_GNUC_UNUSED void (*init) (GTypeModule *type_module); + G_GNUC_UNUSED void (*exit) (void); + G_GNUC_UNUSED GtkIMContext *(*create) (const gchar *context_id); gpointer list_ptr; gpointer init_ptr;