X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=sdl_gui.c;h=c63f9b804b5e994926b5bb8f548747cdb96c95ad;hp=bdc809b59d58e0b33797eabc11fc9439b99636af;hb=769888ee3175ed60df3c23caf51cdad5db33d141;hpb=2ed89c59f0efcd0a2763f47c7d3455663241e623 diff --git a/sdl_gui.c b/sdl_gui.c index bdc809b5..c63f9b80 100644 --- a/sdl_gui.c +++ b/sdl_gui.c @@ -1,25 +1,17 @@ /* - * Copyright (C) 2003-2006 Andre Noll + * Copyright (C) 2003-2007 Andre Noll * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Licensed under the GPL v2. For licencing details see COPYING. */ /** \file sdl_gui.c SDL-based interface for paraslash */ +#include +#include + #include "para.h" -#include "string.h" +#include "gui_common.h" +#include "fd.h" #include @@ -42,7 +34,7 @@ static int width = 0; static int height = 0; extern const char *status_item_list[NUM_STAT_ITEMS]; -struct gengetopt_args_info args_info; +struct sdl_gui_args_info args_info; #define FRAME_WIDTH 10 #define FONT_HEIGHT 36 @@ -68,19 +60,19 @@ struct gengetopt_args_info args_info; struct stat_item{ - char *name; - char *prefix; - char *postfix; - char *content; - unsigned x; - unsigned y; - unsigned w; - unsigned h; + const char *name; + const char *prefix; + const char *postfix; + char *content; + unsigned x; + unsigned y; + unsigned w; + unsigned h; Uint8 r; Uint8 g; Uint8 b; - int font; - int align; + int font; + int align; }; struct font { @@ -118,7 +110,7 @@ struct font fonts[] = { static struct stat_item stat_items[NUM_STAT_ITEMS]; -void para_log(__unused int ll, __unused char* fmt,...) /* no logging */ +void para_log(__a_unused int ll, __a_unused const char* fmt,...) /* no logging */ { } @@ -135,7 +127,6 @@ static void init_stat_items(void) s[SI_STATUS_BAR].prefix = ""; s[SI_STATUS_BAR].postfix = ""; - s[SI_STATUS_BAR].content = ""; s[SI_STATUS_BAR].x = 0; s[SI_STATUS_BAR].y = 10; s[SI_STATUS_BAR].w = 100; @@ -148,7 +139,6 @@ static void init_stat_items(void) s[SI_PLAY_TIME].prefix = ""; s[SI_PLAY_TIME].postfix = ""; - s[SI_PLAY_TIME].content = ""; s[SI_PLAY_TIME].x = 35; s[SI_PLAY_TIME].y = 20; s[SI_PLAY_TIME].w = 65; @@ -161,7 +151,6 @@ static void init_stat_items(void) s[SI_STATUS].prefix = ""; s[SI_STATUS].postfix = ""; - s[SI_STATUS].content = ""; s[SI_STATUS].x = 35; s[SI_STATUS].y = 28; s[SI_STATUS].w = 12; @@ -174,7 +163,6 @@ static void init_stat_items(void) s[SI_STATUS_FLAGS].prefix = " ("; s[SI_STATUS_FLAGS].postfix = ")"; - s[SI_STATUS_FLAGS].content = ""; s[SI_STATUS_FLAGS].x = 47; s[SI_STATUS_FLAGS].y = 28; s[SI_STATUS_FLAGS].w = 15; @@ -187,7 +175,6 @@ static void init_stat_items(void) s[SI_NUM_PLAYED].prefix = "#"; s[SI_NUM_PLAYED].postfix = ""; - s[SI_NUM_PLAYED].content = "0"; s[SI_NUM_PLAYED].x = 62; s[SI_NUM_PLAYED].y = 28; s[SI_NUM_PLAYED].w = 13; @@ -200,7 +187,6 @@ static void init_stat_items(void) s[SI_UPTIME].prefix = "Up: "; s[SI_UPTIME].postfix = ""; - s[SI_UPTIME].content = ""; s[SI_UPTIME].x = 75; s[SI_UPTIME].y = 28; s[SI_UPTIME].w = 25; @@ -211,22 +197,20 @@ static void init_stat_items(void) s[SI_UPTIME].font = N_YELLOW; s[SI_UPTIME].align = RIGHT; - s[SI_DBTOOL].prefix = "dbtool: "; - s[SI_DBTOOL].postfix = ""; - s[SI_DBTOOL].content = "no content yet"; - s[SI_DBTOOL].x = 35; - s[SI_DBTOOL].y = 48; - s[SI_DBTOOL].w = 35; - s[SI_DBTOOL].h = FONT_HEIGHT; - s[SI_DBTOOL].r = 0; - s[SI_DBTOOL].g = 0; - s[SI_DBTOOL].b = 0; - s[SI_DBTOOL].font = N_YELLOW; - s[SI_DBTOOL].align = LEFT; + s[SI_SELECTOR].prefix = "selector: "; + s[SI_SELECTOR].postfix = ""; + s[SI_SELECTOR].x = 35; + s[SI_SELECTOR].y = 48; + s[SI_SELECTOR].w = 35; + s[SI_SELECTOR].h = FONT_HEIGHT; + s[SI_SELECTOR].r = 0; + s[SI_SELECTOR].g = 0; + s[SI_SELECTOR].b = 0; + s[SI_SELECTOR].font = N_YELLOW; + s[SI_SELECTOR].align = LEFT; s[SI_FORMAT].prefix = "Format: "; s[SI_FORMAT].postfix = ""; - s[SI_FORMAT].content = ""; s[SI_FORMAT].x = 70; s[SI_FORMAT].y = 48; s[SI_FORMAT].w = 30; @@ -239,7 +223,6 @@ static void init_stat_items(void) s[SI_MTIME].prefix = "MTime: "; s[SI_MTIME].postfix = ""; - s[SI_MTIME].content = ""; s[SI_MTIME].x = 35; s[SI_MTIME].y = 35; s[SI_MTIME].w = 65; @@ -252,7 +235,6 @@ static void init_stat_items(void) s[SI_FILE_SIZE].prefix = "Size: "; s[SI_FILE_SIZE].postfix = "kb"; - s[SI_FILE_SIZE].content = ""; s[SI_FILE_SIZE].x = 35; s[SI_FILE_SIZE].y = 42; s[SI_FILE_SIZE].w = 20; @@ -265,7 +247,6 @@ static void init_stat_items(void) s[SI_AUDIO_INFO1].prefix = ""; s[SI_AUDIO_INFO1].postfix = ""; - s[SI_AUDIO_INFO1].content = ""; s[SI_AUDIO_INFO1].x = 0; s[SI_AUDIO_INFO1].y = 60; s[SI_AUDIO_INFO1].w = 100; @@ -278,7 +259,6 @@ static void init_stat_items(void) s[SI_AUDIO_INFO2].prefix = ""; s[SI_AUDIO_INFO2].postfix = ""; - s[SI_AUDIO_INFO2].content = ""; s[SI_AUDIO_INFO2].x = 0; s[SI_AUDIO_INFO2].y = 65; s[SI_AUDIO_INFO2].w = 100; @@ -291,7 +271,6 @@ static void init_stat_items(void) s[SI_AUDIO_INFO3].prefix = ""; s[SI_AUDIO_INFO3].postfix = ""; - s[SI_AUDIO_INFO3].content = ""; s[SI_AUDIO_INFO3].x = 0; s[SI_AUDIO_INFO3].y = 70; s[SI_AUDIO_INFO3].w = 100; @@ -305,7 +284,6 @@ static void init_stat_items(void) s[SI_DBINFO1].name = "dbinfo1:"; s[SI_DBINFO1].prefix = ""; s[SI_DBINFO1].postfix = ""; - s[SI_DBINFO1].content = ""; s[SI_DBINFO1].x = 0; s[SI_DBINFO1].y = 83; s[SI_DBINFO1].w = 100; @@ -318,7 +296,6 @@ static void init_stat_items(void) s[SI_DBINFO2].prefix = ""; s[SI_DBINFO2].postfix = ""; - s[SI_DBINFO2].content = ""; s[SI_DBINFO2].x = 0; s[SI_DBINFO2].y = 88; s[SI_DBINFO2].w = 100; @@ -332,7 +309,6 @@ static void init_stat_items(void) s[SI_DBINFO3].name = "dbinfo3:"; s[SI_DBINFO3].prefix = ""; s[SI_DBINFO3].postfix = ""; - s[SI_DBINFO3].content = ""; s[SI_DBINFO3].x = 0; s[SI_DBINFO3].y = 93; s[SI_DBINFO3].w = 100; @@ -371,7 +347,7 @@ static void init_SDL(void) SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE); /* Set the window manager title bar */ SDL_WM_SetCaption("The Gui of death that makes you blind (paraslash " - VERSION ")", "SFont"); + PACKAGE_VERSION ")", "SFont"); } /* @@ -450,7 +426,7 @@ static void tab2space(char *text) } } -static void print_msg(char *msg) +static void print_msg(const char *msg) { SFont_FontInfo *font = &(fonts[MSG_FONT].fontinfo); char *buf = strdup(msg); @@ -499,7 +475,7 @@ SDLKey get_key(void) /* * print message, wait for key (blocking), return 1 for 'q', 0 else */ -static SDLKey hit_key(char *msg) +static SDLKey hit_key(const char *msg) { SDLKey sym; @@ -520,7 +496,7 @@ static SDLKey hit_key(char *msg) */ static int command_handler(void) { - FILE *pipe; + FILE *f; unsigned count = 0; char text[MAXLINE]=""; char buf[MAXLINE]=""; @@ -536,15 +512,15 @@ static int command_handler(void) if (text[0] == '!') { if (text[1] == '\0') return 1; - pipe = popen(text + 1, "r"); + f = popen(text + 1, "r"); } else { sprintf(buf, BINDIR "/para_client %s 2>&1", text); - pipe = popen(buf, "r"); + f = popen(buf, "r"); } - if (!pipe) + if (!f) return 0; fill_output_rect(); - while(fgets(text, MAXLINE - 1, pipe)) { + while(fgets(text, MAXLINE - 1, f)) { int len; tab2space(text); @@ -569,7 +545,7 @@ static int command_handler(void) update_all(); hit_key("Hit any key to return"); out: fill_output_rect(); - pclose(pipe); + pclose(f); return 1; } @@ -600,14 +576,14 @@ SDL_Surface *load_jpg(void) SDL_RWops *rwop; int fds[3] = {0, 1, 0}; pid_t pid; - FILE *pipe; + FILE *f; if (para_exec_cmdline_pid(&pid, args_info.pic_cmd_arg, fds) < 0) return NULL; - pipe = fdopen(fds[1], "r"); - if (!pipe) + f = fdopen(fds[1], "r"); + if (!f) return NULL; - if (!(rwop = SDL_RWFromFP(pipe, 0))) + if (!(rwop = SDL_RWFromFP(f, 0))) return NULL; return IMG_LoadJPG_RW(rwop); } @@ -687,24 +663,25 @@ static void do_update(int i) * Check if buf is a known status line. If so call do_update and return 1. * Return 0 otherwise. */ -void update_status(char *buf) +int update_status(char *buf, __a_unused void *data) { int i; i = stat_line_valid(buf); if (i < 0) - return; + return 1; //free(stat_items[i].content); stat_items[i].content = para_strdup(buf + strlen(status_item_list[i]) + 1); do_update(i); + return 1; } /* * Read stat line from pipe if pipe is ready, call update_status to * display information. */ -static int draw_status(int pipe) +static int draw_status(int fd) { fd_set rfds; int ret; @@ -713,14 +690,12 @@ static int draw_status(int pipe) tv.tv_sec = 0; tv.tv_usec = 3000000; FD_ZERO(&rfds); - FD_SET(pipe, &rfds); - ret = select(pipe + 1, &rfds, NULL, NULL, &tv); -// printf("select returned %d\n", ret); + FD_SET(fd, &rfds); + ret = para_select(fd + 1, &rfds, NULL, &tv); if (ret <= 0) return 0; - if (read_audiod_pipe(pipe, update_status) > 0) + if (read_audiod_pipe(fd, update_status) > 0) return 1; -// clear_all_items(); free(stat_items[SI_STATUS_BAR].content); stat_items[SI_STATUS_BAR].content = para_strdup("audiod not running!?\n"); @@ -756,10 +731,11 @@ static int configfile_exists(void) */ int main(int argc, char *argv[]) { - int i, ret, pipe; + int i, ret, fd = -1; SDLKey sym; - cmdline_parser(argc, argv, &args_info); + sdl_gui_cmdline_parser(argc, argv, &args_info); + HANDLE_VERSION_FLAG("sdl_gui", args_info); ret = configfile_exists(); // printf("w=%i,h=%i,ret=%i, cf=%s\n", width, height, ret, args_info.config_file_arg); @@ -768,15 +744,21 @@ int main(int argc, char *argv[]) args_info.config_file_arg); exit(EXIT_FAILURE); } - if (ret) - cmdline_parser_configfile(args_info.config_file_arg, - &args_info, 0, 0, 0); + if (ret) { + struct sdl_gui_cmdline_parser_params params = { + .override = 0, + .initialize = 0, + .check_required = 0, + .check_ambiguity = 0 + }; + sdl_gui_cmdline_parser_config_file(args_info.config_file_arg, + &args_info, ¶ms); + } signal(SIGCHLD, SIG_IGN); width = args_info.width_arg; height = args_info.height_arg; // printf("w=%i,h=%i,ret=%i, cf=%s\n", width, height, ret, args_info.config_file_arg); init_stat_items(); - pipe = para_open_audiod_pipe(args_info.stat_cmd_arg); init_SDL(); for (i = 0; fonts[i].name[0]; i++) { char buf[MAXLINE]; @@ -792,10 +774,15 @@ int main(int argc, char *argv[]) update_input(); } for (;;) { - ret = draw_status(pipe); + if (fd < 0) { + fd = para_open_audiod_pipe(args_info.stat_cmd_arg); + if (fd < 0) + clean_exit(EXIT_FAILURE); + } + ret = draw_status(fd); if (ret < 0) { - close(pipe); - pipe = -1; + close(fd); + fd = -1; } if (SDL_QuitRequested()) clean_exit(0); @@ -819,12 +806,6 @@ int main(int argc, char *argv[]) || sym == SDLK_COMPOSE ) continue; - if (pipe < 0) { -// printf("closing pipe\n"); - kill(0, SIGINT); - close(pipe); -// printf("pipe closed\n"); - } fill_input_rect(); update_input(); if (!command_handler()) @@ -833,7 +814,6 @@ int main(int argc, char *argv[]) print_help(); update_pic(); SDL_UpdateRect(screen, 0, 0, 0, 0); - pipe = para_open_audiod_pipe(args_info.stat_cmd_arg); break; } }