From: Kalle Wallin Date: Tue, 13 Jul 2004 15:28:43 +0000 (+0000) Subject: Use my_wgetch() instead of wgetch(), added --[no-]mouse option X-Git-Tag: v0.12_alpha1~462 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f674c3f262a6bf2542debd29c4aa61281a976cbc;p=ncmpc.git Use my_wgetch() instead of wgetch(), added --[no-]mouse option git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1864 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- diff --git a/src/command.c b/src/command.c index c8d43d9..c256d0c 100644 --- a/src/command.c +++ b/src/command.c @@ -39,6 +39,7 @@ #define DK(x) #endif +extern void sigstop(void); extern void screen_resize(void); #define BS KEY_BACKSPACE @@ -378,6 +379,29 @@ get_key_command(int key) return find_key_command(key, cmds); } +int +my_wgetch(WINDOW *w) +{ + int c; + + c = wgetch(w); + + /* handle resize event */ + if( c==KEY_RESIZE ) + screen_resize(); + +#ifdef ENABLE_RAW_MODE + /* handle SIGSTOP (Ctrl-Z) */ + if( c==26 || c==407 ) + sigstop(); + /* handle SIGINT (Ctrl-C) */ + if( c==3 ) + exit(EXIT_SUCCESS); +#endif + + return c; +} + command_t get_keyboard_command_with_timeout(int ms) { @@ -385,18 +409,10 @@ get_keyboard_command_with_timeout(int ms) if( ms != SCREEN_TIMEOUT) timeout(ms); - key = wgetch(stdscr); + key = my_wgetch(stdscr); if( ms != SCREEN_TIMEOUT) timeout(SCREEN_TIMEOUT); - if( key==KEY_RESIZE ) - screen_resize(); - -#ifdef ENABLE_RAW_MODE - if( key==KEY_SIGSTOP ) - sigstop(); -#endif - if( key==ERR ) return CMD_NONE; @@ -490,18 +506,21 @@ check_key_bindings(command_definition_t *cp, char *buf, size_t bufsize) } int -write_key_bindings(FILE *f) +write_key_bindings(FILE *f, int flags) { int i,j; - fprintf(f, "# Key bindings for ncmpc (generated by ncmpc)\n\n"); + if( flags & KEYDEF_WRITE_HEADER ) + fprintf(f, "## Key bindings for ncmpc (generated by ncmpc)\n\n"); i=0; while( cmds[i].name && !ferror(f) ) { - if( cmds[i].flags & COMMAND_KEY_MODIFIED ) + if( cmds[i].flags & COMMAND_KEY_MODIFIED || flags & KEYDEF_WRITE_ALL) { - fprintf(f, "# %s\n", cmds[i].description); + fprintf(f, "## %s\n", cmds[i].description); + if( flags & KEYDEF_COMMENT_ALL ) + fprintf(f, "#"); fprintf(f, "key %s = ", cmds[i].name); for(j=0; jenable_xterm_title = str2bool(value); } - else if( !strcasecmp(CONF_MOUSE_EVENTS, name) ) + else if( !strcasecmp(CONF_ENABLE_MOUSE, name) ) { - options->enable_mouse_events = str2bool(value); + options->enable_mouse = str2bool(value); } else { diff --git a/src/main.c b/src/main.c index 19dad29..1cba667 100644 --- a/src/main.c +++ b/src/main.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "config.h" diff --git a/src/ncmpc.h b/src/ncmpc.h index dec530d..7c1d519 100644 --- a/src/ncmpc.h +++ b/src/ncmpc.h @@ -40,16 +40,12 @@ void D(char *format, ...); /* song format - list window */ #define DEFAULT_LIST_FORMAT "%name%|[%artist% - ]%title%|%shortfile%" -#define LIST_FORMAT (options.list_format ? options.list_format : DEFAULT_LIST_FORMAT) +#define LIST_FORMAT (options.list_format ? options.list_format : \ + DEFAULT_LIST_FORMAT) /* song format - status window */ #define DEFAULT_STATUS_FORMAT "[%artist% - ]%title%|%shortfile%" -#define STATUS_FORMAT (options.status_format ? options.status_format : DEFAULT_STATUS_FORMAT) - -/* sigstop key (Ctrl-Z) */ -#define KEY_SIGSTOP 26 - -/* send SIGSTOP */ -void sigstop(void); +#define STATUS_FORMAT (options.status_format ? options.status_format : \ + DEFAULT_STATUS_FORMAT) #endif /* NCMPC_H */ diff --git a/src/options.c b/src/options.c index 94da5b8..514ba54 100644 --- a/src/options.c +++ b/src/options.c @@ -21,12 +21,15 @@ #include #include #include +#include #include #include "config.h" #include "ncmpc.h" #include "support.h" #include "options.h" +#include "command.h" +#include "conf.h" #define MAX_LONGOPT_LENGTH 32 @@ -56,6 +59,10 @@ static arg_opt_t option_table[] = { { 'V', "version", NULL, "Display version information" }, { 'c', "colors", NULL, "Enable colors" }, { 'C', "no-colors", NULL, "Disable colors" }, +#ifdef HAVE_GETMOUSE + { 'm', "mouse", NULL, "Enable mouse" }, + { 'M', "no-mouse", NULL, "Disable mouse" }, +#endif { 'e', "exit", NULL, "Exit on connection errors" }, { 'p', "port", "PORT", "Connect to server on port [" DEFAULT_PORT_STR "]" }, { 'h', "host", "HOST", "Connect to server on host [" DEFAULT_HOST "]" }, @@ -63,6 +70,7 @@ static arg_opt_t option_table[] = { { 'f', "config", "FILE", "Read configuration from file" }, { 'k', "key-file","FILE", "Read configuration from file" }, #ifdef DEBUG + { 'K', "dump-keys", NULL, "Dump key bindings to stdout" }, { 'D', "debug", NULL, "Enable debug output on stderr" }, #endif { 0, NULL, NULL, NULL }, @@ -144,7 +152,21 @@ handle_option(int c, char *arg) display_help(); exit(EXIT_SUCCESS); case 'V': /* --version */ - printf("Version %s\n", VERSION); + printf("%s version: %s\n", PACKAGE, VERSION); + printf("build options:"); +#ifdef DEBUG + printf(" debug"); +#endif +#ifdef ENABLE_NLS + printf(" nls"); +#endif +#ifdef ENABLE_KEYDEF_SCREEN + printf(" key-screen"); +#endif +#ifdef ENABLE_CLOCK_SCREEN + printf(" clock-screen"); +#endif + printf("\n"); exit(EXIT_SUCCESS); case 'c': /* --colors */ options.enable_colors = TRUE; @@ -152,6 +174,12 @@ handle_option(int c, char *arg) case 'C': /* --no-colors */ options.enable_colors = FALSE; break; + case 'm': /* --mouse */ + options.enable_mouse = TRUE; + break; + case 'M': /* --no-mouse */ + options.enable_mouse = FALSE; + break; case 'e': /* --exit */ options.reconnect = FALSE; break; @@ -178,9 +206,16 @@ handle_option(int c, char *arg) g_free(options.key_file); options.key_file = g_strdup(arg); break; +#ifdef DEBUG + case 'K': /* --dump-keys */ + read_configuration(&options); + write_key_bindings(stdout, KEYDEF_WRITE_ALL | KEYDEF_COMMENT_ALL); + exit(EXIT_SUCCESS); + break; case 'D': /* --debug */ options.debug = TRUE; break; +#endif default: fprintf(stderr,"Unknown Option %c = %s\n", c, arg); break; diff --git a/src/options.h b/src/options.h index 9cbe386..1a4e4b6 100644 --- a/src/options.h +++ b/src/options.h @@ -23,7 +23,7 @@ typedef struct gboolean audible_bell; gboolean visible_bell; gboolean enable_xterm_title; - gboolean enable_mouse_events; + gboolean enable_mouse; } options_t; diff --git a/src/screen.c b/src/screen.c index 9ea46f7..f7145be 100644 --- a/src/screen.c +++ b/src/screen.c @@ -478,7 +478,7 @@ screen_init(mpdclient_t *c) timeout(SCREEN_TIMEOUT); /* initialize mouse support */ #ifdef HAVE_GETMOUSE - if( options.enable_mouse_events ) + if( options.enable_mouse ) mousemask(ALL_MOUSE_EVENTS, NULL); #endif @@ -587,7 +587,7 @@ screen_init(mpdclient_t *c) mode_fn->open(screen, c); /* initialize wreadln */ - wrln_resize_callback = screen_resize; + wrln_wgetch = my_wgetch; wrln_max_history_length = 16; return 0; diff --git a/src/screen_keydef.c b/src/screen_keydef.c index 7ea8c3f..4ed30df 100644 --- a/src/screen_keydef.c +++ b/src/screen_keydef.c @@ -102,7 +102,7 @@ save_keys(void) g_free(filename); return -1; } - if( write_key_bindings(f) ) + if( write_key_bindings(f, KEYDEF_WRITE_HEADER) ) screen_status_printf(_("Error: %s - %s"), filename, strerror(errno)); else screen_status_printf(_("Wrote %s"), filename); diff --git a/src/screen_utils.c b/src/screen_utils.c index cd3fc1e..9870fc3 100644 --- a/src/screen_utils.c +++ b/src/screen_utils.c @@ -63,25 +63,15 @@ screen_getch(WINDOW *w, char *prompt) curs_set(1); timeout(-1); - while( (key=wgetch(w)) == ERR ) + while( (key=my_wgetch(w)) == ERR ) ; -#ifdef ENABLE_RAW_MODE - if( key==KEY_SIGSTOP ) - sigstop(); -#endif - #ifdef HAVE_GETMOUSE /* ignore mouse events */ if( key==KEY_MOUSE ) return screen_getch(w, prompt); #endif - if( key==KEY_RESIZE ) - { - screen_resize(); - } - noecho(); curs_set(0); timeout(SCREEN_TIMEOUT); diff --git a/src/wreadln.c b/src/wreadln.c index d020432..700769b 100644 --- a/src/wreadln.c +++ b/src/wreadln.c @@ -39,12 +39,11 @@ unsigned int wrln_max_line_size = WRLN_MAX_LINE_SIZE; unsigned int wrln_max_history_length = WRLN_MAX_HISTORY_LENGTH; -GVoidFunc wrln_resize_callback = NULL; +wrln_wgetch_fn_t wrln_wgetch = NULL; wrln_gcmp_pre_cb_t wrln_pre_completion_callback = NULL; wrln_gcmp_post_cb_t wrln_post_completion_callback = NULL; extern void screen_bell(void); -extern void sigstop(void); char * wreadln(WINDOW *w, @@ -152,7 +151,10 @@ wreadln(WINDOW *w, while( key!=13 && key!='\n' ) { - key = wgetch(w); + if( wrln_wgetch ) + key = wrln_wgetch(w); + else + key = wgetch(w); /* check if key is a function key */ for(i=0; i<63; i++) @@ -164,21 +166,12 @@ wreadln(WINDOW *w, switch (key) { -#ifdef HAVE_GETMOUSE case KEY_MOUSE: /* ignore mouse events */ -#endif case ERR: /* ingnore errors */ break; -#ifdef ENABLE_RAW_MODE - case 26: - sigstop(); - break; -#endif case KEY_RESIZE: - /* a resize event -> call an external callback function */ - if( wrln_resize_callback ) - wrln_resize_callback(); + /* a resize event */ if( x1>COLS ) { x1=COLS; diff --git a/src/wreadln.h b/src/wreadln.h index 520ba2a..55c24b9 100644 --- a/src/wreadln.h +++ b/src/wreadln.h @@ -7,8 +7,9 @@ extern unsigned int wrln_max_line_size; /* max items stored in the history list */ extern unsigned int wrln_max_history_length; -/* a callback function for KEY_RESIZE */ -extern GVoidFunc wrln_resize_callback; +/* custom wgetch function */ +typedef int (*wrln_wgetch_fn_t) (WINDOW *w); +extern wrln_wgetch_fn_t wrln_wgetch; /* called after TAB is pressed but before g_completion_complete */ typedef void (*wrln_gcmp_pre_cb_t) (GCompletion *gcmp, gchar *buf);