Fix several fallback codepaths (RHEL-50819)

Resolves: RHEL-50819
This commit is contained in:
David King 2026-03-23 11:41:44 +00:00
parent f71863976b
commit 79b394ddd4
2 changed files with 154 additions and 1 deletions

View File

@ -0,0 +1,148 @@
From 09fc9f6fdfafe6ed5886e130f297877a1fa6ba16 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ball=C3=B3=20Gy=C3=B6rgy?= <ballogyor@gmail.com>
Date: Wed, 26 Jun 2024 18:56:57 +0200
Subject: [PATCH] Fix various fallback paths
- Fallback to full screen screenshot if trying to take a window screenshot
when there are no windows using the Shell backend.
- Don't attempt to fallback to X11 backend on Wayland.
- Don't hang the application when no usable method is available.
---
src/screenshot-area-selection.c | 20 +++++++++++++++++---
src/screenshot-backend-shell.c | 17 +++++++++++++++--
src/screenshot-utils.c | 10 ++++------
3 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/src/screenshot-area-selection.c b/src/screenshot-area-selection.c
index 224d93d..d6c8244 100644
--- a/src/screenshot-area-selection.c
+++ b/src/screenshot-area-selection.c
@@ -24,6 +24,9 @@
#include "screenshot-area-selection.h"
+#ifdef HAVE_X11
+#include <gdk/gdkx.h>
+
typedef struct {
GdkRectangle rect;
gboolean button_pressed;
@@ -200,6 +203,7 @@ create_select_window (void)
return window;
}
+#endif
typedef struct {
GdkRectangle rectangle;
@@ -223,6 +227,7 @@ emit_select_callback_in_idle (gpointer user_data)
return FALSE;
}
+#ifdef HAVE_X11
static void
screenshot_select_area_x11_async (CallbackData *cb_data)
{
@@ -272,6 +277,7 @@ screenshot_select_area_x11_async (CallbackData *cb_data)
*/
g_timeout_add (200, emit_select_callback_in_idle, cb_data);
}
+#endif
static void
select_area_done (GObject *source_object,
@@ -292,10 +298,18 @@ select_area_done (GObject *source_object,
return;
}
- g_message ("Unable to select area using GNOME Shell's builtin screenshot "
- "interface, resorting to fallback X11.");
+ g_warning ("Unable to use GNOME Shell's builtin screenshot interface: %s", error->message);
+#ifdef HAVE_X11
+ if (GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
+ {
+ g_message ("Resorting to fallback X11.");
+ screenshot_select_area_x11_async (cb_data);
+ return;
+ }
+#endif
- screenshot_select_area_x11_async (cb_data);
+ cb_data->aborted = TRUE;
+ g_idle_add (emit_select_callback_in_idle, cb_data);
return;
}
diff --git a/src/screenshot-backend-shell.c b/src/screenshot-backend-shell.c
index b651311..17c935a 100644
--- a/src/screenshot-backend-shell.c
+++ b/src/screenshot-backend-shell.c
@@ -99,15 +99,28 @@ screenshot_backend_shell_get_pixbuf (ScreenshotBackend *backend,
NULL,
&error);
- if (error == NULL && *filename)
+ if (error != NULL)
+ {
+ g_warning ("Unable to use GNOME Shell's builtin screenshot interface: %s", error->message);
+ return NULL;
+ }
+
+ if (*filename)
{
screenshot = gdk_pixbuf_new_from_file (filename, &error);
+ if (!screenshot && screenshot_config->take_window_shot)
+ {
+ screenshot_config->take_window_shot = FALSE;
+ return screenshot_backend_shell_get_pixbuf (backend, NULL);
+ }
+
/* remove the temporary file created by the shell */
g_unlink (filename);
+ return screenshot;
}
- return screenshot;
+ return NULL;
}
static void
diff --git a/src/screenshot-utils.c b/src/screenshot-utils.c
index 080696c..9fb064d 100644
--- a/src/screenshot-utils.c
+++ b/src/screenshot-utils.c
@@ -30,6 +30,7 @@
#include "screenshot-config.h"
#ifdef HAVE_X11
+#include <gdk/gdkx.h>
#include "screenshot-backend-x11.h"
#endif
@@ -51,19 +52,16 @@ screenshot_get_pixbuf (GdkRectangle *rectangle)
if (!screenshot && screenshot_config->copy_to_clipboard)
return NULL;
- if (!screenshot)
#ifdef HAVE_X11
- g_message ("Unable to use GNOME Shell's builtin screenshot interface, "
- "resorting to fallback X11.");
-#else
- g_message ("Unable to use GNOME Shell's builtin screenshot interface.");
+ if (!screenshot && GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
+ g_message ("Resorting to fallback X11.");
#endif
}
else
g_message ("Using fallback X11 as requested");
#ifdef HAVE_X11
- if (!screenshot)
+ if (!screenshot && GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
{
g_clear_object (&backend);
backend = screenshot_backend_x11_new ();
--
2.53.0

View File

@ -2,7 +2,7 @@
Name: gnome-screenshot
Version: 40.0
Release: 5%{?dist}
Release: 6%{?dist}
Summary: A screenshot utility for GNOME
License: GPLv2+
@ -12,6 +12,8 @@ Source0: https://download.gnome.org/sources/gnome-screenshot/40/gnome-scr
Patch0: gnome-screenshot-40.0-headless-fix.patch
Patch1: 0001-app-Specify-empty-filename-to-let-GNOME-Shell-store-.patch
# https://redhat.atlassian.net/browse/RHEL-50819
Patch2: gnome-screenshot-40.0-fix-fallbacks.patch
BuildRequires: gcc
BuildRequires: gettext
@ -61,6 +63,9 @@ desktop-file-validate %{buildroot}%{_datadir}/applications/org.gnome.Screenshot.
%changelog
* Mon Mar 23 2026 David King <dking@redhat.com> - 40.0-6
- Fix several fallback codepaths (RHEL-50819)
* Thu Apr 18 2024 Carlos Garnacho <cgarnach@redhat.com> - 40.0-5
- Fix pasting into clipboard through CLI (RHEL-25179)