diff options
-rw-r--r-- | src/command.c | 45 | ||||
-rw-r--r-- | src/command.h | 10 | ||||
-rw-r--r-- | src/conf.c | 6 | ||||
-rw-r--r-- | src/main.c | 1 | ||||
-rw-r--r-- | src/ncmpc.h | 12 | ||||
-rw-r--r-- | src/options.c | 37 | ||||
-rw-r--r-- | src/options.h | 2 | ||||
-rw-r--r-- | src/screen.c | 4 | ||||
-rw-r--r-- | src/screen_keydef.c | 2 | ||||
-rw-r--r-- | src/screen_utils.c | 12 | ||||
-rw-r--r-- | src/wreadln.c | 19 | ||||
-rw-r--r-- | src/wreadln.h | 5 |
12 files changed, 98 insertions, 57 deletions
diff --git a/src/command.c b/src/command.c index c8d43d99d..c256d0c5c 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; j<MAX_COMMAND_KEYS; j++) { diff --git a/src/command.h b/src/command.h index db2c9cee0..fc436a443 100644 --- a/src/command.h +++ b/src/command.h @@ -54,10 +54,15 @@ typedef enum } command_t; -/* flags */ +/* command definition flags */ #define COMMAND_KEY_MODIFIED 0x01 #define COMMAND_KEY_CONFLICT 0x02 +/* write key bindings flags */ +#define KEYDEF_WRITE_HEADER 0x01 +#define KEYDEF_WRITE_ALL 0x02 +#define KEYDEF_COMMENT_ALL 0x04 + typedef struct { int keys[MAX_COMMAND_KEYS]; @@ -72,7 +77,7 @@ command_t find_key_command(int key, command_definition_t *cmds); void command_dump_keys(void); int check_key_bindings(command_definition_t *cmds, char *buf, size_t size); -int write_key_bindings(FILE *f); +int write_key_bindings(FILE *f, int all); char *key2str(int key); char *get_key_description(command_t command); @@ -82,6 +87,7 @@ command_t get_key_command(int key); command_t get_key_command_from_name(char *name); int assign_keys(command_t command, int keys[MAX_COMMAND_KEYS]); +int my_wgetch(WINDOW *w); command_t get_keyboard_command(void); command_t get_keyboard_command_with_timeout(int milliseconds); diff --git a/src/conf.c b/src/conf.c index f1f1223a3..b31b7b173 100644 --- a/src/conf.c +++ b/src/conf.c @@ -57,7 +57,7 @@ #define CONF_AUDIBLE_BELL "audible-bell" #define CONF_VISIBLE_BELL "visible-bell" #define CONF_XTERM_TITLE "set-xterm-title" -#define CONF_MOUSE_EVENTS "enable-mouse" +#define CONF_ENABLE_MOUSE "enable-mouse" typedef enum { KEY_PARSER_UNKNOWN, @@ -463,9 +463,9 @@ read_rc_file(char *filename, options_t *options) { options->enable_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 19dad2987..1cba667bf 100644 --- a/src/main.c +++ b/src/main.c @@ -23,6 +23,7 @@ #include <unistd.h> #include <signal.h> #include <string.h> +#include <ncurses.h> #include <glib.h> #include "config.h" diff --git a/src/ncmpc.h b/src/ncmpc.h index dec530dc2..7c1d51958 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 94da5b836..514ba544b 100644 --- a/src/options.c +++ b/src/options.c @@ -21,12 +21,15 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <ncurses.h> #include <glib.h> #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 9cbe38675..1a4e4b61e 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 9ea46f739..f7145be6b 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 7ea8c3fdb..4ed30dfcc 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 cd3fc1ed0..9870fc33a 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 d0204329e..700769bd1 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 520ba2a6a..55c24b91f 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); |