Move screenshot shortcuts in-house (#1411)

This commit is contained in:
David Hewitt 2022-04-23 22:26:40 +00:00 committed by GitHub
parent 1e223b3027
commit e86a9518c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 99 additions and 9 deletions

View File

@ -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) {

View File

@ -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>

View File

@ -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 {
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_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 {
string filename = clipboard ? "" : generate_screenshot_filename ();
bool success = false;
string 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
}