gala/SOURCES/e86a951.patch
2023-03-17 17:06:14 +01:00

180 lines
8.1 KiB
Diff

From e86a9518c24b742118b8624e34f84cb0ef76c7bd Mon Sep 17 00:00:00 2001
From: David Hewitt <davidmhewitt@users.noreply.github.com>
Date: Sat, 23 Apr 2022 22:26:40 +0000
Subject: [PATCH] Move screenshot shortcuts in-house (#1411)
---
daemon/MenuDaemon.vala | 6 ++--
data/gala.gschema.xml | 24 +++++++++++++
src/WindowManager.vala | 78 ++++++++++++++++++++++++++++++++++++++----
3 files changed, 99 insertions(+), 9 deletions(-)
diff --git a/daemon/MenuDaemon.vala b/daemon/MenuDaemon.vala
index 7918d4c72..32bc347a5 100644
--- a/daemon/MenuDaemon.vala
+++ b/daemon/MenuDaemon.vala
@@ -60,11 +60,11 @@ namespace Gala {
ulong on_visible_workspace_sid = 0U;
private static GLib.Settings keybind_settings;
- private static GLib.Settings media_keys_settings;
+ private static GLib.Settings gala_keybind_settings;
static construct {
keybind_settings = new GLib.Settings ("org.gnome.desktop.wm.keybindings");
- media_keys_settings = new GLib.Settings ("org.gnome.settings-daemon.plugins.media-keys");
+ gala_keybind_settings = new GLib.Settings ("org.pantheon.desktop.gala.keybindings");
}
[DBus (visible = false)]
@@ -269,7 +269,7 @@ namespace Gala {
move_left_accellabel.accel_string = keybind_settings.get_strv ("move-to-workspace-left")[0];
}
- screenshot_accellabel.accel_string = media_keys_settings.get_strv ("window-screenshot")[0];
+ screenshot_accellabel.accel_string = gala_keybind_settings.get_strv ("window-screenshot")[0];
close.visible = Gala.WindowFlags.CAN_CLOSE in flags;
if (close.visible) {
diff --git a/data/gala.gschema.xml b/data/gala.gschema.xml
index 684c1dd80..1d0b2b00e 100644
--- a/data/gala.gschema.xml
+++ b/data/gala.gschema.xml
@@ -159,6 +159,30 @@
<default><![CDATA[['<Super>space','<Alt>F2']]]></default>
<summary>Open the applications menu</summary>
</key>
+ <key name="screenshot" type="as">
+ <default><![CDATA[['Print']]]></default>
+ <summary>Take a screenshot</summary>
+ </key>
+ <key name="window-screenshot" type="as">
+ <default><![CDATA[['<Alt>Print']]]></default>
+ <summary>Take a screenshot of a window</summary>
+ </key>
+ <key name="area-screenshot" type="as">
+ <default><![CDATA[['<Shift>Print']]]></default>
+ <summary>Take a screenshot of an area</summary>
+ </key>
+ <key name="screenshot-clip" type="as">
+ <default><![CDATA[['<Control>Print']]]></default>
+ <summary>Copy a screenshot to clipboard</summary>
+ </key>
+ <key name="window-screenshot-clip" type="as">
+ <default><![CDATA[['<Control><Alt>Print']]]></default>
+ <summary>Copy a screenshot of a window to clipboard</summary>
+ </key>
+ <key name="area-screenshot-clip" type="as">
+ <default><![CDATA[['<Control><Shift>Print']]]></default>
+ <summary>Copy a screenshot of an area to clipboard</summary>
+ </key>
<key type="as" name="switch-input-source">
<default><![CDATA[['<Alt>space']]]></default>
<summary>Cycle to next keyboard layout</summary>
diff --git a/src/WindowManager.vala b/src/WindowManager.vala
index 2a38dc697..91dbaeab0 100644
--- a/src/WindowManager.vala
+++ b/src/WindowManager.vala
@@ -248,6 +248,15 @@ namespace Gala {
Meta.KeyBinding.set_custom_handler ("panel-main-menu", (Meta.KeyHandlerFunc) handle_applications_menu);
#endif
+#if HAS_MUTTER42
+ display.add_keybinding ("screenshot", keybinding_settings, 0, (Meta.KeyHandlerFunc) handle_screenshot);
+ display.add_keybinding ("window-screenshot", keybinding_settings, 0, (Meta.KeyHandlerFunc) handle_screenshot);
+ display.add_keybinding ("area-screenshot", keybinding_settings, 0, (Meta.KeyHandlerFunc) handle_screenshot);
+ display.add_keybinding ("screenshot-clip", keybinding_settings, 0, (Meta.KeyHandlerFunc) handle_screenshot);
+ display.add_keybinding ("window-screenshot-clip", keybinding_settings, 0, (Meta.KeyHandlerFunc) handle_screenshot);
+ display.add_keybinding ("area-screenshot-clip", keybinding_settings, 0, (Meta.KeyHandlerFunc) handle_screenshot);
+#endif
+
display.overlay_key.connect (() => {
launch_action ("overlay-action");
});
@@ -443,6 +452,31 @@ namespace Gala {
launch_action ("panel-main-menu-action");
}
+ [CCode (instance_pos = -1)]
+ void handle_screenshot (Meta.Display display, Meta.Window? window,
+ Clutter.KeyEvent event, Meta.KeyBinding binding) {
+ switch (binding.get_name ()) {
+ case "screenshot":
+ screenshot_screen.begin ();
+ break;
+ case "area-screenshot":
+ screenshot_area.begin ();
+ break;
+ case "window-screenshot":
+ screenshot_current_window.begin ();
+ break;
+ case "screenshot-clip":
+ screenshot_screen.begin (true);
+ break;
+ case "area-screenshot-clip":
+ screenshot_area.begin (true);
+ break;
+ case "window-screenshot-clip":
+ screenshot_current_window.begin (true);
+ break;
+ }
+ }
+
private void on_gesture_detected (Gesture gesture) {
if (workspace_view.is_opened ()) {
return;
@@ -2115,15 +2149,47 @@ namespace Gala {
return info;
}
- private async void screenshot_current_window () {
+ private string generate_screenshot_filename () {
+ var date_time = new GLib.DateTime.now_local ().format ("%Y-%m-%d %H.%M.%S");
+ /// TRANSLATORS: %s represents a timestamp here
+ return _("Screenshot from %s").printf (date_time);
+ }
+
+ private async void screenshot_current_window (bool clipboard = false) {
+ try {
+ string filename = clipboard ? "" : generate_screenshot_filename ();
+ bool success = false;
+ string filename_used = "";
+ unowned var screenshot_manager = ScreenshotManager.init (this);
+ yield screenshot_manager.screenshot_window (true, false, true, filename, out success, out filename_used);
+ } catch (Error e) {
+ // Ignore this error
+ }
+ }
+
+ private async void screenshot_area (bool clipboard = false) {
+ try {
+ string filename = clipboard ? "" : generate_screenshot_filename ();
+ bool success = false;
+ string filename_used = "";
+
+ unowned var screenshot_manager = ScreenshotManager.init (this);
+
+ int x, y, w, h;
+ yield screenshot_manager.select_area (out x, out y, out w, out h);
+ yield screenshot_manager.screenshot_area (x, y, w, h, true, filename, out success, out filename_used);
+ } catch (Error e) {
+ // Ignore this error
+ }
+ }
+
+ private async void screenshot_screen (bool clipboard = false) {
try {
- var date_time = new GLib.DateTime.now_local ().format ("%Y-%m-%d %H.%M.%S");
- /// TRANSLATORS: %s represents a timestamp here
- string file_name = _("Screenshot from %s").printf (date_time);
+ string filename = clipboard ? "" : generate_screenshot_filename ();
bool success = false;
string filename_used = "";
- var screenshot_manager = ScreenshotManager.init (this);
- yield screenshot_manager.screenshot_window (true, false, true, file_name, out success, out filename_used);
+ unowned var screenshot_manager = ScreenshotManager.init (this);
+ yield screenshot_manager.screenshot (false, true, filename, out success, out filename_used);
} catch (Error e) {
// Ignore this error
}