[gnome-shell/screenshot-ui-gsd-binds: 9/10] screenshot-ui: Add two key bindings from g-s-d




commit 32bdec176771500ffbe3d80850794a0bac2cce6c
Author: Ivan Molodetskikh <yalterz gmail com>
Date:   Sat Jan 15 19:06:49 2022 +0300

    screenshot-ui: Add two key bindings from g-s-d
    
    These two are moving into gnome-shell to unify screenshot handling and
    allow for same-frame capturing.
    
    While we're at it, move the keybindings .xml file from g-c-c here
    because it belongs to gnome-shell.

 data/50-gnome-shell-screenshots.xml | 17 ++++++++++
 data/meson.build                    |  1 +
 data/org.gnome.shell.gschema.xml.in |  8 +++++
 js/ui/screenshot.js                 | 64 +++++++++++++++++++++++++++++++++++++
 po/POTFILES.in                      |  1 +
 5 files changed, 91 insertions(+)
---
diff --git a/data/50-gnome-shell-screenshots.xml b/data/50-gnome-shell-screenshots.xml
new file mode 100644
index 0000000000..bc73c67366
--- /dev/null
+++ b/data/50-gnome-shell-screenshots.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<KeyListEntries schema="org.gnome.shell.keybindings"
+                group="system"
+                name="Screenshots"
+                wm_name="GNOME Shell"
+                package="gnome-shell">
+
+    <KeyListEntry name="show-screenshot-ui"
+                  description="Show the screenshot UI"/>
+
+    <KeyListEntry name="screenshot"
+                  description="Take a screenshot"/>
+
+    <KeyListEntry name="screenshot-window"
+                  description="Take a screenshot of a window"/>
+
+</KeyListEntries>
\ No newline at end of file
diff --git a/data/meson.build b/data/meson.build
index 76ae45c93a..30457efefe 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -75,6 +75,7 @@ configure_file(
 
 keybinding_files = [
   '50-gnome-shell-launchers.xml',
+  '50-gnome-shell-screenshots.xml',
   '50-gnome-shell-system.xml',
 ]
 
diff --git a/data/org.gnome.shell.gschema.xml.in b/data/org.gnome.shell.gschema.xml.in
index 1dadb13c28..031f959258 100644
--- a/data/org.gnome.shell.gschema.xml.in
+++ b/data/org.gnome.shell.gschema.xml.in
@@ -234,6 +234,14 @@
       <default>["Print"]</default>
       <summary>Show screenshot UI</summary>
     </key>
+    <key name="screenshot-window" type="as">
+      <default>["&lt;Alt&gt;Print"]</default>
+      <summary>Take a screenshot of a window</summary>
+    </key>
+    <key name="screenshot" type="as">
+      <default>["&lt;Shift&gt;Print"]</default>
+      <summary>Take a screenshot</summary>
+    </key>
   </schema>
 
   <schema id="org.gnome.shell.app-switcher"
diff --git a/js/ui/screenshot.js b/js/ui/screenshot.js
index 39c4fe6e8a..65fe1f64e5 100644
--- a/js/ui/screenshot.js
+++ b/js/ui/screenshot.js
@@ -1270,6 +1270,30 @@ class ScreenshotUI extends St.Widget {
             Shell.ActionMode.POPUP,
             showScreenshotUI
         );
+
+        Main.wm.addKeybinding(
+            'screenshot-window',
+            new Gio.Settings({ schema_id: 'org.gnome.shell.keybindings' }),
+            Meta.KeyBindingFlags.IGNORE_AUTOREPEAT | Meta.KeyBindingFlags.PER_WINDOW,
+            Shell.ActionMode.NORMAL |
+            Shell.ActionMode.OVERVIEW |
+            Shell.ActionMode.SYSTEM_MODAL |
+            Shell.ActionMode.LOOKING_GLASS |
+            Shell.ActionMode.POPUP,
+            _screenshotWindow
+        );
+
+        Main.wm.addKeybinding(
+            'screenshot',
+            new Gio.Settings({ schema_id: 'org.gnome.shell.keybindings' }),
+            Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
+            Shell.ActionMode.NORMAL |
+            Shell.ActionMode.OVERVIEW |
+            Shell.ActionMode.SYSTEM_MODAL |
+            Shell.ActionMode.LOOKING_GLASS |
+            Shell.ActionMode.POPUP,
+            _screenshot
+        );
     }
 
     _rebuildMonitorBins() {
@@ -2075,6 +2099,46 @@ function showScreenshotUI() {
     });
 }
 
+/**
+ * Takes a screenshot of the currently focused window.
+ *
+ * @param {Meta.Display} [_display] - The display.
+ * @param {Meta.Window} window - The window.
+ * @param {Meta.KeyBinding} [_binding] - The key binding.
+ * @private
+ */
+function _screenshotWindow(_display, window, _binding) {
+    try {
+        const actor = window.get_compositor_private();
+        const content = actor.paint_to_content(null);
+        const texture = content.get_texture();
+
+        captureScreenshot(texture, null, 1, null);
+    } catch (e) {
+        log('Error capturing screenshot: %s'.format(e.message));
+    }
+}
+
+/**
+ * Takes a screenshot of the entire stage.
+ *
+ * @param {Meta.Display} [_display] - The display.
+ * @param {Meta.Window} [_window] - The window.
+ * @param {Meta.KeyBinding} [_binding] - The key binding.
+ * @private
+ */
+async function _screenshot(_display, _window, _binding) {
+    try {
+        const shooter = new Shell.Screenshot();
+        const [content] = await shooter.to_content();
+        const texture = content.get_texture();
+
+        captureScreenshot(texture, null, 1, null);
+    } catch (e) {
+        log('Error capturing screenshot: %s'.format(e.message));
+    }
+}
+
 var ScreenshotService = class {
     constructor() {
         this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(ScreenshotIface, this);
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 6340bff17a..8dbfe02af6 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,6 +1,7 @@
 # List of source files containing translatable strings.
 # Please keep this file sorted alphabetically.
 data/50-gnome-shell-launchers.xml
+data/50-gnome-shell-screenshots.xml
 data/50-gnome-shell-system.xml
 data/org.gnome.Shell.desktop.in.in
 data/org.gnome.shell.gschema.xml.in


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]