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> /* uint16_t, int16_t */
29 #include "../common/yx_uint16.h" /* yx_uint16 struct */
33 /* "Win" structs describe windows as frames located inside the virtual screen
34 * pad through which "winmaps" are visible, 2-dimensional maps of ncurses
35 * chtypes. If a winmap is bigger than its frame, scrolling hints will appear at
36 * the proper edges. Win structs are chained into a linked list of all the
37 * windows visible on the virtual screen and also contain pointers to what
38 * content is to be drawn inside the window, and by use of what method.
42 struct Win * prev; /* chain pointers; if 0, they mark the start or end */
43 struct Win * next; /* of the chain; if both are 0, Win is outside chain */
44 struct yx_uint16 framesize; /* window frame size to see winmap through */
45 struct yx_uint16 start; /* upper left corner of window in pad */
46 struct yx_uint16 center; /* winmap cell to center frame on if smaller*/
47 char * title; /* title to be used in window title bar */
48 void (* draw) (struct Win *); /* function that draws/updates the winmap */
49 chtype * winmap; /* sequence of cells, sorted into lines ... */
50 struct yx_uint16 winmapsize; /* ... with these geometry infos */
53 /* The window manager's parent struct WinMeta contains the virtual screen,
54 * relates it to the terminal screen and anchors the chain of visible windows.
58 struct yx_uint16 padsize; /* virtual screen size */
59 WINDOW * screen; /* ncurses' pointer to the terminal screen */
60 WINDOW * pad; /* ncurses pad of virtual screen */
61 struct Win * chain_start; /* first Win in chain; its _prev == 0 */
62 struct Win * chain_end; /* last Win in chain; its _next == 0 */
63 struct Win * active; /* Win highlighted/selected for manipulation */
64 uint16_t pad_offset; /* number of cells view is moved to the right */
69 /* Initialize world.wmeta and ncurses on terminal screen. All struct members
70 * initialize to 0 (.pad = NULL), except for .screen (= initscr()).
72 extern void init_wmeta_and_ncurses();
74 /* Initialize a Win child "wp" of "wmeta" to "title", "height" and "width" and
75 * appoint "func"() as its .draw. Initialize other members to 0.
77 * Pass 0 for "width" to make the window as wide as the terminal screen. Pass 0
78 * for "height" for the maximum allowed height: one cell smaller than that of
79 * the terminal screen. Pass negative values for either of them to make the
80 * window width/height so many cells smaller than what 0 would set. Values that
81 * that would reduce the window height or width to less than 1 cell according to
82 * the aforementioned rules set the height/width as if they were set to 0.
84 extern void init_win(struct Win ** wp, char * title, int16_t height,
85 int16_t width, void * func);
87 /* Free memory initianized Win structs. */
88 extern void free_win(struct Win * win);
90 /* Append/suspend window "w" to/from chain of visible windows below "wmeta".
91 * Appended windows will become active. Suspended active windows will move the
92 * active window selection to their successor in the window chain or, failing
93 * that, their predecessor, or, failing that, to 0 (no window active).
95 extern void append_win(struct Win * w);
96 extern void suspend_win(struct Win * w);
98 /* Apply scrolling offset "new_offset" to virtual screen if it is equal/greater
99 * 0 and does not push the view (further) beyond the virtual screen's border. If
100 * the view is already beyond the virtual screen's border due to it having
101 * shrunk after suspension of windows, only allow screen scrolling leftwards.
103 extern void reset_pad_offset(uint16_t new_offset);
105 /* Apply "size" to the active window if it provides a minimum size of 1x1 cells
106 * and is in height at least one cell smaller than the screen's vertical height
107 * (to provide space for the title bar). Does nothing if no window is active.
109 extern void resize_active_win(struct yx_uint16 size);
111 /* Cycle active window selection forwards ("dir" == "f") or backwards (any
112 * other "dir"). Wrap around in the windows chain if start / end of it is met.
113 * Does nothing if no window is active.
115 extern void cycle_active_win(char dir);
117 /* Move active window forwards ("dir" == "f") or backwards (any other "dir") in
118 * the window chain. Wrap around in the window chain if start / end of it is
119 * met. Does nothing if no window is active.
121 extern void shift_active_win(char dir);
123 /* Draw virtual screen and its windows. Add scroll hints where edges of terminal
124 * screen hit non-edges inside the virtual screen. Then update terminal screen.
126 extern void draw_all_wins();