~attente/gnome-settings-daemon/1318539

« back to all changes in this revision

Viewing changes to debian/patches/16_use_synchronous_notifications.patch

  • Committer: Tim Lunn
  • Date: 2014-05-12 08:41:47 UTC
  • Revision ID: tim@feathertop.org-20140512084147-kn3ngcx05yttyr96
* Drop all Unity patches and legacy features (LP: #1318539)
  - Keep schemas for background plugin, since they are used by u-s-d
* debian/patches: Refreshed
  - git_new_screencast_keybinding.patch
  - git_xsettings_segfaults.patch
* debian/control.in: Fix lintian warnings
  - gnome-settings-daemon-schemas add ${misc:Depends}
  - gnome-settings-daemon fix binNMUable error for gnome-settings-daemon-schemas
* Bump standards to 3.9.5 (No changes)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Description: Use synchronous notifications when they are supported
2
 
Author: ?
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
6
 
@@ -62,6 +62,8 @@
7
 
 #include "gvc-mixer-control.h"
8
 
 #include "gvc-mixer-sink.h"
9
 
 
10
 
+#include <libnotify/notify.h>
11
 
+
12
 
 #define GSD_MEDIA_KEYS_DBUS_PATH GSD_DBUS_PATH "/MediaKeys"
13
 
 #define GSD_MEDIA_KEYS_DBUS_NAME GSD_DBUS_NAME ".MediaKeys"
14
 
 
15
 
@@ -185,6 +187,11 @@
16
 
         GCancellable    *cancellable;
17
 
 
18
 
         guint            start_idle_id;
19
 
+
20
 
+        /* Ubuntu notifications */
21
 
+        NotifyNotification *volume_notification;
22
 
+        NotifyNotification *brightness_notification;
23
 
+        NotifyNotification *kb_backlight_notification;
24
 
 };
25
 
 
26
 
 static void     gsd_media_keys_manager_class_init  (GsdMediaKeysManagerClass *klass);
27
 
@@ -203,6 +210,132 @@
28
 
 
29
 
 static gpointer manager_object = NULL;
30
 
 
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"
34
 
+
35
 
+typedef struct {
36
 
+        GsdMediaKeysManager *manager;
37
 
+        MediaKeyType type;
38
 
+        guint old_percentage;
39
 
+
40
 
+} GsdBrightnessActionData;
41
 
+
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",
47
 
+        NULL
48
 
+};
49
 
+
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",
56
 
+        NULL
57
 
+};
58
 
+
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",
65
 
+        NULL
66
 
+};
67
 
+
68
 
+static const char *
69
 
+calculate_icon_name (gint value, const char **icon_names)
70
 
+{
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);
75
 
+
76
 
+        return icon_names[s];
77
 
+}
78
 
+
79
 
+static gboolean
80
 
+ubuntu_osd_notification_is_supported (void)
81
 
+{
82
 
+        GList *caps;
83
 
+        gboolean has_cap;
84
 
+
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);
88
 
+        g_list_free (caps);
89
 
+
90
 
+        return has_cap;
91
 
+}
92
 
+
93
 
+static gboolean
94
 
+ubuntu_osd_notification_show_icon (const char *icon,
95
 
+                                   const char *hint)
96
 
+{
97
 
+        if (!ubuntu_osd_notification_is_supported ())
98
 
+                return FALSE;
99
 
+
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);
103
 
+
104
 
+        gboolean res = notify_notification_show (notification, NULL);
105
 
+        g_object_unref (notification);
106
 
+
107
 
+        return res;
108
 
+}
109
 
+
110
 
+static gboolean
111
 
+ubuntu_osd_do_notification (NotifyNotification **notification,
112
 
+                            const char *hint,
113
 
+                            gint value,
114
 
+                            gboolean muted,
115
 
+                            const char **icon_names)
116
 
+{
117
 
+        if (!ubuntu_osd_notification_is_supported ())
118
 
+                return FALSE;
119
 
+
120
 
+        if (!*notification) {
121
 
+                *notification = notify_notification_new (" ", "", NULL);
122
 
+                notify_notification_set_hint_string (*notification, NOTIFY_CAP_PRIVATE_SYNCHRONOUS, hint);
123
 
+        }
124
 
+
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);
129
 
+
130
 
+        return notify_notification_show (*notification, NULL);
131
 
+}
132
 
+
133
 
+static gboolean
134
 
+ubuntu_osd_notification_show_volume (GsdMediaKeysManager *manager,
135
 
+                                     gint value,
136
 
+                                     gboolean muted)
137
 
+{
138
 
+        return ubuntu_osd_do_notification (&manager->priv->volume_notification,
139
 
+                                           "volume", value, muted, volume_icons);
140
 
+}
141
 
+
142
 
+static gboolean
143
 
+ubuntu_osd_notification_show_brightness (GsdMediaKeysManager *manager,
144
 
+                                         gint value)
145
 
