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
, buffer
;
45 Atom wm_delete_window_atom
, wm_protocol_atom
;
49 Pixel
GetColor(char *ColorName
, Display
* disp
, Window win
)
52 XWindowAttributes Attributes
;
54 XGetWindowAttributes(disp
, win
, &Attributes
);
57 if (!XParseColor(disp
, Attributes
.colormap
, ColorName
, &Color
))
58 printf("wmradio: can't parse %s\n", ColorName
);
59 else if (!XAllocColor(disp
, Attributes
.colormap
, &Color
))
60 printf("wmradio: can't allocate %s\n", ColorName
);
65 int parse_command_line(int argc
, char *argv
[],RadioInfo
*info
)
67 static struct option long_options
[] = {
68 {"dont-quit-mode",0,0,0}, /* 0 */
69 {"start-muted",0,0,0},
74 {"osd-font",1,0,0}, /* 5 */
76 {"osd-position",1,0,0},
77 {"osd-shadow-offset",1,0,0},
78 {"osd-timeout",1,0,0},
86 int x
,y
,offset
,timeout
;
89 opt
= getopt_long(argc
,argv
,"qmhvof:c:p:s:t:k:",long_options
, &option_index
);
90 if( opt
== -1 ) break;
91 if( opt
== 0 ) opt
= option_index
;
95 info
->dont_quit_mode
= 1;
96 rc_set_variable_as_int(SECTION_CONFIG
,"dont-quit-mode",1);
100 rc_set_variable_as_int(SECTION_CONFIG
,"start-muted",1);
104 printf("wmradio [options]\n"
106 " -h|--help print this help\n"
107 " -m|--start-muted program starts, but doesn't open radio device\n"
108 " -q|--dont-quit-mode program doesn't quit, just close radio device\n"
109 " -v|--version print version and quit\n"
110 " -o|--osd use osd\n"
111 " -f|--osd-font font osd font\n"
112 " -c|--osd-color font color\n"
113 " -p|--osd-position display position (-p 10x30 for example)\n"
114 " -s|--osd-shadow-offset shadow offset\n"
115 " -t|--osd-timeout osd timeout\n"
121 printf("This is %s %s\n", PACKAGE
,VERSION
);
125 rc_set_variable_as_int(SECTION_CONFIG
,"osd",1);
129 rc_set_variable(SECTION_CONFIG
,"osd-font",optarg
);
133 rc_set_variable(SECTION_CONFIG
,"osd-color",optarg
);
137 if (sscanf(optarg
,"%ix%i", &x
, &y
) < 2) {
138 fprintf(stderr
, "%s: incorrect syntax in OSD position\n", argv
[0]);
140 rc_set_variable_as_int(SECTION_CONFIG
,"osd-position",x
);
141 /* rc_set_variable_as_int(SECTION_CONFIG,"osd-position",y); */
146 if (sscanf(optarg
,"%i", &offset
) < 1) {
147 fprintf(stderr
, "%s: incorrect syntax in OSD shadow offset\n", argv
[0]);
149 rc_set_variable_as_int(SECTION_CONFIG
,"osd-shadow-offset",offset
);
154 if (sscanf(optarg
,"%i", &timeout
) < 1) {
155 fprintf(stderr
, "%s: incorrect syntax in OSD timeout\n", argv
[0]);
157 rc_set_variable_as_int(SECTION_CONFIG
,"osd-timeout",timeout
);
162 rc_set_variable(SECTION_CONFIG
,"skin",optarg
);
169 void video_mainloop(void)
176 while (radio_continue
) {
178 while (XPending(main_display
)) {
179 XNextEvent(main_display
, &xe
);
180 /* printf("xe.type = %i\n", xe.type); */
183 re
.type
= REVENT_EXPOSE
;
184 wmradio_handle_event(&re
);
187 if(xe
.xclient
.message_type
== wm_protocol_atom
) {
188 Atom a
= (xe
.xclient
.data
.l
)[0];
189 if( a
== wm_delete_window_atom
) {
190 re
.type
= REVENT_QUIT
;
191 wmradio_handle_event(&re
);
196 re
.type
= REVENT_QUIT
;
197 wmradio_handle_event(&re
);
200 if(xe
.xbutton
.button
< 4) {
201 re
.type
= REVENT_BUTTON_PRESS
;
204 re
.button
= xe
.xbutton
.button
;
205 re
.control
= xe
.xbutton
.state
& ControlMask
?
206 CONTROL_STATE_PRESSED
: CONTROL_STATE_NOT_PRESSED
;
207 re
.shift
= xe
.xbutton
.state
& ShiftMask
?
208 CONTROL_STATE_PRESSED
: CONTROL_STATE_NOT_PRESSED
;
209 wmradio_handle_event(&re
);
213 re
.type
= REVENT_BUTTON_RELEASE
;
216 re
.button
= xe
.xbutton
.button
;
217 re
.control
= xe
.xbutton
.state
& ControlMask
?
218 CONTROL_STATE_PRESSED
: CONTROL_STATE_NOT_PRESSED
;
219 re
.shift
= xe
.xbutton
.state
& ShiftMask
?
220 CONTROL_STATE_PRESSED
: CONTROL_STATE_NOT_PRESSED
;
221 if(re
.button
== 4) re
.type
= REVENT_SCROLL_UP
;
222 if(re
.button
== 5) re
.type
= REVENT_SCROLL_DOWN
;
223 wmradio_handle_event(&re
);
228 re
.type
= REVENT_TIMER
;
229 wmradio_handle_event(&re
);
230 for(i
= 0; i
<10; i
++){
232 if(XPending(main_display
)) i
=1000;
236 XCloseDisplay(main_display
);
239 void video_close(void)
244 void video_draw(float freq
,int stereo
)
246 skin_to_window(main_display
,buffer
, NormalGC
,freq
,stereo
);
247 XCopyArea(main_display
,buffer
, applet
, NormalGC
,0,0,skin_width(),skin_height(),0,0);
250 int main(int argc
, char *argv
[])
252 Pixel foreground
,background
;
254 XClassHint classhint
;
257 char * appletname
= "WmRadio";
261 wmradio_init_radio_info();
263 parse_command_line(argc
,argv
,wmradio_radio_info());
264 main_display
= XOpenDisplay(NULL
);
266 printf("wmradio: can't open display %s.\n",XDisplayName(NULL
));
269 screen
= DefaultScreen(main_display
);
270 root
= RootWindow(main_display
,screen
);
272 background
= GetColor("black", main_display
, root
);
273 foreground
= GetColor("white", main_display
, root
);
274 create_skin(rc_get_variable(SECTION_CONFIG
,"skin","default.skin"),main_display
,root
);
276 applet
= XCreateSimpleWindow(main_display
,
278 0,0,skin_width(),skin_height(),
280 foreground
,background
);
281 buffer
= XCreatePixmap(main_display
,
283 skin_width(),skin_height(),
284 DefaultDepth(main_display
,screen
)/*16 color_depth */);
286 status
= XStringListToTextProperty(&appletname
, 1, &title
);
287 XSetWMName(main_display
, applet
, &title
);
288 classhint
.res_name
= "wmradio" ;
289 classhint
.res_class
= "WMRADIO";
290 XSetClassHint(main_display
, applet
, &classhint
);
293 sh
.min_width
= sh
.max_width
=skin_width();
294 sh
.min_height
= sh
.max_height
= skin_height();
295 sh
.flags
= PResizeInc
| PMinSize
| PMaxSize
;
296 XSetWMNormalHints(main_display
,applet
,&sh
);
297 XStoreName(main_display
, applet
, "WmRadio");
298 XSetIconName(main_display
, applet
, "WmRadio");
300 status
= XMapWindow(main_display
, applet
);
301 gcm
= GCForeground
| GCBackground
| GCGraphicsExposures
;
302 gcv
.foreground
= foreground
;
303 gcv
.background
= background
;
304 gcv
.graphics_exposures
= 0;
305 NormalGC
= XCreateGC(main_display
, root
, gcm
, &gcv
);
306 wm_delete_window_atom
= XInternAtom(main_display
, "WM_DELETE_WINDOW", 0);
307 wm_protocol_atom
= XInternAtom(main_display
, "WM_PROTOCOLS", 0);
308 XSetWMProtocols(main_display
, applet
, &wm_delete_window_atom
, 1);
309 XSelectInput(main_display
, applet
,
310 ButtonPressMask
| ExposureMask
|
311 ButtonReleaseMask
| PointerMotionMask
|
312 StructureNotifyMask
);