summaryrefslogtreecommitdiff
path: root/gwm.h
blob: d1d17ca8e34d74c55f352fa659a8a764266fd0ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#ifndef _GWM_H_
#define _GWM_H_

#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif

#if !defined(__GNUC__) && !defined(__attribute__)
#define __attribute__()
#endif

#ifndef CONST
#define CONST __attribute__((const))
#endif

#ifndef FORMAT
#define FORMAT( archetype, string_index, first_to_check ) \
    __attribute__((format( archetype, string_index, first_to_check ) ))
#endif

#ifndef MALLOC
#define MALLOC __attribute__((malloc))
#endif

#ifndef NORETURN
#define NORETURN __attribute__((noreturn))
#endif

#ifndef PURE
#define PURE __attribute__((pure))
#endif

#define SEND_EVENT_MASK 0x80

extern MALLOC void *xmalloc( size_t size );
extern void *xrealloc( void *p, size_t size );
extern MALLOC void *xcalloc( size_t number, size_t size );

enum _extended_event_type {
    SYNTHETIC_EVENT = XCB_MAPPING_NOTIFY + 1,
    SHAPE_NOTIFY
};

extern xcb_connection_t *c;
extern xcb_timestamp_t latest_timestamp;

enum x_atom {
    /* See X Window System Protocol (version 11, release 6.7), Appendix B. */
    ATOM = 4,
    INTEGER = 19,
    RGB_COLOR_MAP = 24,
    RGB_DEFAULT_MAP = 27,
    STRING = 31,
    WINDOW = 33,
    WM_HINTS = 35,
    WM_ICON_NAME = 37,
    WM_NAME = 39,
    WM_NORMAL_HINTS = 40,
    WM_SIZE_HINTS = 41
};

enum gwm_atom {
    ATOM_COMPOUND_TEXT,
    ATOM_MANAGER,
    ATOM__MOTIF_WM_HINTS,
    ATOM__NET_WM_NAME,
    ATOM_UTF8_STRING,
    ATOM_VERSION,
    ATOM_WM_CHANGE_STATE,
    ATOM_WM_COLORMAP_NOTIFY,
    ATOM_WM_COLORMAP_WINDOWS,
    ATOM_WM_DELETE_WINDOW,
    ATOM_WM_PROTOCOLS,
    ATOM_WM_STATE,
    ATOM_WM_TAKE_FOCUS,
    NUM_ATOMS
};

extern xcb_atom_t atoms[ NUM_ATOMS ];

enum gwm_property_type {
    PROP__MOTIF_WM_HINTS,
    PROP__NET_WM_NAME,
    PROP_WM_COLORMAP_WINDOWS,
    PROP_WM_HINTS,
    PROP_WM_NAME,
    PROP_WM_NORMAL_HINTS,
    PROP_WM_PROTOCOLS,
    NUM_PROPS
};

#define PROP_SIZE 64 /* maximum number of 32-bit words to retrieve */

extern xcb_atom_t prop_atoms[ NUM_PROPS ];
extern xcb_atom_t prop_types[ NUM_PROPS ];

enum gwm_extension {
#if USE_COMPOSITE
    EXT_COMPOSITE,
#endif
#if USE_DAMAGE
    EXT_DAMAGE,
#endif
#if USE_RENDER
    EXT_RENDER,
#endif
#if USE_SHAPE
    EXT_SHAPE, /* any version */
#endif
#if USE_XFIXES
    EXT_XFIXES, /* requires version 2 */
#endif
    NUM_EXTENSIONS
};

#if USE_COMPOSITE || USE_DAMAGE || USE_RENDER || USE_SHAPE || USE_FIXES
#define EXTENSIONS_SIZE NUM_EXTENSIONS
#else
#define EXTENSIONS_SIZE 1 /* avoid zero length arrays */
#endif

extern int have_extension[ EXTENSIONS_SIZE ];
extern uint8_t extension_event[ EXTENSIONS_SIZE ],
    extension_error[ EXTENSIONS_SIZE ];

