]> Pileus Git - wmpus/blob - sys.h
Revert window activate handling
[wmpus] / sys.h
1 /*
2  * Copyright (c) 2011, Andy Spencer <andy753421@gmail.com>
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  */
15
16 /* Windowing system interface:
17  *
18  * The sys provides input to the window manager. It creates
19  * the main loop and responds to input events from the user,
20  * generally by converting them to a system independent form
21  * and then passing them to the wm.
22  *
23  * The sys also provides the API used by the wm to position
24  * and control windows. */
25
26
27 /* Window states */
28 typedef enum {
29         st_show,  // show as regular window
30         st_full,  // fullscreen/maximized
31         st_shade, // show titlebar only
32         st_icon,  // iconified/minimized
33         st_hide,  // completely hidden
34 } state_t;
35
36 /* Basic window type */
37 typedef struct win_sys win_sys_t;
38 typedef struct win_wm  win_wm_t;
39 typedef struct {
40         int x, y, z;
41         int w, h;
42         state_t    state;
43         win_sys_t *sys;
44         win_wm_t  *wm;
45 } win_t;
46
47 /* Generic key codes, also used for some other events
48  * Keys map to their Unicode value */
49 typedef enum {
50         key_alert       = '\a',
51         key_backspace   = '\b',
52         key_formfeed    = '\f',
53         key_newline     = '\n',
54         key_return      = '\r',
55         key_tab         = '\t',
56         key_vtab        = '\v',
57         key_singlequote = '\'',
58         key_doublequote = '\"',
59         key_backslash   = '\\',
60         key_question    = '\?',
61         key_none        = 0xF0000, // unused Unicode space
62         key_mouse0, key_mouse1, key_mouse2, key_mouse3,
63         key_mouse4, key_mouse5, key_mouse6, key_mouse7,
64         key_left, key_right, key_up,     key_down,
65         key_home, key_end,   key_pageup, key_pagedown,
66         key_f1, key_f2,  key_f3,  key_f4,
67         key_f5, key_f6,  key_f7,  key_f8,
68         key_f9, key_f10, key_f11, key_f12,
69         key_alt, key_ctrl, key_shift, key_win,
70         key_enter, key_leave, key_focus, key_unfocus,
71 } Key_t;
72
73 /* Key modifiers, up is for button release */
74 typedef struct {
75         unsigned char alt   : 1;
76         unsigned char ctrl  : 1;
77         unsigned char shift : 1;
78         unsigned char win   : 1;
79         unsigned char up    : 1;
80 } mod_t;
81 #define MOD(...)     ((mod_t){__VA_ARGS__})
82 #define mod2int(mod) (*((unsigned char*)&(mod)))
83
84 /* Mouse movement */
85 typedef struct {
86         int  x,  y;
87         int rx, ry;
88 } ptr_t;
89 #define PTR(...) ((ptr_t){__VA_ARGS__})
90
91
92 /* Move the window to the specified location and set it's
93  * geometry. The position and size include borders and
94  * window decorations. */
95 void sys_move(win_t *win, int x, int y, int w, int h);
96
97 /* Rise the window above all other windows */
98 void sys_raise(win_t *win);
99
100 /* Give keyboard focus to the window and update window
101  * decorations. */
102 void sys_focus(win_t *win);
103
104 /* Set the windows drawing state */
105 void sys_show(win_t *win, state_t st);
106
107 /* Start watching for a key events. The sys subsequently
108  * calls wm_handle_key whenever the event occurs. */
109 void sys_watch(win_t *win, Key_t key, mod_t mod);
110
111 /* Stop watching a key event */
112 void sys_unwatch(win_t *win, Key_t key, mod_t mod);
113
114 /* Return a list of windows representing the geometry of the
115  * physical displays attached to the computer. */
116 list_t *sys_info(win_t *root);
117
118 /* First call, calls wm_insert for each existing window */
119 win_t *sys_init(void);
120
121 /* Starts the main loop */
122 void sys_run(win_t *root);
123
124 /* Exit main loop */
125 void sys_exit(void);
126
127 /* Free all static data, for memory debugging */
128 void sys_free(win_t *root);