From a221e0da4cc05ea47050eb2e5e7ffec72bcb403f Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 08:27:49 +0200 Subject: [PATCH 01/32] tests: fix GtkBuilder signal callback prototypes Based on the Guix gtk2-fix-builder-test.patch. The callbacks are connected to notify-style signals and must take a GParamSpec pointer, not a GParamSpec by value. This avoids stack/register ABI problems on platforms such as ppc64el. --- gtk/tests/builder.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gtk/tests/builder.c b/gtk/tests/builder.c index ebba220e9..121012704 100644 --- a/gtk/tests/builder.c +++ b/gtk/tests/builder.c @@ -132,7 +132,7 @@ static int object = 0; static int object_after = 0; void /* exported for GtkBuilder */ -signal_normal (GtkWindow *window, GParamSpec spec) +signal_normal (GtkWindow *window, GParamSpec *spec) { g_assert (GTK_IS_WINDOW (window)); g_assert (normal == 0); @@ -142,7 +142,7 @@ signal_normal (GtkWindow *window, GParamSpec spec) } void /* exported for GtkBuilder */ -signal_after (GtkWindow *window, GParamSpec spec) +signal_after (GtkWindow *window, GParamSpec *spec) { g_assert (GTK_IS_WINDOW (window)); g_assert (normal == 1); @@ -152,7 +152,7 @@ signal_after (GtkWindow *window, GParamSpec spec) } void /* exported for GtkBuilder */ -signal_object (GtkButton *button, GParamSpec spec) +signal_object (GtkButton *button, GParamSpec *spec) { g_assert (GTK_IS_BUTTON (button)); g_assert (object == 0); @@ -162,7 +162,7 @@ signal_object (GtkButton *button, GParamSpec spec) } void /* exported for GtkBuilder */ -signal_object_after (GtkButton *button, GParamSpec spec) +signal_object_after (GtkButton *button, GParamSpec *spec) { g_assert (GTK_IS_BUTTON (button)); g_assert (object == 1); @@ -172,28 +172,28 @@ signal_object_after (GtkButton *button, GParamSpec spec) } void /* exported for GtkBuilder */ -signal_first (GtkButton *button, GParamSpec spec) +signal_first (GtkButton *button, GParamSpec *spec) { g_assert (normal == 0); normal = 10; } void /* exported for GtkBuilder */ -signal_second (GtkButton *button, GParamSpec spec) +signal_second (GtkButton *button, GParamSpec *spec) { g_assert (normal == 10); normal = 20; } void /* exported for GtkBuilder */ -signal_extra (GtkButton *button, GParamSpec spec) +signal_extra (GtkButton *button, GParamSpec *spec) { g_assert (normal == 20); normal = 30; } void /* exported for GtkBuilder */ -signal_extra2 (GtkButton *button, GParamSpec spec) +signal_extra2 (GtkButton *button, GParamSpec *spec) { g_assert (normal == 30); normal = 40; From 385df5517bddc7326901797c6cbea1b2294c9d2e Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 08:34:50 +0200 Subject: [PATCH 02/32] gtkrc: search XDG data dirs for themes Based on the Guix gtk2-theme-paths.patch by Jookia. Keep the existing ~/.themes and gtk_rc_get_theme_dir() lookup paths, but check g_get_system_data_dirs() in between so profile- and prefix-based theme installations can be found. --- gtk/gtkrc.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gtk/gtkrc.c b/gtk/gtkrc.c index 7bfbea85c..d316a0d90 100644 --- a/gtk/gtkrc.c +++ b/gtk/gtkrc.c @@ -808,6 +808,8 @@ gtk_rc_parse_named (GtkRcContext *context, gchar *path = NULL; const gchar *home_dir; gchar *subpath; + const gchar * const *xdg_data_dirs; + gint i; if (type) subpath = g_strconcat ("gtk-2.0-", type, @@ -829,6 +831,22 @@ gtk_rc_parse_named (GtkRcContext *context, } } + if (!path) + { + xdg_data_dirs = g_get_system_data_dirs (); + for (i = 0; xdg_data_dirs[i]; i++) + { + path = g_build_filename (xdg_data_dirs[i], "themes", name, subpath, NULL); + if (g_file_test (path, G_FILE_TEST_EXISTS)) + break; + else + { + g_free (path); + path = NULL; + } + } + } + if (!path) { gchar *theme_dir = gtk_rc_get_theme_dir (); From 2d1ba49ab4399c8e35abc2a3756c9bf2015e32a9 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 09:15:53 +0200 Subject: [PATCH 03/32] build: disable GNU visibility aliases on Apple platforms Based on the MacPorts patch-aliases.diff. Keep the existing GNU visibility alias generation on other platforms, but avoid it on Apple targets where this alias mechanism is not suitable. --- gdk/makegdkalias.pl | 2 +- gtk/makegtkalias.pl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gdk/makegdkalias.pl b/gdk/makegdkalias.pl index 97a6e6007..27646cc0a 100755 --- a/gdk/makegdkalias.pl +++ b/gdk/makegdkalias.pl @@ -14,7 +14,7 @@ print < -#ifdef G_HAVE_GNUC_VISIBILITY +#if defined(G_HAVE_GNUC_VISIBILITY) && !defined(__APPLE__) EOF diff --git a/gtk/makegtkalias.pl b/gtk/makegtkalias.pl index 3f956b05e..67ec7c973 100755 --- a/gtk/makegtkalias.pl +++ b/gtk/makegtkalias.pl @@ -14,7 +14,7 @@ print < -#ifdef G_HAVE_GNUC_VISIBILITY +#if defined(G_HAVE_GNUC_VISIBILITY) && !defined(__APPLE__) EOF From 8347521bfda45433c6c7c303fc7e7745864db18d Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 09:16:45 +0200 Subject: [PATCH 04/32] quartz: add newer macOS version constants Based on the MacPorts patch-gdkquartz-osx-versions.diff. Extend the Quartz OS version enum so later macOS-specific code can distinguish Catalina, Big Sur, Monterey, Ventura, Sonoma, and Sequoia while preserving the existing older constants. --- gdk/quartz/gdkquartz.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gdk/quartz/gdkquartz.h b/gdk/quartz/gdkquartz.h index 8206db019..42aac50b9 100644 --- a/gdk/quartz/gdkquartz.h +++ b/gdk/quartz/gdkquartz.h @@ -54,7 +54,13 @@ typedef enum GDK_OSX_SIERRA = 12, GDK_OSX_HIGH_SIERRA = 13, GDK_OSX_MOJAVE = 14, - GDK_OSX_CURRENT = 14, + GDK_OSX_CATALINA = 15, + GDK_OSX_BIG_SUR = 16, + GDK_OSX_MONTEREY = 17, + GDK_OSX_VENTURA = 18, + GDK_OSX_SONOMA = 19, + GDK_OSX_SEQUOIA = 20, + GDK_OSX_CURRENT = 20, GDK_OSX_NEW = 99 } GdkOSXVersion; From eebe1148c159186d54b7cb876d0c77953dbfe177 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 09:27:16 +0200 Subject: [PATCH 05/32] quartz: avoid focus locking on Mojave and newer Based on part of the MacPorts Big Sur performance patch for GIMP issue 5989. The NSView focus-locking API is deprecated on newer macOS releases and can cause expensive redraw behaviour. Keep the old path for older macOS versions, but avoid lockFocusIfCanDraw/unlockFocus on Mojave and newer. --- gdk/quartz/gdkdrawable-quartz.c | 3 ++- gdk/quartz/gdkwindow-quartz.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gdk/quartz/gdkdrawable-quartz.c b/gdk/quartz/gdkdrawable-quartz.c index 11dd12737..eb520f08d 100644 --- a/gdk/quartz/gdkdrawable-quartz.c +++ b/gdk/quartz/gdkdrawable-quartz.c @@ -893,7 +893,8 @@ gdk_quartz_drawable_release_context (GdkDrawable *drawable, if (window_impl->in_paint_rect_count == 0) { _gdk_quartz_drawable_flush (drawable); - [window_impl->view unlockFocus]; + if (gdk_quartz_osx_version () < GDK_OSX_MOJAVE) + [window_impl->view unlockFocus]; } } else if (GDK_IS_PIXMAP_IMPL_QUARTZ (drawable)) diff --git a/gdk/quartz/gdkwindow-quartz.c b/gdk/quartz/gdkwindow-quartz.c index 6c7a2facb..205fd85e6 100644 --- a/gdk/quartz/gdkwindow-quartz.c +++ b/gdk/quartz/gdkwindow-quartz.c @@ -104,7 +104,8 @@ gdk_window_impl_quartz_get_context (GdkDrawable *drawable, * and for widgets that send fake expose events like the arrow * buttons in spinbuttons or the position marker in rulers. */ - if (window_impl->in_paint_rect_count == 0) + if (window_impl->in_paint_rect_count == 0 && + gdk_quartz_osx_version () < GDK_OSX_MOJAVE) { if (![window_impl->view lockFocusIfCanDraw]) return NULL; From 35e2e048fc512fb51f6987c795482222dd693808 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 09:29:27 +0200 Subject: [PATCH 06/32] quartz: map macOS 11 and newer to internal OS versions Based on part of the MacPorts Big Sur performance patch for GIMP issue 5989. GTK2 represents macOS 10.x releases by their minor version. Read the major version as well and map macOS 11 and newer into the same sequence so Big Sur and later releases can be detected correctly. --- gdk/quartz/gdkglobals-quartz.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gdk/quartz/gdkglobals-quartz.c b/gdk/quartz/gdkglobals-quartz.c index f013f2830..4e596eef5 100644 --- a/gdk/quartz/gdkglobals-quartz.c +++ b/gdk/quartz/gdkglobals-quartz.c @@ -34,9 +34,20 @@ gdk_quartz_osx_version (void) if (minor == GDK_OSX_UNSUPPORTED) { - OSErr err = Gestalt (gestaltSystemVersionMinor, (SInt32*)&minor); + gint32 major = GDK_OSX_UNSUPPORTED; + OSErr err = Gestalt (gestaltSystemVersionMajor, (SInt32*)&major); g_return_val_if_fail (err == noErr, GDK_OSX_UNSUPPORTED); + + err = Gestalt (gestaltSystemVersionMinor, (SInt32*)&minor); + g_return_val_if_fail (err == noErr, GDK_OSX_UNSUPPORTED); + + /* GTK2 encodes macOS 10.x releases by their minor version. + * Map macOS 11+ into the same sequence: + * 11 -> 16, 12 -> 17, 13 -> 18, ... + */ + if (major > 10) + minor = major + 5; } if (minor < GDK_OSX_MIN) From ceb158a3e1be917b55f2db4ce9b477cc8347c163 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 09:32:30 +0200 Subject: [PATCH 07/32] quartz: use CGContext accessor on Yosemite and newer Based on part of the MacPorts Big Sur performance patch for GIMP issue 5989. Use the modern NSGraphicsContext CGContext accessor on Yosemite and newer, matching the existing Quartz window code, while preserving graphicsPort for older macOS versions. --- gtk/gtkquartz.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gtk/gtkquartz.c b/gtk/gtkquartz.c index 87ba87745..caf8404f8 100644 --- a/gtk/gtkquartz.c +++ b/gtk/gtkquartz.c @@ -67,7 +67,10 @@ _gtk_quartz_create_image_from_pixbuf (GdkPixbuf *pixbuf) } [nsimage lockFocus]; - context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; + if (gdk_quartz_osx_version () < GDK_OSX_YOSEMITE) + context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; + else + context = [[NSGraphicsContext currentContext] CGContext]; CGContextDrawImage (context, CGRectMake (0, 0, pixbuf_width, pixbuf_height), image); [nsimage unlockFocus]; From 032c5f1efdfaebbff28353308ffce3081b3b2a68 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 09:41:36 +0200 Subject: [PATCH 08/32] quartz: avoid screen update suppression on Mojave and newer Based on part of the MacPorts Big Sur performance patch for GIMP issue 5989. NSDisableScreenUpdates and NSEnableScreenUpdates are deprecated on newer macOS releases. Keep using them for older macOS versions, but avoid them on Mojave and newer. --- gdk/quartz/gdkwindow-quartz.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gdk/quartz/gdkwindow-quartz.c b/gdk/quartz/gdkwindow-quartz.c index 205fd85e6..5c1bde0cd 100644 --- a/gdk/quartz/gdkwindow-quartz.c +++ b/gdk/quartz/gdkwindow-quartz.c @@ -469,7 +469,8 @@ _gdk_windowing_before_process_all_updates (void) { in_process_all_updates = TRUE; - NSDisableScreenUpdates (); + if (gdk_quartz_osx_version () < GDK_OSX_MOJAVE) + NSDisableScreenUpdates (); } void @@ -503,7 +504,8 @@ _gdk_windowing_after_process_all_updates (void) in_process_all_updates = FALSE; - NSEnableScreenUpdates (); + if (gdk_quartz_osx_version () < GDK_OSX_MOJAVE) + NSEnableScreenUpdates (); } static void From 3b177953c1ac9463a1a24d7371be1107facabd71 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 09:49:48 +0200 Subject: [PATCH 09/32] quartz: request 8-bit layer contents on Big Sur and newer Based on part of the MacPorts Big Sur performance patch for GIMP issue 5989. Use a dynamic Objective-C call to request 8-bit layer contents on macOS 11 and newer, avoiding a hard QuartzCore/CALayer compile-time dependency and preserving old behaviour on older macOS releases. --- gdk/quartz/GdkQuartzView.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gdk/quartz/GdkQuartzView.c b/gdk/quartz/GdkQuartzView.c index 368e040ec..bad737da2 100644 --- a/gdk/quartz/GdkQuartzView.c +++ b/gdk/quartz/GdkQuartzView.c @@ -599,6 +599,25 @@ gdk_screen_get_rgba_colormap (_gdk_screen); } +-(void)viewWillDraw +{ + /* macOS 11 (Big Sur) and newer may use a higher precision backing + * format for layer contents. For GTK2's 8-bit drawing this can add + * avoidable conversion overhead. Use a dynamic Objective-C call here + * instead of a hard QuartzCore/CALayer dependency, so old SDKs and old + * macOS targets keep building and keep their old behaviour. + */ + if (gdk_quartz_osx_version () >= GDK_OSX_BIG_SUR) + { + id layer = [self layer]; + + if (layer && [layer respondsToSelector: @selector(setContentsFormat:)]) + [layer setValue: @"RGBA8Uint" forKey: @"contentsFormat"]; + } + + [super viewWillDraw]; +} + -(void)drawRect: (NSRect)rect { GdkRectangle gdk_rect; From 243fcad89fe502e4cb1ef11ebe060b3510b7ed99 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 09:54:51 +0200 Subject: [PATCH 10/32] quartz: avoid extra content invalidation on Big Sur and newer Based on part of the MacPorts Big Sur performance patch for GIMP issue 5989. Keep the existing Mojave-era setNeedsDisplay workaround for macOS 10.14 and 10.15, but avoid the extra full-window invalidation on Big Sur and newer where it can cause expensive redraw behaviour. --- gdk/quartz/gdkwindow-quartz.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gdk/quartz/gdkwindow-quartz.c b/gdk/quartz/gdkwindow-quartz.c index 5c1bde0cd..38ada80b2 100644 --- a/gdk/quartz/gdkwindow-quartz.c +++ b/gdk/quartz/gdkwindow-quartz.c @@ -491,8 +491,9 @@ _gdk_windowing_after_process_all_updates (void) /* 10.14 needs to be told that the view needs to be redrawn, see * https://gitlab.gnome.org/GNOME/gtk/issues/1479 */ - if (gdk_quartz_osx_version() >= GDK_OSX_MOJAVE) - [[nswindow contentView] setNeedsDisplay:YES]; + if (gdk_quartz_osx_version () >= GDK_OSX_MOJAVE && + gdk_quartz_osx_version () < GDK_OSX_BIG_SUR) + [[nswindow contentView] setNeedsDisplay:YES]; [nswindow enableFlushWindow]; [nswindow flushWindow]; [nswindow release]; From b305265deaa1d106cb4a4cb779373160f5439050 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 09:59:26 +0200 Subject: [PATCH 11/32] quartz: avoid extra resize-idle updates on Big Sur and newer Based on part of the MacPorts Big Sur performance patch for GIMP issue 5989. Keep the existing gdk_window_process_all_updates() call for non-Quartz targets and for older macOS releases, but avoid this extra resize-idle update path on Big Sur and newer where it can contribute to expensive full-window redraw behaviour. --- gtk/gtkcontainer.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c index 2f7007fd2..e4c98c8c2 100644 --- a/gtk/gtkcontainer.c +++ b/gtk/gtkcontainer.c @@ -40,6 +40,9 @@ #include "gtktoolbar.h" #include #include +#ifdef GDK_WINDOWING_QUARTZ +#include "gdk/quartz/gdkquartz.h" +#endif #include "gtkalias.h" @@ -1357,7 +1360,16 @@ gtk_container_idle_sizer (gpointer data) gtk_container_check_resize (GTK_CONTAINER (widget)); } +#ifdef GDK_WINDOWING_QUARTZ + /* macOS 11 and newer can trigger expensive full-window redraws here. + * Keep the traditional update processing path for older Quartz targets, + * but let the normal GDK update idle handle updates on Big Sur and newer. + */ + if (gdk_quartz_osx_version () < GDK_OSX_BIG_SUR) + gdk_window_process_all_updates (); +#else gdk_window_process_all_updates (); +#endif return FALSE; } From cd4145185c7369249774c183a10809ccd48940c0 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 10:06:34 +0200 Subject: [PATCH 12/32] win32: improve mouse window lookup through transparent children Based on the MSYS2 0013_fix_mouse_events.patch. Use CWP_SKIPTRANSPARENT while walking from the desktop window, but stop skipping transparent windows after the first level so transparent child windows are still considered correctly. --- gdk/win32/gdkwindow-win32.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gdk/win32/gdkwindow-win32.c b/gdk/win32/gdkwindow-win32.c index b7ea0404a..1a21a1b67 100644 --- a/gdk/win32/gdkwindow-win32.c +++ b/gdk/win32/gdkwindow-win32.c @@ -2767,6 +2767,10 @@ _gdk_windowing_window_at_pointer (GdkDisplay *display, * WindowFromPoint() can find our windows, we follow similar logic * here, and ignore invisible and disabled windows. */ + UINT cwp_flags = CWP_SKIPDISABLED | + CWP_SKIPINVISIBLE | + CWP_SKIPTRANSPARENT; + hwnd = GetDesktopWindow (); do { window = gdk_win32_handle_table_lookup ((GdkNativeWindow) hwnd); @@ -2777,8 +2781,7 @@ _gdk_windowing_window_at_pointer (GdkDisplay *display, break; screen_to_client (hwnd, screen_pt, &client_pt); - hwndc = ChildWindowFromPointEx (hwnd, client_pt, CWP_SKIPDISABLED | - CWP_SKIPINVISIBLE); + hwndc = ChildWindowFromPointEx (hwnd, client_pt, cwp_flags); /* Verify that we're really inside the client area of the window */ if (hwndc != hwnd) @@ -2789,6 +2792,8 @@ _gdk_windowing_window_at_pointer (GdkDisplay *display, hwndc = hwnd; } + /* Only ignore top-level transparent windows */ + cwp_flags &= ~CWP_SKIPTRANSPARENT; } while (hwndc != hwnd && (hwnd = hwndc, 1)); } From e42049b412566993ba779e8b411a5cc22264d683 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 10:07:25 +0200 Subject: [PATCH 13/32] icontheme: detect SVG icons by extension on Win32 Based on the MSYS2 0022-icontheme-win32-detect-SVG-files-by-extension.patch. Some Windows systems report .svg files with a generic or incorrect content type. On Win32, fall back to the .svg extension so SVG icons can still be detected. --- gtk/gtkicontheme.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c index 0d4435c72..f8aaf9a3b 100644 --- a/gtk/gtkicontheme.c +++ b/gtk/gtkicontheme.c @@ -2945,6 +2945,10 @@ icon_info_ensure_scale_and_pixbuf (GtkIconInfo *icon_info, if (mime_type && strcmp (mime_type, "image/svg+xml") == 0) is_svg = TRUE; +#ifdef G_OS_WIN32 + else if (content_type && strcmp (content_type, ".svg") == 0) + is_svg = TRUE; +#endif } g_object_unref (file_info); From 45fc03183e4e192baa7596fc7edcc2df666a782d Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 10:08:01 +0200 Subject: [PATCH 14/32] win32: initialize key state before updating keymap Based on the MSYS2 0023-gdkkeys-win32.c-fix-initialisation-of-key_state-in-u.patch. Clear the key_state array before using it during keymap updates so stale state cannot affect layout handling, including Japanese IME input. --- gdk/win32/gdkkeys-win32.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gdk/win32/gdkkeys-win32.c b/gdk/win32/gdkkeys-win32.c index d8ab30347..9a34083c4 100644 --- a/gdk/win32/gdkkeys-win32.c +++ b/gdk/win32/gdkkeys-win32.c @@ -692,6 +692,7 @@ update_keymap (GdkKeymap *gdk_keymap) if (hkls_len != keymap->layout_handles->len) keymap->keysym_tab = g_renew (guint, keymap->keysym_tab, keysym_tab_size); + memset (key_state, 0, sizeof(key_state)); memset (keymap->keysym_tab, 0, keysym_tab_size); g_array_set_size (keymap->layout_handles, hkls_len); g_array_set_size (keymap->options, hkls_len); From 442630afe580ca7390f18bab56ae293a68ad5c77 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 10:09:36 +0200 Subject: [PATCH 15/32] win32: quote icon cache manifest in resource file Based on the MSYS2 0024-gtk-update-icon-cache-rc-quote.patch. Quote the manifest path when generating the gtk-update-icon-cache resource file so windres parses it correctly. --- gtk/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 5cbe2a326..4df1c78bd 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -1139,7 +1139,7 @@ $(GTK_UPDATE_ICON_CACHE_MANIFEST): echo '' ) >$@ $(GTK_UPDATE_ICON_CACHE_RC): - (echo -e '#include \nCREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST '$(GTK_UPDATE_ICON_CACHE_MANIFEST)) >$@ + (echo -e '#include \nCREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "'$(GTK_UPDATE_ICON_CACHE_MANIFEST)'"') >$@ $(GTK_UPDATE_ICON_CACHE_MANIFEST_OBJECT): $(GTK_UPDATE_ICON_CACHE_RC) $(GTK_UPDATE_ICON_CACHE_MANIFEST) $(WINDRES) --input $< --output $@ --output-format=coff From cc3ccba88d065c16657e98b795665ee704b01b91 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 10:19:49 +0200 Subject: [PATCH 16/32] introspection: pass compiler and GTK DLL path to scanner Based on the MSYS2 0009-give-cc-to-gir-scanner.mingw.patch and 0010-put-gtk-dll-into-path.mingw.patch. Pass CC to g-ir-scanner and add the GTK build directory to PATH while scanning GTK, so MinGW builds can run the scanner with the just-built DLLs. --- gdk/Makefile.am | 2 ++ gtk/Makefile.am | 3 +++ 2 files changed, 5 insertions(+) diff --git a/gdk/Makefile.am b/gdk/Makefile.am index 1b186afa1..35dbc026c 100644 --- a/gdk/Makefile.am +++ b/gdk/Makefile.am @@ -2,6 +2,8 @@ include $(top_srcdir)/Makefile.decl -include $(INTROSPECTION_MAKEFILE) INTROSPECTION_GIRS = +INTROSPECTION_SCANNER_ENV = \ + CC="$(CC)" INTROSPECTION_SCANNER_ARGS = \ --warn-all \ --add-include-path=../gdk diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 4df1c78bd..083fd07b7 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -2,6 +2,9 @@ include $(top_srcdir)/Makefile.decl -include $(INTROSPECTION_MAKEFILE) INTROSPECTION_GIRS = +INTROSPECTION_SCANNER_ENV = \ + CC="$(CC)" \ + PATH="$(builddir):$(builddir)/.libs:$${PATH}:" INTROSPECTION_SCANNER_ARGS = \ --warn-all \ --add-include-path=../gdk From 4cde9b16fd154de2da39557cbe0eb8488f6d346e Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 10:48:27 +0200 Subject: [PATCH 17/32] introspection: add GdkWin32 GIR generation Based on the MSYS2 0011-gir-for-gdkwin32.mingw.patch. Add Win32 backend sources to introspection when building the Win32 target and generate GdkWin32-2.0.gir alongside the common Gdk-2.0 GIR. --- gdk/Makefile.am | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/gdk/Makefile.am b/gdk/Makefile.am index 35dbc026c..1b4cd9b50 100644 --- a/gdk/Makefile.am +++ b/gdk/Makefile.am @@ -215,6 +215,11 @@ Gdk_2_0_gir_CFLAGS = \ -I$(top_builddir) \ -I$(top_builddir)/gdk \ $(INCLUDES) + +if OS_WIN32 +Gdk_2_0_gir_CFLAGS += -I$(srcdir)/win32 -I$(srcdir) +endif + INTROSPECTION_GIRS += Gdk-2.0.gir if USE_X11 @@ -270,6 +275,62 @@ introspection_files += $(filter-out x11/gdkx.h, $(x11_introspection_files)) endif # USE_X11 +if OS_WIN32 +win32_introspection_files = \ + win32/gdkapplaunchcontext-win32.c \ + win32/gdkcolor-win32.c \ + win32/gdkcursor-win32.c \ + win32/gdkdisplay-win32.c \ + win32/gdkdnd-win32.c \ + win32/gdkdrawable-win32.c \ + win32/gdkdrawable-win32.h \ + win32/gdkevents-win32.c \ + win32/gdkfont-win32.c \ + win32/gdkgc-win32.c \ + win32/gdkgeometry-win32.c \ + win32/gdkglobals-win32.c \ + win32/gdkimage-win32.c \ + win32/gdkim-win32.c \ + win32/gdkinput.c \ + win32/gdkinput-win32.c \ + win32/gdkinput-win32.h \ + win32/gdkkeys-win32.c \ + win32/gdkmain-win32.c \ + win32/gdkpixmap-win32.c \ + win32/gdkpixmap-win32.h \ + win32/gdkprivate-win32.h \ + win32/gdkproperty-win32.c \ + win32/gdkscreen-win32.c \ + win32/gdkselection-win32.c \ + win32/gdkspawn-win32.c \ + win32/gdktestutils-win32.c \ + win32/gdkvisual-win32.c \ + win32/gdkwin32.h \ + win32/gdkwin32id.c \ + win32/gdkwindow-win32.c \ + win32/gdkwindow-win32.h + +GdkWin32-2.0.gir: $(gdktargetlib) Gdk-2.0.gir Makefile +GdkWin32_2_0_gir_SCANNERFLAGS = --warn-all --identifier-prefix=Gdk --symbol-prefix=gdk --include-uninstalled=Gdk-2.0.gir +GdkWin32_2_0_gir_INCLUDES = Gio-2.0 Gdk-2.0 GdkPixbuf-2.0 Pango-1.0 +GdkWin32_2_0_gir_LIBS = $(gdktargetlib) +GdkWin32_2_0_gir_FILES = $(win32_introspection_files) +GdkWin32_2_0_gir_EXPORT_PACKAGES = gdk-win32-2.0 +GdkWin32_2_0_gir_CFLAGS = \ + -DGDK_COMPILATION \ + -I$(top_srcdir) \ + -I$(top_builddir) \ + -I$(top_builddir)/gdk \ + -I$(srcdir)/win32 \ + -I$(srcdir) \ + $(INCLUDES) \ + -L$(top_builddir)/gdk +INTROSPECTION_GIRS += GdkWin32-2.0.gir + +introspection_files += $(filter-out win32/gdkwin32.h, $(win32_introspection_files)) + +endif # OS_WIN32 + girdir = $(datadir)/gir-1.0 gir_DATA = $(INTROSPECTION_GIRS) From 06974f39fcacb0ea0fbdfd4bbe72b9387e9eea1e Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 10:48:39 +0200 Subject: [PATCH 18/32] introspection: include Win32 keymap declarations Add gdkwin32keys.h to the Win32 introspection source list so exported Win32 keymap APIs are visible in GdkWin32-2.0.gir. The corresponding gdk_win32_keymap_get_type() and gdk_win32_keymap_check_compose() symbols are already exported, so this keeps the GIR closer to the installed Win32 API surface. --- gdk/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/gdk/Makefile.am b/gdk/Makefile.am index 1b4cd9b50..f9804aa85 100644 --- a/gdk/Makefile.am +++ b/gdk/Makefile.am @@ -307,6 +307,7 @@ win32_introspection_files = \ win32/gdkvisual-win32.c \ win32/gdkwin32.h \ win32/gdkwin32id.c \ + win32/gdkwin32keys.h \ win32/gdkwindow-win32.c \ win32/gdkwindow-win32.h From 1ae5c7beec862294c56d8e00a2dd1bd9c62c9287 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 10:55:56 +0200 Subject: [PATCH 19/32] docs: use top_srcdir for GDK X11 header reference Based on the MSYS2 0005-Fix-header-ref.all.patch. Use an explicit top_srcdir-relative path for gdkx.h in the GDK reference documentation instead of a fragile relative path. --- docs/reference/gdk/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/gdk/Makefile.am b/docs/reference/gdk/Makefile.am index c0facc151..43a67508c 100644 --- a/docs/reference/gdk/Makefile.am +++ b/docs/reference/gdk/Makefile.am @@ -37,7 +37,7 @@ IGNORE_HFILES= \ # Extra files to add when scanning (relative to $srcdir) EXTRA_HFILES= \ - ../../../gdk/x11/gdkx.h + $(top_srcdir)/gdk/x11/gdkx.h # CFLAGS and LDFLAGS for compiling scan program. Only needed # if $(DOC_MODULE).types is non-empty. From 7cc56a996537d7699b6ac7499da0e26d71fabd10 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 11:25:19 +0200 Subject: [PATCH 20/32] gtktrayicon: use explicit void prototypes for reserved slots Based on the Mageia gtk+-2.24.32-warnings.patch. Declare the reserved GtkTrayIconClass function pointers with explicit void parameter lists to avoid strict-prototype warnings without changing the class layout. --- gtk/gtktrayicon.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gtk/gtktrayicon.h b/gtk/gtktrayicon.h index 9ad1c54f2..ab4eda2f5 100644 --- a/gtk/gtktrayicon.h +++ b/gtk/gtktrayicon.h @@ -46,12 +46,12 @@ struct _GtkTrayIconClass { GtkPlugClass parent_class; - void (*__gtk_reserved1); - void (*__gtk_reserved2); - void (*__gtk_reserved3); - void (*__gtk_reserved4); - void (*__gtk_reserved5); - void (*__gtk_reserved6); + void (*__gtk_reserved1) (void); + void (*__gtk_reserved2) (void); + void (*__gtk_reserved3) (void); + void (*__gtk_reserved4) (void); + void (*__gtk_reserved5) (void); + void (*__gtk_reserved6) (void); }; GType gtk_tray_icon_get_type (void) G_GNUC_CONST; From 525150055d6fa30265a41df9f92326e1d618de7e Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 11:46:52 +0200 Subject: [PATCH 21/32] print: preserve default-printer wait during status updates Based on the openSUSE gtk2-default-printer.patch. Avoid treating printer status updates as user-driven printer selection changes, so the print dialog can continue waiting for a default printer that may appear later. --- gtk/gtkprintunixdialog.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c index da9010b96..af64a5a37 100644 --- a/gtk/gtkprintunixdialog.c +++ b/gtk/gtkprintunixdialog.c @@ -796,7 +796,9 @@ printer_status_cb (GtkPrintBackend *backend, /* When the pause state change then we need to update sensitive property * of GTK_RESPONSE_OK button inside of selected_printer_changed function. */ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->printer_treeview)); + priv->internal_printer_change = TRUE; selected_printer_changed (selection, dialog); + priv->internal_printer_change = FALSE; if (gtk_print_backend_printer_list_is_done (backend) && gtk_printer_is_default (printer) && From 02a2c61f2dfc574a88343c81ddf10fc515136533 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 11:49:09 +0200 Subject: [PATCH 22/32] gdk: handle 30-bit RGB drawables in GdkRGB Based on the openSUSE gtk2-bgo625202-30-bit-drawables-remain-black.patch. Add a dedicated conversion path for 32bpp 30-bit truecolor visuals so 8-bit RGB source data is expanded to 10-bit channels instead of producing black or overly dark output. --- gdk/gdkrgb.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/gdk/gdkrgb.c b/gdk/gdkrgb.c index b0ff66833..1e37a6181 100644 --- a/gdk/gdkrgb.c +++ b/gdk/gdkrgb.c @@ -2242,6 +2242,51 @@ gdk_rgb_convert_8880_br (GdkRgbInfo *image_info, GdkImage *image, } } +static void +gdk_rgb_convert_0AAA_br (GdkRgbInfo *image_info, GdkImage *image, + gint x0, gint y0, gint width, gint height, + const guchar *buf, int rowstride, + gint x_align, gint y_align, GdkRgbCmap *cmap) +{ + int y, w; + guchar *obuf, *p; + gint bpl; + const guchar *bptr, *bp2; + guchar r, g, b; + + bptr = buf; + bpl = image->bpl; + obuf = ((guchar *) image->mem) + y0 * bpl + x0 * 4; + + for (y = 0; y < height; y++) + { + bp2 = bptr; + p = obuf; + w = width; + + while (w--) + { + r = *bp2++; + g = *bp2++; + b = *bp2++; + + /* Since the R, G and B channels are coded in a char, we + * replicate the two most significant bits to the two least + * significant ones. + */ + *((guint32 *) p) = 0x3 << 30 | + b << 22 | (b >> 6) << 20 | + g << 12 | (g >> 6) << 10 | + r << 2 | (r >> 6); + + p += 4; + } + + bptr += rowstride; + obuf += bpl; + } +} + /* Generic truecolor/directcolor conversion function. Slow, but these are oddball modes. */ static void @@ -3195,6 +3240,11 @@ gdk_rgb_select_conv (GdkRgbInfo *image_info) #endif } #endif + else if (bpp == 32 && (depth == 30 || depth == 32) && + vtype == GDK_VISUAL_TRUE_COLOR && + (red_mask == 0x3ff && green_mask == 0xffc00 && + blue_mask == 0x3ff00000 && byte_order == GDK_LSB_FIRST)) + conv = gdk_rgb_convert_0AAA_br; else if (vtype == GDK_VISUAL_TRUE_COLOR && byte_order == GDK_LSB_FIRST) { conv = gdk_rgb_convert_truecolor_lsb; From 438c13366aae3c02a797f8689b447193733a1a7a Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 12:12:49 +0200 Subject: [PATCH 23/32] fontsel: localize common font style names Based on the openSUSE bugzilla-129753-gtk+-2.8.9-localize-font-style-name.diff. Mark common font style names for translation and use translated names in the font selection UI when Pango returns standard style names. --- gtk/gtkfontbutton.c | 2 +- gtk/gtkfontsel.c | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gtk/gtkfontbutton.c b/gtk/gtkfontbutton.c index 08aea103e..a52ddd470 100644 --- a/gtk/gtkfontbutton.c +++ b/gtk/gtkfontbutton.c @@ -889,7 +889,7 @@ gtk_font_button_update_font_info (GtkFontButton *font_button) if (style == NULL || !g_ascii_strcasecmp (style, "Regular")) family_style = g_strdup (family); else - family_style = g_strdup_printf ("%s %s", family, style); + family_style = g_strdup_printf ("%s %s", family, _(style)); gtk_label_set_text (GTK_LABEL (font_button->priv->font_label), family_style); diff --git a/gtk/gtkfontsel.c b/gtk/gtkfontsel.c index 701d22841..7dc9a6ee8 100644 --- a/gtk/gtkfontsel.c +++ b/gtk/gtkfontsel.c @@ -76,6 +76,22 @@ #define DEFAULT_FONT_NAME "Sans 10" +/* Common font style names, listed here so they can be translated when + * Pango returns the standard English names. + */ +#define FONT_STYLE_ULTRA_LIGHT N_("Ultra-Light") +#define FONT_STYLE_LIGHT N_("Light") +#define FONT_STYLE_MEDIUM N_("Medium") +#define FONT_STYLE_NORMAL N_("Normal") +#define FONT_STYLE_REGULAR N_("Regular") +#define FONT_STYLE_ITALIC N_("Italic") +#define FONT_STYLE_OBLIQUE N_("Oblique") +#define FONT_STYLE_SEMI_BOLD N_("Semi-Bold") +#define FONT_STYLE_BOLD N_("Bold") +#define FONT_STYLE_ULTRA_BOLD N_("Ultra-Bold") +#define FONT_STYLE_HEAVY N_("Heavy") +#define FONT_STYLE_BOLD_ITALIC N_("Bold Italic") + /* This is the initial and maximum height of the preview entry (it expands when large font sizes are selected). Initial height is also the minimum. */ #define INITIAL_PREVIEW_HEIGHT 44 @@ -869,7 +885,7 @@ gtk_font_selection_show_available_styles (GtkFontSelection *fontsel) gtk_list_store_append (model, &iter); gtk_list_store_set (model, &iter, FACE_COLUMN, faces[i], - FACE_NAME_COLUMN, str, + FACE_NAME_COLUMN, _(str), -1); if (i == 0) From 2901f63d0d3fa8856e46dd68f7a72dd83f8849c6 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 12:23:35 +0200 Subject: [PATCH 24/32] cups: add Secret Service helper for print authentication Based on the openSUSE gtk2-bgo743166-remember-printing-authentication.patch. Add the CUPS Secret Service helper source files separately before wiring them into the print backend. --- .../printbackends/cups/gtkcupssecretsutils.c | 1044 +++++++++++++++++ .../printbackends/cups/gtkcupssecretsutils.h | 41 + 2 files changed, 1085 insertions(+) create mode 100644 modules/printbackends/cups/gtkcupssecretsutils.c create mode 100644 modules/printbackends/cups/gtkcupssecretsutils.h diff --git a/modules/printbackends/cups/gtkcupssecretsutils.c b/modules/printbackends/cups/gtkcupssecretsutils.c new file mode 100644 index 000000000..2ed0db57c --- /dev/null +++ b/modules/printbackends/cups/gtkcupssecretsutils.c @@ -0,0 +1,1044 @@ +/* gtkcupssecretsutils.h: Helper to use a secrets service for printer passwords + * Copyright (C) 2014, Intevation GmbH + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include +#include +#include + +#include + +#include "gtkcupssecretsutils.h" + +#define SECRETS_BUS "org.freedesktop.secrets" +#define SECRETS_IFACE(interface) "org.freedesktop.Secret."interface +#define SECRETS_PATH "/org/freedesktop/secrets" +#define SECRETS_TIMEOUT 5000 + +typedef enum +{ + SECRETS_SERVICE_ACTION_QUERY, + SECRETS_SERVICE_ACTION_STORE +} SecretsServiceAction; + +typedef struct +{ + GDBusConnection *dbus_connection; + SecretsServiceAction action; + gchar **auth_info, + **auth_info_labels, + **auth_info_required, + *printer_uri, + *session_path, + *collection_path; + GDBusProxy *item_proxy; + guint prompt_subscription; +} SecretsServiceData; + +/** + * create_attributes: + * @printer_uri: URI for the printer + * @additional_labels: Optional labels for additional attributes + * @additional_attrs: Optional additional attributes + * + * Creates a GVariant dictionary with key / value pairs that + * can be used to identify a secret item. + * + * Returns: A GVariant dictionary of string pairs or NULL on error. + */ +static GVariant * +create_attributes (const gchar *printer_uri, + gchar **additional_attrs, + gchar **additional_labels) +{ + GVariantBuilder *attr_builder = NULL; + GVariant *ret = NULL; + + if (printer_uri == NULL) + { + GTK_NOTE (PRINTING, + g_print ("create_attributes called with invalid parameters.\n")); + return NULL; + } + + attr_builder = g_variant_builder_new (G_VARIANT_TYPE_DICTIONARY); + /* The printer uri is the main identifying part */ + g_variant_builder_add (attr_builder, "{ss}", "uri", printer_uri); + + if (additional_labels != NULL) + { + int i; + for (i = 0; additional_labels[i] != NULL; i++) + { + g_variant_builder_add (attr_builder, "{ss}", + additional_labels[i], + additional_attrs[i]); + } + } + + ret = g_variant_builder_end (attr_builder); + g_variant_builder_unref (attr_builder); + + return ret; +} + +static void +get_secret_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GTask *task; + SecretsServiceData *task_data; + GError *error = NULL; + GVariant *output, + *attributes; + gchar **auth_info = NULL, + *key = NULL, + *value = NULL; + GVariantIter *iter = NULL; + guint i; + gint pw_field = -1; + + task = user_data; + task_data = g_task_get_task_data (task); + + output = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), + res, + &error); + if (output == NULL) + { + g_task_return_error (task, error); + return; + } + + attributes = g_dbus_proxy_get_cached_property (task_data->item_proxy, + "Attributes"); + if (attributes == NULL) + { + GTK_NOTE (PRINTING, g_print ("Failed to lookup attributes.\n")); + g_variant_unref (output); + g_task_return_pointer (task, NULL, NULL); + return; + } + + /* Iterate over the attributes to fill the auth info */ + g_variant_get (attributes, "a{ss}", &iter); + + auth_info = g_new0 (gchar *, + g_strv_length (task_data->auth_info_required) + 1); + + while (g_variant_iter_loop (iter, "{ss}", &key, &value)) + { + /* Match attributes with required auth info */ + for (i = 0; task_data->auth_info_required[i] != NULL; i++) + { + if ((strcmp (key, "user") == 0 || + strcmp (key, "username") == 0) && + strcmp (task_data->auth_info_required[i], + "username") == 0) + { + auth_info[i] = g_strdup (value); + } + else if (strcmp (key, "domain") == 0 && + strcmp (task_data->auth_info_required[i], "domain") == 0) + { + auth_info[i] = g_strdup (value); + } + else if ((strcmp (key, "hostname") == 0 || + strcmp (key, "server") == 0 ) && + strcmp (task_data->auth_info_required[i], "hostname") == 0) + { + auth_info[i] = g_strdup (value); + } + else if (strcmp (task_data->auth_info_required[i], "password") == 0) + { + pw_field = i; + } + } + } + + if (pw_field == -1) + { + /* should not happen... */ + GTK_NOTE (PRINTING, g_print ("No password required?.\n")); + g_variant_unref (output); + goto fail; + } + else + { + GVariant *secret, + *s_value; + gconstpointer ba_passwd = NULL; + gsize len = 0; + + secret = g_variant_get_child_value (output, 0); + g_variant_unref (output); + if (secret == NULL || g_variant_n_children (secret) != 4) + { + GTK_NOTE (PRINTING, g_print ("Get secret response invalid.\n")); + if (secret != NULL) + g_variant_unref (secret); + goto fail; + } + s_value = g_variant_get_child_value (secret, 2); + ba_passwd = g_variant_get_fixed_array (s_value, + &len, + sizeof (guchar)); + + g_variant_unref (secret); + + if (ba_passwd == NULL) + { + /* No secret or the secret is not a zero terminated value */ + GTK_NOTE (PRINTING, g_print ("Invalid / no secret found.\n")); + g_variant_unref (s_value); + goto fail; + } + + auth_info[pw_field] = g_strndup (ba_passwd, len); + g_variant_unref (s_value); + } + + for (i = 0; task_data->auth_info_required[i] != NULL; i++) + { + if (auth_info[i] == NULL) + { + /* Error out if we did not find everything */ + GTK_NOTE (PRINTING, g_print ("Failed to lookup required attribute: %s.\n", + task_data->auth_info_required[i])); + goto fail; + } + } + + g_task_return_pointer (task, auth_info, NULL); + return; + +fail: + /* Error out */ + GTK_NOTE (PRINTING, g_print ("Failed to lookup secret.\n")); + for (i = 0; i < g_strv_length (task_data->auth_info_required); i++) + { + /* Not all fields of auth_info are neccessarily written so we can not + use strfreev here */ + g_free (auth_info[i]); + } + g_free (auth_info); + g_task_return_pointer (task, NULL, NULL); +} + +static void +create_item_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GTask *task; + GError *error = NULL; + GVariant *output; + gchar *item = NULL; + + task = user_data; + + output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), + res, + &error); + if (output == NULL) + { + g_task_return_error (task, error); + return; + } + + g_variant_get (output, "(&o&o)", &item, NULL); + if (item != NULL && strlen (item) > 1) + { + GTK_NOTE (PRINTING, g_print ("Successfully stored auth info.\n")); + g_task_return_pointer (task, NULL, NULL); + return; + } + g_variant_unref (output); +} + +static void +do_store_auth_info (GTask *task) +{ + GVariant *attributes = NULL, + *properties = NULL, + *secret = NULL; + gchar **additional_attrs = NULL, + **additional_labels = NULL, + *password = NULL; + SecretsServiceData *task_data = g_task_get_task_data (task); + guint i, + length, + additional_count = 0; + GVariantBuilder *prop_builder = NULL; + + length = g_strv_length (task_data->auth_info_labels); + + additional_attrs = g_new0 (gchar *, length + 1); + additional_labels = g_new0 (gchar *, length + 1); + /* The labels user and server are chosen to be compatible with + the attributes used by system-config-printer */ + for (i = 0; task_data->auth_info_labels[i] != NULL; i++) + { + if (g_strcmp0 (task_data->auth_info_labels[i], "username") == 0) + { + additional_attrs[additional_count] = task_data->auth_info[i]; + additional_labels[additional_count++] = "user"; + } + else if (g_strcmp0 (task_data->auth_info_labels[i], "hostname") == 0) + { + additional_attrs[additional_count] = task_data->auth_info[i]; + additional_labels[additional_count++] = "server"; + } + else if (g_strcmp0 (task_data->auth_info_labels[i], "password") == 0) + { + password = task_data->auth_info[i]; + } + } + + attributes = create_attributes (task_data->printer_uri, + additional_attrs, + additional_labels); + g_free (additional_labels); + g_free (additional_attrs); + if (attributes == NULL) + { + GTK_NOTE (PRINTING, g_print ("Failed to create attributes.\n")); + g_task_return_pointer (task, NULL, NULL); + return; + } + + if (password == NULL) + { + GTK_NOTE (PRINTING, g_print ("No secret to store.\n")); + g_task_return_pointer (task, NULL, NULL); + return; + } + + prop_builder = g_variant_builder_new (G_VARIANT_TYPE_DICTIONARY); + + g_variant_builder_add (prop_builder, "{sv}", SECRETS_IFACE ("Item.Label"), + g_variant_new_string (task_data->printer_uri)); + g_variant_builder_add (prop_builder, "{sv}", SECRETS_IFACE ("Item.Attributes"), + attributes); + + properties = g_variant_builder_end (prop_builder); + + g_variant_builder_unref (prop_builder); + + secret = g_variant_new ("(oay@ays)", + task_data->session_path, + NULL, + g_variant_new_bytestring (password), + "text/plain"); + + g_dbus_connection_call (task_data->dbus_connection, + SECRETS_BUS, + task_data->collection_path, + SECRETS_IFACE ("Collection"), + "CreateItem", + g_variant_new ("(@a{sv}@(oayays)b)", + properties, + secret, + TRUE), + G_VARIANT_TYPE ("(oo)"), + G_DBUS_CALL_FLAGS_NONE, + SECRETS_TIMEOUT, + g_task_get_cancellable (task), + create_item_cb, + task); +} + +static void +prompt_completed_cb (GDBusConnection *connection, + const gchar *sender_name, + const gchar *object_path, + const gchar *interface_name, + const gchar *signal_name, + GVariant *parameters, + gpointer user_data) +{ + GTask *task; + SecretsServiceData *task_data; + GVariant *dismissed; + gboolean is_dismissed = TRUE; + + task = user_data; + task_data = g_task_get_task_data (task); + + g_dbus_connection_signal_unsubscribe (task_data->dbus_connection, + task_data->prompt_subscription); + task_data->prompt_subscription = 0; + + dismissed = g_variant_get_child_value (parameters, 0); + + if (dismissed == NULL) + { + GTK_NOTE (PRINTING, g_print ("Invalid prompt signal.\n")); + g_task_return_pointer (task, NULL, NULL); + return; + } + + g_variant_get (dismissed, "b", &is_dismissed); + g_variant_unref (dismissed); + + if (is_dismissed) + { + GTK_NOTE (PRINTING, g_print ("Collection unlock dismissed.\n")); + g_task_return_pointer (task, NULL, NULL); + return; + } + + /* Prompt successfull, proceed to get or store secret */ + switch (task_data->action) + { + case SECRETS_SERVICE_ACTION_STORE: + do_store_auth_info (task); + break; + + case SECRETS_SERVICE_ACTION_QUERY: + g_dbus_proxy_call (task_data->item_proxy, + "GetSecret", + g_variant_new ("(o)", + task_data->session_path), + G_DBUS_CALL_FLAGS_NONE, + SECRETS_TIMEOUT, + g_task_get_cancellable (task), + get_secret_cb, + task); + break; + } +} + +static void +prompt_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GTask *task; + SecretsServiceData *task_data; + GError *error = NULL; + GVariant *output; + + task = user_data; + task_data = g_task_get_task_data (task); + + output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), + res, + &error); + if (output == NULL) + { + g_task_return_error (task, error); + return; + } + + g_variant_unref (output); + + /* Connect to the prompt's completed signal */ + task_data->prompt_subscription = + g_dbus_connection_signal_subscribe (task_data->dbus_connection, + NULL, + SECRETS_IFACE ("Prompt"), + "Completed", + NULL, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + prompt_completed_cb, + task, + NULL); +} + +static void +unlock_collection_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GTask *task; + SecretsServiceData *task_data; + GError *error = NULL; + GVariant *output; + const gchar *prompt_path; + + task = user_data; + task_data = g_task_get_task_data (task); + + output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), + res, + &error); + if (output == NULL) + { + g_task_return_error (task, error); + return; + } + + g_variant_get (output, "(@ao&o)", NULL, &prompt_path); + + if (prompt_path != NULL && strlen (prompt_path) > 1) + { + g_dbus_connection_call (task_data->dbus_connection, + SECRETS_BUS, + prompt_path, + SECRETS_IFACE ("Prompt"), + "Prompt", + g_variant_new ("(s)", "0"), + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + SECRETS_TIMEOUT, + g_task_get_cancellable (task), + prompt_cb, + task); + } + else + { + switch (task_data->action) + { + case SECRETS_SERVICE_ACTION_STORE: + do_store_auth_info (task); + break; + + case SECRETS_SERVICE_ACTION_QUERY: + /* Prompt successfull proceed to get secret */ + g_dbus_proxy_call (task_data->item_proxy, + "GetSecret", + g_variant_new ("(o)", + task_data->session_path), + G_DBUS_CALL_FLAGS_NONE, + SECRETS_TIMEOUT, + g_task_get_cancellable (task), + get_secret_cb, + task); + break; + } + } + g_variant_unref (output); +} + +static void +unlock_read_alias_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GTask *task; + SecretsServiceData *task_data; + GError *error = NULL; + GVariant *output, + *subresult; + gsize path_len = 0; + const gchar *collection_path; + + task = user_data; + task_data = g_task_get_task_data (task); + + output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), + res, + &error); + if (output == NULL) + { + g_task_return_error (task, error); + return; + } + + subresult = g_variant_get_child_value (output, 0); + g_variant_unref (output); + + if (subresult == NULL) + { + GTK_NOTE (PRINTING, g_print ("Invalid ReadAlias response.\n")); + g_task_return_pointer (task, NULL, NULL); + return; + } + + collection_path = g_variant_get_string (subresult, &path_len); + + const gchar * const to_unlock[] = + { + collection_path, NULL + }; + + task_data->collection_path = g_strdup (collection_path); + + g_dbus_connection_call (task_data->dbus_connection, + SECRETS_BUS, + SECRETS_PATH, + SECRETS_IFACE ("Service"), + "Unlock", + g_variant_new ("(^ao)", to_unlock), + G_VARIANT_TYPE ("(aoo)"), + G_DBUS_CALL_FLAGS_NONE, + SECRETS_TIMEOUT, + g_task_get_cancellable (task), + unlock_collection_cb, + task); + + g_variant_unref (subresult); +} + +static void +item_proxy_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GTask *task; + SecretsServiceData *task_data; + GError *error = NULL; + GDBusProxy *item_proxy; + GVariant *locked; + gboolean is_locked; + + task = user_data; + task_data = g_task_get_task_data (task); + + item_proxy = g_dbus_proxy_new_finish (res, + &error); + if (item_proxy == NULL) + { + g_task_return_error (task, error); + return; + } + + task_data->item_proxy = item_proxy; + + locked = g_dbus_proxy_get_cached_property (item_proxy, "Locked"); + + if (locked == NULL) + { + GTK_NOTE (PRINTING, g_print ("Failed to look up \"Locked\" property on item.\n")); + g_task_return_pointer (task, NULL, NULL); + return; + } + + g_variant_get (locked, "b", &is_locked); + g_variant_unref (locked); + + if (is_locked) + { + /* Go down the unlock -> lookup path */ + g_dbus_connection_call (task_data->dbus_connection, + SECRETS_BUS, + SECRETS_PATH, + SECRETS_IFACE ("Service"), + "ReadAlias", + g_variant_new ("(s)", "default"), + G_VARIANT_TYPE ("(o)"), + G_DBUS_CALL_FLAGS_NONE, + SECRETS_TIMEOUT, + g_task_get_cancellable (task), + unlock_read_alias_cb, + task); + return; + } + + /* Unlocked proceed to get or store secret */ + switch (task_data->action) + { + case SECRETS_SERVICE_ACTION_STORE: + do_store_auth_info (task); + break; + + case SECRETS_SERVICE_ACTION_QUERY: + g_dbus_proxy_call (item_proxy, + "GetSecret", + g_variant_new ("(o)", + task_data->session_path), + G_DBUS_CALL_FLAGS_NONE, + SECRETS_TIMEOUT, + g_task_get_cancellable (task), + get_secret_cb, + task); + break; + } +} + +static void +search_items_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GTask *task; + SecretsServiceData *task_data; + GError *error = NULL; + GVariant *output; + gsize array_cnt, + i; + gboolean found_item = FALSE; + + task = user_data; + task_data = g_task_get_task_data (task); + + output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), + res, + &error); + if (output == NULL) + { + g_task_return_error (task, error); + return; + } + + array_cnt = g_variant_n_children (output); + + for (i = 0; i < array_cnt; i++) + { + GVariant * const item_paths = g_variant_get_child_value (output, i); + const gchar **items = NULL; + + if (item_paths == NULL) + { + GTK_NOTE (PRINTING, + g_print ("SearchItems returned invalid result.\n")); + continue; + } + + items = g_variant_get_objv (item_paths, NULL); + + if (*items == NULL) + { + g_variant_unref (item_paths); + g_free ((gpointer) items); + continue; + } + + /* Access the first found item. */ + found_item = TRUE; + g_dbus_proxy_new (task_data->dbus_connection, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + SECRETS_BUS, + *items, + SECRETS_IFACE ("Item"), + g_task_get_cancellable (task), + item_proxy_cb, + task); + g_free ((gpointer) items); + g_variant_unref (item_paths); + break; + } + g_variant_unref (output); + + if (!found_item) + { + GTK_NOTE (PRINTING, g_print ("No match found in secrets service.\n")); + g_task_return_pointer (task, NULL, NULL); + return; + } +} + +static void +open_session_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GTask *task; + GVariant *output, + *session_variant; + SecretsServiceData *task_data; + GError *error = NULL; + + task = user_data; + task_data = g_task_get_task_data (task); + + output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), + res, + &error); + if (output == NULL) + { + g_task_return_error (task, error); + return; + } + + session_variant = g_variant_get_child_value (output, 1); + + if (session_variant == NULL) + { + GTK_NOTE (PRINTING, g_print ("Invalid session path response.\n")); + g_variant_unref (output); + g_task_return_pointer (task, NULL, NULL); + return; + } + + task_data->session_path = g_variant_dup_string (session_variant, NULL); + + if (task_data->session_path == NULL) + { + GTK_NOTE (PRINTING, g_print ("Invalid session path string value.\n")); + g_variant_unref (session_variant); + g_variant_unref (output); + g_task_return_pointer (task, NULL, NULL); + return; + } + + g_variant_unref (session_variant); + g_variant_unref (output); + + switch (task_data->action) + { + case SECRETS_SERVICE_ACTION_QUERY: + { + /* Search for the secret item */ + GVariant *secrets_attrs; + + secrets_attrs = create_attributes (task_data->printer_uri, NULL, NULL); + if (secrets_attrs == NULL) + { + GTK_NOTE (PRINTING, g_print ("Failed to create attributes.\n")); + g_task_return_pointer (task, NULL, NULL); + return; + } + + g_dbus_connection_call (task_data->dbus_connection, + SECRETS_BUS, + SECRETS_PATH, + SECRETS_IFACE ("Service"), + "SearchItems", + g_variant_new ("(@a{ss})", secrets_attrs), + G_VARIANT_TYPE ("(aoao)"), + G_DBUS_CALL_FLAGS_NONE, + SECRETS_TIMEOUT, + g_task_get_cancellable (task), + search_items_cb, + task); + break; + } + + case SECRETS_SERVICE_ACTION_STORE: + { + /* Look up / unlock the default collection for storing */ + g_dbus_connection_call (task_data->dbus_connection, + SECRETS_BUS, + SECRETS_PATH, + SECRETS_IFACE ("Service"), + "ReadAlias", + g_variant_new ("(s)", "default"), + G_VARIANT_TYPE ("(o)"), + G_DBUS_CALL_FLAGS_NONE, + SECRETS_TIMEOUT, + g_task_get_cancellable (task), + unlock_read_alias_cb, + task); + break; + } + } +} + +static void +get_connection_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GTask *task; + SecretsServiceData *task_data; + GError *error = NULL; + + task = user_data; + task_data = g_task_get_task_data (task); + + task_data->dbus_connection = g_bus_get_finish (res, &error); + if (task_data->dbus_connection == NULL) + { + g_task_return_error (task, error); + return; + } + + /* Now open a session */ + g_dbus_connection_call (task_data->dbus_connection, + SECRETS_BUS, + SECRETS_PATH, + SECRETS_IFACE ("Service"), + "OpenSession", + g_variant_new ("(sv)", "plain", + g_variant_new_string ("")), + G_VARIANT_TYPE ("(vo)"), + G_DBUS_CALL_FLAGS_NONE, + SECRETS_TIMEOUT, + g_task_get_cancellable (task), + open_session_cb, + task); +} + +/** + * gtk_cups_secrets_service_watch: + * @appeared: The callback to call when the service interface appears + * @vanished: The callback to call when the service interface vanishes + * @user_data: A reference to the watching printbackend + * + * Registers a watch for the secrets service interface. + * + * Returns: The watcher id + */ +guint +gtk_cups_secrets_service_watch (GBusNameAppearedCallback appeared, + GBusNameVanishedCallback vanished, + gpointer user_data) +{ + return g_bus_watch_name (G_BUS_TYPE_SESSION, + SECRETS_BUS, + G_BUS_NAME_WATCHER_FLAGS_AUTO_START, + appeared, + vanished, + user_data, + NULL); +} + +void +cleanup_task_data (gpointer data) +{ + gint i; + SecretsServiceData *task_data = data; + + g_free (task_data->collection_path); + g_strfreev (task_data->auth_info_labels); + g_strfreev (task_data->auth_info_required); + g_free (task_data->printer_uri); + + if (task_data->auth_info != NULL) + { + for (i = 0; task_data->auth_info[i] != NULL; i++) + { + memset (task_data->auth_info[i], 0, strlen (task_data->auth_info[i])); + g_clear_pointer (&task_data->auth_info[i], g_free); + } + g_clear_pointer (&task_data->auth_info, g_free); + } + + if (task_data->prompt_subscription != 0) + { + g_dbus_connection_signal_unsubscribe (task_data->dbus_connection, + task_data->prompt_subscription); + task_data->prompt_subscription = 0; + } + + if (task_data->session_path != NULL) + { + g_dbus_connection_call (task_data->dbus_connection, + SECRETS_BUS, + task_data->session_path, + SECRETS_IFACE ("Session"), + "Close", + NULL, + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + SECRETS_TIMEOUT, + NULL, + NULL, + NULL); + } + + g_clear_object (&task_data->dbus_connection); + g_clear_pointer (&task_data->session_path, g_free); + g_clear_object (&task_data->item_proxy); +} + +/** + * gtk_cups_secrets_service_query_task: + * @source_object: Source object for this task + * @cancellable: Cancellable to cancel this task + * @callback: Callback to call once the query is finished + * @user_data: The user_data passed to the callback + * @printer_uri: URI of the printer + * @auth_info_required: Info required for authentication + * + * Checks if a secrets service as described by the secrets-service standard + * is available and if so it tries to find the authentication info in the + * default collection of the service. + * + * This is the entry point to a chain of async calls to open a session, + * search the secret, unlock the collection (if necessary) and finally + * to lookup the secret. + * + * See: http://standards.freedesktop.org/secret-service/ for documentation + * of the used API. + */ +void +gtk_cups_secrets_service_query_task (gpointer source_object, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data, + const gchar *printer_uri, + gchar **auth_info_required) +{ + GTask *task; + SecretsServiceData *task_data; + + task_data = g_new0 (SecretsServiceData, 1); + task_data->action = SECRETS_SERVICE_ACTION_QUERY; + task_data->printer_uri = g_strdup (printer_uri); + task_data->auth_info_required = g_strdupv (auth_info_required); + + task = g_task_new (source_object, cancellable, callback, user_data); + + g_task_set_task_data (task, task_data, cleanup_task_data); + + g_bus_get (G_BUS_TYPE_SESSION, cancellable, + get_connection_cb, task); +} + +static void +store_done_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GTask *task = (GTask *) res; + GError *error = NULL; + + g_task_propagate_pointer (task, &error); + + if (error != NULL) + { + GTK_NOTE (PRINTING, + g_print ("Failed to store auth info: %s\n", error->message)); + g_error_free (error); + } + + g_object_unref (task); + GTK_NOTE (PRINTING, + g_print ("gtk_cups_secrets_service_store finished.\n")); +} + +/** + * gtk_cups_secrets_service_store: + * @auth_info: Auth info that should be stored + * @auth_info_labels: The keys to use for the auth info + * @printer_uri: URI of the printer + * + * Tries to store the auth_info in a secrets service. + */ +void +gtk_cups_secrets_service_store (gchar **auth_info, + gchar **auth_info_labels, + const gchar *printer_uri) +{ + GTask *task; + SecretsServiceData *task_data; + + if (auth_info == NULL || auth_info_labels == NULL || printer_uri == NULL) + { + GTK_NOTE (PRINTING, + g_print ("Invalid call to gtk_cups_secrets_service_store.\n")); + return; + } + + task_data = g_new0 (SecretsServiceData, 1); + task_data->action = SECRETS_SERVICE_ACTION_STORE; + task_data->printer_uri = g_strdup (printer_uri); + task_data->auth_info = g_strdupv (auth_info); + task_data->auth_info_labels = g_strdupv (auth_info_labels); + + task = g_task_new (NULL, NULL, store_done_cb, NULL); + + g_task_set_task_data (task, task_data, cleanup_task_data); + + g_bus_get (G_BUS_TYPE_SESSION, NULL, + get_connection_cb, task); +} diff --git a/modules/printbackends/cups/gtkcupssecretsutils.h b/modules/printbackends/cups/gtkcupssecretsutils.h new file mode 100644 index 000000000..1a0424a3b --- /dev/null +++ b/modules/printbackends/cups/gtkcupssecretsutils.h @@ -0,0 +1,41 @@ +/* gtkcupssecretsutils.h: Helper to use a secrets service for printer passwords + * Copyright (C) 2014 Intevation GmbH + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ +#ifndef __GTK_SECRETS_UTILS_H__ +#define __GTK_SECRETS_UTILS_H__ + +#include + +#include "gtkcupsutils.h" + +G_BEGIN_DECLS + +void gtk_cups_secrets_service_query_task (gpointer source_object, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data, + const gchar *printer_uri, + gchar **auth_info_required); +guint gtk_cups_secrets_service_watch (GBusNameAppearedCallback appeared, + GBusNameVanishedCallback vanished, + gpointer user_data); +void gtk_cups_secrets_service_store (gchar **auth_info, + gchar **auth_info_labels, + const gchar *printer_uri); + +G_END_DECLS + +#endif /* __GTK_SECRETS_UTILS_H__ */ From 0d089cd6deaf9f89522215c0454d67219075bd47 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 12:29:23 +0200 Subject: [PATCH 25/32] cups: build Secret Service authentication helper Wire the imported CUPS Secret Service helper into the CUPS print backend build. --- modules/printbackends/cups/Makefile.am | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/printbackends/cups/Makefile.am b/modules/printbackends/cups/Makefile.am index 5bc26cde6..369d8446c 100644 --- a/modules/printbackends/cups/Makefile.am +++ b/modules/printbackends/cups/Makefile.am @@ -27,12 +27,14 @@ backend_LTLIBRARIES = libprintbackend-cups.la libprintbackend_cups_la_SOURCES = \ gtkprintbackendcups.c \ gtkprintercups.c \ - gtkcupsutils.c + gtkcupsutils.c \ + gtkcupssecretsutils.c noinst_HEADERS = \ gtkprintbackendcups.h \ gtkprintercups.h \ - gtkcupsutils.h + gtkcupsutils.h \ + gtkcupssecretsutils.h libprintbackend_cups_la_LDFLAGS = -avoid-version -module $(no_undefined) libprintbackend_cups_la_LIBADD = $(LDADDS) $(CUPS_LIBS) From dab59b874bf35753e6e3c2f1176ea9fff3aeffa5 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 12:36:45 +0200 Subject: [PATCH 26/32] print: add optional remember-password UI state Prepare the print authentication dialog for backends that can store credentials without changing the request-password signal or gtk_print_backend_set_password() ABI. This keeps the openSUSE CUPS Secret Service feature ABI-conservative for gtk2-ng. --- gtk/gtkprintbackend.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/gtk/gtkprintbackend.c b/gtk/gtkprintbackend.c index 66f5b41a9..669e1c1e2 100644 --- a/gtk/gtkprintbackend.c +++ b/gtk/gtkprintbackend.c @@ -349,6 +349,9 @@ gtk_print_backend_load_modules (void) G_DEFINE_TYPE_WITH_PRIVATE (GtkPrintBackend, gtk_print_backend, G_TYPE_OBJECT) +#define GTK_PRINT_BACKEND_CAN_STORE_AUTH_INFO_KEY "gtk-print-backend-can-store-auth-info" +#define GTK_PRINT_BACKEND_STORE_AUTH_INFO_KEY "gtk-print-backend-store-auth-info" + static void fallback_printer_request_details (GtkPrinter *printer); static gboolean fallback_printer_mark_conflicts (GtkPrinter *printer, GtkPrinterOptionSet *options); @@ -690,6 +693,17 @@ store_entry (GtkEntry *entry, *data = g_strdup (gtk_entry_get_text (entry)); } +static void +store_auth_info_toggled (GtkToggleButton *button, + gpointer user_data) +{ + GtkPrintBackend *backend = GTK_PRINT_BACKEND (user_data); + + g_object_set_data (G_OBJECT (backend), + GTK_PRINT_BACKEND_STORE_AUTH_INFO_KEY, + GINT_TO_POINTER (gtk_toggle_button_get_active (button))); +} + static void password_dialog_response (GtkWidget *dialog, gint response_id, @@ -729,7 +743,7 @@ request_password (GtkPrintBackend *backend, const gchar *prompt) { GtkPrintBackendPrivate *priv = backend->priv; - GtkWidget *dialog, *box, *main_box, *label, *icon, *vbox, *entry; + GtkWidget *dialog, *box, *main_box, *label, *icon, *vbox, *entry, *chkbtn; GtkWidget *focus = NULL; gchar *markup; gint length; @@ -743,6 +757,10 @@ request_password (GtkPrintBackend *backend, length = g_strv_length (ai_required); priv->auth_info = g_new0 (gchar *, length + 1); + g_object_set_data (G_OBJECT (backend), + GTK_PRINT_BACKEND_STORE_AUTH_INFO_KEY, + GINT_TO_POINTER (FALSE)); + dialog = gtk_dialog_new_with_buttons ( _("Authentication"), NULL, GTK_DIALOG_MODAL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, @@ -810,6 +828,17 @@ request_password (GtkPrintBackend *backend, } } + if (g_object_get_data (G_OBJECT (backend), + GTK_PRINT_BACKEND_CAN_STORE_AUTH_INFO_KEY)) + { + chkbtn = gtk_check_button_new_with_mnemonic (_("_Remember password")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (chkbtn), FALSE); + gtk_box_pack_start (GTK_BOX (vbox), chkbtn, FALSE, FALSE, 6); + g_signal_connect (chkbtn, "toggled", + G_CALLBACK (store_auth_info_toggled), + backend); + } + if (focus != NULL) { gtk_widget_grab_focus (focus); From 0c87680876a415195a8ec74dd347294527854a20 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 12:56:13 +0200 Subject: [PATCH 27/32] cups: wire Secret Service storage into authentication flow Use the imported Secret Service helper to optionally store CUPS authentication data when a secrets service is available and the user enables password remembering. Keep the GtkPrintBackend request-password signal and gtk_print_backend_set_password() ABI unchanged by passing the transient UI state through private object data. --- .../printbackends/cups/gtkprintbackendcups.c | 74 ++++++++++++++++++- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/modules/printbackends/cups/gtkprintbackendcups.c b/modules/printbackends/cups/gtkprintbackendcups.c index e17d97d21..21ab80836 100644 --- a/modules/printbackends/cups/gtkprintbackendcups.c +++ b/modules/printbackends/cups/gtkprintbackendcups.c @@ -60,6 +60,11 @@ #include "gtkprintercups.h" #include "gtkcupsutils.h" +#include "gtkcupssecretsutils.h" + +#define GTK_PRINT_BACKEND_CAN_STORE_AUTH_INFO_KEY "gtk-print-backend-can-store-auth-info" +#define GTK_PRINT_BACKEND_STORE_AUTH_INFO_KEY "gtk-print-backend-store-auth-info" +#define GTK_PRINT_BACKEND_AUTH_PRINTER_URI_KEY "gtk-print-backend-auth-printer-uri" typedef struct _GtkPrintBackendCupsClass GtkPrintBackendCupsClass; @@ -144,6 +149,9 @@ struct _GtkPrintBackendCups GHashTable *auth; gchar *username; gboolean authentication_lock; + + gboolean secrets_service_available; + guint secrets_service_watch_id; #ifdef HAVE_CUPS_API_1_6 GDBusConnection *dbus_connection; gchar *avahi_default_printer; @@ -213,6 +221,14 @@ static cairo_surface_t * cups_printer_create_cairo_surface (GtkPrinter static void gtk_print_backend_cups_set_password (GtkPrintBackend *backend, gchar **auth_info_required, gchar **auth_info); +static void secrets_service_appeared (GDBusConnection *connection, + const gchar *name, + const gchar *name_owner, + gpointer user_data); +static void secrets_service_vanished (GDBusConnection *connection, + const gchar *name, + gpointer user_data); + void overwrite_and_free (gpointer data); static gboolean is_address_local (const gchar *address); @@ -751,6 +767,27 @@ void overwrite_and_free (gpointer data) } } +static void +secrets_service_appeared (GDBusConnection *connection, + const gchar *name, + const gchar *name_owner, + gpointer user_data) +{ + GtkPrintBackendCups *cups_backend = GTK_PRINT_BACKEND_CUPS (user_data); + + cups_backend->secrets_service_available = TRUE; +} + +static void +secrets_service_vanished (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + GtkPrintBackendCups *cups_backend = GTK_PRINT_BACKEND_CUPS (user_data); + + cups_backend->secrets_service_available = FALSE; +} + static void gtk_print_backend_cups_init (GtkPrintBackendCups *backend_cups) { @@ -767,6 +804,11 @@ gtk_print_backend_cups_init (GtkPrintBackendCups *backend_cups) backend_cups->requests = NULL; backend_cups->auth = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, overwrite_and_free); backend_cups->authentication_lock = FALSE; + backend_cups->secrets_service_available = FALSE; + backend_cups->secrets_service_watch_id = + gtk_cups_secrets_service_watch (secrets_service_appeared, + secrets_service_vanished, + backend_cups); backend_cups->covers = NULL; backend_cups->number_of_covers = 0; @@ -836,6 +878,12 @@ gtk_print_backend_cups_dispose (GObject *object) backend_cups = GTK_PRINT_BACKEND_CUPS (object); + if (backend_cups->secrets_service_watch_id != 0) + { + g_bus_unwatch_name (backend_cups->secrets_service_watch_id); + backend_cups->secrets_service_watch_id = 0; + } + if (backend_cups->list_printers_poll > 0) g_source_remove (backend_cups->list_printers_poll); backend_cups->list_printers_poll = 0; @@ -940,7 +988,7 @@ gtk_print_backend_cups_set_password (GtkPrintBackend *backend, GtkPrintBackendCups *cups_backend = GTK_PRINT_BACKEND_CUPS (backend); GList *l; char dispatch_hostname[HTTP_MAX_URI]; - gchar *key; + gchar *key = NULL; gchar *username = NULL; gchar *hostname = NULL; gchar *password = NULL; @@ -962,15 +1010,27 @@ gtk_print_backend_cups_set_password (GtkPrintBackend *backend, if (hostname != NULL && username != NULL && password != NULL) { + const gchar *printer_uri; + gboolean store_auth_info; + key = g_strconcat (username, "@", hostname, NULL); g_hash_table_insert (cups_backend->auth, key, g_strdup (password)); + + printer_uri = g_object_get_data (G_OBJECT (backend), + GTK_PRINT_BACKEND_AUTH_PRINTER_URI_KEY); + store_auth_info = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (backend), + GTK_PRINT_BACKEND_STORE_AUTH_INFO_KEY)); + + if (store_auth_info && cups_backend->secrets_service_available && printer_uri != NULL) + gtk_cups_secrets_service_store (auth_info, auth_info_required, printer_uri); } g_free (cups_backend->username); cups_backend->username = g_strdup (username); - GTK_NOTE (PRINTING, - g_print ("CUPS backend: storing password for %s\n", key)); + if (key != NULL) + GTK_NOTE (PRINTING, + g_print ("CUPS backend: storing password for %s\n", key)); for (l = cups_backend->requests; l; l = l->next) { @@ -1114,6 +1174,14 @@ request_password (gpointer data) g_free (printer_name); + g_object_set_data (G_OBJECT (dispatch->backend), + GTK_PRINT_BACKEND_CAN_STORE_AUTH_INFO_KEY, + GINT_TO_POINTER (dispatch->backend->secrets_service_available)); + g_object_set_data_full (G_OBJECT (dispatch->backend), + GTK_PRINT_BACKEND_AUTH_PRINTER_URI_KEY, + g_strdup (printer_uri), + g_free); + g_signal_emit_by_name (dispatch->backend, "request-password", auth_info_required, auth_info_default, auth_info_display, auth_info_visible, prompt); From 3501d8c4f558e1387faf2c2151d1d4db937d2623 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Wed, 13 May 2026 13:20:06 +0200 Subject: [PATCH 28/32] fontsel: defer expensive selection updates Based on the openSUSE gtk2-bnc130159-bgo319483-async-selection-in-gtk-font-selection.diff. Coalesce font family, style and size selection updates with short timeouts to keep GtkFontSelection responsive while preserving immediate updates for internal programmatic selection changes. --- gtk/gtkfontsel.c | 166 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 150 insertions(+), 16 deletions(-) diff --git a/gtk/gtkfontsel.c b/gtk/gtkfontsel.c index 7dc9a6ee8..76927c797 100644 --- a/gtk/gtkfontsel.c +++ b/gtk/gtkfontsel.c @@ -585,6 +585,79 @@ gtk_font_selection_new (void) return GTK_WIDGET (fontsel); } +static GQuark +font_selection_font_timeout_quark (void) +{ + return g_quark_from_static_string ("gtk-font-selection-font-timeout"); +} + +static GQuark +font_selection_style_timeout_quark (void) +{ + return g_quark_from_static_string ("gtk-font-selection-style-timeout"); +} + +static GQuark +font_selection_size_timeout_quark (void) +{ + return g_quark_from_static_string ("gtk-font-selection-size-timeout"); +} + +static GQuark +font_selection_immediate_quark (void) +{ + return g_quark_from_static_string ("gtk-font-selection-immediate"); +} + +static void +gtk_font_selection_remove_timeout (GtkFontSelection *fontsel, + GQuark quark) +{ + guint timeout_id; + + timeout_id = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (fontsel), quark)); + if (timeout_id) + { + g_source_remove (timeout_id); + g_object_set_qdata (G_OBJECT (fontsel), quark, NULL); + } +} + +static gboolean +gtk_font_selection_get_immediate (GtkFontSelection *fontsel) +{ + return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (fontsel), + font_selection_immediate_quark ())) != 0; +} + +static void +gtk_font_selection_set_immediate (GtkFontSelection *fontsel, + gboolean immediate) +{ + g_object_set_qdata (G_OBJECT (fontsel), + font_selection_immediate_quark (), + GUINT_TO_POINTER (immediate ? 1 : 0)); +} + +static void +gtk_font_selection_schedule_selection (GtkFontSelection *fontsel, + GQuark quark, + GSourceFunc func) +{ + guint timeout_id; + + gtk_font_selection_remove_timeout (fontsel, quark); + + if (gtk_font_selection_get_immediate (fontsel)) + { + func (fontsel); + return; + } + + timeout_id = g_timeout_add (200, func, fontsel); + g_object_set_qdata (G_OBJECT (fontsel), quark, GUINT_TO_POINTER (timeout_id)); +} + static void gtk_font_selection_finalize (GObject *object) { @@ -594,6 +667,10 @@ gtk_font_selection_finalize (GObject *object) fontsel = GTK_FONT_SELECTION (object); + gtk_font_selection_remove_timeout (fontsel, font_selection_font_timeout_quark ()); + gtk_font_selection_remove_timeout (fontsel, font_selection_style_timeout_quark ()); + gtk_font_selection_remove_timeout (fontsel, font_selection_size_timeout_quark ()); + if (fontsel->font) gdk_font_unref (fontsel->font); @@ -632,6 +709,8 @@ gtk_font_selection_reload_fonts (GtkFontSelection *fontsel) PangoFontDescription *desc; desc = gtk_font_selection_get_font_description (fontsel); + gtk_font_selection_set_immediate (fontsel, TRUE); + gtk_font_selection_show_available_fonts (fontsel); gtk_font_selection_show_available_sizes (fontsel, TRUE); gtk_font_selection_show_available_styles (fontsel); @@ -639,6 +718,8 @@ gtk_font_selection_reload_fonts (GtkFontSelection *fontsel) gtk_font_selection_select_font_desc (fontsel, desc, NULL, NULL); gtk_font_selection_scroll_to_selection (fontsel); + gtk_font_selection_set_immediate (fontsel, FALSE); + pango_font_description_free (desc); } } @@ -715,11 +796,11 @@ gtk_font_selection_scroll_on_map (GtkWidget *widget, } /* This is called when a family is selected in the list. */ -static void -gtk_font_selection_select_font (GtkTreeSelection *selection, - gpointer data) +static gboolean +gtk_font_selection_real_select_font (gpointer data) { GtkFontSelection *fontsel; + GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeIter iter; #ifdef INCLUDE_FONT_ENTRIES @@ -727,6 +808,7 @@ gtk_font_selection_select_font (GtkTreeSelection *selection, #endif fontsel = GTK_FONT_SELECTION (data); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (fontsel->family_list)); if (gtk_tree_selection_get_selected (selection, &model, &iter)) { @@ -734,20 +816,35 @@ gtk_font_selection_select_font (GtkTreeSelection *selection, gtk_tree_model_get (model, &iter, FAMILY_COLUMN, &family, -1); if (fontsel->family != family) - { - gtk_font_selection_ref_family (fontsel, family); + { + gtk_font_selection_ref_family (fontsel, family); #ifdef INCLUDE_FONT_ENTRIES - family_name = pango_font_family_get_name (fontsel->family); - gtk_entry_set_text (GTK_ENTRY (fontsel->font_entry), family_name); + family_name = pango_font_family_get_name (fontsel->family); + gtk_entry_set_text (GTK_ENTRY (fontsel->font_entry), family_name); #endif - gtk_font_selection_show_available_styles (fontsel); - gtk_font_selection_select_best_style (fontsel, TRUE); - } + gtk_font_selection_show_available_styles (fontsel); + gtk_font_selection_select_best_style (fontsel, TRUE); + } g_object_unref (family); } + + g_object_set_qdata (G_OBJECT (fontsel), font_selection_font_timeout_quark (), NULL); + + return FALSE; +} + +static void +gtk_font_selection_select_font (GtkTreeSelection *selection, + gpointer data) +{ + GtkFontSelection *fontsel = GTK_FONT_SELECTION (data); + + gtk_font_selection_schedule_selection (fontsel, + font_selection_font_timeout_quark (), + gtk_font_selection_real_select_font); } static int @@ -950,14 +1047,16 @@ gtk_font_selection_select_best_style (GtkFontSelection *fontsel, /* This is called when a style is selected in the list. */ -static void -gtk_font_selection_select_style (GtkTreeSelection *selection, - gpointer data) +static gboolean +gtk_font_selection_real_select_style (gpointer data) { GtkFontSelection *fontsel = GTK_FONT_SELECTION (data); + GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeIter iter; + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (fontsel->face_list)); + if (gtk_tree_selection_get_selected (selection, &model, &iter)) { PangoFontFace *face; @@ -969,6 +1068,21 @@ gtk_font_selection_select_style (GtkTreeSelection *selection, gtk_font_selection_show_available_sizes (fontsel, FALSE); gtk_font_selection_select_best_size (fontsel); + + g_object_set_qdata (G_OBJECT (fontsel), font_selection_style_timeout_quark (), NULL); + + return FALSE; +} + +static void +gtk_font_selection_select_style (GtkTreeSelection *selection, + gpointer data) +{ + GtkFontSelection *fontsel = GTK_FONT_SELECTION (data); + + gtk_font_selection_schedule_selection (fontsel, + font_selection_style_timeout_quark (), + gtk_font_selection_real_select_style); } static void @@ -1101,22 +1215,38 @@ gtk_font_selection_size_focus_out (GtkWidget *w, } /* This is called when a size is selected in the list. */ -static void -gtk_font_selection_select_size (GtkTreeSelection *selection, - gpointer data) +static gboolean +gtk_font_selection_real_select_size (gpointer data) { GtkFontSelection *fontsel; + GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeIter iter; gint new_size; fontsel = GTK_FONT_SELECTION (data); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (fontsel->size_list)); if (gtk_tree_selection_get_selected (selection, &model, &iter)) { gtk_tree_model_get (model, &iter, SIZE_COLUMN, &new_size, -1); gtk_font_selection_set_size (fontsel, new_size * PANGO_SCALE); } + + g_object_set_qdata (G_OBJECT (fontsel), font_selection_size_timeout_quark (), NULL); + + return FALSE; +} + +static void +gtk_font_selection_select_size (GtkTreeSelection *selection, + gpointer data) +{ + GtkFontSelection *fontsel = GTK_FONT_SELECTION (data); + + gtk_font_selection_schedule_selection (fontsel, + font_selection_size_timeout_quark (), + gtk_font_selection_real_select_size); } static void @@ -1450,6 +1580,8 @@ gtk_font_selection_select_font_desc (GtkFontSelection *fontsel, if (!new_family) return FALSE; + gtk_font_selection_set_immediate (fontsel, TRUE); + if (pfamily) *pfamily = new_family; else @@ -1500,6 +1632,8 @@ gtk_font_selection_select_font_desc (GtkFontSelection *fontsel, gtk_font_selection_set_size (fontsel, pango_font_description_get_size (new_desc)); + gtk_font_selection_set_immediate (fontsel, FALSE); + return TRUE; } From dda8c3764a2c25983199d05d26c9c1dc5663e025 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Thu, 14 May 2026 14:34:46 +0200 Subject: [PATCH 29/32] fontsel: use insert_with_values when populating lists Use gtk_list_store_insert_with_values() for font family, style and size list population to avoid separate append/set updates while preserving the same inserted values and row selection behavior. --- gtk/gtkfontsel.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/gtk/gtkfontsel.c b/gtk/gtkfontsel.c index 76927c797..46aa6c01a 100644 --- a/gtk/gtkfontsel.c +++ b/gtk/gtkfontsel.c @@ -878,11 +878,10 @@ gtk_font_selection_show_available_fonts (GtkFontSelection *fontsel) const gchar *name = pango_font_family_get_name (families[i]); GtkTreeIter iter; - gtk_list_store_append (model, &iter); - gtk_list_store_set (model, &iter, - FAMILY_COLUMN, families[i], - FAMILY_NAME_COLUMN, name, - -1); + gtk_list_store_insert_with_values (model, &iter, -1, + FAMILY_COLUMN, families[i], + FAMILY_NAME_COLUMN, name, + -1); if (i == 0 || !g_ascii_strcasecmp (name, "sans")) { @@ -979,11 +978,10 @@ gtk_font_selection_show_available_styles (GtkFontSelection *fontsel) GtkTreeIter iter; const gchar *str = pango_font_face_get_face_name (faces[i]); - gtk_list_store_append (model, &iter); - gtk_list_store_set (model, &iter, - FACE_COLUMN, faces[i], - FACE_NAME_COLUMN, _(str), - -1); + gtk_list_store_insert_with_values (model, &iter, -1, + FACE_COLUMN, faces[i], + FACE_NAME_COLUMN, _(str), + -1); if (i == 0) { @@ -1105,8 +1103,9 @@ gtk_font_selection_show_available_sizes (GtkFontSelection *fontsel, { GtkTreeIter iter; - gtk_list_store_append (model, &iter); - gtk_list_store_set (model, &iter, SIZE_COLUMN, font_sizes[i], -1); + gtk_list_store_insert_with_values (model, &iter, -1, + SIZE_COLUMN, font_sizes[i], + -1); if (font_sizes[i] * PANGO_SCALE == fontsel->size) set_cursor_to_iter (GTK_TREE_VIEW (fontsel->size_list), &iter); From c062dcb54d73dc3600389532e40eb3c2eb778e08 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Thu, 14 May 2026 15:00:25 +0200 Subject: [PATCH 30/32] updateiconcache: sort directory entries before scanning Based on the openSUSE gtk2-updateiconcache_sort.patch. Sort directory entries while building the icon cache so cache output is deterministic, but keep the implementation portable by using GLib arrays instead of scandir()/alphasort(). Also free the scanned directory path before returning. --- gtk/updateiconcache.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/gtk/updateiconcache.c b/gtk/updateiconcache.c index 4a3158e12..b46d97c04 100644 --- a/gtk/updateiconcache.c +++ b/gtk/updateiconcache.c @@ -608,6 +608,16 @@ replace_backslashes_with_slashes (gchar *path) path[i] = '/'; } +static gint +compare_string_pointers (gconstpointer a, + gconstpointer b) +{ + const gchar * const *str_a = a; + const gchar * const *str_b = b; + + return strcmp (*str_a, *str_b); +} + static GList * scan_directory (const gchar *base_path, const gchar *subdir, @@ -617,10 +627,12 @@ scan_directory (const gchar *base_path, { GHashTable *dir_hash; GDir *dir; + GPtrArray *names; const gchar *name; gchar *dir_path; gboolean dir_added = FALSE; guint dir_index = 0xffff; + guint i; dir_path = g_build_path ("/", base_path, subdir, NULL); @@ -628,12 +640,25 @@ scan_directory (const gchar *base_path, dir = g_dir_open (dir_path, 0, NULL); if (!dir) - return directories; + { + g_free (dir_path); + return directories; + } + + names = g_ptr_array_new_with_free_func (g_free); + + while ((name = g_dir_read_name (dir))) + g_ptr_array_add (names, g_strdup (name)); + + g_dir_close (dir); + + g_ptr_array_sort (names, compare_string_pointers); dir_hash = g_hash_table_new (g_str_hash, g_str_equal); - while ((name = g_dir_read_name (dir))) + for (i = 0; i < names->len; i++) { + name = g_ptr_array_index (names, i); gchar *path; gboolean retval; int flags = 0; @@ -712,7 +737,8 @@ scan_directory (const gchar *base_path, g_free (path); } - g_dir_close (dir); + g_ptr_array_free (names, TRUE); + g_free (dir_path); /* Move dir into the big file hash */ g_hash_table_foreach_remove (dir_hash, foreach_remove_func, files); From de9f5196faf5d9c09350d636eae272c955091d3c Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Fri, 15 May 2026 08:41:24 +0200 Subject: [PATCH 31/32] configure: add rpath-link flags for custom library prefixes When building with a custom library prefix, GNU ld may find a directly linked shared library through -L but fail to locate that library's indirect DT_NEEDED dependencies from the same prefix. Derive -Wl,-rpath-link entries from existing LDFLAGS -L paths on Linux. This improves configure tests for musl, cross-toolchain and custom-prefix builds without changing the pkg-config dependency set. --- configure.ac | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 29297423f..47377e76e 100644 --- a/configure.ac +++ b/configure.ac @@ -718,6 +718,48 @@ fi saved_cflags="$CFLAGS" saved_ldflags="$LDFLAGS" +# Help GNU ld find indirect shared-library dependencies from custom +# library prefixes. This is useful for musl/cross/custom-prefix builds +# where a directly linked .so is found through -L, but its DT_NEEDED +# libraries from the same prefix are not in the default linker search path. +case "$host_os" in + linux*) + GTK_RPATH_LINK_FLAGS= + gtk_next_is_libdir=no + + for gtk_ldflag in $LDFLAGS; do + if test "x$gtk_next_is_libdir" = xyes; then + gtk_libdir="$gtk_ldflag" + gtk_next_is_libdir=no + else + case $gtk_ldflag in + -L) + gtk_next_is_libdir=yes + continue + ;; + -L*) + gtk_libdir=`echo "$gtk_ldflag" | sed 's/^-L//'` + ;; + *) + continue + ;; + esac + fi + + case " $GTK_RPATH_LINK_FLAGS " in + *" -Wl,-rpath-link,$gtk_libdir "*) + ;; + *) + GTK_RPATH_LINK_FLAGS="$GTK_RPATH_LINK_FLAGS -Wl,-rpath-link,$gtk_libdir" + ;; + esac + done + + LDFLAGS="$LDFLAGS $GTK_RPATH_LINK_FLAGS" + ;; +esac + + # Checks for header files. # Checks for typedefs, structures, and compiler characteristics. @@ -1392,7 +1434,7 @@ CFLAGS="$CFLAGS $PANGO_CFLAGS" if $PKG_CONFIG --uninstalled $PANGO_PACKAGES; then : else - gtk_save_LIBS="$LIBS" + gtk_save_LIBS="$LIBS" LIBS="$PANGO_LIBS $LIBS" AC_LINK_IFELSE( [AC_LANG_CALL([], [pango_context_new])], From 9423346201c9fc250eb5de4c628247aa32bd6c9c Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Fri, 15 May 2026 09:39:48 +0200 Subject: [PATCH 32/32] gtk: include local module path fallback --- gtk/gtkmodules.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/gtk/gtkmodules.c b/gtk/gtkmodules.c index da5568ffa..fa7a6a50b 100644 --- a/gtk/gtkmodules.c +++ b/gtk/gtkmodules.c @@ -131,6 +131,7 @@ get_module_path (void) gchar *home_gtk_dir = NULL; gchar *module_path; gchar *default_dir; + gchar *local_dir = NULL; static gchar **result = NULL; if (result) @@ -146,22 +147,47 @@ get_module_path (void) if (exe_prefix) default_dir = g_build_filename (exe_prefix, "lib", "gtk-2.0", NULL); else - default_dir = g_build_filename (GTK_LIBDIR, "gtk-2.0", NULL); + { + default_dir = g_build_filename (GTK_LIBDIR, "gtk-2.0", NULL); - if (module_path_env && home_gtk_dir) +#ifndef G_OS_WIN32 + if (g_str_has_prefix (GTK_LIBDIR, "/usr/lib")) + { + const gchar *lib_subdir = GTK_LIBDIR + strlen ("/usr/"); + + if (lib_subdir[0] != '\0') + local_dir = g_build_filename ("/usr/local", lib_subdir, "gtk-2.0", NULL); + } +#endif + } + + if (module_path_env && home_gtk_dir && local_dir) module_path = g_build_path (G_SEARCHPATH_SEPARATOR_S, - module_path_env, home_gtk_dir, default_dir, NULL); + module_path_env, home_gtk_dir, local_dir, default_dir, NULL); + else if (module_path_env && home_gtk_dir) + module_path = g_build_path (G_SEARCHPATH_SEPARATOR_S, + module_path_env, home_gtk_dir, default_dir, NULL); + else if (module_path_env && local_dir) + module_path = g_build_path (G_SEARCHPATH_SEPARATOR_S, + module_path_env, local_dir, default_dir, NULL); else if (module_path_env) module_path = g_build_path (G_SEARCHPATH_SEPARATOR_S, - module_path_env, default_dir, NULL); + module_path_env, default_dir, NULL); + else if (home_gtk_dir && local_dir) + module_path = g_build_path (G_SEARCHPATH_SEPARATOR_S, + home_gtk_dir, local_dir, default_dir, NULL); else if (home_gtk_dir) module_path = g_build_path (G_SEARCHPATH_SEPARATOR_S, - home_gtk_dir, default_dir, NULL); + home_gtk_dir, default_dir, NULL); + else if (local_dir) + module_path = g_build_path (G_SEARCHPATH_SEPARATOR_S, + local_dir, default_dir, NULL); else module_path = g_build_path (G_SEARCHPATH_SEPARATOR_S, - default_dir, NULL); + default_dir, NULL); g_free (home_gtk_dir); + g_free (local_dir); g_free (default_dir); result = split_file_list (module_path);