1 /* src/client/windows.c */
4 #include <ncurses.h> /* chtype, getmaxx(), getmaxy(), erase(), werase(),
5 * endwin(), delwin(), wnoutrefresh(), pnoutrefresh(),
6 * doupdate(), refresh(), delwin(), newpad(), mvwaddch(),
7 * mvwaddstr(), wresize()
9 #include <stddef.h> /* NULL */
10 #include <stdlib.h> /* free(), atoi() */
11 #include <stdint.h> /* uint8_t, uint16_t, uint32_t, UINT16_MAX */
12 #include <stdio.h> /* sprintf() */
13 #include <string.h> /* memcpy(), strlen(), strnlen(), strchr(), memset() */
14 #include "../common/rexit.h" /* exit_trouble(), exit_err() */
15 #include "../common/readwrite.h" /* try_fputc(), try_write(), try_fgets(),
18 #include "../common/try_malloc.h" /* try_malloc() */
19 #include "../common/yx_uint16.h" /* struct yx_uint16 */
20 #include "draw_wins.h" /* draw_winconf_geometry(), draw_winconf_keybindings(),
21 * draw_win_inventory(), draw_win_info(), draw_win_log(),
22 * draw_win_available_keybindings(), draw_win_map(),
23 * draw_win_keybindings_winconf_keybindings(),
24 * draw_win_keybindings_winconf_geometry(),
25 * draw_win_keybindings_global()
27 #include "keybindings.h" /* free_keybindings(), write_keybidings_to_file(),
28 * read_keybindings_from_file()
30 #include "misc.h" /* array_append() */
31 #include "world.h" /* global world */
35 /* Get position of id "c" in world.winDB.order or return Win before/after (or
36 * NULL if there is no window before/after).
38 static uint8_t get_pos_in_order(char c);
39 static struct Win * get_win_after(char c);
40 static struct Win * get_win_before(char c);
42 /* Calculate "id"'s window's size from v_screen size and .target_(height/width).
43 * A .target_width == 0 makes the window as wide as .t_screen. .target_height ==
44 * 0 sets the maximum allowed height: one cell smaller than that of .v_screen.
45 * Negative values make width/height so many cells smaller than what 0 would
46 * set. Values that would reduce the window height or width to less than 1 cell
47 * according to the aforementioned rules set the height/width as if they were 0.
49 static void init_win_size_from_winconf_and_v_screen_size(char id);
51 /* Get (Win->draw) function identified by "c"; NULL if c not mapped to one.
52 * match_func() is just a little helper to it.
54 static uint8_t match_func(char c, void (** f) (), char c_m, void (* f_m) ());
55 static void * get_drawfunc_by_char(char c);
57 /* Write "win"'s size back to .target_(height/width) as per .target_*_type. */
58 static void set_win_target_size(struct Win * win);
60 /* Iterate over chars of world.winDB.ids array / string. Restart after \0.*/
61 static char get_next_win_id();
63 /* Make .v_screen just wide enough to contain all visible windows. */
64 static void refit_v_screen();
66 /* Update geometry (sizes, positions) of window "w" and its successors in the
67 * window chain. Use place_win() for the positioning algorithm.
69 static void update_wins(struct Win * w);
70 static void place_win(struct Win * w);
72 /* Draw scroll hint (a line saying that there are "dist" more elements of "unit"
73 * further into the direction symbolized by "dir") into .v_screen, onto an
74 * appropriate edge of a window or .v_screen; the left/right edge if "dir" is
75 * "<"/">", or the top/bottom edge if it is "^"/"v". Use "start" as the start
76 * coordinate of the frame that is to contain the scroll hints. winscroll_hint()
77 * is a wrapper that uses the border of window "w" as this frame.
79 static void scroll_hint(struct yx_uint16 fsize, char dir, uint16_t dist,
80 char * unit, struct yx_uint16 start);
81 static void winscroll_hint(struct Win * w, char dir, uint16_t dist);
83 /* draw_win_borderlines() draws vertical/horizontal borders of window "w" sans
84 * corners into .v_screen. It draws the top border line as the windows' title
85 * bar (highlighted if the window is selected as active). It is called
86 * recursively by draw_wins_borderlines() on all windows from "w" on.
87 * draw_wins_bordercorners() draws the border corners of "w" and its successors.
89 static void draw_win_borderlines(struct Win * w);
90 static void draw_wins_borderlines(struct Win * w);
91 static void draw_wins_bordercorners(struct Win * w);
93 /* Draw contents of all windows in window chain from window "w" onwards. */
94 static void draw_wins(struct Win * w);
96 /* Append/suspend window "w" to/from chain of visible windows. Appended windows
97 * will become active. Suspended active windows will move the active window
98 * selection to their successor in the window chain or, failing that, their
99 * predecessor, or, failing that, to 0 (no window active).
101 static void append_win(struct Win * w);
102 static void suspend_win(struct Win * w);
106 static uint8_t get_pos_in_order(char c)
109 for (i = 0; c != world.winDB.order[i]; i++);
115 static struct Win * get_win_after(char c)
117 return get_win_by_id(world.winDB.order[get_pos_in_order(c) + 1]);
122 static struct Win * get_win_before(char c)
124 uint8_t i = get_pos_in_order(c);
127 return get_win_by_id(world.winDB.order[i - 1]);
134 static void init_win_size_from_winconf_and_v_screen_size(char id)
136 struct Win * w = get_win_by_id(id);
137 w->frame_size.y = world.winDB.v_screen_size.y - 1;
138 if ( 0 < w->target_height
139 && w->target_height <= world.winDB.v_screen_size.y - 1)
141 w->frame_size.y = w->target_height;
143 else if ( 0 > w->target_height
144 && world.winDB.v_screen_size.y + (w->target_height - 1) > 0)
146 w->frame_size.y = world.winDB.v_screen_size.y + (w->target_height - 1);
148 w->frame_size.x = world.winDB.v_screen_size.x;
149 if (0 < w->target_width)
151 w->frame_size.x = w->target_width;
153 else if ( 0 > w->target_width
154 && world.winDB.v_screen_size.x + w->target_width > 0)
156 w->frame_size.x = world.winDB.v_screen_size.x + w->target_width;
162 static uint8_t match_func(char c, void (** f) (), char c_m, void (* f_m) ())
174 static void * get_drawfunc_by_char(char c)
176 void (* f) (struct Win *) = NULL;
177 if ( match_func(c, &f, 'c', draw_win_inventory)
178 || match_func(c, &f, 'i', draw_win_info)
179 || match_func(c, &f, 'l', draw_win_log)
180 || match_func(c, &f, 'k', draw_win_available_keybindings)
181 || match_func(c, &f, 'm', draw_win_map)
182 || match_func(c, &f, '0', draw_win_keybindings_global)
183 || match_func(c, &f, '1', draw_win_keybindings_winconf_geometry)
184 || match_func(c, &f, '2', draw_win_keybindings_winconf_keybindings));
190 static void set_win_target_size(struct Win * wcp)
192 if (0 == wcp->target_height_type)
194 wcp->target_height = wcp->frame_size.y;
196 else if (1 == wcp->target_height_type)
198 wcp->target_height = wcp->frame_size.y - world.winDB.v_screen_size.y +1;
200 if (0 == wcp->target_width_type)
202 wcp->target_width = wcp->frame_size.x;
204 else if (1 == wcp->target_width_type)
206 wcp->target_width = wcp->frame_size.x - world.winDB.v_screen_size.x;
212 static char get_next_win_id()
214 static uint8_t i = 0;
215 char c = world.winDB.ids[i];
227 static void refit_v_screen()
229 /* Determine rightmost window column. */
230 uint32_t lastwcol = 0;
231 struct Win * wp = get_win_by_id(world.winDB.order[0]);
234 if ((uint32_t) wp->start.x + (uint32_t) wp->frame_size.x > lastwcol + 1)
236 lastwcol = (uint32_t) wp->start.x + (uint32_t) wp->frame_size.x - 1;
238 wp = get_win_after(wp->id);
241 /* Only resize .v_screen if the rightmost window column has changed. */
242 char * err_s = "refit_v_screen() grows virtual screen beyond legal sizes.";
243 char * err_m = "refit_v_screen() triggers memory alloc error in wresize().";
244 if (getmaxx(world.winDB.v_screen) + 1 != lastwcol)
246 uint8_t t = (lastwcol + 2 > UINT16_MAX);
248 t = wresize(world.winDB.v_screen, getmaxy(world.winDB.v_screen),
256 static void update_wins(struct Win * w)
260 struct Win * next = get_win_after(w->id);
269 static void place_win(struct Win * w)
271 /* If w is first window, it goes into the top left corner. */
273 w->start.y = 1; /* Leave space for title bar. */
274 struct Win * w_prev = get_win_before(w->id);
278 /* If not, fit w's top left to top right of last top predecessor. */
279 struct Win * w_top = w_prev;
282 w_top = get_win_before(w_top->id));
283 w->start.x = w_top->start.x + w_top->frame_size.x + 1;
285 /* Fit w's top left to bottom left of its ->prev if enough space. */
286 uint16_t w_prev_maxy = w_prev->start.y + w_prev->frame_size.y;
287 if ( w->frame_size.x <= w_prev->frame_size.x
288 && w->frame_size.y < world.winDB.v_screen_size.y - w_prev_maxy)
290 w->start.x = w_prev->start.x;
291 w->start.y = w_prev_maxy + 1;
295 /* Failing that, try to fit w' top left to the top right of the last
296 * predecessor w_test 1) not followed by windows with a left corner
297 * further rightwards than its own 2) with enough space rightwards for w
298 * until the bottom right of w_thr directly throning over it 3) and with
299 * this same space extending far enough to the bottom for fitting in w.
301 struct Win * w_test = w_prev;
303 while (w_test != w_top)
305 for (w_thr = get_win_before(w_test->id);
306 w_test->start.y <= w_thr->start.y;
307 w_thr = get_win_before(w_thr->id));
308 uint16_t w_thr_bottom = w_thr->start.y + w_thr->frame_size.y;
309 uint16_t free_width = (w_thr->start.x + w_thr->frame_size.x)
310 - (w_test->start.x + w_test->frame_size.x);
311 if ( w->frame_size.y < world.winDB.v_screen_size.y - w_thr_bottom
312 && w->frame_size.x < free_width)
314 w->start.x = w_test->start.x + w_test->frame_size.x + 1;
315 w->start.y = w_thr_bottom + 1;
325 static void scroll_hint(struct yx_uint16 fsize, char dir, uint16_t dist,
326 char * unit, struct yx_uint16 start)
328 /* Decide on alignment (vertical/horizontal?), thereby hint text space. */
329 char * more = "more";
330 uint16_t dsc_space = fsize.x;
331 if ('<' == dir || '>' == dir)
334 } /* vv-- 10 = max strlen for uint16_t */
335 char scrolldsc[1 + strlen(more) + 1 + 10 + 1 + strlen(unit) + 1 + 1];
336 sprintf(scrolldsc, " %d %s %s ", dist, more, unit);
338 /* Decide on offset of the description text inside the scroll hint line. */
339 uint16_t dsc_offset = 1;
340 if (dsc_space > strlen(scrolldsc) + 1)
342 dsc_offset = (dsc_space - strlen(scrolldsc)) / 2;
345 /* Draw scroll hint line as dir symbols bracketing description text. */
346 uint16_t draw_offset = 0;
349 draw_offset = fsize.x - 1;
353 draw_offset = fsize.y - 1;
356 for (; q < dsc_space; q++)
358 chtype c = dir | A_REVERSE;
359 if (q >= dsc_offset && q < strlen(scrolldsc) + dsc_offset)
361 c = scrolldsc[q - dsc_offset] | A_REVERSE;
363 if ('<' == dir || '>' == dir)
365 mvwaddch(world.winDB.v_screen, start.y+q, start.x+draw_offset, c);
368 mvwaddch(world.winDB.v_screen, start.y + draw_offset, start.x + q, c);
374 static void winscroll_hint(struct Win * w, char dir, uint16_t dist)
376 char * unit = "lines";
377 if ('<' == dir || '>' == dir)
381 struct yx_uint16 start = w->start;
382 scroll_hint(w->frame_size, dir, dist, unit, start);
387 static void draw_win_borderlines(struct Win * w)
389 /* Draw vertical and horizontal border lines. */
391 for (y = w->start.y; y <= w->start.y + w->frame_size.y; y++)
393 mvwaddch(world.winDB.v_screen, y, w->start.x - 1, '|');
394 mvwaddch(world.winDB.v_screen, y, w->start.x + w->frame_size.x, '|');
396 for (x = w->start.x; x <= w->start.x + w->frame_size.x; x++)
398 mvwaddch(world.winDB.v_screen, w->start.y - 1, x, '-');
399 mvwaddch(world.winDB.v_screen, w->start.y + w->frame_size.y, x, '-');
402 /* Draw as much as possible of the title into center of top border line. */
403 uint8_t min_title_length_visible = 3;/* min. 1 char +2 padding/decoration*/
404 if (w->frame_size.x >= min_title_length_visible)
407 if (w->frame_size.x > strlen(w->title) + 2)
409 offset = (w->frame_size.x - (strlen(w->title) + 2)) / 2;
410 } /* +2 is for padding/decoration */
411 uint16_t length_visible = strnlen(w->title, w->frame_size.x - 2);
412 char title[length_visible + 3];
413 char decoration = ' ';
414 if (w->id == world.winDB.active)
418 memcpy(title + 1, w->title, length_visible);
419 title[0] = title[length_visible + 1] = decoration;
420 title[length_visible + 2] = '\0';
421 mvwaddstr(world.winDB.v_screen, w->start.y-1, w->start.x+offset, title);
427 static void draw_wins_borderlines(struct Win * w)
429 draw_win_borderlines(w);
430 struct Win * next = get_win_after(w->id);
433 draw_wins_borderlines(next);
439 static void draw_wins_bordercorners(struct Win * w)
441 mvwaddch(world.winDB.v_screen,
442 w->start.y - 1, w->start.x - 1, '+');
443 mvwaddch(world.winDB.v_screen,
444 w->start.y - 1, w->start.x + w->frame_size.x, '+');
445 mvwaddch(world.winDB.v_screen,
446 w->start.y + w->frame_size.y, w->start.x - 1, '+');
447 mvwaddch(world.winDB.v_screen, w->start.y + w->frame_size.y,
448 w->start.x + w->frame_size.x, '+');
449 struct Win * next = get_win_after(w->id);
452 draw_wins_bordercorners(next);
458 static void draw_wins(struct Win * w)
460 void (* drawfunc) (struct Win *) = get_drawfunc_by_char(w->id);
463 drawfunc = draw_winconf_geometry;
465 else if (2 == w->view)
467 drawfunc = draw_winconf_keybindings;
470 uint16_t size_y = w->winmap_size.y;
471 uint16_t size_x = w->winmap_size.x;
472 uint16_t offset_y = center_offset(w->center.y, size_y, w->frame_size.y);
473 uint16_t offset_x = center_offset(w->center.x, size_x, w->frame_size.x);
475 for (y = offset_y; y < w->frame_size.y + offset_y && y < size_y; y++)
477 for (x = offset_x; x < w->frame_size.x + offset_x && x < size_x; x++)
479 chtype ch = w->winmap[(y * w->winmap_size.x) + x];
480 mvwaddch(world.winDB.v_screen, w->start.y + (y - offset_y),
481 w->start.x + (x - offset_x), ch);
484 free(w->winmap); /* NULL so draw_wins.c's try_resize_winmap() may always */
485 w->winmap = NULL;/* free() it before (re-)allocation, even the first time.*/
486 memset(&w->winmap_size, 0, sizeof(struct yx_uint16));
489 winscroll_hint(w, '^', offset_y + 1);
491 if (size_y > offset_y + w->frame_size.y)
493 winscroll_hint(w, 'v', size_y - ((offset_y + w->frame_size.y) - 1));
497 winscroll_hint(w, '<', offset_x + 1);
499 if (size_x > offset_x + w->frame_size.x)
501 winscroll_hint(w, '>', size_x - ((offset_x + w->frame_size.x) - 1));
503 struct Win * next = get_win_after(w->id);
506 return draw_wins(next);
512 static void append_win(struct Win * w)
514 char * f_name = "append_win()";
515 uint8_t old_size = strlen(world.winDB.order) + 1;
516 char * new_order = try_malloc(old_size + 1, f_name);
517 memcpy(new_order, world.winDB.order, old_size - 1);
518 new_order[old_size - 1] = w->id;
519 new_order[old_size] = '\0';
520 free(world.winDB.order);
521 world.winDB.order = new_order;
522 world.winDB.active = w->id;
528 static void suspend_win(struct Win * w)
530 char * f_name = "suspend_win()";
531 uint8_t new_size = strlen(world.winDB.order);
532 char * new_order = try_malloc(new_size, f_name);
533 uint8_t i = get_pos_in_order(w->id);
534 char next_char = world.winDB.order[i + 1];
535 world.winDB.order[i] = '\0';
536 char * second_part = &world.winDB.order[i + 1];
537 sprintf(new_order, "%s%s", world.winDB.order, second_part);
538 free(world.winDB.order);
539 world.winDB.order = new_order;
540 world.winDB.active = world.winDB.order[i];
541 if (!world.winDB.order[i] && 0 < i)
543 world.winDB.active = world.winDB.order[i - 1];
545 if (world.winDB.order[i])
547 update_wins(get_win_by_id(next_char)); /* Already calls */
548 return; /* refit_v_screen(), so leave. */
555 extern uint16_t center_offset(uint16_t position, uint16_t mapsize,
559 if (mapsize > frame_size)
561 if (position > frame_size / 2)
563 if (position < mapsize - (frame_size / 2))
565 offset = position - (frame_size / 2);
569 offset = mapsize - frame_size;
578 extern struct Win * get_win_by_id(char id)
581 while ('\0' != world.winDB.ids[i])
583 if (id == world.winDB.ids[i])
585 return &world.winDB.wins[i];
594 extern uint8_t read_winconf_from_file(char * line, uint32_t linemax,
597 char * f_name = "read_winconf_from_file()";
598 int test = try_fgetc(file, f_name);
599 if (EOF == test || '\n' == test)
604 memset(&win, 0, sizeof(struct Win));
605 win.id = (char) test;
606 try_fgetc(file, f_name);
607 try_fgets(line, linemax + 1, file, f_name);
608 win.title = try_malloc(strlen(line), f_name);
609 memcpy(win.title, line, strlen(line) - 1); /* Eliminate newline char */
610 win.title[strlen(line) - 1] = '\0'; /* char at end of string. */
611 try_fgets(line, linemax + 1, file, f_name);
612 win.target_height = atoi(line);
613 win.target_height_type = (0 >= win.target_height);
614 try_fgets(line, linemax + 1, file, f_name);
615 win.target_width = atoi(line);
616 win.target_width_type = (0 >= win.target_width);
617 read_keybindings_from_file(line, linemax, file, &win.kb);
620 uint8_t old_ids_size = strlen(world.winDB.ids);
621 char * new_ids = try_malloc(old_ids_size + 1 + 1, f_name);
622 sprintf(new_ids, "%s%c", world.winDB.ids, win.id);
623 free(world.winDB.ids);
624 world.winDB.ids = new_ids;
625 array_append(old_ids_size, sizeof(struct Win), (void *) &win,
626 (void **) &world.winDB.wins);
629 world.winDB.ids = try_malloc(2, f_name);
630 sprintf(world.winDB.ids, "%c", win.id);
631 world.winDB.wins = try_malloc(sizeof(struct Win), f_name);
632 world.winDB.wins[0] = win;
638 extern void write_winconf_of_id_to_file(FILE * file, char c, char * delim)
640 char * f_name = "write_winconf_of_id_to_file()";
641 struct Win * wc = get_win_by_id(c);
642 uint8_t size = strlen(wc->title) + 2;
643 if (size < 7) /* Ensure that at least 5 + 2 char fit into line so that */
644 { /* the digit representation of any uint16_t may be stored. */
648 sprintf(line, "%c\n", wc->id);
649 try_fwrite(line, sizeof(char), strlen(line), file, f_name);
650 sprintf(line, "%s\n", wc->title);
651 try_fwrite(line, sizeof(char), strlen(line), file, f_name);
652 sprintf(line, "%d\n", wc->target_height);
653 try_fwrite(line, sizeof(char), strlen(line), file, f_name);
654 sprintf(line, "%d\n", wc->target_width);
655 try_fwrite(line, sizeof(char), strlen(line), file, f_name);
656 write_keybindings_to_file(file, &wc->kb, delim);
661 extern void read_order_wins_visible_active(char * line, uint32_t linemax,
664 char * f_name = "read_order_wins_visible_active()";
665 char win_order[linemax + 1];
666 try_fgets(win_order, linemax + 1, file, f_name);
667 win_order[strlen(win_order) - 1] = '\0';
668 world.winDB.order = try_malloc(strlen(win_order) + 1, f_name);
669 sprintf(world.winDB.order, "%s", win_order);
670 int char_or_eof = try_fgetc(file, f_name);
671 char * err_eof = "fgetc() unexpectedly hitting EOF";
672 exit_trouble(EOF == char_or_eof, f_name, err_eof);
673 world.winDB.active = (uint8_t) char_or_eof;
674 exit_trouble(EOF == try_fgetc(file, f_name), f_name, err_eof);
675 try_fgets(line, linemax + 1, file, f_name);
680 extern void write_order_wins_visible_active(FILE * file, char * delim)
682 char * f_name = "write_order_wins_visible_active()";
683 try_fwrite(world.winDB.order, strlen(world.winDB.order), 1, file, f_name);
684 try_fputc('\n', file, f_name);
685 try_fputc(world.winDB.active, file, f_name);
686 try_fputc('\n', file, f_name);
687 try_fwrite(delim, strlen(delim), 1, file, f_name);
692 extern void make_v_screen_and_init_win_sizes()
694 char * f_name = "make_v_screen_and_init_win_sizes()";
695 char * err_s = "creating an illegaly large virtual screen";
696 char * err_m = "triggering a memory allocation error via newpad()";
697 uint32_t maxy_test = getmaxy(world.winDB.t_screen);
698 uint32_t maxx_test = getmaxx(world.winDB.t_screen);
699 exit_trouble(maxy_test>UINT16_MAX || maxx_test>UINT16_MAX, f_name, err_s);
700 world.winDB.v_screen_size.y = maxy_test;
701 world.winDB.v_screen_size.x = maxx_test;
702 world.winDB.v_screen = newpad(world.winDB.v_screen_size.y, 1);
703 exit_trouble(NULL == world.winDB.v_screen, f_name, err_m);
705 while (0 != (id = get_next_win_id()))
707 init_win_size_from_winconf_and_v_screen_size(id);
713 extern void free_winDB()
716 while (0 != (id = get_next_win_id()))
718 struct Win * wc = get_win_by_id(id);
720 free_keybindings(wc->kb.kbs);
722 free(world.winDB.ids); /* NULL this too since add_win_to_winDB() checks */
723 world.winDB.ids = NULL; /* for it to detect its first post-DB-purge round.*/
724 free(world.winDB.wins);
725 free(world.winDB.order);
730 extern void winch_called(int signal)
737 extern void reset_windows_on_winch()
739 endwin(); /* "[S]tandard way" to recalibrate ncurses post SIGWINCH, says */
740 refresh(); /* <http://invisible-island.net/ncurses/ncurses-intro.html>. */
741 char tmp_order[strlen(world.winDB.order) + 1];
742 sprintf(tmp_order, "%s", world.winDB.order);
744 char tmp_active = world.winDB.active;
745 for (i = 0; i < strlen(tmp_order); toggle_window(tmp_order[i]), i++);
746 delwin(world.winDB.v_screen);
747 make_v_screen_and_init_win_sizes();
748 for (i = 0; i < strlen(tmp_order); toggle_window(tmp_order[i]), i++);
749 world.winDB.active = tmp_active;
754 extern void draw_all_wins()
756 /* Empty everything before filling it a-new. */
758 wnoutrefresh(world.winDB.t_screen);
759 werase(world.winDB.v_screen);
760 if (world.winDB.active)
763 /* Draw borders, wins. Order matters: corners should overwrite lines. */
764 draw_wins_borderlines(get_win_by_id(world.winDB.order[0]));
765 draw_wins_bordercorners(get_win_by_id(world.winDB.order[0]));
766 draw_wins(get_win_by_id(world.winDB.order[0]));
768 /* Draw .v_screen scroll hints. */
769 struct yx_uint16 start;
771 start.x = world.winDB.v_screen_offset;
772 char * cols_string = "columns";
773 if (world.winDB.v_screen_offset > 0)
775 scroll_hint(world.winDB.v_screen_size, '<',
776 world.winDB.v_screen_offset + 1, cols_string, start);
778 uint16_t size_x = getmaxx(world.winDB.v_screen);
779 uint16_t right_edge = world.winDB.v_screen_offset
780 + world.winDB.v_screen_size.x;
781 if (right_edge < size_x - 1)
783 scroll_hint(world.winDB.v_screen_size, '>',
784 size_x - right_edge, cols_string, start);
787 /* Put .v_screen segment to be shown on .t_screen to .t_screen buffer.*/
788 pnoutrefresh(world.winDB.v_screen, 0, world.winDB.v_screen_offset, 0, 0,
789 world.winDB.v_screen_size.y,
790 world.winDB.v_screen_size.x - 1);
793 /* Only at the end write accumulated changes to .t_screen. */
799 extern void toggle_window(char id)
801 struct Win * win = get_win_by_id(id);
802 if (NULL == strchr(world.winDB.order, id))
812 extern void toggle_winconfig()
814 if (!world.winDB.active)
818 struct Win * w = get_win_by_id(world.winDB.active);
822 w->target_center = w->center;
823 memset(&w->center, 0, sizeof(struct yx_uint16));
826 else if (1 == w->view)
833 w->center = w->target_center;
838 extern void toggle_win_size_type(char axis)
840 struct Win * w = get_win_by_id(world.winDB.active);
843 w->target_height_type = (0 == w->target_height_type);
844 set_win_target_size(w);
847 w->target_width_type = ( 0 == w->target_width_type
848 && w->frame_size.x <= world.winDB.v_screen_size.x);
849 set_win_target_size(w);
854 extern void resize_active_win(char change)
856 if (world.winDB.active)
858 struct Win * w = get_win_by_id(world.winDB.active);
859 if (change == '-' && w->frame_size.y > 1)
863 else if (change == '_' && w->frame_size.y > 1)
867 else if ( change == '+'
868 && w->frame_size.y < world.winDB.v_screen_size.y - 1)
872 else if (change == '*' && w->frame_size.y < UINT16_MAX)
876 if ( 1 == w->target_width_type
877 && w->frame_size.x > world.winDB.v_screen_size.x)
879 w->target_width_type = 0;
881 set_win_target_size(w);
888 extern void shift_active_win(char dir)
890 uint8_t len_order = strlen(world.winDB.order);
893 char tmp[len_order + 1];
894 tmp[len_order] = '\0';
895 uint8_t pos = get_pos_in_order(world.winDB.active);
898 if (pos == len_order - 1)
900 memcpy(tmp + 1, world.winDB.order, len_order - 1);
901 tmp[0] = world.winDB.active;
902 memcpy(world.winDB.order, tmp, len_order + 1);
906 world.winDB.order[pos] = world.winDB.order[pos + 1];
907 world.winDB.order[pos + 1] = world.winDB.active;
914 memcpy(tmp, world.winDB.order + 1, len_order - 1);
915 tmp[len_order - 1] = world.winDB.active;
916 memcpy(world.winDB.order, tmp, len_order + 1);
920 world.winDB.order[pos] = world.winDB.order[pos - 1];
921 world.winDB.order[pos - 1] = world.winDB.active;
924 update_wins(get_win_by_id(world.winDB.order[0]));
930 extern void scroll_v_screen(char dir)
933 && world.winDB.v_screen_offset + world.winDB.v_screen_size.x + 1
934 < getmaxx(world.winDB.v_screen))
936 world.winDB.v_screen_offset++;
939 && world.winDB.v_screen_offset > 0)
941 world.winDB.v_screen_offset--;
947 extern void cycle_active_win(char dir)
949 uint8_t len_order = strlen(world.winDB.order);
952 uint8_t pos = get_pos_in_order(world.winDB.active);
955 world.winDB.active = world.winDB.order[pos + 1];
956 if ('\0' == world.winDB.active)
958 world.winDB.active = world.winDB.order[0];
964 world.winDB.active = world.winDB.order[pos - 1];
967 world.winDB.active = world.winDB.order[len_order - 1];