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 ncurses and world.wmeta on terminal screen. All struct members
70 * initialize to 0, except for .screen, the newly created virtual screen .pad
71 * and its .padsize (height: that of the terminal screen; width: 1 cell).
73 extern void init_win_meta();
75 /* Initialize a Win child "wp" of "wmeta" to "title", "height" and "width" and
76 * appoint "func"() as its .draw. Initialize other members to 0.
78 * Pass 0 for "width" to make the window as wide as the terminal screen. Pass 0
79 * for "height" for the maximum allowed height: one cell smaller than that of
80 * the terminal screen. Pass negative values for either of them to make the
81 * window width/height so many cells smaller than what 0 would set. Values that
82 * that would reduce the window height or width to less than 1 cell according to
83 * the aforementioned rules set the height/width as if they were set to 0.
85 extern void init_win(struct Win ** wp, char * title, int16_t height,
86 int16_t width, void * func);
88 /* Free memory initialized below world.wmeta and run endwin(). */
89 extern void free_winmeta_and_endwin();
91 /* Free memory initianized Win structs. */
92 extern void free_win(struct Win * win);
94 /* Append/suspend window "w" to/from chain of visible windows below "wmeta".
95 * Appended windows will become active. Suspended active windows will move the
96 * active window selection to their successor in the window chain or, failing
97 * that, their predecessor, or, failing that, to 0 (no window active).
99 extern void append_win(struct Win * w);
100 extern void suspend_win(struct Win * w);
102 /* Apply scrolling offset "new_offset" to virtual screen if it is equal/greater
103 * 0 and does not push the view (further) beyond the virtual screen's border. If
104 * the view is already beyond the virtual screen's border due to it having
105 * shrunk after suspension of windows, only allow screen scrolling leftwards.
107 extern void reset_pad_offset(uint16_t new_offset);
109 /* Apply "size" to the active window if it provides a minimum size of 1x1 cells
110 * and is in height at least one cell smaller than the screen's vertical height
111 * (to provide space for the title bar). Does nothing if no window is active.
113 extern void resize_active_win(struct yx_uint16 size);
115 /* Cycle active window selection forwards ("dir" == "f") or backwards (any
116 * other "dir"). Wrap around in the windows chain if start / end of it is met.
117 * Does nothing if no window is active.
119 extern void cycle_active_win(char dir);
121 /* Move active window forwards ("dir" == "f") or backwards (any other "dir") in
122 * the window chain. Wrap around in the window chain if start / end of it is
123 * met. Does nothing if no window is active.
125 extern void shift_active_win(char dir);
127 /* Draw virtual screen and its windows. Add scroll hints where edges of terminal
128 * screen hit non-edges inside the virtual screen. Then update terminal screen.
130 extern void draw_all_wins();