2 * Copyright (C) 12 Jun 2003 Tomas Cermak
4 * This file is part of wmradio program.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <panel-applet.h>
25 #include <gdk/gdkprivate.h>
28 #include "gnome_applet_envelope.h"
44 f
= fopen("/tmp/wmradio.log","a");
50 Pixel
GetColor(char *ColorName
, Display
* disp
, Window win
)
53 XWindowAttributes Attributes
;
55 XGetWindowAttributes(disp
, win
, &Attributes
);
58 if (!XParseColor(disp
, Attributes
.colormap
, ColorName
, &Color
))
59 printf("wmradio: can't parse %s\n", ColorName
);
60 else if (!XAllocColor(disp
, Attributes
.colormap
, &Color
))
61 printf("wmradio: can't allocate %s\n", ColorName
);
67 void gtk_drawing_area_copy_from_X11_drawable(GtkDrawingArea
*DA
,
71 unsigned int width
, unsigned int height
,
76 g_return_if_fail( DA
!= NULL
);
77 g_return_if_fail( X11
!= 0 );
79 gdkwindow
= GDK_WINDOW(GTK_WIDGET(DA
)->window
);
80 if(!GDK_WINDOW_DESTROYED( gdkwindow
) ) {
81 XCopyArea(GDK_DISPLAY(),
83 GDK_WINDOW_XWINDOW(gdkwindow
),
85 srcx
,srcy
,width
,height
,destx
,desty
);
89 gint
on_expose(GtkWidget
*w
, GdkEventExpose
*e
)
93 re
.type
= REVENT_EXPOSE
;
94 wmradio_handle_event(&re
);
98 gint
on_button_press(GtkWidget
*w
, GdkEventButton
*e
)
102 re
.type
= REVENT_BUTTON_PRESS
;
105 re
.control
= e
->state
& GDK_CONTROL_MASK
?
106 CONTROL_STATE_PRESSED
: CONTROL_STATE_NOT_PRESSED
;
107 re
.shift
= e
->state
& GDK_SHIFT_MASK
?
108 CONTROL_STATE_PRESSED
: CONTROL_STATE_NOT_PRESSED
;
109 wmradio_handle_event(&re
);
110 if( e
->button
& 2 ) return FALSE
;
114 gint
on_button_release(GtkWidget
*w
, GdkEventButton
*e
)
118 re
.type
= REVENT_BUTTON_RELEASE
;
121 re
.control
= e
->state
& GDK_CONTROL_MASK
?
122 CONTROL_STATE_PRESSED
: CONTROL_STATE_NOT_PRESSED
;
123 re
.shift
= e
->state
& GDK_SHIFT_MASK
?
124 CONTROL_STATE_PRESSED
: CONTROL_STATE_NOT_PRESSED
;
125 wmradio_handle_event(&re
);
126 if( e
->button
& 2 ) return FALSE
;
130 gint
on_scroll(GtkWidget
*w
, GdkEventScroll
*e
)
134 switch(e
->direction
) {
136 re
.type
= REVENT_SCROLL_UP
;
138 case GDK_SCROLL_DOWN
:
139 re
.type
= REVENT_SCROLL_DOWN
;
146 re
.control
= e
->state
& GDK_CONTROL_MASK
?
147 CONTROL_STATE_PRESSED
: CONTROL_STATE_NOT_PRESSED
;
148 re
.shift
= e
->state
& GDK_SHIFT_MASK
?
149 CONTROL_STATE_PRESSED
: CONTROL_STATE_NOT_PRESSED
;
150 wmradio_handle_event(&re
);
154 gint
on_timer(gpointer data
)
158 re
.type
= REVENT_TIMER
;
159 wmradio_handle_event(&re
);
163 void on_realize(GtkWidget
*widget
, gpointer not_used
)
165 Pixel foreground
,background
;
168 wmradio_init_radio_info();
170 create_skin(rc_get_variable(SECTION_CONFIG
,"skin","gdefault.skin"),
173 gtk_drawing_area_size(GTK_DRAWING_AREA(radio
), skin_width(),skin_height());
174 wmradio_radio_info()->dont_quit_mode
= 1;
175 rc_set_variable_as_int(SECTION_CONFIG
,"start-muted",1);
178 background
= GetColor("black", GDK_DISPLAY(), GDK_ROOT_WINDOW());
179 foreground
= GetColor("white", GDK_DISPLAY(), GDK_ROOT_WINDOW());
180 gcm
= GCForeground
| GCBackground
| GCGraphicsExposures
;
181 gcv
.foreground
= foreground
;
182 gcv
.background
= background
;
183 gcv
.graphics_exposures
= 0;
184 NormalGC
= XCreateGC(GDK_DISPLAY(), GDK_ROOT_WINDOW(), gcm
, &gcv
);
185 screen
= DefaultScreen(GDK_DISPLAY());
186 buffer
= XCreatePixmap(GDK_DISPLAY(),
188 skin_width(),skin_height(),
189 DefaultDepth(GDK_DISPLAY(),screen
)/*16 color_depth */);
190 timer
= gtk_timeout_add(1000,on_timer
,NULL
);
193 GtkWidget
*video_init(void)
195 radio
= gtk_drawing_area_new();
196 gtk_signal_connect(GTK_OBJECT(radio
),"expose-event",
197 GTK_SIGNAL_FUNC(on_expose
),NULL
);
198 gtk_signal_connect(GTK_OBJECT(radio
),"button-press-event",
199 GTK_SIGNAL_FUNC(on_button_press
),NULL
);
200 gtk_signal_connect(GTK_OBJECT(radio
),"button-release-event",
201 GTK_SIGNAL_FUNC(on_button_release
),NULL
);
202 gtk_signal_connect(GTK_OBJECT(radio
),"realize",
203 GTK_SIGNAL_FUNC(on_realize
),NULL
);
204 gtk_signal_connect(GTK_OBJECT(radio
),"scroll-event",
205 GTK_SIGNAL_FUNC(on_scroll
),NULL
);
206 gtk_widget_set_events(radio
,
208 | GDK_BUTTON_PRESS_MASK
209 | GDK_POINTER_MOTION_MASK
210 | GDK_BUTTON_RELEASE_MASK
216 void video_mainloop(void)
218 /*applet_widget_gtk_main();*/
219 gtk_timeout_remove(timer
);
222 void video_close(void)
224 /*applet_widget_remove(APPLET_WIDGET(applet));*/
225 /*applet_widget_gtk_main_quit();*/
228 void video_draw(float freq
,int stereo
)
230 skin_to_window(GDK_DISPLAY(),buffer
, NormalGC
,freq
,stereo
);
231 gtk_drawing_area_copy_from_X11_drawable(
232 GTK_DRAWING_AREA(radio
),
235 0,0,skin_width(),skin_height(),0,0);
238 static gboolean
wmradio_applet_fill(PanelApplet
*applet
,
242 if (strcmp (iid
, "OAFIID:WMRadioApplet") != 0) return FALSE
;
245 gtk_container_add (GTK_CONTAINER (applet
), radio
);
246 gtk_widget_show_all (GTK_WIDGET (applet
));
251 PANEL_APPLET_BONOBO_FACTORY ("OAFIID:WMRadioApplet_Factory",
253 "The WMRadio Applet",
258 /* int main(int argc, char *argv[]) */
260 /* GtkWidget *win; */
262 /* gtk_set_locale(); */
263 /* gtk_init(&argc,&argv); */
265 /* win = gtk_window_new(GTK_WINDOW_TOPLEVEL); */
266 /* radio = video_init(); */
267 /* gtk_container_add (GTK_CONTAINER (win), radio); */
268 /* gtk_widget_show_all(win); */