From f674c3f262a6bf2542debd29c4aa61281a976cbc Mon Sep 17 00:00:00 2001 From: Kalle Wallin Date: Tue, 13 Jul 2004 15:28:43 +0000 Subject: 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 --- src/command.c | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) (limited to 'src/command.c') 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