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.
21 #include <sys/types.h>
34 #include "wm_envelope.h"
39 Display
*main_display
= 0;
40 Window root
, applet
, icon
, buffer
;
48 Atom wm_delete_window_atom
, wm_protocol_atom
;
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
);
66 int parse_command_line(int argc
, char *argv
[],RadioInfo
*info
)
68 static struct option long_options
[] = {
69 {"dont-quit-mode",0,0,0}, /* 0 */
70 {"start-muted",0,0,0},
75 {"osd-font",1,0,0}, /* 5 */
77 {"osd-position",1,0,0},
78 {"osd-shadow-offset",1,0,0},
79 {"osd-timeout",1,0,0},
87 int x
,y
,offset
,timeout
;
90 opt
= getopt_long(argc
,argv
,"qmhvof:c:p:s:t:k:",long_options
, &option_index
);
91 if( opt
== -1 ) break;
92 if( opt
== 0 ) opt
= option_index
;
96 info
->dont_quit_mode
= 1;
97 rc_set_variable_as_int(SECTION_CONFIG
,"dont-quit-mode",1);
101 rc_set_variable_as_int(SECTION_CONFIG
,"start-muted",1);
105 printf("wmradio [options]\n"
107 " -h|--help print this help\n"
108 " -m|--start-muted program starts, but doesn't open radio device\n"
109 " -q|--dont-quit-mode program doesn't quit, just close radio device\n"
110 " -v|--version print version and quit\n"
111 " -o|--osd use osd\n"
112 " -f|--osd-font font osd font\n"
113 " -c|--osd-color font color\n"
114 " -p|--osd-position display position (-p 10x30 for example)\n"
115 " -s|--osd-shadow-offset shadow offset\n"
116 " -t|--osd-timeout osd timeout\n"
122 printf("This is %s %s\n", PACKAGE
,VERSION
);
126 rc_set_variable_as_int(SECTION_CONFIG
,"osd",1);
130 rc_set_variable(SECTION_CONFIG
,"osd-font",optarg
);
134 rc_set_variable(SECTION_CONFIG
,"osd-color",optarg
);
138 if (sscanf(optarg
,"%ix%i", &x
, &y
) < 2) {
139 fprintf(stderr
, "%s: incorrect syntax in OSD position\n", argv
[0]);
141 rc_set_variable_as_int(SECTION_CONFIG
,"osd-position",x
);
142 /* rc_set_variable_as_int(SECTION_CONFIG,"osd-position",y); */
147 if (sscanf(optarg
,"%i", &offset
) < 1) {
148 fprintf(stderr
, "%s: incorrect syntax in OSD shadow offset\n", argv
[0]);
150 rc_set_variable_as_int(SECTION_CONFIG
,"osd-shadow-offset",offset
);
155 if (sscanf(optarg
,"%i", &timeout
) < 1) {
156 fprintf(stderr
, "%s: incorrect syntax in OSD timeout\n", argv
[0]);
158 rc_set_variable_as_int(SECTION_CONFIG
,"osd-timeout",timeout
);
163 rc_set_variable(SECTION_CONFIG
,"skin",optarg
);
170 void video_mainloop(void)
176 while (radio_continue
) {
178 while (XPending(main_display
)) {
179 XNextEvent(main_display
, &xe
);
182 re
.type
= REVENT_EXPOSE
;
183 wmradio_handle_event(&re
);
186 if(xe
.xclient
.message_type
== wm_protocol_atom
) {
187 Atom a
= (xe
.xclient
.data
.l
)[0];
188 if( a
== wm_delete_window_atom
) {
189 re
.type
= REVENT_QUIT
;
191 wmradio_handle_event(&re
);
196 re
.type
= REVENT_QUIT
;
197 wmradio_handle_event(&re
);
201 if(xe
.xbutton
.button
< 4) {
202 re
.type
= REVENT_BUTTON_PRESS
;
203 if(xe
.xbutton
.button
== 4) re
.type
= REVENT_SCROLL_UP
;
204 if(xe
.xbutton
.button
== 5) re
.type
= REVENT_SCROLL_DOWN
;
207 re
.button
= xe
.xbutton
.button
;
208 re
.control
= xe
.xbutton
.state
& ControlMask
?
209 CONTROL_STATE_PRESSED
: CONTROL_STATE_NOT_PRESSED
;
210 re
.shift
= xe
.xbutton
.state
& ShiftMask
?
211 CONTROL_STATE_PRESSED
: CONTROL_STATE_NOT_PRESSED
;
212 wmradio_handle_event(&re
);
216 re
.type
= REVENT_BUTTON_RELEASE
;
219 re
.button
= xe
.xbutton
.button
;
220 re
.control
= xe
.xbutton
.state
& ControlMask
?
221 CONTROL_STATE_PRESSED
: CONTROL_STATE_NOT_PRESSED
;
222 re
.shift
= xe
.xbutton
.state
& ShiftMask
?
223 CONTROL_STATE_PRESSED
: CONTROL_STATE_NOT_PRESSED
;
224 if(re
.button
== 4) re
.type
= REVENT_SCROLL_UP
;
225 if(re
.button
== 5) re
.type
= REVENT_SCROLL_DOWN
;
226 wmradio_handle_event(&re
);
231 re
.type
= REVENT_TIMER
;
232 wmradio_handle_event(&re
);
234 XCloseDisplay(main_display
);
237 void video_close(void)
242 void video_draw(float freq
,int stereo
)
244 skin_to_window(main_display
,buffer
, NormalGC
,freq
,stereo
);
245 XCopyArea(main_display
,buffer
, icon
, NormalGC
,0,0,skin_width(),skin_height(),0,0);
246 XCopyArea(main_display
,buffer
, applet
, NormalGC
,0,0,skin_width(),skin_height(),0,0);
249 int main(int argc
, char *argv
[])
251 Pixel foreground
,background
;
254 XClassHint classhint
;
257 char * appletname
= "WmRadio";
259 wmradio_init_radio_info();
261 parse_command_line(argc
,argv
,wmradio_radio_info());
263 main_display
= XOpenDisplay(NULL
);
265 printf("wmradio: can't open display %s.\n",XDisplayName(NULL
));
268 screen
= DefaultScreen(main_display
);
269 root
= RootWindow(main_display
,screen
);
271 background
= GetColor("black", main_display
, root
);
272 foreground
= GetColor("white", main_display
, root
);
273 create_skin(rc_get_variable(SECTION_CONFIG
,"skin","default.skin"),main_display
,root
);
275 applet
= XCreateSimpleWindow(main_display
,
277 0,0,skin_width(),skin_height(),
279 foreground
,background
);
280 icon
= XCreateSimpleWindow(main_display
,
282 0,0,skin_width(),skin_height(),
284 foreground
,background
);
285 WmHints
.flags
= StateHint
| IconWindowHint
;
286 WmHints
.initial_state
= WithdrawnState
;
287 WmHints
.icon_window
= icon
;
288 WmHints
.window_group
= applet
;
289 WmHints
.flags
|= WindowGroupHint
;
291 XSetWMHints(main_display
,
295 buffer
= XCreatePixmap(main_display
,
297 skin_width(),skin_height(),
298 DefaultDepth(main_display
,screen
)/*16 color_depth */);
300 status
= XStringListToTextProperty(&appletname
, 1, &title
);
301 XSetWMName(main_display
, applet
, &title
);
302 XSetWMName(main_display
, icon
, &title
);
303 classhint
.res_name
= "wmradio" ;
304 classhint
.res_class
= "WMRADIO";
305 XSetClassHint(main_display
, applet
, &classhint
);
306 XStoreName(main_display
, applet
, "WmRadio");
307 XSetIconName(main_display
, applet
, "WmRadio");
309 wm_delete_window_atom
= XInternAtom(main_display
, "WM_DELETE_WINDOW", 0);
310 wm_protocol_atom
= XInternAtom(main_display
, "WM_PROTOCOLS", 0);
311 XSetWMProtocols(main_display
, applet
, &wm_delete_window_atom
, 1);
313 status
= XMapWindow(main_display
, applet
);
314 gcm
= GCForeground
| GCBackground
| GCGraphicsExposures
;
315 gcv
.foreground
= foreground
;
316 gcv
.background
= background
;
317 gcv
.graphics_exposures
= 0;
318 NormalGC
= XCreateGC(main_display
, root
, gcm
, &gcv
);
319 XSelectInput(main_display
, applet
,
320 ButtonPressMask
| ExposureMask
|
321 ButtonReleaseMask
| PointerMotionMask
|
322 StructureNotifyMask
);
323 XSelectInput(main_display
, icon
,
324 ButtonPressMask
| ExposureMask
|
325 ButtonReleaseMask
| PointerMotionMask
|
326 StructureNotifyMask
);