2 * Copyright (c) 2009-2015 Marco Peereboom <marco@peereboom.us>
3 * Copyright (c) 2009-2011 Ryan McBride <mcbride@countersiege.com>
4 * Copyright (c) 2009 Darrin Chandler <dwchandler@stilyagin.com>
5 * Copyright (c) 2009 Pierre-Yves Ritschard <pyr@spootnik.org>
6 * Copyright (c) 2010 Tuukka Kataja <stuge@xor.fi>
7 * Copyright (c) 2011 Jason L. Wright <jason@thought.net>
8 * Copyright (c) 2011-2015 Reginald Kennedy <rk@rejii.com>
9 * Copyright (c) 2011-2012 Lawrence Teo <lteo@lteo.net>
10 * Copyright (c) 2011-2012 Tiago Cunha <tcunha@gmx.com>
11 * Copyright (c) 2012-2015 David Hill <dhill@mindcry.org>
12 * Copyright (c) 2014-2015 Yuri D'Elia <yuri.delia@eurac.edu>
14 * Permission to use, copy, modify, and distribute this software for any
15 * purpose with or without fee is hereby granted, provided that the above
16 * copyright notice and this permission notice appear in all copies.
18 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
19 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
21 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
23 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
24 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
27 * Much code and ideas taken from dwm under the following license:
28 * MIT/X Consortium License
30 * 2006-2008 Anselm R Garbe <garbeam at gmail dot com>
31 * 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
32 * 2006-2007 Jukka Salmi <jukka at salmi dot ch>
33 * 2007 Premysl Hruby <dfenze at gmail dot com>
34 * 2007 Szabolcs Nagy <nszabolcs at gmail dot com>
35 * 2007 Christof Musik <christof at sendfax dot de>
36 * 2007-2008 Enno Gottox Boland <gottox at s01 dot de>
37 * 2007-2008 Peter Hartlich <sgkkr at hartlich dot com>
38 * 2008 Martin Hurton <martin dot hurton at gmail dot com>
40 * Permission is hereby granted, free of charge, to any person obtaining a
41 * copy of this software and associated documentation files (the "Software"),
42 * to deal in the Software without restriction, including without limitation
43 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
44 * and/or sell copies of the Software, and to permit persons to whom the
45 * Software is furnished to do so, subject to the following conditions:
47 * The above copyright notice and this permission notice shall be included in
48 * all copies or substantial portions of the Software.
50 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
51 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
52 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
53 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
54 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
55 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
56 * DEALINGS IN THE SOFTWARE.
60 #include <sys/types.h>
64 #include <sys/queue.h>
65 #include <sys/param.h>
66 #include <sys/select.h>
67 #if defined(__linux__)
69 #elif defined(__OpenBSD__)
71 #elif defined(__FreeBSD__)
95 #include <X11/cursorfont.h>
96 #include <X11/extensions/Xrandr.h>
97 #include <X11/Xcursor/Xcursor.h>
98 #include <X11/Xft/Xft.h>
99 #include <X11/Xlib-xcb.h>
100 #include <xcb/xcb_atom.h>
101 #include <xcb/xcb_aux.h>
102 #include <xcb/xcb_event.h>
103 #include <xcb/xcb_icccm.h>
104 #include <xcb/xcb_keysyms.h>
105 #include <xcb/xtest.h>
106 #include <xcb/randr.h>
114 #ifdef SPECTRWM_BUILDSTR
115 static const char *buildstr
= SPECTRWM_BUILDSTR
;
117 static const char *buildstr
= SPECTRWM_VERSION
;
120 #if !defined(__CYGWIN__) /* cygwin chokes on randr stuff */
122 # error RandR versions less than 1.0 are not supported
125 # if RANDR_MAJOR >= 1
126 # if RANDR_MINOR >= 2
127 # define SWM_XRR_HAS_CRTC
130 #endif /* __CYGWIN__ */
132 #ifndef XCB_ICCCM_NUM_WM_HINTS_ELEMENTS
133 #define XCB_ICCCM_SIZE_HINT_P_MIN_SIZE XCB_SIZE_HINT_P_MIN_SIZE
134 #define XCB_ICCCM_SIZE_HINT_P_MAX_SIZE XCB_SIZE_HINT_P_MAX_SIZE
135 #define XCB_ICCCM_SIZE_HINT_P_RESIZE_INC XCB_SIZE_HINT_P_RESIZE_INC
136 #define XCB_ICCCM_WM_HINT_INPUT XCB_WM_HINT_INPUT
137 #define XCB_ICCCM_WM_HINT_X_URGENCY XCB_WM_HINT_X_URGENCY
138 #define XCB_ICCCM_WM_STATE_ICONIC XCB_WM_STATE_ICONIC
139 #define XCB_ICCCM_WM_STATE_WITHDRAWN XCB_WM_STATE_WITHDRAWN
140 #define XCB_ICCCM_WM_STATE_NORMAL XCB_WM_STATE_NORMAL
141 #define xcb_icccm_get_text_property_reply_t xcb_get_text_property_reply_t
142 #define xcb_icccm_get_text_property_reply_wipe xcb_get_text_property_reply_wipe
143 #define xcb_icccm_get_wm_class xcb_get_wm_class
144 #define xcb_icccm_get_wm_class_reply xcb_get_wm_class_reply
145 #define xcb_icccm_get_wm_class_reply_t xcb_get_wm_class_reply_t
146 #define xcb_icccm_get_wm_class_reply_wipe xcb_get_wm_class_reply_wipe
147 #define xcb_icccm_get_wm_hints xcb_get_wm_hints
148 #define xcb_icccm_wm_hints_get_urgency xcb_wm_hints_get_urgency
149 #define xcb_icccm_get_wm_hints_reply xcb_get_wm_hints_reply
150 #define xcb_icccm_get_wm_name xcb_get_wm_name
151 #define xcb_icccm_get_wm_name_reply xcb_get_wm_name_reply
152 #define xcb_icccm_get_wm_normal_hints xcb_get_wm_normal_hints
153 #define xcb_icccm_get_wm_normal_hints_reply xcb_get_wm_normal_hints_reply
154 #define xcb_icccm_get_wm_protocols xcb_get_wm_protocols
155 #define xcb_icccm_get_wm_protocols_reply xcb_get_wm_protocols_reply
156 #define xcb_icccm_get_wm_protocols_reply_t xcb_get_wm_protocols_reply_t
157 #define xcb_icccm_get_wm_protocols_reply_wipe xcb_get_wm_protocols_reply_wipe
158 #define xcb_icccm_get_wm_transient_for xcb_get_wm_transient_for
159 #define xcb_icccm_get_wm_transient_for_reply xcb_get_wm_transient_for_reply
160 #define xcb_icccm_wm_hints_t xcb_wm_hints_t
163 /*#define SWM_DEBUG*/
165 #define DPRINTF(x...) do { \
167 fprintf(stderr, x); \
169 #define DNPRINTF(n,x...) do { \
170 if (swm_debug & n) { \
171 fprintf(stderr, "%ld ", (long)(time(NULL) - time_started)); \
172 fprintf(stderr, x); \
175 #define SWM_D_MISC 0x0001
176 #define SWM_D_EVENT 0x0002
177 #define SWM_D_WS 0x0004
178 #define SWM_D_FOCUS 0x0008
179 #define SWM_D_MOVE 0x0010
180 #define SWM_D_STACK 0x0020
181 #define SWM_D_MOUSE 0x0040
182 #define SWM_D_PROP 0x0080
183 #define SWM_D_CLASS 0x0100
184 #define SWM_D_KEY 0x0200
185 #define SWM_D_QUIRK 0x0400
186 #define SWM_D_SPAWN 0x0800
187 #define SWM_D_EVENTQ 0x1000
188 #define SWM_D_CONF 0x2000
189 #define SWM_D_BAR 0x4000
190 #define SWM_D_INIT 0x8000
192 uint32_t swm_debug
= 0
211 #define DPRINTF(x...)
212 #define DNPRINTF(n,x...)
215 #define SWM_EWMH_ACTION_COUNT_MAX (8)
216 #define EWMH_F_FULLSCREEN (0x001)
217 #define EWMH_F_ABOVE (0x002)
218 #define EWMH_F_HIDDEN (0x004)
219 #define EWMH_F_MAXIMIZED_VERT (0x008)
220 #define EWMH_F_MAXIMIZED_HORZ (0x010)
221 #define EWMH_F_SKIP_PAGER (0x020)
222 #define EWMH_F_SKIP_TASKBAR (0x040)
223 #define SWM_F_MANUAL (0x080)
225 #define EWMH_F_MAXIMIZED (EWMH_F_MAXIMIZED_VERT | EWMH_F_MAXIMIZED_HORZ)
227 /* convert 8-bit to 16-bit */
228 #define RGB_8_TO_16(col) (((col) << 8) + (col))
230 #define PIXEL_TO_XRENDERCOLOR(px, xrc) \
231 xrc.red = RGB_8_TO_16((px) >> 16 & 0xff); \
232 xrc.green = RGB_8_TO_16((px) >> 8 & 0xff); \
233 xrc.blue = RGB_8_TO_16((px) & 0xff); \
236 #define LENGTH(x) (int)(sizeof (x) / sizeof (x)[0])
237 #define MODKEY XCB_MOD_MASK_1
238 #define CLEANMASK(mask) ((mask) & ~(numlockmask | XCB_MOD_MASK_LOCK))
239 #define BUTTONMASK (XCB_EVENT_MASK_BUTTON_PRESS | \
240 XCB_EVENT_MASK_BUTTON_RELEASE)
241 #define MOUSEMASK (BUTTONMASK|XCB_EVENT_MASK_POINTER_MOTION)
242 #define SWM_PROPLEN (16)
243 #define SWM_FUNCNAME_LEN (32)
244 #define SWM_KEYS_LEN (255)
245 #define SWM_QUIRK_LEN (64)
246 #define X(r) ((r)->g.x)
247 #define Y(r) ((r)->g.y)
248 #define WIDTH(r) ((r)->g.w)
249 #define HEIGHT(r) ((r)->g.h)
250 #define BORDER(w) ((w)->bordered ? border_width : 0)
251 #define MAX_X(r) ((r)->g.x + (r)->g.w)
252 #define MAX_Y(r) ((r)->g.y + (r)->g.h)
253 #define SH_MIN(w) ((w)->sh.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE)
254 #define SH_MIN_W(w) ((w)->sh.min_width)
255 #define SH_MIN_H(w) ((w)->sh.min_height)
256 #define SH_MAX(w) ((w)->sh.flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE)
257 #define SH_MAX_W(w) ((w)->sh.max_width)
258 #define SH_MAX_H(w) ((w)->sh.max_height)
259 #define SH_INC(w) ((w)->sh.flags & XCB_ICCCM_SIZE_HINT_P_RESIZE_INC)
260 #define SH_INC_W(w) ((w)->sh.width_inc)
261 #define SH_INC_H(w) ((w)->sh.height_inc)
262 #define SWM_MAX_FONT_STEPS (3)
263 #define WINID(w) ((w) ? (w)->id : XCB_WINDOW_NONE)
264 #define WS_FOCUSED(ws) ((ws)->r && (ws)->r->s->r_focus == (ws)->r)
265 #define YESNO(x) ((x) ? "yes" : "no")
266 #define ICONIC(w) ((w)->ewmh_flags & EWMH_F_HIDDEN)
267 #define ABOVE(w) ((w)->ewmh_flags & EWMH_F_ABOVE)
268 #define FULLSCREEN(w) ((w)->ewmh_flags & EWMH_F_FULLSCREEN)
269 #define MAXIMIZED_VERT(w) ((w)->ewmh_flags & EWMH_F_MAXIMIZED_VERT)
270 #define MAXIMIZED_HORZ(w) ((w)->ewmh_flags & EWMH_F_MAXIMIZED_HORZ)
271 #define MAXIMIZED(w) (MAXIMIZED_VERT(w) || MAXIMIZED_HORZ(w))
272 #define MANUAL(w) ((w)->ewmh_flags & SWM_F_MANUAL)
273 #define TRANS(w) ((w)->transient != XCB_WINDOW_NONE)
274 #define FLOATING(w) (ABOVE(w) || TRANS(w) || FULLSCREEN(w) || \
277 /* Constrain Window flags */
278 #define SWM_CW_RESIZABLE (0x01)
279 #define SWM_CW_SOFTBOUNDARY (0x02)
280 #define SWM_CW_HARDBOUNDARY (0x04)
281 #define SWM_CW_RIGHT (0x10)
282 #define SWM_CW_LEFT (0x20)
283 #define SWM_CW_BOTTOM (0x40)
284 #define SWM_CW_TOP (0x80)
285 #define SWM_CW_ALLSIDES (0xf0)
287 #define SWM_FOCUS_DEFAULT (0)
288 #define SWM_FOCUS_FOLLOW (1)
289 #define SWM_FOCUS_MANUAL (2)
291 #define SWM_CK_NONE (0)
292 #define SWM_CK_ALL (0xf)
293 #define SWM_CK_FOCUS (0x1)
294 #define SWM_CK_POINTER (0x2)
295 #define SWM_CK_FALLBACK (0x4)
296 #define SWM_CK_REGION (0x8)
298 #define SWM_G_ALL (0xf)
299 #define SWM_G_SIZE (0x1)
300 #define SWM_G_POS (0x2)
302 #define SWM_CONF_DEFAULT (0)
303 #define SWM_CONF_KEYMAPPING (1)
306 #define SWM_LIB "/usr/local/lib/libswmhack.so"
313 xcb_atom_t a_net_wm_check
;
314 xcb_atom_t a_net_supported
;
315 xcb_atom_t a_takefocus
;
316 xcb_atom_t a_utf8_string
;
318 volatile sig_atomic_t running
= 1;
319 volatile sig_atomic_t restart_wm
= 0;
320 xcb_timestamp_t last_event_time
= 0;
324 unsigned int numlockmask
= 0;
327 xcb_connection_t
*conn
;
328 xcb_key_symbols_t
*syms
;
330 int boundary_width
= 50;
331 bool cycle_empty
= false;
332 bool cycle_visible
= false;
334 int font_adjusted
= 0;
335 unsigned int mod_key
= MODKEY
;
336 bool warp_focus
= false;
337 bool warp_pointer
= false;
338 bool workspace_clamp
= false;
341 struct swm_region
*search_r
;
342 int select_list_pipe
[2];
343 int select_resp_pipe
[2];
345 volatile sig_atomic_t search_resp
;
346 int search_resp_action
;
348 struct search_window
{
349 TAILQ_ENTRY(search_window
) entry
;
353 xcb_window_t indicator
;
355 TAILQ_HEAD(search_winlist
, search_window
);
356 struct search_winlist search_wl
;
361 SWM_SEARCH_UNICONIFY
,
362 SWM_SEARCH_NAME_WORKSPACE
,
363 SWM_SEARCH_SEARCH_WORKSPACE
,
364 SWM_SEARCH_SEARCH_WINDOW
367 #define SWM_STACK_TOP (0)
368 #define SWM_STACK_BOTTOM (1)
369 #define SWM_STACK_ABOVE (2)
370 #define SWM_STACK_BELOW (3)
373 double dialog_ratio
= 0.6;
375 #define SWM_BAR_MAX (256)
376 #define SWM_BAR_JUSTIFY_LEFT (0)
377 #define SWM_BAR_JUSTIFY_CENTER (1)
378 #define SWM_BAR_JUSTIFY_RIGHT (2)
379 #define SWM_BAR_OFFSET (4)
380 #define SWM_BAR_FONTS "-*-terminus-medium-*-*-*-12-*-*-*-*-*-*-*," \
381 "-*-profont-*-*-*-*-12-*-*-*-*-*-*-*," \
382 "-*-times-medium-r-*-*-12-*-*-*-*-*-*-*," \
383 "-misc-fixed-medium-r-*-*-12-*-*-*-*-*-*-*," \
384 "-*-*-*-r-*-*-*-*-*-*-*-*-*-*"
386 #ifdef X_HAVE_UTF8_STRING
387 #define DRAWSTRING(x...) Xutf8DrawString(x)
389 #define DRAWSTRING(x...) XmbDrawString(x)
392 char *bar_argv
[] = { NULL
, NULL
};
394 char bar_ext
[SWM_BAR_MAX
];
395 char bar_ext_buf
[SWM_BAR_MAX
];
396 char bar_vertext
[SWM_BAR_MAX
];
397 bool bar_version
= false;
398 bool bar_enabled
= true;
399 int bar_border_width
= 1;
400 bool bar_at_bottom
= false;
401 bool bar_extra
= false;
403 int bar_justify
= SWM_BAR_JUSTIFY_LEFT
;
404 char *bar_format
= NULL
;
405 bool stack_enabled
= true;
406 bool clock_enabled
= true;
407 bool iconic_enabled
= false;
408 bool maximize_hide_bar
= false;
409 bool urgent_enabled
= false;
410 bool urgent_collapse
= false;
411 char *clock_format
= NULL
;
412 bool window_class_enabled
= false;
413 bool window_instance_enabled
= false;
414 bool window_name_enabled
= false;
415 int focus_mode
= SWM_FOCUS_DEFAULT
;
416 int focus_close
= SWM_STACK_BELOW
;
417 bool focus_close_wrap
= true;
418 int focus_default
= SWM_STACK_TOP
;
419 int spawn_position
= SWM_STACK_TOP
;
420 bool disable_border
= false;
421 int border_width
= 1;
422 int region_padding
= 0;
424 bool java_workaround
= true;
425 bool verbose_layout
= false;
431 XFontSetExtents
*bar_fs_extents
;
433 bool bar_font_legacy
= true;
435 XftColor bar_font_color
;
436 XftColor search_font_color
;
438 char *startup_exception
;
439 unsigned int nr_exceptions
= 0;
441 /* layout manager data */
442 struct swm_geometry
{
455 struct swm_geometry g
;
458 /* virtual "screens" */
460 TAILQ_ENTRY(swm_region
) entry
;
462 struct swm_geometry g
;
463 struct workspace
*ws
; /* current workspace on this region */
464 struct workspace
*ws_prior
; /* prior workspace on this region */
465 struct swm_screen
*s
; /* screen idx */
468 TAILQ_HEAD(swm_region_list
, swm_region
);
471 TAILQ_ENTRY(ws_win
) entry
;
472 TAILQ_ENTRY(ws_win
) stack_entry
;
474 xcb_window_t transient
;
475 struct ws_win
*focus_child
; /* focus on child transient */
476 struct swm_geometry g
; /* current geometry */
477 struct swm_geometry g_float
; /* region coordinates */
478 bool g_floatvalid
; /* g_float geometry validity */
482 int font_size_boundary
[SWM_MAX_FONT_STEPS
];
489 struct workspace
*ws
; /* always valid */
490 struct swm_screen
*s
; /* always valid, never changes */
492 xcb_icccm_get_wm_class_reply_t ch
;
493 xcb_icccm_wm_hints_t hints
;
495 TAILQ_HEAD(ws_win_list
, ws_win
);
496 TAILQ_HEAD(ws_win_stack
, ws_win
);
500 TAILQ_ENTRY(pid_e
) entry
;
504 TAILQ_HEAD(pid_list
, pid_e
);
505 struct pid_list pidlist
= TAILQ_HEAD_INITIALIZER(pidlist
);
507 /* layout handlers */
509 void vertical_config(struct workspace
*, int);
510 void vertical_stack(struct workspace
*, struct swm_geometry
*);
511 void horizontal_config(struct workspace
*, int);
512 void horizontal_stack(struct workspace
*, struct swm_geometry
*);
513 void max_stack(struct workspace
*, struct swm_geometry
*);
514 void plain_stacker(struct workspace
*);
515 void fancy_stacker(struct workspace
*);
518 void (*l_stack
)(struct workspace
*, struct swm_geometry
*);
519 void (*l_config
)(struct workspace
*, int);
521 #define SWM_L_FOCUSPREV (1<<0)
522 #define SWM_L_MAPONFOCUS (1<<1)
523 void (*l_string
)(struct workspace
*);
525 /* stack, configure */
526 { vertical_stack
, vertical_config
, 0, plain_stacker
},
527 { horizontal_stack
, horizontal_config
, 0, plain_stacker
},
529 SWM_L_MAPONFOCUS
| SWM_L_FOCUSPREV
, plain_stacker
},
530 { NULL
, NULL
, 0, NULL
},
533 /* position of max_stack mode in the layouts array, index into layouts! */
534 #define SWM_V_STACK (0)
535 #define SWM_H_STACK (1)
536 #define SWM_MAX_STACK (2)
538 #define SWM_H_SLICE (32)
539 #define SWM_V_SLICE (32)
541 /* define work spaces */
543 int idx
; /* workspace index */
544 char *name
; /* workspace name */
545 bool always_raise
; /* raise windows on focus */
546 bool bar_enabled
; /* bar visibility */
547 struct layout
*cur_layout
; /* current layout handlers */
548 struct ws_win
*focus
; /* may be NULL */
549 struct ws_win
*focus_prev
; /* may be NULL */
550 struct ws_win
*focus_pending
; /* may be NULL */
551 struct swm_region
*r
; /* may be NULL */
552 struct swm_region
*old_r
; /* may be NULL */
553 struct ws_win_list winlist
; /* list of windows in ws */
554 struct ws_win_list unmanagedlist
; /* list of dead windows in ws */
555 struct ws_win_stack stack
; /* stacking order */
556 int state
; /* mapping state */
557 char stacker
[10]; /* display stacker and layout */
561 int horizontal_msize
;
563 int horizontal_stacks
;
564 bool horizontal_flip
;
574 SWM_WS_STATE_MAPPING
,
580 SWM_S_COLOR_BAR_BORDER
,
581 SWM_S_COLOR_BAR_BORDER_UNFOCUS
,
582 SWM_S_COLOR_BAR_FONT
,
584 SWM_S_COLOR_FOCUS_MAXIMIZED
,
586 SWM_S_COLOR_UNFOCUS_MAXIMIZED
,
590 /* physical screen mapping */
591 #define SWM_WS_MAX (22) /* hard limit */
592 int workspace_limit
= 10; /* soft limit */
595 int idx
; /* screen index */
596 struct swm_region_list rl
; /* list of regions on this screen */
597 struct swm_region_list orl
; /* list of old regions */
599 struct workspace ws
[SWM_WS_MAX
];
600 struct swm_region
*r_focus
;
607 } c
[SWM_S_COLOR_MAX
];
609 xcb_gcontext_t bar_gc
;
612 struct swm_screen
*screens
;
614 /* args to functions */
617 #define SWM_ARG_ID_FOCUSNEXT (0)
618 #define SWM_ARG_ID_FOCUSPREV (1)
619 #define SWM_ARG_ID_FOCUSMAIN (2)
620 #define SWM_ARG_ID_FOCUSURGENT (3)
621 #define SWM_ARG_ID_SWAPNEXT (10)
622 #define SWM_ARG_ID_SWAPPREV (11)
623 #define SWM_ARG_ID_SWAPMAIN (12)
624 #define SWM_ARG_ID_MOVELAST (13)
625 #define SWM_ARG_ID_MASTERSHRINK (20)
626 #define SWM_ARG_ID_MASTERGROW (21)
627 #define SWM_ARG_ID_MASTERADD (22)
628 #define SWM_ARG_ID_MASTERDEL (23)
629 #define SWM_ARG_ID_FLIPLAYOUT (24)
630 #define SWM_ARG_ID_STACKRESET (30)
631 #define SWM_ARG_ID_STACKINIT (31)
632 #define SWM_ARG_ID_STACKBALANCE (32)
633 #define SWM_ARG_ID_CYCLEWS_UP (40)
634 #define SWM_ARG_ID_CYCLEWS_DOWN (41)
635 #define SWM_ARG_ID_CYCLERG_UP (42)
636 #define SWM_ARG_ID_CYCLERG_DOWN (43)
637 #define SWM_ARG_ID_CYCLEWS_UP_ALL (44)
638 #define SWM_ARG_ID_CYCLEWS_DOWN_ALL (45)
639 #define SWM_ARG_ID_CYCLEWS_MOVE_UP (46)
640 #define SWM_ARG_ID_CYCLEWS_MOVE_DOWN (47)
641 #define SWM_ARG_ID_STACKINC (50)
642 #define SWM_ARG_ID_STACKDEC (51)
643 #define SWM_ARG_ID_SS_ALL (60)
644 #define SWM_ARG_ID_SS_WINDOW (61)
645 #define SWM_ARG_ID_DONTCENTER (70)
646 #define SWM_ARG_ID_CENTER (71)
647 #define SWM_ARG_ID_KILLWINDOW (80)
648 #define SWM_ARG_ID_DELETEWINDOW (81)
649 #define SWM_ARG_ID_WIDTHGROW (90)
650 #define SWM_ARG_ID_WIDTHSHRINK (91)
651 #define SWM_ARG_ID_HEIGHTGROW (92)
652 #define SWM_ARG_ID_HEIGHTSHRINK (93)
653 #define SWM_ARG_ID_MOVEUP (100)
654 #define SWM_ARG_ID_MOVEDOWN (101)
655 #define SWM_ARG_ID_MOVELEFT (102)
656 #define SWM_ARG_ID_MOVERIGHT (103)
657 #define SWM_ARG_ID_RAISE (105)
658 #define SWM_ARG_ID_LOWER (106)
659 #define SWM_ARG_ID_BAR_TOGGLE (110)
660 #define SWM_ARG_ID_BAR_TOGGLE_WS (111)
661 #define SWM_ARG_ID_CYCLERG_MOVE_UP (112)
662 #define SWM_ARG_ID_CYCLERG_MOVE_DOWN (113)
668 TAILQ_ENTRY(quirk
) entry
;
669 char *class; /* WM_CLASS:class */
670 char *instance
; /* WM_CLASS:instance */
671 char *name
; /* WM_NAME */
673 regex_t regex_instance
;
676 int ws
; /* Initial workspace. */
677 #define SWM_Q_FLOAT (1<<0) /* float this window */
678 #define SWM_Q_TRANSSZ (1<<1) /* transiend window size too small */
679 #define SWM_Q_ANYWHERE (1<<2) /* don't position this window */
680 #define SWM_Q_XTERM_FONTADJ (1<<3) /* adjust xterm fonts when resizing */
681 #define SWM_Q_FULLSCREEN (1<<4) /* remove border */
682 #define SWM_Q_FOCUSPREV (1<<5) /* focus on caller */
683 #define SWM_Q_NOFOCUSONMAP (1<<6) /* Don't focus on window when mapped. */
684 #define SWM_Q_FOCUSONMAP_SINGLE (1<<7) /* Only focus if single win of type. */
685 #define SWM_Q_OBEYAPPFOCUSREQ (1<<8) /* Focus when applications ask. */
686 #define SWM_Q_IGNOREPID (1<<9) /* Ignore PID when determining ws. */
687 #define SWM_Q_IGNORESPAWNWS (1<<10) /* Ignore _SWM_WS when managing win. */
688 #define SWM_Q_NOFOCUSCYCLE (1<<11) /* Remove from normal focus cycle. */
690 TAILQ_HEAD(quirk_list
, quirk
);
691 struct quirk_list quirks
= TAILQ_HEAD_INITIALIZER(quirks
);
694 * Supported EWMH hints should be added to
695 * both the enum and the ewmh array
701 _NET_CURRENT_DESKTOP
,
702 _NET_DESKTOP_GEOMETRY
,
704 _NET_DESKTOP_VIEWPORT
,
705 _NET_MOVERESIZE_WINDOW
,
706 _NET_NUMBER_OF_DESKTOPS
,
708 _NET_WM_ACTION_ABOVE
,
709 _NET_WM_ACTION_CLOSE
,
710 _NET_WM_ACTION_FULLSCREEN
,
712 _NET_WM_ACTION_RESIZE
,
713 _NET_WM_ALLOWED_ACTIONS
,
715 _NET_WM_FULL_PLACEMENT
,
719 _NET_WM_STATE_FULLSCREEN
,
720 _NET_WM_STATE_HIDDEN
,
721 _NET_WM_STATE_MAXIMIZED_VERT
,
722 _NET_WM_STATE_MAXIMIZED_HORZ
,
723 _NET_WM_STATE_SKIP_PAGER
,
724 _NET_WM_STATE_SKIP_TASKBAR
,
726 _NET_WM_WINDOW_TYPE_DIALOG
,
727 _NET_WM_WINDOW_TYPE_DOCK
,
728 _NET_WM_WINDOW_TYPE_NORMAL
,
729 _NET_WM_WINDOW_TYPE_SPLASH
,
730 _NET_WM_WINDOW_TYPE_TOOLBAR
,
731 _NET_WM_WINDOW_TYPE_UTILITY
,
732 _SWM_WM_STATE_MANUAL
,
739 } ewmh
[SWM_EWMH_HINT_MAX
] = {
740 /* must be in same order as in the enum */
741 {"_NET_ACTIVE_WINDOW", XCB_ATOM_NONE
},
742 {"_NET_CLIENT_LIST", XCB_ATOM_NONE
},
743 {"_NET_CLOSE_WINDOW", XCB_ATOM_NONE
},
744 {"_NET_CURRENT_DESKTOP", XCB_ATOM_NONE
},
745 {"_NET_DESKTOP_GEOMETRY", XCB_ATOM_NONE
},
746 {"_NET_DESKTOP_NAMES", XCB_ATOM_NONE
},
747 {"_NET_DESKTOP_VIEWPORT", XCB_ATOM_NONE
},
748 {"_NET_MOVERESIZE_WINDOW", XCB_ATOM_NONE
},
749 {"_NET_NUMBER_OF_DESKTOPS", XCB_ATOM_NONE
},
750 {"_NET_RESTACK_WINDOW", XCB_ATOM_NONE
},
751 {"_NET_WM_ACTION_ABOVE", XCB_ATOM_NONE
},
752 {"_NET_WM_ACTION_CLOSE", XCB_ATOM_NONE
},
753 {"_NET_WM_ACTION_FULLSCREEN", XCB_ATOM_NONE
},
754 {"_NET_WM_ACTION_MOVE", XCB_ATOM_NONE
},
755 {"_NET_WM_ACTION_RESIZE", XCB_ATOM_NONE
},
756 {"_NET_WM_ALLOWED_ACTIONS", XCB_ATOM_NONE
},
757 {"_NET_WM_DESKTOP", XCB_ATOM_NONE
},
758 {"_NET_WM_FULL_PLACEMENT", XCB_ATOM_NONE
},
759 {"_NET_WM_NAME", XCB_ATOM_NONE
},
760 {"_NET_WM_STATE", XCB_ATOM_NONE
},
761 {"_NET_WM_STATE_ABOVE", XCB_ATOM_NONE
},
762 {"_NET_WM_STATE_FULLSCREEN", XCB_ATOM_NONE
},
763 {"_NET_WM_STATE_HIDDEN", XCB_ATOM_NONE
},
764 {"_NET_WM_STATE_MAXIMIZED_VERT", XCB_ATOM_NONE
},
765 {"_NET_WM_STATE_MAXIMIZED_HORZ", XCB_ATOM_NONE
},
766 {"_NET_WM_STATE_SKIP_PAGER", XCB_ATOM_NONE
},
767 {"_NET_WM_STATE_SKIP_TASKBAR", XCB_ATOM_NONE
},
768 {"_NET_WM_WINDOW_TYPE", XCB_ATOM_NONE
},
769 {"_NET_WM_WINDOW_TYPE_DIALOG", XCB_ATOM_NONE
},
770 {"_NET_WM_WINDOW_TYPE_DOCK", XCB_ATOM_NONE
},
771 {"_NET_WM_WINDOW_TYPE_NORMAL", XCB_ATOM_NONE
},
772 {"_NET_WM_WINDOW_TYPE_SPLASH", XCB_ATOM_NONE
},
773 {"_NET_WM_WINDOW_TYPE_TOOLBAR", XCB_ATOM_NONE
},
774 {"_NET_WM_WINDOW_TYPE_UTILITY", XCB_ATOM_NONE
},
775 {"_SWM_WM_STATE_MANUAL", XCB_ATOM_NONE
},
778 /* EWMH source type */
780 EWMH_SOURCE_TYPE_NONE
= 0,
781 EWMH_SOURCE_TYPE_NORMAL
= 1,
782 EWMH_SOURCE_TYPE_OTHER
= 2,
789 XC_BOTTOM_LEFT_CORNER
,
790 XC_BOTTOM_RIGHT_CORNER
,
798 char *name
; /* Name used by Xcursor .*/
799 uint8_t cf_char
; /* cursorfont index. */
801 } cursors
[XC_MAX
] = {
802 {"fleur", XC_fleur
, XCB_CURSOR_NONE
},
803 {"left_ptr", XC_left_ptr
, XCB_CURSOR_NONE
},
804 {"bottom_left_corner", XC_bottom_left_corner
, XCB_CURSOR_NONE
},
805 {"bottom_right_corner", XC_bottom_right_corner
, XCB_CURSOR_NONE
},
806 {"sizing", XC_sizing
, XCB_CURSOR_NONE
},
807 {"top_left_corner", XC_top_left_corner
, XCB_CURSOR_NONE
},
808 {"top_right_corner", XC_top_right_corner
, XCB_CURSOR_NONE
},
811 #define SWM_SPAWN_OPTIONAL 0x1
815 TAILQ_ENTRY(spawn_prog
) entry
;
821 TAILQ_HEAD(spawn_list
, spawn_prog
);
822 struct spawn_list spawns
= TAILQ_HEAD_INITIALIZER(spawns
);
824 /* user/key callable function IDs */
943 KF_DUMPWINS
, /* MUST BE LAST */
951 enum keyfuncid funcid
;
954 RB_HEAD(key_tree
, key
);
956 /* function prototypes */
957 void adjust_font(struct ws_win
*);
958 char *argsep(char **);
959 void bar_cleanup(struct swm_region
*);
960 void bar_extra_setup(void);
961 void bar_extra_stop(void);
962 int bar_extra_update(void);
963 void bar_fmt(const char *, char *, struct swm_region
*, size_t);
964 void bar_fmt_expand(char *, size_t);
966 void bar_print(struct swm_region
*, const char *);
967 void bar_print_legacy(struct swm_region
*, const char *);
968 void bar_replace(char *, char *, struct swm_region
*, size_t);
969 void bar_replace_pad(char *, int *, size_t);
970 char *bar_replace_seq(char *, char *, struct swm_region
*, size_t *, size_t);
971 void bar_setup(struct swm_region
*);
972 void bar_toggle(struct swm_region
*, union arg
*);
973 void bar_urgent(char *, size_t);
974 void bar_window_class(char *, size_t, struct swm_region
*);
975 void bar_window_class_instance(char *, size_t, struct swm_region
*);
976 void bar_window_float(char *, size_t, struct swm_region
*);
977 void bar_window_instance(char *, size_t, struct swm_region
*);
978 void bar_window_name(char *, size_t, struct swm_region
*);
979 void bar_window_state(char *, size_t, struct swm_region
*);
980 void bar_workspace_name(char *, size_t, struct swm_region
*);
981 void buttonpress(xcb_button_press_event_t
*);
982 void center_pointer(struct swm_region
*);
983 void check_conn(void);
984 void clear_keys(void);
985 int clear_maximized(struct workspace
*);
986 void clientmessage(xcb_client_message_event_t
*);
987 void client_msg(struct ws_win
*, xcb_atom_t
, xcb_timestamp_t
);
988 int conf_load(const char *, int);
989 void configurenotify(xcb_configure_notify_event_t
*);
990 void configurerequest(xcb_configure_request_event_t
*);
991 void config_win(struct ws_win
*, xcb_configure_request_event_t
*);
992 void constrain_window(struct ws_win
*, struct swm_geometry
*, int *);
993 int count_win(struct workspace
*, bool);
994 void cursors_cleanup(void);
995 void cursors_load(void);
996 void custom_region(const char *);
997 void cyclerg(struct swm_region
*, union arg
*);
998 void cyclews(struct swm_region
*, union arg
*);
999 void cycle_layout(struct swm_region
*, union arg
*);
1000 void destroynotify(xcb_destroy_notify_event_t
*);
1001 void dumpwins(struct swm_region
*, union arg
*);
1002 int enable_wm(void);
1003 void enternotify(xcb_enter_notify_event_t
*);
1004 void event_drain(uint8_t);
1005 void event_error(xcb_generic_error_t
*);
1006 void event_handle(xcb_generic_event_t
*);
1007 void ewmh_apply_flags(struct ws_win
*, uint32_t);
1008 void ewmh_autoquirk(struct ws_win
*);
1009 void ewmh_get_desktop_names(void);
1010 void ewmh_get_wm_state(struct ws_win
*);
1011 void ewmh_update_actions(struct ws_win
*);
1012 void ewmh_update_client_list(void);
1013 void ewmh_update_current_desktop(void);
1014 void ewmh_update_desktop_names(void);
1015 void ewmh_update_desktops(void);
1016 void ewmh_change_wm_state(struct ws_win
*, xcb_atom_t
, long);
1017 void ewmh_update_wm_state(struct ws_win
*);
1018 char *expand_tilde(const char *);
1019 void expose(xcb_expose_event_t
*);
1020 void fake_keypress(struct ws_win
*, xcb_keysym_t
, uint16_t);
1021 struct pid_e
*find_pid(pid_t
);
1022 struct ws_win
*find_unmanaged_window(xcb_window_t
);
1023 struct ws_win
*find_window(xcb_window_t
);
1024 void floating_toggle(struct swm_region
*, union arg
*);
1025 void focus(struct swm_region
*, union arg
*);
1027 void focusin(xcb_focus_in_event_t
*);
1028 void focusout(xcb_focus_out_event_t
*);
1030 void focus_flush(void);
1031 void focus_region(struct swm_region
*);
1032 void focusrg(struct swm_region
*, union arg
*);
1033 void focus_win(struct ws_win
*);
1034 void fontset_init(void);
1035 void free_window(struct ws_win
*);
1036 xcb_atom_t
get_atom_from_string(const char *);
1038 char *get_atom_name(xcb_atom_t
);
1040 struct ws_win
*get_focus_magic(struct ws_win
*);
1041 struct ws_win
*get_focus_prev(struct ws_win
*);
1043 char *get_notify_detail_label(uint8_t);
1044 char *get_notify_mode_label(uint8_t);
1046 struct ws_win
*get_pointer_win(xcb_window_t
);
1047 struct ws_win
*get_region_focus(struct swm_region
*);
1048 int get_region_index(struct swm_region
*);
1049 xcb_screen_t
*get_screen(int);
1050 int get_screen_count(void);
1052 char *get_source_type_label(uint32_t);
1053 char *get_stack_mode_name(uint8_t);
1055 int32_t get_swm_ws(xcb_window_t
);
1056 bool get_urgent(struct ws_win
*);
1057 char *get_win_name(xcb_window_t
);
1058 uint8_t get_win_state(xcb_window_t
);
1059 void get_wm_protocols(struct ws_win
*);
1060 int get_ws_idx(struct ws_win
*);
1061 void grabbuttons(struct ws_win
*);
1062 void grabkeys(void);
1063 void grab_windows(void);
1064 void iconify(struct swm_region
*, union arg
*);
1065 bool isxlfd(char *);
1066 void keypress(xcb_key_press_event_t
*);
1067 int key_cmp(struct key
*, struct key
*);
1068 void key_insert(unsigned int, KeySym
, enum keyfuncid
, const char *);
1069 struct key
*key_lookup(unsigned int, KeySym
);
1070 void key_remove(struct key
*);
1071 void key_replace(struct key
*, unsigned int, KeySym
, enum keyfuncid
,
1073 void kill_bar_extra_atexit(void);
1074 void kill_refs(struct ws_win
*);
1076 void leavenotify(xcb_leave_notify_event_t
*);
1078 void load_float_geom(struct ws_win
*);
1079 void lower_window(struct ws_win
*);
1080 struct ws_win
*manage_window(xcb_window_t
, int, bool);
1081 void map_window(struct ws_win
*);
1082 void mapnotify(xcb_map_notify_event_t
*);
1083 void mappingnotify(xcb_mapping_notify_event_t
*);
1084 void maprequest(xcb_map_request_event_t
*);
1085 void maximize_toggle(struct swm_region
*, union arg
*);
1086 void motionnotify(xcb_motion_notify_event_t
*);
1087 void move(struct ws_win
*, union arg
*);
1088 void move_step(struct swm_region
*, union arg
*);
1089 uint32_t name_to_pixel(int, const char *);
1090 void name_workspace(struct swm_region
*, union arg
*);
1091 void new_region(struct swm_screen
*, int, int, int, int);
1092 int parsekeys(const char *, unsigned int, unsigned int *, KeySym
*);
1093 int parsequirks(const char *, uint32_t *, int *);
1094 int parse_rgb(const char *, uint16_t *, uint16_t *, uint16_t *);
1095 void pressbutton(struct swm_region
*, union arg
*);
1096 void priorws(struct swm_region
*, union arg
*);
1098 void print_win_geom(xcb_window_t
);
1100 void propertynotify(xcb_property_notify_event_t
*);
1101 void quirk_free(struct quirk
*);
1102 void quirk_insert(const char *, const char *, const char *, uint32_t, int);
1103 void quirk_remove(struct quirk
*);
1104 void quirk_replace(struct quirk
*, const char *, const char *, const char *,
1106 void quit(struct swm_region
*, union arg
*);
1107 void raise_toggle(struct swm_region
*, union arg
*);
1108 void raise_window(struct ws_win
*);
1109 void region_containment(struct ws_win
*, struct swm_region
*, int);
1110 struct swm_region
*region_under(struct swm_screen
*, int, int);
1111 void regionize(struct ws_win
*, int, int);
1112 void resize(struct ws_win
*, union arg
*);
1113 void resize_step(struct swm_region
*, union arg
*);
1114 void restart(struct swm_region
*, union arg
*);
1115 struct swm_region
*root_to_region(xcb_window_t
, int);
1116 void screenchange(xcb_randr_screen_change_notify_event_t
*);
1117 void scan_randr(int);
1118 void search_do_resp(void);
1119 void search_resp_name_workspace(const char *, size_t);
1120 void search_resp_search_window(const char *);
1121 void search_resp_search_workspace(const char *);
1122 void search_resp_uniconify(const char *, size_t);
1123 void search_win(struct swm_region
*, union arg
*);
1124 void search_win_cleanup(void);
1125 void search_workspace(struct swm_region
*, union arg
*);
1126 void send_to_rg(struct swm_region
*, union arg
*);
1127 void send_to_ws(struct swm_region
*, union arg
*);
1128 void set_region(struct swm_region
*);
1129 int setautorun(const char *, const char *, int);
1130 int setconfbinding(const char *, const char *, int);
1131 int setconfcolor(const char *, const char *, int);
1132 int setconfmodkey(const char *, const char *, int);
1133 int setconfquirk(const char *, const char *, int);
1134 int setconfregion(const char *, const char *, int);
1135 int setconfspawn(const char *, const char *, int);
1136 int setconfvalue(const char *, const char *, int);
1137 void setkeybinding(unsigned int, KeySym
, enum keyfuncid
, const char *);
1138 int setkeymapping(const char *, const char *, int);
1139 int setlayout(const char *, const char *, int);
1140 void setquirk(const char *, const char *, const char *, uint32_t, int);
1141 void setscreencolor(const char *, int, int);
1142 void setspawn(const char *, const char *, int);
1143 void setup_ewmh(void);
1144 void setup_globals(void);
1145 void setup_keys(void);
1146 void setup_quirks(void);
1147 void setup_screens(void);
1148 void setup_spawn(void);
1149 void set_child_transient(struct ws_win
*, xcb_window_t
*);
1150 void set_win_state(struct ws_win
*, uint8_t);
1151 void shutdown_cleanup(void);
1153 void socket_setnonblock(int);
1154 void sort_windows(struct ws_win_list
*);
1155 void spawn(int, union arg
*, bool);
1156 void spawn_custom(struct swm_region
*, union arg
*, const char *);
1157 int spawn_expand(struct swm_region
*, union arg
*, const char *, char ***);
1158 void spawn_insert(const char *, const char *, int);
1159 struct spawn_prog
*spawn_find(const char *);
1160 void spawn_remove(struct spawn_prog
*);
1161 void spawn_replace(struct spawn_prog
*, const char *, const char *, int);
1162 void spawn_select(struct swm_region
*, union arg
*, const char *, int *);
1163 void stack_config(struct swm_region
*, union arg
*);
1164 void stack_master(struct workspace
*, struct swm_geometry
*, int, bool);
1165 void store_float_geom(struct ws_win
*);
1166 char *strdupsafe(const char *);
1167 void swapwin(struct swm_region
*, union arg
*);
1168 void switchws(struct swm_region
*, union arg
*);
1169 void teardown_ewmh(void);
1170 void unescape_selector(char *);
1171 void unfocus_win(struct ws_win
*);
1172 void uniconify(struct swm_region
*, union arg
*);
1173 void unmanage_window(struct ws_win
*);
1174 void unmapnotify(xcb_unmap_notify_event_t
*);
1175 void unmap_all(void);
1176 void unmap_window(struct ws_win
*);
1177 void updatenumlockmask(void);
1178 void update_floater(struct ws_win
*);
1179 void update_modkey(unsigned int);
1180 void update_win_stacking(struct ws_win
*);
1181 void update_window(struct ws_win
*);
1182 void update_window_color(struct ws_win
*);
1183 void update_wm_state(struct ws_win
*win
);
1184 void validate_spawns(void);
1185 int validate_win(struct ws_win
*);
1186 int validate_ws(struct workspace
*);
1187 void version(struct swm_region
*, union arg
*);
1188 void win_to_ws(struct ws_win
*, int, bool);
1189 pid_t
window_get_pid(xcb_window_t
);
1190 void wkill(struct swm_region
*, union arg
*);
1191 void update_ws_stack(struct workspace
*);
1192 void xft_init(struct swm_region
*);
1193 void _add_startup_exception(const char *, va_list);
1194 void add_startup_exception(const char *, ...);
1196 RB_PROTOTYPE(key_tree
, key
, entry
, key_cmp
);
1197 RB_GENERATE(key_tree
, key
, entry
, key_cmp
);
1198 struct key_tree keys
;
1203 xcb_font_t cf
= XCB_NONE
;
1206 for (i
= 0; i
< LENGTH(cursors
); ++i
) {
1207 /* try to load Xcursor first. */
1208 cursors
[i
].cid
= XcursorLibraryLoadCursor(display
,
1211 /* fallback to cursorfont. */
1212 if (cursors
[i
].cid
== XCB_CURSOR_NONE
) {
1213 if (cf
== XCB_NONE
) {
1214 cf
= xcb_generate_id(conn
);
1215 xcb_open_font(conn
, cf
, strlen("cursor"),
1219 cursors
[i
].cid
= xcb_generate_id(conn
);
1220 xcb_create_glyph_cursor(conn
, cursors
[i
].cid
, cf
, cf
,
1221 cursors
[i
].cf_char
, cursors
[i
].cf_char
+ 1, 0, 0, 0,
1222 0xffff, 0xffff, 0xffff);
1228 xcb_close_font(conn
, cf
);
1232 cursors_cleanup(void)
1235 for (i
= 0; i
< LENGTH(cursors
); ++i
)
1236 xcb_free_cursor(conn
, cursors
[i
].cid
);
1240 expand_tilde(const char *s
)
1242 struct passwd
*ppwd
;
1250 errx(1, "expand_tilde: NULL string.");
1253 result
= strdup(sc
);
1259 if ((max
= sysconf(_SC_LOGIN_NAME_MAX
)) == -1)
1260 errx(1, "expand_tilde: sysconf");
1262 if ((user
= calloc(1, max
+ 1)) == NULL
)
1263 errx(1, "expand_tilde: calloc");
1265 for (i
= 0; s
[i
] != '/' && s
[i
] != '\0'; ++i
)
1270 ppwd
= strlen(user
) == 0 ? getpwuid(getuid()) : getpwnam(user
);
1274 result
= strdup(sc
);
1276 if (asprintf(&result
, "%s%s", ppwd
->pw_dir
, s
) == -1)
1280 errx(1, "expand_tilde: failed to allocate memory.");
1286 parse_rgb(const char *rgb
, uint16_t *rr
, uint16_t *gg
, uint16_t *bb
)
1288 unsigned int tmpr
, tmpg
, tmpb
;
1290 if (sscanf(rgb
, "rgb:%x/%x/%x", &tmpr
, &tmpg
, &tmpb
) != 3)
1293 *rr
= RGB_8_TO_16(tmpr
);
1294 *gg
= RGB_8_TO_16(tmpg
);
1295 *bb
= RGB_8_TO_16(tmpb
);
1301 get_screen(int screen
)
1303 const xcb_setup_t
*r
;
1304 xcb_screen_iterator_t iter
;
1306 if ((r
= xcb_get_setup(conn
)) == NULL
) {
1307 DNPRINTF(SWM_D_MISC
, "get_screen: xcb_get_setup\n");
1311 iter
= xcb_setup_roots_iterator(r
);
1312 for (; iter
.rem
; --screen
, xcb_screen_next(&iter
))
1320 get_screen_count(void)
1322 const xcb_setup_t
*r
;
1324 if ((r
= xcb_get_setup(conn
)) == NULL
) {
1325 DNPRINTF(SWM_D_MISC
, "get_screen_count: xcb_get_setup\n");
1329 return xcb_setup_roots_length(r
);
1333 get_region_index(struct swm_region
*r
)
1335 struct swm_region
*rr
;
1341 TAILQ_FOREACH(rr
, &r
->s
->rl
, entry
) {
1356 if (focus_mode
== SWM_FOCUS_DEFAULT
)
1357 event_drain(XCB_ENTER_NOTIFY
);
1363 get_atom_from_string(const char *str
)
1365 xcb_intern_atom_cookie_t c
;
1366 xcb_intern_atom_reply_t
*r
;
1369 c
= xcb_intern_atom(conn
, 0, strlen(str
), str
);
1370 r
= xcb_intern_atom_reply(conn
, c
, NULL
);
1378 return (XCB_ATOM_NONE
);
1382 get_wm_protocols(struct ws_win
*win
) {
1384 xcb_icccm_get_wm_protocols_reply_t wpr
;
1386 if (xcb_icccm_get_wm_protocols_reply(conn
,
1387 xcb_icccm_get_wm_protocols(conn
, win
->id
, a_prot
),
1389 for (i
= 0; i
< (int)wpr
.atoms_len
; i
++) {
1390 if (wpr
.atoms
[i
] == a_takefocus
)
1391 win
->take_focus
= true;
1392 if (wpr
.atoms
[i
] == a_delete
)
1393 win
->can_delete
= true;
1395 xcb_icccm_get_wm_protocols_reply_wipe(&wpr
);
1402 xcb_window_t root
, win
;
1403 int i
, j
, num_screens
;
1405 for (i
= 0; i
< LENGTH(ewmh
); i
++)
1406 ewmh
[i
].atom
= get_atom_from_string(ewmh
[i
].name
);
1408 num_screens
= get_screen_count();
1409 for (i
= 0; i
< num_screens
; i
++) {
1410 root
= screens
[i
].root
;
1412 /* Set up _NET_SUPPORTING_WM_CHECK. */
1413 win
= xcb_generate_id(conn
);
1414 xcb_create_window(conn
, XCB_COPY_FROM_PARENT
, win
, root
,
1415 0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT
,
1416 XCB_COPY_FROM_PARENT
, 0, NULL
);
1418 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, root
,
1419 a_net_wm_check
, XCB_ATOM_WINDOW
, 32, 1, &win
);
1420 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
,
1421 a_net_wm_check
, XCB_ATOM_WINDOW
, 32, 1, &win
);
1424 * Impersonate LG3D non-reparenting WM, written by Sun, to
1425 * workaround a Java GUI rendering issue.
1427 if (java_workaround
)
1428 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
,
1429 ewmh
[_NET_WM_NAME
].atom
, a_utf8_string
,
1430 8, strlen("LG3D"), "LG3D");
1432 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
,
1433 ewmh
[_NET_WM_NAME
].atom
, a_utf8_string
,
1434 8, strlen("spectrwm"), "spectrwm");
1436 /* Report supported atoms */
1437 xcb_delete_property(conn
, root
, a_net_supported
);
1438 for (j
= 0; j
< LENGTH(ewmh
); j
++)
1439 xcb_change_property(conn
, XCB_PROP_MODE_APPEND
, root
,
1440 a_net_supported
, XCB_ATOM_ATOM
, 32, 1,
1445 ewmh_update_desktops();
1446 ewmh_get_desktop_names();
1454 xcb_get_property_cookie_t pc
;
1455 xcb_get_property_reply_t
*pr
;
1457 num_screens
= get_screen_count();
1459 for (i
= 0; i
< num_screens
; i
++) {
1460 /* Get the support check window and destroy it */
1461 pc
= xcb_get_property(conn
, 0, screens
[i
].root
, a_net_wm_check
,
1462 XCB_ATOM_WINDOW
, 0, 1);
1463 pr
= xcb_get_property_reply(conn
, pc
, NULL
);
1466 if (pr
->format
== a_net_wm_check
) {
1467 id
= *((xcb_window_t
*)xcb_get_property_value(pr
));
1469 xcb_destroy_window(conn
, id
);
1470 xcb_delete_property(conn
, screens
[i
].root
,
1472 xcb_delete_property(conn
, screens
[i
].root
,
1480 ewmh_autoquirk(struct ws_win
*win
)
1482 xcb_get_property_reply_t
*r
;
1483 xcb_get_property_cookie_t c
;
1487 c
= xcb_get_property(conn
, 0, win
->id
,
1488 ewmh
[_NET_WM_WINDOW_TYPE
].atom
, XCB_ATOM_ATOM
, 0, UINT32_MAX
);
1489 r
= xcb_get_property_reply(conn
, c
, NULL
);
1493 type
= xcb_get_property_value(r
);
1494 n
= xcb_get_property_value_length(r
) / sizeof(xcb_atom_t
);
1496 for (i
= 0; i
< n
; i
++) {
1497 if (type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_NORMAL
].atom
)
1499 if (type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_DOCK
].atom
||
1500 type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_TOOLBAR
].atom
||
1501 type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_UTILITY
].atom
) {
1502 win
->quirks
= SWM_Q_FLOAT
| SWM_Q_ANYWHERE
;
1505 if (type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_SPLASH
].atom
||
1506 type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_DIALOG
].atom
) {
1507 win
->quirks
= SWM_Q_FLOAT
;
1515 ewmh_update_actions(struct ws_win
*win
)
1517 xcb_atom_t actions
[SWM_EWMH_ACTION_COUNT_MAX
];
1523 actions
[n
++] = ewmh
[_NET_WM_ACTION_CLOSE
].atom
;
1526 actions
[n
++] = ewmh
[_NET_WM_ACTION_MOVE
].atom
;
1527 actions
[n
++] = ewmh
[_NET_WM_ACTION_RESIZE
].atom
;
1528 actions
[n
++] = ewmh
[_NET_WM_ACTION_ABOVE
].atom
;
1531 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
,
1532 ewmh
[_NET_WM_ALLOWED_ACTIONS
].atom
, XCB_ATOM_ATOM
, 32, 1, actions
);
1535 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1536 #define _NET_WM_STATE_ADD 1 /* add/set property */
1537 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1540 ewmh_change_wm_state(struct ws_win
*win
, xcb_atom_t state
, long action
)
1547 name
= get_atom_name(state
);
1548 DNPRINTF(SWM_D_PROP
, "ewmh_change_wm_state: win %#x, state: %s, "
1549 "action: %ld\n", WINID(win
), name
, action
);
1555 if (state
== ewmh
[_NET_WM_STATE_FULLSCREEN
].atom
)
1556 flag
= EWMH_F_FULLSCREEN
;
1557 else if (state
== ewmh
[_NET_WM_STATE_ABOVE
].atom
)
1558 flag
= EWMH_F_ABOVE
;
1559 else if (state
== ewmh
[_NET_WM_STATE_HIDDEN
].atom
)
1560 flag
= EWMH_F_HIDDEN
;
1561 else if (state
== ewmh
[_NET_WM_STATE_MAXIMIZED_VERT
].atom
||
1562 state
== ewmh
[_NET_WM_STATE_MAXIMIZED_HORZ
].atom
)
1563 flag
= EWMH_F_MAXIMIZED
;
1564 else if (state
== ewmh
[_SWM_WM_STATE_MANUAL
].atom
)
1565 flag
= SWM_F_MANUAL
;
1566 else if (state
== ewmh
[_NET_WM_STATE_SKIP_PAGER
].atom
)
1567 flag
= EWMH_F_SKIP_PAGER
;
1568 else if (state
== ewmh
[_NET_WM_STATE_SKIP_TASKBAR
].atom
)
1569 flag
= EWMH_F_SKIP_TASKBAR
;
1571 /* Disallow unfloating transients. */
1572 if (TRANS(win
) && flag
== EWMH_F_ABOVE
)
1575 new_flags
= win
->ewmh_flags
;
1578 case _NET_WM_STATE_REMOVE
:
1581 case _NET_WM_STATE_ADD
:
1584 case _NET_WM_STATE_TOGGLE
:
1589 ewmh_apply_flags(win
, new_flags
);
1592 DNPRINTF(SWM_D_PROP
, "ewmh_change_wm_state: done.\n");
1596 ewmh_apply_flags(struct ws_win
*win
, uint32_t pending
)
1598 struct workspace
*ws
;
1601 changed
= win
->ewmh_flags
^ pending
;
1605 DNPRINTF(SWM_D_PROP
, "ewmh_apply_flags: pending: %d\n", pending
);
1607 win
->ewmh_flags
= pending
;
1610 if (changed
& EWMH_F_HIDDEN
) {
1612 if (focus_mode
!= SWM_FOCUS_FOLLOW
)
1613 ws
->focus_pending
= get_focus_prev(win
);
1618 /* Reload floating geometry in case region changed. */
1620 load_float_geom(win
);
1622 /* The window is no longer iconic, prepare focus. */
1623 if (focus_mode
!= SWM_FOCUS_FOLLOW
)
1624 ws
->focus_pending
= get_focus_magic(win
);
1629 if (changed
& EWMH_F_ABOVE
) {
1630 if (ws
->cur_layout
!= &layouts
[SWM_MAX_STACK
]) {
1632 load_float_geom(win
);
1633 else if (!MAXIMIZED(win
))
1634 store_float_geom(win
);
1636 win
->ewmh_flags
&= ~EWMH_F_MAXIMIZED
;
1637 changed
&= ~EWMH_F_MAXIMIZED
;
1641 win
->ewmh_flags
^= EWMH_F_ABOVE
& pending
;
1645 if (changed
& EWMH_F_MAXIMIZED
) {
1646 /* VERT and/or HORZ changed. */
1648 if (!MAXIMIZED(win
))
1649 load_float_geom(win
);
1651 store_float_geom(win
);
1654 if (MAXIMIZED(win
)) {
1655 if (focus_mode
!= SWM_FOCUS_FOLLOW
&&
1656 ws
->cur_layout
!= &layouts
[SWM_MAX_STACK
]) {
1660 ws
->focus_pending
= win
;
1664 update_window_color(win
);
1668 if (changed
& EWMH_F_FULLSCREEN
) {
1669 if (FULLSCREEN(win
)) {
1670 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
1674 ws
->focus_pending
= win
;
1677 load_float_geom(win
);
1680 win
->ewmh_flags
&= ~EWMH_F_MAXIMIZED
;
1684 DNPRINTF(SWM_D_PROP
, "ewmh_apply_flags: done.\n");
1688 ewmh_update_wm_state(struct ws_win
*win
) {
1689 xcb_atom_t vals
[SWM_EWMH_ACTION_COUNT_MAX
];
1693 vals
[n
++] = ewmh
[_NET_WM_STATE_HIDDEN
].atom
;
1694 if (FULLSCREEN(win
))
1695 vals
[n
++] = ewmh
[_NET_WM_STATE_FULLSCREEN
].atom
;
1696 if (MAXIMIZED_VERT(win
))
1697 vals
[n
++] = ewmh
[_NET_WM_STATE_MAXIMIZED_VERT
].atom
;
1698 if (MAXIMIZED_HORZ(win
))
1699 vals
[n
++] = ewmh
[_NET_WM_STATE_MAXIMIZED_HORZ
].atom
;
1700 if (win
->ewmh_flags
& EWMH_F_SKIP_PAGER
)
1701 vals
[n
++] = ewmh
[_NET_WM_STATE_SKIP_PAGER
].atom
;
1702 if (win
->ewmh_flags
& EWMH_F_SKIP_TASKBAR
)
1703 vals
[n
++] = ewmh
[_NET_WM_STATE_SKIP_TASKBAR
].atom
;
1704 if (win
->ewmh_flags
& EWMH_F_ABOVE
)
1705 vals
[n
++] = ewmh
[_NET_WM_STATE_ABOVE
].atom
;
1706 if (win
->ewmh_flags
& SWM_F_MANUAL
)
1707 vals
[n
++] = ewmh
[_SWM_WM_STATE_MANUAL
].atom
;
1710 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
,
1711 ewmh
[_NET_WM_STATE
].atom
, XCB_ATOM_ATOM
, 32, n
, vals
);
1713 xcb_delete_property(conn
, win
->id
, ewmh
[_NET_WM_STATE
].atom
);
1717 ewmh_get_wm_state(struct ws_win
*win
)
1720 xcb_get_property_cookie_t c
;
1721 xcb_get_property_reply_t
*r
;
1727 win
->ewmh_flags
= 0;
1729 c
= xcb_get_property(conn
, 0, win
->id
, ewmh
[_NET_WM_STATE
].atom
,
1730 XCB_ATOM_ATOM
, 0, UINT32_MAX
);
1731 r
= xcb_get_property_reply(conn
, c
, NULL
);
1735 states
= xcb_get_property_value(r
);
1736 n
= xcb_get_property_value_length(r
) / sizeof(xcb_atom_t
);
1738 for (i
= 0; i
< n
; i
++)
1739 ewmh_change_wm_state(win
, states
[i
], _NET_WM_STATE_ADD
);
1747 dumpwins(struct swm_region
*r
, union arg
*args
)
1751 xcb_get_window_attributes_cookie_t c
;
1752 xcb_get_window_attributes_reply_t
*wa
;
1754 /* suppress unused warning since var is needed */
1757 if (r
->ws
== NULL
) {
1758 DPRINTF("dumpwins: invalid workspace\n");
1762 DPRINTF("=== managed window list ws %02d ===\n", r
->ws
->idx
);
1763 TAILQ_FOREACH(w
, &r
->ws
->winlist
, entry
) {
1764 state
= get_win_state(w
->id
);
1765 c
= xcb_get_window_attributes(conn
, w
->id
);
1766 wa
= xcb_get_window_attributes_reply(conn
, c
, NULL
);
1768 DPRINTF("win %#x, map_state: %d, state: %u, "
1769 "transient: %#x\n", w
->id
, wa
->map_state
,
1770 state
, w
->transient
);
1773 DPRINTF("win %#x, failed xcb_get_window_attributes\n",
1777 DPRINTF("=== stacking order (top down) === \n");
1778 TAILQ_FOREACH(w
, &r
->ws
->stack
, stack_entry
) {
1779 DPRINTF("win %#x, fs: %s, maximized: %s, above: %s, "
1780 "iconic: %s\n", w
->id
, YESNO(FULLSCREEN(w
)),
1781 YESNO(MAXIMIZED(w
)), YESNO(ABOVE(w
)), YESNO(ICONIC(w
)));
1784 DPRINTF("===== unmanaged window list =====\n");
1785 TAILQ_FOREACH(w
, &r
->ws
->unmanagedlist
, entry
) {
1786 state
= get_win_state(w
->id
);
1787 c
= xcb_get_window_attributes(conn
, w
->id
);
1788 wa
= xcb_get_window_attributes_reply(conn
, c
, NULL
);
1790 DPRINTF("win %#x, map_state: %d, state: %u, "
1791 "transient: %#x\n", w
->id
, wa
->map_state
,
1792 state
, w
->transient
);
1795 DPRINTF("win %#x, failed xcb_get_window_attributes\n",
1799 DPRINTF("=================================\n");
1803 dumpwins(struct swm_region
*r
, union arg
*s
)
1808 #endif /* SWM_DEBUG */
1813 int saved_errno
, status
;
1816 saved_errno
= errno
;
1820 while ((pid
= waitpid(WAIT_ANY
, &status
, WNOHANG
)) != 0) {
1825 if (errno
!= ECHILD
)
1826 warn("sighdlr: waitpid");
1827 #endif /* SWM_DEBUG */
1830 if (pid
== searchpid
)
1834 if (WIFEXITED(status
)) {
1835 if (WEXITSTATUS(status
) != 0)
1836 warnx("sighdlr: child exit status: %d",
1837 WEXITSTATUS(status
));
1839 warnx("sighdlr: child is terminated "
1841 #endif /* SWM_DEBUG */
1855 errno
= saved_errno
;
1861 struct pid_e
*p
= NULL
;
1863 DNPRINTF(SWM_D_MISC
, "find_pid: %d\n", pid
);
1868 TAILQ_FOREACH(p
, &pidlist
, entry
) {
1877 name_to_pixel(int sidx
, const char *colorname
)
1879 uint32_t result
= 0;
1880 char cname
[32] = "#";
1881 xcb_screen_t
*screen
;
1882 xcb_colormap_t cmap
;
1883 xcb_alloc_color_reply_t
*cr
;
1884 xcb_alloc_named_color_reply_t
*nr
;
1885 uint16_t rr
, gg
, bb
;
1887 screen
= get_screen(sidx
);
1888 cmap
= screen
->default_colormap
;
1890 /* color is in format rgb://rr/gg/bb */
1891 if (strncmp(colorname
, "rgb:", 4) == 0) {
1892 if (parse_rgb(colorname
, &rr
, &gg
, &bb
) == -1)
1893 warnx("could not parse rgb %s", colorname
);
1895 cr
= xcb_alloc_color_reply(conn
,
1896 xcb_alloc_color(conn
, cmap
, rr
, gg
, bb
),
1902 warnx("color '%s' not found", colorname
);
1905 nr
= xcb_alloc_named_color_reply(conn
,
1906 xcb_alloc_named_color(conn
, cmap
, strlen(colorname
),
1909 strlcat(cname
, colorname
+ 2, sizeof cname
- 1);
1910 nr
= xcb_alloc_named_color_reply(conn
,
1911 xcb_alloc_named_color(conn
, cmap
, strlen(cname
),
1918 warnx("color '%s' not found", colorname
);
1925 setscreencolor(const char *val
, int i
, int c
)
1927 if (i
< 0 || i
>= get_screen_count())
1930 screens
[i
].c
[c
].pixel
= name_to_pixel(i
, val
);
1931 free(screens
[i
].c
[c
].name
);
1932 if ((screens
[i
].c
[c
].name
= strdup(val
)) == NULL
)
1937 fancy_stacker(struct workspace
*ws
)
1939 strlcpy(ws
->stacker
, "[ ]", sizeof ws
->stacker
);
1940 if (ws
->cur_layout
->l_stack
== vertical_stack
)
1941 snprintf(ws
->stacker
, sizeof ws
->stacker
,
1942 ws
->l_state
.vertical_flip
? "[%d>%d]" : "[%d|%d]",
1943 ws
->l_state
.vertical_mwin
, ws
->l_state
.vertical_stacks
);
1944 else if (ws
->cur_layout
->l_stack
== horizontal_stack
)
1945 snprintf(ws
->stacker
, sizeof ws
->stacker
,
1946 ws
->l_state
.horizontal_flip
? "[%dv%d]" : "[%d-%d]",
1947 ws
->l_state
.horizontal_mwin
, ws
->l_state
.horizontal_stacks
);
1951 plain_stacker(struct workspace
*ws
)
1953 strlcpy(ws
->stacker
, "[ ]", sizeof ws
->stacker
);
1954 if (ws
->cur_layout
->l_stack
== vertical_stack
)
1955 strlcpy(ws
->stacker
, ws
->l_state
.vertical_flip
? "[>]" : "[|]",
1956 sizeof ws
->stacker
);
1957 else if (ws
->cur_layout
->l_stack
== horizontal_stack
)
1958 strlcpy(ws
->stacker
, ws
->l_state
.horizontal_flip
? "[v]" : "[-]",
1959 sizeof ws
->stacker
);
1963 custom_region(const char *val
)
1965 unsigned int x
, y
, w
, h
;
1966 int sidx
, num_screens
;
1967 xcb_screen_t
*screen
;
1969 num_screens
= get_screen_count();
1970 if (sscanf(val
, "screen[%d]:%ux%u+%u+%u", &sidx
, &w
, &h
, &x
, &y
) != 5)
1971 errx(1, "invalid custom region, "
1972 "should be 'screen[<n>]:<n>x<n>+<n>+<n>");
1973 if (sidx
< 1 || sidx
> num_screens
)
1974 errx(1, "invalid screen index: %d out of bounds (maximum %d)",
1978 if ((screen
= get_screen(sidx
)) == NULL
)
1979 errx(1, "ERROR: can't get screen %d.", sidx
);
1982 errx(1, "region %ux%u+%u+%u too small", w
, h
, x
, y
);
1984 if (x
> screen
->width_in_pixels
||
1985 y
> screen
->height_in_pixels
||
1986 w
+ x
> screen
->width_in_pixels
||
1987 h
+ y
> screen
->height_in_pixels
) {
1988 warnx("ignoring region %ux%u+%u+%u - not within screen "
1989 "boundaries (%ux%u)", w
, h
, x
, y
,
1990 screen
->width_in_pixels
, screen
->height_in_pixels
);
1994 new_region(&screens
[sidx
], x
, y
, w
, h
);
1998 socket_setnonblock(int fd
)
2002 if ((flags
= fcntl(fd
, F_GETFL
, 0)) == -1)
2003 err(1, "fcntl F_GETFL");
2004 flags
|= O_NONBLOCK
;
2005 if ((flags
= fcntl(fd
, F_SETFL
, flags
)) == -1)
2006 err(1, "fcntl F_SETFL");
2010 bar_print_legacy(struct swm_region
*r
, const char *s
)
2012 xcb_rectangle_t rect
;
2017 XRectangle ibox
, lbox
;
2021 XmbTextExtents(bar_fs
, s
, len
, &ibox
, &lbox
);
2023 switch (bar_justify
) {
2024 case SWM_BAR_JUSTIFY_LEFT
:
2027 case SWM_BAR_JUSTIFY_CENTER
:
2028 x
= (WIDTH(r
) - lbox
.width
) / 2;
2030 case SWM_BAR_JUSTIFY_RIGHT
:
2031 x
= WIDTH(r
) - lbox
.width
- SWM_BAR_OFFSET
;
2035 if (x
< SWM_BAR_OFFSET
)
2040 rect
.width
= WIDTH(r
->bar
);
2041 rect
.height
= HEIGHT(r
->bar
);
2043 /* clear back buffer */
2044 gcv
[0] = r
->s
->c
[SWM_S_COLOR_BAR
].pixel
;
2045 xcb_change_gc(conn
, r
->s
->bar_gc
, XCB_GC_FOREGROUND
, gcv
);
2046 xcb_poly_fill_rectangle(conn
, r
->bar
->buffer
, r
->s
->bar_gc
, 1, &rect
);
2048 /* draw back buffer */
2049 gcvd
.graphics_exposures
= 0;
2050 draw
= XCreateGC(display
, r
->bar
->buffer
, GCGraphicsExposures
, &gcvd
);
2051 XSetForeground(display
, draw
, r
->s
->c
[SWM_S_COLOR_BAR_FONT
].pixel
);
2052 DRAWSTRING(display
, r
->bar
->buffer
, bar_fs
, draw
,
2053 x
, (bar_fs_extents
->max_logical_extent
.height
- lbox
.height
) / 2 -
2055 XFreeGC(display
, draw
);
2058 xcb_copy_area(conn
, r
->bar
->buffer
, r
->bar
->id
, r
->s
->bar_gc
, 0, 0,
2059 0, 0, WIDTH(r
->bar
), HEIGHT(r
->bar
));
2063 bar_print(struct swm_region
*r
, const char *s
)
2066 xcb_rectangle_t rect
;
2074 XftTextExtentsUtf8(display
, bar_font
, (FcChar8
*)s
, len
, &info
);
2076 switch (bar_justify
) {
2077 case SWM_BAR_JUSTIFY_LEFT
:
2080 case SWM_BAR_JUSTIFY_CENTER
:
2081 x
= (WIDTH(r
) - info
.width
) / 2;
2083 case SWM_BAR_JUSTIFY_RIGHT
:
2084 x
= WIDTH(r
) - info
.width
- SWM_BAR_OFFSET
;
2088 if (x
< SWM_BAR_OFFSET
)
2093 rect
.width
= WIDTH(r
->bar
);
2094 rect
.height
= HEIGHT(r
->bar
);
2096 /* clear back buffer */
2097 gcv
[0] = r
->s
->c
[SWM_S_COLOR_BAR
].pixel
;
2098 xcb_change_gc(conn
, r
->s
->bar_gc
, XCB_GC_FOREGROUND
, gcv
);
2099 xcb_poly_fill_rectangle(conn
, r
->bar
->buffer
, r
->s
->bar_gc
, 1, &rect
);
2101 /* draw back buffer */
2102 draw
= XftDrawCreate(display
, r
->bar
->buffer
,
2103 DefaultVisual(display
, r
->s
->idx
),
2104 DefaultColormap(display
, r
->s
->idx
));
2106 XftDrawStringUtf8(draw
, &bar_font_color
, bar_font
, x
,
2107 (HEIGHT(r
->bar
) + bar_font
->height
) / 2 - bar_font
->descent
,
2110 XftDrawDestroy(draw
);
2113 xcb_copy_area(conn
, r
->bar
->buffer
, r
->bar
->id
, r
->s
->bar_gc
, 0, 0,
2114 0, 0, WIDTH(r
->bar
), HEIGHT(r
->bar
));
2118 bar_extra_stop(void)
2122 bzero(bar_pipe
, sizeof bar_pipe
);
2125 kill(bar_pid
, SIGTERM
);
2128 strlcpy(bar_ext
, "", sizeof bar_ext
);
2133 bar_window_class(char *s
, size_t sz
, struct swm_region
*r
)
2135 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2137 if (r
->ws
->focus
->ch
.class_name
!= NULL
)
2138 strlcat(s
, r
->ws
->focus
->ch
.class_name
, sz
);
2142 bar_window_instance(char *s
, size_t sz
, struct swm_region
*r
)
2144 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2146 if (r
->ws
->focus
->ch
.instance_name
!= NULL
)
2147 strlcat(s
, r
->ws
->focus
->ch
.instance_name
, sz
);
2151 bar_window_class_instance(char *s
, size_t sz
, struct swm_region
*r
)
2153 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2156 bar_window_class(s
, sz
, r
);
2157 strlcat(s
, ":", sz
);
2158 bar_window_instance(s
, sz
, r
);
2162 bar_window_state(char *s
, size_t sz
, struct swm_region
*r
)
2164 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2166 if (MAXIMIZED(r
->ws
->focus
))
2167 strlcat(s
, "(m)", sz
);
2168 else if (ABOVE(r
->ws
->focus
))
2169 strlcat(s
, "(f)", sz
);
2173 bar_window_name(char *s
, size_t sz
, struct swm_region
*r
)
2177 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2180 title
= get_win_name(r
->ws
->focus
->id
);
2181 strlcat(s
, title
, sz
);
2186 get_urgent(struct ws_win
*win
)
2188 xcb_icccm_wm_hints_t hints
;
2189 xcb_get_property_cookie_t c
;
2190 bool urgent
= false;
2193 c
= xcb_icccm_get_wm_hints(conn
, win
->id
);
2194 if (xcb_icccm_get_wm_hints_reply(conn
, c
, &hints
, NULL
))
2195 urgent
= xcb_icccm_wm_hints_get_urgency(&hints
);
2202 bar_urgent(char *s
, size_t sz
)
2205 int i
, j
, num_screens
;
2206 bool urgent
[SWM_WS_MAX
];
2209 for (i
= 0; i
< workspace_limit
; i
++)
2212 num_screens
= get_screen_count();
2213 for (i
= 0; i
< num_screens
; i
++)
2214 for (j
= 0; j
< workspace_limit
; j
++)
2215 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
2216 if (get_urgent(win
))
2219 for (i
= 0; i
< workspace_limit
; i
++) {
2221 snprintf(b
, sizeof b
, "%d ", i
+ 1);
2223 } else if (!urgent_collapse
) {
2224 strlcat(s
, "- ", sz
);
2227 if(urgent_collapse
&& s
[0])
2228 s
[strlen(s
) - 1] = 0;
2232 bar_workspace_name(char *s
, size_t sz
, struct swm_region
*r
)
2234 if (r
== NULL
|| r
->ws
== NULL
)
2236 if (r
->ws
->name
!= NULL
)
2237 strlcat(s
, r
->ws
->name
, sz
);
2240 /* build the default bar format according to the defined enabled options */
2242 bar_fmt(const char *fmtexp
, char *fmtnew
, struct swm_region
*r
, size_t sz
)
2246 /* if format provided, just copy the buffers */
2247 if (bar_format
!= NULL
) {
2248 strlcpy(fmtnew
, fmtexp
, sz
);
2252 /* reset the output buffer */
2255 strlcat(fmtnew
, "+N:+I ", sz
);
2257 strlcat(fmtnew
, "+S", sz
);
2258 strlcat(fmtnew
, " ", sz
);
2260 /* only show the workspace name if there's actually one */
2261 if (r
!= NULL
&& r
->ws
!= NULL
&& r
->ws
->name
!= NULL
)
2262 strlcat(fmtnew
, "<+D>", sz
);
2264 /* If enabled, only show the iconic count if there are iconic wins. */
2265 if (iconic_enabled
&& r
!= NULL
&& r
->ws
!= NULL
)
2266 TAILQ_FOREACH(w
, &r
->ws
->winlist
, entry
)
2268 strlcat(fmtnew
, "{+M}", sz
);
2272 strlcat(fmtnew
, "+3<", sz
);
2274 if (clock_enabled
) {
2275 strlcat(fmtnew
, fmtexp
, sz
);
2276 strlcat(fmtnew
, "+4<", sz
);
2279 /* bar_urgent already adds the space before the last asterisk */
2281 strlcat(fmtnew
, "* +U*+4<", sz
);
2283 if (window_class_enabled
) {
2284 strlcat(fmtnew
, "+C", sz
);
2285 if (!window_instance_enabled
)
2286 strlcat(fmtnew
, "+4<", sz
);
2289 /* checks needed by the colon and floating strlcat(3) calls below */
2290 if (r
!= NULL
&& r
->ws
!= NULL
&& r
->ws
->focus
!= NULL
) {
2291 if (window_instance_enabled
) {
2292 if (window_class_enabled
)
2293 strlcat(fmtnew
, ":", sz
);
2294 strlcat(fmtnew
, "+T+4<", sz
);
2296 if (window_name_enabled
) {
2297 if (ABOVE(r
->ws
->focus
) || MAXIMIZED(r
->ws
->focus
))
2298 strlcat(fmtnew
, "+F ", sz
);
2299 strlcat(fmtnew
, "+64W ", sz
);
2303 /* finally add the action script output and the version */
2304 strlcat(fmtnew
, "+4<+A+4<+V", sz
);
2308 bar_replace_pad(char *tmp
, int *limit
, size_t sz
)
2310 /* special case; no limit given, pad one space, instead */
2311 if (*limit
== (int)sz
- 1)
2313 snprintf(tmp
, sz
, "%*s", *limit
, " ");
2316 /* replaces the bar format character sequences (like in tmux(1)) */
2318 bar_replace_seq(char *fmt
, char *fmtrep
, struct swm_region
*r
, size_t *offrep
,
2323 char tmp
[SWM_BAR_MAX
];
2324 int limit
, size
, count
;
2327 /* reset strlcat(3) buffer */
2330 /* get number, if any */
2333 if (sscanf(fmt
, "%d%n", &limit
, &size
) != 1)
2334 limit
= sizeof tmp
- 1;
2335 if (limit
<= 0 || limit
>= (int)sizeof tmp
)
2336 limit
= sizeof tmp
- 1;
2338 /* there is nothing to replace (ie EOL) */
2345 bar_replace_pad(tmp
, &limit
, sizeof tmp
);
2348 snprintf(tmp
, sizeof tmp
, "%s", bar_ext
);
2351 bar_window_class(tmp
, sizeof tmp
, r
);
2354 bar_workspace_name(tmp
, sizeof tmp
, r
);
2357 bar_window_state(tmp
, sizeof tmp
, r
);
2360 snprintf(tmp
, sizeof tmp
, "%d", r
->ws
->idx
+ 1);
2364 TAILQ_FOREACH(w
, &r
->ws
->winlist
, entry
)
2368 snprintf(tmp
, sizeof tmp
, "%d", count
);
2371 snprintf(tmp
, sizeof tmp
, "%d", r
->s
->idx
+ 1);
2374 bar_window_class_instance(tmp
, sizeof tmp
, r
);
2377 snprintf(tmp
, sizeof tmp
, "%s", r
->ws
->stacker
);
2380 bar_window_instance(tmp
, sizeof tmp
, r
);
2383 bar_urgent(tmp
, sizeof tmp
);
2386 snprintf(tmp
, sizeof tmp
, "%s", bar_vertext
);
2389 bar_window_name(tmp
, sizeof tmp
, r
);
2392 /* unknown character sequence; copy as-is */
2393 snprintf(tmp
, sizeof tmp
, "+%c", *fmt
);
2399 if ((int)len
< limit
)
2401 while (limit
-- > 0) {
2402 if (*offrep
>= sz
- 1)
2404 fmtrep
[(*offrep
)++] = *ptr
++;
2412 bar_replace(char *fmt
, char *fmtrep
, struct swm_region
*r
, size_t sz
)
2417 while (*fmt
!= '\0') {
2419 /* skip ordinary characters */
2422 fmtrep
[off
++] = *fmt
++;
2426 /* character sequence found; replace it */
2427 fmt
= bar_replace_seq(fmt
, fmtrep
, r
, &off
, sz
);
2436 bar_fmt_expand(char *fmtexp
, size_t sz
)
2443 /* start by grabbing the current time and date */
2445 localtime_r(&tmt
, &tm
);
2447 /* figure out what to expand */
2448 if (bar_format
!= NULL
)
2450 else if (bar_format
== NULL
&& clock_enabled
)
2452 /* if nothing to expand bail out */
2458 /* copy as-is, just in case the format shouldn't be expanded below */
2459 strlcpy(fmtexp
, fmt
, sz
);
2460 /* finally pass the string through strftime(3) */
2461 #ifndef SWM_DENY_CLOCK_FORMAT
2462 if ((len
= strftime(fmtexp
, sz
, fmt
, &tm
)) == 0)
2463 warnx("format too long");
2468 /* Redraws the bar; need to follow with xcb_flush() or focus_flush(). */
2472 char fmtexp
[SWM_BAR_MAX
], fmtnew
[SWM_BAR_MAX
];
2473 char fmtrep
[SWM_BAR_MAX
];
2475 struct swm_region
*r
;
2477 /* expand the format by first passing it through strftime(3) */
2478 bar_fmt_expand(fmtexp
, sizeof fmtexp
);
2480 num_screens
= get_screen_count();
2481 for (i
= 0; i
< num_screens
; i
++) {
2482 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
) {
2486 if (bar_enabled
&& r
->ws
->bar_enabled
)
2487 xcb_map_window(conn
, r
->bar
->id
);
2489 xcb_unmap_window(conn
, r
->bar
->id
);
2493 if (startup_exception
)
2494 snprintf(fmtrep
, sizeof fmtrep
, "total "
2495 "exceptions: %d, first exception: %s",
2499 bar_fmt(fmtexp
, fmtnew
, r
, sizeof fmtnew
);
2500 bar_replace(fmtnew
, fmtrep
, r
, sizeof fmtrep
);
2502 if (bar_font_legacy
)
2503 bar_print_legacy(r
, fmtrep
);
2505 bar_print(r
, fmtrep
);
2511 * Reads external script output; call when stdin is readable.
2512 * Returns 1 if bar_ext was updated; otherwise 0.
2515 bar_extra_update(void)
2518 char b
[SWM_BAR_MAX
];
2519 bool changed
= false;
2524 while (fgets(b
, sizeof(b
), stdin
) != NULL
) {
2527 if (b
[len
- 1] == '\n') {
2528 /* Remove newline. */
2531 /* "Clear" bar_ext. */
2534 /* Flush buffered output. */
2535 strlcpy(bar_ext
, bar_ext_buf
, sizeof(bar_ext
));
2536 bar_ext_buf
[0] = '\0';
2538 /* Append new output to bar. */
2539 strlcat(bar_ext
, b
, sizeof(bar_ext
));
2543 /* Buffer output. */
2544 strlcat(bar_ext_buf
, b
, sizeof(bar_ext_buf
));
2549 if (errno
!= EAGAIN
) {
2550 warn("bar_action failed");
2559 bar_toggle(struct swm_region
*r
, union arg
*args
)
2561 struct swm_region
*tmpr
;
2564 /* suppress unused warnings since vars are needed */
2568 DNPRINTF(SWM_D_BAR
, "bar_toggle\n");
2571 case SWM_ARG_ID_BAR_TOGGLE_WS
:
2572 /* Only change if master switch is enabled. */
2574 r
->ws
->bar_enabled
= !r
->ws
->bar_enabled
;
2576 bar_enabled
= r
->ws
->bar_enabled
= true;
2578 case SWM_ARG_ID_BAR_TOGGLE
:
2579 bar_enabled
= !bar_enabled
;
2583 /* update bars as necessary */
2584 num_screens
= get_screen_count();
2585 for (i
= 0; i
< num_screens
; i
++)
2586 TAILQ_FOREACH(tmpr
, &screens
[i
].rl
, entry
)
2588 if (bar_enabled
&& tmpr
->ws
->bar_enabled
)
2589 xcb_map_window(conn
, tmpr
->bar
->id
);
2591 xcb_unmap_window(conn
, tmpr
->bar
->id
);
2596 /* must be after stack */
2603 bar_extra_setup(void)
2605 /* do this here because the conf file is in memory */
2606 if (!bar_extra
&& bar_argv
[0]) {
2607 /* launch external status app */
2609 if (pipe(bar_pipe
) == -1)
2610 err(1, "pipe error");
2611 socket_setnonblock(bar_pipe
[0]);
2612 socket_setnonblock(bar_pipe
[1]); /* XXX hmmm, really? */
2614 /* Set stdin to read from the pipe. */
2615 if (dup2(bar_pipe
[0], STDIN_FILENO
) == -1)
2618 /* Set stdout to write to the pipe. */
2619 if (dup2(bar_pipe
[1], STDOUT_FILENO
) == -1)
2622 if (signal(SIGPIPE
, SIG_IGN
) == SIG_ERR
)
2623 err(1, "could not disable SIGPIPE");
2624 switch (bar_pid
= fork()) {
2626 err(1, "cannot fork");
2630 execvp(bar_argv
[0], bar_argv
);
2631 err(1, "%s external app failed", bar_argv
[0]);
2633 default: /* parent */
2638 atexit(kill_bar_extra_atexit
);
2643 kill_bar_extra_atexit(void)
2646 kill(bar_pid
, SIGTERM
);
2654 while ((s
= index(s
, '-'))) {
2659 return (count
== 14);
2665 char *default_string
;
2666 char **missing_charsets
;
2667 int num_missing_charsets
= 0;
2671 XFreeFontSet(display
, bar_fs
);
2675 DNPRINTF(SWM_D_INIT
, "fontset_init: loading bar_fonts: %s\n", bar_fonts
);
2677 bar_fs
= XCreateFontSet(display
, bar_fonts
, &missing_charsets
,
2678 &num_missing_charsets
, &default_string
);
2680 if (num_missing_charsets
> 0) {
2681 warnx("Unable to load charset(s):");
2683 for (i
= 0; i
< num_missing_charsets
; ++i
)
2684 warnx("%s", missing_charsets
[i
]);
2686 XFreeStringList(missing_charsets
);
2688 if (strcmp(default_string
, ""))
2689 warnx("Glyphs from those sets will be replaced "
2690 "by '%s'.", default_string
);
2692 warnx("Glyphs from those sets won't be drawn.");
2696 errx(1, "Error creating font set structure.");
2698 bar_fs_extents
= XExtentsOfFontSet(bar_fs
);
2700 bar_height
= bar_fs_extents
->max_logical_extent
.height
+
2701 2 * bar_border_width
;
2708 xft_init(struct swm_region
*r
)
2710 char *font
, *d
, *search
;
2713 if (bar_font
== NULL
) {
2714 if ((d
= strdup(bar_fonts
)) == NULL
)
2715 errx(1, "insufficient memory.");
2717 while ((font
= strsep(&search
, ",")) != NULL
) {
2721 DNPRINTF(SWM_D_INIT
, "xft_init: try font %s\n", font
);
2724 bar_font
= XftFontOpenXlfd(display
, r
->s
->idx
,
2727 bar_font
= XftFontOpenName(display
, r
->s
->idx
,
2731 if (bar_font
== NULL
) {
2732 warnx("unable to load font %s", font
);
2735 DNPRINTF(SWM_D_INIT
, "successfully opened "
2743 if (bar_font
== NULL
)
2744 errx(1, "unable to open a font");
2746 PIXEL_TO_XRENDERCOLOR(r
->s
->c
[SWM_S_COLOR_BAR_FONT
].pixel
, color
);
2748 if (!XftColorAllocValue(display
, DefaultVisual(display
, r
->s
->idx
),
2749 DefaultColormap(display
, r
->s
->idx
), &color
, &bar_font_color
))
2750 warn("Xft error: unable to allocate color.");
2752 PIXEL_TO_XRENDERCOLOR(r
->s
->c
[SWM_S_COLOR_BAR
].pixel
, color
);
2754 if (!XftColorAllocValue(display
, DefaultVisual(display
, r
->s
->idx
),
2755 DefaultColormap(display
, r
->s
->idx
), &color
, &search_font_color
))
2756 warn("Xft error: unable to allocate color.");
2758 bar_height
= bar_font
->height
+ 2 * bar_border_width
;
2765 bar_setup(struct swm_region
*r
)
2767 xcb_screen_t
*screen
;
2770 DNPRINTF(SWM_D_BAR
, "bar_setup: screen %d.\n",
2773 if ((screen
= get_screen(r
->s
->idx
)) == NULL
)
2774 errx(1, "ERROR: can't get screen %d.", r
->s
->idx
);
2779 if ((r
->bar
= calloc(1, sizeof(struct swm_bar
))) == NULL
)
2780 err(1, "bar_setup: calloc: failed to allocate memory.");
2782 if (bar_font_legacy
)
2788 Y(r
->bar
) = bar_at_bottom
? (Y(r
) + HEIGHT(r
) - bar_height
) : Y(r
);
2789 WIDTH(r
->bar
) = WIDTH(r
) - 2 * bar_border_width
;
2790 HEIGHT(r
->bar
) = bar_height
- 2 * bar_border_width
;
2792 /* Assume region is unfocused when we create the bar. */
2793 r
->bar
->id
= xcb_generate_id(conn
);
2794 wa
[0] = r
->s
->c
[SWM_S_COLOR_BAR
].pixel
;
2795 wa
[1] = r
->s
->c
[SWM_S_COLOR_BAR_BORDER_UNFOCUS
].pixel
;
2796 wa
[2] = XCB_EVENT_MASK_EXPOSURE
| XCB_EVENT_MASK_POINTER_MOTION
|
2797 XCB_EVENT_MASK_POINTER_MOTION_HINT
;
2799 xcb_create_window(conn
, XCB_COPY_FROM_PARENT
, r
->bar
->id
, r
->s
->root
,
2800 X(r
->bar
), Y(r
->bar
), WIDTH(r
->bar
), HEIGHT(r
->bar
),
2801 bar_border_width
, XCB_WINDOW_CLASS_INPUT_OUTPUT
,
2802 XCB_COPY_FROM_PARENT
, XCB_CW_BACK_PIXEL
| XCB_CW_BORDER_PIXEL
2803 | XCB_CW_EVENT_MASK
, wa
);
2805 /* Stack bar window above region window to start. */
2807 wa
[1] = XCB_STACK_MODE_ABOVE
;
2809 xcb_configure_window(conn
, r
->bar
->id
, XCB_CONFIG_WINDOW_SIBLING
|
2810 XCB_CONFIG_WINDOW_STACK_MODE
, wa
);
2812 r
->bar
->buffer
= xcb_generate_id(conn
);
2813 xcb_create_pixmap(conn
, screen
->root_depth
, r
->bar
->buffer
, r
->bar
->id
,
2814 WIDTH(r
->bar
), HEIGHT(r
->bar
));
2817 xcb_randr_select_input(conn
, r
->bar
->id
,
2818 XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE
);
2821 xcb_map_window(conn
, r
->bar
->id
);
2823 DNPRINTF(SWM_D_BAR
, "bar_setup: win %#x, (x,y) w x h: (%d,%d) "
2824 "%d x %d\n", WINID(r
->bar
), X(r
->bar
), Y(r
->bar
), WIDTH(r
->bar
),
2831 bar_cleanup(struct swm_region
*r
)
2835 xcb_destroy_window(conn
, r
->bar
->id
);
2836 xcb_free_pixmap(conn
, r
->bar
->buffer
);
2842 set_win_state(struct ws_win
*win
, uint8_t state
)
2844 uint16_t data
[2] = { state
, XCB_ATOM_NONE
};
2846 DNPRINTF(SWM_D_EVENT
, "set_win_state: win %#x, state: %u\n",
2852 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
, a_state
,
2853 a_state
, 32, 2, data
);
2857 get_win_state(xcb_window_t w
)
2859 xcb_get_property_reply_t
*r
;
2860 xcb_get_property_cookie_t c
;
2861 uint32_t result
= 0;
2863 c
= xcb_get_property(conn
, 0, w
, a_state
, a_state
, 0L, 2L);
2864 r
= xcb_get_property_reply(conn
, c
, NULL
);
2866 if (r
->type
== a_state
&& r
->format
== 32 && r
->length
== 2)
2867 result
= *((uint32_t *)xcb_get_property_value(r
));
2871 DNPRINTF(SWM_D_MISC
, "get_win_state property: win %#x state %u\n", w
,
2877 version(struct swm_region
*r
, union arg
*args
)
2879 /* suppress unused warnings since vars are needed */
2883 bar_version
= !bar_version
;
2885 snprintf(bar_vertext
, sizeof bar_vertext
,
2886 "Version: %s Build: %s", SPECTRWM_VERSION
, buildstr
);
2888 strlcpy(bar_vertext
, "", sizeof bar_vertext
);
2895 client_msg(struct ws_win
*win
, xcb_atom_t a
, xcb_timestamp_t t
)
2897 xcb_client_message_event_t ev
;
2905 name
= get_atom_name(a
);
2906 DNPRINTF(SWM_D_EVENT
, "client_msg: win %#x, atom: %s(%u), "
2908 win
->id
, name
, a
, t
);
2912 bzero(&ev
, sizeof ev
);
2913 ev
.response_type
= XCB_CLIENT_MESSAGE
;
2914 ev
.window
= win
->id
;
2917 ev
.data
.data32
[0] = a
;
2918 ev
.data
.data32
[1] = t
;
2920 xcb_send_event(conn
, 0, win
->id
,
2921 XCB_EVENT_MASK_NO_EVENT
, (const char *)&ev
);
2924 /* synthetic response to a ConfigureRequest when not making a change */
2926 config_win(struct ws_win
*win
, xcb_configure_request_event_t
*ev
)
2928 xcb_configure_notify_event_t ce
;
2933 /* send notification of unchanged state. */
2934 bzero(&ce
, sizeof(ce
));
2935 ce
.response_type
= XCB_CONFIGURE_NOTIFY
;
2938 ce
.width
= WIDTH(win
);
2939 ce
.height
= HEIGHT(win
);
2940 ce
.override_redirect
= 0;
2945 ce
.window
= win
->id
;
2946 ce
.border_width
= BORDER(win
);
2947 ce
.above_sibling
= XCB_WINDOW_NONE
;
2950 ce
.event
= ev
->window
;
2951 ce
.window
= ev
->window
;
2953 /* make response appear more WM_SIZE_HINTS-compliant */
2954 if (win
->sh
.flags
) {
2955 DNPRINTF(SWM_D_MISC
, "config_win: hints: win %#x,"
2956 " sh.flags: %u, min: %d x %d, max: %d x %d, inc: "
2957 "%d x %d\n", win
->id
, win
->sh
.flags
, SH_MIN_W(win
),
2958 SH_MIN_H(win
), SH_MAX_W(win
), SH_MAX_H(win
),
2959 SH_INC_W(win
), SH_INC_H(win
));
2964 /* the hint may be set... to 0! */
2965 if (SH_MIN_W(win
) > 0 && ce
.width
< SH_MIN_W(win
))
2966 ce
.width
= SH_MIN_W(win
);
2967 if (SH_MIN_H(win
) > 0 && ce
.height
< SH_MIN_H(win
))
2968 ce
.height
= SH_MIN_H(win
);
2973 /* may also be advertized as 0 */
2974 if (SH_MAX_W(win
) > 0 && ce
.width
> SH_MAX_W(win
))
2975 ce
.width
= SH_MAX_W(win
);
2976 if (SH_MAX_H(win
) > 0 && ce
.height
> SH_MAX_H(win
))
2977 ce
.height
= SH_MAX_H(win
);
2980 /* resize increment. */
2982 if (SH_INC_W(win
) > 1 && ce
.width
> SH_INC_W(win
))
2983 ce
.width
-= (ce
.width
- SH_MIN_W(win
)) %
2985 if (SH_INC_H(win
) > 1 && ce
.height
> SH_INC_H(win
))
2986 ce
.height
-= (ce
.height
- SH_MIN_H(win
)) %
2990 /* adjust x and y for requested border_width. */
2991 ce
.x
+= BORDER(win
) - ev
->border_width
;
2992 ce
.y
+= BORDER(win
) - ev
->border_width
;
2993 ce
.border_width
= ev
->border_width
;
2994 ce
.above_sibling
= ev
->sibling
;
2997 DNPRINTF(SWM_D_MISC
, "config_win: ewmh: %s, win %#x, (x,y) w x h: "
2998 "(%d,%d) %d x %d, border: %d\n", YESNO(ev
== NULL
), win
->id
, ce
.x
,
2999 ce
.y
, ce
.width
, ce
.height
, ce
.border_width
);
3001 xcb_send_event(conn
, 0, win
->id
, XCB_EVENT_MASK_STRUCTURE_NOTIFY
,
3006 count_win(struct workspace
*ws
, bool count_transient
)
3011 TAILQ_FOREACH(win
, &ws
->winlist
, entry
) {
3012 if (!count_transient
&& FLOATING(win
))
3018 DNPRINTF(SWM_D_MISC
, "count_win: %d\n", count
);
3024 quit(struct swm_region
*r
, union arg
*args
)
3026 /* suppress unused warnings since vars are needed */
3030 DNPRINTF(SWM_D_MISC
, "quit\n");
3035 lower_window(struct ws_win
*win
)
3037 struct ws_win
*target
= NULL
;
3038 struct workspace
*ws
;
3045 DNPRINTF(SWM_D_EVENT
, "lower_window: win %#x\n", win
->id
);
3047 TAILQ_FOREACH(target
, &ws
->stack
, stack_entry
) {
3048 if (target
== win
|| ICONIC(target
))
3050 if (ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
3053 if (win
->transient
== target
->transient
)
3055 if (win
->transient
== target
->id
)
3058 if (FULLSCREEN(target
))
3060 if (FULLSCREEN(win
))
3062 if (MAXIMIZED(target
))
3066 if (ABOVE(target
) || TRANS(target
))
3068 if (ABOVE(win
) || TRANS(win
))
3072 /* Change stack position. */
3073 TAILQ_REMOVE(&ws
->stack
, win
, stack_entry
);
3075 TAILQ_INSERT_BEFORE(target
, win
, stack_entry
);
3077 TAILQ_INSERT_TAIL(&ws
->stack
, win
, stack_entry
);
3079 update_win_stacking(win
);
3082 if (swm_debug
& SWM_D_STACK
) {
3083 DPRINTF("=== stacking order (top down) === \n");
3084 TAILQ_FOREACH(target
, &ws
->stack
, stack_entry
) {
3085 DPRINTF("win %#x, fs: %s, maximized: %s, above: %s, "
3086 "iconic: %s\n", target
->id
, YESNO(FULLSCREEN(target
)),
3087 YESNO(MAXIMIZED(target
)), YESNO(ABOVE(target
)),
3088 YESNO(ICONIC(target
)));
3092 DNPRINTF(SWM_D_EVENT
, "lower_window: done\n");
3096 raise_window(struct ws_win
*win
)
3098 struct ws_win
*target
= NULL
;
3099 struct workspace
*ws
;
3105 DNPRINTF(SWM_D_EVENT
, "raise_window: win %#x\n", win
->id
);
3107 TAILQ_FOREACH(target
, &ws
->stack
, stack_entry
) {
3108 if (target
== win
|| ICONIC(target
))
3110 if (ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
3112 if (TRANS(win
) && (win
->transient
== target
->transient
||
3113 win
->transient
== target
->id
))
3115 if (FULLSCREEN(win
))
3117 if (FULLSCREEN(target
))
3121 if (MAXIMIZED(target
))
3123 if (ABOVE(win
) || TRANS(win
) ||
3124 (win
->ws
->focus
== win
&& ws
->always_raise
))
3126 if (!ABOVE(target
) && !TRANS(target
))
3130 TAILQ_REMOVE(&ws
->stack
, win
, stack_entry
);
3132 TAILQ_INSERT_BEFORE(target
, win
, stack_entry
);
3134 TAILQ_INSERT_TAIL(&ws
->stack
, win
, stack_entry
);
3136 update_win_stacking(win
);
3139 if (swm_debug
& SWM_D_STACK
) {
3140 DPRINTF("=== stacking order (top down) === \n");
3141 TAILQ_FOREACH(target
, &ws
->stack
, stack_entry
) {
3142 DPRINTF("win %#x, fs: %s, maximized: %s, above: %s, "
3143 "iconic: %s\n", target
->id
, YESNO(FULLSCREEN(target
)),
3144 YESNO(MAXIMIZED(target
)), YESNO(ABOVE(target
)),
3145 YESNO(ICONIC(target
)));
3149 DNPRINTF(SWM_D_EVENT
, "raise_window: done\n");
3153 update_win_stacking(struct ws_win
*win
)
3155 struct ws_win
*sibling
;
3156 struct swm_region
*r
;
3159 if (win
== NULL
|| (r
= win
->ws
->r
) == NULL
)
3162 sibling
= TAILQ_NEXT(win
, stack_entry
);
3163 if (sibling
!= NULL
&& (FLOATING(win
) == FLOATING(sibling
) ||
3164 (win
->ws
->always_raise
&& win
->ws
->focus
== win
)))
3165 val
[0] = sibling
->id
;
3166 else if (FLOATING(win
) || (win
->ws
->always_raise
&&
3167 win
->ws
->focus
== win
))
3168 val
[0] = r
->bar
->id
;
3172 DNPRINTF(SWM_D_EVENT
, "update_win_stacking: %#x, sibling %#x\n",
3175 val
[1] = XCB_STACK_MODE_ABOVE
;
3177 xcb_configure_window(conn
, win
->id
, XCB_CONFIG_WINDOW_SIBLING
|
3178 XCB_CONFIG_WINDOW_STACK_MODE
, val
);
3182 map_window(struct ws_win
*win
)
3187 DNPRINTF(SWM_D_EVENT
, "map_window: win %#x, mapped: %s\n",
3188 win
->id
, YESNO(win
->mapped
));
3193 xcb_map_window(conn
, win
->id
);
3194 set_win_state(win
, XCB_ICCCM_WM_STATE_NORMAL
);
3199 unmap_window(struct ws_win
*win
)
3204 DNPRINTF(SWM_D_EVENT
, "unmap_window: win %#x, mapped: %s\n", win
->id
,
3205 YESNO(win
->mapped
));
3210 xcb_unmap_window(conn
, win
->id
);
3211 set_win_state(win
, XCB_ICCCM_WM_STATE_ICONIC
);
3212 win
->mapped
= false;
3219 int i
, j
, num_screens
;
3221 num_screens
= get_screen_count();
3222 for (i
= 0; i
< num_screens
; i
++)
3223 for (j
= 0; j
< workspace_limit
; j
++)
3224 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
3229 fake_keypress(struct ws_win
*win
, xcb_keysym_t keysym
, uint16_t modifiers
)
3231 xcb_key_press_event_t event
;
3232 xcb_keycode_t
*keycode
;
3237 keycode
= xcb_key_symbols_get_keycode(syms
, keysym
);
3239 DNPRINTF(SWM_D_MISC
, "fake_keypress: win %#x, keycode %u\n",
3242 bzero(&event
, sizeof(event
));
3243 event
.event
= win
->id
;
3244 event
.root
= win
->s
->root
;
3245 event
.child
= XCB_WINDOW_NONE
;
3246 event
.time
= XCB_CURRENT_TIME
;
3247 event
.event_x
= X(win
);
3248 event
.event_y
= Y(win
);
3251 event
.same_screen
= 1;
3252 event
.detail
= *keycode
;
3253 event
.state
= modifiers
;
3255 event
.response_type
= XCB_KEY_PRESS
;
3256 xcb_send_event(conn
, 1, win
->id
,
3257 XCB_EVENT_MASK_KEY_PRESS
, (const char *)&event
);
3259 event
.response_type
= XCB_KEY_RELEASE
;
3260 xcb_send_event(conn
, 1, win
->id
,
3261 XCB_EVENT_MASK_KEY_RELEASE
, (const char *)&event
);
3267 restart(struct swm_region
*r
, union arg
*args
)
3269 /* suppress unused warning since var is needed */
3273 DNPRINTF(SWM_D_MISC
, "restart: %s\n", start_argv
[0]);
3277 execvp(start_argv
[0], start_argv
);
3278 warn("execvp failed");
3283 get_pointer_win(xcb_window_t root
)
3285 struct ws_win
*win
= NULL
;
3286 xcb_query_pointer_reply_t
*r
;
3288 DNPRINTF(SWM_D_EVENT
, "get_pointer_win: root: %#x.\n", root
);
3290 r
= xcb_query_pointer_reply(conn
, xcb_query_pointer(conn
, root
), NULL
);
3292 win
= find_window(r
->child
);
3294 DNPRINTF(SWM_D_EVENT
, "get_pointer_win: %#x.\n",
3297 DNPRINTF(SWM_D_EVENT
, "get_pointer_win: none.\n");
3306 center_pointer(struct swm_region
*r
)
3310 if (!warp_pointer
|| r
== NULL
)
3315 DNPRINTF(SWM_D_EVENT
, "center_pointer: win %#x.\n", WINID(win
));
3317 if (win
&& win
->mapped
)
3318 xcb_warp_pointer(conn
, XCB_NONE
, win
->id
, 0, 0, 0, 0,
3319 WIDTH(win
) / 2, HEIGHT(win
) / 2);
3321 xcb_warp_pointer(conn
, XCB_NONE
, r
->id
, 0, 0, 0, 0,
3322 WIDTH(r
) / 2, HEIGHT(r
) / 2);
3326 root_to_region(xcb_window_t root
, int check
)
3329 struct swm_region
*r
= NULL
;
3331 xcb_query_pointer_reply_t
*qpr
;
3332 xcb_get_input_focus_reply_t
*gifr
;
3334 DNPRINTF(SWM_D_MISC
, "root_to_region: win %#x\n", root
);
3336 num_screens
= get_screen_count();
3337 for (i
= 0; i
< num_screens
; i
++)
3338 if (screens
[i
].root
== root
)
3341 if (check
& SWM_CK_REGION
)
3342 r
= screens
[i
].r_focus
;
3344 if (r
== NULL
&& check
& SWM_CK_FOCUS
) {
3345 /* Try to find an actively focused window */
3346 gifr
= xcb_get_input_focus_reply(conn
,
3347 xcb_get_input_focus(conn
), NULL
);
3349 cfw
= find_window(gifr
->focus
);
3350 if (cfw
&& cfw
->ws
->r
)
3357 if (r
== NULL
&& check
& SWM_CK_POINTER
) {
3358 /* No region with an active focus; try to use pointer. */
3359 qpr
= xcb_query_pointer_reply(conn
, xcb_query_pointer(conn
,
3360 screens
[i
].root
), NULL
);
3362 DNPRINTF(SWM_D_MISC
, "root_to_region: pointer: "
3363 "(%d,%d)\n", qpr
->root_x
, qpr
->root_y
);
3364 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
3365 if (X(r
) <= qpr
->root_x
&&
3366 qpr
->root_x
< MAX_X(r
) &&
3367 Y(r
) <= qpr
->root_y
&&
3368 qpr
->root_y
< MAX_Y(r
))
3375 if (r
== NULL
&& check
& SWM_CK_FALLBACK
)
3376 r
= TAILQ_FIRST(&screens
[i
].rl
);
3378 DNPRINTF(SWM_D_MISC
, "root_to_region: idx: %d\n", get_region_index(r
));
3384 find_unmanaged_window(xcb_window_t id
)
3387 int i
, j
, num_screens
;
3389 num_screens
= get_screen_count();
3390 for (i
= 0; i
< num_screens
; i
++)
3391 for (j
= 0; j
< workspace_limit
; j
++)
3392 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].unmanagedlist
,
3400 find_window(xcb_window_t id
)
3403 int i
, j
, num_screens
;
3404 xcb_query_tree_reply_t
*r
;
3406 num_screens
= get_screen_count();
3407 for (i
= 0; i
< num_screens
; i
++)
3408 for (j
= 0; j
< workspace_limit
; j
++)
3409 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
3413 r
= xcb_query_tree_reply(conn
, xcb_query_tree(conn
, id
), NULL
);
3417 /* if we were looking for the parent return that window instead */
3418 if (r
->parent
== 0 || r
->root
== r
->parent
) {
3423 /* look for parent */
3424 for (i
= 0; i
< num_screens
; i
++)
3425 for (j
= 0; j
< workspace_limit
; j
++)
3426 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
3427 if (r
->parent
== win
->id
) {
3437 spawn(int ws_idx
, union arg
*args
, bool close_fd
)
3442 DNPRINTF(SWM_D_MISC
, "spawn: %s\n", args
->argv
[0]);
3444 close(xcb_get_file_descriptor(conn
));
3446 setenv("LD_PRELOAD", SWM_LIB
, 1);
3448 if (asprintf(&ret
, "%d", ws_idx
) == -1) {
3449 warn("spawn: asprintf SWM_WS");
3452 setenv("_SWM_WS", ret
, 1);
3456 if (asprintf(&ret
, "%d", getpid()) == -1) {
3457 warn("spawn: asprintf _SWM_PID");
3460 setenv("_SWM_PID", ret
, 1);
3464 if (setsid() == -1) {
3465 warn("spawn: setsid");
3471 * close stdin and stdout to prevent interaction between apps
3472 * and the baraction script
3473 * leave stderr open to record errors
3475 if ((fd
= open(_PATH_DEVNULL
, O_RDWR
, 0)) == -1) {
3476 warn("spawn: open");
3479 dup2(fd
, STDIN_FILENO
);
3480 dup2(fd
, STDOUT_FILENO
);
3485 execvp(args
->argv
[0], args
->argv
);
3487 warn("spawn: execvp");
3492 kill_refs(struct ws_win
*win
)
3494 int i
, x
, num_screens
;
3495 struct swm_region
*r
;
3496 struct workspace
*ws
;
3501 num_screens
= get_screen_count();
3502 for (i
= 0; i
< num_screens
; i
++)
3503 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
3504 for (x
= 0; x
< workspace_limit
; x
++) {
3506 if (win
== ws
->focus
)
3508 if (win
== ws
->focus_prev
)
3509 ws
->focus_prev
= NULL
;
3514 validate_win(struct ws_win
*testwin
)
3517 struct workspace
*ws
;
3518 struct swm_region
*r
;
3519 int i
, x
, num_screens
;
3521 if (testwin
== NULL
)
3524 num_screens
= get_screen_count();
3525 for (i
= 0; i
< num_screens
; i
++)
3526 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
3527 for (x
= 0; x
< workspace_limit
; x
++) {
3529 TAILQ_FOREACH(win
, &ws
->winlist
, entry
)
3537 validate_ws(struct workspace
*testws
)
3539 struct swm_region
*r
;
3540 struct workspace
*ws
;
3541 int i
, x
, num_screens
;
3543 /* validate all ws */
3544 num_screens
= get_screen_count();
3545 for (i
= 0; i
< num_screens
; i
++)
3546 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
3547 for (x
= 0; x
< workspace_limit
; x
++) {
3556 unfocus_win(struct ws_win
*win
)
3558 xcb_window_t none
= XCB_WINDOW_NONE
;
3560 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: win %#x\n", WINID(win
));
3565 if (win
->ws
== NULL
) {
3566 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: NULL ws.\n");
3570 if (validate_ws(win
->ws
)) {
3571 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: invalid ws.\n");
3575 if (win
->ws
->r
== NULL
) {
3576 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: NULL region.\n");
3580 if (validate_win(win
)) {
3581 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: invalid win.\n");
3586 if (win
->ws
->focus
== win
) {
3587 win
->ws
->focus
= NULL
;
3588 win
->ws
->focus_prev
= win
;
3591 if (validate_win(win
->ws
->focus
)) {
3592 kill_refs(win
->ws
->focus
);
3593 win
->ws
->focus
= NULL
;
3596 if (validate_win(win
->ws
->focus_prev
)) {
3597 kill_refs(win
->ws
->focus_prev
);
3598 win
->ws
->focus_prev
= NULL
;
3601 update_window_color(win
);
3603 /* Raise window to "top unfocused position." */
3604 if (win
->ws
->always_raise
)
3607 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->s
->root
,
3608 ewmh
[_NET_ACTIVE_WINDOW
].atom
, XCB_ATOM_WINDOW
, 32, 1, &none
);
3610 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: done.\n");
3614 focus_win(struct ws_win
*win
)
3616 struct ws_win
*cfw
= NULL
, *parent
= NULL
, *w
, *tmpw
;
3617 struct workspace
*ws
;
3618 xcb_get_input_focus_reply_t
*gifr
;
3620 DNPRINTF(SWM_D_FOCUS
, "focus_win: win %#x\n", WINID(win
));
3622 if (win
== NULL
|| win
->ws
== NULL
|| !win
->mapped
)
3627 if (validate_ws(ws
))
3630 if (validate_win(win
)) {
3635 gifr
= xcb_get_input_focus_reply(conn
, xcb_get_input_focus(conn
), NULL
);
3637 cfw
= find_window(gifr
->focus
);
3638 if (cfw
!= NULL
&& cfw
!= win
) {
3639 if (cfw
->ws
!= ws
&& cfw
->ws
->r
!= NULL
) {
3640 /* Change border to unfocused color. */
3641 xcb_change_window_attributes(conn
, cfw
->id
,
3642 XCB_CW_BORDER_PIXEL
,
3643 &cfw
->s
->c
[(MAXIMIZED(cfw
) ?
3644 SWM_S_COLOR_UNFOCUS_MAXIMIZED
:
3645 SWM_S_COLOR_UNFOCUS
)].pixel
);
3653 if (ws
->focus
!= win
) {
3654 if (ws
->focus
&& ws
->focus
!= cfw
)
3655 unfocus_win(ws
->focus
);
3659 /* If this window directs focus to a child window, then clear. */
3660 if (win
->focus_child
)
3661 win
->focus_child
= NULL
;
3663 /* If transient, adjust parent's focus child for focus_magic. */
3665 parent
= find_window(win
->transient
);
3666 if (parent
&& parent
->focus_child
!= win
)
3667 parent
->focus_child
= win
;
3670 if (cfw
!= win
&& ws
->r
!= NULL
) {
3671 /* Set input focus if no input hint, or indicated by hint. */
3672 if (!(win
->hints
.flags
& XCB_ICCCM_WM_HINT_INPUT
) ||
3673 (win
->hints
.flags
& XCB_ICCCM_WM_HINT_INPUT
&&
3675 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
,
3676 win
->id
, last_event_time
);
3678 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
,
3679 ws
->r
->id
, XCB_CURRENT_TIME
);
3681 /* Tell app it can adjust focus to a specific window. */
3682 if (win
->take_focus
) {
3683 /* java is special; always tell parent */
3684 if (TRANS(win
) && win
->java
)
3685 client_msg(parent
, a_takefocus
,
3688 client_msg(win
, a_takefocus
, last_event_time
);
3691 if (ws
->cur_layout
->flags
& SWM_L_MAPONFOCUS
||
3693 /* If a parent exists, map it first. */
3695 raise_window(parent
);
3698 /* Map siblings next. */
3699 TAILQ_FOREACH_SAFE(w
, &ws
->stack
, stack_entry
,
3701 if (w
!= win
&& !ICONIC(w
) &&
3702 w
->transient
== parent
->id
) {
3708 /* Map focused window. */
3712 /* Stack any children of focus window. */
3713 TAILQ_FOREACH_SAFE(w
, &ws
->stack
, stack_entry
, tmpw
)
3714 if (w
->transient
== win
->id
&& !ICONIC(w
)) {
3718 } else if (tile_gap
< 0 && !ABOVE(win
)) {
3720 * Windows overlap in the layout.
3721 * Raise focused win above all tiled wins.
3729 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->s
->root
,
3730 ewmh
[_NET_ACTIVE_WINDOW
].atom
, XCB_ATOM_WINDOW
, 32, 1,
3735 /* Update window border even if workspace is hidden. */
3736 update_window_color(win
);
3741 DNPRINTF(SWM_D_FOCUS
, "focus_win: done.\n");
3744 /* If a child window should have focus instead, return it. */
3746 get_focus_magic(struct ws_win
*win
)
3748 struct ws_win
*parent
= NULL
;
3749 struct ws_win
*child
= NULL
;
3751 DNPRINTF(SWM_D_FOCUS
, "get_focus_magic: win %#x\n", WINID(win
));
3756 parent
= find_window(win
->transient
);
3758 /* If parent prefers focus elsewhere, then try to do so. */
3759 if (parent
&& (child
= parent
->focus_child
)) {
3760 if (validate_win(child
) == 0 && child
->mapped
)
3763 parent
->focus_child
= NULL
;
3767 /* If this window prefers focus elsewhere, then try to do so. */
3768 if ((child
= win
->focus_child
)) {
3769 if (validate_win(child
) == 0 && child
->mapped
)
3772 win
->focus_child
= NULL
;
3779 event_drain(uint8_t rt
)
3781 xcb_generic_event_t
*evt
;
3783 /* ensure all pending requests have been processed before filtering. */
3785 while ((evt
= xcb_poll_for_event(conn
))) {
3786 if (XCB_EVENT_RESPONSE_TYPE(evt
) != rt
)
3794 set_region(struct swm_region
*r
)
3796 struct swm_region
*rf
;
3803 /* Unfocus old region bar. */
3808 xcb_change_window_attributes(conn
, rf
->bar
->id
,
3809 XCB_CW_BORDER_PIXEL
,
3810 &r
->s
->c
[SWM_S_COLOR_BAR_BORDER_UNFOCUS
].pixel
);
3813 if (rf
!= NULL
&& rf
!= r
&& (X(rf
) != X(r
) || Y(rf
) != Y(r
) ||
3814 WIDTH(rf
) != WIDTH(r
) || HEIGHT(rf
) != HEIGHT(r
))) {
3815 /* Set _NET_DESKTOP_GEOMETRY. */
3817 vals
[1] = HEIGHT(r
);
3818 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, r
->s
->root
,
3819 ewmh
[_NET_DESKTOP_GEOMETRY
].atom
, XCB_ATOM_CARDINAL
, 32, 2,
3823 /* Set region bar border to focus_color. */
3824 xcb_change_window_attributes(conn
, r
->bar
->id
,
3825 XCB_CW_BORDER_PIXEL
, &r
->s
->c
[SWM_S_COLOR_BAR_BORDER
].pixel
);
3829 ewmh_update_current_desktop();
3833 focus_region(struct swm_region
*r
)
3836 struct swm_region
*old_r
;
3841 old_r
= r
->s
->r_focus
;
3844 nfw
= get_region_focus(r
);
3848 /* New region is empty; need to manually unfocus win. */
3850 unfocus_win(old_r
->ws
->focus
);
3852 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
, r
->id
,
3855 /* Clear bar since empty. */
3861 switchws(struct swm_region
*r
, union arg
*args
)
3863 struct swm_region
*this_r
, *other_r
;
3865 struct workspace
*new_ws
, *old_ws
;
3866 xcb_window_t none
= XCB_WINDOW_NONE
;
3867 int wsid
= args
->id
;
3868 bool unmap_old
= false;
3873 if (wsid
>= workspace_limit
)
3877 old_ws
= this_r
->ws
;
3878 new_ws
= &this_r
->s
->ws
[wsid
];
3880 DNPRINTF(SWM_D_WS
, "switchws: screen[%d]:%dx%d+%d+%d: %d -> %d\n",
3881 r
->s
->idx
, WIDTH(r
), HEIGHT(r
), X(r
), Y(r
), old_ws
->idx
, wsid
);
3883 if (new_ws
== NULL
|| old_ws
== NULL
)
3885 if (new_ws
== old_ws
)
3888 other_r
= new_ws
->r
;
3889 if (other_r
&& workspace_clamp
) {
3890 DNPRINTF(SWM_D_WS
, "switchws: ws clamped.\n");
3893 DNPRINTF(SWM_D_WS
, "switchws: warping focus to region "
3894 "with ws %d.\n", wsid
);
3895 focus_region(other_r
);
3896 center_pointer(other_r
);
3902 if ((win
= old_ws
->focus
) != NULL
) {
3903 update_window_color(win
);
3905 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->s
->root
,
3906 ewmh
[_NET_ACTIVE_WINDOW
].atom
, XCB_ATOM_WINDOW
, 32, 1,
3911 /* the other ws is visible in another region, exchange them */
3912 other_r
->ws_prior
= new_ws
;
3913 other_r
->ws
= old_ws
;
3914 old_ws
->r
= other_r
;
3916 /* the other workspace is hidden, hide this one */
3921 this_r
->ws_prior
= old_ws
;
3922 this_r
->ws
= new_ws
;
3925 /* Set focus_pending before stacking, if needed. */
3926 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& (!new_ws
->focus_pending
||
3927 validate_win(new_ws
->focus_pending
))) {
3928 new_ws
->focus_pending
= get_region_focus(new_ws
->r
);
3929 new_ws
->focus
= new_ws
->focus_prev
;
3930 new_ws
->focus_prev
= NULL
;
3933 new_ws
->state
= SWM_WS_STATE_MAPPING
;
3936 /* unmap old windows */
3938 TAILQ_FOREACH(win
, &old_ws
->winlist
, entry
)
3940 old_ws
->state
= SWM_WS_STATE_HIDDEN
;
3943 /* if workspaces were swapped, then don't wait to set focus */
3944 if (old_ws
->r
&& focus_mode
!= SWM_FOCUS_FOLLOW
) {
3945 if (new_ws
->focus_pending
) {
3946 focus_win(new_ws
->focus_pending
);
3947 new_ws
->focus_pending
= NULL
;
3951 /* Clear bar and set focus on region input win if new ws is empty. */
3952 if (new_ws
->focus_pending
== NULL
&& new_ws
->focus
== NULL
) {
3953 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
, r
->id
,
3958 ewmh_update_current_desktop();
3962 new_ws
->state
= SWM_WS_STATE_MAPPED
;
3964 DNPRINTF(SWM_D_WS
, "switchws: done.\n");
3968 cyclews(struct swm_region
*r
, union arg
*args
)
3971 struct swm_screen
*s
= r
->s
;
3972 bool cycle_all
= false, mv
= false;
3974 DNPRINTF(SWM_D_WS
, "cyclews: id: %d, screen[%d]:%dx%d+%d+%d, ws: %d\n",
3975 args
->id
, r
->s
->idx
, WIDTH(r
), HEIGHT(r
), X(r
), Y(r
), r
->ws
->idx
);
3981 case SWM_ARG_ID_CYCLEWS_MOVE_UP
:
3984 case SWM_ARG_ID_CYCLEWS_UP_ALL
:
3987 case SWM_ARG_ID_CYCLEWS_UP
:
3988 a
.id
= (a
.id
< workspace_limit
- 1) ? a
.id
+ 1 : 0;
3990 case SWM_ARG_ID_CYCLEWS_MOVE_DOWN
:
3993 case SWM_ARG_ID_CYCLEWS_DOWN_ALL
:
3996 case SWM_ARG_ID_CYCLEWS_DOWN
:
3997 a
.id
= (a
.id
> 0) ? a
.id
- 1 : workspace_limit
- 1;
4004 (!cycle_empty
&& TAILQ_EMPTY(&s
->ws
[a
.id
].winlist
)))
4006 if (!cycle_visible
&& s
->ws
[a
.id
].r
!= NULL
)
4013 } while (a
.id
!= r
->ws
->idx
);
4015 DNPRINTF(SWM_D_FOCUS
, "cyclews: done\n");
4019 priorws(struct swm_region
*r
, union arg
*args
)
4025 DNPRINTF(SWM_D_WS
, "priorws: id: %d, screen[%d]:%dx%d+%d+%d, ws: %d\n",
4026 args
->id
, r
->s
->idx
, WIDTH(r
), HEIGHT(r
), X(r
), Y(r
), r
->ws
->idx
);
4028 if (r
->ws_prior
== NULL
)
4031 a
.id
= r
->ws_prior
->idx
;
4033 DNPRINTF(SWM_D_FOCUS
, "priorws: done\n");
4037 focusrg(struct swm_region
*r
, union arg
*args
)
4039 int ridx
= args
->id
, i
, num_screens
;
4040 struct swm_region
*rr
= NULL
;
4042 num_screens
= get_screen_count();
4043 /* do nothing if we don't have more than one screen */
4044 if (!(num_screens
> 1 || outputs
> 1))
4047 DNPRINTF(SWM_D_FOCUS
, "focusrg: id: %d\n", ridx
);
4049 rr
= TAILQ_FIRST(&r
->s
->rl
);
4050 for (i
= 0; i
< ridx
&& rr
!= NULL
; ++i
)
4051 rr
= TAILQ_NEXT(rr
, entry
);
4059 DNPRINTF(SWM_D_FOCUS
, "focusrg: done\n");
4063 cyclerg(struct swm_region
*r
, union arg
*args
)
4066 struct swm_region
*rr
= NULL
;
4069 num_screens
= get_screen_count();
4070 /* do nothing if we don't have more than one screen */
4071 if (!(num_screens
> 1 || outputs
> 1))
4075 DNPRINTF(SWM_D_FOCUS
, "cyclerg: id: %d, region: %d\n", args
->id
, i
);
4078 case SWM_ARG_ID_CYCLERG_UP
:
4079 case SWM_ARG_ID_CYCLERG_MOVE_UP
:
4080 rr
= TAILQ_NEXT(r
, entry
);
4082 rr
= TAILQ_FIRST(&screens
[i
].rl
);
4084 case SWM_ARG_ID_CYCLERG_DOWN
:
4085 case SWM_ARG_ID_CYCLERG_MOVE_DOWN
:
4086 rr
= TAILQ_PREV(r
, swm_region_list
, entry
);
4088 rr
= TAILQ_LAST(&screens
[i
].rl
, swm_region_list
);
4097 case SWM_ARG_ID_CYCLERG_UP
:
4098 case SWM_ARG_ID_CYCLERG_DOWN
:
4103 case SWM_ARG_ID_CYCLERG_MOVE_UP
:
4104 case SWM_ARG_ID_CYCLERG_MOVE_DOWN
:
4112 DNPRINTF(SWM_D_FOCUS
, "cyclerg: done\n");
4115 /* Sorts transients after parent. */
4117 sort_windows(struct ws_win_list
*wl
)
4119 struct ws_win
*win
, *parent
, *nxt
;
4124 for (win
= TAILQ_FIRST(wl
); win
!= TAILQ_END(wl
); win
= nxt
) {
4125 nxt
= TAILQ_NEXT(win
, entry
);
4127 parent
= find_window(win
->transient
);
4128 if (parent
== NULL
) {
4129 warnx("not possible bug");
4132 TAILQ_REMOVE(wl
, win
, entry
);
4133 TAILQ_INSERT_AFTER(wl
, parent
, win
, entry
);
4139 swapwin(struct swm_region
*r
, union arg
*args
)
4141 struct ws_win
*target
, *source
;
4142 struct ws_win
*cur_focus
;
4143 struct ws_win_list
*wl
;
4145 DNPRINTF(SWM_D_WS
, "swapwin: id: %d, screen[%d]:%dx%d+%d+%d, ws: %d\n",
4146 args
->id
, r
->s
->idx
, WIDTH(r
), HEIGHT(r
), X(r
), Y(r
), r
->ws
->idx
);
4148 cur_focus
= r
->ws
->focus
;
4149 if (cur_focus
== NULL
|| FULLSCREEN(cur_focus
))
4152 /* Adjust stacking in floating layer. */
4153 if (ABOVE(cur_focus
)) {
4155 case SWM_ARG_ID_SWAPPREV
:
4156 target
= TAILQ_PREV(cur_focus
, ws_win_stack
,
4158 if (target
!= NULL
&& FLOATING(target
)) {
4159 TAILQ_REMOVE(&cur_focus
->ws
->stack
, cur_focus
,
4161 TAILQ_INSERT_BEFORE(target
, cur_focus
,
4163 update_win_stacking(cur_focus
);
4167 case SWM_ARG_ID_SWAPNEXT
:
4168 target
= TAILQ_NEXT(cur_focus
, stack_entry
);
4169 if (target
!= NULL
&& FLOATING(target
)) {
4170 TAILQ_REMOVE(&cur_focus
->ws
->stack
, cur_focus
,
4172 TAILQ_INSERT_AFTER(&cur_focus
->ws
->stack
,
4173 target
, cur_focus
, stack_entry
);
4174 update_win_stacking(cur_focus
);
4182 if (r
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
4185 clear_maximized(r
->ws
);
4188 wl
= &source
->ws
->winlist
;
4191 case SWM_ARG_ID_SWAPPREV
:
4193 source
= find_window(source
->transient
);
4194 target
= TAILQ_PREV(source
, ws_win_list
, entry
);
4195 if (target
&& target
->transient
)
4196 target
= find_window(target
->transient
);
4197 TAILQ_REMOVE(wl
, source
, entry
);
4199 TAILQ_INSERT_TAIL(wl
, source
, entry
);
4201 TAILQ_INSERT_BEFORE(target
, source
, entry
);
4203 case SWM_ARG_ID_SWAPNEXT
:
4204 target
= TAILQ_NEXT(source
, entry
);
4205 /* move the parent and let the sort handle the move */
4207 source
= find_window(source
->transient
);
4208 TAILQ_REMOVE(wl
, source
, entry
);
4210 TAILQ_INSERT_HEAD(wl
, source
, entry
);
4212 TAILQ_INSERT_AFTER(wl
, target
, source
, entry
);
4214 case SWM_ARG_ID_SWAPMAIN
:
4215 target
= TAILQ_FIRST(wl
);
4216 if (target
== source
) {
4217 if (source
->ws
->focus_prev
!= NULL
&&
4218 source
->ws
->focus_prev
!= target
)
4219 source
= source
->ws
->focus_prev
;
4223 if (target
== NULL
|| source
== NULL
)
4225 source
->ws
->focus_prev
= target
;
4226 TAILQ_REMOVE(wl
, target
, entry
);
4227 TAILQ_INSERT_BEFORE(source
, target
, entry
);
4228 TAILQ_REMOVE(wl
, source
, entry
);
4229 TAILQ_INSERT_HEAD(wl
, source
, entry
);
4231 case SWM_ARG_ID_MOVELAST
:
4232 TAILQ_REMOVE(wl
, source
, entry
);
4233 TAILQ_INSERT_TAIL(wl
, source
, entry
);
4236 DNPRINTF(SWM_D_MOVE
, "swapwin: invalid id: %d\n", args
->id
);
4241 ewmh_update_client_list();
4247 DNPRINTF(SWM_D_MOVE
, "swapwin: done\n");
4251 get_focus_prev(struct ws_win
*win
)
4253 struct ws_win
*winfocus
= NULL
;
4254 struct ws_win
*cur_focus
= NULL
;
4255 struct ws_win_list
*wl
= NULL
;
4256 struct workspace
*ws
= NULL
;
4258 if (!(win
&& win
->ws
))
4263 cur_focus
= ws
->focus
;
4265 DNPRINTF(SWM_D_FOCUS
, "get_focus_prev: win %#x, cur_focus: %#x, "
4266 "focus_prev: %#x\n", WINID(win
), WINID(cur_focus
),
4267 WINID(ws
->focus_prev
));
4269 /* pickle, just focus on whatever */
4270 if (cur_focus
== NULL
) {
4271 /* use prev_focus if valid */
4272 if (ws
->focus_prev
&& find_window(ws
->focus_prev
->id
))
4273 winfocus
= ws
->focus_prev
;
4277 /* if transient focus on parent */
4278 if (TRANS(cur_focus
)) {
4279 winfocus
= find_window(cur_focus
->transient
);
4283 /* if in max_stack try harder */
4284 if ((win
->quirks
& SWM_Q_FOCUSPREV
) ||
4285 (ws
->cur_layout
->flags
& SWM_L_FOCUSPREV
)) {
4286 if (cur_focus
!= ws
->focus_prev
)
4287 winfocus
= ws
->focus_prev
;
4289 winfocus
= TAILQ_PREV(win
, ws_win_list
, entry
);
4294 DNPRINTF(SWM_D_FOCUS
, "get_focus_prev: focus_close: %d\n", focus_close
);
4296 if (winfocus
== NULL
|| winfocus
== win
) {
4297 switch (focus_close
) {
4298 case SWM_STACK_BOTTOM
:
4299 TAILQ_FOREACH(winfocus
, wl
, entry
)
4300 if (!ICONIC(winfocus
) && winfocus
!= cur_focus
)
4304 TAILQ_FOREACH_REVERSE(winfocus
, wl
, ws_win_list
, entry
)
4305 if (!ICONIC(winfocus
) && winfocus
!= cur_focus
)
4308 case SWM_STACK_ABOVE
:
4309 winfocus
= TAILQ_NEXT(cur_focus
, entry
);
4310 while (winfocus
&& ICONIC(winfocus
))
4311 winfocus
= TAILQ_NEXT(winfocus
, entry
);
4313 if (winfocus
== NULL
) {
4314 if (focus_close_wrap
) {
4315 TAILQ_FOREACH(winfocus
, wl
, entry
)
4316 if (!ICONIC(winfocus
) &&
4317 winfocus
!= cur_focus
)
4320 TAILQ_FOREACH_REVERSE(winfocus
, wl
,
4322 if (!ICONIC(winfocus
) &&
4323 winfocus
!= cur_focus
)
4328 case SWM_STACK_BELOW
:
4329 winfocus
= TAILQ_PREV(cur_focus
, ws_win_list
, entry
);
4330 while (winfocus
&& ICONIC(winfocus
))
4331 winfocus
= TAILQ_PREV(winfocus
, ws_win_list
,
4334 if (winfocus
== NULL
) {
4335 if (focus_close_wrap
) {
4336 TAILQ_FOREACH_REVERSE(winfocus
, wl
,
4338 if (!ICONIC(winfocus
) &&
4339 winfocus
!= cur_focus
)
4342 TAILQ_FOREACH(winfocus
, wl
, entry
)
4343 if (!ICONIC(winfocus
) &&
4344 winfocus
!= cur_focus
)
4352 if (winfocus
== NULL
||
4353 (winfocus
&& (ICONIC(winfocus
) || winfocus
== cur_focus
))) {
4354 if (focus_default
== SWM_STACK_TOP
) {
4355 TAILQ_FOREACH_REVERSE(winfocus
, wl
, ws_win_list
, entry
)
4356 if (!ICONIC(winfocus
) && winfocus
!= cur_focus
)
4359 TAILQ_FOREACH(winfocus
, wl
, entry
)
4360 if (!ICONIC(winfocus
) && winfocus
!= cur_focus
)
4367 return get_focus_magic(winfocus
);
4371 get_region_focus(struct swm_region
*r
)
4373 struct ws_win
*winfocus
= NULL
;
4378 if (r
->ws
->focus
&& !ICONIC(r
->ws
->focus
))
4379 winfocus
= r
->ws
->focus
;
4380 else if (r
->ws
->focus_prev
&& !ICONIC(r
->ws
->focus_prev
))
4381 winfocus
= r
->ws
->focus_prev
;
4383 TAILQ_FOREACH(winfocus
, &r
->ws
->winlist
, entry
)
4384 if (!ICONIC(winfocus
))
4387 return get_focus_magic(winfocus
);
4391 focus(struct swm_region
*r
, union arg
*args
)
4393 struct ws_win
*head
, *cur_focus
= NULL
, *winfocus
= NULL
;
4394 struct ws_win_list
*wl
= NULL
;
4395 struct workspace
*ws
= NULL
;
4402 cur_focus
= r
->ws
->focus
;
4406 DNPRINTF(SWM_D_FOCUS
, "focus: id: %d, cur_focus: %#x\n", args
->id
,
4409 /* Make sure an uniconified window has focus, if one exists. */
4410 if (cur_focus
== NULL
) {
4411 cur_focus
= TAILQ_FIRST(wl
);
4412 while (cur_focus
!= NULL
&& ICONIC(cur_focus
))
4413 cur_focus
= TAILQ_NEXT(cur_focus
, entry
);
4415 DNPRINTF(SWM_D_FOCUS
, "focus: new cur_focus: %#x\n",
4420 case SWM_ARG_ID_FOCUSPREV
:
4421 if (cur_focus
== NULL
)
4424 winfocus
= cur_focus
;
4426 winfocus
= TAILQ_PREV(winfocus
, ws_win_list
, entry
);
4427 if (winfocus
== NULL
)
4428 winfocus
= TAILQ_LAST(wl
, ws_win_list
);
4429 if (winfocus
== cur_focus
)
4431 } while (winfocus
&& (ICONIC(winfocus
) ||
4432 winfocus
->id
== cur_focus
->transient
||
4433 (cur_focus
->transient
!= XCB_WINDOW_NONE
&&
4434 winfocus
->transient
== cur_focus
->transient
) ||
4435 (winfocus
->quirks
& SWM_Q_NOFOCUSCYCLE
)));
4437 case SWM_ARG_ID_FOCUSNEXT
:
4438 if (cur_focus
== NULL
)
4441 winfocus
= cur_focus
;
4443 winfocus
= TAILQ_NEXT(winfocus
, entry
);
4444 if (winfocus
== NULL
)
4445 winfocus
= TAILQ_FIRST(wl
);
4446 if (winfocus
== cur_focus
)
4448 } while (winfocus
&& (ICONIC(winfocus
) ||
4449 winfocus
->id
== cur_focus
->transient
||
4450 (cur_focus
->transient
!= XCB_WINDOW_NONE
&&
4451 winfocus
->transient
== cur_focus
->transient
) ||
4452 (winfocus
->quirks
& SWM_Q_NOFOCUSCYCLE
)));
4454 case SWM_ARG_ID_FOCUSMAIN
:
4455 if (cur_focus
== NULL
)
4458 winfocus
= TAILQ_FIRST(wl
);
4459 if (winfocus
== cur_focus
)
4460 winfocus
= cur_focus
->ws
->focus_prev
;
4462 case SWM_ARG_ID_FOCUSURGENT
:
4463 /* Search forward for the next urgent window. */
4467 for (i
= 0; i
<= workspace_limit
; ++i
) {
4469 head
= TAILQ_FIRST(&r
->s
->ws
[(ws
->idx
+ i
) %
4470 workspace_limit
].winlist
);
4473 if (head
== cur_focus
) {
4475 winfocus
= cur_focus
;
4478 } else if (get_urgent(head
)) {
4483 head
= TAILQ_NEXT(head
, entry
);
4490 /* Switch ws if new focus is on a different ws. */
4491 if (winfocus
&& winfocus
->ws
!= ws
) {
4492 a
.id
= winfocus
->ws
->idx
;
4500 if (clear_maximized(ws
) > 0)
4503 focus_win(get_focus_magic(winfocus
));
4508 DNPRINTF(SWM_D_FOCUS
, "focus: done\n");
4512 cycle_layout(struct swm_region
*r
, union arg
*args
)
4514 struct workspace
*ws
= r
->ws
;
4516 /* suppress unused warning since var is needed */
4519 DNPRINTF(SWM_D_EVENT
, "cycle_layout: workspace: %d\n", ws
->idx
);
4522 if (ws
->cur_layout
->l_stack
== NULL
)
4523 ws
->cur_layout
= &layouts
[0];
4525 clear_maximized(ws
);
4530 focus_win(get_region_focus(r
));
4537 stack_config(struct swm_region
*r
, union arg
*args
)
4539 struct workspace
*ws
= r
->ws
;
4541 DNPRINTF(SWM_D_STACK
, "stack_config: id: %d workspace: %d\n",
4544 if (clear_maximized(ws
) > 0)
4547 if (ws
->cur_layout
->l_config
!= NULL
)
4548 ws
->cur_layout
->l_config(ws
, args
->id
);
4550 if (args
->id
!= SWM_ARG_ID_STACKINIT
)
4560 struct swm_geometry g
;
4561 struct swm_region
*r
, *r_prev
= NULL
;
4568 DNPRINTF(SWM_D_STACK
, "stack: begin\n");
4570 num_screens
= get_screen_count();
4571 for (i
= 0; i
< num_screens
; i
++) {
4575 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
) {
4576 /* Adjust stack area for region bar and padding. */
4578 g
.x
+= region_padding
;
4579 g
.y
+= region_padding
;
4580 g
.w
-= 2 * border_width
+ 2 * region_padding
;
4581 g
.h
-= 2 * border_width
+ 2 * region_padding
;
4582 if (bar_enabled
&& r
->ws
->bar_enabled
) {
4588 DNPRINTF(SWM_D_STACK
, "stack: workspace: %d (screen: "
4589 "%d, region: %d), (x,y) WxH: (%d,%d) %d x %d\n",
4590 r
->ws
->idx
, i
, j
++, g
.x
, g
.y
, g
.w
, g
.h
);
4593 /* Stack bar/input relative to prev. region. */
4594 val
[1] = XCB_STACK_MODE_ABOVE
;
4596 val
[0] = r_prev
->id
;
4597 DNPRINTF(SWM_D_STACK
, "stack: region input %#x "
4598 "relative to %#x.\n", r
->id
, val
[0]);
4599 xcb_configure_window(conn
, r
->id
,
4600 XCB_CONFIG_WINDOW_SIBLING
|
4601 XCB_CONFIG_WINDOW_STACK_MODE
, val
);
4603 val
[0] = r_prev
->bar
->id
;
4604 DNPRINTF(SWM_D_STACK
, "stack: region bar %#x "
4605 "relative to %#x.\n", r
->bar
->id
, val
[0]);
4606 xcb_configure_window(conn
, r
->bar
->id
,
4607 XCB_CONFIG_WINDOW_SIBLING
|
4608 XCB_CONFIG_WINDOW_STACK_MODE
, val
);
4611 r
->ws
->cur_layout
->l_stack(r
->ws
, &g
);
4612 r
->ws
->cur_layout
->l_string(r
->ws
);
4613 /* save r so we can track region changes */
4621 DNPRINTF(SWM_D_STACK
, "stack: end\n");
4625 store_float_geom(struct ws_win
*win
)
4627 if (win
== NULL
|| win
->ws
->r
== NULL
)
4630 /* retain window geom and region geom */
4631 win
->g_float
= win
->g
;
4632 win
->g_float
.x
-= X(win
->ws
->r
);
4633 win
->g_float
.y
-= Y(win
->ws
->r
);
4634 win
->g_floatvalid
= true;
4635 DNPRINTF(SWM_D_MISC
, "store_float_geom: win %#x, g: (%d,%d)"
4636 " %d x %d, g_float: (%d,%d) %d x %d\n", win
->id
, X(win
), Y(win
),
4637 WIDTH(win
), HEIGHT(win
), win
->g_float
.x
, win
->g_float
.y
,
4638 win
->g_float
.w
, win
->g_float
.h
);
4642 load_float_geom(struct ws_win
*win
)
4644 if (win
== NULL
|| win
->ws
->r
== NULL
)
4647 if (win
->g_floatvalid
) {
4648 win
->g
= win
->g_float
;
4649 X(win
) += X(win
->ws
->r
);
4650 Y(win
) += Y(win
->ws
->r
);
4651 DNPRINTF(SWM_D_MISC
, "load_float_geom: win %#x, g: (%d,%d)"
4652 "%d x %d\n", win
->id
, X(win
), Y(win
), WIDTH(win
),
4655 DNPRINTF(SWM_D_MISC
, "load_float_geom: win %#x, g_float "
4656 "is not set.\n", win
->id
);
4661 update_floater(struct ws_win
*win
)
4663 struct workspace
*ws
;
4664 struct swm_region
*r
;
4671 if ((r
= ws
->r
) == NULL
)
4674 DNPRINTF(SWM_D_MISC
, "update_floater: win %#x\n", win
->id
);
4676 win
->bordered
= true;
4678 if (FULLSCREEN(win
)) {
4679 /* _NET_WM_FULLSCREEN: fullscreen without border. */
4680 if (!win
->g_floatvalid
)
4681 store_float_geom(win
);
4684 win
->bordered
= false;
4685 } else if (MAXIMIZED(win
)) {
4686 /* Maximize: like a single stacked window. */
4687 if (!win
->g_floatvalid
)
4688 store_float_geom(win
);
4692 if (bar_enabled
&& ws
->bar_enabled
&& !maximize_hide_bar
) {
4694 Y(win
) += bar_height
;
4695 HEIGHT(win
) -= bar_height
;
4696 } else if (disable_border
) {
4697 win
->bordered
= false;
4700 if (win
->bordered
) {
4701 HEIGHT(win
) -= 2 * border_width
;
4702 WIDTH(win
) -= 2 * border_width
;
4705 /* Normal floating window. */
4706 /* Update geometry if new region. */
4708 load_float_geom(win
);
4710 if ((win
->quirks
& SWM_Q_FULLSCREEN
) &&
4711 WIDTH(win
) >= WIDTH(r
) && HEIGHT(win
) >= HEIGHT(r
)) {
4712 /* Remove border for FULLSCREEN quirk. */
4713 win
->bordered
= false;
4714 } else if (!MANUAL(win
)) {
4715 if (TRANS(win
) && (win
->quirks
& SWM_Q_TRANSSZ
)) {
4716 /* Adjust size on TRANSSZ quirk. */
4717 WIDTH(win
) = (double)WIDTH(r
) * dialog_ratio
;
4718 HEIGHT(win
) = (double)HEIGHT(r
) * dialog_ratio
;
4721 if (!(win
->quirks
& SWM_Q_ANYWHERE
)) {
4723 * Floaters and transients are auto-centred
4724 * unless manually moved, resized or ANYWHERE
4727 X(win
) = X(r
) + (WIDTH(r
) - WIDTH(win
)) / 2 -
4729 Y(win
) = Y(r
) + (HEIGHT(r
) - HEIGHT(win
)) / 2 -
4731 store_float_geom(win
);
4736 /* Ensure at least 1 pixel of the window is in the region. */
4737 region_containment(win
, r
, SWM_CW_ALLSIDES
);
4743 * Send keystrokes to terminal to decrease/increase the font size as the
4744 * window size changes.
4747 adjust_font(struct ws_win
*win
)
4749 if (!(win
->quirks
& SWM_Q_XTERM_FONTADJ
) ||
4750 ABOVE(win
) || TRANS(win
))
4753 if (win
->sh
.width_inc
&& win
->last_inc
!= win
->sh
.width_inc
&&
4754 WIDTH(win
) / win
->sh
.width_inc
< term_width
&&
4755 win
->font_steps
< SWM_MAX_FONT_STEPS
) {
4756 win
->font_size_boundary
[win
->font_steps
] =
4757 (win
->sh
.width_inc
* term_width
) + win
->sh
.base_width
;
4760 win
->last_inc
= win
->sh
.width_inc
;
4761 fake_keypress(win
, XK_KP_Subtract
, XCB_MOD_MASK_SHIFT
);
4762 } else if (win
->font_steps
&& win
->last_inc
!= win
->sh
.width_inc
&&
4763 WIDTH(win
) > win
->font_size_boundary
[win
->font_steps
- 1]) {
4766 win
->last_inc
= win
->sh
.width_inc
;
4767 fake_keypress(win
, XK_KP_Add
, XCB_MOD_MASK_SHIFT
);
4771 #define SWAPXY(g) do { \
4773 tmp = (g)->y; (g)->y = (g)->x; (g)->x = tmp; \
4774 tmp = (g)->h; (g)->h = (g)->w; (g)->w = tmp; \
4777 stack_master(struct workspace
*ws
, struct swm_geometry
*g
, int rot
, bool flip
)
4779 struct swm_geometry win_g
, r_g
= *g
;
4781 int i
, j
, s
, stacks
;
4782 int w_inc
= 1, h_inc
, w_base
= 1, h_base
;
4783 int hrh
, extra
= 0, h_slice
, last_h
= 0;
4784 int split
, colno
, winno
, mwin
, msize
, mscale
;
4785 int remain
, missing
, v_slice
;
4786 bool bordered
= true, reconfigure
= false;
4788 DNPRINTF(SWM_D_STACK
, "stack_master: workspace: %d, rot: %s, "
4789 "flip: %s\n", ws
->idx
, YESNO(rot
), YESNO(flip
));
4791 /* Prepare tiling variables, if needed. */
4792 if ((winno
= count_win(ws
, false)) > 0) {
4793 /* Find first tiled window. */
4794 TAILQ_FOREACH(win
, &ws
->winlist
, entry
)
4795 if (!FLOATING(win
) && !ICONIC(win
))
4798 /* Take into account size hints of first tiled window. */
4800 w_inc
= win
->sh
.width_inc
;
4801 w_base
= win
->sh
.base_width
;
4802 mwin
= ws
->l_state
.horizontal_mwin
;
4803 mscale
= ws
->l_state
.horizontal_msize
;
4804 stacks
= ws
->l_state
.horizontal_stacks
;
4807 w_inc
= win
->sh
.height_inc
;
4808 w_base
= win
->sh
.base_height
;
4809 mwin
= ws
->l_state
.vertical_mwin
;
4810 mscale
= ws
->l_state
.vertical_msize
;
4811 stacks
= ws
->l_state
.vertical_stacks
;
4815 if (stacks
> winno
- mwin
)
4816 stacks
= winno
- mwin
;
4820 h_slice
= r_g
.h
/ SWM_H_SLICE
;
4821 if (mwin
&& winno
> mwin
) {
4822 v_slice
= r_g
.w
/ SWM_V_SLICE
;
4826 win_g
.w
= v_slice
* mscale
;
4828 if (w_inc
> 1 && w_inc
< v_slice
) {
4829 /* Adjust for requested size increment. */
4830 remain
= (win_g
.w
- w_base
) % w_inc
;
4836 win_g
.x
+= r_g
.w
- msize
;
4839 colno
= split
= winno
/ stacks
;
4840 win_g
.w
= ((r_g
.w
- (stacks
* 2 * border_width
) +
4841 2 * border_width
) / stacks
);
4843 hrh
= r_g
.h
/ colno
;
4844 extra
= r_g
.h
- (colno
* hrh
);
4845 win_g
.h
= hrh
- 2 * border_width
;
4846 i
= j
= 0, s
= stacks
;
4849 /* Update window geometry. */
4850 TAILQ_FOREACH(win
, &ws
->winlist
, entry
) {
4854 if (FLOATING(win
)) {
4855 update_floater(win
);
4860 if (split
&& i
== split
) {
4861 colno
= (winno
- mwin
) / stacks
;
4862 if (s
<= (winno
- mwin
) % stacks
)
4865 hrh
= r_g
.h
/ colno
;
4866 extra
= r_g
.h
- (colno
* hrh
);
4869 win_g
.x
+= win_g
.w
+ 2 * border_width
+
4872 win_g
.w
= (r_g
.w
- msize
-
4873 (stacks
* (2 * border_width
+ tile_gap
))) / stacks
;
4875 win_g
.w
+= (r_g
.w
- msize
-
4876 (stacks
* (2 * border_width
+ tile_gap
))) %
4880 win_g
.x
-= win_g
.w
+ 2 * border_width
+
4886 win_g
.h
= hrh
- 2 * border_width
- tile_gap
;
4889 h_inc
= win
->sh
.width_inc
;
4890 h_base
= win
->sh
.base_width
;
4892 h_inc
= win
->sh
.height_inc
;
4893 h_base
= win
->sh
.base_height
;
4896 if (j
== colno
- 1) {
4897 win_g
.h
= hrh
+ extra
;
4898 } else if (h_inc
> 1 && h_inc
< h_slice
) {
4899 /* adjust for window's requested size increment */
4900 remain
= (win_g
.h
- h_base
) % h_inc
;
4901 missing
= h_inc
- remain
;
4903 if (missing
<= extra
|| j
== 0) {
4915 win_g
.y
+= last_h
+ 2 * border_width
+ tile_gap
;
4917 if (disable_border
&& !(bar_enabled
&& ws
->bar_enabled
) &&
4920 win_g
.w
+= 2 * border_width
;
4921 win_g
.h
+= 2 * border_width
;
4927 if (X(win
) != win_g
.y
|| Y(win
) != win_g
.x
||
4928 WIDTH(win
) != win_g
.h
|| HEIGHT(win
) != win_g
.w
) {
4932 WIDTH(win
) = win_g
.h
;
4933 HEIGHT(win
) = win_g
.w
;
4936 if (X(win
) != win_g
.x
|| Y(win
) != win_g
.y
||
4937 WIDTH(win
) != win_g
.w
|| HEIGHT(win
) != win_g
.h
) {
4941 WIDTH(win
) = win_g
.w
;
4942 HEIGHT(win
) = win_g
.h
;
4946 if (bordered
!= win
->bordered
) {
4948 win
->bordered
= bordered
;
4961 /* Stack all windows from bottom up. */
4962 TAILQ_FOREACH_REVERSE(win
, &ws
->stack
, ws_win_stack
, stack_entry
)
4964 update_win_stacking(win
);
4966 /* Map all windows from top down. */
4967 TAILQ_FOREACH(win
, &ws
->stack
, stack_entry
)
4971 DNPRINTF(SWM_D_STACK
, "stack_master: done\n");
4975 vertical_config(struct workspace
*ws
, int id
)
4977 DNPRINTF(SWM_D_STACK
, "vertical_config: id: %d, workspace: %d\n",
4981 case SWM_ARG_ID_STACKRESET
:
4982 case SWM_ARG_ID_STACKINIT
:
4983 ws
->l_state
.vertical_msize
= SWM_V_SLICE
/ 2;
4984 ws
->l_state
.vertical_mwin
= 1;
4985 ws
->l_state
.vertical_stacks
= 1;
4987 case SWM_ARG_ID_MASTERSHRINK
:
4988 if (ws
->l_state
.vertical_msize
> 1)
4989 ws
->l_state
.vertical_msize
--;
4991 case SWM_ARG_ID_MASTERGROW
:
4992 if (ws
->l_state
.vertical_msize
< SWM_V_SLICE
- 1)
4993 ws
->l_state
.vertical_msize
++;
4995 case SWM_ARG_ID_MASTERADD
:
4996 ws
->l_state
.vertical_mwin
++;
4998 case SWM_ARG_ID_MASTERDEL
:
4999 if (ws
->l_state
.vertical_mwin
> 0)
5000 ws
->l_state
.vertical_mwin
--;
5002 case SWM_ARG_ID_STACKBALANCE
:
5003 ws
->l_state
.vertical_msize
= SWM_V_SLICE
/ (ws
->l_state
.vertical_stacks
+ 1);
5005 case SWM_ARG_ID_STACKINC
:
5006 ws
->l_state
.vertical_stacks
++;
5008 case SWM_ARG_ID_STACKDEC
:
5009 if (ws
->l_state
.vertical_stacks
> 1)
5010 ws
->l_state
.vertical_stacks
--;
5012 case SWM_ARG_ID_FLIPLAYOUT
:
5013 ws
->l_state
.vertical_flip
= !ws
->l_state
.vertical_flip
;
5021 vertical_stack(struct workspace
*ws
, struct swm_geometry
*g
)
5023 DNPRINTF(SWM_D_STACK
, "vertical_stack: workspace: %d\n", ws
->idx
);
5025 stack_master(ws
, g
, 0, ws
->l_state
.vertical_flip
);
5029 horizontal_config(struct workspace
*ws
, int id
)
5031 DNPRINTF(SWM_D_STACK
, "horizontal_config: workspace: %d\n", ws
->idx
);
5034 case SWM_ARG_ID_STACKRESET
:
5035 case SWM_ARG_ID_STACKINIT
:
5036 ws
->l_state
.horizontal_mwin
= 1;
5037 ws
->l_state
.horizontal_msize
= SWM_H_SLICE
/ 2;
5038 ws
->l_state
.horizontal_stacks
= 1;
5040 case SWM_ARG_ID_MASTERSHRINK
:
5041 if (ws
->l_state
.horizontal_msize
> 1)
5042 ws
->l_state
.horizontal_msize
--;
5044 case SWM_ARG_ID_MASTERGROW
:
5045 if (ws
->l_state
.horizontal_msize
< SWM_H_SLICE
- 1)
5046 ws
->l_state
.horizontal_msize
++;
5048 case SWM_ARG_ID_MASTERADD
:
5049 ws
->l_state
.horizontal_mwin
++;
5051 case SWM_ARG_ID_MASTERDEL
:
5052 if (ws
->l_state
.horizontal_mwin
> 0)
5053 ws
->l_state
.horizontal_mwin
--;
5055 case SWM_ARG_ID_STACKBALANCE
:
5056 ws
->l_state
.horizontal_msize
= SWM_H_SLICE
/ (ws
->l_state
.horizontal_stacks
+ 1);
5058 case SWM_ARG_ID_STACKINC
:
5059 ws
->l_state
.horizontal_stacks
++;
5061 case SWM_ARG_ID_STACKDEC
:
5062 if (ws
->l_state
.horizontal_stacks
> 1)
5063 ws
->l_state
.horizontal_stacks
--;
5065 case SWM_ARG_ID_FLIPLAYOUT
:
5066 ws
->l_state
.horizontal_flip
= !ws
->l_state
.horizontal_flip
;
5074 horizontal_stack(struct workspace
*ws
, struct swm_geometry
*g
)
5076 DNPRINTF(SWM_D_STACK
, "horizontal_stack: workspace: %d\n", ws
->idx
);
5078 stack_master(ws
, g
, 1, ws
->l_state
.horizontal_flip
);
5081 /* fullscreen view */
5083 max_stack(struct workspace
*ws
, struct swm_geometry
*g
)
5085 struct swm_geometry gg
= *g
;
5086 struct ws_win
*w
, *win
= NULL
, *parent
= NULL
, *tmpw
;
5089 DNPRINTF(SWM_D_STACK
, "max_stack: workspace: %d\n", ws
->idx
);
5094 winno
= count_win(ws
, false);
5095 if (winno
== 0 && count_win(ws
, true) == 0)
5098 /* Figure out which top level window should be visible. */
5099 if (ws
->focus_pending
)
5100 win
= ws
->focus_pending
;
5103 else if (ws
->focus_prev
)
5104 win
= ws
->focus_prev
;
5106 win
= TAILQ_FIRST(&ws
->winlist
);
5108 DNPRINTF(SWM_D_STACK
, "max_stack: focus_pending: %#x, focus: %#x, "
5109 "focus_prev: %#x, first: %#x, win: %#x\n", WINID(ws
->focus_pending
),
5110 WINID(ws
->focus
), WINID(ws
->focus_prev
),
5111 WINID(TAILQ_FIRST(&ws
->winlist
)), win
->id
);
5113 /* Update window geometry. */
5114 TAILQ_FOREACH(w
, &ws
->winlist
, entry
) {
5123 /* Set maximized flag for all maxed windows. */
5124 if (!MAXIMIZED(w
)) {
5125 /* Preserve floating geometry. */
5127 store_float_geom(w
);
5129 ewmh_apply_flags(w
, w
->ewmh_flags
| EWMH_F_MAXIMIZED
);
5130 ewmh_update_wm_state(w
);
5133 /* Only reconfigure if necessary. */
5134 if (X(w
) != gg
.x
|| Y(w
) != gg
.y
|| WIDTH(w
) != gg
.w
||
5135 HEIGHT(w
) != gg
.h
) {
5138 if (disable_border
&& !(bar_enabled
&& ws
->bar_enabled
)) {
5139 w
->bordered
= false;
5140 WIDTH(w
) += 2 * border_width
;
5141 HEIGHT(w
) += 2 * border_width
;
5150 /* If transient, stack parent and its children. */
5151 if (TRANS(win
) && (parent
= find_window(win
->transient
))) {
5152 raise_window(parent
);
5154 TAILQ_FOREACH_SAFE(w
, &ws
->stack
, stack_entry
, tmpw
)
5155 if (w
->transient
== parent
->id
)
5159 /* Make sure focus window is on top. */
5162 /* Stack any children of focus window. */
5163 TAILQ_FOREACH_SAFE(w
, &ws
->stack
, stack_entry
, tmpw
)
5164 if (w
->transient
== win
->id
)
5167 /* Map all windows. */
5168 TAILQ_FOREACH(w
, &ws
->stack
, stack_entry
)
5174 send_to_rg(struct swm_region
*r
, union arg
*args
)
5176 int ridx
= args
->id
, i
, num_screens
;
5177 struct swm_region
*rr
= NULL
;
5180 num_screens
= get_screen_count();
5181 /* do nothing if we don't have more than one screen */
5182 if (!(num_screens
> 1 || outputs
> 1))
5185 DNPRINTF(SWM_D_FOCUS
, "send_to_rg: id: %d\n", ridx
);
5187 rr
= TAILQ_FIRST(&r
->s
->rl
);
5188 for (i
= 0; i
< ridx
&& rr
!= NULL
; ++i
)
5189 rr
= TAILQ_NEXT(rr
, entry
);
5200 region_under(struct swm_screen
*s
, int x
, int y
)
5202 struct swm_region
*r
= NULL
;
5204 TAILQ_FOREACH(r
, &s
->rl
, entry
) {
5205 DNPRINTF(SWM_D_MISC
, "region_under: ws: %d, region g: (%d,%d) "
5206 "%d x %d, coords: (%d,%d)\n", r
->ws
->idx
, X(r
), Y(r
),
5207 WIDTH(r
), HEIGHT(r
), x
, y
);
5208 if (X(r
) <= x
&& x
< MAX_X(r
))
5209 if (Y(r
) <= y
&& y
< MAX_Y(r
))
5216 /* Transfer focused window to target workspace and focus. */
5218 send_to_ws(struct swm_region
*r
, union arg
*args
)
5220 int wsid
= args
->id
;
5221 struct ws_win
*win
= NULL
;
5223 if (r
&& r
->ws
&& r
->ws
->focus
)
5228 DNPRINTF(SWM_D_MOVE
, "send_to_ws: win %#x, ws %d\n", win
->id
, wsid
);
5230 if (wsid
< 0 || wsid
>= workspace_limit
)
5233 if (win
->ws
->idx
== wsid
)
5236 win_to_ws(win
, wsid
, true);
5238 /* Set new focus on target ws. */
5239 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
5240 win
->ws
->focus_prev
= win
->ws
->focus
;
5241 win
->ws
->focus
= win
;
5242 win
->ws
->focus_pending
= NULL
;
5244 if (win
->ws
->focus_prev
)
5245 update_window_color(win
->ws
->focus_prev
);
5248 DNPRINTF(SWM_D_STACK
, "send_to_ws: focus_pending: %#x, focus: %#x, "
5249 "focus_prev: %#x, first: %#x, win: %#x\n",
5250 WINID(r
->ws
->focus_pending
), WINID(r
->ws
->focus
),
5251 WINID(r
->ws
->focus_prev
), WINID(TAILQ_FIRST(&r
->ws
->winlist
)),
5254 ewmh_apply_flags(win
, win
->ewmh_flags
& ~EWMH_F_MAXIMIZED
);
5255 ewmh_update_wm_state(win
);
5257 /* Restack and set new focus on current ws. */
5259 load_float_geom(win
);
5263 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
5264 if (r
->ws
->focus
!= NULL
) {
5265 focus_win(r
->ws
->focus
);
5267 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
, r
->id
,
5278 win_to_ws(struct ws_win
*win
, int wsid
, bool unfocus
)
5280 struct ws_win
*parent
;
5281 struct workspace
*ws
, *nws
, *pws
;
5283 if (wsid
< 0 || wsid
>= workspace_limit
)
5286 if (win
->ws
->idx
== wsid
)
5290 nws
= &win
->s
->ws
[wsid
];
5292 DNPRINTF(SWM_D_MOVE
, "win_to_ws: win %#x, ws %d -> %d\n", win
->id
,
5295 /* Cleanup focus on source ws. */
5296 if (focus_mode
!= SWM_FOCUS_FOLLOW
&&
5297 (ws
->focus
== win
|| ws
->focus_pending
== win
))
5298 ws
->focus_pending
= get_focus_prev(win
);
5300 /* Move the parent if this is a transient window. */
5302 parent
= find_window(win
->transient
);
5305 /* Set new focus in parent's ws if needed. */
5306 if (pws
->focus
== parent
) {
5307 if (focus_mode
!= SWM_FOCUS_FOLLOW
)
5308 pws
->focus_pending
=
5309 get_focus_prev(parent
);
5311 unfocus_win(parent
);
5313 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
5314 pws
->focus
= pws
->focus_pending
;
5315 pws
->focus_pending
= NULL
;
5319 /* Don't unmap parent if new ws is visible */
5321 unmap_window(parent
);
5324 TAILQ_REMOVE(&ws
->winlist
, parent
, entry
);
5325 TAILQ_REMOVE(&ws
->stack
, parent
, stack_entry
);
5326 TAILQ_INSERT_TAIL(&nws
->winlist
, parent
, entry
);
5327 TAILQ_INSERT_TAIL(&nws
->stack
, parent
, stack_entry
);
5330 DNPRINTF(SWM_D_PROP
, "win_to_ws: set property: "
5331 "_NET_WM_DESKTOP: %d\n", wsid
);
5332 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5333 parent
->id
, ewmh
[_NET_WM_DESKTOP
].atom
,
5334 XCB_ATOM_CARDINAL
, 32, 1, &wsid
);
5341 if (ws
->focus_prev
== win
)
5342 ws
->focus_prev
= NULL
;
5344 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& ws
->focus_pending
!= NULL
) {
5345 ws
->focus
= ws
->focus_pending
;
5346 ws
->focus_pending
= NULL
;
5349 /* Don't unmap if new ws is visible */
5354 TAILQ_REMOVE(&ws
->winlist
, win
, entry
);
5355 TAILQ_REMOVE(&ws
->stack
, win
, stack_entry
);
5356 TAILQ_INSERT_TAIL(&nws
->winlist
, win
, entry
);
5357 TAILQ_INSERT_TAIL(&nws
->stack
, win
, stack_entry
);
5360 /* Update the window's workspace property: _NET_WM_DESKTOP */
5361 DNPRINTF(SWM_D_PROP
, "win_to_ws: set property: "
5362 "_NET_WM_DESKTOP: %d\n", wsid
);
5363 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
,
5364 ewmh
[_NET_WM_DESKTOP
].atom
, XCB_ATOM_CARDINAL
, 32, 1, &wsid
);
5366 ewmh_update_client_list();
5368 DNPRINTF(SWM_D_MOVE
, "win_to_ws: done.\n");
5372 pressbutton(struct swm_region
*r
, union arg
*args
)
5374 /* suppress unused warning since var is needed */
5377 xcb_test_fake_input(conn
, XCB_BUTTON_PRESS
, args
->id
,
5378 XCB_CURRENT_TIME
, XCB_WINDOW_NONE
, 0, 0, 0);
5379 xcb_test_fake_input(conn
, XCB_BUTTON_RELEASE
, args
->id
,
5380 XCB_CURRENT_TIME
, XCB_WINDOW_NONE
, 0, 0, 0);
5384 raise_toggle(struct swm_region
*r
, union arg
*args
)
5386 /* Suppress warning. */
5389 if (r
== NULL
|| r
->ws
== NULL
)
5392 if (r
->ws
->focus
&& MAXIMIZED(r
->ws
->focus
))
5395 r
->ws
->always_raise
= !r
->ws
->always_raise
;
5397 /* Update focused win stacking order based on new always_raise value. */
5398 raise_window(r
->ws
->focus
);
5404 iconify(struct swm_region
*r
, union arg
*args
)
5408 /* Suppress warning. */
5411 if ((w
= r
->ws
->focus
) == NULL
)
5414 ewmh_apply_flags(w
, w
->ewmh_flags
| EWMH_F_HIDDEN
);
5415 ewmh_update_wm_state(w
);
5423 get_win_name(xcb_window_t win
)
5426 xcb_get_property_cookie_t c
;
5427 xcb_get_property_reply_t
*r
;
5429 /* First try _NET_WM_NAME for UTF-8. */
5430 c
= xcb_get_property(conn
, 0, win
, ewmh
[_NET_WM_NAME
].atom
,
5431 XCB_GET_PROPERTY_TYPE_ANY
, 0, UINT_MAX
);
5432 r
= xcb_get_property_reply(conn
, c
, NULL
);
5433 if (r
&& r
->type
== XCB_NONE
) {
5435 /* Use WM_NAME instead; no UTF-8. */
5436 c
= xcb_get_property(conn
, 0, win
, XCB_ATOM_WM_NAME
,
5437 XCB_GET_PROPERTY_TYPE_ANY
, 0, UINT_MAX
);
5438 r
= xcb_get_property_reply(conn
, c
, NULL
);
5441 if (r
&& r
->type
!= XCB_NONE
&& r
->length
> 0)
5442 name
= strndup(xcb_get_property_value(r
),
5443 xcb_get_property_value_length(r
));
5448 err(1, "get_win_name: failed to allocate memory.");
5456 uniconify(struct swm_region
*r
, union arg
*args
)
5463 DNPRINTF(SWM_D_MISC
, "uniconify\n");
5465 if (r
== NULL
|| r
->ws
== NULL
)
5468 /* make sure we have anything to uniconify */
5469 TAILQ_FOREACH(win
, &r
->ws
->winlist
, entry
) {
5470 if (win
->ws
== NULL
)
5471 continue; /* should never happen */
5477 DNPRINTF(SWM_D_MISC
, "uniconify: count: %d\n", count
);
5483 search_resp_action
= SWM_SEARCH_UNICONIFY
;
5485 spawn_select(r
, args
, "search", &searchpid
);
5487 if ((lfile
= fdopen(select_list_pipe
[1], "w")) == NULL
)
5490 TAILQ_FOREACH(win
, &r
->ws
->winlist
, entry
) {
5491 if (win
->ws
== NULL
)
5492 continue; /* should never happen */
5496 name
= get_win_name(win
->id
);
5497 fprintf(lfile
, "%s.%u\n", name
, win
->id
);
5505 name_workspace(struct swm_region
*r
, union arg
*args
)
5509 DNPRINTF(SWM_D_MISC
, "name_workspace\n");
5515 search_resp_action
= SWM_SEARCH_NAME_WORKSPACE
;
5517 spawn_select(r
, args
, "name_workspace", &searchpid
);
5519 if ((lfile
= fdopen(select_list_pipe
[1], "w")) == NULL
)
5522 fprintf(lfile
, "%s", "");
5527 search_workspace(struct swm_region
*r
, union arg
*args
)
5530 struct workspace
*ws
;
5533 DNPRINTF(SWM_D_MISC
, "search_workspace\n");
5539 search_resp_action
= SWM_SEARCH_SEARCH_WORKSPACE
;
5541 spawn_select(r
, args
, "search", &searchpid
);
5543 if ((lfile
= fdopen(select_list_pipe
[1], "w")) == NULL
)
5546 for (i
= 0; i
< workspace_limit
; i
++) {
5550 fprintf(lfile
, "%d%s%s\n", ws
->idx
+ 1,
5551 (ws
->name
? ":" : ""), (ws
->name
? ws
->name
: ""));
5558 search_win_cleanup(void)
5560 struct search_window
*sw
= NULL
;
5562 while ((sw
= TAILQ_FIRST(&search_wl
)) != NULL
) {
5563 xcb_destroy_window(conn
, sw
->indicator
);
5564 TAILQ_REMOVE(&search_wl
, sw
, entry
);
5570 search_win(struct swm_region
*r
, union arg
*args
)
5572 struct ws_win
*win
= NULL
;
5573 struct search_window
*sw
= NULL
;
5576 xcb_screen_t
*screen
;
5577 int i
, width
, height
;
5585 XRectangle l_ibox
, l_lbox
;
5587 DNPRINTF(SWM_D_MISC
, "search_win\n");
5590 search_resp_action
= SWM_SEARCH_SEARCH_WINDOW
;
5592 spawn_select(r
, args
, "search", &searchpid
);
5594 if ((lfile
= fdopen(select_list_pipe
[1], "w")) == NULL
)
5597 if ((screen
= get_screen(r
->s
->idx
)) == NULL
)
5598 errx(1, "ERROR: can't get screen %d.", r
->s
->idx
);
5600 TAILQ_INIT(&search_wl
);
5603 TAILQ_FOREACH(win
, &r
->ws
->winlist
, entry
) {
5607 sw
= calloc(1, sizeof(struct search_window
));
5609 warn("search_win: calloc");
5611 search_win_cleanup();
5617 snprintf(s
, sizeof s
, "%d", i
);
5620 w
= xcb_generate_id(conn
);
5621 wa
[0] = r
->s
->c
[SWM_S_COLOR_FOCUS
].pixel
;
5622 wa
[1] = r
->s
->c
[SWM_S_COLOR_UNFOCUS
].pixel
;
5623 wa
[2] = screen
->default_colormap
;
5625 if (bar_font_legacy
) {
5626 XmbTextExtents(bar_fs
, s
, len
, &l_ibox
, &l_lbox
);
5627 width
= l_lbox
.width
+ 4;
5628 height
= bar_fs_extents
->max_logical_extent
.height
+ 4;
5630 XftTextExtentsUtf8(display
, bar_font
, (FcChar8
*)s
, len
,
5632 width
= info
.width
+ 4;
5633 height
= bar_font
->height
+ 4;
5636 xcb_create_window(conn
, screen
->root_depth
, w
, win
->id
, 0, 0,
5637 width
, height
, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT
,
5638 screen
->root_visual
, XCB_CW_BACK_PIXEL
|
5639 XCB_CW_BORDER_PIXEL
| XCB_CW_COLORMAP
, wa
);
5641 xcb_map_window(conn
, w
);
5644 TAILQ_INSERT_TAIL(&search_wl
, sw
, entry
);
5646 if (bar_font_legacy
) {
5647 l_gcv
.graphics_exposures
= 0;
5648 l_draw
= XCreateGC(display
, w
, 0, &l_gcv
);
5650 XSetForeground(display
, l_draw
,
5651 r
->s
->c
[SWM_S_COLOR_BAR
].pixel
);
5653 DRAWSTRING(display
, w
, bar_fs
, l_draw
, 2,
5654 (bar_fs_extents
->max_logical_extent
.height
-
5655 l_lbox
.height
) / 2 - l_lbox
.y
, s
, len
);
5657 XFreeGC(display
, l_draw
);
5660 draw
= XftDrawCreate(display
, w
,
5661 DefaultVisual(display
, r
->s
->idx
),
5662 DefaultColormap(display
, r
->s
->idx
));
5664 XftDrawStringUtf8(draw
, &search_font_color
, bar_font
, 2,
5665 (HEIGHT(r
->bar
) + bar_font
->height
) / 2 -
5666 bar_font
->descent
, (FcChar8
*)s
, len
);
5668 XftDrawDestroy(draw
);
5671 DNPRINTF(SWM_D_MISC
, "search_win: mapped win %#x\n", w
);
5673 fprintf(lfile
, "%d\n", i
);
5683 search_resp_uniconify(const char *resp
, size_t len
)
5689 DNPRINTF(SWM_D_MISC
, "search_resp_uniconify: resp: %s\n", resp
);
5691 TAILQ_FOREACH(win
, &search_r
->ws
->winlist
, entry
) {
5694 name
= get_win_name(win
->id
);
5695 if (asprintf(&s
, "%s.%u", name
, win
->id
) == -1) {
5700 if (strncmp(s
, resp
, len
) == 0) {
5701 /* XXX this should be a callback to generalize */
5702 ewmh_apply_flags(win
, win
->ewmh_flags
& ~EWMH_F_HIDDEN
);
5703 ewmh_update_wm_state(win
);
5713 search_resp_name_workspace(const char *resp
, size_t len
)
5715 struct workspace
*ws
;
5717 DNPRINTF(SWM_D_MISC
, "search_resp_name_workspace: resp: %s\n", resp
);
5719 if (search_r
->ws
== NULL
)
5724 free(search_r
->ws
->name
);
5725 search_r
->ws
->name
= NULL
;
5729 ws
->name
= strdup(resp
);
5730 if (ws
->name
== NULL
) {
5731 DNPRINTF(SWM_D_MISC
, "search_resp_name_workspace: "
5732 "strdup: %s", strerror(errno
));
5736 ewmh_update_desktop_names();
5737 ewmh_get_desktop_names();
5742 ewmh_update_desktop_names(void)
5744 char *name_list
= NULL
, *p
;
5745 int num_screens
, i
, j
, len
= 0, tot
= 0;
5747 num_screens
= get_screen_count();
5748 for (i
= 0; i
< num_screens
; ++i
) {
5749 for (j
= 0; j
< workspace_limit
; ++j
) {
5750 if (screens
[i
].ws
[j
].name
!= NULL
)
5751 len
+= strlen(screens
[i
].ws
[j
].name
);
5755 if((name_list
= calloc(len
, sizeof(char))) == NULL
)
5756 err(1, "update_desktop_names: calloc: failed to "
5757 "allocate memory.");
5760 for (j
= 0; j
< workspace_limit
; ++j
) {
5761 if (screens
[i
].ws
[j
].name
!= NULL
) {
5762 len
= strlen(screens
[i
].ws
[j
].name
);
5763 memcpy(p
, screens
[i
].ws
[j
].name
, len
);
5772 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5773 screens
[i
].root
, ewmh
[_NET_DESKTOP_NAMES
].atom
,
5774 a_utf8_string
, 8, tot
, name_list
);
5784 ewmh_get_desktop_names(void)
5787 xcb_get_property_cookie_t c
;
5788 xcb_get_property_reply_t
*r
;
5789 int num_screens
, i
, j
, n
, k
;
5791 num_screens
= get_screen_count();
5792 for (i
= 0; i
< num_screens
; ++i
) {
5793 for (j
= 0; j
< workspace_limit
; ++j
) {
5794 free(screens
[i
].ws
[j
].name
);
5795 screens
[i
].ws
[j
].name
= NULL
;
5798 c
= xcb_get_property(conn
, 0, screens
[i
].root
,
5799 ewmh
[_NET_DESKTOP_NAMES
].atom
,
5800 a_utf8_string
, 0, UINT32_MAX
);
5801 r
= xcb_get_property_reply(conn
, c
, NULL
);
5805 names
= xcb_get_property_value(r
);
5806 n
= xcb_get_property_value_length(r
);
5808 for (j
= 0, k
= 0; j
< n
; ++j
) {
5809 if (*(names
+ j
) != '\0') {
5810 screens
[i
].ws
[k
].name
= strdup(names
+ j
);
5811 j
+= strlen(names
+ j
);
5820 ewmh_update_client_list(void)
5823 int num_screens
, i
, j
, k
= 0, count
= 0;
5826 num_screens
= get_screen_count();
5827 for (i
= 0; i
< num_screens
; ++i
) {
5828 for (j
= 0; j
< workspace_limit
; ++j
)
5829 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
5832 DNPRINTF(SWM_D_PROP
, "ewmh_update_client_list: win count: %d\n",
5838 wins
= calloc(count
, sizeof(xcb_window_t
));
5840 err(1, "ewmh_update_client_list: calloc: failed to "
5841 "allocate memory.");
5843 for (j
= 0, k
= 0; j
< workspace_limit
; ++j
)
5844 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
5845 wins
[k
++] = win
->id
;
5847 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5848 screens
[i
].root
, ewmh
[_NET_CLIENT_LIST
].atom
,
5849 XCB_ATOM_WINDOW
, 32, count
, wins
);
5856 ewmh_update_current_desktop(void)
5860 num_screens
= get_screen_count();
5861 for (i
= 0; i
< num_screens
; ++i
) {
5862 if (screens
[i
].r_focus
)
5863 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5864 screens
[i
].root
, ewmh
[_NET_CURRENT_DESKTOP
].atom
,
5865 XCB_ATOM_CARDINAL
, 32, 1,
5866 &screens
[i
].r_focus
->ws
->idx
);
5871 ewmh_update_desktops(void)
5873 int num_screens
, i
, j
;
5876 vals
= calloc(workspace_limit
* 2, sizeof(uint32_t));
5878 err(1, "ewmh_update_desktops: calloc: failed to allocate "
5881 num_screens
= get_screen_count();
5882 for (i
= 0; i
< num_screens
; i
++) {
5883 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5884 screens
[i
].root
, ewmh
[_NET_NUMBER_OF_DESKTOPS
].atom
,
5885 XCB_ATOM_CARDINAL
, 32, 1, &workspace_limit
);
5887 for (j
= 0; j
< workspace_limit
; ++j
) {
5888 if (screens
[i
].ws
[j
].r
!= NULL
) {
5889 vals
[j
* 2] = X(screens
[i
].ws
[j
].r
);
5890 vals
[j
* 2 + 1] = Y(screens
[i
].ws
[j
].r
);
5891 } else if (screens
[i
].ws
[j
].old_r
!= NULL
) {
5892 vals
[j
* 2] = X(screens
[i
].ws
[j
].old_r
);
5893 vals
[j
* 2 + 1] = Y(screens
[i
].ws
[j
].old_r
);
5895 vals
[j
* 2] = vals
[j
* 2 + 1] = 0;
5899 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5900 screens
[i
].root
, ewmh
[_NET_DESKTOP_VIEWPORT
].atom
,
5901 XCB_ATOM_CARDINAL
, 32, workspace_limit
* 2, vals
);
5908 search_resp_search_workspace(const char *resp
)
5915 DNPRINTF(SWM_D_MISC
, "search_resp_search_workspace: resp: %s\n", resp
);
5919 DNPRINTF(SWM_D_MISC
, "search_resp_search_workspace: strdup: %s",
5926 ws_idx
= (int)strtonum(q
, 1, workspace_limit
, &errstr
);
5928 DNPRINTF(SWM_D_MISC
, "workspace idx is %s: %s",
5935 switchws(search_r
, &a
);
5939 search_resp_search_window(const char *resp
)
5944 struct search_window
*sw
;
5946 DNPRINTF(SWM_D_MISC
, "search_resp_search_window: resp: %s\n", resp
);
5950 DNPRINTF(SWM_D_MISC
, "search_resp_search_window: strdup: %s",
5955 idx
= (int)strtonum(s
, 1, INT_MAX
, &errstr
);
5957 DNPRINTF(SWM_D_MISC
, "window idx is %s: %s",
5964 TAILQ_FOREACH(sw
, &search_wl
, entry
)
5965 if (idx
== sw
->idx
) {
5971 #define MAX_RESP_LEN 1024
5974 search_do_resp(void)
5980 DNPRINTF(SWM_D_MISC
, "search_do_resp:\n");
5985 if ((resp
= calloc(1, MAX_RESP_LEN
+ 1)) == NULL
) {
5986 warn("search: calloc");
5990 rbytes
= read(select_resp_pipe
[0], resp
, MAX_RESP_LEN
);
5992 warn("search: read error");
5995 resp
[rbytes
] = '\0';
5998 * Older versions of dmenu (Atleast pre 4.4.1) do not send a
5999 * newline, so work around that by sanitizing the resp now.
6001 resp
[strcspn(resp
, "\n")] = '\0';
6004 switch (search_resp_action
) {
6005 case SWM_SEARCH_UNICONIFY
:
6006 search_resp_uniconify(resp
, len
);
6008 case SWM_SEARCH_NAME_WORKSPACE
:
6009 search_resp_name_workspace(resp
, len
);
6011 case SWM_SEARCH_SEARCH_WORKSPACE
:
6012 search_resp_search_workspace(resp
);
6014 case SWM_SEARCH_SEARCH_WINDOW
:
6015 search_resp_search_window(resp
);
6020 if (search_resp_action
== SWM_SEARCH_SEARCH_WINDOW
)
6021 search_win_cleanup();
6023 search_resp_action
= SWM_SEARCH_NONE
;
6024 close(select_resp_pipe
[0]);
6031 wkill(struct swm_region
*r
, union arg
*args
)
6033 DNPRINTF(SWM_D_MISC
, "wkill: win %#x, id: %d\n", WINID(r
->ws
->focus
),
6036 if (r
->ws
->focus
== NULL
)
6039 if (args
->id
== SWM_ARG_ID_KILLWINDOW
)
6040 xcb_kill_client(conn
, r
->ws
->focus
->id
);
6042 if (r
->ws
->focus
->can_delete
)
6043 client_msg(r
->ws
->focus
, a_delete
, 0);
6049 clear_maximized(struct workspace
*ws
)
6054 /* Clear any maximized win(s) on ws, from bottom up. */
6055 TAILQ_FOREACH_REVERSE(w
, &ws
->stack
, ws_win_stack
, stack_entry
)
6057 ewmh_apply_flags(w
, w
->ewmh_flags
& ~EWMH_F_MAXIMIZED
);
6058 ewmh_update_wm_state(w
);
6066 maximize_toggle(struct swm_region
*r
, union arg
*args
)
6068 struct ws_win
*w
= r
->ws
->focus
;
6070 /* suppress unused warning since var is needed */
6076 DNPRINTF(SWM_D_MISC
, "maximize_toggle: win %#x\n", w
->id
);
6081 if (w
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
6084 ewmh_apply_flags(w
, w
->ewmh_flags
^ EWMH_F_MAXIMIZED
);
6085 ewmh_update_wm_state(w
);
6089 if (w
== w
->ws
->focus
)
6094 DNPRINTF(SWM_D_MISC
, "maximize_toggle: done\n");
6098 floating_toggle(struct swm_region
*r
, union arg
*args
)
6100 struct ws_win
*w
= r
->ws
->focus
;
6102 /* suppress unused warning since var is needed */
6108 DNPRINTF(SWM_D_MISC
, "floating_toggle: win %#x\n", w
->id
);
6110 if (FULLSCREEN(w
) || TRANS(w
))
6113 if (w
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
6116 ewmh_apply_flags(w
, w
->ewmh_flags
^ EWMH_F_ABOVE
);
6117 ewmh_update_wm_state(w
);
6121 if (w
== w
->ws
->focus
)
6126 DNPRINTF(SWM_D_MISC
, "floating_toggle: done\n");
6130 region_containment(struct ws_win
*win
, struct swm_region
*r
, int opts
)
6132 struct swm_geometry g
= r
->g
;
6133 int rt
, lt
, tp
, bm
, bw
;
6135 bw
= (opts
& SWM_CW_SOFTBOUNDARY
) ? boundary_width
: 0;
6138 * Perpendicular distance of each side of the window to the respective
6139 * side of the region boundary. Positive values indicate the side of
6140 * the window has passed beyond the region boundary.
6142 rt
= opts
& SWM_CW_RIGHT
? MAX_X(win
) + BORDER(win
) - MAX_X(r
) : bw
;
6143 lt
= opts
& SWM_CW_LEFT
? X(r
) - X(win
) + BORDER(win
) : bw
;
6144 bm
= opts
& SWM_CW_BOTTOM
? MAX_Y(win
) + BORDER(win
) - MAX_Y(r
) : bw
;
6145 tp
= opts
& SWM_CW_TOP
? Y(r
) - Y(win
) + BORDER(win
) : bw
;
6147 DNPRINTF(SWM_D_MISC
, "region_containment: win %#x, rt: %d, lt: %d, "
6148 "bm: %d, tp: %d, SOFTBOUNDARY: %s, HARDBOUNDARY: %s\n", win
->id
, rt
,
6149 lt
, bm
, tp
, YESNO(opts
& SWM_CW_SOFTBOUNDARY
),
6150 YESNO(opts
& SWM_CW_HARDBOUNDARY
));
6153 * Disable containment if any of the flagged sides went beyond the
6154 * containment boundary, or if containment is disabled.
6156 if (!(opts
& SWM_CW_HARDBOUNDARY
|| opts
& SWM_CW_SOFTBOUNDARY
) ||
6157 (bw
!= 0 && ((rt
> bw
) || (lt
> bw
) || (bm
> bw
) || (tp
> bw
)))) {
6158 /* Make sure window has at least 1 pixel in the region */
6159 g
.x
+= 1 - WIDTH(win
);
6160 g
.y
+= 1 - HEIGHT(win
);
6161 g
.w
+= 2 * WIDTH(win
) - 2;
6162 g
.h
+= 2 * HEIGHT(win
) - 2;
6165 constrain_window(win
, &g
, &opts
);
6168 /* Move or resize a window so that flagged side(s) fit into the supplied box. */
6170 constrain_window(struct ws_win
*win
, struct swm_geometry
*b
, int *opts
)
6172 DNPRINTF(SWM_D_MISC
, "constrain_window: win %#x, (x,y) w x h: "
6173 "(%d,%d) %d x %d, box: (x,y) w x h: (%d,%d) %d x %d, rt: %s, "
6174 "lt: %s, bt: %s, tp: %s, allow resize: %s\n", win
->id
, X(win
),
6175 Y(win
), WIDTH(win
), HEIGHT(win
), b
->x
, b
->y
, b
->w
, b
->h
,
6176 YESNO(*opts
& SWM_CW_RIGHT
), YESNO(*opts
& SWM_CW_LEFT
),
6177 YESNO(*opts
& SWM_CW_BOTTOM
), YESNO(*opts
& SWM_CW_TOP
),
6178 YESNO(*opts
& SWM_CW_RESIZABLE
));
6180 if ((*opts
& SWM_CW_RIGHT
) && MAX_X(win
) + BORDER(win
) > b
->x
+ b
->w
) {
6181 if (*opts
& SWM_CW_RESIZABLE
)
6182 WIDTH(win
) = b
->x
+ b
->w
- X(win
) - BORDER(win
);
6184 X(win
) = b
->x
+ b
->w
- WIDTH(win
) - BORDER(win
);
6187 if ((*opts
& SWM_CW_LEFT
) && X(win
) + BORDER(win
) < b
->x
) {
6188 if (*opts
& SWM_CW_RESIZABLE
)
6189 WIDTH(win
) -= b
->x
- X(win
) - BORDER(win
);
6191 X(win
) = b
->x
- BORDER(win
);
6194 if ((*opts
& SWM_CW_BOTTOM
) && MAX_Y(win
) + BORDER(win
) > b
->y
+ b
->h
) {
6195 if (*opts
& SWM_CW_RESIZABLE
)
6196 HEIGHT(win
) = b
->y
+ b
->h
- Y(win
) - BORDER(win
);
6198 Y(win
) = b
->y
+ b
->h
- HEIGHT(win
) - BORDER(win
);
6201 if ((*opts
& SWM_CW_TOP
) && Y(win
) + BORDER(win
) < b
->y
) {
6202 if (*opts
& SWM_CW_RESIZABLE
)
6203 HEIGHT(win
) -= b
->y
- Y(win
) - BORDER(win
);
6205 Y(win
) = b
->y
- BORDER(win
);
6208 if (*opts
& SWM_CW_RESIZABLE
) {
6211 if (HEIGHT(win
) < 1)
6217 update_window_color(struct ws_win
*win
)
6221 if (WS_FOCUSED(win
->ws
) && win
->ws
->focus
== win
)
6222 pixel
= MAXIMIZED(win
) ?
6223 &win
->s
->c
[SWM_S_COLOR_FOCUS_MAXIMIZED
].pixel
:
6224 &win
->s
->c
[SWM_S_COLOR_FOCUS
].pixel
;
6226 pixel
= MAXIMIZED(win
) ?
6227 &win
->s
->c
[SWM_S_COLOR_UNFOCUS_MAXIMIZED
].pixel
:
6228 &win
->s
->c
[SWM_S_COLOR_UNFOCUS
].pixel
;
6230 xcb_change_window_attributes(conn
, win
->id
,
6231 XCB_CW_BORDER_PIXEL
, pixel
);
6235 update_window(struct ws_win
*win
)
6240 mask
= XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
|
6241 XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
|
6242 XCB_CONFIG_WINDOW_BORDER_WIDTH
;
6246 wc
[3] = HEIGHT(win
);
6247 wc
[4] = BORDER(win
);
6249 DNPRINTF(SWM_D_EVENT
, "update_window: win %#x, (x,y) w x h: "
6250 "(%d,%d) %d x %d, bordered: %s\n", win
->id
, wc
[0], wc
[1], wc
[2],
6251 wc
[3], YESNO(win
->bordered
));
6253 xcb_configure_window(conn
, win
->id
, mask
, wc
);
6256 #define SWM_RESIZE_STEPS (50)
6259 resize(struct ws_win
*win
, union arg
*args
)
6261 xcb_timestamp_t timestamp
= 0;
6262 struct swm_region
*r
= NULL
;
6263 struct swm_geometry g
;
6265 int top
= 0, left
= 0;
6267 xcb_cursor_t cursor
;
6268 xcb_query_pointer_reply_t
*xpr
= NULL
;
6269 xcb_generic_event_t
*evt
;
6270 xcb_motion_notify_event_t
*mne
;
6277 if (FULLSCREEN(win
))
6280 /* In max_stack mode, should only resize transients. */
6281 if (win
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
] && !TRANS(win
))
6284 DNPRINTF(SWM_D_EVENT
, "resize: win %#x, floating: %s, "
6285 "transient: %#x\n", win
->id
, YESNO(ABOVE(win
)),
6289 store_float_geom(win
);
6290 else if (!(TRANS(win
) || ABOVE(win
)))
6293 ewmh_apply_flags(win
, (win
->ewmh_flags
| SWM_F_MANUAL
| EWMH_F_ABOVE
) &
6295 ewmh_update_wm_state(win
);
6301 /* It's possible for win to have been freed during focus_flush(). */
6302 if (validate_win(win
)) {
6303 DNPRINTF(SWM_D_EVENT
, "resize: invalid win.\n");
6308 case SWM_ARG_ID_WIDTHSHRINK
:
6309 WIDTH(win
) -= SWM_RESIZE_STEPS
;
6312 case SWM_ARG_ID_WIDTHGROW
:
6313 WIDTH(win
) += SWM_RESIZE_STEPS
;
6316 case SWM_ARG_ID_HEIGHTSHRINK
:
6317 HEIGHT(win
) -= SWM_RESIZE_STEPS
;
6320 case SWM_ARG_ID_HEIGHTGROW
:
6321 HEIGHT(win
) += SWM_RESIZE_STEPS
;
6328 region_containment(win
, r
, SWM_CW_ALLSIDES
| SWM_CW_RESIZABLE
|
6329 SWM_CW_HARDBOUNDARY
);
6331 store_float_geom(win
);
6335 region_containment(win
, r
, SWM_CW_ALLSIDES
| SWM_CW_RESIZABLE
|
6336 SWM_CW_SOFTBOUNDARY
);
6339 /* get cursor offset from window root */
6340 xpr
= xcb_query_pointer_reply(conn
, xcb_query_pointer(conn
, win
->id
),
6347 if (xpr
->win_x
< WIDTH(win
) / 2)
6350 if (xpr
->win_y
< HEIGHT(win
) / 2)
6353 if (args
->id
== SWM_ARG_ID_CENTER
)
6354 cursor
= cursors
[XC_SIZING
].cid
;
6356 cursor
= cursors
[left
? XC_TOP_LEFT_CORNER
:
6357 XC_TOP_RIGHT_CORNER
].cid
;
6359 cursor
= cursors
[left
? XC_BOTTOM_LEFT_CORNER
:
6360 XC_BOTTOM_RIGHT_CORNER
].cid
;
6362 xcb_grab_pointer(conn
, 0, win
->id
, MOUSEMASK
,
6363 XCB_GRAB_MODE_ASYNC
, XCB_GRAB_MODE_ASYNC
, XCB_WINDOW_NONE
, cursor
,
6368 while (resizing
&& (evt
= xcb_wait_for_event(conn
))) {
6369 switch (XCB_EVENT_RESPONSE_TYPE(evt
)) {
6370 case XCB_BUTTON_RELEASE
:
6371 DNPRINTF(SWM_D_EVENT
, "resize: BUTTON_RELEASE\n");
6374 case XCB_MOTION_NOTIFY
:
6375 mne
= (xcb_motion_notify_event_t
*)evt
;
6376 /* cursor offset/delta from start of the operation */
6377 dx
= mne
->root_x
- xpr
->root_x
;
6378 dy
= mne
->root_y
- xpr
->root_y
;
6384 if (args
->id
== SWM_ARG_ID_CENTER
) {
6385 if (g
.h
/ 2 + dy
< 1)
6389 HEIGHT(win
) = g
.h
+ 2 * dy
;
6397 HEIGHT(win
) = g
.h
+ dy
;
6404 if (args
->id
== SWM_ARG_ID_CENTER
) {
6405 if (g
.w
/ 2 + dx
< 1)
6409 WIDTH(win
) = g
.w
+ 2 * dx
;
6417 WIDTH(win
) = g
.w
+ dx
;
6420 /* not free, don't sync more than 120 times / second */
6421 if ((mne
->time
- timestamp
) > (1000 / 120) ) {
6422 timestamp
= mne
->time
;
6423 regionize(win
, mne
->root_x
, mne
->root_y
);
6424 region_containment(win
, r
, SWM_CW_ALLSIDES
|
6425 SWM_CW_RESIZABLE
| SWM_CW_HARDBOUNDARY
|
6426 SWM_CW_SOFTBOUNDARY
);
6433 xcb_allow_events(conn
, XCB_ALLOW_ASYNC_KEYBOARD
,
6434 ((xcb_key_press_event_t
*)evt
)->time
);
6440 /* It's possible for win to have been freed above. */
6441 if (validate_win(win
)) {
6442 DNPRINTF(SWM_D_EVENT
, "resize: invalid win.\n");
6450 region_containment(win
, r
, SWM_CW_ALLSIDES
| SWM_CW_RESIZABLE
|
6451 SWM_CW_HARDBOUNDARY
| SWM_CW_SOFTBOUNDARY
);
6455 store_float_geom(win
);
6457 xcb_ungrab_pointer(conn
, XCB_CURRENT_TIME
);
6459 DNPRINTF(SWM_D_EVENT
, "resize: done.\n");
6463 resize_step(struct swm_region
*r
, union arg
*args
)
6465 struct ws_win
*win
= NULL
;
6467 if (r
&& r
->ws
&& r
->ws
->focus
)
6477 /* Try to set window region based on supplied coordinates or window center. */
6479 regionize(struct ws_win
*win
, int x
, int y
)
6481 struct swm_region
*r
= NULL
;
6483 r
= region_under(win
->s
, x
, y
);
6485 r
= region_under(win
->s
, X(win
) + WIDTH(win
) / 2,
6486 Y(win
) + HEIGHT(win
) / 2);
6488 if (r
!= NULL
&& r
!= win
->ws
->r
) {
6489 if (clear_maximized(r
->ws
) > 0)
6492 win_to_ws(win
, r
->ws
->idx
, false);
6494 /* Set focus on new ws. */
6495 unfocus_win(r
->ws
->focus
);
6503 #define SWM_MOVE_STEPS (50)
6506 move(struct ws_win
*win
, union arg
*args
)
6508 struct swm_region
*r
;
6509 xcb_timestamp_t timestamp
= 0;
6511 xcb_query_pointer_reply_t
*qpr
= NULL
;
6512 xcb_generic_event_t
*evt
;
6513 xcb_motion_notify_event_t
*mne
;
6514 bool moving
, restack
= false;
6519 if ((r
= win
->ws
->r
) == NULL
)
6522 if (FULLSCREEN(win
))
6525 DNPRINTF(SWM_D_EVENT
, "move: win %#x, floating: %s, transient: "
6526 "%#x\n", win
->id
, YESNO(ABOVE(win
)), win
->transient
);
6528 /* in max_stack mode should only move transients */
6529 if (win
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
] && !TRANS(win
))
6532 if (!(ABOVE(win
) || TRANS(win
)) || MAXIMIZED(win
)) {
6533 store_float_geom(win
);
6537 ewmh_apply_flags(win
, (win
->ewmh_flags
| SWM_F_MANUAL
| EWMH_F_ABOVE
) &
6539 ewmh_update_wm_state(win
);
6546 /* It's possible for win to have been freed during focus_flush(). */
6547 if (validate_win(win
)) {
6548 DNPRINTF(SWM_D_EVENT
, "move: invalid win.\n");
6554 case SWM_ARG_ID_MOVELEFT
:
6555 X(win
) -= (SWM_MOVE_STEPS
- border_width
);
6558 case SWM_ARG_ID_MOVERIGHT
:
6559 X(win
) += (SWM_MOVE_STEPS
- border_width
);
6562 case SWM_ARG_ID_MOVEUP
:
6563 Y(win
) -= (SWM_MOVE_STEPS
- border_width
);
6566 case SWM_ARG_ID_MOVEDOWN
:
6567 Y(win
) += (SWM_MOVE_STEPS
- border_width
);
6574 regionize(win
, -1, -1);
6575 region_containment(win
, win
->ws
->r
, SWM_CW_ALLSIDES
);
6577 store_float_geom(win
);
6581 xcb_grab_pointer(conn
, 0, win
->id
, MOUSEMASK
,
6582 XCB_GRAB_MODE_ASYNC
, XCB_GRAB_MODE_ASYNC
,
6583 XCB_WINDOW_NONE
, cursors
[XC_FLEUR
].cid
, XCB_CURRENT_TIME
);
6585 /* get cursor offset from window root */
6586 qpr
= xcb_query_pointer_reply(conn
, xcb_query_pointer(conn
, win
->id
),
6589 xcb_ungrab_pointer(conn
, XCB_CURRENT_TIME
);
6593 regionize(win
, qpr
->root_x
, qpr
->root_y
);
6594 region_containment(win
, win
->ws
->r
, SWM_CW_ALLSIDES
|
6595 SWM_CW_SOFTBOUNDARY
);
6599 while (moving
&& (evt
= xcb_wait_for_event(conn
))) {
6600 switch (XCB_EVENT_RESPONSE_TYPE(evt
)) {
6601 case XCB_BUTTON_RELEASE
:
6602 DNPRINTF(SWM_D_EVENT
, "move: BUTTON_RELEASE\n");
6605 case XCB_MOTION_NOTIFY
:
6606 mne
= (xcb_motion_notify_event_t
*)evt
;
6607 DNPRINTF(SWM_D_EVENT
, "motion: root: %#x\n", mne
->root
);
6608 X(win
) = mne
->root_x
- qpr
->win_x
- border_width
;
6609 Y(win
) = mne
->root_y
- qpr
->win_y
- border_width
;
6611 /* not free, don't sync more than 120 times / second */
6612 if ((mne
->time
- timestamp
) > (1000 / 120) ) {
6613 timestamp
= mne
->time
;
6614 regionize(win
, mne
->root_x
, mne
->root_y
);
6615 region_containment(win
, win
->ws
->r
,
6616 SWM_CW_ALLSIDES
| SWM_CW_SOFTBOUNDARY
);
6623 xcb_allow_events(conn
, XCB_ALLOW_ASYNC_KEYBOARD
,
6624 ((xcb_key_press_event_t
*)evt
)->time
);
6630 /* It's possible for win to have been freed above. */
6631 if (validate_win(win
)) {
6632 DNPRINTF(SWM_D_EVENT
, "move: invalid win.\n");
6640 region_containment(win
, win
->ws
->r
, SWM_CW_ALLSIDES
|
6641 SWM_CW_SOFTBOUNDARY
);
6645 store_float_geom(win
);
6647 /* New region set to fullscreen layout. */
6648 if (win
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
]) {
6655 xcb_ungrab_pointer(conn
, XCB_CURRENT_TIME
);
6656 DNPRINTF(SWM_D_EVENT
, "move: done.\n");
6660 move_step(struct swm_region
*r
, union arg
*args
)
6662 struct ws_win
*win
= NULL
;
6664 if (r
&& r
->ws
&& r
->ws
->focus
)
6669 if (!TRANS(win
) && !ABOVE(win
))
6677 /* key definitions */
6679 char name
[SWM_FUNCNAME_LEN
];
6680 void (*func
)(struct swm_region
*r
, union arg
*);
6682 } keyfuncs
[KF_INVALID
+ 1] = {
6683 /* name function argument */
6684 { "bar_toggle", bar_toggle
, {.id
= SWM_ARG_ID_BAR_TOGGLE
} },
6685 { "bar_toggle_ws", bar_toggle
, {.id
= SWM_ARG_ID_BAR_TOGGLE_WS
} },
6686 { "button2", pressbutton
, {2} },
6687 { "cycle_layout", cycle_layout
, {0} },
6688 { "flip_layout", stack_config
, {.id
= SWM_ARG_ID_FLIPLAYOUT
} },
6689 { "float_toggle", floating_toggle
,{0} },
6690 { "focus_main", focus
, {.id
= SWM_ARG_ID_FOCUSMAIN
} },
6691 { "focus_next", focus
, {.id
= SWM_ARG_ID_FOCUSNEXT
} },
6692 { "focus_prev", focus
, {.id
= SWM_ARG_ID_FOCUSPREV
} },
6693 { "focus_urgent", focus
, {.id
= SWM_ARG_ID_FOCUSURGENT
} },
6694 { "maximize_toggle", maximize_toggle
,{0} },
6695 { "height_grow", resize_step
, {.id
= SWM_ARG_ID_HEIGHTGROW
} },
6696 { "height_shrink", resize_step
, {.id
= SWM_ARG_ID_HEIGHTSHRINK
} },
6697 { "iconify", iconify
, {0} },
6698 { "master_shrink", stack_config
, {.id
= SWM_ARG_ID_MASTERSHRINK
} },
6699 { "master_grow", stack_config
, {.id
= SWM_ARG_ID_MASTERGROW
} },
6700 { "master_add", stack_config
, {.id
= SWM_ARG_ID_MASTERADD
} },
6701 { "master_del", stack_config
, {.id
= SWM_ARG_ID_MASTERDEL
} },
6702 { "move_down", move_step
, {.id
= SWM_ARG_ID_MOVEDOWN
} },
6703 { "move_left", move_step
, {.id
= SWM_ARG_ID_MOVELEFT
} },
6704 { "move_right", move_step
, {.id
= SWM_ARG_ID_MOVERIGHT
} },
6705 { "move_up", move_step
, {.id
= SWM_ARG_ID_MOVEUP
} },
6706 { "mvrg_1", send_to_rg
, {.id
= 0} },
6707 { "mvrg_2", send_to_rg
, {.id
= 1} },
6708 { "mvrg_3", send_to_rg
, {.id
= 2} },
6709 { "mvrg_4", send_to_rg
, {.id
= 3} },
6710 { "mvrg_5", send_to_rg
, {.id
= 4} },
6711 { "mvrg_6", send_to_rg
, {.id
= 5} },
6712 { "mvrg_7", send_to_rg
, {.id
= 6} },
6713 { "mvrg_8", send_to_rg
, {.id
= 7} },
6714 { "mvrg_9", send_to_rg
, {.id
= 8} },
6715 { "mvws_1", send_to_ws
, {.id
= 0} },
6716 { "mvws_2", send_to_ws
, {.id
= 1} },
6717 { "mvws_3", send_to_ws
, {.id
= 2} },
6718 { "mvws_4", send_to_ws
, {.id
= 3} },
6719 { "mvws_5", send_to_ws
, {.id
= 4} },
6720 { "mvws_6", send_to_ws
, {.id
= 5} },
6721 { "mvws_7", send_to_ws
, {.id
= 6} },
6722 { "mvws_8", send_to_ws
, {.id
= 7} },
6723 { "mvws_9", send_to_ws
, {.id
= 8} },
6724 { "mvws_10", send_to_ws
, {.id
= 9} },
6725 { "mvws_11", send_to_ws
, {.id
= 10} },
6726 { "mvws_12", send_to_ws
, {.id
= 11} },
6727 { "mvws_13", send_to_ws
, {.id
= 12} },
6728 { "mvws_14", send_to_ws
, {.id
= 13} },
6729 { "mvws_15", send_to_ws
, {.id
= 14} },
6730 { "mvws_16", send_to_ws
, {.id
= 15} },
6731 { "mvws_17", send_to_ws
, {.id
= 16} },
6732 { "mvws_18", send_to_ws
, {.id
= 17} },
6733 { "mvws_19", send_to_ws
, {.id
= 18} },
6734 { "mvws_20", send_to_ws
, {.id
= 19} },
6735 { "mvws_21", send_to_ws
, {.id
= 20} },
6736 { "mvws_22", send_to_ws
, {.id
= 21} },
6737 { "name_workspace", name_workspace
, {0} },
6738 { "quit", quit
, {0} },
6739 { "raise_toggle", raise_toggle
, {0} },
6740 { "restart", restart
, {0} },
6741 { "rg_1", focusrg
, {.id
= 0} },
6742 { "rg_2", focusrg
, {.id
= 1} },
6743 { "rg_3", focusrg
, {.id
= 2} },
6744 { "rg_4", focusrg
, {.id
= 3} },
6745 { "rg_5", focusrg
, {.id
= 4} },
6746 { "rg_6", focusrg
, {.id
= 5} },
6747 { "rg_7", focusrg
, {.id
= 6} },
6748 { "rg_8", focusrg
, {.id
= 7} },
6749 { "rg_9", focusrg
, {.id
= 8} },
6750 { "rg_move_next", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_MOVE_UP
} },
6751 { "rg_move_prev", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_MOVE_DOWN
} },
6752 { "rg_next", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_UP
} },
6753 { "rg_prev", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_DOWN
} },
6754 { "screen_next", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_UP
} },
6755 { "screen_prev", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_DOWN
} },
6756 { "search_win", search_win
, {0} },
6757 { "search_workspace", search_workspace
, {0} },
6758 { "spawn_custom", NULL
, {0} },
6759 { "stack_balance", stack_config
, {.id
= SWM_ARG_ID_STACKBALANCE
} },
6760 { "stack_inc", stack_config
, {.id
= SWM_ARG_ID_STACKINC
} },
6761 { "stack_dec", stack_config
, {.id
= SWM_ARG_ID_STACKDEC
} },
6762 { "stack_reset", stack_config
, {.id
= SWM_ARG_ID_STACKRESET
} },
6763 { "swap_main", swapwin
, {.id
= SWM_ARG_ID_SWAPMAIN
} },
6764 { "swap_next", swapwin
, {.id
= SWM_ARG_ID_SWAPNEXT
} },
6765 { "swap_prev", swapwin
, {.id
= SWM_ARG_ID_SWAPPREV
} },
6766 { "uniconify", uniconify
, {0} },
6767 { "version", version
, {0} },
6768 { "width_grow", resize_step
, {.id
= SWM_ARG_ID_WIDTHGROW
} },
6769 { "width_shrink", resize_step
, {.id
= SWM_ARG_ID_WIDTHSHRINK
} },
6770 { "wind_del", wkill
, {.id
= SWM_ARG_ID_DELETEWINDOW
} },
6771 { "wind_kill", wkill
, {.id
= SWM_ARG_ID_KILLWINDOW
} },
6772 { "ws_1", switchws
, {.id
= 0} },
6773 { "ws_2", switchws
, {.id
= 1} },
6774 { "ws_3", switchws
, {.id
= 2} },
6775 { "ws_4", switchws
, {.id
= 3} },
6776 { "ws_5", switchws
, {.id
= 4} },
6777 { "ws_6", switchws
, {.id
= 5} },
6778 { "ws_7", switchws
, {.id
= 6} },
6779 { "ws_8", switchws
, {.id
= 7} },
6780 { "ws_9", switchws
, {.id
= 8} },
6781 { "ws_10", switchws
, {.id
= 9} },
6782 { "ws_11", switchws
, {.id
= 10} },
6783 { "ws_12", switchws
, {.id
= 11} },
6784 { "ws_13", switchws
, {.id
= 12} },
6785 { "ws_14", switchws
, {.id
= 13} },
6786 { "ws_15", switchws
, {.id
= 14} },
6787 { "ws_16", switchws
, {.id
= 15} },
6788 { "ws_17", switchws
, {.id
= 16} },
6789 { "ws_18", switchws
, {.id
= 17} },
6790 { "ws_19", switchws
, {.id
= 18} },
6791 { "ws_20", switchws
, {.id
= 19} },
6792 { "ws_21", switchws
, {.id
= 20} },
6793 { "ws_22", switchws
, {.id
= 21} },
6794 { "ws_next", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_UP
} },
6795 { "ws_next_all", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_UP_ALL
} },
6796 { "ws_next_move", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_MOVE_UP
} },
6797 { "ws_prev", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_DOWN
} },
6798 { "ws_prev_all", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_DOWN_ALL
} },
6799 { "ws_prev_move", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_MOVE_DOWN
} },
6800 { "ws_prior", priorws
, {0} },
6801 { "dumpwins", dumpwins
, {0} }, /* MUST BE LAST */
6802 { "invalid key func", NULL
, {0} },
6806 key_cmp(struct key
*kp1
, struct key
*kp2
)
6808 if (kp1
->keysym
< kp2
->keysym
)
6810 if (kp1
->keysym
> kp2
->keysym
)
6813 if (kp1
->mod
< kp2
->mod
)
6815 if (kp1
->mod
> kp2
->mod
)
6822 enum { client_click
, root_click
};
6824 unsigned int action
;
6826 unsigned int button
;
6827 void (*func
)(struct ws_win
*, union arg
*);
6830 #define MODKEY_SHIFT MODKEY | XCB_MOD_MASK_SHIFT
6831 /* action key mouse button func args */
6832 { client_click
, MODKEY
, XCB_BUTTON_INDEX_3
, resize
, {.id
= SWM_ARG_ID_DONTCENTER
} },
6833 { client_click
, MODKEY_SHIFT
, XCB_BUTTON_INDEX_3
, resize
, {.id
= SWM_ARG_ID_CENTER
} },
6834 { client_click
, MODKEY
, XCB_BUTTON_INDEX_1
, move
, {0} },
6839 update_modkey(unsigned int mod
)
6845 RB_FOREACH(kp
, key_tree
, &keys
)
6846 if (kp
->mod
& XCB_MOD_MASK_SHIFT
)
6847 kp
->mod
= mod
| XCB_MOD_MASK_SHIFT
;
6851 for (i
= 0; i
< LENGTH(buttons
); i
++)
6852 if (buttons
[i
].mask
& XCB_MOD_MASK_SHIFT
)
6853 buttons
[i
].mask
= mod
| XCB_MOD_MASK_SHIFT
;
6855 buttons
[i
].mask
= mod
;
6859 spawn_expand(struct swm_region
*r
, union arg
*args
, const char *spawn_name
,
6862 struct spawn_prog
*prog
= NULL
;
6864 char *ap
, **real_args
;
6866 /* suppress unused warning since var is needed */
6869 DNPRINTF(SWM_D_SPAWN
, "spawn_expand: %s\n", spawn_name
);
6872 TAILQ_FOREACH(prog
, &spawns
, entry
) {
6873 if (strcasecmp(spawn_name
, prog
->name
) == 0)
6877 warnx("spawn_custom: program %s not found", spawn_name
);
6881 /* make room for expanded args */
6882 if ((real_args
= calloc(prog
->argc
+ 1, sizeof(char *))) == NULL
)
6883 err(1, "spawn_custom: calloc real_args");
6885 /* expand spawn_args into real_args */
6886 for (i
= c
= 0; i
< prog
->argc
; i
++) {
6888 DNPRINTF(SWM_D_SPAWN
, "spawn_custom: raw arg: %s\n", ap
);
6889 if (strcasecmp(ap
, "$bar_border") == 0) {
6891 strdup(r
->s
->c
[SWM_S_COLOR_BAR_BORDER
].name
))
6893 err(1, "spawn_custom border color");
6894 } else if (strcasecmp(ap
, "$bar_color") == 0) {
6896 strdup(r
->s
->c
[SWM_S_COLOR_BAR
].name
))
6898 err(1, "spawn_custom bar color");
6899 } else if (strcasecmp(ap
, "$bar_font") == 0) {
6900 if ((real_args
[c
] = strdup(bar_fonts
))
6902 err(1, "spawn_custom bar fonts");
6903 } else if (strcasecmp(ap
, "$bar_font_color") == 0) {
6905 strdup(r
->s
->c
[SWM_S_COLOR_BAR_FONT
].name
))
6907 err(1, "spawn_custom color font");
6908 } else if (strcasecmp(ap
, "$color_focus") == 0) {
6910 strdup(r
->s
->c
[SWM_S_COLOR_FOCUS
].name
))
6912 err(1, "spawn_custom color focus");
6913 } else if (strcasecmp(ap
, "$color_focus_maximized") == 0) {
6915 strdup(r
->s
->c
[SWM_S_COLOR_FOCUS_MAXIMIZED
].name
))
6917 err(1, "spawn_custom color focus maximized");
6918 } else if (strcasecmp(ap
, "$color_unfocus") == 0) {
6920 strdup(r
->s
->c
[SWM_S_COLOR_UNFOCUS
].name
))
6922 err(1, "spawn_custom color unfocus");
6923 } else if (strcasecmp(ap
, "$color_unfocus_maximized") == 0) {
6925 strdup(r
->s
->c
[SWM_S_COLOR_UNFOCUS_MAXIMIZED
].name
))
6927 err(1, "spawn_custom color unfocus maximized");
6928 } else if (strcasecmp(ap
, "$region_index") == 0) {
6929 if (asprintf(&real_args
[c
], "%d",
6930 get_region_index(r
) + 1) < 1)
6931 err(1, "spawn_custom region index");
6932 } else if (strcasecmp(ap
, "$workspace_index") == 0) {
6933 if (asprintf(&real_args
[c
], "%d", r
->ws
->idx
+ 1) < 1)
6934 err(1, "spawn_custom workspace index");
6935 } else if (strcasecmp(ap
, "$dmenu_bottom") == 0) {
6938 if ((real_args
[c
] = strdup("-b")) == NULL
)
6939 err(1, "spawn_custom workspace index");
6941 /* no match --> copy as is */
6942 if ((real_args
[c
] = strdup(ap
)) == NULL
)
6943 err(1, "spawn_custom strdup(ap)");
6945 DNPRINTF(SWM_D_SPAWN
, "spawn_custom: cooked arg: %s\n",
6951 DNPRINTF(SWM_D_SPAWN
, "spawn_custom: result: ");
6952 for (i
= 0; i
< c
; ++i
)
6953 DPRINTF("\"%s\" ", real_args
[i
]);
6956 *ret_args
= real_args
;
6961 spawn_custom(struct swm_region
*r
, union arg
*args
, const char *spawn_name
)
6967 if ((spawn_argc
= spawn_expand(r
, args
, spawn_name
, &real_args
)) < 0)
6971 spawn(r
->ws
->idx
, &a
, true);
6973 for (i
= 0; i
< spawn_argc
; i
++)
6979 spawn_select(struct swm_region
*r
, union arg
*args
, const char *spawn_name
,
6986 if ((spawn_argc
= spawn_expand(r
, args
, spawn_name
, &real_args
)) < 0)
6990 if (pipe(select_list_pipe
) == -1)
6991 err(1, "pipe error");
6992 if (pipe(select_resp_pipe
) == -1)
6993 err(1, "pipe error");
6995 if (signal(SIGPIPE
, SIG_IGN
) == SIG_ERR
)
6996 err(1, "could not disable SIGPIPE");
6997 switch (*pid
= fork()) {
6999 err(1, "cannot fork");
7002 if (dup2(select_list_pipe
[0], STDIN_FILENO
) == -1)
7004 if (dup2(select_resp_pipe
[1], STDOUT_FILENO
) == -1)
7006 close(select_list_pipe
[1]);
7007 close(select_resp_pipe
[0]);
7008 spawn(r
->ws
->idx
, &a
, false);
7010 default: /* parent */
7011 close(select_list_pipe
[0]);
7012 close(select_resp_pipe
[1]);
7016 for (i
= 0; i
< spawn_argc
; i
++)
7021 /* Argument tokenizer. */
7024 char *arg
, *cp
, *next
;
7025 bool single_quoted
= false, double_quoted
= false;
7030 /* Eat and move characters until end of argument is found. */
7031 for (arg
= next
= cp
= *sp
; *cp
!= '\0'; ++cp
) {
7032 if (!double_quoted
&& *cp
== '\'') {
7033 /* Eat single-quote. */
7034 single_quoted
= !single_quoted
;
7035 } else if (!single_quoted
&& *cp
== '"') {
7036 /* Eat double-quote. */
7037 double_quoted
= !double_quoted
;
7038 } else if (!single_quoted
&& *cp
== '\\' && *(cp
+ 1) == '"') {
7039 /* Eat backslash; copy escaped character to arg. */
7041 } else if (!single_quoted
&& !double_quoted
&& *cp
== '\\' &&
7042 (*(cp
+ 1) == '\'' || *(cp
+ 1) == ' ')) {
7043 /* Eat backslash; move escaped character. */
7045 } else if (!single_quoted
&& !double_quoted
&&
7046 (*cp
== ' ' || *cp
== '\t')) {
7047 /* Terminate argument. */
7049 /* Point sp to beginning of next argument. */
7053 /* Move regular character. */
7058 /* Terminate argument if end of string. */
7068 spawn_insert(const char *name
, const char *args
, int flags
)
7070 struct spawn_prog
*sp
;
7071 char *arg
, *cp
, *ptr
;
7073 DNPRINTF(SWM_D_SPAWN
, "spawn_insert: %s[%s]\n", name
, args
);
7075 if (args
== NULL
|| *args
== '\0')
7078 if ((sp
= calloc(1, sizeof *sp
)) == NULL
)
7079 err(1, "spawn_insert: calloc");
7080 if ((sp
->name
= strdup(name
)) == NULL
)
7081 err(1, "spawn_insert: strdup");
7083 /* Convert the arguments to an argument list. */
7084 if ((ptr
= cp
= strdup(args
)) == NULL
)
7085 err(1, "spawn_insert: strdup");
7086 while ((arg
= argsep(&ptr
)) != NULL
) {
7087 /* Null argument; skip it. */
7092 if ((sp
->argv
= realloc(sp
->argv
, sp
->argc
*
7093 sizeof *sp
->argv
)) == NULL
)
7094 err(1, "spawn_insert: realloc");
7095 if ((sp
->argv
[sp
->argc
- 1] = strdup(arg
)) == NULL
)
7096 err(1, "spawn_insert: strdup");
7102 DNPRINTF(SWM_D_SPAWN
, "arg %d: [%s]\n", sp
->argc
, sp
->argv
[sp
->argc
-1]);
7103 TAILQ_INSERT_TAIL(&spawns
, sp
, entry
);
7104 DNPRINTF(SWM_D_SPAWN
, "spawn_insert: leave\n");
7108 spawn_remove(struct spawn_prog
*sp
)
7112 DNPRINTF(SWM_D_SPAWN
, "spawn_remove: %s\n", sp
->name
);
7114 TAILQ_REMOVE(&spawns
, sp
, entry
);
7115 for (i
= 0; i
< sp
->argc
; i
++)
7121 DNPRINTF(SWM_D_SPAWN
, "spawn_remove: leave\n");
7125 spawn_find(const char *name
)
7127 struct spawn_prog
*sp
;
7129 TAILQ_FOREACH(sp
, &spawns
, entry
)
7130 if (strcasecmp(sp
->name
, name
) == 0)
7137 setspawn(const char *name
, const char *args
, int flags
)
7139 struct spawn_prog
*sp
;
7141 DNPRINTF(SWM_D_SPAWN
, "setspawn: %s\n", name
);
7146 /* Remove any old spawn under the same name. */
7147 if ((sp
= spawn_find(name
)) != NULL
)
7151 spawn_insert(name
, args
, flags
);
7153 warnx("error: setspawn: cannot find program: %s", name
);
7155 DNPRINTF(SWM_D_SPAWN
, "setspawn: leave\n");
7159 setconfspawn(const char *selector
, const char *value
, int flags
)
7163 if (selector
== NULL
|| strlen(selector
) == 0)
7166 args
= expand_tilde(value
);
7168 DNPRINTF(SWM_D_SPAWN
, "setconfspawn: [%s] [%s]\n", selector
, args
);
7170 setspawn(selector
, args
, flags
);
7173 DNPRINTF(SWM_D_SPAWN
, "setconfspawn: done.\n");
7178 validate_spawns(void)
7180 struct spawn_prog
*sp
;
7181 char which
[PATH_MAX
];
7186 RB_FOREACH(kp
, key_tree
, &keys
) {
7187 if (kp
->funcid
!= KF_SPAWN_CUSTOM
)
7191 sp
= spawn_find(kp
->spawn_name
);
7192 if (sp
== NULL
|| sp
->flags
& SWM_SPAWN_OPTIONAL
)
7195 /* verify we have the goods */
7196 snprintf(which
, sizeof which
, "which %s", sp
->argv
[0]);
7197 DNPRINTF(SWM_D_CONF
, "validate_spawns: which %s\n",
7199 for (i
= strlen("which "); i
< strlen(which
); i
++)
7200 if (which
[i
] == ' ') {
7204 if (system(which
) != 0)
7205 add_startup_exception("could not find %s",
7206 &which
[strlen("which ")]);
7213 setconfspawn("lock", "xlock", 0);
7215 setconfspawn("term", "xterm", 0);
7216 setconfspawn("spawn_term", "xterm", 0);
7218 setconfspawn("menu", "dmenu_run"
7222 " -nf $bar_font_color"
7224 " -sf $bar_color", 0);
7226 setconfspawn("search", "dmenu"
7231 " -nf $bar_font_color"
7233 " -sf $bar_color", 0);
7235 setconfspawn("name_workspace", "dmenu"
7240 " -nf $bar_font_color"
7242 " -sf $bar_color", 0);
7244 /* These are not verified for existence, even with a binding set. */
7245 setconfspawn("screenshot_all", "screenshot.sh full", SWM_SPAWN_OPTIONAL
);
7246 setconfspawn("screenshot_wind", "screenshot.sh window", SWM_SPAWN_OPTIONAL
);
7247 setconfspawn("initscr", "initscreen.sh", SWM_SPAWN_OPTIONAL
);
7251 #define SWM_MODNAME_SIZE 32
7252 #define SWM_KEY_WS "\n+ \t"
7254 parsekeys(const char *keystr
, unsigned int currmod
, unsigned int *mod
, KeySym
*ks
)
7256 char *str
, *cp
, *name
;
7259 DNPRINTF(SWM_D_KEY
, "parsekeys: enter [%s]\n", keystr
);
7260 if (mod
== NULL
|| ks
== NULL
) {
7261 DNPRINTF(SWM_D_KEY
, "parsekeys: no mod or key vars\n");
7264 if (keystr
== NULL
|| strlen(keystr
) == 0) {
7265 DNPRINTF(SWM_D_KEY
, "parsekeys: no keystr\n");
7269 if ((cp
= str
= strdup(keystr
)) == NULL
)
7270 err(1, "parsekeys: strdup");
7272 *ks
= XCB_NO_SYMBOL
;
7274 while ((name
= strsep(&cp
, SWM_KEY_WS
)) != NULL
) {
7275 DNPRINTF(SWM_D_KEY
, "parsekeys: key [%s]\n", name
);
7277 cp
+= (long)strspn(cp
, SWM_KEY_WS
);
7278 if (strncasecmp(name
, "MOD", SWM_MODNAME_SIZE
) == 0)
7280 else if (strncasecmp(name
, "Mod1", SWM_MODNAME_SIZE
) == 0)
7281 *mod
|= XCB_MOD_MASK_1
;
7282 else if (strncasecmp(name
, "Mod2", SWM_MODNAME_SIZE
) == 0)
7283 *mod
+= XCB_MOD_MASK_2
;
7284 else if (strncmp(name
, "Mod3", SWM_MODNAME_SIZE
) == 0)
7285 *mod
|= XCB_MOD_MASK_3
;
7286 else if (strncmp(name
, "Mod4", SWM_MODNAME_SIZE
) == 0)
7287 *mod
|= XCB_MOD_MASK_4
;
7288 else if (strncmp(name
, "Mod5", SWM_MODNAME_SIZE
) == 0)
7289 *mod
|= XCB_MOD_MASK_5
;
7290 else if (strncasecmp(name
, "SHIFT", SWM_MODNAME_SIZE
) == 0)
7291 *mod
|= XCB_MOD_MASK_SHIFT
;
7292 else if (strncasecmp(name
, "CONTROL", SWM_MODNAME_SIZE
) == 0)
7293 *mod
|= XCB_MOD_MASK_CONTROL
;
7295 *ks
= XStringToKeysym(name
);
7296 XConvertCase(*ks
, ks
, &uks
);
7297 if (ks
== XCB_NO_SYMBOL
) {
7299 "parsekeys: invalid key %s\n",
7308 DNPRINTF(SWM_D_KEY
, "parsekeys: leave ok\n");
7313 strdupsafe(const char *str
)
7318 return (strdup(str
));
7322 key_insert(unsigned int mod
, KeySym ks
, enum keyfuncid kfid
,
7323 const char *spawn_name
)
7327 DNPRINTF(SWM_D_KEY
, "key_insert: enter %s [%s]\n",
7328 keyfuncs
[kfid
].name
, spawn_name
);
7330 if ((kp
= malloc(sizeof *kp
)) == NULL
)
7331 err(1, "key_insert: malloc");
7336 kp
->spawn_name
= strdupsafe(spawn_name
);
7337 RB_INSERT(key_tree
, &keys
, kp
);
7339 DNPRINTF(SWM_D_KEY
, "key_insert: leave\n");
7343 key_lookup(unsigned int mod
, KeySym ks
)
7350 return (RB_FIND(key_tree
, &keys
, &kp
));
7354 key_remove(struct key
*kp
)
7356 DNPRINTF(SWM_D_KEY
, "key_remove: %s\n", keyfuncs
[kp
->funcid
].name
);
7358 RB_REMOVE(key_tree
, &keys
, kp
);
7359 free(kp
->spawn_name
);
7362 DNPRINTF(SWM_D_KEY
, "key_remove: leave\n");
7366 key_replace(struct key
*kp
, unsigned int mod
, KeySym ks
, enum keyfuncid kfid
,
7367 const char *spawn_name
)
7369 DNPRINTF(SWM_D_KEY
, "key_replace: %s [%s]\n", keyfuncs
[kp
->funcid
].name
,
7373 key_insert(mod
, ks
, kfid
, spawn_name
);
7375 DNPRINTF(SWM_D_KEY
, "key_replace: leave\n");
7379 setkeybinding(unsigned int mod
, KeySym ks
, enum keyfuncid kfid
,
7380 const char *spawn_name
)
7384 DNPRINTF(SWM_D_KEY
, "setkeybinding: enter %s [%s]\n",
7385 keyfuncs
[kfid
].name
, spawn_name
);
7387 if ((kp
= key_lookup(mod
, ks
)) != NULL
) {
7388 if (kfid
== KF_INVALID
)
7391 key_replace(kp
, mod
, ks
, kfid
, spawn_name
);
7392 DNPRINTF(SWM_D_KEY
, "setkeybinding: leave\n");
7395 if (kfid
== KF_INVALID
) {
7396 warnx("bind: Key combination already unbound.");
7397 DNPRINTF(SWM_D_KEY
, "setkeybinding: leave\n");
7401 key_insert(mod
, ks
, kfid
, spawn_name
);
7402 DNPRINTF(SWM_D_KEY
, "setkeybinding: leave\n");
7406 setconfbinding(const char *selector
, const char *value
, int flags
)
7408 enum keyfuncid kfid
;
7411 struct spawn_prog
*sp
;
7413 /* suppress unused warning since var is needed */
7416 DNPRINTF(SWM_D_KEY
, "setconfbinding: enter selector: [%s], "
7417 "value: [%s]\n", selector
, value
);
7418 if (selector
== NULL
|| strlen(selector
) == 0) {
7419 DNPRINTF(SWM_D_KEY
, "setconfbinding: unbind %s\n", value
);
7420 if (parsekeys(value
, mod_key
, &mod
, &ks
) == 0) {
7422 setkeybinding(mod
, ks
, kfid
, NULL
);
7427 /* search by key function name */
7428 for (kfid
= 0; kfid
< KF_INVALID
; (kfid
)++) {
7429 if (strncasecmp(selector
, keyfuncs
[kfid
].name
,
7430 SWM_FUNCNAME_LEN
) == 0) {
7431 DNPRINTF(SWM_D_KEY
, "setconfbinding: %s: match "
7432 "keyfunc\n", selector
);
7433 if (parsekeys(value
, mod_key
, &mod
, &ks
) == 0) {
7434 setkeybinding(mod
, ks
, kfid
, NULL
);
7440 /* search by custom spawn name */
7441 if ((sp
= spawn_find(selector
)) != NULL
) {
7442 DNPRINTF(SWM_D_KEY
, "setconfbinding: %s: match "
7443 "spawn\n", selector
);
7444 if (parsekeys(value
, mod_key
, &mod
, &ks
) == 0) {
7445 setkeybinding(mod
, ks
, KF_SPAWN_CUSTOM
,
7451 DNPRINTF(SWM_D_KEY
, "setconfbinding: no match\n");
7458 #define MODKEY_SHIFT MODKEY | XCB_MOD_MASK_SHIFT
7459 setkeybinding(MODKEY
, XK_b
, KF_BAR_TOGGLE
, NULL
);
7460 setkeybinding(MODKEY_SHIFT
, XK_b
, KF_BAR_TOGGLE_WS
,NULL
);
7461 setkeybinding(MODKEY
, XK_v
, KF_BUTTON2
, NULL
);
7462 setkeybinding(MODKEY
, XK_space
, KF_CYCLE_LAYOUT
,NULL
);
7463 setkeybinding(MODKEY_SHIFT
, XK_backslash
, KF_FLIP_LAYOUT
, NULL
);
7464 setkeybinding(MODKEY
, XK_t
, KF_FLOAT_TOGGLE
,NULL
);
7465 setkeybinding(MODKEY
, XK_m
, KF_FOCUS_MAIN
, NULL
);
7466 setkeybinding(MODKEY
, XK_j
, KF_FOCUS_NEXT
, NULL
);
7467 setkeybinding(MODKEY
, XK_Tab
, KF_FOCUS_NEXT
, NULL
);
7468 setkeybinding(MODKEY
, XK_k
, KF_FOCUS_PREV
, NULL
);
7469 setkeybinding(MODKEY_SHIFT
, XK_Tab
, KF_FOCUS_PREV
, NULL
);
7470 setkeybinding(MODKEY
, XK_u
, KF_FOCUS_URGENT
,NULL
);
7471 setkeybinding(MODKEY
, XK_e
, KF_MAXIMIZE_TOGGLE
,NULL
);
7472 setkeybinding(MODKEY_SHIFT
, XK_equal
, KF_HEIGHT_GROW
,NULL
);
7473 setkeybinding(MODKEY_SHIFT
, XK_minus
, KF_HEIGHT_SHRINK
,NULL
);
7474 setkeybinding(MODKEY
, XK_w
, KF_ICONIFY
, NULL
);
7475 setkeybinding(MODKEY
, XK_h
, KF_MASTER_SHRINK
, NULL
);
7476 setkeybinding(MODKEY
, XK_l
, KF_MASTER_GROW
, NULL
);
7477 setkeybinding(MODKEY
, XK_comma
, KF_MASTER_ADD
, NULL
);
7478 setkeybinding(MODKEY
, XK_period
, KF_MASTER_DEL
, NULL
);
7479 setkeybinding(MODKEY_SHIFT
, XK_bracketright
,KF_MOVE_DOWN
,NULL
);
7480 setkeybinding(MODKEY
, XK_bracketleft
, KF_MOVE_LEFT
,NULL
);
7481 setkeybinding(MODKEY
, XK_bracketright
,KF_MOVE_RIGHT
,NULL
);
7482 setkeybinding(MODKEY_SHIFT
, XK_bracketleft
, KF_MOVE_UP
, NULL
);
7483 setkeybinding(MODKEY_SHIFT
, XK_KP_End
, KF_MVRG_1
, NULL
);
7484 setkeybinding(MODKEY_SHIFT
, XK_KP_Down
, KF_MVRG_2
, NULL
);
7485 setkeybinding(MODKEY_SHIFT
, XK_KP_Next
, KF_MVRG_3
, NULL
);
7486 setkeybinding(MODKEY_SHIFT
, XK_KP_Left
, KF_MVRG_4
, NULL
);
7487 setkeybinding(MODKEY_SHIFT
, XK_KP_Begin
, KF_MVRG_5
, NULL
);
7488 setkeybinding(MODKEY_SHIFT
, XK_KP_Right
, KF_MVRG_6
, NULL
);
7489 setkeybinding(MODKEY_SHIFT
, XK_KP_Home
, KF_MVRG_7
, NULL
);
7490 setkeybinding(MODKEY_SHIFT
, XK_KP_Up
, KF_MVRG_8
, NULL
);
7491 setkeybinding(MODKEY_SHIFT
, XK_KP_Prior
, KF_MVRG_9
, NULL
);
7492 setkeybinding(MODKEY_SHIFT
, XK_1
, KF_MVWS_1
, NULL
);
7493 setkeybinding(MODKEY_SHIFT
, XK_2
, KF_MVWS_2
, NULL
);
7494 setkeybinding(MODKEY_SHIFT
, XK_3
, KF_MVWS_3
, NULL
);
7495 setkeybinding(MODKEY_SHIFT
, XK_4
, KF_MVWS_4
, NULL
);
7496 setkeybinding(MODKEY_SHIFT
, XK_5
, KF_MVWS_5
, NULL
);
7497 setkeybinding(MODKEY_SHIFT
, XK_6
, KF_MVWS_6
, NULL
);
7498 setkeybinding(MODKEY_SHIFT
, XK_7
, KF_MVWS_7
, NULL
);
7499 setkeybinding(MODKEY_SHIFT
, XK_8
, KF_MVWS_8
, NULL
);
7500 setkeybinding(MODKEY_SHIFT
, XK_9
, KF_MVWS_9
, NULL
);
7501 setkeybinding(MODKEY_SHIFT
, XK_0
, KF_MVWS_10
, NULL
);
7502 setkeybinding(MODKEY_SHIFT
, XK_F1
, KF_MVWS_11
, NULL
);
7503 setkeybinding(MODKEY_SHIFT
, XK_F2
, KF_MVWS_12
, NULL
);
7504 setkeybinding(MODKEY_SHIFT
, XK_F3
, KF_MVWS_13
, NULL
);
7505 setkeybinding(MODKEY_SHIFT
, XK_F4
, KF_MVWS_14
, NULL
);
7506 setkeybinding(MODKEY_SHIFT
, XK_F5
, KF_MVWS_15
, NULL
);
7507 setkeybinding(MODKEY_SHIFT
, XK_F6
, KF_MVWS_16
, NULL
);
7508 setkeybinding(MODKEY_SHIFT
, XK_F7
, KF_MVWS_17
, NULL
);
7509 setkeybinding(MODKEY_SHIFT
, XK_F8
, KF_MVWS_18
, NULL
);
7510 setkeybinding(MODKEY_SHIFT
, XK_F9
, KF_MVWS_19
, NULL
);
7511 setkeybinding(MODKEY_SHIFT
, XK_F10
, KF_MVWS_20
, NULL
);
7512 setkeybinding(MODKEY_SHIFT
, XK_F11
, KF_MVWS_21
, NULL
);
7513 setkeybinding(MODKEY_SHIFT
, XK_F12
, KF_MVWS_22
, NULL
);
7514 setkeybinding(MODKEY_SHIFT
, XK_slash
, KF_NAME_WORKSPACE
,NULL
);
7515 setkeybinding(MODKEY_SHIFT
, XK_q
, KF_QUIT
, NULL
);
7516 setkeybinding(MODKEY_SHIFT
, XK_r
, KF_RAISE_TOGGLE
,NULL
);
7517 setkeybinding(MODKEY
, XK_q
, KF_RESTART
, NULL
);
7518 setkeybinding(MODKEY
, XK_KP_End
, KF_RG_1
, NULL
);
7519 setkeybinding(MODKEY
, XK_KP_Down
, KF_RG_2
, NULL
);
7520 setkeybinding(MODKEY
, XK_KP_Next
, KF_RG_3
, NULL
);
7521 setkeybinding(MODKEY
, XK_KP_Left
, KF_RG_4
, NULL
);
7522 setkeybinding(MODKEY
, XK_KP_Begin
, KF_RG_5
, NULL
);
7523 setkeybinding(MODKEY
, XK_KP_Right
, KF_RG_6
, NULL
);
7524 setkeybinding(MODKEY
, XK_KP_Home
, KF_RG_7
, NULL
);
7525 setkeybinding(MODKEY
, XK_KP_Up
, KF_RG_8
, NULL
);
7526 setkeybinding(MODKEY
, XK_KP_Prior
, KF_RG_9
, NULL
);
7527 setkeybinding(MODKEY_SHIFT
, XK_Right
, KF_RG_NEXT
, NULL
);
7528 setkeybinding(MODKEY_SHIFT
, XK_Left
, KF_RG_PREV
, NULL
);
7529 setkeybinding(MODKEY
, XK_f
, KF_SEARCH_WIN
, NULL
);
7530 setkeybinding(MODKEY
, XK_slash
, KF_SEARCH_WORKSPACE
,NULL
);
7531 setkeybinding(MODKEY_SHIFT
, XK_i
, KF_SPAWN_CUSTOM
,"initscr");
7532 setkeybinding(MODKEY_SHIFT
, XK_Delete
, KF_SPAWN_CUSTOM
,"lock");
7533 setkeybinding(MODKEY
, XK_p
, KF_SPAWN_CUSTOM
,"menu");
7534 setkeybinding(MODKEY
, XK_s
, KF_SPAWN_CUSTOM
,"screenshot_all");
7535 setkeybinding(MODKEY_SHIFT
, XK_s
, KF_SPAWN_CUSTOM
,"screenshot_wind");
7536 setkeybinding(MODKEY_SHIFT
, XK_Return
, KF_SPAWN_CUSTOM
,"term");
7537 setkeybinding(MODKEY_SHIFT
, XK_comma
, KF_STACK_INC
, NULL
);
7538 setkeybinding(MODKEY_SHIFT
, XK_period
, KF_STACK_DEC
, NULL
);
7539 setkeybinding(MODKEY_SHIFT
, XK_space
, KF_STACK_RESET
, NULL
);
7540 setkeybinding(MODKEY
, XK_Return
, KF_SWAP_MAIN
, NULL
);
7541 setkeybinding(MODKEY_SHIFT
, XK_j
, KF_SWAP_NEXT
, NULL
);
7542 setkeybinding(MODKEY_SHIFT
, XK_k
, KF_SWAP_PREV
, NULL
);
7543 setkeybinding(MODKEY_SHIFT
, XK_w
, KF_UNICONIFY
, NULL
);
7544 setkeybinding(MODKEY_SHIFT
, XK_v
, KF_VERSION
, NULL
);
7545 setkeybinding(MODKEY
, XK_equal
, KF_WIDTH_GROW
, NULL
);
7546 setkeybinding(MODKEY
, XK_minus
, KF_WIDTH_SHRINK
,NULL
);
7547 setkeybinding(MODKEY
, XK_x
, KF_WIND_DEL
, NULL
);
7548 setkeybinding(MODKEY_SHIFT
, XK_x
, KF_WIND_KILL
, NULL
);
7549 setkeybinding(MODKEY
, XK_1
, KF_WS_1
, NULL
);
7550 setkeybinding(MODKEY
, XK_2
, KF_WS_2
, NULL
);
7551 setkeybinding(MODKEY
, XK_3
, KF_WS_3
, NULL
);
7552 setkeybinding(MODKEY
, XK_4
, KF_WS_4
, NULL
);
7553 setkeybinding(MODKEY
, XK_5
, KF_WS_5
, NULL
);
7554 setkeybinding(MODKEY
, XK_6
, KF_WS_6
, NULL
);
7555 setkeybinding(MODKEY
, XK_7
, KF_WS_7
, NULL
);
7556 setkeybinding(MODKEY
, XK_8
, KF_WS_8
, NULL
);
7557 setkeybinding(MODKEY
, XK_9
, KF_WS_9
, NULL
);
7558 setkeybinding(MODKEY
, XK_0
, KF_WS_10
, NULL
);
7559 setkeybinding(MODKEY
, XK_F1
, KF_WS_11
, NULL
);
7560 setkeybinding(MODKEY
, XK_F2
, KF_WS_12
, NULL
);
7561 setkeybinding(MODKEY
, XK_F3
, KF_WS_13
, NULL
);
7562 setkeybinding(MODKEY
, XK_F4
, KF_WS_14
, NULL
);
7563 setkeybinding(MODKEY
, XK_F5
, KF_WS_15
, NULL
);
7564 setkeybinding(MODKEY
, XK_F6
, KF_WS_16
, NULL
);
7565 setkeybinding(MODKEY
, XK_F7
, KF_WS_17
, NULL
);
7566 setkeybinding(MODKEY
, XK_F8
, KF_WS_18
, NULL
);
7567 setkeybinding(MODKEY
, XK_F9
, KF_WS_19
, NULL
);
7568 setkeybinding(MODKEY
, XK_F10
, KF_WS_20
, NULL
);
7569 setkeybinding(MODKEY
, XK_F11
, KF_WS_21
, NULL
);
7570 setkeybinding(MODKEY
, XK_F12
, KF_WS_22
, NULL
);
7571 setkeybinding(MODKEY
, XK_Right
, KF_WS_NEXT
, NULL
);
7572 setkeybinding(MODKEY
, XK_Left
, KF_WS_PREV
, NULL
);
7573 setkeybinding(MODKEY
, XK_Up
, KF_WS_NEXT_ALL
, NULL
);
7574 setkeybinding(MODKEY
, XK_Down
, KF_WS_PREV_ALL
, NULL
);
7575 setkeybinding(MODKEY_SHIFT
, XK_Up
, KF_WS_NEXT_MOVE
,NULL
);
7576 setkeybinding(MODKEY_SHIFT
, XK_Down
, KF_WS_PREV_MOVE
,NULL
);
7577 setkeybinding(MODKEY
, XK_a
, KF_WS_PRIOR
, NULL
);
7579 setkeybinding(MODKEY_SHIFT
, XK_d
, KF_DUMPWINS
, NULL
);
7589 while (RB_EMPTY(&keys
) == 0) {
7590 kp
= RB_ROOT(&keys
);
7596 setkeymapping(const char *selector
, const char *value
, int flags
)
7598 char *keymapping_file
;
7600 /* suppress unused warnings since vars are needed */
7604 DNPRINTF(SWM_D_KEY
, "setkeymapping: enter\n");
7606 keymapping_file
= expand_tilde(value
);
7609 /* load new key bindings; if it fails, revert to default bindings */
7610 if (conf_load(keymapping_file
, SWM_CONF_KEYMAPPING
)) {
7615 free(keymapping_file
);
7617 DNPRINTF(SWM_D_KEY
, "setkeymapping: leave\n");
7622 updatenumlockmask(void)
7625 xcb_get_modifier_mapping_reply_t
*modmap_r
;
7626 xcb_keycode_t
*modmap
, kc
, *keycode
;
7630 modmap_r
= xcb_get_modifier_mapping_reply(conn
,
7631 xcb_get_modifier_mapping(conn
),
7634 modmap
= xcb_get_modifier_mapping_keycodes(modmap_r
);
7635 for (i
= 0; i
< 8; i
++) {
7636 for (j
= 0; j
< modmap_r
->keycodes_per_modifier
; j
++) {
7637 kc
= modmap
[i
* modmap_r
->keycodes_per_modifier
7639 keycode
= xcb_key_symbols_get_keycode(syms
,
7643 numlockmask
= (1 << i
);
7650 DNPRINTF(SWM_D_MISC
, "updatenumlockmask: %d\n", numlockmask
);
7657 int num_screens
, k
, j
;
7658 unsigned int modifiers
[4];
7659 xcb_keycode_t
*code
;
7661 DNPRINTF(SWM_D_MISC
, "grabkeys\n");
7662 updatenumlockmask();
7665 modifiers
[1] = numlockmask
;
7666 modifiers
[2] = XCB_MOD_MASK_LOCK
;
7667 modifiers
[3] = numlockmask
| XCB_MOD_MASK_LOCK
;
7669 num_screens
= get_screen_count();
7670 for (k
= 0; k
< num_screens
; k
++) {
7671 if (TAILQ_EMPTY(&screens
[k
].rl
))
7673 xcb_ungrab_key(conn
, XCB_GRAB_ANY
, screens
[k
].root
,
7675 RB_FOREACH(kp
, key_tree
, &keys
) {
7676 /* Skip unused ws binds. */
7677 if ((int)kp
->funcid
> KF_WS_1
+ workspace_limit
- 1 &&
7678 kp
->funcid
<= KF_WS_22
)
7681 /* Skip unused mvws binds. */
7682 if ((int)kp
->funcid
> KF_MVWS_1
+ workspace_limit
- 1 &&
7683 kp
->funcid
<= KF_MVWS_22
)
7686 if ((code
= xcb_key_symbols_get_keycode(syms
,
7688 for (j
= 0; j
< LENGTH(modifiers
); j
++)
7689 xcb_grab_key(conn
, 1,
7691 kp
->mod
| modifiers
[j
],
7692 *code
, XCB_GRAB_MODE_SYNC
,
7693 XCB_GRAB_MODE_SYNC
);
7701 grabbuttons(struct ws_win
*win
)
7703 unsigned int modifiers
[4];
7706 DNPRINTF(SWM_D_MOUSE
, "grabbuttons: win %#x\n", win
->id
);
7707 updatenumlockmask();
7710 modifiers
[1] = numlockmask
;
7711 modifiers
[2] = XCB_MOD_MASK_LOCK
;
7712 modifiers
[3] = numlockmask
| XCB_MOD_MASK_LOCK
;
7714 for (i
= 0; i
< LENGTH(buttons
); i
++)
7715 if (buttons
[i
].action
== client_click
)
7716 for (j
= 0; j
< LENGTH(modifiers
); ++j
)
7717 xcb_grab_button(conn
, 0, win
->id
, BUTTONMASK
,
7718 XCB_GRAB_MODE_SYNC
, XCB_GRAB_MODE_ASYNC
,
7719 XCB_WINDOW_NONE
, XCB_CURSOR_NONE
,
7720 buttons
[i
].button
, buttons
[i
].mask
|
7724 const char *quirkname
[] = {
7725 "NONE", /* config string for "no value" */
7733 "FOCUSONMAP_SINGLE",
7740 /* SWM_Q_DELIM: retain '|' for back compat for now (2009-08-11) */
7741 #define SWM_Q_DELIM "\n|+ \t"
7743 parsequirks(const char *qstr
, uint32_t *quirk
, int *ws
)
7745 char *str
, *cp
, *name
;
7748 if (quirk
== NULL
|| qstr
== NULL
)
7751 if ((str
= strdup(qstr
)) == NULL
)
7752 err(1, "parsequirks: strdup");
7756 while ((name
= strsep(&cp
, SWM_Q_DELIM
)) != NULL
) {
7758 cp
+= (long)strspn(cp
, SWM_Q_DELIM
);
7760 if (sscanf(name
, "WS[%d]", ws
) == 1) {
7766 for (i
= 0; i
< LENGTH(quirkname
); i
++) {
7767 if (strncasecmp(name
, quirkname
[i
],
7768 SWM_QUIRK_LEN
) == 0) {
7769 DNPRINTF(SWM_D_QUIRK
,
7770 "parsequirks: %s\n", name
);
7776 *quirk
|= 1 << (i
-1);
7780 if (i
>= LENGTH(quirkname
)) {
7781 DNPRINTF(SWM_D_QUIRK
,
7782 "parsequirks: invalid quirk [%s]\n", name
);
7793 quirk_insert(const char *class, const char *instance
, const char *name
,
7794 uint32_t quirk
, int ws
)
7798 bool failed
= false;
7800 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: class: %s, instance: %s, name: %s,"
7801 " value: %u, ws: %d\n", class, instance
, name
, quirk
, ws
);
7803 if ((qp
= malloc(sizeof *qp
)) == NULL
)
7804 err(1, "quirk_insert: malloc");
7806 if ((qp
->class = strdup(class)) == NULL
)
7807 err(1, "quirk_insert: strdup");
7808 if ((qp
->instance
= strdup(instance
)) == NULL
)
7809 err(1, "quirk_insert: strdup");
7810 if ((qp
->name
= strdup(name
)) == NULL
)
7811 err(1, "quirk_insert: strdup");
7813 if (asprintf(&str
, "^%s$", class) == -1)
7814 err(1, "quirk_insert: asprintf");
7815 if (regcomp(&qp
->regex_class
, str
, REG_EXTENDED
| REG_NOSUB
)) {
7816 add_startup_exception("regex failed to compile quirk 'class' "
7817 "field: %s", class);
7820 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: compiled: %s\n", str
);
7823 if (asprintf(&str
, "^%s$", instance
) == -1)
7824 err(1, "quirk_insert: asprintf");
7825 if (regcomp(&qp
->regex_instance
, str
, REG_EXTENDED
| REG_NOSUB
)) {
7826 add_startup_exception("regex failed to compile quirk 'instance'"
7827 " field: %s", instance
);
7830 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: compiled: %s\n", str
);
7833 if (asprintf(&str
, "^%s$", name
) == -1)
7834 err(1, "quirk_insert: asprintf");
7835 if (regcomp(&qp
->regex_name
, str
, REG_EXTENDED
| REG_NOSUB
)) {
7836 add_startup_exception("regex failed to compile quirk 'name' "
7840 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: compiled: %s\n", str
);
7844 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: regex error; skipping.\n");
7849 TAILQ_INSERT_TAIL(&quirks
, qp
, entry
);
7851 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: leave\n");
7855 quirk_remove(struct quirk
*qp
)
7857 DNPRINTF(SWM_D_QUIRK
, "quirk_remove: %s:%s [%u]\n", qp
->class,
7858 qp
->name
, qp
->quirk
);
7860 TAILQ_REMOVE(&quirks
, qp
, entry
);
7863 DNPRINTF(SWM_D_QUIRK
, "quirk_remove: leave\n");
7867 quirk_free(struct quirk
*qp
)
7869 regfree(&qp
->regex_class
);
7870 regfree(&qp
->regex_instance
);
7871 regfree(&qp
->regex_name
);
7879 quirk_replace(struct quirk
*qp
, const char *class, const char *instance
,
7880 const char *name
, uint32_t quirk
, int ws
)
7882 DNPRINTF(SWM_D_QUIRK
, "quirk_replace: %s:%s:%s [%u], ws: %d\n", qp
->class,
7883 qp
->instance
, qp
->name
, qp
->quirk
, qp
->ws
);
7886 quirk_insert(class, instance
, name
, quirk
, ws
);
7888 DNPRINTF(SWM_D_QUIRK
, "quirk_replace: leave\n");
7892 setquirk(const char *class, const char *instance
, const char *name
,
7893 uint32_t quirk
, int ws
)
7897 DNPRINTF(SWM_D_QUIRK
, "setquirk: enter %s:%s:%s [%u], ws: %d\n", class,
7898 instance
, name
, quirk
, ws
);
7900 /* Remove/replace existing quirk. */
7901 TAILQ_FOREACH(qp
, &quirks
, entry
) {
7902 if (strcmp(qp
->class, class) == 0 &&
7903 strcmp(qp
->instance
, instance
) == 0 &&
7904 strcmp(qp
->name
, name
) == 0) {
7905 if (quirk
== 0 && ws
== -1)
7908 quirk_replace(qp
, class, instance
, name
, quirk
,
7910 DNPRINTF(SWM_D_QUIRK
, "setquirk: leave\n");
7915 /* Only insert if quirk is not NONE or forced ws is set. */
7916 if (quirk
|| ws
!= -1)
7917 quirk_insert(class, instance
, name
, quirk
, ws
);
7919 DNPRINTF(SWM_D_QUIRK
, "setquirk: leave\n");
7922 /* Eat '\' in str used to escape square brackets and colon. */
7924 unescape_selector(char *str
)
7928 for (cp
= str
; *str
!= '\0'; ++str
, ++cp
) {
7929 if (*str
== '\\' && (*(str
+ 1) == ':' || *(str
+ 1) == ']' ||
7939 setconfquirk(const char *selector
, const char *value
, int flags
)
7941 char *str
, *cp
, *class;
7942 char *instance
= NULL
, *name
= NULL
;
7943 int retval
, count
= 0, ws
= -1;
7946 /* suppress unused warning since var is needed */
7949 if (selector
== NULL
|| strlen(selector
) == 0)
7952 if ((str
= strdup(selector
)) == NULL
)
7953 err(1, "setconfquirk: strdup");
7955 /* Find non-escaped colon. */
7962 for (++cp
; *cp
!= '\0'; ++cp
) {
7963 if (*cp
== ':' && *(cp
- 1) != '\\') {
7969 unescape_selector(class);
7971 instance
= class + strlen(class) + 1;
7972 unescape_selector(instance
);
7978 name
= instance
+ strlen(instance
) + 1;
7979 unescape_selector(name
);
7984 DNPRINTF(SWM_D_CONF
, "setconfquirk: class: %s, instance: %s, "
7985 "name: %s\n", class, instance
, name
);
7987 if ((retval
= parsequirks(value
, &qrks
, &ws
)) == 0)
7988 setquirk(class, instance
, name
, qrks
, ws
);
7997 setquirk("MPlayer", "xv", ".*",
7998 SWM_Q_FLOAT
| SWM_Q_FULLSCREEN
| SWM_Q_FOCUSPREV
, -1);
7999 setquirk("OpenOffice.org 3.2", "VCLSalFrame", ".*",
8001 setquirk("Firefox-bin", "firefox-bin", ".*",
8003 setquirk("Firefox", "Dialog", ".*",
8005 setquirk("Gimp", "gimp", ".*",
8006 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
8007 setquirk("XTerm", "xterm", ".*",
8008 SWM_Q_XTERM_FONTADJ
, -1);
8009 setquirk("xine", "Xine Window", ".*",
8010 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
8011 setquirk("Xitk", "Xitk Combo", ".*",
8012 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
8013 setquirk("xine", "xine Panel", ".*",
8014 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
8015 setquirk("Xitk", "Xine Window", ".*",
8016 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
8017 setquirk("xine", "xine Video Fullscreen Window", ".*",
8018 SWM_Q_FULLSCREEN
| SWM_Q_FLOAT
, -1);
8019 setquirk("pcb", "pcb", ".*",
8021 setquirk("SDL_App", "SDL_App", ".*",
8022 SWM_Q_FLOAT
| SWM_Q_FULLSCREEN
, -1);
8025 /* conf file stuff */
8026 #define SWM_CONF_FILE "spectrwm.conf"
8027 #define SWM_CONF_FILE_OLD "scrotwm.conf"
8031 SWM_S_BAR_AT_BOTTOM
,
8032 SWM_S_BAR_BORDER_WIDTH
,
8035 SWM_S_BAR_ENABLED_WS
,
8040 SWM_S_BOUNDARY_WIDTH
,
8041 SWM_S_CLOCK_ENABLED
,
8044 SWM_S_CYCLE_VISIBLE
,
8046 SWM_S_DISABLE_BORDER
,
8048 SWM_S_FOCUS_CLOSE_WRAP
,
8049 SWM_S_FOCUS_DEFAULT
,
8051 SWM_S_ICONIC_ENABLED
,
8052 SWM_S_JAVA_WORKAROUND
,
8053 SWM_S_MAXIMIZE_HIDE_BAR
,
8054 SWM_S_REGION_PADDING
,
8059 SWM_S_STACK_ENABLED
,
8062 SWM_S_URGENT_COLLAPSE
,
8063 SWM_S_URGENT_ENABLED
,
8064 SWM_S_VERBOSE_LAYOUT
,
8067 SWM_S_WINDOW_CLASS_ENABLED
,
8068 SWM_S_WINDOW_INSTANCE_ENABLED
,
8069 SWM_S_WINDOW_NAME_ENABLED
,
8070 SWM_S_WORKSPACE_CLAMP
,
8071 SWM_S_WORKSPACE_LIMIT
,
8072 SWM_S_WORKSPACE_NAME
,
8076 setconfvalue(const char *selector
, const char *value
, int flags
)
8078 struct workspace
*ws
;
8079 int i
, ws_id
, num_screens
;
8080 char *b
, *str
, s
[1024];
8083 case SWM_S_BAR_ACTION
:
8085 if ((bar_argv
[0] = expand_tilde(value
)) == NULL
)
8086 err(1, "setconfvalue: bar_action");
8088 case SWM_S_BAR_AT_BOTTOM
:
8089 bar_at_bottom
= (atoi(value
) != 0);
8091 case SWM_S_BAR_BORDER_WIDTH
:
8092 bar_border_width
= atoi(value
);
8093 if (bar_border_width
< 0)
8094 bar_border_width
= 0;
8096 case SWM_S_BAR_DELAY
:
8097 /* No longer needed; leave to not break old conf files. */
8099 case SWM_S_BAR_ENABLED
:
8100 bar_enabled
= (atoi(value
) != 0);
8102 case SWM_S_BAR_ENABLED_WS
:
8103 ws_id
= atoi(selector
) - 1;
8104 if (ws_id
< 0 || ws_id
>= workspace_limit
)
8105 errx(1, "setconfvalue: bar_enabled_ws: invalid "
8106 "workspace %d.", ws_id
+ 1);
8108 num_screens
= get_screen_count();
8109 for (i
= 0; i
< num_screens
; i
++) {
8110 ws
= (struct workspace
*)&screens
[i
].ws
;
8111 ws
[ws_id
].bar_enabled
= (atoi(value
) != 0);
8114 case SWM_S_BAR_FONT
:
8116 if (asprintf(&bar_fonts
, "%s,%s", value
, bar_fonts
) == -1)
8117 err(1, "setconfvalue: asprintf: failed to allocate "
8118 "memory for bar_fonts.");
8121 /* If already in xft mode, then we are done. */
8122 if (!bar_font_legacy
)
8125 if ((str
= strdup(value
)) == NULL
)
8126 err(1, "setconfvalue: strdup");
8128 /* If there are any non-XLFD entries, switch to Xft mode. */
8129 while ((b
= strsep(&str
, ",")) != NULL
) {
8133 bar_font_legacy
= false;
8140 case SWM_S_BAR_FORMAT
:
8142 if ((bar_format
= strdup(value
)) == NULL
)
8143 err(1, "setconfvalue: bar_format");
8145 case SWM_S_BAR_JUSTIFY
:
8146 if (strcmp(value
, "left") == 0)
8147 bar_justify
= SWM_BAR_JUSTIFY_LEFT
;
8148 else if (strcmp(value
, "center") == 0)
8149 bar_justify
= SWM_BAR_JUSTIFY_CENTER
;
8150 else if (strcmp(value
, "right") == 0)
8151 bar_justify
= SWM_BAR_JUSTIFY_RIGHT
;
8153 errx(1, "invalid bar_justify");
8155 case SWM_S_BORDER_WIDTH
:
8156 border_width
= atoi(value
);
8157 if (border_width
< 0)
8160 case SWM_S_BOUNDARY_WIDTH
:
8161 boundary_width
= atoi(value
);
8162 if (boundary_width
< 0)
8165 case SWM_S_CLOCK_ENABLED
:
8166 clock_enabled
= (atoi(value
) != 0);
8168 case SWM_S_CLOCK_FORMAT
:
8169 #ifndef SWM_DENY_CLOCK_FORMAT
8171 if ((clock_format
= strdup(value
)) == NULL
)
8172 err(1, "setconfvalue: clock_format");
8175 case SWM_S_CYCLE_EMPTY
:
8176 cycle_empty
= (atoi(value
) != 0);
8178 case SWM_S_CYCLE_VISIBLE
:
8179 cycle_visible
= (atoi(value
) != 0);
8181 case SWM_S_DIALOG_RATIO
:
8182 dialog_ratio
= atof(value
);
8183 if (dialog_ratio
> 1.0 || dialog_ratio
<= .3)
8186 case SWM_S_DISABLE_BORDER
:
8187 disable_border
= (atoi(value
) != 0);
8189 case SWM_S_FOCUS_CLOSE
:
8190 if (strcmp(value
, "first") == 0)
8191 focus_close
= SWM_STACK_BOTTOM
;
8192 else if (strcmp(value
, "last") == 0)
8193 focus_close
= SWM_STACK_TOP
;
8194 else if (strcmp(value
, "next") == 0)
8195 focus_close
= SWM_STACK_ABOVE
;
8196 else if (strcmp(value
, "previous") == 0)
8197 focus_close
= SWM_STACK_BELOW
;
8199 errx(1, "focus_close");
8201 case SWM_S_FOCUS_CLOSE_WRAP
:
8202 focus_close_wrap
= (atoi(value
) != 0);
8204 case SWM_S_FOCUS_DEFAULT
:
8205 if (strcmp(value
, "last") == 0)
8206 focus_default
= SWM_STACK_TOP
;
8207 else if (strcmp(value
, "first") == 0)
8208 focus_default
= SWM_STACK_BOTTOM
;
8210 errx(1, "focus_default");
8212 case SWM_S_FOCUS_MODE
:
8213 if (strcmp(value
, "default") == 0)
8214 focus_mode
= SWM_FOCUS_DEFAULT
;
8215 else if (strcmp(value
, "follow") == 0 ||
8216 strcmp(value
, "follow_cursor") == 0)
8217 focus_mode
= SWM_FOCUS_FOLLOW
;
8218 else if (strcmp(value
, "manual") == 0)
8219 focus_mode
= SWM_FOCUS_MANUAL
;
8221 errx(1, "focus_mode");
8223 case SWM_S_ICONIC_ENABLED
:
8224 iconic_enabled
= (atoi(value
) != 0);
8226 case SWM_S_JAVA_WORKAROUND
:
8227 java_workaround
= (atoi(value
) != 0);
8229 case SWM_S_MAXIMIZE_HIDE_BAR
:
8230 maximize_hide_bar
= atoi(value
);
8232 case SWM_S_REGION_PADDING
:
8233 region_padding
= atoi(value
);
8234 if (region_padding
< 0)
8237 case SWM_S_SPAWN_ORDER
:
8238 if (strcmp(value
, "first") == 0)
8239 spawn_position
= SWM_STACK_BOTTOM
;
8240 else if (strcmp(value
, "last") == 0)
8241 spawn_position
= SWM_STACK_TOP
;
8242 else if (strcmp(value
, "next") == 0)
8243 spawn_position
= SWM_STACK_ABOVE
;
8244 else if (strcmp(value
, "previous") == 0)
8245 spawn_position
= SWM_STACK_BELOW
;
8247 errx(1, "spawn_position");
8249 case SWM_S_SPAWN_TERM
:
8250 setconfspawn("term", value
, 0);
8251 setconfspawn("spawn_term", value
, 0);
8254 /* No longer needed; leave to not break old conf files. */
8256 case SWM_S_SS_ENABLED
:
8257 /* No longer needed; leave to not break old conf files. */
8259 case SWM_S_STACK_ENABLED
:
8260 stack_enabled
= (atoi(value
) != 0);
8262 case SWM_S_TERM_WIDTH
:
8263 term_width
= atoi(value
);
8267 case SWM_S_TILE_GAP
:
8268 tile_gap
= atoi(value
);
8270 case SWM_S_URGENT_COLLAPSE
:
8271 urgent_collapse
= (atoi(value
) != 0);
8273 case SWM_S_URGENT_ENABLED
:
8274 urgent_enabled
= (atoi(value
) != 0);
8276 case SWM_S_VERBOSE_LAYOUT
:
8277 verbose_layout
= (atoi(value
) != 0);
8278 for (i
= 0; layouts
[i
].l_stack
!= NULL
; i
++) {
8280 layouts
[i
].l_string
= fancy_stacker
;
8282 layouts
[i
].l_string
= plain_stacker
;
8285 case SWM_S_WARP_FOCUS
:
8286 warp_focus
= (atoi(value
) != 0);
8288 case SWM_S_WARP_POINTER
:
8289 warp_pointer
= (atoi(value
) != 0);
8291 case SWM_S_WINDOW_CLASS_ENABLED
:
8292 window_class_enabled
= (atoi(value
) != 0);
8294 case SWM_S_WINDOW_INSTANCE_ENABLED
:
8295 window_instance_enabled
= (atoi(value
) != 0);
8297 case SWM_S_WINDOW_NAME_ENABLED
:
8298 window_name_enabled
= (atoi(value
) != 0);
8300 case SWM_S_WORKSPACE_CLAMP
:
8301 workspace_clamp
= (atoi(value
) != 0);
8303 case SWM_S_WORKSPACE_LIMIT
:
8304 workspace_limit
= atoi(value
);
8305 if (workspace_limit
> SWM_WS_MAX
)
8306 workspace_limit
= SWM_WS_MAX
;
8307 else if (workspace_limit
< 1)
8308 workspace_limit
= 1;
8310 ewmh_update_desktops();
8312 case SWM_S_WORKSPACE_NAME
:
8313 if (getenv("SWM_STARTED") != NULL
)
8317 if (sscanf(value
, "ws[%d]:%1023c", &ws_id
, s
) != 2)
8318 errx(1, "invalid entry, should be 'ws[<idx>]:name'");
8320 if (ws_id
< 0 || ws_id
>= workspace_limit
)
8321 errx(1, "setconfvalue: workspace_name: invalid "
8322 "workspace %d.", ws_id
+ 1);
8324 num_screens
= get_screen_count();
8325 for (i
= 0; i
< num_screens
; ++i
) {
8326 ws
= (struct workspace
*)&screens
[i
].ws
;
8328 if (strlen(s
) > 0) {
8329 free(ws
[ws_id
].name
);
8330 if ((ws
[ws_id
].name
= strdup(s
)) == NULL
)
8331 err(1, "setconfvalue: workspace_name.");
8333 ewmh_update_desktop_names();
8334 ewmh_get_desktop_names();
8345 setconfmodkey(const char *selector
, const char *value
, int flags
)
8347 /* suppress unused warnings since vars are needed */
8351 if (strncasecmp(value
, "Mod1", strlen("Mod1")) == 0)
8352 update_modkey(XCB_MOD_MASK_1
);
8353 else if (strncasecmp(value
, "Mod2", strlen("Mod2")) == 0)
8354 update_modkey(XCB_MOD_MASK_2
);
8355 else if (strncasecmp(value
, "Mod3", strlen("Mod3")) == 0)
8356 update_modkey(XCB_MOD_MASK_3
);
8357 else if (strncasecmp(value
, "Mod4", strlen("Mod4")) == 0)
8358 update_modkey(XCB_MOD_MASK_4
);
8359 else if (strncasecmp(value
, "Mod5", strlen("Mod5")) == 0)
8360 update_modkey(XCB_MOD_MASK_5
);
8367 setconfcolor(const char *selector
, const char *value
, int flags
)
8369 int first
, last
, i
= 0, num_screens
;
8371 num_screens
= get_screen_count();
8373 /* conf screen indices begin at 1; treat vals <= 0 as 'all screens.' */
8374 if (selector
== NULL
|| strlen(selector
) == 0 ||
8375 (last
= atoi(selector
) - 1) < 0) {
8377 last
= num_screens
- 1;
8382 if (last
>= num_screens
) {
8383 add_startup_exception("invalid screen index: %d out of bounds "
8384 "(maximum %d)", last
+ 1, num_screens
);
8388 for (i
= first
; i
<= last
; ++i
) {
8389 setscreencolor(value
, i
, flags
);
8392 * When setting focus/unfocus colors, we need to also
8393 * set maximize colors to match if they haven't been customized.
8395 if (flags
== SWM_S_COLOR_FOCUS
&&
8396 !screens
[i
].c
[SWM_S_COLOR_FOCUS_MAXIMIZED
].manual
)
8397 setscreencolor(value
, i
, SWM_S_COLOR_FOCUS_MAXIMIZED
);
8398 else if (flags
== SWM_S_COLOR_UNFOCUS
&&
8399 !screens
[i
].c
[SWM_S_COLOR_UNFOCUS_MAXIMIZED
].manual
)
8400 setscreencolor(value
, i
, SWM_S_COLOR_UNFOCUS_MAXIMIZED
);
8402 screens
[i
].c
[flags
].manual
= 1;
8409 setconfregion(const char *selector
, const char *value
, int flags
)
8411 /* suppress unused warnings since vars are needed */
8415 custom_region(value
);
8420 setautorun(const char *selector
, const char *value
, int flags
)
8430 /* suppress unused warnings since vars are needed */
8434 if (getenv("SWM_STARTED"))
8438 if (sscanf(value
, "ws[%d]:%1023c", &ws_id
, s
) != 2)
8439 errx(1, "invalid autorun entry, should be 'ws[<idx>]:command'");
8441 if (ws_id
< 0 || ws_id
>= workspace_limit
)
8442 errx(1, "autorun: invalid workspace %d", ws_id
+ 1);
8444 sp
= expand_tilde((char *)&s
);
8447 * This is a little intricate
8449 * If the pid already exists we simply reuse it because it means it was
8450 * used before AND not claimed by manage_window. We get away with
8451 * altering it in the parent after INSERT because this can not be a race
8454 while ((ap
= strsep(&sp
, " \t")) != NULL
) {
8457 DNPRINTF(SWM_D_SPAWN
, "setautorun: arg [%s]\n", ap
);
8459 if ((a
.argv
= realloc(a
.argv
, argc
* sizeof(char *))) == NULL
)
8460 err(1, "setautorun: realloc");
8461 a
.argv
[argc
- 1] = ap
;
8465 if ((a
.argv
= realloc(a
.argv
, (argc
+ 1) * sizeof(char *))) == NULL
)
8466 err(1, "setautorun: realloc");
8467 a
.argv
[argc
] = NULL
;
8469 if ((pid
= fork()) == 0) {
8470 spawn(ws_id
, &a
, true);
8479 p
= calloc(1, sizeof *p
);
8482 TAILQ_INSERT_TAIL(&pidlist
, p
, entry
);
8492 setlayout(const char *selector
, const char *value
, int flags
)
8494 struct workspace
*ws
;
8495 int ws_id
, i
, x
, mg
, ma
, si
, ar
;
8496 int st
= SWM_V_STACK
, num_screens
;
8500 /* suppress unused warnings since vars are needed */
8504 if (getenv("SWM_STARTED"))
8508 if (sscanf(value
, "ws[%d]:%d:%d:%d:%d:%1023c",
8509 &ws_id
, &mg
, &ma
, &si
, &ar
, s
) != 6)
8510 errx(1, "invalid layout entry, should be 'ws[<idx>]:"
8511 "<master_grow>:<master_add>:<stack_inc>:<always_raise>:"
8514 if (ws_id
< 0 || ws_id
>= workspace_limit
)
8515 errx(1, "layout: invalid workspace %d", ws_id
+ 1);
8517 if (strcasecmp(s
, "vertical") == 0)
8519 else if (strcasecmp(s
, "vertical_flip") == 0) {
8522 } else if (strcasecmp(s
, "horizontal") == 0)
8524 else if (strcasecmp(s
, "horizontal_flip") == 0) {
8527 } else if (strcasecmp(s
, "fullscreen") == 0)
8530 errx(1, "invalid layout entry, should be 'ws[<idx>]:"
8531 "<master_grow>:<master_add>:<stack_inc>:<always_raise>:"
8534 num_screens
= get_screen_count();
8535 for (i
= 0; i
< num_screens
; i
++) {
8536 ws
= (struct workspace
*)&screens
[i
].ws
;
8537 ws
[ws_id
].cur_layout
= &layouts
[st
];
8539 ws
[ws_id
].always_raise
= (ar
!= 0);
8540 if (st
== SWM_MAX_STACK
)
8544 for (x
= 0; x
< abs(mg
); x
++) {
8545 ws
[ws_id
].cur_layout
->l_config(&ws
[ws_id
],
8546 mg
>= 0 ? SWM_ARG_ID_MASTERGROW
:
8547 SWM_ARG_ID_MASTERSHRINK
);
8550 for (x
= 0; x
< abs(ma
); x
++) {
8551 ws
[ws_id
].cur_layout
->l_config(&ws
[ws_id
],
8552 ma
>= 0 ? SWM_ARG_ID_MASTERADD
:
8553 SWM_ARG_ID_MASTERDEL
);
8556 for (x
= 0; x
< abs(si
); x
++) {
8557 ws
[ws_id
].cur_layout
->l_config(&ws
[ws_id
],
8558 si
>= 0 ? SWM_ARG_ID_STACKINC
:
8559 SWM_ARG_ID_STACKDEC
);
8563 ws
[ws_id
].cur_layout
->l_config(&ws
[ws_id
],
8564 SWM_ARG_ID_FLIPLAYOUT
);
8571 /* config options */
8572 struct config_option
{
8574 int (*func
)(const char*, const char*, int);
8577 struct config_option configopt
[] = {
8578 { "autorun", setautorun
, 0 },
8579 { "bar_action", setconfvalue
, SWM_S_BAR_ACTION
},
8580 { "bar_at_bottom", setconfvalue
, SWM_S_BAR_AT_BOTTOM
},
8581 { "bar_border", setconfcolor
, SWM_S_COLOR_BAR_BORDER
},
8582 { "bar_border_unfocus", setconfcolor
, SWM_S_COLOR_BAR_BORDER_UNFOCUS
},
8583 { "bar_border_width", setconfvalue
, SWM_S_BAR_BORDER_WIDTH
},
8584 { "bar_color", setconfcolor
, SWM_S_COLOR_BAR
},
8585 { "bar_delay", setconfvalue
, SWM_S_BAR_DELAY
},
8586 { "bar_enabled", setconfvalue
, SWM_S_BAR_ENABLED
},
8587 { "bar_enabled_ws", setconfvalue
, SWM_S_BAR_ENABLED_WS
},
8588 { "bar_font", setconfvalue
, SWM_S_BAR_FONT
},
8589 { "bar_font_color", setconfcolor
, SWM_S_COLOR_BAR_FONT
},
8590 { "bar_format", setconfvalue
, SWM_S_BAR_FORMAT
},
8591 { "bar_justify", setconfvalue
, SWM_S_BAR_JUSTIFY
},
8592 { "bind", setconfbinding
, 0 },
8593 { "border_width", setconfvalue
, SWM_S_BORDER_WIDTH
},
8594 { "boundary_width", setconfvalue
, SWM_S_BOUNDARY_WIDTH
},
8595 { "clock_enabled", setconfvalue
, SWM_S_CLOCK_ENABLED
},
8596 { "clock_format", setconfvalue
, SWM_S_CLOCK_FORMAT
},
8597 { "color_focus", setconfcolor
, SWM_S_COLOR_FOCUS
},
8598 { "color_focus_maximized", setconfcolor
, SWM_S_COLOR_FOCUS_MAXIMIZED
},
8599 { "color_unfocus", setconfcolor
, SWM_S_COLOR_UNFOCUS
},
8600 { "color_unfocus_maximized", setconfcolor
, SWM_S_COLOR_UNFOCUS_MAXIMIZED
},
8601 { "cycle_empty", setconfvalue
, SWM_S_CYCLE_EMPTY
},
8602 { "cycle_visible", setconfvalue
, SWM_S_CYCLE_VISIBLE
},
8603 { "dialog_ratio", setconfvalue
, SWM_S_DIALOG_RATIO
},
8604 { "disable_border", setconfvalue
, SWM_S_DISABLE_BORDER
},
8605 { "focus_close", setconfvalue
, SWM_S_FOCUS_CLOSE
},
8606 { "focus_close_wrap", setconfvalue
, SWM_S_FOCUS_CLOSE_WRAP
},
8607 { "focus_default", setconfvalue
, SWM_S_FOCUS_DEFAULT
},
8608 { "focus_mode", setconfvalue
, SWM_S_FOCUS_MODE
},
8609 { "iconic_enabled", setconfvalue
, SWM_S_ICONIC_ENABLED
},
8610 { "java_workaround", setconfvalue
, SWM_S_JAVA_WORKAROUND
},
8611 { "keyboard_mapping", setkeymapping
, 0 },
8612 { "layout", setlayout
, 0 },
8613 { "maximize_hide_bar", setconfvalue
, SWM_S_MAXIMIZE_HIDE_BAR
},
8614 { "modkey", setconfmodkey
, 0 },
8615 { "program", setconfspawn
, 0 },
8616 { "quirk", setconfquirk
, 0 },
8617 { "region", setconfregion
, 0 },
8618 { "region_padding", setconfvalue
, SWM_S_REGION_PADDING
},
8619 { "screenshot_app", setconfvalue
, SWM_S_SS_APP
},
8620 { "screenshot_enabled", setconfvalue
, SWM_S_SS_ENABLED
},
8621 { "spawn_position", setconfvalue
, SWM_S_SPAWN_ORDER
},
8622 { "spawn_term", setconfvalue
, SWM_S_SPAWN_TERM
},
8623 { "stack_enabled", setconfvalue
, SWM_S_STACK_ENABLED
},
8624 { "term_width", setconfvalue
, SWM_S_TERM_WIDTH
},
8625 { "tile_gap", setconfvalue
, SWM_S_TILE_GAP
},
8626 { "title_class_enabled", setconfvalue
, SWM_S_WINDOW_CLASS_ENABLED
}, /* For backwards compat. */
8627 { "title_name_enabled", setconfvalue
, SWM_S_WINDOW_INSTANCE_ENABLED
}, /* For backwards compat. */
8628 { "urgent_collapse", setconfvalue
, SWM_S_URGENT_COLLAPSE
},
8629 { "urgent_enabled", setconfvalue
, SWM_S_URGENT_ENABLED
},
8630 { "verbose_layout", setconfvalue
, SWM_S_VERBOSE_LAYOUT
},
8631 { "warp_focus", setconfvalue
, SWM_S_WARP_FOCUS
},
8632 { "warp_pointer", setconfvalue
, SWM_S_WARP_POINTER
},
8633 { "window_class_enabled", setconfvalue
, SWM_S_WINDOW_CLASS_ENABLED
},
8634 { "window_instance_enabled", setconfvalue
, SWM_S_WINDOW_INSTANCE_ENABLED
},
8635 { "window_name_enabled", setconfvalue
, SWM_S_WINDOW_NAME_ENABLED
},
8636 { "workspace_clamp", setconfvalue
, SWM_S_WORKSPACE_CLAMP
},
8637 { "workspace_limit", setconfvalue
, SWM_S_WORKSPACE_LIMIT
},
8638 { "name", setconfvalue
, SWM_S_WORKSPACE_NAME
},
8642 _add_startup_exception(const char *fmt
, va_list ap
)
8644 if (vasprintf(&startup_exception
, fmt
, ap
) == -1)
8645 warn("%s: asprintf", __func__
);
8649 add_startup_exception(const char *fmt
, ...)
8655 if (startup_exception
)
8658 /* force bar to be enabled due to exception */
8662 _add_startup_exception(fmt
, ap
);
8667 conf_load(const char *filename
, int keymapping
)
8670 char *line
= NULL
, *cp
, *ce
, *optsub
, *optval
= NULL
;
8671 size_t linelen
, lineno
= 0;
8672 int wordlen
, i
, optidx
, count
;
8673 struct config_option
*opt
= NULL
;
8675 DNPRINTF(SWM_D_CONF
, "conf_load: begin\n");
8677 if (filename
== NULL
) {
8678 warnx("conf_load: no filename");
8682 DNPRINTF(SWM_D_CONF
, "conf_load: open %s\n", filename
);
8684 if ((config
= fopen(filename
, "r")) == NULL
) {
8685 warn("conf_load: fopen: %s", filename
);
8689 while (!feof(config
)) {
8693 if ((line
= fparseln(config
, &linelen
, &lineno
, NULL
,
8694 FPARSELN_UNESCCOMM
| FPARSELN_UNESCCONT
)) == NULL
) {
8696 err(1, "%s", filename
);
8701 cp
+= strspn(cp
, " \t\n"); /* eat whitespace */
8702 if (cp
[0] == '\0') {
8706 /* get config option */
8707 wordlen
= strcspn(cp
, "=[ \t\n");
8709 add_startup_exception("%s: line %zd: no option found",
8714 for (i
= 0; i
< LENGTH(configopt
); i
++) {
8715 opt
= &configopt
[i
];
8716 if (strncasecmp(cp
, opt
->optname
, wordlen
) == 0 &&
8717 (int)strlen(opt
->optname
) == wordlen
) {
8723 add_startup_exception("%s: line %zd: unknown option "
8724 "%.*s", filename
, lineno
, wordlen
, cp
);
8727 if (keymapping
&& opt
&& strcmp(opt
->optname
, "bind")) {
8728 add_startup_exception("%s: line %zd: invalid option "
8729 "%.*s", filename
, lineno
, wordlen
, cp
);
8733 cp
+= strspn(cp
, " \t\n"); /* eat whitespace */
8735 /* get [selector] if any */
8740 /* Get length of selector. */
8741 for (ce
= ++cp
; *ce
!= '\0'; ++ce
) {
8742 /* Find matching (not escaped) bracket. */
8743 if (*ce
== ']' && *(ce
- 1) != '\\') {
8750 add_startup_exception("%s: line %zd: syntax "
8751 "error: unterminated selector", filename
,
8756 /* ce points at ']'; terminate optsub. */
8761 cp
+= strspn(cp
, "= \t\n"); /* eat trailing */
8764 if (strlen(optval
) == 0) {
8765 add_startup_exception("%s: line %zd: must supply value "
8766 "to %s", filename
, lineno
,
8767 configopt
[optidx
].optname
);
8770 /* call function to deal with it all */
8771 if (configopt
[optidx
].func(optsub
, optval
,
8772 configopt
[optidx
].funcflags
) != 0) {
8773 add_startup_exception("%s: line %zd: invalid data for "
8774 "%s", filename
, lineno
, configopt
[optidx
].optname
);
8782 DNPRINTF(SWM_D_CONF
, "conf_load: end\n");
8788 set_child_transient(struct ws_win
*win
, xcb_window_t
*trans
)
8790 struct ws_win
*parent
, *w
;
8791 struct swm_region
*r
;
8792 struct workspace
*ws
;
8793 xcb_icccm_wm_hints_t wmh
;
8795 parent
= find_window(win
->transient
);
8797 parent
->focus_child
= win
;
8799 DNPRINTF(SWM_D_MISC
, "set_child_transient: parent doesn't exist"
8800 " for %#x trans %#x\n", win
->id
, win
->transient
);
8802 r
= root_to_region(win
->s
->root
, SWM_CK_ALL
);
8804 /* parent doen't exist in our window list */
8805 TAILQ_FOREACH(w
, &ws
->winlist
, entry
) {
8806 if (xcb_icccm_get_wm_hints_reply(conn
,
8807 xcb_icccm_get_wm_hints(conn
, w
->id
),
8809 warnx("can't get hints for %#x", w
->id
);
8813 if (win
->hints
.window_group
!= wmh
.window_group
)
8816 w
->focus_child
= win
;
8817 win
->transient
= w
->id
;
8819 DNPRINTF(SWM_D_MISC
, "set_child_transient: adjusting "
8820 "transient to %#x\n", win
->transient
);
8827 window_get_pid(xcb_window_t win
)
8832 xcb_get_property_cookie_t pc
;
8833 xcb_get_property_reply_t
*pr
;
8835 apid
= get_atom_from_string("_NET_WM_PID");
8836 if (apid
== XCB_ATOM_NONE
)
8839 pc
= xcb_get_property(conn
, 0, win
, apid
, XCB_ATOM_CARDINAL
, 0, 1);
8840 pr
= xcb_get_property_reply(conn
, pc
, NULL
);
8843 if (pr
->type
!= XCB_ATOM_CARDINAL
) {
8848 if (pr
->type
== apid
&& pr
->format
== 32)
8849 ret
= *((pid_t
*)xcb_get_property_value(pr
));
8855 apid
= get_atom_from_string("_SWM_PID");
8856 pc
= xcb_get_property(conn
, 0, win
, apid
, XCB_ATOM_STRING
,
8858 pr
= xcb_get_property_reply(conn
, pc
, NULL
);
8861 if (pr
->type
!= apid
) {
8866 ret
= (pid_t
)strtonum(xcb_get_property_value(pr
), 0, INT_MAX
, &errstr
);
8873 get_swm_ws(xcb_window_t id
)
8879 xcb_get_property_reply_t
*gpr
;
8881 gpr
= xcb_get_property_reply(conn
,
8882 xcb_get_property(conn
, 0, id
, a_swm_ws
,
8883 XCB_ATOM_STRING
, 0, SWM_PROPLEN
),
8888 proplen
= xcb_get_property_value_length(gpr
);
8890 prop
= malloc(proplen
+ 1);
8893 xcb_get_property_value(gpr
),
8895 prop
[proplen
] = '\0';
8902 DNPRINTF(SWM_D_PROP
, "get_swm_ws: _SWM_WS: %s\n", prop
);
8903 ws_idx
= (int)strtonum(prop
, 0, workspace_limit
- 1, &errstr
);
8905 DNPRINTF(SWM_D_PROP
, "get_swm_ws: win #%s: %s",
8915 get_ws_idx(struct ws_win
*win
)
8917 xcb_get_property_reply_t
*gpr
;
8923 gpr
= xcb_get_property_reply(conn
,
8924 xcb_get_property(conn
, 0, win
->id
, ewmh
[_NET_WM_DESKTOP
].atom
,
8925 XCB_ATOM_CARDINAL
, 0, 1),
8928 if (gpr
->type
== XCB_ATOM_CARDINAL
&& gpr
->format
== 32)
8929 ws_idx
= *((int *)xcb_get_property_value(gpr
));
8933 if (ws_idx
== -1 && !(win
->quirks
& SWM_Q_IGNORESPAWNWS
))
8934 ws_idx
= get_swm_ws(win
->id
);
8936 if (ws_idx
> workspace_limit
- 1 || ws_idx
< -1)
8939 DNPRINTF(SWM_D_PROP
, "get_ws_idx: win %#x, ws_idx: %d\n", win
->id
,
8946 manage_window(xcb_window_t id
, int spawn_pos
, bool mapped
)
8948 struct ws_win
*win
, *ww
;
8949 struct swm_region
*r
;
8952 xcb_get_geometry_reply_t
*gr
;
8953 xcb_window_t trans
= XCB_WINDOW_NONE
;
8954 uint32_t i
, wa
[2], new_flags
;
8955 int ws_idx
, force_ws
= -1;
8956 char *class, *instance
, *name
;
8958 if ((win
= find_window(id
)) != NULL
) {
8959 DNPRINTF(SWM_D_MISC
, "manage_window: win %#x already "
8960 "managed; skipping.)\n", id
);
8961 return (win
); /* Already managed. */
8964 /* See if window is on the unmanaged list. */
8965 if ((win
= find_unmanaged_window(id
)) != NULL
) {
8966 DNPRINTF(SWM_D_MISC
, "manage_window: win %#x found on "
8967 "unmanaged list.\n", id
);
8968 TAILQ_REMOVE(&win
->ws
->unmanagedlist
, win
, entry
);
8971 set_child_transient(win
, &trans
);
8975 DNPRINTF(SWM_D_MISC
, "manage_window: win %#x is new.\n", id
);
8978 /* Try to get initial window geometry. */
8979 gr
= xcb_get_geometry_reply(conn
, xcb_get_geometry(conn
, id
), NULL
);
8981 DNPRINTF(SWM_D_MISC
, "manage_window: get geometry failed.\n");
8985 /* Create and initialize ws_win object. */
8986 if ((win
= calloc(1, sizeof(struct ws_win
))) == NULL
)
8987 err(1, "manage_window: calloc: failed to allocate memory for "
8992 /* Figureout which region the window belongs to. */
8993 r
= root_to_region(gr
->root
, SWM_CK_ALL
);
8995 /* Ignore window border if there is one. */
8996 WIDTH(win
) = gr
->width
;
8997 HEIGHT(win
) = gr
->height
;
8998 X(win
) = gr
->x
+ gr
->border_width
- border_width
;
8999 Y(win
) = gr
->y
+ gr
->border_width
- border_width
;
9000 win
->bordered
= true;
9001 win
->mapped
= mapped
;
9002 win
->s
= r
->s
; /* this never changes */
9006 /* Select which X events to monitor and set border pixel color. */
9007 wa
[0] = win
->s
->c
[SWM_S_COLOR_UNFOCUS
].pixel
;
9008 wa
[1] = XCB_EVENT_MASK_ENTER_WINDOW
| XCB_EVENT_MASK_PROPERTY_CHANGE
|
9009 XCB_EVENT_MASK_STRUCTURE_NOTIFY
;
9011 wa
[1] |= XCB_EVENT_MASK_LEAVE_WINDOW
| XCB_EVENT_MASK_FOCUS_CHANGE
;
9014 xcb_change_window_attributes(conn
, win
->id
, XCB_CW_BORDER_PIXEL
|
9015 XCB_CW_EVENT_MASK
, wa
);
9017 /* Get WM_SIZE_HINTS. */
9018 xcb_icccm_get_wm_normal_hints_reply(conn
,
9019 xcb_icccm_get_wm_normal_hints(conn
, win
->id
),
9023 xcb_icccm_get_wm_hints_reply(conn
,
9024 xcb_icccm_get_wm_hints(conn
, win
->id
),
9027 /* Get WM_TRANSIENT_FOR; see if window is a transient. */
9028 xcb_icccm_get_wm_transient_for_reply(conn
,
9029 xcb_icccm_get_wm_transient_for(conn
, win
->id
),
9032 win
->transient
= trans
;
9033 set_child_transient(win
, &win
->transient
);
9036 /* Get WM_PROTOCOLS. */
9037 get_wm_protocols(win
);
9039 /* Set initial quirks based on EWMH. */
9040 ewmh_autoquirk(win
);
9042 /* Determine initial quirks. */
9043 xcb_icccm_get_wm_class_reply(conn
,
9044 xcb_icccm_get_wm_class(conn
, win
->id
),
9047 class = win
->ch
.class_name
? win
->ch
.class_name
: "";
9048 instance
= win
->ch
.instance_name
? win
->ch
.instance_name
: "";
9049 name
= get_win_name(win
->id
);
9051 DNPRINTF(SWM_D_CLASS
, "manage_window: class: %s, instance: %s, "
9052 "name: %s\n", class, instance
, name
);
9054 /* java is retarded so treat it special */
9055 if (strstr(instance
, "sun-awt")) {
9056 DNPRINTF(SWM_D_CLASS
, "manage_window: java window detected.\n");
9060 TAILQ_FOREACH(qp
, &quirks
, entry
) {
9061 if (regexec(&qp
->regex_class
, class, 0, NULL
, 0) == 0 &&
9062 regexec(&qp
->regex_instance
, instance
, 0, NULL
, 0) == 0 &&
9063 regexec(&qp
->regex_name
, name
, 0, NULL
, 0) == 0) {
9064 DNPRINTF(SWM_D_CLASS
, "manage_window: matched "
9065 "quirk: %s:%s:%s mask: %#x, ws: %d\n", qp
->class,
9066 qp
->instance
, qp
->name
, qp
->quirk
, qp
->ws
);
9067 win
->quirks
= qp
->quirk
;
9068 if (qp
->ws
>= 0 && qp
->ws
< workspace_limit
)
9075 /* Reset font sizes (the bruteforce way; no default keybinding). */
9076 if (win
->quirks
& SWM_Q_XTERM_FONTADJ
) {
9077 for (i
= 0; i
< SWM_MAX_FONT_STEPS
; i
++)
9078 fake_keypress(win
, XK_KP_Subtract
, XCB_MOD_MASK_SHIFT
);
9079 for (i
= 0; i
< SWM_MAX_FONT_STEPS
; i
++)
9080 fake_keypress(win
, XK_KP_Add
, XCB_MOD_MASK_SHIFT
);
9083 /* Figure out which workspace the window belongs to. */
9084 if (!(win
->quirks
& SWM_Q_IGNOREPID
) &&
9085 (p
= find_pid(window_get_pid(win
->id
))) != NULL
) {
9086 win
->ws
= &r
->s
->ws
[p
->ws
];
9087 TAILQ_REMOVE(&pidlist
, p
, entry
);
9090 } else if ((ws_idx
= get_ws_idx(win
)) != -1 &&
9092 /* _SWM_WS is set; use that. */
9093 win
->ws
= &r
->s
->ws
[ws_idx
];
9094 } else if (trans
&& (ww
= find_window(trans
)) != NULL
) {
9095 /* Launch transients in the same ws as parent. */
9102 win
->ws
= &r
->s
->ws
[force_ws
];
9104 /* Set the _NET_WM_DESKTOP atom. */
9105 DNPRINTF(SWM_D_PROP
, "manage_window: set _NET_WM_DESKTOP: %d\n",
9107 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
,
9108 ewmh
[_NET_WM_DESKTOP
].atom
, XCB_ATOM_CARDINAL
, 32, 1, &win
->ws
->idx
);
9110 /* Remove any _SWM_WS now that we set _NET_WM_DESKTOP. */
9111 xcb_delete_property(conn
, win
->id
, a_swm_ws
);
9113 /* WS must already be set for this to work. */
9114 store_float_geom(win
);
9116 /* Make sure window is positioned inside its region, if its active. */
9118 region_containment(win
, r
, SWM_CW_ALLSIDES
|
9119 SWM_CW_HARDBOUNDARY
);
9124 /* Figure out where to insert the window in the workspace list. */
9125 if (trans
&& (ww
= find_window(trans
)))
9126 TAILQ_INSERT_AFTER(&win
->ws
->winlist
, ww
, win
, entry
);
9127 else if (win
->ws
->focus
&& spawn_pos
== SWM_STACK_ABOVE
)
9128 TAILQ_INSERT_AFTER(&win
->ws
->winlist
, win
->ws
->focus
, win
,
9130 else if (win
->ws
->focus
&& spawn_pos
== SWM_STACK_BELOW
)
9131 TAILQ_INSERT_BEFORE(win
->ws
->focus
, win
, entry
);
9132 else switch (spawn_pos
) {
9135 case SWM_STACK_ABOVE
:
9136 TAILQ_INSERT_TAIL(&win
->ws
->winlist
, win
, entry
);
9138 case SWM_STACK_BOTTOM
:
9139 case SWM_STACK_BELOW
:
9140 TAILQ_INSERT_HEAD(&win
->ws
->winlist
, win
, entry
);
9143 ewmh_update_client_list();
9145 TAILQ_INSERT_HEAD(&win
->ws
->stack
, win
, stack_entry
);
9148 /* Get/apply initial _NET_WM_STATE */
9149 ewmh_get_wm_state(win
);
9152 new_flags
= win
->ewmh_flags
;
9154 if (win
->quirks
& SWM_Q_FLOAT
)
9155 new_flags
|= EWMH_F_ABOVE
;
9157 if (win
->quirks
& SWM_Q_ANYWHERE
)
9158 new_flags
|= SWM_F_MANUAL
;
9160 ewmh_apply_flags(win
, new_flags
);
9161 ewmh_update_wm_state(win
);
9163 /* Set initial _NET_WM_ALLOWED_ACTIONS */
9164 ewmh_update_actions(win
);
9168 DNPRINTF(SWM_D_MISC
, "manage_window: done. win %#x, (x,y) w x h: "
9169 "(%d,%d) %d x %d, ws: %d, iconic: %s, transient: %#x\n", win
->id
,
9170 X(win
), Y(win
), WIDTH(win
), HEIGHT(win
), win
->ws
->idx
,
9171 YESNO(ICONIC(win
)), win
->transient
);
9177 free_window(struct ws_win
*win
)
9179 DNPRINTF(SWM_D_MISC
, "free_window: win %#x\n", win
->id
);
9184 TAILQ_REMOVE(&win
->ws
->unmanagedlist
, win
, entry
);
9186 xcb_icccm_get_wm_class_reply_wipe(&win
->ch
);
9191 memset(win
, 0xff, sizeof *win
); /* XXX kill later */
9194 DNPRINTF(SWM_D_MISC
, "free_window: done.\n");
9198 unmanage_window(struct ws_win
*win
)
9200 struct ws_win
*parent
;
9205 DNPRINTF(SWM_D_MISC
, "unmanage_window: win %#x\n", win
->id
);
9208 parent
= find_window(win
->transient
);
9210 parent
->focus_child
= NULL
;
9213 TAILQ_REMOVE(&win
->ws
->stack
, win
, stack_entry
);
9214 TAILQ_REMOVE(&win
->ws
->winlist
, win
, entry
);
9215 TAILQ_INSERT_TAIL(&win
->ws
->unmanagedlist
, win
, entry
);
9217 ewmh_update_client_list();
9221 expose(xcb_expose_event_t
*e
)
9224 struct swm_region
*r
;
9226 DNPRINTF(SWM_D_EVENT
, "expose: win %#x\n", e
->window
);
9228 num_screens
= get_screen_count();
9229 for (i
= 0; i
< num_screens
; i
++)
9230 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
9231 if (e
->window
== WINID(r
->bar
))
9239 focusin(xcb_focus_in_event_t
*e
)
9241 DNPRINTF(SWM_D_EVENT
, "focusin: win %#x, mode: %s(%u), "
9242 "detail: %s(%u)\n", e
->event
, get_notify_mode_label(e
->mode
),
9243 e
->mode
, get_notify_detail_label(e
->detail
), e
->detail
);
9247 focusout(xcb_focus_out_event_t
*e
)
9249 DNPRINTF(SWM_D_EVENT
, "focusout: win %#x, mode: %s(%u), "
9250 "detail: %s(%u)\n", e
->event
, get_notify_mode_label(e
->mode
),
9251 e
->mode
, get_notify_detail_label(e
->detail
), e
->detail
);
9256 keypress(xcb_key_press_event_t
*e
)
9258 xcb_keysym_t keysym
;
9261 keysym
= xcb_key_press_lookup_keysym(syms
, e
, 0);
9263 DNPRINTF(SWM_D_EVENT
, "keypress: keysym: %u, win (x,y): %#x (%d,%d), "
9264 "detail: %u, time: %u, root (x,y): %#x (%d,%d), child: %#x, "
9265 "state: %u, same_screen: %s\n", keysym
, e
->event
, e
->event_x
,
9266 e
->event_y
, e
->detail
, e
->time
, e
->root
, e
->root_x
, e
->root_y
,
9267 e
->child
, e
->state
, YESNO(e
->same_screen
));
9269 if ((kp
= key_lookup(CLEANMASK(e
->state
), keysym
)) == NULL
)
9272 last_event_time
= e
->time
;
9274 if (kp
->funcid
== KF_SPAWN_CUSTOM
)
9275 spawn_custom(root_to_region(e
->root
, SWM_CK_ALL
),
9276 &(keyfuncs
[kp
->funcid
].args
), kp
->spawn_name
);
9277 else if (keyfuncs
[kp
->funcid
].func
)
9278 keyfuncs
[kp
->funcid
].func(root_to_region(e
->root
, SWM_CK_ALL
),
9279 &(keyfuncs
[kp
->funcid
].args
));
9282 /* Unfreeze grab events. */
9283 xcb_allow_events(conn
, XCB_ALLOW_ASYNC_KEYBOARD
, e
->time
);
9286 DNPRINTF(SWM_D_EVENT
, "keypress: done.\n");
9290 buttonpress(xcb_button_press_event_t
*e
)
9292 struct ws_win
*win
= NULL
;
9293 struct swm_region
*r
, *old_r
;
9295 bool handled
= false;
9297 DNPRINTF(SWM_D_EVENT
, "buttonpress: win (x,y): %#x (%d,%d), "
9298 "detail: %u, time: %u, root (x,y): %#x (%d,%d), child: %#x, "
9299 "state: %u, same_screen: %s\n", e
->event
, e
->event_x
, e
->event_y
,
9300 e
->detail
, e
->time
, e
->root
, e
->root_x
, e
->root_y
, e
->child
,
9301 e
->state
, YESNO(e
->same_screen
));
9303 if (e
->event
== e
->root
) {
9304 if (e
->child
!= 0) {
9305 win
= find_window(e
->child
);
9306 /* Pass ButtonPress to window if it isn't managed. */
9310 /* Focus on empty region */
9311 /* If no windows on region if its empty. */
9312 r
= root_to_region(e
->root
, SWM_CK_POINTER
);
9314 DNPRINTF(SWM_D_EVENT
, "buttonpress: "
9315 "NULL region; ignoring.\n");
9319 if (TAILQ_EMPTY(&r
->ws
->winlist
)) {
9320 old_r
= root_to_region(e
->root
, SWM_CK_FOCUS
);
9321 if (old_r
&& old_r
!= r
)
9322 unfocus_win(old_r
->ws
->focus
);
9324 xcb_set_input_focus(conn
,
9325 XCB_INPUT_FOCUS_PARENT
, e
->root
, e
->time
);
9327 /* Clear bar since empty. */
9335 win
= find_window(e
->event
);
9341 last_event_time
= e
->time
;
9343 focus_win(get_focus_magic(win
));
9345 for (i
= 0; i
< LENGTH(buttons
); i
++)
9346 if (client_click
== buttons
[i
].action
&& buttons
[i
].func
&&
9347 buttons
[i
].button
== e
->detail
&&
9348 CLEANMASK(buttons
[i
].mask
) == CLEANMASK(e
->state
)) {
9349 buttons
[i
].func(win
, &buttons
[i
].args
);
9355 DNPRINTF(SWM_D_EVENT
, "buttonpress: passing to window.\n");
9356 /* Replay event to event window */
9357 xcb_allow_events(conn
, XCB_ALLOW_REPLAY_POINTER
, e
->time
);
9359 DNPRINTF(SWM_D_EVENT
, "buttonpress: handled.\n");
9360 /* Unfreeze grab events. */
9361 xcb_allow_events(conn
, XCB_ALLOW_SYNC_POINTER
, e
->time
);
9369 print_win_geom(xcb_window_t w
)
9371 xcb_get_geometry_reply_t
*wa
;
9373 wa
= xcb_get_geometry_reply(conn
, xcb_get_geometry(conn
, w
), NULL
);
9375 DNPRINTF(SWM_D_MISC
, "print_win_geom: window not found: %#x\n",
9380 DNPRINTF(SWM_D_MISC
, "print_win_geom: win %#x, root: %#x, "
9381 "depth: %u, (x,y) w x h: (%d,%d) %d x %d, border: %d\n",
9382 w
, wa
->root
, wa
->depth
, wa
->x
, wa
->y
, wa
->width
, wa
->height
,
9391 get_stack_mode_name(uint8_t mode
)
9396 case XCB_STACK_MODE_ABOVE
:
9399 case XCB_STACK_MODE_BELOW
:
9402 case XCB_STACK_MODE_TOP_IF
:
9405 case XCB_STACK_MODE_BOTTOM_IF
:
9408 case XCB_STACK_MODE_OPPOSITE
:
9420 configurerequest(xcb_configure_request_event_t
*e
)
9423 struct swm_region
*r
= NULL
;
9425 uint32_t wc
[7] = {0};
9429 if ((win
= find_window(e
->window
)) == NULL
)
9430 if ((win
= find_unmanaged_window(e
->window
)) == NULL
)
9434 if (swm_debug
& SWM_D_EVENT
) {
9435 print_win_geom(e
->window
);
9437 DNPRINTF(SWM_D_EVENT
, "configurerequest: win %#x, "
9438 "parent: %#x, new: %s, value_mask: %u { ", e
->window
,
9439 e
->parent
, YESNO(new), e
->value_mask
);
9440 if (e
->value_mask
& XCB_CONFIG_WINDOW_X
)
9441 DPRINTF("X: %d ", e
->x
);
9442 if (e
->value_mask
& XCB_CONFIG_WINDOW_Y
)
9443 DPRINTF("Y: %d ", e
->y
);
9444 if (e
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
9445 DPRINTF("W: %u ", e
->width
);
9446 if (e
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
9447 DPRINTF("H: %u ", e
->height
);
9448 if (e
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
9449 DPRINTF("Border: %u ", e
->border_width
);
9450 if (e
->value_mask
& XCB_CONFIG_WINDOW_SIBLING
)
9451 DPRINTF("Sibling: %#x ", e
->sibling
);
9452 if (e
->value_mask
& XCB_CONFIG_WINDOW_STACK_MODE
)
9453 DPRINTF("StackMode: %s(%u) ",
9454 get_stack_mode_name(e
->stack_mode
), e
->stack_mode
);
9460 if (e
->value_mask
& XCB_CONFIG_WINDOW_X
) {
9461 mask
|= XCB_CONFIG_WINDOW_X
;
9464 if (e
->value_mask
& XCB_CONFIG_WINDOW_Y
) {
9465 mask
|= XCB_CONFIG_WINDOW_Y
;
9468 if (e
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
) {
9469 mask
|= XCB_CONFIG_WINDOW_WIDTH
;
9472 if (e
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
) {
9473 mask
|= XCB_CONFIG_WINDOW_HEIGHT
;
9474 wc
[i
++] = e
->height
;
9476 if (e
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
) {
9477 mask
|= XCB_CONFIG_WINDOW_BORDER_WIDTH
;
9478 wc
[i
++] = e
->border_width
;
9480 if (e
->value_mask
& XCB_CONFIG_WINDOW_SIBLING
) {
9481 mask
|= XCB_CONFIG_WINDOW_SIBLING
;
9482 wc
[i
++] = e
->sibling
;
9484 if (e
->value_mask
& XCB_CONFIG_WINDOW_STACK_MODE
) {
9485 mask
|= XCB_CONFIG_WINDOW_STACK_MODE
;
9486 wc
[i
++] = e
->stack_mode
;
9490 xcb_configure_window(conn
, e
->window
, mask
, wc
);
9493 } else if ((!MANUAL(win
) || win
->quirks
& SWM_Q_ANYWHERE
) &&
9494 !FULLSCREEN(win
) && !MAXIMIZED(win
)) {
9497 else if (win
->ws
->old_r
)
9500 /* windows are centered unless ANYWHERE quirk is set. */
9501 if (win
->quirks
& SWM_Q_ANYWHERE
) {
9502 if (e
->value_mask
& XCB_CONFIG_WINDOW_X
) {
9503 win
->g_float
.x
= e
->x
;
9505 win
->g_float
.x
-= X(r
);
9508 if (e
->value_mask
& XCB_CONFIG_WINDOW_Y
) {
9509 win
->g_float
.y
= e
->y
;
9511 win
->g_float
.y
-= Y(r
);
9515 if (e
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
9516 win
->g_float
.w
= e
->width
;
9518 if (e
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
9519 win
->g_float
.h
= e
->height
;
9521 win
->g_floatvalid
= true;
9523 if (!MAXIMIZED(win
) && !FULLSCREEN(win
) &&
9524 (TRANS(win
) || (ABOVE(win
) &&
9525 win
->ws
->cur_layout
!= &layouts
[SWM_MAX_STACK
]))) {
9526 WIDTH(win
) = win
->g_float
.w
;
9527 HEIGHT(win
) = win
->g_float
.h
;
9530 update_floater(win
);
9545 DNPRINTF(SWM_D_EVENT
, "configurerequest: done.\n");
9549 configurenotify(xcb_configure_notify_event_t
*e
)
9553 DNPRINTF(SWM_D_EVENT
, "configurenotify: win %#x, event win: %#x, "
9554 "(x,y) WxH: (%d,%d) %ux%u, border: %u, above_sibling: %#x, "
9555 "override_redirect: %s\n", e
->window
, e
->event
, e
->x
, e
->y
,
9556 e
->width
, e
->height
, e
->border_width
, e
->above_sibling
,
9557 YESNO(e
->override_redirect
));
9559 win
= find_window(e
->window
);
9561 xcb_icccm_get_wm_normal_hints_reply(conn
,
9562 xcb_icccm_get_wm_normal_hints(conn
, win
->id
),
9565 if (font_adjusted
) {
9573 destroynotify(xcb_destroy_notify_event_t
*e
)
9577 DNPRINTF(SWM_D_EVENT
, "destroynotify: win %#x\n", e
->window
);
9579 if ((win
= find_window(e
->window
)) == NULL
) {
9580 if ((win
= find_unmanaged_window(e
->window
)) == NULL
)
9586 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
9587 /* If we were focused, make sure we focus on something else. */
9588 if (win
== win
->ws
->focus
)
9589 win
->ws
->focus_pending
= get_focus_prev(win
);
9592 unmanage_window(win
);
9595 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& WS_FOCUSED(win
->ws
)) {
9596 if (win
->ws
->focus_pending
) {
9597 focus_win(win
->ws
->focus_pending
);
9598 win
->ws
->focus_pending
= NULL
;
9599 } else if (win
== win
->ws
->focus
) {
9600 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
,
9601 win
->ws
->r
->id
, XCB_CURRENT_TIME
);
9612 get_notify_detail_label(uint8_t detail
)
9617 case XCB_NOTIFY_DETAIL_ANCESTOR
:
9620 case XCB_NOTIFY_DETAIL_VIRTUAL
:
9623 case XCB_NOTIFY_DETAIL_INFERIOR
:
9626 case XCB_NOTIFY_DETAIL_NONLINEAR
:
9627 label
= "Nonlinear";
9629 case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL
:
9630 label
= "NonlinearVirtual";
9632 case XCB_NOTIFY_DETAIL_POINTER
:
9635 case XCB_NOTIFY_DETAIL_POINTER_ROOT
:
9636 label
= "PointerRoot";
9638 case XCB_NOTIFY_DETAIL_NONE
:
9649 get_notify_mode_label(uint8_t mode
)
9654 case XCB_NOTIFY_MODE_NORMAL
:
9657 case XCB_NOTIFY_MODE_GRAB
:
9660 case XCB_NOTIFY_MODE_UNGRAB
:
9663 case XCB_NOTIFY_MODE_WHILE_GRABBED
:
9664 label
= "WhileGrabbed";
9675 enternotify(xcb_enter_notify_event_t
*e
)
9678 struct swm_region
*r
;
9680 DNPRINTF(SWM_D_FOCUS
, "enternotify: time: %u, win (x,y): %#x "
9681 "(%d,%d), mode: %s(%d), detail: %s(%d), root (x,y): %#x (%d,%d), "
9682 "child: %#x, same_screen_focus: %s, state: %d\n",
9683 e
->time
, e
->event
, e
->event_x
, e
->event_y
,
9684 get_notify_mode_label(e
->mode
), e
->mode
,
9685 get_notify_detail_label(e
->detail
), e
->detail
,
9686 e
->root
, e
->root_x
, e
->root_y
, e
->child
,
9687 YESNO(e
->same_screen_focus
), e
->state
);
9689 if (focus_mode
== SWM_FOCUS_MANUAL
&&
9690 e
->mode
== XCB_NOTIFY_MODE_NORMAL
) {
9691 DNPRINTF(SWM_D_EVENT
, "enternotify: manual focus; ignoring.\n");
9695 if (focus_mode
!= SWM_FOCUS_FOLLOW
&&
9696 e
->mode
== XCB_NOTIFY_MODE_UNGRAB
) {
9697 DNPRINTF(SWM_D_EVENT
, "enternotify: ungrab; ignoring.\n");
9701 last_event_time
= e
->time
;
9703 if ((win
= find_window(e
->event
)) == NULL
) {
9704 if (e
->event
== e
->root
) {
9705 /* If no windows on pointer region, then focus root. */
9706 r
= root_to_region(e
->root
, SWM_CK_POINTER
);
9708 DNPRINTF(SWM_D_EVENT
, "enternotify: "
9709 "NULL region; ignoring.\n");
9715 DNPRINTF(SWM_D_EVENT
, "enternotify: window is NULL; "
9720 if (e
->mode
== XCB_NOTIFY_MODE_NORMAL
&&
9721 e
->detail
== XCB_NOTIFY_DETAIL_INFERIOR
) {
9722 DNPRINTF(SWM_D_EVENT
, "enternotify: entering from "
9723 "inferior; ignoring\n");
9727 focus_win(get_focus_magic(win
));
9735 leavenotify(xcb_leave_notify_event_t
*e
)
9737 DNPRINTF(SWM_D_FOCUS
, "leavenotify: time: %u, win (x,y): %#x "
9738 "(%d,%d), mode: %s(%d), detail: %s(%d), root (x,y): %#x (%d,%d), "
9739 "child: %#x, same_screen_focus: %s, state: %d\n",
9740 e
->time
, e
->event
, e
->event_x
, e
->event_y
,
9741 get_notify_mode_label(e
->mode
), e
->mode
,
9742 get_notify_detail_label(e
->detail
), e
->detail
,
9743 e
->root
, e
->root_x
, e
->root_y
, e
->child
,
9744 YESNO(e
->same_screen_focus
), e
->state
);
9749 mapnotify(xcb_map_notify_event_t
*e
)
9751 struct ws_win
*win
, *parent
= NULL
;
9752 struct workspace
*ws
;
9754 DNPRINTF(SWM_D_EVENT
, "mapnotify: win %#x\n", e
->window
);
9756 if ((win
= manage_window(e
->window
, spawn_position
, true)) == NULL
)
9760 /* Need to know if win was mapped due to ws switch. */
9761 if (ws
->state
== SWM_WS_STATE_MAPPED
) {
9762 if (ws
->focus_pending
&& TRANS(ws
->focus_pending
))
9763 parent
= find_window(win
->transient
);
9765 /* If window's parent is maximized, don't clear it. */
9766 if ((parent
== NULL
) || !MAXIMIZED(parent
))
9767 if (clear_maximized(ws
) > 0)
9772 set_win_state(win
, XCB_ICCCM_WM_STATE_NORMAL
);
9774 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& WS_FOCUSED(win
->ws
)) {
9775 if (ws
->focus_pending
== win
) {
9777 ws
->focus_pending
= NULL
;
9778 center_pointer(win
->ws
->r
);
9787 mappingnotify(xcb_mapping_notify_event_t
*e
)
9790 int i
, j
, num_screens
;
9792 xcb_refresh_keyboard_mapping(syms
, e
);
9794 if (e
->request
== XCB_MAPPING_KEYBOARD
) {
9797 /* Regrab buttons on all managed windows. */
9798 num_screens
= get_screen_count();
9799 for (i
= 0; i
< num_screens
; i
++)
9800 for (j
= 0; j
< workspace_limit
; j
++)
9801 TAILQ_FOREACH(w
, &screens
[i
].ws
[j
].winlist
,
9808 maprequest(xcb_map_request_event_t
*e
)
9810 struct ws_win
*win
, *w
= NULL
;
9811 xcb_get_window_attributes_reply_t
*war
;
9813 DNPRINTF(SWM_D_EVENT
, "maprequest: win %#x\n",
9816 war
= xcb_get_window_attributes_reply(conn
,
9817 xcb_get_window_attributes(conn
, e
->window
),
9820 DNPRINTF(SWM_D_EVENT
, "maprequest: window lost.\n");
9824 if (war
->override_redirect
) {
9825 DNPRINTF(SWM_D_EVENT
, "maprequest: override_redirect; "
9830 win
= manage_window(e
->window
, spawn_position
,
9831 (war
->map_state
== XCB_MAP_STATE_VIEWABLE
));
9835 /* The new window should get focus; prepare. */
9836 if (focus_mode
!= SWM_FOCUS_FOLLOW
&&
9837 !(win
->quirks
& SWM_Q_NOFOCUSONMAP
) &&
9838 (!(win
->hints
.flags
& XCB_ICCCM_WM_HINT_INPUT
) ||
9839 (win
->hints
.flags
& XCB_ICCCM_WM_HINT_INPUT
&&
9840 win
->hints
.input
))) {
9841 if (win
->quirks
& SWM_Q_FOCUSONMAP_SINGLE
) {
9842 /* See if other wins of same type are already mapped. */
9843 TAILQ_FOREACH(w
, &win
->ws
->winlist
, entry
) {
9844 if (w
== win
|| !w
->mapped
)
9847 if (w
->ch
.class_name
&&
9848 win
->ch
.class_name
&&
9849 strcmp(w
->ch
.class_name
,
9850 win
->ch
.class_name
) == 0 &&
9851 w
->ch
.instance_name
&&
9852 win
->ch
.instance_name
&&
9853 strcmp(w
->ch
.instance_name
,
9854 win
->ch
.instance_name
) == 0)
9860 win
->ws
->focus_pending
= get_focus_magic(win
);
9863 /* All windows need to be mapped if they are in the current workspace.*/
9867 /* Ignore EnterNotify to handle the mapnotify without interference. */
9868 if (focus_mode
== SWM_FOCUS_DEFAULT
)
9869 event_drain(XCB_ENTER_NOTIFY
);
9872 DNPRINTF(SWM_D_EVENT
, "maprequest: done.\n");
9876 motionnotify(xcb_motion_notify_event_t
*e
)
9878 struct swm_region
*r
= NULL
;
9881 DNPRINTF(SWM_D_FOCUS
, "motionnotify: time: %u, win (x,y): %#x "
9882 "(%d,%d), detail: %s(%d), root (x,y): %#x (%d,%d), "
9883 "child: %#x, same_screen_focus: %s, state: %d\n",
9884 e
->time
, e
->event
, e
->event_x
, e
->event_y
,
9885 get_notify_detail_label(e
->detail
), e
->detail
,
9886 e
->root
, e
->root_x
, e
->root_y
, e
->child
,
9887 YESNO(e
->same_screen
), e
->state
);
9889 last_event_time
= e
->time
;
9891 if (focus_mode
== SWM_FOCUS_MANUAL
)
9894 num_screens
= get_screen_count();
9895 for (i
= 0; i
< num_screens
; i
++)
9896 if (screens
[i
].root
== e
->root
)
9899 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
9900 if (X(r
) <= e
->root_x
&& e
->root_x
< MAX_X(r
) &&
9901 Y(r
) <= e
->root_y
&& e
->root_y
< MAX_Y(r
))
9909 get_atom_name(xcb_atom_t atom
)
9912 #ifdef SWM_DEBUG_ATOM_NAMES
9914 * This should be disabled during most debugging since
9915 * xcb_get_* causes an xcb_flush.
9918 xcb_get_atom_name_reply_t
*r
;
9920 r
= xcb_get_atom_name_reply(conn
,
9921 xcb_get_atom_name(conn
, atom
),
9924 len
= xcb_get_atom_name_name_length(r
);
9926 name
= malloc(len
+ 1);
9928 memcpy(name
, xcb_get_atom_name_name(r
), len
);
9942 propertynotify(xcb_property_notify_event_t
*e
)
9945 struct workspace
*ws
;
9949 name
= get_atom_name(e
->atom
);
9950 DNPRINTF(SWM_D_EVENT
, "propertynotify: win %#x, atom: %s(%u), "
9951 "time: %#x, state: %u\n", e
->window
, name
, e
->atom
, e
->time
,
9955 win
= find_window(e
->window
);
9961 last_event_time
= e
->time
;
9963 if (e
->atom
== a_state
) {
9964 /* State just changed, make sure it gets focused if mapped. */
9965 if (e
->state
== XCB_PROPERTY_NEW_VALUE
) {
9966 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& WS_FOCUSED(ws
)) {
9968 ws
->focus_pending
== win
) {
9969 focus_win(ws
->focus_pending
);
9970 ws
->focus_pending
= NULL
;
9974 } else if (e
->atom
== XCB_ATOM_WM_CLASS
||
9975 e
->atom
== XCB_ATOM_WM_NAME
) {
9977 } else if (e
->atom
== a_prot
) {
9978 get_wm_protocols(win
);
9985 unmapnotify(xcb_unmap_notify_event_t
*e
)
9988 struct workspace
*ws
;
9990 DNPRINTF(SWM_D_EVENT
, "unmapnotify: win %#x\n", e
->window
);
9992 /* If we aren't managing the window, then ignore. */
9993 win
= find_window(e
->window
);
9994 if (win
== NULL
|| win
->id
!= e
->window
)
9997 /* Do nothing if already withdrawn. */
9998 if (!win
->mapped
&& !ICONIC(win
))
10002 win
->mapped
= false;
10004 /* If win was focused, make sure to focus on something else. */
10005 if (win
== ws
->focus
) {
10006 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
10007 ws
->focus_pending
= get_focus_prev(win
);
10008 DNPRINTF(SWM_D_EVENT
, "unmapnotify: "
10009 "focus_pending: %#x\n",
10010 WINID(ws
->focus_pending
));
10018 set_win_state(win
, XCB_ICCCM_WM_STATE_ICONIC
);
10021 set_win_state(win
, XCB_ICCCM_WM_STATE_WITHDRAWN
);
10022 unmanage_window(win
);
10028 /* Update focus if ws is active. */
10029 if (WS_FOCUSED(ws
)) {
10030 if (focus_mode
== SWM_FOCUS_FOLLOW
) {
10031 focus_win(get_pointer_win(ws
->r
->s
->root
));
10032 } else if (ws
->focus_pending
) {
10033 focus_win(ws
->focus_pending
);
10034 ws
->focus_pending
= NULL
;
10035 } else if (ws
->focus
== NULL
) {
10036 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
,
10037 ws
->r
->id
, XCB_CURRENT_TIME
);
10041 center_pointer(ws
->r
);
10047 get_source_type_label(uint32_t type
)
10052 case EWMH_SOURCE_TYPE_NONE
:
10055 case EWMH_SOURCE_TYPE_NORMAL
:
10058 case EWMH_SOURCE_TYPE_OTHER
:
10070 clientmessage(xcb_client_message_event_t
*e
)
10072 struct ws_win
*win
;
10073 struct swm_region
*r
= NULL
;
10076 int num_screens
, i
;
10077 xcb_map_request_event_t mre
;
10081 name
= get_atom_name(e
->type
);
10082 DNPRINTF(SWM_D_EVENT
, "clientmessage: win %#x, atom: %s(%u)\n",
10083 e
->window
, name
, e
->type
);
10087 if (e
->type
== ewmh
[_NET_CURRENT_DESKTOP
].atom
) {
10088 num_screens
= get_screen_count();
10089 for (i
= 0; i
< num_screens
; i
++)
10090 if (screens
[i
].root
== e
->window
) {
10091 r
= screens
[i
].r_focus
;
10095 if (r
&& e
->data
.data32
[0] < (uint32_t)workspace_limit
) {
10096 a
.id
= e
->data
.data32
[0];
10104 win
= find_window(e
->window
);
10106 if (e
->type
== ewmh
[_NET_ACTIVE_WINDOW
].atom
) {
10107 /* Manage the window with maprequest. */
10108 DNPRINTF(SWM_D_EVENT
, "clientmessage: request focus on "
10109 "unmanaged window.\n");
10110 mre
.window
= e
->window
;
10116 if (e
->type
== ewmh
[_NET_ACTIVE_WINDOW
].atom
) {
10117 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_ACTIVE_WINDOW, "
10118 "source_type: %s(%d)\n",
10119 get_source_type_label(e
->data
.data32
[0]),
10120 e
->data
.data32
[0]);
10123 * Allow focus changes that are a result of direct user
10124 * action and from applications that use the old EWMH spec.
10126 if (e
->data
.data32
[0] != EWMH_SOURCE_TYPE_NORMAL
||
10127 win
->quirks
& SWM_Q_OBEYAPPFOCUSREQ
) {
10128 if (WS_FOCUSED(win
->ws
))
10131 win
->ws
->focus_pending
= win
;
10133 } else if (e
->type
== ewmh
[_NET_CLOSE_WINDOW
].atom
) {
10134 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_CLOSE_WINDOW\n");
10135 if (win
->can_delete
)
10136 client_msg(win
, a_delete
, 0);
10138 xcb_kill_client(conn
, win
->id
);
10139 } else if (e
->type
== ewmh
[_NET_MOVERESIZE_WINDOW
].atom
) {
10140 DNPRINTF(SWM_D_EVENT
,
10141 "clientmessage: _NET_MOVERESIZE_WINDOW\n");
10143 if (e
->data
.data32
[0] & (1<<8)) /* x */
10144 X(win
) = e
->data
.data32
[1];
10145 if (e
->data
.data32
[0] & (1<<9)) /* y */
10146 Y(win
) = e
->data
.data32
[2];
10147 if (e
->data
.data32
[0] & (1<<10)) /* width */
10148 WIDTH(win
) = e
->data
.data32
[3];
10149 if (e
->data
.data32
[0] & (1<<11)) /* height */
10150 HEIGHT(win
) = e
->data
.data32
[4];
10152 update_window(win
);
10154 /* Notify no change was made. */
10155 config_win(win
, NULL
);
10156 /* TODO: Change stack sizes */
10158 } else if (e
->type
== ewmh
[_NET_RESTACK_WINDOW
].atom
) {
10159 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_RESTACK_WINDOW\n");
10160 val
[0] = e
->data
.data32
[1]; /* Sibling window. */
10161 val
[1] = e
->data
.data32
[2]; /* Stack mode detail. */
10163 xcb_configure_window(conn
, win
->id
, XCB_CONFIG_WINDOW_SIBLING
|
10164 XCB_CONFIG_WINDOW_STACK_MODE
, val
);
10165 } else if (e
->type
== ewmh
[_NET_WM_STATE
].atom
) {
10166 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_WM_STATE\n");
10167 ewmh_change_wm_state(win
, e
->data
.data32
[1], e
->data
.data32
[0]);
10168 if (e
->data
.data32
[2])
10169 ewmh_change_wm_state(win
, e
->data
.data32
[2],
10170 e
->data
.data32
[0]);
10172 ewmh_update_wm_state(win
);
10174 } else if (e
->type
== ewmh
[_NET_WM_DESKTOP
].atom
) {
10175 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_WM_DESKTOP\n");
10178 win_to_ws(win
, e
->data
.data32
[0], true);
10180 /* Restack if either the source or destination ws is mapped. */
10181 if (r
!= NULL
|| win
->ws
->r
!= NULL
) {
10183 load_float_geom(win
);
10195 int errcode
= xcb_connection_has_error(conn
);
10196 #ifdef XCB_CONN_ERROR
10199 case XCB_CONN_ERROR
:
10200 s
= "Socket error, pipe error or other stream error.";
10202 case XCB_CONN_CLOSED_EXT_NOTSUPPORTED
:
10203 s
= "Extension not supported.";
10205 case XCB_CONN_CLOSED_MEM_INSUFFICIENT
:
10206 s
= "Insufficient memory.";
10208 case XCB_CONN_CLOSED_REQ_LEN_EXCEED
:
10209 s
= "Request length was exceeded.";
10211 case XCB_CONN_CLOSED_PARSE_ERR
:
10212 s
= "Error parsing display string.";
10215 s
= "Unknown error.";
10218 errx(errcode
, "X CONNECTION ERROR: %s", s
);
10221 errx(errcode
, "X CONNECTION ERROR");
10228 int num_screens
, i
;
10229 const uint32_t val
= XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT
|
10230 XCB_EVENT_MASK_ENTER_WINDOW
;
10232 xcb_void_cookie_t wac
;
10233 xcb_generic_error_t
*error
;
10235 /* this causes an error if some other window manager is running */
10236 num_screens
= get_screen_count();
10237 for (i
= 0; i
< num_screens
; i
++) {
10238 if ((sc
= get_screen(i
)) == NULL
)
10239 errx(1, "ERROR: can't get screen %d.", i
);
10240 DNPRINTF(SWM_D_INIT
, "enable_wm: screen %d, root: %#x\n",
10242 wac
= xcb_change_window_attributes_checked(conn
, sc
->root
,
10243 XCB_CW_EVENT_MASK
, &val
);
10244 if ((error
= xcb_request_check(conn
, wac
))) {
10245 DNPRINTF(SWM_D_INIT
, "enable_wm: error_code: %u\n",
10246 error
->error_code
);
10251 /* click to focus on empty region */
10252 xcb_grab_button(conn
, 1, sc
->root
, BUTTONMASK
,
10253 XCB_GRAB_MODE_SYNC
, XCB_GRAB_MODE_ASYNC
, XCB_WINDOW_NONE
,
10254 XCB_CURSOR_NONE
, XCB_BUTTON_INDEX_1
, XCB_BUTTON_MASK_ANY
);
10261 new_region(struct swm_screen
*s
, int x
, int y
, int w
, int h
)
10263 struct swm_region
*r
= NULL
, *n
;
10264 struct workspace
*ws
= NULL
;
10268 DNPRINTF(SWM_D_MISC
, "new region: screen[%d]:%dx%d+%d+%d\n",
10269 s
->idx
, w
, h
, x
, y
);
10271 /* remove any conflicting regions */
10272 n
= TAILQ_FIRST(&s
->rl
);
10275 n
= TAILQ_NEXT(r
, entry
);
10276 if (X(r
) < (x
+ w
) && (X(r
) + WIDTH(r
)) > x
&&
10277 Y(r
) < (y
+ h
) && (Y(r
) + HEIGHT(r
)) > y
) {
10278 if (r
->ws
->r
!= NULL
)
10279 r
->ws
->old_r
= r
->ws
->r
;
10282 xcb_destroy_window(conn
, r
->id
);
10283 TAILQ_REMOVE(&s
->rl
, r
, entry
);
10284 TAILQ_INSERT_TAIL(&s
->orl
, r
, entry
);
10288 /* search old regions for one to reuse */
10290 /* size + location match */
10291 TAILQ_FOREACH(r
, &s
->orl
, entry
)
10292 if (X(r
) == x
&& Y(r
) == y
&&
10293 HEIGHT(r
) == h
&& WIDTH(r
) == w
)
10297 TAILQ_FOREACH(r
, &s
->orl
, entry
)
10298 if (HEIGHT(r
) == h
&& WIDTH(r
) == w
)
10302 TAILQ_REMOVE(&s
->orl
, r
, entry
);
10303 /* try to use old region's workspace */
10304 if (r
->ws
->r
== NULL
)
10307 if ((r
= calloc(1, sizeof(struct swm_region
))) == NULL
)
10308 err(1, "new_region: calloc: failed to allocate memory "
10311 /* if we don't have a workspace already, find one */
10313 for (i
= 0; i
< workspace_limit
; i
++)
10314 if (s
->ws
[i
].r
== NULL
) {
10321 errx(1, "new_region: no free workspaces");
10323 if (ws
->state
== SWM_WS_STATE_HIDDEN
)
10324 ws
->state
= SWM_WS_STATE_MAPPING
;
10332 r
->ws_prior
= NULL
;
10335 TAILQ_INSERT_TAIL(&s
->rl
, r
, entry
);
10337 /* Invisible region window to detect pointer events on empty regions. */
10338 r
->id
= xcb_generate_id(conn
);
10339 wa
[0] = XCB_EVENT_MASK_POINTER_MOTION
|
10340 XCB_EVENT_MASK_POINTER_MOTION_HINT
;
10342 xcb_create_window(conn
, XCB_COPY_FROM_PARENT
, r
->id
, r
->s
->root
,
10343 X(r
), Y(r
), WIDTH(r
), HEIGHT(r
), 0, XCB_WINDOW_CLASS_INPUT_ONLY
,
10344 XCB_COPY_FROM_PARENT
, XCB_CW_EVENT_MASK
, wa
);
10346 /* Make sure region input is at the bottom. */
10347 wa
[0] = XCB_STACK_MODE_BELOW
;
10348 xcb_configure_window(conn
, r
->id
, XCB_CONFIG_WINDOW_STACK_MODE
, wa
);
10350 xcb_map_window(conn
, r
->id
);
10354 scan_randr(int idx
)
10356 #ifdef SWM_XRR_HAS_CRTC
10359 #endif /* SWM_XRR_HAS_CRTC */
10360 struct swm_region
*r
;
10361 struct ws_win
*win
;
10363 xcb_randr_get_screen_resources_current_cookie_t src
;
10364 xcb_randr_get_screen_resources_current_reply_t
*srr
;
10365 xcb_randr_get_crtc_info_cookie_t cic
;
10366 xcb_randr_get_crtc_info_reply_t
*cir
= NULL
;
10367 xcb_randr_crtc_t
*crtc
;
10368 xcb_screen_t
*screen
;
10370 DNPRINTF(SWM_D_MISC
, "scan_randr: screen: %d\n", idx
);
10372 if ((screen
= get_screen(idx
)) == NULL
)
10373 errx(1, "ERROR: can't get screen %d.", idx
);
10375 num_screens
= get_screen_count();
10376 if (idx
>= num_screens
)
10377 errx(1, "scan_randr: invalid screen");
10379 /* remove any old regions */
10380 while ((r
= TAILQ_FIRST(&screens
[idx
].rl
)) != NULL
) {
10381 r
->ws
->old_r
= r
->ws
->r
= NULL
;
10383 xcb_destroy_window(conn
, r
->id
);
10384 TAILQ_REMOVE(&screens
[idx
].rl
, r
, entry
);
10385 TAILQ_INSERT_TAIL(&screens
[idx
].orl
, r
, entry
);
10389 /* map virtual screens onto physical screens */
10390 #ifdef SWM_XRR_HAS_CRTC
10391 if (randr_support
) {
10392 src
= xcb_randr_get_screen_resources_current(conn
,
10393 screens
[idx
].root
);
10394 srr
= xcb_randr_get_screen_resources_current_reply(conn
, src
,
10397 new_region(&screens
[idx
], 0, 0,
10398 screen
->width_in_pixels
,
10399 screen
->height_in_pixels
);
10402 ncrtc
= srr
->num_crtcs
;
10404 crtc
= xcb_randr_get_screen_resources_current_crtcs(srr
);
10405 for (c
= 0; c
< ncrtc
; c
++) {
10406 cic
= xcb_randr_get_crtc_info(conn
, crtc
[c
],
10408 cir
= xcb_randr_get_crtc_info_reply(conn
, cic
, NULL
);
10411 if (cir
->num_outputs
== 0) {
10416 if (cir
->mode
== 0)
10417 new_region(&screens
[idx
], 0, 0,
10418 screen
->width_in_pixels
,
10419 screen
->height_in_pixels
);
10421 new_region(&screens
[idx
],
10422 cir
->x
, cir
->y
, cir
->width
, cir
->height
);
10427 #endif /* SWM_XRR_HAS_CRTC */
10429 /* If detection failed, create a single region that spans the screen. */
10430 if (TAILQ_EMPTY(&screens
[idx
].rl
))
10431 new_region(&screens
[idx
], 0, 0, screen
->width_in_pixels
,
10432 screen
->height_in_pixels
);
10435 /* Cleanup unused previously visible workspaces. */
10436 TAILQ_FOREACH(r
, &screens
[idx
].orl
, entry
) {
10437 TAILQ_FOREACH(win
, &r
->ws
->winlist
, entry
)
10439 r
->ws
->state
= SWM_WS_STATE_HIDDEN
;
10441 /* The screen shouldn't focus on an unused region. */
10442 if (screens
[idx
].r_focus
== r
)
10443 screens
[idx
].r_focus
= NULL
;
10446 DNPRINTF(SWM_D_MISC
, "scan_randr: done.\n");
10450 screenchange(xcb_randr_screen_change_notify_event_t
*e
)
10452 struct swm_region
*r
;
10453 int i
, num_screens
;
10455 DNPRINTF(SWM_D_EVENT
, "screenchange: root: %#x\n", e
->root
);
10457 num_screens
= get_screen_count();
10458 /* silly event doesn't include the screen index */
10459 for (i
= 0; i
< num_screens
; i
++)
10460 if (screens
[i
].root
== e
->root
)
10462 if (i
>= num_screens
)
10463 errx(1, "screenchange: screen not found");
10465 /* brute force for now, just re-enumerate the regions */
10469 print_win_geom(e
->root
);
10471 /* add bars to all regions */
10472 for (i
= 0; i
< num_screens
; i
++) {
10473 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
10479 /* Make sure a region has focus on each screen. */
10480 for (i
= 0; i
< num_screens
; i
++) {
10481 if (screens
[i
].r_focus
== NULL
) {
10482 r
= TAILQ_FIRST(&screens
[i
].rl
);
10491 /* Update workspace state on all regions. */
10492 for (i
= 0; i
< num_screens
; i
++)
10493 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
10494 r
->ws
->state
= SWM_WS_STATE_MAPPED
;
10500 struct swm_region
*r
= NULL
;
10501 xcb_window_t
*wins
= NULL
, trans
, *cwins
= NULL
;
10502 int i
, j
, k
, n
, no
, num_screens
;
10504 bool manage
, mapped
;
10506 xcb_query_tree_cookie_t qtc
;
10507 xcb_query_tree_reply_t
*qtr
;
10508 xcb_get_window_attributes_cookie_t gac
;
10509 xcb_get_window_attributes_reply_t
*gar
;
10510 xcb_get_property_cookie_t pc
;
10511 xcb_get_property_reply_t
*pr
;
10513 DNPRINTF(SWM_D_INIT
, "grab_windows: begin\n");
10514 num_screens
= get_screen_count();
10515 for (i
= 0; i
< num_screens
; i
++) {
10516 qtc
= xcb_query_tree(conn
, screens
[i
].root
);
10517 qtr
= xcb_query_tree_reply(conn
, qtc
, NULL
);
10520 wins
= xcb_query_tree_children(qtr
);
10521 no
= xcb_query_tree_children_length(qtr
);
10523 /* Try to sort windows according to _NET_CLIENT_LIST. */
10524 pr
= xcb_get_property_reply(conn
, xcb_get_property(conn
, 0,
10525 screens
[i
].root
, ewmh
[_NET_CLIENT_LIST
].atom
,
10526 XCB_ATOM_WINDOW
, 0, UINT32_MAX
), NULL
);
10528 cwins
= xcb_get_property_value(pr
);
10529 n
= xcb_get_property_value_length(pr
) /
10530 sizeof(xcb_atom_t
);
10532 for (j
= 0; j
< n
; ++j
) {
10533 for (k
= j
; k
< no
; ++k
) {
10534 if (wins
[k
] == cwins
[j
]) {
10535 /* Swap wins j and k. */
10537 wins
[j
] = cwins
[j
];
10545 /* attach windows to a region */
10546 /* normal windows */
10547 DNPRINTF(SWM_D_INIT
, "grab_windows: grab top level windows.\n");
10548 for (j
= 0; j
< no
; j
++) {
10549 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
) {
10550 if (r
->id
== wins
[j
]) {
10551 DNPRINTF(SWM_D_INIT
, "grab_windows: "
10552 "skip %#x; region input window.\n",
10555 } else if (r
->bar
->id
== wins
[j
]) {
10556 DNPRINTF(SWM_D_INIT
, "grab_windows: "
10557 "skip %#x; region bar.\n",
10566 gac
= xcb_get_window_attributes(conn
, wins
[j
]);
10567 gar
= xcb_get_window_attributes_reply(conn
, gac
, NULL
);
10569 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10570 "doesn't exist.\n", wins
[j
]);
10574 if (gar
->override_redirect
) {
10575 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10576 "override_redirect set.\n", wins
[j
]);
10581 pc
= xcb_icccm_get_wm_transient_for(conn
, wins
[j
]);
10582 if (xcb_icccm_get_wm_transient_for_reply(conn
, pc
,
10584 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10585 "is transient for %#x.\n", wins
[j
], trans
);
10590 state
= get_win_state(wins
[j
]);
10591 manage
= state
!= XCB_ICCCM_WM_STATE_WITHDRAWN
;
10592 mapped
= gar
->map_state
== XCB_MAP_STATE_VIEWABLE
;
10593 if (mapped
|| manage
)
10594 manage_window(wins
[j
], SWM_STACK_TOP
, mapped
);
10597 /* transient windows */
10598 DNPRINTF(SWM_D_INIT
, "grab_windows: grab transient windows.\n");
10599 for (j
= 0; j
< no
; j
++) {
10600 gac
= xcb_get_window_attributes(conn
, wins
[j
]);
10601 gar
= xcb_get_window_attributes_reply(conn
, gac
, NULL
);
10603 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10604 "doesn't exist.\n", wins
[j
]);
10608 if (gar
->override_redirect
) {
10609 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10610 "override_redirect set.\n", wins
[j
]);
10615 state
= get_win_state(wins
[j
]);
10616 manage
= state
!= XCB_ICCCM_WM_STATE_WITHDRAWN
;
10617 mapped
= gar
->map_state
== XCB_MAP_STATE_VIEWABLE
;
10618 pc
= xcb_icccm_get_wm_transient_for(conn
, wins
[j
]);
10619 if (xcb_icccm_get_wm_transient_for_reply(conn
, pc
,
10620 &trans
, NULL
) && manage
)
10621 manage_window(wins
[j
], SWM_STACK_TOP
, mapped
);
10626 DNPRINTF(SWM_D_INIT
, "grab_windows: done.\n");
10630 setup_screens(void)
10632 int i
, j
, k
, num_screens
;
10633 struct workspace
*ws
;
10634 uint32_t gcv
[1], wa
[1];
10635 const xcb_query_extension_reply_t
*qep
;
10636 xcb_screen_t
*screen
;
10637 xcb_randr_query_version_cookie_t c
;
10638 xcb_randr_query_version_reply_t
*r
;
10640 num_screens
= get_screen_count();
10641 if ((screens
= calloc(num_screens
,
10642 sizeof(struct swm_screen
))) == NULL
)
10643 err(1, "setup_screens: calloc: failed to allocate memory for "
10646 /* Initial RandR setup. */
10647 randr_support
= false;
10648 qep
= xcb_get_extension_data(conn
, &xcb_randr_id
);
10649 if (qep
->present
) {
10650 c
= xcb_randr_query_version(conn
, 1, 1);
10651 r
= xcb_randr_query_version_reply(conn
, c
, NULL
);
10653 if (r
->major_version
>= 1) {
10654 randr_support
= true;
10655 randr_eventbase
= qep
->first_event
;
10661 wa
[0] = cursors
[XC_LEFT_PTR
].cid
;
10663 /* map physical screens */
10664 for (i
= 0; i
< num_screens
; i
++) {
10665 DNPRINTF(SWM_D_WS
, "setup_screens: init screen: %d\n", i
);
10666 screens
[i
].idx
= i
;
10667 screens
[i
].r_focus
= NULL
;
10669 TAILQ_INIT(&screens
[i
].rl
);
10670 TAILQ_INIT(&screens
[i
].orl
);
10671 if ((screen
= get_screen(i
)) == NULL
)
10672 errx(1, "ERROR: can't get screen %d.", i
);
10673 screens
[i
].root
= screen
->root
;
10675 /* set default colors */
10676 setscreencolor("red", i
, SWM_S_COLOR_FOCUS
);
10677 setscreencolor("rgb:88/88/88", i
, SWM_S_COLOR_UNFOCUS
);
10678 setscreencolor("rgb:00/80/80", i
, SWM_S_COLOR_BAR_BORDER
);
10679 setscreencolor("rgb:00/40/40", i
,
10680 SWM_S_COLOR_BAR_BORDER_UNFOCUS
);
10681 setscreencolor("black", i
, SWM_S_COLOR_BAR
);
10682 setscreencolor("rgb:a0/a0/a0", i
, SWM_S_COLOR_BAR_FONT
);
10683 setscreencolor("red", i
, SWM_S_COLOR_FOCUS_MAXIMIZED
);
10684 setscreencolor("rgb:88/88/88", i
,
10685 SWM_S_COLOR_UNFOCUS_MAXIMIZED
);
10687 /* create graphics context on screen */
10688 screens
[i
].bar_gc
= xcb_generate_id(conn
);
10690 xcb_create_gc(conn
, screens
[i
].bar_gc
, screens
[i
].root
,
10691 XCB_GC_GRAPHICS_EXPOSURES
, gcv
);
10693 /* set default cursor */
10694 xcb_change_window_attributes(conn
, screens
[i
].root
,
10695 XCB_CW_CURSOR
, wa
);
10697 /* init all workspaces */
10698 /* XXX these should be dynamically allocated too */
10699 for (j
= 0; j
< SWM_WS_MAX
; j
++) {
10700 ws
= &screens
[i
].ws
[j
];
10703 ws
->bar_enabled
= true;
10705 ws
->focus_prev
= NULL
;
10706 ws
->focus_pending
= NULL
;
10709 ws
->state
= SWM_WS_STATE_HIDDEN
;
10710 TAILQ_INIT(&ws
->stack
);
10711 TAILQ_INIT(&ws
->winlist
);
10712 TAILQ_INIT(&ws
->unmanagedlist
);
10714 for (k
= 0; layouts
[k
].l_stack
!= NULL
; k
++)
10715 if (layouts
[k
].l_config
!= NULL
)
10716 layouts
[k
].l_config(ws
,
10717 SWM_ARG_ID_STACKINIT
);
10718 ws
->cur_layout
= &layouts
[0];
10719 ws
->cur_layout
->l_string(ws
);
10725 xcb_randr_select_input(conn
, screens
[i
].root
,
10726 XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE
);
10731 setup_globals(void)
10733 if ((bar_fonts
= strdup(SWM_BAR_FONTS
)) == NULL
)
10734 err(1, "setup_globals: strdup: failed to allocate memory.");
10736 if ((clock_format
= strdup("%a %b %d %R %Z %Y")) == NULL
)
10737 err(1, "setup_globals: strdup: failed to allocate memory.");
10739 if ((syms
= xcb_key_symbols_alloc(conn
)) == NULL
)
10740 errx(1, "unable to allocate key symbols");
10742 a_state
= get_atom_from_string("WM_STATE");
10743 a_prot
= get_atom_from_string("WM_PROTOCOLS");
10744 a_delete
= get_atom_from_string("WM_DELETE_WINDOW");
10745 a_net_supported
= get_atom_from_string("_NET_SUPPORTED");
10746 a_net_wm_check
= get_atom_from_string("_NET_SUPPORTING_WM_CHECK");
10747 a_takefocus
= get_atom_from_string("WM_TAKE_FOCUS");
10748 a_utf8_string
= get_atom_from_string("UTF8_STRING");
10749 a_swm_ws
= get_atom_from_string("_SWM_WS");
10753 shutdown_cleanup(void)
10755 int i
, num_screens
;
10757 /* disable alarm because the following code may not be interrupted */
10759 if (signal(SIGALRM
, SIG_IGN
) == SIG_ERR
)
10760 err(1, "can't disable alarm");
10769 num_screens
= get_screen_count();
10770 for (i
= 0; i
< num_screens
; ++i
) {
10771 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_POINTER_ROOT
,
10772 screens
[i
].root
, XCB_CURRENT_TIME
);
10774 if (screens
[i
].bar_gc
!= XCB_NONE
)
10775 xcb_free_gc(conn
, screens
[i
].bar_gc
);
10776 if (!bar_font_legacy
) {
10777 XftColorFree(display
, DefaultVisual(display
, i
),
10778 DefaultColormap(display
, i
), &bar_font_color
);
10779 XftColorFree(display
, DefaultVisual(display
, i
),
10780 DefaultColormap(display
, i
), &search_font_color
);
10784 if (bar_font_legacy
)
10785 XFreeFontSet(display
, bar_fs
);
10787 XftFontClose(display
, bar_font
);
10790 xcb_key_symbols_free(syms
);
10792 xcb_disconnect(conn
);
10796 event_error(xcb_generic_error_t
*e
)
10800 DNPRINTF(SWM_D_EVENT
, "event_error: %s(%u) from %s(%u), sequence: %u, "
10801 "resource_id: %u, minor_code: %u\n",
10802 xcb_event_get_error_label(e
->error_code
), e
->error_code
,
10803 xcb_event_get_request_label(e
->major_code
), e
->major_code
,
10804 e
->sequence
, e
->resource_id
, e
->minor_code
);
10808 event_handle(xcb_generic_event_t
*evt
)
10810 uint8_t type
= XCB_EVENT_RESPONSE_TYPE(evt
);
10812 DNPRINTF(SWM_D_EVENT
, "XCB Event: %s(%d), seq %u\n",
10813 xcb_event_get_label(XCB_EVENT_RESPONSE_TYPE(evt
)),
10814 XCB_EVENT_RESPONSE_TYPE(evt
), evt
->sequence
);
10817 #define EVENT(type, callback) case type: callback((void *)evt); return
10818 EVENT(0, event_error
);
10819 EVENT(XCB_BUTTON_PRESS
, buttonpress
);
10820 /*EVENT(XCB_BUTTON_RELEASE, buttonpress);*/
10821 /*EVENT(XCB_CIRCULATE_NOTIFY, );*/
10822 /*EVENT(XCB_CIRCULATE_REQUEST, );*/
10823 EVENT(XCB_CLIENT_MESSAGE
, clientmessage
);
10824 /*EVENT(XCB_COLORMAP_NOTIFY, );*/
10825 EVENT(XCB_CONFIGURE_NOTIFY
, configurenotify
);
10826 EVENT(XCB_CONFIGURE_REQUEST
, configurerequest
);
10827 /*EVENT(XCB_CREATE_NOTIFY, );*/
10828 EVENT(XCB_DESTROY_NOTIFY
, destroynotify
);
10829 EVENT(XCB_ENTER_NOTIFY
, enternotify
);
10830 EVENT(XCB_EXPOSE
, expose
);
10832 EVENT(XCB_FOCUS_IN
, focusin
);
10833 EVENT(XCB_FOCUS_OUT
, focusout
);
10835 /*EVENT(XCB_GRAPHICS_EXPOSURE, );*/
10836 /*EVENT(XCB_GRAVITY_NOTIFY, );*/
10837 EVENT(XCB_KEY_PRESS
, keypress
);
10838 /*EVENT(XCB_KEY_RELEASE, keypress);*/
10839 /*EVENT(XCB_KEYMAP_NOTIFY, );*/
10841 EVENT(XCB_LEAVE_NOTIFY
, leavenotify
);
10843 EVENT(XCB_MAP_NOTIFY
, mapnotify
);
10844 EVENT(XCB_MAP_REQUEST
, maprequest
);
10845 EVENT(XCB_MAPPING_NOTIFY
, mappingnotify
);
10846 EVENT(XCB_MOTION_NOTIFY
, motionnotify
);
10847 /*EVENT(XCB_NO_EXPOSURE, );*/
10848 EVENT(XCB_PROPERTY_NOTIFY
, propertynotify
);
10849 /*EVENT(XCB_REPARENT_NOTIFY, );*/
10850 /*EVENT(XCB_RESIZE_REQUEST, );*/
10851 /*EVENT(XCB_SELECTION_CLEAR, );*/
10852 /*EVENT(XCB_SELECTION_NOTIFY, );*/
10853 /*EVENT(XCB_SELECTION_REQUEST, );*/
10854 EVENT(XCB_UNMAP_NOTIFY
, unmapnotify
);
10855 /*EVENT(XCB_VISIBILITY_NOTIFY, );*/
10858 if (type
- randr_eventbase
== XCB_RANDR_SCREEN_CHANGE_NOTIFY
)
10859 screenchange((void *)evt
);
10863 main(int argc
, char *argv
[])
10865 struct swm_region
*r
;
10866 char conf
[PATH_MAX
], *cfile
= NULL
;
10868 int xfd
, i
, num_screens
;
10869 struct sigaction sact
;
10870 xcb_generic_event_t
*evt
;
10872 struct pollfd pfd
[2];
10873 bool stdin_ready
= false, startup
= true;
10875 /* suppress unused warning since var is needed */
10879 time_started
= time(NULL
);
10883 warnx("Welcome to spectrwm V%s Build: %s", SPECTRWM_VERSION
, buildstr
);
10884 if (setlocale(LC_CTYPE
, "") == NULL
|| setlocale(LC_TIME
, "") == NULL
)
10885 warnx("no locale support");
10887 /* handle some signals */
10888 bzero(&sact
, sizeof(sact
));
10889 sigemptyset(&sact
.sa_mask
);
10891 sact
.sa_handler
= sighdlr
;
10892 sigaction(SIGINT
, &sact
, NULL
);
10893 sigaction(SIGQUIT
, &sact
, NULL
);
10894 sigaction(SIGTERM
, &sact
, NULL
);
10895 sigaction(SIGHUP
, &sact
, NULL
);
10897 sact
.sa_handler
= sighdlr
;
10898 sact
.sa_flags
= SA_NOCLDSTOP
;
10899 sigaction(SIGCHLD
, &sact
, NULL
);
10901 if ((display
= XOpenDisplay(0)) == NULL
)
10902 errx(1, "can not open display");
10904 conn
= XGetXCBConnection(display
);
10905 if (xcb_connection_has_error(conn
))
10906 errx(1, "can not get XCB connection");
10908 XSetEventQueueOwner(display
, XCBOwnsEventQueue
);
10910 xcb_prefetch_extension_data(conn
, &xcb_randr_id
);
10911 xfd
= xcb_get_file_descriptor(conn
);
10913 /* look for local and global conf file */
10914 pwd
= getpwuid(getuid());
10916 errx(1, "invalid user: %d", getuid());
10918 xcb_grab_server(conn
);
10919 xcb_aux_sync(conn
);
10921 /* flush all events */
10922 while ((evt
= xcb_poll_for_event(conn
))) {
10923 if (XCB_EVENT_RESPONSE_TYPE(evt
) == 0)
10929 errx(1, "another window manager is currently running");
10931 /* Load Xcursors and/or cursorfont glyph cursors. */
10934 xcb_aux_sync(conn
);
10944 for (i
= 0; ; i
++) {
10949 snprintf(conf
, sizeof conf
, "%s/.%s",
10950 pwd
->pw_dir
, SWM_CONF_FILE
);
10954 snprintf(conf
, sizeof conf
, "/etc/%s",
10959 snprintf(conf
, sizeof conf
, "%s/.%s",
10960 pwd
->pw_dir
, SWM_CONF_FILE_OLD
);
10963 /* global compat */
10964 snprintf(conf
, sizeof conf
, "/etc/%s",
10965 SWM_CONF_FILE_OLD
);
10971 if (strlen(conf
) && stat(conf
, &sb
) != -1)
10972 if (S_ISREG(sb
.st_mode
)) {
10979 /* load conf (if any) */
10981 conf_load(cfile
, SWM_CONF_DEFAULT
);
10985 if (getenv("SWM_STARTED") == NULL
)
10986 setenv("SWM_STARTED", "YES", 1);
10988 /* setup all bars */
10989 num_screens
= get_screen_count();
10990 for (i
= 0; i
< num_screens
; i
++)
10991 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
10994 /* Manage existing windows. */
11001 xcb_ungrab_server(conn
);
11004 /* Update state of each newly mapped workspace. */
11005 for (i
= 0; i
< num_screens
; i
++)
11006 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
11007 r
->ws
->state
= SWM_WS_STATE_MAPPED
;
11009 memset(&pfd
, 0, sizeof(pfd
));
11011 pfd
[0].events
= POLLIN
;
11012 pfd
[1].fd
= STDIN_FILENO
;
11013 pfd
[1].events
= POLLIN
;
11016 while ((evt
= xcb_poll_for_event(conn
))) {
11023 /* If just (re)started, set default focus if needed. */
11027 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
11028 r
= TAILQ_FIRST(&screens
[0].rl
);
11037 num_readable
= poll(pfd
, bar_extra
? 2 : 1, 1000);
11038 if (num_readable
== -1) {
11039 DNPRINTF(SWM_D_MISC
, "poll failed: %s", strerror(errno
));
11040 } else if (num_readable
> 0 && bar_extra
&& pfd
[1].revents
& POLLIN
) {
11041 stdin_ready
= true;
11045 restart(NULL
, NULL
);
11054 stdin_ready
= false;
11055 bar_extra_update();
11062 shutdown_cleanup();