Remove useless parts.
[lxde/lxpanel.git] / src / plugins / volume / volume.c
CommitLineData
31b80004
JH
1#include <gtk/gtk.h>
2#include <stdlib.h>
3#include <fcntl.h>
4#include <unistd.h>
5
6#include <gdk-pixbuf/gdk-pixbuf.h>
7
8#include "panel.h"
9#include "misc.h"
10#include "plugin.h"
11
12#include "dbg.h"
13
14#include "volume-impl.h"
15
16#include "volume_xpm.h"
17
18int mixer_fd;
19
20typedef struct {
21 GtkWidget *mainw;
22 GtkWidget *dlg;
23} volume_t;
24
25static void
26volume_destructor(plugin *p)
27{
28 volume_t *ns = (volume_t *) p->priv;
29
30 ENTER;
948d4bd7
JH
31 if (ns->dlg)
32 gtk_widget_destroy(ns->dlg);
31b80004
JH
33 gtk_widget_destroy(ns->mainw);
34 if (mixer_fd)
35 close(mixer_fd);
36 g_free(ns);
37 RET();
38}
39
40static void on_volume_focus (GtkWidget* dlg, GdkEventFocus *event, volume_t *ns)
41{
42 /* FIXME: use smarter method */
43 gtk_widget_destroy( dlg );
44 ns->dlg = NULL;
45}
46
47static void on_button_press (GtkWidget* widget, GdkEventButton* evt, plugin* p)
48{
49 volume_t *ns = (volume_t*) p->priv;
50
51 if( evt->button == 1 ) { /* Left click*/
52 if( ! ns->dlg ) {
53 ns->dlg = create_volume_window();
54 g_signal_connect( ns->dlg, "focus-out-event", on_volume_focus, ns );
55 }
56 gtk_window_present( GTK_WINDOW(ns->dlg) );
57 }
58}
59
60static int
61volume_constructor(plugin *p)
62{
63 volume_t *ns;
64 line s;
65 GdkPixbuf *icon;
66 GtkWidget *image;
67
68 ENTER;
69 s.len = 256;
70 ns = g_new0(volume_t, 1);
71 g_return_val_if_fail(ns != NULL, 0);
72 p->priv = ns;
73
74 /* check if OSS mixer device could be open */
75 mixer_fd = open ("/dev/mixer", O_RDWR, 0);
76 if (mixer_fd < 0) {
77 RET(0);
78 }
79
80 ns->mainw = gtk_event_box_new();
81
82 icon = gdk_pixbuf_new_from_xpm_data(volume_xpm);
83 if(icon) {
84 image = gtk_image_new_from_pixbuf(icon);
85 gtk_container_add (GTK_CONTAINER (ns->mainw), image);
86 }
87
88 gtk_widget_add_events( ns->mainw, GDK_BUTTON_PRESS_MASK );
89 g_signal_connect( ns->mainw, "button-press-event",
90 G_CALLBACK(on_button_press), p );
91 gtk_widget_set_size_request( ns->mainw, 24, 24 );
92
948d4bd7 93 ns->dlg = NULL;
31b80004
JH
94 gtk_widget_show_all(ns->mainw);
95
96 gtk_container_add(GTK_CONTAINER(p->pwid), ns->mainw);
97
98 RET(1);
99
100error:
101 volume_destructor(p);
102 RET(0);
103}
104
105
106plugin_class volume_plugin_class = {
107 fname: NULL,
108 count: 0,
109
110 type : "volume",
111 name : "volume",
112 version: "1.0",
113 description : "Display and control volume",
114
115 constructor : volume_constructor,
116 destructor : volume_destructor,
117};