From: Christian Heller Date: Tue, 17 Sep 2013 02:48:33 +0000 (+0200) Subject: Also save active window selection in windows config. X-Git-Tag: tce~960 X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/blog?a=commitdiff_plain;h=967562b96d9903fc73ee04716dbeb639e18db823;p=plomrogue Also save active window selection in windows config. --- diff --git a/config/windows/toggle_order b/config/windows/toggle_order deleted file mode 100644 index 0b431e9..0000000 --- a/config/windows/toggle_order +++ /dev/null @@ -1 +0,0 @@ -kmil diff --git a/config/windows/toggle_order_and_active b/config/windows/toggle_order_and_active new file mode 100644 index 0000000..6053b2c --- /dev/null +++ b/config/windows/toggle_order_and_active @@ -0,0 +1,2 @@ +kmil +m \ No newline at end of file diff --git a/src/main.c b/src/main.c index 457aae5..046ef1a 100644 --- a/src/main.c +++ b/src/main.c @@ -22,7 +22,7 @@ * try_calloc(), check_tempfile(), check_xor_files() */ #include "wincontrol.h" /* for create_winconfs(), init_winconfs(), init_wins(), - * sorted_wintoggle() + * sorted_wintoggle_and_activate() */ #include "rrand.h" /* for rrand(), rrand_seed() */ #include "rexit.h" /* for exit_game(), exit_err() */ @@ -184,7 +184,7 @@ int main(int argc, char *argv[]) init_winconfs(&world); init_wins(&world); set_cleanup_flag(CLEANUP_WINCONFS); - sorted_wintoggle(&world); + sorted_wintoggle_and_activate(&world); err_winmem = "Trouble with draw_all_wins() in main()."; /* Replay mode. */ diff --git a/src/wincontrol.c b/src/wincontrol.c index 0fbb33c..6682087 100644 --- a/src/wincontrol.c +++ b/src/wincontrol.c @@ -23,7 +23,7 @@ * 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() */ @@ -173,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()"; @@ -424,15 +424,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++) { @@ -440,7 +449,13 @@ 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); + + if (a == (uint8_t) win_order[i]) + { + world->wmeta->active = win; + } } } @@ -455,7 +470,7 @@ extern void reload_win_config(struct World * world) free_winconfs(world); init_winconfs(world); init_wins(world); - sorted_wintoggle(world); + sorted_wintoggle_and_activate(world); } @@ -470,8 +485,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]; @@ -486,6 +501,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); } diff --git a/src/wincontrol.h b/src/wincontrol.h index 79f895a..b516a4f 100644 --- a/src/wincontrol.h +++ b/src/wincontrol.h @@ -53,11 +53,13 @@ extern void init_wins(struct World * world); /* Toggle windows in world->wins in the order desribed by the first line of - * config/windows/toggled_win_order, wherein each character should correspond to - * one window the ID of which is found in world->winconf_ids. Unknown characters - * are silently ignored. + * config/windows/toggle_order_and_active, wherein each character should + * correspond to one window whose ID is found in world->winconf_ids. Unknown + * characters are silently ignored. The first character of the second line of + * the file is also read to determine which window to focus as active (but only + * if it fits the ID of a window thus toggled visible). */ -extern void sorted_wintoggle(struct World * world); +extern void sorted_wintoggle_and_activate(struct World * world); /* Reload windows in order and sizes defined in win config. */ extern void reload_win_config(struct World * world);