4 #include <stdint.h> /* for uint8_t */
5 #include "windows.h" /* for cycle_active_win(), shift_active_win(), struct Win,
8 #include "keybindings.h" /* for get_keycode_to_action(), mod_selected_keyb(),
9 * move_keyb_mod_selection(), get_func_to_keycode()
11 #include "map.h" /* for map_scroll(), map_center() */
12 #include "main.h" /* for world global */
13 #include "rexit.h" /* for exit_err() */
14 #include "wincontrol.h" /* for struct WinConf, scroll_pad(), toggle_window(),
15 * growshrink_active_window(),toggle_winconfig(),
16 * toggle_win_height_type(), toggle_win_width_type()
18 #include "map_object_actions.h" /* for player_wait(), move_player(),
19 * player_drop(), player_pick()
21 #include "command_db.h" /* for is_command_id_shortdsc() */
22 #include "misc.h" /* for reload_interface_conf(), save_interface_conf(),
28 /* If "cmd" (either (type = "i") command or (type = "k") keybinding identifier)
29 * matches "match" in is_cmd_id_shortdsc() or get_available_keycode_to_action(),
30 * execute "f" with provided char arguments and return 1; else only return 0.
32 static uint8_t try_cmd_0args(char type, int cmd, char * match, void (* f) ());
33 static uint8_t try_cmd_1args(char type, int cmd, char * match,
34 void (* f) (char), char c);
35 static uint8_t try_cmd_2args(char type, int cmd, char * match,
36 void (* f) (char, char), char c1, char c2);
38 /* Return pointer to global keybindings or to keybindings for wingeometry config
39 * (c = "g") or winkeys config (c = "k") or active window's keybindings ("w").
41 static struct KeyBiData * select_keybidata_pointer(char c);
43 /* Wrappers to make some functions compatible to try_cmd_* single char args. */
44 static void wrap_mod_selected_keyb(char c);
45 static void wrap_mv_kb_mod(char c1, char c2);
49 static uint8_t try_cmd_0args(char type, int cmd, char * match, void (* f) ())
51 if ( ('k' == type && cmd == get_available_keycode_to_action(match))
52 || ('i' == type && is_command_id_shortdsc(cmd, match)))
62 static uint8_t try_cmd_1args(char type, int cmd, char * match,
63 void (* f) (char), char c)
65 if ( ('k' == type && cmd == get_available_keycode_to_action(match))
66 || ('i' == type && is_command_id_shortdsc(cmd, match)))
76 static uint8_t try_cmd_2args(char type, int cmd, char * match,
77 void (* f) (char, char), char c1, char c2)
79 if ( ('k' == type && cmd == get_available_keycode_to_action(match))
80 || ('i' == type && is_command_id_shortdsc(cmd, match)))
90 static struct KeyBiData * select_keybidata_pointer(char c)
92 struct KeyBiData * kbd;
93 kbd = &world.kb_global;
96 kbd = &world.kb_wingeom;
100 kbd = &world.kb_winkeys;
104 struct WinConf * wc = get_winconf_by_win(world.wmeta->active);
112 static void wrap_mod_selected_keyb(char c)
114 mod_selected_keyb(select_keybidata_pointer(c));
119 static void wrap_mv_kb_mod(char c1, char c2)
121 move_keyb_mod_selection(select_keybidata_pointer(c1), c2);
126 extern uint16_t get_available_keycode_to_action(char * name)
128 uint16_t keycode = get_keycode_to_action(world.kb_global.kbs, name);
129 if (0 != keycode || 0 == world.wmeta->active)
133 struct WinConf * wc = get_winconf_by_win(world.wmeta->active);
136 keycode = get_keycode_to_action(wc->kb.kbs, name);
138 else if (1 == wc->view)
140 keycode = get_keycode_to_action(world.kb_wingeom.kbs, name);
142 else if (2 == wc->view)
144 keycode = get_keycode_to_action(world.kb_winkeys.kbs, name);
151 extern uint8_t player_control_by_key(int key)
153 char * action_name = get_func_to_keycode(world.kb_global.kbs, key);
154 if (NULL == action_name && 0 != world.wmeta->active)
156 struct WinConf * wc = get_winconf_by_win(world.wmeta->active);
157 action_name = get_func_to_keycode(wc->kb.kbs, key);
159 if (NULL != action_name)
161 uint8_t action_id = get_command_id(action_name);
162 return player_control_by_id(action_id);
169 extern uint8_t player_control_by_id(int action)
171 if ( try_cmd_0args('i', action, "wait", player_wait)
172 || try_cmd_0args('i', action, "drop", player_drop)
173 || try_cmd_0args('i', action, "pick", player_pick)
174 || try_cmd_0args('i', action, "use", player_use)
175 || try_cmd_1args('i', action, "player_u", move_player, 'N')
176 || try_cmd_1args('i', action, "player_d", move_player, 'S')
177 || try_cmd_1args('i', action, "player_r", move_player, 'E')
178 || try_cmd_1args('i', action, "player_l", move_player, 'W'))
187 extern uint8_t wingeom_control(int key)
189 if ( try_cmd_0args('k', key, "to_height_t", toggle_win_height_type)
190 || try_cmd_0args('k', key, "to_width_t", toggle_win_width_type)
191 || try_cmd_1args('k', key, "grow_h", growshrink_active_window, '*')
192 || try_cmd_1args('k', key, "shri_h", growshrink_active_window, '_')
193 || try_cmd_1args('k', key, "grow_v", growshrink_active_window, '+')
194 || try_cmd_1args('k', key, "shri_v", growshrink_active_window, '-')
195 || try_cmd_1args('k', key, "shift_f", shift_active_win, 'f')
196 || try_cmd_1args('k', key, "shift_b", shift_active_win, 'b'))
205 extern uint8_t winkeyb_control(int key)
207 if ( try_cmd_1args('k', key, "w_keys_m", wrap_mod_selected_keyb, 'w')
208 || try_cmd_2args('k', key, "w_keys_u", wrap_mv_kb_mod, 'w', 'u')
209 || try_cmd_2args('k', key, "w_keys_d", wrap_mv_kb_mod, 'w', 'd'))
218 extern uint8_t meta_control(int key)
220 uint8_t ret = (key == get_available_keycode_to_action("quit"));
222 && ( try_cmd_0args('k', key, "winconf", toggle_winconfig)
223 || try_cmd_0args('k', key, "reload_conf", reload_interface_conf)
224 || try_cmd_0args('k', key, "save_conf", save_interface_conf)
225 || try_cmd_0args('k', key, "map_c", map_center)
226 || try_cmd_1args('k', key, "scrl_r", scroll_pad, '+')
227 || try_cmd_1args('k', key, "scrl_l", scroll_pad, '-')
228 || try_cmd_1args('k', key, "to_a_keywin", toggle_window, 'k')
229 || try_cmd_1args('k', key, "to_g_keywin", toggle_window, '0')
230 || try_cmd_1args('k', key, "to_wg_keywin", toggle_window, '1')
231 || try_cmd_1args('k', key, "to_wk_keywin", toggle_window, '2')
232 || try_cmd_1args('k', key, "to_mapwin", toggle_window, 'm')
233 || try_cmd_1args('k', key, "to_infowin", toggle_window, 'i')
234 || try_cmd_1args('k', key, "to_inv", toggle_window, 'c')
235 || try_cmd_1args('k', key, "to_logwin", toggle_window, 'l')
236 || try_cmd_1args('k', key, "cyc_win_f", cycle_active_win, 'f')
237 || try_cmd_1args('k', key, "cyc_win_b", cycle_active_win, 'b')
238 || try_cmd_1args('k', key, "g_keys_m", wrap_mod_selected_keyb, 'G')
239 || try_cmd_1args('k', key, "wg_keys_m", wrap_mod_selected_keyb, 'g')
240 || try_cmd_1args('k', key, "wk_keys_m", wrap_mod_selected_keyb, 'k')
241 || try_cmd_1args('k', key, "inv_u", nav_inventory, 'u')
242 || try_cmd_1args('k', key, "inv_d", nav_inventory, 'd')
243 || try_cmd_1args('k', key, "map_u", map_scroll, 'N')
244 || try_cmd_1args('k', key, "map_d", map_scroll, 'S')
245 || try_cmd_1args('k', key, "map_r", map_scroll, 'E')
246 || try_cmd_1args('k', key, "map_l", map_scroll, 'W')
247 || try_cmd_2args('k', key, "g_keys_u", wrap_mv_kb_mod, 'G', 'u')
248 || try_cmd_2args('k', key, "g_keys_d", wrap_mv_kb_mod, 'G', 'd')
249 || try_cmd_2args('k', key, "wg_keys_u", wrap_mv_kb_mod, 'g', 'u')
250 || try_cmd_2args('k', key, "wg_keys_d", wrap_mv_kb_mod, 'g', 'd')
251 || try_cmd_2args('k', key, "wk_keys_u", wrap_mv_kb_mod, 'k', 'u')
252 || try_cmd_2args('k', key, "wk_keys_d", wrap_mv_kb_mod, 'k', 'd')))