Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions daemon-gtk3/DBus.vala
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,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 {
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, 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);
Expand Down
39 changes: 29 additions & 10 deletions daemon/DBus.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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<MonitorLabel> monitor_labels = new List<MonitorLabel> ();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = {
Expand All @@ -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 {
Expand Down
34 changes: 19 additions & 15 deletions src/Background/BackgroundContainer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Background/BackgroundManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
46 changes: 18 additions & 28 deletions src/DaemonManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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);
}
Expand Down
12 changes: 10 additions & 2 deletions src/WindowManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
Loading