A tiling window manager
1/*
2 * our datatypes and global variables
3 * Copyright (C) 2000, 2001, 2002, 2003, 2004 Shawn Betts <sabetts@vcn.bc.ca>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place, Suite 330, Boston, MA 02111-1307 USA.
18 */
19
20#ifndef _SDORFEHS_DATA_H
21#define _SDORFEHS_DATA_H
22
23#include "linkedlist.h"
24#include "number.h"
25
26#include <X11/X.h>
27#include <X11/Xlib.h>
28#include <X11/Xutil.h>
29#include <X11/Xft/Xft.h>
30
31typedef struct rp_window rp_window;
32typedef struct rp_screen rp_screen;
33typedef struct rp_global_screen rp_global_screen;
34typedef struct rp_vscreen rp_vscreen;
35typedef struct rp_action rp_action;
36typedef struct rp_keymap rp_keymap;
37typedef struct rp_frame rp_frame;
38typedef struct rp_child_info rp_child_info;
39typedef struct rp_window_elem rp_window_elem;
40typedef struct rp_completions rp_completions;
41typedef struct rp_input_line rp_input_line;
42
43enum rp_edge {
44 EDGE_TOP = (1 << 1),
45 EDGE_LEFT = (1 << 2),
46 EDGE_RIGHT = (1 << 3),
47 EDGE_BOTTOM = (1 << 4),
48};
49
50struct rp_frame {
51 rp_vscreen *vscreen;
52
53 int number;
54 int x, y, width, height;
55
56 /* The number of the window that is focused in this frame. */
57 int win_number;
58
59 /* The number of the window to focus when restoring this frame. */
60 int restore_win_number;
61
62 /* For determining the last frame. */
63 int last_access;
64
65 /*
66 * Boolean that is set when a frame is `dedicated' (a.k.a. glued) to
67 * one window.
68 */
69 unsigned int dedicated;
70
71 /* Whether this frame is touching an edge before a screen update */
72 enum rp_edge edges;
73
74 struct list_head node;
75};
76
77struct rp_window {
78 rp_vscreen *vscreen;
79 Window w;
80 int state;
81 int last_access;
82 int named;
83
84 /*
85 * A number uniquely identifying this window. This is a different
86 * number than the one given to it by the vscreen it is in. This number
87 * is used for internal purposes, whereas the vscreen number is what
88 * the user sees.
89 */
90 int number;
91
92 /* Window name hints. */
93 char *user_name;
94 char *wm_name;
95 char *res_name;
96 char *res_class;
97
98 /* Dimensions */
99 int x, y, width, height, border, full_screen;
100
101 /* WM Hints */
102 XSizeHints *hints;
103
104 /* Colormap */
105 Colormap colormap;
106
107 /* Is this a transient window? */
108 int transient;
109 Window transient_for;
110
111 /* Saved mouse position */
112 int mouse_x, mouse_y;
113
114 /*
115 * The alignment of the window. Decides to what side or corner the
116 * window sticks to.
117 */
118 int gravity;
119
120 /*
121 * A window can be visible inside a frame but not the frame's current
122 * window. This keeps track of what frame the window was mapped into.
123 */
124 int frame_number;
125
126 /* The frame number we want to remain in */
127 int sticky_frame;
128
129 /*
130 * Sometimes a window is intended for a certain frame. When a window is
131 * mapped and this is >0 then use the frame (if it exists).
132 */
133 int intended_frame_number;
134
135 struct list_head node;
136};
137
138struct rp_window_elem {
139 rp_window *win;
140 int number;
141 struct list_head node;
142};
143
144struct rp_global_screen {
145 Window root, wm_check;
146 unsigned long fgcolor, bgcolor, fwcolor, bwcolor, bar_bordercolor;
147
148 /* This numset is responsible for giving out numbers for each screen */
149 struct numset *numset;
150
151 /* The path to and open fd of our control socket */
152 char *control_socket_path;
153 int control_socket_fd;
154
155 /* The path to and open fd of our bar FIFO */
156 char *bar_fifo_path;
157 int bar_fifo_fd;
158};
159
160struct xrandr_info {
161 int output;
162 int crtc;
163 int primary;
164 char *name;
165};
166
167struct rp_vscreen {
168 rp_screen *screen;
169
170 /* Virtual screen number, handled by rp_screen's vscreens_numset */
171 int number;
172
173 /* Name */
174 char *name;
175
176 /* For determining the last vscreen. */
177 int last_access;
178
179 /*
180 * A list of frames that may or may not contain windows. There should
181 * always be one in the list.
182 */
183 struct list_head frames;
184
185 /* Keep track of which numbers have been given to frames. */
186 struct numset *frames_numset;
187
188 /*
189 * The number of the currently focused frame. One for each vscreen so
190 * when you switch vscreens the focus doesn't get frobbed.
191 */
192 int current_frame;
193
194 /* The list of windows participating in this vscreen. */
195 struct list_head mapped_windows, unmapped_windows;
196
197 /*
198 * This numset is responsible for giving out numbers for each window in
199 * the vscreen.
200 */
201 struct numset *numset;
202
203 struct list_head node;
204};
205
206struct rp_font {
207 char *name;
208 XftFont *font;
209};
210
211struct rp_screen {
212 GC normal_gc, inverse_gc;
213 Window root, bar_window, key_window, input_window, frame_window,
214 help_window;
215 int bar_is_raised;
216 int screen_num; /* Our screen number as dictated by X */
217 Colormap def_cmap;
218 Cursor rat;
219
220 /* Screen number, handled by rp_global_screen numset */
221 int number;
222
223 struct xrandr_info xrandr;
224
225 /* Here to abstract over the Xrandr vs X screens difference */
226 int left, top, width, height;
227
228 char *display_string;
229
230 /* Used by sfrestore */
231 struct sbuf *scratch_buffer;
232
233 XftFont *xft_font;
234 struct rp_font xft_font_cache[5];
235 XftColor xft_fgcolor, xft_bgcolor;
236
237 struct list_head vscreens;
238 struct numset *vscreens_numset;
239 rp_vscreen *current_vscreen;
240
241 rp_window *full_screen_win;
242
243 struct sbuf *bar_text;
244
245 /* This structure can exist in a list. */
246 struct list_head node;
247};
248
249struct rp_action {
250 KeySym key;
251 unsigned int state;
252 char *data; /* misc data to be passed to the function */
253 /* void (*func)(void *); */
254};
255
256struct rp_keymap {
257 char *name;
258 rp_action *actions;
259 int actions_last;
260 int actions_size;
261
262 /* This structure can be part of a list. */
263 struct list_head node;
264};
265
266struct rp_key {
267 KeySym sym;
268 unsigned int state;
269};
270
271struct rp_defaults {
272 /*
273 * Default positions for new normal windows, transient windows, and
274 * normal windows with maxsize hints.
275 */
276 int win_gravity;
277 int trans_gravity;
278 int maxsize_gravity;
279
280 int input_window_size;
281 int window_border_width;
282 int only_border;
283
284 int bar_x_padding;
285 int bar_y_padding;
286 int bar_location;
287 int bar_timeout;
288 int bar_border_width;
289 int bar_in_padding;
290 int bar_sticky;
291
292 int frame_indicator_timeout;
293 int frame_resize_unit;
294
295 int padding_left;
296 int padding_right;
297 int padding_top;
298 int padding_bottom;
299
300 char *font_string;
301
302 char *fgcolor_string;
303 char *bgcolor_string;
304 char *fwcolor_string;
305 char *bwcolor_string;
306 char *barbordercolor_string;
307
308 int wait_for_key_cursor;
309
310 char *window_fmt;
311 char *info_fmt;
312 char *sticky_fmt;
313 char *resize_fmt;
314
315 /* Which name to use: wm_name, res_name, res_class. */
316 int win_name;
317
318 int startup_message;
319
320 /*
321 * Decides whether the window list is displayed in a row or a column.
322 */
323 int window_list_style;
324
325 /* Pointer warping toggle. */
326 int warp;
327
328 int history_size;
329 /* remove older history when adding the same again */
330 int history_compaction;
331 /* expand ! when compiled with libhistory */
332 int history_expansion;
333
334 char *frame_selectors;
335
336 /* How many frame sets to remember when undoing. */
337 int maxundos;
338
339 /* The name of the top level keymap */
340 char *top_kmap;
341
342 /* Frame indicator format */
343 char *frame_fmt;
344
345 /* Number of virtual screens */
346 int vscreens;
347
348 /* Window gap */
349 int gap;
350
351 /* Whether to ignore window size hints */
352 int ignore_resize_hints;
353
354 /* New mapped window always uses current vscreen */
355 int win_add_cur_vscreen;
356};
357
358/* Information about a child process. */
359struct rp_child_info {
360 /* The command that was executed. */
361 char *cmd;
362
363 /* PID of the process. */
364 int pid;
365
366 /* Return status when the child process finished. */
367 int status;
368
369 /* When this is != 0 then the process finished. */
370 int terminated;
371
372 /* what was current when it was launched? */
373 rp_frame *frame;
374 rp_screen *screen;
375 rp_vscreen *vscreen;
376
377 /*
378 * Non-zero when the pid has mapped a window. This is to prevent every
379 * window the program opens from getting mapped in the frame it was
380 * launched from. Only the first window should do this.
381 */
382 int window_mapped;
383
384 /* This structure can exist in a list. */
385 struct list_head node;
386};
387
388/*
389 * These defines should be used to specify the modifier mask for keys and they
390 * are translated into the X11 modifier mask when the time comes to compare
391 * modifier masks.
392 */
393#define RP_SHIFT_MASK 1
394#define RP_CONTROL_MASK 2
395#define RP_META_MASK 4
396#define RP_ALT_MASK 8
397#define RP_SUPER_MASK 16
398#define RP_HYPER_MASK 32
399
400struct modifier_info {
401 /* unsigned int mode_switch_mask; */
402 unsigned int meta_mod_mask;
403 unsigned int alt_mod_mask;
404 unsigned int super_mod_mask;
405 unsigned int hyper_mod_mask;
406
407 /*
408 * Keep track of these because they mess up the grab and should be
409 * ignored.
410 */
411 unsigned int num_lock_mask;
412 unsigned int scroll_lock_mask;
413};
414
415typedef struct list_head *(*completion_fn) (char *string);
416
417/*
418 BASIC: The completion shall begin with the same characters as the partial
419 string. Case is ignored.
420
421 SUBSTRING: The partial string shall be a subpart of the completion. Case
422 is ignored.
423*/
424enum completion_styles {
425 BASIC,
426 SUBSTRING
427};
428
429struct rp_completions {
430 /*
431 * A pointer to the partial string that is being completed. We need to
432 * store this so that the user can cycle through all possible
433 * completions.
434 */
435 char *partial;
436
437 /*
438 * A pointer to the string that was last matched string. Used to keep
439 * track of where we are in the completion list.
440 */
441 struct sbuf *last_match;
442
443 /* A list of sbuf's which are possible completions. */
444 struct list_head completion_list;
445
446 /* The function that generates the completions. */
447 completion_fn complete_fn;
448
449 /*
450 * virgin = 1 means no completions have been attempted on the input
451 * string.
452 */
453 unsigned short int virgin;
454
455 /* The completion style used to perform string comparisons */
456 enum completion_styles style;
457};
458
459struct rp_input_line {
460 char *buffer;
461 char *prompt;
462 char *saved;
463 size_t position;
464 size_t length;
465 size_t size;
466 rp_completions *compl;
467 Atom selection;
468 int history_id;
469};
470
471/* The hook dictionary. */
472struct rp_hook_db_entry {
473 char *name;
474 struct list_head *hook;
475};
476
477typedef struct rp_xselection rp_xselection;
478struct rp_xselection {
479 char *text;
480 int len;
481};
482
483#endif /* _SDORFEHS_DATA_H */