Send a synthetic ConfigureNotify to the client on reparenting a window.
[gwm.git] / gwm.h
blob5f63b9d9a1574136f174971476b01620a5ab3090
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 #define SEND_EVENT_MASK 0x80
38 extern MALLOC void *xmalloc( size_t size );
39 extern void *xrealloc( void *p, size_t size );
40 extern MALLOC void *xcalloc( size_t number, size_t size );
42 enum _extended_event_type {
43 SYNTHETIC_EVENT = XCB_MAPPING_NOTIFY + 1,
44 SHAPE_NOTIFY
47 extern xcb_connection_t *c;
48 extern xcb_timestamp_t latest_timestamp;
50 enum x_atom {
51 /* See X Window System Protocol (version 11, release 6.7), Appendix B. */
52 ATOM = 4,
53 INTEGER = 19,
54 RGB_COLOR_MAP = 24,
55 RGB_DEFAULT_MAP = 27,
56 STRING = 31,
57 WINDOW = 33,
58 WM_HINTS = 35,
59 WM_ICON_NAME = 37,
60 WM_NAME = 39,
61 WM_NORMAL_HINTS = 40,
62 WM_SIZE_HINTS = 41
65 enum gwm_atom {
66 ATOM_COMPOUND_TEXT,
67 ATOM_MANAGER,
68 ATOM_UTF8_STRING,
69 ATOM_VERSION,
70 ATOM_WM_CHANGE_STATE,
71 ATOM_WM_COLORMAP_NOTIFY,
72 ATOM_WM_COLORMAP_WINDOWS,
73 ATOM_WM_DELETE_WINDOW,
74 ATOM_WM_PROTOCOLS,
75 ATOM_WM_STATE,
76 ATOM_WM_TAKE_FOCUS,
77 NUM_ATOMS
80 extern xcb_atom_t atoms[ NUM_ATOMS ];
82 enum gwm_property_type {
83 PROP_WM_COLORMAP_WINDOWS,
84 PROP_WM_HINTS,
85 PROP_WM_NAME,
86 PROP_WM_NORMAL_HINTS,
87 PROP_WM_PROTOCOLS,
88 NUM_PROPS
91 #define PROP_SIZE 64 /* maximum number of 32-bit words to retrieve */
93 extern xcb_atom_t prop_atoms[ NUM_PROPS ];
94 extern xcb_atom_t prop_types[ NUM_PROPS ];
96 enum gwm_extension {
97 #if USE_COMPOSITE
98 EXT_COMPOSITE,
99 #endif
100 #if USE_DAMAGE
101 EXT_DAMAGE,
102 #endif
103 #if USE_RENDER
104 EXT_RENDER,
105 #endif
106 #if USE_SHAPE
107 EXT_SHAPE, /* any version */
108 #endif
109 #if USE_XFIXES
110 EXT_XFIXES, /* requires version 2 */
111 #endif
112 NUM_EXTENSIONS
115 #if USE_COMPOSITE || USE_DAMAGE || USE_RENDER || USE_SHAPE || USE_FIXES
116 #define EXTENSIONS_SIZE NUM_EXTENSIONS
117 #else
118 #define EXTENSIONS_SIZE 1 /* avoid zero length arrays */
119 #endif
121 extern int have_extension[ EXTENSIONS_SIZE ];
122 extern uint8_t extension_event[ EXTENSIONS_SIZE ],
123 extension_error[ EXTENSIONS_SIZE ];
125 enum decoration_col {
126 COL_FRAME_ACTIVE,
127 COL_FRAME_INACTIVE,
128 COL_BORDER,
129 COL_BUTTON_ACTIVE,
130 COL_BUTTON_INACTIVE,
131 COL_TITLE_ACTIVE,
132 COL_TITLE_INACTIVE,
133 COL_FEEDBACK_BACK,
134 COL_FEEDBACK_FORE,
135 NUM_COLS
138 extern int num_screens;
139 extern xcb_screen_t **screens;
141 struct gwm_screen {
142 xcb_visualtype_t *root_visual;
143 xcb_atom_t wm_atom; /* the atom WM_Sn, where n is the screen number */
144 xcb_colormap_t cmap; /* the most recently installed colormap */
145 xcb_timestamp_t cmap_time; /* the time at which it was installed */
146 uint32_t pixels[ NUM_COLS ]; /* pixel values in the default cmap */
149 extern struct gwm_screen *gwm_screens;
151 enum gwm_cursor {
152 CURSOR_ARROW,
153 CURSOR_DESTROY,
154 CURSOR_TL,
155 CURSOR_T,
156 CURSOR_TR,
157 CURSOR_L,
158 CURSOR_C,
159 CURSOR_R,
160 CURSOR_BL,
161 CURSOR_B,
162 CURSOR_BR,
163 NUM_CURSORS
165 extern xcb_cursor_t cursors[ NUM_CURSORS ];
167 #define HINT_ICONIC 0x1 /* otherwise normal */
168 #define HINT_INPUT 0x2
169 #define HINT_USER_POSITION 0x4
170 #define HINT_PROGRAM_POSITION 0x8
171 #define HINT_POSITION 0xC /* HINT_USER_POSITION | HINT_PROGRAM_POSITION */
172 #define PROTOCOL_DELETE_WINDOW 0x1
173 #define PROTOCOL_TAKE_FOCUS 0x2
175 #define STATE_WITHDRAWN 0
176 #define STATE_NORMAL 1
177 #define STATE_ICONIC 3
179 struct gwm_window {
180 xcb_window_t w;
181 int screen;
182 enum _gwm_window_type {
183 WINDOW_ROOT, WINDOW_MANAGED, WINDOW_FRAME, WINDOW_BUTTON, WINDOW_FAKE,
184 WINDOW_FEEDBACK, WINDOW_INCOMPLETE
185 } type;
186 xcb_rectangle_t update; /* the area which needs updating */
187 int cleared; /* TRUE if the update area has already been cleared */
188 union _gwm_window_union {
189 struct _gwm_managed {
190 struct gwm_window *frame;
191 uint16_t border_width;
192 xcb_colormap_t cmap;
193 /* from WM_COLORMAP_WINDOWS: */
194 xcb_window_t cmap_window;
195 /* from WM_HINTS: */
196 int hints; /* see HINT_* above */
197 /* from WM_NAME: */
198 char *name; /* must be free()d */
199 /* from WM_NORMAL_HINTS: */
200 int min_width, min_height, max_width, max_height, width_inc,
201 height_inc, min_aspect_x, min_aspect_y, max_aspect_x,
202 max_aspect_y, base_width, base_height, win_gravity;
203 /* from WM_PROTOCOLS: */
204 int protocols; /* see PROTOCOL_* above */
205 /* WM_STATE: */
206 int state; /* see STATE_* above */
207 } managed;
208 struct _gwm_frame {
209 struct gwm_window *child, *button;
210 int x, y, width, height;
211 } frame;
212 struct _gwm_button {
213 struct gwm_window *frame;
214 } button;
215 struct _gwm_fake {
216 xcb_timestamp_t timestamp;
217 } fake;
218 struct _gwm_feedback {
219 int fb_width, fb_height;
220 } feedback;
221 struct _gwm_incomplete {
222 unsigned int sequence;
223 } incomplete;
224 } u;
227 extern struct gwm_window *fake_window; /* a window created solely to hold the
228 WM_Sn selections */
229 extern struct gwm_window *focus_frame; /* the WINDOW_FRAME which has the
230 focus, if any */
232 extern const char *argv0;
234 union callback_param {
235 long l;
236 void *p;
239 /* Schedule a callback function to be invoked when a reply or error is
240 available for handling, or when neither can arrive. */
241 extern void handle_async_reply( unsigned int sequence,
242 void ( *callback )( unsigned int sequence,
243 void *reply,
244 xcb_generic_error_t *error,
245 union callback_param p ),
246 union callback_param p );
247 /* Block until the scheduled callback function has completed. */
248 extern void sync_with_callback( unsigned int sequence );
250 #define ERR_MASK_REQUEST 0x000001
251 #define ERR_MASK_VALUE 0x00002
252 #define ERR_MASK_WINDOW 0x00004
253 #define ERR_MASK_PIXMAP 0x00008
254 #define ERR_MASK_ATOM 0x00010
255 #define ERR_MASK_CURSOR 0x00020
256 #define ERR_MASK_FONT 0x00040
257 #define ERR_MASK_MATCH 0x00080
258 #define ERR_MASK_DRAWABLE 0x00100
259 #define ERR_MASK_ACCESS 0x00200
260 #define ERR_MASK_ALLOC 0x00400
261 #define ERR_MASK_COLORMAP 0x00800
262 #define ERR_MASK_G_CONTEXT 0x01000
263 #define ERR_MASK_ID_CHOICE 0x02000
264 #define ERR_MASK_NAME 0x04000
265 #define ERR_MASK_LENGTH 0x08000
266 #define ERR_MASK_IMPLEMENTATION 0x10000
268 extern void handle_error_reply( xcb_void_cookie_t cookie, unsigned ignore );
269 extern void show_error( xcb_generic_error_t *error );
271 typedef void ( *event_handler )( struct gwm_window *window,
272 xcb_generic_event_t *ev );
274 /* Return TRUE iff an event is the only button pressed (and so would
275 initiate a passive grab). */
276 extern CONST int initial_press( xcb_button_press_event_t *ev );
278 /* Return TRUE iff an event is the release of the last button (and so would
279 terminate a passive grab). */
280 extern CONST int final_release( xcb_button_release_event_t *ev );
282 /* The window which has the pointer automatically grabbed via a button
283 press, or XCB_NONE. */
284 extern xcb_window_t passive_grab;
286 /* Install a window's colormap on a screen, or the default colormap if
287 unspecified. */
288 extern void install_window_colormap( int screen, struct gwm_window *window,
289 xcb_timestamp_t t );
291 extern void translate_child_to_frame( int *fx, int *fy, int *fwidth,
292 int *fheight, int cx, int cy,
293 int cwidth, int cheight,
294 int cborder, int win_gravity );
296 extern void translate_frame_to_child( int *cx, int *cy, int fx, int fy,
297 int cborder, int win_gravity );
299 extern void apply_size_constraints( struct gwm_window *window, int *width,
300 int *height );
302 extern void generic_expose( struct gwm_window *window,
303 xcb_expose_event_t *ev );
305 extern void deactivate_focus_frame( void );
307 extern void iconic_to_normal( struct gwm_window *window );
309 extern void manage_window( xcb_window_t w, int map_request );
310 extern void unmanage_window( struct gwm_window *window );
312 /* A replacement for xcb_wait_for_event (which is broken, because it
313 always restarts interrupted system calls). Also invokes any
314 asynchronous callbacks scheduled for replies and errors. */
315 extern xcb_generic_event_t *wait_for_event( void );
317 #define FRAME_X_BORDER 1 /* X border added to all four sides of frame */
318 #define FRAME_BORDER_WIDTH 2 /* pixels added to left, right and bottom;
319 includes padding but excludes X border */
320 #define FRAME_TITLE_HEIGHT 16 /* pixels added to top; includes title
321 bar but excludes X border */
322 #define FRAME_BUTTON_SIZE 12 /* size of buttons in title bar; excludes
323 X border */
324 #define FEEDBACK_WIDTH 96 /* width of size feedback window */
325 #define FEEDBACK_HEIGHT 24 /* height of size feedback window */
327 #endif