diff options
author | Kalle Wallin <kaw@linux.se> | 2004-06-30 17:18:02 +0000 |
---|---|---|
committer | Kalle Wallin <kaw@linux.se> | 2004-06-30 17:18:02 +0000 |
commit | 919b0f13474fd323c7cd9e0b872b1990068a012d (patch) | |
tree | bb24d5e31ec390c8df695704881e0d0a96aa0adc /src | |
parent | e6c52179ca6e78a0a6a61002a80aa37b4f21719c (diff) | |
download | mpd-919b0f13474fd323c7cd9e0b872b1990068a012d.tar.gz mpd-919b0f13474fd323c7cd9e0b872b1990068a012d.tar.xz mpd-919b0f13474fd323c7cd9e0b872b1990068a012d.zip |
Added flags for conflicting, modified key bindings - check_key_bindings()
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1743 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r-- | src/command.c | 170 | ||||
-rw-r--r-- | src/command.h | 9 | ||||
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/screen_keydef.c | 19 |
4 files changed, 130 insertions, 72 deletions
diff --git a/src/command.c b/src/command.c index 2899d3255..50dcdf7d7 100644 --- a/src/command.c +++ b/src/command.c @@ -64,120 +64,120 @@ extern void screen_resize(void); static command_definition_t cmds[] = { #ifdef ENABLE_KEYDEF_SCREEN - { {'K', 0, 0 }, CMD_SCREEN_KEYDEF, "screen-keyedit", + { {'K', 0, 0 }, 0, CMD_SCREEN_KEYDEF, "screen-keyedit", N_("Key configuration screen") }, #endif - { { 'q', 'Q', 3 }, CMD_QUIT, "quit", + { { 'q', 'Q', 3 }, 0, CMD_QUIT, "quit", N_("Quit") }, /* movment */ - { { UP, 'k', 0 }, CMD_LIST_PREVIOUS, "up", + { { UP, 'k', 0 }, 0, CMD_LIST_PREVIOUS, "up", N_("Move cursor up") }, - { { DWN, 'j', 0 }, CMD_LIST_NEXT, "down", + { { DWN, 'j', 0 }, 0, CMD_LIST_NEXT, "down", N_("Move cursor down") }, - { { HOME, 0x01, 0 }, CMD_LIST_FIRST, "home", + { { HOME, 0x01, 0 }, 0, CMD_LIST_FIRST, "home", N_("Home ") }, - { { END, 0x05, 0 }, CMD_LIST_LAST, "end", + { { END, 0x05, 0 }, 0, CMD_LIST_LAST, "end", N_("End ") }, - { { PGUP, 0, 0 }, CMD_LIST_PREVIOUS_PAGE, "pgup", + { { PGUP, 0, 0 }, 0, CMD_LIST_PREVIOUS_PAGE, "pgup", N_("Page up") }, - { { PGDN, 0, 0 }, CMD_LIST_NEXT_PAGE, "pgdn", + { { PGDN, 0, 0 }, 0, CMD_LIST_NEXT_PAGE, "pgdn", N_("Page down") }, /* basic screens */ - { { '1', F1, 'h' }, CMD_SCREEN_HELP, "screen-help", + { { '1', F1, 'h' }, 0, CMD_SCREEN_HELP, "screen-help", N_("Help screen") }, - { { '2', F2, 0 }, CMD_SCREEN_PLAY, "screen-playlist", + { { '2', F2, 0 }, 0, CMD_SCREEN_PLAY, "screen-playlist", N_("Playlist screen") }, - { { '3', F3, 0 }, CMD_SCREEN_FILE, "screen-browse", + { { '3', F3, 0 }, 0, CMD_SCREEN_FILE, "screen-browse", N_("Browse screen") }, /* player commands */ - { { 13, 0, 0 }, CMD_PLAY, "play", + { { 13, 0, 0 }, 0, CMD_PLAY, "play", N_("Play/Enter directory") }, - { { 'P', 0, 0 }, CMD_PAUSE,"pause", + { { 'P', 0, 0 }, 0, CMD_PAUSE,"pause", N_("Pause") }, - { { 's', BS, 0 }, CMD_STOP, "stop", + { { 's', BS, 0 }, 0, CMD_STOP, "stop", N_("Stop") }, - { { '>', 0, 0 }, CMD_TRACK_NEXT, "next", + { { '>', 0, 0 }, 0, CMD_TRACK_NEXT, "next", N_("Next track") }, - { { '<', 0, 0 }, CMD_TRACK_PREVIOUS, "prev", + { { '<', 0, 0 }, 0, CMD_TRACK_PREVIOUS, "prev", N_("Previous track") }, - { { 'f', 0, 0 }, CMD_SEEK_FORWARD, "seek-forward", + { { 'f', 0, 0 }, 0, CMD_SEEK_FORWARD, "seek-forward", N_("Seek forward") }, - { { 'b', 0, 0 }, CMD_SEEK_BACKWARD, "seek-backward", + { { 'b', 0, 0 }, 0, CMD_SEEK_BACKWARD, "seek-backward", N_("Seek backward") }, - { { '+', RGHT, 0 }, CMD_VOLUME_UP, "volume-up", + { { '+', RGHT, 0 }, 0, CMD_VOLUME_UP, "volume-up", N_("Increase volume") }, - { { '-', LEFT, 0 }, CMD_VOLUME_DOWN, "volume-down", + { { '-', LEFT, 0 }, 0, CMD_VOLUME_DOWN, "volume-down", N_("Decrease volume") }, - { { ' ', 0, 0 }, CMD_SELECT, "select", + { { ' ', 0, 0 }, 0, CMD_SELECT, "select", N_("Select/deselect song in playlist") }, - { { DEL, 'd', 0 }, CMD_DELETE, "delete", + { { DEL, 'd', 0 }, 0, CMD_DELETE, "delete", N_("Delete song from playlist") }, - { { 'Z', 0, 0 }, CMD_SHUFFLE, "shuffle", + { { 'Z', 0, 0 }, 0, CMD_SHUFFLE, "shuffle", N_("Shuffle playlist") }, - { { 'c', 0, 0 }, CMD_CLEAR, "clear", + { { 'c', 0, 0 }, 0, CMD_CLEAR, "clear", N_("Clear playlist") }, - { { 'r', 0, 0 }, CMD_REPEAT, "repeat", + { { 'r', 0, 0 }, 0, CMD_REPEAT, "repeat", N_("Toggle repeat mode") }, - { { 'z', 0, 0 }, CMD_RANDOM, "random", + { { 'z', 0, 0 }, 0, CMD_RANDOM, "random", N_("Toggle random mode") }, - { { 'x', 0, 0 }, CMD_CROSSFADE, "crossfade", + { { 'x', 0, 0 }, 0, CMD_CROSSFADE, "crossfade", N_("Toggle crossfade mode") }, - { { 21, 0, 0 }, CMD_DB_UPDATE, "db-update", + { { 21, 0, 0 }, 0, CMD_DB_UPDATE, "db-update", N_("Start a music database update") }, - { { 'S', 0, 0 }, CMD_SAVE_PLAYLIST, "save", + { { 'S', 0, 0 }, 0, CMD_SAVE_PLAYLIST, "save", N_("Save playlist") }, - { { 'a', 0, 0 }, CMD_ADD, "add", + { { 'a', 0, 0 }, 0, CMD_ADD, "add", N_("Add url/file to playlist") }, /* lists */ - { { 11, 0, 0 }, CMD_LIST_MOVE_UP, "move-up", + { { 11, 0, 0 }, 0, CMD_LIST_MOVE_UP, "move-up", N_("Move item up") }, - { { 10, 0, 0 }, CMD_LIST_MOVE_DOWN, "move-down", + { { 10, 0, 0 }, 0, CMD_LIST_MOVE_DOWN, "move-down", N_("Move item down") }, - { { 12, 0, 0 }, CMD_SCREEN_UPDATE, "update", + { { 12, 0, 0 }, 0, CMD_SCREEN_UPDATE, "update", N_("Update screen") }, /* ncmpc options */ - { { 'w', 0, 0 }, CMD_TOGGLE_FIND_WRAP, "wrap-mode", + { { 'w', 0, 0 }, 0, CMD_TOGGLE_FIND_WRAP, "wrap-mode", N_("Toggle find mode") }, - { { 'U', 0, 0 }, CMD_TOGGLE_AUTOCENTER, "autocenter-mode", + { { 'U', 0, 0 }, 0, CMD_TOGGLE_AUTOCENTER, "autocenter-mode", N_("Toggle auto center mode") }, /* change screen */ - { { TAB, 0, 0 }, CMD_SCREEN_NEXT, "screen-next", + { { TAB, 0, 0 }, 0, CMD_SCREEN_NEXT, "screen-next", N_("Next screen") }, - { { STAB, 0, 0 }, CMD_SCREEN_PREVIOUS, "screen-prev", + { { STAB, 0, 0 }, 0, CMD_SCREEN_PREVIOUS, "screen-prev", N_("Previous screen") }, /* find */ - { { '/', 0, 0 }, CMD_LIST_FIND, "find", + { { '/', 0, 0 }, 0, CMD_LIST_FIND, "find", N_("Forward find") }, - { { 'n', 0, 0 }, CMD_LIST_FIND_NEXT, "find-next", + { { 'n', 0, 0 }, 0, CMD_LIST_FIND_NEXT, "find-next", N_("Forward find next") }, - { { '?', 0, 0 }, CMD_LIST_RFIND, "rfind", + { { '?', 0, 0 }, 0, CMD_LIST_RFIND, "rfind", N_("Backward find") }, - { { 'p', 0, 0 }, CMD_LIST_RFIND_NEXT, "rfind-next", + { { 'p', 0, 0 }, 0, CMD_LIST_RFIND_NEXT, "rfind-next", N_("Backward find previous") }, /* extra screens */ #ifdef ENABLE_CLOCK_SCREEN - { {'4', F4, 0 }, CMD_SCREEN_CLOCK, "screen-clock", + { {'4', F4, 0 }, 0, CMD_SCREEN_CLOCK, "screen-clock", N_("Clock screen") }, #endif - { { -1, -1, -1 }, CMD_NONE, NULL, NULL } + { { -1, -1, -1 }, 0, CMD_NONE, NULL, NULL } }; command_definition_t * @@ -262,6 +262,24 @@ command_dump_keys(void) } } +int +set_key_flags(command_definition_t *cp, command_t command, int flags) +{ + int i; + + i=0; + while( cp[i].name ) + { + if( cp[i].command == command ) + { + cp[i].flags |= flags; + return 0; + } + i++; + } + return 1; +} + char * get_key_names(command_t command, int all) { @@ -398,6 +416,7 @@ assign_keys(command_t command, int keys[MAX_COMMAND_KEYS]) if( cmds[i].command == command ) { memcpy(cmds[i].keys, keys, sizeof(int)*MAX_COMMAND_KEYS); + cmds[i].flags |= COMMAND_KEY_MODIFIED; return 0; } i++; @@ -406,44 +425,56 @@ assign_keys(command_t command, int keys[MAX_COMMAND_KEYS]) } int -check_key_bindings(char *buf, size_t bufsize) +check_key_bindings(command_definition_t *cp, char *buf, size_t bufsize) { int i; int retval = 0; + + if( cp==NULL ) + cp = cmds; + + i=0; + while( cp[i].name ) + { + cp[i].flags &= ~COMMAND_KEY_CONFLICT; + i++; + } i=0; - while( cmds[i].name ) + while( cp[i].name ) { int j; - command_t cmd; + command_t cmd; for(j=0; j<MAX_COMMAND_KEYS; j++) - if( cmds[i].keys[j] && - (cmd=get_key_command(cmds[i].keys[j])) != cmds[i].command ) + if( cp[i].keys[j] && + (cmd=find_key_command(cp[i].keys[j],cp)) != cp[i].command ) { if( buf ) #ifdef ENABLE_KEYDEF_SCREEN snprintf(buf, bufsize, _("Key %s assigned to %s and %s (press %s for the key editor)"), - key2str(cmds[i].keys[j]), - get_key_command_name(cmds[i].command), + key2str(cp[i].keys[j]), + get_key_command_name(cp[i].command), get_key_command_name(cmd), get_key_names(CMD_SCREEN_KEYDEF,0)); #else snprintf(buf, bufsize, _("Error: Key %s assigned to %s and %s !!!\n"), - key2str(cmds[i].keys[j]), - get_key_command_name(cmds[i].command), + key2str(cp[i].keys[j]), + get_key_command_name(cp[i].command), get_key_command_name(cmd)); #endif else fprintf(stderr, _("Error: Key %s assigned to %s and %s !!!\n"), - key2str(cmds[i].keys[j]), - get_key_command_name(cmds[i].command), + key2str(cp[i].keys[j]), + get_key_command_name(cp[i].command), get_key_command_name(cmd)); + cp[i].flags |= COMMAND_KEY_CONFLICT; + set_key_flags(cp, cmd, COMMAND_KEY_CONFLICT); retval = -1; - } + } i++; } return retval; @@ -454,25 +485,30 @@ write_key_bindings(FILE *f) { int i,j; + fprintf(f, "# Key bindings for ncmpc (generated by ncmpc)\n\n"); + i=0; while( cmds[i].name && !ferror(f) ) { - fprintf(f, "# %s\n", cmds[i].description); - fprintf(f, "key %s = ", cmds[i].name); - for(j=0; j<MAX_COMMAND_KEYS; j++) + if( cmds[i].flags & COMMAND_KEY_MODIFIED ) { - if( j && cmds[i].keys[j] ) - fprintf(f, ", "); - if( !j || cmds[i].keys[j] ) + fprintf(f, "# %s\n", cmds[i].description); + fprintf(f, "key %s = ", cmds[i].name); + for(j=0; j<MAX_COMMAND_KEYS; j++) { - if( cmds[i].keys[j]<256 && (isalpha(cmds[i].keys[j]) || - isdigit(cmds[i].keys[j])) ) - fprintf(f, "\'%c\'", cmds[i].keys[j]); - else - fprintf(f, "%d", cmds[i].keys[j]); + if( j && cmds[i].keys[j] ) + fprintf(f, ", "); + if( !j || cmds[i].keys[j] ) + { + if( cmds[i].keys[j]<256 && (isalpha(cmds[i].keys[j]) || + isdigit(cmds[i].keys[j])) ) + fprintf(f, "\'%c\'", cmds[i].keys[j]); + else + fprintf(f, "%d", cmds[i].keys[j]); + } } + fprintf(f,"\n\n"); } - fprintf(f,"\n\n"); i++; } return ferror(f); diff --git a/src/command.h b/src/command.h index c212ac025..593f6993e 100644 --- a/src/command.h +++ b/src/command.h @@ -3,6 +3,7 @@ #define MAX_COMMAND_KEYS 3 +/* commands */ typedef enum { CMD_NONE = 0, @@ -51,9 +52,15 @@ typedef enum CMD_QUIT } command_t; + +/* flags */ +#define COMMAND_KEY_MODIFIED 0x01 +#define COMMAND_KEY_CONFLICT 0x02 + typedef struct { int keys[MAX_COMMAND_KEYS]; + char flags; command_t command; char *name; char *description; @@ -63,7 +70,7 @@ command_definition_t *get_command_definitions(void); command_t find_key_command(int key, command_definition_t *cmds); void command_dump_keys(void); -int check_key_bindings(char *buf, size_t size); +int check_key_bindings(command_definition_t *cmds, char *buf, size_t size); int write_key_bindings(FILE *f); char *key2str(int key); diff --git a/src/main.c b/src/main.c index 0490e6ba7..2ace29740 100644 --- a/src/main.c +++ b/src/main.c @@ -169,7 +169,7 @@ main(int argc, const char *argv[]) read_configuration(options); /* check key bindings */ - key_error = check_key_bindings(NULL, 0); + key_error = check_key_bindings(NULL, NULL, 0); /* parse command line options - 2 pass */ options_parse(argc, argv); @@ -241,7 +241,7 @@ main(int argc, const char *argv[]) { char buf[BUFSIZE]; - key_error=check_key_bindings(buf, BUFSIZE); + key_error=check_key_bindings(NULL, buf, BUFSIZE); screen_status_printf("%s", buf); } diff --git a/src/screen_keydef.c b/src/screen_keydef.c index b85c094c5..7ea8c3fdb 100644 --- a/src/screen_keydef.c +++ b/src/screen_keydef.c @@ -137,10 +137,12 @@ delete_key(int cmd_index, int key_index) while( i<MAX_COMMAND_KEYS && cmds[cmd_index].keys[i] ) cmds[cmd_index].keys[key_index++] = cmds[cmd_index].keys[i++]; cmds[cmd_index].keys[key_index] = 0; - + cmds[cmd_index].flags |= COMMAND_KEY_MODIFIED; check_subcmd_length(); lw->clear = 1; lw->repaint = 1; + /* update key conflict flags */ + check_key_bindings(cmds, NULL, 0); } static void @@ -169,10 +171,14 @@ assign_new_key(WINDOW *w, int cmd_index, int key_index) return; } cmds[cmd_index].keys[key_index] = key; + cmds[cmd_index].flags |= COMMAND_KEY_MODIFIED; + screen_status_printf(_("Assigned %s to %s"), key2str(key),cmds[cmd_index].name); check_subcmd_length(); lw->repaint = 1; + /* update key conflict flags */ + check_key_bindings(cmds, NULL, 0); } static char * @@ -180,10 +186,15 @@ list_callback(int index, int *highlight, void *data) { static char buf[BUFSIZE]; + *highlight = 0; if( subcmd <0 ) { if( index<command_list_length ) - return cmds[index].name; + { + if( cmds[index].flags & COMMAND_KEY_CONFLICT ) + *highlight = 1; + return cmds[index].name; + } else if( index==LIST_ITEM_APPLY() ) return LIST_ITEM_APPLY_LABEL; else if( index==LIST_ITEM_SAVE() ) @@ -347,6 +358,10 @@ keydef_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) delete_key(subcmd, lw->selected-STATIC_SUB_ITEMS); return 1; break; + case CMD_SAVE_PLAYLIST: + apply_keys(); + save_keys(); + break; case CMD_LIST_FIND: case CMD_LIST_RFIND: case CMD_LIST_FIND_NEXT: |