Merge branch 'master' into lenemter/windowclone-fix-mem-leak

This commit is contained in:
Leo 2024-07-07 19:32:28 +09:00 committed by GitHub
commit b976d3a82a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
25 changed files with 869 additions and 178 deletions

133
daemon-gtk3/DBus.vala Normal file
View File

@ -0,0 +1,133 @@
/*
* Copyright 2024 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
[DBus (name = "org.pantheon.gala")]
public interface Gala.WMDBus : GLib.Object {
public abstract void perform_action (Gala.ActionType type) throws DBusError, IOError;
}
public struct Gala.Daemon.MonitorLabelInfo {
public int monitor;
public string label;
public string background_color;
public string text_color;
public int x;
public int y;
}
[DBus (name = "org.pantheon.gala.daemon")]
public class Gala.Daemon.DBus : GLib.Object {
private const string DBUS_NAME = "org.pantheon.gala";
private const string DBUS_OBJECT_PATH = "/org/pantheon/gala";
private const string DAEMON_DBUS_NAME = "org.pantheon.gala.daemon";
private const string DAEMON_DBUS_OBJECT_PATH = "/org/pantheon/gala/daemon";
private WMDBus? wm_proxy = null;
private WindowMenu? window_menu;
private BackgroundMenu? background_menu;
private List<MonitorLabel> monitor_labels = new List<MonitorLabel> ();
construct {
Bus.watch_name (BusType.SESSION, DBUS_NAME, BusNameWatcherFlags.NONE, gala_appeared, lost_gala);
}
private void on_gala_get (GLib.Object? obj, GLib.AsyncResult? res) {
try {
wm_proxy = Bus.get_proxy.end (res);
} catch (Error e) {
warning ("Failed to get Gala proxy: %s", e.message);
}
}
private void lost_gala () {
wm_proxy = null;
}
private void gala_appeared () {
if (wm_proxy == null) {
Bus.get_proxy.begin<WMDBus> (BusType.SESSION, DBUS_NAME, DBUS_OBJECT_PATH, 0, null, on_gala_get);
}
}
private void perform_action (Gala.ActionType type) {
if (wm_proxy != null) {
try {
wm_proxy.perform_action (type);
} catch (Error e) {
warning ("Failed to perform Gala action over DBus: %s", e.message);
}
}
}
public void show_window_menu (Gala.WindowFlags flags, int display_width, int display_height, int x, int y) throws DBusError, IOError {
if (window_menu == null) {
window_menu = new WindowMenu ();
window_menu.perform_action.connect (perform_action);
}
window_menu.update (flags);
show_menu (window_menu, display_width, display_height, x, y, true);
}
public void show_desktop_menu (int display_width, int display_height, int x, int y) throws DBusError, IOError {
if (background_menu == null) {
background_menu = new BackgroundMenu ();
}
show_menu (background_menu, display_width, display_height, x, y, false);
}
private void show_menu (Gtk.Menu menu, int display_width, int display_height, int x, int y, bool ignore_first_release) {
var window = new Window (display_width, display_height);
window.present ();
menu.attach_to_widget (window.content, null);
Gdk.Rectangle rect = {
x,
y,
0,
0
};
menu.show_all ();
menu.popup_at_rect (window.get_window (), rect, NORTH, NORTH_WEST);
menu.deactivate.connect (window.close);
if (ignore_first_release) {
bool first = true;
menu.button_release_event.connect (() => {
if (first) {
first = false;
return Gdk.EVENT_STOP;
}
return Gdk.EVENT_PROPAGATE;
});
}
}
public void show_monitor_labels (MonitorLabelInfo[] label_infos) throws GLib.DBusError, GLib.IOError {
hide_monitor_labels ();
monitor_labels = new List<MonitorLabel> ();
foreach (var info in label_infos) {
var label = new MonitorLabel (info);
monitor_labels.append (label);
label.present ();
}
}
public void hide_monitor_labels () throws GLib.DBusError, GLib.IOError {
foreach (var monitor_label in monitor_labels) {
monitor_label.close ();
}
}
}

49
daemon-gtk3/Main.vala Normal file
View File

@ -0,0 +1,49 @@
/*
* Copyright 2024 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
public class Gala.Daemon.Application : Gtk.Application {
public Application () {
Object (application_id: "org.pantheon.gala.daemon");
}
public override void startup () {
base.startup ();
var granite_settings = Granite.Settings.get_default ();
var gtk_settings = Gtk.Settings.get_default ();
gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
granite_settings.notify["prefers-color-scheme"].connect (() => {
gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
});
var app_provider = new Gtk.CssProvider ();
app_provider.load_from_resource ("io/elementary/desktop/gala-daemon/gala-daemon.css");
Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), app_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
}
public override void activate () {
hold ();
}
public override bool dbus_register (DBusConnection connection, string object_path) throws Error {
base.dbus_register (connection, object_path);
connection.register_object (object_path, new DBus ());
return true;
}
}
public static int main (string[] args) {
GLib.Intl.setlocale (LocaleCategory.ALL, "");
GLib.Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
GLib.Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
GLib.Intl.textdomain (Config.GETTEXT_PACKAGE);
var app = new Gala.Daemon.Application ();
return app.run ();
}

View File

@ -0,0 +1,62 @@
/*
* Copyright 2024 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
public class Gala.Daemon.MonitorLabel : Hdy.Window {
private const int SPACING = 12;
private const string COLORED_STYLE_CSS = """
.%s {
background-color: alpha(%s, 0.8);
color: %s;
}
""";
public MonitorLabelInfo info { get; construct; }
public MonitorLabel (MonitorLabelInfo info) {
Object (info: info);
}
construct {
child = new Gtk.Label (info.label);
title = "LABEL-%i".printf (info.monitor);
input_shape_combine_region (null);
accept_focus = false;
decorated = false;
resizable = false;
deletable = false;
can_focus = false;
skip_taskbar_hint = true;
skip_pager_hint = true;
type_hint = Gdk.WindowTypeHint.TOOLTIP;
set_keep_above (true);
stick ();
var scale_factor = get_style_context ().get_scale ();
move (
(int) (info.x / scale_factor) + SPACING,
(int) (info.y / scale_factor) + SPACING
);
var provider = new Gtk.CssProvider ();
try {
provider.load_from_data (COLORED_STYLE_CSS.printf (title, info.background_color, info.text_color));
get_style_context ().add_class (title);
get_style_context ().add_class ("monitor-label");
Gtk.StyleContext.add_provider_for_screen (
Gdk.Screen.get_default (),
provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
);
} catch (Error e) {
warning ("Failed to load CSS: %s", e.message);
}
show_all ();
}
}

50
daemon-gtk3/Window.vala Normal file
View File

@ -0,0 +1,50 @@
/*
* Copyright 2024 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Authored by: Leonhard Kargl <leo.kargl@proton.me>
*/
public class Gala.Daemon.Window : Gtk.Window {
public Gtk.Box content { get; construct; }
public Window (int width, int height) {
Object (
default_width: width,
default_height: height
);
}
class construct {
set_css_name ("daemon-window");
}
construct {
decorated = false;
resizable = false;
deletable = false;
can_focus = false;
input_shape_combine_region (null);
accept_focus = false;
skip_taskbar_hint = true;
skip_pager_hint = true;
type_hint = Gdk.WindowTypeHint.DOCK;
set_keep_above (true);
title = "MODAL";
child = content = new Gtk.Box (HORIZONTAL, 0) {
hexpand = true,
vexpand = true
};
set_visual (get_screen ().get_rgba_visual ());
show_all ();
move (0, 0);
button_press_event.connect (() => {
close ();
return Gdk.EVENT_STOP;
});
}
}

