Merge lp:~equinox-i/xfce4-volumed-pulse/add-support-for-mic-mute into lp:~mrpouit/xfce4-volumed-pulse/master

Proposed by Christian Pointner
Status: Needs review
Proposed branch: lp:~equinox-i/xfce4-volumed-pulse/add-support-for-mic-mute
Merge into: lp:~mrpouit/xfce4-volumed-pulse/master
Diff against target: 562 lines (+352/-6)
7 files modified
src/main.c (+2/-0)
src/xvd_data_types.h (+3/-0)
src/xvd_keys.c (+47/-2)
src/xvd_notify.c (+36/-0)
src/xvd_notify.h (+5/-0)
src/xvd_pulse.c (+254/-4)
src/xvd_pulse.h (+5/-0)
To merge this branch: bzr merge lp:~equinox-i/xfce4-volumed-pulse/add-support-for-mic-mute
Reviewer Review Type Date Requested Status
Simon Steinbeiß (community) Approve
Lionel Le Folgoc Pending
Review via email: mp+270876@code.launchpad.net

Commit message

Addes support for MicMute Key

Description of the change

This adds support for the MicMute Key on modern Laptops..

To post a comment you must log in.
64. By Christian Pointner on 2016-02-02

use icon for microphone mute status

Revision history for this message
Simon Steinbeiß (ochosi) wrote :

Thanks for your work! Please note that xfce4-volumed-pulse is now maintained at https://git.xfce.org/apps/xfce4-volumed-pulse.

Your patch has been reviewed and merged there.

Revision history for this message
Simon Steinbeiß (ochosi) :
review: Approve

Unmerged revisions

64. By Christian Pointner on 2016-02-02

use icon for microphone mute status

63. By Christian Pointner on 2015-09-11

