Skip to content

Commit 183cfad

Browse files
committed
Use DBusMenuModel and DBusActionGroup for the window menu
1 parent 4514740 commit 183cfad

12 files changed

Lines changed: 244 additions & 590 deletions

daemon-gtk3/DBus.vala

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
* SPDX-License-Identifier: GPL-3.0-or-later
44
*/
55

6-
[DBus (name = "org.pantheon.gala")]
7-
public interface Gala.WMDBus : GLib.Object {
8-
public abstract void perform_action (Gala.ActionType type) throws DBusError, IOError;
9-
}
10-
116
public struct Gala.Daemon.MonitorLabelInfo {
127
public int monitor;
138
public string label;
@@ -19,59 +14,32 @@ public struct Gala.Daemon.MonitorLabelInfo {
1914

2015
[DBus (name = "org.pantheon.gala.daemon")]
2116
public class Gala.Daemon.DBus : GLib.Object {
22-
private const string DBUS_NAME = "org.pantheon.gala";
23-
private const string DBUS_OBJECT_PATH = "/org/pantheon/gala";
24-
25-
private const string DAEMON_DBUS_NAME = "org.pantheon.gala.daemon";
26-
private const string DAEMON_DBUS_OBJECT_PATH = "/org/pantheon/gala/daemon";
27-
28-
private WMDBus? wm_proxy = null;
29-
30-
private WindowMenu? window_menu;
17+
private Gtk.Menu? window_menu;
3118
private BackgroundMenu? background_menu;
3219

3320
private List<MonitorLabel> monitor_labels = new List<MonitorLabel> ();
3421

3522
construct {
36-
Bus.watch_name (BusType.SESSION, DBUS_NAME, BusNameWatcherFlags.NONE, gala_appeared, lost_gala);
23+
load_window_menu.begin ();
3724
}
3825

39-
private void on_gala_get (GLib.Object? obj, GLib.AsyncResult? res) {
26+
private async void load_window_menu () {
27+
DBusConnection connection;
4028
try {
41-
wm_proxy = Bus.get_proxy.end (res);
29+
connection = yield Bus.get (SESSION, null);
4230
} catch (Error e) {
43-
warning ("Failed to get Gala proxy: %s", e.message);
31+
warning ("Failed to get DBus connection: %s", e.message);
32+
return;
4433
}
45-
}
46-
47-
private void lost_gala () {
48-
wm_proxy = null;
49-
}
5034

51-
private void gala_appeared () {
52-
if (wm_proxy == null) {
53-
Bus.get_proxy.begin<WMDBus> (BusType.SESSION, DBUS_NAME, DBUS_OBJECT_PATH, 0, null, on_gala_get);
54-
}
55-
}
35+
var menu_model = DBusMenuModel.get (connection, "org.pantheon.gala", "/io/elementary/gala/window_menu");
36+
var action_group = DBusActionGroup.get (connection, "org.pantheon.gala", "/io/elementary/gala/window_menu");
5637

57-
private void perform_action (Gala.ActionType type) {
58-
if (wm_proxy != null) {
59-
try {
60-
wm_proxy.perform_action (type);
61-
} catch (Error e) {
62-
warning ("Failed to perform Gala action over DBus: %s", e.message);
63-
}
64-
}
38+
window_menu = new Gtk.Menu.from_model (menu_model);
39+
window_menu.insert_action_group ("window-menu", action_group);
6540
}
6641

67-
public void show_window_menu (Gala.WindowFlags flags, int display_width, int display_height, int x, int y) throws DBusError, IOError {
68-
if (window_menu == null) {
69-
window_menu = new WindowMenu ();
70-
window_menu.perform_action.connect (perform_action);
71-
}
72-
73-
window_menu.update (flags);
74-
42+
public void show_window_menu (int display_width, int display_height, int x, int y) throws DBusError, IOError {
7543
show_menu (window_menu, display_width, display_height, x, y, true);
7644
}
7745

daemon-gtk3/WindowMenu.vala

Lines changed: 0 additions & 194 deletions
This file was deleted.

daemon-gtk3/meson.build

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ gala_daemon_sources = files(
33
'DBus.vala',
44
'MonitorLabel.vala',
55
'Window.vala',
6-
'WindowMenu.vala',
76
'BackgroundMenu.vala',
87
)
98

@@ -13,7 +12,6 @@ hdy_dep = dependency('libhandy-1')
1312
executable(
1413
'gala-daemon-gtk3',
1514
gala_daemon_sources,
16-
gala_common_enums,
1715
config_header,
1816
gala_resources,
1917
dependencies: [granite6_dep, hdy_dep],

0 commit comments

Comments
 (0)