X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;f=src%2Fwincontrol.c;h=5680ff97ee3de08ba2694ebab86d797ca078f8b0;hb=d1dfbfa5a6f5f05d761238010b4f853088e3a373;hp=6095d36a7a25dcd17f9888d0566edbea1929ce66;hpb=550d22ec0c3f530f5d317746f3f7e75251a1de4b;p=plomrogue diff --git a/src/wincontrol.c b/src/wincontrol.c index 6095d36..5680ff9 100644 --- a/src/wincontrol.c +++ b/src/wincontrol.c @@ -17,12 +17,13 @@ #include "rexit.h" /* for exit_err() */ #include "main.h" /* for World struct */ #include "draw_wins.h" /* for draw_win_map(), draw_win_info(), draw_win_og(), - * draw_win_keybindings_global(), + * draw_win_available_keybindings(), + * draw_win_keybindings_global(), draw_win_inventory(), * draw_win_keybindings_winconf_geometry(), * draw_win_keybindings_winconf_keybindings(), * draw_winconf_geometry(), draw_winconf_keybindings() */ -#include "misc.h" /* for try_malloc() */ +#include "misc.h" /* for try_malloc(), trouble_msg() */ #include "dirent.h" /* for opendir(), closedir(), readdir() */ #include "errno.h" /* for errno */ #include "keybindings.h" /* for KeyBinding struct, free_keybindings() */ @@ -172,7 +173,7 @@ static void init_win_from_winconf(struct World * world, char id) -extern void save_win_config(struct World * world, char id) +static void save_win_config(struct World * world, char id) { char * f_name = "save_win_config()"; @@ -207,12 +208,12 @@ extern void save_win_config(struct World * world, char id) } linemax = linemax + 6; /* + 6 = + 3 digits + whitespace + \n + \0 */ - char keyb_line[linemax]; + char kb_line[linemax]; kb_p = wc->kb.kbs; while (0 != kb_p) { - snprintf(keyb_line, linemax, "%d %s\n", kb_p->key, kb_p->name); - try_fwrite(keyb_line, sizeof(char), strlen(keyb_line), file, world, f_name); + snprintf(kb_line, linemax, "%d %s\n", kb_p->key, kb_p->name); + try_fwrite(kb_line, sizeof(char), strlen(kb_line), file, world, f_name); kb_p = kb_p->next; } @@ -239,20 +240,19 @@ static void set_winconf_geometry(struct World * world, char id) struct WinConf * wcp = get_winconf_by_id(world, id); if (0 == wcp->height_type) { - wcp->height = wcp->win->frame.size.y; + wcp->height = wcp->win->framesize.y; } else if (1 == wcp->height_type) { - wcp->height = wcp->win->frame.size.y - world->wmeta->padframe.size.y - + 1; + wcp->height = wcp->win->framesize.y - world->wmeta->padsize.y + 1; } if (0 == wcp->width_type) { - wcp->width = wcp->win->frame.size.x; + wcp->width = wcp->win->framesize.x; } else if (1 == wcp->width_type) { - wcp->width = wcp->win->frame.size.x - world->wmeta->padframe.size.x; + wcp->width = wcp->win->framesize.x - world->wmeta->padsize.x; } } @@ -275,6 +275,10 @@ static struct WinConf * get_winconf_by_id(struct World * world, char id) static void * get_drawfunc_by_char(char c) { + if ('c' == c) + { + return draw_win_inventory; + } if ('i' == c) { return draw_win_info; @@ -283,6 +287,10 @@ static void * get_drawfunc_by_char(char c) { return draw_win_log; } + else if ('k' == c) + { + return draw_win_available_keybindings; + } else if ('m' == c) { return draw_win_map; @@ -419,15 +427,24 @@ extern void init_wins(struct World * world) -extern void sorted_wintoggle(struct World * world) +extern void sorted_wintoggle_and_activate(struct World * world) { - char * f_name = "sorted_wintoggle()"; - char * path = "config/windows/toggle_order"; + char * f_name = "sorted_wintoggle_and_activate()"; + + char * path = "config/windows/toggle_order_and_active"; FILE * file = try_fopen(path, "r", world, f_name); uint16_t linemax = get_linemax(file, world, f_name); + char win_order[linemax + 1]; try_fgets(win_order, linemax + 1, file, world, f_name); + + uint8_t a = 0; + char * err = trouble_msg(world, f_name, "read_uint8()"); + exit_err(read_uint8(file, &a), world, err); + free(err); + try_fclose(file, world, f_name); + uint8_t i = 0; for (; i < linemax - 1; i++) { @@ -435,22 +452,14 @@ extern void sorted_wintoggle(struct World * world) { continue; } - toggle_window(world->wmeta, get_win_by_id(world, win_order[i])); - } -} - + struct Win * win = get_win_by_id(world, win_order[i]); + toggle_window(world->wmeta, win); - -extern void reload_win_config(struct World * world) -{ - while (0 != world->wmeta->active) - { - suspend_win(world->wmeta, world->wmeta->active); + if (a == (uint8_t) win_order[i]) + { + world->wmeta->active = win; + } } - free_winconfs(world); - init_winconfs(world); - init_wins(world); - sorted_wintoggle(world); } @@ -465,8 +474,8 @@ extern void save_win_configs(struct World * world) save_win_config(world, id); } - char * path = "config/windows/toggle_order"; - char * path_tmp = "config/windows/toggle_order_tmp"; + char * path = "config/windows/toggle_order_and_active"; + char * path_tmp = "config/windows/toggle_order_and_active_tmp"; FILE * file = try_fopen(path_tmp, "w", world, f_name); char line[6]; @@ -481,6 +490,11 @@ extern void save_win_configs(struct World * world) } line[i] = '\n'; try_fwrite(line, sizeof(char), strlen(line), file, world, f_name); + if (0 != world->wmeta->active) + { + struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active); + write_uint8(wc->id, file); + } try_fclose_unlink_rename(file, path_tmp, path, world, f_name); } @@ -489,13 +503,13 @@ extern void save_win_configs(struct World * world) extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win) { - if (0 != win->frame.curses_win) + if (0 == win->prev && win_meta->chain_start != win) /* Win outside chain. */ { - return suspend_win(win_meta, win); + return append_win(win_meta, win); } else { - return append_win(win_meta, win); + return suspend_win(win_meta, win); } } @@ -508,15 +522,20 @@ extern void toggle_winconfig(struct World * world, struct Win * win) { win->draw = draw_winconf_geometry; wcp->view = 1; + wcp->center = win->center; + win->center.y = 0; + win->center.x = 0; } else if (1 == wcp->view) { win->draw = draw_winconf_keybindings; wcp->view = 2; + win->center.x = 0; } else { win->draw = get_drawfunc_by_char(wcp->draw); + win->center = wcp->center; wcp->view = 0; } } @@ -542,8 +561,7 @@ extern void toggle_win_height_type(struct World * world, struct Win * win) extern void toggle_win_width_type(struct World * world, struct Win * win) { struct WinConf * wcp = get_winconf_by_win(world, win); - if ( 0 == wcp->width_type - && win->frame.size.x <= world->wmeta->padframe.size.x) + if (0 == wcp->width_type && win->framesize.x <= world->wmeta->padsize.x) { wcp->width_type = 1; } @@ -574,7 +592,7 @@ extern uint8_t growshrink_active_window(struct World * world, char change) { if (0 != world->wmeta->active) { - struct yx_uint16 size = world->wmeta->active->frame.size; + struct yx_uint16 size = world->wmeta->active->framesize; if (change == '-') { size.y--; @@ -594,8 +612,7 @@ extern uint8_t growshrink_active_window(struct World * world, char change) uint8_t x = resize_active_win(world->wmeta, size); struct WinConf * wcp = get_winconf_by_win(world, world->wmeta->active); if ( 1 == wcp->width_type - && world->wmeta->active->frame.size.x - > world->wmeta->padframe.size.x) + && world->wmeta->active->framesize.x > world->wmeta->padsize.x) { wcp->width_type = 0; }