Bug Summary

File:plugins/media-keys/csd_media-keys-manager.c
Warning:line 603, column 25
Value stored to 'score' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name csd_media-keys-manager.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/rootdir/plugins/media-keys -resource-dir /usr/lib/llvm-14/lib/clang/14.0.6 -D HAVE_CONFIG_H -I . -I ../.. -I ../../cafe-settings-daemon -I ../../plugins/common -D PIXMAPDIR="/usr/share/cafe-settings-daemon" -D CTKBUILDERDIR="/usr/share/cafe-settings-daemon" -D CAFE_SETTINGS_LOCALEDIR="/usr/share/locale" -I /usr/include/ctk-3.0 -I /usr/include/pango-1.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/gio-unix-2.0 -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/cafe-mixer -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -D _REENTRANT -I /usr/include/ctk-3.0 -I /usr/include/pango-1.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/gio-unix-2.0 -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.6/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/rootdir/plugins/media-keys -ferror-limit 19 -fgnuc-version=4.2.1 -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2023-08-26-174004-64287-1 -x c csd_media-keys-manager.c
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2001-2003 Bastien Nocera <hadess@hadess.net>
4 * Copyright (C) 2006-2007 William Jon McCann <mccann@jhu.edu>
5 * Copyright (C) 2014 Michal Ratajsky <michal.ratajsky@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23#include "config.h"
24
25#include <glib.h>
26#include <glib/gi18n.h>
27#include <cdk/cdk.h>
28#include <cdk/cdkx.h>
29#include <ctk/ctk.h>
30#include <gio/gio.h>
31
32#include <dbus/dbus-glib.h>
33#include <dbus/dbus-glib-lowlevel.h>
34
35#ifdef HAVE_LIBCAFEMIXER1
36#include <libcafemixer/cafemixer.h>
37#endif
38
39#ifdef HAVE_LIBKANBERRA1
40#include <kanberra-ctk.h>
41#endif
42
43#include "cafe-settings-profile.h"
44#include "csd_marshal.h"
45#include "csd_media-keys-manager.h"
46#include "csd_media-keys-manager-glue.h"
47
48#include "eggaccelerators.h"
49#include "acme.h"
50#include "csd_media-keys-window.h"
51#include "csd_input-helper.h"
52
53#define CSD_DBUS_PATH"/org/cafe/SettingsDaemon" "/org/cafe/SettingsDaemon"
54#define CSD_DBUS_NAME"org.cafe.SettingsDaemon" "org.cafe.SettingsDaemon"
55#define CSD_MEDIA_KEYS_DBUS_PATH"/org/cafe/SettingsDaemon" "/MediaKeys" CSD_DBUS_PATH"/org/cafe/SettingsDaemon" "/MediaKeys"
56#define CSD_MEDIA_KEYS_DBUS_NAME"org.cafe.SettingsDaemon" ".MediaKeys" CSD_DBUS_NAME"org.cafe.SettingsDaemon" ".MediaKeys"
57
58#define TOUCHPAD_SCHEMA"org.cafe.peripherals-touchpad" "org.cafe.peripherals-touchpad"
59#define TOUCHPAD_ENABLED_KEY"touchpad-enabled" "touchpad-enabled"
60
61typedef struct {
62 char *application;
63 guint32 time;
64} MediaPlayer;
65
66struct _CsdMediaKeysManagerPrivate
67{
68#ifdef HAVE_LIBCAFEMIXER1
69 /* Volume bits */
70 CafeMixerContext *context;
71 CafeMixerStream *stream;
72 CafeMixerStream *source_stream;
73 CafeMixerStreamControl *control;
74 CafeMixerStreamControl *source_control;
75#endif
76 CtkWidget *dialog;
77 GSettings *settings;
78 GVolumeMonitor *volume_monitor;
79
80 /* Multihead stuff */
81 CdkScreen *current_screen;
82 GSList *screens;
83
84 /* RFKill stuff */
85 guint rfkill_watch_id;
86 GDBusProxy *rfkill_proxy;
87 GCancellable *rfkill_cancellable;
88
89 GList *media_players;
90
91 DBusGConnection *connection;
92 guint notify[HANDLED_KEYS];
93};
94
95enum {
96 MEDIA_PLAYER_KEY_PRESSED,
97 LAST_SIGNAL
98};
99
100static guint signals[LAST_SIGNAL] = { 0 };
101
102G_DEFINE_TYPE_WITH_PRIVATE (CsdMediaKeysManager, csd_media_keys_manager, G_TYPE_OBJECT)static void csd_media_keys_manager_init (CsdMediaKeysManager *
self); static void csd_media_keys_manager_class_init (CsdMediaKeysManagerClass
*klass); static GType csd_media_keys_manager_get_type_once (
void); static gpointer csd_media_keys_manager_parent_class = (
(void*)0); static gint CsdMediaKeysManager_private_offset; static
void csd_media_keys_manager_class_intern_init (gpointer klass
) { csd_media_keys_manager_parent_class = g_type_class_peek_parent
(klass); if (CsdMediaKeysManager_private_offset != 0) g_type_class_adjust_private_offset
(klass, &CsdMediaKeysManager_private_offset); csd_media_keys_manager_class_init
((CsdMediaKeysManagerClass*) klass); } __attribute__ ((__unused__
)) static inline gpointer csd_media_keys_manager_get_instance_private
(CsdMediaKeysManager *self) { return (((gpointer) ((guint8*)
(self) + (glong) (CsdMediaKeysManager_private_offset)))); } GType
csd_media_keys_manager_get_type (void) { static gsize static_g_define_type_id
= 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); (void
) (0 ? (gpointer) *(&static_g_define_type_id) : ((void*)0
)); (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(*(&static_g_define_type_id)) gapg_temp_newval; __typeof__
((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id
); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5)
; gapg_temp_newval; })) && g_once_init_enter (&static_g_define_type_id
)); }))) { GType g_define_type_id = csd_media_keys_manager_get_type_once
(); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); 0 ?
(void) (*(&static_g_define_type_id) = (g_define_type_id)
) : (void) 0; g_once_init_leave ((&static_g_define_type_id
), (gsize) (g_define_type_id)); })); } return static_g_define_type_id
; } __attribute__ ((__noinline__)) static GType csd_media_keys_manager_get_type_once
(void) { GType g_define_type_id = g_type_register_static_simple
(((GType) ((20) << (2))), g_intern_static_string ("CsdMediaKeysManager"
), sizeof (CsdMediaKeysManagerClass), (GClassInitFunc)(void (
*)(void)) csd_media_keys_manager_class_intern_init, sizeof (CsdMediaKeysManager
), (GInstanceInitFunc)(void (*)(void)) csd_media_keys_manager_init
, (GTypeFlags) 0); { {{ CsdMediaKeysManager_private_offset = g_type_add_instance_private
(g_define_type_id, sizeof (CsdMediaKeysManagerPrivate)); };}
} return g_define_type_id; }
103
104static gpointer manager_object = NULL((void*)0);
105
106static void
107init_screens (CsdMediaKeysManager *manager)
108{
109 CdkDisplay *display;
110
111 display = cdk_display_get_default ();
112
113 CdkScreen *screen;
114
115 screen = cdk_display_get_default_screen (display);
116
117 if (screen != NULL((void*)0)) {
118 manager->priv->screens = g_slist_append (manager->priv->screens, screen);
119 }
120
121 manager->priv->current_screen = manager->priv->screens->data;
122}
123
124static void
125acme_error (char * msg)
126{
127 CtkWidget *error_dialog;
128
129 error_dialog = ctk_message_dialog_new (NULL((void*)0),
130 CTK_DIALOG_MODAL,
131 CTK_MESSAGE_ERROR,
132 CTK_BUTTONS_OK,
133 msg, NULL((void*)0));
134 ctk_dialog_set_default_response (CTK_DIALOG (error_dialog)((((CtkDialog*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((error_dialog)), ((ctk_dialog_get_type ()))))))
,
135 CTK_RESPONSE_OK);
136 ctk_widget_show (error_dialog);
137 g_signal_connect (error_dialog,g_signal_connect_data ((error_dialog), ("response"), (((GCallback
) (ctk_widget_destroy))), (((void*)0)), ((void*)0), (GConnectFlags
) 0)
138 "response",g_signal_connect_data ((error_dialog), ("response"), (((GCallback
) (ctk_widget_destroy))), (((void*)0)), ((void*)0), (GConnectFlags
) 0)
139 G_CALLBACK (ctk_widget_destroy),g_signal_connect_data ((error_dialog), ("response"), (((GCallback
) (ctk_widget_destroy))), (((void*)0)), ((void*)0), (GConnectFlags
) 0)
140 NULL)g_signal_connect_data ((error_dialog), ("response"), (((GCallback
) (ctk_widget_destroy))), (((void*)0)), ((void*)0), (GConnectFlags
) 0)
;
141}
142
143static char *
144get_term_command (CsdMediaKeysManager *manager)
145{
146 char *cmd_term, *cmd_args;
147 char *cmd = NULL((void*)0);
148 GSettings *settings;
149
150 settings = g_settings_new ("org.cafe.applications-terminal");
151 cmd_term = g_settings_get_string (settings, "exec");
152 cmd_args = g_settings_get_string (settings, "exec-arg");
153
154 if (cmd_term[0] != '\0') {
155 cmd = g_strdup_printf ("%s %s -e", cmd_term, cmd_args);
156 } else {
157 cmd = g_strdup_printf ("cafe-terminal -e");
158 }
159
160 g_free (cmd_args);
161 g_free (cmd_term);
162 g_object_unref (settings);
163
164 return cmd;
165}
166
167static void
168execute (CsdMediaKeysManager *manager,
169 char *cmd,
170 gboolean sync,
171 gboolean need_term)
172{
173 gboolean retval;
174 char **argv;
175 int argc;
176 char *exec;
177 char *term = NULL((void*)0);
178
179 retval = FALSE(0);
180
181 if (need_term) {
182 term = get_term_command (manager);
183 if (term == NULL((void*)0)) {
184 acme_error (_("Could not get default terminal. Verify that your default "gettext ("Could not get default terminal. Verify that your default "
"terminal command is set and points to a valid application."
)
185 "terminal command is set and points to a valid application.")gettext ("Could not get default terminal. Verify that your default "
"terminal command is set and points to a valid application."
)
);
186 return;
187 }
188 }
189
190 if (term) {
191 exec = g_strdup_printf ("%s %s", term, cmd);
192 g_free (term);
193 } else {
194 exec = g_strdup (cmd)g_strdup_inline (cmd);
195 }
196
197 if (g_shell_parse_argv (exec, &argc, &argv, NULL((void*)0))) {
198 if (sync != FALSE(0)) {
199 retval = g_spawn_sync (g_get_home_dir (),
200 argv,
201 NULL((void*)0),
202 G_SPAWN_SEARCH_PATH,
203 NULL((void*)0),
204 NULL((void*)0),
205 NULL((void*)0),
206 NULL((void*)0),
207 NULL((void*)0),
208 NULL((void*)0));
209 } else {
210 retval = g_spawn_async (g_get_home_dir (),
211 argv,
212 NULL((void*)0),
213 G_SPAWN_SEARCH_PATH,
214 NULL((void*)0),
215 NULL((void*)0),
216 NULL((void*)0),
217 NULL((void*)0));
218 }
219 g_strfreev (argv);
220 }
221
222 if (retval == FALSE(0)) {
223 char *msg;
224 msg = g_strdup_printf (_("Couldn't execute command: %s\n"gettext ("Couldn't execute command: %s\n" "Verify that this is a valid command."
)
225 "Verify that this is a valid command.")gettext ("Couldn't execute command: %s\n" "Verify that this is a valid command."
)
,
226 exec);
227
228 acme_error (msg);
229 g_free (msg);
230 }
231 g_free (exec);
232}
233
234static void
235dialog_init (CsdMediaKeysManager *manager)
236{
237 if (manager->priv->dialog != NULL((void*)0)
238 && !csd_osd_window_is_valid (CSD_OSD_WINDOW (manager->priv->dialog)((((CsdOsdWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((manager->priv->dialog)), ((csd_osd_window_get_type
()))))))
)) {
239 ctk_widget_destroy (manager->priv->dialog);
240 manager->priv->dialog = NULL((void*)0);
241 }
242
243 if (manager->priv->dialog == NULL((void*)0)) {
244 manager->priv->dialog = csd_media_keys_window_new ();
245 }
246}
247
248static gboolean
249is_valid_shortcut (const char *string)
250{
251 if (string == NULL((void*)0) || string[0] == '\0') {
252 return FALSE(0);
253 }
254 if (strcmp (string, "disabled") == 0) {
255 return FALSE(0);
256 }
257
258 return TRUE(!(0));
259}
260
261static void
262update_kbd_cb (GSettings *settings,
263 gchar *settings_key,
264 CsdMediaKeysManager *manager)
265{
266 int i;
267 CdkDisplay *dpy;
268 gboolean need_flush = TRUE(!(0));
269
270 g_return_if_fail (settings_key != NULL)do { if ((settings_key != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "settings_key != NULL"
); return; } } while (0)
;
271
272 dpy = cdk_display_get_default ();
273 cdk_x11_display_error_trap_push (dpy);
274
275 /* Find the key that was modified */
276 for (i = 0; i < HANDLED_KEYS; i++) {
277 if (g_strcmp0 (settings_key, keys[i].settings_key) == 0) {
278 char *tmp;
279 Key *key;
280
281 if (keys[i].key != NULL((void*)0)) {
282 need_flush = TRUE(!(0));
283 grab_key_unsafe (keys[i].key, FALSE(0), manager->priv->screens);
284 }
285
286 g_free (keys[i].key);
287 keys[i].key = NULL((void*)0);
288
289 /* We can't have a change in a hard-coded key */
290 g_assert (keys[i].settings_key != NULL)do { if (keys[i].settings_key != ((void*)0)) ; else g_assertion_message_expr
(((gchar*) 0), "csd_media-keys-manager.c", 290, ((const char
*) (__func__)), "keys[i].settings_key != NULL"); } while (0)
;
291
292 tmp = g_settings_get_string (settings,
293 keys[i].settings_key);
294
295 if (is_valid_shortcut (tmp) == FALSE(0)) {
296 g_free (tmp);
297 break;
298 }
299
300 key = g_new0 (Key, 1)((Key *) g_malloc0_n ((1), sizeof (Key)));
301 if (!egg_accelerator_parse_virtual (tmp, &key->keysym, &key->keycodes, &key->state)) {
302 g_free (tmp);
303 g_free (key);
304 break;
305 }
306
307 need_flush = TRUE(!(0));
308 grab_key_unsafe (key, TRUE(!(0)), manager->priv->screens);
309 keys[i].key = key;
310
311 g_free (tmp);
312
313 break;
314 }
315 }
316
317 if (need_flush)
318 cdk_display_flush (dpy);
319 if (cdk_x11_display_error_trap_pop (dpy))
320 g_warning ("Grab failed for some keys, another application may already have access the them.");
321}
322
323static void init_kbd(CsdMediaKeysManager* manager)
324{
325 int i;
326 CdkDisplay *dpy;
327 gboolean need_flush = FALSE(0);
328
329 cafe_settings_profile_start(NULL);
330
331 dpy = cdk_display_get_default ();
332 cdk_x11_display_error_trap_push (dpy);
333
334 for (i = 0; i < HANDLED_KEYS; i++)
335 {
336 char* tmp;
337 Key* key;
338
339 gchar* signal_name;
340 signal_name = g_strdup_printf ("changed::%s", keys[i].settings_key);
341 g_signal_connect (manager->priv->settings,g_signal_connect_data ((manager->priv->settings), (signal_name
), (((GCallback) (update_kbd_cb))), (manager), ((void*)0), (GConnectFlags
) 0)
342 signal_name,g_signal_connect_data ((manager->priv->settings), (signal_name
), (((GCallback) (update_kbd_cb))), (manager), ((void*)0), (GConnectFlags
) 0)
343 G_CALLBACK (update_kbd_cb),g_signal_connect_data ((manager->priv->settings), (signal_name
), (((GCallback) (update_kbd_cb))), (manager), ((void*)0), (GConnectFlags
) 0)
344 manager)g_signal_connect_data ((manager->priv->settings), (signal_name
), (((GCallback) (update_kbd_cb))), (manager), ((void*)0), (GConnectFlags
) 0)
;
345 g_free (signal_name);
346
347 if (keys[i].settings_key != NULL((void*)0)) {
348 tmp = g_settings_get_string (manager->priv->settings, keys[i].settings_key);
349 } else {
350 tmp = g_strdup (keys[i].hard_coded)g_strdup_inline (keys[i].hard_coded);
351 }
352
353 if (!is_valid_shortcut(tmp))
354 {
355 g_debug("Not a valid shortcut: '%s'", tmp);
356 g_free(tmp);
357 continue;
358 }
359
360 key = g_new0(Key, 1)((Key *) g_malloc0_n ((1), sizeof (Key)));
361
362 if (!egg_accelerator_parse_virtual(tmp, &key->keysym, &key->keycodes, &key->state))
363 {
364 g_debug("Unable to parse: '%s'", tmp);
365 g_free(tmp);
366 g_free(key);
367 continue;
368 }
369
370 g_free(tmp);
371
372 keys[i].key = key;
373
374 need_flush = TRUE(!(0));
375 grab_key_unsafe(key, TRUE(!(0)), manager->priv->screens);
376 }
377
378 if (need_flush)
379 {
380 cdk_display_flush (dpy);
381 }
382
383 if (cdk_x11_display_error_trap_pop (dpy))
384 {
385 g_warning("Grab failed for some keys, another application may already have access the them.");
386 }
387
388 cafe_settings_profile_end(NULL);
389}
390
391static void
392ensure_cancellable (GCancellable **cancellable)
393{
394 if (*cancellable == NULL((void*)0)) {
395 *cancellable = g_cancellable_new ();
396 g_object_add_weak_pointer (G_OBJECT (*cancellable)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((*cancellable)), (((GType) ((20) << (2))))))))
,
397 (gpointer *)cancellable);
398 } else {
399 g_object_ref (*cancellable)((__typeof__ (*cancellable)) (g_object_ref) (*cancellable));
400 }
401}
402
403static void
404dialog_show (CsdMediaKeysManager *manager)
405{
406 int orig_w;
407 int orig_h;
408 int screen_w;
409 int screen_h;
410 int x;
411 int y;
412 CdkDisplay *display;
413 CdkSeat *seat;
414 CdkDevice *pointer;
415 int pointer_x;
416 int pointer_y;
417 CtkRequisition win_req;
418 CdkScreen *pointer_screen;
419 CdkRectangle geometry;
420 CdkMonitor *monitor;
421
422 ctk_window_set_screen (CTK_WINDOW (manager->priv->dialog)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((manager->priv->dialog)), ((ctk_window_get_type ())
)))))
,
423 manager->priv->current_screen);
424
425 /* Return if OSD notifications are disabled */
426 if (!g_settings_get_boolean (manager->priv->settings, "enable-osd"))
427 return;
428
429 /*
430 * get the window size
431 * if the window hasn't been mapped, it doesn't necessarily
432 * know its true size, yet, so we need to jump through hoops
433 */
434 ctk_window_get_default_size (CTK_WINDOW (manager->priv->dialog)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((manager->priv->dialog)), ((ctk_window_get_type ())
)))))
, &orig_w, &orig_h);
435 ctk_widget_get_preferred_size (manager->priv->dialog, NULL((void*)0), &win_req);
436
437 if (win_req.width > orig_w) {
438 orig_w = win_req.width;
439 }
440 if (win_req.height > orig_h) {
441 orig_h = win_req.height;
442 }
443
444 pointer_screen = NULL((void*)0);
445 display = cdk_screen_get_display (manager->priv->current_screen);
446 seat = cdk_display_get_default_seat (display);
447 pointer = cdk_seat_get_pointer (seat);
448
449 cdk_device_get_position (pointer,
450 &pointer_screen,
451 &pointer_x,
452 &pointer_y);
453
454 if (pointer_screen != manager->priv->current_screen) {
455 /* The pointer isn't on the current screen, so just
456 * assume the default monitor
457 */
458 monitor = cdk_display_get_monitor (display, 0);
459 } else {
460 monitor = cdk_display_get_monitor_at_point (display, pointer_x, pointer_y);
461 }
462
463 cdk_monitor_get_geometry (monitor, &geometry);
464
465 screen_w = geometry.width;
466 screen_h = geometry.height;
467
468 x = ((screen_w - orig_w) / 2) + geometry.x;
469 y = geometry.y + (screen_h / 2) + (screen_h / 2 - orig_h) / 2;
470
471 ctk_window_move (CTK_WINDOW (manager->priv->dialog)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((manager->priv->dialog)), ((ctk_window_get_type ())
)))))
, x, y);
472
473 ctk_widget_show (manager->priv->dialog);
474
475 cdk_display_sync (cdk_screen_get_display (manager->priv->current_screen));
476}
477
478static void
479do_url_action (CsdMediaKeysManager *manager,
480 const gchar *scheme)
481{
482 GError *error = NULL((void*)0);
483 GAppInfo *app_info;
484
485 app_info = g_app_info_get_default_for_uri_scheme (scheme);
486
487 if (app_info != NULL((void*)0)) {
488 if (!g_app_info_launch (app_info, NULL((void*)0), NULL((void*)0), &error)) {
489 g_warning ("Could not launch '%s': %s",
490 g_app_info_get_commandline (app_info),
491 error->message);
492 g_object_unref (app_info);
493 g_error_free (error);
494 }
495 }
496 else {
497 g_warning ("Could not find default application for '%s' scheme", scheme);
498 }
499}
500
501static void
502do_media_action (CsdMediaKeysManager *manager)
503{
504 GError *error = NULL((void*)0);
505 GAppInfo *app_info;
506
507 app_info = g_app_info_get_default_for_type ("audio/x-vorbis+ogg", FALSE(0));
508
509 if (app_info != NULL((void*)0)) {
510 if (!g_app_info_launch (app_info, NULL((void*)0), NULL((void*)0), &error)) {
511 g_warning ("Could not launch '%s': %s",
512 g_app_info_get_commandline (app_info),
513 error->message);
514 g_error_free (error);
515 }
516 }
517 else {
518 g_warning ("Could not find default application for '%s' mime-type", "audio/x-vorbis+ogg");
519 }
520}
521
522static void
523do_calculator_action (CsdMediaKeysManager *manager)
524{
525 GSettings *settings;
526 char *calc;
527
528 settings = g_settings_new ("org.cafe.applications-calculator");
529 calc = g_settings_get_string (settings, "exec");
530
531 if (calc)
532 execute (manager, calc, FALSE(0), FALSE(0));
533
534 g_free (calc);
535 g_object_unref (settings);
536}
537
538static void
539do_messenger_action (CsdMediaKeysManager *manager)
540{
541 GSettings *settings;
542 char *messenger;
543
544 settings = g_settings_new ("org.cafe.applications-messenger");
545 messenger = g_settings_get_string (settings, "exec");
546
547 if (messenger)
548 execute (manager, messenger, FALSE(0), FALSE(0));
549
550 g_free (messenger);
551 g_object_unref (settings);
552}
553
554static void
555do_shutdown_action (CsdMediaKeysManager *manager)
556{
557 execute (manager, "cafe-session-save --shutdown-dialog", FALSE(0), FALSE(0));
558}
559
560static void
561do_logout_action (CsdMediaKeysManager *manager)
562{
563 execute (manager, "cafe-session-save --logout-dialog", FALSE(0), FALSE(0));
564}
565
566static void
567do_eject_action_cb (GDrive *drive,
568 GAsyncResult *res,
569 CsdMediaKeysManager *manager)
570{
571 g_drive_eject_with_operation_finish (drive, res, NULL((void*)0));
572}
573
574#define NO_SCORE0 0
575#define SCORE_CAN_EJECT50 50
576#define SCORE_HAS_MEDIA100 100
577static void
578do_eject_action (CsdMediaKeysManager *manager)
579{
580 GList *drives, *l;
581 GDrive *fav_drive;
582 guint score;
583
584 /* Find the best drive to eject */
585 fav_drive = NULL((void*)0);
586 score = NO_SCORE0;
587 drives = g_volume_monitor_get_connected_drives (manager->priv->volume_monitor);
588 for (l = drives; l != NULL((void*)0); l = l->next) {
589 GDrive *drive = l->data;
590
591 if (g_drive_can_eject (drive) == FALSE(0))
592 continue;
593 if (g_drive_is_media_removable (drive) == FALSE(0))
594 continue;
595 if (score < SCORE_CAN_EJECT50) {
596 fav_drive = drive;
597 score = SCORE_CAN_EJECT50;
598 }
599 if (g_drive_has_media (drive) == FALSE(0))
600 continue;
601 if (score < SCORE_HAS_MEDIA100) {
602 fav_drive = drive;
603 score = SCORE_HAS_MEDIA100;
Value stored to 'score' is never read
604 break;
605 }
606 }
607
608 /* Show the dialogue */
609 dialog_init (manager);
610 csd_media_keys_window_set_action_custom (CSD_MEDIA_KEYS_WINDOW (manager->priv->dialog)((((CsdMediaKeysWindow*) (void *) g_type_check_instance_cast (
(GTypeInstance*) ((manager->priv->dialog)), ((csd_media_keys_window_get_type
()))))))
,
611 "media-eject",
612 NULL((void*)0));
613 dialog_show (manager);
614
615 /* Clean up the drive selection and exit if no suitable
616 * drives are found */
617 if (fav_drive != NULL((void*)0))
618 fav_drive = g_object_ref (fav_drive)((__typeof__ (fav_drive)) (g_object_ref) (fav_drive));
619
620 g_list_foreach (drives, (GFunc) g_object_unref, NULL((void*)0));
621 if (fav_drive == NULL((void*)0))
622 return;
623
624 /* Eject! */
625 g_drive_eject_with_operation (fav_drive, G_MOUNT_UNMOUNT_FORCE,
626 NULL((void*)0), NULL((void*)0),
627 (GAsyncReadyCallback) do_eject_action_cb,
628 manager);
629 g_object_unref (fav_drive);
630}
631
632static void
633do_touchpad_osd_action (CsdMediaKeysManager *manager, gboolean state)
634{
635 dialog_init (manager);
636 csd_media_keys_window_set_action_custom (CSD_MEDIA_KEYS_WINDOW (manager->priv->dialog)((((CsdMediaKeysWindow*) (void *) g_type_check_instance_cast (
(GTypeInstance*) ((manager->priv->dialog)), ((csd_media_keys_window_get_type
()))))))
,
637 state ? "input-touchpad" : "touchpad-disabled",
638 state ? _("Touchpad enabled")gettext ("Touchpad enabled") : _("Touchpad disabled")gettext ("Touchpad disabled"));
639 dialog_show (manager);
640}
641
642static void
643do_touchpad_action (CsdMediaKeysManager *manager)
644{
645 GSettings *settings = g_settings_new (TOUCHPAD_SCHEMA"org.cafe.peripherals-touchpad");
646 gboolean state = g_settings_get_boolean (settings, TOUCHPAD_ENABLED_KEY"touchpad-enabled");
647
648 if (touchpad_is_present () == FALSE(0)) {
649 do_touchpad_osd_action (manager, FALSE(0));
650 return;
651 }
652
653 do_touchpad_osd_action (manager, !state);
654
655 g_settings_set_boolean (settings, TOUCHPAD_ENABLED_KEY"touchpad-enabled", !state);
656 g_object_unref (settings);
657}
658
659#ifdef HAVE_LIBCAFEMIXER1
660static void
661update_dialog (CsdMediaKeysManager *manager,
662 guint volume,
663 gboolean muted,
664 gboolean sound_changed,
665 gboolean quiet,
666 gboolean is_mic)
667{
668 if (muted)
669 volume = 0.0;
670
671 dialog_init (manager);
672
673 if (is_mic)
674 csd_media_keys_window_set_mic_muted (CSD_MEDIA_KEYS_WINDOW (manager->priv->dialog)((((CsdMediaKeysWindow*) (void *) g_type_check_instance_cast (
(GTypeInstance*) ((manager->priv->dialog)), ((csd_media_keys_window_get_type
()))))))
,
675 muted);
676 else
677 csd_media_keys_window_set_volume_muted (CSD_MEDIA_KEYS_WINDOW (manager->priv->dialog)((((CsdMediaKeysWindow*) (void *) g_type_check_instance_cast (
(GTypeInstance*) ((manager->priv->dialog)), ((csd_media_keys_window_get_type
()))))))
,
678 muted);
679
680 csd_media_keys_window_set_volume_level (CSD_MEDIA_KEYS_WINDOW (manager->priv->dialog)((((CsdMediaKeysWindow*) (void *) g_type_check_instance_cast (
(GTypeInstance*) ((manager->priv->dialog)), ((csd_media_keys_window_get_type
()))))))
,
681 volume);
682
683 csd_media_keys_window_set_action (CSD_MEDIA_KEYS_WINDOW (manager->priv->dialog)((((CsdMediaKeysWindow*) (void *) g_type_check_instance_cast (
(GTypeInstance*) ((manager->priv->dialog)), ((csd_media_keys_window_get_type
()))))))
,
684 CSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME);
685 dialog_show (manager);
686
687#ifdef HAVE_LIBKANBERRA1
688 if (quiet == FALSE(0) && sound_changed != FALSE(0) && muted == FALSE(0) && is_mic == FALSE(0))
689 ka_ctk_play_for_widget (manager->priv->dialog, 0,
690 KA_PROP_EVENT_ID"event.id", "audio-volume-change",
691 KA_PROP_EVENT_DESCRIPTION"event.description", "Volume changed through key press",
692 KA_PROP_APPLICATION_NAME"application.name", PACKAGE_NAME"cafe-settings-daemon",
693 KA_PROP_APPLICATION_VERSION"application.version", PACKAGE_VERSION"1.25.2",
694 KA_PROP_APPLICATION_ID"application.id", "org.cafe.SettingsDaemon",
695 NULL((void*)0));
696#endif
697}
698
699static void
700do_sound_action (CsdMediaKeysManager *manager,
701 int type,
702 gboolean quiet)
703{
704 gboolean muted;
705 gboolean muted_last;
706 gboolean sound_changed = FALSE(0);
707 guint volume;
708 guint volume_min, volume_max;
709 guint volume_step;
710 guint volume_last;
711 CafeMixerStreamControl *control;
712
713 gboolean is_input_control =
714 type == MIC_MUTE_KEY ? TRUE(!(0)) : FALSE(0);
715 if (is_input_control)
716 control = manager->priv->source_control;
717 else
718 control = manager->priv->control;
719 if (control == NULL((void*)0))
720 return;
721
722 /* Theoretically the volume limits might be different for different
723 * streams, also the minimum might not always start at 0 */
724 volume_min = cafe_mixer_stream_control_get_min_volume (control);
725 volume_max = cafe_mixer_stream_control_get_normal_volume (control);
726
727 volume_step = g_settings_get_int (manager->priv->settings, "volume-step");
728 if (volume_step <= 0 || volume_step > 100) {
729 GVariant *variant = g_settings_get_default_value (manager->priv->settings, "volume-step");
730 volume_step = g_variant_get_int32 (variant);
731 g_variant_unref (variant);
732 }
733
734 /* Scale the volume step size accordingly to the range used by the control */
735 volume_step = (volume_max - volume_min) * volume_step / 100;
736
737 volume = volume_last =
738 cafe_mixer_stream_control_get_volume (control);
739 muted = muted_last =
740 cafe_mixer_stream_control_get_mute (control);
741
742 switch (type) {
743 case MUTE_KEY:
744 case MIC_MUTE_KEY:
745 muted = !muted;
746 break;
747 case VOLUME_DOWN_KEY:
748 if (volume <= (volume_min + volume_step)) {
749 volume = volume_min;
750 muted = TRUE(!(0));
751 } else {
752 volume -= volume_step;
753 muted = FALSE(0);
754 }
755 break;
756 case VOLUME_UP_KEY:
757 if (muted) {
758 muted = FALSE(0);
759 if (volume <= volume_min)
760 volume = volume_min + volume_step;
761 } else
762 volume = CLAMP (volume + volume_step,(((volume + volume_step) > (volume_max)) ? (volume_max) : (
((volume + volume_step) < (volume_min)) ? (volume_min) : (
volume + volume_step)))
763 volume_min,(((volume + volume_step) > (volume_max)) ? (volume_max) : (
((volume + volume_step) < (volume_min)) ? (volume_min) : (
volume + volume_step)))
764 volume_max)(((volume + volume_step) > (volume_max)) ? (volume_max) : (
((volume + volume_step) < (volume_min)) ? (volume_min) : (
volume + volume_step)))
;
765 break;
766 }
767
768 if (muted != muted_last) {
769 if (cafe_mixer_stream_control_set_mute (control, muted))
770 sound_changed = TRUE(!(0));
771 else
772 muted = muted_last;
773 }
774
775 if (volume != cafe_mixer_stream_control_get_volume (control)) {
776 if (cafe_mixer_stream_control_set_volume (control, volume))
777 sound_changed = TRUE(!(0));
778 else
779 volume = volume_last;
780 }
781
782 update_dialog (manager,
783 CLAMP (100 * volume / (volume_max - volume_min), 0, 100)(((100 * volume / (volume_max - volume_min)) > (100)) ? (100
) : (((100 * volume / (volume_max - volume_min)) < (0)) ? (
0) : (100 * volume / (volume_max - volume_min))))
,
784 muted,
785 sound_changed,
786 quiet,
787 is_input_control);
788}
789
790static void
791update_default_output (CsdMediaKeysManager *manager)
792{
793 CafeMixerStream *stream;
794 CafeMixerStreamControl *control = NULL((void*)0);
795
796 stream = cafe_mixer_context_get_default_output_stream (manager->priv->context);
797 if (stream != NULL((void*)0))
798 control = cafe_mixer_stream_get_default_control (stream);
799
800 if (stream == manager->priv->stream)
801 return;
802
803 g_clear_object (&manager->priv->stream)do { _Static_assert (sizeof *((&manager->priv->stream
)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(((&manager->priv->stream))) _pp = ((&manager->
priv->stream)); __typeof__ (*((&manager->priv->stream
))) _ptr = *_pp; *_pp = ((void*)0); if (_ptr) (g_object_unref
) (_ptr); } while (0)
;
804 g_clear_object (&manager->priv->control)do { _Static_assert (sizeof *((&manager->priv->control
)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(((&manager->priv->control))) _pp = ((&manager
->priv->control)); __typeof__ (*((&manager->priv
->control))) _ptr = *_pp; *_pp = ((void*)0); if (_ptr) (g_object_unref
) (_ptr); } while (0)
;
805
806 if (control != NULL((void*)0)) {
807 CafeMixerStreamControlFlags flags = cafe_mixer_stream_control_get_flags (control);
808
809 /* Do not use the stream if it is not possible to mute it or
810 * change the volume */
811 if (!(flags & CAFE_MIXER_STREAM_CONTROL_MUTE_WRITABLE) &&
812 !(flags & CAFE_MIXER_STREAM_CONTROL_VOLUME_WRITABLE))
813 return;
814
815 manager->priv->stream = g_object_ref (stream)((__typeof__ (stream)) (g_object_ref) (stream));
816 manager->priv->control = g_object_ref (control)((__typeof__ (control)) (g_object_ref) (control));
817 g_debug ("Default output stream updated to %s",
818 cafe_mixer_stream_get_name (stream));
819 } else
820 g_debug ("Default output stream unset");
821}
822
823static void
824update_default_input (CsdMediaKeysManager *manager)
825{
826 CafeMixerStream *stream;
827 CafeMixerStreamControl *control = NULL((void*)0);
828
829 stream = cafe_mixer_context_get_default_input_stream (manager->priv->context);
830 if (stream != NULL((void*)0))
831 control = cafe_mixer_stream_get_default_control (stream);
832
833 if (stream == manager->priv->source_stream)
834 return;
835
836 g_clear_object (&manager->priv->source_stream)do { _Static_assert (sizeof *((&manager->priv->source_stream
)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(((&manager->priv->source_stream))) _pp = ((&manager
->priv->source_stream)); __typeof__ (*((&manager->
priv->source_stream))) _ptr = *_pp; *_pp = ((void*)0); if (
_ptr) (g_object_unref) (_ptr); } while (0)
;
837 g_clear_object (&manager->priv->source_control)do { _Static_assert (sizeof *((&manager->priv->source_control
)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(((&manager->priv->source_control))) _pp = ((&
manager->priv->source_control)); __typeof__ (*((&manager
->priv->source_control))) _ptr = *_pp; *_pp = ((void*)0
); if (_ptr) (g_object_unref) (_ptr); } while (0)
;
838
839 if (control != NULL((void*)0)) {
840 CafeMixerStreamControlFlags flags = cafe_mixer_stream_control_get_flags (control);
841
842 /* Do not use the stream if it is not possible to mute it or
843 * change the volume */
844 if (!(flags & CAFE_MIXER_STREAM_CONTROL_MUTE_WRITABLE))
845 return;
846
847 manager->priv->source_stream = g_object_ref (stream)((__typeof__ (stream)) (g_object_ref) (stream));
848 manager->priv->source_control = g_object_ref (control)((__typeof__ (control)) (g_object_ref) (control));
849 g_debug ("Default input stream updated to %s",
850 cafe_mixer_stream_get_name (stream));
851 } else
852 g_debug ("Default input stream unset");
853}
854
855static void
856on_context_state_notify (CafeMixerContext *context,
857 GParamSpec *pspec,
858 CsdMediaKeysManager *manager)
859{
860 update_default_output (manager);
861 update_default_input (manager);
862}
863
864static void
865on_context_default_output_notify (CafeMixerContext *context,
866 GParamSpec *pspec,
867 CsdMediaKeysManager *manager)
868{
869 update_default_output (manager);
870}
871
872static void
873on_context_default_input_notify (CafeMixerContext *context,
874 GParamSpec *pspec,
875 CsdMediaKeysManager *manager)
876{
877 update_default_input (manager);
878}
879
880static void
881on_context_stream_removed (CafeMixerContext *context,
882 const gchar *name,
883 CsdMediaKeysManager *manager)
884{
885 if (manager->priv->stream != NULL((void*)0)) {
886 CafeMixerStream *stream =
887 cafe_mixer_context_get_stream (manager->priv->context, name);
888
889 if (stream == manager->priv->stream) {
890 g_clear_object (&manager->priv->stream)do { _Static_assert (sizeof *((&manager->priv->stream
)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(((&manager->priv->stream))) _pp = ((&manager->
priv->stream)); __typeof__ (*((&manager->priv->stream
))) _ptr = *_pp; *_pp = ((void*)0); if (_ptr) (g_object_unref
) (_ptr); } while (0)
;
891 g_clear_object (&manager->priv->control)do { _Static_assert (sizeof *((&manager->priv->control
)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(((&manager->priv->control))) _pp = ((&manager
->priv->control)); __typeof__ (*((&manager->priv
->control))) _ptr = *_pp; *_pp = ((void*)0); if (_ptr) (g_object_unref
) (_ptr); } while (0)
;
892 }
893 }
894 if (manager->priv->source_stream != NULL((void*)0)) {
895 CafeMixerStream *stream =
896 cafe_mixer_context_get_stream (manager->priv->context, name);
897
898 if (stream == manager->priv->source_stream) {
899 g_clear_object (&manager->priv->source_stream)do { _Static_assert (sizeof *((&manager->priv->source_stream
)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(((&manager->priv->source_stream))) _pp = ((&manager
->priv->source_stream)); __typeof__ (*((&manager->
priv->source_stream))) _ptr = *_pp; *_pp = ((void*)0); if (
_ptr) (g_object_unref) (_ptr); } while (0)
;
900 g_clear_object (&manager->priv->source_control)do { _Static_assert (sizeof *((&manager->priv->source_control
)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(((&manager->priv->source_control))) _pp = ((&
manager->priv->source_control)); __typeof__ (*((&manager
->priv->source_control))) _ptr = *_pp; *_pp = ((void*)0
); if (_ptr) (g_object_unref) (_ptr); } while (0)
;
901 }
902 }
903}
904#endif /* HAVE_LIBCAFEMIXER */
905
906static gboolean
907get_rfkill_property (CsdMediaKeysManager *manager,
908 const char *property)
909{
910 GVariant *v;
911 gboolean ret;
912
913 v = g_dbus_proxy_get_cached_property (manager->priv->rfkill_proxy, property);
914 if (!v)
915 return FALSE(0);
916 ret = g_variant_get_boolean (v);
917 g_variant_unref (v);
918
919 return ret;
920}
921
922typedef struct {
923 CsdMediaKeysManager *manager;
924 char *property;
925 gboolean bluetooth;
926 gboolean target_state;
927} RfkillData;
928
929static void
930set_rfkill_complete (GObject *object,
931 GAsyncResult *result,
932 gpointer user_data)
933{
934 GError *error = NULL((void*)0);
935 GVariant *variant;
936 RfkillData *data = user_data;
937
938 variant = g_dbus_proxy_call_finish (G_DBUS_PROXY (object)((((GDBusProxy*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((object)), ((g_dbus_proxy_get_type ()))))))
, result, &error);
939
940 if (variant == NULL((void*)0)) {
941 if (!g_error_matches (error, G_IO_ERRORg_io_error_quark(), G_IO_ERROR_CANCELLED))
942 g_warning ("Failed to set '%s' property: %s", data->property, error->message);
943 g_error_free (error);
944 goto out;
945 }
946 g_variant_unref (variant);
947
948 g_debug ("Finished changing rfkill, property %s is now %s",
949 data->property, data->target_state ? "true" : "false");
950
951 if (data->bluetooth){
952 if (data->target_state)
953 csd_media_keys_window_set_action_custom (CSD_MEDIA_KEYS_WINDOW (data->manager->priv->dialog)((((CsdMediaKeysWindow*) (void *) g_type_check_instance_cast (
(GTypeInstance*) ((data->manager->priv->dialog)), ((
csd_media_keys_window_get_type ()))))))
,
954 "bluetooth-disabled-symbolic", _("Bluetooth disabled")gettext ("Bluetooth disabled"));
955 else
956 csd_media_keys_window_set_action_custom (CSD_MEDIA_KEYS_WINDOW (data->manager->priv->dialog)((((CsdMediaKeysWindow*) (void *) g_type_check_instance_cast (
(GTypeInstance*) ((data->manager->priv->dialog)), ((
csd_media_keys_window_get_type ()))))))
,
957 "bluetooth-active-symbolic", _("Bluetooth enabled")gettext ("Bluetooth enabled"));
958 } else {
959 if (data->target_state)
960 csd_media_keys_window_set_action_custom (CSD_MEDIA_KEYS_WINDOW (data->manager->priv->dialog)((((CsdMediaKeysWindow*) (void *) g_type_check_instance_cast (
(GTypeInstance*) ((data->manager->priv->dialog)), ((
csd_media_keys_window_get_type ()))))))
,
961 "airplane-mode-symbolic", _("Airplane mode enabled")gettext ("Airplane mode enabled"));
962 else
963 csd_media_keys_window_set_action_custom (CSD_MEDIA_KEYS_WINDOW (data->manager->priv->dialog)((((CsdMediaKeysWindow*) (void *) g_type_check_instance_cast (
(GTypeInstance*) ((data->manager->priv->dialog)), ((
csd_media_keys_window_get_type ()))))))
,
964 "network-wireless-signal-excellent-symbolic", _("Airplane mode disabled")gettext ("Airplane mode disabled"));
965 }
966 dialog_show (data->manager);
967out:
968 g_free (data->property);
969 g_free (data);
970}
971
972static void
973do_rfkill_action (CsdMediaKeysManager *manager,
974 gboolean bluetooth)
975{
976 const char *has_mode, *hw_mode, *mode;
977 gboolean new_state;
978 RfkillData *data;
979
980 dialog_init (manager);
981
982 has_mode = bluetooth ? "BluetoothHasAirplaneMode" : "HasAirplaneMode";
983 hw_mode = bluetooth ? "BluetoothHardwareAirplaneMode" : "HardwareAirplaneMode";
984 mode = bluetooth ? "BluetoothAirplaneMode" : "AirplaneMode";
985
986 if (manager->priv->rfkill_proxy == NULL((void*)0))
987 return;
988
989 if (get_rfkill_property (manager, has_mode) == FALSE(0))
990 return;
991
992 if (get_rfkill_property (manager, hw_mode)) {
993 csd_media_keys_window_set_action_custom (CSD_MEDIA_KEYS_WINDOW (manager->priv->dialog)((((CsdMediaKeysWindow*) (void *) g_type_check_instance_cast (
(GTypeInstance*) ((manager->priv->dialog)), ((csd_media_keys_window_get_type
()))))))
,
994 "airplane-mode-symbolic",
995 _("Hardware Airplane Mode")gettext ("Hardware Airplane Mode"));
996 dialog_show (manager);
997 return;
998 }
999
1000 new_state = !get_rfkill_property (manager, mode);
1001 data = g_new0 (RfkillData, 1)((RfkillData *) g_malloc0_n ((1), sizeof (RfkillData)));
1002 data->manager = manager;
1003 data->property = g_strdup (mode)g_strdup_inline (mode);
1004 data->bluetooth = bluetooth;
1005 data->target_state = new_state;
1006 g_dbus_proxy_call (manager->priv->rfkill_proxy,
1007 "org.freedesktop.DBus.Properties.Set",
1008 g_variant_new ("(ssv)",
1009 "org.cafe.SettingsDaemon.Rfkill",
1010 data->property,
1011 g_variant_new_boolean (new_state)),
1012 G_DBUS_CALL_FLAGS_NONE, -1,
1013 manager->priv->rfkill_cancellable,
1014 set_rfkill_complete, data);
1015
1016 g_debug ("Setting rfkill property %s to %s",
1017 data->property, new_state ? "true" : "false");
1018}
1019
1020static void
1021do_display_osd_action (CsdMediaKeysManager *manager)
1022{
1023 CdkDisplay *display;
1024 int n_monitors;
1025
1026 display = cdk_display_get_default ();
1027 n_monitors = cdk_display_get_n_monitors (display);
1028
1029 dialog_init (manager);
1030 if (n_monitors > 1)
1031 csd_media_keys_window_set_action_custom (CSD_MEDIA_KEYS_WINDOW (manager->priv->dialog)((((CsdMediaKeysWindow*) (void *) g_type_check_instance_cast (
(GTypeInstance*) ((manager->priv->dialog)), ((csd_media_keys_window_get_type
()))))))
,
1032 "video-joined-displays-symbolic",
1033 _("Changing Screen Layout")gettext ("Changing Screen Layout"));
1034 else
1035 csd_media_keys_window_set_action_custom (CSD_MEDIA_KEYS_WINDOW (manager->priv->dialog)((((CsdMediaKeysWindow*) (void *) g_type_check_instance_cast (
(GTypeInstance*) ((manager->priv->dialog)), ((csd_media_keys_window_get_type
()))))))
,
1036 "video-single-display-symbolic",
1037 _("No External Display")gettext ("No External Display"));
1038 dialog_show (manager);
1039}
1040
1041static gint
1042find_by_application (gconstpointer a,
1043 gconstpointer b)
1044{
1045 return strcmp (((MediaPlayer *)a)->application, b);
1046}
1047
1048static gint
1049find_by_time (gconstpointer a,
1050 gconstpointer b)
1051{
1052 return ((MediaPlayer *)a)->time < ((MediaPlayer *)b)->time;
1053}
1054
1055/*
1056 * Register a new media player. Most applications will want to call
1057 * this with time = CDK_CURRENT_TIME. This way, the last registered
1058 * player will receive media events. In some cases, applications
1059 * may want to register with a lower priority (usually 1), to grab
1060 * events only nobody is interested.
1061 */
1062gboolean
1063csd_media_keys_manager_grab_media_player_keys (CsdMediaKeysManager *manager,
1064 const char *application,
1065 guint32 time,
1066 GError **error)
1067{
1068 GList *iter;
1069 MediaPlayer *media_player;
1070
1071 if (time == CDK_CURRENT_TIME0L) {
1072 GTimeVal tv;
1073
1074 g_get_current_time (&tv);
1075 time = tv.tv_sec * 1000 + tv.tv_usec / 1000;
1076 }
1077
1078 iter = g_list_find_custom (manager->priv->media_players,
1079 application,
1080 find_by_application);
1081
1082 if (iter != NULL((void*)0)) {
1083 if (((MediaPlayer *)iter->data)->time < time) {
1084 g_free (((MediaPlayer *)iter->data)->application);
1085 g_free (iter->data);
1086 manager->priv->media_players = g_list_delete_link (manager->priv->media_players, iter);
1087 } else {
1088 return TRUE(!(0));
1089 }
1090 }
1091
1092 g_debug ("Registering %s at %u", application, time);
1093 media_player = g_new0 (MediaPlayer, 1)((MediaPlayer *) g_malloc0_n ((1), sizeof (MediaPlayer)));
1094 media_player->application = g_strdup (application)g_strdup_inline (application);
1095 media_player->time = time;
1096
1097 manager->priv->media_players = g_list_insert_sorted (manager->priv->media_players,
1098 media_player,
1099 find_by_time);
1100
1101 return TRUE(!(0));
1102}
1103
1104gboolean
1105csd_media_keys_manager_release_media_player_keys (CsdMediaKeysManager *manager,
1106 const char *application,
1107 GError **error)
1108{
1109 GList *iter;
1110
1111 iter = g_list_find_custom (manager->priv->media_players,
1112 application,
1113 find_by_application);
1114
1115 if (iter != NULL((void*)0)) {
1116 g_debug ("Deregistering %s", application);
1117 g_free (((MediaPlayer *)iter->data)->application);
1118 g_free (iter->data);
1119 manager->priv->media_players = g_list_delete_link (manager->priv->media_players, iter);
1120 }
1121
1122 return TRUE(!(0));
1123}
1124
1125static gboolean
1126csd_media_player_key_pressed (CsdMediaKeysManager *manager,
1127 const char *key)
1128{
1129 const char *application = NULL((void*)0);
1130 gboolean have_listeners;
1131
1132 have_listeners = (manager->priv->media_players != NULL((void*)0));
1133
1134 if (have_listeners) {
1135 application = ((MediaPlayer *)manager->priv->media_players->data)->application;
1136 }
1137
1138 g_signal_emit (manager, signals[MEDIA_PLAYER_KEY_PRESSED], 0, application, key);
1139
1140 return !have_listeners;
1141}
1142
1143static gboolean
1144do_multimedia_player_action (CsdMediaKeysManager *manager,
1145 const char *key)
1146{
1147 return csd_media_player_key_pressed (manager, key);
1148}
1149
1150static void
1151do_toggle_accessibility_key (const char *key)
1152{
1153 GSettings *settings;
1154 gboolean state;
1155
1156 settings = g_settings_new ("org.gnome.desktop.a11y.applications");
1157 state = g_settings_get_boolean (settings, key);
1158 g_settings_set_boolean (settings, key, !state);
1159 g_object_unref (settings);
1160}
1161
1162static void
1163do_magnifier_action (CsdMediaKeysManager *manager)
1164{
1165 do_toggle_accessibility_key ("screen-magnifier-enabled");
1166}
1167
1168static void
1169do_screenreader_action (CsdMediaKeysManager *manager)
1170{
1171 do_toggle_accessibility_key ("screen-reader-enabled");
1172}
1173
1174static void
1175do_on_screen_keyboard_action (CsdMediaKeysManager *manager)
1176{
1177 do_toggle_accessibility_key ("screen-keyboard-enabled");
1178}
1179
1180static gboolean
1181do_action (CsdMediaKeysManager *manager,
1182 int type)
1183{
1184 char *cmd;
1185 char *path;
1186
1187 switch (type) {
1188 case TOUCHPAD_KEY:
1189 do_touchpad_action (manager);
1190 break;
1191 case TOUCHPAD_ON_KEY:
1192 do_touchpad_osd_action(manager, TRUE(!(0)));
1193 break;
1194 case TOUCHPAD_OFF_KEY:
1195 do_touchpad_osd_action(manager, FALSE(0));
1196 break;
1197 case MUTE_KEY:
1198 case VOLUME_DOWN_KEY:
1199 case VOLUME_UP_KEY:
1200 case MIC_MUTE_KEY:
1201#ifdef HAVE_LIBCAFEMIXER1
1202 do_sound_action (manager, type, FALSE(0));
1203#endif
1204 break;
1205 case MUTE_QUIET_KEY:
1206#ifdef HAVE_LIBCAFEMIXER1
1207 do_sound_action (manager, MUTE_KEY, TRUE(!(0)));
1208#endif
1209 break;
1210 case VOLUME_DOWN_QUIET_KEY:
1211#ifdef HAVE_LIBCAFEMIXER1
1212 do_sound_action (manager, VOLUME_DOWN_KEY, TRUE(!(0)));
1213#endif
1214 break;
1215 case VOLUME_UP_QUIET_KEY:
1216#ifdef HAVE_LIBCAFEMIXER1
1217 do_sound_action (manager, VOLUME_UP_KEY, TRUE(!(0)));
1218#endif
1219 break;
1220 case POWER_KEY:
1221 do_shutdown_action (manager);
1222 break;
1223 case LOGOUT_KEY:
1224 do_logout_action (manager);
1225 break;
1226 case EJECT_KEY:
1227 do_eject_action (manager);
1228 break;
1229 case HOME_KEY:
1230 path = g_shell_quote (g_get_home_dir ());
1231 cmd = g_strconcat ("baul --no-desktop ", path, NULL((void*)0));
1232 g_free (path);
1233 execute (manager, cmd, FALSE(0), FALSE(0));
1234 g_free (cmd);
1235 break;
1236 case SEARCH_KEY:
1237 cmd = NULL((void*)0);
1238 if ((cmd = g_find_program_in_path ("beagle-search"))) {
1239 execute (manager, "beagle-search", FALSE(0), FALSE(0));
1240 } else if ((cmd = g_find_program_in_path ("tracker-search-tool"))) {
1241 execute (manager, "tracker-search-tool", FALSE(0), FALSE(0));
1242 } else {
1243 execute (manager, "cafe-search-tool", FALSE(0), FALSE(0));
1244 }
1245 g_free (cmd);
1246 break;
1247 case EMAIL_KEY:
1248 do_url_action (manager, "mailto");
1249 break;
1250 case CONTROL_CENTER_KEY:
1251 if ((cmd = g_find_program_in_path ("cafe-control-center")))
1252 execute (manager, "cafe-control-center", FALSE(0), FALSE(0));
1253
1254 g_free (cmd);
1255 break;
1256 case SCREENSAVER_KEY:
1257 if ((cmd = g_find_program_in_path ("cafe-screensaver-command"))) {
1258 execute (manager, "cafe-screensaver-command --lock", FALSE(0), FALSE(0));
1259 } else {
1260 execute (manager, "xscreensaver-command -lock", FALSE(0), FALSE(0));
1261 }
1262
1263 g_free (cmd);
1264 break;
1265 case HELP_KEY:
1266 do_url_action (manager, "help");
1267 break;
1268 case WWW_KEY:
1269 do_url_action (manager, "http");
1270 break;
1271 case MEDIA_KEY:
1272 do_media_action (manager);
1273 break;
1274 case CALCULATOR_KEY:
1275 do_calculator_action (manager);
1276 break;
1277 case MESSENGER_KEY:
1278 do_messenger_action (manager);
1279 break;
1280 case PLAY_KEY:
1281 return do_multimedia_player_action (manager, "Play");
1282 case PAUSE_KEY:
1283 return do_multimedia_player_action (manager, "Pause");
1284 case STOP_KEY:
1285 return do_multimedia_player_action (manager, "Stop");
1286 case PREVIOUS_KEY:
1287 return do_multimedia_player_action (manager, "Previous");
1288 case NEXT_KEY:
1289 return do_multimedia_player_action (manager, "Next");
1290 case REWIND_KEY:
1291 return do_multimedia_player_action (manager, "Rewind");
1292 case FORWARD_KEY:
1293 return do_multimedia_player_action (manager, "FastForward");
1294 case REPEAT_KEY:
1295 return do_multimedia_player_action (manager, "Repeat");
1296 case RANDOM_KEY:
1297 return do_multimedia_player_action (manager, "Shuffle");
1298 case MAGNIFIER_KEY:
1299 do_magnifier_action (manager);
1300 break;
1301 case SCREENREADER_KEY:
1302 do_screenreader_action (manager);
1303 break;
1304 case ON_SCREEN_KEYBOARD_KEY:
1305 do_on_screen_keyboard_action (manager);
1306 break;
1307 case RFKILL_KEY:
1308 do_rfkill_action (manager, FALSE(0));
1309 break;
1310 case BLUETOOTH_RFKILL_KEY:
1311 do_rfkill_action (manager, TRUE(!(0)));
1312 break;
1313 case DISPLAY_KEY:
1314 do_display_osd_action (manager);
1315 break;
1316 default:
1317 g_assert_not_reached ()do { g_assertion_message_expr (((gchar*) 0), "csd_media-keys-manager.c"
, 1317, ((const char*) (__func__)), ((void*)0)); } while (0)
;
1318 }
1319
1320 return FALSE(0);
1321}
1322
1323static CdkScreen *
1324acme_get_screen_from_event (CsdMediaKeysManager *manager,
1325 XAnyEvent *xanyev)
1326{
1327 CdkWindow *window;
1328 CdkScreen *screen;
1329 GSList *l;
1330
1331 /* Look for which screen we're receiving events */
1332 for (l = manager->priv->screens; l != NULL((void*)0); l = l->next) {
1333 screen = (CdkScreen *) l->data;
1334 window = cdk_screen_get_root_window (screen);
1335
1336 if (CDK_WINDOW_XID (window)(cdk_x11_window_get_xid (window)) == xanyev->window) {
1337 return screen;
1338 }
1339 }
1340
1341 return NULL((void*)0);
1342}
1343
1344static CdkFilterReturn
1345acme_filter_events (CdkXEvent *xevent,
1346 CdkEvent *event,
1347 CsdMediaKeysManager *manager)
1348{
1349 XEvent *xev = (XEvent *) xevent;
1350 XAnyEvent *xany = (XAnyEvent *) xevent;
1351 int i;
1352
1353 /* verify we have a key event */
1354 if (xev->type != KeyPress2) {
1355 return CDK_FILTER_CONTINUE;
1356 }
1357
1358 for (i = 0; i < HANDLED_KEYS; i++) {
1359 if (match_key (keys[i].key, xev)) {
1360 switch (keys[i].key_type) {
1361 case VOLUME_DOWN_KEY:
1362 case VOLUME_UP_KEY:
1363 case VOLUME_DOWN_QUIET_KEY:
1364 case VOLUME_UP_QUIET_KEY:
1365 /* auto-repeatable keys */
1366 if (xev->type != KeyPress2) {
1367 return CDK_FILTER_CONTINUE;
1368 }
1369 break;
1370 }
1371
1372 manager->priv->current_screen = acme_get_screen_from_event (manager, xany);
1373
1374 if (do_action (manager, keys[i].key_type) == FALSE(0)) {
1375 return CDK_FILTER_REMOVE;
1376 } else {
1377 return CDK_FILTER_CONTINUE;
1378 }
1379 }
1380 }
1381
1382 return CDK_FILTER_CONTINUE;
1383}
1384
1385static void
1386on_rfkill_proxy_ready (GObject *source,
1387 GAsyncResult *result,
1388 gpointer data)
1389{
1390 CsdMediaKeysManager *manager = data;
1391
1392 manager->priv->rfkill_proxy =
1393 g_dbus_proxy_new_for_bus_finish (result, NULL((void*)0));
1394}
1395
1396static void
1397rfkill_appeared_cb (GDBusConnection *connection,
1398 const gchar *name,
1399 const gchar *name_owner,
1400 gpointer user_data)
1401{
1402 CsdMediaKeysManager *manager = user_data;
1403
1404 g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
1405 0, NULL((void*)0),
1406 "org.cafe.SettingsDaemon.Rfkill",
1407 "/org/cafe/SettingsDaemon/Rfkill",
1408 "org.cafe.SettingsDaemon.Rfkill",
1409 manager->priv->rfkill_cancellable,
1410 on_rfkill_proxy_ready, manager);
1411}
1412
1413static gboolean
1414start_media_keys_idle_cb (CsdMediaKeysManager *manager)
1415{
1416 GSList *l;
1417 CdkDisplay *dpy;
1418 Display *xdpy;
1419
1420 g_debug ("Starting media_keys manager");
1421 cafe_settings_profile_start (NULL);
1422
1423 dpy = cdk_display_get_default ();
1424 xdpy = CDK_DISPLAY_XDISPLAY (dpy)(cdk_x11_display_get_xdisplay (dpy));
1425
1426 manager->priv->volume_monitor = g_volume_monitor_get ();
1427 manager->priv->settings = g_settings_new (BINDING_SCHEMA"org.cafe.SettingsDaemon.plugins.media-keys");
1428
1429 ensure_cancellable (&manager->priv->rfkill_cancellable);
1430
1431 init_screens (manager);
1432 init_kbd (manager);
1433
1434 /* Start filtering the events */
1435 for (l = manager->priv->screens; l != NULL((void*)0); l = l->next) {
1436 CdkWindow *window;
1437 Window xwindow;
1438 XWindowAttributes atts;
1439
1440 cafe_settings_profile_start ("cdk_window_add_filter");
1441
1442 window = cdk_screen_get_root_window (l->data);
1443 xwindow = CDK_WINDOW_XID (window)(cdk_x11_window_get_xid (window));
1444
1445 g_debug ("adding key filter for screen: %d",
1446 cdk_x11_screen_get_screen_number (l->data));
1447
1448 cdk_window_add_filter (window,
1449 (CdkFilterFunc)acme_filter_events,
1450 manager);
1451
1452 cdk_x11_display_error_trap_push (dpy);
1453 /* Add KeyPressMask to the currently reportable event masks */
1454 XGetWindowAttributes (xdpy, xwindow, &atts);
1455 XSelectInput (xdpy, xwindow, atts.your_event_mask | KeyPressMask(1L<<0));
1456 cdk_x11_display_error_trap_pop_ignored (dpy);
1457
1458 cafe_settings_profile_end ("cdk_window_add_filter");
1459 }
1460
1461 manager->priv->rfkill_watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
1462 "org.cafe.SettingsDaemon.Rfkill",
1463 G_BUS_NAME_WATCHER_FLAGS_NONE,
1464 rfkill_appeared_cb,
1465 NULL((void*)0),
1466 manager, NULL((void*)0));
1467
1468 cafe_settings_profile_end (NULL);
1469
1470 return FALSE(0);
1471}
1472
1473gboolean
1474csd_media_keys_manager_start (CsdMediaKeysManager *manager, GError **error)
1475{
1476 cafe_settings_profile_start (NULL);
1477
1478#ifdef HAVE_LIBCAFEMIXER1
1479 if (G_LIKELY (cafe_mixer_is_initialized ())(cafe_mixer_is_initialized ())) {
1480 cafe_settings_profile_start ("cafe_mixer_context_new");
1481
1482 manager->priv->context = cafe_mixer_context_new ();
1483
1484 g_signal_connect (manager->priv->context,g_signal_connect_data ((manager->priv->context), ("notify::state"
), (((GCallback) (on_context_state_notify))), (manager), ((void
*)0), (GConnectFlags) 0)
1485 "notify::state",g_signal_connect_data ((manager->priv->context), ("notify::state"
), (((GCallback) (on_context_state_notify))), (manager), ((void
*)0), (GConnectFlags) 0)
1486 G_CALLBACK (on_context_state_notify),g_signal_connect_data ((manager->priv->context), ("notify::state"
), (((GCallback) (on_context_state_notify))), (manager), ((void
*)0), (GConnectFlags) 0)
1487 manager)g_signal_connect_data ((manager->priv->context), ("notify::state"
), (((GCallback) (on_context_state_notify))), (manager), ((void
*)0), (GConnectFlags) 0)
;
1488 g_signal_connect (manager->priv->context,g_signal_connect_data ((manager->priv->context), ("notify::default-output-stream"
), (((GCallback) (on_context_default_output_notify))), (manager
), ((void*)0), (GConnectFlags) 0)
1489 "notify::default-output-stream",g_signal_connect_data ((manager->priv->context), ("notify::default-output-stream"
), (((GCallback) (on_context_default_output_notify))), (manager
), ((void*)0), (GConnectFlags) 0)
1490 G_CALLBACK (on_context_default_output_notify),g_signal_connect_data ((manager->priv->context), ("notify::default-output-stream"
), (((GCallback) (on_context_default_output_notify))), (manager
), ((void*)0), (GConnectFlags) 0)
1491 manager)g_signal_connect_data ((manager->priv->context), ("notify::default-output-stream"
), (((GCallback) (on_context_default_output_notify))), (manager
), ((void*)0), (GConnectFlags) 0)
;
1492 g_signal_connect (manager->priv->context,g_signal_connect_data ((manager->priv->context), ("notify::default-input-stream"
), (((GCallback) (on_context_default_input_notify))), (manager
), ((void*)0), (GConnectFlags) 0)
1493 "notify::default-input-stream",g_signal_connect_data ((manager->priv->context), ("notify::default-input-stream"
), (((GCallback) (on_context_default_input_notify))), (manager
), ((void*)0), (GConnectFlags) 0)
1494 G_CALLBACK (on_context_default_input_notify),g_signal_connect_data ((manager->priv->context), ("notify::default-input-stream"
), (((GCallback) (on_context_default_input_notify))), (manager
), ((void*)0), (GConnectFlags) 0)
1495 manager)g_signal_connect_data ((manager->priv->context), ("notify::default-input-stream"
), (((GCallback) (on_context_default_input_notify))), (manager
), ((void*)0), (GConnectFlags) 0)
;
1496 g_signal_connect (manager->priv->context,g_signal_connect_data ((manager->priv->context), ("stream-removed"
), (((GCallback) (on_context_stream_removed))), (manager), ((
void*)0), (GConnectFlags) 0)
1497 "stream-removed",g_signal_connect_data ((manager->priv->context), ("stream-removed"
), (((GCallback) (on_context_stream_removed))), (manager), ((
void*)0), (GConnectFlags) 0)
1498 G_CALLBACK (on_context_stream_removed),g_signal_connect_data ((manager->priv->context), ("stream-removed"
), (((GCallback) (on_context_stream_removed))), (manager), ((
void*)0), (GConnectFlags) 0)
1499 manager)g_signal_connect_data ((manager->priv->context), ("stream-removed"
), (((GCallback) (on_context_stream_removed))), (manager), ((
void*)0), (GConnectFlags) 0)
;
1500
1501 cafe_mixer_context_open (manager->priv->context);
1502
1503 cafe_settings_profile_end ("cafe_mixer_context_new");
1504 }
1505#endif
1506 g_idle_add ((GSourceFunc) start_media_keys_idle_cb, manager);
1507
1508 cafe_settings_profile_end (NULL);
1509
1510 return TRUE(!(0));
1511}
1512
1513void
1514csd_media_keys_manager_stop (CsdMediaKeysManager *manager)
1515{
1516 CsdMediaKeysManagerPrivate *priv = manager->priv;
1517 CdkDisplay *dpy;
1518 GSList *ls;
1519 GList *l;
1520 int i;
1521 gboolean need_flush;
1522
1523 g_debug ("Stopping media_keys manager");
1524
1525 for (ls = priv->screens; ls != NULL((void*)0); ls = ls->next) {
1526 cdk_window_remove_filter (cdk_screen_get_root_window (ls->data),
1527 (CdkFilterFunc) acme_filter_events,
1528 manager);
1529 }
1530
1531 if (manager->priv->rfkill_watch_id > 0) {
1532 g_bus_unwatch_name (manager->priv->rfkill_watch_id);
1533 manager->priv->rfkill_watch_id = 0;
1534 }
1535
1536 if (priv->settings != NULL((void*)0)) {
1537 g_object_unref (priv->settings);
1538 priv->settings = NULL((void*)0);
1539 }
1540
1541 if (priv->volume_monitor != NULL((void*)0)) {
1542 g_object_unref (priv->volume_monitor);
1543 priv->volume_monitor = NULL((void*)0);
1544 }
1545
1546 if (priv->connection != NULL((void*)0)) {
1547 dbus_g_connection_unref (priv->connection);
1548 priv->connection = NULL((void*)0);
1549 }
1550
1551 need_flush = FALSE(0);
1552 dpy = cdk_display_get_default ();
1553 cdk_x11_display_error_trap_push (dpy);
1554
1555 for (i = 0; i < HANDLED_KEYS; ++i) {
1556 if (keys[i].key) {
1557 need_flush = TRUE(!(0));
1558 grab_key_unsafe (keys[i].key, FALSE(0), priv->screens);
1559
1560 g_free (keys[i].key->keycodes);
1561 g_free (keys[i].key);
1562 keys[i].key = NULL((void*)0);
1563 }
1564 }
1565
1566 if (need_flush)
1567 cdk_display_flush (dpy);
1568
1569 cdk_x11_display_error_trap_pop_ignored (dpy);
1570
1571 g_slist_free (priv->screens);
1572 priv->screens = NULL((void*)0);
1573
1574 if (priv->rfkill_cancellable != NULL((void*)0)) {
1575 g_cancellable_cancel (priv->rfkill_cancellable);
1576 g_clear_object (&priv->rfkill_cancellable)do { _Static_assert (sizeof *((&priv->rfkill_cancellable
)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(((&priv->rfkill_cancellable))) _pp = ((&priv->
rfkill_cancellable)); __typeof__ (*((&priv->rfkill_cancellable
))) _ptr = *_pp; *_pp = ((void*)0); if (_ptr) (g_object_unref
) (_ptr); } while (0)
;
1577 }
1578
1579#ifdef HAVE_LIBCAFEMIXER1
1580 g_clear_object (&priv->stream)do { _Static_assert (sizeof *((&priv->stream)) == sizeof
(gpointer), "Expression evaluates to false"); __typeof__ (((
&priv->stream))) _pp = ((&priv->stream)); __typeof__
(*((&priv->stream))) _ptr = *_pp; *_pp = ((void*)0); if
(_ptr) (g_object_unref) (_ptr); } while (0)
;
1581 g_clear_object (&priv->source_stream)do { _Static_assert (sizeof *((&priv->source_stream)) ==
sizeof (gpointer), "Expression evaluates to false"); __typeof__
(((&priv->source_stream))) _pp = ((&priv->source_stream
)); __typeof__ (*((&priv->source_stream))) _ptr = *_pp
; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while
(0)
;
1582 g_clear_object (&priv->control)do { _Static_assert (sizeof *((&priv->control)) == sizeof
(gpointer), "Expression evaluates to false"); __typeof__ (((
&priv->control))) _pp = ((&priv->control)); __typeof__
(*((&priv->control))) _ptr = *_pp; *_pp = ((void*)0);
if (_ptr) (g_object_unref) (_ptr); } while (0)
;
1583 g_clear_object (&priv->source_control)do { _Static_assert (sizeof *((&priv->source_control))
== sizeof (gpointer), "Expression evaluates to false"); __typeof__
(((&priv->source_control))) _pp = ((&priv->source_control
)); __typeof__ (*((&priv->source_control))) _ptr = *_pp
; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while
(0)
;
1584 g_clear_object (&priv->context)do { _Static_assert (sizeof *((&priv->context)) == sizeof
(gpointer), "Expression evaluates to false"); __typeof__ (((
&priv->context))) _pp = ((&priv->context)); __typeof__
(*((&priv->context))) _ptr = *_pp; *_pp = ((void*)0);
if (_ptr) (g_object_unref) (_ptr); } while (0)
;
1585#endif
1586
1587 if (priv->dialog != NULL((void*)0)) {
1588 ctk_widget_destroy (priv->dialog);
1589 priv->dialog = NULL((void*)0);
1590 }
1591
1592 for (l = priv->media_players; l; l = l->next) {
1593 MediaPlayer *mp = l->data;
1594 g_free (mp->application);
1595 g_free (mp);
1596 }
1597 g_list_free (priv->media_players);
1598 priv->media_players = NULL((void*)0);
1599}
1600
1601static void
1602csd_media_keys_manager_class_init (CsdMediaKeysManagerClass *klass)
1603{
1604 signals[MEDIA_PLAYER_KEY_PRESSED] =
1605 g_signal_new ("media-player-key-pressed",
1606 G_OBJECT_CLASS_TYPE (klass)((((GTypeClass*) (klass))->g_type)),
1607 G_SIGNAL_RUN_LAST,
1608 G_STRUCT_OFFSET (CsdMediaKeysManagerClass, media_player_key_pressed)((glong) __builtin_offsetof(CsdMediaKeysManagerClass, media_player_key_pressed
))
,
1609 NULL((void*)0),
1610 NULL((void*)0),
1611 csd_marshal_VOID__STRING_STRING,
1612 G_TYPE_NONE((GType) ((1) << (2))),
1613 2,
1614 G_TYPE_STRING((GType) ((16) << (2))),
1615 G_TYPE_STRING((GType) ((16) << (2))));
1616
1617 dbus_g_object_type_install_info (CSD_TYPE_MEDIA_KEYS_MANAGER(csd_media_keys_manager_get_type ()), &dbus_glib_csd_media_keys_manager_object_info);
1618}
1619
1620static void
1621csd_media_keys_manager_init (CsdMediaKeysManager *manager)
1622{
1623 manager->priv = csd_media_keys_manager_get_instance_private (manager);
1624}
1625
1626static gboolean
1627register_manager (CsdMediaKeysManager *manager)
1628{
1629 GError *error = NULL((void*)0);
1630
1631 manager->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
1632 if (manager->priv->connection == NULL((void*)0)) {
1633 if (error != NULL((void*)0)) {
1634 g_error ("Error getting session bus: %s", error->message);
1635 g_error_free (error);
1636 }
1637 return FALSE(0);
1638 }
1639
1640 dbus_g_connection_register_g_object (manager->priv->connection, CSD_MEDIA_KEYS_DBUS_PATH"/org/cafe/SettingsDaemon" "/MediaKeys", G_OBJECT (manager)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((manager)), (((GType) ((20) << (2))))))))
);
1641
1642 return TRUE(!(0));
1643}
1644
1645CsdMediaKeysManager *
1646csd_media_keys_manager_new (void)
1647{
1648 if (manager_object != NULL((void*)0)) {
1649 g_object_ref (manager_object)((__typeof__ (manager_object)) (g_object_ref) (manager_object
))
;
1650 } else {
1651 gboolean res;
1652
1653 manager_object = g_object_new (CSD_TYPE_MEDIA_KEYS_MANAGER(csd_media_keys_manager_get_type ()), NULL((void*)0));
1654 g_object_add_weak_pointer (manager_object,
1655 (gpointer *) &manager_object);
1656 res = register_manager (manager_object);
1657 if (! res) {
1658 g_object_unref (manager_object);
1659 return NULL((void*)0);
1660 }
1661 }
1662
1663 return CSD_MEDIA_KEYS_MANAGER (manager_object)((((CsdMediaKeysManager*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((manager_object)), ((csd_media_keys_manager_get_type
()))))))
;
1664}