Merge lp:~equinox-i/xfce4-volumed-pulse/add-support-for-mic-mute into lp:~mrpouit/xfce4-volumed-pulse/master
- add-support-for-mic-mute
- Merge into 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 | ||||
Related bugs: |
|
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
-
use icon for microphone mute status
Unmerged revisions
- 64. By Christian Pointner
-
use icon for microphone mute status
- 63. By Christian Pointner
-
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 | 101 | i->pa_main_loop = NULL; | 101 | i->pa_main_loop = NULL; |
6 | 102 | i->pulse_context = NULL; | 102 | i->pulse_context = NULL; |
7 | 103 | i->sink_index = -1; | 103 | i->sink_index = -1; |
8 | 104 | i->source_index = -1; | ||
9 | 104 | i->chan = NULL; | 105 | i->chan = NULL; |
10 | 105 | i->loop = NULL; | 106 | i->loop = NULL; |
11 | 106 | #ifdef HAVE_LIBNOTIFY | 107 | #ifdef HAVE_LIBNOTIFY |
12 | 107 | i->gauge_notifications = FALSE; | 108 | i->gauge_notifications = FALSE; |
13 | 108 | i->notification = NULL; | 109 | i->notification = NULL; |
14 | 110 | i->notification_mic = NULL; | ||
15 | 109 | #endif | 111 | #endif |
16 | 110 | } | 112 | } |
17 | 111 | 113 | ||
18 | 112 | 114 | ||
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 | 55 | pa_glib_mainloop *pa_main_loop; | 55 | pa_glib_mainloop *pa_main_loop; |
24 | 56 | pa_context *pulse_context; | 56 | pa_context *pulse_context; |
25 | 57 | guint32 sink_index; | 57 | guint32 sink_index; |
26 | 58 | guint32 source_index; | ||
27 | 58 | pa_cvolume volume; | 59 | pa_cvolume volume; |
28 | 59 | int mute; | 60 | int mute; |
29 | 61 | int mic_mute; | ||
30 | 60 | 62 | ||
31 | 61 | /* Xfconf vars */ | 63 | /* Xfconf vars */ |
32 | 62 | XfconfChannel *chan; | 64 | XfconfChannel *chan; |
33 | @@ -66,6 +68,7 @@ | |||
34 | 66 | /* Libnotify vars */ | 68 | /* Libnotify vars */ |
35 | 67 | gboolean gauge_notifications; | 69 | gboolean gauge_notifications; |
36 | 68 | NotifyNotification* notification; | 70 | NotifyNotification* notification; |
37 | 71 | NotifyNotification* notification_mic; | ||
38 | 69 | #endif | 72 | #endif |
39 | 70 | 73 | ||
40 | 71 | /* Other Xvd vars */ | 74 | /* Other Xvd vars */ |
41 | 72 | 75 | ||
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 | 55 | { | 55 | { |
47 | 56 | XvdInstance *xvd_inst = (XvdInstance *) Inst; | 56 | XvdInstance *xvd_inst = (XvdInstance *) Inst; |
48 | 57 | 57 | ||
50 | 58 | g_debug ("The LowerVolume key was pressed."); | 58 | g_debug ("The Mute key was pressed."); |
51 | 59 | 59 | ||
52 | 60 | xvd_toggle_mute (xvd_inst); | 60 | xvd_toggle_mute (xvd_inst); |
53 | 61 | } | 61 | } |
54 | 62 | 62 | ||
55 | 63 | static | ||
56 | 64 | void xvd_mic_mute_handler (const char *keystring, void *Inst) | ||
57 | 65 | { | ||
58 | 66 | XvdInstance *xvd_inst = (XvdInstance *) Inst; | ||
59 | 67 | |||
60 | 68 | g_debug ("The MicMute key was pressed."); | ||
61 | 69 | |||
62 | 70 | xvd_toggle_mic_mute (xvd_inst); | ||
63 | 71 | } | ||
64 | 72 | |||
65 | 63 | void | 73 | void |
66 | 64 | xvd_keys_init(XvdInstance *Inst) | 74 | xvd_keys_init(XvdInstance *Inst) |
67 | 65 | { | 75 | { |
68 | @@ -117,6 +127,24 @@ | |||
69 | 117 | keybinder_bind ("<Ctrl><Alt><Super>XF86AudioMute", xvd_mute_handler, Inst); | 127 | keybinder_bind ("<Ctrl><Alt><Super>XF86AudioMute", xvd_mute_handler, Inst); |
70 | 118 | keybinder_bind ("<Shift><Alt><Super>XF86AudioMute", xvd_mute_handler, Inst); | 128 | keybinder_bind ("<Shift><Alt><Super>XF86AudioMute", xvd_mute_handler, Inst); |
71 | 119 | keybinder_bind ("<Ctrl><Shift><Alt><Super>XF86AudioMute", xvd_mute_handler, Inst); | 129 | keybinder_bind ("<Ctrl><Shift><Alt><Super>XF86AudioMute", xvd_mute_handler, Inst); |
72 | 130 | |||
73 | 131 | |||
74 | 132 | keybinder_bind ("XF86AudioMicMute", xvd_mic_mute_handler, Inst); | ||
75 | 133 | keybinder_bind ("<Ctrl>XF86AudioMicMute", xvd_mic_mute_handler, Inst); | ||
76 | 134 | keybinder_bind ("<Alt>XF86AudioMicMute", xvd_mic_mute_handler, Inst); | ||
77 | 135 | keybinder_bind ("<Super>XF86AudioMicMute", xvd_mic_mute_handler, Inst); | ||
78 | 136 | keybinder_bind ("<Shift>XF86AudioMicMute", xvd_mic_mute_handler, Inst); | ||
79 | 137 | keybinder_bind ("<Ctrl><Shift>XF86AudioMicMute", xvd_mic_mute_handler, Inst); | ||
80 | 138 | keybinder_bind ("<Ctrl><Alt>XF86AudioMicMute", xvd_mic_mute_handler, Inst); | ||
81 | 139 | keybinder_bind ("<Ctrl><Super>XF86AudioMicMute", xvd_mic_mute_handler, Inst); | ||
82 | 140 | keybinder_bind ("<Alt><Shift>XF86AudioMicMute", xvd_mic_mute_handler, Inst); | ||
83 | 141 | keybinder_bind ("<Alt><Super>XF86AudioMicMute", xvd_mic_mute_handler, Inst); | ||
84 | 142 | keybinder_bind ("<Shift><Super>XF86AudioMicMute", xvd_mic_mute_handler, Inst); | ||
85 | 143 | keybinder_bind ("<Ctrl><Shift><Super>XF86AudioMicMute", xvd_mic_mute_handler, Inst); | ||
86 | 144 | keybinder_bind ("<Ctrl><Shift><Alt>XF86AudioMicMute", xvd_mic_mute_handler, Inst); | ||
87 | 145 | keybinder_bind ("<Ctrl><Alt><Super>XF86AudioMicMute", xvd_mic_mute_handler, Inst); | ||
88 | 146 | keybinder_bind ("<Shift><Alt><Super>XF86AudioMicMute", xvd_mic_mute_handler, Inst); | ||
89 | 147 | keybinder_bind ("<Ctrl><Shift><Alt><Super>XF86AudioMicMute", xvd_mic_mute_handler, Inst); | ||
90 | 120 | } | 148 | } |
91 | 121 | 149 | ||
92 | 122 | void | 150 | void |
93 | @@ -175,5 +203,22 @@ | |||
94 | 175 | keybinder_unbind ("<Ctrl><Alt><Super>XF86AudioMute", xvd_mute_handler); | 203 | keybinder_unbind ("<Ctrl><Alt><Super>XF86AudioMute", xvd_mute_handler); |
95 | 176 | keybinder_unbind ("<Shift><Alt><Super>XF86AudioMute", xvd_mute_handler); | 204 | keybinder_unbind ("<Shift><Alt><Super>XF86AudioMute", xvd_mute_handler); |
96 | 177 | keybinder_unbind ("<Ctrl><Shift><Alt><Super>XF86AudioMute", xvd_mute_handler); | 205 | keybinder_unbind ("<Ctrl><Shift><Alt><Super>XF86AudioMute", xvd_mute_handler); |
98 | 178 | 206 | ||
99 | 207 | |||
100 | 208 | keybinder_unbind ("XF86AudioMicMute", xvd_mic_mute_handler); | ||
101 | 209 | keybinder_unbind ("<Ctrl>XF86AudioMicMute", xvd_mic_mute_handler); | ||
102 | 210 | keybinder_unbind ("<Alt>XF86AudioMicMute", xvd_mic_mute_handler); | ||
103 | 211 | keybinder_unbind ("<Super>XF86AudioMicMute", xvd_mic_mute_handler); | ||
104 | 212 | keybinder_unbind ("<Shift>XF86AudioMicMute", xvd_mic_mute_handler); | ||
105 | 213 | keybinder_unbind ("<Ctrl><Shift>XF86AudioMicMute", xvd_mic_mute_handler); | ||
106 | 214 | keybinder_unbind ("<Ctrl><Alt>XF86AudioMicMute", xvd_mic_mute_handler); | ||
107 | 215 | keybinder_unbind ("<Ctrl><Super>XF86AudioMicMute", xvd_mic_mute_handler); | ||
108 | 216 | keybinder_unbind ("<Alt><Shift>XF86AudioMicMute", xvd_mic_mute_handler); | ||
109 | 217 | keybinder_unbind ("<Alt><Super>XF86AudioMicMute", xvd_mic_mute_handler); | ||
110 | 218 | keybinder_unbind ("<Shift><Super>XF86AudioMicMute", xvd_mic_mute_handler); | ||
111 | 219 | keybinder_unbind ("<Ctrl><Shift><Super>XF86AudioMicMute", xvd_mic_mute_handler); | ||
112 | 220 | keybinder_unbind ("<Ctrl><Shift><Alt>XF86AudioMicMute", xvd_mic_mute_handler); | ||
113 | 221 | keybinder_unbind ("<Ctrl><Alt><Super>XF86AudioMicMute", xvd_mic_mute_handler); | ||
114 | 222 | keybinder_unbind ("<Shift><Alt><Super>XF86AudioMicMute", xvd_mic_mute_handler); | ||
115 | 223 | keybinder_unbind ("<Ctrl><Shift><Alt><Super>XF86AudioMicMute", xvd_mic_mute_handler); | ||
116 | 179 | } | 224 | } |
117 | 180 | 225 | ||
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 | 99 | (Inst->gauge_notifications) ? -1 : 0); | 99 | (Inst->gauge_notifications) ? -1 : 0); |
123 | 100 | } | 100 | } |
124 | 101 | 101 | ||
125 | 102 | void | ||
126 | 103 | xvd_notify_mic_notification(XvdInstance *Inst) | ||
127 | 104 | { | ||
128 | 105 | GError* error = NULL; | ||
129 | 106 | gchar* title = NULL; | ||
130 | 107 | gchar* icon = NULL; | ||
131 | 108 | |||
132 | 109 | title = g_strdup_printf ("Microphone is %s", (Inst->mic_mute) ? "muted" : "active"); | ||
133 | 110 | icon = (Inst->mic_mute) ? "microphone-sensitivity-muted" : "microphone-sensitivity-high"; | ||
134 | 111 | |||
135 | 112 | notify_notification_update (Inst->notification_mic, | ||
136 | 113 | title, | ||
137 | 114 | NULL, | ||
138 | 115 | icon); | ||
139 | 116 | |||
140 | 117 | g_free (title); | ||
141 | 118 | |||
142 | 119 | if (Inst->gauge_notifications) { | ||
143 | 120 | notify_notification_set_hint_int32 (Inst->notification_mic, | ||
144 | 121 | LAYOUT_ICON_ONLY, | ||
145 | 122 | 1); | ||
146 | 123 | } | ||
147 | 124 | |||
148 | 125 | if (!notify_notification_show (Inst->notification_mic, &error)) | ||
149 | 126 | { | ||
150 | 127 | g_warning ("Error while sending mic notification : %s\n", error->message); | ||
151 | 128 | g_error_free (error); | ||
152 | 129 | } | ||
153 | 130 | |||
154 | 131 | } | ||
155 | 132 | |||
156 | 102 | void | 133 | void |
157 | 103 | xvd_notify_init(XvdInstance *Inst, | 134 | xvd_notify_init(XvdInstance *Inst, |
158 | 104 | const gchar *appname) | 135 | const gchar *appname) |
159 | @@ -128,11 +159,14 @@ | |||
160 | 128 | #ifdef NOTIFY_CHECK_VERSION | 159 | #ifdef NOTIFY_CHECK_VERSION |
161 | 129 | #if NOTIFY_CHECK_VERSION (0, 7, 0) | 160 | #if NOTIFY_CHECK_VERSION (0, 7, 0) |
162 | 130 | Inst->notification = notify_notification_new ("Xfce4-Volumed", NULL, NULL); | 161 | Inst->notification = notify_notification_new ("Xfce4-Volumed", NULL, NULL); |
163 | 162 | Inst->notification_mic = notify_notification_new ("Xfce4-Volumed", NULL, NULL); | ||
164 | 131 | #else | 163 | #else |
165 | 132 | Inst->notification = notify_notification_new ("Xfce4-Volumed", NULL, NULL, NULL); | 164 | Inst->notification = notify_notification_new ("Xfce4-Volumed", NULL, NULL, NULL); |
166 | 165 | Inst->notification_mic = notify_notification_new ("Xfce4-Volumed", NULL, NULL, NULL); | ||
167 | 133 | #endif | 166 | #endif |
168 | 134 | #else | 167 | #else |
169 | 135 | Inst->notification = notify_notification_new ("Xfce4-Volumed", NULL, NULL, NULL); | 168 | Inst->notification = notify_notification_new ("Xfce4-Volumed", NULL, NULL, NULL); |
170 | 169 | Inst->notification_mic = notify_notification_new ("Xfce4-Volumed", NULL, NULL, NULL); | ||
171 | 136 | #endif | 170 | #endif |
172 | 137 | } | 171 | } |
173 | 138 | 172 | ||
174 | @@ -141,5 +175,7 @@ | |||
175 | 141 | { | 175 | { |
176 | 142 | g_object_unref (G_OBJECT (Inst->notification)); | 176 | g_object_unref (G_OBJECT (Inst->notification)); |
177 | 143 | Inst->notification = NULL; | 177 | Inst->notification = NULL; |
178 | 178 | g_object_unref (G_OBJECT (Inst->notification_mic)); | ||
179 | 179 | Inst->notification_mic = NULL; | ||
180 | 144 | notify_uninit (); | 180 | notify_uninit (); |
181 | 145 | } | 181 | } |
182 | 146 | 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 | 46 | void | 46 | void |
188 | 47 | xvd_notify_undershoot_notification(XvdInstance *Inst); | 47 | xvd_notify_undershoot_notification(XvdInstance *Inst); |
189 | 48 | 48 | ||
190 | 49 | |||
191 | 50 | void | ||
192 | 51 | xvd_notify_mic_notification(XvdInstance *Inst); | ||
193 | 52 | |||
194 | 53 | |||
195 | 49 | void | 54 | void |
196 | 50 | xvd_notify_init(XvdInstance *Inst, | 55 | xvd_notify_init(XvdInstance *Inst, |
197 | 51 | const gchar *appname); | 56 | const gchar *appname); |
198 | 52 | 57 | ||
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 | 39 | 39 | ||
204 | 40 | static pa_cvolume old_volume; | 40 | static pa_cvolume old_volume; |
205 | 41 | static int old_mute; | 41 | static int old_mute; |
206 | 42 | static int old_mic_mute; | ||
207 | 42 | 43 | ||
208 | 43 | 44 | ||
209 | 44 | #ifdef HAVE_LIBNOTIFY | 45 | #ifdef HAVE_LIBNOTIFY |
210 | 45 | static void xvd_notify_volume_callback (pa_context *c, | 46 | static void xvd_notify_volume_callback (pa_context *c, |
211 | 46 | int success, | 47 | int success, |
212 | 47 | void *userdata); | 48 | void *userdata); |
213 | 49 | |||
214 | 50 | static void xvd_notify_mic_callback (pa_context *c, | ||
215 | 51 | int success, | ||
216 | 52 | void *userdata); | ||
217 | 48 | #else | 53 | #else |
218 | 49 | #define xvd_notify_volume_callback NULL | 54 | #define xvd_notify_volume_callback NULL |
219 | 55 | #define xvd_notify_mic_callback NULL | ||
220 | 50 | #endif | 56 | #endif |
221 | 51 | 57 | ||
222 | 52 | static void xvd_context_state_callback (pa_context *c, | 58 | static void xvd_context_state_callback (pa_context *c, |
223 | @@ -76,6 +82,21 @@ | |||
224 | 76 | int eol, | 82 | int eol, |
225 | 77 | void *userdata); | 83 | void *userdata); |
226 | 78 | 84 | ||
227 | 85 | static void xvd_default_source_info_callback (pa_context *c, | ||
228 | 86 | const pa_source_info *info, | ||
229 | 87 | int eol, | ||
230 | 88 | void *userdata); | ||
231 | 89 | |||
232 | 90 | static void xvd_source_info_callback (pa_context *c, | ||
233 | 91 | const pa_source_info *source, | ||
234 | 92 | int eol, | ||
235 | 93 | void *userdata); | ||
236 | 94 | |||
237 | 95 | static void xvd_update_source_callback (pa_context *c, | ||
238 | 96 | const pa_source_info *info, | ||
239 | 97 | int eol, | ||
240 | 98 | void *userdata); | ||
241 | 99 | |||
242 | 79 | static gboolean xvd_connect_to_pulse (XvdInstance *i); | 100 | static gboolean xvd_connect_to_pulse (XvdInstance *i); |
243 | 80 | 101 | ||
244 | 81 | 102 | ||
245 | @@ -201,6 +222,47 @@ | |||
246 | 201 | } | 222 | } |
247 | 202 | 223 | ||
248 | 203 | 224 | ||
249 | 225 | void | ||
250 | 226 | xvd_toggle_mic_mute (XvdInstance *i) | ||
251 | 227 | { | ||
252 | 228 | pa_operation *op = NULL; | ||
253 | 229 | |||
254 | 230 | if (!i || !i->pulse_context) | ||
255 | 231 | { | ||
256 | 232 | g_warning ("xvd_toggle_mic_mute: pulseaudio context is null"); | ||
257 | 233 | return; | ||
258 | 234 | } | ||
259 | 235 | |||
260 | 236 | if (pa_context_get_state (i->pulse_context) != PA_CONTEXT_READY) | ||
261 | 237 | { | ||
262 | 238 | g_warning ("xvd_toggle_mic_mute: pulseaudio context isn't ready"); | ||
263 | 239 | return; | ||
264 | 240 | } | ||
265 | 241 | |||
266 | 242 | if (i->source_index == PA_INVALID_INDEX) | ||
267 | 243 | { | ||
268 | 244 | g_warning ("xvd_toggle_mic_mute: undefined source"); | ||
269 | 245 | return; | ||
270 | 246 | } | ||
271 | 247 | |||
272 | 248 | /* backup existing mute and update */ | ||
273 | 249 | i->mic_mute = !(old_mic_mute = i->mic_mute); | ||
274 | 250 | |||
275 | 251 | op = pa_context_set_source_mute_by_index (i->pulse_context, | ||
276 | 252 | i->source_index, | ||
277 | 253 | i->mic_mute, | ||
278 | 254 | xvd_notify_mic_callback, | ||
279 | 255 | i); | ||
280 | 256 | |||
281 | 257 | if (!op) | ||
282 | 258 | { | ||
283 | 259 | g_warning ("xvd_toggle_mic_mute: failed"); | ||
284 | 260 | return; | ||
285 | 261 | } | ||
286 | 262 | pa_operation_unref (op); | ||
287 | 263 | } | ||
288 | 264 | |||
289 | 265 | |||
290 | 204 | gint | 266 | gint |
291 | 205 | xvd_get_readable_volume (const pa_cvolume *vol) | 267 | xvd_get_readable_volume (const pa_cvolume *vol) |
292 | 206 | { | 268 | { |
293 | @@ -259,13 +321,13 @@ | |||
294 | 259 | 321 | ||
295 | 260 | if (!c || !userdata) | 322 | if (!c || !userdata) |
296 | 261 | { | 323 | { |
298 | 262 | g_warning ("xvd_notify_volume_update: invalid argument"); | 324 | g_warning ("xvd_notify_volume_callback: invalid argument"); |
299 | 263 | return; | 325 | return; |
300 | 264 | } | 326 | } |
301 | 265 | 327 | ||
302 | 266 | if (!success) | 328 | if (!success) |
303 | 267 | { | 329 | { |
305 | 268 | g_warning ("xvd_notify_volume_update: operation failed, %s", | 330 | g_warning ("xvd_notify_volume_callback: operation failed, %s", |
306 | 269 | pa_strerror (pa_context_errno (c))); | 331 | pa_strerror (pa_context_errno (c))); |
307 | 270 | return; | 332 | return; |
308 | 271 | } | 333 | } |
309 | @@ -290,6 +352,39 @@ | |||
310 | 290 | else | 352 | else |
311 | 291 | xvd_notify_volume_notification (i); | 353 | xvd_notify_volume_notification (i); |
312 | 292 | } | 354 | } |
313 | 355 | |||
314 | 356 | |||
315 | 357 | /** | ||
316 | 358 | * Shows Mic mute status notification | ||
317 | 359 | */ | ||
318 | 360 | static void | ||
319 | 361 | xvd_notify_mic_callback (pa_context *c, | ||
320 | 362 | int success, | ||
321 | 363 | void *userdata) | ||
322 | 364 | { | ||
323 | 365 | XvdInstance *i = (XvdInstance *) userdata; | ||
324 | 366 | guint32 r_oldv, r_curv; | ||
325 | 367 | |||
326 | 368 | if (!c || !userdata) | ||
327 | 369 | { | ||
328 | 370 | g_warning ("xvd_notify_mic_callback: invalid argument"); | ||
329 | 371 | return; | ||
330 | 372 | } | ||
331 | 373 | |||
332 | 374 | if (!success) | ||
333 | 375 | { | ||
334 | 376 | g_warning ("xvd_notify_mic_callback: operation failed, %s", | ||
335 | 377 | pa_strerror (pa_context_errno (c))); | ||
336 | 378 | return; | ||
337 | 379 | } | ||
338 | 380 | |||
339 | 381 | /* the sink was (un)muted */ | ||
340 | 382 | if (old_mic_mute != i->mic_mute) | ||
341 | 383 | { | ||
342 | 384 | xvd_notify_mic_notification (i); | ||
343 | 385 | return; | ||
344 | 386 | } | ||
345 | 387 | } | ||
346 | 293 | #endif | 388 | #endif |
347 | 294 | 389 | ||
348 | 295 | 390 | ||
349 | @@ -335,6 +430,28 @@ | |||
350 | 335 | pa_operation_unref (op); | 430 | pa_operation_unref (op); |
351 | 336 | } | 431 | } |
352 | 337 | break; | 432 | break; |
353 | 433 | /* change on a source, re-fetch it */ | ||
354 | 434 | case PA_SUBSCRIPTION_EVENT_SOURCE: | ||
355 | 435 | if (i->source_index != index) | ||
356 | 436 | return; | ||
357 | 437 | |||
358 | 438 | if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) | ||
359 | 439 | i->source_index = PA_INVALID_INDEX; | ||
360 | 440 | else | ||
361 | 441 | { | ||
362 | 442 | op = pa_context_get_source_info_by_index (c, | ||
363 | 443 | index, | ||
364 | 444 | xvd_update_source_callback, | ||
365 | 445 | userdata); | ||
366 | 446 | |||
367 | 447 | if (!op) | ||
368 | 448 | { | ||
369 | 449 | g_warning ("xvd_subscribed_events_callback: failed to get source info"); | ||
370 | 450 | return; | ||
371 | 451 | } | ||
372 | 452 | pa_operation_unref (op); | ||
373 | 453 | } | ||
374 | 454 | break; | ||
375 | 338 | /* change on the server, re-fetch everything */ | 455 | /* change on the server, re-fetch everything */ |
376 | 339 | case PA_SUBSCRIPTION_EVENT_SERVER: | 456 | case PA_SUBSCRIPTION_EVENT_SERVER: |
377 | 340 | op = pa_context_get_server_info (c, | 457 | op = pa_context_get_server_info (c, |
378 | @@ -360,7 +477,7 @@ | |||
379 | 360 | void *userdata) | 477 | void *userdata) |
380 | 361 | { | 478 | { |
381 | 362 | XvdInstance *i = (XvdInstance *) userdata; | 479 | XvdInstance *i = (XvdInstance *) userdata; |
383 | 363 | pa_subscription_mask_t mask = PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SERVER; | 480 | pa_subscription_mask_t mask = PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SOURCE | PA_SUBSCRIPTION_MASK_SERVER; |
384 | 364 | pa_operation *op = NULL; | 481 | pa_operation *op = NULL; |
385 | 365 | 482 | ||
386 | 366 | if (!c || !userdata) | 483 | if (!c || !userdata) |
387 | @@ -390,6 +507,7 @@ | |||
388 | 390 | case PA_CONTEXT_FAILED: | 507 | case PA_CONTEXT_FAILED: |
389 | 391 | g_critical("xvd_context_state_callback: The connection failed or was disconnected, is PulseAudio Daemon running?"); | 508 | g_critical("xvd_context_state_callback: The connection failed or was disconnected, is PulseAudio Daemon running?"); |
390 | 392 | i->sink_index = PA_INVALID_INDEX; | 509 | i->sink_index = PA_INVALID_INDEX; |
391 | 510 | i->source_index = PA_INVALID_INDEX; | ||
392 | 393 | break; | 511 | break; |
393 | 394 | case PA_CONTEXT_READY: | 512 | case PA_CONTEXT_READY: |
394 | 395 | g_debug ("xvd_context_state_callback: The connection is established, the context is ready to execute operations"); | 513 | g_debug ("xvd_context_state_callback: The connection is established, the context is ready to execute operations"); |
395 | @@ -397,7 +515,7 @@ | |||
396 | 397 | xvd_subscribed_events_callback, | 515 | xvd_subscribed_events_callback, |
397 | 398 | userdata); | 516 | userdata); |
398 | 399 | 517 | ||
400 | 400 | /* subscribe to sink and server changes, we don't need more */ | 518 | /* subscribe to sink/source and server changes, we don't need more */ |
401 | 401 | op = pa_context_subscribe (c, | 519 | op = pa_context_subscribe (c, |
402 | 402 | mask, | 520 | mask, |
403 | 403 | NULL, | 521 | NULL, |
404 | @@ -476,6 +594,36 @@ | |||
405 | 476 | } | 594 | } |
406 | 477 | pa_operation_unref (op); | 595 | pa_operation_unref (op); |
407 | 478 | } | 596 | } |
408 | 597 | |||
409 | 598 | if (info->default_source_name) | ||
410 | 599 | { | ||
411 | 600 | op = pa_context_get_source_info_by_name (c, | ||
412 | 601 | info->default_source_name, | ||
413 | 602 | xvd_default_source_info_callback, | ||
414 | 603 | userdata); | ||
415 | 604 | |||
416 | 605 | if (!op) | ||
417 | 606 | { | ||
418 | 607 | g_warning("xvd_server_info_callback: pa_context_get_source_info_by_name() failed"); | ||
419 | 608 | return; | ||
420 | 609 | } | ||
421 | 610 | pa_operation_unref (op); | ||
422 | 611 | } | ||
423 | 612 | else | ||
424 | 613 | { | ||
425 | 614 | /* when PulseAudio doesn't set a default source, look at all of them | ||
426 | 615 | and hope to find a usable one */ | ||
427 | 616 | op = pa_context_get_source_info_list(c, | ||
428 | 617 | xvd_source_info_callback, | ||
429 | 618 | userdata); | ||
430 | 619 | |||
431 | 620 | if (!op) | ||
432 | 621 | { | ||
433 | 622 | g_warning("xvd_server_info_callback: pa_context_get_source_info_list() failed"); | ||
434 | 623 | return; | ||
435 | 624 | } | ||
436 | 625 | pa_operation_unref (op); | ||
437 | 626 | } | ||
438 | 479 | } | 627 | } |
439 | 480 | 628 | ||
440 | 481 | 629 | ||
441 | @@ -584,3 +732,105 @@ | |||
442 | 584 | #endif | 732 | #endif |
443 | 585 | } | 733 | } |
444 | 586 | } | 734 | } |
445 | 735 | |||
446 | 736 | |||
447 | 737 | /** | ||
448 | 738 | * Callback to retrieve the infos of a given source. | ||
449 | 739 | */ | ||
450 | 740 | static void | ||
451 | 741 | xvd_source_info_callback (pa_context *c, | ||
452 | 742 | const pa_source_info *source, | ||
453 | 743 | int eol, | ||
454 | 744 | void *userdata) | ||
455 | 745 | { | ||
456 | 746 | XvdInstance *i = (XvdInstance *) userdata; | ||
457 | 747 | |||
458 | 748 | /* detect the end of the list */ | ||
459 | 749 | if (eol > 0) | ||
460 | 750 | return; | ||
461 | 751 | else | ||
462 | 752 | { | ||
463 | 753 | if (!userdata || !source) | ||
464 | 754 | { | ||
465 | 755 | g_warning ("xvd_source_info_callback: invalid argument"); | ||
466 | 756 | return; | ||
467 | 757 | } | ||
468 | 758 | |||
469 | 759 | /* If there's no default source, try to use this one */ | ||
470 | 760 | if (i->source_index == PA_INVALID_INDEX | ||
471 | 761 | /* indicator-sound does that check */ | ||
472 | 762 | && g_ascii_strncasecmp ("auto_null", source->name, 9) != 0) | ||
473 | 763 | { | ||
474 | 764 | i->source_index = source->index; | ||
475 | 765 | old_mic_mute = i->mic_mute = source->mute; | ||
476 | 766 | } | ||
477 | 767 | } | ||
478 | 768 | } | ||
479 | 769 | |||
480 | 770 | |||
481 | 771 | /** | ||
482 | 772 | * Callback to retrieve the infos of the default source. | ||
483 | 773 | */ | ||
484 | 774 | static void | ||
485 | 775 | xvd_default_source_info_callback (pa_context *c, | ||
486 | 776 | const pa_source_info *info, | ||
487 | 777 | int eol, | ||
488 | 778 | void *userdata) | ||
489 | 779 | { | ||
490 | 780 | XvdInstance *i = (XvdInstance *) userdata; | ||
491 | 781 | |||
492 | 782 | /* detect the end of the list */ | ||
493 | 783 | if (eol > 0) | ||
494 | 784 | return; | ||
495 | 785 | else | ||
496 | 786 | { | ||
497 | 787 | if (!userdata || !info) | ||
498 | 788 | { | ||
499 | 789 | g_warning ("xvd_default_source_info_callback: invalid argument"); | ||
500 | 790 | return; | ||
501 | 791 | } | ||
502 | 792 | |||
503 | 793 | /* is this a new default source? */ | ||
504 | 794 | if (i->source_index != info->index) | ||
505 | 795 | { | ||
506 | 796 | i->source_index = info->index; | ||
507 | 797 | old_mic_mute = i->mic_mute = info->mute; | ||
508 | 798 | } | ||
509 | 799 | } | ||
510 | 800 | } | ||
511 | 801 | |||
512 | 802 | |||
513 | 803 | /** | ||
514 | 804 | * Callback for source changes reported by PulseAudio. | ||
515 | 805 | */ | ||
516 | 806 | static void | ||
517 | 807 | xvd_update_source_callback (pa_context *c, | ||
518 | 808 | const pa_source_info *info, | ||
519 | 809 | int eol, | ||
520 | 810 | void *userdata) | ||
521 | 811 | { | ||
522 | 812 | XvdInstance *i = (XvdInstance *) userdata; | ||
523 | 813 | |||
524 | 814 | /* detect the end of the list */ | ||
525 | 815 | if (eol > 0) | ||
526 | 816 | return; | ||
527 | 817 | else | ||
528 | 818 | { | ||
529 | 819 | if (!c || !userdata || !info) | ||
530 | 820 | { | ||
531 | 821 | g_warning ("xvd_update_source_callback: invalid argument"); | ||
532 | 822 | return; | ||
533 | 823 | } | ||
534 | 824 | |||
535 | 825 | /* re-fetch infos from PulseAudio */ | ||
536 | 826 | i->source_index = info->index; | ||
537 | 827 | old_mic_mute = i->mic_mute; | ||
538 | 828 | i->mic_mute = info->mute; | ||
539 | 829 | |||
540 | 830 | #ifdef HAVE_LIBNOTIFY | ||
541 | 831 | /* notify user of the possible changes */ | ||
542 | 832 | if (old_mic_mute != i->mic_mute) | ||
543 | 833 | xvd_notify_mic_callback (c, 1, i); | ||
544 | 834 | #endif | ||
545 | 835 | } | ||
546 | 836 | } | ||
547 | 587 | 837 | ||
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 | 47 | void xvd_toggle_mute (XvdInstance *i); | 47 | void xvd_toggle_mute (XvdInstance *i); |
553 | 48 | 48 | ||
554 | 49 | /** | 49 | /** |
555 | 50 | * Toggle mic mute. | ||
556 | 51 | */ | ||
557 | 52 | void xvd_toggle_mic_mute (XvdInstance *i); | ||
558 | 53 | |||
559 | 54 | /** | ||
560 | 50 | * Returns a percentage volume (i.e. between 0 and 100, usable on notifications) | 55 | * Returns a percentage volume (i.e. between 0 and 100, usable on notifications) |
561 | 51 | */ | 56 | */ |
562 | 52 | gint xvd_get_readable_volume (const pa_cvolume *vol); | 57 | gint xvd_get_readable_volume (const pa_cvolume *vol); |
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.