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