#if USE_RENDER && defined( XCB_RENDER_MAJOR_VERSION )
extern xcb_render_pictformat_t fmt_rgba8, fmt_a8;
extern xcb_render_directformat_t dfmt_rgba8, dfmt_a8;
#endif

enum decoration_col {
    COL_FRAME_ACTIVE,
    COL_FRAME_INACTIVE,
    COL_BORDER,
    COL_BUTTON_ACTIVE,
    COL_BUTTON_INACTIVE,
    COL_TITLE_ACTIVE,
    COL_TITLE_INACTIVE,
    COL_FEEDBACK_BACK,
    COL_FEEDBACK_FORE,
    NUM_COLS
};

extern int num_screens;
extern xcb_screen_t **screens;

struct gwm_screen {
    xcb_visualtype_t *root_visual;
    xcb_atom_t wm_atom; /* the atom WM_Sn, where n is the screen number */
    xcb_colormap_t cmap; /* the most recently installed colormap */
    xcb_timestamp_t cmap_time; /* the time at which it was installed */
    uint32_t pixels[ NUM_COLS ]; /* pixel values in the default cmap */
#if USE_RENDER
    uint32_t root_pictformat;
#endif
};

extern struct gwm_screen *gwm_screens;

enum border_region {
    BR_TL,
    BR_T,
    BR_TR,
    BR_L,
    BR_R,
    BR_BL,
    BR_B,
    BR_BR,
    NUM_BORDER_REGIONS
};

enum gwm_cursor {
    CURSOR_TL,
    CURSOR_T,
    CURSOR_TR,
    CURSOR_L,
    CURSOR_C,
    CURSOR_R,
    CURSOR_BL,
    CURSOR_B,
    CURSOR_BR,
    CURSOR_ARROW,
    CURSOR_DESTROY,
    NUM_CURSORS
};
extern xcb_cursor_t cursors[ NUM_CURSORS ];

#define HINT_ICONIC 0x1 /* otherwise normal */
#define HINT_INPUT 0x2
#define HINT_USER_POSITION 0x4
#define HINT_PROGRAM_POSITION 0x8
#define HINT_POSITION 0xC /* HINT_USER_POSITION | HINT_PROGRAM_POSITION */
#define PROTOCOL_DELETE_WINDOW 0x1
#define PROTOCOL_TAKE_FOCUS 0x2

#define STATE_WITHDRAWN 0
#define STATE_NORMAL 1
#define STATE_ICONIC 3

#define DEC_BORDER 0x1
#define DEC_TITLE 0x2
#define DEC_DEFAULT ( DEC_BORDER | DEC_TITLE )

struct gwm_window {
    xcb_window_t w;
    int screen;
    enum _gwm_window_type {
	WINDOW_ROOT, WINDOW_MANAGED, WINDOW_FRAME, WINDOW_BUTTON, WINDOW_FAKE,
	WINDOW_FEEDBACK, WINDOW_INCOMPLETE, WINDOW_CHILDLESS
    } type;
    xcb_rectangle_t update; /* the area which needs updating */
    int cleared; /* TRUE if the update area has already been cleared */
    union _gwm_window_union {
	struct _gwm_managed {
	    struct gwm_window *frame;
	    uint16_t border_width;
	    xcb_colormap_t cmap;
#if USE_SHAPE
	    int shaped;
#endif
	    /* from WM_COLORMAP_WINDOWS: */
	    xcb_window_t cmap_window;
	    /* from WM_HINTS: */
	    int hints; /* see HINT_* above */
	    /* from WM_NAME and _NET_WM_NAME: */
	    char *name; /* must be free()d */
	    int net_wm_name;
	    /* from WM_NORMAL_HINTS: */
	    int min_width, min_height, max_width, max_height, width_inc,
		height_inc, min_aspect_x, min_aspect_y, max_aspect_x,
		max_aspect_y, base_width, base_height, win_gravity;
	    /* from WM_PROTOCOLS: */
	    int protocols; /* see PROTOCOL_* above */
	    /* WM_STATE: */
	    int state; /* see STATE_* above */
	} managed;
	struct _gwm_frame {
	    struct gwm_window *child, *button;
	    int x, y, width, height;
	    int decoration; /* see DEC_* above */
	    xcb_window_t border_regions[ NUM_BORDER_REGIONS ];
	} frame;
	struct _gwm_button {
	    struct gwm_window *frame;
	} button;
	struct _gwm_fake {
	    xcb_timestamp_t timestamp;	    
	} fake;
	struct _gwm_feedback {
	    int fb_width, fb_height;
	} feedback;
	struct _gwm_incomplete {
	    unsigned int sequence;
	} incomplete;
    } u;
};

