mirror of
https://github.com/elementary/gala.git
synced 2024-11-25 03:06:14 +01:00
Desktop context menu (#879)
This commit is contained in:
parent
ace05d7ac7
commit
7de1313128
@ -29,6 +29,7 @@ namespace Gala {
|
||||
|
||||
[DBus (name = "org.pantheon.gala.daemon")]
|
||||
public class MenuDaemon : Object {
|
||||
// Window Menu
|
||||
private Granite.AccelLabel always_on_top_accellabel;
|
||||
private Granite.AccelLabel close_accellabel;
|
||||
private Granite.AccelLabel minimize_accellabel;
|
||||
@ -48,6 +49,9 @@ namespace Gala {
|
||||
Gtk.MenuItem move_right;
|
||||
Gtk.MenuItem close;
|
||||
|
||||
// Desktop Menu
|
||||
Gtk.Menu? desktop_menu = null;
|
||||
|
||||
WMDBus? wm_proxy = null;
|
||||
|
||||
ulong always_on_top_sid = 0U;
|
||||
@ -258,5 +262,78 @@ namespace Gala {
|
||||
push_in = true;
|
||||
}, 3, Gdk.CURRENT_TIME);
|
||||
}
|
||||
|
||||
public void show_desktop_menu (int x, int y) throws DBusError, IOError {
|
||||
if (desktop_menu == null) {
|
||||
var change_wallpaper = new Gtk.MenuItem.with_label (_("Change Wallpaper…"));
|
||||
change_wallpaper.activate.connect (() => {
|
||||
try {
|
||||
AppInfo.launch_default_for_uri ("settings://desktop/appearance/wallpaper", null);
|
||||
} catch (Error e) {
|
||||
var message_dialog = new Granite.MessageDialog.with_image_from_icon_name (
|
||||
"Failed to Open Wallpaper Settings",
|
||||
"Unable 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.run ();
|
||||
message_dialog.destroy ();
|
||||
}
|
||||
});
|
||||
|
||||
var display_settings = new Gtk.MenuItem.with_label (_("Display Settings…"));
|
||||
display_settings.activate.connect (() => {
|
||||
try {
|
||||
AppInfo.launch_default_for_uri ("settings://display", null);
|
||||
} catch (Error e) {
|
||||
var message_dialog = new Granite.MessageDialog.with_image_from_icon_name (
|
||||
"Failed to Open Display Settings",
|
||||
"Unable to open System Settings. A handler for the `settings://` URI scheme must be installed.",
|
||||
"dialog-warning",
|
||||
Gtk.ButtonsType.CLOSE
|
||||
);
|
||||
message_dialog.show_error_details (e.message);
|
||||
message_dialog.run ();
|
||||
message_dialog.destroy ();
|
||||
}
|
||||
});
|
||||
|
||||
var system_settings = new Gtk.MenuItem.with_label (_("System Settings…"));
|
||||
system_settings.activate.connect (() => {
|
||||
try {
|
||||
AppInfo.launch_default_for_uri ("settings://", null);
|
||||
} catch (Error e) {
|
||||
var message_dialog = new Granite.MessageDialog.with_image_from_icon_name (
|
||||
"Failed to Open System Settings",
|
||||
"Unable to open System Settings. A handler for the `settings://` URI scheme must be installed.",
|
||||
"dialog-warning",
|
||||
Gtk.ButtonsType.CLOSE
|
||||
);
|
||||
message_dialog.show_error_details (e.message);
|
||||
message_dialog.run ();
|
||||
message_dialog.destroy ();
|
||||
}
|
||||
});
|
||||
|
||||
var separator = new Gtk.SeparatorMenuItem ();
|
||||
|
||||
desktop_menu = new Gtk.Menu ();
|
||||
desktop_menu.append (change_wallpaper);
|
||||
desktop_menu.append (display_settings);
|
||||
desktop_menu.append (separator);
|
||||
desktop_menu.append (system_settings);
|
||||
desktop_menu.show_all ();
|
||||
}
|
||||
|
||||
desktop_menu.popup (null, null, (m, ref px, ref py, out push_in) => {
|
||||
var scale = m.scale_factor;
|
||||
px = x / scale;
|
||||
// Move the menu 1 pixel outside of the pointer or else it closes instantly
|
||||
// on the mouse up event
|
||||
py = (y / scale) + 1;
|
||||
push_in = true;
|
||||
}, 3, Gdk.CURRENT_TIME);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
namespace Gala {
|
||||
public class BackgroundContainer : Meta.BackgroundGroup {
|
||||
public signal void changed ();
|
||||
public signal void show_background_menu (int x, int y);
|
||||
|
||||
#if HAS_MUTTER330
|
||||
public Meta.Display display { get; construct; }
|
||||
@ -29,6 +30,13 @@ namespace Gala {
|
||||
construct {
|
||||
Meta.MonitorManager.@get ().monitors_changed.connect (update);
|
||||
|
||||
reactive = true;
|
||||
button_release_event.connect ((event) => {
|
||||
if (event.button == Gdk.BUTTON_SECONDARY) {
|
||||
show_background_menu ((int)event.x, (int)event.y);
|
||||
}
|
||||
});
|
||||
|
||||
update ();
|
||||
}
|
||||
|
||||
@ -45,6 +53,13 @@ namespace Gala {
|
||||
construct {
|
||||
screen.monitors_changed.connect (update);
|
||||
|
||||
reactive = true;
|
||||
button_press_event.connect ((event) => {
|
||||
if (event.button == Gdk.BUTTON_SECONDARY) {
|
||||
show_background_menu ((int)event.x, (int)event.y);
|
||||
}
|
||||
});
|
||||
|
||||
update ();
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ namespace Gala {
|
||||
[DBus (name = "org.pantheon.gala.daemon")]
|
||||
public interface Daemon: GLib.Object {
|
||||
public abstract async void show_window_menu (WindowFlags flags, int x, int y) throws Error;
|
||||
public abstract async void show_desktop_menu (int x, int y) throws Error;
|
||||
}
|
||||
|
||||
public class WindowManagerGala : Meta.Plugin, WindowManager {
|
||||
@ -230,8 +231,10 @@ namespace Gala {
|
||||
|
||||
#if HAS_MUTTER330
|
||||
background_group = new BackgroundContainer (display);
|
||||
((BackgroundContainer)background_group).show_background_menu.connect (on_show_background_menu);
|
||||
#else
|
||||
background_group = new BackgroundContainer (screen);
|
||||
((BackgroundContainer)background_group).show_background_menu.connect (on_show_background_menu);
|
||||
#endif
|
||||
window_group.add_child (background_group);
|
||||
window_group.set_child_below_sibling (background_group, null);
|
||||
@ -372,6 +375,18 @@ namespace Gala {
|
||||
return false;
|
||||
}
|
||||
|
||||
void on_show_background_menu (int x, int y) {
|
||||
if (daemon_proxy == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
daemon_proxy.show_desktop_menu.begin (x, y);
|
||||
} catch (Error e) {
|
||||
message ("Error invoking MenuManager: %s", e.message);
|
||||
}
|
||||
}
|
||||
|
||||
void on_monitors_changed () {
|
||||
configure_hotcorners ();
|
||||
screen_shield.expand_to_screen_size ();
|
||||
|
Loading…
Reference in New Issue
Block a user