Skip to content

Commit 737951a

Browse files
committed
Merge branch 'leolost/interruptible-workspace-switch-mtv' of github.com:elementary/gala into leolost/interruptible-workspace-switch-mtv
2 parents f569de0 + 5d0f066 commit 737951a

11 files changed

+978
-1047
lines changed

src/DBus.vala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class Gala.DBus {
1111
private static WindowManagerGala wm;
1212

1313
[DBus (visible = false)]
14-
public static void init (WindowManagerGala _wm, ScreenshotManager screenshot_manager) {
14+
public static void init (WindowManagerGala _wm, NotificationsManager notifications_manager, ScreenshotManager screenshot_manager) {
1515
wm = _wm;
1616

1717
Bus.own_name (BusType.SESSION, "org.pantheon.gala", BusNameOwnerFlags.NONE,
@@ -33,7 +33,7 @@ public class Gala.DBus {
3333
Bus.own_name (BusType.SESSION, "org.gnome.Shell", BusNameOwnerFlags.NONE,
3434
(connection) => {
3535
try {
36-
connection.register_object ("/org/gnome/Shell", new DBusAccelerator (wm.get_display ()));
36+
connection.register_object ("/org/gnome/Shell", new DBusAccelerator (wm.get_display (), notifications_manager));
3737
connection.register_object ("/org/gnome/Shell/Screenshot", screenshot_manager);
3838
} catch (Error e) { warning (e.message); }
3939
},

src/DBusAccelerator.vala

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,17 @@ namespace Gala {
7373

7474
[DBus (name="org.gnome.Shell")]
7575
public class DBusAccelerator {
76+
private const string NOTIFICATION_COMPONENT_NAME = "DBusAccelerator";
77+
7678
public signal void accelerator_activated (uint action, GLib.HashTable<string, Variant> parameters);
7779

7880
private Meta.Display display;
81+
private NotificationsManager notifications_manager;
7982
private GLib.HashTable<unowned string, GrabbedAccelerator> grabbed_accelerators;
8083

81-
public DBusAccelerator (Meta.Display _display) {
84+
public DBusAccelerator (Meta.Display _display, NotificationsManager _notifications_manager) {
8285
display = _display;
86+
notifications_manager = _notifications_manager;
8387
grabbed_accelerators = new HashTable<unowned string, GrabbedAccelerator> (str_hash, str_equal);
8488
display.accelerator_activated.connect (on_accelerator_activated);
8589
}
@@ -166,7 +170,17 @@ namespace Gala {
166170
level = (int)(double_level * 100);
167171
}
168172

169-
MediaFeedback.send (icon, level);
173+
var hints = new GLib.HashTable<string, Variant> (null, null);
174+
hints.set ("x-canonical-private-synchronous", new Variant.string ("gala-feedback"));
175+
hints.set ("value", new Variant.int32 (level));
176+
177+
notifications_manager.send.begin (
178+
NOTIFICATION_COMPONENT_NAME,
179+
icon,
180+
label,
181+
"",
182+
hints
183+
);
170184
}
171185
}
172186
}

src/MediaFeedback.vala

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

src/NotificationsManager.vala

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2016 Rico Tzschichholz
4+
* 2025 elementary, Inc. (https://elementary.io)
5+
*/
6+
7+
/**
8+
* Gala.NotificationsManager can be used to send notifications to org.freedesktop.Notifications
9+
*/
10+
public class Gala.NotificationsManager : GLib.Object {
11+
[DBus (name = "org.freedesktop.Notifications")]
12+
private interface DBusNotifications : GLib.Object {
13+
public abstract async uint32 notify (string app_name, uint32 replaces_id, string app_icon, string summary,
14+
string body, string[] actions, HashTable<string, Variant> hints, int32 expire_timeout) throws DBusError, IOError;
15+
}
16+
17+
private const int EXPIRE_TIMEOUT = 2000;
18+
19+
private DBusNotifications? notifications = null;
20+
private GLib.HashTable<string, uint32> replaces_id_table = new GLib.HashTable<string, uint32> (str_hash, str_equal);
21+
22+
construct {
23+
Bus.watch_name (BusType.SESSION, "org.freedesktop.Notifications", BusNameWatcherFlags.NONE, on_watch, on_unwatch);
24+
}
25+
26+
private void on_watch (DBusConnection connection) {
27+
connection.get_proxy.begin<DBusNotifications> (
28+
"org.freedesktop.Notifications", "/org/freedesktop/Notifications", DBusProxyFlags.NONE, null,
29+
(obj, res) => {
30+
try {
31+
notifications = ((DBusConnection) obj).get_proxy.end<DBusNotifications> (res);
32+
} catch (Error e) {
33+
warning ("NotificationsManager: Couldn't connect to notifications server: %s", e.message);
34+
notifications = null;
35+
}
36+
}
37+
);
38+
}
39+
40+
private void on_unwatch (DBusConnection conn) {
41+
warning ("NotificationsManager: Lost connection to notifications server");
42+
notifications = null;
43+
}
44+
45+
public async void send (
46+
string component_name,
47+
string icon,
48+
string summary,
49+
string body,
50+
GLib.HashTable<string, Variant> hints
51+
) {
52+
if (notifications == null) {
53+
warning ("NotificationsManager: Unable to send notification. No connection to notification server");
54+
return;
55+
}
56+
57+
uint32? replaces_id = replaces_id_table.get (component_name);
58+
if (replaces_id == null) {
59+
replaces_id = 0;
60+
}
61+
62+
try {
63+
var notification_id = yield notifications.notify (
64+
"gala-feedback",
65+
replaces_id,
66+
icon,
67+
summary,
68+
body,
69+
{},
70+
hints,
71+
EXPIRE_TIMEOUT
72+
);
73+
74+
replaces_id_table.insert (component_name, notification_id);
75+
} catch (Error e) {
76+
critical ("NotificationsManager: There was an error sending a notification: %s", e.message);
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)