Add support for the zoomed state to managed windows.
[gwm.git] / gwm.h
blob631b4cb6b9d90523778aea1f9711a8aa6646bab8
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 RANDR_CRTC_CHANGE_NOTIFY,
53 SHAPE_NOTIFY,
54 NUM_EXTENDED_EVENTS
57 extern xcb_connection_t *c;
58 extern xcb_timestamp_t latest_timestamp;
60 enum x_atom {
61 /* See X Window System Protocol (version 11, release 6.7), Appendix B. */
62 ATOM = 4,
63 CARDINAL = 6,
64 INTEGER = 19,
65 RGB_COLOR_MAP = 24,
66 RGB_DEFAULT_MAP = 27,
67 STRING = 31,
68 WINDOW = 33,
69 WM_HINTS = 35,
70 WM_ICON_NAME = 37,
71 WM_ICON_SIZE = 38,
72 WM_NAME = 39,
73 WM_NORMAL_HINTS = 40,
74 WM_SIZE_HINTS = 41
77 enum gwm_atom {
78 ATOM_COMPOUND_TEXT,
79 ATOM_MANAGER,
80 ATOM__MOTIF_WM_HINTS,
81 ATOM__NET_CURRENT_DESKTOP,
82 ATOM__NET_DESKTOP_GEOMETRY,
83 ATOM__NET_DESKTOP_VIEWPORT,
84 ATOM__NET_FRAME_EXTENTS,
85 ATOM__NET_NUMBER_OF_DESKTOPS,
86 ATOM__NET_SUPPORTED,
87 ATOM__NET_SUPPORTING_WM_CHECK,
88 ATOM__NET_WM_ICON,
89 ATOM__NET_WM_NAME,
90 ATOM__NET_WM_STATE,
91 ATOM__NET_WM_STATE_FULLSCREEN,
92 ATOM__NET_WM_STATE_MAXIMIZED_HORZ,
93 ATOM__NET_WM_STATE_MAXIMIZED_VERT,
94 ATOM__NET_WORKAREA,
95 ATOM_UTF8_STRING,
96 ATOM_VERSION,
97 ATOM_WM_CHANGE_STATE,
98 ATOM_WM_COLORMAP_NOTIFY,
99 ATOM_WM_COLORMAP_WINDOWS,
100 ATOM_WM_DELETE_WINDOW,
101 ATOM_WM_PROTOCOLS,
102 ATOM_WM_STATE,
103 ATOM_WM_TAKE_FOCUS,
104 NUM_ATOMS
107 extern xcb_atom_t atoms[ NUM_ATOMS ];
109 enum gwm_property_type {
110 PROP__MOTIF_WM_HINTS,
111 PROP__NET_WM_ICON,
112 PROP__NET_WM_NAME,
113 PROP__NET_WM_STATE,
114 PROP_WM_COLORMAP_WINDOWS,
115 PROP_WM_HINTS,
116 PROP_WM_NAME,
117 PROP_WM_NORMAL_HINTS,
118 PROP_WM_PROTOCOLS,
119 NUM_PROPS
122 #define PROP_SIZE 262144 /* maximum number of 32-bit words to retrieve */
124 extern xcb_atom_t prop_atoms[ NUM_PROPS ];
125 extern xcb_atom_t prop_types[ NUM_PROPS ];
127 enum gwm_extension {
128 #if USE_COMPOSITE
129 EXT_COMPOSITE,
130 #endif
131 #if USE_DAMAGE
132 EXT_DAMAGE,
133 #endif
134 #if USE_RANDR
135 EXT_RANDR,
136 #endif
137 #if USE_RENDER
138 EXT_RENDER,
139 #endif
140 #if USE_SHAPE
141 EXT_SHAPE, /* any version */
142 #endif
143 #if USE_XFIXES
144 EXT_XFIXES, /* requires version 2 */
145 #endif
146 NUM_EXTENSIONS
149 #if USE_COMPOSITE || USE_DAMAGE || USE_RANDR || USE_RENDER || USE_SHAPE || \
150 USE_XFIXES
151 #define EXTENSIONS_SIZE NUM_EXTENSIONS
152 #else
153 #define EXTENSIONS_SIZE 1 /* avoid zero length arrays */
154 #endif
156 extern int have_extension[ EXTENSIONS_SIZE ];
157 extern uint8_t extension_event[ EXTENSIONS_SIZE ],
158 extension_error[ EXTENSIONS_SIZE ];
160 enum decoration_col {
161 COL_FRAME_ACTIVE,
162 COL_FRAME_INACTIVE,
163 COL_BORDER,
164 COL_BUTTON_ACTIVE,
165 COL_BUTTON_INACTIVE,
166 COL_TITLE_ACTIVE,
167 COL_TITLE_INACTIVE,
168 COL_FEEDBACK_BACK,
169 COL_FEEDBACK_FORE,
170 COL_MENU_ACTIVE_BACK,
171 COL_MENU_ACTIVE_FORE,
172 COL_MENU_INACTIVE_BACK,
173 COL_MENU_INACTIVE_FORE,
174 NUM_COLS
177 extern int num_screens;
178 extern xcb_screen_t **screens;
180 #if USE_RANDR
181 struct gwm_crtc {
182 uint32_t crtc;
183 int x, y, width, height;
185 #endif
187 struct gwm_screen {
188 xcb_visualtype_t *root_visual;
189 xcb_atom_t wm_atom; /* the atom WM_Sn, where n is the screen number */
190 xcb_colormap_t cmap; /* the most recently installed colormap */
191 xcb_timestamp_t cmap_time; /* the time at which it was installed */
192 uint32_t pixels[ NUM_COLS ]; /* pixel values in the default cmap */
193 #if USE_RANDR
194 struct gwm_crtc **crtcs;
195 int num_crtcs;
196 #endif
199 extern struct gwm_screen *gwm_screens;
201 enum border_region {
202 BR_TL,
203 BR_T,
204 BR_TR,
205 BR_L,
206 BR_R,
207 BR_BL,
208 BR_B,
209 BR_BR,
210 NUM_BORDER_REGIONS
213 enum gwm_cursor {
214 CURSOR_TL,
215 CURSOR_T,
216 CURSOR_TR,
217 CURSOR_L,
218 CURSOR_C,
219 CURSOR_R,
220 CURSOR_BL,
221 CURSOR_B,
222 CURSOR_BR,
223 CURSOR_ARROW,
224 CURSOR_DESTROY,
225 NUM_CURSORS
227 /* FIXME these should really be indexed by (screen,cursor), not just by
228 cursor -- screens might be different resolutions, for instance. */
229 extern xcb_cursor_t cursors[ NUM_CURSORS ];
231 union callback_param {
232 long l;
233 void *p;
236 struct gwm_window;
238 #define HINT_ICONIC 0x1 /* otherwise normal */
239 #define HINT_INPUT 0x2
240 #define HINT_USER_POSITION 0x4
241 #define HINT_PROGRAM_POSITION 0x8
242 #define HINT_POSITION 0xC /* HINT_USER_POSITION | HINT_PROGRAM_POSITION */
243 #define PROTOCOL_DELETE_WINDOW 0x1
244 #define PROTOCOL_TAKE_FOCUS 0x2
246 #define STATE_WITHDRAWN 0
247 #define STATE_NORMAL 1
248 #define STATE_ICONIC 3
250 #define DEC_BORDER 0x1
251 #define DEC_TITLE 0x2
252 #define DEC_DEFAULT ( DEC_BORDER | DEC_TITLE )
254 #define ZOOM_NORMAL 0x0
255 #define ZOOM_FULLSCREEN 0x1 /* _NET_WM_STATE_FULLSCREEN */
256 #define ZOOM_MAXIMISE 0x2 /* _NET_WM_STATE_MAXIMIZED_* */
258 struct gwm_window {
259 xcb_window_t w;
260 int screen;
261 enum _gwm_window_type {
262 WINDOW_ROOT, WINDOW_MANAGED, WINDOW_FRAME, WINDOW_BUTTON, WINDOW_MENU,
263 WINDOW_MENUITEM, WINDOW_FAKE, WINDOW_FEEDBACK, WINDOW_INCOMPLETE,
264 WINDOW_CHILDLESS
265 } type;
266 xcb_rectangle_t update; /* the area which needs updating */
267 int cleared; /* TRUE if the update area has already been cleared */
268 union _gwm_window_union {
269 struct _gwm_managed {
270 struct gwm_window *frame;
271 uint16_t border_width;
272 xcb_colormap_t cmap;
273 #if USE_SHAPE
274 int shaped;
275 #endif
276 /* from WM_COLORMAP_WINDOWS: */
277 xcb_window_t cmap_window;
278 /* from WM_HINTS: */
279 int hints; /* see HINT_* above */
280 /* from _NET_WM_ICON: */
281 #if USE_RENDER
282 uint32_t *full_icons, *menu_icons; /* pictures, screen indexed */
283 int net_wm_icon;
284 #endif
285 /* from WM_NAME and _NET_WM_NAME: */
286 char *name; /* legal UTF-8; must be free()d */
287 int net_wm_name;
288 /* from WM_NORMAL_HINTS: */
289 int min_width, min_height, max_width, max_height, width_inc,
290 height_inc, min_aspect_x, min_aspect_y, max_aspect_x,
291 max_aspect_y, base_width, base_height, win_gravity;
292 /* from WM_PROTOCOLS: */
293 int protocols; /* see PROTOCOL_* above */
294 /* WM_STATE: */
295 int state; /* see STATE_* above */
296 } managed;
297 struct _gwm_frame {
298 struct gwm_window *child, *button;
299 int x, y, width, height;
300 int decoration; /* see DEC_* above */
301 int unzoomed_x, unzoomed_y, unzoomed_width, unzoomed_height,
302 unzoomed_decoration;
303 int zoom_state; /* see ZOOM_* above */
304 xcb_window_t border_regions[ NUM_BORDER_REGIONS ];
305 } frame;
306 struct _gwm_button {
307 struct gwm_window *frame;
308 } button;
309 struct _gwm_menu {
310 xcb_window_t window_param;
311 int num_items, active_item;
312 int width;
313 int has_icons;
314 struct gwm_window **items; /* must be free()d */
315 } menu;
316 struct _gwm_menuitem {
317 struct gwm_window *menu;
318 char *label; /* must be free()d */
319 void ( *action )( struct gwm_window *window,
320 xcb_generic_event_t *ev,
321 union callback_param cp );
322 void ( *enter_action )( struct gwm_window *window,
323 xcb_generic_event_t *ev,
324 union callback_param cp );
325 void ( *leave_action )( struct gwm_window *window,
326 xcb_generic_event_t *ev,
327 union callback_param cp );
328 union callback_param cp;
329 xcb_window_t icon;
330 } menuitem;
331 struct _gwm_fake {
332 xcb_timestamp_t timestamp;
333 } fake;
334 struct _gwm_feedback {
335 int fb_width, fb_height;
336 } feedback;
337 struct _gwm_incomplete {
338 unsigned int sequence;
339 } incomplete;
340 } u;
343 extern struct gwm_window *fake_window; /* a window created solely to hold the
344 WM_Sn selections */
346 extern const char *argv0;
347 extern volatile int signal_caught;
349 extern FORMAT( printf, 1, 2 ) void warning( char *format, ... );
350 extern FORMAT( printf, 1, 2 ) NORETURN void fatal( char *format, ... );
352 /* Schedule a callback function to be invoked when a reply or error is
353 available for handling, or when neither can arrive. */
354 extern void handle_async_reply( unsigned int sequence,
355 void ( *callback )( unsigned int sequence,
356 void *reply,
357 xcb_generic_error_t *error,
358 union callback_param p ),
359 union callback_param p );
360 /* Block until the scheduled callback function has completed. */
361 extern void sync_with_callback( unsigned int sequence );
363 #define ERR_MASK_REQUEST 0x000001
364 #define ERR_MASK_VALUE 0x00002
365 #define ERR_MASK_WINDOW 0x00004
366 #define ERR_MASK_PIXMAP 0x00008
367 #define ERR_MASK_ATOM 0x00010
368 #define ERR_MASK_CURSOR 0x00020
369 #define ERR_MASK_FONT 0x00040
370 #define ERR_MASK_MATCH 0x00080
371 #define ERR_MASK_DRAWABLE 0x00100
372 #define ERR_MASK_ACCESS 0x00200
373 #define ERR_MASK_ALLOC 0x00400
374 #define ERR_MASK_COLORMAP 0x00800
375 #define ERR_MASK_G_CONTEXT 0x01000
376 #define ERR_MASK_ID_CHOICE 0x02000
377 #define ERR_MASK_NAME 0x04000
378 #define ERR_MASK_LENGTH 0x08000
379 #define ERR_MASK_IMPLEMENTATION 0x10000
381 extern void handle_error_reply( xcb_void_cookie_t cookie, unsigned ignore );
382 extern void show_error( xcb_generic_error_t *error );
384 typedef void ( *event_handler )( struct gwm_window *window,
385 xcb_generic_event_t *ev );
387 /* Return TRUE iff an event is the only button pressed. */
388 extern CONST int initial_press( xcb_button_press_event_t *ev );
390 /* Return TRUE iff an event is the release of the last button (and so would
391 terminate a passive grab). */
392 extern CONST int final_release( xcb_button_release_event_t *ev );
394 /* Return TRUE iff a point is "live" (within at least one CRTC). */
395 extern int point_live( int screen, int x, int y );
397 /* Move an area the shortest Manhattan distance so that at an area of at
398 least min_x x min_y pixels fall within at least one CRTC, if possible. */
399 extern void make_area_live( int screen, int *x, int *y, int width, int height,
400 int min_x, int min_y );
402 extern CONST xcb_timestamp_t event_time( xcb_generic_event_t *ev );
404 /* The window whose event handler(s) should be invoked for pointer events.
405 Unlike pointer grabs, this mechanism is implemented entirely on the
406 client side, and has no effect on the contents of events. */
407 extern xcb_window_t pointer_demux;
409 /* Install a window's colormap on a screen, or the default colormap if
410 unspecified. */
411 extern void install_window_colormap( int screen, struct gwm_window *window,
412 xcb_timestamp_t t );
414 extern void update_crtc( int screen, int crtc, int width, int height,
415 int x, int y );
417 extern void generic_expose( struct gwm_window *window,
418 xcb_expose_event_t *ev );
420 extern void manage_window( xcb_window_t w, int map_request );
421 extern void unmanage_window( struct gwm_window *window );
423 /* A replacement for xcb_wait_for_event (which is broken, because it
424 always restarts interrupted system calls). Also invokes any
425 asynchronous callbacks scheduled for replies and errors. */
426 extern xcb_generic_event_t *wait_for_event( void );
428 extern void ( *window_size )( struct gwm_window *window, int *width,
429 int *height );
430 extern void ( *replace_icons )( struct gwm_window *window, int num_icons,
431 int *widths, int *heights, uint32_t **icons,
432 xcb_pixmap_t *pixmaps );
434 #endif