From: Christian Heller Date: Wed, 22 Jan 2014 05:08:10 +0000 (+0100) Subject: Client: Moved KeyBindingDB selection by char into keybindings library, making wrapper... X-Git-Tag: tce~881 X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/%7B%7Bprefix%7D%7D/test?a=commitdiff_plain;h=f118d194b29320b6fbebd254207514aba1241b08;p=plomrogue Client: Moved KeyBindingDB selection by char into keybindings library, making wrapper functions unnecessary. --- diff --git a/src/client/control.c b/src/client/control.c index 7e1a596..906cf29 100644 --- a/src/client/control.c +++ b/src/client/control.c @@ -5,9 +5,8 @@ #include /* sprintf() */ #include /* strlen() */ #include "io.h" /* try_send() */ -#include "keybindings.h" /* struct KeyBindingDB, get_command_to_keycode(), - * get_keycode_to_command(), mod_selected_keyb(), - * move_keyb_mod_selection() +#include "keybindings.h" /* get_command_to_keycode(), get_keycode_to_command(), + * mod_selected_keyb(), move_keyb_selection() */ #include "map_window.h" /* for map_scroll(), map_center() */ #include "misc.h" /* reload_interface_conf(), save_interface_conf(), @@ -22,15 +21,6 @@ -/* Return pointer to global keybindings or to keybindings for wingeometry config - * (c = "g") or winkeys config (c = "k") or active window's keybindings ("w"). - */ -static struct KeyBindingDB * select_keybindingdb_pointer(char c); - -/* Wrappers to make some functions compatible to try_cmd_* single char args. */ -static void wrap_mod_selected_keyb(char c); -static void wrap_mv_kb_mod(char c1, char c2); - /* If "command"'s .dsc_short fits "match", apply "f" with provided char * arguments and return 1; else, return 0. */ @@ -53,42 +43,6 @@ static uint8_t try_server_commands(struct Command * command); -static struct KeyBindingDB * select_keybindingdb_pointer(char c) -{ - struct KeyBindingDB * kbd; - kbd = &world.kb_global; - if ('g' == c) - { - kbd = &world.kb_wingeom; - } - else if ('k' == c) - { - kbd = &world.kb_winkeys; - } - else if ('w' == c) - { - struct WinConf * wc = get_winconf_by_win(world.wmeta.active); - kbd = &wc->kb; - } - return kbd; -} - - - -static void wrap_mod_selected_keyb(char c) -{ - mod_selected_keyb(select_keybindingdb_pointer(c)); -} - - - -static void wrap_mv_kb_mod(char c1, char c2) -{ - move_keyb_mod_selection(select_keybindingdb_pointer(c1), c2); -} - - - static uint8_t try_0args(struct Command * command, char * match, void (* f) ()) { if (!strcmp(command->dsc_short, match)) @@ -143,9 +97,6 @@ static uint8_t try_client_commands(struct Command * command) || try_1args(command, "to_logwin", toggle_window, 'l') || try_1args(command, "cyc_win_f", cycle_active_win, 'f') || try_1args(command, "cyc_win_b", cycle_active_win, 'b') - || try_1args(command, "g_keys_m", wrap_mod_selected_keyb, 'G') - || try_1args(command, "wg_keys_m", wrap_mod_selected_keyb, 'g') - || try_1args(command, "wk_keys_m", wrap_mod_selected_keyb, 'k') || try_1args(command, "inv_u", nav_inventory, 'u') || try_1args(command, "inv_d", nav_inventory, 'd') || try_1args(command, "map_u", map_scroll, 'N') @@ -160,15 +111,18 @@ static uint8_t try_client_commands(struct Command * command) || try_1args(command, "shri_v", growshrink_active_window, '-') || try_1args(command, "shift_f", shift_active_win, 'f') || try_1args(command, "shift_b", shift_active_win, 'b') - || try_1args(command, "w_keys_m", wrap_mod_selected_keyb, 'w') - || try_2args(command, "w_keys_u", wrap_mv_kb_mod, 'w', 'u') - || try_2args(command, "w_keys_d", wrap_mv_kb_mod, 'w', 'd') - || try_2args(command, "g_keys_u", wrap_mv_kb_mod, 'G', 'u') - || try_2args(command, "g_keys_d", wrap_mv_kb_mod, 'G', 'd') - || try_2args(command, "wg_keys_u", wrap_mv_kb_mod, 'g', 'u') - || try_2args(command, "wg_keys_d", wrap_mv_kb_mod, 'g', 'd') - || try_2args(command, "wk_keys_u", wrap_mv_kb_mod, 'k', 'u') - || try_2args(command, "wk_keys_d", wrap_mv_kb_mod, 'k', 'd')); + || try_1args(command, "g_keys_m", mod_selected_keyb, 'G') + || try_1args(command, "wg_keys_m", mod_selected_keyb, 'g') + || try_1args(command, "wk_keys_m", mod_selected_keyb, 'k') + || try_1args(command, "w_keys_m", mod_selected_keyb, 'w') + || try_2args(command, "wg_keys_u", move_keyb_selection, 'g', 'u') + || try_2args(command, "wg_keys_d", move_keyb_selection, 'g', 'd') + || try_2args(command, "wk_keys_u", move_keyb_selection, 'k', 'u') + || try_2args(command, "wk_keys_d", move_keyb_selection, 'k', 'd') + || try_2args(command, "w_keys_u", move_keyb_selection, 'w', 'u') + || try_2args(command, "w_keys_d", move_keyb_selection, 'w', 'd') + || try_2args(command, "g_keys_u", move_keyb_selection, 'G', 'u') + || try_2args(command, "g_keys_d", move_keyb_selection, 'G', 'd')); } diff --git a/src/client/keybindings.c b/src/client/keybindings.c index ab34d24..7363535 100644 --- a/src/client/keybindings.c +++ b/src/client/keybindings.c @@ -10,7 +10,8 @@ * try_fclose(), try_fclose_unlink_rename(), * try_fwrite() */ -#include "../common/try_malloc.h" /* for try_malloc() */ +#include "../common/try_malloc.h" /* try_malloc() */ +#include "wincontrol.h" /* get_winconf_by_win() */ #include "windows.h" /* draw_all_wins() */ #include "world.h" /* global world */ @@ -22,6 +23,11 @@ static struct KeyBinding * get_keyb_of_n(struct KeyBinding * kb_p, uint16_t n); /* Return number of keybindings in keybindings chain from "kb_p" on. */ static uint16_t get_n_of_keybs(struct KeyBinding * kb_p); +/* Return pointer to global keybindings or to keybindings for wingeometry config + * (c = "g") or winkeys config (c = "k") or active window's keybindings ("w"). + */ +static struct KeyBindingDB * char_selected_kb_db(char c); + /* If "keycode_given" equals "keycode_match", copy "keyname_match" to "keyname" * and return 1; otherwise return 0. */ @@ -64,6 +70,28 @@ static uint16_t get_n_of_keybs(struct KeyBinding * kb_p) +static struct KeyBindingDB * char_selected_kb_db(char c) +{ + struct KeyBindingDB * kbd; + kbd = &world.kb_global; + if ('g' == c) + { + kbd = &world.kb_wingeom; + } + else if ('k' == c) + { + kbd = &world.kb_winkeys; + } + else if ('w' == c) + { + struct WinConf * wc = get_winconf_by_win(world.wmeta.active); + kbd = &wc->kb; + } + return kbd; +} + + + static uint8_t try_keycode(uint16_t keycode_given, char * keyname, uint16_t keycode_match, char * keyname_match) { @@ -211,8 +239,9 @@ extern void free_keybindings(struct KeyBinding * kb_start) -extern void mod_selected_keyb(struct KeyBindingDB * kbd) +extern void mod_selected_keyb(char kb_c) { + struct KeyBindingDB * kbd = char_selected_kb_db(kb_c); kbd->edit = 1; draw_all_wins(); cbreak(); @@ -228,8 +257,9 @@ extern void mod_selected_keyb(struct KeyBindingDB * kbd) -extern void move_keyb_mod_selection(struct KeyBindingDB * kbd, char dir) +extern void move_keyb_selection(char kb_c, char dir) { + struct KeyBindingDB * kbd = char_selected_kb_db(kb_c); if ('u' == dir && kbd->select > 0) { kbd->select--; diff --git a/src/client/keybindings.h b/src/client/keybindings.h index e288203..b191c59 100644 --- a/src/client/keybindings.h +++ b/src/client/keybindings.h @@ -45,16 +45,16 @@ extern void save_keybindings(char * path, struct KeyBindingDB * kbd); /* Free keybinding chain starting at "kb_start". */ extern void free_keybindings(struct KeyBinding * kb_start); -/* Mark keybinding selected for modification as being edited, get user input to - * modify it, then unmark it again. Ensure there are max. three digits in the - * ASCII representation of the keycode read from the user. +/* Mark keybinding in KeybindingDB (char_selected_kb_db()-) selected by "kb_c" + * as being edited, get user input to modify it, then unmark it again. Ensure + * there are max. three digits in the ASCII string of the kecode read from user. */ -extern void mod_selected_keyb(struct KeyBindingDB * kbd); +extern void mod_selected_keyb(char kb_c); -/* Move keybinding modification selection upwards ("dir"=="u") or downwards - * ("dir"=="d") within the limits of the keybindings chain length. +/* Move .select in KeybindingDB (char-selected_kb_db()-) selected by "kb_c" + * upwards ("dir"=="u") or downwards ("dir"=="d") within KeyBindingDB limits. */ -extern void move_keyb_mod_selection(struct KeyBindingDB * kbd, char dir); +extern void move_keyb_selection(char kb_c, char dir);