home · contact · privacy
License everything (GPL).
[plomrogue] / src / client / wincontrol.c
index eda233b43ab762d3bdba90f6fe6e4bc486731770..eb9270b411130e5f4ce38471de247a817060857c 100644 (file)
-/* src/client/wincontrol.c */
+/* src/client/wincontrol.c
+ *
+ * This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
+ * or any later version. For details on its copyright, license, and warranties,
+ * see the file NOTICE in the root directory of the PlomRogue source package.
+ */
 
 #include "wincontrol.h"
-#include <errno.h> /* global errno */
-#include <dirent.h> /* DIR, struct dirent, opendir(), closedir(), readdir() */
-#include <stdint.h> /* uint8_t, uint16_t, uint32_t */
-#include <stdio.h> /* FILE */
-#include <stdlib.h> /* free(), atoi() */
-#include <string.h> /* strlen(), strchr(), strstr(), memcpy() */
-#include "../common/readwrite.h" /* try_fopen(), textfile_sizes(), try_fgets(),
-                                  * textfile_sizes(), try_fwrite(), try_fgetc(),
-                                  * try_fclose_unlink_rename(), try_fputc()
-                                  */
+#include <ncurses.h> /* getmaxx(), getmaxy(), wresize() */
+#include <stddef.h> /* NULL */
+#include <stdint.h> /* uint8_t, uint32_t, UINT16_MAX */
+#include <stdio.h> /* sprintf() */
+#include <stdlib.h> /* free() */
+#include <string.h> /* memcpy(), memset(), strchr(), strlen() */
 #include "../common/rexit.h" /* exit_err(), exit_trouble() */
 #include "../common/try_malloc.h" /* try_malloc() */
-#include "../common/yx_uint16.h" /* struct yx_uint16 */
-#include "draw_wins.h" /* draw_win_map(), draw_win_info(), draw_win_log(),
-                        * draw_win_available_keybindings(),
-                        * draw_win_inventory(), draw_win_keybindings_global(),
-                        * draw_win_keybindings_winconf_geometry(),
-                        * draw_win_keybindings_winconf_keybindings(),
-                        * draw_winconf_geometry(), draw_winconf_keybindings()
-                        */
-#include "keybindings.h" /* struct KeyBinding, free_keybindings() */
-#include "windows.h" /* struct Win, resize_active_win(), reset_pad_offset(),
-                      * append_win(), suspend_win(), init_win(), free_win()
-                      */
+#include "windows.h" /* Win,yx_uint16, get_win_by_id(),get_win_pos_in_order() */
 #include "world.h" /* global world */
 
 
 
-/* Return string "prefix" + "id"; malloc()'s string, remember to call free()! */
-static char * string_prefixed_id(char * prefix, char id);
-
-/* Initialize Winconf of "id" from appropriate config file.*/
-static void init_winconf_from_file(char id, struct WinConf * winconf);
-
-/* Wrapper around init_win() called with values from Winconf of "id". */
-static void init_win_from_winconf(char id);
-
-/* Save title, draw function, size of window identified by "id" to conffile. */
-static void save_win_config(char id);
+/* Get Win before window identified by "c" or NULL if there is none. */
+static struct Win * get_win_before(char c);
 
-/* Free data pointed to inside individual WinConf struct of "id". */
-static void free_winconf_data(char id);
+/* Make .v_screen just wide enough to contain all visible windows. */
+static void refit_v_screen();
 
-/* Write geometry of a window to its WinConf, as positive or negative values
- * (dependent on state ofWinConf->height_type / WinConf->width_type).
+/* Update geometry (sizes, positions) of window "w" and its successors in the
+ * window chain. Use place_win() for the positioning algorithm.
  */
