summaryrefslogtreecommitdiff
path: root/src/libcompositewm/xcwm_internal.h
blob: 94081c7414e247487db2524db5b1f570d48ffe49 (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
/* Copyright (c) 2012 Jess VanDerwalker <washu@sonic.net>
 * All rights reserved.
 *
 * xcwm_internal.h
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef _XTOQ_INTERNAL_H_
#define _XTOQ_INTERNAL_H_

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <xcb/xcb.h>
#include <xcb/xcb_image.h>
#include <xcb/xcb_icccm.h>
#include <xcb/xcb_atom.h>
#include <xcwm/xcwm.h>

#include "data.h"

/**
 * Strucuture used to pass nesessary data to xcwm_start_event_loop.
 */
typedef struct xcwm_event_connetion {
	xcb_connection_t *conn;	          /* Connection to listen to events on */
	xcwm_event_cb_t event_callback;   /* Fuction to call when event caught */
} xcwm_event_connection;

/**
 * Structure to hold WM_* atoms that we care about
 */
typedef struct xcwm_wm_atoms {
    xcb_atom_t wm_protocols_atom;
    xcb_atom_t wm_delete_window_atom;
} xcwm_wm_atoms;

/**
 * Global for the atoms needed
 */
extern xcwm_wm_atoms *_wm_atoms;

/**
 * Mutex lock supplied to client to lock event loop thread
 */
extern pthread_mutex_t event_thread_lock;

/* util.c */

/**
 * Return the given windows attributes reply. Caller must free memory
 * allocated for reply.
 * @param conn The windows connection.
 * @param window The window.
 * @return The window attributes reply. Null if the request fails.
 */
xcb_get_window_attributes_reply_t *
_xcwm_get_window_attributes (xcb_connection_t *conn, xcb_window_t window);

/**
 * Return the geometry of the window in a geometry reply. Caller must free
 * memory allocated for reply.
 * @param conn The windows connection.
 * @param window The window.
 * @return The window's geometry reply. Null if the request for reply fails.
 */
xcb_get_geometry_reply_t *
_xcwm_get_window_geometry (xcb_connection_t *conn, xcb_window_t window);

/**
 * Print out information about the existing windows attached to our
 * root. Most of this code is taken from src/manage.c from the i3 code
 * by Michael Stapelberg
 * @param conn a connection the the xserver.
 * @param window the window.
 * @return the geometry of the window
 */
void
_xcwm_write_all_children_window_info (xcb_connection_t *conn,
								 xcb_window_t root);

/**
 * Get the image data for a window.
 * @param conn the connection to the xserver.
 * @param root the window acenstral to all children to be written.
 * @return a structure containing data and data length.
 */
image_data_t
_xcwm_get_window_image_data (xcb_connection_t *conn, xcb_window_t window);

/**
 * Write information about a window out to stdio.
 * TODO: Add the ability to pass in the stream to write to.
 * @param conn The connection with the window.
 * @param window The window.
 */
void
_xcwm_write_window_info (xcb_connection_t *conn, xcb_window_t window);

/**
 * Check the request cookie and determine if there is an error.
 * @param conn The connection the request was sent on.
 * @param cookie The cookie returned by the request.
 * @param msg the string to display if there is an error with the request.
 * @return int The number of the error code, if any. Otherwise zero.
 */
int
_xcwm_request_check (xcb_connection_t *conn, xcb_void_cookie_t cookie,
              char *msg);

/****************
 * init.c
 ****************/

/**
 * Initializes an extension on the xserver.
 * @param conn The connection to the xserver.
 * @param extension_name The string specifying the name of the extension.
 * @return The reply structure
 */
xcb_query_extension_reply_t * 
_xcwm_init_extension(xcb_connection_t *conn, char *extension_name);

/**
 * Initializes damage on a window contained in a context.
 * The context will likely contain the root window.
 * @param contxt A context containing a window 
 */
void 
_xcwm_init_damage(xcwm_context_t *contxt);

/**
 * Initializes the composite extension on the context containg
 * the root window.
 * @param contxt The contxt containing the root window
 */
void 
_xcwm_init_composite(xcwm_context_t *contxt);

/**
 * Initialize the xfixes extension.
 * @param contxt The context
 */
void
_xcwm_init_xfixes (xcwm_context_t *contxt);

/**
 * Get the values for the WM_* atoms that we need.
 * @param contxt The context
 */
void
_xcwm_get_wm_atoms (xcwm_context_t *contxt);

/****************
 * event_loop.c
 ****************/

/**
 * Starts the event loop thread which listens on the given connection and
 * calls event_callback if an event is caught.
 * @param *conn The connection to listen for X events on
 * @param event_callback The callback function to call when a event is caught.
 * @return 0 on success, nonzero on failure.
 */
int
_xcwm_start_event_loop (xcb_connection_t *conn,
						xcwm_event_cb_t event_callback);

/**
 * Stops the thread running the event loop.
 * @return 0 on success, otherwise zero.
 */
int
_xcwm_stop_event_loop (void);

/****************
 * context_list.c
 ****************/

/**
 * A structure (doubly linked list) to hold
 * pointers to the contexts
 */
typedef struct _xcwm_context_node {
    struct xcwm_context_t *context;   /**< Pointer to a context */
    struct _xcwm_context_node * next; /**< Pointer to the next context node */
    struct _xcwm_context_node * prev; /**< Pointer to the previous context node */
} _xcwm_context_node;

/* this is the head pointer */
extern _xcwm_context_node *_xcwm_window_list_head;

/**
 * Add a newly created context to the context_list.
 * @param context The context to be added to the linked list
 * @return Pointer to context added to the list.
 */
xcwm_context_t * 
_xcwm_add_context_t(struct xcwm_context_t *context);

/**
 * Remove a context to the context_list using the window's id.
 * @param window_id The window_id of the context which should
 * be removed from the context_list
 */
void
_xcwm_remove_context_node(xcb_window_t window_id);

/**
 * Find a context in the doubly linked list using its window_id.
 * @param window_id The window_id of the context which should
 * @return Pointer to context (if found), NULL if not found.
 */
xcwm_context_t *
_xcwm_get_context_node_by_window_id (xcb_window_t window_id);

/****************
 * window.c
 ****************/

/**
 * Create a new context for the window specified in the event.
 * @param conn The connection to xserver
 * @param evt The map event for the window
 * @return Pointer to new context. NULL if window already exists.
 */
xcwm_context_t *
_xcwm_window_created(xcb_connection_t * conn,
									 xcb_map_request_event_t *evt);
/**
 * Destroy the damage object associated with the window. 
 * Call the remove function in context_list.c
 * @param conn The connection to xserver
 * @param event The destroy notify event for the window
 * @return Pointer to the context that was removed from the list, NULL if
 * window isn't being managed by context_list
 */
xcwm_context_t *
_xcwm_destroy_window(xcb_destroy_notify_event_t *event);

/**
 * Resize the window to given width and height.
 * @param conn The connection
 * @param window The id of window to resize
 * @param width The new width
 * @param height The new height
 */
void
_xcwm_resize_window (xcb_connection_t *conn, xcb_window_t window,
					 int width, int height);

/**
 * Map the given window.
 * @param context The context of the window to map
 */
void
_xcwm_map_window (xcwm_context_t *context);

#endif  /* _XTOQ_INTERNAL_H_ */