From 919b0f13474fd323c7cd9e0b872b1990068a012d Mon Sep 17 00:00:00 2001 From: Kalle Wallin Date: Wed, 30 Jun 2004 17:18:02 +0000 Subject: [PATCH] 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 --- src/command.c | 170 +++++++++++++++++++++++++++----------------- src/command.h | 9 ++- src/main.c | 4 +- src/screen_keydef.c | 19 ++++- 4 files changed, 130 insertions(+), 72 deletions(-) diff --git a/src/command.c b/src/command.c index 2899d32..50dcdf7 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; jclear = 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( indexselected-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: -- 2.30.2