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