194
daemon-gtk3/WindowMenu.vala Normal file
View File

@ -0,0 +1,194 @@
/*
* Copyright 2024 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
public class Gala.Daemon.WindowMenu : Gtk.Menu {
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");
public signal void perform_action (Gala.ActionType type);
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;
private Gtk.MenuItem minimize;
private Gtk.MenuItem maximize;
private Gtk.MenuItem move;
private Gtk.MenuItem resize;
private Gtk.CheckMenuItem always_on_top;
private Gtk.CheckMenuItem on_visible_workspace;
private Gtk.MenuItem move_left;
private Gtk.MenuItem move_right;
private Gtk.MenuItem close;
private Gtk.MenuItem screenshot;
private ulong always_on_top_sid = 0U;
private ulong on_visible_workspace_sid = 0U;
construct {
minimize_accellabel = new Granite.AccelLabel (_("Hide"));
minimize = new Gtk.MenuItem ();
minimize.add (minimize_accellabel);
minimize.activate.connect (() => {
perform_action (Gala.ActionType.HIDE_CURRENT);
});
maximize = new Gtk.MenuItem ();
maximize.activate.connect (() => {
perform_action (Gala.ActionType.MAXIMIZE_CURRENT);
});
move_accellabel = new Granite.AccelLabel (_("Move"));
move = new Gtk.MenuItem ();
move.add (move_accellabel);
move.activate.connect (() => {
perform_action (Gala.ActionType.START_MOVE_CURRENT);
});
resize_accellabel = new Granite.AccelLabel (_("Resize"));
resize = new Gtk.MenuItem ();
resize.add (resize_accellabel);
resize.activate.connect (() => {
perform_action (Gala.ActionType.START_RESIZE_CURRENT);
});
always_on_top_accellabel = new Granite.AccelLabel (_("Always on Top"));
always_on_top = new Gtk.CheckMenuItem ();
always_on_top.add (always_on_top_accellabel);
always_on_top_sid = always_on_top.activate.connect (() => {
perform_action (Gala.ActionType.TOGGLE_ALWAYS_ON_TOP_CURRENT);
});
on_visible_workspace_accellabel = new Granite.AccelLabel (_("Always on Visible Workspace"));
on_visible_workspace = new Gtk.CheckMenuItem ();
on_visible_workspace.add (on_visible_workspace_accellabel);
on_visible_workspace_sid = on_visible_workspace.activate.connect (() => {
perform_action (Gala.ActionType.TOGGLE_ALWAYS_ON_VISIBLE_WORKSPACE_CURRENT);
});
move_left_accellabel = new Granite.AccelLabel (_("Move to Workspace Left"));
move_left = new Gtk.MenuItem ();
move_left.add (move_left_accellabel);
move_left.activate.connect (() => {
perform_action (Gala.ActionType.MOVE_CURRENT_WORKSPACE_LEFT);
});
move_right_accellabel = new Granite.AccelLabel (_("Move to Workspace Right"));
move_right = new Gtk.MenuItem ();
move_right.add (move_right_accellabel);
move_right.activate.connect (() => {
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 ();
close.add (close_accellabel);
close.activate.connect (() => {
perform_action (Gala.ActionType.CLOSE_CURRENT);
});
append (screenshot);
append (new Gtk.SeparatorMenuItem ());
append (always_on_top);
append (on_visible_workspace);
append (move_left);
append (move_right);
append (new Gtk.SeparatorMenuItem ());
append (move);
append (resize);
append (maximize);
append (new Gtk.SeparatorMenuItem ());
append (minimize);
append (close);
}
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 ();
maximize.add (
new Granite.AccelLabel (
maximize_label,
keybind_settings.get_strv ("toggle-maximized")[0]
)
);
}
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];
}
// Setting active causes signal fires on activate so
// 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];
}
}
}

19
daemon-gtk3/meson.build Normal file
View File

@ -0,0 +1,19 @@
gala_daemon_sources = files(
'Main.vala',
'DBus.vala',
'MonitorLabel.vala',
'Window.vala',
'WindowMenu.vala',
'BackgroundMenu.vala',
)
granite_dep_old = dependency('granite')
hdy_dep = dependency('libhandy-1')
gala_daemon_bin = executable(
'gala-daemon-gtk3',
gala_daemon_sources,
dependencies: [gala_dep, gala_base_dep, granite_dep_old, hdy_dep],
include_directories: config_inc_dir,
install: true,
)

View File

@ -3,6 +3,42 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
public enum Gala.ActionType {
NONE = 0,
SHOW_WORKSPACE_VIEW,
MAXIMIZE_CURRENT,
HIDE_CURRENT,
OPEN_LAUNCHER,
CUSTOM_COMMAND,
WINDOW_OVERVIEW,
WINDOW_OVERVIEW_ALL,
SWITCH_TO_WORKSPACE_PREVIOUS,
SWITCH_TO_WORKSPACE_NEXT,
SWITCH_TO_WORKSPACE_LAST,
START_MOVE_CURRENT,
START_RESIZE_CURRENT,
TOGGLE_ALWAYS_ON_TOP_CURRENT,
TOGGLE_ALWAYS_ON_VISIBLE_WORKSPACE_CURRENT,
MOVE_CURRENT_WORKSPACE_LEFT,
MOVE_CURRENT_WORKSPACE_RIGHT,
CLOSE_CURRENT,
SCREENSHOT_CURRENT
}
[Flags]
public enum Gala.WindowFlags {
NONE = 0,
CAN_HIDE,
CAN_MAXIMIZE,
IS_MAXIMIZED,
ALLOWS_MOVE,
ALLOWS_RESIZE,
ALWAYS_ON_TOP,
ON_ALL_WORKSPACES,
CAN_CLOSE,
IS_TILED
}
[DBus (name = "org.pantheon.gala")]
public interface Gala.WMDBus : GLib.Object {
public abstract void perform_action (Gala.ActionType type) throws DBusError, IOError;
@ -25,15 +61,68 @@ public class Gala.Daemon.DBus : GLib.Object {
private const string DAEMON_DBUS_NAME = "org.pantheon.gala.daemon";
private const string DAEMON_DBUS_OBJECT_PATH = "/org/pantheon/gala/daemon";
private const string BG_MENU_ACTION_GROUP_PREFIX = "background-menu";
private const string BG_MENU_ACTION_PREFIX = BG_MENU_ACTION_GROUP_PREFIX + ".";
private WMDBus? wm_proxy = null;
private Window window;
private WindowMenu? window_menu;
private BackgroundMenu? background_menu;
private Gtk.PopoverMenu background_menu;
private List<MonitorLabel> monitor_labels = new List<MonitorLabel> ();
construct {
Bus.watch_name (BusType.SESSION, DBUS_NAME, BusNameWatcherFlags.NONE, gala_appeared, lost_gala);
window = new Window ();
var background_menu_top_section = new Menu ();
background_menu_top_section.append (
_("Change Wallpaper…"),
Action.print_detailed_name (BG_MENU_ACTION_PREFIX + "launch-uri", "settings://desktop/appearance/wallpaper")
);
background_menu_top_section.append (
_("Display Settings…"),
Action.print_detailed_name (BG_MENU_ACTION_PREFIX + "launch-uri", "settings://display")
);
var background_menu_bottom_section = new Menu ();
background_menu_bottom_section.append (
_("System Settings…"),
Action.print_detailed_name (BG_MENU_ACTION_PREFIX + "launch-uri", "settings://")
);
var background_menu_model = new Menu ();
background_menu_model.append_section (null, background_menu_top_section);
background_menu_model.append_section (null, background_menu_bottom_section);
background_menu = new Gtk.PopoverMenu.from_model (background_menu_model) {
halign = START,
position = BOTTOM,
autohide = false,
has_arrow = false
};
background_menu.set_parent (window.child);
background_menu.closed.connect (window.close);
var launch_action = new SimpleAction ("launch-uri", VariantType.STRING);
launch_action.activate.connect (action_launch);
var action_group = new SimpleActionGroup ();
action_group.add_action (launch_action);
background_menu.insert_action_group (BG_MENU_ACTION_GROUP_PREFIX, action_group);
window_menu = new WindowMenu ();
window_menu.set_parent (window.child);
window_menu.closed.connect (window.close);
window_menu.perform_action.connect ((type) => {
Idle.add (() => {
perform_action (type);
return Source.REMOVE;
});
});
}
private void on_gala_get (GLib.Object? obj, GLib.AsyncResult? res) {
@ -65,53 +154,32 @@ public class Gala.Daemon.DBus : GLib.Object {
}
public void show_window_menu (Gala.WindowFlags flags, int display_width, int display_height, int x, int y) throws DBusError, IOError {
if (window_menu == null) {
window_menu = new WindowMenu ();
window_menu.perform_action.connect (perform_action);
}
window_menu.update (flags);
show_menu (window_menu, display_width, display_height, x, y, true);
show_menu (window_menu, display_width, display_height, x, y);
}
public void show_desktop_menu (int display_width, int display_height, int x, int y) throws DBusError, IOError {
if (background_menu == null) {
background_menu = new BackgroundMenu ();
}
show_menu (background_menu, display_width, display_height, x, y, false);
show_menu (background_menu, display_width, display_height, x, y);
}
private void show_menu (Gtk.Menu menu, int display_width, int display_height, int x, int y, bool ignore_first_release) {
var window = new Window (display_width, display_height);
private void show_menu (Gtk.Popover menu, int display_width, int display_height, int x, int y) {
window.default_width = display_width;
window.default_height = display_height;
window.present ();
menu.attach_to_widget (window.content, null);
Gdk.Rectangle rect = {
x,
y,
0,
0
};
menu.pointing_to = rect;
menu.show_all ();
menu.popup_at_rect (window.get_window (), rect, NORTH, NORTH_WEST);
menu.deactivate.connect (window.close);
if (ignore_first_release) {
bool first = true;
menu.button_release_event.connect (() => {
if (first) {
first = false;
return Gdk.EVENT_STOP;
}
return Gdk.EVENT_PROPAGATE;
});
}
Idle.add (() => {
menu.popup ();
return Source.REMOVE;
});
}
public void show_monitor_labels (MonitorLabelInfo[] label_infos) throws GLib.DBusError, GLib.IOError {
@ -130,4 +198,20 @@ public class Gala.Daemon.DBus : GLib.Object {
monitor_label.close ();
}
}
private static void action_launch (SimpleAction action, Variant? variant) {
try {
AppInfo.launch_default_for_uri (variant.get_string (), null);
} catch (Error e) {
var message_dialog = new Granite.MessageDialog.with_image_from_icon_name (
_("Failed to open System Settings"),
_("A handler for the “settings://” URI scheme must be installed."),
"dialog-error",
Gtk.ButtonsType.CLOSE
);
message_dialog.show_error_details (e.message);
message_dialog.present ();
message_dialog.response.connect (message_dialog.destroy);
}
}
}

View File

@ -21,8 +21,8 @@ public class Gala.Daemon.Application : Gtk.Application {
});
var app_provider = new Gtk.CssProvider ();
app_provider.load_from_resource ("io/elementary/desktop/gala-daemon/gala-daemon.css");
Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), app_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
app_provider.load_from_resource ("/io/elementary/desktop/gala-daemon/gala-daemon.css");
Gtk.StyleContext.add_provider_for_display (Gdk.Display.get_default (), app_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
}
public override void activate () {
@ -32,6 +32,9 @@ public class Gala.Daemon.Application : Gtk.Application {
public override bool dbus_register (DBusConnection connection, string object_path) throws Error {
base.dbus_register (connection, object_path);
// We are using gtk in the DBus () constructor so we need to init it early
Gtk.init ();
connection.register_object (object_path, new DBus ());
return true;

View File

@ -3,7 +3,7 @@
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
public class Gala.Daemon.MonitorLabel : Hdy.Window {
public class Gala.Daemon.MonitorLabel : Gtk.Window {
private const int SPACING = 12;
private const string COLORED_STYLE_CSS = """
.%s {
@ -23,33 +23,20 @@
title = "LABEL-%i".printf (info.monitor);
input_shape_combine_region (null);
accept_focus = false;
decorated = false;
resizable = false;
deletable = false;
can_focus = false;
skip_taskbar_hint = true;
skip_pager_hint = true;
type_hint = Gdk.WindowTypeHint.TOOLTIP;
set_keep_above (true);
stick ();
var scale_factor = get_style_context ().get_scale ();
move (
(int) (info.x / scale_factor) + SPACING,
(int) (info.y / scale_factor) + SPACING
);
titlebar = new Gtk.Grid ();
var provider = new Gtk.CssProvider ();
try {
provider.load_from_data (COLORED_STYLE_CSS.printf (title, info.background_color, info.text_color));
provider.load_from_string (COLORED_STYLE_CSS.printf (title, info.background_color, info.text_color));
get_style_context ().add_class (title);
get_style_context ().add_class ("monitor-label");
Gtk.StyleContext.add_provider_for_screen (
Gdk.Screen.get_default (),
Gtk.StyleContext.add_provider_for_display (
Gdk.Display.get_default (),
provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
);
@ -57,6 +44,6 @@
warning ("Failed to load CSS: %s", e.message);
}
show_all ();
present ();
}
}

View File

@ -6,15 +6,6 @@
*/
public class Gala.Daemon.Window : Gtk.Window {
public Gtk.Box content { get; construct; }
public Window (int width, int height) {
Object (
default_width: width,
default_height: height
);
}
class construct {
set_css_name ("daemon-window");
}
@ -24,27 +15,22 @@ public class Gala.Daemon.Window : Gtk.Window {
resizable = false;
deletable = false;
can_focus = false;
input_shape_combine_region (null);
accept_focus = false;
skip_taskbar_hint = true;
skip_pager_hint = true;
type_hint = Gdk.WindowTypeHint.DOCK;
set_keep_above (true);
title = "MODAL";
child = content = new Gtk.Box (HORIZONTAL, 0) {
hide_on_close = true;
child = new Gtk.Box (HORIZONTAL, 0) {
hexpand = true,
vexpand = true
};
set_visual (get_screen ().get_rgba_visual ());
var controller = new Gtk.GestureClick ();
child.add_controller (controller);
controller.released.connect (close);
}
show_all ();
move (0, 0);
button_press_event.connect (() => {
close ();
return Gdk.EVENT_STOP;
});
public override void snapshot (Gtk.Snapshot snapshot) {
base.snapshot (snapshot);
// We need to append something here otherwise GTK thinks the snapshot is empty and therefore doesn't
// render anything and therefore doesn't present a window which is needed for our popovers
snapshot.append_color ({0, 0, 0, 0}, {{0, 0}, {0, 0}});
}
}

View File

@ -3,11 +3,13 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
public class Gala.Daemon.WindowMenu : Gtk.Menu {
public class Gala.Daemon.WindowMenu : Gtk.Popover {
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");
public signal void perform_action (Gala.ActionType type);
public signal void perform_action (Gala.ActionType type) {
popdown ();
}
private Granite.AccelLabel always_on_top_accellabel;
private Granite.AccelLabel close_accellabel;
@ -18,16 +20,16 @@ public class Gala.Daemon.WindowMenu : Gtk.Menu {
private Granite.AccelLabel on_visible_workspace_accellabel;
private Granite.AccelLabel resize_accellabel;
private Granite.AccelLabel screenshot_accellabel;
private Gtk.MenuItem minimize;
private Gtk.MenuItem maximize;
private Gtk.MenuItem move;
private Gtk.MenuItem resize;
private Gtk.CheckMenuItem always_on_top;
private Gtk.CheckMenuItem on_visible_workspace;
private Gtk.MenuItem move_left;
private Gtk.MenuItem move_right;
private Gtk.MenuItem close;
private Gtk.MenuItem screenshot;
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;
private ulong always_on_top_sid = 0U;
private ulong on_visible_workspace_sid = 0U;
@ -35,94 +37,121 @@ public class Gala.Daemon.WindowMenu : Gtk.Menu {
construct {
minimize_accellabel = new Granite.AccelLabel (_("Hide"));
minimize = new Gtk.MenuItem ();
minimize.add (minimize_accellabel);
minimize.activate.connect (() => {
minimize = new Gtk.Button () {
child = minimize_accellabel
};
minimize.add_css_class (Granite.STYLE_CLASS_MENUITEM);
minimize.clicked.connect (() => {
perform_action (Gala.ActionType.HIDE_CURRENT);
});
maximize = new Gtk.MenuItem ();
maximize.activate.connect (() => {
maximize = new Gtk.Button ();
maximize.add_css_class (Granite.STYLE_CLASS_MENUITEM);
maximize.clicked.connect (() => {
perform_action (Gala.ActionType.MAXIMIZE_CURRENT);
});
move_accellabel = new Granite.AccelLabel (_("Move"));
move = new Gtk.MenuItem ();
move.add (move_accellabel);
move.activate.connect (() => {
move = new Gtk.Button () {
child = move_accellabel
};
move.add_css_class (Granite.STYLE_CLASS_MENUITEM);
move.clicked.connect (() => {
perform_action (Gala.ActionType.START_MOVE_CURRENT);
});
resize_accellabel = new Granite.AccelLabel (_("Resize"));
resize = new Gtk.MenuItem ();
resize.add (resize_accellabel);
resize.activate.connect (() => {
resize = new Gtk.Button () {
child = resize_accellabel
};
resize.add_css_class (Granite.STYLE_CLASS_MENUITEM);
resize.clicked.connect (() => {
perform_action (Gala.ActionType.START_RESIZE_CURRENT);
});
always_on_top_accellabel = new Granite.AccelLabel (_("Always on Top"));
always_on_top = new Gtk.CheckMenuItem ();
always_on_top.add (always_on_top_accellabel);
always_on_top_sid = always_on_top.activate.connect (() => {
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 (() => {
perform_action (Gala.ActionType.TOGGLE_ALWAYS_ON_TOP_CURRENT);
});
on_visible_workspace_accellabel = new Granite.AccelLabel (_("Always on Visible Workspace"));
on_visible_workspace = new Gtk.CheckMenuItem ();
on_visible_workspace.add (on_visible_workspace_accellabel);
on_visible_workspace_sid = on_visible_workspace.activate.connect (() => {
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 (() => {
perform_action (Gala.ActionType.TOGGLE_ALWAYS_ON_VISIBLE_WORKSPACE_CURRENT);
});
move_left_accellabel = new Granite.AccelLabel (_("Move to Workspace Left"));
move_left = new Gtk.MenuItem ();
move_left.add (move_left_accellabel);
move_left.activate.connect (() => {
move_left = new Gtk.Button () {
child = move_left_accellabel
};
move_left.add_css_class (Granite.STYLE_CLASS_MENUITEM);
move_left.clicked.connect (() => {
perform_action (Gala.ActionType.MOVE_CURRENT_WORKSPACE_LEFT);
});
move_right_accellabel = new Granite.AccelLabel (_("Move to Workspace Right"));
move_right = new Gtk.MenuItem ();
move_right.add (move_right_accellabel);
move_right.activate.connect (() => {
move_right = new Gtk.Button () {
child = move_right_accellabel
};
move_right.add_css_class (Granite.STYLE_CLASS_MENUITEM);
move_right.clicked.connect (() => {
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 (() => {
screenshot = new Gtk.Button () {
child = screenshot_accellabel
};
screenshot.add_css_class (Granite.STYLE_CLASS_MENUITEM);
screenshot.clicked.connect (() => {
perform_action (Gala.ActionType.SCREENSHOT_CURRENT);
});
close_accellabel = new Granite.AccelLabel (_("Close"));
close = new Gtk.MenuItem ();
close.add (close_accellabel);
close.activate.connect (() => {
close = new Gtk.Button () {
child = close_accellabel
};
close.add_css_class (Granite.STYLE_CLASS_MENUITEM);
close.clicked.connect (() => {
perform_action (Gala.ActionType.CLOSE_CURRENT);
});
append (screenshot);
append (new Gtk.SeparatorMenuItem ());
append (always_on_top);
append (on_visible_workspace);
append (move_left);
append (move_right);
append (new Gtk.SeparatorMenuItem ());
append (move);
append (resize);
append (maximize);
append (new Gtk.SeparatorMenuItem ());
append (minimize);
append (close);
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);
}
public void update (Gala.WindowFlags flags) {
@ -141,15 +170,12 @@ public class Gala.Daemon.WindowMenu : Gtk.Menu {
}
maximize.get_child ().destroy ();
maximize.add (
new Granite.AccelLabel (
maximize_label,
keybind_settings.get_strv ("toggle-maximized")[0]
)
maximize.child = new Granite.AccelLabel (
maximize_label,
keybind_settings.get_strv ("toggle-maximized")[0]
);
}
move.visible = Gala.WindowFlags.ALLOWS_MOVE in flags;
if (move.visible) {
move_accellabel.accel_string = keybind_settings.get_strv ("begin-move")[0];
@ -160,7 +186,7 @@ public class Gala.Daemon.WindowMenu : Gtk.Menu {
resize_accellabel.accel_string = keybind_settings.get_strv ("begin-resize")[0];
}
// Setting active causes signal fires on activate so
// Setting active causes signal fires on clicked so
// 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);

View File

@ -4,13 +4,13 @@ gala_daemon_sources = files(
'MonitorLabel.vala',
'Window.vala',
'WindowMenu.vala',
'BackgroundMenu.vala',
)
gala_daemon_bin = executable(
'gala-daemon',
gala_daemon_sources,
dependencies: [gala_dep, gala_base_dep, granite_dep, hdy_dep],
gala_resources,
dependencies: [config_dep, granite_dep, gtk4_dep],
include_directories: config_inc_dir,
install: true,
)

View File

@ -4,7 +4,7 @@
*/
daemon-window {
background-color: transparent;
background: transparent;
}
.monitor-label {

View File

@ -439,12 +439,4 @@
<description></description>
</key>
</schema>
<schema path="/io/elementary/desktop/wm/shell/" id="io.elementary.desktop.wm.shell">
<key type="aas" name="trusted-clients">
<default>[['io.elementary.dock'], ["io.elementary.wingpanel"]]</default>
<summary>Clients to be launched by gala as trusted for interacting with the shell wl protcol.</summary>
<description>An array of arrays of arguments to be used to launch the client.</description>
</key>
</schema>
</schemalist>

View File

@ -0,0 +1,7 @@
[io.elementary.wingpanel]
launch-on-x=true
args=io.elementary.wingpanel
[io.elementary.dock]
launch-on-x=false
args=io.elementary.dock

View File

@ -4,6 +4,11 @@ install_data(
rename: 'org.pantheon.desktop.gala.gschema.xml'
)
install_data(
'io.elementary.desktop.wm.shell',
install_dir: get_option('sysconfdir') / 'xdg',
)
i18n.merge_file(
input: 'gala.metainfo.xml.in',
output: meson.project_name() + '.metainfo.xml',

View File

@ -109,6 +109,11 @@ namespace Gala {
private InputDevice? grabbed_device = null;
private ulong on_event_id = 0;
static construct {
sources = new Gee.HashMap<string,Gee.LinkedList<unowned Actor>> ();
destinations = new Gee.HashMap<string,Gee.LinkedList<unowned Actor>> ();
}
/**
* Create a new DragDropAction
*
@ -119,18 +124,12 @@ namespace Gala {
*/
public DragDropAction (DragDropActionType type, string id) {
Object (drag_type : type, drag_id : id);
if (sources == null)
sources = new Gee.HashMap<string,Gee.LinkedList<unowned Actor>> ();
if (destinations == null)
destinations = new Gee.HashMap<string,Gee.LinkedList<unowned Actor>> ();
}
~DragDropAction () {
if (actor != null)
if (actor != null) {
release_actor (actor);
}
}
public override void set_actor (Actor? new_actor) {
@ -197,6 +196,11 @@ namespace Gala {
switch (event.get_type ()) {
case EventType.BUTTON_PRESS:
case EventType.TOUCH_BEGIN:
if (!is_valid_touch_event (event)) {
return Clutter.EVENT_PROPAGATE;
}
if (grabbed_actor != null) {
return Clutter.EVENT_PROPAGATE;
}
@ -213,6 +217,11 @@ namespace Gala {
return Clutter.EVENT_STOP;
case EventType.BUTTON_RELEASE:
case EventType.TOUCH_END:
if (!is_valid_touch_event (event)) {
return Clutter.EVENT_PROPAGATE;
}
if (!dragging) {
float x, y, ex, ey;
event.get_coords (out ex, out ey);
@ -290,6 +299,11 @@ namespace Gala {
}
break;
case EventType.MOTION:
case EventType.TOUCH_UPDATE:
if (!is_valid_touch_event (event)) {
return Clutter.EVENT_PROPAGATE;
}
float x, y;
event.get_coords (out x, out y);
@ -447,5 +461,17 @@ namespace Gala {
dragging = false;
}
private bool is_valid_touch_event (Clutter.Event event) {
var type = event.get_type ();
return (
type != Clutter.EventType.TOUCH_BEGIN &&
type != Clutter.EventType.TOUCH_CANCEL &&
type != Clutter.EventType.TOUCH_END &&
type != Clutter.EventType.TOUCH_UPDATE ||
Meta.Util.is_wayland_compositor ()
);
}
}
}

View File

@ -294,7 +294,6 @@ namespace Gala {
*
* @param actor The actor from which to create a snapshot
* @param inner_rect The inner (actually visible) rectangle of the window
* @param outer_rect The outer (input region) rectangle of the window
*
* @return A copy of the actor at that time or %NULL
*/

View File

@ -71,8 +71,6 @@ add_project_arguments([
'-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_44',
'-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_44',
'-DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_10',
'-DGDK_VERSION_MAX_ALLOWED=GDK_VERSION_3_10',
],
language: 'c',
)
@ -89,10 +87,10 @@ gio_dep = dependency('gio-2.0', version: '>= @0@'.format(glib_version_required))
gio_unix_dep = dependency('gio-unix-2.0', version: '>= @0@'.format(glib_version_required))
gmodule_dep = dependency('gmodule-2.0')
gtk_dep = [dependency('gtk+-3.0', version: '>= @0@'.format(gtk_version_required)), dependency('gdk-x11-3.0')]
gtk4_dep = dependency('gtk4')
gee_dep = dependency('gee-0.8')
granite_dep = dependency('granite', version: '>= 5.4.0')
granite_dep = dependency('granite-7')
gnome_desktop_dep = dependency('gnome-desktop-3.0')
hdy_dep = dependency('libhandy-1')
m_dep = cc.find_library('m', required: false)
posix_dep = vala.find_library('posix', required: false)
sqlite3_dep = dependency('sqlite3')
@ -184,6 +182,7 @@ subdir('protocol')
subdir('lib')
subdir('src')
subdir('daemon')
subdir('daemon-gtk3')
subdir('plugins/pip')
subdir('plugins/template')
if get_option('documentation')

View File

@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: beat-box\n"
"Report-Msgid-Bugs-To: https://github.com/elementary/gala/issues\n"
"POT-Creation-Date: 2024-06-17 17:08+0000\n"
"PO-Revision-Date: 2024-04-26 18:13+0000\n"
"PO-Revision-Date: 2024-07-01 13:16+0000\n"
"Last-Translator: Ihor Hordiichuk <igor_ck@outlook.com>\n"
"Language-Team: Ukrainian <https://l10n.elementary.io/projects/desktop/gala/"
"uk/>\n"
@ -18,7 +18,7 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
"X-Generator: Weblate 5.0.2\n"
"X-Generator: Weblate 5.5.5\n"
"X-Launchpad-Export-Date: 2017-02-21 05:47+0000\n"
#: src/Dialogs.vala:144
@ -49,23 +49,23 @@ msgstr "Зачекати"
#: src/Dialogs.vala:217
#, c-format
msgid "“%s” wants to inhibit system shortcuts"
msgstr ""
msgstr "“%s” хоче заборонити використання системних комбінацій клавіш"
#: src/Dialogs.vala:219
msgid "An application wants to inhibit system shortcuts"
msgstr ""
msgstr "Застосунок хоче заборонити використання системних комбінацій клавіш"
#: src/Dialogs.vala:222
msgid "All system shortcuts will be redirected to the application."
msgstr ""
msgstr "Усі системні комбінації клавіш будуть перенаправлені до застосунку."
#: src/Dialogs.vala:223
msgid "Allow"
msgstr ""
msgstr "Дозволити"
#: src/Dialogs.vala:224
msgid "Deny"
msgstr ""
msgstr "Відхилити"
#: src/ScreenshotManager.vala:285
msgid "Screenshots"

View File

@ -67,7 +67,7 @@ public class Gala.DaemonManager : GLib.Object {
private async void start_x () {
try {
var subprocess = new Subprocess (NONE, "gala-daemon");
var subprocess = new Subprocess (NONE, "gala-daemon-gtk3");
yield subprocess.wait_async ();
//Restart the daemon if it crashes
@ -102,6 +102,7 @@ public class Gala.DaemonManager : GLib.Object {
break;
case "MODAL":
daemon_client.make_dock (window);
window.move_frame (false, 0, 0);
window.make_above ();
break;

View File

@ -146,7 +146,6 @@ namespace Gala {
}
var window_actor = (Meta.WindowActor) window.get_compositor_private ();
unowned Meta.ShapedTexture window_texture = (Meta.ShapedTexture) window_actor.get_texture ();
float actor_x, actor_y;
window_actor.get_position (out actor_x, out actor_y);
@ -162,8 +161,14 @@ namespace Gala {
#else
Cairo.RectangleInt clip = { rect.x - (int) actor_x, rect.y - (int) actor_y, rect.width, rect.height };
#endif
var image = (Cairo.ImageSurface) window_texture.get_image (clip);
var image = (Cairo.ImageSurface) window_actor.get_image (clip);
if (include_cursor) {
if (window.get_client_type () == Meta.WindowClientType.WAYLAND) {
float resource_scale = window_actor.get_resource_scale ();
image.set_device_scale (resource_scale, resource_scale);
}
image = composite_stage_cursor (image, { rect.x, rect.y, rect.width, rect.height });
}

View File

@ -21,6 +21,8 @@ public class Gala.PanelWindow : Object {
private PanelClone clone;
private uint idle_move_id = 0;
private int width = -1;
private int height = -1;
@ -132,8 +134,14 @@ public class Gala.PanelWindow : Object {
}
private void move_window_idle (int x, int y) {
Idle.add (() => {
if (idle_move_id != 0) {
Source.remove (idle_move_id);
}
idle_move_id = Idle.add (() => {
window.move_frame (false, x, y);
idle_move_id = 0;
return Source.REMOVE;
});
}

View File

@ -34,10 +34,66 @@ public class Gala.ShellClientsManager : Object {
construct {
notifications_client = new NotificationsClient (wm.get_display ());
var shell_settings = new Settings ("io.elementary.desktop.wm.shell");
var clients = shell_settings.get_value ("trusted-clients");
foreach (var client in clients) {
protocol_clients += new ManagedClient (wm.get_display (), client.get_strv ());
start_clients.begin ();
}
private async void start_clients () {
// Prioritize user config over system
(unowned string)[] config_dirs = { Environment.get_user_config_dir () };
foreach (unowned var dir in Environment.get_system_config_dirs ()) {
config_dirs += dir;
}
string? path = null;
foreach (unowned var dir in config_dirs) {
var file_path = Path.build_filename (dir, "io.elementary.desktop.wm.shell");
warning (file_path);
if (FileUtils.test (file_path, EXISTS)) {
path = file_path;
break;
}
}
if (path == null) {
warning ("No shell config file found.");
return;
}
var file = File.new_for_path (path);
Bytes bytes;
try {
bytes = yield file.load_bytes_async (null, null);
} catch (Error e) {
warning ("Failed to load shell config file: %s", e.message);
return;
}
var key_file = new KeyFile ();
try {
key_file.load_from_bytes (bytes, NONE);
} catch (Error e) {
warning ("Failed to parse shell config file: %s", e.message);
return;
}
foreach (var group in key_file.get_groups ()) {
if (!Meta.Util.is_wayland_compositor ()) {
try {
if (!key_file.get_boolean (group, "launch-on-x")) {
continue;
}
} catch (Error e) {
warning ("Failed to check whether client should be launched on x, assuming yes: %s", e.message);
}
}
try {
var args = key_file.get_string_list (group, "args");
protocol_clients += new ManagedClient (wm.get_display (), args);
} catch (Error e) {
warning ("Failed to load launch args for client %s: %s", group, e.message);
}
}
}