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, uint32_t */
29 #include "../common/yx_uint16.h" /* yx_uint16 struct */
30 #include "keybindings.h" /* struct KeyBindingDB */
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 * legal_ids; /* ids allowed to be used */
41 char * ids; /* all windows' ids, followed by \0 */
42 char * order; /* visible windows' id's order, followed by \0 */
43 uint16_t v_screen_offset; /* how many cells v_screen view moved rightwards*/
44 char active; /* id of window selected as active */
49 struct KeyBindingDB kb; /* window-specific keybindings */
50 char * title; /* title to be used in window title bar */
51 struct yx_uint16 target_center; /* saves .center when toggling .view */
52 struct yx_uint16 frame_size; /* size of window/frame to see winmap through*/
53 struct yx_uint16 start; /* upper left corner of window in v_screen */
54 struct yx_uint16 center; /* winnap cell to center frame on if < winmap */
55 struct yx_uint16 winmap_size; /* delimits .winmap, sorts it into lines */
56 chtype * winmap; /* window content in sequence of chtype's to write */
57 int16_t target_height; /* window size / .frame_size description in config */
58 int16_t target_width; /* file format, i.e. values <= 0 may be used */
59 char id; /* Win identifier; also maps to default window drawing function. */
60 uint8_t target_height_type; /* 0: read .height/.width as positive size; */
61 uint8_t target_width_type; /* 1: as negative diff to v_screen size */
62 uint8_t linebreak; /* linebreaking modes: 0: wide; 1: long; 2: compact */
63 uint8_t view; /* window view mode: 0: use .id- set default draw function */
64 }; /* 1/2: use one of the two config view draw function */
68 /* Get position of id "c" in world.winDB.order*/
69 extern uint8_t get_win_pos_in_order(char c);
71 /* Get Win after window identified by "c" or NULL if there is none. */
72 extern struct Win * get_win_after(char c);
74 /* Return yx offset to focus map of "mapsize" on "position" in "frame_size". */
75 extern uint16_t center_offset(uint16_t position,
76 uint32_t mapsize, uint32_t frame_size);
78 /* Get Win of "id". */
79 extern struct Win * get_win_by_id(char id);
81 /* Builds virtual sreen from .t_screen's size, fits win's sizes to them.*/
82 extern void make_v_screen_and_init_win_sizes();
84 /* Free all winDB data. */
85 extern void free_winDB();
87 /* The SIGWINCH handler winch_called() merely sets world.winch to 1. This info
88 * is used by io_loop() to call reset_windows_on_winch(), which adapts the
89 * currently loaded interface configuration to the new .t_screen size.
91 extern void winch_called();
92 extern void reset_windows_on_winch();
94 /* Draw .v_screen and its windows. Add scroll hints where edges of .t_screen hit
95 * .non-edges inside the virtual screen. Then update .t_screen.
97 extern void draw_all_wins();