2024-02-18 05:03:26 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2024 elementary, Inc. (https://elementary.io)
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
2024-07-05 21:14:35 +03:00
|
|
|
public class Gala.Daemon.WindowMenu : Gtk.Popover {
|
2024-02-18 05:03:26 +03:00
|
|
|
private static GLib.Settings gala_keybind_settings = new GLib.Settings ("org.pantheon.desktop.gala.keybindings");
|
|
|
|
private static GLib.Settings keybind_settings = new GLib.Settings ("org.gnome.desktop.wm.keybindings");
|
|
|
|
|
2024-07-05 21:14:35 +03:00
|
|
|
public signal void perform_action (Gala.ActionType type) {
|
|
|
|
popdown ();
|
|
|
|
}
|
2024-02-18 05:03:26 +03:00
|
|
|
|
|
|
|
private Granite.AccelLabel always_on_top_accellabel;
|
|
|
|
private Granite.AccelLabel close_accellabel;
|
|
|
|
private Granite.AccelLabel minimize_accellabel;
|
|
|
|
private Granite.AccelLabel move_accellabel;
|
|
|
|
private Granite.AccelLabel move_left_accellabel;
|
|
|
|
private Granite.AccelLabel move_right_accellabel;
|
|
|
|
private Granite.AccelLabel on_visible_workspace_accellabel;
|
|
|
|
private Granite.AccelLabel resize_accellabel;
|
|
|
|
private Granite.AccelLabel screenshot_accellabel;
|
2024-07-05 21:14:35 +03:00
|
|
|
private Gtk.Button minimize;
|
|
|
|
private Gtk.Button maximize;
|
|
|
|
private Gtk.Button move;
|
|
|
|
private Gtk.Button resize;
|
|
|
|
private Gtk.CheckButton always_on_top;
|
|
|
|
private Gtk.CheckButton on_visible_workspace;
|
|
|
|
private Gtk.Button move_left;
|
|
|
|
private Gtk.Button move_right;
|
|
|
|
private Gtk.Button close;
|
|
|
|
private Gtk.Button screenshot;
|
2024-02-18 05:03:26 +03:00
|
|
|
|
|
|
|
private ulong always_on_top_sid = 0U;
|
|
|
|
private ulong on_visible_workspace_sid = 0U;
|
|
|
|
|
|
|
|
construct {
|
|
|
|
minimize_accellabel = new Granite.AccelLabel (_("Hide"));
|
|
|
|
|
2024-07-05 21:14:35 +03:00
|
|
|
minimize = new Gtk.Button () {
|
|
|
|
child = minimize_accellabel
|
|
|
|
};
|
|
|
|
minimize.add_css_class (Granite.STYLE_CLASS_MENUITEM);
|
|
|
|
minimize.clicked.connect (() => {
|
2024-02-18 05:03:26 +03:00
|
|
|
perform_action (Gala.ActionType.HIDE_CURRENT);
|
|
|
|
});
|
|
|
|
|
2024-07-05 21:14:35 +03:00
|
|
|
maximize = new Gtk.Button ();
|
|
|
|
maximize.add_css_class (Granite.STYLE_CLASS_MENUITEM);
|
|
|
|
maximize.clicked.connect (() => {
|
2024-02-18 05:03:26 +03:00
|
|
|
perform_action (Gala.ActionType.MAXIMIZE_CURRENT);
|
|
|
|
});
|
|
|
|
|
|
|
|
move_accellabel = new Granite.AccelLabel (_("Move"));
|
|
|
|
|
2024-07-05 21:14:35 +03:00
|
|
|
move = new Gtk.Button () {
|
|
|
|
child = move_accellabel
|
|
|
|
};
|
|
|
|
move.add_css_class (Granite.STYLE_CLASS_MENUITEM);
|
|
|
|
move.clicked.connect (() => {
|
2024-02-18 05:03:26 +03:00
|
|
|
perform_action (Gala.ActionType.START_MOVE_CURRENT);
|
|
|
|
});
|
|
|
|
|
|
|
|
resize_accellabel = new Granite.AccelLabel (_("Resize"));
|
|
|
|
|
2024-07-05 21:14:35 +03:00
|
|
|
resize = new Gtk.Button () {
|
|
|
|
child = resize_accellabel
|
|
|
|
};
|
|
|
|
resize.add_css_class (Granite.STYLE_CLASS_MENUITEM);
|
|
|
|
resize.clicked.connect (() => {
|
2024-02-18 05:03:26 +03:00
|
|
|
perform_action (Gala.ActionType.START_RESIZE_CURRENT);
|
|
|
|
});
|
|
|
|
|
|
|
|
always_on_top_accellabel = new Granite.AccelLabel (_("Always on Top"));
|
|
|
|
|
2024-07-05 21:14:35 +03:00
|
|
|
always_on_top = new Gtk.CheckButton () {
|
|
|
|
child = always_on_top_accellabel
|
|
|
|
};
|
|
|
|
always_on_top.add_css_class (Granite.STYLE_CLASS_MENUITEM);
|
|
|
|
always_on_top_sid = always_on_top.toggled.connect (() => {
|
2024-02-18 05:03:26 +03:00
|
|
|
perform_action (Gala.ActionType.TOGGLE_ALWAYS_ON_TOP_CURRENT);
|
|
|
|
});
|
|
|
|
|
|
|
|
on_visible_workspace_accellabel = new Granite.AccelLabel (_("Always on Visible Workspace"));
|
|
|
|
|
2024-07-05 21:14:35 +03:00
|
|
|
on_visible_workspace = new Gtk.CheckButton () {
|
|
|
|
child = on_visible_workspace_accellabel
|
|
|
|
};
|
|
|
|
on_visible_workspace.add_css_class (Granite.STYLE_CLASS_MENUITEM);
|
|
|
|
on_visible_workspace_sid = on_visible_workspace.toggled.connect (() => {
|
2024-02-18 05:03:26 +03:00
|
|
|
perform_action (Gala.ActionType.TOGGLE_ALWAYS_ON_VISIBLE_WORKSPACE_CURRENT);
|
|
|
|
});
|
|
|
|
|
|
|
|
move_left_accellabel = new Granite.AccelLabel (_("Move to Workspace Left"));
|
|
|
|
|
2024-07-05 21:14:35 +03:00
|
|
|
move_left = new Gtk.Button () {
|
|
|
|
child = move_left_accellabel
|
|
|
|
};
|
|
|
|
move_left.add_css_class (Granite.STYLE_CLASS_MENUITEM);
|
|
|
|
move_left.clicked.connect (() => {
|
2024-02-18 05:03:26 +03:00
|
|
|
perform_action (Gala.ActionType.MOVE_CURRENT_WORKSPACE_LEFT);
|
|
|
|
});
|
|
|
|
|
|
|
|
move_right_accellabel = new Granite.AccelLabel (_("Move to Workspace Right"));
|
|
|
|
|
2024-07-05 21:14:35 +03:00
|
|
|
move_right = new Gtk.Button () {
|
|
|
|
child = move_right_accellabel
|
|
|
|
};
|
|
|
|
move_right.add_css_class (Granite.STYLE_CLASS_MENUITEM);
|
|
|
|
move_right.clicked.connect (() => {
|
2024-02-18 05:03:26 +03:00
|
|
|
perform_action (Gala.ActionType.MOVE_CURRENT_WORKSPACE_RIGHT);
|
|
|
|
});
|
|
|
|
|
|
|
|
screenshot_accellabel = new Granite.AccelLabel (_("Take Screenshot"));
|
|
|
|
|
2024-07-05 21:14:35 +03:00
|
|
|
screenshot = new Gtk.Button () {
|
|
|
|
child = screenshot_accellabel
|
|
|
|
};
|
|
|
|
screenshot.add_css_class (Granite.STYLE_CLASS_MENUITEM);
|
|
|
|
screenshot.clicked.connect (() => {
|
2024-02-18 05:03:26 +03:00
|
|
|
perform_action (Gala.ActionType.SCREENSHOT_CURRENT);
|
|
|
|
});
|
|
|
|
|
|
|
|
close_accellabel = new Granite.AccelLabel (_("Close"));
|
|
|
|
|
2024-07-05 21:14:35 +03:00
|
|
|
close = new Gtk.Button () {
|
|
|
|
child = close_accellabel
|
|
|
|
};
|
|
|
|
close.add_css_class (Granite.STYLE_CLASS_MENUITEM);
|
|
|
|
close.clicked.connect (() => {
|
2024-02-18 05:03:26 +03:00
|
|
|
perform_action (Gala.ActionType.CLOSE_CURRENT);
|
|
|
|
});
|
|
|
|
|
2024-07-05 21:14:35 +03:00
|
|
|
var box = new Gtk.Box (VERTICAL, 0);
|
|
|
|
box.append (screenshot);
|
|
|
|
box.append (new Gtk.Separator (HORIZONTAL));
|
|
|
|
box.append (always_on_top);
|
|
|
|
box.append (on_visible_workspace);
|
|
|
|
box.append (move_left);
|
|
|
|
box.append (move_right);
|
|
|
|
box.append (new Gtk.Separator (HORIZONTAL));
|
|
|
|
box.append (move);
|
|
|
|
box.append (resize);
|
|
|
|
box.append (maximize);
|
|
|
|
box.append (new Gtk.Separator (HORIZONTAL));
|
|
|
|
box.append (minimize);
|
|
|
|
box.append (close);
|
|
|
|
|
|
|
|
child = box;
|
|
|
|
halign = START;
|
|
|
|
position = BOTTOM;
|
|
|
|
autohide = false;
|
|
|
|
has_arrow = false;
|
|
|
|
add_css_class (Granite.STYLE_CLASS_MENU);
|
2024-02-18 05:03:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public void update (Gala.WindowFlags flags) {
|
|
|
|
minimize.visible = Gala.WindowFlags.CAN_HIDE in flags;
|
|
|
|
if (minimize.visible) {
|
|
|
|
minimize_accellabel.accel_string = keybind_settings.get_strv ("minimize")[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
maximize.visible = Gala.WindowFlags.CAN_MAXIMIZE in flags;
|
|
|
|
if (maximize.visible) {
|
|
|
|
unowned string maximize_label;
|
|
|
|
if (Gala.WindowFlags.IS_MAXIMIZED in flags) {
|
|
|
|
maximize_label = (Gala.WindowFlags.IS_TILED in flags) ? _("Untile") : _("Unmaximize");
|
|
|
|
} else {
|
|
|
|
maximize_label = _("Maximize");
|
|
|
|
}
|
|
|
|
|
|
|
|
maximize.get_child ().destroy ();
|
2024-07-05 21:14:35 +03:00
|
|
|
maximize.child = new Granite.AccelLabel (
|
|
|
|
maximize_label,
|
|
|
|
keybind_settings.get_strv ("toggle-maximized")[0]
|
2024-02-18 05:03:26 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
move.visible = Gala.WindowFlags.ALLOWS_MOVE in flags;
|
|
|
|
if (move.visible) {
|
|
|
|
move_accellabel.accel_string = keybind_settings.get_strv ("begin-move")[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
resize.visible = Gala.WindowFlags.ALLOWS_RESIZE in flags;
|
|
|
|
if (resize.visible) {
|
|
|
|
resize_accellabel.accel_string = keybind_settings.get_strv ("begin-resize")[0];
|
|
|
|
}
|
|
|
|
|
2024-07-05 21:14:35 +03:00
|
|
|
// Setting active causes signal fires on clicked so
|
2024-02-18 05:03:26 +03:00
|
|
|
// we temporarily block those signals from emissions
|
|
|
|
SignalHandler.block (always_on_top, always_on_top_sid);
|
|
|
|
SignalHandler.block (on_visible_workspace, on_visible_workspace_sid);
|
|
|
|
|
|
|
|
always_on_top.active = Gala.WindowFlags.ALWAYS_ON_TOP in flags;
|
|
|
|
always_on_top_accellabel.accel_string = keybind_settings.get_strv ("always-on-top")[0];
|
|
|
|
|
|
|
|
on_visible_workspace.active = Gala.WindowFlags.ON_ALL_WORKSPACES in flags;
|
|
|
|
on_visible_workspace_accellabel.accel_string = keybind_settings.get_strv ("toggle-on-all-workspaces")[0];
|
|
|
|
|
|
|
|
SignalHandler.unblock (always_on_top, always_on_top_sid);
|
|
|
|
SignalHandler.unblock (on_visible_workspace, on_visible_workspace_sid);
|
|
|
|
|
|
|
|
move_right.sensitive = !on_visible_workspace.active;
|
|
|
|
if (move_right.sensitive) {
|
|
|
|
move_right_accellabel.accel_string = keybind_settings.get_strv ("move-to-workspace-right")[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
move_left.sensitive = !on_visible_workspace.active;
|
|
|
|
if (move_left.sensitive) {
|
|
|
|
move_left_accellabel.accel_string = keybind_settings.get_strv ("move-to-workspace-left")[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
screenshot_accellabel.accel_string = gala_keybind_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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|