]> Pileus Git - wmpus/blob - sys.h
Improve input handling
[wmpus] / sys.h
1 /*
2  * Copyright (c) 2011-2012, 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_HIDE,  // completely hidden
30         ST_SHOW,  // show as regular window
31         ST_FULL,  // fullscreen (without decorations)
32         ST_MAX,   // maximized (with decorations)
33         ST_SHADE, // show titlebar only
34         ST_ICON,  // iconified/minimized
35         ST_CLOSE, // close the window
36 } state_t;
37
38 /* Window types */
39 typedef enum {
40         TYPE_NORMAL,
41         TYPE_DIALOG,
42         TYPE_TOOLBAR,
43         TYPE_POPUP,
44         TYPE_CURSOR,
45 } type_t;
46
47 /* Basic window type */
48 typedef struct win_sys win_sys_t;
49 typedef struct win_wm  win_wm_t;
50 typedef struct win {
51         int x, y, z;
52         int w, h;
53         state_t state;
54         type_t  type;
55         struct win *parent;
56         win_sys_t  *sys;
57         win_wm_t   *wm;
58 } win_t;
59
60 /* Generic key codes, also used for some other events
61  * Keys map to their Unicode value */
62 typedef int event_t;
63 enum {
64         EV_ALERT       = '\a',
65         EV_BACKSPACE   = '\b',
66         EV_FORMFEED    = '\f',
67         EV_NEWLINE     = '\n',
68         EV_RETURN      = '\r',
69         EV_TAB         = '\t',
70         EV_VTAB        = '\v',
71         EV_SINGLEQUOTE = '\'',
72         EV_DOUBLEQUOTE = '\"',
73         EV_BACKSLASH   = '\\',
74         EV_QUESTION    = '\?',
75         EV_NONE        = 0xF0000, // unused Unicode space
76         EV_MOUSE0, EV_MOUSE1, EV_MOUSE2, EV_MOUSE3,
77         EV_MOUSE4, EV_MOUSE5, EV_MOUSE6, EV_MOUSE7,
78         EV_LEFT, EV_RIGHT, EV_UP,     EV_DOWN,
79         EV_HOME, EV_END,   EV_PAGEUP, EV_PAGEDOWN,
80         EV_F1, EV_F2,  EV_F3,  EV_F4,
81         EV_F5, EV_F6,  EV_F7,  EV_F8,
82         EV_F9, EV_F10, EV_F11, EV_F12,
83         EV_ALT, EV_CTRL, EV_SHIFT, EV_WIN,
84         EV_ENTER, EV_LEAVE, EV_FOCUS, EV_UNFOCUS,
85 };
86
87 /* Key modifiers, up is for button release */
88 typedef struct {
89         unsigned char alt   : 1;
90         unsigned char ctrl  : 1;
91         unsigned char shift : 1;
92         unsigned char win   : 1;
93         unsigned char up    : 1;
94 } mod_t;
95 #define MOD(...)     ((mod_t){__VA_ARGS__})
96 #define mod2int(mod) (*((unsigned char*)&(mod)))
97
98 /* Mouse movement */
99 typedef struct {
100         int  x,  y;
101         int rx, ry;
102 } ptr_t;
103 #define PTR(...) ((ptr_t){__VA_ARGS__})
104
105
106 /* Move the window to the specified location and set it's
107  * geometry. The position and size include borders and
108  * window decorations. */
109 void sys_move(win_t *win, int x, int y, int w, int h);
110
111 /* Rise the window above all other windows */
112 void sys_raise(win_t *win);
113
114 /* Give keyboard focus to the window and update window
115  * decorations. */
116 void sys_focus(win_t *win);
117
118 /* Set the windows drawing state */
119 void sys_show(win_t *win, state_t st);
120
121 /* Start watching for an event. The sys subsequently
122  * calls wm_handle_event whenever the event occurs. */
123 void sys_watch(win_t *win, event_t ev, mod_t mod);
124
125 /* Stop watching an event */
126 void sys_unwatch(win_t *win, event_t event, mod_t mod);
127
128 /* Return a list of windows representing the geometry of the
129  * physical displays attached to the computer. */
130 list_t *sys_info(win_t *root);
131
132 /* First call, calls wm_insert for each existing window */
133 win_t *sys_init(void);
134
135 /* Starts the main loop */
136 void sys_run(win_t *root);
137
138 /* Exit main loop */
139 void sys_exit(void);
140
141 /* Free all static data, for memory debugging */
142 void sys_free(win_t *root);