Merge lp:~jm-leddy/ubuntu/precise/gnome-settings-daemon/micmute into lp:ubuntu/precise-proposed/gnome-settings-daemon
- Precise (12.04)
- micmute
- Merge into precise-proposed
Proposed by
James M. Leddy
Status: | Merged | ||||
---|---|---|---|---|---|
Merge reported by: | Sebastien Bacher | ||||
Merged at revision: | not available | ||||
Proposed branch: | lp:~jm-leddy/ubuntu/precise/gnome-settings-daemon/micmute | ||||
Merge into: | lp:ubuntu/precise-proposed/gnome-settings-daemon | ||||
Diff against target: |
3533 lines (+3328/-16) 8 files modified
.pc/64_micmute.patch/plugins/media-keys/gsd-media-keys-manager.c (+2743/-0) .pc/64_micmute.patch/plugins/media-keys/shortcuts-list.h (+152/-0) .pc/applied-patches (+1/-0) debian/changelog (+8/-0) debian/patches/64_micmute.patch (+291/-0) debian/patches/series (+1/-0) plugins/media-keys/gsd-media-keys-manager.c (+130/-16) plugins/media-keys/shortcuts-list.h (+2/-0) |
||||
To merge this branch: | bzr merge lp:~jm-leddy/ubuntu/precise/gnome-settings-daemon/micmute | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Sebastien Bacher | Needs Fixing | ||
Review via email: mp+188676@code.launchpad.net |
This proposal supersedes a proposal from 2013-10-01.
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory '.pc/64_micmute.patch' | |||
2 | === added file '.pc/64_micmute.patch/.timestamp' | |||
3 | === added directory '.pc/64_micmute.patch/plugins' | |||
4 | === added directory '.pc/64_micmute.patch/plugins/media-keys' | |||
5 | === added file '.pc/64_micmute.patch/plugins/media-keys/gsd-media-keys-manager.c' | |||
6 | --- .pc/64_micmute.patch/plugins/media-keys/gsd-media-keys-manager.c 1970-01-01 00:00:00 +0000 | |||
7 | +++ .pc/64_micmute.patch/plugins/media-keys/gsd-media-keys-manager.c 2013-10-01 18:19:26 +0000 | |||
8 | @@ -0,0 +1,2743 @@ | |||
9 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- | ||
10 | 2 | * | ||
11 | 3 | * Copyright (C) 2001-2003 Bastien Nocera <hadess@hadess.net> | ||
12 | 4 | * Copyright (C) 2006-2007 William Jon McCann <mccann@jhu.edu> | ||
13 | 5 | * | ||
14 | 6 | * This program is free software; you can redistribute it and/or modify | ||
15 | 7 | * it under the terms of the GNU General Public License as published by | ||
16 | 8 | * the Free Software Foundation; either version 2 of the License, or | ||
17 | 9 | * (at your option) any later version. | ||
18 | 10 | * | ||
19 | 11 | * This program is distributed in the hope that it will be useful, | ||
20 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
22 | 14 | * GNU General Public License for more details. | ||
23 | 15 | * | ||
24 | 16 | * You should have received a copy of the GNU General Public License | ||
25 | 17 | * along with this program; if not, write to the Free Software | ||
26 | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
27 | 19 | * | ||
28 | 20 | */ | ||
29 | 21 | |||
30 | 22 | #include "config.h" | ||
31 | 23 | |||
32 | 24 | #include <sys/types.h> | ||
33 | 25 | #include <sys/wait.h> | ||
34 | 26 | #include <stdlib.h> | ||
35 | 27 | #include <stdio.h> | ||
36 | 28 | #include <unistd.h> | ||
37 | 29 | #include <string.h> | ||
38 | 30 | #include <errno.h> | ||
39 | 31 | #include <math.h> | ||
40 | 32 | |||
41 | 33 | #include <locale.h> | ||
42 | 34 | |||
43 | 35 | #include <glib.h> | ||
44 | 36 | #include <glib/gi18n.h> | ||
45 | 37 | #include <gio/gio.h> | ||
46 | 38 | #include <gdk/gdk.h> | ||
47 | 39 | #include <gdk/gdkx.h> | ||
48 | 40 | #include <gtk/gtk.h> | ||
49 | 41 | #include <gio/gdesktopappinfo.h> | ||
50 | 42 | #include <gconf/gconf-client.h> | ||
51 | 43 | |||
52 | 44 | #ifdef HAVE_GUDEV | ||
53 | 45 | #include <gudev/gudev.h> | ||
54 | 46 | #endif | ||
55 | 47 | |||
56 | 48 | #include "gnome-settings-profile.h" | ||
57 | 49 | #include "gsd-marshal.h" | ||
58 | 50 | #include "gsd-media-keys-manager.h" | ||
59 | 51 | |||
60 | 52 | #include "shortcuts-list.h" | ||
61 | 53 | #include "gsd-media-keys-window.h" | ||
62 | 54 | #include "gsd-input-helper.h" | ||
63 | 55 | #include "gsd-enums.h" | ||
64 | 56 | |||
65 | 57 | #include <canberra.h> | ||
66 | 58 | #include <pulse/pulseaudio.h> | ||
67 | 59 | #include "gvc-mixer-control.h" | ||
68 | 60 | |||
69 | 61 | #include <libnotify/notify.h> | ||
70 | 62 | |||
71 | 63 | #define GSD_DBUS_PATH "/org/gnome/SettingsDaemon" | ||
72 | 64 | #define GSD_DBUS_NAME "org.gnome.SettingsDaemon" | ||
73 | 65 | #define GSD_MEDIA_KEYS_DBUS_PATH GSD_DBUS_PATH "/MediaKeys" | ||
74 | 66 | #define GSD_MEDIA_KEYS_DBUS_NAME GSD_DBUS_NAME ".MediaKeys" | ||
75 | 67 | |||
76 | 68 | #define GNOME_SESSION_DBUS_NAME "org.gnome.SessionManager" | ||
77 | 69 | #define GNOME_SESSION_DBUS_PATH "/org/gnome/SessionManager" | ||
78 | 70 | #define GNOME_SESSION_DBUS_INTERFACE "org.gnome.SessionManager" | ||
79 | 71 | |||
80 | 72 | #define GNOME_KEYRING_DBUS_NAME "org.gnome.keyring" | ||
81 | 73 | #define GNOME_KEYRING_DBUS_PATH "/org/gnome/keyring/daemon" | ||
82 | 74 | #define GNOME_KEYRING_DBUS_INTERFACE "org.gnome.keyring.Daemon" | ||
83 | 75 | |||
84 | 76 | #define GCONF_BINDING_DIR "/desktop/gnome/keybindings" | ||
85 | 77 | |||
86 | 78 | static const gchar introspection_xml[] = | ||
87 | 79 | "<node>" | ||
88 | 80 | " <interface name='org.gnome.SettingsDaemon.MediaKeys'>" | ||
89 | 81 | " <annotation name='org.freedesktop.DBus.GLib.CSymbol' value='gsd_media_keys_manager'/>" | ||
90 | 82 | " <method name='GrabMediaPlayerKeys'>" | ||
91 | 83 | " <arg name='application' direction='in' type='s'/>" | ||
92 | 84 | " <arg name='time' direction='in' type='u'/>" | ||
93 | 85 | " </method>" | ||
94 | 86 | " <method name='ReleaseMediaPlayerKeys'>" | ||
95 | 87 | " <arg name='application' direction='in' type='s'/>" | ||
96 | 88 | " </method>" | ||
97 | 89 | " <signal name='MediaPlayerKeyPressed'>" | ||
98 | 90 | " <arg name='application' type='s'/>" | ||
99 | 91 | " <arg name='key' type='s'/>" | ||
100 | 92 | " </signal>" | ||
101 | 93 | " </interface>" | ||
102 | 94 | "</node>"; | ||
103 | 95 | |||
104 | 96 | #define SETTINGS_INTERFACE_DIR "org.gnome.desktop.interface" | ||
105 | 97 | #define SETTINGS_POWER_DIR "org.gnome.settings-daemon.plugins.power" | ||
106 | 98 | #define SETTINGS_XSETTINGS_DIR "org.gnome.settings-daemon.plugins.xsettings" | ||
107 | 99 | #define SETTINGS_TOUCHPAD_DIR "org.gnome.settings-daemon.peripherals.touchpad" | ||
108 | 100 | #define TOUCHPAD_ENABLED_KEY "touchpad-enabled" | ||
109 | 101 | #define HIGH_CONTRAST "HighContrast" | ||
110 | 102 | |||
111 | 103 | #define VOLUME_STEP 6 /* percents for one volume button press */ | ||
112 | 104 | #define MAX_VOLUME 65536.0 | ||
113 | 105 | |||
114 | 106 | #define GSD_MEDIA_KEYS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_MEDIA_KEYS_MANAGER, GsdMediaKeysManagerPrivate)) | ||
115 | 107 | |||
116 | 108 | typedef struct { | ||
117 | 109 | char *application; | ||
118 | 110 | char *name; | ||
119 | 111 | guint32 time; | ||
120 | 112 | guint watch_id; | ||
121 | 113 | } MediaPlayer; | ||
122 | 114 | |||
123 | 115 | typedef struct { | ||
124 | 116 | MediaKeyType key_type; | ||
125 | 117 | const char *settings_key; | ||
126 | 118 | const char *hard_coded; | ||
127 | 119 | char *gconf_dir; | ||
128 | 120 | char *custom_command; | ||
129 | 121 | Key *key; | ||
130 | 122 | } MediaKey; | ||
131 | 123 | |||
132 | 124 | struct GsdMediaKeysManagerPrivate | ||
133 | 125 | { | ||
134 | 126 | /* Volume bits */ | ||
135 | 127 | GvcMixerControl *volume; | ||
136 | 128 | GvcMixerStream *stream; | ||
137 | 129 | ca_context *ca; | ||
138 | 130 | GtkSettings *gtksettings; | ||
139 | 131 | #ifdef HAVE_GUDEV | ||
140 | 132 | GHashTable *streams; /* key = X device ID, value = stream id */ | ||
141 | 133 | GUdevClient *udev_client; | ||
142 | 134 | #endif /* HAVE_GUDEV */ | ||
143 | 135 | |||
144 | 136 | GtkWidget *dialog; | ||
145 | 137 | GSettings *settings; | ||
146 | 138 | |||
147 | 139 | GPtrArray *keys; | ||
148 | 140 | GConfClient *gconf; | ||
149 | 141 | guint gconf_id; | ||
150 | 142 | |||
151 | 143 | /* HighContrast theme settings */ | ||
152 | 144 | GSettings *interface_settings; | ||
153 | 145 | char *icon_theme; | ||
154 | 146 | char *gtk_theme; | ||
155 | 147 | |||
156 | 148 | /* Power stuff */ | ||
157 | 149 | GSettings *power_settings; | ||
158 | 150 | GDBusProxy *upower_proxy; | ||
159 | 151 | GDBusProxy *power_screen_proxy; | ||
160 | 152 | GDBusProxy *power_keyboard_proxy; | ||
161 | 153 | |||
162 | 154 | /* Multihead stuff */ | ||
163 | 155 | GdkScreen *current_screen; | ||
164 | 156 | GSList *screens; | ||
165 | 157 | int opcode; | ||
166 | 158 | |||
167 | 159 | GList *media_players; | ||
168 | 160 | |||
169 | 161 | GDBusNodeInfo *introspection_data; | ||
170 | 162 | GDBusConnection *connection; | ||
171 | 163 | GCancellable *bus_cancellable; | ||
172 | 164 | GDBusProxy *xrandr_proxy; | ||
173 | 165 | GCancellable *cancellable; | ||
174 | 166 | |||
175 | 167 | guint start_idle_id; | ||
176 | 168 | |||
177 | 169 | /* Ubuntu notifications */ | ||
178 | 170 | NotifyNotification *volume_notification; | ||
179 | 171 | NotifyNotification *brightness_notification; | ||
180 | 172 | NotifyNotification *kb_backlight_notification; | ||
181 | 173 | }; | ||
182 | 174 | |||
183 | 175 | static void gsd_media_keys_manager_class_init (GsdMediaKeysManagerClass *klass); | ||
184 | 176 | static void gsd_media_keys_manager_init (GsdMediaKeysManager *media_keys_manager); | ||
185 | 177 | static void gsd_media_keys_manager_finalize (GObject *object); | ||
186 | 178 | static void register_manager (GsdMediaKeysManager *manager); | ||
187 | 179 | G_DEFINE_TYPE (GsdMediaKeysManager, gsd_media_keys_manager, G_TYPE_OBJECT) | ||
188 | 180 | |||
189 | 181 | static gpointer manager_object = NULL; | ||
190 | 182 | |||
191 | 183 | #define NOTIFY_CAP_PRIVATE_SYNCHRONOUS "x-canonical-private-synchronous" | ||
192 | 184 | #define NOTIFY_CAP_PRIVATE_ICON_ONLY "x-canonical-private-icon-only" | ||
193 | 185 | #define NOTIFY_HINT_TRUE "true" | ||
194 | 186 | |||
195 | 187 | typedef struct { | ||
196 | 188 | GsdMediaKeysManager *manager; | ||
197 | 189 | MediaKeyType type; | ||
198 | 190 | guint old_percentage; | ||
199 | 191 | |||
200 | 192 | } GsdBrightnessActionData; | ||
201 | 193 | |||
202 | 194 | static const char *volume_icons[] = { | ||
203 | 195 | "notification-audio-volume-muted", | ||
204 | 196 | "notification-audio-volume-low", | ||
205 | 197 | "notification-audio-volume-medium", | ||
206 | 198 | "notification-audio-volume-high", | ||
207 | 199 | NULL | ||
208 | 200 | }; | ||
209 | 201 | |||
210 | 202 | static const char *brightness_icons[] = { | ||
211 | 203 | "notification-display-brightness-off", | ||
212 | 204 | "notification-display-brightness-low", | ||
213 | 205 | "notification-display-brightness-medium", | ||
214 | 206 | "notification-display-brightness-high", | ||
215 | 207 | "notification-display-brightness-full", | ||
216 | 208 | NULL | ||
217 | 209 | }; | ||
218 | 210 | |||
219 | 211 | static const char *kb_backlight_icons[] = { | ||
220 | 212 | "notification-keyboard-brightness-off", | ||
221 | 213 | "notification-keyboard-brightness-low", | ||
222 | 214 | "notification-keyboard-brightness-medium", | ||
223 | 215 | "notification-keyboard-brightness-high", | ||
224 | 216 | "notification-keyboard-brightness-full", | ||
225 | 217 | NULL | ||
226 | 218 | }; | ||
227 | 219 | |||
228 | 220 | static const char * | ||
229 | 221 | calculate_icon_name (gint value, const char **icon_names) | ||
230 | 222 | { | ||
231 | 223 | value = CLAMP (value, 0, 100); | ||
232 | 224 | gint length = g_strv_length (icon_names); | ||
233 | 225 | gint s = (length - 1) * value / 100 + 1; | ||
234 | 226 | s = CLAMP (s, 1, length - 1); | ||
235 | 227 | |||
236 | 228 | return icon_names[s]; | ||
237 | 229 | } | ||
238 | 230 | |||
239 | 231 | static gboolean | ||
240 | 232 | ubuntu_osd_notification_is_supported (void) | ||
241 | 233 | { | ||
242 | 234 | GList *caps; | ||
243 | 235 | gboolean has_cap; | ||
244 | 236 | |||
245 | 237 | caps = notify_get_server_caps (); | ||
246 | 238 | has_cap = (g_list_find_custom (caps, NOTIFY_CAP_PRIVATE_SYNCHRONOUS, (GCompareFunc) g_strcmp0) != NULL); | ||
247 | 239 | g_list_foreach (caps, (GFunc) g_free, NULL); | ||
248 | 240 | g_list_free (caps); | ||
249 | 241 | |||
250 | 242 | return has_cap; | ||
251 | 243 | } | ||
252 | 244 | |||
253 | 245 | static gboolean | ||
254 | 246 | ubuntu_osd_notification_show_icon (const char *icon, | ||
255 | 247 | const char *hint) | ||
256 | 248 | { | ||
257 | 249 | if (!ubuntu_osd_notification_is_supported ()) | ||
258 | 250 | return FALSE; | ||
259 | 251 | |||
260 | 252 | NotifyNotification *notification = notify_notification_new (" ", "", icon); | ||
261 | 253 | notify_notification_set_hint_string (notification, NOTIFY_CAP_PRIVATE_SYNCHRONOUS, hint); | ||
262 | 254 | notify_notification_set_hint_string (notification, NOTIFY_CAP_PRIVATE_ICON_ONLY, NOTIFY_HINT_TRUE); | ||
263 | 255 | |||
264 | 256 | gboolean res = notify_notification_show (notification, NULL); | ||
265 | 257 | g_object_unref (notification); | ||
266 | 258 | |||
267 | 259 | return res; | ||
268 | 260 | } | ||
269 | 261 | |||
270 | 262 | static gboolean | ||
271 | 263 | ubuntu_osd_do_notification (NotifyNotification **notification, | ||
272 | 264 | const char *hint, | ||
273 | 265 | gint value, | ||
274 | 266 | gboolean muted, | ||
275 | 267 | const char **icon_names) | ||
276 | 268 | { | ||
277 | 269 | if (!ubuntu_osd_notification_is_supported ()) | ||
278 | 270 | return FALSE; | ||
279 | 271 | |||
280 | 272 | if (!*notification) { | ||
281 | 273 | *notification = notify_notification_new (" ", "", NULL); | ||
282 | 274 | notify_notification_set_hint_string (*notification, NOTIFY_CAP_PRIVATE_SYNCHRONOUS, hint); | ||
283 | 275 | } | ||
284 | 276 | |||
285 | 277 | value = CLAMP (value, -1, 101); | ||
286 | 278 | const char *icon = muted ? icon_names[0] : calculate_icon_name (value, icon_names); | ||
287 | 279 | notify_notification_set_hint_int32 (*notification, "value", value); | ||
288 | 280 | notify_notification_update (*notification, " ", "", icon); | ||
289 | 281 | |||
290 | 282 | return notify_notification_show (*notification, NULL); | ||
291 | 283 | } | ||
292 | 284 | |||
293 | 285 | static gboolean | ||
294 | 286 | ubuntu_osd_notification_show_volume (GsdMediaKeysManager *manager, | ||
295 | 287 | gint value, | ||
296 | 288 | gboolean muted) | ||
297 | 289 | { | ||
298 | 290 | return ubuntu_osd_do_notification (&manager->priv->volume_notification, | ||
299 | 291 | "volume", value, muted, volume_icons); | ||
300 | 292 | } | ||
301 | 293 | |||
302 | 294 | static gboolean | ||
303 | 295 | ubuntu_osd_notification_show_brightness (GsdMediaKeysManager *manager, | ||
304 | 296 | gint value) | ||
305 | 297 | { | ||
306 | 298 | return ubuntu_osd_do_notification (&manager->priv->brightness_notification, | ||
307 | 299 | "brightness", value, value <= 0, brightness_icons); | ||
308 | 300 | } | ||
309 | 301 | |||
310 | 302 | static gboolean | ||
311 | 303 | ubuntu_osd_notification_show_kb_backlight (GsdMediaKeysManager *manager, | ||
312 | 304 | gint value) | ||
313 | 305 | { | ||
314 | 306 | return ubuntu_osd_do_notification (&manager->priv->kb_backlight_notification, | ||
315 | 307 | "keyboard", value, value <= 0, kb_backlight_icons); | ||
316 | 308 | } | ||
317 | 309 | |||
318 | 310 | static void | ||
319 | 311 | init_screens (GsdMediaKeysManager *manager) | ||
320 | 312 | { | ||
321 | 313 | GdkDisplay *display; | ||
322 | 314 | int i; | ||
323 | 315 | |||
324 | 316 | display = gdk_display_get_default (); | ||
325 | 317 | for (i = 0; i < gdk_display_get_n_screens (display); i++) { | ||
326 | 318 | GdkScreen *screen; | ||
327 | 319 | |||
328 | 320 | screen = gdk_display_get_screen (display, i); | ||
329 | 321 | if (screen == NULL) { | ||
330 | 322 | continue; | ||
331 | 323 | } | ||
332 | 324 | manager->priv->screens = g_slist_append (manager->priv->screens, screen); | ||
333 | 325 | } | ||
334 | 326 | |||
335 | 327 | manager->priv->current_screen = manager->priv->screens->data; | ||
336 | 328 | } | ||
337 | 329 | |||
338 | 330 | static void | ||
339 | 331 | media_key_free (MediaKey *key) | ||
340 | 332 | { | ||
341 | 333 | if (key == NULL) | ||
342 | 334 | return; | ||
343 | 335 | g_free (key->gconf_dir); | ||
344 | 336 | g_free (key->custom_command); | ||
345 | 337 | free_key (key->key); | ||
346 | 338 | g_free (key); | ||
347 | 339 | } | ||
348 | 340 | |||
349 | 341 | static char * | ||
350 | 342 | get_term_command (GsdMediaKeysManager *manager) | ||
351 | 343 | { | ||
352 | 344 | char *cmd_term, *cmd_args;; | ||
353 | 345 | char *cmd = NULL; | ||
354 | 346 | GSettings *settings; | ||
355 | 347 | |||
356 | 348 | settings = g_settings_new ("org.gnome.desktop.default-applications.terminal"); | ||
357 | 349 | cmd_term = g_settings_get_string (settings, "exec"); | ||
358 | 350 | if (cmd_term[0] == '\0') | ||
359 | 351 | cmd_term = g_strdup ("gnome-terminal"); | ||
360 | 352 | |||
361 | 353 | cmd_args = g_settings_get_string (settings, "exec-arg"); | ||
362 | 354 | if (strcmp (cmd_term, "") != 0) { | ||
363 | 355 | cmd = g_strdup_printf ("%s %s -e", cmd_term, cmd_args); | ||
364 | 356 | } else { | ||
365 | 357 | cmd = g_strdup_printf ("%s -e", cmd_term); | ||
366 | 358 | } | ||
367 | 359 | |||
368 | 360 | g_free (cmd_args); | ||
369 | 361 | g_free (cmd_term); | ||
370 | 362 | g_object_unref (settings); | ||
371 | 363 | |||
372 | 364 | return cmd; | ||
373 | 365 | } | ||
374 | 366 | |||
375 | 367 | static char ** | ||
376 | 368 | get_keyring_env (GsdMediaKeysManager *manager) | ||
377 | 369 | { | ||
378 | 370 | GError *error = NULL; | ||
379 | 371 | GVariant *variant, *item; | ||
380 | 372 | GVariantIter *iter; | ||
381 | 373 | char **envp; | ||
382 | 374 | |||
383 | 375 | variant = g_dbus_connection_call_sync (manager->priv->connection, | ||
384 | 376 | GNOME_KEYRING_DBUS_NAME, | ||
385 | 377 | GNOME_KEYRING_DBUS_PATH, | ||
386 | 378 | GNOME_KEYRING_DBUS_INTERFACE, | ||
387 | 379 | "GetEnvironment", | ||
388 | 380 | NULL, | ||
389 | 381 | NULL, | ||
390 | 382 | G_DBUS_CALL_FLAGS_NONE, | ||
391 | 383 | -1, | ||
392 | 384 | NULL, | ||
393 | 385 | &error); | ||
394 | 386 | if (variant == NULL) { | ||
395 | 387 | g_warning ("Failed to call GetEnvironment on keyring daemon: %s", error->message); | ||
396 | 388 | g_error_free (error); | ||
397 | 389 | return NULL; | ||
398 | 390 | } | ||
399 | 391 | |||
400 | 392 | envp = g_get_environ (); | ||
401 | 393 | |||
402 | 394 | g_variant_get (variant, "(a{ss})", &iter); | ||
403 | 395 | |||
404 | 396 | while ((item = g_variant_iter_next_value (iter))) { | ||
405 | 397 | char *key; | ||
406 | 398 | char *value; | ||
407 | 399 | |||
408 | 400 | g_variant_get (item, | ||
409 | 401 | "{ss}", | ||
410 | 402 | &key, | ||
411 | 403 | &value); | ||
412 | 404 | |||
413 | 405 | envp = g_environ_setenv (envp, key, value, TRUE); | ||
414 | 406 | |||
415 | 407 | g_variant_unref (item); | ||
416 | 408 | g_free (key); | ||
417 | 409 | g_free (value); | ||
418 | 410 | } | ||
419 | 411 | |||
420 | 412 | g_variant_iter_free (iter); | ||
421 | 413 | g_variant_unref (variant); | ||
422 | 414 | |||
423 | 415 | return envp; | ||
424 | 416 | } | ||
425 | 417 | |||
426 | 418 | static void | ||
427 | 419 | execute (GsdMediaKeysManager *manager, | ||
428 | 420 | char *cmd, | ||
429 | 421 | gboolean need_term) | ||
430 | 422 | { | ||
431 | 423 | gboolean retval; | ||
432 | 424 | char **argv; | ||
433 | 425 | int argc; | ||
434 | 426 | char *exec; | ||
435 | 427 | char *term = NULL; | ||
436 | 428 | GError *error = NULL; | ||
437 | 429 | |||
438 | 430 | retval = FALSE; | ||
439 | 431 | |||
440 | 432 | if (need_term) | ||
441 | 433 | term = get_term_command (manager); | ||
442 | 434 | |||
443 | 435 | if (term) { | ||
444 | 436 | exec = g_strdup_printf ("%s %s", term, cmd); | ||
445 | 437 | g_free (term); | ||
446 | 438 | } else { | ||
447 | 439 | exec = g_strdup (cmd); | ||
448 | 440 | } | ||
449 | 441 | |||
450 | 442 | if (g_shell_parse_argv (exec, &argc, &argv, NULL)) { | ||
451 | 443 | char **envp; | ||
452 | 444 | |||
453 | 445 | envp = get_keyring_env (manager); | ||
454 | 446 | |||
455 | 447 | retval = g_spawn_async (g_get_home_dir (), | ||
456 | 448 | argv, | ||
457 | 449 | envp, | ||
458 | 450 | G_SPAWN_SEARCH_PATH, | ||
459 | 451 | NULL, | ||
460 | 452 | NULL, | ||
461 | 453 | NULL, | ||
462 | 454 | &error); | ||
463 | 455 | |||
464 | 456 | g_strfreev (argv); | ||
465 | 457 | g_strfreev (envp); | ||
466 | 458 | } | ||
467 | 459 | |||
468 | 460 | if (retval == FALSE) { | ||
469 | 461 | g_warning ("Couldn't execute command: %s: %s", exec, error->message); | ||
470 | 462 | g_error_free (error); | ||
471 | 463 | } | ||
472 | 464 | g_free (exec); | ||
473 | 465 | } | ||
474 | 466 | |||
475 | 467 | static void | ||
476 | 468 | dialog_init (GsdMediaKeysManager *manager) | ||
477 | 469 | { | ||
478 | 470 | if (manager->priv->dialog != NULL | ||
479 | 471 | && !gsd_osd_window_is_valid (GSD_OSD_WINDOW (manager->priv->dialog))) { | ||
480 | 472 | gtk_widget_destroy (manager->priv->dialog); | ||
481 | 473 | manager->priv->dialog = NULL; | ||
482 | 474 | } | ||
483 | 475 | |||
484 | 476 | if (manager->priv->dialog == NULL) { | ||
485 | 477 | manager->priv->dialog = gsd_media_keys_window_new (); | ||
486 | 478 | } | ||
487 | 479 | } | ||
488 | 480 | |||
489 | 481 | static void | ||
490 | 482 | print_key_parse_error (MediaKey *key, | ||
491 | 483 | const char *str) | ||
492 | 484 | { | ||
493 | 485 | if (str == NULL || *str == '\0') | ||
494 | 486 | return; | ||
495 | 487 | if (key->settings_key != NULL) | ||
496 | 488 | g_debug ("Unable to parse key '%s' for GSettings entry '%s'", str, key->settings_key); | ||
497 | 489 | else | ||
498 | 490 | g_debug ("Unable to parse hard-coded key '%s'", key->hard_coded); | ||
499 | 491 | } | ||
500 | 492 | |||
501 | 493 | static char * | ||
502 | 494 | get_key_string (GsdMediaKeysManager *manager, | ||
503 | 495 | MediaKey *key) | ||
504 | 496 | { | ||
505 | 497 | if (key->settings_key != NULL) | ||
506 | 498 | return g_settings_get_string (manager->priv->settings, key->settings_key); | ||
507 | 499 | else if (key->hard_coded != NULL) | ||
508 | 500 | return g_strdup (key->hard_coded); | ||
509 | 501 | else if (key->gconf_dir != NULL) { | ||
510 | 502 | char *entry, *str; | ||
511 | 503 | |||
512 | 504 | entry = g_strdup_printf ("%s/binding", key->gconf_dir); | ||
513 | 505 | str = gconf_client_get_string (manager->priv->gconf, entry, NULL); | ||
514 | 506 | g_free (entry); | ||
515 | 507 | return str; | ||
516 | 508 | } else | ||
517 | 509 | g_assert_not_reached (); | ||
518 | 510 | } | ||
519 | 511 | |||
520 | 512 | static gboolean | ||
521 | 513 | grab_media_key (MediaKey *key, | ||
522 | 514 | GsdMediaKeysManager *manager) | ||
523 | 515 | { | ||
524 | 516 | char *tmp; | ||
525 | 517 | gboolean need_flush; | ||
526 | 518 | |||
527 | 519 | need_flush = FALSE; | ||
528 | 520 | |||
529 | 521 | if (key->key != NULL) { | ||
530 | 522 | need_flush = TRUE; | ||
531 | 523 | grab_key_unsafe (key->key, FALSE, manager->priv->screens); | ||
532 | 524 | } | ||
533 | 525 | |||
534 | 526 | free_key (key->key); | ||
535 | 527 | key->key = NULL; | ||
536 | 528 | |||
537 | 529 | tmp = get_key_string (manager, key); | ||
538 | 530 | |||
539 | 531 | key->key = parse_key (tmp); | ||
540 | 532 | if (key->key == NULL) { | ||
541 | 533 | print_key_parse_error (key, tmp); | ||
542 | 534 | g_free (tmp); | ||
543 | 535 | return need_flush; | ||
544 | 536 | } | ||
545 | 537 | |||
546 | 538 | grab_key_unsafe (key->key, TRUE, manager->priv->screens); | ||
547 | 539 | |||
548 | 540 | g_free (tmp); | ||
549 | 541 | |||
550 | 542 | return TRUE; | ||
551 | 543 | } | ||
552 | 544 | |||
553 | 545 | static void | ||
554 | 546 | gsettings_changed_cb (GSettings *settings, | ||
555 | 547 | const gchar *settings_key, | ||
556 | 548 | GsdMediaKeysManager *manager) | ||
557 | 549 | { | ||
558 | 550 | int i; | ||
559 | 551 | gboolean need_flush = TRUE; | ||
560 | 552 | |||
561 | 553 | gdk_error_trap_push (); | ||
562 | 554 | |||
563 | 555 | /* Find the key that was modified */ | ||
564 | 556 | for (i = 0; i < manager->priv->keys->len; i++) { | ||
565 | 557 | MediaKey *key; | ||
566 | 558 | |||
567 | 559 | key = g_ptr_array_index (manager->priv->keys, i); | ||
568 | 560 | |||
569 | 561 | /* Skip over hard-coded and GConf keys */ | ||
570 | 562 | if (key->settings_key == NULL) | ||
571 | 563 | continue; | ||
572 | 564 | if (strcmp (settings_key, key->settings_key) == 0) { | ||
573 | 565 | if (grab_media_key (key, manager)) | ||
574 | 566 | need_flush = TRUE; | ||
575 | 567 | break; | ||
576 | 568 | } | ||
577 | 569 | } | ||
578 | 570 | |||
579 | 571 | if (need_flush) | ||
580 | 572 | gdk_flush (); | ||
581 | 573 | if (gdk_error_trap_pop ()) | ||
582 | 574 | g_warning ("Grab failed for some keys, another application may already have access the them."); | ||
583 | 575 | } | ||
584 | 576 | |||
585 | 577 | static char * | ||
586 | 578 | entry_get_string (GConfEntry *entry) | ||
587 | 579 | { | ||
588 | 580 | GConfValue *value = gconf_entry_get_value (entry); | ||
589 | 581 | |||
590 | 582 | if (value == NULL || value->type != GCONF_VALUE_STRING) { | ||
591 | 583 | return NULL; | ||
592 | 584 | } | ||
593 | 585 | |||
594 | 586 | return g_strdup (gconf_value_get_string (value)); | ||
595 | 587 | } | ||
596 | 588 | |||
597 | 589 | static MediaKey * | ||
598 | 590 | media_key_new_for_gconf (GsdMediaKeysManager *manager, | ||
599 | 591 | char *dir) | ||
600 | 592 | { | ||
601 | 593 | GSList *list, *l; | ||
602 | 594 | char *action, *binding; | ||
603 | 595 | MediaKey *key; | ||
604 | 596 | |||
605 | 597 | /* Get entries for this binding */ | ||
606 | 598 | list = gconf_client_all_entries (manager->priv->gconf, dir, NULL); | ||
607 | 599 | action = NULL; | ||
608 | 600 | binding = NULL; | ||
609 | 601 | |||
610 | 602 | for (l = list; l != NULL; l = l->next) { | ||
611 | 603 | GConfEntry *entry = l->data; | ||
612 | 604 | char *key_name; | ||
613 | 605 | |||
614 | 606 | key_name = g_path_get_basename (gconf_entry_get_key (entry)); | ||
615 | 607 | |||
616 | 608 | if (key_name == NULL) { | ||
617 | 609 | /* ignore entry */ | ||
618 | 610 | } else if (strcmp (key_name, "action") == 0) { | ||
619 | 611 | action = entry_get_string (entry); | ||
620 | 612 | } else if (strcmp (key_name, "binding") == 0) { | ||
621 | 613 | binding = entry_get_string (entry); | ||
622 | 614 | } | ||
623 | 615 | |||
624 | 616 | g_free (key_name); | ||
625 | 617 | gconf_entry_free (entry); | ||
626 | 618 | } | ||
627 | 619 | |||
628 | 620 | g_slist_free (list); | ||
629 | 621 | |||
630 | 622 | if (action == NULL && binding == NULL) { | ||
631 | 623 | g_debug ("Key binding (%s) is incomplete", dir); | ||
632 | 624 | return NULL; | ||
633 | 625 | } | ||
634 | 626 | g_free (binding); | ||
635 | 627 | |||
636 | 628 | key = g_new0 (MediaKey, 1); | ||
637 | 629 | key->key_type = CUSTOM_KEY; | ||
638 | 630 | key->gconf_dir = dir; | ||
639 | 631 | key->custom_command = action; | ||
640 | 632 | |||
641 | 633 | return key; | ||
642 | 634 | } | ||
643 | 635 | |||
644 | 636 | static void | ||
645 | 637 | gconf_changed_cb (GConfClient *client, | ||
646 | 638 | guint cnxn_id, | ||
647 | 639 | GConfEntry *entry, | ||
648 | 640 | GsdMediaKeysManager *manager) | ||
649 | 641 | { | ||
650 | 642 | char *gconf_key, **key_elems; | ||
651 | 643 | int i; | ||
652 | 644 | MediaKey *key; | ||
653 | 645 | |||
654 | 646 | g_return_if_fail (entry != NULL); | ||
655 | 647 | g_return_if_fail (entry->key[0] == '/'); | ||
656 | 648 | |||
657 | 649 | /* Look for the dir that changed, thus the MediaKey */ | ||
658 | 650 | key_elems = g_strsplit (entry->key + 1, "/", -1); | ||
659 | 651 | if (key_elems == NULL || | ||
660 | 652 | (g_strv_length (key_elems) != 4 && | ||
661 | 653 | g_strv_length (key_elems) != 5)) { | ||
662 | 654 | g_warning ("Unexpected GConf notification for key '%s'", entry->key); | ||
663 | 655 | g_strfreev (key_elems); | ||
664 | 656 | return; | ||
665 | 657 | } | ||
666 | 658 | |||
667 | 659 | if (g_strv_length (key_elems) == 5 && | ||
668 | 660 | g_str_equal (key_elems[4], "binding") == FALSE && | ||
669 | 661 | g_str_equal (key_elems[4], "action") == FALSE) { | ||
670 | 662 | g_debug ("Not interested in notification for key '%s'", entry->key); | ||
671 | 663 | g_strfreev (key_elems); | ||
672 | 664 | return; | ||
673 | 665 | } | ||
674 | 666 | gconf_key = g_strdup_printf ("/%s/%s/%s/%s", | ||
675 | 667 | key_elems[0], | ||
676 | 668 | key_elems[1], | ||
677 | 669 | key_elems[2], | ||
678 | 670 | key_elems[3]); | ||
679 | 671 | g_strfreev (key_elems); | ||
680 | 672 | |||
681 | 673 | g_debug ("Got notification for key '%s' (dir: '%s')", | ||
682 | 674 | entry->key, gconf_key); | ||
683 | 675 | |||
684 | 676 | /* Remove the existing key */ | ||
685 | 677 | for (i = 0; i < manager->priv->keys->len; i++) { | ||
686 | 678 | key = g_ptr_array_index (manager->priv->keys, i); | ||
687 | 679 | |||
688 | 680 | if (key->gconf_dir == NULL) | ||
689 | 681 | continue; | ||
690 | 682 | if (strcmp (key->gconf_dir, gconf_key) == 0) { | ||
691 | 683 | if (key->key) { | ||
692 | 684 | gdk_error_trap_push (); | ||
693 | 685 | |||
694 | 686 | grab_key_unsafe (key->key, FALSE, manager->priv->screens); | ||
695 | 687 | |||
696 | 688 | gdk_flush (); | ||
697 | 689 | if (gdk_error_trap_pop ()) | ||
698 | 690 | g_warning ("Ungrab failed for GConf key '%s'", gconf_key); | ||
699 | 691 | } | ||
700 | 692 | g_ptr_array_remove_index_fast (manager->priv->keys, i); | ||
701 | 693 | break; | ||
702 | 694 | } | ||
703 | 695 | } | ||
704 | 696 | |||
705 | 697 | /* And create a new one! */ | ||
706 | 698 | key = media_key_new_for_gconf (manager, gconf_key); | ||
707 | 699 | if (key) { | ||
708 | 700 | g_ptr_array_add (manager->priv->keys, key); | ||
709 | 701 | |||
710 | 702 | gdk_error_trap_push (); | ||
711 | 703 | |||
712 | 704 | grab_media_key (key, manager); | ||
713 | 705 | |||
714 | 706 | gdk_flush (); | ||
715 | 707 | if (gdk_error_trap_pop ()) | ||
716 | 708 | g_warning ("Grab failed for GConf key '%s'", key->gconf_dir); | ||
717 | 709 | } else { | ||
718 | 710 | g_free (gconf_key); | ||
719 | 711 | } | ||
720 | 712 | } | ||
721 | 713 | |||
722 | 714 | |||
723 | 715 | static void | ||
724 | 716 | add_key (GsdMediaKeysManager *manager, guint i) | ||
725 | 717 | { | ||
726 | 718 | MediaKey *key; | ||
727 | 719 | |||
728 | 720 | key = g_new0 (MediaKey, 1); | ||
729 | 721 | key->key_type = media_keys[i].key_type; | ||
730 | 722 | key->settings_key = media_keys[i].settings_key; | ||
731 | 723 | key->hard_coded = media_keys[i].hard_coded; | ||
732 | 724 | |||
733 | 725 | g_ptr_array_add (manager->priv->keys, key); | ||
734 | 726 | |||
735 | 727 | grab_media_key (key, manager); | ||
736 | 728 | } | ||
737 | 729 | |||
738 | 730 | static void | ||
739 | 731 | init_kbd (GsdMediaKeysManager *manager) | ||
740 | 732 | { | ||
741 | 733 | int i; | ||
742 | 734 | GSList *list, *l; | ||
743 | 735 | |||
744 | 736 | gnome_settings_profile_start (NULL); | ||
745 | 737 | |||
746 | 738 | gdk_error_trap_push (); | ||
747 | 739 | |||
748 | 740 | manager->priv->keys = g_ptr_array_new_with_free_func ((GDestroyNotify) media_key_free); | ||
749 | 741 | |||
750 | 742 | /* Media keys | ||
751 | 743 | * Add hard-coded shortcuts first so that they can't be preempted */ | ||
752 | 744 | for (i = 0; i < G_N_ELEMENTS (media_keys); i++) { | ||
753 | 745 | if (media_keys[i].hard_coded) | ||
754 | 746 | add_key (manager, i); | ||
755 | 747 | } | ||
756 | 748 | for (i = 0; i < G_N_ELEMENTS (media_keys); i++) { | ||
757 | 749 | if (media_keys[i].hard_coded == NULL) | ||
758 | 750 | add_key (manager, i); | ||
759 | 751 | } | ||
760 | 752 | |||
761 | 753 | /* Custom shortcuts */ | ||
762 | 754 | list = gconf_client_all_dirs (manager->priv->gconf, GCONF_BINDING_DIR, NULL); | ||
763 | 755 | for (l = list; l != NULL; l = l->next) { | ||
764 | 756 | MediaKey *key; | ||
765 | 757 | |||
766 | 758 | key = media_key_new_for_gconf (manager, l->data); | ||
767 | 759 | if (!key) { | ||
768 | 760 | g_free (l->data); | ||
769 | 761 | continue; | ||
770 | 762 | } | ||
771 | 763 | g_ptr_array_add (manager->priv->keys, key); | ||
772 | 764 | |||
773 | 765 | grab_media_key (key, manager); | ||
774 | 766 | } | ||
775 | 767 | g_slist_free (list); | ||
776 | 768 | |||
777 | 769 | gdk_flush (); | ||
778 | 770 | if (gdk_error_trap_pop ()) | ||
779 | 771 | g_warning ("Grab failed for some keys, another application may already have access the them."); | ||
780 | 772 | |||
781 | 773 | gnome_settings_profile_end (NULL); | ||
782 | 774 | } | ||
783 | 775 | |||
784 | 776 | static void | ||
785 | 777 | dialog_show (GsdMediaKeysManager *manager) | ||
786 | 778 | { | ||
787 | 779 | int orig_w; | ||
788 | 780 | int orig_h; | ||
789 | 781 | int screen_w; | ||
790 | 782 | int screen_h; | ||
791 | 783 | int x; | ||
792 | 784 | int y; | ||
793 | 785 | GtkRequisition win_req; | ||
794 | 786 | GdkRectangle geometry; | ||
795 | 787 | int monitor; | ||
796 | 788 | |||
797 | 789 | gtk_window_set_screen (GTK_WINDOW (manager->priv->dialog), | ||
798 | 790 | manager->priv->current_screen); | ||
799 | 791 | |||
800 | 792 | /* | ||
801 | 793 | * get the window size | ||
802 | 794 | * if the window hasn't been mapped, it doesn't necessarily | ||
803 | 795 | * know its true size, yet, so we need to jump through hoops | ||
804 | 796 | */ | ||
805 | 797 | gtk_window_get_default_size (GTK_WINDOW (manager->priv->dialog), &orig_w, &orig_h); | ||
806 | 798 | gtk_widget_size_request (manager->priv->dialog, &win_req); | ||
807 | 799 | |||
808 | 800 | if (win_req.width > orig_w) | ||
809 | 801 | orig_w = win_req.width; | ||
810 | 802 | if (win_req.height > orig_h) | ||
811 | 803 | orig_h = win_req.height; | ||
812 | 804 | |||
813 | 805 | monitor = gdk_screen_get_primary_monitor (manager->priv->current_screen); | ||
814 | 806 | |||
815 | 807 | gdk_screen_get_monitor_geometry (manager->priv->current_screen, | ||
816 | 808 | monitor, | ||
817 | 809 | &geometry); | ||
818 | 810 | |||
819 | 811 | screen_w = geometry.width; | ||
820 | 812 | screen_h = geometry.height; | ||
821 | 813 | |||
822 | 814 | x = ((screen_w - orig_w) / 2) + geometry.x; | ||
823 | 815 | y = geometry.y + (screen_h / 2) + (screen_h / 2 - orig_h) / 2; | ||
824 | 816 | |||
825 | 817 | gtk_window_move (GTK_WINDOW (manager->priv->dialog), x, y); | ||
826 | 818 | |||
827 | 819 | gtk_widget_show (manager->priv->dialog); | ||
828 | 820 | |||
829 | 821 | gdk_display_sync (gdk_screen_get_display (manager->priv->current_screen)); | ||
830 | 822 | } | ||
831 | 823 | |||
832 | 824 | static void | ||
833 | 825 | launch_app (GAppInfo *app_info, | ||
834 | 826 | gint64 timestamp) | ||
835 | 827 | { | ||
836 | 828 | GError *error = NULL; | ||
837 | 829 | GdkAppLaunchContext *launch_context; | ||
838 | 830 | |||
839 | 831 | /* setup the launch context so the startup notification is correct */ | ||
840 | 832 | launch_context = gdk_display_get_app_launch_context (gdk_display_get_default ()); | ||
841 | 833 | gdk_app_launch_context_set_timestamp (launch_context, timestamp); | ||
842 | 834 | |||
843 | 835 | if (!g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), &error)) { | ||
844 | 836 | g_warning ("Could not launch '%s': %s", | ||
845 | 837 | g_app_info_get_commandline (app_info), | ||
846 | 838 | error->message); | ||
847 | 839 | g_error_free (error); | ||
848 | 840 | } | ||
849 | 841 | g_object_unref (launch_context); | ||
850 | 842 | } | ||
851 | 843 | |||
852 | 844 | static void | ||
853 | 845 | do_url_action (GsdMediaKeysManager *manager, | ||
854 | 846 | const char *scheme, | ||
855 | 847 | gint64 timestamp) | ||
856 | 848 | { | ||
857 | 849 | GAppInfo *app_info; | ||
858 | 850 | |||
859 | 851 | app_info = g_app_info_get_default_for_uri_scheme (scheme); | ||
860 | 852 | if (app_info != NULL) { | ||
861 | 853 | launch_app (app_info, timestamp); | ||
862 | 854 | g_object_unref (app_info); | ||
863 | 855 | } else { | ||
864 | 856 | g_warning ("Could not find default application for '%s' scheme", scheme); | ||
865 | 857 | } | ||
866 | 858 | } | ||
867 | 859 | |||
868 | 860 | static void | ||
869 | 861 | do_media_action (GsdMediaKeysManager *manager, | ||
870 | 862 | gint64 timestamp) | ||
871 | 863 | { | ||
872 | 864 | GAppInfo *app_info; | ||
873 | 865 | |||
874 | 866 | app_info = g_app_info_get_default_for_type ("audio/x-vorbis+ogg", FALSE); | ||
875 | 867 | if (app_info != NULL) { | ||
876 | 868 | launch_app (app_info, timestamp); | ||
877 | 869 | g_object_unref (app_info); | ||
878 | 870 | } else { | ||
879 | 871 | g_warning ("Could not find default application for '%s' mime-type", "audio/x-vorbis+ogg"); | ||
880 | 872 | } | ||
881 | 873 | } | ||
882 | 874 | |||
883 | 875 | static void | ||
884 | 876 | gnome_session_shutdown (GsdMediaKeysManager *manager) | ||
885 | 877 | { | ||
886 | 878 | GError *error = NULL; | ||
887 | 879 | GVariant *variant; | ||
888 | 880 | |||
889 | 881 | /* Shouldn't happen, but you never know */ | ||
890 | 882 | if (manager->priv->connection == NULL) { | ||
891 | 883 | execute (manager, "gnome-session-quit --logout", FALSE); | ||
892 | 884 | return; | ||
893 | 885 | } | ||
894 | 886 | |||
895 | 887 | variant = g_dbus_connection_call_sync (manager->priv->connection, | ||
896 | 888 | GNOME_SESSION_DBUS_NAME, | ||
897 | 889 | GNOME_SESSION_DBUS_PATH, | ||
898 | 890 | GNOME_SESSION_DBUS_INTERFACE, | ||
899 | 891 | "Shutdown", | ||
900 | 892 | NULL, | ||
901 | 893 | NULL, | ||
902 | 894 | G_DBUS_CALL_FLAGS_NONE, | ||
903 | 895 | -1, | ||
904 | 896 | NULL, | ||
905 | 897 | &error); | ||
906 | 898 | if (variant == NULL) { | ||
907 | 899 | g_warning ("Failed to call Shutdown on session manager: %s", error->message); | ||
908 | 900 | g_error_free (error); | ||
909 | 901 | return; | ||
910 | 902 | } | ||
911 | 903 | g_variant_unref (variant); | ||
912 | 904 | } | ||
913 | 905 | |||
914 | 906 | static void | ||
915 | 907 | do_logout_action (GsdMediaKeysManager *manager) | ||
916 | 908 | { | ||
917 | 909 | execute (manager, "gnome-session-quit --logout", FALSE); | ||
918 | 910 | } | ||
919 | 911 | |||
920 | 912 | static void | ||
921 | 913 | do_eject_action_cb (GDrive *drive, | ||
922 | 914 | GAsyncResult *res, | ||
923 | 915 | GsdMediaKeysManager *manager) | ||
924 | 916 | { | ||
925 | 917 | g_drive_eject_with_operation_finish (drive, res, NULL); | ||
926 | 918 | } | ||
927 | 919 | |||
928 | 920 | #define NO_SCORE 0 | ||
929 | 921 | #define SCORE_CAN_EJECT 50 | ||
930 | 922 | #define SCORE_HAS_MEDIA 100 | ||
931 | 923 | static void | ||
932 | 924 | do_eject_action (GsdMediaKeysManager *manager) | ||
933 | 925 | { | ||
934 | 926 | GList *drives, *l; | ||
935 | 927 | GDrive *fav_drive; | ||
936 | 928 | guint score; | ||
937 | 929 | GVolumeMonitor *volume_monitor; | ||
938 | 930 | |||
939 | 931 | volume_monitor = g_volume_monitor_get (); | ||
940 | 932 | |||
941 | 933 | /* Find the best drive to eject */ | ||
942 | 934 | fav_drive = NULL; | ||
943 | 935 | score = NO_SCORE; | ||
944 | 936 | drives = g_volume_monitor_get_connected_drives (volume_monitor); | ||
945 | 937 | for (l = drives; l != NULL; l = l->next) { | ||
946 | 938 | GDrive *drive = l->data; | ||
947 | 939 | |||
948 | 940 | if (g_drive_can_eject (drive) == FALSE) | ||
949 | 941 | continue; | ||
950 | 942 | if (g_drive_is_media_removable (drive) == FALSE) | ||
951 | 943 | continue; | ||
952 | 944 | if (score < SCORE_CAN_EJECT) { | ||
953 | 945 | fav_drive = drive; | ||
954 | 946 | score = SCORE_CAN_EJECT; | ||
955 | 947 | } | ||
956 | 948 | if (g_drive_has_media (drive) == FALSE) | ||
957 | 949 | continue; | ||
958 | 950 | if (score < SCORE_HAS_MEDIA) { | ||
959 | 951 | fav_drive = drive; | ||
960 | 952 | score = SCORE_HAS_MEDIA; | ||
961 | 953 | break; | ||
962 | 954 | } | ||
963 | 955 | } | ||
964 | 956 | |||
965 | 957 | /* Show the dialogue */ | ||
966 | 958 | if (!ubuntu_osd_notification_show_icon ("notification-device-eject", "Eject")) { | ||
967 | 959 | dialog_init (manager); | ||
968 | 960 | gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), | ||
969 | 961 | "media-eject-symbolic", | ||
970 | 962 | FALSE); | ||
971 | 963 | dialog_show (manager); | ||
972 | 964 | } | ||
973 | 965 | |||
974 | 966 | /* Clean up the drive selection and exit if no suitable | ||
975 | 967 | * drives are found */ | ||
976 | 968 | if (fav_drive != NULL) | ||
977 | 969 | fav_drive = g_object_ref (fav_drive); | ||
978 | 970 | |||
979 | 971 | g_list_foreach (drives, (GFunc) g_object_unref, NULL); | ||
980 | 972 | if (fav_drive == NULL) | ||
981 | 973 | return; | ||
982 | 974 | |||
983 | 975 | /* Eject! */ | ||
984 | 976 | g_drive_eject_with_operation (fav_drive, G_MOUNT_UNMOUNT_FORCE, | ||
985 | 977 | NULL, NULL, | ||
986 | 978 | (GAsyncReadyCallback) do_eject_action_cb, | ||
987 | 979 | manager); | ||
988 | 980 | g_object_unref (fav_drive); | ||
989 | 981 | g_object_unref (volume_monitor); | ||
990 | 982 | } | ||
991 | 983 | |||
992 | 984 | static void | ||
993 | 985 | do_home_key_action (GsdMediaKeysManager *manager, | ||
994 | 986 | gint64 timestamp) | ||
995 | 987 | { | ||
996 | 988 | GFile *file; | ||
997 | 989 | GError *error = NULL; | ||
998 | 990 | char *uri; | ||
999 | 991 | |||
1000 | 992 | file = g_file_new_for_path (g_get_home_dir ()); | ||
1001 | 993 | uri = g_file_get_uri (file); | ||
1002 | 994 | g_object_unref (file); | ||
1003 | 995 | |||
1004 | 996 | if (gtk_show_uri (NULL, uri, timestamp, &error) == FALSE) { | ||
1005 | 997 | g_warning ("Failed to launch '%s': %s", uri, error->message); | ||
1006 | 998 | g_error_free (error); | ||
1007 | 999 | } | ||
1008 | 1000 | g_free (uri); | ||
1009 | 1001 | } | ||
1010 | 1002 | |||
1011 | 1003 | static void | ||
1012 | 1004 | do_execute_desktop (GsdMediaKeysManager *manager, | ||
1013 | 1005 | const char *desktop, | ||
1014 | 1006 | gint64 timestamp) | ||
1015 | 1007 | { | ||
1016 | 1008 | GDesktopAppInfo *app_info; | ||
1017 | 1009 | |||
1018 | 1010 | app_info = g_desktop_app_info_new (desktop); | ||
1019 | 1011 | if (app_info != NULL) { | ||
1020 | 1012 | launch_app (G_APP_INFO (app_info), timestamp); | ||
1021 | 1013 | g_object_unref (app_info); | ||
1022 | 1014 | } else { | ||
1023 | 1015 | g_warning ("Could not find application '%s'", desktop); | ||
1024 | 1016 | } | ||
1025 | 1017 | } | ||
1026 | 1018 | |||
1027 | 1019 | static void | ||
1028 | 1020 | do_touchpad_osd_action (GsdMediaKeysManager *manager, gboolean state) | ||
1029 | 1021 | { | ||
1030 | 1022 | if (!ubuntu_osd_notification_show_icon ((!state) ? "touchpad-disabled-symbolic" : "input-touchpad-symbolic", "Touchpad")) { | ||
1031 | 1023 | dialog_init (manager); | ||
1032 | 1024 | gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), | ||
1033 | 1025 | state ? "input-touchpad-symbolic" : "touchpad-disabled-symbolic", | ||
1034 | 1026 | FALSE); | ||
1035 | 1027 | dialog_show (manager); | ||
1036 | 1028 | } | ||
1037 | 1029 | } | ||
1038 | 1030 | |||
1039 | 1031 | static void | ||
1040 | 1032 | do_touchpad_action (GsdMediaKeysManager *manager) | ||
1041 | 1033 | { | ||
1042 | 1034 | GSettings *settings; | ||
1043 | 1035 | gboolean state; | ||
1044 | 1036 | |||
1045 | 1037 | if (touchpad_is_present () == FALSE) { | ||
1046 | 1038 | do_touchpad_osd_action (manager, FALSE); | ||
1047 | 1039 | return; | ||
1048 | 1040 | } | ||
1049 | 1041 | |||
1050 | 1042 | settings = g_settings_new (SETTINGS_TOUCHPAD_DIR); | ||
1051 | 1043 | state = g_settings_get_boolean (settings, TOUCHPAD_ENABLED_KEY); | ||
1052 | 1044 | |||
1053 | 1045 | do_touchpad_osd_action (manager, !state); | ||
1054 | 1046 | |||
1055 | 1047 | g_settings_set_boolean (settings, TOUCHPAD_ENABLED_KEY, !state); | ||
1056 | 1048 | g_object_unref (settings); | ||
1057 | 1049 | } | ||
1058 | 1050 | |||
1059 | 1051 | static void | ||
1060 | 1052 | update_dialog (GsdMediaKeysManager *manager, | ||
1061 | 1053 | GvcMixerStream *stream, | ||
1062 | 1054 | guint vol, | ||
1063 | 1055 | gboolean muted, | ||
1064 | 1056 | gboolean sound_changed, | ||
1065 | 1057 | gboolean quiet) | ||
1066 | 1058 | { | ||
1067 | 1059 | if (ubuntu_osd_notification_show_volume (manager, vol, muted)) | ||
1068 | 1060 | goto done; | ||
1069 | 1061 | |||
1070 | 1062 | vol = CLAMP (vol, 0, 100); | ||
1071 | 1063 | |||
1072 | 1064 | dialog_init (manager); | ||
1073 | 1065 | gsd_media_keys_window_set_volume_muted (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), | ||
1074 | 1066 | muted); | ||
1075 | 1067 | gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), vol); | ||
1076 | 1068 | gsd_media_keys_window_set_action (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), | ||
1077 | 1069 | GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); | ||
1078 | 1070 | dialog_show (manager); | ||
1079 | 1071 | |||
1080 | 1072 | done: | ||
1081 | 1073 | if (quiet == FALSE && sound_changed != FALSE && muted == FALSE) { | ||
1082 | 1074 | ca_context_change_device (manager->priv->ca, | ||
1083 | 1075 | gvc_mixer_stream_get_name (stream)); | ||
1084 | 1076 | ca_context_play (manager->priv->ca, 1, | ||
1085 | 1077 | CA_PROP_EVENT_ID, "audio-volume-change", | ||
1086 | 1078 | CA_PROP_EVENT_DESCRIPTION, "volume changed through key press", | ||
1087 | 1079 | CA_PROP_CANBERRA_CACHE_CONTROL, "permanent", | ||
1088 | 1080 | NULL); | ||
1089 | 1081 | } | ||
1090 | 1082 | } | ||
1091 | 1083 | |||
1092 | 1084 | #ifdef HAVE_GUDEV | ||
1093 | 1085 | /* PulseAudio gives us /devices/... paths, when udev | ||
1094 | 1086 | * expects /sys/devices/... paths. */ | ||
1095 | 1087 | static GUdevDevice * | ||
1096 | 1088 | get_udev_device_for_sysfs_path (GsdMediaKeysManager *manager, | ||
1097 | 1089 | const char *sysfs_path) | ||
1098 | 1090 | { | ||
1099 | 1091 | char *path; | ||
1100 | 1092 | GUdevDevice *dev; | ||
1101 | 1093 | |||
1102 | 1094 | path = g_strdup_printf ("/sys%s", sysfs_path); | ||
1103 | 1095 | dev = g_udev_client_query_by_sysfs_path (manager->priv->udev_client, path); | ||
1104 | 1096 | g_free (path); | ||
1105 | 1097 | |||
1106 | 1098 | return dev; | ||
1107 | 1099 | } | ||
1108 | 1100 | |||
1109 | 1101 | static GvcMixerStream * | ||
1110 | 1102 | get_stream_for_device_id (GsdMediaKeysManager *manager, | ||
1111 | 1103 | guint deviceid) | ||
1112 | 1104 | { | ||
1113 | 1105 | char *devnode; | ||
1114 | 1106 | gpointer id_ptr; | ||
1115 | 1107 | GvcMixerStream *res; | ||
1116 | 1108 | GUdevDevice *dev, *parent; | ||
1117 | 1109 | GSList *sinks, *l; | ||
1118 | 1110 | |||
1119 | 1111 | id_ptr = g_hash_table_lookup (manager->priv->streams, GUINT_TO_POINTER (deviceid)); | ||
1120 | 1112 | if (id_ptr != NULL) { | ||
1121 | 1113 | if (GPOINTER_TO_UINT (id_ptr) == (guint) -1) | ||
1122 | 1114 | return NULL; | ||
1123 | 1115 | else | ||
1124 | 1116 | return gvc_mixer_control_lookup_stream_id (manager->priv->volume, GPOINTER_TO_UINT (id_ptr)); | ||
1125 | 1117 | } | ||
1126 | 1118 | |||
1127 | 1119 | devnode = xdevice_get_device_node (deviceid); | ||
1128 | 1120 | if (devnode == NULL) { | ||
1129 | 1121 | g_debug ("Could not find device node for XInput device %d", deviceid); | ||
1130 | 1122 | return NULL; | ||
1131 | 1123 | } | ||
1132 | 1124 | |||
1133 | 1125 | dev = g_udev_client_query_by_device_file (manager->priv->udev_client, devnode); | ||
1134 | 1126 | if (dev == NULL) { | ||
1135 | 1127 | g_debug ("Could not find udev device for device path '%s'", devnode); | ||
1136 | 1128 | g_free (devnode); | ||
1137 | 1129 | return NULL; | ||
1138 | 1130 | } | ||
1139 | 1131 | g_free (devnode); | ||
1140 | 1132 | |||
1141 | 1133 | if (g_strcmp0 (g_udev_device_get_property (dev, "ID_BUS"), "usb") != 0) { | ||
1142 | 1134 | g_debug ("Not handling XInput device %d, not USB", deviceid); | ||
1143 | 1135 | g_hash_table_insert (manager->priv->streams, | ||
1144 | 1136 | GUINT_TO_POINTER (deviceid), | ||
1145 | 1137 | GUINT_TO_POINTER ((guint) -1)); | ||
1146 | 1138 | g_object_unref (dev); | ||
1147 | 1139 | return NULL; | ||
1148 | 1140 | } | ||
1149 | 1141 | |||
1150 | 1142 | parent = g_udev_device_get_parent_with_subsystem (dev, "usb", "usb_device"); | ||
1151 | 1143 | if (parent == NULL) { | ||
1152 | 1144 | g_warning ("No USB device parent for XInput device %d even though it's USB", deviceid); | ||
1153 | 1145 | g_object_unref (dev); | ||
1154 | 1146 | return NULL; | ||
1155 | 1147 | } | ||
1156 | 1148 | |||
1157 | 1149 | res = NULL; | ||
1158 | 1150 | sinks = gvc_mixer_control_get_sinks (manager->priv->volume); | ||
1159 | 1151 | for (l = sinks; l; l = l->next) { | ||
1160 | 1152 | GvcMixerStream *stream = l->data; | ||
1161 | 1153 | const char *sysfs_path; | ||
1162 | 1154 | GUdevDevice *sink_dev, *sink_parent; | ||
1163 | 1155 | |||
1164 | 1156 | sysfs_path = gvc_mixer_stream_get_sysfs_path (stream); | ||
1165 | 1157 | sink_dev = get_udev_device_for_sysfs_path (manager, sysfs_path); | ||
1166 | 1158 | if (sink_dev == NULL) | ||
1167 | 1159 | continue; | ||
1168 | 1160 | sink_parent = g_udev_device_get_parent_with_subsystem (sink_dev, "usb", "usb_device"); | ||
1169 | 1161 | g_object_unref (sink_dev); | ||
1170 | 1162 | if (sink_parent == NULL) | ||
1171 | 1163 | continue; | ||
1172 | 1164 | |||
1173 | 1165 | if (g_strcmp0 (g_udev_device_get_sysfs_path (sink_parent), | ||
1174 | 1166 | g_udev_device_get_sysfs_path (parent)) == 0) { | ||
1175 | 1167 | res = stream; | ||
1176 | 1168 | } | ||
1177 | 1169 | g_object_unref (sink_parent); | ||
1178 | 1170 | if (res != NULL) | ||
1179 | 1171 | break; | ||
1180 | 1172 | } | ||
1181 | 1173 | |||
1182 | 1174 | if (res) | ||
1183 | 1175 | g_hash_table_insert (manager->priv->streams, | ||
1184 | 1176 | GUINT_TO_POINTER (deviceid), | ||
1185 | 1177 | GUINT_TO_POINTER (gvc_mixer_stream_get_id (res))); | ||
1186 | 1178 | else | ||
1187 | 1179 | g_hash_table_insert (manager->priv->streams, | ||
1188 | 1180 | GUINT_TO_POINTER (deviceid), | ||
1189 | 1181 | GUINT_TO_POINTER ((guint) -1)); | ||
1190 | 1182 | |||
1191 | 1183 | return res; | ||
1192 | 1184 | } | ||
1193 | 1185 | #endif /* HAVE_GUDEV */ | ||
1194 | 1186 | |||
1195 | 1187 | static void | ||
1196 | 1188 | do_sound_action (GsdMediaKeysManager *manager, | ||
1197 | 1189 | guint deviceid, | ||
1198 | 1190 | int type, | ||
1199 | 1191 | gboolean quiet) | ||
1200 | 1192 | { | ||
1201 | 1193 | GvcMixerStream *stream; | ||
1202 | 1194 | gboolean old_muted, new_muted; | ||
1203 | 1195 | guint old_vol, new_vol, norm_vol_step, osd_vol; | ||
1204 | 1196 | gboolean sound_changed; | ||
1205 | 1197 | |||
1206 | 1198 | /* Find the stream that corresponds to the device, if any */ | ||
1207 | 1199 | #ifdef HAVE_GUDEV | ||
1208 | 1200 | stream = get_stream_for_device_id (manager, deviceid); | ||
1209 | 1201 | if (stream == NULL) | ||
1210 | 1202 | #endif /* HAVE_GUDEV */ | ||
1211 | 1203 | stream = manager->priv->stream; | ||
1212 | 1204 | if (stream == NULL) | ||
1213 | 1205 | return; | ||
1214 | 1206 | |||
1215 | 1207 | norm_vol_step = PA_VOLUME_NORM * VOLUME_STEP / 100; | ||
1216 | 1208 | |||
1217 | 1209 | /* FIXME: this is racy */ | ||
1218 | 1210 | new_vol = old_vol = gvc_mixer_stream_get_volume (stream); | ||
1219 | 1211 | new_muted = old_muted = gvc_mixer_stream_get_is_muted (stream); | ||
1220 | 1212 | sound_changed = FALSE; | ||
1221 | 1213 | |||
1222 | 1214 | switch (type) { | ||
1223 | 1215 | case MUTE_KEY: | ||
1224 | 1216 | new_muted = !old_muted; | ||
1225 | 1217 | break; | ||
1226 | 1218 | case VOLUME_DOWN_KEY: | ||
1227 | 1219 | if (old_vol <= norm_vol_step) { | ||
1228 | 1220 | new_vol = 0; | ||
1229 | 1221 | new_muted = TRUE; | ||
1230 | 1222 | } else { | ||
1231 | 1223 | new_vol = old_vol - norm_vol_step; | ||
1232 | 1224 | } | ||
1233 | 1225 | break; | ||
1234 | 1226 | case VOLUME_UP_KEY: | ||
1235 | 1227 | new_muted = FALSE; | ||
1236 | 1228 | /* When coming out of mute only increase the volume if it was 0 */ | ||
1237 | 1229 | if (!old_muted || old_vol == 0) | ||
1238 | 1230 | new_vol = MIN (old_vol + norm_vol_step, MAX_VOLUME); | ||
1239 | 1231 | break; | ||
1240 | 1232 | } | ||
1241 | 1233 | |||
1242 | 1234 | if (old_muted != new_muted) { | ||
1243 | 1235 | gvc_mixer_stream_change_is_muted (stream, new_muted); | ||
1244 | 1236 | sound_changed = TRUE; | ||
1245 | 1237 | } | ||
1246 | 1238 | |||
1247 | 1239 | if (old_vol != new_vol) { | ||
1248 | 1240 | if (gvc_mixer_stream_set_volume (stream, new_vol) != FALSE) { | ||
1249 | 1241 | gvc_mixer_stream_push_volume (stream); | ||
1250 | 1242 | sound_changed = TRUE; | ||
1251 | 1243 | } | ||
1252 | 1244 | } | ||
1253 | 1245 | |||
1254 | 1246 | if (type == VOLUME_DOWN_KEY && old_vol == 0 && old_muted) | ||
1255 | 1247 | osd_vol = -1; | ||
1256 | 1248 | else if (type == VOLUME_UP_KEY && old_vol == PA_VOLUME_NORM && !old_muted) | ||
1257 | 1249 | osd_vol = 101; | ||
1258 | 1250 | else if (!new_muted) | ||
1259 | 1251 | osd_vol = (int) (100 * (double) new_vol / PA_VOLUME_NORM); | ||
1260 | 1252 | else | ||
1261 | 1253 | osd_vol = 0; | ||
1262 | 1254 | |||
1263 | 1255 | update_dialog (manager, stream, osd_vol, new_muted, sound_changed, quiet); | ||
1264 | 1256 | } | ||
1265 | 1257 | |||
1266 | 1258 | static void | ||
1267 | 1259 | sound_theme_changed (GtkSettings *settings, | ||
1268 | 1260 | GParamSpec *pspec, | ||
1269 | 1261 | GsdMediaKeysManager *manager) | ||
1270 | 1262 | { | ||
1271 | 1263 | char *theme_name; | ||
1272 | 1264 | |||
1273 | 1265 | g_object_get (G_OBJECT (manager->priv->gtksettings), "gtk-sound-theme-name", &theme_name, NULL); | ||
1274 | 1266 | if (theme_name) | ||
1275 | 1267 | ca_context_change_props (manager->priv->ca, CA_PROP_CANBERRA_XDG_THEME_NAME, theme_name, NULL); | ||
1276 | 1268 | g_free (theme_name); | ||
1277 | 1269 | } | ||
1278 | 1270 | |||
1279 | 1271 | static void | ||
1280 | 1272 | update_default_sink (GsdMediaKeysManager *manager) | ||
1281 | 1273 | { | ||
1282 | 1274 | GvcMixerStream *stream; | ||
1283 | 1275 | |||
1284 | 1276 | stream = gvc_mixer_control_get_default_sink (manager->priv->volume); | ||
1285 | 1277 | if (stream == manager->priv->stream) | ||
1286 | 1278 | return; | ||
1287 | 1279 | |||
1288 | 1280 | if (manager->priv->stream != NULL) { | ||
1289 | 1281 | g_object_unref (manager->priv->stream); | ||
1290 | 1282 | manager->priv->stream = NULL; | ||
1291 | 1283 | } | ||
1292 | 1284 | |||
1293 | 1285 | if (stream != NULL) { | ||
1294 | 1286 | manager->priv->stream = g_object_ref (stream); | ||
1295 | 1287 | } else { | ||
1296 | 1288 | g_warning ("Unable to get default sink"); | ||
1297 | 1289 | } | ||
1298 | 1290 | } | ||
1299 | 1291 | |||
1300 | 1292 | static void | ||
1301 | 1293 | on_control_state_changed (GvcMixerControl *control, | ||
1302 | 1294 | GvcMixerControlState new_state, | ||
1303 | 1295 | GsdMediaKeysManager *manager) | ||
1304 | 1296 | { | ||
1305 | 1297 | update_default_sink (manager); | ||
1306 | 1298 | } | ||
1307 | 1299 | |||
1308 | 1300 | static void | ||
1309 | 1301 | on_control_default_sink_changed (GvcMixerControl *control, | ||
1310 | 1302 | guint id, | ||
1311 | 1303 | GsdMediaKeysManager *manager) | ||
1312 | 1304 | { | ||
1313 | 1305 | update_default_sink (manager); | ||
1314 | 1306 | } | ||
1315 | 1307 | |||
1316 | 1308 | #ifdef HAVE_GUDEV | ||
1317 | 1309 | static gboolean | ||
1318 | 1310 | remove_stream (gpointer key, | ||
1319 | 1311 | gpointer value, | ||
1320 | 1312 | gpointer id) | ||
1321 | 1313 | { | ||
1322 | 1314 | if (GPOINTER_TO_UINT (value) == GPOINTER_TO_UINT (id)) | ||
1323 | 1315 | return TRUE; | ||
1324 | 1316 | return FALSE; | ||
1325 | 1317 | } | ||
1326 | 1318 | #endif /* HAVE_GUDEV */ | ||
1327 | 1319 | |||
1328 | 1320 | static void | ||
1329 | 1321 | on_control_stream_removed (GvcMixerControl *control, | ||
1330 | 1322 | guint id, | ||
1331 | 1323 | GsdMediaKeysManager *manager) | ||
1332 | 1324 | { | ||
1333 | 1325 | if (manager->priv->stream != NULL) { | ||
1334 | 1326 | if (gvc_mixer_stream_get_id (manager->priv->stream) == id) { | ||
1335 | 1327 | g_object_unref (manager->priv->stream); | ||
1336 | 1328 | manager->priv->stream = NULL; | ||
1337 | 1329 | } | ||
1338 | 1330 | } | ||
1339 | 1331 | |||
1340 | 1332 | #ifdef HAVE_GUDEV | ||
1341 | 1333 | g_hash_table_foreach_remove (manager->priv->streams, (GHRFunc) remove_stream, GUINT_TO_POINTER (id)); | ||
1342 | 1334 | #endif | ||
1343 | 1335 | } | ||
1344 | 1336 | |||
1345 | 1337 | static void | ||
1346 | 1338 | free_media_player (MediaPlayer *player) | ||
1347 | 1339 | { | ||
1348 | 1340 | if (player->watch_id > 0) { | ||
1349 | 1341 | g_bus_unwatch_name (player->watch_id); | ||
1350 | 1342 | player->watch_id = 0; | ||
1351 | 1343 | } | ||
1352 | 1344 | g_free (player->application); | ||
1353 | 1345 | g_free (player->name); | ||
1354 | 1346 | g_free (player); | ||
1355 | 1347 | } | ||
1356 | 1348 | |||
1357 | 1349 | static gint | ||
1358 | 1350 | find_by_application (gconstpointer a, | ||
1359 | 1351 | gconstpointer b) | ||
1360 | 1352 | { | ||
1361 | 1353 | return strcmp (((MediaPlayer *)a)->application, b); | ||
1362 | 1354 | } | ||
1363 | 1355 | |||
1364 | 1356 | static gint | ||
1365 | 1357 | find_by_name (gconstpointer a, | ||
1366 | 1358 | gconstpointer b) | ||
1367 | 1359 | { | ||
1368 | 1360 | return strcmp (((MediaPlayer *)a)->name, b); | ||
1369 | 1361 | } | ||
1370 | 1362 | |||
1371 | 1363 | static gint | ||
1372 | 1364 | find_by_time (gconstpointer a, | ||
1373 | 1365 | gconstpointer b) | ||
1374 | 1366 | { | ||
1375 | 1367 | return ((MediaPlayer *)a)->time < ((MediaPlayer *)b)->time; | ||
1376 | 1368 | } | ||
1377 | 1369 | |||
1378 | 1370 | static void | ||
1379 | 1371 | name_vanished_handler (GDBusConnection *connection, | ||
1380 | 1372 | const gchar *name, | ||
1381 | 1373 | GsdMediaKeysManager *manager) | ||
1382 | 1374 | { | ||
1383 | 1375 | GList *iter; | ||
1384 | 1376 | |||
1385 | 1377 | iter = g_list_find_custom (manager->priv->media_players, | ||
1386 | 1378 | name, | ||
1387 | 1379 | find_by_name); | ||
1388 | 1380 | |||
1389 | 1381 | if (iter != NULL) { | ||
1390 | 1382 | MediaPlayer *player; | ||
1391 | 1383 | |||
1392 | 1384 | player = iter->data; | ||
1393 | 1385 | g_debug ("Deregistering vanished %s (name: %s)", player->application, player->name); | ||
1394 | 1386 | free_media_player (player); | ||
1395 | 1387 | manager->priv->media_players = g_list_delete_link (manager->priv->media_players, iter); | ||
1396 | 1388 | } | ||
1397 | 1389 | } | ||
1398 | 1390 | |||
1399 | 1391 | /* | ||
1400 | 1392 | * Register a new media player. Most applications will want to call | ||
1401 | 1393 | * this with time = GDK_CURRENT_TIME. This way, the last registered | ||
1402 | 1394 | * player will receive media events. In some cases, applications | ||
1403 | 1395 | * may want to register with a lower priority (usually 1), to grab | ||
1404 | 1396 | * events only nobody is interested. | ||
1405 | 1397 | */ | ||
1406 | 1398 | static void | ||
1407 | 1399 | gsd_media_keys_manager_grab_media_player_keys (GsdMediaKeysManager *manager, | ||
1408 | 1400 | const char *application, | ||
1409 | 1401 | const char *name, | ||
1410 | 1402 | guint32 time) | ||
1411 | 1403 | { | ||
1412 | 1404 | GList *iter; | ||
1413 | 1405 | MediaPlayer *media_player; | ||
1414 | 1406 | guint watch_id; | ||
1415 | 1407 | |||
1416 | 1408 | if (time == GDK_CURRENT_TIME) { | ||
1417 | 1409 | GTimeVal tv; | ||
1418 | 1410 | |||
1419 | 1411 | g_get_current_time (&tv); | ||
1420 | 1412 | time = tv.tv_sec * 1000 + tv.tv_usec / 1000; | ||
1421 | 1413 | } | ||
1422 | 1414 | |||
1423 | 1415 | iter = g_list_find_custom (manager->priv->media_players, | ||
1424 | 1416 | application, | ||
1425 | 1417 | find_by_application); | ||
1426 | 1418 | |||
1427 | 1419 | if (iter != NULL) { | ||
1428 | 1420 | if (((MediaPlayer *)iter->data)->time < time) { | ||
1429 | 1421 | MediaPlayer *player = iter->data; | ||
1430 | 1422 | free_media_player (player); | ||
1431 | 1423 | manager->priv->media_players = g_list_delete_link (manager->priv->media_players, iter); | ||
1432 | 1424 | } else { | ||
1433 | 1425 | return; | ||
1434 | 1426 | } | ||
1435 | 1427 | } | ||
1436 | 1428 | |||
1437 | 1429 | watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION, | ||
1438 | 1430 | name, | ||
1439 | 1431 | G_BUS_NAME_WATCHER_FLAGS_NONE, | ||
1440 | 1432 | NULL, | ||
1441 | 1433 | (GBusNameVanishedCallback) name_vanished_handler, | ||
1442 | 1434 | manager, | ||
1443 | 1435 | NULL); | ||
1444 | 1436 | |||
1445 | 1437 | g_debug ("Registering %s at %u", application, time); | ||
1446 | 1438 | media_player = g_new0 (MediaPlayer, 1); | ||
1447 | 1439 | media_player->application = g_strdup (application); | ||
1448 | 1440 | media_player->name = g_strdup (name); | ||
1449 | 1441 | media_player->time = time; | ||
1450 | 1442 | media_player->watch_id = watch_id; | ||
1451 | 1443 | |||
1452 | 1444 | manager->priv->media_players = g_list_insert_sorted (manager->priv->media_players, | ||
1453 | 1445 | media_player, | ||
1454 | 1446 | find_by_time); | ||
1455 | 1447 | } | ||
1456 | 1448 | |||
1457 | 1449 | static void | ||
1458 | 1450 | gsd_media_keys_manager_release_media_player_keys (GsdMediaKeysManager *manager, | ||
1459 | 1451 | const char *application, | ||
1460 | 1452 | const char *name) | ||
1461 | 1453 | { | ||
1462 | 1454 | GList *iter = NULL; | ||
1463 | 1455 | |||
1464 | 1456 | g_return_if_fail (application != NULL || name != NULL); | ||
1465 | 1457 | |||
1466 | 1458 | if (application != NULL) { | ||
1467 | 1459 | iter = g_list_find_custom (manager->priv->media_players, | ||
1468 | 1460 | application, | ||
1469 | 1461 | find_by_application); | ||
1470 | 1462 | } | ||
1471 | 1463 | |||
1472 | 1464 | if (iter == NULL && name != NULL) { | ||
1473 | 1465 | iter = g_list_find_custom (manager->priv->media_players, | ||
1474 | 1466 | name, | ||
1475 | 1467 | find_by_name); | ||
1476 | 1468 | } | ||
1477 | 1469 | |||
1478 | 1470 | if (iter != NULL) { | ||
1479 | 1471 | MediaPlayer *player; | ||
1480 | 1472 | |||
1481 | 1473 | player = iter->data; | ||
1482 | 1474 | g_debug ("Deregistering %s (name: %s)", application, player->name); | ||
1483 | 1475 | free_media_player (player); | ||
1484 | 1476 | manager->priv->media_players = g_list_delete_link (manager->priv->media_players, iter); | ||
1485 | 1477 | } | ||
1486 | 1478 | } | ||
1487 | 1479 | |||
1488 | 1480 | static gboolean | ||
1489 | 1481 | gsd_media_player_key_pressed (GsdMediaKeysManager *manager, | ||
1490 | 1482 | const char *key) | ||
1491 | 1483 | { | ||
1492 | 1484 | const char *application; | ||
1493 | 1485 | gboolean have_listeners; | ||
1494 | 1486 | GError *error = NULL; | ||
1495 | 1487 | MediaPlayer *player; | ||
1496 | 1488 | |||
1497 | 1489 | g_return_val_if_fail (key != NULL, FALSE); | ||
1498 | 1490 | |||
1499 | 1491 | g_debug ("Media key '%s' pressed", key); | ||
1500 | 1492 | |||
1501 | 1493 | have_listeners = (manager->priv->media_players != NULL); | ||
1502 | 1494 | |||
1503 | 1495 | if (!have_listeners) { | ||
1504 | 1496 | /* Popup a dialog with an (/) icon */ | ||
1505 | 1497 | dialog_init (manager); | ||
1506 | 1498 | gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), | ||
1507 | 1499 | "action-unavailable-symbolic", | ||
1508 | 1500 | FALSE); | ||
1509 | 1501 | dialog_show (manager); | ||
1510 | 1502 | return TRUE; | ||
1511 | 1503 | } | ||
1512 | 1504 | |||
1513 | 1505 | player = manager->priv->media_players->data; | ||
1514 | 1506 | application = player->application; | ||
1515 | 1507 | |||
1516 | 1508 | if (g_dbus_connection_emit_signal (manager->priv->connection, | ||
1517 | 1509 | player->name, | ||
1518 | 1510 | GSD_MEDIA_KEYS_DBUS_PATH, | ||
1519 | 1511 | GSD_MEDIA_KEYS_DBUS_NAME, | ||
1520 | 1512 | "MediaPlayerKeyPressed", | ||
1521 | 1513 | g_variant_new ("(ss)", application ? application : "", key), | ||
1522 | 1514 | &error) == FALSE) { | ||
1523 | 1515 | g_debug ("Error emitting signal: %s", error->message); | ||
1524 | 1516 | g_error_free (error); | ||
1525 | 1517 | } | ||
1526 | 1518 | |||
1527 | 1519 | return !have_listeners; | ||
1528 | 1520 | } | ||
1529 | 1521 | |||
1530 | 1522 | static void | ||
1531 | 1523 | handle_method_call (GDBusConnection *connection, | ||
1532 | 1524 | const gchar *sender, | ||
1533 | 1525 | const gchar *object_path, | ||
1534 | 1526 | const gchar *interface_name, | ||
1535 | 1527 | const gchar *method_name, | ||
1536 | 1528 | GVariant *parameters, | ||
1537 | 1529 | GDBusMethodInvocation *invocation, | ||
1538 | 1530 | gpointer user_data) | ||
1539 | 1531 | { | ||
1540 | 1532 | GsdMediaKeysManager *manager = (GsdMediaKeysManager *) user_data; | ||
1541 | 1533 | |||
1542 | 1534 | g_debug ("Calling method '%s' for media-keys", method_name); | ||
1543 | 1535 | |||
1544 | 1536 | if (g_strcmp0 (method_name, "ReleaseMediaPlayerKeys") == 0) { | ||
1545 | 1537 | const char *app_name; | ||
1546 | 1538 | |||
1547 | 1539 | g_variant_get (parameters, "(&s)", &app_name); | ||
1548 | 1540 | gsd_media_keys_manager_release_media_player_keys (manager, app_name, sender); | ||
1549 | 1541 | g_dbus_method_invocation_return_value (invocation, NULL); | ||
1550 | 1542 | } else if (g_strcmp0 (method_name, "GrabMediaPlayerKeys") == 0) { | ||
1551 | 1543 | const char *app_name; | ||
1552 | 1544 | guint32 time; | ||
1553 | 1545 | |||
1554 | 1546 | g_variant_get (parameters, "(&su)", &app_name, &time); | ||
1555 | 1547 | gsd_media_keys_manager_grab_media_player_keys (manager, app_name, sender, time); | ||
1556 | 1548 | g_dbus_method_invocation_return_value (invocation, NULL); | ||
1557 | 1549 | } | ||
1558 | 1550 | } | ||
1559 | 1551 | |||
1560 | 1552 | static const GDBusInterfaceVTable interface_vtable = | ||
1561 | 1553 | { | ||
1562 | 1554 | handle_method_call, | ||
1563 | 1555 | NULL, /* Get Property */ | ||
1564 | 1556 | NULL, /* Set Property */ | ||
1565 | 1557 | }; | ||
1566 | 1558 | |||
1567 | 1559 | static gboolean | ||
1568 | 1560 | do_multimedia_player_action (GsdMediaKeysManager *manager, | ||
1569 | 1561 | const char *icon, | ||
1570 | 1562 | const char *key) | ||
1571 | 1563 | { | ||
1572 | 1564 | if (icon != NULL) | ||
1573 | 1565 | ubuntu_osd_notification_show_icon (icon, key); | ||
1574 | 1566 | return gsd_media_player_key_pressed (manager, key); | ||
1575 | 1567 | } | ||
1576 | 1568 | |||
1577 | 1569 | static void | ||
1578 | 1570 | on_xrandr_action_call_finished (GObject *source_object, | ||
1579 | 1571 | GAsyncResult *res, | ||
1580 | 1572 | GsdMediaKeysManager *manager) | ||
1581 | 1573 | { | ||
1582 | 1574 | GError *error = NULL; | ||
1583 | 1575 | GVariant *variant; | ||
1584 | 1576 | char *action; | ||
1585 | 1577 | |||
1586 | 1578 | action = g_object_get_data (G_OBJECT (source_object), | ||
1587 | 1579 | "gsd-media-keys-manager-xrandr-action"); | ||
1588 | 1580 | |||
1589 | 1581 | variant = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); | ||
1590 | 1582 | |||
1591 | 1583 | g_object_unref (manager->priv->cancellable); | ||
1592 | 1584 | manager->priv->cancellable = NULL; | ||
1593 | 1585 | |||
1594 | 1586 | if (error != NULL) { | ||
1595 | 1587 | g_warning ("Unable to call '%s': %s", action, error->message); | ||
1596 | 1588 | g_error_free (error); | ||
1597 | 1589 | } else { | ||
1598 | 1590 | g_variant_unref (variant); | ||
1599 | 1591 | } | ||
1600 | 1592 | |||
1601 | 1593 | g_free (action); | ||
1602 | 1594 | } | ||
1603 | 1595 | |||
1604 | 1596 | static void | ||
1605 | 1597 | do_xrandr_action (GsdMediaKeysManager *manager, | ||
1606 | 1598 | const char *action, | ||
1607 | 1599 | gint64 timestamp) | ||
1608 | 1600 | { | ||
1609 | 1601 | GsdMediaKeysManagerPrivate *priv = manager->priv; | ||
1610 | 1602 | |||
1611 | 1603 | if (priv->connection == NULL || priv->xrandr_proxy == NULL) { | ||
1612 | 1604 | g_warning ("No existing D-Bus connection trying to handle XRANDR keys"); | ||
1613 | 1605 | return; | ||
1614 | 1606 | } | ||
1615 | 1607 | |||
1616 | 1608 | if (priv->cancellable != NULL) { | ||
1617 | 1609 | g_debug ("xrandr action already in flight"); | ||
1618 | 1610 | return; | ||
1619 | 1611 | } | ||
1620 | 1612 | |||
1621 | 1613 | priv->cancellable = g_cancellable_new (); | ||
1622 | 1614 | |||
1623 | 1615 | g_object_set_data (G_OBJECT (priv->xrandr_proxy), | ||
1624 | 1616 | "gsd-media-keys-manager-xrandr-action", | ||
1625 | 1617 | g_strdup (action)); | ||
1626 | 1618 | |||
1627 | 1619 | g_dbus_proxy_call (priv->xrandr_proxy, | ||
1628 | 1620 | action, | ||
1629 | 1621 | g_variant_new ("(x)", timestamp), | ||
1630 | 1622 | G_DBUS_CALL_FLAGS_NONE, | ||
1631 | 1623 | -1, | ||
1632 | 1624 | priv->cancellable, | ||
1633 | 1625 | (GAsyncReadyCallback) on_xrandr_action_call_finished, | ||
1634 | 1626 | manager); | ||
1635 | 1627 | } | ||
1636 | 1628 | |||
1637 | 1629 | static gboolean | ||
1638 | 1630 | do_video_out_action (GsdMediaKeysManager *manager, | ||
1639 | 1631 | gint64 timestamp) | ||
1640 | 1632 | { | ||
1641 | 1633 | do_xrandr_action (manager, "VideoModeSwitch", timestamp); | ||
1642 | 1634 | return FALSE; | ||
1643 | 1635 | } | ||
1644 | 1636 | |||
1645 | 1637 | static gboolean | ||
1646 | 1638 | do_video_rotate_action (GsdMediaKeysManager *manager, | ||
1647 | 1639 | gint64 timestamp) | ||
1648 | 1640 | { | ||
1649 | 1641 | do_xrandr_action (manager, "Rotate", timestamp); | ||
1650 | 1642 | return FALSE; | ||
1651 | 1643 | } | ||
1652 | 1644 | |||
1653 | 1645 | static void | ||
1654 | 1646 | do_toggle_accessibility_key (const char *key) | ||
1655 | 1647 | { | ||
1656 | 1648 | GSettings *settings; | ||
1657 | 1649 | gboolean state; | ||
1658 | 1650 | |||
1659 | 1651 | settings = g_settings_new ("org.gnome.desktop.a11y.applications"); | ||
1660 | 1652 | state = g_settings_get_boolean (settings, key); | ||
1661 | 1653 | g_settings_set_boolean (settings, key, !state); | ||
1662 | 1654 | g_object_unref (settings); | ||
1663 | 1655 | } | ||
1664 | 1656 | |||
1665 | 1657 | static void | ||
1666 | 1658 | do_magnifier_action (GsdMediaKeysManager *manager) | ||
1667 | 1659 | { | ||
1668 | 1660 | do_toggle_accessibility_key ("screen-magnifier-enabled"); | ||
1669 | 1661 | } | ||
1670 | 1662 | |||
1671 | 1663 | static void | ||
1672 | 1664 | do_screenreader_action (GsdMediaKeysManager *manager) | ||
1673 | 1665 | { | ||
1674 | 1666 | do_toggle_accessibility_key ("screen-reader-enabled"); | ||
1675 | 1667 | } | ||
1676 | 1668 | |||
1677 | 1669 | static void | ||
1678 | 1670 | do_on_screen_keyboard_action (GsdMediaKeysManager *manager) | ||
1679 | 1671 | { | ||
1680 | 1672 | do_toggle_accessibility_key ("screen-keyboard-enabled"); | ||
1681 | 1673 | } | ||
1682 | 1674 | |||
1683 | 1675 | static void | ||
1684 | 1676 | do_text_size_action (GsdMediaKeysManager *manager, | ||
1685 | 1677 | MediaKeyType type) | ||
1686 | 1678 | { | ||
1687 | 1679 | gdouble factor, best, distance; | ||
1688 | 1680 | guint i; | ||
1689 | 1681 | |||
1690 | 1682 | /* Same values used in the Seeing tab of the Universal Access panel */ | ||
1691 | 1683 | static gdouble factors[] = { | ||
1692 | 1684 | 0.75, | ||
1693 | 1685 | 1.0, | ||
1694 | 1686 | 1.25, | ||
1695 | 1687 | 1.5 | ||
1696 | 1688 | }; | ||
1697 | 1689 | |||
1698 | 1690 | /* Figure out the current DPI scaling factor */ | ||
1699 | 1691 | factor = g_settings_get_double (manager->priv->interface_settings, "text-scaling-factor"); | ||
1700 | 1692 | factor += (type == INCREASE_TEXT_KEY ? 0.25 : -0.25); | ||
1701 | 1693 | |||
1702 | 1694 | /* Try to find a matching value */ | ||
1703 | 1695 | distance = 1e6; | ||
1704 | 1696 | best = 1.0; | ||
1705 | 1697 | for (i = 0; i < G_N_ELEMENTS(factors); i++) { | ||
1706 | 1698 | gdouble d; | ||
1707 | 1699 | d = fabs (factor - factors[i]); | ||
1708 | 1700 | if (d < distance) { | ||
1709 | 1701 | best = factors[i]; | ||
1710 | 1702 | distance = d; | ||
1711 | 1703 | } | ||
1712 | 1704 | } | ||
1713 | 1705 | |||
1714 | 1706 | if (best == 1.0) | ||
1715 | 1707 | g_settings_reset (manager->priv->interface_settings, "text-scaling-factor"); | ||
1716 | 1708 | else | ||
1717 | 1709 | g_settings_set_double (manager->priv->interface_settings, "text-scaling-factor", best); | ||
1718 | 1710 | } | ||
1719 | 1711 | |||
1720 | 1712 | static void | ||
1721 | 1713 | do_magnifier_zoom_action (GsdMediaKeysManager *manager, | ||
1722 | 1714 | MediaKeyType type) | ||
1723 | 1715 | { | ||
1724 | 1716 | GSettings *settings; | ||
1725 | 1717 | gdouble offset, value; | ||
1726 | 1718 | |||
1727 | 1719 | if (type == MAGNIFIER_ZOOM_IN_KEY) | ||
1728 | 1720 | offset = 1.0; | ||
1729 | 1721 | else | ||
1730 | 1722 | offset = -1.0; | ||
1731 | 1723 | |||
1732 | 1724 | settings = g_settings_new ("org.gnome.desktop.a11y.magnifier"); | ||
1733 | 1725 | value = g_settings_get_double (settings, "mag-factor"); | ||
1734 | 1726 | value += offset; | ||
1735 | 1727 | value = roundl (value); | ||
1736 | 1728 | g_settings_set_double (settings, "mag-factor", value); | ||
1737 | 1729 | g_object_unref (settings); | ||
1738 | 1730 | } | ||
1739 | 1731 | |||
1740 | 1732 | static void | ||
1741 | 1733 | do_toggle_contrast_action (GsdMediaKeysManager *manager) | ||
1742 | 1734 | { | ||
1743 | 1735 | gboolean high_contrast; | ||
1744 | 1736 | char *theme; | ||
1745 | 1737 | |||
1746 | 1738 | /* Are we using HighContrast now? */ | ||
1747 | 1739 | theme = g_settings_get_string (manager->priv->interface_settings, "gtk-theme"); | ||
1748 | 1740 | high_contrast = g_str_equal (theme, HIGH_CONTRAST); | ||
1749 | 1741 | g_free (theme); | ||
1750 | 1742 | |||
1751 | 1743 | if (high_contrast != FALSE) { | ||
1752 | 1744 | if (manager->priv->gtk_theme == NULL) | ||
1753 | 1745 | g_settings_reset (manager->priv->interface_settings, "gtk-theme"); | ||
1754 | 1746 | else | ||
1755 | 1747 | g_settings_set (manager->priv->interface_settings, "gtk-theme", manager->priv->gtk_theme); | ||
1756 | 1748 | g_settings_set (manager->priv->interface_settings, "icon-theme", manager->priv->icon_theme); | ||
1757 | 1749 | } else { | ||
1758 | 1750 | g_settings_set (manager->priv->interface_settings, "gtk-theme", HIGH_CONTRAST); | ||
1759 | 1751 | g_settings_set (manager->priv->interface_settings, "icon-theme", HIGH_CONTRAST); | ||
1760 | 1752 | } | ||
1761 | 1753 | } | ||
1762 | 1754 | |||
1763 | 1755 | static void | ||
1764 | 1756 | upower_sleep_cb (GObject *source_object, | ||
1765 | 1757 | GAsyncResult *res, | ||
1766 | 1758 | gpointer user_data) | ||
1767 | 1759 | { | ||
1768 | 1760 | GVariant *result; | ||
1769 | 1761 | GError *error = NULL; | ||
1770 | 1762 | |||
1771 | 1763 | result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), | ||
1772 | 1764 | res, | ||
1773 | 1765 | &error); | ||
1774 | 1766 | if (result == NULL) { | ||
1775 | 1767 | g_warning ("couldn't sleep using UPower: %s", | ||
1776 | 1768 | error->message); | ||
1777 | 1769 | g_error_free (error); | ||
1778 | 1770 | } else { | ||
1779 | 1771 | g_variant_unref (result); | ||
1780 | 1772 | } | ||
1781 | 1773 | } | ||
1782 | 1774 | |||
1783 | 1775 | static void | ||
1784 | 1776 | do_config_power_action (GsdMediaKeysManager *manager, | ||
1785 | 1777 | const gchar *config_key) | ||
1786 | 1778 | { | ||
1787 | 1779 | GsdPowerActionType action_type; | ||
1788 | 1780 | |||
1789 | 1781 | action_type = g_settings_get_enum (manager->priv->power_settings, | ||
1790 | 1782 | config_key); | ||
1791 | 1783 | switch (action_type) { | ||
1792 | 1784 | case GSD_POWER_ACTION_SUSPEND: | ||
1793 | 1785 | g_dbus_proxy_call (manager->priv->upower_proxy, | ||
1794 | 1786 | "Suspend", | ||
1795 | 1787 | NULL, | ||
1796 | 1788 | G_DBUS_CALL_FLAGS_NONE, | ||
1797 | 1789 | -1, NULL, | ||
1798 | 1790 | upower_sleep_cb, NULL); | ||
1799 | 1791 | break; | ||
1800 | 1792 | case GSD_POWER_ACTION_INTERACTIVE: | ||
1801 | 1793 | case GSD_POWER_ACTION_SHUTDOWN: | ||
1802 | 1794 | gnome_session_shutdown (manager); | ||
1803 | 1795 | break; | ||
1804 | 1796 | case GSD_POWER_ACTION_HIBERNATE: | ||
1805 | 1797 | g_dbus_proxy_call (manager->priv->upower_proxy, | ||
1806 | 1798 | "Hibernate", | ||
1807 | 1799 | NULL, | ||
1808 | 1800 | G_DBUS_CALL_FLAGS_NONE, | ||
1809 | 1801 | -1, NULL, | ||
1810 | 1802 | upower_sleep_cb, NULL); | ||
1811 | 1803 | break; | ||
1812 | 1804 | case GSD_POWER_ACTION_BLANK: | ||
1813 | 1805 | case GSD_POWER_ACTION_NOTHING: | ||
1814 | 1806 | /* these actions cannot be handled by media-keys and | ||
1815 | 1807 | * are not used in this context */ | ||
1816 | 1808 | break; | ||
1817 | 1809 | } | ||
1818 | 1810 | } | ||
1819 | 1811 | |||
1820 | 1812 | static void | ||
1821 | 1813 | update_screen_cb (GObject *source_object, | ||
1822 | 1814 | GAsyncResult *res, | ||
1823 | 1815 | gpointer user_data) | ||
1824 | 1816 | { | ||
1825 | 1817 | GError *error = NULL; | ||
1826 | 1818 | guint percentage; | ||
1827 | 1819 | GVariant *new_percentage; | ||
1828 | 1820 | GsdBrightnessActionData *data = (GsdBrightnessActionData *) user_data; | ||
1829 | 1821 | GsdMediaKeysManager *manager = data->manager; | ||
1830 | 1822 | |||
1831 | 1823 | new_percentage = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), | ||
1832 | 1824 | res, &error); | ||
1833 | 1825 | if (new_percentage == NULL) { | ||
1834 | 1826 | g_warning ("Failed to set new screen percentage: %s", | ||
1835 | 1827 | error->message); | ||
1836 | 1828 | g_error_free (error); | ||
1837 | 1829 | g_free (data); | ||
1838 | 1830 | return; | ||
1839 | 1831 | } | ||
1840 | 1832 | |||
1841 | 1833 | /* update the dialog with the new value */ | ||
1842 | 1834 | g_variant_get (new_percentage, "(u)", &percentage); | ||
1843 | 1835 | |||
1844 | 1836 | guint osd_percentage; | ||
1845 | 1837 | if (data->old_percentage == 100 && data->type == SCREEN_BRIGHTNESS_UP_KEY) | ||
1846 | 1838 | osd_percentage = 101; | ||
1847 | 1839 | else if (data->old_percentage == 0 && data->type == SCREEN_BRIGHTNESS_DOWN_KEY) | ||
1848 | 1840 | osd_percentage = -1; | ||
1849 | 1841 | else | ||
1850 | 1842 | osd_percentage = CLAMP (percentage, 0, 100); | ||
1851 | 1843 | |||
1852 | 1844 | if (!ubuntu_osd_notification_show_brightness (manager, osd_percentage)) { | ||
1853 | 1845 | dialog_init (manager); | ||
1854 | 1846 | gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), | ||
1855 | 1847 | "display-brightness-symbolic", | ||
1856 | 1848 | TRUE); | ||
1857 | 1849 | gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), | ||
1858 | 1850 | percentage); | ||
1859 | 1851 | dialog_show (manager); | ||
1860 | 1852 | } | ||
1861 | 1853 | g_free (data); | ||
1862 | 1854 | g_variant_unref (new_percentage); | ||
1863 | 1855 | } | ||
1864 | 1856 | |||
1865 | 1857 | static void | ||
1866 | 1858 | do_screen_brightness_action_real (GObject *source_object, | ||
1867 | 1859 | GAsyncResult *res, | ||
1868 | 1860 | gpointer user_data) | ||
1869 | 1861 | { | ||
1870 | 1862 | GsdBrightnessActionData *data = (GsdBrightnessActionData *) user_data; | ||
1871 | 1863 | GsdMediaKeysManager *manager = data->manager; | ||
1872 | 1864 | GError *error = NULL; | ||
1873 | 1865 | |||
1874 | 1866 | GVariant *old_percentage = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), | ||
1875 | 1867 | res, &error); | ||
1876 | 1868 | if (old_percentage == NULL) { | ||
1877 | 1869 | g_warning ("Failed to get old screen percentage: %s", error->message); | ||
1878 | 1870 | g_error_free (error); | ||
1879 | 1871 | g_free (data); | ||
1880 | 1872 | return; | ||
1881 | 1873 | } | ||
1882 | 1874 | |||
1883 | 1875 | g_variant_get (old_percentage, "(u)", &data->old_percentage); | ||
1884 | 1876 | |||
1885 | 1877 | /* call into the power plugin */ | ||
1886 | 1878 | g_dbus_proxy_call (manager->priv->power_screen_proxy, | ||
1887 | 1879 | data->type == SCREEN_BRIGHTNESS_UP_KEY ? "StepUp" : "StepDown", | ||
1888 | 1880 | NULL, | ||
1889 | 1881 | G_DBUS_CALL_FLAGS_NONE, | ||
1890 | 1882 | -1, | ||
1891 | 1883 | NULL, | ||
1892 | 1884 | update_screen_cb, | ||
1893 | 1885 | data); | ||
1894 | 1886 | |||
1895 | 1887 | g_variant_unref (old_percentage); | ||
1896 | 1888 | } | ||
1897 | 1889 | |||
1898 | 1890 | static void | ||
1899 | 1891 | do_screen_brightness_action (GsdMediaKeysManager *manager, | ||
1900 | 1892 | MediaKeyType type) | ||
1901 | 1893 | { | ||
1902 | 1894 | if (manager->priv->connection == NULL || | ||
1903 | 1895 | manager->priv->power_screen_proxy == NULL) { | ||
1904 | 1896 | g_warning ("No existing D-Bus connection trying to handle power keys"); | ||
1905 | 1897 | return; | ||
1906 | 1898 | } | ||
1907 | 1899 | |||
1908 | 1900 | GsdBrightnessActionData *data = g_new0 (GsdBrightnessActionData, 1); | ||
1909 | 1901 | data->manager = manager; | ||
1910 | 1902 | data->type = type; | ||
1911 | 1903 | |||
1912 | 1904 | g_dbus_proxy_call (manager->priv->power_screen_proxy, | ||
1913 | 1905 | "GetPercentage", | ||
1914 | 1906 | NULL, | ||
1915 | 1907 | G_DBUS_CALL_FLAGS_NONE, | ||
1916 | 1908 | -1, | ||
1917 | 1909 | NULL, | ||
1918 | 1910 | do_screen_brightness_action_real, | ||
1919 | 1911 | data); | ||
1920 | 1912 | } | ||
1921 | 1913 | |||
1922 | 1914 | static void | ||
1923 | 1915 | update_keyboard_cb (GObject *source_object, | ||
1924 | 1916 | GAsyncResult *res, | ||
1925 | 1917 | gpointer user_data) | ||
1926 | 1918 | { | ||
1927 | 1919 | GError *error = NULL; | ||
1928 | 1920 | guint percentage; | ||
1929 | 1921 | GVariant *new_percentage; | ||
1930 | 1922 | GsdMediaKeysManager *manager = GSD_MEDIA_KEYS_MANAGER (user_data); | ||
1931 | 1923 | |||
1932 | 1924 | new_percentage = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), | ||
1933 | 1925 | res, &error); | ||
1934 | 1926 | if (new_percentage == NULL) { | ||
1935 | 1927 | g_warning ("Failed to set new keyboard percentage: %s", | ||
1936 | 1928 | error->message); | ||
1937 | 1929 | g_error_free (error); | ||
1938 | 1930 | return; | ||
1939 | 1931 | } | ||
1940 | 1932 | |||
1941 | 1933 | /* update the dialog with the new value */ | ||
1942 | 1934 | g_variant_get (new_percentage, "(u)", &percentage); | ||
1943 | 1935 | |||
1944 | 1936 | /* FIXME: No overshoot effect for keyboard, as the power plugin has no interface | ||
1945 | 1937 | * to get the old brightness */ | ||
1946 | 1938 | if (!ubuntu_osd_notification_show_kb_backlight (manager, CLAMP (percentage, 0, 100))) { | ||
1947 | 1939 | dialog_init (manager); | ||
1948 | 1940 | gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), | ||
1949 | 1941 | "keyboard-brightness-symbolic", | ||
1950 | 1942 | TRUE); | ||
1951 | 1943 | gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), | ||
1952 | 1944 | percentage); | ||
1953 | 1945 | dialog_show (manager); | ||
1954 | 1946 | } | ||
1955 | 1947 | g_variant_unref (new_percentage); | ||
1956 | 1948 | } | ||
1957 | 1949 | |||
1958 | 1950 | static void | ||
1959 | 1951 | do_keyboard_brightness_action (GsdMediaKeysManager *manager, | ||
1960 | 1952 | MediaKeyType type) | ||
1961 | 1953 | { | ||
1962 | 1954 | if (manager->priv->connection == NULL || | ||
1963 | 1955 | manager->priv->power_keyboard_proxy == NULL) { | ||
1964 | 1956 | g_warning ("No existing D-Bus connection trying to handle power keys"); | ||
1965 | 1957 | return; | ||
1966 | 1958 | } | ||
1967 | 1959 | |||
1968 | 1960 | /* call into the power plugin */ | ||
1969 | 1961 | g_dbus_proxy_call (manager->priv->power_keyboard_proxy, | ||
1970 | 1962 | type == KEYBOARD_BRIGHTNESS_UP_KEY ? "StepUp" : "StepDown", | ||
1971 | 1963 | NULL, | ||
1972 | 1964 | G_DBUS_CALL_FLAGS_NONE, | ||
1973 | 1965 | -1, | ||
1974 | 1966 | NULL, | ||
1975 | 1967 | update_keyboard_cb, | ||
1976 | 1968 | manager); | ||
1977 | 1969 | } | ||
1978 | 1970 | |||
1979 | 1971 | static void | ||
1980 | 1972 | do_custom_action (GsdMediaKeysManager *manager, | ||
1981 | 1973 | MediaKey *key, | ||
1982 | 1974 | gint64 timestamp) | ||
1983 | 1975 | { | ||
1984 | 1976 | execute (manager, key->custom_command, FALSE); | ||
1985 | 1977 | } | ||
1986 | 1978 | |||
1987 | 1979 | static gboolean | ||
1988 | 1980 | do_action (GsdMediaKeysManager *manager, | ||
1989 | 1981 | guint deviceid, | ||
1990 | 1982 | MediaKeyType type, | ||
1991 | 1983 | gint64 timestamp) | ||
1992 | 1984 | { | ||
1993 | 1985 | char *cmd; | ||
1994 | 1986 | |||
1995 | 1987 | g_debug ("Launching action for key type '%d' (on device id %d)", type, deviceid); | ||
1996 | 1988 | |||
1997 | 1989 | switch (type) { | ||
1998 | 1990 | case TOUCHPAD_KEY: | ||
1999 | 1991 | do_touchpad_action (manager); | ||
2000 | 1992 | break; | ||
2001 | 1993 | case TOUCHPAD_ON_KEY: | ||
2002 | 1994 | do_touchpad_osd_action (manager, TRUE); | ||
2003 | 1995 | break; | ||
2004 | 1996 | case TOUCHPAD_OFF_KEY: | ||
2005 | 1997 | do_touchpad_osd_action (manager, FALSE); | ||
2006 | 1998 | break; | ||
2007 | 1999 | case MUTE_KEY: | ||
2008 | 2000 | case VOLUME_DOWN_KEY: | ||
2009 | 2001 | case VOLUME_UP_KEY: | ||
2010 | 2002 | do_sound_action (manager, deviceid, type, FALSE); | ||
2011 | 2003 | break; | ||
2012 | 2004 | case MUTE_QUIET_KEY: | ||
2013 | 2005 | do_sound_action (manager, deviceid, MUTE_KEY, TRUE); | ||
2014 | 2006 | break; | ||
2015 | 2007 | case VOLUME_DOWN_QUIET_KEY: | ||
2016 | 2008 | do_sound_action (manager, deviceid, VOLUME_DOWN_KEY, TRUE); | ||
2017 | 2009 | break; | ||
2018 | 2010 | case VOLUME_UP_QUIET_KEY: | ||
2019 | 2011 | do_sound_action (manager, deviceid, VOLUME_UP_KEY, TRUE); | ||
2020 | 2012 | break; | ||
2021 | 2013 | case LOGOUT_KEY: | ||
2022 | 2014 | do_logout_action (manager); | ||
2023 | 2015 | break; | ||
2024 | 2016 | case EJECT_KEY: | ||
2025 | 2017 | do_eject_action (manager); | ||
2026 | 2018 | break; | ||
2027 | 2019 | case HOME_KEY: | ||
2028 | 2020 | do_home_key_action (manager, timestamp); | ||
2029 | 2021 | break; | ||
2030 | 2022 | case SEARCH_KEY: | ||
2031 | 2023 | cmd = NULL; | ||
2032 | 2024 | if ((cmd = g_find_program_in_path ("tracker-search-tool"))) | ||
2033 | 2025 | do_execute_desktop (manager, "tracker-needle.desktop", timestamp); | ||
2034 | 2026 | else | ||
2035 | 2027 | do_execute_desktop (manager, "gnome-search-tool.desktop", timestamp); | ||
2036 | 2028 | g_free (cmd); | ||
2037 | 2029 | break; | ||
2038 | 2030 | case EMAIL_KEY: | ||
2039 | 2031 | do_url_action (manager, "mailto", timestamp); | ||
2040 | 2032 | break; | ||
2041 | 2033 | case SCREENSAVER_KEY: | ||
2042 | 2034 | execute (manager, "gnome-screensaver-command --lock", FALSE); | ||
2043 | 2035 | break; | ||
2044 | 2036 | case HELP_KEY: | ||
2045 | 2037 | do_url_action (manager, "ghelp", timestamp); | ||
2046 | 2038 | break; | ||
2047 | 2039 | case SCREENSHOT_KEY: | ||
2048 | 2040 | execute (manager, "gnome-screenshot", FALSE); | ||
2049 | 2041 | break; | ||
2050 | 2042 | case WINDOW_SCREENSHOT_KEY: | ||
2051 | 2043 | execute (manager, "gnome-screenshot --window", FALSE); | ||
2052 | 2044 | break; | ||
2053 | 2045 | case AREA_SCREENSHOT_KEY: | ||
2054 | 2046 | execute (manager, "gnome-screenshot --area", FALSE); | ||
2055 | 2047 | break; | ||
2056 | 2048 | case SCREENSHOT_CLIP_KEY: | ||
2057 | 2049 | execute (manager, "gnome-screenshot --clipboard", FALSE); | ||
2058 | 2050 | break; | ||
2059 | 2051 | case WINDOW_SCREENSHOT_CLIP_KEY: | ||
2060 | 2052 | execute (manager, "gnome-screenshot --window --clipboard", FALSE); | ||
2061 | 2053 | break; | ||
2062 | 2054 | case AREA_SCREENSHOT_CLIP_KEY: | ||
2063 | 2055 | execute (manager, "gnome-screenshot --area --clipboard", FALSE); | ||
2064 | 2056 | break; | ||
2065 | 2057 | case WWW_KEY: | ||
2066 | 2058 | do_url_action (manager, "http", timestamp); | ||
2067 | 2059 | break; | ||
2068 | 2060 | case MEDIA_KEY: | ||
2069 | 2061 | do_media_action (manager, timestamp); | ||
2070 | 2062 | break; | ||
2071 | 2063 | case CALCULATOR_KEY: | ||
2072 | 2064 | do_execute_desktop (manager, "gcalctool.desktop", timestamp); | ||
2073 | 2065 | break; | ||
2074 | 2066 | case PLAY_KEY: | ||
2075 | 2067 | return do_multimedia_player_action (manager, NULL, "Play"); | ||
2076 | 2068 | case PAUSE_KEY: | ||
2077 | 2069 | return do_multimedia_player_action (manager, NULL, "Pause"); | ||
2078 | 2070 | case STOP_KEY: | ||
2079 | 2071 | return do_multimedia_player_action (manager, NULL, "Stop"); | ||
2080 | 2072 | case PREVIOUS_KEY: | ||
2081 | 2073 | return do_multimedia_player_action (manager, NULL, "Previous"); | ||
2082 | 2074 | case NEXT_KEY: | ||
2083 | 2075 | return do_multimedia_player_action (manager, NULL, "Next"); | ||
2084 | 2076 | case REWIND_KEY: | ||
2085 | 2077 | return do_multimedia_player_action (manager, NULL, "Rewind"); | ||
2086 | 2078 | case FORWARD_KEY: | ||
2087 | 2079 | return do_multimedia_player_action (manager, NULL, "FastForward"); | ||
2088 | 2080 | case REPEAT_KEY: | ||
2089 | 2081 | return do_multimedia_player_action (manager, NULL, "Repeat"); | ||
2090 | 2082 | case RANDOM_KEY: | ||
2091 | 2083 | return do_multimedia_player_action (manager, NULL, "Shuffle"); | ||
2092 | 2084 | case VIDEO_OUT_KEY: | ||
2093 | 2085 | do_video_out_action (manager, timestamp); | ||
2094 | 2086 | break; | ||
2095 | 2087 | case ROTATE_VIDEO_KEY: | ||
2096 | 2088 | do_video_rotate_action (manager, timestamp); | ||
2097 | 2089 | break; | ||
2098 | 2090 | case MAGNIFIER_KEY: | ||
2099 | 2091 | do_magnifier_action (manager); | ||
2100 | 2092 | break; | ||
2101 | 2093 | case SCREENREADER_KEY: | ||
2102 | 2094 | do_screenreader_action (manager); | ||
2103 | 2095 | break; | ||
2104 | 2096 | case ON_SCREEN_KEYBOARD_KEY: | ||
2105 | 2097 | do_on_screen_keyboard_action (manager); | ||
2106 | 2098 | break; | ||
2107 | 2099 | case INCREASE_TEXT_KEY: | ||
2108 | 2100 | case DECREASE_TEXT_KEY: | ||
2109 | 2101 | do_text_size_action (manager, type); | ||
2110 | 2102 | break; | ||
2111 | 2103 | case MAGNIFIER_ZOOM_IN_KEY: | ||
2112 | 2104 | case MAGNIFIER_ZOOM_OUT_KEY: | ||
2113 | 2105 | do_magnifier_zoom_action (manager, type); | ||
2114 | 2106 | break; | ||
2115 | 2107 | case TOGGLE_CONTRAST_KEY: | ||
2116 | 2108 | do_toggle_contrast_action (manager); | ||
2117 | 2109 | break; | ||
2118 | 2110 | case POWER_KEY: | ||
2119 | 2111 | do_config_power_action (manager, "button-power"); | ||
2120 | 2112 | break; | ||
2121 | 2113 | case SLEEP_KEY: | ||
2122 | 2114 | do_config_power_action (manager, "button-sleep"); | ||
2123 | 2115 | break; | ||
2124 | 2116 | case SUSPEND_KEY: | ||
2125 | 2117 | do_config_power_action (manager, "button-suspend"); | ||
2126 | 2118 | break; | ||
2127 | 2119 | case HIBERNATE_KEY: | ||
2128 | 2120 | do_config_power_action (manager, "button-hibernate"); | ||
2129 | 2121 | break; | ||
2130 | 2122 | case SCREEN_BRIGHTNESS_UP_KEY: | ||
2131 | 2123 | case SCREEN_BRIGHTNESS_DOWN_KEY: | ||
2132 | 2124 | do_screen_brightness_action (manager, type); | ||
2133 | 2125 | break; | ||
2134 | 2126 | case KEYBOARD_BRIGHTNESS_UP_KEY: | ||
2135 | 2127 | case KEYBOARD_BRIGHTNESS_DOWN_KEY: | ||
2136 | 2128 | case KEYBOARD_BRIGHTNESS_TOGGLE_KEY: | ||
2137 | 2129 | do_keyboard_brightness_action (manager, type); | ||
2138 | 2130 | break; | ||
2139 | 2131 | case BATTERY_KEY: | ||
2140 | 2132 | do_execute_desktop (manager, "gnome-power-statistics.desktop", timestamp); | ||
2141 | 2133 | break; | ||
2142 | 2134 | /* Note, no default so compiler catches missing keys */ | ||
2143 | 2135 | case CUSTOM_KEY: | ||
2144 | 2136 | g_assert_not_reached (); | ||
2145 | 2137 | } | ||
2146 | 2138 | |||
2147 | 2139 | return FALSE; | ||
2148 | 2140 | } | ||
2149 | 2141 | |||
2150 | 2142 | static GdkScreen * | ||
2151 | 2143 | get_screen_from_root (GsdMediaKeysManager *manager, | ||
2152 | 2144 | Window root) | ||
2153 | 2145 | { | ||
2154 | 2146 | GSList *l; | ||
2155 | 2147 | |||
2156 | 2148 | /* Look for which screen we're receiving events */ | ||
2157 | 2149 | for (l = manager->priv->screens; l != NULL; l = l->next) { | ||
2158 | 2150 | GdkScreen *screen = (GdkScreen *) l->data; | ||
2159 | 2151 | GdkWindow *window = gdk_screen_get_root_window (screen); | ||
2160 | 2152 | |||
2161 | 2153 | if (GDK_WINDOW_XID (window) == root) | ||
2162 | 2154 | return screen; | ||
2163 | 2155 | } | ||
2164 | 2156 | |||
2165 | 2157 | return NULL; | ||
2166 | 2158 | } | ||
2167 | 2159 | |||
2168 | 2160 | static GdkFilterReturn | ||
2169 | 2161 | filter_key_events (XEvent *xevent, | ||
2170 | 2162 | GdkEvent *event, | ||
2171 | 2163 | GsdMediaKeysManager *manager) | ||
2172 | 2164 | { | ||
2173 | 2165 | XIEvent *xiev; | ||
2174 | 2166 | XIDeviceEvent *xev; | ||
2175 | 2167 | XGenericEventCookie *cookie; | ||
2176 | 2168 | guint i; | ||
2177 | 2169 | guint deviceid; | ||
2178 | 2170 | |||
2179 | 2171 | /* verify we have a key event */ | ||
2180 | 2172 | if (xevent->type != GenericEvent) | ||
2181 | 2173 | return GDK_FILTER_CONTINUE; | ||
2182 | 2174 | cookie = &xevent->xcookie; | ||
2183 | 2175 | if (cookie->extension != manager->priv->opcode) | ||
2184 | 2176 | return GDK_FILTER_CONTINUE; | ||
2185 | 2177 | |||
2186 | 2178 | xiev = (XIEvent *) xevent->xcookie.data; | ||
2187 | 2179 | |||
2188 | 2180 | if (xiev->evtype != XI_KeyPress && | ||
2189 | 2181 | xiev->evtype != XI_KeyRelease) | ||
2190 | 2182 | return GDK_FILTER_CONTINUE; | ||
2191 | 2183 | |||
2192 | 2184 | xev = (XIDeviceEvent *) xiev; | ||
2193 | 2185 | |||
2194 | 2186 | deviceid = xev->sourceid; | ||
2195 | 2187 | |||
2196 | 2188 | for (i = 0; i < manager->priv->keys->len; i++) { | ||
2197 | 2189 | MediaKey *key; | ||
2198 | 2190 | |||
2199 | 2191 | key = g_ptr_array_index (manager->priv->keys, i); | ||
2200 | 2192 | |||
2201 | 2193 | if (match_xi2_key (key->key, xev)) { | ||
2202 | 2194 | switch (key->key_type) { | ||
2203 | 2195 | case VOLUME_DOWN_KEY: | ||
2204 | 2196 | case VOLUME_UP_KEY: | ||
2205 | 2197 | case VOLUME_DOWN_QUIET_KEY: | ||
2206 | 2198 | case VOLUME_UP_QUIET_KEY: | ||
2207 | 2199 | /* auto-repeatable keys */ | ||
2208 | 2200 | if (xiev->evtype != XI_KeyPress) | ||
2209 | 2201 | return GDK_FILTER_CONTINUE; | ||
2210 | 2202 | break; | ||
2211 | 2203 | default: | ||
2212 | 2204 | if (xiev->evtype != XI_KeyRelease) { | ||
2213 | 2205 | return GDK_FILTER_CONTINUE; | ||
2214 | 2206 | } | ||
2215 | 2207 | } | ||
2216 | 2208 | |||
2217 | 2209 | manager->priv->current_screen = get_screen_from_root (manager, xev->root); | ||
2218 | 2210 | |||
2219 | 2211 | if (key->key_type == CUSTOM_KEY) { | ||
2220 | 2212 | do_custom_action (manager, key, xev->time); | ||
2221 | 2213 | return GDK_FILTER_REMOVE; | ||
2222 | 2214 | } | ||
2223 | 2215 | |||
2224 | 2216 | if (do_action (manager, deviceid, key->key_type, xev->time) == FALSE) { | ||
2225 | 2217 | return GDK_FILTER_REMOVE; | ||
2226 | 2218 | } else { | ||
2227 | 2219 | return GDK_FILTER_CONTINUE; | ||
2228 | 2220 | } | ||
2229 | 2221 | } | ||
2230 | 2222 | } | ||
2231 | 2223 | |||
2232 | 2224 | return GDK_FILTER_CONTINUE; | ||
2233 | 2225 | } | ||
2234 | 2226 | |||
2235 | 2227 | static void | ||
2236 | 2228 | update_theme_settings (GSettings *settings, | ||
2237 | 2229 | const char *key, | ||
2238 | 2230 | GsdMediaKeysManager *manager) | ||
2239 | 2231 | { | ||
2240 | 2232 | char *theme; | ||
2241 | 2233 | |||
2242 | 2234 | theme = g_settings_get_string (manager->priv->interface_settings, key); | ||
2243 | 2235 | if (g_str_equal (theme, HIGH_CONTRAST)) { | ||
2244 | 2236 | g_free (theme); | ||
2245 | 2237 | } else { | ||
2246 | 2238 | if (g_str_equal (key, "gtk-theme")) { | ||
2247 | 2239 | g_free (manager->priv->gtk_theme); | ||
2248 | 2240 | manager->priv->gtk_theme = theme; | ||
2249 | 2241 | } else { | ||
2250 | 2242 | g_free (manager->priv->icon_theme); | ||
2251 | 2243 | manager->priv->icon_theme = theme; | ||
2252 | 2244 | } | ||
2253 | 2245 | } | ||
2254 | 2246 | } | ||
2255 | 2247 | |||
2256 | 2248 | static gboolean | ||
2257 | 2249 | start_media_keys_idle_cb (GsdMediaKeysManager *manager) | ||
2258 | 2250 | { | ||
2259 | 2251 | GSList *l; | ||
2260 | 2252 | char *theme_name; | ||
2261 | 2253 | |||
2262 | 2254 | g_debug ("Starting media_keys manager"); | ||
2263 | 2255 | gnome_settings_profile_start (NULL); | ||
2264 | 2256 | |||
2265 | 2257 | |||
2266 | 2258 | gvc_mixer_control_open (manager->priv->volume); | ||
2267 | 2259 | |||
2268 | 2260 | manager->priv->settings = g_settings_new (SETTINGS_BINDING_DIR); | ||
2269 | 2261 | g_signal_connect (G_OBJECT (manager->priv->settings), "changed", | ||
2270 | 2262 | G_CALLBACK (gsettings_changed_cb), manager); | ||
2271 | 2263 | |||
2272 | 2264 | manager->priv->gconf = gconf_client_get_default (); | ||
2273 | 2265 | gconf_client_add_dir (manager->priv->gconf, GCONF_BINDING_DIR, GCONF_CLIENT_PRELOAD_RECURSIVE, NULL); | ||
2274 | 2266 | manager->priv->gconf_id = gconf_client_notify_add (manager->priv->gconf, | ||
2275 | 2267 | GCONF_BINDING_DIR, | ||
2276 | 2268 | (GConfClientNotifyFunc) gconf_changed_cb, | ||
2277 | 2269 | manager, | ||
2278 | 2270 | NULL, | ||
2279 | 2271 | NULL); | ||
2280 | 2272 | |||
2281 | 2273 | /* Sound events */ | ||
2282 | 2274 | ca_context_create (&manager->priv->ca); | ||
2283 | 2275 | ca_context_set_driver (manager->priv->ca, "pulse"); | ||
2284 | 2276 | ca_context_change_props (manager->priv->ca, 0, | ||
2285 | 2277 | CA_PROP_APPLICATION_ID, "org.gnome.VolumeControl", | ||
2286 | 2278 | NULL); | ||
2287 | 2279 | manager->priv->gtksettings = gtk_settings_get_for_screen (gdk_screen_get_default ()); | ||
2288 | 2280 | g_object_get (G_OBJECT (manager->priv->gtksettings), "gtk-sound-theme-name", &theme_name, NULL); | ||
2289 | 2281 | if (theme_name) | ||
2290 | 2282 | ca_context_change_props (manager->priv->ca, CA_PROP_CANBERRA_XDG_THEME_NAME, theme_name, NULL); | ||
2291 | 2283 | g_free (theme_name); | ||
2292 | 2284 | g_signal_connect (manager->priv->gtksettings, "notify::gtk-sound-theme-name", | ||
2293 | 2285 | G_CALLBACK (sound_theme_changed), manager); | ||
2294 | 2286 | |||
2295 | 2287 | /* for the power plugin interface code */ | ||
2296 | 2288 | manager->priv->power_settings = g_settings_new (SETTINGS_POWER_DIR); | ||
2297 | 2289 | |||
2298 | 2290 | /* Logic from http://git.gnome.org/browse/gnome-shell/tree/js/ui/status/accessibility.js#n163 */ | ||
2299 | 2291 | manager->priv->interface_settings = g_settings_new (SETTINGS_INTERFACE_DIR); | ||
2300 | 2292 | g_signal_connect (G_OBJECT (manager->priv->interface_settings), "changed::gtk-theme", | ||
2301 | 2293 | G_CALLBACK (update_theme_settings), manager); | ||
2302 | 2294 | g_signal_connect (G_OBJECT (manager->priv->interface_settings), "changed::icon-theme", | ||
2303 | 2295 | G_CALLBACK (update_theme_settings), manager); | ||
2304 | 2296 | manager->priv->gtk_theme = g_settings_get_string (manager->priv->interface_settings, "gtk-theme"); | ||
2305 | 2297 | if (g_str_equal (manager->priv->gtk_theme, HIGH_CONTRAST)) { | ||
2306 | 2298 | g_free (manager->priv->gtk_theme); | ||
2307 | 2299 | manager->priv->gtk_theme = NULL; | ||
2308 | 2300 | } | ||
2309 | 2301 | manager->priv->icon_theme = g_settings_get_string (manager->priv->interface_settings, "icon-theme"); | ||
2310 | 2302 | |||
2311 | 2303 | init_screens (manager); | ||
2312 | 2304 | init_kbd (manager); | ||
2313 | 2305 | |||
2314 | 2306 | /* Start filtering the events */ | ||
2315 | 2307 | for (l = manager->priv->screens; l != NULL; l = l->next) { | ||
2316 | 2308 | gnome_settings_profile_start ("gdk_window_add_filter"); | ||
2317 | 2309 | |||
2318 | 2310 | g_debug ("adding key filter for screen: %d", | ||
2319 | 2311 | gdk_screen_get_number (l->data)); | ||
2320 | 2312 | |||
2321 | 2313 | gdk_window_add_filter (gdk_screen_get_root_window (l->data), | ||
2322 | 2314 | (GdkFilterFunc) filter_key_events, | ||
2323 | 2315 | manager); | ||
2324 | 2316 | gnome_settings_profile_end ("gdk_window_add_filter"); | ||
2325 | 2317 | } | ||
2326 | 2318 | |||
2327 | 2319 | gnome_settings_profile_end (NULL); | ||
2328 | 2320 | |||
2329 | 2321 | manager->priv->start_idle_id = 0; | ||
2330 | 2322 | |||
2331 | 2323 | return FALSE; | ||
2332 | 2324 | } | ||
2333 | 2325 | |||
2334 | 2326 | gboolean | ||
2335 | 2327 | gsd_media_keys_manager_start (GsdMediaKeysManager *manager, | ||
2336 | 2328 | GError **error) | ||
2337 | 2329 | { | ||
2338 | 2330 | const char * const subsystems[] = { "input", "usb", "sound", NULL }; | ||
2339 | 2331 | |||
2340 | 2332 | gnome_settings_profile_start (NULL); | ||
2341 | 2333 | |||
2342 | 2334 | if (supports_xinput2_devices (&manager->priv->opcode) == FALSE) { | ||
2343 | 2335 | g_debug ("No Xinput2 support, disabling plugin"); | ||
2344 | 2336 | return TRUE; | ||
2345 | 2337 | } | ||
2346 | 2338 | |||
2347 | 2339 | #ifdef HAVE_GUDEV | ||
2348 | 2340 | manager->priv->streams = g_hash_table_new (g_direct_hash, g_direct_equal); | ||
2349 | 2341 | manager->priv->udev_client = g_udev_client_new (subsystems); | ||
2350 | 2342 | #endif | ||
2351 | 2343 | |||
2352 | 2344 | /* initialise Volume handler | ||
2353 | 2345 | * | ||
2354 | 2346 | * We do this one here to force checking gstreamer cache, etc. | ||
2355 | 2347 | * The rest (grabbing and setting the keys) can happen in an | ||
2356 | 2348 | * idle. | ||
2357 | 2349 | */ | ||
2358 | 2350 | gnome_settings_profile_start ("gvc_mixer_control_new"); | ||
2359 | 2351 | |||
2360 | 2352 | manager->priv->volume = gvc_mixer_control_new ("GNOME Volume Control Media Keys"); | ||
2361 | 2353 | |||
2362 | 2354 | g_signal_connect (manager->priv->volume, | ||
2363 | 2355 | "state-changed", | ||
2364 | 2356 | G_CALLBACK (on_control_state_changed), | ||
2365 | 2357 | manager); | ||
2366 | 2358 | g_signal_connect (manager->priv->volume, | ||
2367 | 2359 | "default-sink-changed", | ||
2368 | 2360 | G_CALLBACK (on_control_default_sink_changed), | ||
2369 | 2361 | manager); | ||
2370 | 2362 | g_signal_connect (manager->priv->volume, | ||
2371 | 2363 | "stream-removed", | ||
2372 | 2364 | G_CALLBACK (on_control_stream_removed), | ||
2373 | 2365 | manager); | ||
2374 | 2366 | |||
2375 | 2367 | gnome_settings_profile_end ("gvc_mixer_control_new"); | ||
2376 | 2368 | |||
2377 | 2369 | manager->priv->start_idle_id = g_idle_add ((GSourceFunc) start_media_keys_idle_cb, manager); | ||
2378 | 2370 | |||
2379 | 2371 | register_manager (manager_object); | ||
2380 | 2372 | |||
2381 | 2373 | gnome_settings_profile_end (NULL); | ||
2382 | 2374 | |||
2383 | 2375 | return TRUE; | ||
2384 | 2376 | } | ||
2385 | 2377 | |||
2386 | 2378 | void | ||
2387 | 2379 | gsd_media_keys_manager_stop (GsdMediaKeysManager *manager) | ||
2388 | 2380 | { | ||
2389 | 2381 | GsdMediaKeysManagerPrivate *priv = manager->priv; | ||
2390 | 2382 | GSList *ls; | ||
2391 | 2383 | GList *l; | ||
2392 | 2384 | int i; | ||
2393 | 2385 | |||
2394 | 2386 | g_debug ("Stopping media_keys manager"); | ||
2395 | 2387 | |||
2396 | 2388 | if (priv->bus_cancellable != NULL) { | ||
2397 | 2389 | g_cancellable_cancel (priv->bus_cancellable); | ||
2398 | 2390 | g_object_unref (priv->bus_cancellable); | ||
2399 | 2391 | priv->bus_cancellable = NULL; | ||
2400 | 2392 | } | ||
2401 | 2393 | |||
2402 | 2394 | for (ls = priv->screens; ls != NULL; ls = ls->next) { | ||
2403 | 2395 | gdk_window_remove_filter (gdk_screen_get_root_window (ls->data), | ||
2404 | 2396 | (GdkFilterFunc) filter_key_events, | ||
2405 | 2397 | manager); | ||
2406 | 2398 | } | ||
2407 | 2399 | |||
2408 | 2400 | if (manager->priv->gtksettings != NULL) { | ||
2409 | 2401 | g_signal_handlers_disconnect_by_func (manager->priv->gtksettings, sound_theme_changed, manager); | ||
2410 | 2402 | manager->priv->gtksettings = NULL; | ||
2411 | 2403 | } | ||
2412 | 2404 | |||
2413 | 2405 | if (manager->priv->ca) { | ||
2414 | 2406 | ca_context_destroy (manager->priv->ca); | ||
2415 | 2407 | manager->priv->ca = NULL; | ||
2416 | 2408 | } | ||
2417 | 2409 | |||
2418 | 2410 | #ifdef HAVE_GUDEV | ||
2419 | 2411 | if (priv->streams) { | ||
2420 | 2412 | g_hash_table_destroy (priv->streams); | ||
2421 | 2413 | priv->streams = NULL; | ||
2422 | 2414 | } | ||
2423 | 2415 | if (priv->udev_client) { | ||
2424 | 2416 | g_object_unref (priv->udev_client); | ||
2425 | 2417 | priv->udev_client = NULL; | ||
2426 | 2418 | } | ||
2427 | 2419 | #endif /* HAVE_GUDEV */ | ||
2428 | 2420 | |||
2429 | 2421 | if (priv->settings) { | ||
2430 | 2422 | g_object_unref (priv->settings); | ||
2431 | 2423 | priv->settings = NULL; | ||
2432 | 2424 | } | ||
2433 | 2425 | |||
2434 | 2426 | if (priv->power_settings) { | ||
2435 | 2427 | g_object_unref (priv->power_settings); | ||
2436 | 2428 | priv->power_settings = NULL; | ||
2437 | 2429 | } | ||
2438 | 2430 | |||
2439 | 2431 | if (priv->power_screen_proxy) { | ||
2440 | 2432 | g_object_unref (priv->power_screen_proxy); | ||
2441 | 2433 | priv->power_screen_proxy = NULL; | ||
2442 | 2434 | } | ||
2443 | 2435 | |||
2444 | 2436 | if (priv->power_keyboard_proxy) { | ||
2445 | 2437 | g_object_unref (priv->power_keyboard_proxy); | ||
2446 | 2438 | priv->power_keyboard_proxy = NULL; | ||
2447 | 2439 | } | ||
2448 | 2440 | |||
2449 | 2441 | if (priv->upower_proxy) { | ||
2450 | 2442 | g_object_unref (priv->upower_proxy); | ||
2451 | 2443 | priv->upower_proxy = NULL; | ||
2452 | 2444 | } | ||
2453 | 2445 | |||
2454 | 2446 | if (priv->cancellable != NULL) { | ||
2455 | 2447 | g_cancellable_cancel (priv->cancellable); | ||
2456 | 2448 | g_object_unref (priv->cancellable); | ||
2457 | 2449 | priv->cancellable = NULL; | ||
2458 | 2450 | } | ||
2459 | 2451 | |||
2460 | 2452 | if (priv->introspection_data) { | ||
2461 | 2453 | g_dbus_node_info_unref (priv->introspection_data); | ||
2462 | 2454 | priv->introspection_data = NULL; | ||
2463 | 2455 | } | ||
2464 | 2456 | |||
2465 | 2457 | if (priv->connection != NULL) { | ||
2466 | 2458 | g_object_unref (priv->connection); | ||
2467 | 2459 | priv->connection = NULL; | ||
2468 | 2460 | } | ||
2469 | 2461 | |||
2470 | 2462 | if (priv->volume_notification != NULL) { | ||
2471 | 2463 | notify_notification_close (priv->volume_notification, NULL); | ||
2472 | 2464 | g_object_unref (priv->volume_notification); | ||
2473 | 2465 | priv->volume_notification = NULL; | ||
2474 | 2466 | } | ||
2475 | 2467 | |||
2476 | 2468 | if (priv->brightness_notification != NULL) { | ||
2477 | 2469 | notify_notification_close (priv->brightness_notification, NULL); | ||
2478 | 2470 | g_object_unref (priv->brightness_notification); | ||
2479 | 2471 | priv->brightness_notification = NULL; | ||
2480 | 2472 | } | ||
2481 | 2473 | |||
2482 | 2474 | if (priv->kb_backlight_notification != NULL) { | ||
2483 | 2475 | notify_notification_close (priv->kb_backlight_notification, NULL); | ||
2484 | 2476 | g_object_unref (priv->kb_backlight_notification); | ||
2485 | 2477 | priv->kb_backlight_notification = NULL; | ||
2486 | 2478 | } | ||
2487 | 2479 | |||
2488 | 2480 | if (priv->keys != NULL) { | ||
2489 | 2481 | gdk_error_trap_push (); | ||
2490 | 2482 | for (i = 0; i < priv->keys->len; ++i) { | ||
2491 | 2483 | MediaKey *key; | ||
2492 | 2484 | |||
2493 | 2485 | key = g_ptr_array_index (manager->priv->keys, i); | ||
2494 | 2486 | |||
2495 | 2487 | if (key->key) | ||
2496 | 2488 | grab_key_unsafe (key->key, FALSE, priv->screens); | ||
2497 | 2489 | } | ||
2498 | 2490 | g_ptr_array_free (priv->keys, TRUE); | ||
2499 | 2491 | priv->keys = NULL; | ||
2500 | 2492 | |||
2501 | 2493 | gdk_flush (); | ||
2502 | 2494 | gdk_error_trap_pop_ignored (); | ||
2503 | 2495 | } | ||
2504 | 2496 | |||
2505 | 2497 | if (priv->gconf_id) { | ||
2506 | 2498 | gconf_client_remove_dir (priv->gconf, GCONF_BINDING_DIR, NULL); | ||
2507 | 2499 | gconf_client_notify_remove (priv->gconf, priv->gconf_id); | ||
2508 | 2500 | priv->gconf_id = 0; | ||
2509 | 2501 | } | ||
2510 | 2502 | |||
2511 | 2503 | if (priv->gconf) { | ||
2512 | 2504 | g_object_unref (priv->gconf); | ||
2513 | 2505 | priv->gconf = NULL; | ||
2514 | 2506 | } | ||
2515 | 2507 | |||
2516 | 2508 | if (priv->screens != NULL) { | ||
2517 | 2509 | g_slist_free (priv->screens); | ||
2518 | 2510 | priv->screens = NULL; | ||
2519 | 2511 | } | ||
2520 | 2512 | |||
2521 | 2513 | if (priv->stream) { | ||
2522 | 2514 | g_object_unref (priv->stream); | ||
2523 | 2515 | priv->stream = NULL; | ||
2524 | 2516 | } | ||
2525 | 2517 | |||
2526 | 2518 | if (priv->volume) { | ||
2527 | 2519 | g_object_unref (priv->volume); | ||
2528 | 2520 | priv->volume = NULL; | ||
2529 | 2521 | } | ||
2530 | 2522 | |||
2531 | 2523 | if (priv->dialog != NULL) { | ||
2532 | 2524 | gtk_widget_destroy (priv->dialog); | ||
2533 | 2525 | priv->dialog = NULL; | ||
2534 | 2526 | } | ||
2535 | 2527 | |||
2536 | 2528 | if (priv->media_players != NULL) { | ||
2537 | 2529 | for (l = priv->media_players; l; l = l->next) { | ||
2538 | 2530 | MediaPlayer *mp = l->data; | ||
2539 | 2531 | g_free (mp->application); | ||
2540 | 2532 | g_free (mp); | ||
2541 | 2533 | } | ||
2542 | 2534 | g_list_free (priv->media_players); | ||
2543 | 2535 | priv->media_players = NULL; | ||
2544 | 2536 | } | ||
2545 | 2537 | } | ||
2546 | 2538 | |||
2547 | 2539 | static GObject * | ||
2548 | 2540 | gsd_media_keys_manager_constructor (GType type, | ||
2549 | 2541 | guint n_construct_properties, | ||
2550 | 2542 | GObjectConstructParam *construct_properties) | ||
2551 | 2543 | { | ||
2552 | 2544 | GsdMediaKeysManager *media_keys_manager; | ||
2553 | 2545 | |||
2554 | 2546 | media_keys_manager = GSD_MEDIA_KEYS_MANAGER (G_OBJECT_CLASS (gsd_media_keys_manager_parent_class)->constructor (type, | ||
2555 | 2547 | n_construct_properties, | ||
2556 | 2548 | construct_properties)); | ||
2557 | 2549 | |||
2558 | 2550 | return G_OBJECT (media_keys_manager); | ||
2559 | 2551 | } | ||
2560 | 2552 | |||
2561 | 2553 | static void | ||
2562 | 2554 | gsd_media_keys_manager_class_init (GsdMediaKeysManagerClass *klass) | ||
2563 | 2555 | { | ||
2564 | 2556 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
2565 | 2557 | |||
2566 | 2558 | object_class->constructor = gsd_media_keys_manager_constructor; | ||
2567 | 2559 | object_class->finalize = gsd_media_keys_manager_finalize; | ||
2568 | 2560 | |||
2569 | 2561 | g_type_class_add_private (klass, sizeof (GsdMediaKeysManagerPrivate)); | ||
2570 | 2562 | } | ||
2571 | 2563 | |||
2572 | 2564 | static void | ||
2573 | 2565 | gsd_media_keys_manager_init (GsdMediaKeysManager *manager) | ||
2574 | 2566 | { | ||
2575 | 2567 | manager->priv = GSD_MEDIA_KEYS_MANAGER_GET_PRIVATE (manager); | ||
2576 | 2568 | } | ||
2577 | 2569 | |||
2578 | 2570 | static void | ||
2579 | 2571 | gsd_media_keys_manager_finalize (GObject *object) | ||
2580 | 2572 | { | ||
2581 | 2573 | GsdMediaKeysManager *media_keys_manager; | ||
2582 | 2574 | |||
2583 | 2575 | g_return_if_fail (object != NULL); | ||
2584 | 2576 | g_return_if_fail (GSD_IS_MEDIA_KEYS_MANAGER (object)); | ||
2585 | 2577 | |||
2586 | 2578 | media_keys_manager = GSD_MEDIA_KEYS_MANAGER (object); | ||
2587 | 2579 | |||
2588 | 2580 | g_return_if_fail (media_keys_manager->priv != NULL); | ||
2589 | 2581 | |||
2590 | 2582 | if (media_keys_manager->priv->start_idle_id != 0) | ||
2591 | 2583 | g_source_remove (media_keys_manager->priv->start_idle_id); | ||
2592 | 2584 | |||
2593 | 2585 | G_OBJECT_CLASS (gsd_media_keys_manager_parent_class)->finalize (object); | ||
2594 | 2586 | } | ||
2595 | 2587 | |||
2596 | 2588 | static void | ||
2597 | 2589 | xrandr_ready_cb (GObject *source_object, | ||
2598 | 2590 | GAsyncResult *res, | ||
2599 | 2591 | GsdMediaKeysManager *manager) | ||
2600 | 2592 | { | ||
2601 | 2593 | GError *error = NULL; | ||
2602 | 2594 | |||
2603 | 2595 | manager->priv->xrandr_proxy = g_dbus_proxy_new_finish (res, &error); | ||
2604 | 2596 | if (manager->priv->xrandr_proxy == NULL) { | ||
2605 | 2597 | g_warning ("Failed to get proxy for XRandR operations: %s", error->message); | ||
2606 | 2598 | g_error_free (error); | ||
2607 | 2599 | } | ||
2608 | 2600 | } | ||
2609 | 2601 | |||
2610 | 2602 | static void | ||
2611 | 2603 | upower_ready_cb (GObject *source_object, | ||
2612 | 2604 | GAsyncResult *res, | ||
2613 | 2605 | GsdMediaKeysManager *manager) | ||
2614 | 2606 | { | ||
2615 | 2607 | GError *error = NULL; | ||
2616 | 2608 | |||
2617 | 2609 | manager->priv->upower_proxy = g_dbus_proxy_new_finish (res, &error); | ||
2618 | 2610 | if (manager->priv->upower_proxy == NULL) { | ||
2619 | 2611 | g_warning ("Failed to get proxy for upower: %s", | ||
2620 | 2612 | error->message); | ||
2621 | 2613 | g_error_free (error); | ||
2622 | 2614 | } | ||
2623 | 2615 | } | ||
2624 | 2616 | |||
2625 | 2617 | static void | ||
2626 | 2618 | power_screen_ready_cb (GObject *source_object, | ||
2627 | 2619 | GAsyncResult *res, | ||
2628 | 2620 | GsdMediaKeysManager *manager) | ||
2629 | 2621 | { | ||
2630 | 2622 | GError *error = NULL; | ||
2631 | 2623 | |||
2632 | 2624 | manager->priv->power_screen_proxy = g_dbus_proxy_new_finish (res, &error); | ||
2633 | 2625 | if (manager->priv->power_screen_proxy == NULL) { | ||
2634 | 2626 | g_warning ("Failed to get proxy for power (screen): %s", | ||
2635 | 2627 | error->message); | ||
2636 | 2628 | g_error_free (error); | ||
2637 | 2629 | } | ||
2638 | 2630 | } | ||
2639 | 2631 | |||
2640 | 2632 | static void | ||
2641 | 2633 | power_keyboard_ready_cb (GObject *source_object, | ||
2642 | 2634 | GAsyncResult *res, | ||
2643 | 2635 | GsdMediaKeysManager *manager) | ||
2644 | 2636 | { | ||
2645 | 2637 | GError *error = NULL; | ||
2646 | 2638 | |||
2647 | 2639 | manager->priv->power_keyboard_proxy = g_dbus_proxy_new_finish (res, &error); | ||
2648 | 2640 | if (manager->priv->power_keyboard_proxy == NULL) { | ||
2649 | 2641 | g_warning ("Failed to get proxy for power (keyboard): %s", | ||
2650 | 2642 | error->message); | ||
2651 | 2643 | g_error_free (error); | ||
2652 | 2644 | } | ||
2653 | 2645 | } | ||
2654 | 2646 | |||
2655 | 2647 | static void | ||
2656 | 2648 | on_bus_gotten (GObject *source_object, | ||
2657 | 2649 | GAsyncResult *res, | ||
2658 | 2650 | GsdMediaKeysManager *manager) | ||
2659 | 2651 | { | ||
2660 | 2652 | GDBusConnection *connection; | ||
2661 | 2653 | GError *error = NULL; | ||
2662 | 2654 | |||
2663 | 2655 | if (manager->priv->bus_cancellable == NULL || | ||
2664 | 2656 | g_cancellable_is_cancelled (manager->priv->bus_cancellable)) { | ||
2665 | 2657 | g_warning ("Operation has been cancelled, so not retrieving session bus"); | ||
2666 | 2658 | return; | ||
2667 | 2659 | } | ||
2668 | 2660 | |||
2669 | 2661 | connection = g_bus_get_finish (res, &error); | ||
2670 | 2662 | if (connection == NULL) { | ||
2671 | 2663 | g_warning ("Could not get session bus: %s", error->message); | ||
2672 | 2664 | g_error_free (error); | ||
2673 | 2665 | return; | ||
2674 | 2666 | } | ||
2675 | 2667 | manager->priv->connection = connection; | ||
2676 | 2668 | |||
2677 | 2669 | g_dbus_connection_register_object (connection, | ||
2678 | 2670 | GSD_MEDIA_KEYS_DBUS_PATH, | ||
2679 | 2671 | manager->priv->introspection_data->interfaces[0], | ||
2680 | 2672 | &interface_vtable, | ||
2681 | 2673 | manager, | ||
2682 | 2674 | NULL, | ||
2683 | 2675 | NULL); | ||
2684 | 2676 | |||
2685 | 2677 | g_dbus_proxy_new (manager->priv->connection, | ||
2686 | 2678 | G_DBUS_PROXY_FLAGS_NONE, | ||
2687 | 2679 | NULL, | ||
2688 | 2680 | "org.gnome.SettingsDaemon", | ||
2689 | 2681 | "/org/gnome/SettingsDaemon/XRANDR", | ||
2690 | 2682 | "org.gnome.SettingsDaemon.XRANDR_2", | ||
2691 | 2683 | NULL, | ||
2692 | 2684 | (GAsyncReadyCallback) xrandr_ready_cb, | ||
2693 | 2685 | manager); | ||
2694 | 2686 | |||
2695 | 2687 | g_dbus_proxy_new (manager->priv->connection, | ||
2696 | 2688 | G_DBUS_PROXY_FLAGS_NONE, | ||
2697 | 2689 | NULL, | ||
2698 | 2690 | "org.gnome.SettingsDaemon", | ||
2699 | 2691 | "/org/gnome/SettingsDaemon/Power", | ||
2700 | 2692 | "org.gnome.SettingsDaemon.Power.Screen", | ||
2701 | 2693 | NULL, | ||
2702 | 2694 | (GAsyncReadyCallback) power_screen_ready_cb, | ||
2703 | 2695 | manager); | ||
2704 | 2696 | |||
2705 | 2697 | g_dbus_proxy_new (manager->priv->connection, | ||
2706 | 2698 | G_DBUS_PROXY_FLAGS_NONE, | ||
2707 | 2699 | NULL, | ||
2708 | 2700 | "org.gnome.SettingsDaemon", | ||
2709 | 2701 | "/org/gnome/SettingsDaemon/Power", | ||
2710 | 2702 | "org.gnome.SettingsDaemon.Power.Keyboard", | ||
2711 | 2703 | NULL, | ||
2712 | 2704 | (GAsyncReadyCallback) power_keyboard_ready_cb, | ||
2713 | 2705 | manager); | ||
2714 | 2706 | } | ||
2715 | 2707 | |||
2716 | 2708 | static void | ||
2717 | 2709 | register_manager (GsdMediaKeysManager *manager) | ||
2718 | 2710 | { | ||
2719 | 2711 | manager->priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); | ||
2720 | 2712 | manager->priv->bus_cancellable = g_cancellable_new (); | ||
2721 | 2713 | g_assert (manager->priv->introspection_data != NULL); | ||
2722 | 2714 | |||
2723 | 2715 | g_bus_get (G_BUS_TYPE_SESSION, | ||
2724 | 2716 | manager->priv->bus_cancellable, | ||
2725 | 2717 | (GAsyncReadyCallback) on_bus_gotten, | ||
2726 | 2718 | manager); | ||
2727 | 2719 | |||
2728 | 2720 | g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, | ||
2729 | 2721 | G_DBUS_PROXY_FLAGS_NONE, | ||
2730 | 2722 | NULL, | ||
2731 | 2723 | "org.freedesktop.UPower", | ||
2732 | 2724 | "/org/freedesktop/UPower", | ||
2733 | 2725 | "org.freedesktop.UPower", | ||
2734 | 2726 | NULL, | ||
2735 | 2727 | (GAsyncReadyCallback) upower_ready_cb, | ||
2736 | 2728 | manager); | ||
2737 | 2729 | } | ||
2738 | 2730 | |||
2739 | 2731 | GsdMediaKeysManager * | ||
2740 | 2732 | gsd_media_keys_manager_new (void) | ||
2741 | 2733 | { | ||
2742 | 2734 | if (manager_object != NULL) { | ||
2743 | 2735 | g_object_ref (manager_object); | ||
2744 | 2736 | } else { | ||
2745 | 2737 | manager_object = g_object_new (GSD_TYPE_MEDIA_KEYS_MANAGER, NULL); | ||
2746 | 2738 | g_object_add_weak_pointer (manager_object, | ||
2747 | 2739 | (gpointer *) &manager_object); | ||
2748 | 2740 | } | ||
2749 | 2741 | |||
2750 | 2742 | return GSD_MEDIA_KEYS_MANAGER (manager_object); | ||
2751 | 2743 | } | ||
2752 | 0 | 2744 | ||
2753 | === added file '.pc/64_micmute.patch/plugins/media-keys/shortcuts-list.h' | |||
2754 | --- .pc/64_micmute.patch/plugins/media-keys/shortcuts-list.h 1970-01-01 00:00:00 +0000 | |||
2755 | +++ .pc/64_micmute.patch/plugins/media-keys/shortcuts-list.h 2013-10-01 18:19:26 +0000 | |||
2756 | @@ -0,0 +1,152 @@ | |||
2757 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- | ||
2758 | 2 | * | ||
2759 | 3 | * Copyright (C) 2001 Bastien Nocera <hadess@hadess.net> | ||
2760 | 4 | * | ||
2761 | 5 | * This program is free software; you can redistribute it and/or modify | ||
2762 | 6 | * it under the terms of the GNU General Public License as published by | ||
2763 | 7 | * the Free Software Foundation; either version 2 of the License, or | ||
2764 | 8 | * (at your option) any later version. | ||
2765 | 9 | * | ||
2766 | 10 | * This program is distributed in the hope that it will be useful, | ||
2767 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2768 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2769 | 13 | * GNU General Public License for more details. | ||
2770 | 14 | * | ||
2771 | 15 | * You should have received a copy of the GNU General Public License | ||
2772 | 16 | * along with this program; if not, write to the Free Software | ||
2773 | 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | ||
2774 | 18 | * USA. | ||
2775 | 19 | */ | ||
2776 | 20 | |||
2777 | 21 | #ifndef __ACME_H__ | ||
2778 | 22 | #define __ACME_H__ | ||
2779 | 23 | |||
2780 | 24 | #include "gsd-keygrab.h" | ||
2781 | 25 | |||
2782 | 26 | #define SETTINGS_BINDING_DIR "org.gnome.settings-daemon.plugins.media-keys" | ||
2783 | 27 | |||
2784 | 28 | typedef enum { | ||
2785 | 29 | TOUCHPAD_KEY, | ||
2786 | 30 | TOUCHPAD_ON_KEY, | ||
2787 | 31 | TOUCHPAD_OFF_KEY, | ||
2788 | 32 | MUTE_KEY, | ||
2789 | 33 | VOLUME_DOWN_KEY, | ||
2790 | 34 | VOLUME_UP_KEY, | ||
2791 | 35 | MUTE_QUIET_KEY, | ||
2792 | 36 | VOLUME_DOWN_QUIET_KEY, | ||
2793 | 37 | VOLUME_UP_QUIET_KEY, | ||
2794 | 38 | LOGOUT_KEY, | ||
2795 | 39 | EJECT_KEY, | ||
2796 | 40 | HOME_KEY, | ||
2797 | 41 | MEDIA_KEY, | ||
2798 | 42 | CALCULATOR_KEY, | ||
2799 | 43 | SEARCH_KEY, | ||
2800 | 44 | EMAIL_KEY, | ||
2801 | 45 | SCREENSAVER_KEY, | ||
2802 | 46 | HELP_KEY, | ||
2803 | 47 | SCREENSHOT_KEY, | ||
2804 | 48 | WINDOW_SCREENSHOT_KEY, | ||
2805 | 49 | AREA_SCREENSHOT_KEY, | ||
2806 | 50 | SCREENSHOT_CLIP_KEY, | ||
2807 | 51 | WINDOW_SCREENSHOT_CLIP_KEY, | ||
2808 | 52 | AREA_SCREENSHOT_CLIP_KEY, | ||
2809 | 53 | WWW_KEY, | ||
2810 | 54 | PLAY_KEY, | ||
2811 | 55 | PAUSE_KEY, | ||
2812 | 56 | STOP_KEY, | ||
2813 | 57 | PREVIOUS_KEY, | ||
2814 | 58 | NEXT_KEY, | ||
2815 | 59 | REWIND_KEY, | ||
2816 | 60 | FORWARD_KEY, | ||
2817 | 61 | REPEAT_KEY, | ||
2818 | 62 | RANDOM_KEY, | ||
2819 | 63 | VIDEO_OUT_KEY, | ||
2820 | 64 | ROTATE_VIDEO_KEY, | ||
2821 | 65 | MAGNIFIER_KEY, | ||
2822 | 66 | SCREENREADER_KEY, | ||
2823 | 67 | ON_SCREEN_KEYBOARD_KEY, | ||
2824 | 68 | INCREASE_TEXT_KEY, | ||
2825 | 69 | DECREASE_TEXT_KEY, | ||
2826 | 70 | TOGGLE_CONTRAST_KEY, | ||
2827 | 71 | MAGNIFIER_ZOOM_IN_KEY, | ||
2828 | 72 | MAGNIFIER_ZOOM_OUT_KEY, | ||
2829 | 73 | POWER_KEY, | ||
2830 | 74 | SLEEP_KEY, | ||
2831 | 75 | SUSPEND_KEY, | ||
2832 | 76 | HIBERNATE_KEY, | ||
2833 | 77 | SCREEN_BRIGHTNESS_UP_KEY, | ||
2834 | 78 | SCREEN_BRIGHTNESS_DOWN_KEY, | ||
2835 | 79 | KEYBOARD_BRIGHTNESS_UP_KEY, | ||
2836 | 80 | KEYBOARD_BRIGHTNESS_DOWN_KEY, | ||
2837 | 81 | KEYBOARD_BRIGHTNESS_TOGGLE_KEY, | ||
2838 | 82 | BATTERY_KEY, | ||
2839 | 83 | CUSTOM_KEY | ||
2840 | 84 | } MediaKeyType; | ||
2841 | 85 | |||
2842 | 86 | static struct { | ||
2843 | 87 | MediaKeyType key_type; | ||
2844 | 88 | const char *settings_key; | ||
2845 | 89 | const char *hard_coded; | ||
2846 | 90 | } media_keys[] = { | ||
2847 | 91 | { TOUCHPAD_KEY, NULL, "XF86TouchpadToggle" }, | ||
2848 | 92 | { TOUCHPAD_ON_KEY, NULL, "XF86TouchpadOn" }, | ||
2849 | 93 | { TOUCHPAD_OFF_KEY, NULL, "XF86TouchpadOff" }, | ||
2850 | 94 | { MUTE_KEY, "volume-mute", NULL }, | ||
2851 | 95 | { VOLUME_DOWN_KEY, "volume-down", NULL }, | ||
2852 | 96 | { VOLUME_UP_KEY, "volume-up", NULL }, | ||
2853 | 97 | { MUTE_QUIET_KEY, NULL, "<Alt>XF86AudioMute" }, | ||
2854 | 98 | { VOLUME_DOWN_QUIET_KEY, NULL, "<Alt>XF86AudioLowerVolume" }, | ||
2855 | 99 | { VOLUME_UP_QUIET_KEY, NULL, "<Alt>XF86AudioRaiseVolume" }, | ||
2856 | 100 | { LOGOUT_KEY, "logout", NULL }, | ||
2857 | 101 | { EJECT_KEY, "eject", NULL }, | ||
2858 | 102 | { HOME_KEY, "home", NULL }, | ||
2859 | 103 | { MEDIA_KEY, "media", NULL }, | ||
2860 | 104 | { CALCULATOR_KEY, "calculator", NULL }, | ||
2861 | 105 | { SEARCH_KEY, "search", NULL }, | ||
2862 | 106 | { EMAIL_KEY, "email", NULL }, | ||
2863 | 107 | { SCREENSAVER_KEY, "screensaver", NULL }, | ||
2864 | 108 | { SCREENSAVER_KEY, NULL, "XF86ScreenSaver" }, | ||
2865 | 109 | { HELP_KEY, "help", NULL }, | ||
2866 | 110 | { SCREENSHOT_KEY, "screenshot", NULL }, | ||
2867 | 111 | { WINDOW_SCREENSHOT_KEY, "window-screenshot", NULL }, | ||
2868 | 112 | { AREA_SCREENSHOT_KEY, "area-screenshot", NULL }, | ||
2869 | 113 | { SCREENSHOT_CLIP_KEY, "screenshot-clip", NULL }, | ||
2870 | 114 | { WINDOW_SCREENSHOT_CLIP_KEY, "window-screenshot-clip", NULL }, | ||
2871 | 115 | { AREA_SCREENSHOT_CLIP_KEY, "area-screenshot-clip", NULL }, | ||
2872 | 116 | { WWW_KEY, "www", NULL }, | ||
2873 | 117 | { PLAY_KEY, "play", NULL }, | ||
2874 | 118 | { PAUSE_KEY, "pause", NULL }, | ||
2875 | 119 | { STOP_KEY, "stop", NULL }, | ||
2876 | 120 | { PREVIOUS_KEY, "previous", NULL }, | ||
2877 | 121 | { NEXT_KEY, "next", NULL }, | ||
2878 | 122 | { REWIND_KEY, NULL, "XF86AudioRewind" }, | ||
2879 | 123 | { FORWARD_KEY, NULL, "XF86AudioForward" }, | ||
2880 | 124 | { REPEAT_KEY, NULL, "XF86AudioRepeat" }, | ||
2881 | 125 | { RANDOM_KEY, NULL, "XF86AudioRandomPlay"}, | ||
2882 | 126 | { VIDEO_OUT_KEY, NULL, "<Super>p" }, | ||
2883 | 127 | /* Key code of the XF86Display key (Fn-F7 on Thinkpads, Fn-F4 on HP machines, etc.) */ | ||
2884 | 128 | { VIDEO_OUT_KEY, NULL, "XF86Display" }, | ||
2885 | 129 | /* Key code of the XF86RotateWindows key (present on some tablets) */ | ||
2886 | 130 | { ROTATE_VIDEO_KEY, NULL, "XF86RotateWindows" }, | ||
2887 | 131 | { MAGNIFIER_KEY, "magnifier", NULL }, | ||
2888 | 132 | { SCREENREADER_KEY, "screenreader", NULL }, | ||
2889 | 133 | { ON_SCREEN_KEYBOARD_KEY, "on-screen-keyboard", NULL }, | ||
2890 | 134 | { INCREASE_TEXT_KEY, "increase-text-size", NULL }, | ||
2891 | 135 | { DECREASE_TEXT_KEY, "decrease-text-size", NULL }, | ||
2892 | 136 | { TOGGLE_CONTRAST_KEY, "toggle-contrast", NULL }, | ||
2893 | 137 | { MAGNIFIER_ZOOM_IN_KEY, "magnifier-zoom-in", NULL }, | ||
2894 | 138 | { MAGNIFIER_ZOOM_OUT_KEY, "magnifier-zoom-out", NULL }, | ||
2895 | 139 | { POWER_KEY, NULL, "XF86PowerOff" }, | ||
2896 | 140 | /* the kernel / Xorg names really are like this... */ | ||
2897 | 141 | { SLEEP_KEY, NULL, "XF86Suspend" }, | ||
2898 | 142 | { SUSPEND_KEY, NULL, "XF86Sleep" }, | ||
2899 | 143 | { HIBERNATE_KEY, NULL, "XF86Hibernate" }, | ||
2900 | 144 | { SCREEN_BRIGHTNESS_UP_KEY, NULL, "XF86MonBrightnessUp" }, | ||
2901 | 145 | { SCREEN_BRIGHTNESS_DOWN_KEY, NULL, "XF86MonBrightnessDown" }, | ||
2902 | 146 | { KEYBOARD_BRIGHTNESS_UP_KEY, NULL, "XF86KbdBrightnessUp" }, | ||
2903 | 147 | { KEYBOARD_BRIGHTNESS_DOWN_KEY, NULL, "XF86KbdBrightnessDown" }, | ||
2904 | 148 | { KEYBOARD_BRIGHTNESS_TOGGLE_KEY, NULL, "XF86KbdLightOnOff" }, | ||
2905 | 149 | { BATTERY_KEY, NULL, "XF86Battery" }, | ||
2906 | 150 | }; | ||
2907 | 151 | |||
2908 | 152 | #endif /* __ACME_H__ */ | ||
2909 | 0 | 153 | ||
2910 | === modified file '.pc/applied-patches' | |||
2911 | --- .pc/applied-patches 2013-01-10 17:23:56 +0000 | |||
2912 | +++ .pc/applied-patches 2013-10-01 18:19:26 +0000 | |||
2913 | @@ -33,3 +33,4 @@ | |||
2914 | 33 | git_no_numlock_eating_cpu_loop.patch | 33 | git_no_numlock_eating_cpu_loop.patch |
2915 | 34 | git_new_xinput_handle.patch | 34 | git_new_xinput_handle.patch |
2916 | 35 | git-smartcard-crash.patch | 35 | git-smartcard-crash.patch |
2917 | 36 | 64_micmute.patch | ||
2918 | 36 | 37 | ||
2919 | === modified file 'debian/changelog' | |||
2920 | --- debian/changelog 2013-01-10 17:23:56 +0000 | |||
2921 | +++ debian/changelog 2013-10-01 18:19:26 +0000 | |||
2922 | @@ -1,3 +1,11 @@ | |||
2923 | 1 | gnome-settings-daemon (3.4.2-0ubuntu0.6.3) precise; urgency=low | ||
2924 | 2 | |||
2925 | 3 | * debian/patches/64_micmute.patch: | ||
2926 | 4 | - put the mic mute key used on thinkpad laptops to good use | ||
2927 | 5 | (lp: #408903) | ||
2928 | 6 | |||
2929 | 7 | -- James M Leddy <james.leddy@canonical.com> Sat, 01 Jun 2013 10:01:49 -0400 | ||
2930 | 8 | |||
2931 | 1 | gnome-settings-daemon (3.4.2-0ubuntu0.6.2) precise; urgency=low | 9 | gnome-settings-daemon (3.4.2-0ubuntu0.6.2) precise; urgency=low |
2932 | 2 | 10 | ||
2933 | 3 | * debian/patches/git-smartcard-crash.patch: | 11 | * debian/patches/git-smartcard-crash.patch: |
2934 | 4 | 12 | ||
2935 | === added file 'debian/patches/64_micmute.patch' | |||
2936 | --- debian/patches/64_micmute.patch 1970-01-01 00:00:00 +0000 | |||
2937 | +++ debian/patches/64_micmute.patch 2013-10-01 18:19:26 +0000 | |||
2938 | @@ -0,0 +1,291 @@ | |||
2939 | 1 | --- a/plugins/media-keys/gsd-media-keys-manager.c | ||
2940 | 2 | +++ b/plugins/media-keys/gsd-media-keys-manager.c | ||
2941 | 3 | @@ -126,6 +126,7 @@ | ||
2942 | 4 | /* Volume bits */ | ||
2943 | 5 | GvcMixerControl *volume; | ||
2944 | 6 | GvcMixerStream *stream; | ||
2945 | 7 | + GvcMixerStream *input_stream; | ||
2946 | 8 | ca_context *ca; | ||
2947 | 9 | GtkSettings *gtksettings; | ||
2948 | 10 | #ifdef HAVE_GUDEV | ||
2949 | 11 | @@ -199,6 +200,14 @@ | ||
2950 | 12 | NULL | ||
2951 | 13 | }; | ||
2952 | 14 | |||
2953 | 15 | +static const char *mic_icons[] = { | ||
2954 | 16 | + "microphone-sensitivity-muted-symbolic", | ||
2955 | 17 | + "microphone-sensitivity-low-symbolic", | ||
2956 | 18 | + "microphone-sensitivity-medium-symbolic", | ||
2957 | 19 | + "microphone-sensitivity-high-symbolic", | ||
2958 | 20 | + NULL | ||
2959 | 21 | +}; | ||
2960 | 22 | + | ||
2961 | 23 | static const char *brightness_icons[] = { | ||
2962 | 24 | "notification-display-brightness-off", | ||
2963 | 25 | "notification-display-brightness-low", | ||
2964 | 26 | @@ -283,15 +292,24 @@ | ||
2965 | 27 | } | ||
2966 | 28 | |||
2967 | 29 | static gboolean | ||
2968 | 30 | -ubuntu_osd_notification_show_volume (GsdMediaKeysManager *manager, | ||
2969 | 31 | - gint value, | ||
2970 | 32 | - gboolean muted) | ||
2971 | 33 | +ubuntu_osd_notification_show_speaker_volume (GsdMediaKeysManager *manager, | ||
2972 | 34 | + gint value, | ||
2973 | 35 | + gboolean muted) | ||
2974 | 36 | { | ||
2975 | 37 | return ubuntu_osd_do_notification (&manager->priv->volume_notification, | ||
2976 | 38 | "volume", value, muted, volume_icons); | ||
2977 | 39 | } | ||
2978 | 40 | |||
2979 | 41 | static gboolean | ||
2980 | 42 | +ubuntu_osd_notification_show_mic_volume (GsdMediaKeysManager *manager, | ||
2981 | 43 | + gint value, | ||
2982 | 44 | + gboolean muted) | ||
2983 | 45 | +{ | ||
2984 | 46 | + return ubuntu_osd_do_notification (&manager->priv->volume_notification, | ||
2985 | 47 | + "volume", value, muted, mic_icons); | ||
2986 | 48 | +} | ||
2987 | 49 | + | ||
2988 | 50 | +static gboolean | ||
2989 | 51 | ubuntu_osd_notification_show_brightness (GsdMediaKeysManager *manager, | ||
2990 | 52 | gint value) | ||
2991 | 53 | { | ||
2992 | 54 | @@ -1049,14 +1067,14 @@ | ||
2993 | 55 | } | ||
2994 | 56 | |||
2995 | 57 | static void | ||
2996 | 58 | -update_dialog (GsdMediaKeysManager *manager, | ||
2997 | 59 | - GvcMixerStream *stream, | ||
2998 | 60 | - guint vol, | ||
2999 | 61 | - gboolean muted, | ||
3000 | 62 | - gboolean sound_changed, | ||
3001 | 63 | - gboolean quiet) | ||
3002 | 64 | +update_speaker_dialog (GsdMediaKeysManager *manager, | ||
3003 | 65 | + GvcMixerStream *stream, | ||
3004 | 66 | + guint vol, | ||
3005 | 67 | + gboolean muted, | ||
3006 | 68 | + gboolean sound_changed, | ||
3007 | 69 | + gboolean quiet) | ||
3008 | 70 | { | ||
3009 | 71 | - if (ubuntu_osd_notification_show_volume (manager, vol, muted)) | ||
3010 | 72 | + if (ubuntu_osd_notification_show_speaker_volume (manager, vol, muted)) | ||
3011 | 73 | goto done; | ||
3012 | 74 | |||
3013 | 75 | vol = CLAMP (vol, 0, 100); | ||
3014 | 76 | @@ -1081,6 +1099,39 @@ | ||
3015 | 77 | } | ||
3016 | 78 | } | ||
3017 | 79 | |||
3018 | 80 | +static void | ||
3019 | 81 | +update_mic_dialog (GsdMediaKeysManager *manager, | ||
3020 | 82 | + GvcMixerStream *stream, | ||
3021 | 83 | + guint vol, | ||
3022 | 84 | + gboolean muted, | ||
3023 | 85 | + gboolean sound_changed, | ||
3024 | 86 | + gboolean quiet) | ||
3025 | 87 | +{ | ||
3026 | 88 | + vol = CLAMP (vol, 0, 100); | ||
3027 | 89 | + ubuntu_osd_notification_show_mic_volume (manager, vol, muted); | ||
3028 | 90 | + | ||
3029 | 91 | + if (quiet == FALSE) { | ||
3030 | 92 | + GtkWidget *window; | ||
3031 | 93 | + if (!manager->priv->dialog) { | ||
3032 | 94 | + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); | ||
3033 | 95 | + gtk_window_set_screen (GTK_WINDOW (window), manager->priv->current_screen); | ||
3034 | 96 | + gtk_widget_realize (window); | ||
3035 | 97 | + | ||
3036 | 98 | + } else { | ||
3037 | 99 | + window = manager->priv->dialog; | ||
3038 | 100 | + } | ||
3039 | 101 | + ca_gtk_play_for_widget (manager->priv->dialog, 0, | ||
3040 | 102 | + CA_PROP_EVENT_ID, "audio-volume-change", | ||
3041 | 103 | + CA_PROP_EVENT_DESCRIPTION, "volume changed through key press", | ||
3042 | 104 | + CA_PROP_APPLICATION_ID, "org.gnome.VolumeControl", | ||
3043 | 105 | + CA_PROP_CANBERRA_CACHE_CONTROL, "permanent", | ||
3044 | 106 | + NULL); | ||
3045 | 107 | + | ||
3046 | 108 | + if (!manager->priv->dialog) | ||
3047 | 109 | + gtk_widget_destroy(window); | ||
3048 | 110 | + } | ||
3049 | 111 | +} | ||
3050 | 112 | + | ||
3051 | 113 | #ifdef HAVE_GUDEV | ||
3052 | 114 | /* PulseAudio gives us /devices/... paths, when udev | ||
3053 | 115 | * expects /sys/devices/... paths. */ | ||
3054 | 116 | @@ -1190,10 +1241,12 @@ | ||
3055 | 117 | int type, | ||
3056 | 118 | gboolean quiet) | ||
3057 | 119 | { | ||
3058 | 120 | - GvcMixerStream *stream; | ||
3059 | 121 | + GvcMixerStream *stream, *input_stream; | ||
3060 | 122 | gboolean old_muted, new_muted; | ||
3061 | 123 | guint old_vol, new_vol, norm_vol_step, osd_vol; | ||
3062 | 124 | - gboolean sound_changed; | ||
3063 | 125 | + gboolean old_mic_muted, new_mic_muted; | ||
3064 | 126 | + guint old_mic_vol, new_mic_vol; | ||
3065 | 127 | + gboolean sound_changed, mic_changed; | ||
3066 | 128 | |||
3067 | 129 | /* Find the stream that corresponds to the device, if any */ | ||
3068 | 130 | #ifdef HAVE_GUDEV | ||
3069 | 131 | @@ -1203,13 +1256,18 @@ | ||
3070 | 132 | stream = manager->priv->stream; | ||
3071 | 133 | if (stream == NULL) | ||
3072 | 134 | return; | ||
3073 | 135 | + input_stream = manager->priv->input_stream; | ||
3074 | 136 | + if (input_stream == NULL) | ||
3075 | 137 | + return; | ||
3076 | 138 | |||
3077 | 139 | norm_vol_step = PA_VOLUME_NORM * VOLUME_STEP / 100; | ||
3078 | 140 | |||
3079 | 141 | /* FIXME: this is racy */ | ||
3080 | 142 | new_vol = old_vol = gvc_mixer_stream_get_volume (stream); | ||
3081 | 143 | + new_mic_vol = old_mic_vol = gvc_mixer_stream_get_volume (input_stream); | ||
3082 | 144 | new_muted = old_muted = gvc_mixer_stream_get_is_muted (stream); | ||
3083 | 145 | - sound_changed = FALSE; | ||
3084 | 146 | + new_mic_muted = old_mic_muted = gvc_mixer_stream_get_is_muted (input_stream); | ||
3085 | 147 | + mic_changed = sound_changed = FALSE; | ||
3086 | 148 | |||
3087 | 149 | switch (type) { | ||
3088 | 150 | case MUTE_KEY: | ||
3089 | 151 | @@ -1229,6 +1287,9 @@ | ||
3090 | 152 | if (!old_muted || old_vol == 0) | ||
3091 | 153 | new_vol = MIN (old_vol + norm_vol_step, MAX_VOLUME); | ||
3092 | 154 | break; | ||
3093 | 155 | + case MUTE_MIC_KEY: | ||
3094 | 156 | + new_mic_muted = !old_mic_muted; | ||
3095 | 157 | + break; | ||
3096 | 158 | } | ||
3097 | 159 | |||
3098 | 160 | if (old_muted != new_muted) { | ||
3099 | 161 | @@ -1243,6 +1304,11 @@ | ||
3100 | 162 | } | ||
3101 | 163 | } | ||
3102 | 164 | |||
3103 | 165 | + if (old_mic_muted != new_mic_muted) { | ||
3104 | 166 | + gvc_mixer_stream_change_is_muted (manager->priv->input_stream, new_mic_muted); | ||
3105 | 167 | + mic_changed = TRUE; | ||
3106 | 168 | + } | ||
3107 | 169 | + | ||
3108 | 170 | if (type == VOLUME_DOWN_KEY && old_vol == 0 && old_muted) | ||
3109 | 171 | osd_vol = -1; | ||
3110 | 172 | else if (type == VOLUME_UP_KEY && old_vol == PA_VOLUME_NORM && !old_muted) | ||
3111 | 173 | @@ -1252,7 +1318,13 @@ | ||
3112 | 174 | else | ||
3113 | 175 | osd_vol = 0; | ||
3114 | 176 | |||
3115 | 177 | - update_dialog (manager, stream, osd_vol, new_muted, sound_changed, quiet); | ||
3116 | 178 | + if (mic_changed) { | ||
3117 | 179 | + osd_vol = (int) (100 * (double) new_mic_vol / PA_VOLUME_NORM); | ||
3118 | 180 | + if (new_mic_muted) osd_vol = 0; | ||
3119 | 181 | + update_mic_dialog(manager, stream, osd_vol, new_mic_muted, mic_changed, quiet); | ||
3120 | 182 | + } else { | ||
3121 | 183 | + update_speaker_dialog (manager, stream, osd_vol, new_muted, sound_changed, quiet); | ||
3122 | 184 | + } | ||
3123 | 185 | } | ||
3124 | 186 | |||
3125 | 187 | static void | ||
3126 | 188 | @@ -1290,11 +1362,34 @@ | ||
3127 | 189 | } | ||
3128 | 190 | |||
3129 | 191 | static void | ||
3130 | 192 | +update_default_source (GsdMediaKeysManager *manager) | ||
3131 | 193 | +{ | ||
3132 | 194 | + GvcMixerStream *input_stream; | ||
3133 | 195 | + | ||
3134 | 196 | + input_stream = | ||
3135 | 197 | + gvc_mixer_control_get_default_source (manager->priv->volume); | ||
3136 | 198 | + if (input_stream == manager->priv->input_stream) | ||
3137 | 199 | + return; | ||
3138 | 200 | + | ||
3139 | 201 | + if (manager->priv->input_stream != NULL) { | ||
3140 | 202 | + g_object_unref (manager->priv->input_stream); | ||
3141 | 203 | + manager->priv->input_stream = NULL; | ||
3142 | 204 | + } | ||
3143 | 205 | + | ||
3144 | 206 | + if (input_stream != NULL) { | ||
3145 | 207 | + manager->priv->input_stream = g_object_ref (input_stream); | ||
3146 | 208 | + } else { | ||
3147 | 209 | + g_warning ("Unable to get default source"); | ||
3148 | 210 | + } | ||
3149 | 211 | +} | ||
3150 | 212 | + | ||
3151 | 213 | +static void | ||
3152 | 214 | on_control_state_changed (GvcMixerControl *control, | ||
3153 | 215 | GvcMixerControlState new_state, | ||
3154 | 216 | - GsdMediaKeysManager *manager) | ||
3155 | 217 | + GsdMediaKeysManager *manager) | ||
3156 | 218 | { | ||
3157 | 219 | update_default_sink (manager); | ||
3158 | 220 | + update_default_source (manager); | ||
3159 | 221 | } | ||
3160 | 222 | |||
3161 | 223 | static void | ||
3162 | 224 | @@ -1318,6 +1413,14 @@ | ||
3163 | 225 | #endif /* HAVE_GUDEV */ | ||
3164 | 226 | |||
3165 | 227 | static void | ||
3166 | 228 | +on_control_default_source_changed (GvcMixerControl *control, | ||
3167 | 229 | + guint id, | ||
3168 | 230 | + GsdMediaKeysManager *manager) | ||
3169 | 231 | +{ | ||
3170 | 232 | + update_default_source (manager); | ||
3171 | 233 | +} | ||
3172 | 234 | + | ||
3173 | 235 | +static void | ||
3174 | 236 | on_control_stream_removed (GvcMixerControl *control, | ||
3175 | 237 | guint id, | ||
3176 | 238 | GsdMediaKeysManager *manager) | ||
3177 | 239 | @@ -1327,8 +1430,12 @@ | ||
3178 | 240 | g_object_unref (manager->priv->stream); | ||
3179 | 241 | manager->priv->stream = NULL; | ||
3180 | 242 | } | ||
3181 | 243 | + if (gvc_mixer_stream_get_id (manager->priv->input_stream) | ||
3182 | 244 | + == id) { | ||
3183 | 245 | + g_object_unref (manager->priv->input_stream); | ||
3184 | 246 | + manager->priv->input_stream = NULL; | ||
3185 | 247 | + } | ||
3186 | 248 | } | ||
3187 | 249 | - | ||
3188 | 250 | #ifdef HAVE_GUDEV | ||
3189 | 251 | g_hash_table_foreach_remove (manager->priv->streams, (GHRFunc) remove_stream, GUINT_TO_POINTER (id)); | ||
3190 | 252 | #endif | ||
3191 | 253 | @@ -2001,6 +2108,9 @@ | ||
3192 | 254 | case VOLUME_UP_KEY: | ||
3193 | 255 | do_sound_action (manager, deviceid, type, FALSE); | ||
3194 | 256 | break; | ||
3195 | 257 | + case MUTE_MIC_KEY: | ||
3196 | 258 | + do_sound_action (manager, deviceid, type, TRUE); | ||
3197 | 259 | + break; | ||
3198 | 260 | case MUTE_QUIET_KEY: | ||
3199 | 261 | do_sound_action (manager, deviceid, MUTE_KEY, TRUE); | ||
3200 | 262 | break; | ||
3201 | 263 | @@ -2360,6 +2470,10 @@ | ||
3202 | 264 | G_CALLBACK (on_control_default_sink_changed), | ||
3203 | 265 | manager); | ||
3204 | 266 | g_signal_connect (manager->priv->volume, | ||
3205 | 267 | + "default-source-changed", | ||
3206 | 268 | + G_CALLBACK (on_control_default_source_changed), | ||
3207 | 269 | + manager); | ||
3208 | 270 | + g_signal_connect (manager->priv->volume, | ||
3209 | 271 | "stream-removed", | ||
3210 | 272 | G_CALLBACK (on_control_stream_removed), | ||
3211 | 273 | manager); | ||
3212 | 274 | --- a/plugins/media-keys/shortcuts-list.h | ||
3213 | 275 | +++ b/plugins/media-keys/shortcuts-list.h | ||
3214 | 276 | @@ -32,6 +32,7 @@ | ||
3215 | 277 | MUTE_KEY, | ||
3216 | 278 | VOLUME_DOWN_KEY, | ||
3217 | 279 | VOLUME_UP_KEY, | ||
3218 | 280 | + MUTE_MIC_KEY, | ||
3219 | 281 | MUTE_QUIET_KEY, | ||
3220 | 282 | VOLUME_DOWN_QUIET_KEY, | ||
3221 | 283 | VOLUME_UP_QUIET_KEY, | ||
3222 | 284 | @@ -94,6 +95,7 @@ | ||
3223 | 285 | { MUTE_KEY, "volume-mute", NULL }, | ||
3224 | 286 | { VOLUME_DOWN_KEY, "volume-down", NULL }, | ||
3225 | 287 | { VOLUME_UP_KEY, "volume-up", NULL }, | ||
3226 | 288 | + { MUTE_MIC_KEY, NULL, "XF86AudioMicMute" }, | ||
3227 | 289 | { MUTE_QUIET_KEY, NULL, "<Alt>XF86AudioMute" }, | ||
3228 | 290 | { VOLUME_DOWN_QUIET_KEY, NULL, "<Alt>XF86AudioLowerVolume" }, | ||
3229 | 291 | { VOLUME_UP_QUIET_KEY, NULL, "<Alt>XF86AudioRaiseVolume" }, | ||
3230 | 0 | 292 | ||
3231 | === modified file 'debian/patches/series' | |||
3232 | --- debian/patches/series 2013-01-10 17:23:56 +0000 | |||
3233 | +++ debian/patches/series 2013-10-01 18:19:26 +0000 | |||
3234 | @@ -33,3 +33,4 @@ | |||
3235 | 33 | git_no_numlock_eating_cpu_loop.patch | 33 | git_no_numlock_eating_cpu_loop.patch |
3236 | 34 | git_new_xinput_handle.patch | 34 | git_new_xinput_handle.patch |
3237 | 35 | git-smartcard-crash.patch | 35 | git-smartcard-crash.patch |
3238 | 36 | 64_micmute.patch | ||
3239 | 36 | 37 | ||
3240 | === modified file 'plugins/media-keys/gsd-media-keys-manager.c' | |||
3241 | --- plugins/media-keys/gsd-media-keys-manager.c 2012-05-23 21:41:42 +0000 | |||
3242 | +++ plugins/media-keys/gsd-media-keys-manager.c 2013-10-01 18:19:26 +0000 | |||
3243 | @@ -126,6 +126,7 @@ | |||
3244 | 126 | /* Volume bits */ | 126 | /* Volume bits */ |
3245 | 127 | GvcMixerControl *volume; | 127 | GvcMixerControl *volume; |
3246 | 128 | GvcMixerStream *stream; | 128 | GvcMixerStream *stream; |
3247 | 129 | GvcMixerStream *input_stream; | ||
3248 | 129 | ca_context *ca; | 130 | ca_context *ca; |
3249 | 130 | GtkSettings *gtksettings; | 131 | GtkSettings *gtksettings; |
3250 | 131 | #ifdef HAVE_GUDEV | 132 | #ifdef HAVE_GUDEV |
3251 | @@ -199,6 +200,14 @@ | |||
3252 | 199 | NULL | 200 | NULL |
3253 | 200 | }; | 201 | }; |
3254 | 201 | 202 | ||
3255 | 203 | static const char *mic_icons[] = { | ||
3256 | 204 | "microphone-sensitivity-muted-symbolic", | ||
3257 | 205 | "microphone-sensitivity-low-symbolic", | ||
3258 | 206 | "microphone-sensitivity-medium-symbolic", | ||
3259 | 207 | "microphone-sensitivity-high-symbolic", | ||
3260 | 208 | NULL | ||
3261 | 209 | }; | ||
3262 | 210 | |||
3263 | 202 | static const char *brightness_icons[] = { | 211 | static const char *brightness_icons[] = { |
3264 | 203 | "notification-display-brightness-off", | 212 | "notification-display-brightness-off", |
3265 | 204 | "notification-display-brightness-low", | 213 | "notification-display-brightness-low", |
3266 | @@ -283,15 +292,24 @@ | |||
3267 | 283 | } | 292 | } |
3268 | 284 | 293 | ||
3269 | 285 | static gboolean | 294 | static gboolean |
3273 | 286 | ubuntu_osd_notification_show_volume (GsdMediaKeysManager *manager, | 295 | ubuntu_osd_notification_show_speaker_volume (GsdMediaKeysManager *manager, |
3274 | 287 | gint value, | 296 | gint value, |
3275 | 288 | gboolean muted) | 297 | gboolean muted) |
3276 | 289 | { | 298 | { |
3277 | 290 | return ubuntu_osd_do_notification (&manager->priv->volume_notification, | 299 | return ubuntu_osd_do_notification (&manager->priv->volume_notification, |
3278 | 291 | "volume", value, muted, volume_icons); | 300 | "volume", value, muted, volume_icons); |
3279 | 292 | } | 301 | } |
3280 | 293 | 302 | ||
3281 | 294 | static gboolean | 303 | static gboolean |
3282 | 304 | ubuntu_osd_notification_show_mic_volume (GsdMediaKeysManager *manager, | ||
3283 | 305 | gint value, | ||
3284 | 306 | gboolean muted) | ||
3285 | 307 | { | ||
3286 | 308 | return ubuntu_osd_do_notification (&manager->priv->volume_notification, | ||
3287 | 309 | "volume", value, muted, mic_icons); | ||
3288 | 310 | } | ||
3289 | 311 | |||
3290 | 312 | static gboolean | ||
3291 | 295 | ubuntu_osd_notification_show_brightness (GsdMediaKeysManager *manager, | 313 | ubuntu_osd_notification_show_brightness (GsdMediaKeysManager *manager, |
3292 | 296 | gint value) | 314 | gint value) |
3293 | 297 | { | 315 | { |
3294 | @@ -1049,14 +1067,14 @@ | |||
3295 | 1049 | } | 1067 | } |
3296 | 1050 | 1068 | ||
3297 | 1051 | static void | 1069 | static void |
3304 | 1052 | update_dialog (GsdMediaKeysManager *manager, | 1070 | update_speaker_dialog (GsdMediaKeysManager *manager, |
3305 | 1053 | GvcMixerStream *stream, | 1071 | GvcMixerStream *stream, |
3306 | 1054 | guint vol, | 1072 | guint vol, |
3307 | 1055 | gboolean muted, | 1073 | gboolean muted, |
3308 | 1056 | gboolean sound_changed, | 1074 | gboolean sound_changed, |
3309 | 1057 | gboolean quiet) | 1075 | gboolean quiet) |
3310 | 1058 | { | 1076 | { |
3312 | 1059 | if (ubuntu_osd_notification_show_volume (manager, vol, muted)) | 1077 | if (ubuntu_osd_notification_show_speaker_volume (manager, vol, muted)) |
3313 | 1060 | goto done; | 1078 | goto done; |
3314 | 1061 | 1079 | ||
3315 | 1062 | vol = CLAMP (vol, 0, 100); | 1080 | vol = CLAMP (vol, 0, 100); |
3316 | @@ -1081,6 +1099,39 @@ | |||
3317 | 1081 | } | 1099 | } |
3318 | 1082 | } | 1100 | } |
3319 | 1083 | 1101 | ||
3320 | 1102 | static void | ||
3321 | 1103 | update_mic_dialog (GsdMediaKeysManager *manager, | ||
3322 | 1104 | GvcMixerStream *stream, | ||
3323 | 1105 | guint vol, | ||
3324 | 1106 | gboolean muted, | ||
3325 | 1107 | gboolean sound_changed, | ||
3326 | 1108 | gboolean quiet) | ||
3327 | 1109 | { | ||
3328 | 1110 | vol = CLAMP (vol, 0, 100); | ||
3329 | 1111 | ubuntu_osd_notification_show_mic_volume (manager, vol, muted); | ||
3330 | 1112 | |||
3331 | 1113 | if (quiet == FALSE) { | ||
3332 | 1114 | GtkWidget *window; | ||
3333 | 1115 | if (!manager->priv->dialog) { | ||
3334 | 1116 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); | ||
3335 | 1117 | gtk_window_set_screen (GTK_WINDOW (window), manager->priv->current_screen); | ||
3336 | 1118 | gtk_widget_realize (window); | ||
3337 | 1119 | |||
3338 | 1120 | } else { | ||
3339 | 1121 | window = manager->priv->dialog; | ||
3340 | 1122 | } | ||
3341 | 1123 | ca_gtk_play_for_widget (manager->priv->dialog, 0, | ||
3342 | 1124 | CA_PROP_EVENT_ID, "audio-volume-change", | ||
3343 | 1125 | CA_PROP_EVENT_DESCRIPTION, "volume changed through key press", | ||
3344 | 1126 | CA_PROP_APPLICATION_ID, "org.gnome.VolumeControl", | ||
3345 | 1127 | CA_PROP_CANBERRA_CACHE_CONTROL, "permanent", | ||
3346 | 1128 | NULL); | ||
3347 | 1129 | |||
3348 | 1130 | if (!manager->priv->dialog) | ||
3349 | 1131 | gtk_widget_destroy(window); | ||
3350 | 1132 | } | ||
3351 | 1133 | } | ||
3352 | 1134 | |||
3353 | 1084 | #ifdef HAVE_GUDEV | 1135 | #ifdef HAVE_GUDEV |
3354 | 1085 | /* PulseAudio gives us /devices/... paths, when udev | 1136 | /* PulseAudio gives us /devices/... paths, when udev |
3355 | 1086 | * expects /sys/devices/... paths. */ | 1137 | * expects /sys/devices/... paths. */ |
3356 | @@ -1190,10 +1241,12 @@ | |||
3357 | 1190 | int type, | 1241 | int type, |
3358 | 1191 | gboolean quiet) | 1242 | gboolean quiet) |
3359 | 1192 | { | 1243 | { |
3361 | 1193 | GvcMixerStream *stream; | 1244 | GvcMixerStream *stream, *input_stream; |
3362 | 1194 | gboolean old_muted, new_muted; | 1245 | gboolean old_muted, new_muted; |
3363 | 1195 | guint old_vol, new_vol, norm_vol_step, osd_vol; | 1246 | guint old_vol, new_vol, norm_vol_step, osd_vol; |
3365 | 1196 | gboolean sound_changed; | 1247 | gboolean old_mic_muted, new_mic_muted; |
3366 | 1248 | guint old_mic_vol, new_mic_vol; | ||
3367 | 1249 | gboolean sound_changed, mic_changed; | ||
3368 | 1197 | 1250 | ||
3369 | 1198 | /* Find the stream that corresponds to the device, if any */ | 1251 | /* Find the stream that corresponds to the device, if any */ |
3370 | 1199 | #ifdef HAVE_GUDEV | 1252 | #ifdef HAVE_GUDEV |
3371 | @@ -1203,13 +1256,18 @@ | |||
3372 | 1203 | stream = manager->priv->stream; | 1256 | stream = manager->priv->stream; |
3373 | 1204 | if (stream == NULL) | 1257 | if (stream == NULL) |
3374 | 1205 | return; | 1258 | return; |
3375 | 1259 | input_stream = manager->priv->input_stream; | ||
3376 | 1260 | if (input_stream == NULL) | ||
3377 | 1261 | return; | ||
3378 | 1206 | 1262 | ||
3379 | 1207 | norm_vol_step = PA_VOLUME_NORM * VOLUME_STEP / 100; | 1263 | norm_vol_step = PA_VOLUME_NORM * VOLUME_STEP / 100; |
3380 | 1208 | 1264 | ||
3381 | 1209 | /* FIXME: this is racy */ | 1265 | /* FIXME: this is racy */ |
3382 | 1210 | new_vol = old_vol = gvc_mixer_stream_get_volume (stream); | 1266 | new_vol = old_vol = gvc_mixer_stream_get_volume (stream); |
3383 | 1267 | new_mic_vol = old_mic_vol = gvc_mixer_stream_get_volume (input_stream); | ||
3384 | 1211 | new_muted = old_muted = gvc_mixer_stream_get_is_muted (stream); | 1268 | new_muted = old_muted = gvc_mixer_stream_get_is_muted (stream); |
3386 | 1212 | sound_changed = FALSE; | 1269 | new_mic_muted = old_mic_muted = gvc_mixer_stream_get_is_muted (input_stream); |
3387 | 1270 | mic_changed = sound_changed = FALSE; | ||
3388 | 1213 | 1271 | ||
3389 | 1214 | switch (type) { | 1272 | switch (type) { |
3390 | 1215 | case MUTE_KEY: | 1273 | case MUTE_KEY: |
3391 | @@ -1229,6 +1287,9 @@ | |||
3392 | 1229 | if (!old_muted || old_vol == 0) | 1287 | if (!old_muted || old_vol == 0) |
3393 | 1230 | new_vol = MIN (old_vol + norm_vol_step, MAX_VOLUME); | 1288 | new_vol = MIN (old_vol + norm_vol_step, MAX_VOLUME); |
3394 | 1231 | break; | 1289 | break; |
3395 | 1290 | case MUTE_MIC_KEY: | ||
3396 | 1291 | new_mic_muted = !old_mic_muted; | ||
3397 | 1292 | break; | ||
3398 | 1232 | } | 1293 | } |
3399 | 1233 | 1294 | ||
3400 | 1234 | if (old_muted != new_muted) { | 1295 | if (old_muted != new_muted) { |
3401 | @@ -1243,6 +1304,11 @@ | |||
3402 | 1243 | } | 1304 | } |
3403 | 1244 | } | 1305 | } |
3404 | 1245 | 1306 | ||
3405 | 1307 | if (old_mic_muted != new_mic_muted) { | ||
3406 | 1308 | gvc_mixer_stream_change_is_muted (manager->priv->input_stream, new_mic_muted); | ||
3407 | 1309 | mic_changed = TRUE; | ||
3408 | 1310 | } | ||
3409 | 1311 | |||
3410 | 1246 | if (type == VOLUME_DOWN_KEY && old_vol == 0 && old_muted) | 1312 | if (type == VOLUME_DOWN_KEY && old_vol == 0 && old_muted) |
3411 | 1247 | osd_vol = -1; | 1313 | osd_vol = -1; |
3412 | 1248 | else if (type == VOLUME_UP_KEY && old_vol == PA_VOLUME_NORM && !old_muted) | 1314 | else if (type == VOLUME_UP_KEY && old_vol == PA_VOLUME_NORM && !old_muted) |
3413 | @@ -1252,7 +1318,13 @@ | |||
3414 | 1252 | else | 1318 | else |
3415 | 1253 | osd_vol = 0; | 1319 | osd_vol = 0; |
3416 | 1254 | 1320 | ||
3418 | 1255 | update_dialog (manager, stream, osd_vol, new_muted, sound_changed, quiet); | 1321 | if (mic_changed) { |
3419 | 1322 | osd_vol = (int) (100 * (double) new_mic_vol / PA_VOLUME_NORM); | ||
3420 | 1323 | if (new_mic_muted) osd_vol = 0; | ||
3421 | 1324 | update_mic_dialog(manager, stream, osd_vol, new_mic_muted, mic_changed, quiet); | ||
3422 | 1325 | } else { | ||
3423 | 1326 | update_speaker_dialog (manager, stream, osd_vol, new_muted, sound_changed, quiet); | ||
3424 | 1327 | } | ||
3425 | 1256 | } | 1328 | } |
3426 | 1257 | 1329 | ||
3427 | 1258 | static void | 1330 | static void |
3428 | @@ -1290,11 +1362,34 @@ | |||
3429 | 1290 | } | 1362 | } |
3430 | 1291 | 1363 | ||
3431 | 1292 | static void | 1364 | static void |
3432 | 1365 | update_default_source (GsdMediaKeysManager *manager) | ||
3433 | 1366 | { | ||
3434 | 1367 | GvcMixerStream *input_stream; | ||
3435 | 1368 | |||
3436 | 1369 | input_stream = | ||
3437 | 1370 | gvc_mixer_control_get_default_source (manager->priv->volume); | ||
3438 | 1371 | if (input_stream == manager->priv->input_stream) | ||
3439 | 1372 | return; | ||
3440 | 1373 | |||
3441 | 1374 | if (manager->priv->input_stream != NULL) { | ||
3442 | 1375 | g_object_unref (manager->priv->input_stream); | ||
3443 | 1376 | manager->priv->input_stream = NULL; | ||
3444 | 1377 | } | ||
3445 | 1378 | |||
3446 | 1379 | if (input_stream != NULL) { | ||
3447 | 1380 | manager->priv->input_stream = g_object_ref (input_stream); | ||
3448 | 1381 | } else { | ||
3449 | 1382 | g_warning ("Unable to get default source"); | ||
3450 | 1383 | } | ||
3451 | 1384 | } | ||
3452 | 1385 | |||
3453 | 1386 | static void | ||
3454 | 1293 | on_control_state_changed (GvcMixerControl *control, | 1387 | on_control_state_changed (GvcMixerControl *control, |
3455 | 1294 | GvcMixerControlState new_state, | 1388 | GvcMixerControlState new_state, |
3457 | 1295 | GsdMediaKeysManager *manager) | 1389 | GsdMediaKeysManager *manager) |
3458 | 1296 | { | 1390 | { |
3459 | 1297 | update_default_sink (manager); | 1391 | update_default_sink (manager); |
3460 | 1392 | update_default_source (manager); | ||
3461 | 1298 | } | 1393 | } |
3462 | 1299 | 1394 | ||
3463 | 1300 | static void | 1395 | static void |
3464 | @@ -1318,6 +1413,14 @@ | |||
3465 | 1318 | #endif /* HAVE_GUDEV */ | 1413 | #endif /* HAVE_GUDEV */ |
3466 | 1319 | 1414 | ||
3467 | 1320 | static void | 1415 | static void |
3468 | 1416 | on_control_default_source_changed (GvcMixerControl *control, | ||
3469 | 1417 | guint id, | ||
3470 | 1418 | GsdMediaKeysManager *manager) | ||
3471 | 1419 | { | ||
3472 | 1420 | update_default_source (manager); | ||
3473 | 1421 | } | ||
3474 | 1422 | |||
3475 | 1423 | static void | ||
3476 | 1321 | on_control_stream_removed (GvcMixerControl *control, | 1424 | on_control_stream_removed (GvcMixerControl *control, |
3477 | 1322 | guint id, | 1425 | guint id, |
3478 | 1323 | GsdMediaKeysManager *manager) | 1426 | GsdMediaKeysManager *manager) |
3479 | @@ -1327,8 +1430,12 @@ | |||
3480 | 1327 | g_object_unref (manager->priv->stream); | 1430 | g_object_unref (manager->priv->stream); |
3481 | 1328 | manager->priv->stream = NULL; | 1431 | manager->priv->stream = NULL; |
3482 | 1329 | } | 1432 | } |
3483 | 1433 | if (gvc_mixer_stream_get_id (manager->priv->input_stream) | ||
3484 | 1434 | == id) { | ||
3485 | 1435 | g_object_unref (manager->priv->input_stream); | ||
3486 | 1436 | manager->priv->input_stream = NULL; | ||
3487 | 1437 | } | ||
3488 | 1330 | } | 1438 | } |
3489 | 1331 | |||
3490 | 1332 | #ifdef HAVE_GUDEV | 1439 | #ifdef HAVE_GUDEV |
3491 | 1333 | g_hash_table_foreach_remove (manager->priv->streams, (GHRFunc) remove_stream, GUINT_TO_POINTER (id)); | 1440 | g_hash_table_foreach_remove (manager->priv->streams, (GHRFunc) remove_stream, GUINT_TO_POINTER (id)); |
3492 | 1334 | #endif | 1441 | #endif |
3493 | @@ -2001,6 +2108,9 @@ | |||
3494 | 2001 | case VOLUME_UP_KEY: | 2108 | case VOLUME_UP_KEY: |
3495 | 2002 | do_sound_action (manager, deviceid, type, FALSE); | 2109 | do_sound_action (manager, deviceid, type, FALSE); |
3496 | 2003 | break; | 2110 | break; |
3497 | 2111 | case MUTE_MIC_KEY: | ||
3498 | 2112 | do_sound_action (manager, deviceid, type, TRUE); | ||
3499 | 2113 | break; | ||
3500 | 2004 | case MUTE_QUIET_KEY: | 2114 | case MUTE_QUIET_KEY: |
3501 | 2005 | do_sound_action (manager, deviceid, MUTE_KEY, TRUE); | 2115 | do_sound_action (manager, deviceid, MUTE_KEY, TRUE); |
3502 | 2006 | break; | 2116 | break; |
3503 | @@ -2360,6 +2470,10 @@ | |||
3504 | 2360 | G_CALLBACK (on_control_default_sink_changed), | 2470 | G_CALLBACK (on_control_default_sink_changed), |
3505 | 2361 | manager); | 2471 | manager); |
3506 | 2362 | g_signal_connect (manager->priv->volume, | 2472 | g_signal_connect (manager->priv->volume, |
3507 | 2473 | "default-source-changed", | ||
3508 | 2474 | G_CALLBACK (on_control_default_source_changed), | ||
3509 | 2475 | manager); | ||
3510 | 2476 | g_signal_connect (manager->priv->volume, | ||
3511 | 2363 | "stream-removed", | 2477 | "stream-removed", |
3512 | 2364 | G_CALLBACK (on_control_stream_removed), | 2478 | G_CALLBACK (on_control_stream_removed), |
3513 | 2365 | manager); | 2479 | manager); |
3514 | 2366 | 2480 | ||
3515 | === modified file 'plugins/media-keys/shortcuts-list.h' | |||
3516 | --- plugins/media-keys/shortcuts-list.h 2012-02-15 11:41:52 +0000 | |||
3517 | +++ plugins/media-keys/shortcuts-list.h 2013-10-01 18:19:26 +0000 | |||
3518 | @@ -32,6 +32,7 @@ | |||
3519 | 32 | MUTE_KEY, | 32 | MUTE_KEY, |
3520 | 33 | VOLUME_DOWN_KEY, | 33 | VOLUME_DOWN_KEY, |
3521 | 34 | VOLUME_UP_KEY, | 34 | VOLUME_UP_KEY, |
3522 | 35 | MUTE_MIC_KEY, | ||
3523 | 35 | MUTE_QUIET_KEY, | 36 | MUTE_QUIET_KEY, |
3524 | 36 | VOLUME_DOWN_QUIET_KEY, | 37 | VOLUME_DOWN_QUIET_KEY, |
3525 | 37 | VOLUME_UP_QUIET_KEY, | 38 | VOLUME_UP_QUIET_KEY, |
3526 | @@ -94,6 +95,7 @@ | |||
3527 | 94 | { MUTE_KEY, "volume-mute", NULL }, | 95 | { MUTE_KEY, "volume-mute", NULL }, |
3528 | 95 | { VOLUME_DOWN_KEY, "volume-down", NULL }, | 96 | { VOLUME_DOWN_KEY, "volume-down", NULL }, |
3529 | 96 | { VOLUME_UP_KEY, "volume-up", NULL }, | 97 | { VOLUME_UP_KEY, "volume-up", NULL }, |
3530 | 98 | { MUTE_MIC_KEY, NULL, "XF86AudioMicMute" }, | ||
3531 | 97 | { MUTE_QUIET_KEY, NULL, "<Alt>XF86AudioMute" }, | 99 | { MUTE_QUIET_KEY, NULL, "<Alt>XF86AudioMute" }, |
3532 | 98 | { VOLUME_DOWN_QUIET_KEY, NULL, "<Alt>XF86AudioLowerVolume" }, | 100 | { VOLUME_DOWN_QUIET_KEY, NULL, "<Alt>XF86AudioLowerVolume" }, |
3533 | 99 | { VOLUME_UP_QUIET_KEY, NULL, "<Alt>XF86AudioRaiseVolume" }, | 101 | { VOLUME_UP_QUIET_KEY, NULL, "<Alt>XF86AudioRaiseVolume" }, |
That got uploaded but apprently the update is making the notification not working anymore, we are going to need to revert (or drop the SRU rather)