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