11 #if !defined(__GNUC__) && !defined(__attribute__)
12 #define __attribute__()
16 #define CONST __attribute__((const))
20 #define FORMAT( archetype, string_index, first_to_check ) \
21 __attribute__((format( archetype, string_index, first_to_check ) ))
25 #define MALLOC __attribute__((malloc))
29 #define NORETURN __attribute__((noreturn))
33 #define PURE __attribute__((pure))
37 #define INIT __attribute__((section( ".gwminit.text" ) ))
38 #define INITD __attribute__((section( ".gwminit.rodata" ) ))
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
,
57 extern xcb_connection_t
*c
;
58 extern xcb_timestamp_t latest_timestamp
;
61 /* See X Window System Protocol (version 11, release 6.7), Appendix B. */
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
,
87 ATOM__NET_SUPPORTING_WM_CHECK
,
91 ATOM__NET_WM_STATE_FULLSCREEN
,
92 ATOM__NET_WM_STATE_MAXIMIZED_HORZ
,
93 ATOM__NET_WM_STATE_MAXIMIZED_VERT
,
98 ATOM_WM_COLORMAP_NOTIFY
,
99 ATOM_WM_COLORMAP_WINDOWS
,
100 ATOM_WM_DELETE_WINDOW
,
107 extern xcb_atom_t atoms
[ NUM_ATOMS
];
109 enum gwm_property_type
{
110 PROP__MOTIF_WM_HINTS
,
114 PROP_WM_COLORMAP_WINDOWS
,
117 PROP_WM_NORMAL_HINTS
,
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
];
141 EXT_SHAPE
, /* any version */
144 EXT_XFIXES
, /* requires version 2 */
149 #if USE_COMPOSITE || USE_DAMAGE || USE_RANDR || USE_RENDER || USE_SHAPE || \
151 #define EXTENSIONS_SIZE NUM_EXTENSIONS
153 #define EXTENSIONS_SIZE 1 /* avoid zero length arrays */
156 extern int have_extension
[ EXTENSIONS_SIZE
];
157 extern uint8_t extension_event
[ EXTENSIONS_SIZE
],
158 extension_error
[ EXTENSIONS_SIZE
];
160 enum decoration_col
{
170 COL_MENU_ACTIVE_BACK
,
171 COL_MENU_ACTIVE_FORE
,
172 COL_MENU_INACTIVE_BACK
,
173 COL_MENU_INACTIVE_FORE
,
177 extern int num_screens
;
178 extern xcb_screen_t
**screens
;
183 int x
, y
, width
, height
;
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 */
194 struct gwm_crtc
**crtcs
;
199 extern struct gwm_screen
*gwm_screens
;
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
{
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_* */
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
,
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
;
276 /* from WM_COLORMAP_WINDOWS: */
277 xcb_window_t cmap_window
;
279 int hints
; /* see HINT_* above */
280 /* from _NET_WM_ICON: */
282 uint32_t *full_icons
, *menu_icons
; /* pictures, screen indexed */
285 /* from WM_NAME and _NET_WM_NAME: */
286 char *name
; /* legal UTF-8; must be free()d */
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 */
295 int state
; /* see STATE_* above */
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
,
303 int zoom_state
; /* see ZOOM_* above */
304 xcb_window_t border_regions
[ NUM_BORDER_REGIONS
];
307 struct gwm_window
*frame
;
310 xcb_window_t window_param
;
311 int num_items
, active_item
;
314 struct gwm_window
**items
; /* must be free()d */
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
;
332 xcb_timestamp_t timestamp
;
334 struct _gwm_feedback
{
335 int fb_width
, fb_height
;
337 struct _gwm_incomplete
{
338 unsigned int sequence
;
343 extern struct gwm_window
*fake_window
; /* a window created solely to hold the
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
,
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
411 extern void install_window_colormap( int screen
, struct gwm_window
*window
,
414 extern void update_crtc( int screen
, int crtc
, int width
, int height
,
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
,
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
);