From: Christian Heller Date: Fri, 7 Nov 2014 14:00:00 +0000 (+0100) Subject: Client: Restructure passing of keybinding manipulation commands. X-Git-Tag: tce~616 X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/%7B%7Bprefix%7D%7D/condition?a=commitdiff_plain;h=06e80a3d3fa38c2465d58eef1306dfebe4512497;p=plomrogue Client: Restructure passing of keybinding manipulation commands. --- diff --git a/confclient/commands b/confclient/commands index f5b987e..71004bf 100644 --- a/confclient/commands +++ b/confclient/commands @@ -74,13 +74,13 @@ DESCRIPTION 'scroll pad left' COMMAND scrl_r DESCRIPTION 'scroll pad right' -COMMAND g_keys_d +COMMAND keyb_dG DESCRIPTION 'nav down global keys' -COMMAND g_keys_u +COMMAND keyb_uG DESCRIPTION 'nav up global keys' -COMMAND g_keys_m +COMMAND keyb_mG DESCRIPTION 'mod global keys' COMMAND winconf @@ -113,31 +113,31 @@ DESCRIPTION 'nav down object' COMMAND inv_u DESCRIPTION 'nav up object' -COMMAND w_keys_d +COMMAND keyb_dw DESCRIPTION 'nav down window keys' -COMMAND w_keys_u +COMMAND keyb_uw DESCRIPTION 'nav up window nav' -COMMAND w_keys_m +COMMAND keyb_mw DESCRIPTION 'mod window key' -COMMAND wg_keys_d +COMMAND keyb_dg DESCRIPTION 'nav down win geometry config keys' -COMMAND wg_keys_u +COMMAND keyb_ug DESCRIPTION 'nav up win geometry config keys' -COMMAND wg_keys_m +COMMAND keyb_mg DESCRIPTION 'mod win geometry config keys' -COMMAND wk_keys_d +COMMAND keyb_dk DESCRIPTION 'nav down win keys config keys' -COMMAND wk_keys_u +COMMAND keyb_uk DESCRIPTION 'nav up win keys config keys' -COMMAND wk_keys_m +COMMAND keyb_mk DESCRIPTION 'mod win keys config keys' COMMAND reload_conf diff --git a/confclient/interface_conf b/confclient/interface_conf index 96a6b2e..820e199 100644 --- a/confclient/interface_conf +++ b/confclient/interface_conf @@ -29,30 +29,39 @@ KEY 121 to_height_t KEY 120 to_width_t KEYBINDINGS 'winkeys' -KEY 258 w_keys_d -KEY 259 w_keys_u -KEY 10 w_keys_m +KEY 258 keyb_dw +KEY 259 keyb_uw +KEY 10 keyb_mw WIN_ORDER 'micl0a' WIN_FOCUS 'm' +WINDOW 0 +NAME 'Set global keys' +BREAK 0 +WIDTH 22 +HEIGHT 7 +KEY 258 keyb_dG +KEY 259 keyb_uG +KEY 10 keyb_mG + WINDOW 1 NAME 'Set window geometry keys' BREAK 0 WIDTH 29 HEIGHT 9 -KEY 258 wg_keys_d -KEY 259 wg_keys_u -KEY 10 wg_keys_m +KEY 258 keyb_dg +KEY 259 keyb_ug +KEY 10 keyb_mg WINDOW 2 NAME 'Set window keybinding keys' BREAK 0 WIDTH 29 HEIGHT 3 -KEY 258 wk_keys_d -KEY 259 wk_keys_u -KEY 10 wk_keys_m +KEY 258 keyb_dk +KEY 259 keyb_uk +KEY 10 keyb_mk WINDOW c NAME 'Inventory' @@ -97,15 +106,6 @@ KEY 261 map_r KEY 46 map_c KEY 70 to_autofocus -WINDOW 0 -NAME 'Set global keys' -BREAK 0 -WIDTH 22 -HEIGHT 7 -KEY 258 g_keys_d -KEY 259 g_keys_u -KEY 10 g_keys_m - WINDOW a NAME 'Active window`s keys' BREAK 0 diff --git a/confclient/single_wins/info b/confclient/single_wins/info index c17470d..bf9c031 100644 --- a/confclient/single_wins/info +++ b/confclient/single_wins/info @@ -41,9 +41,9 @@ KEY 121 to_height_t KEY 120 to_width_t KEYBINDINGS 'winkeys' -KEY 258 w_keys_d -KEY 259 w_keys_u -KEY 10 w_keys_m +KEY 258 keyb_dw +KEY 259 keyb_uw +KEY 10 keyb_mw WIN_ORDER 'i' WIN_FOCUS 'i' @@ -54,23 +54,32 @@ BREAK 2 WIDTH 0 HEIGHT 0 +WINDOW 0 +NAME 'Set global keys' +BREAK 0 +WIDTH 22 +HEIGHT 7 +KEY 258 keyb_dG +KEY 259 keyb_uG +KEY 10 keyb_mG + WINDOW 1 NAME 'Set window geometry keys' BREAK 0 WIDTH 29 HEIGHT 9 -KEY 258 wg_keys_d -KEY 259 wg_keys_u -KEY 10 wg_keys_m +KEY 258 keyb_dg +KEY 259 keyb_ug +KEY 10 keyb_mg WINDOW 2 NAME 'Set window keybinding keys' BREAK 0 WIDTH 29 HEIGHT 3 -KEY 258 wk_keys_d -KEY 259 wk_keys_u -KEY 10 wk_keys_m +KEY 258 keyb_dk +KEY 259 keyb_uk +KEY 10 keyb_mk WINDOW c NAME 'Inventory' @@ -109,18 +118,8 @@ KEY 261 map_r KEY 46 map_c KEY 70 to_autofocus -WINDOW 0 -NAME 'Set global keys' -BREAK 0 -WIDTH 22 -HEIGHT 7 -KEY 258 g_keys_d -KEY 259 g_keys_u -KEY 10 g_keys_m - WINDOW a NAME 'Active window`s keys' BREAK 0 WIDTH 22 HEIGHT -8 - diff --git a/confclient/single_wins/inventory b/confclient/single_wins/inventory index 481e9dc..fbc775e 100644 --- a/confclient/single_wins/inventory +++ b/confclient/single_wins/inventory @@ -41,9 +41,9 @@ KEY 121 to_height_t KEY 120 to_width_t KEYBINDINGS 'winkeys' -KEY 258 w_keys_d -KEY 259 w_keys_u -KEY 10 w_keys_m +KEY 258 keyb_dw +KEY 259 keyb_uw +KEY 10 keyb_mw WIN_ORDER 'c' WIN_FOCUS 'c' @@ -56,23 +56,32 @@ HEIGHT 0 KEY 259 inv_u KEY 258 inv_d +WINDOW 0 +NAME 'Set global keys' +BREAK 0 +WIDTH 22 +HEIGHT 7 +KEY 258 keyb_dG +KEY 259 keyb_uG +KEY 10 keyb_mG + WINDOW 1 NAME 'Set window geometry keys' BREAK 0 WIDTH 29 HEIGHT 9 -KEY 258 wg_keys_d -KEY 259 wg_keys_u -KEY 10 wg_keys_m +KEY 258 keyb_dg +KEY 259 keyb_ug +KEY 10 keyb_mg WINDOW 2 NAME 'Set window keybinding keys' BREAK 0 WIDTH 29 HEIGHT 3 -KEY 258 wk_keys_d -KEY 259 wk_keys_u -KEY 10 wk_keys_m +KEY 258 keyb_dk +KEY 259 keyb_uk +KEY 10 keyb_mk WINDOW i NAME 'Info' @@ -107,15 +116,6 @@ KEY 261 map_r KEY 46 map_c KEY 70 to_autofocus -WINDOW 0 -NAME 'Set global keys' -BREAK 0 -WIDTH 22 -HEIGHT 7 -KEY 258 g_keys_d -KEY 259 g_keys_u -KEY 10 g_keys_m - WINDOW a NAME 'Active window`s keys' BREAK 0 diff --git a/confclient/single_wins/log b/confclient/single_wins/log index c5825c6..d064db5 100644 --- a/confclient/single_wins/log +++ b/confclient/single_wins/log @@ -41,9 +41,9 @@ KEY 121 to_height_t KEY 120 to_width_t KEYBINDINGS 'winkeys' -KEY 258 w_keys_d -KEY 259 w_keys_u -KEY 10 w_keys_m +KEY 258 keyb_dw +KEY 259 keyb_uw +KEY 10 keyb_mw WIN_ORDER 'l' WIN_FOCUS 'l' @@ -54,23 +54,32 @@ BREAK 0 WIDTH 0 HEIGHT 0 +WINDOW 0 +NAME 'Set global keys' +BREAK 0 +WIDTH 22 +HEIGHT 7 +KEY 258 keyb_dG +KEY 259 keyb_uG +KEY 10 keyb_mG + WINDOW 1 NAME 'Set window geometry keys' BREAK 0 WIDTH 29 HEIGHT 9 -KEY 258 wg_keys_d -KEY 259 wg_keys_u -KEY 10 wg_keys_m +KEY 258 keyb_dg +KEY 259 keyb_ug +KEY 10 keyb_mg WINDOW 2 NAME 'Set window keybinding keys' BREAK 0 WIDTH 29 HEIGHT 3 -KEY 258 wk_keys_d -KEY 259 wk_keys_u -KEY 10 wk_keys_m +KEY 258 keyb_dk +KEY 259 keyb_uk +KEY 10 keyb_mk WINDOW c NAME 'Inventory' @@ -109,15 +118,6 @@ KEY 261 map_r KEY 46 map_c KEY 70 to_autofocus -WINDOW 0 -NAME 'Set global keys' -BREAK 0 -WIDTH 22 -HEIGHT 7 -KEY 258 g_keys_d -KEY 259 g_keys_u -KEY 10 g_keys_m - WINDOW a NAME 'Active window`s keys' BREAK 0 diff --git a/confclient/single_wins/map b/confclient/single_wins/map index 77ddc78..38ed98a 100644 --- a/confclient/single_wins/map +++ b/confclient/single_wins/map @@ -41,9 +41,9 @@ KEY 121 to_height_t KEY 120 to_width_t KEYBINDINGS 'winkeys' -KEY 258 w_keys_d -KEY 259 w_keys_u -KEY 10 w_keys_m +KEY 258 keyb_dw +KEY 259 keyb_uw +KEY 10 keyb_mw WIN_ORDER 'm' WIN_FOCUS 'm' @@ -58,23 +58,32 @@ KEY 258 map_d KEY 260 map_l KEY 261 map_r +WINDOW 0 +NAME 'Set global keys' +BREAK 0 +WIDTH 22 +HEIGHT 7 +KEY 258 keyb_dG +KEY 259 keyb_uG +KEY 10 keyb_mG + WINDOW 1 NAME 'Set window geometry keys' BREAK 0 WIDTH 29 HEIGHT 9 -KEY 258 wg_keys_d -KEY 259 wg_keys_u -KEY 10 wg_keys_m +KEY 258 keyb_dg +KEY 259 keyb_ug +KEY 10 keyb_mg WINDOW 2 NAME 'Set window keybinding keys' BREAK 0 WIDTH 29 HEIGHT 3 -KEY 258 wk_keys_d -KEY 259 wk_keys_u -KEY 10 wk_keys_m +KEY 258 keyb_dk +KEY 259 keyb_uk +KEY 10 keyb_mk WINDOW c NAME 'Inventory' @@ -98,15 +107,6 @@ BREAK 0 WIDTH 13 HEIGHT -8 -WINDOW 0 -NAME 'Set global keys' -BREAK 0 -WIDTH 22 -HEIGHT 7 -KEY 258 g_keys_d -KEY 259 g_keys_u -KEY 10 g_keys_m - WINDOW a NAME 'Active window`s keys' BREAK 0 diff --git a/src/client/control.c b/src/client/control.c index 5595ccc..536c567 100644 --- a/src/client/control.c +++ b/src/client/control.c @@ -9,7 +9,7 @@ #include /* uint8_t, uint16_t, uint32_t, UINT32_MAX */ #include /* free() */ #include /* sprintf() */ -#include /* strlen() */ +#include /* strlen(), strcmp(), strncmp() */ #include "../common/rexit.h" /* exit_err(), exit_trouble() */ #include "../common/try_malloc.h" /* try_malloc() */ #include "interface_conf.h" /* reload_interface_conf(), save_interface_conf() */ @@ -37,8 +37,12 @@ static void nav_inventory(char dir); static uint8_t try_0args(struct Command * command, char * match, void (* f) ()); static uint8_t try_1args(struct Command * command, char * match, void (* f) (char), char c); -static uint8_t try_2args(struct Command * command, char * match, - void (* f) (char, char), char c1, char c2); + +/* If "command" fits pattern "keyb_XY" with Y a proper keybinding list ID char + * and X one of "u" (for "up"), "d" (for "down") or "m" (for "modify"), move up + * or down or modify entry in the selected keybinding list. + */ +static uint8_t try_kb_manip(char * command); /* Try if "command" matches a hard-coded list of client-only commands and, if * successful, execute the match and return 1. Else, return 0. @@ -106,12 +110,23 @@ static uint8_t try_1args(struct Command * command, char * match, -static uint8_t try_2args(struct Command * command, char * match, - void (* f) (char, char), char c1, char c2) +/* If "command" fits pattern "keyb_XY" with Y a proper keybinding list ID char + * and X one of "u" (for "up"), "d" (for "down") or "m" (for "modify"), move up + * or down or modify entry in the selected keybinding list. + */ +static uint8_t try_kb_manip(char * command) { - if (!strcmp(command->dsc_short, match)) + char * cmp = "keyb_"; + if (strlen(command) == strlen(cmp)+2 && !strncmp(command, cmp, strlen(cmp))) { - f(c1, c2); + if ('m' == command[strlen(cmp)]) + { + mod_selected_keyb(command[strlen(cmp) + 1]); + } + else if ('u' == command[strlen(cmp)] || 'd' == command[strlen(cmp)]) + { + move_keyb_selection(command[strlen(cmp) + 1], command[strlen(cmp)]); + } return 1; } return 0; @@ -153,18 +168,7 @@ static uint8_t try_client_commands(struct Command * command) || try_1args(command, "shift_b", shift_active_win, 'b') || try_0args(command, "reload_conf", reload_interface_conf) || try_0args(command, "save_conf", save_interface_conf) - || try_1args(command, "g_keys_m", mod_selected_keyb, 'G') - || try_2args(command, "g_keys_u", move_keyb_selection, 'G', 'u') - || try_2args(command, "g_keys_d", move_keyb_selection, 'G', 'd') - || try_1args(command, "w_keys_m", mod_selected_keyb, 'w') - || try_2args(command, "w_keys_u", move_keyb_selection, 'w', 'u') - || try_2args(command, "w_keys_d", move_keyb_selection, 'w', 'd') - || try_1args(command, "wg_keys_m", mod_selected_keyb, 'g') - || try_2args(command, "wg_keys_u", move_keyb_selection, 'g', 'u') - || try_2args(command, "wg_keys_d", move_keyb_selection, 'g', 'd') - || try_1args(command, "wk_keys_m", mod_selected_keyb, 'k') - || try_2args(command, "wk_keys_u", move_keyb_selection, 'k', 'u') - || try_2args(command, "wk_keys_d", move_keyb_selection, 'k', 'd')); + || try_kb_manip(command->dsc_short)); } diff --git a/src/client/map.h b/src/client/map.h index 0031da2..bd919d8 100644 --- a/src/client/map.h +++ b/src/client/map.h @@ -23,4 +23,6 @@ extern void map_center(); /* Toggle world.focus_each_turn (auto-centering of map on player each turn). */ extern void toggle_autofocus(); + + #endif diff --git a/src/client/windows.h b/src/client/windows.h index 3b272e2..91f3f7b 100644 --- a/src/client/windows.h +++ b/src/client/windows.h @@ -60,7 +60,7 @@ struct Win struct yx_uint16 target_center; /* saves .center when toggling .view */ struct yx_uint16 frame_size; /* size of window/frame to see winmap through*/ struct yx_uint16 start; /* upper left corner of window in v_screen */ - struct yx_uint16 center; /* winnap cell to center frame on if < winmap */ + struct yx_uint16 center; /* winmap cell to center frame on if < winmap */ struct yx_uint16 winmap_size; /* delimits .winmap, sorts it into lines */ chtype * winmap; /* window content in sequence of chtype's to write */ int16_t target_height; /* window size / .frame_size description in config */