home · contact · privacy
Fixed bug that crashed the client on terminal resizing due to wrongly expecting there...
[plomrogue] / src / client / wincontrol.h
1 /* src/client/wincontrol.h
2  *
3  * Routines that build on top of the windows library to provide a simple window
4  * management API to the game. Also helps managing window-specific keybindings.
5  */
6
7 #ifndef WINCONTROL_H
8 #define WINCONTROL_H
9
10 #include <stdint.h> /* uint8_t, int16_t */
11 #include "keybindings.h" /* struct KeyBindingDB */
12 #include "../common/yx_uint16.h" /* yx_uint16 struct */
13 struct Win;
14
15
16
17 struct WinConfDB
18 {
19     struct WinConf * winconfs;
20     char * ids;
21     char * order; /* order of visible windows (identified by IDs) */
22     char active; /* id of window selected as active */
23 };
24
25 /* Window's configuration (like geometry, keybindings) and the Win itself. */
26 struct WinConf
27 {
28     struct Win * win;    /* Window / Win struct configured by this WinConf. */
29     struct KeyBindingDB kb; /* Window-specific keybindings. */
30     struct yx_uint16 center; /* Designated Win.center. */
31     int16_t height;      /* Designated height to pass to init_win(). */
32     int16_t width;       /* Designated width to pass to init_win(). */
33     uint8_t height_type; /* 0: read .height/.width as size in positive cells; */
34     uint8_t width_type;  /* 1: as negative diff in cells to the screen size.  */
35     uint8_t view; /* 0: use .draw as Win.draw; 1/2: use draw_winconf()_(1/2). */
36     char id; /* Identifier of WinConf, also identifies Win.draw function. */
37     char * title; /* Designated title to pass to init_win(). */
38 };
39
40
41
42 /* Get WinConf fathering "win" / get Win of WinConf of "id". */
43 extern struct WinConf * get_winconf_by_win(struct Win * win);
44 extern struct Win * get_win_by_id(char id);
45
46 /* Free all WinConf DB data. */
47 extern void free_winconfs();
48
49 /* Initialize  Win structs for WinConfs in WinConf database. */
50 extern void init_wins();
51
52 /* Toggle windows in order set by world.win_order. Point active window selection
53  * to window identified by world.winconf_db.active.
54  */
55 extern void sorted_win_toggle_and_activate();
56
57 /* Read/write world.win_order and world.winconf_db.active from/to "file". */
58 extern void read_order_wins_visible_active(char * line, uint32_t linemax, FILE * file);
59 extern void write_order_wins_visible_active(FILE * file, char * delim);
60
61 /* Iterate over chars of world.winconf_db.winconf_ids array. Restart after \0.*/
62 extern char get_next_winconf_id();
63
64 /* Read/write individual WinConf (identified by "c") from/to file. */
65 extern uint8_t read_winconf_from_file(char * line, uint32_t linemax, FILE * file);
66 extern void write_winconf_of_id_to_file(FILE * file, char c, char * delim);
67
68 /* Toggle "window configuration" view for active window. Sets sensible
69  * Win.center values for the various configuration views (for winconf_geometry:
70  * y=0, x=0; for winconf_keys: x=0 (y is set by draw_winconf_keybindings()).
71  */
72 extern void toggle_winconfig();
73
74 /* Toggle WinConf.(height/width)_type ("axis" = "y": height; else: width). Avoid
75  * positive diff to screen width (value would be wrongly read as a non-diff),
76  * width_type toggles to 1 only if world.wmeta->screen's width >= WinConf.width.
77  */
78 extern void toggle_win_size_type(char axis);
79
80 /* Toggle display of a window identified by "id". */
81  extern void toggle_window(char id);
82
83 /* Try scrolling virtual screen left ("dir" = "-") or right ("dir" = "+") to the
84  * degree allowed by the window manager's reset_pad_offset().
85  */
86 extern void scroll_pad(char dir);
87
88 /* Try to grow or shrink the active window horizontally ("change" = "*"/"_") or
89  * vertically ("change = "+"/"-") by one cell size to the degree allowed by the
90  * window manager's resize_active_win(). If a new window width would surpass
91  * that of the terminal screen, set WinConf.width_type to 0.
92  */
93 extern void growshrink_active_window(char change);
94
95
96
97 #endif