Commit 2828692c authored by Ivan Molodetskikh's avatar Ivan Molodetskikh
Browse files

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.
parent 6461a0f8
......@@ -96,36 +96,6 @@
<summary>Microphone mute/unmute</summary>
<description>Binding to mute/unmute the microphone.</description>
</key>
<key name="screenshot" type="s">
<default>'Print'</default>
<summary>Take a screenshot</summary>
<description>Binding to take a screenshot.</description>
</key>
<key name="window-screenshot" type="s">
<default>'&lt;Alt&gt;Print'</default>
<summary>Take a screenshot of a window</summary>
<description>Binding to take a screenshot of a window.</description>
</key>
<key name="area-screenshot" type="s">
<default>'&lt;Shift&gt;Print'</default>
<summary>Take a screenshot of an area</summary>
<description>Binding to take a screenshot of an area.</description>
</key>
<key name="screenshot-clip" type="s">
<default>'&lt;Ctrl&gt;Print'</default>
<summary>Copy a screenshot to clipboard</summary>
<description>Binding to copy a screenshot to clipboard.</description>
</key>
<key name="window-screenshot-clip" type="s">
<default>'&lt;Ctrl&gt;&lt;Alt&gt;Print'</default>
<summary>Copy a screenshot of a window to clipboard</summary>
<description>Binding to copy a screenshot of a window to clipboard.</description>
</key>
<key name="area-screenshot-clip" type="s">
<default>'&lt;Ctrl&gt;&lt;Shift&gt;Print'</default>
<summary>Copy a screenshot of an area to clipboard</summary>
<description>Binding to copy a screenshot of an area to clipboard.</description>
</key>
<key name="screencast" type="s">
<default>'&lt;Ctrl&gt;&lt;Shift&gt;&lt;Alt&gt;R'</default>
<summary>Record a short video of the screen</summary>
......@@ -317,36 +287,6 @@
<summary>Microphone mute/unmute</summary>
<description>Binding to mute/unmute the microphone.</description>
</key>
<key name="screenshot" type="as">
<default>['Print']</default>
<summary>Take a screenshot</summary>
<description>Binding to take a screenshot.</description>
</key>
<key name="window-screenshot" type="as">
<default>['&lt;Alt&gt;Print']</default>
<summary>Take a screenshot of a window</summary>
<description>Binding to take a screenshot of a window.</description>
</key>
<key name="area-screenshot" type="as">
<default>['&lt;Shift&gt;Print']</default>
<summary>Take a screenshot of an area</summary>
<description>Binding to take a screenshot of an area.</description>
</key>
<key name="screenshot-clip" type="as">
<default>['&lt;Ctrl&gt;Print']</default>
<summary>Copy a screenshot to clipboard</summary>
<description>Binding to copy a screenshot to clipboard.</description>
</key>
<key name="window-screenshot-clip" type="as">
<default>['&lt;Ctrl&gt;&lt;Alt&gt;Print']</default>
<summary>Copy a screenshot of a window to clipboard</summary>
<description>Binding to copy a screenshot of a window to clipboard.</description>
</key>
<key name="area-screenshot-clip" type="as">
<default>['&lt;Ctrl&gt;&lt;Shift&gt;Print']</default>
<summary>Copy a screenshot of an area to clipboard</summary>
<description>Binding to copy a screenshot of an area to clipboard.</description>
</key>
<key name="screencast" type="as">
<default>['&lt;Ctrl&gt;&lt;Shift&gt;&lt;Alt&gt;R']</default>
<summary>Record a short video of the screen</summary>
......
......@@ -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 },
......
/* 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);
}
/* 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__ */
......@@ -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,
......
sources = files(
'bus-watch-namespace.c',
'gsd-media-keys-manager.c',
'gsd-screenshot-utils.c',
'main.c',
'mpris-controller.c'
)
......
......@@ -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 },
......
Supports Markdown
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