volumealsa: fix detection of ALSA error
[lxde/lxpanel.git] / src / plugins / volumealsa / volumealsa.c
1 /**
2 * Copyright (c) 2008 LxDE Developers, see the file AUTHORS for details.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <gtk/gtk.h>
20 #include <stdlib.h>
21 #include <fcntl.h>
22 #include <unistd.h>
23 #include <glib.h>
24 #include <glib/gi18n.h>
25 #include <gdk-pixbuf/gdk-pixbuf.h>
26 #include <alsa/asoundlib.h>
27 #include <poll.h>
28 #include "panel.h"
29 #include "misc.h"
30 #include "plugin.h"
31 #include "dbg.h"
32
33 #define ICONS_VOLUME_HIGH PACKAGE_DATA_DIR "/lxpanel/images/volume-high.png"
34 #define ICONS_VOLUME_MEDIUM PACKAGE_DATA_DIR "/lxpanel/images/volume-medium.png"
35 #define ICONS_VOLUME_LOW PACKAGE_DATA_DIR "/lxpanel/images/volume-low.png"
36 #define ICONS_MUTE PACKAGE_DATA_DIR "/lxpanel/images/mute.png"
37
38 typedef struct {
39
40 /* Graphics. */
41 Plugin * plugin; /* Back pointer to plugin */
42 GtkWidget * tray_icon; /* Displayed image */
43 GtkWidget * popup_window; /* Top level window for popup */
44 GtkWidget * volume_scale; /* Scale for volume */
45 GtkWidget * mute_check; /* Checkbox for mute state */
46 gboolean show_popup; /* Toggle to show and hide the popup on left click */
47 guint volume_scale_handler; /* Handler for vscale widget */
48 guint mute_check_handler; /* Handler for mute_check widget */
49
50 /* ALSA interface. */
51 snd_mixer_t * mixer; /* The mixer */
52 snd_mixer_selem_id_t * sid; /* The element ID */
53 snd_mixer_elem_t * master_element; /* The Master element */
54 guint mixer_evt_idle; /* Timer to handle restarting poll */
55 } VolumeALSAPlugin;
56
57 static gboolean asound_find_element(VolumeALSAPlugin * vol, const char * ename);
58 static gboolean asound_reset_mixer_evt_idle(VolumeALSAPlugin * vol);
59 static gboolean asound_mixer_event(GIOChannel * channel, GIOCondition cond, gpointer vol_gpointer);
60 static gboolean asound_initialize(VolumeALSAPlugin * vol);
61 static gboolean asound_has_mute(VolumeALSAPlugin * vol);
62 static gboolean asound_is_muted(VolumeALSAPlugin * vol);
63 static int asound_get_volume(VolumeALSAPlugin * vol);
64 static void asound_set_volume(VolumeALSAPlugin * vol, int volume);
65 static void volumealsa_update_display(VolumeALSAPlugin * vol);
66 static gboolean volumealsa_button_press_event(GtkWidget * widget, GdkEventButton * event, VolumeALSAPlugin * vol);
67 static gboolean volumealsa_popup_focus_out(GtkWidget * widget, GdkEvent * event, VolumeALSAPlugin * vol);
68 static void volumealsa_popup_map(GtkWidget * widget, VolumeALSAPlugin * vol);
69 static void volumealsa_popup_scale_changed(GtkRange * range, VolumeALSAPlugin * vol);
70 static void volumealsa_popup_scale_scrolled(GtkScale * scale, GdkEventScroll * evt, VolumeALSAPlugin * vol);
71 static void volumealsa_popup_mute_toggled(GtkWidget * widget, VolumeALSAPlugin * vol);
72 static void volumealsa_build_popup_window(Plugin * p);
73 static int volumealsa_constructor(Plugin * p, char ** fp);
74 static void volumealsa_destructor(Plugin * p);
75 static void volumealsa_panel_configuration_changed(Plugin * p);
76
77 /*** ALSA ***/
78
79 static gboolean asound_find_element(VolumeALSAPlugin * vol, const char * ename)
80 {
81 for (
82 vol->master_element = snd_mixer_first_elem(vol->mixer);
83 vol->master_element != NULL;
84 vol->master_element = snd_mixer_elem_next(vol->master_element))
85 {
86 snd_mixer_selem_get_id(vol->master_element, vol->sid);
87 if ((snd_mixer_selem_is_active(vol->master_element))
88 && (strcmp(ename, snd_mixer_selem_id_get_name(vol->sid)) == 0))
89 return TRUE;
90 }
91 return FALSE;
92 }
93
94 /* NOTE by PCMan:
95 * This is magic! Since ALSA uses its own machanism to handle this part.
96 * After polling of mixer fds, it requires that we should call
97 * snd_mixer_handle_events to clear all pending mixer events.
98 * However, when using the glib IO channels approach, we don't have
99 * poll() and snd_mixer_poll_descriptors_revents(). Due to the design of
100 * glib, on_mixer_event() will be called for every fd whose status was
101 * changed. So, after each poll(), it's called for several times,
102 * not just once. Therefore, we cannot call snd_mixer_handle_events()
103 * directly in the event handler. Otherwise, it will get called for
104 * several times, which might clear unprocessed pending events in the queue.
105 * So, here we call it once in the event callback for the first fd.
106 * Then, we don't call it for the following fds. After all fds with changed
107 * status are handled, we remove this restriction in an idle handler.
108 * The next time the event callback is involked for the first fs, we can
109 * call snd_mixer_handle_events() again. Racing shouldn't happen here
110 * because the idle handler has the same priority as the io channel callback.
111 * So, io callbacks for future pending events should be in the next gmain
112 * iteration, and won't be affected.
113 */
114
115 static gboolean asound_reset_mixer_evt_idle(VolumeALSAPlugin * vol)
116 {
117 vol->mixer_evt_idle = 0;
118 return FALSE;
119 }
120
121 /* Handler for I/O event on ALSA channel. */
122 static gboolean asound_mixer_event(GIOChannel * channel, GIOCondition cond, gpointer vol_gpointer)
123 {
124 VolumeALSAPlugin * vol = (VolumeALSAPlugin *) vol_gpointer;
125 int res = 0;
126
127 if (vol->mixer_evt_idle == 0)
128 {
129 vol->mixer_evt_idle = g_idle_add_full(G_PRIORITY_DEFAULT, (GSourceFunc) asound_reset_mixer_evt_idle, vol, NULL);
130 res = snd_mixer_handle_events(vol->mixer);
131 }
132
133 if (cond & G_IO_IN)
134 {
135 /* the status of mixer is changed. update of display is needed. */
136 volumealsa_update_display(vol);
137 }
138
139 if ((cond & G_IO_HUP) || (res < 0))
140 {
141 /* This means there're some problems with alsa. */
142 ERR("volumealsa: ALSA (or pulseaudio) had a problem: \n"
143 "volumealsa: snd_mixer_handle_events() = %d,"
144 " cond 0x%x (IN: 0x%x, HUP: 0x%x).\n", res, cond,
145 G_IO_IN, G_IO_HUP);
146 gtk_widget_set_tooltip_text(vol->plugin->pwid, "ALSA (or pulseaudio) had a problem."
147 " Please check the lxpanel logs.");
148 return FALSE;
149 }
150
151 return TRUE;
152 }
153
154 /* Initialize the ALSA interface. */
155 static gboolean asound_initialize(VolumeALSAPlugin * vol)
156 {
157 /* Access the "default" device. */
158 snd_mixer_selem_id_alloca(&vol->sid);
159 snd_mixer_open(&vol->mixer, 0);
160 snd_mixer_attach(vol->mixer, "default");
161 snd_mixer_selem_register(vol->mixer, NULL, NULL);
162 snd_mixer_load(vol->mixer);
163
164 /* Find Master element, or Front element, or PCM element, or LineOut element.
165 * If one of these succeeds, master_element is valid. */
166 if ( ! asound_find_element(vol, "Master"))
167 if ( ! asound_find_element(vol, "Front"))
168 if ( ! asound_find_element(vol, "PCM"))
169 if ( ! asound_find_element(vol, "LineOut"))
170 return FALSE;
171
172 /* Set the playback volume range as we wish it. */
173 snd_mixer_selem_set_playback_volume_range(vol->master_element, 0, 100);
174
175 /* Listen to events from ALSA. */
176 int n_fds = snd_mixer_poll_descriptors_count(vol->mixer);
177 struct pollfd * fds = g_new0(struct pollfd, n_fds);
178
179 snd_mixer_poll_descriptors(vol->mixer, fds, n_fds);
180 int i;
181 for (i = 0; i < n_fds; ++i)
182 {
183 GIOChannel* channel = g_io_channel_unix_new(fds[i].fd);
184 g_io_add_watch(channel, G_IO_IN | G_IO_HUP, asound_mixer_event, vol);
185 g_io_channel_unref(channel);
186 }
187 g_free(fds);
188 return TRUE;
189 }
190
191 /* Get the presence of the mute control from the sound system. */
192 static gboolean asound_has_mute(VolumeALSAPlugin * vol)
193 {
194 return ((vol->master_element != NULL) ? snd_mixer_selem_has_playback_switch(vol->master_element) : FALSE);
195 }
196
197 /* Get the condition of the mute control from the sound system. */
198 static gboolean asound_is_muted(VolumeALSAPlugin * vol)
199 {
200 /* The switch is on if sound is not muted, and off if the sound is muted.
201 * Initialize so that the sound appears unmuted if the control does not exist. */
202 int value = 1;
203 if (vol->master_element != NULL)
204 snd_mixer_selem_get_playback_switch(vol->master_element, 0, &value);
205 return (value == 0);
206 }
207
208 /* Get the volume from the sound system.
209 * This implementation returns the average of the Front Left and Front Right channels. */
210 static int asound_get_volume(VolumeALSAPlugin * vol)
211 {
212 long aleft = 0;
213 long aright = 0;
214 if (vol->master_element != NULL)
215 {
216 snd_mixer_selem_get_playback_volume(vol->master_element, SND_MIXER_SCHN_FRONT_LEFT, &aleft);
217 snd_mixer_selem_get_playback_volume(vol->master_element, SND_MIXER_SCHN_FRONT_RIGHT, &aright);
218 }
219 return (aleft + aright) >> 1;
220 }
221
222 /* Set the volume to the sound system.
223 * This implementation sets the Front Left and Front Right channels to the specified value. */
224 static void asound_set_volume(VolumeALSAPlugin * vol, int volume)
225 {
226 if (vol->master_element != NULL)
227 {
228 snd_mixer_selem_set_playback_volume(vol->master_element, SND_MIXER_SCHN_FRONT_LEFT, volume);
229 snd_mixer_selem_set_playback_volume(vol->master_element, SND_MIXER_SCHN_FRONT_RIGHT, volume);
230 }
231 }
232
233 /*** Graphics ***/
234
235 /* Do a full redraw of the display. */
236 static void volumealsa_update_display(VolumeALSAPlugin * vol)
237 {
238 /* Mute status. */
239 gboolean mute = asound_is_muted(vol);
240 int level = asound_get_volume(vol);
241
242 /* Change icon according to mute / volume */
243 const char* icon="audio-volume-muted";
244 const char* icon_panel="audio-volume-muted-panel";
245 const char* icon_fallback=ICONS_MUTE;
246 if (mute)
247 {
248 icon_panel = "audio-volume-muted-panel";
249 icon="audio-volume-muted";
250 icon_fallback=ICONS_MUTE;
251 }
252 else if (level >= 75)
253 {
254 icon_panel = "audio-volume-high-panel";
255 icon="audio-volume-high";
256 icon_fallback=ICONS_VOLUME_HIGH;
257 }
258 else if (level >= 50)
259 {
260 icon_panel = "audio-volume-medium-panel";
261 icon="audio-volume-medium";
262 icon_fallback=ICONS_VOLUME_MEDIUM;
263 }
264 else if (level > 0)
265 {
266 icon_panel = "audio-volume-low-panel";
267 icon="audio-volume-low";
268 icon_fallback=ICONS_VOLUME_LOW;
269 }
270
271 /* Change icon, fallback to default icon if theme doesn't exsit */
272 if ( ! panel_image_set_icon_theme(vol->plugin->panel, vol->tray_icon, icon_panel))
273 {
274 if ( ! panel_image_set_icon_theme(vol->plugin->panel, vol->tray_icon, icon))
275 {
276 panel_image_set_from_file(vol->plugin->panel, vol->tray_icon, icon_fallback);
277 }
278 }
279
280 g_signal_handler_block(vol->mute_check, vol->mute_check_handler);
281 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(vol->mute_check), mute);
282 gtk_widget_set_sensitive(vol->mute_check, asound_has_mute(vol));
283 g_signal_handler_unblock(vol->mute_check, vol->mute_check_handler);
284
285 /* Volume. */
286 if (vol->volume_scale != NULL)
287 {
288 g_signal_handler_block(vol->volume_scale, vol->volume_scale_handler);
289 gtk_range_set_value(GTK_RANGE(vol->volume_scale), asound_get_volume(vol));
290 g_signal_handler_unblock(vol->volume_scale, vol->volume_scale_handler);
291 }
292
293 /* Display current level in tooltip. */
294 char * tooltip = g_strdup_printf("%s %d", _("Volume control"), level);
295 gtk_widget_set_tooltip_text(vol->plugin->pwid, tooltip);
296 g_free(tooltip);
297 }
298
299 /* Handler for "button-press-event" signal on main widget. */
300 static gboolean volumealsa_button_press_event(GtkWidget * widget, GdkEventButton * event, VolumeALSAPlugin * vol)
301 {
302 /* Standard right-click handling. */
303 if (plugin_button_press_event(widget, event, vol->plugin))
304 return TRUE;
305
306 /* Left-click. Show or hide the popup window. */
307 if (event->button == 1)
308 {
309 if (vol->show_popup)
310 {
311 gtk_widget_hide(vol->popup_window);
312 vol->show_popup = FALSE;
313 }
314 else
315 {
316 gtk_widget_show_all(vol->popup_window);
317 vol->show_popup = TRUE;
318 }
319 }
320
321 /* Middle-click. Toggle the mute status. */
322 else if (event->button == 2)
323 {
324 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(vol->mute_check), ! gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(vol->mute_check)));
325 }
326 return TRUE;
327 }
328
329 /* Handler for "focus-out" signal on popup window. */
330 static gboolean volumealsa_popup_focus_out(GtkWidget * widget, GdkEvent * event, VolumeALSAPlugin * vol)
331 {
332 /* Hide the widget. */
333 gtk_widget_hide(vol->popup_window);
334 vol->show_popup = FALSE;
335 return FALSE;
336 }
337
338 /* Handler for "map" signal on popup window. */
339 static void volumealsa_popup_map(GtkWidget * widget, VolumeALSAPlugin * vol)
340 {
341 plugin_adjust_popup_position(widget, vol->plugin);
342 }
343
344 /* Handler for "value_changed" signal on popup window vertical scale. */
345 static void volumealsa_popup_scale_changed(GtkRange * range, VolumeALSAPlugin * vol)
346 {
347 /* Reflect the value of the control to the sound system. */
348 asound_set_volume(vol, gtk_range_get_value(range));
349
350 /* Redraw the controls. */
351 volumealsa_update_display(vol);
352 }
353
354 /* Handler for "scroll-event" signal on popup window vertical scale. */
355 static void volumealsa_popup_scale_scrolled(GtkScale * scale, GdkEventScroll * evt, VolumeALSAPlugin * vol)
356 {
357 /* Get the state of the vertical scale. */
358 gdouble val = gtk_range_get_value(GTK_RANGE(vol->volume_scale));
359
360 /* Dispatch on scroll direction to update the value. */
361 if ((evt->direction == GDK_SCROLL_UP) || (evt->direction == GDK_SCROLL_LEFT))
362 val += 2;
363 else
364 val -= 2;
365
366 /* Reset the state of the vertical scale. This provokes a "value_changed" event. */
367 gtk_range_set_value(GTK_RANGE(vol->volume_scale), CLAMP((int)val, 0, 100));
368 }
369
370 /* Handler for "toggled" signal on popup window mute checkbox. */
371 static void volumealsa_popup_mute_toggled(GtkWidget * widget, VolumeALSAPlugin * vol)
372 {
373 /* Get the state of the mute toggle. */
374 gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
375
376 /* Reflect the mute toggle to the sound system. */
377 if (vol->master_element != NULL)
378 {
379 int chn;
380 for (chn = 0; chn <= SND_MIXER_SCHN_LAST; chn++)
381 snd_mixer_selem_set_playback_switch(vol->master_element, chn, ((active) ? 0 : 1));
382 }
383
384 /* Redraw the controls. */
385 volumealsa_update_display(vol);
386 }
387
388 /* Build the window that appears when the top level widget is clicked. */
389 static void volumealsa_build_popup_window(Plugin * p)
390 {
391 VolumeALSAPlugin * vol = p->priv;
392
393 /* Create a new window. */
394 vol->popup_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
395 gtk_window_set_decorated(GTK_WINDOW(vol->popup_window), FALSE);
396 gtk_container_set_border_width(GTK_CONTAINER(vol->popup_window), 5);
397 gtk_window_set_default_size(GTK_WINDOW(vol->popup_window), 80, 140);
398 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(vol->popup_window), TRUE);
399 gtk_window_set_skip_pager_hint(GTK_WINDOW(vol->popup_window), TRUE);
400 gtk_window_set_type_hint(GTK_WINDOW(vol->popup_window), GDK_WINDOW_TYPE_HINT_DIALOG);
401
402 /* Connect signals. */
403 g_signal_connect(G_OBJECT(vol->popup_window), "focus_out_event", G_CALLBACK(volumealsa_popup_focus_out), vol);
404 g_signal_connect(G_OBJECT(vol->popup_window), "map", G_CALLBACK(volumealsa_popup_map), vol);
405
406 /* Create a scrolled window as the child of the top level window. */
407 GtkWidget * scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
408 gtk_container_set_border_width (GTK_CONTAINER(scrolledwindow), 0);
409 gtk_widget_show(scrolledwindow);
410 gtk_container_add(GTK_CONTAINER(vol->popup_window), scrolledwindow);
411 GTK_WIDGET_UNSET_FLAGS(scrolledwindow, GTK_CAN_FOCUS);
412 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
413 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow), GTK_SHADOW_NONE);
414
415 /* Create a viewport as the child of the scrolled window. */
416 GtkWidget * viewport = gtk_viewport_new(NULL, NULL);
417 gtk_container_add(GTK_CONTAINER(scrolledwindow), viewport);
418 gtk_viewport_set_shadow_type(GTK_VIEWPORT(viewport), GTK_SHADOW_NONE);
419 gtk_widget_show(viewport);
420
421 /* Create a frame as the child of the viewport. */
422 GtkWidget * frame = gtk_frame_new(_("Volume"));
423 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
424 gtk_container_add(GTK_CONTAINER(viewport), frame);
425
426 /* Create a vertical box as the child of the frame. */
427 GtkWidget * box = gtk_vbox_new(FALSE, 0);
428 gtk_container_add(GTK_CONTAINER(frame), box);
429
430 /* Create a vertical scale as the child of the vertical box. */
431 vol->volume_scale = gtk_vscale_new(GTK_ADJUSTMENT(gtk_adjustment_new(100, 0, 100, 0, 0, 0)));
432 gtk_scale_set_draw_value(GTK_SCALE(vol->volume_scale), FALSE);
433 gtk_range_set_inverted(GTK_RANGE(vol->volume_scale), TRUE);
434 gtk_box_pack_start(GTK_BOX(box), vol->volume_scale, TRUE, TRUE, 0);
435
436 /* Value-changed and scroll-event signals. */
437 vol->volume_scale_handler = g_signal_connect(vol->volume_scale, "value_changed", G_CALLBACK(volumealsa_popup_scale_changed), vol);
438 g_signal_connect(vol->volume_scale, "scroll-event", G_CALLBACK(volumealsa_popup_scale_scrolled), vol);
439
440 /* Create a check button as the child of the vertical box. */
441 vol->mute_check = gtk_check_button_new_with_label(_("Mute"));
442 gtk_box_pack_end(GTK_BOX(box), vol->mute_check, FALSE, FALSE, 0);
443 vol->mute_check_handler = g_signal_connect(vol->mute_check, "toggled", G_CALLBACK(volumealsa_popup_mute_toggled), vol);
444
445 /* Set background to default. */
446 gtk_widget_set_style(viewport, p->panel->defstyle);
447 }
448
449 /* Plugin constructor. */
450 static int volumealsa_constructor(Plugin * p, char ** fp)
451 {
452 /* Allocate and initialize plugin context and set into Plugin private data pointer. */
453 VolumeALSAPlugin * vol = g_new0(VolumeALSAPlugin, 1);
454 vol->plugin = p;
455 p->priv = vol;
456
457 /* Initialize ALSA. If that fails, present nothing. */
458 if ( ! asound_initialize(vol))
459 return 1;
460
461 /* Allocate top level widget and set into Plugin widget pointer. */
462 p->pwid = gtk_event_box_new();
463 gtk_widget_add_events(p->pwid, GDK_BUTTON_PRESS_MASK);
464 gtk_widget_set_tooltip_text(p->pwid, _("Volume control"));
465
466 /* Allocate icon as a child of top level. */
467 vol->tray_icon = gtk_image_new();
468 gtk_container_add(GTK_CONTAINER(p->pwid), vol->tray_icon);
469
470 /* Initialize window to appear when icon clicked. */
471 volumealsa_build_popup_window(p);
472
473 /* Connect signals. */
474 g_signal_connect(G_OBJECT(p->pwid), "button-press-event", G_CALLBACK(volumealsa_button_press_event), vol);
475 g_signal_connect(G_OBJECT(p->pwid), "scroll-event", G_CALLBACK(volumealsa_popup_scale_scrolled), vol );
476
477 /* Update the display, show the widget, and return. */
478 volumealsa_update_display(vol);
479 gtk_widget_show_all(p->pwid);
480 return 1;
481 }
482
483 /* Plugin destructor. */
484 static void volumealsa_destructor(Plugin * p)
485 {
486 VolumeALSAPlugin * vol = (VolumeALSAPlugin *) p->priv;
487
488 /* Remove the periodic timer. */
489 if (vol->mixer_evt_idle != 0)
490 g_source_remove(vol->mixer_evt_idle);
491
492 /* If the dialog box is open, dismiss it. */
493 if (vol->popup_window != NULL)
494 gtk_widget_destroy(vol->popup_window);
495
496 /* Deallocate all memory. */
497 g_free(vol);
498 }
499
500 /* Callback when the configuration dialog is to be shown. */
501
502 static void volumealsa_configure(Plugin * p, GtkWindow * parent)
503 {
504
505 GdkScreen *screen = gdk_screen_get_default();
506 GError *error = NULL;
507 const gchar *command_line = NULL;
508
509 if (g_find_program_in_path("pulseaudio"))
510 {
511 /* Assume that when pulseaudio is installed, it's launching every time */
512 if (g_find_program_in_path("gnome-sound-applet"))
513 {
514 command_line = "gnome-sound-applet";
515 }
516 else
517 {
518 if (g_find_program_in_path("pavucontrol"))
519 {
520 command_line = "pavucontrol";
521 }
522 }
523 }
524
525 /* Fallback to alsamixer when PA is not running, or when no PA utility is find */
526 if (command_line == NULL)
527 {
528 if (g_find_program_in_path("gnome-alsamixer"))
529 {
530 command_line = "gnome-alsamixer";
531 }
532 else
533 {
534 if (g_find_program_in_path("alsamixer"))
535 {
536 if (g_find_program_in_path("xterm"))
537 {
538 command_line = "xterm -e alsamixer";
539 }
540 }
541 }
542 }
543
544 if (command_line)
545 {
546 gdk_spawn_command_line_on_screen(screen,
547 command_line,
548 &error);
549 }
550 else
551 {
552
553 GtkWidget* msg;
554
555 msg = gtk_message_dialog_new( NULL,
556 0,
557 GTK_MESSAGE_ERROR,
558 GTK_BUTTONS_OK,
559 (_("Error, you need to install an application to configure the sound (pavucontol, alsamixer ...)")) );
560 gtk_dialog_run( GTK_DIALOG(msg) );
561 gtk_widget_destroy( msg );
562
563 }
564
565 if (error)
566 {
567 g_print("%s\n", error->message);
568 g_free (error);
569 }
570
571 }
572
573 /* Callback when panel configuration changes. */
574 static void volumealsa_panel_configuration_changed(Plugin * p)
575 {
576 /* Do a full redraw. */
577 volumealsa_update_display((VolumeALSAPlugin *) p->priv);
578 }
579
580 /* Plugin descriptor. */
581 PluginClass volumealsa_plugin_class = {
582
583 PLUGINCLASS_VERSIONING,
584
585 type : "volumealsa",
586 name : N_("Volume Control"),
587 version: "1.0",
588 description : "Display and control volume for ALSA",
589
590 constructor : volumealsa_constructor,
591 destructor : volumealsa_destructor,
592 config :volumealsa_configure,
593 save : NULL,
594 panel_configuration_changed : volumealsa_panel_configuration_changed
595
596 };
597
598 /* vim: set sw=4 et sts=4 : */