1 /* src/client/windows.h
3 * This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
4 * or any later version. For details on its copyright, license, and warranties,
5 * see the file NOTICE in the root directory of the PlomRogue source package.
7 * A tiled window manager for the terminal.
9 * It provides a virtual screen that can be scrolled horizontally and may carry
10 * any number of windows to be appeared, disappeared, resized and moved around.
11 * They have borders and a title bar and are positioned automatically.
13 * Windows can be any width between 1 and 2^16 cells. The virtual screen grows
14 * with them as needed -- but only horizontally and only up to 2^16 cells. Their
15 * height is limited by the height of the terminal screen (maximum 2^16 cells).
17 * Windows' positioning can be influenced only indirectly: by resizing them, and
18 * by shifting their relative position inside the (currently invisible) chain
19 * that the window manager treats their plurality as. The first window goes into
20 * the top left corner of the virtual screen. Further windows are fitted as
21 * left-aligned as possible below their (chain-wise) closest predecessor that
22 * thrones over enough space to contain them and that is open to the right. If
23 * that fails, they're fitted up-right to the window with the rightmost border.
25 * TODO: Think up a more intuitive window positioning algorithm.
31 #include <ncurses.h> /* WINDOW, chtype */
32 #include <stdint.h> /* uint8_t, int16_t, uint16_t, uint32_t */
33 #include "keybindings.h" /* struct KeyBindingDB */
45 WINDOW * t_screen; /* ncurses' pointer to the terminal screen */
46 WINDOW * v_screen; /* virtual screen (ncurses pad) */
47 struct Win * wins; /* array of windows */
48 struct yx_uint16 v_screen_size; /* virtual screen size */
49 char * legal_ids; /* ids allowed to be used */
50 char * ids; /* all windows' ids, followed by \0 */
51 char * order; /* visible windows' id's order, followed by \0 */
52 uint16_t v_screen_offset; /* how many cells v_screen view moved rightwards*/
53 char active; /* id of window selected as active */
58 struct KeyBindingDB kb; /* window-specific keybindings */
59 char * title; /* title to be used in window title bar */
60 struct yx_uint16 target_center; /* saves .center when toggling .view */
61 struct yx_uint16 frame_size; /* size of window/frame to see winmap through*/
62 struct yx_uint16 start; /* upper left corner of window in v_screen */
63 struct yx_uint16 center; /* winnap cell to center frame on if < winmap */
64 struct yx_uint16 winmap_size; /* delimits .winmap, sorts it into lines */
65 chtype * winmap; /* window content in sequence of chtype's to write */
66 int16_t target_height; /* window size / .frame_size description in config */
67 int16_t target_width; /* file format, i.e. values <= 0 may be used */
68 char id; /* Win identifier; also maps to default window drawing function. */
69 uint8_t target_height_type; /* 0: read .height/.width as positive size; */
70 uint8_t target_width_type; /* 1: as negative diff to v_screen size */
71 uint8_t linebreak; /* linebreaking modes: 0: wide; 1: long; 2: compact */
72 uint8_t view; /* window view mode: 0: use .id- set default draw function */
73 }; /* 1/2: use one of the two config view draw function */
77 /* Get position of id "c" in world.winDB.order*/
78 extern uint8_t get_win_pos_in_order(char c);
80 /* Get Win after window identified by "c" or NULL if there is none. */
81 extern struct Win * get_win_after(char c);
83 /* Return yx offset to focus map of "mapsize" on "position" in "frame_size". */
84 extern uint16_t center_offset(uint16_t position,
85 uint32_t mapsize, uint32_t frame_size);
87 /* Get Win of "id". */
88 extern struct Win * get_win_by_id(char id);
90 /* Builds virtual sreen from .t_screen's size, fits win's sizes to them.*/
91 extern void make_v_screen_and_init_win_sizes();
93 /* Free all winDB data. */
94 extern void free_winDB();
96 /* The SIGWINCH handler winch_called() merely sets world.winch to 1. This info
97 * is used by io_loop() to call reset_windows_on_winch(), which adapts the
98 * currently loaded interface configuration to the new .t_screen size.
100 extern void winch_called();
101 extern void reset_windows_on_winch();
103 /* Draw .v_screen and its windows. Add scroll hints where edges of .t_screen hit
104 * .non-edges inside the virtual screen. Then update .t_screen.
106 extern void draw_all_wins();