Commit 3694da66 authored by Niels De Graef's avatar Niels De Graef 😁
Browse files

screenshot: Remove GNOME Shell implementation

GNOME Shell has started restricting access for it's Screenshot D-Bus API
to internal components only [1] for security reasons. In other words,
this will start failing, so remove it in favor of just using the
freedesktop portal, which should always work.

[1]: gnome-shell!1970
parent e9ef4b79
Pipeline #340696 passed with stages
in 34 minutes and 26 seconds
......@@ -48,8 +48,6 @@ screenshot_SOURCES = \
screenshot.h \
screenshot-freedesktop.c \
screenshot-freedesktop.h \
screenshot-gnome-shell.c \
screenshot-gnome-shell.h \
screenshot-icon.h \
screenshot-kwin.c \
screenshot-kwin.h \
......
......@@ -2,7 +2,6 @@ plugin_name = 'screenshot'
plugin_sources = [
'screenshot-freedesktop.c',
'screenshot-gnome-shell.c',
'screenshot-kwin.c',
'screenshot-osx.c',
'screenshot-win32.c',
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* Screenshot plug-in
* Copyright 1998-2007 Sven Neumann <sven@gimp.org>
* Copyright 2003 Henrik Brix Andersen <brix@gimp.org>
* Copyright 2016 Michael Natterer <mitch@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <glib.h>
#include <glib/gstdio.h> /* g_unlink() */
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "screenshot.h"
#include "screenshot-gnome-shell.h"
static GDBusProxy *proxy = NULL;
gboolean
screenshot_gnome_shell_available (void)
{
proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
NULL,
"org.gnome.Shell.Screenshot",
"/org/gnome/Shell/Screenshot",
"org.gnome.Shell.Screenshot",
NULL, NULL);
if (proxy)
{
GError *error = NULL;
g_dbus_proxy_call_sync (proxy, "org.freedesktop.DBus.Peer.Ping",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1, NULL, &error);
if (! error)
return TRUE;
g_clear_error (&error);
g_object_unref (proxy);
proxy = NULL;
}
return FALSE;
}
ScreenshotCapabilities
screenshot_gnome_shell_get_capabilities (void)
{
return (SCREENSHOT_CAN_SHOOT_DECORATIONS |
SCREENSHOT_CAN_SHOOT_POINTER |
SCREENSHOT_CAN_SHOOT_REGION |
SCREENSHOT_CAN_SHOOT_WINDOW);
}
GimpPDBStatusType
screenshot_gnome_shell_shoot (ScreenshotValues *shootvals,
GdkMonitor *monitor,
GimpImage **image,
GError **error)
{
GFile *file;
gchar *filename;
const gchar *method = NULL;
GVariant *args = NULL;
GVariant *retval;
gboolean success;
file = gimp_temp_file ("png");
filename = g_file_get_path (file);
switch (shootvals->shoot_type)
{
case SHOOT_ROOT:
if (shootvals->screenshot_delay > 0)
screenshot_delay (shootvals->screenshot_delay);
method = "Screenshot";
args = g_variant_new ("(bbs)",
shootvals->show_cursor,
TRUE, /* flash */
filename);
/* FIXME: figure profile */
break;
case SHOOT_REGION:
if (shootvals->select_delay > 0)
screenshot_delay (shootvals->select_delay);
retval = g_dbus_proxy_call_sync (proxy, "SelectArea", NULL,
G_DBUS_CALL_FLAGS_NONE,
-1, NULL, error);
if (! retval)
goto failure;
g_variant_get (retval, "(iiii)",
&shootvals->x1,
&shootvals->y1,
&shootvals->x2,
&shootvals->y2);
g_variant_unref (retval);
shootvals->x2 += shootvals->x1;
shootvals->y2 += shootvals->y1;
method = "ScreenshotArea";
args = g_variant_new ("(iiiibs)",
shootvals->x1,
shootvals->y1,
shootvals->x2 - shootvals->x1,
shootvals->y2 - shootvals->y1,
TRUE, /* flash */
filename);
monitor =
gdk_display_get_monitor_at_point (gdk_monitor_get_display (monitor),
(shootvals->x1 + shootvals->x2) / 2,
(shootvals->y1 + shootvals->y2) / 2);
if (shootvals->screenshot_delay > 0)
screenshot_delay (shootvals->screenshot_delay);
break;
case SHOOT_WINDOW:
if (shootvals->screenshot_delay > 0)
screenshot_delay (shootvals->screenshot_delay);
method = "ScreenshotWindow";
args = g_variant_new ("(bbbs)",
shootvals->decorate,
shootvals->show_cursor,
TRUE, /* flash */
filename);
/* FIXME: figure monitor */
break;
}
g_clear_pointer (&filename, g_free);
g_clear_object (&file);
retval = g_dbus_proxy_call_sync (proxy, method, args,
G_DBUS_CALL_FLAGS_NONE,
-1, NULL, error);
if (! retval)
goto failure;
g_variant_get (retval, "(bs)",
&success,
&filename);
g_variant_unref (retval);
if (success && filename)
{
GimpColorProfile *profile;
*image = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
g_file_new_for_path (filename));
gimp_image_set_file (*image, g_file_new_for_path ("screenshot.png"));
profile = gimp_monitor_get_color_profile (monitor);
if (profile)
{
gimp_image_set_color_profile (*image, profile);
g_object_unref (profile);
}
g_unlink (filename);
g_free (filename);
g_object_unref (proxy);
proxy = NULL;
return GIMP_PDB_SUCCESS;
}
failure:
g_free (filename);
g_object_unref (proxy);
proxy = NULL;
return GIMP_PDB_EXECUTION_ERROR;
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __SCREENSHOT_GNOME_SHELL_H__
#define __SCREENSHOT_GNOME_SHELL_H__
gboolean screenshot_gnome_shell_available (void);
ScreenshotCapabilities screenshot_gnome_shell_get_capabilities (void);
GimpPDBStatusType screenshot_gnome_shell_shoot (ScreenshotValues *shootvals,
GdkMonitor *monitor,
GimpImage **image,
GError **error);
#endif /* __SCREENSHOT_GNOME_SHELL_H__ */
......@@ -28,7 +28,6 @@
#include "screenshot.h"
#include "screenshot-freedesktop.h"
#include "screenshot-gnome-shell.h"
#include "screenshot-icon.h"
#include "screenshot-kwin.h"
#include "screenshot-osx.h"
......@@ -151,7 +150,7 @@ screenshot_create_procedure (GimpPlugIn *plug_in,
"passed as a parameter. The last four parameters "
"are optional and can be used to specify the corners "
"of the region to be grabbed."
"On Mac OS X or on gnome-shell, "
"On Mac OS X, "
"when called non-interactively, the plug-in"
"only can take screenshots of the entire root window."
"Grabbing a window or a region is not supported"
......@@ -256,12 +255,7 @@ screenshot_run (GimpProcedure *procedure,
}
#endif
if (! backend && screenshot_gnome_shell_available ())
{
backend = SCREENSHOT_BACKEND_GNOME_SHELL;
capabilities = screenshot_gnome_shell_get_capabilities ();
}
else if (! backend && screenshot_kwin_available ())
if (! backend && screenshot_kwin_available ())
{
backend = SCREENSHOT_BACKEND_KWIN;
capabilities = screenshot_kwin_get_capabilities ();
......@@ -432,8 +426,6 @@ shoot (GdkMonitor *monitor,
if (backend == SCREENSHOT_BACKEND_FREEDESKTOP)
return screenshot_freedesktop_shoot (&shootvals, monitor, image, error);
else if (backend == SCREENSHOT_BACKEND_GNOME_SHELL)
return screenshot_gnome_shell_shoot (&shootvals, monitor, image, error);
else if (backend == SCREENSHOT_BACKEND_KWIN)
return screenshot_kwin_shoot (&shootvals, monitor, image, error);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment