1 /* src/client/windows.h
3 * A tiled window manager for the terminal.
5 * It provides a virtual screen that can be scrolled horizontally and may carry
6 * any number of windows to be appeared, disappeared, resized and moved around.
7 * They have borders and a title bar and are positioned automatically.
9 * Windows can be any width between 1 and 2^16 cells. The virtual screen grows
10 * with them as needed -- but only horizontally and only up to 2^16 cells. Their
11 * height is limited by the height of the terminal screen (maximum 2^16 cells).
13 * Windows' positioning can be influenced only indirectly: by resizing them, and
14 * by shifting their relative position inside the (currently invisible) chain
15 * that the window manager treats their plurality as. The first window goes into
16 * the top left corner of the virtual screen. Further windows are fitted as
17 * left-aligned as possible below their (chain-wise) closest predecessor that
18 * thrones over enough space to contain them and that is open to the right. If
19 * that fails, they're fitted up-right to the window with the rightmost border.
21 * TODO: Think up a more intuitive window positioning algorithm.
27 #include <ncurses.h> /* WINDOW, chtype */
28 #include <stdint.h> /* uint8_t, int16_t, uint16_t */
29 #include "keybindings.h" /* struct KeyBindingDB */
30 #include "../common/yx_uint16.h" /* yx_uint16 struct */
36 WINDOW * t_screen; /* ncurses' pointer to the terminal screen */
37 WINDOW * v_screen; /* virtual screen (ncurses pad) */
38 struct Win * wins; /* array of windows */
39 struct yx_uint16 v_screen_size; /* virtual screen size */
40 char * ids; /* all windows' ids, followed by \0 */
41 char * order; /* visible windows' id's order, followed by \0 */
42 uint16_t v_screen_offset; /* how many cells v_screen view moved rightwards*/
43 char active; /* id of window selected as active */
48 struct KeyBindingDB kb; /* window-specific keybindings */
49 char * title; /* title to be used in window title bar */
50 struct yx_uint16 target_center; /* saves .center when toggling .view */
51 struct yx_uint16 frame_size; /* size of window/frame to see winmap through*/
52 struct yx_uint16 start; /* upper left corner of window in v_screen */
53 struct yx_uint16 center; /* winnap cell to center frame on if < winmap */
54 struct yx_uint16 winmap_size; /* delimits .winmap, sorts it into lines */
55 chtype * winmap; /* window content in sequence of chtype's to write */
56 int16_t target_height; /* window size / .frame_size description in config */
57 int16_t target_width; /* file format, i.e. values <= 0 may be used */
58 char id; /* Win identifier; also maps to default window drawing function. */
59 uint8_t target_height_type; /* 0: read .height/.width as positive size; */
60 uint8_t target_width_type; /* 1: as negative diff to v_screen size */
61 uint8_t view; /* winde view mode: 0: use default draw function set by .id */
62 }; /* 1/2: use one of the two config view draw function */
66 /* Return yx offset to focus map of "mapsize" on "position" in "frame_size". */
67 extern uint16_t center_offset(uint16_t position,
68 uint16_t mapsize, uint16_t frame_size);
70 /* Get Win of "id". */
71 extern struct Win * get_win_by_id(char id);
73 /* Read/write individual Win (identified by "c") and world.windb.order /
74 * world.windb.active from/to "file". Follow writing with "delim" delimiter.
75 * Use "line" and "linemax" as expected by try_fgets().
77 extern uint8_t read_winconf_from_file(char * line, uint32_t linemax,
79 extern void write_winconf_of_id_to_file(FILE * file, char c, char * delim);
80 extern void read_order_wins_visible_active(char * line, uint32_t linemax,
82 extern void write_order_wins_visible_active(FILE * file, char * delim);
84 /* Builds virtual sreen from .t_screen's size, fits win's sizes to them.*/
85 extern void make_v_screen_and_init_win_sizes();
87 /* Free all WinDB data. */
88 extern void free_windb();
90 /* The SIGWINCH handler winch_called() merely sets world.winch to 1. This info
91 * is used by io_loop() to call reset_windows_on_winch(), which adapts the
92 * currently loaded interface configuration to the new .t_screen size.
94 extern void winch_called();
95 extern void reset_windows_on_winch();
97 /* Draw .v_screen and its windows. Add scroll hints where edges of .t_screen hit
98 * .non-edges inside the virtual screen. Then update .t_screen.
100 extern void draw_all_wins();
102 /* Toggle display of a window of "id". */
103 extern void toggle_window(char id);
105 /* Toggle "window configuration" view for active window. Sets sensible .center
106 * values for each configuration view (for winconf_geometry: y=0, x=0; for
107 * winconf_keys: x=0 (y is set by draw_winconf_keybindings()); stores default
108 * view's .center in .target_center to return to it when toggling back.
110 extern void toggle_winconfig();
112 /* Toggle active window's .target_(height/width)_type ("axis" = "y": height;
113 * else: width). Don't toggle to .target_width_type of 1 (saving the width as a
114 * diff to the .t_screen's width) if window's width is larger than .t_screen's
115 * width, for such width is better saved directly with .target_width_type of 0.
117 extern void toggle_win_size_type(char axis);
119 /* Grow or shrink active window horizontally ("change" = "*"/"_") or vertically
120 * ("change" = "+"/"-") if the new size was at least 1x1, the height at least
121 * one cell smaller than .v_screen's vertical hight (to provide space for the
122 * title bar) and the width max. (2^16) - 1 cells. If a new window width would
123 * surpass that of .t_screen, set active window's .target_width_type to 0.
125 extern void resize_active_win(char c);
127 /* Move active window forwards ("dir" == "f") or backwards (any other "dir") in
128 * window chain. Wrap around in the window chain if start / end of it is met.
130 extern void shift_active_win(char dir);
132 /* Sroll .v_screen one cell to the left if "dir" is "-" and .v_screen_offset is
133 * more than 1, or to the right if "dir" is "+" and .v_screen's right edge would
134 * not move (further, if suspension of windows has moved it to the left already)
135 * leftwards to .t_screen's right edge.
137 extern void scroll_v_screen(char dir);
139 /* Cycle active window selection forwards ("dir" == "f") or backwards (any
140 * other "dir"). Wrap around in the windows chain if start / end of it is met.
142 extern void cycle_active_win(char dir);