From: Christian Heller Date: Wed, 6 Nov 2013 05:20:24 +0000 (+0100) Subject: Strongly simplified / standardized user action interfaces. X-Git-Tag: tce~934 X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bprefix%7D%7D/%7Broute%7D?a=commitdiff_plain;h=c01d4595cbde0eaae357490b8b3305953293108c;p=plomrogue Strongly simplified / standardized user action interfaces. --- diff --git a/config/windows/toggle_order_and_active b/config/windows/toggle_order_and_active index 2ae7c2c..f188d83 100644 --- a/config/windows/toggle_order_and_active +++ b/config/windows/toggle_order_and_active @@ -1,2 +1,2 @@ kmicl -m +m \ No newline at end of file diff --git a/src/control.c b/src/control.c index 287c099..ca15c6d 100644 --- a/src/control.c +++ b/src/control.c @@ -6,87 +6,161 @@ * struct WinMeta */ #include "keybindings.h" /* for get_keycode_to_action(), mod_selected_keyb(), - * move_keyb_mod_selection() + * move_keyb_mod_selection(), get_func_to_keycode() */ -#include "map.h" /* for map_scroll() */ +#include "map.h" /* for map_scroll(), map_center() */ #include "main.h" /* for world global */ #include "rexit.h" /* for exit_err() */ -#include "wincontrol.h" /* for scroll_pad(), toggle_window(), - * growshrink_active_window(), toggle_winconfig(), +#include "wincontrol.h" /* for struct WinConf, scroll_pad(), toggle_window(), + * growshrink_active_window(),toggle_winconfig(), * toggle_win_height_type(), toggle_win_width_type() */ #include "map_object_actions.h" /* for player_wait(), move_player(), * player_drop(), player_pick() */ #include "command_db.h" /* for is_command_id_shortdsc() */ -#include "misc.h" /* for load_interface_conf(), unload_interface_conf(), - * save_interface_conf(), nav_inventory() +#include "misc.h" /* for reload_interface_conf(), save_interface_conf(), + * nav_inventory() */ -#include "yx_uint16.h" /* for dir enum */ -#include "map_objects.h" /* for get_player() */ -extern uint16_t get_available_keycode_to_action(char * name) +/* If "cmd" (either (type = "i") command or (type = "k") keybinding identifier) + * matches "match" in is_cmd_id_shortdsc() or get_available_keycode_to_action(), + * execute "f" with provided char arguments and return 1; else only return 0. + */ +static uint8_t try_cmd_0args(char type, int cmd, char * match, void (* f) ()); +static uint8_t try_cmd_1args(char type, int cmd, char * match, + void (* f) (char), char c); +static uint8_t try_cmd_2args(char type, int cmd, char * match, + void (* f) (char, char), char c1, char c2); + +/* 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 KeyBiData * select_keybidata_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); +static void wrap_cycle_active_win(char c); +static void wrap_shift_active_win(char c); + + + +static uint8_t try_cmd_0args(char type, int cmd, char * match, void (* f) ()) { - uint16_t keycode = get_keycode_to_action(world.kb_global.kbs, name); - if (0 != keycode || 0 == world.wmeta->active) + if ( ('k' == type && cmd == get_available_keycode_to_action(match)) + || ('i' == type && is_command_id_shortdsc(cmd, match))) { - return keycode; - } - struct WinConf * wc = get_winconf_by_win(world.wmeta->active); - if (0 == wc->view) - { - keycode = get_keycode_to_action(wc->kb.kbs, name); - } - else if (1 == wc->view) - { - keycode = get_keycode_to_action(world.kb_wingeom.kbs, name); + f(); + return 1; } - else if (2 == wc->view) + return 0; +} + + + +static uint8_t try_cmd_1args(char type, int cmd, char * match, + void (* f) (char), char c) +{ + if ( ('k' == type && cmd == get_available_keycode_to_action(match)) + || ('i' == type && is_command_id_shortdsc(cmd, match))) { - keycode = get_keycode_to_action(world.kb_winkeys.kbs, name); + f(c); + return 1; } - return keycode; + return 0; } -extern uint8_t player_control_by_id(int action) +static uint8_t try_cmd_2args(char type, int cmd, char * match, + void (* f) (char, char), char c1, char c2) { - if (is_command_id_shortdsc(action, "wait")) + if ( ('k' == type && cmd == get_available_keycode_to_action(match)) + || ('i' == type && is_command_id_shortdsc(cmd, match))) { - player_wait(); + f(c1, c2); + return 1; } - else if (is_command_id_shortdsc(action, "player_u")) + return 0; +} + + + +static struct KeyBiData * select_keybidata_pointer(char c) +{ + struct KeyBiData * kbd; + kbd = &world.kb_global; + if ('g' == c) { - move_player(NORTH); + kbd = &world.kb_wingeom; } - else if (is_command_id_shortdsc(action, "player_r")) + else if ('k' == c) { - move_player(EAST); + kbd = &world.kb_winkeys; } - else if (is_command_id_shortdsc(action, "player_d")) + else if ('w' == c) { - move_player(SOUTH); + struct WinConf * wc = get_winconf_by_win(world.wmeta->active); + kbd = &wc->kb; } - else if (is_command_id_shortdsc(action, "player_l")) + return kbd; +} + + + +static void wrap_mod_selected_keyb(char c) +{ + mod_selected_keyb(select_keybidata_pointer(c)); +} + + + +static void wrap_mv_kb_mod(char c1, char c2) +{ + move_keyb_mod_selection(select_keybidata_pointer(c1), c2); +} + + + +static void wrap_cycle_active_win(char c) +{ + cycle_active_win(world.wmeta, c); +} + + + +static void wrap_shift_active_win(char c) +{ + char * err = "Trouble with shift_active_win() in wingeom_control()."; + exit_err(shift_active_win(world.wmeta, c), err); +} + + + +extern uint16_t get_available_keycode_to_action(char * name) +{ + uint16_t keycode = get_keycode_to_action(world.kb_global.kbs, name); + if (0 != keycode || 0 == world.wmeta->active) { - move_player(WEST); + return keycode; } - else if (is_command_id_shortdsc(action, "drop")) + struct WinConf * wc = get_winconf_by_win(world.wmeta->active); + if (0 == wc->view) { - player_drop(); + keycode = get_keycode_to_action(wc->kb.kbs, name); } - else if (is_command_id_shortdsc(action, "pick")) + else if (1 == wc->view) { - player_pick(); + keycode = get_keycode_to_action(world.kb_wingeom.kbs, name); } - else + else if (2 == wc->view) { - return 0; + keycode = get_keycode_to_action(world.kb_winkeys.kbs, name); } - return 1; + return keycode; } @@ -109,214 +183,91 @@ extern uint8_t player_control_by_key(int key) -extern uint8_t wingeom_control(int key) +extern uint8_t player_control_by_id(int action) { - char * err_shift = "Trouble with shift_active_win() in wingeom_control()."; - char * err_resize = "Trouble with growshrink_active_window() in " - "wingeom_control()."; - if (key == get_available_keycode_to_action("to_height_t")) - { - toggle_win_height_type(world.wmeta->active); - } - else if (key == get_available_keycode_to_action("to_width_t")) - { - toggle_win_width_type(world.wmeta->active); - } - else if (key == get_available_keycode_to_action("grow_h")) - { - exit_err(growshrink_active_window('*'), err_resize); - } - else if (key == get_available_keycode_to_action("shri_h")) - { - exit_err(growshrink_active_window('_'), err_resize); - } - else if (key == get_available_keycode_to_action("grow_v")) - { - exit_err(growshrink_active_window('+'), err_resize); - } - else if (key == get_available_keycode_to_action("shri_v")) - { - exit_err(growshrink_active_window('-'), err_resize); - } - else if (key == get_available_keycode_to_action("shift_f")) + if ( try_cmd_0args('i', action, "wait", player_wait) + || try_cmd_0args('i', action, "drop", player_drop) + || try_cmd_0args('i', action, "pick", player_pick) + || try_cmd_1args('i', action, "player_u", move_player, 'N') + || try_cmd_1args('i', action, "player_d", move_player, 'S') + || try_cmd_1args('i', action, "player_r", move_player, 'E') + || try_cmd_1args('i', action, "player_l", move_player, 'W')) { - exit_err(shift_active_win(world.wmeta, 'f'), err_shift); - } - else if (key == get_available_keycode_to_action("shift_b")) - { - exit_err(shift_active_win(world.wmeta, 'b'), err_shift); - } - else - { - return 0; + return 1; } - return 1; + return 0; } -extern uint8_t winkeyb_control(int key) +extern uint8_t wingeom_control(int key) { - struct WinConf * wc = get_winconf_by_win(world.wmeta->active); - if (key == get_available_keycode_to_action("w_keys_u")) + if ( try_cmd_0args('k', key, "to_height_t", toggle_win_height_type) + || try_cmd_0args('k', key, "to_width_t", toggle_win_width_type) + || try_cmd_1args('k', key, "grow_h", growshrink_active_window, '*') + || try_cmd_1args('k', key, "shri_h", growshrink_active_window, '_') + || try_cmd_1args('k', key, "grow_v", growshrink_active_window, '+') + || try_cmd_1args('k', key, "shri_v", growshrink_active_window, '-') + || try_cmd_1args('k', key, "shift_f", wrap_shift_active_win, 'f') + || try_cmd_1args('k', key, "shift_b", wrap_shift_active_win, 'b')) { - move_keyb_mod_selection(&wc->kb, 'u'); - } - else if (key == get_available_keycode_to_action("w_keys_d")) - { - move_keyb_mod_selection(&wc->kb, 'd'); - } - else if (key == get_available_keycode_to_action("w_keys_m")) - { - mod_selected_keyb(&wc->kb); - } - else - { - return 0; + return 1; } - return 1; + return 0; } -extern uint8_t meta_control(int key) +extern uint8_t winkeyb_control(int key) { - struct WinMeta * win_meta = world.wmeta; - struct Win * win_map = get_win_by_id('m'); - char * err_toggle = "Trouble with toggle_window() in meta_control()."; - if (key == get_available_keycode_to_action("quit")) + if ( try_cmd_1args('k', key, "w_keys_m", wrap_mod_selected_keyb, 'w') + || try_cmd_2args('k', key, "w_keys_u", wrap_mv_kb_mod, 'w', 'u') + || try_cmd_2args('k', key, "w_keys_d", wrap_mv_kb_mod, 'w', 'd')) { return 1; } - else if (key == get_available_keycode_to_action("winconf")) - { - toggle_winconfig(world.wmeta->active); - } - else if (key == get_available_keycode_to_action("cyc_win_f")) - { - cycle_active_win(world.wmeta, 'f'); - } - else if (key == get_available_keycode_to_action("cyc_win_b")) - { - cycle_active_win(world.wmeta, 'b'); - } - else if (key == get_available_keycode_to_action("scrl_r")) - { - scroll_pad(win_meta, '+'); - } - else if (key == get_available_keycode_to_action("scrl_l")) - { - scroll_pad(win_meta, '-'); - } - else if (key == get_available_keycode_to_action("to_a_keywin")) - { - exit_err(toggle_window(win_meta, get_win_by_id('k')), err_toggle); - } - else if (key == get_available_keycode_to_action("to_g_keywin")) - { - exit_err(toggle_window(win_meta, get_win_by_id('0')), err_toggle); - } - else if (key == get_available_keycode_to_action("to_wg_keywin")) - { - exit_err(toggle_window(win_meta, get_win_by_id('1')), err_toggle); - } - else if (key == get_available_keycode_to_action("to_wk_keywin")) - { - exit_err(toggle_window(win_meta, get_win_by_id('2')), err_toggle); - } - else if (key == get_available_keycode_to_action("to_mapwin")) - { - exit_err(toggle_window(win_meta, win_map), err_toggle); - } - else if (key == get_available_keycode_to_action("to_infowin")) - { - exit_err(toggle_window(win_meta, get_win_by_id('i')), err_toggle); - } - else if (key == get_available_keycode_to_action("to_inv")) - { - exit_err(toggle_window(win_meta, get_win_by_id('c')), err_toggle); - } - else if (key == get_available_keycode_to_action("to_logwin")) - { - exit_err(toggle_window(win_meta, get_win_by_id('l')), err_toggle); - } - else if (key == get_available_keycode_to_action("save_conf")) - { - save_interface_conf(); - } - else if (key == get_available_keycode_to_action("g_keys_u")) - { - move_keyb_mod_selection(&world.kb_global, 'u'); - } - else if (key == get_available_keycode_to_action("g_keys_d")) - { - move_keyb_mod_selection(&world.kb_global, 'd'); - } - else if (key == get_available_keycode_to_action("g_keys_m")) - { - mod_selected_keyb(&world.kb_global); - } - else if (key == get_available_keycode_to_action("wg_keys_u")) - { - move_keyb_mod_selection(&world.kb_wingeom, 'u'); - } - else if (key == get_available_keycode_to_action("wg_keys_d")) - { - move_keyb_mod_selection(&world.kb_wingeom, 'd'); - } - else if (key == get_available_keycode_to_action("wg_keys_m")) - { - mod_selected_keyb(&world.kb_wingeom); - } - else if (key == get_available_keycode_to_action("wk_keys_u")) - { - move_keyb_mod_selection(&world.kb_winkeys, 'u'); - } - else if (key == get_available_keycode_to_action("wk_keys_d")) - { - move_keyb_mod_selection(&world.kb_winkeys, 'd'); - } - else if (key == get_available_keycode_to_action("wk_keys_m")) - { - mod_selected_keyb(&world.kb_winkeys); - } - else if (key == get_available_keycode_to_action("map_u")) - { - map_scroll(win_map, world.map->size, NORTH); - } - else if (key == get_available_keycode_to_action("map_d")) - { - map_scroll(win_map, world.map->size, SOUTH); - } - else if (key == get_available_keycode_to_action("map_r")) - { - map_scroll(win_map, world.map->size, EAST); - } - else if (key == get_available_keycode_to_action("map_l")) - { - map_scroll(win_map, world.map->size, WEST); - } - else if (key == get_available_keycode_to_action("map_c")) - { - struct MapObj * player = get_player(); - win_map->center = player->pos; - } - else if (key == get_available_keycode_to_action("inv_u")) - { - nav_inventory('u'); - } - else if (key == get_available_keycode_to_action("inv_d")) - { - nav_inventory('d'); - } - else if (key == get_available_keycode_to_action("reload_conf")) - { - unload_interface_conf(); - load_interface_conf(); - } - else if (key == get_available_keycode_to_action("winconf")) - { - toggle_winconfig(world.wmeta->active); - } return 0; } + + + +extern uint8_t meta_control(int key) +{ + uint8_t ret = (key == get_available_keycode_to_action("quit")); + if ( (0 == ret) + && ( try_cmd_0args('k', key, "winconf", toggle_winconfig) + || try_cmd_0args('k', key, "reload_conf", reload_interface_conf) + || try_cmd_0args('k', key, "save_conf", save_interface_conf) + || try_cmd_0args('k', key, "map_c", map_center) + || try_cmd_1args('k', key, "scrl_r", scroll_pad, '+') + || try_cmd_1args('k', key, "scrl_l", scroll_pad, '-') + || try_cmd_1args('k', key, "to_a_keywin", toggle_window, 'k') + || try_cmd_1args('k', key, "to_g_keywin", toggle_window, '0') + || try_cmd_1args('k', key, "to_wg_keywin", toggle_window, '1') + || try_cmd_1args('k', key, "to_wk_keywin", toggle_window, '2') + || try_cmd_1args('k', key, "to_mapwin", toggle_window, 'm') + || try_cmd_1args('k', key, "to_infowin", toggle_window, 'i') + || try_cmd_1args('k', key, "to_inv", toggle_window, 'c') + || try_cmd_1args('k', key, "to_logwin", toggle_window, 'l') + || try_cmd_1args('k', key, "cyc_win_f", wrap_cycle_active_win, 'f') + || try_cmd_1args('k', key, "cyc_win_b", wrap_cycle_active_win, 'b') + || try_cmd_1args('k', key, "g_keys_m", wrap_mod_selected_keyb, 'G') + || try_cmd_1args('k', key, "wg_keys_m", wrap_mod_selected_keyb, 'g') + || try_cmd_1args('k', key, "wk_keys_m", wrap_mod_selected_keyb, 'k') + || try_cmd_1args('k', key, "inv_u", nav_inventory, 'u') + || try_cmd_1args('k', key, "inv_d", nav_inventory, 'd') + || try_cmd_1args('k', key, "map_u", map_scroll, 'N') + || try_cmd_1args('k', key, "map_d", map_scroll, 'S') + || try_cmd_1args('k', key, "map_r", map_scroll, 'E') + || try_cmd_1args('k', key, "map_l", map_scroll, 'W') + || try_cmd_2args('k', key, "g_keys_u", wrap_mv_kb_mod, 'G', 'u') + || try_cmd_2args('k', key, "g_keys_d", wrap_mv_kb_mod, 'G', 'd') + || try_cmd_2args('k', key, "wg_keys_u", wrap_mv_kb_mod, 'g', 'u') + || try_cmd_2args('k', key, "wg_keys_d", wrap_mv_kb_mod, 'g', 'd') + || try_cmd_2args('k', key, "wk_keys_u", wrap_mv_kb_mod, 'k', 'u') + || try_cmd_2args('k', key, "wk_keys_d", wrap_mv_kb_mod, 'k', 'd'))) + { + ; + } + return ret; +} diff --git a/src/control.h b/src/control.h index 492ac88..30b2dda 100644 --- a/src/control.h +++ b/src/control.h @@ -18,8 +18,8 @@ extern uint16_t get_available_keycode_to_action(char * name); /* Control the player character, either via action id "action" or pressed "key". * Return 1 on success, 0 if no appropriate action to trigger was found. */ -extern uint8_t player_control_by_id(int action); extern uint8_t player_control_by_key(int key); +extern uint8_t player_control_by_id(int action); diff --git a/src/map.c b/src/map.c index 629e813..45cd2e1 100644 --- a/src/map.c +++ b/src/map.c @@ -1,10 +1,12 @@ #include "map.h" #include /* for uint16_t, uint32_t */ #include "misc.h" /* for try_malloc(), center_offset() */ -#include "map_objects.h" /* for Player struct */ +#include "map_objects.h" /* for get_player() */ #include "yx_uint16.h" /* for yx_uint16 and dir enums */ #include "rrand.h" /* for rrand() */ #include "windows.h" /* for struct Win */ +#include "main.h" /* for world global */ +#include "wincontrol.h" /* for get_win_by_id() */ @@ -53,33 +55,45 @@ extern struct Map init_map() -extern void map_scroll(struct Win * win, struct yx_uint16 map_size, enum dir d) +extern void map_scroll(char d) { + struct Win * win = get_win_by_id('m'); uint16_t offset; - if ((NORTH == d || SOUTH == d) && map_size.y > win->framesize.y) + if (('N' == d || 'S' == d) && world.map->size.y > win->framesize.y) { - offset = center_offset(win->center.y, map_size.y, win->framesize.y); + offset = center_offset(win->center.y, + world.map->size.y, win->framesize.y); win->center.y = offset + (win->framesize.y / 2); - if (NORTH == d && win->center.y > 0) + if ('N' == d && win->center.y > 0) { win->center.y--; } - else if (SOUTH == d && win->center.y < map_size.y - 1) + else if ('S' == d && win->center.y < world.map->size.y - 1) { win->center.y++; } } - else if ((WEST == d || EAST == d) && map_size.x > win->framesize.x) + else if (('W' == d || 'E' == d) && world.map->size.x > win->framesize.x) { - offset = center_offset(win->center.x, map_size.x, win->framesize.x); + offset = center_offset(win->center.x, + world.map->size.x, win->framesize.x); win->center.x = offset + (win->framesize.x / 2); - if (WEST == d && win->center.x > 0) + if ('W' == d && win->center.x > 0) { win->center.x--; } - else if (EAST == d && win->center.x < map_size.x - 1) + else if ('E' == d && win->center.x < world.map->size.x - 1) { win->center.x++; } } } + + + +extern void map_center() +{ + struct MapObj * player = get_player(); + struct Win * win_map = get_win_by_id('m'); + win_map->center = player->pos; +} diff --git a/src/map.h b/src/map.h index 7cc9871..4f67bb1 100644 --- a/src/map.h +++ b/src/map.h @@ -1,6 +1,6 @@ /* map.h * - * Struct for the game map and routines to manipulate it. + * Struct for the game map and routines to create and scroll on it. */ #ifndef MAP_H @@ -31,8 +31,15 @@ extern struct Map init_map(); -/* Try to change the view center of map "win" of "map_size" into dir "d". */ -extern void map_scroll(struct Win * win, struct yx_uint16 map_size, enum dir d); +/* Try to change the view center of map into directino described by "d" (north + * = "N", east = "E" etc.). + */ +extern void map_scroll(char d); + + + +/* Center map on player. */ +extern void map_center(); diff --git a/src/map_object_actions.c b/src/map_object_actions.c index 44e0263..9875997 100644 --- a/src/map_object_actions.c +++ b/src/map_object_actions.c @@ -64,7 +64,7 @@ static void actor_hits_actor(struct MapObj * hitter, struct MapObj * hitted) -extern uint8_t move_actor(struct MapObj * actor, enum dir d) +extern uint8_t move_actor(struct MapObj * actor, char d) { struct yx_uint16 target = mv_yx_in_dir(d, actor->pos); struct MapObj * other_actor; @@ -92,29 +92,29 @@ extern uint8_t move_actor(struct MapObj * actor, enum dir d) -extern void move_player(enum dir d) +extern void move_player(char d) { char * dsc_dir; char * action_dsc_prototype = "player_"; uint8_t len_action_dsc_prototype = strlen(action_dsc_prototype); char action_dsc[len_action_dsc_prototype + 2]; memcpy(action_dsc, action_dsc_prototype, len_action_dsc_prototype); - if (NORTH == d) + if ('N' == d) { dsc_dir = "north"; action_dsc[len_action_dsc_prototype] = 'u'; } - else if (EAST == d) + else if ('E' == d) { dsc_dir = "east" ; action_dsc[len_action_dsc_prototype] = 'r'; } - else if (SOUTH == d) + else if ('S' == d) { dsc_dir = "south"; action_dsc[len_action_dsc_prototype] = 'd'; } - else if (WEST == d) + else if ('W' == d) { dsc_dir = "west" ; action_dsc[len_action_dsc_prototype] = 'l'; diff --git a/src/map_object_actions.h b/src/map_object_actions.h index 46dc92c..1b2d95b 100644 --- a/src/map_object_actions.h +++ b/src/map_object_actions.h @@ -12,12 +12,12 @@ struct MapObj; -/* Try to move "actor" one step in direction "d" and handle the consequences: - * either the move succeeds, or another actor is encountered and hit (which - * leads to its lifepoint decreasing by one and potentially its death), or the - * target square is not passable and the move fails. +/* Try to move "actor" one step in direction "d" (where east is 'E', north 'N' + * etc.) and handle the consequences: either the move succeeds, or another actor + * is encountered and hit (which leads to its lifepoint decreasing by one and + * potentially its death), or the target square is not passable, the move fails. */ -extern uint8_t move_actor(struct MapObj * actor, enum dir d); +extern uint8_t move_actor(struct MapObj * actor, char d); @@ -25,7 +25,7 @@ extern uint8_t move_actor(struct MapObj * actor, enum dir d); * the game log with appropriate messages on the move attempt and its results; * turns over to turn_over() when finished. */ -extern void move_player(enum dir d); +extern void move_player(char d); diff --git a/src/misc.c b/src/misc.c index 466defa..30ed5ce 100644 --- a/src/misc.c +++ b/src/misc.c @@ -138,6 +138,14 @@ extern void unload_interface_conf() +extern void reload_interface_conf() +{ + unload_interface_conf(); + load_interface_conf(); +} + + + extern void update_log(char * text) { char * f_name = "update_log()"; @@ -228,7 +236,8 @@ extern void turn_over(char action) { if (0 < monster->lifepoints && 0 != monster->id) { - move_actor(monster, rrand() % 5); + char * sel = "\0NSEW"; + move_actor(monster, sel[rrand() % 5]); } } } diff --git a/src/misc.h b/src/misc.h index ed906c2..7e106fe 100644 --- a/src/misc.h +++ b/src/misc.h @@ -33,10 +33,11 @@ extern void check_files_xor(char * p1, char * p2); -/* Save / load / unload (free) interface configuration data. */ +/* Save / load / unload (free) / reload interface configuration data. */ extern void save_interface_conf(); extern void load_interface_conf(); extern void unload_interface_conf(); +extern void reload_interface_conf(); diff --git a/src/wincontrol.c b/src/wincontrol.c index 41ba945..2798455 100644 --- a/src/wincontrol.c +++ b/src/wincontrol.c @@ -10,7 +10,7 @@ * structs Win, WinMeta */ #include "yx_uint16.h" /* for yx_uint16 struct */ -#include "main.h" /* for Wins struct */ +#include "main.h" /* for world global */ #include "readwrite.h" /* for get_linemax(), try_fopen(), try_fclose(), * try_fgets(), try_fclose_unlink_rename(), try_fwrite() */ @@ -449,12 +449,11 @@ extern void sorted_wintoggle_and_activate() { continue; } - struct Win * win = get_win_by_id(win_order[i]); - toggle_window(world.wmeta, win); + toggle_window(win_order[i]); if (a == (uint8_t) win_order[i]) { - world.wmeta->active = win; + world.wmeta->active = get_win_by_id(win_order[i]); } } } @@ -498,23 +497,26 @@ extern void save_win_configs() -extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win) +extern void toggle_window(char id) { - if (0 == win->prev && win_meta->chain_start != win) /* Win outside chain. */ + char * err = "Trouble with toggle_window()."; + struct Win * win = get_win_by_id(id); + if (0 == win->prev && world.wmeta->chain_start != win) /* Win outside chain. */ { - return append_win(win_meta, win); + exit_err(append_win(world.wmeta, win), err); } else { - return suspend_win(win_meta, win); + exit_err(suspend_win(world.wmeta, win), err); } } -extern void toggle_winconfig(struct Win * win) +extern void toggle_winconfig() { - struct WinConf * wcp = get_winconf_by_win(win); + struct Win * win = world.wmeta->active; + struct WinConf * wcp = get_winconf_by_win(win); if (0 == wcp->view) { win->draw = draw_winconf_geometry; @@ -539,8 +541,9 @@ extern void toggle_winconfig(struct Win * win) -extern void toggle_win_height_type(struct Win * win) +extern void toggle_win_height_type() { + struct Win * win = world.wmeta->active; struct WinConf * wcp = get_winconf_by_win(win); if (0 == wcp->height_type) { @@ -555,8 +558,9 @@ extern void toggle_win_height_type(struct Win * win) -extern void toggle_win_width_type(struct Win * win) +extern void toggle_win_width_type() { + struct Win * win = world.wmeta->active; struct WinConf * wcp = get_winconf_by_win(win); if (0 == wcp->width_type && win->framesize.x <= world.wmeta->padsize.x) { @@ -571,22 +575,24 @@ extern void toggle_win_width_type(struct Win * win) -extern void scroll_pad(struct WinMeta * win_meta, char dir) +extern void scroll_pad(char dir) { if ('+' == dir) { - reset_pad_offset(win_meta, win_meta->pad_offset + 1); + reset_pad_offset(world.wmeta, world.wmeta->pad_offset + 1); } else if ('-' == dir) { - reset_pad_offset(win_meta, win_meta->pad_offset - 1); + reset_pad_offset(world.wmeta, world.wmeta->pad_offset - 1); } } -extern uint8_t growshrink_active_window(char change) +extern void growshrink_active_window(char change) { + char * err = "Trouble with resize_active_win() in " + "growshink_active_window()."; if (0 != world.wmeta->active) { struct yx_uint16 size = world.wmeta->active->framesize; @@ -606,7 +612,7 @@ extern uint8_t growshrink_active_window(char change) { size.x++; } - uint8_t x = resize_active_win(world.wmeta, size); + exit_err(resize_active_win(world.wmeta, size), err); struct WinConf * wcp = get_winconf_by_win(world.wmeta->active); if ( 1 == wcp->width_type && world.wmeta->active->framesize.x > world.wmeta->padsize.x) @@ -614,7 +620,5 @@ extern uint8_t growshrink_active_window(char change) wcp->width_type = 0; } set_winconf_geometry(wcp->id); - return x; } - return 0; } diff --git a/src/wincontrol.h b/src/wincontrol.h index f73ab4a..b75b0e7 100644 --- a/src/wincontrol.h +++ b/src/wincontrol.h @@ -67,27 +67,24 @@ extern void save_win_configs(); -/* Toggle "window configuration" view for "win". This also sets sensible values - * for win->center for the various configuration views (y=0, x=0 for +/* Toggle "window configuration" view for active window. This also sets sensible + * values for Win->center for the various configuration views (y=0, x=0 for * winconf_geometry and x= for winconf_keys). */ -extern void toggle_winconfig(struct Win * win); +extern void toggle_winconfig(); -/* Toggle interpretation type for Win's width/height of Win in WinConf. Width +/* Toggle interpretation type for active Win's width/height in WinConf. Width * only toggles to 1 if terminal window is at least as wide as WinConf->width. */ -extern void toggle_win_height_type(struct Win * win); -extern void toggle_win_width_type(struct Win * win); +extern void toggle_win_height_type(); +extern void toggle_win_width_type(); -/* Toggle display of a window "win". - * - * Return 0 on success, 1 on (ncurses pad/window memory allocation) error. - */ -extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win); +/* Toggle display of a window identified by "id". */ +extern void toggle_window(char id); @@ -95,7 +92,7 @@ extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win); * subject to the limitations provided by the window manager via * reset_pad_offset(). */ -extern void scroll_pad(struct WinMeta * win_meta, char dir); +extern void scroll_pad(char dir); @@ -104,10 +101,8 @@ extern void scroll_pad(struct WinMeta * win_meta, char dir); * provided by the window manager via resize_active_win(). * * Forces WinConf->width_type = 0 if new width surpasses that of terminal win. - * - * Return 0 on success, 1 on (ncurses pad/window memory allocation) error. */ -extern uint8_t growshrink_active_window(char change); +extern void growshrink_active_window(char change); diff --git a/src/yx_uint16.c b/src/yx_uint16.c index 54274f4..6adc034 100644 --- a/src/yx_uint16.c +++ b/src/yx_uint16.c @@ -20,21 +20,21 @@ extern uint8_t yx_uint16_cmp(struct yx_uint16 * a, struct yx_uint16 * b) -extern struct yx_uint16 mv_yx_in_dir(enum dir d, struct yx_uint16 yx) +extern struct yx_uint16 mv_yx_in_dir(char d, struct yx_uint16 yx) { - if (d == NORTH) + if (d == 'N') { yx.y--; } - else if (d == EAST) + else if (d == 'E') { yx.x++; } - else if (d == SOUTH) + else if (d == 'S') { yx.y++; } - else if (d == WEST) + else if (d == 'W') { yx.x--; } diff --git a/src/yx_uint16.h b/src/yx_uint16.h index 86812f4..7e3d13b 100644 --- a/src/yx_uint16.h +++ b/src/yx_uint16.h @@ -20,27 +20,17 @@ struct yx_uint16 -/* Directions available for movement. */ -enum dir -{ - NORTH = 1, - EAST, - SOUTH, - WEST -}; - - - /* Return 1 if two yx_uint16 coordinates at "a" and "b" are equal, else 0. */ extern uint8_t yx_uint16_cmp(struct yx_uint16 * a, struct yx_uint16 * b); -/* Return yx_uint16 coordinate one step from coordinate yx in direction dir. +/* Return yx_uint16 coordinate one step from coordinate yx in direction "dir" + * (east: 'E', west: 'W', north: 'N', south: 'S'). * * If an invalid dir "d" is passed, "yx" remains unchanged. */ -extern struct yx_uint16 mv_yx_in_dir(enum dir d, struct yx_uint16 yx); +extern struct yx_uint16 mv_yx_in_dir(char dir, struct yx_uint16 yx);