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 "world.h" /* global world */
34 /* Get position of id "c" in world.windb.order or return Win before/after (or
35 * NULL if there is no window before/after).
37 static uint8_t get_pos_in_order(char c);
38 static struct Win * get_win_after(char c);
39 static struct Win * get_win_before(char c);
41 /* Calculate "id"'s window's size from v_screen size and .target_(height/width).
42 * A .target_width == 0 makes the window as wide as .t_screen. .target_height ==
43 * 0 sets the maximum allowed height: one cell smaller than that of .v_screen.
44 * Negative values make width/height so many cells smaller than what 0 would
45 * set. Values that would reduce the window height or width to less than 1 cell
46 * according to the aforementioned rules set the height/width as if they were 0.
48 static void init_win_size_from_winconf_and_v_screen_size(char id);
50 /* Get (Win->draw) function identified by "c"; NULL if c not mapped to one.
51 * match_func() is just a little helper to it.
53 static uint8_t match_func(char c, void (** f) (), char c_m, void (* f_m) ());
54 static void * get_drawfunc_by_char(char c);
56 /* Write "win"'s size back to .target_(height/width) as per .target_*_type. */
57 static void set_win_target_size(struct Win * win);
59 /* Iterate over chars of world.windb.ids array / string. Restart after \0.*/
60 static char get_next_win_id();
62 /* Make .v_screen just wide enough to contain all visible windows. */
63 static void refit_v_screen();
65 /* Update geometry (sizes, positions) of window "w" and its successors in the
66 * window chain. Use place_win() for the positioning algorithm.
68 static void update_wins(struct Win * w);
69 static void place_win(struct Win * w);
71 /* Draw scroll hint (a line saying that there are "dist" more elements of "unit"
72 * further into the direction symbolized by "dir") into .v_screen, onto an
73 * appropriate edge of a window or .v_screen; the left/right edge if "dir" is
74 * "<"/">", or the top/bottom edge if it is "^"/"v". Use "start" as the start
75 * coordinate of the frame that is to contain the scroll hints. winscroll_hint()
76 * is a wrapper that uses the border of window "w" as this frame.
78 static void scroll_hint(struct yx_uint16 fsize, char dir, uint16_t dist,
79 char * unit, struct yx_uint16 start);
80 static void winscroll_hint(struct Win * w, char dir, uint16_t dist);
82 /* draw_win_borderlines() draws vertical/horizontal borders of window "w" sans
83 * corners into .v_screen. It draws the top border line as the windows' title
84 * bar (highlighted if the window is selected as active). It is called
85 * recursively by draw_wins_borderlines() on all windows from "w" on.
86 * draw_wins_bordercorners() draws the border corners of "w" and its successors.
88 static void draw_win_borderlines(struct Win * w);
89 static void draw_wins_borderlines(struct Win * w);
90 static void draw_wins_bordercorners(struct Win * w);
92 /* Draw contents of all windows in window chain from window "w" onwards. */
93 static void draw_wins(struct Win * w);
95 /* Append/suspend window "w" to/from chain of visible windows. Appended windows
96 * will become active. Suspended active windows will move the active window
97 * selection to their successor in the window chain or, failing that, their
98 * predecessor, or, failing that, to 0 (no window active).
100 static void append_win(struct Win * w);
101 static void suspend_win(struct Win * w);
103 /* Copy Win content pointed to by "win" into appendend world.windb.wins area. */
104 static void add_win_to_windb(struct Win * win);
108 static uint8_t get_pos_in_order(char c)
111 for (i = 0; c != world.windb.order[i]; i++);
117 static struct Win * get_win_after(char c)
119 return get_win_by_id(world.windb.order[get_pos_in_order(c) + 1]);
124 static struct Win * get_win_before(char c)
126 uint8_t i = get_pos_in_order(c);
129 return get_win_by_id(world.windb.order[i - 1]);
136 static void init_win_size_from_winconf_and_v_screen_size(char id)
138 struct Win * w = get_win_by_id(id);
139 w->frame_size.y = world.windb.v_screen_size.y - 1;
140 if ( 0 < w->target_height
141 && w->target_height <= world.windb.v_screen_size.y - 1)
143 w->frame_size.y = w->target_height;
145 else if ( 0 > w->target_height
146 && world.windb.v_screen_size.y + (w->target_height - 1) > 0)
148 w->frame_size.y = world.windb.v_screen_size.y + (w->target_height - 1);
150 w->frame_size.x = world.windb.v_screen_size.x;
151 if (0 < w->target_width)
153 w->frame_size.x = w->target_width;
155 else if ( 0 > w->target_width
156 && world.windb.v_screen_size.x + w->target_width > 0)
158 w->frame_size.x = world.windb.v_screen_size.x + w->target_width;
164 static uint8_t match_func(char c, void (** f) (), char c_m, void (* f_m) ())
176 static void * get_drawfunc_by_char(char c)
178 void (* f) (struct Win *) = NULL;
179 if ( match_func(c, &f, 'c', draw_win_inventory)
180 || match_func(c, &f, 'i', draw_win_info)
181 || match_func(c, &f, 'l', draw_win_log)
182 || match_func(c, &f, 'k', draw_win_available_keybindings)
183 || match_func(c, &f, 'm', draw_win_map)
184 || match_func(c, &f, '0', draw_win_keybindings_global)
185 || match_func(c, &f, '1', draw_win_keybindings_winconf_geometry)
186 || match_func(c, &f, '2', draw_win_keybindings_winconf_keybindings));
192 static void set_win_target_size(struct Win * wcp)
194 if (0 == wcp->target_height_type)
196 wcp->target_height = wcp->frame_size.y;
198 else if (1 == wcp->target_height_type)
200 wcp->target_height = wcp->frame_size.y - world.windb.v_screen_size.y +1;
202 if (0 == wcp->target_width_type)
204 wcp->target_width = wcp->frame_size.x;
206 else if (1 == wcp->target_width_type)
208 wcp->target_width = wcp->frame_size.x - world.windb.v_screen_size.x;
214 static char get_next_win_id()
216 static uint8_t i = 0;
217 char c = world.windb.ids[i];
229 static void refit_v_screen()
231 /* Determine rightmost window column. */
232 uint32_t lastwcol = 0;
233 struct Win * wp = get_win_by_id(world.windb.order[0]);
236 if ((uint32_t) wp->start.x + (uint32_t) wp->frame_size.x > lastwcol + 1)
238 lastwcol = (uint32_t) wp->start.x + (uint32_t) wp->frame_size.x - 1;
240 wp = get_win_after(wp->id);
243 /* Only resize .v_screen if the rightmost window column has changed. */
244 char * err_s = "refit_v_screen() grows virtual screen beyond legal sizes.";
245 char * err_m = "refit_v_screen() triggers memory alloc error in wresize().";
246 if (getmaxx(world.windb.v_screen) + 1 != lastwcol)
248 uint8_t t = (lastwcol + 2 > UINT16_MAX);
250 t = wresize(world.windb.v_screen, getmaxy(world.windb.v_screen),
258 static void update_wins(struct Win * w)
262 struct Win * next = get_win_after(w->id);
271 static void place_win(struct Win * w)
273 /* If w is first window, it goes into the top left corner. */
275 w->start.y = 1; /* Leave space for title bar. */
276 struct Win * w_prev = get_win_before(w->id);
280 /* If not, fit w's top left to top right of last top predecessor. */
281 struct Win * w_top = w_prev;
284 w_top = get_win_before(w_top->id));
285 w->start.x = w_top->start.x + w_top->frame_size.x + 1;
287 /* Fit w's top left to bottom left of its ->prev if enough space. */
288 uint16_t w_prev_maxy = w_prev->start.y + w_prev->frame_size.y;
289 if ( w->frame_size.x <= w_prev->frame_size.x
290 && w->frame_size.y < world.windb.v_screen_size.y - w_prev_maxy)
292 w->start.x = w_prev->start.x;
293 w->start.y = w_prev_maxy + 1;
297 /* Failing that, try to fit w' top left to the top right of the last
298 * predecessor w_test 1) not followed by windows with a left corner
299 * further rightwards than its own 2) with enough space rightwards for w
300 * until the bottom right of w_thr directly throning over it 3) and with
301 * this same space extending far enough to the bottom for fitting in w.
303 struct Win * w_test = w_prev;
305 while (w_test != w_top)
307 for (w_thr = get_win_before(w_test->id);
308 w_test->start.y <= w_thr->start.y;
309 w_thr = get_win_before(w_thr->id));
310 uint16_t w_thr_bottom = w_thr->start.y + w_thr->frame_size.y;
311 uint16_t free_width = (w_thr->start.x + w_thr->frame_size.x)
312 - (w_test->start.x + w_test->frame_size.x);
313 if ( w->frame_size.y < world.windb.v_screen_size.y - w_thr_bottom
314 && w->frame_size.x < free_width)
316 w->start.x = w_test->start.x + w_test->frame_size.x + 1;
317 w->start.y = w_thr_bottom + 1;
327 static void scroll_hint(struct yx_uint16 fsize, char dir, uint16_t dist,
328 char * unit, struct yx_uint16 start)
330 /* Decide on alignment (vertical/horizontal?), thereby hint text space. */
331 char * more = "more";
332 uint16_t dsc_space = fsize.x;
333 if ('<' == dir || '>' == dir)
336 } /* vv-- 10 = max strlen for uint16_t */
337 char scrolldsc[1 + strlen(more) + 1 + 10 + 1 + strlen(unit) + 1 + 1];
338 sprintf(scrolldsc, " %d %s %s ", dist, more, unit);
340 /* Decide on offset of the description text inside the scroll hint line. */
341 uint16_t dsc_offset = 1;
342 if (dsc_space > strlen(scrolldsc) + 1)
344 dsc_offset = (dsc_space - strlen(scrolldsc)) / 2;
347 /* Draw scroll hint line as dir symbols bracketing description text. */
348 uint16_t draw_offset = 0;
351 draw_offset = fsize.x - 1;
355 draw_offset = fsize.y - 1;
358 for (; q < dsc_space; q++)
360 chtype c = dir | A_REVERSE;
361 if (q >= dsc_offset && q < strlen(scrolldsc) + dsc_offset)
363 c = scrolldsc[q - dsc_offset] | A_REVERSE;
365 if ('<' == dir || '>' == dir)
367 mvwaddch(world.windb.v_screen, start.y+q, start.x+draw_offset, c);
370 mvwaddch(world.windb.v_screen, start.y + draw_offset, start.x + q, c);
376 static void winscroll_hint(struct Win * w, char dir, uint16_t dist)
378 char * unit = "lines";
379 if ('<' == dir || '>' == dir)
383 struct yx_uint16 start = w->start;
384 scroll_hint(w->frame_size, dir, dist, unit, start);
389 static void draw_win_borderlines(struct Win * w)
391 /* Draw vertical and horizontal border lines. */
393 for (y = w->start.y; y <= w->start.y + w->frame_size.y; y++)
395 mvwaddch(world.windb.v_screen, y, w->start.x - 1, '|');
396 mvwaddch(world.windb.v_screen, y, w->start.x + w->frame_size.x, '|');
398 for (x = w->start.x; x <= w->start.x + w->frame_size.x; x++)
400 mvwaddch(world.windb.v_screen, w->start.y - 1, x, '-');
401 mvwaddch(world.windb.v_screen, w->start.y + w->frame_size.y, x, '-');
404 /* Draw as much as possible of the title into center of top border line. */
405 uint8_t min_title_length_visible = 3;/* min. 1 char +2 padding/decoration*/
406 if (w->frame_size.x >= min_title_length_visible)
409 if (w->frame_size.x > strlen(w->title) + 2)
411 offset = (w->frame_size.x - (strlen(w->title) + 2)) / 2;
412 } /* +2 is for padding/decoration */
413 uint16_t length_visible = strnlen(w->title, w->frame_size.x - 2);
414 char title[length_visible + 3];
415 char decoration = ' ';
416 if (w->id == world.windb.active)
420 memcpy(title + 1, w->title, length_visible);
421 title[0] = title[length_visible + 1] = decoration;
422 title[length_visible + 2] = '\0';
423 mvwaddstr(world.windb.v_screen, w->start.y-1, w->start.x+offset, title);
429 static void draw_wins_borderlines(struct Win * w)
431 draw_win_borderlines(w);
432 struct Win * next = get_win_after(w->id);
435 draw_wins_borderlines(next);
441 static void draw_wins_bordercorners(struct Win * w)
443 mvwaddch(world.windb.v_screen,
444 w->start.y - 1, w->start.x - 1, '+');
445 mvwaddch(world.windb.v_screen,
446 w->start.y - 1, w->start.x + w->frame_size.x, '+');
447 mvwaddch(world.windb.v_screen,
448 w->start.y + w->frame_size.y, w->start.x - 1, '+');
449 mvwaddch(world.windb.v_screen, w->start.y + w->frame_size.y,
450 w->start.x + w->frame_size.x, '+');
451 struct Win * next = get_win_after(w->id);
454 draw_wins_bordercorners(next);
460 static void draw_wins(struct Win * w)
462 void (* drawfunc) (struct Win *) = get_drawfunc_by_char(w->id);
465 drawfunc = draw_winconf_geometry;
467 else if (2 == w->view)
469 drawfunc = draw_winconf_keybindings;
472 uint16_t size_y = w->winmap_size.y;
473 uint16_t size_x = w->winmap_size.x;
474 uint16_t offset_y = center_offset(w->center.y, size_y, w->frame_size.y);
475 uint16_t offset_x = center_offset(w->center.x, size_x, w->frame_size.x);
477 for (y = offset_y; y < w->frame_size.y + offset_y && y < size_y; y++)
479 for (x = offset_x; x < w->frame_size.x + offset_x && x < size_x; x++)
481 chtype ch = w->winmap[(y * w->winmap_size.x) + x];
482 mvwaddch(world.windb.v_screen, w->start.y + (y - offset_y),
483 w->start.x + (x - offset_x), ch);
486 free(w->winmap); /* NULL so draw_wins.c's try_resize_winmap() may always */
487 w->winmap = NULL;/* free() it before (re-)allocation, even the first time.*/
488 memset(&w->winmap_size, 0, sizeof(struct yx_uint16));
491 winscroll_hint(w, '^', offset_y + 1);
493 if (size_y > offset_y + w->frame_size.y)
495 winscroll_hint(w, 'v', size_y - ((offset_y + w->frame_size.y) - 1));
499 winscroll_hint(w, '<', offset_x + 1);
501 if (size_x > offset_x + w->frame_size.x)
503 winscroll_hint(w, '>', size_x - ((offset_x + w->frame_size.x) - 1));
505 struct Win * next = get_win_after(w->id);
508 return draw_wins(next);
514 static void append_win(struct Win * w)
516 char * f_name = "append_win()";
517 uint8_t old_size = strlen(world.windb.order) + 1;
518 char * new_order = try_malloc(old_size + 1, f_name);
519 memcpy(new_order, world.windb.order, old_size - 1);
520 new_order[old_size - 1] = w->id;
521 new_order[old_size] = '\0';
522 free(world.windb.order);
523 world.windb.order = new_order;
524 world.windb.active = w->id;
530 static void suspend_win(struct Win * w)
532 char * f_name = "suspend_win()";
533 uint8_t new_size = strlen(world.windb.order);
534 char * new_order = try_malloc(new_size, f_name);
535 uint8_t i = get_pos_in_order(w->id);
536 char next_char = world.windb.order[i + 1];
537 world.windb.order[i] = '\0';
538 char * second_part = &world.windb.order[i + 1];
539 sprintf(new_order, "%s%s", world.windb.order, second_part);
540 free(world.windb.order);
541 world.windb.order = new_order;
542 world.windb.active = world.windb.order[i];
543 if (!world.windb.order[i] && 0 < i)
545 world.windb.active = world.windb.order[i - 1];
547 if (world.windb.order[i])
549 update_wins(get_win_by_id(next_char)); /* Already calls */
550 return; /* refit_v_screen(), so leave. */
557 static void add_win_to_windb(struct Win * win)
559 char * f_name = "add_win_to_windb()";
562 uint8_t old_ids_size = strlen(world.windb.ids);
563 char * new_ids = try_malloc(old_ids_size + 1 + 1, f_name);
564 sprintf(new_ids, "%s%c", world.windb.ids, win->id);
565 free(world.windb.ids);
566 world.windb.ids = new_ids;
567 uint16_t old_wins_size = old_ids_size * sizeof(struct Win);
568 uint16_t new_wins_size = old_wins_size + sizeof(struct Win);
569 struct Win * new_wins = try_malloc(new_wins_size, f_name);
570 memcpy(new_wins, world.windb.wins, old_wins_size);
571 new_wins[old_ids_size] = *win;
572 free(world.windb.wins);
573 world.windb.wins = new_wins;
576 world.windb.ids = try_malloc(2, f_name);
577 sprintf(world.windb.ids, "%c", win->id);
578 world.windb.wins = try_malloc(sizeof(struct Win), f_name);
579 world.windb.wins[0] = *win;
584 extern uint16_t center_offset(uint16_t position, uint16_t mapsize,
588 if (mapsize > frame_size)
590 if (position > frame_size / 2)
592 if (position < mapsize - (frame_size / 2))
594 offset = position - (frame_size / 2);
598 offset = mapsize - frame_size;
607 extern struct Win * get_win_by_id(char id)
610 while ('\0' != world.windb.ids[i])
612 if (id == world.windb.ids[i])
614 return &world.windb.wins[i];
623 extern uint8_t read_winconf_from_file(char * line, uint32_t linemax,
626 char * f_name = "read_winconf_from_file()";
627 int test = try_fgetc(file, f_name);
633 memset(&win, 0, sizeof(struct Win));
634 win.id = (char) test;
635 try_fgetc(file, f_name);
636 try_fgets(line, linemax + 1, file, f_name);
637 win.title = try_malloc(strlen(line), f_name);
638 memcpy(win.title, line, strlen(line) - 1); /* Eliminate newline char */
639 win.title[strlen(line) - 1] = '\0'; /* char at end of string. */
640 try_fgets(line, linemax + 1, file, f_name);
641 win.target_height = atoi(line);
642 win.target_height_type = (0 >= win.target_height);
643 try_fgets(line, linemax + 1, file, f_name);
644 win.target_width = atoi(line);
645 win.target_width_type = (0 >= win.target_width);
646 read_keybindings_from_file(line, linemax, file, &win.kb);
647 add_win_to_windb(&win);
653 extern void write_winconf_of_id_to_file(FILE * file, char c, char * delim)
655 char * f_name = "write_winconf_of_id_to_file()";
656 struct Win * wc = get_win_by_id(c);
657 uint8_t size = strlen(wc->title) + 2;
658 if (size < 7) /* Ensure that at least 5 + 2 char fit into line so that */
659 { /* the digit representation of any uint16_t may be stored. */
663 sprintf(line, "%c\n", wc->id);
664 try_fwrite(line, sizeof(char), strlen(line), file, f_name);
665 sprintf(line, "%s\n", wc->title);
666 try_fwrite(line, sizeof(char), strlen(line), file, f_name);
667 sprintf(line, "%d\n", wc->target_height);
668 try_fwrite(line, sizeof(char), strlen(line), file, f_name);
669 sprintf(line, "%d\n", wc->target_width);
670 try_fwrite(line, sizeof(char), strlen(line), file, f_name);
671 write_keybindings_to_file(file, &wc->kb, delim);
676 extern void read_order_wins_visible_active(char * line, uint32_t linemax,
679 char * f_name = "read_order_wins_visible_active()";
680 char win_order[linemax + 1];
681 try_fgets(win_order, linemax + 1, file, f_name);
682 win_order[strlen(win_order) - 1] = '\0';
683 world.windb.order = try_malloc(strlen(win_order) + 1, f_name);
684 sprintf(world.windb.order, "%s", win_order);
685 int char_or_eof = try_fgetc(file, f_name);
686 char * err_eof = "fgetc() unexpectedly hitting EOF";
687 exit_trouble(EOF == char_or_eof, f_name, err_eof);
688 world.windb.active = (uint8_t) char_or_eof;
689 exit_trouble(EOF == try_fgetc(file, f_name), f_name, err_eof);
690 try_fgets(line, linemax + 1, file, f_name);
695 extern void write_order_wins_visible_active(FILE * file, char * delim)
697 char * f_name = "write_order_wins_visible_active()";
698 try_fwrite(world.windb.order, strlen(world.windb.order), 1, file, f_name);
699 try_fputc('\n', file, f_name);
700 try_fputc(world.windb.active, file, f_name);
701 try_fputc('\n', file, f_name);
702 try_fwrite(delim, strlen(delim), 1, file, f_name);
707 extern void make_v_screen_and_init_win_sizes()
709 char * f_name = "make_v_screen_and_init_win_sizes()";
710 char * err_s = "creating an illegaly large virtual screen";
711 char * err_m = "triggering a memory allocation error via newpad()";
712 uint32_t maxy_test = getmaxy(world.windb.t_screen);
713 uint32_t maxx_test = getmaxx(world.windb.t_screen);
714 exit_trouble(maxy_test>UINT16_MAX || maxx_test>UINT16_MAX, f_name, err_s);
715 world.windb.v_screen_size.y = maxy_test;
716 world.windb.v_screen_size.x = maxx_test;
717 world.windb.v_screen = newpad(world.windb.v_screen_size.y, 1);
718 exit_trouble(NULL == world.windb.v_screen, f_name, err_m);
720 while (0 != (id = get_next_win_id()))
722 init_win_size_from_winconf_and_v_screen_size(id);
728 extern void free_windb()
731 while (0 != (id = get_next_win_id()))
733 struct Win * wc = get_win_by_id(id);
735 free_keybindings(wc->kb.kbs);
737 free(world.windb.ids); /* NULL this too since add_win_to_windb() checks */
738 world.windb.ids = NULL; /* for it to detect its first post-DB-purge round.*/
739 free(world.windb.wins);
740 free(world.windb.order);
745 extern void winch_called(int signal)
752 extern void reset_windows_on_winch()
754 endwin(); /* "[S]tandard way" to recalibrate ncurses post SIGWINCH, says */
755 refresh(); /* <http://invisible-island.net/ncurses/ncurses-intro.html>. */
756 char tmp_order[strlen(world.windb.order) + 1];
757 sprintf(tmp_order, "%s", world.windb.order);
759 char tmp_active = world.windb.active;
760 for (i = 0; i < strlen(tmp_order); toggle_window(tmp_order[i]), i++);
761 delwin(world.windb.v_screen);
762 make_v_screen_and_init_win_sizes();
763 for (i = 0; i < strlen(tmp_order); toggle_window(tmp_order[i]), i++);
764 world.windb.active = tmp_active;
769 extern void draw_all_wins()
771 /* Empty everything before filling it a-new. */
773 wnoutrefresh(world.windb.t_screen);
774 werase(world.windb.v_screen);
775 if (world.windb.active)
778 /* Draw borders, wins. Order matters: corners should overwrite lines. */
779 draw_wins_borderlines(get_win_by_id(world.windb.order[0]));
780 draw_wins_bordercorners(get_win_by_id(world.windb.order[0]));
781 draw_wins(get_win_by_id(world.windb.order[0]));
783 /* Draw .v_screen scroll hints. */
784 struct yx_uint16 start;
786 start.x = world.windb.v_screen_offset;
787 char * cols_string = "columns";
788 if (world.windb.v_screen_offset > 0)
790 scroll_hint(world.windb.v_screen_size, '<',
791 world.windb.v_screen_offset + 1, cols_string, start);
793 uint16_t size_x = getmaxx(world.windb.v_screen);
794 uint16_t right_edge = world.windb.v_screen_offset
795 + world.windb.v_screen_size.x;
796 if (right_edge < size_x - 1)
798 scroll_hint(world.windb.v_screen_size, '>',
799 size_x - right_edge, cols_string, start);
802 /* Put .v_screen segment to be shown on .t_screen to .t_screen buffer.*/
803 pnoutrefresh(world.windb.v_screen, 0, world.windb.v_screen_offset, 0, 0,
804 world.windb.v_screen_size.y,
805 world.windb.v_screen_size.x - 1);
808 /* Only at the end write accumulated changes to .t_screen. */
814 extern void toggle_window(char id)
816 struct Win * win = get_win_by_id(id);
817 if (NULL == strchr(world.windb.order, id))
827 extern void toggle_winconfig()
829 if (!world.windb.active)
833 struct Win * w = get_win_by_id(world.windb.active);
837 w->target_center = w->center;
838 memset(&w->center, 0, sizeof(struct yx_uint16));
841 else if (1 == w->view)
848 w->center = w->target_center;
853 extern void toggle_win_size_type(char axis)
855 struct Win * w = get_win_by_id(world.windb.active);
858 w->target_height_type = (0 == w->target_height_type);
859 set_win_target_size(w);
862 w->target_width_type = ( 0 == w->target_width_type
863 && w->frame_size.x <= world.windb.v_screen_size.x);
864 set_win_target_size(w);
869 extern void resize_active_win(char change)
871 if (world.windb.active)
873 struct Win * w = get_win_by_id(world.windb.active);
874 if (change == '-' && w->frame_size.y > 1)
878 else if (change == '_' && w->frame_size.y > 1)
882 else if ( change == '+'
883 && w->frame_size.y < world.windb.v_screen_size.y - 1)
887 else if (change == '*' && w->frame_size.y < UINT16_MAX)
891 if ( 1 == w->target_width_type
892 && w->frame_size.x > world.windb.v_screen_size.x)
894 w->target_width_type = 0;
896 set_win_target_size(w);
903 extern void shift_active_win(char dir)
905 uint8_t len_order = strlen(world.windb.order);
908 char tmp[len_order + 1];
909 tmp[len_order] = '\0';
910 uint8_t pos = get_pos_in_order(world.windb.active);
913 if (pos == len_order - 1)
915 memcpy(tmp + 1, world.windb.order, len_order - 1);
916 tmp[0] = world.windb.active;
917 memcpy(world.windb.order, tmp, len_order + 1);
921 world.windb.order[pos] = world.windb.order[pos + 1];
922 world.windb.order[pos + 1] = world.windb.active;
929 memcpy(tmp, world.windb.order + 1, len_order - 1);
930 tmp[len_order - 1] = world.windb.active;
931 memcpy(world.windb.order, tmp, len_order + 1);
935 world.windb.order[pos] = world.windb.order[pos - 1];
936 world.windb.order[pos - 1] = world.windb.active;
939 update_wins(get_win_by_id(world.windb.order[0]));
945 extern void scroll_v_screen(char dir)
948 && world.windb.v_screen_offset + world.windb.v_screen_size.x + 1
949 < getmaxx(world.windb.v_screen))
951 world.windb.v_screen_offset++;
954 && world.windb.v_screen_offset > 0)
956 world.windb.v_screen_offset--;
962 extern void cycle_active_win(char dir)
964 uint8_t len_order = strlen(world.windb.order);
967 uint8_t pos = get_pos_in_order(world.windb.active);
970 world.windb.active = world.windb.order[pos + 1];
971 if ('\0' == world.windb.active)
973 world.windb.active = world.windb.order[0];
979 world.windb.active = world.windb.order[pos - 1];
982 world.windb.active = world.windb.order[len_order - 1];