Fix #955: Add Take Screenshot to the header context menu (#1068)

This commit is contained in:
José Expósito 2021-03-05 07:48:28 +01:00 committed by GitHub
parent 9678b22370
commit ed77206168
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View File

@ -38,6 +38,7 @@ namespace Gala {
private Granite.AccelLabel move_right_accellabel;
private Granite.AccelLabel on_visible_workspace_accellabel;
private Granite.AccelLabel resize_accellabel;
private Granite.AccelLabel screenshot_accellabel;
Gtk.Menu? window_menu = null;
Gtk.MenuItem hide;
Gtk.MenuItem maximize;
@ -48,6 +49,7 @@ namespace Gala {
Gtk.MenuItem move_left;
Gtk.MenuItem move_right;
Gtk.MenuItem close;
Gtk.MenuItem screenshot;
// Desktop Menu
Gtk.Menu? desktop_menu = null;
@ -58,9 +60,11 @@ namespace Gala {
ulong on_visible_workspace_sid = 0U;
private static GLib.Settings keybind_settings;
private static GLib.Settings media_keys_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");
}
[DBus (visible = false)]
@ -169,6 +173,14 @@ namespace Gala {
perform_action (Gala.ActionType.MOVE_CURRENT_WORKSPACE_RIGHT);
});
screenshot_accellabel = new Granite.AccelLabel (_("Take Screenshot"));
screenshot = new Gtk.MenuItem ();
screenshot.add (screenshot_accellabel);
screenshot.activate.connect (() => {
perform_action (Gala.ActionType.SCREENSHOT_CURRENT);
});
close_accellabel = new Granite.AccelLabel (_("Close"));
close = new Gtk.MenuItem ();
@ -186,6 +198,7 @@ namespace Gala {
window_menu.append (on_visible_workspace);
window_menu.append (move_left);
window_menu.append (move_right);
window_menu.append (screenshot);
window_menu.append (close);
window_menu.show_all ();
}
@ -248,6 +261,8 @@ 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];
close.visible = Gala.WindowFlags.CAN_CLOSE in flags;
if (close.visible) {
close_accellabel.accel_string = keybind_settings.get_strv ("close")[0];

View File

@ -32,7 +32,8 @@ namespace Gala {
TOGGLE_ALWAYS_ON_VISIBLE_WORKSPACE_CURRENT,
MOVE_CURRENT_WORKSPACE_LEFT,
MOVE_CURRENT_WORKSPACE_RIGHT,
CLOSE_CURRENT
CLOSE_CURRENT,
SCREENSHOT_CURRENT
}
[Flags]

View File

@ -886,6 +886,9 @@ namespace Gala {
var workspace = manager.get_workspace_by_index (manager.get_n_workspaces () - 1);
workspace.activate (display.get_current_time ());
break;
case ActionType.SCREENSHOT_CURRENT:
screenshot_current_window ();
break;
default:
warning ("Trying to run unknown action");
break;
@ -2101,6 +2104,21 @@ namespace Gala {
return info;
}
private async void screenshot_current_window () {
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);
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);
} catch (Error e) {
// Ignore this error
}
}
/**
* Notification windows are a special case where the transition state needs
* to be preserved when reparenting the actor. Because Clutter doesn't allow specifying