Addes support for MicMute Key

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/main.c'
2--- src/main.c 2013-03-10 18:28:11 +0000
3+++ src/main.c 2016-02-02 19:54:56 +0000
4@@ -101,11 +101,13 @@
5 i->pa_main_loop = NULL;
6 i->pulse_context = NULL;
7 i->sink_index = -1;
8+ i->source_index = -1;
9 i->chan = NULL;
10 i->loop = NULL;
11 #ifdef HAVE_LIBNOTIFY
12 i->gauge_notifications = FALSE;
13 i->notification = NULL;
14+ i->notification_mic = NULL;
15 #endif
16 }
17
18
19=== modified file 'src/xvd_data_types.h'
20--- src/xvd_data_types.h 2013-03-10 18:28:11 +0000
21+++ src/xvd_data_types.h 2016-02-02 19:54:56 +0000
22@@ -55,8 +55,10 @@
23 pa_glib_mainloop *pa_main_loop;
24 pa_context *pulse_context;
25 guint32 sink_index;
26+ guint32 source_index;
27 pa_cvolume volume;
28 int mute;
29+ int mic_mute;
30
31 /* Xfconf vars */
32 XfconfChannel *chan;
33@@ -66,6 +68,7 @@
34 /* Libnotify vars */
35 gboolean gauge_notifications;
36 NotifyNotification* notification;
37+ NotifyNotification* notification_mic;
38 #endif
39
40 /* Other Xvd vars */
41
42=== modified file 'src/xvd_keys.c'
43--- src/xvd_keys.c 2013-03-10 18:28:11 +0000
44+++ src/xvd_keys.c 2016-02-02 19:54:56 +0000
45@@ -55,11 +55,21 @@
46 {
47 XvdInstance *xvd_inst = (XvdInstance *) Inst;
48
49- g_debug ("The LowerVolume key was pressed.");
50+ g_debug ("The Mute key was pressed.");
51
52 xvd_toggle_mute (xvd_inst);
53 }
54
55+static
56+void xvd_mic_mute_handler (const char *keystring, void *Inst)
57+{
58+ XvdInstance *xvd_inst = (XvdInstance *) Inst;
59+
60+ g_debug ("The MicMute key was pressed.");
61+
62+ xvd_toggle_mic_mute (xvd_inst);
63+}
64+
65 void
66 xvd_keys_init(XvdInstance *Inst)
67 {
68@@ -117,6 +127,24 @@
69 keybinder_bind ("<Ctrl><Alt><Super>XF86AudioMute", xvd_mute_handler, Inst);
70 keybinder_bind ("<Shift><Alt><Super>XF86AudioMute", xvd_mute_handler, Inst);
71 keybinder_bind ("<Ctrl><Shift><Alt><Super>XF86AudioMute", xvd_mute_handler, Inst);
72+
73+
74+ keybinder_bind ("XF86AudioMicMute", xvd_mic_mute_handler, Inst);
75+ keybinder_bind ("<Ctrl>XF86AudioMicMute", xvd_mic_mute_handler, Inst);
76+ keybinder_bind ("<Alt>XF86AudioMicMute", xvd_mic_mute_handler, Inst);
77+ keybinder_bind ("<Super>XF86AudioMicMute", xvd_mic_mute_handler, Inst);
78+ keybinder_bind ("<Shift>XF86AudioMicMute", xvd_mic_mute_handler, Inst);
79+ keybinder_bind ("<Ctrl><Shift>XF86AudioMicMute", xvd_mic_mute_handler, Inst);
80+ keybinder_bind ("<Ctrl><Alt>XF86AudioMicMute", xvd_mic_mute_handler, Inst);
81+ keybinder_bind ("<Ctrl><Super>XF86AudioMicMute", xvd_mic_mute_handler, Inst);
82+ keybinder_bind ("<Alt><Shift>XF86AudioMicMute", xvd_mic_mute_handler, Inst);
83+ keybinder_bind ("<Alt><Super>XF86AudioMicMute", xvd_mic_mute_handler, Inst);
84+ keybinder_bind ("<Shift><Super>XF86AudioMicMute", xvd_mic_mute_handler, Inst);
85+ keybinder_bind ("<Ctrl><Shift><Super>XF86AudioMicMute", xvd_mic_mute_handler, Inst);
86+ keybinder_bind ("<Ctrl><Shift><Alt>XF86AudioMicMute", xvd_mic_mute_handler, Inst);
87+ keybinder_bind ("<Ctrl><Alt><Super>XF86AudioMicMute", xvd_mic_mute_handler, Inst);
88+ keybinder_bind ("<Shift><Alt><Super>XF86AudioMicMute", xvd_mic_mute_handler, Inst);
89+ keybinder_bind ("<Ctrl><Shift><Alt><Super>XF86AudioMicMute", xvd_mic_mute_handler, Inst);
90 }
91
92 void
93@@ -175,5 +203,22 @@
94 keybinder_unbind ("<Ctrl><Alt><Super>XF86AudioMute", xvd_mute_handler);
95 keybinder_unbind ("<Shift><Alt><Super>XF86AudioMute", xvd_mute_handler);
96 keybinder_unbind ("<Ctrl><Shift><Alt><Super>XF86AudioMute", xvd_mute_handler);
97-
98+
99+
100+ keybinder_unbind ("XF86AudioMicMute", xvd_mic_mute_handler);
101+ keybinder_unbind ("<Ctrl>XF86AudioMicMute", xvd_mic_mute_handler);
102+ keybinder_unbind ("<Alt>XF86AudioMicMute", xvd_mic_mute_handler);
103+ keybinder_unbind ("<Super>XF86AudioMicMute", xvd_mic_mute_handler);
104+ keybinder_unbind ("<Shift>XF86AudioMicMute", xvd_mic_mute_handler);
105+ keybinder_unbind ("<Ctrl><Shift>XF86AudioMicMute", xvd_mic_mute_handler);
106+ keybinder_unbind ("<Ctrl><Alt>XF86AudioMicMute", xvd_mic_mute_handler);
107+ keybinder_unbind ("<Ctrl><Super>XF86AudioMicMute", xvd_mic_mute_handler);
108+ keybinder_unbind ("<Alt><Shift>XF86AudioMicMute", xvd_mic_mute_handler);
109+ keybinder_unbind ("<Alt><Super>XF86AudioMicMute", xvd_mic_mute_handler);
110+ keybinder_unbind ("<Shift><Super>XF86AudioMicMute", xvd_mic_mute_handler);
111+ keybinder_unbind ("<Ctrl><Shift><Super>XF86AudioMicMute", xvd_mic_mute_handler);
112+ keybinder_unbind ("<Ctrl><Shift><Alt>XF86AudioMicMute", xvd_mic_mute_handler);
113+ keybinder_unbind ("<Ctrl><Alt><Super>XF86AudioMicMute", xvd_mic_mute_handler);
114+ keybinder_unbind ("<Shift><Alt><Super>XF86AudioMicMute", xvd_mic_mute_handler);
115+ keybinder_unbind ("<Ctrl><Shift><Alt><Super>XF86AudioMicMute", xvd_mic_mute_handler);
116 }
117
118=== modified file 'src/xvd_notify.c'
119--- src/xvd_notify.c 2013-03-10 18:28:11 +0000
120+++ src/xvd_notify.c 2016-02-02 19:54:56 +0000
121@@ -99,6 +99,37 @@
122 (Inst->gauge_notifications) ? -1 : 0);
123 }
124
125+void
126+xvd_notify_mic_notification(XvdInstance *Inst)
127+{
128+ GError* error = NULL;
129+ gchar* title = NULL;
130+ gchar* icon = NULL;
131+
132+ title = g_strdup_printf ("Microphone is %s", (Inst->mic_mute) ? "muted" : "active");
133+ icon = (Inst->mic_mute) ? "microphone-sensitivity-muted" : "microphone-sensitivity-high";
134+
135+ notify_notification_update (Inst->notification_mic,
136+ title,
137+ NULL,
138+ icon);
139+
140+ g_free (title);
141+
142+ if (Inst->gauge_notifications) {
143+ notify_notification_set_hint_int32 (Inst->notification_mic,
144+ LAYOUT_ICON_ONLY,
145+ 1);
146+ }
147+
148+ if (!notify_notification_show (Inst->notification_mic, &error))
149+ {
150+ g_warning ("Error while sending mic notification : %s\n", error->message);
151+ g_error_free (error);
152+ }
153+
154+}
155+
156 void
157 xvd_notify_init(XvdInstance *Inst,
158 const gchar *appname)
159@@ -128,11 +159,14 @@
160 #ifdef NOTIFY_CHECK_VERSION
161 #if NOTIFY_CHECK_VERSION (0, 7, 0)
162 Inst->notification = notify_notification_new ("Xfce4-Volumed", NULL, NULL);
163+ Inst->notification_mic = notify_notification_new ("Xfce4-Volumed", NULL, NULL);
164 #else
165 Inst->notification = notify_notification_new ("Xfce4-Volumed", NULL, NULL, NULL);
166+ Inst->notification_mic = notify_notification_new ("Xfce4-Volumed", NULL, NULL, NULL);
167 #endif
168 #else
169 Inst->notification = notify_notification_new ("Xfce4-Volumed", NULL, NULL, NULL);
170+ Inst->notification_mic = notify_notification_new ("Xfce4-Volumed", NULL, NULL, NULL);
171 #endif
172 }
173
174@@ -141,5 +175,7 @@
175 {
176 g_object_unref (G_OBJECT (Inst->notification));
177 Inst->notification = NULL;
178+ g_object_unref (G_OBJECT (Inst->notification_mic));
179+ Inst->notification_mic = NULL;
180 notify_uninit ();
181 }
182
183=== modified file 'src/xvd_notify.h'
184--- src/xvd_notify.h 2013-03-10 18:28:11 +0000
185+++ src/xvd_notify.h 2016-02-02 19:54:56 +0000
186@@ -46,6 +46,11 @@
187 void
188 xvd_notify_undershoot_notification(XvdInstance *Inst);
189
190+
191+void
192+xvd_notify_mic_notification(XvdInstance *Inst);
193+
194+
195 void
196 xvd_notify_init(XvdInstance *Inst,
197 const gchar *appname);
198
199=== modified file 'src/xvd_pulse.c'
200--- src/xvd_pulse.c 2012-05-26 13:41:02 +0000
201+++ src/xvd_pulse.c 2016-02-02 19:54:56 +0000
202@@ -39,14 +39,20 @@
203
204 static pa_cvolume old_volume;
205 static int old_mute;
206+static int old_mic_mute;
207
208
209 #ifdef HAVE_LIBNOTIFY
210 static void xvd_notify_volume_callback (pa_context *c,
211 int success,
212 void *userdata);
213+
214+static void xvd_notify_mic_callback (pa_context *c,
215+ int success,
216+ void *userdata);
217 #else
218 #define xvd_notify_volume_callback NULL
219+#define xvd_notify_mic_callback NULL
220 #endif
221
222 static void xvd_context_state_callback (pa_context *c,
223@@ -76,6 +82,21 @@
224 int eol,
225 void *userdata);
226
227+static void xvd_default_source_info_callback (pa_context *c,
228+ const pa_source_info *info,
229+ int eol,
230+ void *userdata);
231+
232+static void xvd_source_info_callback (pa_context *c,
233+ const pa_source_info *source,
234+ int eol,
235+ void *userdata);
236+
237+static void xvd_update_source_callback (pa_context *c,
238+ const pa_source_info *info,
239+ int eol,
240+ void *userdata);
241+
242 static gboolean xvd_connect_to_pulse (XvdInstance *i);
243
244
245@@ -201,6 +222,47 @@
246 }
247
248
249+void
250+xvd_toggle_mic_mute (XvdInstance *i)
251+{
252+ pa_operation *op = NULL;
253+
254+ if (!i || !i->pulse_context)
255+ {
256+ g_warning ("xvd_toggle_mic_mute: pulseaudio context is null");
257+ return;
258+ }
259+
260+ if (pa_context_get_state (i->pulse_context) != PA_CONTEXT_READY)
261+ {
262+ g_warning ("xvd_toggle_mic_mute: pulseaudio context isn't ready");
263+ return;
264+ }
265+
266+ if (i->source_index == PA_INVALID_INDEX)
267+ {
268+ g_warning ("xvd_toggle_mic_mute: undefined source");
269+ return;
270+ }
271+
272+ /* backup existing mute and update */
273+ i->mic_mute = !(old_mic_mute = i->mic_mute);
274+
275+ op = pa_context_set_source_mute_by_index (i->pulse_context,
276+ i->source_index,
277+ i->mic_mute,
278+ xvd_notify_mic_callback,
279+ i);
280+
281+ if (!op)
282+ {
283+ g_warning ("xvd_toggle_mic_mute: failed");
284+ return;
285+ }
286+ pa_operation_unref (op);
287+}
288+
289+
290 gint
291 xvd_get_readable_volume (const pa_cvolume *vol)
292 {
293@@ -259,13 +321,13 @@
294
295 if (!c || !userdata)
296 {
297- g_warning ("xvd_notify_volume_update: invalid argument");
298+ g_warning ("xvd_notify_volume_callback: invalid argument");
299 return;
300 }
301
302 if (!success)
303 {
304- g_warning ("xvd_notify_volume_update: operation failed, %s",
305+ g_warning ("xvd_notify_volume_callback: operation failed, %s",
306 pa_strerror (pa_context_errno (c)));
307 return;
308 }
309@@ -290,6 +352,39 @@
310 else
311 xvd_notify_volume_notification (i);
312 }
313+
314+
315+/**
316+ * Shows Mic mute status notification
317+ */
318+static void
319+xvd_notify_mic_callback (pa_context *c,
320+ int success,
321+ void *userdata)
322+{
323+ XvdInstance *i = (XvdInstance *) userdata;
324+ guint32 r_oldv, r_curv;
325+
326+ if (!c || !userdata)
327+ {
328+ g_warning ("xvd_notify_mic_callback: invalid argument");
329+ return;
330+ }
331+
332+ if (!success)
333+ {
334+ g_warning ("xvd_notify_mic_callback: operation failed, %s",
335+ pa_strerror (pa_context_errno (c)));
336+ return;
337+ }
338+
339+ /* the sink was (un)muted */
340+ if (old_mic_mute != i->mic_mute)
341+ {
342+ xvd_notify_mic_notification (i);
343+ return;
344+ }
345+}
346 #endif
347
348
349@@ -335,6 +430,28 @@
350 pa_operation_unref (op);
351 }
352 break;
353+ /* change on a source, re-fetch it */
354+ case PA_SUBSCRIPTION_EVENT_SOURCE:
355+ if (i->source_index != index)
356+ return;
357+
358+ if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE)
359+ i->source_index = PA_INVALID_INDEX;
360+ else
361+ {
362+ op = pa_context_get_source_info_by_index (c,
363+ index,
364+ xvd_update_source_callback,
365+ userdata);
366+
367+ if (!op)
368+ {
369+ g_warning ("xvd_subscribed_events_callback: failed to get source info");
370+ return;
371+ }
372+ pa_operation_unref (op);
373+ }
374+ break;
375 /* change on the server, re-fetch everything */
376 case PA_SUBSCRIPTION_EVENT_SERVER:
377 op = pa_context_get_server_info (c,
378@@ -360,7 +477,7 @@
379 void *userdata)
380 {
381 XvdInstance *i = (XvdInstance *) userdata;
382- pa_subscription_mask_t mask = PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SERVER;
383+ pa_subscription_mask_t mask = PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SOURCE | PA_SUBSCRIPTION_MASK_SERVER;
384 pa_operation *op = NULL;
385
386 if (!c || !userdata)
387@@ -390,6 +507,7 @@
388 case PA_CONTEXT_FAILED:
389 g_critical("xvd_context_state_callback: The connection failed or was disconnected, is PulseAudio Daemon running?");
390 i->sink_index = PA_INVALID_INDEX;
391+ i->source_index = PA_INVALID_INDEX;
392 break;
393 case PA_CONTEXT_READY:
394 g_debug ("xvd_context_state_callback: The connection is established, the context is ready to execute operations");
395@@ -397,7 +515,7 @@
396 xvd_subscribed_events_callback,
397 userdata);
398
399- /* subscribe to sink and server changes, we don't need more */
400+ /* subscribe to sink/source and server changes, we don't need more */
401 op = pa_context_subscribe (c,
402 mask,
403 NULL,
404@@ -476,6 +594,36 @@
405 }
406 pa_operation_unref (op);
407 }
408+
409+ if (info->default_source_name)
410+ {
411+ op = pa_context_get_source_info_by_name (c,
412+ info->default_source_name,
413+ xvd_default_source_info_callback,
414+ userdata);
415+
416+ if (!op)
417+ {
418+ g_warning("xvd_server_info_callback: pa_context_get_source_info_by_name() failed");
419+ return;
420+ }
421+ pa_operation_unref (op);
422+ }
423+ else
424+ {
425+ /* when PulseAudio doesn't set a default source, look at all of them
426+ and hope to find a usable one */
427+ op = pa_context_get_source_info_list(c,
428+ xvd_source_info_callback,
429+ userdata);
430+
431+ if (!op)
432+ {
433+ g_warning("xvd_server_info_callback: pa_context_get_source_info_list() failed");
434+ return;
435+ }
436+ pa_operation_unref (op);
437+ }
438 }
439
440
441@@ -584,3 +732,105 @@
442 #endif
443 }
444 }
445+
446+
447+/**
448+ * Callback to retrieve the infos of a given source.
449+ */
450+static void
451+xvd_source_info_callback (pa_context *c,
452+ const pa_source_info *source,
453+ int eol,
454+ void *userdata)
455+{
456+ XvdInstance *i = (XvdInstance *) userdata;
457+
458+ /* detect the end of the list */
459+ if (eol > 0)
460+ return;
461+ else
462+ {
463+ if (!userdata || !source)
464+ {
465+ g_warning ("xvd_source_info_callback: invalid argument");
466+ return;
467+ }
468+
469+ /* If there's no default source, try to use this one */
470+ if (i->source_index == PA_INVALID_INDEX
471+ /* indicator-sound does that check */
472+ && g_ascii_strncasecmp ("auto_null", source->name, 9) != 0)
473+ {
474+ i->source_index = source->index;
475+ old_mic_mute = i->mic_mute = source->mute;
476+ }
477+ }
478+}
479+
480+
481+/**
482+ * Callback to retrieve the infos of the default source.
483+ */
484+static void
485+xvd_default_source_info_callback (pa_context *c,
486+ const pa_source_info *info,
487+ int eol,
488+ void *userdata)
489+{
490+ XvdInstance *i = (XvdInstance *) userdata;
491+
492+ /* detect the end of the list */
493+ if (eol > 0)
494+ return;
495+ else
496+ {
497+ if (!userdata || !info)
498+ {
499+ g_warning ("xvd_default_source_info_callback: invalid argument");
500+ return;
501+ }
502+
503+ /* is this a new default source? */
504+ if (i->source_index != info->index)
505+ {
506+ i->source_index = info->index;
507+ old_mic_mute = i->mic_mute = info->mute;
508+ }
509+ }
510+}
511+
512+
513+/**
514+ * Callback for source changes reported by PulseAudio.
515+ */
516+static void
517+xvd_update_source_callback (pa_context *c,
518+ const pa_source_info *info,
519+ int eol,
520+ void *userdata)
521+{
522+ XvdInstance *i = (XvdInstance *) userdata;
523+
524+ /* detect the end of the list */
525+ if (eol > 0)
526+ return;
527+ else
528+ {
529+ if (!c || !userdata || !info)
530+ {
531+ g_warning ("xvd_update_source_callback: invalid argument");
532+ return;
533+ }
534+
535+ /* re-fetch infos from PulseAudio */
536+ i->source_index = info->index;
537+ old_mic_mute = i->mic_mute;
538+ i->mic_mute = info->mute;
539+
540+#ifdef HAVE_LIBNOTIFY
541+ /* notify user of the possible changes */
542+ if (old_mic_mute != i->mic_mute)
543+ xvd_notify_mic_callback (c, 1, i);
544+#endif
545+ }
546+}
547
548=== modified file 'src/xvd_pulse.h'
549--- src/xvd_pulse.h 2012-05-24 21:24:41 +0000
550+++ src/xvd_pulse.h 2016-02-02 19:54:56 +0000
551@@ -47,6 +47,11 @@
552 void xvd_toggle_mute (XvdInstance *i);
553
554 /**
555+ * Toggle mic mute.
556+ */
557+void xvd_toggle_mic_mute (XvdInstance *i);
558+
559+/**
560 * Returns a percentage volume (i.e. between 0 and 100, usable on notifications)
561 */
562 gint xvd_get_readable_volume (const pa_cvolume *vol);

Subscribers

People subscribed via source and target branches