diff options
author | Ivan Molodetskikh <yalterz@gmail.com> | 2021-10-14 19:32:16 +0300 |
---|---|---|
committer | Ivan Molodetskikh <yalterz@gmail.com> | 2022-02-12 16:57:44 +0300 |
commit | 2828692c512f8a81ff5e9c2f1f78450781d2c028 (patch) | |
tree | fd8a43647bbef794a7a216a84a2f37c582dcb76d /plugins | |
parent | 6461a0f8556bafbf58c8a2ff8b3fe83b7d0df2b7 (diff) | |
download | gnome-settings-daemon-2828692c512f8a81ff5e9c2f1f78450781d2c028.tar.gz |
media-keys: Remove screenshot key handling
gnome-shell itself now handles the screenshot keys. This is required to
easily provide same-frame response to pressing a screenshot key.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/media-keys/gsd-media-keys-manager.c | 15 | ||||
-rw-r--r-- | plugins/media-keys/gsd-screenshot-utils.c | 286 | ||||
-rw-r--r-- | plugins/media-keys/gsd-screenshot-utils.h | 36 | ||||
-rw-r--r-- | plugins/media-keys/media-keys.h | 6 | ||||
-rw-r--r-- | plugins/media-keys/meson.build | 1 | ||||
-rw-r--r-- | plugins/media-keys/shortcuts-list.h | 6 |
6 files changed, 0 insertions, 350 deletions
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c index 3e2ec3fe..e03cc9f6 100644 --- a/plugins/media-keys/gsd-media-keys-manager.c +++ b/plugins/media-keys/gsd-media-keys-manager.c @@ -58,7 +58,6 @@ #include "shortcuts-list.h" #include "shell-key-grabber.h" -#include "gsd-screenshot-utils.h" #include "gsd-input-helper.h" #include "gsd-enums.h" #include "gsd-shell-helper.h" @@ -2481,14 +2480,6 @@ do_action (GsdMediaKeysManager *manager, case HELP_KEY: do_url_action (manager, "ghelp", timestamp); break; - case SCREENSHOT_KEY: - case SCREENSHOT_CLIP_KEY: - case WINDOW_SCREENSHOT_KEY: - case WINDOW_SCREENSHOT_CLIP_KEY: - case AREA_SCREENSHOT_KEY: - case AREA_SCREENSHOT_CLIP_KEY: - gsd_screenshot_take (type); - break; case SCREENCAST_KEY: do_screencast_action (manager); break; @@ -3095,12 +3086,6 @@ migrate_keybinding_settings (void) { "volume-mute", "volume-mute", map_keybinding }, { "volume-up", "volume-up", map_keybinding }, { "mic-mute", "mic-mute", map_keybinding }, - { "screenshot", "screenshot", map_keybinding }, - { "window-screenshot", "window-screenshot", map_keybinding }, - { "area-screenshot", "area-screenshot", map_keybinding }, - { "screenshot-clip", "screenshot-clip", map_keybinding }, - { "window-screenshot-clip", "window-screenshot-clip", map_keybinding }, - { "area-screenshot-clip", "area-screenshot-clip", map_keybinding }, { "screencast", "screencast", map_keybinding }, { "www", "www", map_keybinding }, { "magnifier", "magnifier", map_keybinding }, diff --git a/plugins/media-keys/gsd-screenshot-utils.c b/plugins/media-keys/gsd-screenshot-utils.c deleted file mode 100644 index bf792d9c..00000000 --- a/plugins/media-keys/gsd-screenshot-utils.c +++ /dev/null @@ -1,286 +0,0 @@ -/* gsd-screenshot-utils.c - utilities to take screenshots - * - * Copyright (C) 2012 Red Hat, Inc. - * - * Adapted from gnome-screenshot code, which is - * Copyright (C) 2001-2006 Jonathan Blandford <jrb@alum.mit.edu> - * Copyright (C) 2006 Emmanuele Bassi <ebassi@gnome.org> - * Copyright (C) 2008-2012 Cosimo Cecchi <cosimoc@gnome.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 2 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, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - */ - -#include <config.h> -#include <gtk/gtk.h> -#include <gio/gio.h> -#include <glib/gi18n.h> -#include <string.h> -#include <glib/gstdio.h> - -#include "gsd-screenshot-utils.h" - -#define SHELL_SCREENSHOT_BUS_NAME "org.gnome.Shell" -#define SHELL_SCREENSHOT_BUS_PATH "/org/gnome/Shell/Screenshot" -#define SHELL_SCREENSHOT_BUS_IFACE "org.gnome.Shell.Screenshot" - -typedef enum { - SCREENSHOT_TYPE_SCREEN, - SCREENSHOT_TYPE_WINDOW, - SCREENSHOT_TYPE_AREA -} ScreenshotType; - -typedef struct { - ScreenshotType type; - gboolean copy_to_clipboard; - - GdkRectangle area_selection; - gchar *save_filename; - gchar *used_filename; - - GDBusConnection *connection; -} ScreenshotContext; - -static void -screenshot_context_free (ScreenshotContext *ctx) -{ - g_free (ctx->save_filename); - g_free (ctx->used_filename); - g_clear_object (&ctx->connection); - g_slice_free (ScreenshotContext, ctx); -} - -static void -screenshot_save_to_recent (ScreenshotContext *ctx) -{ - GFile *file = g_file_new_for_path (ctx->used_filename); - gchar *uri = g_file_get_uri (file); - - gtk_recent_manager_add_item (gtk_recent_manager_get_default (), uri); - - g_free (uri); - g_object_unref (file); -} - -static void -bus_call_ready_cb (GObject *source, - GAsyncResult *res, - gpointer user_data) -{ - GError *error = NULL; - ScreenshotContext *ctx = user_data; - GVariant *variant; - gboolean success; - - variant = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), res, &error); - - if (error != NULL) - { - g_warning ("Failed to save a screenshot: %s\n", error->message); - g_error_free (error); - screenshot_context_free (ctx); - - return; - } - - g_variant_get (variant, "(bs)", &success, &ctx->used_filename); - - if (success) - { - if (!ctx->copy_to_clipboard) - { - screenshot_save_to_recent (ctx); - } - } - - screenshot_context_free (ctx); - g_variant_unref (variant); -} - -static void -screenshot_call_shell (ScreenshotContext *ctx) -{ - const gchar *method_name; - GVariant *method_params; - - if (ctx->type == SCREENSHOT_TYPE_SCREEN) - { - method_name = "Screenshot"; - method_params = g_variant_new ("(bbs)", - FALSE, /* include pointer */ - TRUE, /* flash */ - ctx->save_filename); - } - else if (ctx->type == SCREENSHOT_TYPE_WINDOW) - { - method_name = "ScreenshotWindow"; - method_params = g_variant_new ("(bbbs)", - TRUE, /* include border */ - FALSE, /* include pointer */ - TRUE, /* flash */ - ctx->save_filename); - } - else - { - method_name = "ScreenshotArea"; - method_params = g_variant_new ("(iiiibs)", - ctx->area_selection.x, ctx->area_selection.y, - ctx->area_selection.width, ctx->area_selection.height, - TRUE, /* flash */ - ctx->save_filename); - } - - g_dbus_connection_call (ctx->connection, - SHELL_SCREENSHOT_BUS_NAME, - SHELL_SCREENSHOT_BUS_PATH, - SHELL_SCREENSHOT_BUS_IFACE, - method_name, - method_params, - NULL, - G_DBUS_CALL_FLAGS_NO_AUTO_START, - -1, - NULL, - bus_call_ready_cb, - ctx); -} - -static void -area_selection_ready_cb (GObject *source, - GAsyncResult *res, - gpointer user_data) -{ - GdkRectangle rectangle; - ScreenshotContext *ctx = user_data; - GVariant *geometry; - - geometry = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), - res, NULL); - - /* cancelled by the user */ - if (!geometry) - { - screenshot_context_free (ctx); - return; - } - - g_variant_get (geometry, "(iiii)", - &rectangle.x, &rectangle.y, - &rectangle.width, &rectangle.height); - - ctx->area_selection = rectangle; - screenshot_call_shell (ctx); - g_variant_unref (geometry); -} - -static void -bus_connection_ready_cb (GObject *source, - GAsyncResult *res, - gpointer user_data) -{ - GError *error = NULL; - ScreenshotContext *ctx = user_data; - - ctx->connection = g_bus_get_finish (res, &error); - - if (error != NULL) - { - g_warning ("Failed to save a screenshot: %s\n", error->message); - g_error_free (error); - screenshot_context_free (ctx); - - return; - } - - if (ctx->type == SCREENSHOT_TYPE_AREA) - g_dbus_connection_call (ctx->connection, - SHELL_SCREENSHOT_BUS_NAME, - SHELL_SCREENSHOT_BUS_PATH, - SHELL_SCREENSHOT_BUS_IFACE, - "SelectArea", - NULL, - NULL, - G_DBUS_CALL_FLAGS_NO_AUTO_START, - -1, - NULL, - area_selection_ready_cb, - ctx); - else - screenshot_call_shell (ctx); -} - -static void -screenshot_take (ScreenshotContext *ctx) -{ - g_bus_get (G_BUS_TYPE_SESSION, NULL, bus_connection_ready_cb, ctx); -} - -static gchar * -screenshot_build_filename (void) -{ - char *file_name, *origin; - GDateTime *d; - - d = g_date_time_new_now_local (); - origin = g_date_time_format (d, "%Y-%m-%d %H-%M-%S"); - g_date_time_unref (d); - - /* translators: this is the name of the file that gets made up - * with the screenshot */ - file_name = g_strdup_printf (_("Screenshot from %s"), origin); - g_free (origin); - - return file_name; -} - -static void -screenshot_check_name_ready (ScreenshotContext *ctx) -{ - if (ctx->copy_to_clipboard) - ctx->save_filename = g_strdup (""); - else - ctx->save_filename = screenshot_build_filename (); - - screenshot_take (ctx); -} - -void -gsd_screenshot_take (MediaKeyType key_type) -{ - ScreenshotContext *ctx = g_slice_new0 (ScreenshotContext); - - ctx->copy_to_clipboard = (key_type == SCREENSHOT_CLIP_KEY || - key_type == WINDOW_SCREENSHOT_CLIP_KEY || - key_type == AREA_SCREENSHOT_CLIP_KEY); - - switch (key_type) - { - case SCREENSHOT_KEY: - case SCREENSHOT_CLIP_KEY: - ctx->type = SCREENSHOT_TYPE_SCREEN; - break; - case WINDOW_SCREENSHOT_KEY: - case WINDOW_SCREENSHOT_CLIP_KEY: - ctx->type = SCREENSHOT_TYPE_WINDOW; - break; - case AREA_SCREENSHOT_KEY: - case AREA_SCREENSHOT_CLIP_KEY: - ctx->type = SCREENSHOT_TYPE_AREA; - break; - default: - g_assert_not_reached (); - break; - } - - screenshot_check_name_ready (ctx); -} diff --git a/plugins/media-keys/gsd-screenshot-utils.h b/plugins/media-keys/gsd-screenshot-utils.h deleted file mode 100644 index 39ae136a..00000000 --- a/plugins/media-keys/gsd-screenshot-utils.h +++ /dev/null @@ -1,36 +0,0 @@ -/* gsd-screenshot-utils.h - utilities to take screenshots - * - * Copyright (C) 2012 Red Hat, Inc. - * - * Adapted from gnome-screenshot code, which is - * Copyright (C) 2001-2006 Jonathan Blandford <jrb@alum.mit.edu> - * Copyright (C) 2006 Emmanuele Bassi <ebassi@gnome.org> - * Copyright (C) 2008-2012 Cosimo Cecchi <cosimoc@gnome.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 2 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, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - */ - -#ifndef __GSD_SCREENSHOT_UTILS_H__ -#define __GSD_SCREENSHOT_UTILS_H__ - -#include "media-keys.h" - -G_BEGIN_DECLS - -void gsd_screenshot_take (MediaKeyType key_type); - -G_END_DECLS - -#endif /* __GSD_SCREENSHOT_UTILS_H__ */ diff --git a/plugins/media-keys/media-keys.h b/plugins/media-keys/media-keys.h index cc4ea8e7..f642d8fc 100644 --- a/plugins/media-keys/media-keys.h +++ b/plugins/media-keys/media-keys.h @@ -42,12 +42,6 @@ typedef enum { CONTROL_CENTER_KEY, SCREENSAVER_KEY, HELP_KEY, - SCREENSHOT_KEY, - WINDOW_SCREENSHOT_KEY, - AREA_SCREENSHOT_KEY, - SCREENSHOT_CLIP_KEY, - WINDOW_SCREENSHOT_CLIP_KEY, - AREA_SCREENSHOT_CLIP_KEY, SCREENCAST_KEY, WWW_KEY, PLAY_KEY, diff --git a/plugins/media-keys/meson.build b/plugins/media-keys/meson.build index cbda8eec..92d471a1 100644 --- a/plugins/media-keys/meson.build +++ b/plugins/media-keys/meson.build @@ -1,7 +1,6 @@ sources = files( 'bus-watch-namespace.c', 'gsd-media-keys-manager.c', - 'gsd-screenshot-utils.c', 'main.c', 'mpris-controller.c' ) diff --git a/plugins/media-keys/shortcuts-list.h b/plugins/media-keys/shortcuts-list.h index 8ced72df..9d994254 100644 --- a/plugins/media-keys/shortcuts-list.h +++ b/plugins/media-keys/shortcuts-list.h @@ -64,12 +64,6 @@ static struct { { CONTROL_CENTER_KEY, "control-center", TRUE, GSD_ACTION_MODE_LAUNCHER, META_KEY_BINDING_IGNORE_AUTOREPEAT }, { SCREENSAVER_KEY, "screensaver", TRUE, SCREENSAVER_MODE, META_KEY_BINDING_IGNORE_AUTOREPEAT }, { HELP_KEY, "help", FALSE, GSD_ACTION_MODE_LAUNCHER, META_KEY_BINDING_IGNORE_AUTOREPEAT }, - { SCREENSHOT_KEY, "screenshot", FALSE, NO_LOCK_MODE, META_KEY_BINDING_IGNORE_AUTOREPEAT }, - { WINDOW_SCREENSHOT_KEY, "window-screenshot", FALSE, NO_LOCK_MODE, META_KEY_BINDING_IGNORE_AUTOREPEAT }, - { AREA_SCREENSHOT_KEY, "area-screenshot", FALSE, NO_LOCK_MODE, META_KEY_BINDING_IGNORE_AUTOREPEAT }, - { SCREENSHOT_CLIP_KEY, "screenshot-clip", FALSE, SHELL_ACTION_MODE_ALL, META_KEY_BINDING_IGNORE_AUTOREPEAT }, - { WINDOW_SCREENSHOT_CLIP_KEY, "window-screenshot-clip", FALSE, SHELL_ACTION_MODE_NORMAL, META_KEY_BINDING_IGNORE_AUTOREPEAT }, - { AREA_SCREENSHOT_CLIP_KEY, "area-screenshot-clip", FALSE, SHELL_ACTION_MODE_ALL, META_KEY_BINDING_IGNORE_AUTOREPEAT }, { SCREENCAST_KEY, "screencast", FALSE, NO_LOCK_MODE, META_KEY_BINDING_IGNORE_AUTOREPEAT }, { WWW_KEY, "www", TRUE, GSD_ACTION_MODE_LAUNCHER, META_KEY_BINDING_IGNORE_AUTOREPEAT }, { PLAY_KEY, "play", TRUE, SHELL_ACTION_MODE_ALL, META_KEY_BINDING_IGNORE_AUTOREPEAT }, |