diff --git a/daemon-gtk3/DBus.vala b/daemon-gtk3/DBus.vala index 41a2e0c31..a1af1dad9 100644 --- a/daemon-gtk3/DBus.vala +++ b/daemon-gtk3/DBus.vala @@ -64,7 +64,7 @@ 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 { + public void show_window_menu (Gala.WindowFlags flags, int monitor, int monitor_width, int monitor_height, int x, int y) throws DBusError, IOError { if (window_menu == null) { window_menu = new WindowMenu (); window_menu.perform_action.connect (perform_action); @@ -72,19 +72,21 @@ public class Gala.Daemon.DBus : GLib.Object { window_menu.update (flags); - show_menu (window_menu, display_width, display_height, x, y, true); + show_menu (window_menu, monitor, monitor_width, monitor_height, x, y, true); } - public void show_desktop_menu (int display_width, int display_height, int x, int y) throws DBusError, IOError { + public void show_desktop_menu (int monitor, int monitor_width, int monitor_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, monitor, monitor_width, monitor_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); + private void show_menu (Gtk.Menu menu, int monitor, int monitor_width, int monitor_height, int x, int y, bool ignore_first_release) { + var window = new Window (monitor_width, monitor_height) { + title = "MODAL-%d".printf (monitor) + }; window.present (); menu.attach_to_widget (window.content, null); diff --git a/daemon/DBus.vala b/daemon/DBus.vala index 601f8f006..d21b75270 100644 --- a/daemon/DBus.vala +++ b/daemon/DBus.vala @@ -67,7 +67,8 @@ public class Gala.Daemon.DBus : GLib.Object { private WMDBus? wm_proxy = null; private Window window; - private WindowMenu? window_menu; + private WindowMenu window_menu; + private Gtk.GestureClick window_menu_click_controller; private Gtk.PopoverMenu background_menu; private List monitor_labels = new List (); @@ -123,6 +124,11 @@ public class Gala.Daemon.DBus : GLib.Object { return Source.REMOVE; }); }); + + window_menu_click_controller = new Gtk.GestureClick () { + propagation_phase = Gtk.PropagationPhase.BUBBLE + }; + ((Gtk.Widget) window_menu).add_controller (window_menu_click_controller); } private void on_gala_get (GLib.Object? obj, GLib.AsyncResult? res) { @@ -153,28 +159,29 @@ 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 { + public void show_window_menu (Gala.WindowFlags flags, int monitor, int monitor_width, int monitor_height, int x, int y) throws DBusError, IOError { window_menu.update (flags); - show_menu (window_menu, display_width, display_height, x, y); + show_menu (window_menu, monitor, monitor_width, monitor_height, x, y, true); } - public void show_desktop_menu (int display_width, int display_height, int x, int y) throws DBusError, IOError { - show_menu (background_menu, display_width, display_height, x, y); + public void show_desktop_menu (int monitor, int monitor_width, int monitor_height, int x, int y) throws DBusError, IOError { + show_menu (background_menu, monitor, monitor_width, monitor_height, x, y, false); } - private void show_menu (Gtk.Popover menu, int display_width, int display_height, int x, int y) { + private void show_menu (Gtk.Popover menu, int monitor, int monitor_width, int monitor_height, int x, int y, bool ignore_first_release) { if (!DisplayConfig.is_logical_layout ()) { var scale_factor = window.scale_factor; - display_width /= scale_factor; - display_height /= scale_factor; + monitor_width /= scale_factor; + monitor_height /= scale_factor; x /= scale_factor; y /= scale_factor; } - window.default_width = display_width; - window.default_height = display_height; + window.title = "MODAL-%d".printf (monitor); + window.default_width = monitor_width; + window.default_height = monitor_height; window.present (); Gdk.Rectangle rect = { @@ -189,6 +196,18 @@ public class Gala.Daemon.DBus : GLib.Object { menu.popup (); return Source.REMOVE; }); + + if (ignore_first_release) { + var first = true; + window_menu_click_controller.released.connect (() => { + if (first) { + first = false; + window_menu_click_controller.set_state (Gtk.EventSequenceState.CLAIMED); + } + + window_menu_click_controller.set_state (Gtk.EventSequenceState.NONE); + }); + } } public void show_monitor_labels (MonitorLabelInfo[] label_infos) throws GLib.DBusError, GLib.IOError { diff --git a/src/Background/BackgroundContainer.vala b/src/Background/BackgroundContainer.vala index 9d2425db9..08b33604b 100644 --- a/src/Background/BackgroundContainer.vala +++ b/src/Background/BackgroundContainer.vala @@ -7,9 +7,9 @@ public class Gala.BackgroundContainer : Meta.BackgroundGroup { public signal void changed (); - public signal void show_background_menu (int x, int y); + public signal void show_background_menu (int monitor, int x, int y); - public Meta.Display display { get; construct; } + public Meta.Display display { private get; construct; } public BackgroundContainer (Meta.Display display) { Object (display: display); @@ -19,15 +19,6 @@ public class Gala.BackgroundContainer : Meta.BackgroundGroup { unowned var monitor_manager = display.get_context ().get_backend ().get_monitor_manager (); monitor_manager.monitors_changed.connect (update); - reactive = true; - button_release_event.connect ((event) => { - float x, y; - event.get_coords (out x, out y); - if (event.get_button () == Clutter.Button.SECONDARY) { - show_background_menu ((int)x, (int)y); - } - }); - #if HAS_MUTTER47 background_color = Cogl.Color.from_string ("Black"); #else @@ -43,19 +34,32 @@ public class Gala.BackgroundContainer : Meta.BackgroundGroup { } private void update () { - var reference_child = (get_child_at_index (0) as BackgroundManager); - if (reference_child != null) + var reference_child = (BackgroundManager) get_child_at_index (0); + if (reference_child != null) { reference_child.changed.disconnect (background_changed); + } destroy_all_children (); for (var i = 0; i < display.get_n_monitors (); i++) { var background = new BackgroundManager (display, i); - add_child (background); - if (i == 0) + background.button_release_event.connect ((__background, event) => { + if (event.get_button () == Clutter.Button.SECONDARY) { + float x, y; + event.get_coords (out x, out y); + + var _background = (BackgroundManager) __background; + show_background_menu (_background.monitor_index, (int) x, (int) y); + } + + return Clutter.EVENT_STOP; + }); + + if (i == 0) { background.changed.connect (background_changed); + } } } diff --git a/src/Background/BackgroundManager.vala b/src/Background/BackgroundManager.vala index a178009f3..1d970d54e 100644 --- a/src/Background/BackgroundManager.vala +++ b/src/Background/BackgroundManager.vala @@ -29,6 +29,8 @@ public class Gala.BackgroundManager : Meta.BackgroundGroup, Gala.BackgroundManag } construct { + reactive = true; + background_source = BackgroundCache.get_default ().get_background_source (display); update_background_actor (false); diff --git a/src/DaemonManager.vala b/src/DaemonManager.vala index a7d483172..66a582643 100644 --- a/src/DaemonManager.vala +++ b/src/DaemonManager.vala @@ -12,8 +12,8 @@ public class Gala.DaemonManager : GLib.Object { [DBus (name = "org.pantheon.gala.daemon")] public interface Daemon: GLib.Object { - public abstract async void show_window_menu (WindowFlags flags, int width, int height, int x, int y) throws Error; - public abstract async void show_desktop_menu (int display_width, int display_height, int x, int y) throws Error; + public abstract async void show_window_menu (WindowFlags flags, int monitor, int monitor_width, int monitor_height, int x, int y) throws Error; + public abstract async void show_desktop_menu (int monitor, int monitor_width, int monitor_height, int x, int y) throws GLib.Error; } public Meta.Display display { get; construct; } @@ -77,22 +77,22 @@ public class Gala.DaemonManager : GLib.Object { } private void handle_daemon_window (Meta.Window window) { + if (window.title == null) { + return; + } + var info = window.title.split ("-"); - if (info.length == 0) { - critical ("Couldn't handle daemon window: No title provided"); + if (info.length < 2) { + critical ("Couldn't handle daemon window: Incorrect window title provided"); return; } + var index = int.parse (info[1]); + var monitor_geometry = display.get_monitor_geometry (index); + switch (info[0]) { case "LABEL": - if (info.length < 2) { - return; - } - - var index = int.parse (info[1]); - - var monitor_geometry = display.get_monitor_geometry (index); window.move_frame (false, monitor_geometry.x + SPACING, monitor_geometry.y + SPACING); window.make_above (); break; @@ -101,7 +101,7 @@ public class Gala.DaemonManager : GLib.Object { #if HAS_MUTTER46 daemon_client.make_dock (window); #endif - window.move_frame (false, 0, 0); + window.move_resize_frame (false, monitor_geometry.x, monitor_geometry.y, monitor_geometry.width, monitor_geometry.height); window.make_above (); break; } @@ -123,31 +123,21 @@ public class Gala.DaemonManager : GLib.Object { } } - public async void show_background_menu (int x, int y) { - if (daemon_proxy == null) { - return; - } - - int width, height; - display.get_size (out width, out height); + public async void show_background_menu (int monitor, int x, int y) requires (daemon_proxy != null) { + var monitor_geometry = display.get_monitor_geometry (monitor); try { - yield daemon_proxy.show_desktop_menu (width, height, x, y); + yield daemon_proxy.show_desktop_menu (monitor, monitor_geometry.width, monitor_geometry.height, x, y); } catch (Error e) { warning ("Error invoking MenuManager: %s", e.message); } } - public async void show_window_menu (WindowFlags flags, int x, int y) { - if (daemon_proxy == null) { - return; - } - - int width, height; - display.get_size (out width, out height); + public async void show_window_menu (WindowFlags flags, int monitor, int x, int y) requires (daemon_proxy != null) { + var monitor_geometry = display.get_monitor_geometry (monitor); try { - yield daemon_proxy.show_window_menu (flags, width, height, x, y); + yield daemon_proxy.show_window_menu (flags, monitor, monitor_geometry.width, monitor_geometry.height, x, y); } catch (Error e) { warning ("Error invoking MenuManager: %s", e.message); } diff --git a/src/WindowManager.vala b/src/WindowManager.vala index 9041b9e1b..ac8a8850c 100644 --- a/src/WindowManager.vala +++ b/src/WindowManager.vala @@ -228,7 +228,7 @@ namespace Gala { ui_group.add_child (window_group); background_group = new BackgroundContainer (display); - ((BackgroundContainer)background_group).show_background_menu.connect (daemon_manager.show_background_menu); + ((BackgroundContainer) background_group).show_background_menu.connect (daemon_manager.show_background_menu); window_group.add_child (background_group); window_group.set_child_below_sibling (background_group, null); @@ -938,7 +938,15 @@ namespace Gala { if (window.can_close ()) flags |= WindowFlags.CAN_CLOSE; - daemon_manager.show_window_menu.begin (flags, x, y); + var monitor = window.get_monitor (); + var monitor_geometry = window.display.get_monitor_geometry (monitor); + + daemon_manager.show_window_menu.begin ( + flags, + monitor, + x - monitor_geometry.x, + y - monitor_geometry.y + ); break; case Meta.WindowMenuType.APP: // FIXME we don't have any sort of app menus