+{
146
 
+        return ubuntu_osd_do_notification (&manager->priv->brightness_notification,
147
 
+                                           "brightness", value, value <= 0, brightness_icons);
148
 
+}
149
 
+
150
 
+static gboolean
151
 
+ubuntu_osd_notification_show_kb_backlight (GsdMediaKeysManager *manager,
152
 
+                                           gint value)
153
 
+{
154
 
+        return ubuntu_osd_do_notification (&manager->priv->kb_backlight_notification,
155
 
+                                           "keyboard", value, value <= 0, kb_backlight_icons);
156
 
+}
157
 
 
158
 
 static void
159
 
 media_key_free (MediaKey *key)
160
 
@@ -908,7 +1041,9 @@
161
 
         }
162
 
 
163
 
         /* Show OSD */
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);
167
 
+        }
168
 
 
169
 
         /* Clean up the drive selection and exit if no suitable
170
 
          * drives are found */
171
 
@@ -971,8 +1106,10 @@
172
 
 static void
173
 
 do_touchpad_osd_action (GsdMediaKeysManager *manager, gboolean state)
174
 
 {
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);
180
 
+        }
181
 
 }
182
 
 
183
 
 static void
184
 
@@ -1026,12 +1163,10 @@
185
 
         const GvcMixerStreamPort *port;
186
 
         const char *icon;
187
 
 
188
 
-        if (!muted) {
189
 
-                vol = (int) (100 * (double) vol / PA_VOLUME_NORM);
190
 
-                vol = CLAMP (vol, 0, 100);
191
 
-        } else {
192
 
-                vol = 0.0;
193
 
-        }
194
 
+        if (ubuntu_osd_notification_show_volume (manager, vol, muted))
195
 
+                goto done;
196
 
+
197
 
+        vol = CLAMP (vol, 0, 100);
198
 
 
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);
203
 
         }
204
 
 
205
 
+done:
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 @@
210
 
 {
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;
216
 
 
217
 
         /* Find the stream that corresponds to the device, if any */
218
 
@@ -1231,7 +1367,16 @@
219
 
                 }
220
 
         }
221
 
 
222
 
-        update_dialog (manager, stream, new_vol, new_muted, sound_changed, quiet);
223
 
+        if (type == VOLUME_DOWN_KEY && old_vol == 0 && old_muted)
224
 
+                osd_vol = -1;
225
 
+        else if (type == VOLUME_UP_KEY && old_vol == PA_VOLUME_NORM && !old_muted)
226
 
+                osd_vol = 101;
227
 
+        else if (!new_muted)
228
 
+                osd_vol = (int) (100 * (double) new_vol / PA_VOLUME_NORM);
229
 
+        else
230
 
+                osd_vol = 0;
231
 
+
232
 
+        update_dialog (manager, stream, osd_vol, new_muted, sound_changed, quiet);
233
 
 }
234
 
 
235
 
 static void
236
 
@@ -1559,8 +1704,11 @@
237
 
 
238
 
 static gboolean
239
 
 do_multimedia_player_action (GsdMediaKeysManager *manager,
240
 
+                             const char          *icon,
241
 
                              const char          *key)
242
 
 {
243
 
+        if (icon != NULL)
244
 
+                ubuntu_osd_notification_show_icon (icon, key);
245
 
         return gsd_media_player_key_pressed (manager, key);
246
 
 }
247
 
 
248
 
@@ -1809,7 +1957,8 @@
249
 
         GError *error = NULL;
250
 
         guint percentage;
251
 
         GVariant *new_percentage;
252
 
-        GsdMediaKeysManager *manager = GSD_MEDIA_KEYS_MANAGER (user_data);
253
 
+        GsdBrightnessActionData *data = (GsdBrightnessActionData *) user_data;
254
 
+        GsdMediaKeysManager *manager = data->manager;
255
 
 
256
 
         new_percentage = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object),
257
 
                                                    res, &error);
258
 
@@ -1817,16 +1966,62 @@
259
 
                 g_warning ("Failed to set new screen percentage: %s",
260
 
                            error->message);
261
 
                 g_error_free (error);
262
 
+                g_free (data);
263
 
                 return;
264
 
         }
265
 
 
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;
270
 
+
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;
275
 
+        else
276
 
+                osd_percentage = CLAMP (percentage, 0, 100);
277
 
+
278
 
+        if (!ubuntu_osd_notification_show_brightness (manager, osd_percentage)) {
279
 
+                show_osd (manager, "display-brightness-symbolic", NULL, percentage);
280
 
+        }
281
 
+        g_free (data);
282
 
         g_variant_unref (new_percentage);
283
 
 }
284
 
 
285
 
 static void
286
 
+do_screen_brightness_action_real (GObject       *source_object,
287
 
+                                  GAsyncResult  *res,
288
 
+                                  gpointer       user_data)
289
 
+{
290
 
+        GsdBrightnessActionData *data = (GsdBrightnessActionData *) user_data;
291
 
+        GsdMediaKeysManager *manager = data->manager;
292
 
+        GError *error = NULL;
293
 
+
294
 
+        GVariant *old_percentage = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object),
295
 