-static void set_winconf_geometry(char id);
-
-/* Get WinConf by "id"; get id of WinConf mothering "win". */
-static struct WinConf * get_winconf_by_id(char id);
-
-/* Get (Win->draw) function identified by "c"; NULL if c not mapped to one. */
-static void * get_drawfunc_by_char(char c);
-
-/* Iterate over chars of world.winconf_db.winconf_ids array. Restart after \0.*/
-static char get_next_winconf_id();
-
+static void update_wins(struct Win * w);
+static void place_win(struct Win * w);
 
+/* Write "win"'s size back to .target_(height/width) as per .target_*_type. */
+static void set_win_target_size(struct Win * win);
 
-static char * string_prefixed_id(char * prefix, char id)
-{
-    uint8_t size = strlen(prefix) + 2;
-    char * path = try_malloc(size, "string_prefixed_id()");
-    sprintf(path, "%s_", prefix);
-    path[size - 2] = id;
-    return path;
-}
+/* Append/suspend window "w" to/from chain of visible windows. Appended windows
+ * will become active. Suspended active windows will move the active window
+ * selection to their successor in the window chain or, failing that, their
+ * predecessor, or, failing that, to 0 (no window active).
+ */
+static void append_win(struct Win * w);
+static void suspend_win(struct Win * w);
 
 
 
-static void init_winconf_from_file(char id, struct WinConf * winconf)
+extern struct Win * get_win_before(char c)
 {
-    /* Assign WinConf id to filename path, error message context, winconf->id.*/
-    char * tmp = "init_winconf_from_file() on window id '_'";
-    char * context = try_malloc(strlen(tmp) + 1, "init_winconf_from_file()");
-    memcpy(context, tmp, strlen(tmp) + 1);
-    context[strlen(tmp) - 2] = id;
-    char * path = string_prefixed_id("confclient/windows/Win_", id);
-    winconf->id = id;
-
-    /* Prepare reading in file line by line into "line" array. */
-    FILE * file = try_fopen(path, "r", context);
-    free(path);
-    uint32_t linemax = textfile_sizes(file, NULL);
-    char line[linemax + 1];
-
-    /* Read/determine winconf->title, ->draw, ->height(_type),->width(_type). */
-    try_fgets(line, linemax + 1, file, context);
-    winconf->title = try_malloc(strlen(line), context);
-    memcpy(winconf->title, line, strlen(line) - 1); /* Eliminate newline char */
-    winconf->title[strlen(line) - 1] = '\0';        /* char at end of string. */
-    try_fgets(line, linemax + 1, file, context);
-    winconf->draw = line[0];
-    try_fgets(line, linemax + 1, file, context);
-    winconf->height = atoi(line);
-    winconf->height_type = (0 >= winconf->height);
-    try_fgets(line, linemax + 1, file, context);
-    winconf->width = atoi(line);
-    winconf->width_type = (0 >= winconf->width);
-
-    /* Read in window-specific keybindings (winconf->kb). */
-    char command[linemax + 1];
-    char * cmdptr;
-    struct KeyBinding ** loc_last_ptr = &winconf->kb.kbs;
-    * loc_last_ptr = 0;
-    while (try_fgets(command, linemax + 1, file, context))
+    uint8_t i = get_win_pos_in_order(c);
+    if (i > 0)
     {
-        if ('\n' == command[0] || 0 == command[0])
-        {
-            break;
-        }
-        * loc_last_ptr = try_malloc(sizeof(struct KeyBinding), context);
-        struct KeyBinding * kb_p = * loc_last_ptr;
-        kb_p->next = 0;
-        kb_p->key = atoi(command);
-        cmdptr = strchr(command, ' ') + 1;
-        kb_p->command = try_malloc(strlen(cmdptr), context);
-        memcpy(kb_p->command, cmdptr, strlen(cmdptr) - 1);
-        kb_p->command[strlen(cmdptr) - 1] = '\0';
-        loc_last_ptr = & kb_p->next;
+        return get_win_by_id(world.winDB.order[i - 1]);
     }
-
-    /* Init remaining values to zero and cleaning up. */
-    winconf->view = 0;
-    winconf->kb.edit = 0;
-    winconf->kb.select = 0;
-    try_fclose(file, context);
-    free(context);
-}
-
-
-
-static void init_win_from_winconf(char id)
-{
-    char * err = "get_drawfunc_by_char() returns NULL to init_win_from_file().";
-    struct WinConf * winconf = get_winconf_by_id(id);
-    void * f = get_drawfunc_by_char(winconf->draw);
-    exit_err(NULL == f, err);
-    init_win(&winconf->win, winconf->title, winconf->height, winconf->width, f);
+    return NULL;
 }
 
 
 
