Don't attempt to load non-existent characters.
[gwm.git] / gwm.h
blob10ade5879407bb253dd2e8a2e7af0b558cf22fa2
1 #ifndef _GWM_H_
2 #define _GWM_H_
4 #ifndef FALSE
5 #define FALSE 0
6 #endif
7 #ifndef TRUE
8 #define TRUE 1
9 #endif
11 #if !defined(__GNUC__) && !defined(__attribute__)
12 #define __attribute__()
13 #endif
15 #ifndef CONST
16 #define CONST __attribute__((const))
17 #endif
19 #ifndef FORMAT
20 #define FORMAT( archetype, string_index, first_to_check ) \
21 __attribute__((format( archetype, string_index, first_to_check ) ))
22 #endif
24 #ifndef MALLOC
25 #define MALLOC __attribute__((malloc))
26 #endif
28 #ifndef NORETURN
29 #define NORETURN __attribute__((noreturn))
30 #endif
32 #ifndef PURE
33 #define PURE __attribute__((pure))
34 #endif
36 #if HAVE_INIT_SECTION
37 #define INIT __attribute__((section( ".gwminit.text" ) ))
38 #define INITD __attribute__((section( ".gwminit.rodata" ) ))
39 #else
40 #define INIT
41 #define INITD
42 #endif
44 #define SEND_EVENT_MASK 0x80
46 extern MALLOC void *xmalloc( size_t size );
47 extern void *xrealloc( void *p, size_t size );
48 extern MALLOC void *xcalloc( size_t number, size_t size );
50 enum _extended_event_type {
51 SYNTHETIC_EVENT = XCB_MAPPING_NOTIFY + 1,
52 SHAPE_NOTIFY
55 extern xcb_connection_t *c;
56 extern xcb_timestamp_t latest_timestamp;
58 enum x_atom {
59 /* See X Window System Protocol (version 11, release 6.7), Appendix B. */
60 ATOM = 4,
61 CARDINAL = 6,
62 INTEGER = 19,
63 RGB_COLOR_MAP = 24,
64 RGB_DEFAULT_MAP = 27,
65 STRING = 31,
66 WINDOW = 33,
67 WM_HINTS = 35,
68 WM_ICON_NAME = 37,
69 WM_ICON_SIZE = 38,
70 WM_NAME = 39,
71 WM_NORMAL_HINTS = 40,
72 WM_SIZE_HINTS = 41
75 enum gwm_atom {
76 ATOM_COMPOUND_TEXT,
77 ATOM_MANAGER,
78 ATOM__MOTIF_WM_HINTS,
79 ATOM__NET_CURRENT_DESKTOP,
80 ATOM__NET_DESKTOP_GEOMETRY,
81 ATOM__NET_DESKTOP_VIEWPORT,
82 ATOM__NET_FRAME_EXTENTS,
83 ATOM__NET_NUMBER_OF_DESKTOPS,
84 ATOM__NET_SUPPORTED,
85 ATOM__NET_SUPPORTING_WM_CHECK,
86 ATOM__NET_WM_ICON,
87 ATOM__NET_WM_NAME,
88 ATOM__NET_WORKAREA,
89 ATOM_UTF8_STRING,
90 ATOM_VERSION,
91 ATOM_WM_CHANGE_STATE,
92 ATOM_WM_COLORMAP_NOTIFY,
93 ATOM_WM_COLORMAP_WINDOWS,
94 ATOM_WM_DELETE_WINDOW,
95 ATOM_WM_PROTOCOLS,
96 ATOM_WM_STATE,
97 ATOM_WM_TAKE_FOCUS,
98 NUM_ATOMS
101 extern xcb_atom_t atoms[ NUM_ATOMS ];
103 enum gwm_property_type {
104 PROP__MOTIF_WM_HINTS,
105 PROP__NET_WM_ICON,
106 PROP__NET_WM_NAME,
107 PROP_WM_COLORMAP_WINDOWS,
108 PROP_WM_HINTS,
109 PROP_WM_NAME,
110 PROP_WM_NORMAL_HINTS,
111 PROP_WM_PROTOCOLS,
112 NUM_PROPS
115 #define PROP_SIZE 262144 /* maximum number of 32-bit words to retrieve */
117 extern xcb_atom_t prop_atoms[ NUM_PROPS ];
118 extern xcb_atom_t prop_types[ NUM_PROPS ];
120 enum gwm_extension {
121 #if USE_COMPOSITE
122 EXT_COMPOSITE,
123 #endif
124 #if USE_DAMAGE
125 EXT_DAMAGE,
126 #endif
127 #if USE_RENDER
128 EXT_RENDER,
129 #endif
130 #if USE_SHAPE
131 EXT_SHAPE, /* any version */
132 #endif
133 #if USE_XFIXES
134 EXT_XFIXES, /* requires version 2 */
135 #endif
136 NUM_EXTENSIONS
139 #if USE_COMPOSITE || USE_DAMAGE || USE_RENDER || USE_SHAPE || USE_FIXES
140 #define EXTENSIONS_SIZE NUM_EXTENSIONS
141 #else
142 #define EXTENSIONS_SIZE 1 /* avoid zero length arrays */
143 #endif
145 extern int have_extension[ EXTENSIONS_SIZE ];
146 extern uint8_t extension_event[ EXTENSIONS_SIZE ],
147 extension_error[ EXTENSIONS_SIZE ];
149 enum decoration_col {
150 COL_FRAME_ACTIVE,
151 COL_FRAME_INACTIVE,
152 COL_BORDER,
153 COL_BUTTON_ACTIVE,
154 COL_BUTTON_INACTIVE,
155 COL_TITLE_ACTIVE,
156 COL_TITLE_INACTIVE,
157 COL_FEEDBACK_BACK,
158 COL_FEEDBACK_FORE,
159 COL_MENU_ACTIVE_BACK,
160 COL_MENU_ACTIVE_FORE,
161 COL_MENU_INACTIVE_BACK,
162 COL_MENU_INACTIVE_FORE,
163 NUM_COLS
166 extern int num_screens;
167 extern xcb_screen_t **screens;
169 struct gwm_screen {
170 xcb_visualtype_t *root_visual;
171 xcb_atom_t wm_atom; /* the atom WM_Sn, where n is the screen number */
172 xcb_colormap_t cmap; /* the most recently installed colormap */
173 xcb_timestamp_t cmap_time; /* the time at which it was installed */
174 uint32_t pixels[ NUM_COLS ]; /* pixel values in the default cmap */
177 extern struct gwm_screen *gwm_screens;
179 enum border_region {
180 BR_TL,
181 BR_T,
182 BR_TR,
183 BR_L,
184 BR_R,
185 BR_BL,
186 BR_B,
187 BR_BR,
188 NUM_BORDER_REGIONS
191 enum gwm_cursor {
192 CURSOR_TL,
193 CURSOR_T,
194 CURSOR_TR,
195 CURSOR_L,
196 CURSOR_C,
197 CURSOR_R,
198 CURSOR_BL,
199 CURSOR_B,
200 CURSOR_BR,
201 CURSOR_ARROW,
202 CURSOR_DESTROY,
203 NUM_CURSORS
205 extern xcb_cursor_t cursors[ NUM_CURSORS ];
207 union callback_param {
208 long l;
209 void *p;
212 struct gwm_window;
214 #define HINT_ICONIC 0x1 /* otherwise normal */
215 #define HINT_INPUT 0x2
216 #define HINT_USER_POSITION 0x4
217 #define HINT_PROGRAM_POSITION 0x8
218 #define HINT_POSITION 0xC /* HINT_USER_POSITION | HINT_PROGRAM_POSITION */
219 #define PROTOCOL_DELETE_WINDOW 0x1
220 #define PROTOCOL_TAKE_FOCUS 0x2
222 #define STATE_WITHDRAWN 0
223 #define STATE_NORMAL 1
224 #define STATE_ICONIC 3
226 #define DEC_BORDER 0x1
227 #define DEC_TITLE 0x2
228 #define DEC_DEFAULT ( DEC_BORDER | DEC_TITLE )
230 struct gwm_window {
231 xcb_window_t w;
232 int screen;
233 enum _gwm_window_type {
234 WINDOW_ROOT, WINDOW_MANAGED, WINDOW_FRAME, WINDOW_BUTTON, WINDOW_MENU,
235 WINDOW_MENUITEM, WINDOW_FAKE, WINDOW_FEEDBACK, WINDOW_INCOMPLETE,
236 WINDOW_CHILDLESS
237 } type;
238 xcb_rectangle_t update; /* the area which needs updating */
239 int cleared; /* TRUE if the update area has already been cleared */
240 union _gwm_window_union {
241 struct _gwm_managed {
242 struct gwm_window *frame;
243 uint16_t border_width;
244 xcb_colormap_t cmap;
245 #if USE_SHAPE
246 int shaped;
247 #endif
248 /* from WM_COLORMAP_WINDOWS: */
249 xcb_window_t cmap_window;
250 /* from WM_HINTS: */
251 int hints; /* see HINT_* above */
252 /* from _NET_WM_ICON: */
253 #if USE_RENDER
254 uint32_t *full_icons, *menu_icons; /* pictures, screen indexed */
255 int net_wm_icon;
256 #endif
257 /* from WM_NAME and _NET_WM_NAME: */
258 char *name; /* legal UTF-8; must be free()d */
259 int net_wm_name;
260 /* from WM_NORMAL_HINTS: */
261 int min_width, min_height, max_width, max_height, width_inc,
262 height_inc, min_aspect_x, min_aspect_y, max_aspect_x,
263 max_aspect_y, base_width, base_height, win_gravity;
264 /* from WM_PROTOCOLS: */
265 int protocols; /* see PROTOCOL_* above */
266 /* WM_STATE: */
267 int state; /* see STATE_* above */
268 } managed;
269 struct _gwm_frame {
270 struct gwm_window *child, *button;
271 int x, y, width, height;
272 int decoration; /* see DEC_* above */
273 xcb_window_t border_regions[ NUM_BORDER_REGIONS ];
274 } frame;
275 struct _gwm_button {
276 struct gwm_window *frame;
277 } button;
278 struct _gwm_menu {
279 xcb_window_t window_param;
280 int num_items, active_item;
281 int width;
282 int has_icons;
283 struct gwm_window **items; /* must be free()d */
284 } menu;
285 struct _gwm_menuitem {
286 struct gwm_window *menu;
287 char *label; /* must be free()d */
288 void ( *action )( struct gwm_window *window,
289 xcb_generic_event_t *ev,
290 union callback_param cp );
291 void ( *enter_action )( struct gwm_window *window,
292 xcb_generic_event_t *ev,
293 union callback_param cp );
294 void ( *leave_action )( struct gwm_window *window,
295 xcb_generic_event_t *ev,
296 union callback_param cp );
297 union callback_param cp;
298 xcb_window_t icon;
299 } menuitem;
300 struct _gwm_fake {
301 xcb_timestamp_t timestamp;
302 } fake;
303 struct _gwm_feedback {
304 int fb_width, fb_height;
305 } feedback;
306 struct _gwm_incomplete {
307 unsigned int sequence;
308 } incomplete;
309 } u;
312 extern struct gwm_window *fake_window; /* a window created solely to hold the
313 WM_Sn selections */
315 extern const char *argv0;
316 extern volatile int signal_caught;
318 extern FORMAT( printf, 1, 2 ) void warning( char *format, ... );
319 extern FORMAT( printf, 1, 2 ) NORETURN void fatal( char *format, ... );
321 /* Schedule a callback function to be invoked when a reply or error is
322 available for handling, or when neither can arrive. */
323 extern void handle_async_reply( unsigned int sequence,
324 void ( *callback )( unsigned int sequence,
325 void *reply,
326 xcb_generic_error_t *error,
327 union callback_param p ),
328 union callback_param p );
329 /* Block until the scheduled callback function has completed. */
330 extern void sync_with_callback( unsigned int sequence );
332 #define ERR_MASK_REQUEST 0x000001
333 #define ERR_MASK_VALUE 0x00002
334 #define ERR_MASK_WINDOW 0x00004
335 #define ERR_MASK_PIXMAP 0x00008
336 #define ERR_MASK_ATOM 0x00010
337 #define ERR_MASK_CURSOR 0x00020
338 #define ERR_MASK_FONT 0x00040
339 #define ERR_MASK_MATCH 0x00080
340 #define ERR_MASK_DRAWABLE 0x00100
341 #define ERR_MASK_ACCESS 0x00200
342 #define ERR_MASK_ALLOC 0x00400
343 #define ERR_MASK_COLORMAP 0x00800
344 #define ERR_MASK_G_CONTEXT 0x01000
345 #define ERR_MASK_ID_CHOICE 0x02000
346 #define ERR_MASK_NAME 0x04000
347 #define ERR_MASK_LENGTH 0x08000
348 #define ERR_MASK_IMPLEMENTATION 0x10000
350 extern void handle_error_reply( xcb_void_cookie_t cookie, unsigned ignore );
351 extern void show_error( xcb_generic_error_t *error );
353 typedef void ( *event_handler )( struct gwm_window *window,
354 xcb_generic_event_t *ev );
356 /* Return TRUE iff an event is the only button pressed. */
357 extern CONST int initial_press( xcb_button_press_event_t *ev );
359 /* Return TRUE iff an event is the release of the last button (and so would
360 terminate a passive grab). */
361 extern CONST int final_release( xcb_button_release_event_t *ev );
363 extern CONST xcb_timestamp_t event_time( xcb_generic_event_t *ev );
365 /* The window whose event handler(s) should be invoked for pointer events.
366 Unlike pointer grabs, this mechanism is implemented entirely on the
367 client side, and has no effect on the contents of events. */
368 extern xcb_window_t pointer_demux;
370 /* Install a window's colormap on a screen, or the default colormap if
371 unspecified. */
372 extern void install_window_colormap( int screen, struct gwm_window *window,
373 xcb_timestamp_t t );
375 extern void generic_expose( struct gwm_window *window,
376 xcb_expose_event_t *ev );
378 extern void manage_window( xcb_window_t w, int map_request );
379 extern void unmanage_window( struct gwm_window *window );
381 /* A replacement for xcb_wait_for_event (which is broken, because it
382 always restarts interrupted system calls). Also invokes any
383 asynchronous callbacks scheduled for replies and errors. */
384 extern xcb_generic_event_t *wait_for_event( void );
386 extern void ( *window_size )( struct gwm_window *window, int *width,
387 int *height );
388 extern void ( *replace_icons )( struct gwm_window *window, int num_icons,
389 int *widths, int *heights, uint32_t **icons,
390 xcb_pixmap_t *pixmaps );
392 #endif