From: Christian Heller Date: Mon, 2 Sep 2013 04:01:41 +0000 (+0200) Subject: Window configuration can now be saved; and edited in a special window config view... X-Git-Tag: tce~982 X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7Bprefix%7D%7D/process_efforts?a=commitdiff_plain;h=8de0e493346efc0f7f303ee0c06c19a55957342c;p=plomrogue Window configuration can now be saved; and edited in a special window config view available on each window. Also simplified how init_win() interprets size parameters. --- diff --git a/README b/README index f21799c..457ed7a 100644 --- a/README +++ b/README @@ -46,6 +46,10 @@ _ shrink window horizontally + grow window vertically - shrink window vertically r reload window configuration +z toggle window configuration view +h toggle whether window height is saved as positive or negative +n toggle whether window width is saved as positive or negative +m save window configuration w scroll map up x scroll map down diff --git a/config/commands b/config/commands index e4e9824..10d452c 100644 --- a/config/commands +++ b/config/commands @@ -28,3 +28,7 @@ 28 player_r player right 29 wait wait / next turn 30 reload_wins reload windows configuration +31 winconf toggle window configuration view +32 to_height_t toggle window height type +33 to_width_t toggle window width type +34 save_winconf save window configuration diff --git a/config/keybindings b/config/keybindings index 257ff5e..b8ced54 100644 --- a/config/keybindings +++ b/config/keybindings @@ -1,7 +1,15 @@ 81 quit +119 map_u +120 map_d +97 map_l +100 map_r +115 map_c +87 player_u +88 player_d +65 player_l +68 player_r +83 wait 75 save_keys -260 scrl_l -261 scrl_r 258 keys_d 259 keys_u 10 keys_m @@ -17,14 +25,10 @@ 95 shri_h 43 grow_v 45 shri_v +260 scrl_l +261 scrl_r 114 reload_wins -119 map_u -120 map_d -97 map_l -100 map_r -115 map_c -87 player_u -88 player_d -65 player_l -68 player_r -83 wait +122 winconf +104 to_height_t +110 to_width_t +109 save_winconf diff --git a/config/windows/Win_i b/config/windows/Win_i index a8759ad..948c2ec 100644 --- a/config/windows/Win_i +++ b/config/windows/Win_i @@ -1,3 +1,3 @@ Info 3 -20 +12 diff --git a/config/windows/Win_k b/config/windows/Win_k index a719bf3..67c674e 100644 --- a/config/windows/Win_k +++ b/config/windows/Win_k @@ -1,3 +1,3 @@ Keys 0 -29 +42 diff --git a/config/windows/Win_l b/config/windows/Win_l index feef14f..023229d 100644 --- a/config/windows/Win_l +++ b/config/windows/Win_l @@ -1,3 +1,3 @@ Log -4 -20 +12 diff --git a/config/windows/Win_m b/config/windows/Win_m index a403ed8..cd42830 100644 --- a/config/windows/Win_m +++ b/config/windows/Win_m @@ -1,3 +1,3 @@ Map 0 --51 +-56 diff --git a/src/control.c b/src/control.c index 0b601fe..273fddc 100644 --- a/src/control.c +++ b/src/control.c @@ -11,8 +11,10 @@ #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(), get_win_by_id(), +#include "wincontrol.h" /* for scroll_pad(), toggle_window(), * growshrink_active_window(), reload_win_config() + * toggle_winconfig(), save_win_configs(), + * 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() */ @@ -133,19 +135,19 @@ extern uint8_t meta_control(int key, struct World * world) } else if (key == get_action_key(world->keybindings, "grow_h")) { - exit_err(growshrink_active_window(win_meta, '*'), world, err_resize); + exit_err(growshrink_active_window(world, '*'), world, err_resize); } else if (key == get_action_key(world->keybindings, "shri_h")) { - exit_err(growshrink_active_window(win_meta, '_'), world, err_resize); + exit_err(growshrink_active_window(world, '_'), world, err_resize); } else if (key == get_action_key(world->keybindings, "grow_v")) { - exit_err(growshrink_active_window(win_meta, '+'), world, err_resize); + exit_err(growshrink_active_window(world, '+'), world, err_resize); } else if (key == get_action_key(world->keybindings, "shri_v")) { - exit_err(growshrink_active_window(win_meta, '-'), world, err_resize); + exit_err(growshrink_active_window(world, '-'), world, err_resize); } else if (key == get_action_key(world->keybindings, "save_keys")) { @@ -187,5 +189,21 @@ extern uint8_t meta_control(int key, struct World * world) { reload_win_config(world); } + else if (key == get_action_key(world->keybindings, "winconf")) + { + toggle_winconfig(world, world->wmeta->active); + } + else if (key == get_action_key(world->keybindings, "to_height_t")) + { + toggle_win_height_type(world, world->wmeta->active); + } + else if (key == get_action_key(world->keybindings, "to_width_t")) + { + toggle_win_width_type(world, world->wmeta->active); + } + else if (key == get_action_key(world->keybindings, "save_winconf")) + { + save_win_configs(world); + } return 0; } diff --git a/src/draw_wins.c b/src/draw_wins.c index b15e174..b036d12 100644 --- a/src/draw_wins.c +++ b/src/draw_wins.c @@ -13,6 +13,7 @@ #include "main.h" /* for World struct */ #include "rexit.h" /* for err_exit() */ #include "command_db.h" /* for get_command_longdesc() */ +#include "wincontrol.h" /* for WinConf struct, get_winconf_by_win() */ @@ -287,3 +288,38 @@ extern void draw_keys_win(struct Win * win) } free(keydesc); } + + + +extern void draw_winconf(struct Win * win) +{ + struct World * world = (struct World *) win->data; + struct WinConf * wcp = get_winconf_by_win(world, win); + char * title = "Window configuration:\n"; + char * h_t_d = "\nWill save height as: "; + char * h_pos = "height in positive cells"; + char * h_neg = "negative diff to maximum height"; + char * h_d = "\nHeight to be saved: "; + char * w_t_d = "\n\nWill save width as: "; + char * w_pos = "width in positive cells"; + char * w_neg = "negative diff to maximum width"; + char * w_d = "\nWidth to be saved: "; + char * h_t = h_pos; + char * w_t = w_pos; + if (1 == wcp->height_type) + { + h_t = h_neg; + } + if (1 == wcp->width_type) + { + w_t = w_neg; + } + uint16_t maxl = strlen(title) + + strlen(h_t_d) + strlen(h_t) + strlen(h_d) + 6 + + strlen(w_t_d) + strlen(w_t) + strlen(w_d) + 6 + 1; + char * text = malloc(maxl + 1); + sprintf(text, "%s%s%s%s%d%s%s%s%d", title, h_t_d, h_t, h_d, wcp->height, + w_t_d, w_t, w_d, wcp->width); + draw_with_linebreaks(win, text, 0); + free(text); +} diff --git a/src/draw_wins.h b/src/draw_wins.h index 4b8574b..6a939eb 100644 --- a/src/draw_wins.h +++ b/src/draw_wins.h @@ -25,6 +25,9 @@ extern void draw_info_win(struct Win * win); /* Draw keybindings selection/manipulation menu. */ extern void draw_keys_win(struct Win * win); +/* Draw window configuration info. */ +extern void draw_winconf(struct Win * win); + #endif diff --git a/src/wincontrol.c b/src/wincontrol.c index f20f37a..bcb99b9 100644 --- a/src/wincontrol.c +++ b/src/wincontrol.c @@ -4,6 +4,8 @@ #include /* for malloc(), free() */ #include /* for strlen() */ #include /* for uint8_t, uint16_t */ +#include /* for fopen(), fclose(), fwrite() */ +#include /* for access(), unlink() */ #include "windows.h" /* for suspend_win(), append_win(), reset_pad_offset(), * resize_active_win(), init_win(), free_win(), * structs Win, WinMeta @@ -19,36 +21,83 @@ +/* Return string "prefix" + "id"; malloc()'s string, remember to call free()! */ +static char * string_prefixed_id(struct World * world, char * prefix, char id); + + + +/* Create Winconf, initialize ->iew/height_type/width_type to 0, ->id to "id" + * and ->draw to f. + */ +static void create_winconf(char id, struct WinConf * wcp, + void (* f) (struct Win *)); + /* Initialize Winconf of "id" from appropriate config file.*/ static void init_winconf_from_file(struct World * world, char id); -/* Wrapper around init_win() called with values from appropriate Winconf. */ +/* Wrapper around init_win() called with values from Winconf of "id". */ static void init_win_from_winconf(struct World * world, char id); +/* Save title, size of window identified by "id" to its configuration file. */ +static void save_win_config(struct World * world, char id); -static void init_winconf_from_file(struct World * world, char id) + +/* Write size of a window to its WinConf, as positive or negative values + * (dependent on state ofWinConf->height_type / WinConf->width_type). + */ +static void set_winconf(struct World * world, char id); + + + +/* Get WinConf by "id"; get id of WinConf mothering "win". */ +static struct WinConf * get_winconf_by_id(struct World * world, char id); +static char get_id_by_win(struct World * world, struct Win * win); + + + +static char * string_prefixed_id(struct World * world, char * prefix, char id) { - char * err_m = "Trouble in init_win_from_file() with malloc()."; - char * prefix = "config/windows/Win_"; + char * err = "Trouble in string_prefixed_id() with malloc()."; uint8_t size = strlen(prefix) + 2; char * path = malloc(size); - exit_err(NULL == path, world, err_m); + exit_err(NULL == path, world, err); sprintf(path, "%s_", prefix); path[size - 2] = id; + return path; +} + + + +static void create_winconf(char id, struct WinConf * wcp, + void (* f) (struct Win *)) +{ + wcp->id = id; + wcp->draw = f; + wcp->view = 0; + wcp->height_type = 0; + wcp->width_type = 0; +} + + + +static void init_winconf_from_file(struct World * world, char id) +{ + char * err_m = "Trouble in init_win_from_file() with malloc()."; + char * path = string_prefixed_id(world, "config/windows/Win_", id); char * err = "Trouble in init_win_from_file() with fopen()."; FILE * file = fopen(path, "r"); exit_err(NULL == file, world, err); free(path); + err = "Trouble in init_win_from_file() with textfile_sizes()."; struct WinConf * winconf = get_winconf_by_id(world, id); uint16_t linemax; - err = "Trouble in init_win_from_file() with textfile_sizes()."; exit_err(textfile_sizes(file, &linemax, NULL), world, err); char * line = malloc(linemax); exit_err(NULL == line, world, err_m); - err = "Trouble in init_win_from_file() with fgets()."; + err = "Trouble in init_win_from_file() with fgets()."; exit_err(NULL == fgets(line, linemax, file), world, err); winconf->title = malloc(strlen(line)); exit_err(NULL == winconf->title, world, err_m); @@ -56,9 +105,16 @@ static void init_winconf_from_file(struct World * world, char id) winconf->title[strlen(line) - 1] = '\0'; /* char at end of string. */ exit_err(NULL == fgets(line, linemax, file), world, err); winconf->height = atoi(line); + if (0 >= winconf->height) + { + winconf->height_type = 1; + } exit_err(NULL == fgets(line, linemax, file), world, err); winconf->width = atoi(line); - + if (0 >= winconf->width) + { + winconf->width_type = 1; + } free(line); err = "Trouble in init_win_from_file() with fclose()."; exit_err(fclose(file), world, err); @@ -77,19 +133,126 @@ static void init_win_from_winconf(struct World * world, char id) +extern void save_win_config(struct World * world, char id) +{ + char * err_o = "Trouble in save_win_config() with fopen()."; + char * err_m = "Trouble in save_win_config() with malloc()."; + char * err_c = "Trouble in save_win_config() with fclose()."; + char * err_u = "Trouble in save_win_config() with unlink()."; + char * err_r = "Trouble in save_win_config() with rename()."; + + char * path_tmp = string_prefixed_id(world, "config/windows/Win_tmp_", id); + FILE * file = fopen(path_tmp, "w"); + exit_err(NULL == file, world, err_o); + + struct WinConf * wc = get_winconf_by_id(world, id); + uint8_t size = strlen(wc->title) + 2; + if (size < 7) + { + size = 7; + } + char * line = malloc(size); + exit_err(NULL == line, world, err_m); + sprintf(line, "%s\n", wc->title); + fwrite(line, sizeof(char), strlen(line), file); + sprintf(line, "%d\n", wc->height); + fwrite(line, sizeof(char), strlen(line), file); + sprintf(line, "%d\n", wc->width); + fwrite(line, sizeof(char), strlen(line), file); + + exit_err(fclose(file), world, err_c); + char * path = string_prefixed_id(world, "config/windows/Win_", id); + if (!access(path, F_OK)) + { + exit_err(unlink(path), world, err_u); + } + exit_err(rename(path_tmp, path), world, err_r); + free(path); + free(path_tmp); +} + + + +static void set_winconf(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; + } + else if (1 == wcp->height_type) + { + wcp->height = wcp->win->frame.size.y - world->wmeta->padframe.size.y + + 1; + } + if (0 == wcp->width_type) + { + wcp->width = wcp->win->frame.size.x; + } + else if (1 == wcp->width_type) + { + wcp->width = wcp->win->frame.size.x - world->wmeta->padframe.size.x; + } +} + + + +static struct WinConf * get_winconf_by_id(struct World * world, char id) +{ + uint8_t i = 0; + while (1) + { + if (id == world->winconfs[i].id) + { + return &world->winconfs[i]; + } + i++; + } +} + + + +static char get_id_by_win(struct World * world, struct Win * win) +{ + struct WinConf * wc = get_winconf_by_win(world, win); + return wc->id; +} + + + +extern struct WinConf * get_winconf_by_win(struct World * world, + struct Win * win) +{ + uint8_t i = 0; + while (1) + { + if (win == world->winconfs[i].win) + { + return &world->winconfs[i]; + } + i++; + } +} + + + +extern struct Win * get_win_by_id(struct World * world, char id) +{ + struct WinConf * wc = get_winconf_by_id(world, id); + return wc->win; +} + + + extern void create_winconfs(struct World * world) { char * err = "Trouble with malloc() in init_winconfs()."; struct WinConf * winconfs = malloc(4 * sizeof(struct WinConf)); exit_err(NULL == winconfs, world, err); - winconfs[0].id = 'i'; - winconfs[0].draw = draw_info_win; - winconfs[1].id = 'k'; - winconfs[1].draw = draw_keys_win; - winconfs[2].id = 'l'; - winconfs[2].draw = draw_log_win; - winconfs[3].id = 'm'; - winconfs[3].draw = draw_map_win; + create_winconf('i', &winconfs[0], draw_info_win); + create_winconf('k', &winconfs[1], draw_keys_win); + create_winconf('l', &winconfs[2], draw_log_win); + create_winconf('m', &winconfs[3], draw_map_win); world->winconfs = winconfs; } @@ -144,6 +307,28 @@ extern void free_wins(struct World * world) +extern void sorted_wintoggle(struct World * world) +{ + char * err = "Trouble in sorted_wintoggle() with fopen()."; + FILE * file = fopen("config/windows/toggle_order", "r"); + exit_err(NULL == file, world, err); + uint16_t linemax; + err = "Trouble in sorted_wintoggle() with textfile_sizes()."; + exit_err(textfile_sizes(file, &linemax, NULL), world, err); + char win_order[linemax]; + err = "Trouble in sorted_wintoggle() with fgets()."; + exit_err(NULL == fgets(win_order, linemax, file), world, err); + err = "Trouble in sorted_wintoggle() with fclose()."; + exit_err(fclose(file), world, err); + uint8_t i = 0; + for (; i < linemax - 2; i++) + { + toggle_window(world->wmeta, get_win_by_id(world, win_order[i])); + } +} + + + extern void reload_win_config(struct World * world) { while (0 != world->wmeta->active) @@ -160,62 +345,107 @@ extern void reload_win_config(struct World * world) -extern struct WinConf * get_winconf_by_id(struct World * world, char id) +extern void save_win_configs(struct World * world) { + save_win_config(world, 'i'); + save_win_config(world, 'k'); + save_win_config(world, 'l'); + save_win_config(world, 'm'); + + char * err_o = "Trouble in save_win_configs() with fopen()."; + char * err_m = "Trouble in save_win_configs() with calloc()."; + char * err_c = "Trouble in save_win_configs() with fclose()."; + char * err_u = "Trouble in save_win_configs() with unlink()."; + char * err_r = "Trouble in save_win_configs() with rename()."; + + char * path = "config/windows/toggle_order"; + char * path_tmp = "config/windows/toggle_order_tmp"; + FILE * file = fopen(path_tmp, "w"); + exit_err(NULL == file, world, err_o); + + char * line = calloc(6, sizeof(char)); + exit_err(NULL == line, world, err_m); + struct Win * w_p = world->wmeta->_chain_start; uint8_t i = 0; - while (1) + while (0 != w_p) { - if (id == world->winconfs[i].id) - { - return &world->winconfs[i]; - } + line[i] = get_id_by_win(world, w_p); + w_p = w_p->_next; i++; } + line[i] = '\n'; + fwrite(line, sizeof(char), strlen(line), file); + + exit_err(fclose(file), world, err_c); + if (!access(path, F_OK)) + { + exit_err(unlink(path), world, err_u); + } + exit_err(rename(path_tmp, path), world, err_r); } -extern struct Win * get_win_by_id(struct World * world, char id) +extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win) { - struct WinConf * wc = get_winconf_by_id(world, id); - return wc->win; + if (0 != win->frame.curses_win) + { + return suspend_win(win_meta, win); + } + else + { + return append_win(win_meta, win); + } } -extern void sorted_wintoggle(struct World * world) +extern void toggle_winconfig(struct World * world, struct Win * win) { - char * err = "Trouble in sorted_wintoggle() with fopen()."; - FILE * file = fopen("config/windows/toggle_order", "r"); - exit_err(NULL == file, world, err); - uint16_t linemax; - err = "Trouble in sorted_wintoggle() with textfile_sizes()."; - exit_err(textfile_sizes(file, &linemax, NULL), world, err); - char win_order[linemax]; - err = "Trouble in sorted_wintoggle() with fgets()."; - exit_err(NULL == fgets(win_order, linemax, file), world, err); - err = "Trouble in sorted_wintoggle() with fclose()."; - exit_err(fclose(file), world, err); - uint8_t i = 0; - for (; i < linemax - 2; i++) + struct WinConf * wcp = get_winconf_by_win(world, win); + if (0 == wcp->view) { - toggle_window(world->wmeta, get_win_by_id(world, win_order[i])); + win->_draw = draw_winconf; + wcp->view = 1; + } + else + { + win->_draw = wcp->draw; + wcp->view = 0; } } +extern void toggle_win_height_type(struct World * world, struct Win * win) +{ + struct WinConf * wcp = get_winconf_by_win(world, win); + if (0 == wcp->height_type) + { + wcp->height_type = 1; + } + else + { + wcp->height_type = 0; + } + set_winconf(world, wcp->id); +} + + -extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win) +extern void toggle_win_width_type(struct World * world, struct Win * win) { - if (0 != win->frame.curses_win) + struct WinConf * wcp = get_winconf_by_win(world, win); + if ( 0 == wcp->width_type + && win->frame.size.x <= world->wmeta->padframe.size.x) { - return suspend_win(win_meta, win); + wcp->width_type = 1; } else { - return append_win(win_meta, win); + wcp->width_type = 0; } + set_winconf(world, wcp->id); } @@ -234,11 +464,11 @@ extern void scroll_pad(struct WinMeta * win_meta, char dir) -extern uint8_t growshrink_active_window(struct WinMeta * win_meta, char change) +extern uint8_t growshrink_active_window(struct World * world, char change) { - if (0 != win_meta->active) + if (0 != world->wmeta->active) { - struct yx_uint16 size = win_meta->active->frame.size; + struct yx_uint16 size = world->wmeta->active->frame.size; if (change == '-') { size.y--; @@ -255,7 +485,16 @@ extern uint8_t growshrink_active_window(struct WinMeta * win_meta, char change) { size.x++; } - return resize_active_win (win_meta, size); + 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) + { + wcp->width_type = 0; + } + set_winconf(world, wcp->id); + return x; } return 0; } diff --git a/src/wincontrol.h b/src/wincontrol.h index 5c9c4b5..dc07b98 100644 --- a/src/wincontrol.h +++ b/src/wincontrol.h @@ -16,19 +16,32 @@ struct World; -/* Puts an identifier on each window, interfaces to its config file data. */ +/* Stores designated configuration of a window pointed to in it, and data used + * to manipulate said window in the "window configuration" view of it. + */ struct WinConf { - char id; - struct Win * win; - char * title; - int16_t height; - int16_t width; - void (* draw) (struct Win *); + char id; /* unique identifier of WinConf, abused as ID for ->win, too */ + struct Win * win; /* window configured by this WinConf */ + char * title; /* designated title as passed to init_win() */ + int16_t height; /* designated height as interpreted by init_win()*/ + int16_t width; /* designated width as interpreted by init_win() */ + void (* draw) (struct Win *); /* designated Win->_draw; to be returned to */ + /* after toggling window configuration view */ + uint8_t view; /* 0: use ->draw as Win->_draw; 1: use draw_winconf()*/ + uint8_t height_type; /* both: 0: interpret ->height/->width as size in */ + uint8_t width_type; /* positive cells; 1: as negative diff to max width */ }; +/* Get WinConf fathering "win"; get Win of WinConf of "id". */ +extern struct WinConf * get_winconf_by_win(struct World * world, + struct Win * win); +extern struct Win * get_win_by_id(struct World * world, char id); + + + /* Create/initialize (from config files)/free Winconf / Win structs. */ extern void create_winconfs(struct World * world); extern void init_winconfs(struct World * world); @@ -38,22 +51,28 @@ extern void free_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 may correspond to + * one hardcoded window. + */ +extern void sorted_wintoggle(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); -/* Get WinConf identified by winconf->id == "id", or that winconf's ->win. */ -extern struct WinConf * get_winconf_by_id(struct World * world, char id); -extern struct Win * get_win_by_id(struct World * world, char id); +/* Toggle "window configuration" view for "win". */ +extern void toggle_winconfig(struct World * world, struct Win * win); - -/* Toggle windows in world->wins in the order desribed by the first line of - * config/windows/toggled_win_order, wherein each character may correspond to - * one hardcoded window. +/* Toggle interpretation type for Win's width/height of Win in WinConf. Width + * only toggles to 1 if terminal window is at least as wide as WinConf->width. */ -extern void sorted_wintoggle(struct World * world); +extern void toggle_win_height_type(struct World * world, struct Win * win); +extern void toggle_win_width_type(struct World * world, struct Win * win); @@ -77,9 +96,11 @@ extern void scroll_pad(struct WinMeta * win_meta, char dir); * vertically ("change = "+"/"-") by one cell size, subject to the limitations * provided by the window manager via resize_active_win(). * + * Forces WinConf->width_type = 0 if new width surpasses that of terminal win. + * * Return 0 on success, 1 on (ncurses pad/window memory allocation) error. */ -extern uint8_t growshrink_active_window(struct WinMeta * win_meta, char change); +extern uint8_t growshrink_active_window(struct World * world, char change); diff --git a/src/windows.c b/src/windows.c index 389637b..bd3ec41 100644 --- a/src/windows.c +++ b/src/windows.c @@ -414,26 +414,18 @@ extern uint8_t init_win(struct WinMeta * wmeta, struct Win ** wp, char * title, { w->frame.size.x = width; } - else if (0 > width) + else if (0 >= width) { w->frame.size.x = wmeta->padframe.size.x + width; } - else - { - w->frame.size.x = wmeta->padframe.size.x; - } if (0 < height && height <= wmeta->padframe.size.y - 1) { w->frame.size.y = height; } - else if (0 > height && wmeta->padframe.size.y + (height - 1) > 0) + else if (0 >= height && wmeta->padframe.size.y + (height - 1) > 0) { w->frame.size.y = wmeta->padframe.size.y + (height - 1); } - else - { - w->frame.size.y = wmeta->padframe.size.y - 1; - } *wp = w; return 0; } diff --git a/src/windows.h b/src/windows.h index 5ec4d2f..4914a27 100644 --- a/src/windows.h +++ b/src/windows.h @@ -104,12 +104,13 @@ extern uint8_t init_win_meta(WINDOW * screen, struct WinMeta ** wmeta); * the window is visible. * * Pass 0 for "width" to make the window as wide as the terminal screen. Pass - * negative values for "width" to make the size so many cells smaller than the - * terminal screen. Pass 0 for "height" to give the window the maximum allowed - * height: one cell smaller than the terminal screen. Pass negative values to - * make the window so many smalls smaller than the terminal screen. The maximum - * allowed height is also applied for positive values that exceed it or negative - * values that would reduce the window height < 1 cell. + * negative values for "width" to make the width so many cells smaller than that + * of the terminal screen. Pass 0 for "height" to give the window the maximum + * allowed height: one cell smaller than that of the terminal screen. Pass + * negative values to make the window width so many cells smaller than that of + * the terminal screen. The maximum allowed height is also applied for positive + * values that exceed it or negative values that would reduce the window height + * < 1 cell. * * Other members of the Win struct are initialized to 0. */