3 * Copyright (c)1999 Patrick Crosby <xb@dotfiles.com>.
4 * This software covered by the GPL. See COPYING file for details.
8 * This is the main body of the application. Handles all initialization
9 * plus the X event loop.
11 * $Id: main.c,v 1.11 1999/10/08 22:21:32 pcrosby Exp $
30 int check_options(int argc
, char *argv
[]);
31 int handle_button_press(int x
, int y
);
32 void handle_button_release(int i
);
41 /* from Steven Jorgensen */
42 void stripspace(char *s
) {
44 t
= s
+ strlen(s
) - 1;
45 while (t
> s
&& isspace(*t
)) {
52 int handle_button_press(int x
, int y
) {
55 i
= CheckMouseRegion(x
, y
);
59 button_up(B_PLAY
); /* raise play */
60 button_up(B_PREV_DIR
); /* reactivate directory up/down */
61 button_up(B_NEXT_DIR
);
66 button_gray(B_PREV_DIR
); /* gray out directory up/down */
67 button_gray(B_NEXT_DIR
);
94 fprintf(stderr
, "unknown button pressed\n");
101 void handle_button_release(int i
)
103 /* play stays down, don't mess with toggles */
104 /* ignore song title press too */
105 if (((i
!= B_PLAY
) && (i
!= B_RAND
)) &&
106 ((i
!= B_REPEAT
) && (i
!= B_TITLE
))) {
111 /* don't undo gray of dir up/down */
112 if (((i
== B_STOP
) || (i
== B_BACK
)) || (i
== B_NEXT
)) {
123 char *config_filename
;
128 /* set defualts in case anything fails */
129 set_mpg123("/usr/local/bin/mpg123");
131 set_playlistext(".m3u");
133 pw
= getpwuid(getuid());
134 /* don't forget about the string terminator... */
135 config_filename
= (char *) malloc(sizeof(char) *
136 (strlen(pw
->pw_dir
) + 8));
137 sprintf(config_filename
, "%s/.wmmp3", pw
->pw_dir
);
140 fp
= fopen(config_filename
, "r");
146 fgets(line
, 256, fp
);
148 if ((line
[0] != '#') && (line
[0] != '\n')) {
149 if (sscanf(line
, " %s = %[^\n]", variable
, value
) < 2) {
150 fprintf(stderr
, "Malformed line in config file: %s\n", line
);
152 if (strcmp(variable
, "mpg123") == 0) {
155 } else if (strcmp(variable
, "mp3dir") == 0) {
158 } else if (strcmp(variable
, "mp3dirname") == 0) {
160 add_mp3dirname(value
);
161 } else if (strcmp(variable
, "mp3ext") == 0) {
164 } else if (strcmp(variable
, "playlistext") == 0) {
166 set_playlistext(value
);
167 } else if (strcmp(variable
, "alwaysscroll") == 0) {
169 set_alwaysscroll(value
);
171 fprintf(stderr
, "Unrecognized variable in config file: %s\n",
176 fgets(line
, 256, fp
);
182 fprintf(stderr
, "open of %s failed: %s\n",
187 free(config_filename
);
192 printf("wmmp3 -- by Patrick Crosby -- Version %s\n", VERSION
);
193 printf("At this moment, there are no command line options that do\n");
194 printf("anything special:\n");
195 printf("\t-h,--help: print this message\n");
196 printf("\t-v,--version: print version info\n");
197 printf("All options are set in ~/.wmmp3. See sample.wmmp3 in the\n");
198 printf("distribution or http://dotfiles.com/software/ for more info.\n");
203 printf("wmmp3 -- by Patrick Crosby -- Version %s\n", VERSION
);
206 int check_options(int argc
, char *argv
[])
208 int option_entered
= 0;
212 for (i
= 1; i
< argc
; i
++) {
213 if (streq(argv
[i
], "-h")) {
217 else if (streq(argv
[i
], "--help")) {
221 else if (streq(argv
[i
], "-v")) {
225 else if (streq(argv
[i
], "--version")) {
231 return option_entered
;
234 void main(int argc
, char *argv
[])
236 struct coord pos
[] = {
237 {35, 34, 12, 11}, /* stop */
238 {46, 34, 12, 11}, /* play */
239 {35, 45, 12, 11}, /* back */
240 {46, 45, 12, 11}, /* next */
241 {6, 34, 12, 11}, /* prev_dir */
242 {17, 34, 12, 11}, /* random */
243 {6, 45, 12, 11}, /* next_dir */
244 {17, 45, 12, 11}, /* repeat */
245 {5, 18, 54, 12} /* song title */
248 char mask_bits
[64 * 64];
250 int mask_height
= 64;
255 if (check_options(argc
, argv
)) {
261 /* set up the display area for wmmp3 */
262 createXBMfromXPM(mask_bits
, wmmp3_xpm
, mask_width
, mask_height
);
263 openXwindow(argc
, argv
, wmmp3_xpm
, mask_bits
, mask_width
, mask_height
);
266 draw_string("wmmp3", 5, 5);
270 for (i
= 0; i
< 9; i
++)
271 AddMouseRegion(i
, pos
[i
].x
, pos
[i
].y
,
273 pos
[i
].y
+ pos
[i
].h
);
277 while (XPending(display
)) {
278 XNextEvent(display
, &Event
);
279 switch (Event
.type
) {
286 XCloseDisplay(display
);
289 btn_num
= handle_button_press(Event
.xbutton
.x
,
293 handle_button_release(btn_num
);