]> Pileus Git - wmpus/blob - sys.h
d2001225a1baee26218ec6ccb4a33b8948ae1c8c
[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 /* Basic window type */
28 typedef struct win_sys win_sys_t;
29 typedef struct win_wm  win_wm_t;
30 typedef struct {
31         int x, y, z;
32         int w, h;
33         win_sys_t *sys;
34         win_wm_t  *wm;
35 } win_t;
36
37 /* Generic key codes, also used for some other events
38  * Keys map to their Unicode value */
39 typedef enum {
40         key_alert       = '\a',
41         key_backspace   = '\b',
42         key_formfeed    = '\f',
43         key_newline     = '\n',
44         key_return      = '\r',
45         key_tab         = '\t',
46         key_vtab        = '\v',
47         key_singlequote = '\'',
48         key_doublequote = '\"',
49         key_backslash   = '\\',
50         key_question    = '\?',
51         key_none        = 0xF0000, // unused Unicode space
52         key_mouse0, key_mouse1, key_mouse2, key_mouse3,
53         key_mouse4, key_mouse5, key_mouse6, key_mouse7,
54         key_left, key_right, key_up,     key_down,
55         key_home, key_end,   key_pageup, key_pagedown,
56         key_f1, key_f2,  key_f3,  key_f4,
57         key_f5, key_f6,  key_f7,  key_f8,
58         key_f9, key_f10, key_f11, key_f12,
59         key_alt, key_ctrl, key_shift, key_win,
60         key_enter, key_leave, key_focus, key_unfocus,
61 } Key_t;
62
63 /* Key modifiers, up is for button release */
64 typedef struct {
65         unsigned char alt   : 1;
66         unsigned char ctrl  : 1;
67         unsigned char shift : 1;
68         unsigned char win   : 1;
69         unsigned char up    : 1;
70 } mod_t;
71 #define MOD(...)     ((mod_t){__VA_ARGS__})
72 #define mod2int(mod) (*((unsigned char*)&(mod)))
73
74 /* Mouse movement */
75 typedef struct {
76         int  x,  y;
77         int rx, ry;
78 } ptr_t;
79 #define PTR(...) ((ptr_t){__VA_ARGS__})
80
81 /* Window states */
82 typedef enum {
83         st_show,  // show as regular window
84         st_full,  // fullscreen/maximized
85         st_shade, // show titlebar only
86         st_icon,  // iconified/minimized
87         st_hide,  // completely hidden
88 } state_t;
89
90
91 /* Move the window to the specified location and set it's
92  * geometry. The position and size include borders and
93  * window decorations. */
94 void sys_move(win_t *win, int x, int y, int w, int h);
95
96 /* Rise the window above all other windows */
97 void sys_raise(win_t *win);
98
99 /* Give keyboard focus to the window and update window
100  * decorations. */
101 void sys_focus(win_t *win);
102
103 /* Set the windows drawing state */
104 void sys_show(win_t *win, state_t st);
105
106 /* Start watching for a key events. The sys subsequently
107  * calls wm_handle_key whenever the event occurs. */
108 void sys_watch(win_t *win, Key_t key, mod_t mod);
109
110 /* Stop watching a key event */
111 void sys_unwatch(win_t *win, Key_t key, mod_t mod);
112
113 /* Return a list of windows representing the geometry of the
114  * physical displays attached to the computer. */
115 list_t *sys_info(win_t *root);
116
117 /* First call, calls wm_insert for each existing window */
118 win_t *sys_init(void);
119
120 /* Starts the main loop */
121 void sys_run(win_t *root);