1
Description: Use synchronous notifications when they are supported
3
Upstream: that's Ubuntu specific (notify-osd)
4
--- a/plugins/media-keys/gsd-media-keys-manager.c
5
+++ b/plugins/media-keys/gsd-media-keys-manager.c
7
#include "gvc-mixer-control.h"
8
#include "gvc-mixer-sink.h"
10
+#include <libnotify/notify.h>
12
#define GSD_MEDIA_KEYS_DBUS_PATH GSD_DBUS_PATH "/MediaKeys"
13
#define GSD_MEDIA_KEYS_DBUS_NAME GSD_DBUS_NAME ".MediaKeys"
16
GCancellable *cancellable;
20
+ /* Ubuntu notifications */
21
+ NotifyNotification *volume_notification;
22
+ NotifyNotification *brightness_notification;
23
+ NotifyNotification *kb_backlight_notification;
26
static void gsd_media_keys_manager_class_init (GsdMediaKeysManagerClass *klass);
29
static gpointer manager_object = NULL;
31
+#define NOTIFY_CAP_PRIVATE_SYNCHRONOUS "x-canonical-private-synchronous"
32
+#define NOTIFY_CAP_PRIVATE_ICON_ONLY "x-canonical-private-icon-only"
33
+#define NOTIFY_HINT_TRUE "true"
36
+ GsdMediaKeysManager *manager;
38
+ guint old_percentage;
40
+} GsdBrightnessActionData;
42
+static const char *volume_icons[] = {
43
+ "notification-audio-volume-muted",
44
+ "notification-audio-volume-low",
45
+ "notification-audio-volume-medium",
46
+ "notification-audio-volume-high",
50
+static const char *brightness_icons[] = {
51
+ "notification-display-brightness-off",
52
+ "notification-display-brightness-low",
53
+ "notification-display-brightness-medium",
54
+ "notification-display-brightness-high",
55
+ "notification-display-brightness-full",
59
+static const char *kb_backlight_icons[] = {
60
+ "notification-keyboard-brightness-off",
61
+ "notification-keyboard-brightness-low",
62
+ "notification-keyboard-brightness-medium",
63
+ "notification-keyboard-brightness-high",
64
+ "notification-keyboard-brightness-full",
69
+calculate_icon_name (gint value, const char **icon_names)
71
+ value = CLAMP (value, 0, 100);
72
+ gint length = g_strv_length (icon_names);
73
+ gint s = (length - 1) * value / 100 + 1;
74
+ s = CLAMP (s, 1, length - 1);
76
+ return icon_names[s];
80
+ubuntu_osd_notification_is_supported (void)
85
+ caps = notify_get_server_caps ();
86
+ has_cap = (g_list_find_custom (caps, NOTIFY_CAP_PRIVATE_SYNCHRONOUS, (GCompareFunc) g_strcmp0) != NULL);
87
+ g_list_foreach (caps, (GFunc) g_free, NULL);
94
+ubuntu_osd_notification_show_icon (const char *icon,
97
+ if (!ubuntu_osd_notification_is_supported ())
100
+ NotifyNotification *notification = notify_notification_new (" ", "", icon);
101
+ notify_notification_set_hint_string (notification, NOTIFY_CAP_PRIVATE_SYNCHRONOUS, hint);
102
+ notify_notification_set_hint_string (notification, NOTIFY_CAP_PRIVATE_ICON_ONLY, NOTIFY_HINT_TRUE);
104
+ gboolean res = notify_notification_show (notification, NULL);
105
+ g_object_unref (notification);
111
+ubuntu_osd_do_notification (NotifyNotification **notification,
115
+ const char **icon_names)
117
+ if (!ubuntu_osd_notification_is_supported ())
120
+ if (!*notification) {
121
+ *notification = notify_notification_new (" ", "", NULL);
122
+ notify_notification_set_hint_string (*notification, NOTIFY_CAP_PRIVATE_SYNCHRONOUS, hint);
125
+ value = CLAMP (value, -1, 101);
126
+ const char *icon = muted ? icon_names[0] : calculate_icon_name (value, icon_names);
127
+ notify_notification_set_hint_int32 (*notification, "value", value);
128
+ notify_notification_update (*notification, " ", "", icon);
130
+ return notify_notification_show (*notification, NULL);
134
+ubuntu_osd_notification_show_volume (GsdMediaKeysManager *manager,
138
+ return ubuntu_osd_do_notification (&manager->priv->volume_notification,
139
+ "volume", value, muted, volume_icons);
143
+ubuntu_osd_notification_show_brightness (GsdMediaKeysManager *manager,
146
+ return ubuntu_osd_do_notification (&manager->priv->brightness_notification,
147
+ "brightness", value, value <= 0, brightness_icons);
151
+ubuntu_osd_notification_show_kb_backlight (GsdMediaKeysManager *manager,
154
+ return ubuntu_osd_do_notification (&manager->priv->kb_backlight_notification,
155
+ "keyboard", value, value <= 0, kb_backlight_icons);
159
media_key_free (MediaKey *key)
164
- show_osd (manager, "media-eject-symbolic", NULL, -1);
165
+ if (!ubuntu_osd_notification_show_icon ("notification-device-eject", "Eject")) {
166
+ show_osd (manager, "media-eject-symbolic", NULL, -1);
169
/* Clean up the drive selection and exit if no suitable
170
* drives are found */
171
@@ -971,8 +1106,10 @@
173
do_touchpad_osd_action (GsdMediaKeysManager *manager, gboolean state)
175
- show_osd (manager, state ? "input-touchpad-symbolic"
176
- : "touchpad-disabled-symbolic", NULL, -1);
177
+ if (!ubuntu_osd_notification_show_icon ((!state) ? "touchpad-disabled-symbolic" : "input-touchpad-symbolic", "Touchpad")) {
178
+ show_osd (manager, state ? "input-touchpad-symbolic"
179
+ : "touchpad-disabled-symbolic", NULL, -1);
184
@@ -1026,12 +1163,10 @@
185
const GvcMixerStreamPort *port;
189
- vol = (int) (100 * (double) vol / PA_VOLUME_NORM);
190
- vol = CLAMP (vol, 0, 100);
194
+ if (ubuntu_osd_notification_show_volume (manager, vol, muted))
197
+ vol = CLAMP (vol, 0, 100);
199
icon = get_icon_name_for_volume (!GVC_IS_MIXER_SINK (stream), muted, vol);
200
port = gvc_mixer_stream_get_port (stream);
201
@@ -1044,6 +1179,7 @@
202
show_osd (manager, icon, NULL, vol);
206
if (quiet == FALSE && sound_changed != FALSE && muted == FALSE) {
207
ca_context_change_device (manager->priv->ca,
208
gvc_mixer_stream_get_name (stream));
209
@@ -1173,7 +1309,7 @@
211
GvcMixerStream *stream;
212
gboolean old_muted, new_muted;
213
- guint old_vol, new_vol, norm_vol_step;
214
+ guint old_vol, new_vol, norm_vol_step, osd_vol;
215
gboolean sound_changed;
217
/* Find the stream that corresponds to the device, if any */
218
@@ -1231,7 +1367,16 @@
222
- update_dialog (manager, stream, new_vol, new_muted, sound_changed, quiet);
223
+ if (type == VOLUME_DOWN_KEY && old_vol == 0 && old_muted)
225
+ else if (type == VOLUME_UP_KEY && old_vol == PA_VOLUME_NORM && !old_muted)
227
+ else if (!new_muted)
228
+ osd_vol = (int) (100 * (double) new_vol / PA_VOLUME_NORM);
232
+ update_dialog (manager, stream, osd_vol, new_muted, sound_changed, quiet);
236
@@ -1559,8 +1704,11 @@
239
do_multimedia_player_action (GsdMediaKeysManager *manager,
244
+ ubuntu_osd_notification_show_icon (icon, key);
245
return gsd_media_player_key_pressed (manager, key);
248
@@ -1809,7 +1957,8 @@
249
GError *error = NULL;
251
GVariant *new_percentage;
252
- GsdMediaKeysManager *manager = GSD_MEDIA_KEYS_MANAGER (user_data);
253
+ GsdBrightnessActionData *data = (GsdBrightnessActionData *) user_data;
254
+ GsdMediaKeysManager *manager = data->manager;
256
new_percentage = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object),
258
@@ -1817,16 +1966,62 @@
259
g_warning ("Failed to set new screen percentage: %s",
261
g_error_free (error);
266
/* update the dialog with the new value */
267
g_variant_get (new_percentage, "(u)", &percentage);
268
- show_osd (manager, "display-brightness-symbolic", NULL, percentage);
269
+ guint osd_percentage;
271
+ if (data->old_percentage == 100 && data->type == SCREEN_BRIGHTNESS_UP_KEY)
272
+ osd_percentage = 101;
273
+ else if (data->old_percentage == 0 && data->type == SCREEN_BRIGHTNESS_DOWN_KEY)
274
+ osd_percentage = -1;
276
+ osd_percentage = CLAMP (percentage, 0, 100);
278
+ if (!ubuntu_osd_notification_show_brightness (manager, osd_percentage)) {
279
+ show_osd (manager, "display-brightness-symbolic", NULL, percentage);
282
g_variant_unref (new_percentage);
286
+do_screen_brightness_action_real (GObject *source_object,
288
+ gpointer user_data)
290
+ GsdBrightnessActionData *data = (GsdBrightnessActionData *) user_data;
291
+ GsdMediaKeysManager *manager = data->manager;
292
+ GError *error = NULL;
294
+ GVariant *old_percentage = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object),
296
+ if (old_percentage == NULL) {
297
+ g_warning ("Failed to get old screen percentage: %s", error->message);
298
+ g_error_free (error);
303
+ g_variant_get (old_percentage, "(u)", &data->old_percentage);
305
+ /* call into the power plugin */
306
+ g_dbus_proxy_call (manager->priv->power_screen_proxy,
307
+ data->type == SCREEN_BRIGHTNESS_UP_KEY ? "StepUp" : "StepDown",
309
+ G_DBUS_CALL_FLAGS_NONE,
315
+ g_variant_unref (old_percentage);
319
do_screen_brightness_action (GsdMediaKeysManager *manager,
322
@@ -1836,15 +2031,18 @@
326
- /* call into the power plugin */
327
+ GsdBrightnessActionData *data = g_new0 (GsdBrightnessActionData, 1);
328
+ data->manager = manager;
331
g_dbus_proxy_call (manager->priv->power_screen_proxy,
332
- type == SCREEN_BRIGHTNESS_UP_KEY ? "StepUp" : "StepDown",
335
G_DBUS_CALL_FLAGS_NONE,
340
+ do_screen_brightness_action_real,
345
@@ -1868,7 +2066,12 @@
347
/* update the dialog with the new value */
348
g_variant_get (new_percentage, "(u)", &percentage);
349
- show_osd (manager, "keyboard-brightness-symbolic", NULL, percentage);
351
+ /* FIXME: No overshoot effect for keyboard, as the power plugin has no interface
352
+ * to get the old brightness */
353
+ if (!ubuntu_osd_notification_show_kb_backlight (manager, CLAMP (percentage, 0, 100))) {
354
+ show_osd (manager, "keyboard-brightness-symbolic", NULL, percentage);
356
g_variant_unref (new_percentage);
359
@@ -2017,23 +2220,23 @@
360
do_execute_desktop_or_desktop (manager, "gcalctool.desktop", "gnome-calculator.desktop", timestamp);
363
- return do_multimedia_player_action (manager, "Play");
364
+ return do_multimedia_player_action (manager, NULL, "Play");
366
- return do_multimedia_player_action (manager, "Pause");
367
+ return do_multimedia_player_action (manager, NULL, "Pause");
369
- return do_multimedia_player_action (manager, "Stop");
370
+ return do_multimedia_player_action (manager, NULL, "Stop");
372
- return do_multimedia_player_action (manager, "Previous");
373
+ return do_multimedia_player_action (manager, NULL, "Previous");
375
- return do_multimedia_player_action (manager, "Next");
376
+ return do_multimedia_player_action (manager, NULL, "Next");
378
- return do_multimedia_player_action (manager, "Rewind");
379
+ return do_multimedia_player_action (manager, NULL, "Rewind");
381
- return do_multimedia_player_action (manager, "FastForward");
382
+ return do_multimedia_player_action (manager, NULL, "FastForward");
384
- return do_multimedia_player_action (manager, "Repeat");
385
+ return do_multimedia_player_action (manager, NULL, "Repeat");
387
- return do_multimedia_player_action (manager, "Shuffle");
388
+ return do_multimedia_player_action (manager, NULL, "Shuffle");
390
do_video_out_action (manager, timestamp);
392
@@ -2376,6 +2579,24 @@
393
g_clear_pointer (&priv->introspection_data, g_dbus_node_info_unref);
394
g_clear_object (&priv->connection);
396
+ if (priv->volume_notification != NULL) {
397
+ notify_notification_close (priv->volume_notification, NULL);
398
+ g_object_unref (priv->volume_notification);
399
+ priv->volume_notification = NULL;
402
+ if (priv->brightness_notification != NULL) {
403
+ notify_notification_close (priv->brightness_notification, NULL);
404
+ g_object_unref (priv->brightness_notification);
405
+ priv->brightness_notification = NULL;
408
+ if (priv->kb_backlight_notification != NULL) {
409
+ notify_notification_close (priv->kb_backlight_notification, NULL);
410
+ g_object_unref (priv->kb_backlight_notification);
411
+ priv->kb_backlight_notification = NULL;
414
if (priv->keys != NULL) {
415
for (i = 0; i < priv->keys->len; ++i) {
420
dnl - media-keys plugin stuff
421
dnl ---------------------------------------------------------------------------
423
-PKG_CHECK_MODULES(MEDIA_KEYS, [gio-unix-2.0 libpulse >= $PA_REQUIRED_VERSION $GUDEV_PKG libpulse-mainloop-glib >= $PA_REQUIRED_VERSION libcanberra-gtk3])
424
+PKG_CHECK_MODULES(MEDIA_KEYS, [gio-unix-2.0 libpulse >= $PA_REQUIRED_VERSION $GUDEV_PKG libpulse-mainloop-glib >= $PA_REQUIRED_VERSION libcanberra-gtk3 libnotify])
425
PKG_CHECK_MODULES(GVC, [gobject-2.0 libpulse >= $PA_REQUIRED_VERSION libpulse-mainloop-glib >= $PA_REQUIRED_VERSION])
426
AM_CONDITIONAL(HAVE_INTROSPECTION, false)