+                                                             res, &error);
296
 
+        if (old_percentage == NULL) {
297
 
+                g_warning ("Failed to get old screen percentage: %s", error->message);
298
 
+                g_error_free (error);
299
 
+                g_free (data);
300
 
+                return;
301
 
+        }
302
 
+
303
 
+        g_variant_get (old_percentage, "(u)", &data->old_percentage);
304
 
+
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",
308
 
+                           NULL,
309
 
+                           G_DBUS_CALL_FLAGS_NONE,
310
 
+                           -1,
311
 
+                           NULL,
312
 
+                           update_screen_cb,
313
 
+                           data);
314
 
+
315
 
+        g_variant_unref (old_percentage);
316
 
+}
317
 
+
318
 
+static void
319
 
 do_screen_brightness_action (GsdMediaKeysManager *manager,
320
 
                              MediaKeyType type)
321
 
 {
322
 
@@ -1836,15 +2031,18 @@
323
 
                 return;
324
 
         }
325
 
 
326
 
-        /* call into the power plugin */
327
 
+        GsdBrightnessActionData *data = g_new0 (GsdBrightnessActionData, 1);
328
 
+        data->manager = manager;
329
 
+        data->type = type;
330
 
+
331
 
         g_dbus_proxy_call (manager->priv->power_screen_proxy,
332
 
-                           type == SCREEN_BRIGHTNESS_UP_KEY ? "StepUp" : "StepDown",
333
 
+                           "GetPercentage",
334
 
                            NULL,
335
 
                            G_DBUS_CALL_FLAGS_NONE,
336
 
                            -1,
337
 
                            NULL,
338
 
-                           update_screen_cb,
339
 
-                           manager);
340
 
+                           do_screen_brightness_action_real,
341
 
+                           data);
342
 
 }
343
 
 
344
 
 static void
345
 
@@ -1868,7 +2066,12 @@
346
 
 
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);
350
 
+
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);
355
 
+        }
356
 
         g_variant_unref (new_percentage);
357
 
 }
358
 
 
359
 
@@ -2017,23 +2220,23 @@
360
 
                 do_execute_desktop_or_desktop (manager, "gcalctool.desktop", "gnome-calculator.desktop", timestamp);
361
 
                 break;
362
 
         case PLAY_KEY:
363
 
-                return do_multimedia_player_action (manager, "Play");
364
 
+                return do_multimedia_player_action (manager, NULL, "Play");
365
 
         case PAUSE_KEY:
366
 
-                return do_multimedia_player_action (manager, "Pause");
367
 
+                return do_multimedia_player_action (manager, NULL, "Pause");
368
 
         case STOP_KEY:
369
 
-                return do_multimedia_player_action (manager, "Stop");
370
 
+                return do_multimedia_player_action (manager, NULL, "Stop");
371
 
         case PREVIOUS_KEY:
372
 
-                return do_multimedia_player_action (manager, "Previous");
373
 
+                return do_multimedia_player_action (manager, NULL, "Previous");
374
 
         case NEXT_KEY:
375
 
-                return do_multimedia_player_action (manager, "Next");
376
 
+                return do_multimedia_player_action (manager, NULL, "Next");
377
 
         case REWIND_KEY:
378
 
-                return do_multimedia_player_action (manager, "Rewind");
379
 
+                return do_multimedia_player_action (manager, NULL, "Rewind");
380
 
         case FORWARD_KEY:
381
 
-                return do_multimedia_player_action (manager, "FastForward");
382
 
+                return do_multimedia_player_action (manager, NULL, "FastForward");
383
 
         case REPEAT_KEY:
384
 
-                return do_multimedia_player_action (manager, "Repeat");
385
 
+                return do_multimedia_player_action (manager, NULL, "Repeat");
386
 
         case RANDOM_KEY:
387
 
-                return do_multimedia_player_action (manager, "Shuffle");
388
 
+                return do_multimedia_player_action (manager, NULL, "Shuffle");
389
 
         case VIDEO_OUT_KEY:
390
 
                 do_video_out_action (manager, timestamp);
391
 
                 break;
392
 
@@ -2376,6 +2579,24 @@
393
 
         g_clear_pointer (&priv->introspection_data, g_dbus_node_info_unref);
394
 
         g_clear_object (&priv->connection);
395
 
 
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;
400
 
+        }
401
 
+
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;
406
 
+        }
407
 
+
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;
412
 
+        }
413
 
+
414
 
         if (priv->keys != NULL) {
415
 
                 for (i = 0; i < priv->keys->len; ++i) {
416
 
                         MediaKey *key;
417
 
--- a/configure.ac
418
 
+++ b/configure.ac
419
 
@@ -201,7 +201,7 @@
420
 
 dnl - media-keys plugin stuff
421
 
 dnl ---------------------------------------------------------------------------
422
 
 
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)
427