From: Christian Heller Date: Thu, 23 Jan 2014 21:50:54 +0000 (+0100) Subject: Merged world.wmeta and world.winconf_db into world.wins. X-Git-Tag: tce~868 X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7Byoutube_prefix%7D%7D%7B%7Bvideo_id%7D%7D?a=commitdiff_plain;h=fb9b40f0535b28b37b64983240c4b78e74ee9a2c;p=plomrogue Merged world.wmeta and world.winconf_db into world.wins. --- diff --git a/src/client/command_db.h b/src/client/command_db.h index 9f82062..a3fbd6c 100644 --- a/src/client/command_db.h +++ b/src/client/command_db.h @@ -16,7 +16,7 @@ struct Command { char * dsc_short; /* short name of command to be used internally */ char * dsc_long; /* long description of command to be shown to the user */ - char * server_msg; /* optionally start string of message to send to server */ + char * server_msg; /* optionally start string of message to send to server*/ char arg; /* defines server message suffix by player_control() convention */ }; diff --git a/src/client/control.c b/src/client/control.c index a58c35c..6059096 100644 --- a/src/client/control.c +++ b/src/client/control.c @@ -151,9 +151,9 @@ static uint8_t try_server_commands(struct Command * command) extern uint8_t try_key(uint16_t key) { struct Command * command = get_command_to_keycode(world.kb_global.kbs, key); - if (!command && world.wmeta.active) + if (!command && world.wins.win_active) { - struct WinConf * wc = get_winconf_by_win(world.wmeta.active); + struct WinConf * wc = get_winconf_by_win(world.wins.win_active); if (0 == wc->view) { command = get_command_to_keycode(wc->kb.kbs, key); diff --git a/src/client/draw_wins.c b/src/client/draw_wins.c index 1df666b..8e792ca 100644 --- a/src/client/draw_wins.c +++ b/src/client/draw_wins.c @@ -385,7 +385,7 @@ extern void draw_win_available_keybindings(struct Win * win) { char * title = "Active window's keybindings:"; struct KeyBinding * kb_p; - struct WinConf * wc = get_winconf_by_win(world.wmeta.active); + struct WinConf * wc = get_winconf_by_win(world.wins.win_active); if (0 == wc->view) { kb_p = wc->kb.kbs; diff --git a/src/client/keybindings.c b/src/client/keybindings.c index e57e361..7207641 100644 --- a/src/client/keybindings.c +++ b/src/client/keybindings.c @@ -82,7 +82,7 @@ static struct KeyBindingDB * char_selected_kb_db(char c) } else if ('w' == c) { - struct WinConf * wc = get_winconf_by_win(world.wmeta.active); + struct WinConf * wc = get_winconf_by_win(world.wins.win_active); kbd = &wc->kb; } return kbd; diff --git a/src/client/main.c b/src/client/main.c index 473228c..61c53b8 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -1,14 +1,14 @@ /* main.c */ +#include /* keypad() */ #include /* struct sigaction, sigaction() */ #include /* exit() */ #include /* memset() */ #include "../common/rexit.h" /* set_cleanup_func(), exit_trouble() */ -#include "cleanup.h" /* cleanup() */ +#include "cleanup.h" /* cleanup(), set_cleanup_flag() */ #include "command_db.h" /* init_command_db() */ #include "io.h" /* io_loop(), try_send() */ #include "misc.h" /* load_interface_conf(), winch_called() */ -#include "windows.h" /* init_wmeta_and_ncurses(); */ #include "world.h" /* struct World */ @@ -32,8 +32,11 @@ int main(int argc, char * argv[]) set_cleanup_func(cleanup); /* Initialize the whole interface. */ - init_wmeta_and_ncurses(); - keypad(world.wmeta.screen, TRUE); + world.wins.screen = initscr(); + set_cleanup_flag(CLEANUP_NCURSES); + noecho(); + curs_set(0); + keypad(world.wins.screen, TRUE); init_command_db(); /* The command DB needs to be initialized before */ load_interface_conf(); /* the interface, whose keybindings depend on it. */ diff --git a/src/client/misc.c b/src/client/misc.c index ff1600c..a37155b 100644 --- a/src/client/misc.c +++ b/src/client/misc.c @@ -58,9 +58,9 @@ extern void save_interface_conf() write_keybindings_to_file(file, &world.kb_winkeys, delim); write_order_wins_visible_active(file, delim); uint8_t i; - for (i = 0; i < strlen(world.winconf_db.ids); i++) + for (i = 0; i < strlen(world.wins.ids); i++) { - write_winconf_of_id_to_file(file, world.winconf_db.ids[i], delim); + write_winconf_of_id_to_file(file, world.wins.ids[i], delim); } try_fclose_unlink_rename(file, path_tmp, path, f_name); } @@ -101,12 +101,12 @@ extern void unload_interface_conf() world.kb_wingeom.kbs = NULL; free_keybindings(world.kb_winkeys.kbs); world.kb_winkeys.kbs = NULL; - while (0 != world.wmeta.active) + while (0 != world.wins.win_active) { - suspend_win(world.wmeta.active); + suspend_win(world.wins.win_active); } free_winconfs(); - delwin(world.wmeta.pad); + delwin(world.wins.pad); } @@ -122,23 +122,23 @@ extern void reset_windows() { endwin(); /* "[S]tandard way" to recalibrate ncurses post SIGWINCH, says */ refresh(); /* . */ - struct Win * w_p = world.wmeta.chain_start; - char win_ids[strlen(world.winconf_db.ids) + 1]; - memset(win_ids, '\0', strlen(world.winconf_db.ids) + 1); + struct Win * w_p = world.wins.chain_start; + char win_ids[strlen(world.wins.ids) + 1]; + memset(win_ids, '\0', strlen(world.wins.ids) + 1); uint8_t i = 0; char active = '\0'; for (; NULL != w_p; w_p = w_p->next, i++) { struct WinConf * wc_p = get_winconf_by_win(w_p); win_ids[i] = wc_p->id; - if (w_p == world.wmeta.active) + if (w_p == world.wins.win_active) { active = wc_p->id; } } - while (0 != world.wmeta.active) + while (0 != world.wins.win_active) { - w_p = world.wmeta.active; + w_p = world.wins.win_active; suspend_win(w_p); } char id; @@ -146,7 +146,7 @@ extern void reset_windows() { free_win(get_win_by_id(id)); } - delwin(world.wmeta.pad); + delwin(world.wins.pad); make_pad(); init_wins(); if (strlen(win_ids) < 1) @@ -158,7 +158,7 @@ extern void reset_windows() toggle_window(win_ids[i]); if (active == win_ids[i]) { - world.wmeta.active = get_win_by_id(win_ids[i]); + world.wins.win_active = get_win_by_id(win_ids[i]); } } } diff --git a/src/client/misc.h b/src/client/misc.h index e849703..01e2488 100644 --- a/src/client/misc.h +++ b/src/client/misc.h @@ -15,8 +15,8 @@ extern void obey_argv(int argc, char * argv[]); /* Save / load (init) / unload (free/dissolve) / reload interface configuration - * data, world.wmeta.pad (initialized before opening any windows to the height - * of the terminal screen and a width of 1) and window chains. + * data, world.wins.pad (initialized before opening any windows to the height of + * the terminal screen and a width of 1) and window chains. * * Note that reload_interface_conf() also calls map_center(). */ diff --git a/src/client/wincontrol.c b/src/client/wincontrol.c index fcf3e86..5b82053 100644 --- a/src/client/wincontrol.c +++ b/src/client/wincontrol.c @@ -66,7 +66,7 @@ static void set_winconf_geometry(char id) } else if (1 == wcp->height_type) { - wcp->height = wcp->win->framesize.y - world.wmeta.padsize.y + 1; + wcp->height = wcp->win->framesize.y - world.wins.padsize.y + 1; } if (0 == wcp->width_type) { @@ -74,7 +74,7 @@ static void set_winconf_geometry(char id) } else if (1 == wcp->width_type) { - wcp->width = wcp->win->framesize.x - world.wmeta.padsize.x; + wcp->width = wcp->win->framesize.x - world.wins.padsize.x; } } @@ -136,9 +136,9 @@ static struct WinConf * get_winconf_by_id(char id) uint8_t i = 0; while (1) { - if (id == world.winconf_db.winconfs[i].id) + if (id == world.wins.winconfs[i].id) { - return &world.winconf_db.winconfs[i]; + return &world.wins.winconfs[i]; } i++; } @@ -151,9 +151,9 @@ extern struct WinConf * get_winconf_by_win(struct Win * win) uint8_t i = 0; while (1) { - if (win == world.winconf_db.winconfs[i].win) + if (win == world.wins.winconfs[i].win) { - return &world.winconf_db.winconfs[i]; + return &world.wins.winconfs[i]; } i++; } @@ -169,7 +169,8 @@ extern struct Win * get_win_by_id(char id) -extern uint8_t read_winconf_from_file(char * line, uint32_t linemax, FILE * file) +extern uint8_t read_winconf_from_file(char * line, uint32_t linemax, + FILE * file) { char * f_name = "read_winconf_from_file()"; int test = try_fgetc(file, f_name); @@ -195,27 +196,27 @@ extern uint8_t read_winconf_from_file(char * line, uint32_t linemax, FILE * file winconf.view = 0; winconf.center.y = 0; winconf.center.x = 0; - if (world.winconf_db.ids) + if (world.wins.ids) { - uint8_t old_ids_size = strlen(world.winconf_db.ids); + uint8_t old_ids_size = strlen(world.wins.ids); char * new_ids = try_malloc(old_ids_size + 1 + 1, f_name); - sprintf(new_ids, "%s%c", world.winconf_db.ids, winconf.id); - free(world.winconf_db.ids); - world.winconf_db.ids = new_ids; + sprintf(new_ids, "%s%c", world.wins.ids, winconf.id); + free(world.wins.ids); + world.wins.ids = new_ids; uint16_t old_winconfs_size = old_ids_size * sizeof(struct WinConf); uint16_t new_winconfs_size = old_winconfs_size + sizeof(struct WinConf); struct WinConf * new_winconfs = try_malloc(new_winconfs_size, f_name); - memcpy(new_winconfs, world.winconf_db.winconfs, old_winconfs_size); + memcpy(new_winconfs, world.wins.winconfs, old_winconfs_size); new_winconfs[old_ids_size] = winconf; - free(world.winconf_db.winconfs); - world.winconf_db.winconfs = new_winconfs; + free(world.wins.winconfs); + world.wins.winconfs = new_winconfs; } else { - world.winconf_db.ids = try_malloc(2, f_name); - sprintf(world.winconf_db.ids, "%c", winconf.id); - world.winconf_db.winconfs = try_malloc(sizeof(struct WinConf), f_name); - *world.winconf_db.winconfs = winconf; + world.wins.ids = try_malloc(2, f_name); + sprintf(world.wins.ids, "%c", winconf.id); + world.wins.winconfs = try_malloc(sizeof(struct WinConf), f_name); + *world.wins.winconfs = winconf; } return 1; } @@ -245,18 +246,19 @@ extern void write_winconf_of_id_to_file(FILE * file, char c, char * delim) -extern void read_order_wins_visible_active(char * line, uint32_t linemax, FILE * file) +extern void read_order_wins_visible_active(char * line, uint32_t linemax, + FILE * file) { char * f_name = "read_order_wins_visible_active()"; char win_order[linemax + 1]; try_fgets(win_order, linemax + 1, file, f_name); - world.winconf_db.order = try_malloc(linemax, f_name); + world.wins.order = try_malloc(linemax, f_name); win_order[strlen(win_order) - 1] = '\0'; - sprintf(world.winconf_db.order, "%s", win_order); + sprintf(world.wins.order, "%s", win_order); int char_or_eof = try_fgetc(file, f_name); char * err_eof = "fgetc() unexpectedly hitting EOF"; exit_trouble(EOF == char_or_eof, f_name, err_eof); - world.winconf_db.active = (uint8_t) char_or_eof; + world.wins.id_active = (uint8_t) char_or_eof; exit_trouble(EOF == try_fgetc(file, f_name), f_name, err_eof); try_fgets(line, linemax + 1, file, f_name); } @@ -266,15 +268,15 @@ extern void read_order_wins_visible_active(char * line, uint32_t linemax, FILE * extern void write_order_wins_visible_active(FILE * file, char * delim) { char * f_name = "write_order_wins_visible_active()"; - char line[strlen(world.winconf_db.ids) + 2]; - struct Win * w_p = world.wmeta.chain_start; + char line[strlen(world.wins.ids) + 2]; + struct Win * w_p = world.wins.chain_start; char active = ' '; uint8_t i; for (; NULL != w_p; w_p = w_p->next, i++) { struct WinConf * wc_p = get_winconf_by_win(w_p); line[i] = wc_p->id; - if (w_p == world.wmeta.active) + if (w_p == world.wins.win_active) { active = wc_p->id; } @@ -296,12 +298,12 @@ extern void free_winconfs() { free_winconf_data(id); } - free(world.winconf_db.ids); - world.winconf_db.ids = NULL; - free(world.winconf_db.winconfs); - world.winconf_db.winconfs = NULL; - free(world.winconf_db.order); - world.winconf_db.order = NULL; + free(world.wins.ids); + world.wins.ids = NULL; + free(world.wins.winconfs); + world.wins.winconfs = NULL; + free(world.wins.order); + world.wins.order = NULL; } @@ -320,16 +322,16 @@ extern void init_wins() extern void sorted_win_toggle_and_activate() { uint8_t i = 0; - for (; i < strlen(world.winconf_db.order); i++) + for (; i < strlen(world.wins.order); i++) { - if (NULL == strchr(world.winconf_db.ids, world.winconf_db.order[i])) + if (NULL == strchr(world.wins.ids, world.wins.order[i])) { continue; } - toggle_window(world.winconf_db.order[i]); - if (world.winconf_db.active == (uint8_t) world.winconf_db.order[i]) + toggle_window(world.wins.order[i]); + if (world.wins.id_active == (uint8_t) world.wins.order[i]) { - world.wmeta.active = get_win_by_id(world.winconf_db.order[i]); + world.wins.win_active = get_win_by_id(world.wins.order[i]); } } } @@ -338,7 +340,7 @@ extern void sorted_win_toggle_and_activate() extern char get_next_winconf_id() { static uint8_t i = 0; - char c = world.winconf_db.ids[i]; + char c = world.wins.ids[i]; if (0 == c) { i = 0; @@ -353,7 +355,7 @@ extern char get_next_winconf_id() extern void toggle_window(char id) { struct Win * win = get_win_by_id(id); - if (0 == win->prev && world.wmeta.chain_start != win) /* Win struct is */ + if (0 == win->prev && world.wins.chain_start != win) /* Win struct is */ { /* outside chain? */ append_win(win); } @@ -367,7 +369,7 @@ extern void toggle_window(char id) extern void toggle_winconfig() { - struct Win * win = world.wmeta.active; + struct Win * win = world.wins.win_active; struct WinConf * wcp = get_winconf_by_win(win); if (0 == wcp->view) { @@ -395,7 +397,7 @@ extern void toggle_winconfig() extern void toggle_win_size_type(char axis) { - struct Win * win = world.wmeta.active; + struct Win * win = world.wins.win_active; struct WinConf * wcp = get_winconf_by_win(win); if ('y' == axis) { @@ -404,7 +406,7 @@ extern void toggle_win_size_type(char axis) return; } wcp->width_type = ( 0 == wcp->width_type - && win->framesize.x <= world.wmeta.padsize.x); + && win->framesize.x <= world.wins.padsize.x); set_winconf_geometry(wcp->id); } @@ -414,11 +416,11 @@ extern void scroll_pad(char dir) { if ('+' == dir) { - reset_pad_offset(world.wmeta.pad_offset + 1); + reset_pad_offset(world.wins.pad_offset + 1); } else if ('-' == dir) { - reset_pad_offset(world.wmeta.pad_offset - 1); + reset_pad_offset(world.wins.pad_offset - 1); } } @@ -426,9 +428,9 @@ extern void scroll_pad(char dir) extern void growshrink_active_window(char change) { - if (0 != world.wmeta.active) + if (0 != world.wins.win_active) { - struct yx_uint16 size = world.wmeta.active->framesize; + struct yx_uint16 size = world.wins.win_active->framesize; if (change == '-') { size.y--; @@ -446,9 +448,9 @@ extern void growshrink_active_window(char change) size.x++; } resize_active_win(size); - struct WinConf * wcp = get_winconf_by_win(world.wmeta.active); + struct WinConf * wcp = get_winconf_by_win(world.wins.win_active); if ( 1 == wcp->width_type - && world.wmeta.active->framesize.x > world.wmeta.padsize.x) + && world.wins.win_active->framesize.x > world.wins.padsize.x) { wcp->width_type = 0; } diff --git a/src/client/wincontrol.h b/src/client/wincontrol.h index 2ecb4be..9e7de86 100644 --- a/src/client/wincontrol.h +++ b/src/client/wincontrol.h @@ -12,14 +12,22 @@ #include "../common/yx_uint16.h" /* yx_uint16 struct */ struct Win; +#include struct WinConfDB { + WINDOW * screen; /* ncurses' pointer to the terminal screen */ + WINDOW * pad; /* ncurses pad of virtual screen */ struct WinConf * winconfs; - char * ids; - char * order; /* order of visible windows (identified by IDs) */ - char active; /* id of window selected as active */ + struct Win * chain_start; /* first Win in chain; its .prev == 0 */ + struct Win * chain_end; /* last Win in chain; its .next == 0 */ + struct Win * win_active; /* Win highlighted / selected for manipulation */ + struct yx_uint16 padsize; /* virtual screen size */ + char * ids; /* all windows' ids */ + char * order; /* order of visible windows (identified by IDs) */ + uint16_t pad_offset; /* number of cells view is moved to the right */ + char id_active; /* id of window selected as active */ }; /* Window's configuration (like geometry, keybindings) and the Win itself. */ @@ -50,19 +58,21 @@ extern void free_winconfs(); extern void init_wins(); /* Toggle windows in order set by world.win_order. Point active window selection - * to window identified by world.winconf_db.active. + * to window identified by world.wins.win_active. */ extern void sorted_win_toggle_and_activate(); -/* Read/write world.win_order and world.winconf_db.active from/to "file". */ -extern void read_order_wins_visible_active(char * line, uint32_t linemax, FILE * file); +/* Read/write world.win_order and world.wins.win_active from/to "file". */ +extern void read_order_wins_visible_active(char * line, uint32_t linemax, + FILE * file); extern void write_order_wins_visible_active(FILE * file, char * delim); -/* Iterate over chars of world.winconf_db.winconf_ids array. Restart after \0.*/ +/* Iterate over chars of world.wins.winconf_ids array. Restart after \0.*/ extern char get_next_winconf_id(); /* Read/write individual WinConf (identified by "c") from/to file. */ -extern uint8_t read_winconf_from_file(char * line, uint32_t linemax, FILE * file); +extern uint8_t read_winconf_from_file(char * line, uint32_t linemax, + FILE * file); extern void write_winconf_of_id_to_file(FILE * file, char c, char * delim); /* Toggle "window configuration" view for active window. Sets sensible @@ -73,7 +83,7 @@ extern void toggle_winconfig(); /* Toggle WinConf.(height/width)_type ("axis" = "y": height; else: width). Avoid * positive diff to screen width (value would be wrongly read as a non-diff), - * width_type toggles to 1 only if world.wmeta->screen's width >= WinConf.width. + * width_type toggles to 1 only if world.wins.screen's width >= WinConf.width. */ extern void toggle_win_size_type(char axis); diff --git a/src/client/windows.c b/src/client/windows.c index 1459ec2..c69ee7d 100644 --- a/src/client/windows.c +++ b/src/client/windows.c @@ -7,14 +7,12 @@ #include /* free() */ #include /* strlen(), memcpy(), strnlen() */ #include /* chtype, pnoutrefresh(), doupdate(), werase(), erase(), - * wnoutrefresh(), getmaxx(), getmaxy(), initscr(), - * noecho(), curs_set(), newpad(), mvwaddch(), mvwaddstr(), - * wresize() + * wnoutrefresh(), getmaxx(), getmaxy(), mvwaddstr(), + * mvwaddch(), mvwaddstr(), wresize() */ #include "../common/rexit.h" /* for exit_err() */ #include "../common/try_malloc.h" /* for try_malloc() */ #include "../common/yx_uint16.h" /* for struct yx_uint16 */ -#include "cleanup.h" /* for set_cleanup_flag() */ #include "misc.h" /* for center_offset() */ #include "world.h" /* for world global */ @@ -65,7 +63,7 @@ static void refit_pad() { /* Determine rightmost window column. */ uint32_t lastwcol = 0; - struct Win * wp = world.wmeta.chain_start; + struct Win * wp = world.wins.chain_start; while (wp != 0) { if ((uint32_t) wp->start.x + (uint32_t) wp->framesize.x > lastwcol + 1) @@ -78,11 +76,11 @@ static void refit_pad() /* Only resize the pad if the rightmost window column has changed. */ char * err_s = "refit_pad() extends virtual screen beyond legal sizes."; char * err_m = "refit_pad() triggers memory alloc error via wresize()."; - if (getmaxx(world.wmeta.pad) + 1 != lastwcol) + if (getmaxx(world.wins.pad) + 1 != lastwcol) { uint8_t t = (lastwcol + 2 > UINT16_MAX); exit_err(t, err_s); - t = wresize(world.wmeta.pad, getmaxy(world.wmeta.pad), lastwcol + 2); + t = wresize(world.wins.pad, getmaxy(world.wins.pad), lastwcol + 2); exit_err(t, err_m); } } @@ -120,7 +118,7 @@ static void place_win(struct Win * w) /* Fit w's top left to bottom left of its ->prev if enough space. */ uint16_t w_prev_maxy = w->prev->start.y + w->prev->framesize.y; if ( w->framesize.x <= w->prev->framesize.x - && w->framesize.y < world.wmeta.padsize.y - w_prev_maxy) + && w->framesize.y < world.wins.padsize.y - w_prev_maxy) { w->start.x = w->prev->start.x; w->start.y = w_prev_maxy + 1; @@ -143,7 +141,7 @@ static void place_win(struct Win * w) uint16_t w_thr_bottom = w_thr->start.y + w_thr->framesize.y; uint16_t free_width = (w_thr->start.x + w_thr->framesize.x) - (w_test->start.x + w_test->framesize.x); - if ( w->framesize.y < world.wmeta.padsize.y - w_thr_bottom + if ( w->framesize.y < world.wins.padsize.y - w_thr_bottom && w->framesize.x < free_width) { w->start.x = w_test->start.x + w_test->framesize.x + 1; @@ -198,10 +196,10 @@ static void scroll_hint(struct yx_uint16 fsize, char dir, uint16_t dist, } if ('<' == dir || '>' == dir) { - mvwaddch(world.wmeta.pad, start.y + q, start.x + draw_offset, c); + mvwaddch(world.wins.pad, start.y + q, start.x + draw_offset, c); continue; } - mvwaddch(world.wmeta.pad, start.y + draw_offset, start.x + q, c); + mvwaddch(world.wins.pad, start.y + draw_offset, start.x + q, c); } } @@ -210,8 +208,8 @@ static void padscroll_hint(char dir, uint16_t dist) { struct yx_uint16 start; start.y = 0; - start.x = world.wmeta.pad_offset; - scroll_hint(world.wmeta.padsize, dir, dist, "columns", start); + start.x = world.wins.pad_offset; + scroll_hint(world.wins.padsize, dir, dist, "columns", start); } @@ -242,8 +240,8 @@ static void draw_wins(struct Win * w) for (x = offset_x; x < w->framesize.x + offset_x && x < size_x; x++) { chtype ch = w->winmap[(y * w->winmapsize.x) + x]; - mvwaddch(world.wmeta.pad, w->start.y + (y - offset_y), - w->start.x + (x - offset_x), ch); + mvwaddch(world.wins.pad, w->start.y + (y - offset_y), + w->start.x + (x - offset_x), ch); } } free(w->winmap); @@ -280,13 +278,13 @@ static void draw_win_borderlines(struct Win * w) uint16_t y, x; for (y = w->start.y; y <= w->start.y + w->framesize.y; y++) { - mvwaddch(world.wmeta.pad, y, w->start.x - 1, '|'); - mvwaddch(world.wmeta.pad, y, w->start.x + w->framesize.x, '|'); + mvwaddch(world.wins.pad, y, w->start.x - 1, '|'); + mvwaddch(world.wins.pad, y, w->start.x + w->framesize.x, '|'); } for (x = w->start.x; x <= w->start.x + w->framesize.x; x++) { - mvwaddch(world.wmeta.pad, w->start.y - 1, x, '-'); - mvwaddch(world.wmeta.pad, w->start.y + w->framesize.y, x, '-'); + mvwaddch(world.wins.pad, w->start.y - 1, x, '-'); + mvwaddch(world.wins.pad, w->start.y + w->framesize.y, x, '-'); } /* Draw as much as possible of the title into center of top border line. */ @@ -301,14 +299,14 @@ static void draw_win_borderlines(struct Win * w) uint16_t length_visible = strnlen(w->title, w->framesize.x - 2); char title[length_visible + 3]; char decoration = ' '; - if (w == world.wmeta.active) + if (w == world.wins.win_active) { decoration = '$'; } memcpy(title + 1, w->title, length_visible); title[0] = title[length_visible + 1] = decoration; title[length_visible + 2] = '\0'; - mvwaddstr(world.wmeta.pad, + mvwaddstr(world.wins.pad, w->start.y - 1, w->start.x + title_offset, title); } } @@ -328,10 +326,10 @@ static void draw_wins_borderlines(struct Win * w) static void draw_wins_bordercorners(struct Win * w) { - mvwaddch(world.wmeta.pad, w->start.y - 1, w->start.x - 1, '+'); - mvwaddch(world.wmeta.pad, w->start.y - 1, w->start.x + w->framesize.x,'+'); - mvwaddch(world.wmeta.pad, w->start.y + w->framesize.y, w->start.x - 1,'+'); - mvwaddch(world.wmeta.pad, w->start.y + w->framesize.y, + mvwaddch(world.wins.pad, w->start.y - 1, w->start.x - 1, '+'); + mvwaddch(world.wins.pad, w->start.y - 1, w->start.x + w->framesize.x, '+'); + mvwaddch(world.wins.pad, w->start.y + w->framesize.y, w->start.x - 1, '+'); + mvwaddch(world.wins.pad, w->start.y + w->framesize.y, w->start.x + w->framesize.x, '+'); if (0 != w->next) { @@ -343,40 +341,40 @@ static void draw_wins_bordercorners(struct Win * w) static void shift_win_forward() { - if (world.wmeta.active == world.wmeta.chain_end) + if (world.wins.win_active == world.wins.chain_end) { - world.wmeta.chain_end = world.wmeta.active->prev; - world.wmeta.chain_end->next = 0; - world.wmeta.active->next = world.wmeta.chain_start; - world.wmeta.active->next->prev = world.wmeta.active; - world.wmeta.chain_start = world.wmeta.active; - world.wmeta.chain_start->prev = 0; + world.wins.chain_end = world.wins.win_active->prev; + world.wins.chain_end->next = 0; + world.wins.win_active->next = world.wins.chain_start; + world.wins.win_active->next->prev = world.wins.win_active; + world.wins.chain_start = world.wins.win_active; + world.wins.chain_start->prev = 0; } else { - struct Win * old_prev = world.wmeta.active->prev; - struct Win * old_next = world.wmeta.active->next; - if (world.wmeta.chain_end == world.wmeta.active->next) + struct Win * old_prev = world.wins.win_active->prev; + struct Win * old_next = world.wins.win_active->next; + if (world.wins.chain_end == world.wins.win_active->next) { - world.wmeta.chain_end = world.wmeta.active; - world.wmeta.active->next = 0; + world.wins.chain_end = world.wins.win_active; + world.wins.win_active->next = 0; } else { - world.wmeta.active->next = old_next->next; - world.wmeta.active->next->prev = world.wmeta.active; + world.wins.win_active->next = old_next->next; + world.wins.win_active->next->prev = world.wins.win_active; } - if (world.wmeta.chain_start == world.wmeta.active) + if (world.wins.chain_start == world.wins.win_active) { - world.wmeta.chain_start = old_next; + world.wins.chain_start = old_next; } else { old_prev->next = old_next; } old_next->prev = old_prev; - old_next->next = world.wmeta.active; - world.wmeta.active->prev = old_next; + old_next->next = world.wins.win_active; + world.wins.win_active->prev = old_next; } } @@ -384,73 +382,56 @@ static void shift_win_forward() static void shift_win_backward() { - if (world.wmeta.active == world.wmeta.chain_start) + if (world.wins.win_active == world.wins.chain_start) { - world.wmeta.chain_start = world.wmeta.active->next; - world.wmeta.chain_start->prev = 0; - world.wmeta.active->prev = world.wmeta.chain_end; - world.wmeta.active->prev->next = world.wmeta.active; - world.wmeta.chain_end = world.wmeta.active; - world.wmeta.chain_end->next = 0; + world.wins.chain_start = world.wins.win_active->next; + world.wins.chain_start->prev = 0; + world.wins.win_active->prev = world.wins.chain_end; + world.wins.win_active->prev->next = world.wins.win_active; + world.wins.chain_end = world.wins.win_active; + world.wins.chain_end->next = 0; } else { - struct Win * old_prev = world.wmeta.active->prev; - struct Win * old_next = world.wmeta.active->next; - if (world.wmeta.chain_start == world.wmeta.active->prev) + struct Win * old_prev = world.wins.win_active->prev; + struct Win * old_next = world.wins.win_active->next; + if (world.wins.chain_start == world.wins.win_active->prev) { - world.wmeta.chain_start = world.wmeta.active; - world.wmeta.active->prev = 0; + world.wins.chain_start = world.wins.win_active; + world.wins.win_active->prev = 0; } else { - world.wmeta.active->prev = old_prev->prev; - world.wmeta.active->prev->next = world.wmeta.active; + world.wins.win_active->prev = old_prev->prev; + world.wins.win_active->prev->next = world.wins.win_active; } - if (world.wmeta.chain_end == world.wmeta.active) + if (world.wins.chain_end == world.wins.win_active) { - world.wmeta.chain_end = old_prev; + world.wins.chain_end = old_prev; } else { old_next->prev = old_prev; } old_prev->next = old_next; - old_prev->prev = world.wmeta.active; - world.wmeta.active->next = old_prev; + old_prev->prev = world.wins.win_active; + world.wins.win_active->next = old_prev; } } -extern void init_wmeta_and_ncurses() -{ - world.wmeta.screen = initscr(); - set_cleanup_flag(CLEANUP_NCURSES); - noecho(); - curs_set(0); - world.wmeta.padsize.y = 0; - world.wmeta.padsize.x = 0; - world.wmeta.chain_start = 0; - world.wmeta.chain_end = 0; - world.wmeta.pad_offset = 0; - world.wmeta.pad = NULL; - world.wmeta.active = 0; -} - - - extern void make_pad() { char * err_s = "make_pad() creates an illegaly large virtual screen."; char * err_m = "make_pad() triggers memory allocation error via newpad()."; - uint32_t maxy_test = getmaxy(world.wmeta.screen); - uint32_t maxx_test = getmaxx(world.wmeta.screen); + uint32_t maxy_test = getmaxy(world.wins.screen); + uint32_t maxx_test = getmaxx(world.wins.screen); exit_err(maxy_test > UINT16_MAX || maxx_test > UINT16_MAX, err_s); - world.wmeta.padsize.y = maxy_test; - world.wmeta.padsize.x = maxx_test; - world.wmeta.pad = newpad(world.wmeta.padsize.y, 1); - exit_err(NULL == world.wmeta.pad, err_m); + world.wins.padsize.y = maxy_test; + world.wins.padsize.x = maxx_test; + world.wins.pad = newpad(world.wins.padsize.y, 1); + exit_err(NULL == world.wins.pad, err_m); } @@ -470,23 +451,23 @@ extern void init_win(struct Win ** wp, char * title, int16_t height, w->draw = func; w->center.y = 0; w->center.x = 0; - w->framesize.y = world.wmeta.padsize.y - 1; - if (0 < height && height <= world.wmeta.padsize.y - 1) + w->framesize.y = world.wins.padsize.y - 1; + if (0 < height && height <= world.wins.padsize.y - 1) { w->framesize.y = height; } - else if (0 > height && world.wmeta.padsize.y + (height - 1) > 0) + else if (0 > height && world.wins.padsize.y + (height - 1) > 0) { - w->framesize.y = world.wmeta.padsize.y + (height - 1); + w->framesize.y = world.wins.padsize.y + (height - 1); } - w->framesize.x = world.wmeta.padsize.x; + w->framesize.x = world.wins.padsize.x; if (0 < width) { w->framesize.x = width; } - else if (0 > width && world.wmeta.padsize.x + width > 0) + else if (0 > width && world.wins.padsize.x + width > 0) { - w->framesize.x = world.wmeta.padsize.x + width; + w->framesize.x = world.wins.padsize.x + width; } *wp = w; } @@ -503,17 +484,17 @@ extern void free_win(struct Win * win) extern void append_win(struct Win * w) { - if (0 != world.wmeta.chain_start) + if (0 != world.wins.chain_start) { - w->prev = world.wmeta.chain_end; - world.wmeta.chain_end->next = w; + w->prev = world.wins.chain_end; + world.wins.chain_end->next = w; } else { - world.wmeta.active = w; - world.wmeta.chain_start = w; + world.wins.win_active = w; + world.wins.chain_start = w; } - world.wmeta.chain_end = w; + world.wins.chain_end = w; update_wins(w); } @@ -521,31 +502,31 @@ extern void append_win(struct Win * w) extern void suspend_win(struct Win * w) { - if (world.wmeta.chain_start != w) + if (world.wins.chain_start != w) { w->prev->next = w->next; } else { - world.wmeta.chain_start = w->next; + world.wins.chain_start = w->next; } uint8_t pad_refitted = 0; - if (world.wmeta.chain_end != w) + if (world.wins.chain_end != w) { w->next->prev = w->prev; - if (world.wmeta.active == w) + if (world.wins.win_active == w) { - world.wmeta.active = w->next; + world.wins.win_active = w->next; } update_wins(w->next); /* Positioning of successor windows may be */ pad_refitted = 1; /* affected / need correction. Note that */ } /* update_wins() already refits the pad, */ else /* voiding later need for that. */ { - world.wmeta.chain_end = w->prev; - if (world.wmeta.active == w) + world.wins.chain_end = w->prev; + if (world.wins.win_active == w) { - world.wmeta.active = w->prev; + world.wins.win_active = w->prev; } } w->prev = 0; @@ -561,10 +542,10 @@ extern void suspend_win(struct Win * w) extern void reset_pad_offset(uint16_t new_offset) { if (new_offset >= 0 - && (new_offset < world.wmeta.pad_offset - || new_offset + world.wmeta.padsize.x < getmaxx(world.wmeta.pad))) + && (new_offset < world.wins.pad_offset + || new_offset + world.wins.padsize.x < getmaxx(world.wins.pad))) { - world.wmeta.pad_offset = new_offset; + world.wins.pad_offset = new_offset; } } @@ -572,11 +553,11 @@ extern void reset_pad_offset(uint16_t new_offset) extern void resize_active_win(struct yx_uint16 size) { - if (0 != world.wmeta.active - && size.x > 0 && size.y > 0 && size.y < world.wmeta.padsize.y) + if (0 != world.wins.win_active + && size.x > 0 && size.y > 0 && size.y < world.wins.padsize.y) { - world.wmeta.active->framesize = size; - update_wins(world.wmeta.active); /* Positioning of following */ + world.wins.win_active->framesize = size; + update_wins(world.wins.win_active); /* Positioning of following */ } /* windows may be affected. */ } @@ -584,28 +565,28 @@ extern void resize_active_win(struct yx_uint16 size) extern void cycle_active_win(char dir) { - if (0 != world.wmeta.active) + if (0 != world.wins.win_active) { if ('f' == dir) { - if (world.wmeta.active->next != 0) + if (world.wins.win_active->next != 0) { - world.wmeta.active = world.wmeta.active->next; + world.wins.win_active = world.wins.win_active->next; } else { - world.wmeta.active = world.wmeta.chain_start; + world.wins.win_active = world.wins.chain_start; } } else { - if (world.wmeta.active->prev != 0) + if (world.wins.win_active->prev != 0) { - world.wmeta.active = world.wmeta.active->prev; + world.wins.win_active = world.wins.win_active->prev; } else { - world.wmeta.active = world.wmeta.chain_end; + world.wins.win_active = world.wins.chain_end; } } } @@ -615,19 +596,19 @@ extern void cycle_active_win(char dir) extern void shift_active_win(char dir) { - if ( 0 == world.wmeta.active /* No shifting with < 2 windows visible. */ - || world.wmeta.chain_start == world.wmeta.chain_end) + if ( 0 == world.wins.win_active /* No shifting with <2 windows visible. */ + || world.wins.chain_start == world.wins.chain_end) { return; } if ('f' == dir) { shift_win_forward(); - update_wins(world.wmeta.chain_start); + update_wins(world.wins.chain_start); return; } shift_win_backward(); - update_wins(world.wmeta.chain_start); + update_wins(world.wins.chain_start); } @@ -636,31 +617,31 @@ extern void draw_all_wins() { /* Empty everything before filling it a-new. */ erase(); - wnoutrefresh(world.wmeta.screen); - werase(world.wmeta.pad); - if (world.wmeta.chain_start) + wnoutrefresh(world.wins.screen); + werase(world.wins.pad); + if (world.wins.chain_start) { /* Draw windows' borders first, then windows. */ - draw_wins_borderlines(world.wmeta.chain_start); - draw_wins_bordercorners(world.wmeta.chain_start); - draw_wins(world.wmeta.chain_start); + draw_wins_borderlines(world.wins.chain_start); + draw_wins_bordercorners(world.wins.chain_start); + draw_wins(world.wins.chain_start); /* Draw virtual screen scroll hints. */ - if (world.wmeta.pad_offset > 0) + if (world.wins.pad_offset > 0) { - padscroll_hint('<', world.wmeta.pad_offset + 1); + padscroll_hint('<', world.wins.pad_offset + 1); } - uint16_t size_x = getmaxx(world.wmeta.pad); - uint16_t right_edge = world.wmeta.pad_offset + world.wmeta.padsize.x; + uint16_t size_x = getmaxx(world.wins.pad); + uint16_t right_edge = world.wins.pad_offset + world.wins.padsize.x; if (right_edge < size_x - 1) { padscroll_hint('>', size_x - right_edge); } /* Write pad segment to be shown on physical screen to screen buffer. */ - pnoutrefresh(world.wmeta.pad, 0, world.wmeta.pad_offset, 0, 0, - world.wmeta.padsize.y, world.wmeta.padsize.x - 1); + pnoutrefresh(world.wins.pad, 0, world.wins.pad_offset, 0, 0, + world.wins.padsize.y, world.wins.padsize.x - 1); } /* Only at the end write accumulated changes to the physical screen. */ diff --git a/src/client/windows.h b/src/client/windows.h index 3b3a7ee..2f82667 100644 --- a/src/client/windows.h +++ b/src/client/windows.h @@ -24,7 +24,7 @@ #ifndef WINDOWS_H #define WINDOWS_H -#include /* WINDOW, chtype */ +#include /* chtype */ #include /* uint16_t, int16_t */ #include "../common/yx_uint16.h" /* yx_uint16 struct */ @@ -50,32 +50,13 @@ struct Win struct yx_uint16 winmapsize; /* ... with these geometry infos */ }; -/* The window manager's parent struct WinMeta contains the virtual screen, - * relates it to the terminal screen and anchors the chain of visible windows. - */ -struct WinMeta -{ - struct yx_uint16 padsize; /* virtual screen size */ - WINDOW * screen; /* ncurses' pointer to the terminal screen */ - WINDOW * pad; /* ncurses pad of virtual screen */ - struct Win * chain_start; /* first Win in chain; its _prev == 0 */ - struct Win * chain_end; /* last Win in chain; its _next == 0 */ - struct Win * active; /* Win highlighted/selected for manipulation */ - uint16_t pad_offset; /* number of cells view is moved to the right */ -}; - -/* Initialize world.wmeta and ncurses on terminal screen. All struct members - * initialize to 0 (.pad = NULL), except for .screen (= initscr()). - */ -extern void init_wmeta_and_ncurses(); - -/* Builds world.wmeta.pad from the sizes of the current terminal screen. */ +/* Builds world.wins.pad from the sizes of the current terminal screen. */ extern void make_pad(); -/* Initialize a Win child "wp" of "wmeta" to "title", "height" and "width" and - * appoint "func"() as its .draw. Initialize other members to 0. +/* Initialize a Win at "wp" to "title", "height" and "width" and appoint + * "func"() as its .draw. Initialize other members to 0. * * Pass 0 for "width" to make the window as wide as the terminal screen. Pass 0 * for "height" for the maximum allowed height: one cell smaller than that of @@ -90,10 +71,10 @@ extern void init_win(struct Win ** wp, char * title, int16_t height, /* Free memory initianized Win structs. */ extern void free_win(struct Win * win); -/* Append/suspend window "w" to/from chain of visible windows below "wmeta". - * 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). +/* 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). */ extern void append_win(struct Win * w); extern void suspend_win(struct Win * w); diff --git a/src/client/world.h b/src/client/world.h index 4e92bb2..fb8ae4d 100644 --- a/src/client/world.h +++ b/src/client/world.h @@ -12,15 +12,13 @@ #include "../common/yx_uint16.h" /* struct yx_uint16 */ #include "keybindings.h" /* stuct KeyBindingDB */ #include "command_db.h" /* struct CommandDB */ -#include "windows.h" /* struct WinMeta */ #include "wincontrol.h" /* WinConfDB */ struct World { - struct WinMeta wmeta; - struct WinConfDB winconf_db; + struct WinConfDB wins; struct CommandDB cmd_db; /* Command database. */ struct KeyBindingDB kb_global; /* Global keybindings. */ struct KeyBindingDB kb_wingeom; /* Window geometry config keybindings. */