-static void save_win_config(char id)
+static void refit_v_screen()
 {
-    char * f_name = "save_win_config()";
-
-    /* Prepare atomic file saving. */
-    char * path_tmp = string_prefixed_id("confclient/windows/Win_tmp_", id);
-    FILE * file = try_fopen(path_tmp, "w", f_name);
-
-    /* Save, line by line, ->title, ->draw, ->height and ->width. */
-    struct WinConf * wc = get_winconf_by_id(id);
-    uint8_t size = strlen(wc->title) + 2;
-    if (size < 7)  /* Ensure that at least 5 + 2 char fit into line so that   */
-    {              /* the digit representation of any uint16_t may be stored. */
-        size = 7;
-    }
-    char line[size];
-    sprintf(line, "%s\n", wc->title);
-    try_fwrite(line, sizeof(char), strlen(line), file, f_name);
-    sprintf(line, "%c\n", wc->draw);
-    try_fwrite(line, sizeof(char), strlen(line), file, f_name);
-    sprintf(line, "%d\n", wc->height);
-    try_fwrite(line, sizeof(char), strlen(line), file, f_name);
-    sprintf(line, "%d\n", wc->width);
-    try_fwrite(line, sizeof(char), strlen(line), file, f_name);
-
-    /* Save window-specific keybindings (->kb.kbs). */
-    uint16_t linemax = 0;
-    struct KeyBinding * kb_p = wc->kb.kbs;
-    while (0 != kb_p)
+    /* Determine rightmost window column. */
+    uint32_t lastwcol = 0;
+    struct Win * wp = get_win_by_id(world.winDB.order[0]);
+    while (wp != 0)
     {
-        if (strlen(kb_p->command) > linemax)
+        if ((uint32_t) wp->start.x + (uint32_t) wp->frame_size.x > lastwcol + 1)
         {
-            linemax = strlen(kb_p->command);
+            lastwcol = (uint32_t) wp->start.x + (uint32_t) wp->frame_size.x - 1;
         }
-        kb_p = kb_p->next;
+        wp = get_win_after(wp->id);
     }
-    linemax = linemax + 6;          /* + 6: + 3 digits + whitespace + \n + \0 */
-    char kb_line[linemax];
-    kb_p = wc->kb.kbs;
-    while (0 != kb_p)
+
+    /* Only resize .v_screen if the rightmost window column has changed. */
+    char * err_s = "refit_v_screen() grows virtual screen beyond legal sizes.";
+    char * err_m = "refit_v_screen() triggers memory alloc error in wresize().";
+    if ((uint32_t) getmaxx(world.winDB.v_screen) + 1 != lastwcol)
     {
-        sprintf(kb_line, "%d %s\n", kb_p->key, kb_p->command);
-        try_fwrite(kb_line, sizeof(char), strlen(kb_line), file, f_name);
-        kb_p = kb_p->next;
+        uint8_t t = (lastwcol + 2 > UINT16_MAX);
+        exit_err(t, err_s);
+        t = wresize(world.winDB.v_screen, getmaxy(world.winDB.v_screen),
+                    lastwcol + 2);
+        exit_err(t, err_m);
     }
-
-    /* Finish atomic file saving and clean up. */
-    char * path = string_prefixed_id("confclient/windows/Win_", id);
-    try_fclose_unlink_rename(file, path_tmp, path, f_name);
-    free(path);
-    free(path_tmp);
-}
-
-
-
-static void free_winconf_data(char id)
-{
-    struct WinConf * wc = get_winconf_by_id(id);
-    free(wc->title);
-    free_keybindings(wc->kb.kbs);
-    free_win(wc->win);
 }
 
 
 