extern struct gwm_window *fake_window; /* a window created solely to hold the
					  WM_Sn selections */

extern const char *argv0;

extern FORMAT( printf, 1, 2 ) void warning( char *format, ... );
extern FORMAT( printf, 1, 2 ) NORETURN void fatal( char *format, ... );
    
union callback_param {
    long l;
    void *p;
};

/* Schedule a callback function to be invoked when a reply or error is
   available for handling, or when neither can arrive. */
extern void handle_async_reply( unsigned int sequence,
				void ( *callback )( unsigned int sequence,
						    void *reply,
						    xcb_generic_error_t *error,
						    union callback_param p ),
				union callback_param p );
/* Block until the scheduled callback function has completed. */
extern void sync_with_callback( unsigned int sequence );

#define ERR_MASK_REQUEST 0x000001
#define ERR_MASK_VALUE 0x00002
#define ERR_MASK_WINDOW 0x00004
#define ERR_MASK_PIXMAP 0x00008
#define ERR_MASK_ATOM 0x00010
#define ERR_MASK_CURSOR 0x00020
#define ERR_MASK_FONT 0x00040
#define ERR_MASK_MATCH 0x00080
#define ERR_MASK_DRAWABLE 0x00100
#define ERR_MASK_ACCESS 0x00200
#define ERR_MASK_ALLOC 0x00400
#define ERR_MASK_COLORMAP 0x00800
#define ERR_MASK_G_CONTEXT 0x01000
#define ERR_MASK_ID_CHOICE 0x02000
#define ERR_MASK_NAME 0x04000
#define ERR_MASK_LENGTH 0x08000
#define ERR_MASK_IMPLEMENTATION 0x10000

extern void handle_error_reply( xcb_void_cookie_t cookie, unsigned ignore );
extern void show_error( xcb_generic_error_t *error );

typedef void ( *event_handler )( struct gwm_window *window,
				 xcb_generic_event_t *ev );

/* Return TRUE iff an event is the only button pressed. */
extern CONST int initial_press( xcb_button_press_event_t *ev );

/* Return TRUE iff an event is the release of the last button (and so would
   terminate a passive grab). */
extern CONST int final_release( xcb_button_release_event_t *ev );

/* The window whose event handler(s) should be invoked for pointer events.
   Unlike pointer grabs, this mechanism is implemented entirely on the
   client side, and has no effect on the contents of events. */
extern xcb_window_t pointer_demux;

/* Install a window's colormap on a screen, or the default colormap if
   unspecified. */
extern void install_window_colormap( int screen, struct gwm_window *window,
				     xcb_timestamp_t t );

extern void generic_expose( struct gwm_window *window,
			    xcb_expose_event_t *ev );

extern void iconic_to_normal( struct gwm_window *window );

extern void manage_window( xcb_window_t w, int map_request );
extern void unmanage_window( struct gwm_window *window );

/* A replacement for xcb_wait_for_event (which is broken, because it
   always restarts interrupted system calls).  Also invokes any
   asynchronous callbacks scheduled for replies and errors. */
extern xcb_generic_event_t *wait_for_event( void );

#define FEEDBACK_WIDTH 96 /* width of size feedback window */
#define FEEDBACK_HEIGHT 24 /* height of size feedback window */

#endif