home · contact · privacy
Unified (and heavily re-factored) (un-)loading/saving of keybindings and window confi...
authorChristian Heller <c.heller@plomlompom.de>
Thu, 19 Sep 2013 19:21:13 +0000 (21:21 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 19 Sep 2013 19:21:13 +0000 (21:21 +0200)
config/commands
config/keybindings_global
config/windows/toggle_order_and_active
src/control.c
src/main.c
src/misc.c
src/misc.h
src/rexit.c
src/rexit.h
src/wincontrol.c
src/wincontrol.h

index cdd65b96ea2d296ff8e39ab7e2dafab8d471d477..4eebf3ff4072c0c400637763c434aa75b5a0d9de 100644 (file)
@@ -35,9 +35,8 @@
 35 wk_keys_d win keybindings config keybindings nav down
 36 wk_keys_u win keybindings config keybindings nav up
 37 wk_keys_m win keybindings config keybindings modify
-38 reload_wins reload windows configuration
-39 save_winconf save windows' configuration
-40 save_keys save global keybindings
+38 reload_conf reload windows and keybindings configuration
+39 save_conf save windows and keybindings
 41 map_u map up
 42 map_d map down
 43 map_l map left
index 7d825a62510ffb6deb93f1d20e9bb10fa05614bb..739af7d7638bc47e04079004dde6ad4eea66ad6f 100644 (file)
@@ -12,6 +12,5 @@
 60 cyc_win_b
 262 scrl_l
 360 scrl_r
-114 reload_wins
-75 save_keys
-87 save_winconf
+114 reload_conf
+67 save_conf
index 2ae7c2cbb1461101f9d09d26632e73070ebef7f8..f188d839ab05bf4b020a4c1e9415c84c913d38a8 100644 (file)
@@ -1,2 +1,2 @@
 kmicl
-m
+m
\ No newline at end of file
index 8531b4c6b8be8059e7e60641c65ffd93dbc71db2..8455aaf041272167dbcbaeeb0ab949f2023bda0d 100644 (file)
@@ -5,19 +5,21 @@
 #include "windows.h" /* for cycle_active_win(), shift_active_win(), struct Win,
                       *  struct WinMeta
                       */
-#include "keybindings.h" /* for get_keycode_to_action(), save_keybindings(),
-                          * move_keyb_mod_selection(), mod_selected_keyb()
+#include "keybindings.h" /* for get_keycode_to_action(), mod_selected_keyb(),
+                          * move_keyb_mod_selection()
                           */
 #include "map.h" /* for map_scroll(), map_center_player(), dir enum */
 #include "main.h" /* for World struct */
 #include "rexit.h" /* for exit_err() */
 #include "wincontrol.h" /* for scroll_pad(), toggle_window(),
-                         * growshrink_active_window(), reload_win_config()
-                         * toggle_winconfig(), save_win_configs(),
+                         * growshrink_active_window(), toggle_winconfig(),
                          * toggle_win_height_type(), toggle_win_width_type()
                          */
 #include "map_object_actions.h" /* for player_wait(), move_player() */
 #include "command_db.h" /* for is_command_id_shortdsc() */
+#include "misc.h" /* for load_interface_conf(), unload_interface_conf(),
+                   * save_interface_conf()
+                   */
 
 
 
@@ -242,14 +244,9 @@ extern uint8_t meta_control(int key, struct World * world)
     {
         exit_err(toggle_window(win_meta, win_log), world, err_toggle);
     }
-    else if (key == get_available_keycode_to_action(world, "save_keys"))
+    else if (key == get_available_keycode_to_action(world, "save_conf"))
     {
-        save_keybindings(world, "config/keybindings_global",
-                         &world->kb_global);
-        save_keybindings(world, "config/keybindings_wingeom",
-                         &world->kb_wingeom);
-        save_keybindings(world, "config/keybindings_winkeys",
-                         &world->kb_winkeys);
+        save_interface_conf(world);
     }
     else if (key == get_available_keycode_to_action(world, "g_keys_u"))
     {
@@ -307,17 +304,14 @@ extern uint8_t meta_control(int key, struct World * world)
     {
         map_center_player(world->map, world->player, win_map->frame.size);
     }
-    else if (key == get_available_keycode_to_action(world, "reload_wins"))
+    else if (key == get_available_keycode_to_action(world, "reload_conf"))
     {
-        reload_win_config(world);
+        unload_interface_conf(world);
+        load_interface_conf(world);
     }
     else if (key == get_available_keycode_to_action(world, "winconf"))
     {
         toggle_winconfig(world, world->wmeta->active);
     }
-    else if (key == get_available_keycode_to_action(world, "save_winconf"))
-    {
-        save_win_configs(world);
-    }
     return 0;
 }
index 2c096aef69d6f3450d0b5fa718ee67f661d0cd0d..8d00a5df769bf6c76b3e6b8dba7ead74371143d7 100644 (file)
@@ -7,8 +7,7 @@
 #include <time.h> /* for time() */
 #include <unistd.h> /* for getopt(), optarg */
 #include <stdint.h> /* for uint16_t, uint32_t */
-#include "windows.h" /* for structs WinMeta, Win, init_win(), init_win_meta(),
-                      * draw_all_wins()
+#include "windows.h" /* for structs WinMeta, Win, init_win_meta(), draw_all_wins()
                       */
 #include "readwrite.h" /* for [read/write]_uint[8/16/32][_bigendian](),
                         * try_fopen(), try_fclose(), try_fclose_unlink_rename()
                           */
 #include "map.h" /* for struct Map, init_map() */
 #include "misc.h" /* for update_log(), find_passable_pos(), save_game(),
-                   * try_calloc(), check_tempfile(), check_xor_files()
+                   * try_calloc(), check_tempfile(), check_xor_files(),
+                   * load_interface_conf()
                    */
-#include "wincontrol.h" /* for create_winconfs(), init_winconfs(), init_wins(),
-                         * sorted_wintoggle_and_activate()
-                         */
+#include "wincontrol.h" /* get_win_by_id(), get_winconf_by_win() */
 #include "rrand.h" /* for rrand(), rrand_seed() */
 #include "rexit.h" /* for exit_game(), exit_err() */
 #include "command_db.h" /* for init_command_db() */
-#include "control.h" /* for *_control() */
-#include "keybindings.h" /* for init_keybindings(),
-                          * get_available_keycode_to_action()
-                          */
+#include "control.h" /* for *_control(), get_available_keycode_to_action() */
 
 
 
@@ -175,17 +170,11 @@ int main(int argc, char *argv[])
     curs_set(0);
     keypad(screen, TRUE);
     raw();
-    init_keybindings(&world, "config/keybindings_global",  &world.kb_global);
-    init_keybindings(&world, "config/keybindings_wingeom", &world.kb_wingeom);
-    init_keybindings(&world, "config/keybindings_winkeys", &world.kb_winkeys);
-    set_cleanup_flag(CLEANUP_KEYBINDINGS);
     char * err_winmem = "Trouble with init_win_meta() in main ().";
     exit_err(init_win_meta(screen, &world.wmeta), &world, err_winmem);
     set_cleanup_flag(CLEANUP_WIN_META);
-    init_winconfs(&world);
-    init_wins(&world);
-    set_cleanup_flag(CLEANUP_WINCONFS);
-    sorted_wintoggle_and_activate(&world);
+    load_interface_conf(&world);
+    set_cleanup_flag(CLEANUP_INTERFACE_CONF);
     err_winmem = "Trouble with draw_all_wins() in main().";
 
     /* Focus map on player. */
index 50fee6407854469819a691ccb8826943f55fd08a..e3499c10f7cd4f048a156a695e8cefb95415e712 100644 (file)
 #include "yx_uint16.h" /* for yx_uint16 struct */
 #include "rrand.h" /* for rrand(), rrand_seed() */
 #include "rexit.h" /* for exit_err() */
-
+#include "wincontrol.h" /* for init_winconfs(), init_wins(), free_winconfs(),
+                         * sorted_wintoggle_and_activate()
+                         */
+#include "windows.h" /* for suspend_win() */
 
 
 extern char * trouble_msg(struct World * w, char * parent, char * child)
@@ -95,6 +98,42 @@ extern void check_tempfile(char * path, struct World * w)
 
 
 
+extern void save_interface_conf(struct World * world)
+{
+    save_keybindings(world, "config/keybindings_global", &world->kb_global);
+    save_keybindings(world, "config/keybindings_wingeom", &world->kb_wingeom);
+    save_keybindings(world, "config/keybindings_winkeys", &world->kb_winkeys);
+    save_win_configs(world);
+}
+
+
+
+extern void load_interface_conf(struct World * world)
+{
+    init_keybindings(world, "config/keybindings_global",  &world->kb_global);
+    init_keybindings(world, "config/keybindings_wingeom", &world->kb_wingeom);
+    init_keybindings(world, "config/keybindings_winkeys", &world->kb_winkeys);
+    init_winconfs(world);
+    init_wins(world);
+    sorted_wintoggle_and_activate(world);
+}
+
+
+
+extern void unload_interface_conf(struct World * world)
+{
+    free_keybindings(world->kb_global.kbs);
+    free_keybindings(world->kb_wingeom.kbs);
+    free_keybindings(world->kb_winkeys.kbs);
+    while (0 != world->wmeta->active)
+    {
+        suspend_win(world->wmeta, world->wmeta->active);
+    }
+    free_winconfs(world);
+}
+
+
+
 extern void update_log(struct World * world, char * text)
 {
     char * f_name = "update_log()";
index 782a6fab0512a23a775515a6b4080f55d3b24669..831c4d1170d32374c73b04b38f10ecf8a69c1f93 100644 (file)
@@ -37,6 +37,13 @@ extern void check_files_xor(char * p1, char * p2, struct World * w);
 
 
 
+/* Save / load / unload (free) interface configuration data. */
+extern void save_interface_conf(struct World * world);
+extern void load_interface_conf(struct World * world);
+extern void unload_interface_conf(struct World * world);
+
+
+
 /* Update game log by appending "text", or by appending a "." if "text" is the
  * same as the last one passed.
  */
index e35e8a187d150dcad717c87e74825a5ae4b65d1c..1bc639f3a64ca147c6025f4943dddfb6d073a625 100644 (file)
@@ -13,6 +13,8 @@
 #include "windows.h" /* for Win struct, free_win(), free_winmeta() */
 #include "map_objects.h" /* for free_item_defs(), free_monster_defs() */
 #include "wincontrol.h" /* for free_winconfs() */
+#include "misc.h" /* for unload_interface_conf() */
+
 
 
 /* The clean-up routine and the flag resource by which it decides what to do. */
@@ -49,20 +51,26 @@ static void cleanup(struct World * world)
     {
         free(world->map->cells);
     }
-    if (cleanup_flags & CLEANUP_KEYBINDINGS)
+    if (cleanup_flags & CLEANUP_INTERFACE_CONF)
     {
-        free_keybindings(world->kb_global.kbs);
-        free_keybindings(world->kb_wingeom.kbs);
-        free_keybindings(world->kb_winkeys.kbs);
+        unload_interface_conf(world);
     }
     if (cleanup_flags & CLEANUP_WIN_META)
     {
         free_winmeta(world->wmeta);
     }
+/*
+    if (cleanup_flags & CLEANUP_KEYBINDINGS)
+    {
+        free_keybindings(world->kb_global.kbs);
+        free_keybindings(world->kb_wingeom.kbs);
+        free_keybindings(world->kb_winkeys.kbs);
+    }
     if (cleanup_flags & CLEANUP_WINCONFS)
     {
         free_winconfs(world);
     }
+*/
 }
 
 
index 4738844b8922984323cb2d284b81769242921e95..4c6ddb00dbf4da8f9dec44da1bc9432ab5017871 100644 (file)
@@ -22,13 +22,12 @@ enum cleanup_flag
 {
     CLEANUP_NCURSES         = 0x0001,
     CLEANUP_MAP             = 0x0002,
-    CLEANUP_KEYBINDINGS     = 0x0004,
-    CLEANUP_LOG             = 0x0008,
-    CLEANUP_COMMAND_DB      = 0x0010,
-    CLEANUP_MAP_OBJECTS     = 0x0020,
-    CLEANUP_MAP_OBJECT_DEFS = 0x0040,
-    CLEANUP_WIN_META        = 0x0080,
-    CLEANUP_WINCONFS        = 0x0100
+    CLEANUP_LOG             = 0x0004,
+    CLEANUP_COMMAND_DB      = 0x0008,
+    CLEANUP_MAP_OBJECTS     = 0x0010,
+    CLEANUP_MAP_OBJECT_DEFS = 0x0020,
+    CLEANUP_WIN_META        = 0x0040,
+    CLEANUP_INTERFACE_CONF  = 0x0080
 };
 extern void set_cleanup_flag(enum cleanup_flag flag);
 
index 529457c0dc866f19e7cec44a2544cdd1b589099d..91431814f9fd6629850b3d5696e0e3985aa1b596 100644 (file)
@@ -465,20 +465,6 @@ extern void sorted_wintoggle_and_activate(struct World * world)
 
 
 
-extern void reload_win_config(struct World * world)
-{
-    while (0 != world->wmeta->active)
-    {
-        suspend_win(world->wmeta, world->wmeta->active);
-    }
-    free_winconfs(world);
-    init_winconfs(world);
-    init_wins(world);
-    sorted_wintoggle_and_activate(world);
-}
-
-
-
 extern void save_win_configs(struct World * world)
 {
     char * f_name = "save_win_configs()";
index b516a4fdfad0ff2bb28458664e71706eb17980ff..416cc91c40cd32a84cacdbe1ed3595e8ac24737f 100644 (file)
@@ -61,8 +61,7 @@ extern void init_wins(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);
+
 
 /* Save all window's configurations to their configuration files. */
 extern void save_win_configs(struct World * world);