-static void set_winconf_geometry(char id)
+static void update_wins(struct Win * w)
 {
-    struct WinConf * wcp = get_winconf_by_id(id);
-    if      (0 == wcp->height_type)
-    {
-        wcp->height = wcp->win->framesize.y;
-    }
-    else if (1 == wcp->height_type)
-    {
-        wcp->height = wcp->win->framesize.y - world.wmeta.padsize.y + 1;
-    }
-    if      (0 == wcp->width_type)
+    place_win(w);
+    refit_v_screen();
+    struct Win * next = get_win_after(w->id);
+    if (next)
     {
-        wcp->width = wcp->win->framesize.x;
-    }
-    else if (1 == wcp->width_type)
-    {
-        wcp->width = wcp->win->framesize.x - world.wmeta.padsize.x;
+        update_wins(next);
     }
 }
 
 
 
-static struct WinConf * get_winconf_by_id(char id)
+static void place_win(struct Win * w)
 {
-    uint8_t i = 0;
-    while (1)
-    {
-        if (id == world.winconf_db.winconfs[i].id)
+    uint8_t sep = 1;         /* Width of inter-window borders and title bars. */
+
+    /* If w is first window, it goes into the top left corner. */
+    w->start.x = 0;
+    w->start.y = 0 + sep;
+    struct Win * w_prev = get_win_before(w->id);
+    if (w_prev)
+    {
+
+        /* If not, get w's next predecessor starting a new stack on the screen
+         * top, fit w's top left corner to that predecessor's top right corner.
+         */
+        struct Win * w_top = w_prev;
+        for (; w_top->start.y != 0 + sep; w_top = get_win_before(w_top->id));
+        w->start.x = w_top->start.x + w_top->frame_size.x + sep;
+
+        /* If enough space is found below w's predecessor, fit w's top left
+         * corner to that predecessor's bottom left corner.
+         */
+        uint16_t next_free_y = w_prev->start.y + w_prev->frame_size.y + sep;
+        if (   w->frame_size.x <= w_prev->frame_size.x
+            && w->frame_size.y <= world.winDB.v_screen_size.y - next_free_y)
+        {
+            w->start.x = w_prev->start.x;
+            w->start.y = next_free_y;
+            return;
+        }
+
+        /* If that fails, try to fit w's top left corner to the top right corner
+         * of its next predecessor w_test 1) below w_top (w's next predecessor
+         * starting a new stack on the screen top) 2) and the most rightward
+         * lower neighbor of a window w_high, itself throning over enough free
+         * space for w to fit below it, rightwards of its lower neighbor w_test.
+         */
+        struct Win * w_test = w_prev;
+        struct Win * w_high;
+        while (w_test != w_top)
         {
-            return &world.winconf_db.winconfs[i];
+            for (w_high = get_win_before(w_test->id);  /* Walk down chain     */
+                 w_test->start.y <= w_high->start.y;   /* until w_high starts */
+                 w_high = get_win_before(w_high->id)); /* higher than w_test. */
+            next_free_y = w_high->start.y + w_high->frame_size.y + sep;
+            uint16_t first_free_x = w_test->start.x + w_test->frame_size.x +sep;
+            uint16_t last_free_x = w_high->start.x + w_high->frame_size.x;
+            if (   w->frame_size.y <= world.winDB.v_screen_size.y - next_free_y
+                && w->frame_size.x <= last_free_x - first_free_x)
+            {
+                w->start.x = first_free_x;
+                w->start.y = next_free_y;
+                break;
+            }
+            w_test = w_high;
         }
-        i++;
     }
 }
 
 
 
-static void * get_drawfunc_by_char(char c)
+static void set_win_target_size(struct Win * w)
 {
-
-    if      ('c' == c)
-    {
-        return draw_win_inventory;
-    }
-    else if ('i' == c)
-    {
-        return draw_win_info;
-    }
-    else if ('l' == c)
-    {
-        return draw_win_log;
-    }
-    else if ('k' == c)
-    {
-        return draw_win_available_keybindings;
-    }
-    else if ('m' == c)
+    if      (0 == w->target_height_type)
     {
-        return draw_win_map;
+        w->target_height = w->frame_size.y;
     }
-    else if ('0' == c)
+    else if (1 == w->target_height_type)
     {
-        return draw_win_keybindings_global;
+        w->target_height = w->frame_size.y - world.winDB.v_screen_size.y +1;
     }
-    else if ('1' == c)
+    if      (0 == w->target_width_type)
     {
-        return draw_win_keybindings_winconf_geometry;
+        w->target_width = w->frame_size.x;
     }
-    else if ('2' == c)
+    else if (1 == w->target_width_type)
     {
-        return draw_win_keybindings_winconf_keybindings;
+        w->target_width = w->frame_size.x - world.winDB.v_screen_size.x;
     }
-    return NULL;
 }
 
 
 
-static char get_next_winconf_id()
+static void append_win(struct Win * w)
 {
-    static uint8_t i = 0;
-    char c = world.winconf_db.winconf_ids[i];
-    if (0 == c)
-    {
-        i = 0;
-        return c;
-    }
-    i++;
-    return c;
+    uint8_t old_size = strlen(world.winDB.order) + 1;
+    char * new_order = try_malloc(old_size + 1, __func__);
+    memcpy(new_order, world.winDB.order, old_size - 1);
+    new_order[old_size - 1] = w->id;
+    new_order[old_size] = '\0';
+    free(world.winDB.order);
+    world.winDB.order = new_order;
+    world.winDB.active = w->id;
+    update_wins(w);
 }
 
 
 
-extern struct WinConf * get_winconf_by_win(struct Win * win)
+static void suspend_win(struct Win * w)
 {
-    uint8_t i = 0;
-    while (1)
-    {
-        if (win == world.winconf_db.winconfs[i].win)
-        {
-            return &world.winconf_db.winconfs[i];
-        }
-        i++;
-    }
+    uint8_t new_size = strlen(world.winDB.order);
+    char * new_order = try_malloc(new_size, __func__);
+    uint8_t i = get_win_pos_in_order(w->id);
+    char next_char = world.winDB.order[i + 1];
+    world.winDB.order[i] = '\0';
+    char * second_part = &world.winDB.order[i + 1];
+    int test = sprintf(new_order, "%s%s", world.winDB.order, second_part);
+    exit_trouble(test < 0, __func__, "sprintf");
+    free(world.winDB.order);
+    world.winDB.order = new_order;
+    world.winDB.active = world.winDB.order[i];
+    if (!world.winDB.order[i] && 0 < i)
+    {
+        world.winDB.active = world.winDB.order[i - 1];
+    }
+    if (world.winDB.order[i])
+    {
+        update_wins(get_win_by_id(next_char)); /* Already calls               */
+        return;                                /* refit_v_screen(), so leave. */
+    }
+    refit_v_screen();
 }
 
 
 
-extern struct Win * get_win_by_id(char id)
-{
-    struct WinConf * wc = get_winconf_by_id(id);
-    return wc->win;
-}
-
-
-
-extern void init_winconfs()
+extern void toggle_window(char id)
 {
-    char * f_name = "init_winconfs()";
-
-    /* Fill world.winconf_db.winconf_ids with confclient/windows/Win_*
-     * filenames' end chars.
-     */
-    uint8_t max_wins = 255;         /* Maximum number of window ids to store. */
-    DIR * dp = opendir("confclient/windows");
-    exit_trouble(NULL == dp, f_name, "opendir()");
-    struct dirent * fn;
-    errno = 0;
-    char * winconf_ids = try_malloc(max_wins + 1, f_name);
-    uint8_t i = 0;
-    char id;
-    while (NULL != (fn = readdir(dp)) && i < max_wins)
-    {
-        if (5 == strlen(fn->d_name) && fn->d_name == strstr(fn->d_name, "Win_"))
-        {
-            id = fn->d_name[4];
-            winconf_ids[i] = id;
-            i++;
-        }
-    }
-    winconf_ids[i] = '\0';
-    exit_trouble(errno, f_name, "readdir()");
-    exit_trouble(closedir(dp), f_name, "closedir()");
-    world.winconf_db.winconf_ids = try_malloc(strlen(winconf_ids) + 1, f_name);
-    memcpy(world.winconf_db.winconf_ids, winconf_ids, strlen(winconf_ids) + 1);
-    free(winconf_ids);
-
-    /* Initialize world.winconf_db.winconfs from Win_* files named in
-     * world.winconf_db.winconf_ids.
-     */
-    size_t size = strlen(world.winconf_db.winconf_ids) * sizeof(struct WinConf);
-    world.winconf_db.winconfs = try_malloc(size, f_name);
-    i = 0;
-    while (0 != (id = get_next_winconf_id()))
+    struct Win * win = get_win_by_id(id);
+    if (!strchr(world.winDB.order, id))
     {
-        init_winconf_from_file(id, &world.winconf_db.winconfs[i]);
-        i++;
+        append_win(win);
+        return;
     }
+    suspend_win(win);
 }
 
 
 
-extern void free_winconfs()
+extern void toggle_winconfig()
 {
-    char id;
-    while (0 != (id = get_next_winconf_id()))
+    if (!world.winDB.active)
     {
-        free_winconf_data(id);
+        return;
     }
-    free(world.winconf_db.winconf_ids);
-    free(world.winconf_db.winconfs);
-}
-
-
-
-extern void init_wins()
-{
-    char id;
-    while (0 != (id = get_next_winconf_id()))
+    struct Win * w = get_win_by_id(world.winDB.active);
+    if      (0 == w->view)
+    {
+        w->view          = 1;
+        w->target_center = w->center;
+        memset(&w->center, 0, sizeof(struct yx_uint16));
+        return;
+    }
+    else if (1 == w->view)
     {
-        init_win_from_winconf(id);
+        w->view          = 2;
+        w->center.x      = 0;
+        return;
     }
+    w->view          = 0;
+    w->center        = w->target_center;
 }
 
 
 
-extern void sorted_wintoggle_and_activate()
+extern void toggle_win_size_type(char axis)
 {
-    char * f_name = "sorted_wintoggle_and_activate()";
-
-    /* Read from file order of windows to be toggled + active win selection. */
-    char * path = "confclient/windows/toggle_order_and_active";
-    FILE * file = try_fopen(path, "r", f_name);
-    uint32_t linemax = textfile_sizes(file, NULL);
-    char win_order[linemax + 1];
-    try_fgets(win_order, linemax + 1, file, f_name);
-    int char_or_eof = try_fgetc(file, f_name);
-    exit_trouble(EOF==char_or_eof, f_name, "fgetc() unexpectedly hitting EOF");
-    uint8_t a = (uint8_t) char_or_eof;
-    try_fclose(file, f_name);
-
-    /* Toggle windows and set active window selection. */
-    uint8_t i = 0;
-    for (; i < strlen(win_order) - 1; i++)
+    struct Win * w = get_win_by_id(world.winDB.active);
+    if ('y' == axis)
     {
-        if (NULL == strchr(world.winconf_db.winconf_ids, win_order[i]))
-        {
-            continue;
-        }
-        toggle_window(win_order[i]);
-        if (a == (uint8_t) win_order[i])
-        {
-            world.wmeta.active = get_win_by_id(win_order[i]);
-        }
+        w->target_height_type = (0 == w->target_height_type);
+        set_win_target_size(w);
+        return;
     }
+    w->target_width_type = (   0 == w->target_width_type
+                            && w->frame_size.x <= world.winDB.v_screen_size.x);
+    set_win_target_size(w);
 }
 
 
 
-extern void save_win_configs()
+extern void toggle_linebreak_type()
 {
-    char * f_name = "save_win_configs()";
-
-    /* Save individual world.winconf_db.winconfs to their proper files. */
-    uint8_t max_wins = 255;     /* n of WinConf fitting into world.winconf_db */
-    char id;
-    while (0 != (id = get_next_winconf_id()))
+    struct Win * w = get_win_by_id(world.winDB.active);
+    if      (0 == w->linebreak)
     {
-        save_win_config(id);
+        w->linebreak = 1;
     }
-
-    /* Save order of windows to toggle on start / which to select as active. */
-    char * path     = "confclient/windows/toggle_order_and_active";
-    char * path_tmp = "confclient/windows/toggle_order_and_active_tmp";
-    FILE * file = try_fopen(path_tmp, "w", f_name);
-    char line[max_wins + 2];
-    struct Win * w_p = world.wmeta.chain_start;
-    uint8_t i = 0;
-    while (0 != w_p && i < max_wins)
+    else if (1 == w->linebreak)
     {
-        struct WinConf * wc = get_winconf_by_win(w_p);
-        line[i] = wc->id;
-        w_p = w_p->next;
-        i++;
+        w->linebreak = 2;
     }
-    line[i] = '\n';
-    line[i + 1] = '\0';
-    try_fwrite(line, sizeof(char), strlen(line), file, f_name);
-    if (0 != world.wmeta.active)
+    else if (2 == w->linebreak)
     {
-        struct WinConf * wc = get_winconf_by_win(world.wmeta.active);
-        try_fputc(wc->id, file, f_name);
+        w->linebreak = 0;
     }
-    try_fclose_unlink_rename(file, path_tmp, path, f_name);
 }
 
 
 
-extern void toggle_window(char id)
+extern void resize_active_win(char change)
 {
-    struct Win * win = get_win_by_id(id);
-    if (0 == win->prev && world.wmeta.chain_start != win)   /* Win struct is  */
-    {                                                       /* outside chain? */
-        append_win(win);
-    }
-    else
+    if (world.winDB.active)
     {
-        suspend_win(win);
-    }
-}
-
-
-
-extern void toggle_winconfig()
-{
-   struct Win * win = world.wmeta.active;
-   struct WinConf * wcp = get_winconf_by_win(win);
-    if      (0 == wcp->view)
-    {
-        wcp->view     = 1;
-        win->draw     = draw_winconf_geometry;
-        wcp->center   = win->center;
-        win->center.y = 0;
-        win->center.x = 0;
-    }
-    else if (1 == wcp->view)
-    {
-        wcp->view     = 2;
-        win->draw     = draw_winconf_keybindings;
-        win->center.x = 0;
-    }
-    else
-    {
-        wcp->view     = 0;
-        win->draw     = get_drawfunc_by_char(wcp->draw);
-        win->center   = wcp->center;
+        struct Win * w = get_win_by_id(world.winDB.active);
+        if      (change == '-' && w->frame_size.y > 1)
+        {
+            w->frame_size.y--;
+        }
+        else if (change == '_' && w->frame_size.x > 1)
+        {
+            w->frame_size.x--;
+        }
+        else if (   change == '+'
+                 && w->frame_size.y < world.winDB.v_screen_size.y - 1)
+        {
+            w->frame_size.y++;
+        }
+        else if (change == '*' && w->frame_size.y < UINT16_MAX)
+        {
+            w->frame_size.x++;
+        }
+        if (   1 == w->target_width_type
+            && w->frame_size.x > world.winDB.v_screen_size.x)
+        {
+            w->target_width_type = 0;
+        }
+        set_win_target_size(w);
+        update_wins(w);
     }
 }
 
 
 
-extern void toggle_win_size_type(char axis)
+extern void shift_active_win(char dir)
 {
-    struct Win * win = world.wmeta.active;
-    struct WinConf * wcp = get_winconf_by_win(win);
-    if ('y' == axis)
+    uint8_t len_order = strlen(world.winDB.order);
+    if (1 < len_order)
     {
-        wcp->height_type = (0 == wcp->height_type);
-        set_winconf_geometry(wcp->id);
-        return;
+        char * tmp = try_malloc(len_order + 1, __func__);
+        tmp[len_order] = '\0';
+        uint8_t pos = get_win_pos_in_order(world.winDB.active);
+        if ('f' == dir)
+        {
+            if (pos == len_order - 1)
+            {
+                memcpy(tmp + 1, world.winDB.order, len_order - 1);
+                tmp[0] = world.winDB.active;
+                memcpy(world.winDB.order, tmp, len_order + 1);
+            }
+            else
+            {
+                world.winDB.order[pos] = world.winDB.order[pos + 1];
+                world.winDB.order[pos + 1] = world.winDB.active;
+            }
+        }
+        else
+        {
+            if (pos == 0)
+            {
+                memcpy(tmp, world.winDB.order + 1, len_order - 1);
+                tmp[len_order - 1] = world.winDB.active;
+                memcpy(world.winDB.order, tmp, len_order + 1);
+            }
+            else
+            {
+                world.winDB.order[pos] = world.winDB.order[pos - 1];
+                world.winDB.order[pos - 1] = world.winDB.active;
+            }
+        }
+        free(tmp);
+        update_wins(get_win_by_id(world.winDB.order[0]));
     }
-    wcp->width_type = (   0 == wcp->width_type
-                       && win->framesize.x <= world.wmeta.padsize.x);
-    set_winconf_geometry(wcp->id);
 }
 
 
 
-extern void scroll_pad(char dir)
+extern void scroll_v_screen(char dir)
 {
-    if      ('+' == dir)
+    if      (   '+' == dir
+             &&   world.winDB.v_screen_offset + world.winDB.v_screen_size.x + 1
+                < getmaxx(world.winDB.v_screen))
     {
-        reset_pad_offset(world.wmeta.pad_offset + 1);
+        world.winDB.v_screen_offset++;
     }
-    else if ('-' == dir)
+    else if (   '-' == dir
+             && world.winDB.v_screen_offset > 0)
     {
-        reset_pad_offset(world.wmeta.pad_offset - 1);
+        world.winDB.v_screen_offset--;
     }
 }
 
 
 
-extern void growshrink_active_window(char change)
+extern void cycle_active_win(char dir)
 {
-    if (0 != world.wmeta.active)
+    uint8_t len_order = strlen(world.winDB.order);
+    if (1 < len_order)
     {
-        struct yx_uint16 size = world.wmeta.active->framesize;
-        if      (change == '-')
-        {
-            size.y--;
-        }
-        else if (change == '+')
-        {
-            size.y++;
-        }
-        else if (change == '_')
-        {
-            size.x--;
-        }
-        else if (change == '*')
+        uint8_t pos = get_win_pos_in_order(world.winDB.active);
+        if ('f' == dir)
         {
-            size.x++;
+            world.winDB.active = world.winDB.order[pos + 1];
+            if ('\0' == world.winDB.active)
+            {
+                world.winDB.active = world.winDB.order[0];
+            }
+            return;
         }
-        resize_active_win(size);
-        struct WinConf * wcp = get_winconf_by_win(world.wmeta.active);
-        if (   1 == wcp->width_type
-            && world.wmeta.active->framesize.x > world.wmeta.padsize.x)
+        if (pos > 0)
         {
-            wcp->width_type = 0;
+            world.winDB.active = world.winDB.order[pos - 1];
+            return;
         }
-        set_winconf_geometry(wcp->id);
+        world.winDB.active = world.winDB.order[len_order - 1];
     }
 }