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 $
29 int check_options(int argc
, char *argv
[]);
30 int handle_button_press(int x
, int y
);
31 void handle_button_release(int i
);
40 /* from Steven Jorgensen */
41 void stripspace(char *s
) {
43 t
= s
+ strlen(s
) - 1;
44 while (t
> s
&& isspace(*t
)) {
51 int handle_button_press(int x
, int y
) {
54 i
= CheckMouseRegion(x
, y
);
58 button_up(B_PLAY
); /* raise play */
59 button_up(B_PREV_DIR
); /* reactivate directory up/down */
60 button_up(B_NEXT_DIR
);
65 button_gray(B_PREV_DIR
); /* gray out directory up/down */
66 button_gray(B_NEXT_DIR
);
93 fprintf(stderr
, "unknown button pressed\n");
100 void handle_button_release(int i
)
102 /* play stays down, don't mess with toggles */
103 /* ignore song title press too */
104 if (((i
!= B_PLAY
) && (i
!= B_RAND
)) &&
105 ((i
!= B_REPEAT
) && (i
!= B_TITLE
))) {
110 /* don't undo gray of dir up/down */
111 if (((i
== B_STOP
) || (i
== B_BACK
)) || (i
== B_NEXT
)) {
122 char *config_filename
;
127 /* set defualts in case anything fails */
128 set_mpg123("/usr/local/bin/mpg123");
130 set_playlistext(".m3u");
132 pw
= getpwuid(getuid());
133 /* don't forget about the string terminator... */
134 config_filename
= (char *) malloc(sizeof(char) *
135 (strlen(pw
->pw_dir
) + 8));
136 sprintf(config_filename
, "%s/.wmmp3", pw
->pw_dir
);
139 fp
= fopen(config_filename
, "r");
145 fgets(line
, 256, fp
);
147 if ((line
[0] != '#') && (line
[0] != '\n')) {
148 if (sscanf(line
, " %s = %[^\n]", variable
, value
) < 2) {
149 fprintf(stderr
, "Malformed line in config file: %s\n", line
);
151 if (strcmp(variable
, "mpg123") == 0) {
154 } else if (strcmp(variable
, "mp3dir") == 0) {
157 } else if (strcmp(variable
, "mp3dirname") == 0) {
159 add_mp3dirname(value
);
160 } else if (strcmp(variable
, "mp3ext") == 0) {
163 } else if (strcmp(variable
, "playlistext") == 0) {
165 set_playlistext(value
);
166 } else if (strcmp(variable
, "alwaysscroll") == 0) {
168 set_alwaysscroll(value
);
170 fprintf(stderr
, "Unrecognized variable in config file: %s\n",
175 fgets(line
, 256, fp
);
181 fprintf(stderr
, "open of %s failed: %s\n",
186 free(config_filename
);
191 printf("wmmp3 -- by Patrick Crosby -- Version %s\n", VERSION
);
192 printf("At this moment, there are no command line options that do\n");
193 printf("anything special:\n");
194 printf("\t-h,--help: print this message\n");
195 printf("\t-v,--version: print version info\n");
196 printf("All options are set in ~/.wmmp3. See sample.wmmp3 in the\n");
197 printf("distribution or http://dotfiles.com/software/ for more info.\n");
202 printf("wmmp3 -- by Patrick Crosby -- Version %s\n", VERSION
);
205 int check_options(int argc
, char *argv
[])
207 int option_entered
= 0;
211 for (i
= 1; i
< argc
; i
++) {
212 if (streq(argv
[i
], "-h")) {
216 else if (streq(argv
[i
], "--help")) {
220 else if (streq(argv
[i
], "-v")) {
224 else if (streq(argv
[i
], "--version")) {
230 return option_entered
;
233 void main(int argc
, char *argv
[])
235 struct coord pos
[] = {
236 {35, 34, 12, 11}, /* stop */
237 {46, 34, 12, 11}, /* play */
238 {35, 45, 12, 11}, /* back */
239 {46, 45, 12, 11}, /* next */
240 {6, 34, 12, 11}, /* prev_dir */
241 {17, 34, 12, 11}, /* random */
242 {6, 45, 12, 11}, /* next_dir */
243 {17, 45, 12, 11}, /* repeat */
244 {5, 18, 54, 12} /* song title */
247 char mask_bits
[64 * 64];
249 int mask_height
= 64;
254 if (check_options(argc
, argv
)) {
260 /* set up the display area for wmmp3 */
261 createXBMfromXPM(mask_bits
, wmmp3_xpm
, mask_width
, mask_height
);
262 openXwindow(argc
, argv
, wmmp3_xpm
, mask_bits
, mask_width
, mask_height
);
265 draw_string("wmmp3", 5, 5);
269 for (i
= 0; i
< 9; i
++)
270 AddMouseRegion(i
, pos
[i
].x
, pos
[i
].y
,
272 pos
[i
].y
+ pos
[i
].h
);
276 while (XPending(display
)) {
277 XNextEvent(display
, &Event
);
278 switch (Event
.type
) {
285 XCloseDisplay(display
);
288 btn_num
= handle_button_press(Event
.xbutton
.x
,
292 handle_button_release(btn_num
);