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_pointer
= false;
337 bool visible_noswap
= false;
340 struct swm_region
*search_r
;
341 int select_list_pipe
[2];
342 int select_resp_pipe
[2];
344 volatile sig_atomic_t search_resp
;
345 int search_resp_action
;
347 struct search_window
{
348 TAILQ_ENTRY(search_window
) entry
;
352 xcb_window_t indicator
;
354 TAILQ_HEAD(search_winlist
, search_window
);
355 struct search_winlist search_wl
;
360 SWM_SEARCH_UNICONIFY
,
361 SWM_SEARCH_NAME_WORKSPACE
,
362 SWM_SEARCH_SEARCH_WORKSPACE
,
363 SWM_SEARCH_SEARCH_WINDOW
366 #define SWM_STACK_TOP (0)
367 #define SWM_STACK_BOTTOM (1)
368 #define SWM_STACK_ABOVE (2)
369 #define SWM_STACK_BELOW (3)
372 double dialog_ratio
= 0.6;
374 #define SWM_BAR_MAX (256)
375 #define SWM_BAR_JUSTIFY_LEFT (0)
376 #define SWM_BAR_JUSTIFY_CENTER (1)
377 #define SWM_BAR_JUSTIFY_RIGHT (2)
378 #define SWM_BAR_OFFSET (4)
379 #define SWM_BAR_FONTS "-*-terminus-medium-*-*-*-12-*-*-*-*-*-*-*," \
380 "-*-profont-*-*-*-*-12-*-*-*-*-*-*-*," \
381 "-*-times-medium-r-*-*-12-*-*-*-*-*-*-*," \
382 "-misc-fixed-medium-r-*-*-12-*-*-*-*-*-*-*," \
383 "-*-*-*-r-*-*-*-*-*-*-*-*-*-*"
385 #ifdef X_HAVE_UTF8_STRING
386 #define DRAWSTRING(x...) Xutf8DrawString(x)
388 #define DRAWSTRING(x...) XmbDrawString(x)
391 char *bar_argv
[] = { NULL
, NULL
};
393 char bar_ext
[SWM_BAR_MAX
];
394 char bar_ext_buf
[SWM_BAR_MAX
];
395 char bar_vertext
[SWM_BAR_MAX
];
396 bool bar_version
= false;
397 bool bar_enabled
= true;
398 int bar_border_width
= 1;
399 bool bar_at_bottom
= false;
400 bool bar_extra
= false;
402 int bar_justify
= SWM_BAR_JUSTIFY_LEFT
;
403 char *bar_format
= NULL
;
404 bool stack_enabled
= true;
405 bool clock_enabled
= true;
406 bool iconic_enabled
= false;
407 bool maximize_hide_bar
= false;
408 bool urgent_enabled
= false;
409 bool urgent_collapse
= false;
410 char *clock_format
= NULL
;
411 bool window_class_enabled
= false;
412 bool window_instance_enabled
= false;
413 bool window_name_enabled
= false;
414 int focus_mode
= SWM_FOCUS_DEFAULT
;
415 int focus_close
= SWM_STACK_BELOW
;
416 bool focus_close_wrap
= true;
417 int focus_default
= SWM_STACK_TOP
;
418 int spawn_position
= SWM_STACK_TOP
;
419 bool disable_border
= false;
420 int border_width
= 1;
421 int region_padding
= 0;
423 bool java_workaround
= true;
424 bool verbose_layout
= false;
430 XFontSetExtents
*bar_fs_extents
;
432 bool bar_font_legacy
= true;
434 XftColor bar_font_color
;
435 XftColor search_font_color
;
437 char *startup_exception
;
438 unsigned int nr_exceptions
= 0;
440 /* layout manager data */
441 struct swm_geometry
{
454 struct swm_geometry g
;
457 /* virtual "screens" */
459 TAILQ_ENTRY(swm_region
) entry
;
461 struct swm_geometry g
;
462 struct workspace
*ws
; /* current workspace on this region */
463 struct workspace
*ws_prior
; /* prior workspace on this region */
464 struct swm_screen
*s
; /* screen idx */
467 TAILQ_HEAD(swm_region_list
, swm_region
);
470 TAILQ_ENTRY(ws_win
) entry
;
471 TAILQ_ENTRY(ws_win
) stack_entry
;
473 xcb_window_t transient
;
474 struct ws_win
*focus_child
; /* focus on child transient */
475 struct swm_geometry g
; /* current geometry */
476 struct swm_geometry g_float
; /* region coordinates */
477 bool g_floatvalid
; /* g_float geometry validity */
481 int font_size_boundary
[SWM_MAX_FONT_STEPS
];
488 struct workspace
*ws
; /* always valid */
489 struct swm_screen
*s
; /* always valid, never changes */
491 xcb_icccm_get_wm_class_reply_t ch
;
492 xcb_icccm_wm_hints_t hints
;
494 TAILQ_HEAD(ws_win_list
, ws_win
);
495 TAILQ_HEAD(ws_win_stack
, ws_win
);
499 TAILQ_ENTRY(pid_e
) entry
;
503 TAILQ_HEAD(pid_list
, pid_e
);
504 struct pid_list pidlist
= TAILQ_HEAD_INITIALIZER(pidlist
);
506 /* layout handlers */
508 void vertical_config(struct workspace
*, int);
509 void vertical_stack(struct workspace
*, struct swm_geometry
*);
510 void horizontal_config(struct workspace
*, int);
511 void horizontal_stack(struct workspace
*, struct swm_geometry
*);
512 void max_stack(struct workspace
*, struct swm_geometry
*);
513 void plain_stacker(struct workspace
*);
514 void fancy_stacker(struct workspace
*);
517 void (*l_stack
)(struct workspace
*, struct swm_geometry
*);
518 void (*l_config
)(struct workspace
*, int);
520 #define SWM_L_FOCUSPREV (1<<0)
521 #define SWM_L_MAPONFOCUS (1<<1)
522 void (*l_string
)(struct workspace
*);
524 /* stack, configure */
525 { vertical_stack
, vertical_config
, 0, plain_stacker
},
526 { horizontal_stack
, horizontal_config
, 0, plain_stacker
},
528 SWM_L_MAPONFOCUS
| SWM_L_FOCUSPREV
, plain_stacker
},
529 { NULL
, NULL
, 0, NULL
},
532 /* position of max_stack mode in the layouts array, index into layouts! */
533 #define SWM_V_STACK (0)
534 #define SWM_H_STACK (1)
535 #define SWM_MAX_STACK (2)
537 #define SWM_H_SLICE (32)
538 #define SWM_V_SLICE (32)
540 /* define work spaces */
542 int idx
; /* workspace index */
543 char *name
; /* workspace name */
544 bool always_raise
; /* raise windows on focus */
545 bool bar_enabled
; /* bar visibility */
546 struct layout
*cur_layout
; /* current layout handlers */
547 struct ws_win
*focus
; /* may be NULL */
548 struct ws_win
*focus_prev
; /* may be NULL */
549 struct ws_win
*focus_pending
; /* may be NULL */
550 struct swm_region
*r
; /* may be NULL */
551 struct swm_region
*old_r
; /* may be NULL */
552 struct ws_win_list winlist
; /* list of windows in ws */
553 struct ws_win_list unmanagedlist
; /* list of dead windows in ws */
554 struct ws_win_stack stack
; /* stacking order */
555 int state
; /* mapping state */
556 char stacker
[10]; /* display stacker and layout */
560 int horizontal_msize
;
562 int horizontal_stacks
;
563 bool horizontal_flip
;
573 SWM_WS_STATE_MAPPING
,
579 SWM_S_COLOR_BAR_BORDER
,
580 SWM_S_COLOR_BAR_BORDER_UNFOCUS
,
581 SWM_S_COLOR_BAR_FONT
,
583 SWM_S_COLOR_FOCUS_MAXIMIZED
,
585 SWM_S_COLOR_UNFOCUS_MAXIMIZED
,
589 /* physical screen mapping */
590 #define SWM_WS_MAX (22) /* hard limit */
591 int workspace_limit
= 10; /* soft limit */
594 int idx
; /* screen index */
595 struct swm_region_list rl
; /* list of regions on this screen */
596 struct swm_region_list orl
; /* list of old regions */
598 struct workspace ws
[SWM_WS_MAX
];
599 struct swm_region
*r_focus
;
606 } c
[SWM_S_COLOR_MAX
];
608 xcb_gcontext_t bar_gc
;
611 struct swm_screen
*screens
;
613 /* args to functions */
616 #define SWM_ARG_ID_FOCUSNEXT (0)
617 #define SWM_ARG_ID_FOCUSPREV (1)
618 #define SWM_ARG_ID_FOCUSMAIN (2)
619 #define SWM_ARG_ID_FOCUSURGENT (3)
620 #define SWM_ARG_ID_SWAPNEXT (10)
621 #define SWM_ARG_ID_SWAPPREV (11)
622 #define SWM_ARG_ID_SWAPMAIN (12)
623 #define SWM_ARG_ID_MOVELAST (13)
624 #define SWM_ARG_ID_MASTERSHRINK (20)
625 #define SWM_ARG_ID_MASTERGROW (21)
626 #define SWM_ARG_ID_MASTERADD (22)
627 #define SWM_ARG_ID_MASTERDEL (23)
628 #define SWM_ARG_ID_FLIPLAYOUT (24)
629 #define SWM_ARG_ID_STACKRESET (30)
630 #define SWM_ARG_ID_STACKINIT (31)
631 #define SWM_ARG_ID_STACKBALANCE (32)
632 #define SWM_ARG_ID_CYCLEWS_UP (40)
633 #define SWM_ARG_ID_CYCLEWS_DOWN (41)
634 #define SWM_ARG_ID_CYCLERG_UP (42)
635 #define SWM_ARG_ID_CYCLERG_DOWN (43)
636 #define SWM_ARG_ID_CYCLEWS_UP_ALL (44)
637 #define SWM_ARG_ID_CYCLEWS_DOWN_ALL (45)
638 #define SWM_ARG_ID_CYCLEWS_MOVE_UP (46)
639 #define SWM_ARG_ID_CYCLEWS_MOVE_DOWN (47)
640 #define SWM_ARG_ID_STACKINC (50)
641 #define SWM_ARG_ID_STACKDEC (51)
642 #define SWM_ARG_ID_SS_ALL (60)
643 #define SWM_ARG_ID_SS_WINDOW (61)
644 #define SWM_ARG_ID_DONTCENTER (70)
645 #define SWM_ARG_ID_CENTER (71)
646 #define SWM_ARG_ID_KILLWINDOW (80)
647 #define SWM_ARG_ID_DELETEWINDOW (81)
648 #define SWM_ARG_ID_WIDTHGROW (90)
649 #define SWM_ARG_ID_WIDTHSHRINK (91)
650 #define SWM_ARG_ID_HEIGHTGROW (92)
651 #define SWM_ARG_ID_HEIGHTSHRINK (93)
652 #define SWM_ARG_ID_MOVEUP (100)
653 #define SWM_ARG_ID_MOVEDOWN (101)
654 #define SWM_ARG_ID_MOVELEFT (102)
655 #define SWM_ARG_ID_MOVERIGHT (103)
656 #define SWM_ARG_ID_RAISE (105)
657 #define SWM_ARG_ID_LOWER (106)
658 #define SWM_ARG_ID_BAR_TOGGLE (110)
659 #define SWM_ARG_ID_BAR_TOGGLE_WS (111)
660 #define SWM_ARG_ID_CYCLERG_MOVE_UP (112)
661 #define SWM_ARG_ID_CYCLERG_MOVE_DOWN (113)
667 TAILQ_ENTRY(quirk
) entry
;
668 char *class; /* WM_CLASS:class */
669 char *instance
; /* WM_CLASS:instance */
670 char *name
; /* WM_NAME */
672 regex_t regex_instance
;
675 int ws
; /* Initial workspace. */
676 #define SWM_Q_FLOAT (1<<0) /* float this window */
677 #define SWM_Q_TRANSSZ (1<<1) /* transiend window size too small */
678 #define SWM_Q_ANYWHERE (1<<2) /* don't position this window */
679 #define SWM_Q_XTERM_FONTADJ (1<<3) /* adjust xterm fonts when resizing */
680 #define SWM_Q_FULLSCREEN (1<<4) /* remove border */
681 #define SWM_Q_FOCUSPREV (1<<5) /* focus on caller */
682 #define SWM_Q_NOFOCUSONMAP (1<<6) /* Don't focus on window when mapped. */
683 #define SWM_Q_FOCUSONMAP_SINGLE (1<<7) /* Only focus if single win of type. */
684 #define SWM_Q_OBEYAPPFOCUSREQ (1<<8) /* Focus when applications ask. */
685 #define SWM_Q_IGNOREPID (1<<9) /* Ignore PID when determining ws. */
686 #define SWM_Q_IGNORESPAWNWS (1<<10) /* Ignore _SWM_WS when managing win. */
687 #define SWM_Q_NOFOCUSCYCLE (1<<11) /* Remove from normal focus cycle. */
689 TAILQ_HEAD(quirk_list
, quirk
);
690 struct quirk_list quirks
= TAILQ_HEAD_INITIALIZER(quirks
);
693 * Supported EWMH hints should be added to
694 * both the enum and the ewmh array
700 _NET_CURRENT_DESKTOP
,
701 _NET_DESKTOP_GEOMETRY
,
703 _NET_DESKTOP_VIEWPORT
,
704 _NET_MOVERESIZE_WINDOW
,
705 _NET_NUMBER_OF_DESKTOPS
,
707 _NET_WM_ACTION_ABOVE
,
708 _NET_WM_ACTION_CLOSE
,
709 _NET_WM_ACTION_FULLSCREEN
,
711 _NET_WM_ACTION_RESIZE
,
712 _NET_WM_ALLOWED_ACTIONS
,
714 _NET_WM_FULL_PLACEMENT
,
718 _NET_WM_STATE_FULLSCREEN
,
719 _NET_WM_STATE_HIDDEN
,
720 _NET_WM_STATE_MAXIMIZED_VERT
,
721 _NET_WM_STATE_MAXIMIZED_HORZ
,
722 _NET_WM_STATE_SKIP_PAGER
,
723 _NET_WM_STATE_SKIP_TASKBAR
,
725 _NET_WM_WINDOW_TYPE_DIALOG
,
726 _NET_WM_WINDOW_TYPE_DOCK
,
727 _NET_WM_WINDOW_TYPE_NORMAL
,
728 _NET_WM_WINDOW_TYPE_SPLASH
,
729 _NET_WM_WINDOW_TYPE_TOOLBAR
,
730 _NET_WM_WINDOW_TYPE_UTILITY
,
731 _SWM_WM_STATE_MANUAL
,
738 } ewmh
[SWM_EWMH_HINT_MAX
] = {
739 /* must be in same order as in the enum */
740 {"_NET_ACTIVE_WINDOW", XCB_ATOM_NONE
},
741 {"_NET_CLIENT_LIST", XCB_ATOM_NONE
},
742 {"_NET_CLOSE_WINDOW", XCB_ATOM_NONE
},
743 {"_NET_CURRENT_DESKTOP", XCB_ATOM_NONE
},
744 {"_NET_DESKTOP_GEOMETRY", XCB_ATOM_NONE
},
745 {"_NET_DESKTOP_NAMES", XCB_ATOM_NONE
},
746 {"_NET_DESKTOP_VIEWPORT", XCB_ATOM_NONE
},
747 {"_NET_MOVERESIZE_WINDOW", XCB_ATOM_NONE
},
748 {"_NET_NUMBER_OF_DESKTOPS", XCB_ATOM_NONE
},
749 {"_NET_RESTACK_WINDOW", XCB_ATOM_NONE
},
750 {"_NET_WM_ACTION_ABOVE", XCB_ATOM_NONE
},
751 {"_NET_WM_ACTION_CLOSE", XCB_ATOM_NONE
},
752 {"_NET_WM_ACTION_FULLSCREEN", XCB_ATOM_NONE
},
753 {"_NET_WM_ACTION_MOVE", XCB_ATOM_NONE
},
754 {"_NET_WM_ACTION_RESIZE", XCB_ATOM_NONE
},
755 {"_NET_WM_ALLOWED_ACTIONS", XCB_ATOM_NONE
},
756 {"_NET_WM_DESKTOP", XCB_ATOM_NONE
},
757 {"_NET_WM_FULL_PLACEMENT", XCB_ATOM_NONE
},
758 {"_NET_WM_NAME", XCB_ATOM_NONE
},
759 {"_NET_WM_STATE", XCB_ATOM_NONE
},
760 {"_NET_WM_STATE_ABOVE", XCB_ATOM_NONE
},
761 {"_NET_WM_STATE_FULLSCREEN", XCB_ATOM_NONE
},
762 {"_NET_WM_STATE_HIDDEN", XCB_ATOM_NONE
},
763 {"_NET_WM_STATE_MAXIMIZED_VERT", XCB_ATOM_NONE
},
764 {"_NET_WM_STATE_MAXIMIZED_HORZ", XCB_ATOM_NONE
},
765 {"_NET_WM_STATE_SKIP_PAGER", XCB_ATOM_NONE
},
766 {"_NET_WM_STATE_SKIP_TASKBAR", XCB_ATOM_NONE
},
767 {"_NET_WM_WINDOW_TYPE", XCB_ATOM_NONE
},
768 {"_NET_WM_WINDOW_TYPE_DIALOG", XCB_ATOM_NONE
},
769 {"_NET_WM_WINDOW_TYPE_DOCK", XCB_ATOM_NONE
},
770 {"_NET_WM_WINDOW_TYPE_NORMAL", XCB_ATOM_NONE
},
771 {"_NET_WM_WINDOW_TYPE_SPLASH", XCB_ATOM_NONE
},
772 {"_NET_WM_WINDOW_TYPE_TOOLBAR", XCB_ATOM_NONE
},
773 {"_NET_WM_WINDOW_TYPE_UTILITY", XCB_ATOM_NONE
},
774 {"_SWM_WM_STATE_MANUAL", XCB_ATOM_NONE
},
777 /* EWMH source type */
779 EWMH_SOURCE_TYPE_NONE
= 0,
780 EWMH_SOURCE_TYPE_NORMAL
= 1,
781 EWMH_SOURCE_TYPE_OTHER
= 2,
788 XC_BOTTOM_LEFT_CORNER
,
789 XC_BOTTOM_RIGHT_CORNER
,
797 char *name
; /* Name used by Xcursor .*/
798 uint8_t cf_char
; /* cursorfont index. */
800 } cursors
[XC_MAX
] = {
801 {"fleur", XC_fleur
, XCB_CURSOR_NONE
},
802 {"left_ptr", XC_left_ptr
, XCB_CURSOR_NONE
},
803 {"bottom_left_corner", XC_bottom_left_corner
, XCB_CURSOR_NONE
},
804 {"bottom_right_corner", XC_bottom_right_corner
, XCB_CURSOR_NONE
},
805 {"sizing", XC_sizing
, XCB_CURSOR_NONE
},
806 {"top_left_corner", XC_top_left_corner
, XCB_CURSOR_NONE
},
807 {"top_right_corner", XC_top_right_corner
, XCB_CURSOR_NONE
},
810 #define SWM_SPAWN_OPTIONAL 0x1
814 TAILQ_ENTRY(spawn_prog
) entry
;
820 TAILQ_HEAD(spawn_list
, spawn_prog
);
821 struct spawn_list spawns
= TAILQ_HEAD_INITIALIZER(spawns
);
823 /* user/key callable function IDs */
942 KF_DUMPWINS
, /* MUST BE LAST */
950 enum keyfuncid funcid
;
953 RB_HEAD(key_tree
, key
);
955 /* function prototypes */
956 void adjust_font(struct ws_win
*);
957 char *argsep(char **);
958 void bar_cleanup(struct swm_region
*);
959 void bar_extra_setup(void);
960 void bar_extra_stop(void);
961 int bar_extra_update(void);
962 void bar_fmt(const char *, char *, struct swm_region
*, size_t);
963 void bar_fmt_expand(char *, size_t);
965 void bar_print(struct swm_region
*, const char *);
966 void bar_print_legacy(struct swm_region
*, const char *);
967 void bar_replace(char *, char *, struct swm_region
*, size_t);
968 void bar_replace_pad(char *, int *, size_t);
969 char *bar_replace_seq(char *, char *, struct swm_region
*, size_t *, size_t);
970 void bar_setup(struct swm_region
*);
971 void bar_toggle(struct swm_region
*, union arg
*);
972 void bar_urgent(char *, size_t);
973 void bar_window_class(char *, size_t, struct swm_region
*);
974 void bar_window_class_instance(char *, size_t, struct swm_region
*);
975 void bar_window_float(char *, size_t, struct swm_region
*);
976 void bar_window_instance(char *, size_t, struct swm_region
*);
977 void bar_window_name(char *, size_t, struct swm_region
*);
978 void bar_window_state(char *, size_t, struct swm_region
*);
979 void bar_workspace_name(char *, size_t, struct swm_region
*);
980 void buttonpress(xcb_button_press_event_t
*);
981 void center_pointer(struct swm_region
*);
982 void check_conn(void);
983 void clear_keys(void);
984 int clear_maximized(struct workspace
*);
985 void clientmessage(xcb_client_message_event_t
*);
986 void client_msg(struct ws_win
*, xcb_atom_t
, xcb_timestamp_t
);
987 int conf_load(const char *, int);
988 void configurenotify(xcb_configure_notify_event_t
*);
989 void configurerequest(xcb_configure_request_event_t
*);
990 void config_win(struct ws_win
*, xcb_configure_request_event_t
*);
991 void constrain_window(struct ws_win
*, struct swm_geometry
*, int *);
992 int count_win(struct workspace
*, bool);
993 void cursors_cleanup(void);
994 void cursors_load(void);
995 void custom_region(const char *);
996 void cyclerg(struct swm_region
*, union arg
*);
997 void cyclews(struct swm_region
*, union arg
*);
998 void cycle_layout(struct swm_region
*, union arg
*);
999 void destroynotify(xcb_destroy_notify_event_t
*);
1000 void dumpwins(struct swm_region
*, union arg
*);
1001 int enable_wm(void);
1002 void enternotify(xcb_enter_notify_event_t
*);
1003 void event_drain(uint8_t);
1004 void event_error(xcb_generic_error_t
*);
1005 void event_handle(xcb_generic_event_t
*);
1006 void ewmh_apply_flags(struct ws_win
*, uint32_t);
1007 void ewmh_autoquirk(struct ws_win
*);
1008 void ewmh_get_desktop_names(void);
1009 void ewmh_get_wm_state(struct ws_win
*);
1010 void ewmh_update_actions(struct ws_win
*);
1011 void ewmh_update_client_list(void);
1012 void ewmh_update_current_desktop(void);
1013 void ewmh_update_desktop_names(void);
1014 void ewmh_update_desktops(void);
1015 void ewmh_change_wm_state(struct ws_win
*, xcb_atom_t
, long);
1016 void ewmh_update_wm_state(struct ws_win
*);
1017 char *expand_tilde(const char *);
1018 void expose(xcb_expose_event_t
*);
1019 void fake_keypress(struct ws_win
*, xcb_keysym_t
, uint16_t);
1020 struct pid_e
*find_pid(pid_t
);
1021 struct ws_win
*find_unmanaged_window(xcb_window_t
);
1022 struct ws_win
*find_window(xcb_window_t
);
1023 void floating_toggle(struct swm_region
*, union arg
*);
1024 void focus(struct swm_region
*, union arg
*);
1026 void focusin(xcb_focus_in_event_t
*);
1027 void focusout(xcb_focus_out_event_t
*);
1029 void focus_flush(void);
1030 void focus_region(struct swm_region
*);
1031 void focusrg(struct swm_region
*, union arg
*);
1032 void focus_win(struct ws_win
*);
1033 void fontset_init(void);
1034 void free_window(struct ws_win
*);
1035 xcb_atom_t
get_atom_from_string(const char *);
1037 char *get_atom_name(xcb_atom_t
);
1039 struct ws_win
*get_focus_magic(struct ws_win
*);
1040 struct ws_win
*get_focus_prev(struct ws_win
*);
1042 char *get_notify_detail_label(uint8_t);
1043 char *get_notify_mode_label(uint8_t);
1045 struct ws_win
*get_pointer_win(xcb_window_t
);
1046 struct ws_win
*get_region_focus(struct swm_region
*);
1047 int get_region_index(struct swm_region
*);
1048 xcb_screen_t
*get_screen(int);
1049 int get_screen_count(void);
1051 char *get_source_type_label(uint32_t);
1052 char *get_stack_mode_name(uint8_t);
1054 int32_t get_swm_ws(xcb_window_t
);
1055 bool get_urgent(struct ws_win
*);
1056 char *get_win_name(xcb_window_t
);
1057 uint8_t get_win_state(xcb_window_t
);
1058 void get_wm_protocols(struct ws_win
*);
1059 int get_ws_idx(struct ws_win
*);
1060 void grabbuttons(struct ws_win
*);
1061 void grabkeys(void);
1062 void grab_windows(void);
1063 void iconify(struct swm_region
*, union arg
*);
1064 bool isxlfd(char *);
1065 void keypress(xcb_key_press_event_t
*);
1066 int key_cmp(struct key
*, struct key
*);
1067 void key_insert(unsigned int, KeySym
, enum keyfuncid
, const char *);
1068 struct key
*key_lookup(unsigned int, KeySym
);
1069 void key_remove(struct key
*);
1070 void key_replace(struct key
*, unsigned int, KeySym
, enum keyfuncid
,
1072 void kill_bar_extra_atexit(void);
1073 void kill_refs(struct ws_win
*);
1075 void leavenotify(xcb_leave_notify_event_t
*);
1077 void load_float_geom(struct ws_win
*);
1078 void lower_window(struct ws_win
*);
1079 struct ws_win
*manage_window(xcb_window_t
, int, bool);
1080 void map_window(struct ws_win
*);
1081 void mapnotify(xcb_map_notify_event_t
*);
1082 void mappingnotify(xcb_mapping_notify_event_t
*);
1083 void maprequest(xcb_map_request_event_t
*);
1084 void maximize_toggle(struct swm_region
*, union arg
*);
1085 void motionnotify(xcb_motion_notify_event_t
*);
1086 void move(struct ws_win
*, union arg
*);
1087 void move_step(struct swm_region
*, union arg
*);
1088 uint32_t name_to_pixel(int, const char *);
1089 void name_workspace(struct swm_region
*, union arg
*);
1090 void new_region(struct swm_screen
*, int, int, int, int);
1091 int parsekeys(const char *, unsigned int, unsigned int *, KeySym
*);
1092 int parsequirks(const char *, uint32_t *, int *);
1093 int parse_rgb(const char *, uint16_t *, uint16_t *, uint16_t *);
1094 void pressbutton(struct swm_region
*, union arg
*);
1095 void priorws(struct swm_region
*, union arg
*);
1097 void print_win_geom(xcb_window_t
);
1099 void propertynotify(xcb_property_notify_event_t
*);
1100 void quirk_free(struct quirk
*);
1101 void quirk_insert(const char *, const char *, const char *, uint32_t, int);
1102 void quirk_remove(struct quirk
*);
1103 void quirk_replace(struct quirk
*, const char *, const char *, const char *,
1105 void quit(struct swm_region
*, union arg
*);
1106 void raise_toggle(struct swm_region
*, union arg
*);
1107 void raise_window(struct ws_win
*);
1108 void region_containment(struct ws_win
*, struct swm_region
*, int);
1109 struct swm_region
*region_under(struct swm_screen
*, int, int);
1110 void regionize(struct ws_win
*, int, int);
1111 void resize(struct ws_win
*, union arg
*);
1112 void resize_step(struct swm_region
*, union arg
*);
1113 void restart(struct swm_region
*, union arg
*);
1114 struct swm_region
*root_to_region(xcb_window_t
, int);
1115 void screenchange(xcb_randr_screen_change_notify_event_t
*);
1116 void scan_randr(int);
1117 void search_do_resp(void);
1118 void search_resp_name_workspace(const char *, size_t);
1119 void search_resp_search_window(const char *);
1120 void search_resp_search_workspace(const char *);
1121 void search_resp_uniconify(const char *, size_t);
1122 void search_win(struct swm_region
*, union arg
*);
1123 void search_win_cleanup(void);
1124 void search_workspace(struct swm_region
*, union arg
*);
1125 void send_to_rg(struct swm_region
*, union arg
*);
1126 void send_to_ws(struct swm_region
*, union arg
*);
1127 void set_region(struct swm_region
*);
1128 int setautorun(const char *, const char *, int);
1129 int setconfbinding(const char *, const char *, int);
1130 int setconfcolor(const char *, const char *, int);
1131 int setconfmodkey(const char *, const char *, int);
1132 int setconfquirk(const char *, const char *, int);
1133 int setconfregion(const char *, const char *, int);
1134 int setconfspawn(const char *, const char *, int);
1135 int setconfvalue(const char *, const char *, int);
1136 void setkeybinding(unsigned int, KeySym
, enum keyfuncid
, const char *);
1137 int setkeymapping(const char *, const char *, int);
1138 int setlayout(const char *, const char *, int);
1139 void setquirk(const char *, const char *, const char *, uint32_t, int);
1140 void setscreencolor(const char *, int, int);
1141 void setspawn(const char *, const char *, int);
1142 void setup_ewmh(void);
1143 void setup_globals(void);
1144 void setup_keys(void);
1145 void setup_quirks(void);
1146 void setup_screens(void);
1147 void setup_spawn(void);
1148 void set_child_transient(struct ws_win
*, xcb_window_t
*);
1149 void set_win_state(struct ws_win
*, uint8_t);
1150 void shutdown_cleanup(void);
1152 void socket_setnonblock(int);
1153 void sort_windows(struct ws_win_list
*);
1154 void spawn(int, union arg
*, bool);
1155 void spawn_custom(struct swm_region
*, union arg
*, const char *);
1156 int spawn_expand(struct swm_region
*, union arg
*, const char *, char ***);
1157 void spawn_insert(const char *, const char *, int);
1158 struct spawn_prog
*spawn_find(const char *);
1159 void spawn_remove(struct spawn_prog
*);
1160 void spawn_replace(struct spawn_prog
*, const char *, const char *, int);
1161 void spawn_select(struct swm_region
*, union arg
*, const char *, int *);
1162 void stack_config(struct swm_region
*, union arg
*);
1163 void stack_master(struct workspace
*, struct swm_geometry
*, int, bool);
1164 void store_float_geom(struct ws_win
*);
1165 char *strdupsafe(const char *);
1166 void swapwin(struct swm_region
*, union arg
*);
1167 void switchws(struct swm_region
*, union arg
*);
1168 void teardown_ewmh(void);
1169 void unescape_selector(char *);
1170 void unfocus_win(struct ws_win
*);
1171 void uniconify(struct swm_region
*, union arg
*);
1172 void unmanage_window(struct ws_win
*);
1173 void unmapnotify(xcb_unmap_notify_event_t
*);
1174 void unmap_all(void);
1175 void unmap_window(struct ws_win
*);
1176 void updatenumlockmask(void);
1177 void update_floater(struct ws_win
*);
1178 void update_modkey(unsigned int);
1179 void update_win_stacking(struct ws_win
*);
1180 void update_window(struct ws_win
*);
1181 void update_window_color(struct ws_win
*);
1182 void update_wm_state(struct ws_win
*win
);
1183 void validate_spawns(void);
1184 int validate_win(struct ws_win
*);
1185 int validate_ws(struct workspace
*);
1186 void version(struct swm_region
*, union arg
*);
1187 void win_to_ws(struct ws_win
*, int, bool);
1188 pid_t
window_get_pid(xcb_window_t
);
1189 void wkill(struct swm_region
*, union arg
*);
1190 void update_ws_stack(struct workspace
*);
1191 void xft_init(struct swm_region
*);
1192 void _add_startup_exception(const char *, va_list);
1193 void add_startup_exception(const char *, ...);
1195 RB_PROTOTYPE(key_tree
, key
, entry
, key_cmp
);
1196 RB_GENERATE(key_tree
, key
, entry
, key_cmp
);
1197 struct key_tree keys
;
1202 xcb_font_t cf
= XCB_NONE
;
1205 for (i
= 0; i
< LENGTH(cursors
); ++i
) {
1206 /* try to load Xcursor first. */
1207 cursors
[i
].cid
= XcursorLibraryLoadCursor(display
,
1210 /* fallback to cursorfont. */
1211 if (cursors
[i
].cid
== XCB_CURSOR_NONE
) {
1212 if (cf
== XCB_NONE
) {
1213 cf
= xcb_generate_id(conn
);
1214 xcb_open_font(conn
, cf
, strlen("cursor"),
1218 cursors
[i
].cid
= xcb_generate_id(conn
);
1219 xcb_create_glyph_cursor(conn
, cursors
[i
].cid
, cf
, cf
,
1220 cursors
[i
].cf_char
, cursors
[i
].cf_char
+ 1, 0, 0, 0,
1221 0xffff, 0xffff, 0xffff);
1227 xcb_close_font(conn
, cf
);
1231 cursors_cleanup(void)
1234 for (i
= 0; i
< LENGTH(cursors
); ++i
)
1235 xcb_free_cursor(conn
, cursors
[i
].cid
);
1239 expand_tilde(const char *s
)
1241 struct passwd
*ppwd
;
1249 errx(1, "expand_tilde: NULL string.");
1252 result
= strdup(sc
);
1258 if ((max
= sysconf(_SC_LOGIN_NAME_MAX
)) == -1)
1259 errx(1, "expand_tilde: sysconf");
1261 if ((user
= calloc(1, max
+ 1)) == NULL
)
1262 errx(1, "expand_tilde: calloc");
1264 for (i
= 0; s
[i
] != '/' && s
[i
] != '\0'; ++i
)
1269 ppwd
= strlen(user
) == 0 ? getpwuid(getuid()) : getpwnam(user
);
1273 result
= strdup(sc
);
1275 if (asprintf(&result
, "%s%s", ppwd
->pw_dir
, s
) == -1)
1279 errx(1, "expand_tilde: failed to allocate memory.");
1285 parse_rgb(const char *rgb
, uint16_t *rr
, uint16_t *gg
, uint16_t *bb
)
1287 unsigned int tmpr
, tmpg
, tmpb
;
1289 if (sscanf(rgb
, "rgb:%x/%x/%x", &tmpr
, &tmpg
, &tmpb
) != 3)
1292 *rr
= RGB_8_TO_16(tmpr
);
1293 *gg
= RGB_8_TO_16(tmpg
);
1294 *bb
= RGB_8_TO_16(tmpb
);
1300 get_screen(int screen
)
1302 const xcb_setup_t
*r
;
1303 xcb_screen_iterator_t iter
;
1305 if ((r
= xcb_get_setup(conn
)) == NULL
) {
1306 DNPRINTF(SWM_D_MISC
, "get_screen: xcb_get_setup\n");
1310 iter
= xcb_setup_roots_iterator(r
);
1311 for (; iter
.rem
; --screen
, xcb_screen_next(&iter
))
1319 get_screen_count(void)
1321 const xcb_setup_t
*r
;
1323 if ((r
= xcb_get_setup(conn
)) == NULL
) {
1324 DNPRINTF(SWM_D_MISC
, "get_screen_count: xcb_get_setup\n");
1328 return xcb_setup_roots_length(r
);
1332 get_region_index(struct swm_region
*r
)
1334 struct swm_region
*rr
;
1340 TAILQ_FOREACH(rr
, &r
->s
->rl
, entry
) {
1355 if (focus_mode
== SWM_FOCUS_DEFAULT
)
1356 event_drain(XCB_ENTER_NOTIFY
);
1362 get_atom_from_string(const char *str
)
1364 xcb_intern_atom_cookie_t c
;
1365 xcb_intern_atom_reply_t
*r
;
1368 c
= xcb_intern_atom(conn
, 0, strlen(str
), str
);
1369 r
= xcb_intern_atom_reply(conn
, c
, NULL
);
1377 return (XCB_ATOM_NONE
);
1381 get_wm_protocols(struct ws_win
*win
) {
1383 xcb_icccm_get_wm_protocols_reply_t wpr
;
1385 if (xcb_icccm_get_wm_protocols_reply(conn
,
1386 xcb_icccm_get_wm_protocols(conn
, win
->id
, a_prot
),
1388 for (i
= 0; i
< (int)wpr
.atoms_len
; i
++) {
1389 if (wpr
.atoms
[i
] == a_takefocus
)
1390 win
->take_focus
= true;
1391 if (wpr
.atoms
[i
] == a_delete
)
1392 win
->can_delete
= true;
1394 xcb_icccm_get_wm_protocols_reply_wipe(&wpr
);
1401 xcb_window_t root
, win
;
1402 int i
, j
, num_screens
;
1404 for (i
= 0; i
< LENGTH(ewmh
); i
++)
1405 ewmh
[i
].atom
= get_atom_from_string(ewmh
[i
].name
);
1407 num_screens
= get_screen_count();
1408 for (i
= 0; i
< num_screens
; i
++) {
1409 root
= screens
[i
].root
;
1411 /* Set up _NET_SUPPORTING_WM_CHECK. */
1412 win
= xcb_generate_id(conn
);
1413 xcb_create_window(conn
, XCB_COPY_FROM_PARENT
, win
, root
,
1414 0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT
,
1415 XCB_COPY_FROM_PARENT
, 0, NULL
);
1417 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, root
,
1418 a_net_wm_check
, XCB_ATOM_WINDOW
, 32, 1, &win
);
1419 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
,
1420 a_net_wm_check
, XCB_ATOM_WINDOW
, 32, 1, &win
);
1423 * Impersonate LG3D non-reparenting WM, written by Sun, to
1424 * workaround a Java GUI rendering issue.
1426 if (java_workaround
)
1427 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
,
1428 ewmh
[_NET_WM_NAME
].atom
, a_utf8_string
,
1429 8, strlen("LG3D"), "LG3D");
1431 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
,
1432 ewmh
[_NET_WM_NAME
].atom
, a_utf8_string
,
1433 8, strlen("spectrwm"), "spectrwm");
1435 /* Report supported atoms */
1436 xcb_delete_property(conn
, root
, a_net_supported
);
1437 for (j
= 0; j
< LENGTH(ewmh
); j
++)
1438 xcb_change_property(conn
, XCB_PROP_MODE_APPEND
, root
,
1439 a_net_supported
, XCB_ATOM_ATOM
, 32, 1,
1444 ewmh_update_desktops();
1445 ewmh_get_desktop_names();
1453 xcb_get_property_cookie_t pc
;
1454 xcb_get_property_reply_t
*pr
;
1456 num_screens
= get_screen_count();
1458 for (i
= 0; i
< num_screens
; i
++) {
1459 /* Get the support check window and destroy it */
1460 pc
= xcb_get_property(conn
, 0, screens
[i
].root
, a_net_wm_check
,
1461 XCB_ATOM_WINDOW
, 0, 1);
1462 pr
= xcb_get_property_reply(conn
, pc
, NULL
);
1465 if (pr
->format
== a_net_wm_check
) {
1466 id
= *((xcb_window_t
*)xcb_get_property_value(pr
));
1468 xcb_destroy_window(conn
, id
);
1469 xcb_delete_property(conn
, screens
[i
].root
,
1471 xcb_delete_property(conn
, screens
[i
].root
,
1479 ewmh_autoquirk(struct ws_win
*win
)
1481 xcb_get_property_reply_t
*r
;
1482 xcb_get_property_cookie_t c
;
1486 c
= xcb_get_property(conn
, 0, win
->id
,
1487 ewmh
[_NET_WM_WINDOW_TYPE
].atom
, XCB_ATOM_ATOM
, 0, UINT32_MAX
);
1488 r
= xcb_get_property_reply(conn
, c
, NULL
);
1492 type
= xcb_get_property_value(r
);
1493 n
= xcb_get_property_value_length(r
) / sizeof(xcb_atom_t
);
1495 for (i
= 0; i
< n
; i
++) {
1496 if (type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_NORMAL
].atom
)
1498 if (type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_DOCK
].atom
||
1499 type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_TOOLBAR
].atom
||
1500 type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_UTILITY
].atom
) {
1501 win
->quirks
= SWM_Q_FLOAT
| SWM_Q_ANYWHERE
;
1504 if (type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_SPLASH
].atom
||
1505 type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_DIALOG
].atom
) {
1506 win
->quirks
= SWM_Q_FLOAT
;
1514 ewmh_update_actions(struct ws_win
*win
)
1516 xcb_atom_t actions
[SWM_EWMH_ACTION_COUNT_MAX
];
1522 actions
[n
++] = ewmh
[_NET_WM_ACTION_CLOSE
].atom
;
1525 actions
[n
++] = ewmh
[_NET_WM_ACTION_MOVE
].atom
;
1526 actions
[n
++] = ewmh
[_NET_WM_ACTION_RESIZE
].atom
;
1527 actions
[n
++] = ewmh
[_NET_WM_ACTION_ABOVE
].atom
;
1530 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
,
1531 ewmh
[_NET_WM_ALLOWED_ACTIONS
].atom
, XCB_ATOM_ATOM
, 32, 1, actions
);
1534 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1535 #define _NET_WM_STATE_ADD 1 /* add/set property */
1536 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1539 ewmh_change_wm_state(struct ws_win
*win
, xcb_atom_t state
, long action
)
1546 name
= get_atom_name(state
);
1547 DNPRINTF(SWM_D_PROP
, "ewmh_change_wm_state: win %#x, state: %s, "
1548 "action: %ld\n", WINID(win
), name
, action
);
1554 if (state
== ewmh
[_NET_WM_STATE_FULLSCREEN
].atom
)
1555 flag
= EWMH_F_FULLSCREEN
;
1556 else if (state
== ewmh
[_NET_WM_STATE_ABOVE
].atom
)
1557 flag
= EWMH_F_ABOVE
;
1558 else if (state
== ewmh
[_NET_WM_STATE_HIDDEN
].atom
)
1559 flag
= EWMH_F_HIDDEN
;
1560 else if (state
== ewmh
[_NET_WM_STATE_MAXIMIZED_VERT
].atom
||
1561 state
== ewmh
[_NET_WM_STATE_MAXIMIZED_HORZ
].atom
)
1562 flag
= EWMH_F_MAXIMIZED
;
1563 else if (state
== ewmh
[_SWM_WM_STATE_MANUAL
].atom
)
1564 flag
= SWM_F_MANUAL
;
1565 else if (state
== ewmh
[_NET_WM_STATE_SKIP_PAGER
].atom
)
1566 flag
= EWMH_F_SKIP_PAGER
;
1567 else if (state
== ewmh
[_NET_WM_STATE_SKIP_TASKBAR
].atom
)
1568 flag
= EWMH_F_SKIP_TASKBAR
;
1570 /* Disallow unfloating transients. */
1571 if (TRANS(win
) && flag
== EWMH_F_ABOVE
)
1574 new_flags
= win
->ewmh_flags
;
1577 case _NET_WM_STATE_REMOVE
:
1580 case _NET_WM_STATE_ADD
:
1583 case _NET_WM_STATE_TOGGLE
:
1588 ewmh_apply_flags(win
, new_flags
);
1591 DNPRINTF(SWM_D_PROP
, "ewmh_change_wm_state: done.\n");
1595 ewmh_apply_flags(struct ws_win
*win
, uint32_t pending
)
1597 struct workspace
*ws
;
1600 changed
= win
->ewmh_flags
^ pending
;
1604 DNPRINTF(SWM_D_PROP
, "ewmh_apply_flags: pending: %d\n", pending
);
1606 win
->ewmh_flags
= pending
;
1609 if (changed
& EWMH_F_HIDDEN
) {
1611 if (focus_mode
!= SWM_FOCUS_FOLLOW
)
1612 ws
->focus_pending
= get_focus_prev(win
);
1617 /* Reload floating geometry in case region changed. */
1619 load_float_geom(win
);
1621 /* The window is no longer iconic, prepare focus. */
1622 if (focus_mode
!= SWM_FOCUS_FOLLOW
)
1623 ws
->focus_pending
= get_focus_magic(win
);
1628 if (changed
& EWMH_F_ABOVE
) {
1629 if (ws
->cur_layout
!= &layouts
[SWM_MAX_STACK
]) {
1631 load_float_geom(win
);
1632 else if (!MAXIMIZED(win
))
1633 store_float_geom(win
);
1635 win
->ewmh_flags
&= ~EWMH_F_MAXIMIZED
;
1636 changed
&= ~EWMH_F_MAXIMIZED
;
1640 win
->ewmh_flags
^= EWMH_F_ABOVE
& pending
;
1644 if (changed
& EWMH_F_MAXIMIZED
) {
1645 /* VERT and/or HORZ changed. */
1647 if (!MAXIMIZED(win
))
1648 load_float_geom(win
);
1650 store_float_geom(win
);
1653 if (MAXIMIZED(win
)) {
1654 if (focus_mode
!= SWM_FOCUS_FOLLOW
&&
1655 ws
->cur_layout
!= &layouts
[SWM_MAX_STACK
]) {
1659 ws
->focus_pending
= win
;
1663 update_window_color(win
);
1667 if (changed
& EWMH_F_FULLSCREEN
) {
1668 if (FULLSCREEN(win
)) {
1669 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
1673 ws
->focus_pending
= win
;
1676 load_float_geom(win
);
1679 win
->ewmh_flags
&= ~EWMH_F_MAXIMIZED
;
1683 DNPRINTF(SWM_D_PROP
, "ewmh_apply_flags: done.\n");
1687 ewmh_update_wm_state(struct ws_win
*win
) {
1688 xcb_atom_t vals
[SWM_EWMH_ACTION_COUNT_MAX
];
1692 vals
[n
++] = ewmh
[_NET_WM_STATE_HIDDEN
].atom
;
1693 if (FULLSCREEN(win
))
1694 vals
[n
++] = ewmh
[_NET_WM_STATE_FULLSCREEN
].atom
;
1695 if (MAXIMIZED_VERT(win
))
1696 vals
[n
++] = ewmh
[_NET_WM_STATE_MAXIMIZED_VERT
].atom
;
1697 if (MAXIMIZED_HORZ(win
))
1698 vals
[n
++] = ewmh
[_NET_WM_STATE_MAXIMIZED_HORZ
].atom
;
1699 if (win
->ewmh_flags
& EWMH_F_SKIP_PAGER
)
1700 vals
[n
++] = ewmh
[_NET_WM_STATE_SKIP_PAGER
].atom
;
1701 if (win
->ewmh_flags
& EWMH_F_SKIP_TASKBAR
)
1702 vals
[n
++] = ewmh
[_NET_WM_STATE_SKIP_TASKBAR
].atom
;
1703 if (win
->ewmh_flags
& EWMH_F_ABOVE
)
1704 vals
[n
++] = ewmh
[_NET_WM_STATE_ABOVE
].atom
;
1705 if (win
->ewmh_flags
& SWM_F_MANUAL
)
1706 vals
[n
++] = ewmh
[_SWM_WM_STATE_MANUAL
].atom
;
1709 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
,
1710 ewmh
[_NET_WM_STATE
].atom
, XCB_ATOM_ATOM
, 32, n
, vals
);
1712 xcb_delete_property(conn
, win
->id
, ewmh
[_NET_WM_STATE
].atom
);
1716 ewmh_get_wm_state(struct ws_win
*win
)
1719 xcb_get_property_cookie_t c
;
1720 xcb_get_property_reply_t
*r
;
1726 win
->ewmh_flags
= 0;
1728 c
= xcb_get_property(conn
, 0, win
->id
, ewmh
[_NET_WM_STATE
].atom
,
1729 XCB_ATOM_ATOM
, 0, UINT32_MAX
);
1730 r
= xcb_get_property_reply(conn
, c
, NULL
);
1734 states
= xcb_get_property_value(r
);
1735 n
= xcb_get_property_value_length(r
) / sizeof(xcb_atom_t
);
1737 for (i
= 0; i
< n
; i
++)
1738 ewmh_change_wm_state(win
, states
[i
], _NET_WM_STATE_ADD
);
1746 dumpwins(struct swm_region
*r
, union arg
*args
)
1750 xcb_get_window_attributes_cookie_t c
;
1751 xcb_get_window_attributes_reply_t
*wa
;
1753 /* suppress unused warning since var is needed */
1756 if (r
->ws
== NULL
) {
1757 DPRINTF("dumpwins: invalid workspace\n");
1761 DPRINTF("=== managed window list ws %02d ===\n", r
->ws
->idx
);
1762 TAILQ_FOREACH(w
, &r
->ws
->winlist
, entry
) {
1763 state
= get_win_state(w
->id
);
1764 c
= xcb_get_window_attributes(conn
, w
->id
);
1765 wa
= xcb_get_window_attributes_reply(conn
, c
, NULL
);
1767 DPRINTF("win %#x, map_state: %d, state: %u, "
1768 "transient: %#x\n", w
->id
, wa
->map_state
,
1769 state
, w
->transient
);
1772 DPRINTF("win %#x, failed xcb_get_window_attributes\n",
1776 DPRINTF("=== stacking order (top down) === \n");
1777 TAILQ_FOREACH(w
, &r
->ws
->stack
, stack_entry
) {
1778 DPRINTF("win %#x, fs: %s, maximized: %s, above: %s, "
1779 "iconic: %s\n", w
->id
, YESNO(FULLSCREEN(w
)),
1780 YESNO(MAXIMIZED(w
)), YESNO(ABOVE(w
)), YESNO(ICONIC(w
)));
1783 DPRINTF("===== unmanaged window list =====\n");
1784 TAILQ_FOREACH(w
, &r
->ws
->unmanagedlist
, entry
) {
1785 state
= get_win_state(w
->id
);
1786 c
= xcb_get_window_attributes(conn
, w
->id
);
1787 wa
= xcb_get_window_attributes_reply(conn
, c
, NULL
);
1789 DPRINTF("win %#x, map_state: %d, state: %u, "
1790 "transient: %#x\n", w
->id
, wa
->map_state
,
1791 state
, w
->transient
);
1794 DPRINTF("win %#x, failed xcb_get_window_attributes\n",
1798 DPRINTF("=================================\n");
1802 dumpwins(struct swm_region
*r
, union arg
*s
)
1807 #endif /* SWM_DEBUG */
1812 int saved_errno
, status
;
1815 saved_errno
= errno
;
1819 while ((pid
= waitpid(WAIT_ANY
, &status
, WNOHANG
)) != 0) {
1824 if (errno
!= ECHILD
)
1825 warn("sighdlr: waitpid");
1826 #endif /* SWM_DEBUG */
1829 if (pid
== searchpid
)
1833 if (WIFEXITED(status
)) {
1834 if (WEXITSTATUS(status
) != 0)
1835 warnx("sighdlr: child exit status: %d",
1836 WEXITSTATUS(status
));
1838 warnx("sighdlr: child is terminated "
1840 #endif /* SWM_DEBUG */
1854 errno
= saved_errno
;
1860 struct pid_e
*p
= NULL
;
1862 DNPRINTF(SWM_D_MISC
, "find_pid: %d\n", pid
);
1867 TAILQ_FOREACH(p
, &pidlist
, entry
) {
1876 name_to_pixel(int sidx
, const char *colorname
)
1878 uint32_t result
= 0;
1879 char cname
[32] = "#";
1880 xcb_screen_t
*screen
;
1881 xcb_colormap_t cmap
;
1882 xcb_alloc_color_reply_t
*cr
;
1883 xcb_alloc_named_color_reply_t
*nr
;
1884 uint16_t rr
, gg
, bb
;
1886 screen
= get_screen(sidx
);
1887 cmap
= screen
->default_colormap
;
1889 /* color is in format rgb://rr/gg/bb */
1890 if (strncmp(colorname
, "rgb:", 4) == 0) {
1891 if (parse_rgb(colorname
, &rr
, &gg
, &bb
) == -1)
1892 warnx("could not parse rgb %s", colorname
);
1894 cr
= xcb_alloc_color_reply(conn
,
1895 xcb_alloc_color(conn
, cmap
, rr
, gg
, bb
),
1901 warnx("color '%s' not found", colorname
);
1904 nr
= xcb_alloc_named_color_reply(conn
,
1905 xcb_alloc_named_color(conn
, cmap
, strlen(colorname
),
1908 strlcat(cname
, colorname
+ 2, sizeof cname
- 1);
1909 nr
= xcb_alloc_named_color_reply(conn
,
1910 xcb_alloc_named_color(conn
, cmap
, strlen(cname
),
1917 warnx("color '%s' not found", colorname
);
1924 setscreencolor(const char *val
, int i
, int c
)
1926 if (i
< 0 || i
>= get_screen_count())
1929 screens
[i
].c
[c
].pixel
= name_to_pixel(i
, val
);
1930 free(screens
[i
].c
[c
].name
);
1931 if ((screens
[i
].c
[c
].name
= strdup(val
)) == NULL
)
1936 fancy_stacker(struct workspace
*ws
)
1938 strlcpy(ws
->stacker
, "[ ]", sizeof ws
->stacker
);
1939 if (ws
->cur_layout
->l_stack
== vertical_stack
)
1940 snprintf(ws
->stacker
, sizeof ws
->stacker
,
1941 ws
->l_state
.vertical_flip
? "[%d>%d]" : "[%d|%d]",
1942 ws
->l_state
.vertical_mwin
, ws
->l_state
.vertical_stacks
);
1943 else if (ws
->cur_layout
->l_stack
== horizontal_stack
)
1944 snprintf(ws
->stacker
, sizeof ws
->stacker
,
1945 ws
->l_state
.horizontal_flip
? "[%dv%d]" : "[%d-%d]",
1946 ws
->l_state
.horizontal_mwin
, ws
->l_state
.horizontal_stacks
);
1950 plain_stacker(struct workspace
*ws
)
1952 strlcpy(ws
->stacker
, "[ ]", sizeof ws
->stacker
);
1953 if (ws
->cur_layout
->l_stack
== vertical_stack
)
1954 strlcpy(ws
->stacker
, ws
->l_state
.vertical_flip
? "[>]" : "[|]",
1955 sizeof ws
->stacker
);
1956 else if (ws
->cur_layout
->l_stack
== horizontal_stack
)
1957 strlcpy(ws
->stacker
, ws
->l_state
.horizontal_flip
? "[v]" : "[-]",
1958 sizeof ws
->stacker
);
1962 custom_region(const char *val
)
1964 unsigned int x
, y
, w
, h
;
1965 int sidx
, num_screens
;
1966 xcb_screen_t
*screen
;
1968 num_screens
= get_screen_count();
1969 if (sscanf(val
, "screen[%d]:%ux%u+%u+%u", &sidx
, &w
, &h
, &x
, &y
) != 5)
1970 errx(1, "invalid custom region, "
1971 "should be 'screen[<n>]:<n>x<n>+<n>+<n>");
1972 if (sidx
< 1 || sidx
> num_screens
)
1973 errx(1, "invalid screen index: %d out of bounds (maximum %d)",
1977 if ((screen
= get_screen(sidx
)) == NULL
)
1978 errx(1, "ERROR: can't get screen %d.", sidx
);
1981 errx(1, "region %ux%u+%u+%u too small", w
, h
, x
, y
);
1983 if (x
> screen
->width_in_pixels
||
1984 y
> screen
->height_in_pixels
||
1985 w
+ x
> screen
->width_in_pixels
||
1986 h
+ y
> screen
->height_in_pixels
) {
1987 warnx("ignoring region %ux%u+%u+%u - not within screen "
1988 "boundaries (%ux%u)", w
, h
, x
, y
,
1989 screen
->width_in_pixels
, screen
->height_in_pixels
);
1993 new_region(&screens
[sidx
], x
, y
, w
, h
);
1997 socket_setnonblock(int fd
)
2001 if ((flags
= fcntl(fd
, F_GETFL
, 0)) == -1)
2002 err(1, "fcntl F_GETFL");
2003 flags
|= O_NONBLOCK
;
2004 if ((flags
= fcntl(fd
, F_SETFL
, flags
)) == -1)
2005 err(1, "fcntl F_SETFL");
2009 bar_print_legacy(struct swm_region
*r
, const char *s
)
2011 xcb_rectangle_t rect
;
2016 XRectangle ibox
, lbox
;
2020 XmbTextExtents(bar_fs
, s
, len
, &ibox
, &lbox
);
2022 switch (bar_justify
) {
2023 case SWM_BAR_JUSTIFY_LEFT
:
2026 case SWM_BAR_JUSTIFY_CENTER
:
2027 x
= (WIDTH(r
) - lbox
.width
) / 2;
2029 case SWM_BAR_JUSTIFY_RIGHT
:
2030 x
= WIDTH(r
) - lbox
.width
- SWM_BAR_OFFSET
;
2034 if (x
< SWM_BAR_OFFSET
)
2039 rect
.width
= WIDTH(r
->bar
);
2040 rect
.height
= HEIGHT(r
->bar
);
2042 /* clear back buffer */
2043 gcv
[0] = r
->s
->c
[SWM_S_COLOR_BAR
].pixel
;
2044 xcb_change_gc(conn
, r
->s
->bar_gc
, XCB_GC_FOREGROUND
, gcv
);
2045 xcb_poly_fill_rectangle(conn
, r
->bar
->buffer
, r
->s
->bar_gc
, 1, &rect
);
2047 /* draw back buffer */
2048 gcvd
.graphics_exposures
= 0;
2049 draw
= XCreateGC(display
, r
->bar
->buffer
, GCGraphicsExposures
, &gcvd
);
2050 XSetForeground(display
, draw
, r
->s
->c
[SWM_S_COLOR_BAR_FONT
].pixel
);
2051 DRAWSTRING(display
, r
->bar
->buffer
, bar_fs
, draw
,
2052 x
, (bar_fs_extents
->max_logical_extent
.height
- lbox
.height
) / 2 -
2054 XFreeGC(display
, draw
);
2057 xcb_copy_area(conn
, r
->bar
->buffer
, r
->bar
->id
, r
->s
->bar_gc
, 0, 0,
2058 0, 0, WIDTH(r
->bar
), HEIGHT(r
->bar
));
2062 bar_print(struct swm_region
*r
, const char *s
)
2065 xcb_rectangle_t rect
;
2073 XftTextExtentsUtf8(display
, bar_font
, (FcChar8
*)s
, len
, &info
);
2075 switch (bar_justify
) {
2076 case SWM_BAR_JUSTIFY_LEFT
:
2079 case SWM_BAR_JUSTIFY_CENTER
:
2080 x
= (WIDTH(r
) - info
.width
) / 2;
2082 case SWM_BAR_JUSTIFY_RIGHT
:
2083 x
= WIDTH(r
) - info
.width
- SWM_BAR_OFFSET
;
2087 if (x
< SWM_BAR_OFFSET
)
2092 rect
.width
= WIDTH(r
->bar
);
2093 rect
.height
= HEIGHT(r
->bar
);
2095 /* clear back buffer */
2096 gcv
[0] = r
->s
->c
[SWM_S_COLOR_BAR
].pixel
;
2097 xcb_change_gc(conn
, r
->s
->bar_gc
, XCB_GC_FOREGROUND
, gcv
);
2098 xcb_poly_fill_rectangle(conn
, r
->bar
->buffer
, r
->s
->bar_gc
, 1, &rect
);
2100 /* draw back buffer */
2101 draw
= XftDrawCreate(display
, r
->bar
->buffer
,
2102 DefaultVisual(display
, r
->s
->idx
),
2103 DefaultColormap(display
, r
->s
->idx
));
2105 XftDrawStringUtf8(draw
, &bar_font_color
, bar_font
, x
,
2106 (HEIGHT(r
->bar
) + bar_font
->height
) / 2 - bar_font
->descent
,
2109 XftDrawDestroy(draw
);
2112 xcb_copy_area(conn
, r
->bar
->buffer
, r
->bar
->id
, r
->s
->bar_gc
, 0, 0,
2113 0, 0, WIDTH(r
->bar
), HEIGHT(r
->bar
));
2117 bar_extra_stop(void)
2121 bzero(bar_pipe
, sizeof bar_pipe
);
2124 kill(bar_pid
, SIGTERM
);
2127 strlcpy(bar_ext
, "", sizeof bar_ext
);
2132 bar_window_class(char *s
, size_t sz
, struct swm_region
*r
)
2134 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2136 if (r
->ws
->focus
->ch
.class_name
!= NULL
)
2137 strlcat(s
, r
->ws
->focus
->ch
.class_name
, sz
);
2141 bar_window_instance(char *s
, size_t sz
, struct swm_region
*r
)
2143 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2145 if (r
->ws
->focus
->ch
.instance_name
!= NULL
)
2146 strlcat(s
, r
->ws
->focus
->ch
.instance_name
, sz
);
2150 bar_window_class_instance(char *s
, size_t sz
, struct swm_region
*r
)
2152 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2155 bar_window_class(s
, sz
, r
);
2156 strlcat(s
, ":", sz
);
2157 bar_window_instance(s
, sz
, r
);
2161 bar_window_state(char *s
, size_t sz
, struct swm_region
*r
)
2163 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2165 if (MAXIMIZED(r
->ws
->focus
))
2166 strlcat(s
, "(m)", sz
);
2167 else if (ABOVE(r
->ws
->focus
))
2168 strlcat(s
, "(f)", sz
);
2172 bar_window_name(char *s
, size_t sz
, struct swm_region
*r
)
2176 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2179 title
= get_win_name(r
->ws
->focus
->id
);
2180 strlcat(s
, title
, sz
);
2185 get_urgent(struct ws_win
*win
)
2187 xcb_icccm_wm_hints_t hints
;
2188 xcb_get_property_cookie_t c
;
2189 bool urgent
= false;
2192 c
= xcb_icccm_get_wm_hints(conn
, win
->id
);
2193 if (xcb_icccm_get_wm_hints_reply(conn
, c
, &hints
, NULL
))
2194 urgent
= xcb_icccm_wm_hints_get_urgency(&hints
);
2201 bar_urgent(char *s
, size_t sz
)
2204 int i
, j
, num_screens
;
2205 bool urgent
[SWM_WS_MAX
];
2208 for (i
= 0; i
< workspace_limit
; i
++)
2211 num_screens
= get_screen_count();
2212 for (i
= 0; i
< num_screens
; i
++)
2213 for (j
= 0; j
< workspace_limit
; j
++)
2214 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
2215 if (get_urgent(win
))
2218 for (i
= 0; i
< workspace_limit
; i
++) {
2220 snprintf(b
, sizeof b
, "%d ", i
+ 1);
2222 } else if (!urgent_collapse
) {
2223 strlcat(s
, "- ", sz
);
2226 if(urgent_collapse
&& s
[0])
2227 s
[strlen(s
) - 1] = 0;
2231 bar_workspace_name(char *s
, size_t sz
, struct swm_region
*r
)
2233 if (r
== NULL
|| r
->ws
== NULL
)
2235 if (r
->ws
->name
!= NULL
)
2236 strlcat(s
, r
->ws
->name
, sz
);
2239 /* build the default bar format according to the defined enabled options */
2241 bar_fmt(const char *fmtexp
, char *fmtnew
, struct swm_region
*r
, size_t sz
)
2245 /* if format provided, just copy the buffers */
2246 if (bar_format
!= NULL
) {
2247 strlcpy(fmtnew
, fmtexp
, sz
);
2251 /* reset the output buffer */
2254 strlcat(fmtnew
, "+N:+I ", sz
);
2256 strlcat(fmtnew
, "+S", sz
);
2257 strlcat(fmtnew
, " ", sz
);
2259 /* only show the workspace name if there's actually one */
2260 if (r
!= NULL
&& r
->ws
!= NULL
&& r
->ws
->name
!= NULL
)
2261 strlcat(fmtnew
, "<+D>", sz
);
2263 /* If enabled, only show the iconic count if there are iconic wins. */
2264 if (iconic_enabled
&& r
!= NULL
&& r
->ws
!= NULL
)
2265 TAILQ_FOREACH(w
, &r
->ws
->winlist
, entry
)
2267 strlcat(fmtnew
, "{+M}", sz
);
2271 strlcat(fmtnew
, "+3<", sz
);
2273 if (clock_enabled
) {
2274 strlcat(fmtnew
, fmtexp
, sz
);
2275 strlcat(fmtnew
, "+4<", sz
);
2278 /* bar_urgent already adds the space before the last asterisk */
2280 strlcat(fmtnew
, "* +U*+4<", sz
);
2282 if (window_class_enabled
) {
2283 strlcat(fmtnew
, "+C", sz
);
2284 if (!window_instance_enabled
)
2285 strlcat(fmtnew
, "+4<", sz
);
2288 /* checks needed by the colon and floating strlcat(3) calls below */
2289 if (r
!= NULL
&& r
->ws
!= NULL
&& r
->ws
->focus
!= NULL
) {
2290 if (window_instance_enabled
) {
2291 if (window_class_enabled
)
2292 strlcat(fmtnew
, ":", sz
);
2293 strlcat(fmtnew
, "+T+4<", sz
);
2295 if (window_name_enabled
) {
2296 if (ABOVE(r
->ws
->focus
) || MAXIMIZED(r
->ws
->focus
))
2297 strlcat(fmtnew
, "+F ", sz
);
2298 strlcat(fmtnew
, "+64W ", sz
);
2302 /* finally add the action script output and the version */
2303 strlcat(fmtnew
, "+4<+A+4<+V", sz
);
2307 bar_replace_pad(char *tmp
, int *limit
, size_t sz
)
2309 /* special case; no limit given, pad one space, instead */
2310 if (*limit
== (int)sz
- 1)
2312 snprintf(tmp
, sz
, "%*s", *limit
, " ");
2315 /* replaces the bar format character sequences (like in tmux(1)) */
2317 bar_replace_seq(char *fmt
, char *fmtrep
, struct swm_region
*r
, size_t *offrep
,
2322 char tmp
[SWM_BAR_MAX
];
2323 int limit
, size
, count
;
2326 /* reset strlcat(3) buffer */
2329 /* get number, if any */
2332 if (sscanf(fmt
, "%d%n", &limit
, &size
) != 1)
2333 limit
= sizeof tmp
- 1;
2334 if (limit
<= 0 || limit
>= (int)sizeof tmp
)
2335 limit
= sizeof tmp
- 1;
2337 /* there is nothing to replace (ie EOL) */
2344 bar_replace_pad(tmp
, &limit
, sizeof tmp
);
2347 snprintf(tmp
, sizeof tmp
, "%s", bar_ext
);
2350 bar_window_class(tmp
, sizeof tmp
, r
);
2353 bar_workspace_name(tmp
, sizeof tmp
, r
);
2356 bar_window_state(tmp
, sizeof tmp
, r
);
2359 snprintf(tmp
, sizeof tmp
, "%d", r
->ws
->idx
+ 1);
2363 TAILQ_FOREACH(w
, &r
->ws
->winlist
, entry
)
2367 snprintf(tmp
, sizeof tmp
, "%d", count
);
2370 snprintf(tmp
, sizeof tmp
, "%d", r
->s
->idx
+ 1);
2373 bar_window_class_instance(tmp
, sizeof tmp
, r
);
2376 snprintf(tmp
, sizeof tmp
, "%s", r
->ws
->stacker
);
2379 bar_window_instance(tmp
, sizeof tmp
, r
);
2382 bar_urgent(tmp
, sizeof tmp
);
2385 snprintf(tmp
, sizeof tmp
, "%s", bar_vertext
);
2388 bar_window_name(tmp
, sizeof tmp
, r
);
2391 /* unknown character sequence; copy as-is */
2392 snprintf(tmp
, sizeof tmp
, "+%c", *fmt
);
2398 if ((int)len
< limit
)
2400 while (limit
-- > 0) {
2401 if (*offrep
>= sz
- 1)
2403 fmtrep
[(*offrep
)++] = *ptr
++;
2411 bar_replace(char *fmt
, char *fmtrep
, struct swm_region
*r
, size_t sz
)
2416 while (*fmt
!= '\0') {
2418 /* skip ordinary characters */
2421 fmtrep
[off
++] = *fmt
++;
2425 /* character sequence found; replace it */
2426 fmt
= bar_replace_seq(fmt
, fmtrep
, r
, &off
, sz
);
2435 bar_fmt_expand(char *fmtexp
, size_t sz
)
2442 /* start by grabbing the current time and date */
2444 localtime_r(&tmt
, &tm
);
2446 /* figure out what to expand */
2447 if (bar_format
!= NULL
)
2449 else if (bar_format
== NULL
&& clock_enabled
)
2451 /* if nothing to expand bail out */
2457 /* copy as-is, just in case the format shouldn't be expanded below */
2458 strlcpy(fmtexp
, fmt
, sz
);
2459 /* finally pass the string through strftime(3) */
2460 #ifndef SWM_DENY_CLOCK_FORMAT
2461 if ((len
= strftime(fmtexp
, sz
, fmt
, &tm
)) == 0)
2462 warnx("format too long");
2467 /* Redraws the bar; need to follow with xcb_flush() or focus_flush(). */
2471 char fmtexp
[SWM_BAR_MAX
], fmtnew
[SWM_BAR_MAX
];
2472 char fmtrep
[SWM_BAR_MAX
];
2474 struct swm_region
*r
;
2476 /* expand the format by first passing it through strftime(3) */
2477 bar_fmt_expand(fmtexp
, sizeof fmtexp
);
2479 num_screens
= get_screen_count();
2480 for (i
= 0; i
< num_screens
; i
++) {
2481 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
) {
2485 if (bar_enabled
&& r
->ws
->bar_enabled
)
2486 xcb_map_window(conn
, r
->bar
->id
);
2488 xcb_unmap_window(conn
, r
->bar
->id
);
2492 if (startup_exception
)
2493 snprintf(fmtrep
, sizeof fmtrep
, "total "
2494 "exceptions: %d, first exception: %s",
2498 bar_fmt(fmtexp
, fmtnew
, r
, sizeof fmtnew
);
2499 bar_replace(fmtnew
, fmtrep
, r
, sizeof fmtrep
);
2501 if (bar_font_legacy
)
2502 bar_print_legacy(r
, fmtrep
);
2504 bar_print(r
, fmtrep
);
2510 * Reads external script output; call when stdin is readable.
2511 * Returns 1 if bar_ext was updated; otherwise 0.
2514 bar_extra_update(void)
2517 char b
[SWM_BAR_MAX
];
2518 bool changed
= false;
2523 while (fgets(b
, sizeof(b
), stdin
) != NULL
) {
2526 if (b
[len
- 1] == '\n') {
2527 /* Remove newline. */
2530 /* "Clear" bar_ext. */
2533 /* Flush buffered output. */
2534 strlcpy(bar_ext
, bar_ext_buf
, sizeof(bar_ext
));
2535 bar_ext_buf
[0] = '\0';
2537 /* Append new output to bar. */
2538 strlcat(bar_ext
, b
, sizeof(bar_ext
));
2542 /* Buffer output. */
2543 strlcat(bar_ext_buf
, b
, sizeof(bar_ext_buf
));
2548 if (errno
!= EAGAIN
) {
2549 warn("bar_action failed");
2558 bar_toggle(struct swm_region
*r
, union arg
*args
)
2560 struct swm_region
*tmpr
;
2563 /* suppress unused warnings since vars are needed */
2567 DNPRINTF(SWM_D_BAR
, "bar_toggle\n");
2570 case SWM_ARG_ID_BAR_TOGGLE_WS
:
2571 /* Only change if master switch is enabled. */
2573 r
->ws
->bar_enabled
= !r
->ws
->bar_enabled
;
2575 bar_enabled
= r
->ws
->bar_enabled
= true;
2577 case SWM_ARG_ID_BAR_TOGGLE
:
2578 bar_enabled
= !bar_enabled
;
2582 /* update bars as necessary */
2583 num_screens
= get_screen_count();
2584 for (i
= 0; i
< num_screens
; i
++)
2585 TAILQ_FOREACH(tmpr
, &screens
[i
].rl
, entry
)
2587 if (bar_enabled
&& tmpr
->ws
->bar_enabled
)
2588 xcb_map_window(conn
, tmpr
->bar
->id
);
2590 xcb_unmap_window(conn
, tmpr
->bar
->id
);
2595 /* must be after stack */
2602 bar_extra_setup(void)
2604 /* do this here because the conf file is in memory */
2605 if (!bar_extra
&& bar_argv
[0]) {
2606 /* launch external status app */
2608 if (pipe(bar_pipe
) == -1)
2609 err(1, "pipe error");
2610 socket_setnonblock(bar_pipe
[0]);
2611 socket_setnonblock(bar_pipe
[1]); /* XXX hmmm, really? */
2613 /* Set stdin to read from the pipe. */
2614 if (dup2(bar_pipe
[0], STDIN_FILENO
) == -1)
2617 /* Set stdout to write to the pipe. */
2618 if (dup2(bar_pipe
[1], STDOUT_FILENO
) == -1)
2621 if (signal(SIGPIPE
, SIG_IGN
) == SIG_ERR
)
2622 err(1, "could not disable SIGPIPE");
2623 switch (bar_pid
= fork()) {
2625 err(1, "cannot fork");
2629 execvp(bar_argv
[0], bar_argv
);
2630 err(1, "%s external app failed", bar_argv
[0]);
2632 default: /* parent */
2637 atexit(kill_bar_extra_atexit
);
2642 kill_bar_extra_atexit(void)
2645 kill(bar_pid
, SIGTERM
);
2653 while ((s
= index(s
, '-'))) {
2658 return (count
== 14);
2664 char *default_string
;
2665 char **missing_charsets
;
2666 int num_missing_charsets
= 0;
2670 XFreeFontSet(display
, bar_fs
);
2674 DNPRINTF(SWM_D_INIT
, "fontset_init: loading bar_fonts: %s\n", bar_fonts
);
2676 bar_fs
= XCreateFontSet(display
, bar_fonts
, &missing_charsets
,
2677 &num_missing_charsets
, &default_string
);
2679 if (num_missing_charsets
> 0) {
2680 warnx("Unable to load charset(s):");
2682 for (i
= 0; i
< num_missing_charsets
; ++i
)
2683 warnx("%s", missing_charsets
[i
]);
2685 XFreeStringList(missing_charsets
);
2687 if (strcmp(default_string
, ""))
2688 warnx("Glyphs from those sets will be replaced "
2689 "by '%s'.", default_string
);
2691 warnx("Glyphs from those sets won't be drawn.");
2695 errx(1, "Error creating font set structure.");
2697 bar_fs_extents
= XExtentsOfFontSet(bar_fs
);
2699 bar_height
= bar_fs_extents
->max_logical_extent
.height
+
2700 2 * bar_border_width
;
2707 xft_init(struct swm_region
*r
)
2709 char *font
, *d
, *search
;
2712 if (bar_font
== NULL
) {
2713 if ((d
= strdup(bar_fonts
)) == NULL
)
2714 errx(1, "insufficient memory.");
2716 while ((font
= strsep(&search
, ",")) != NULL
) {
2720 DNPRINTF(SWM_D_INIT
, "xft_init: try font %s\n", font
);
2723 bar_font
= XftFontOpenXlfd(display
, r
->s
->idx
,
2726 bar_font
= XftFontOpenName(display
, r
->s
->idx
,
2730 if (bar_font
== NULL
) {
2731 warnx("unable to load font %s", font
);
2734 DNPRINTF(SWM_D_INIT
, "successfully opened "
2742 if (bar_font
== NULL
)
2743 errx(1, "unable to open a font");
2745 PIXEL_TO_XRENDERCOLOR(r
->s
->c
[SWM_S_COLOR_BAR_FONT
].pixel
, color
);
2747 if (!XftColorAllocValue(display
, DefaultVisual(display
, r
->s
->idx
),
2748 DefaultColormap(display
, r
->s
->idx
), &color
, &bar_font_color
))
2749 warn("Xft error: unable to allocate color.");
2751 PIXEL_TO_XRENDERCOLOR(r
->s
->c
[SWM_S_COLOR_BAR
].pixel
, color
);
2753 if (!XftColorAllocValue(display
, DefaultVisual(display
, r
->s
->idx
),
2754 DefaultColormap(display
, r
->s
->idx
), &color
, &search_font_color
))
2755 warn("Xft error: unable to allocate color.");
2757 bar_height
= bar_font
->height
+ 2 * bar_border_width
;
2764 bar_setup(struct swm_region
*r
)
2766 xcb_screen_t
*screen
;
2769 DNPRINTF(SWM_D_BAR
, "bar_setup: screen %d.\n",
2772 if ((screen
= get_screen(r
->s
->idx
)) == NULL
)
2773 errx(1, "ERROR: can't get screen %d.", r
->s
->idx
);
2778 if ((r
->bar
= calloc(1, sizeof(struct swm_bar
))) == NULL
)
2779 err(1, "bar_setup: calloc: failed to allocate memory.");
2781 if (bar_font_legacy
)
2787 Y(r
->bar
) = bar_at_bottom
? (Y(r
) + HEIGHT(r
) - bar_height
) : Y(r
);
2788 WIDTH(r
->bar
) = WIDTH(r
) - 2 * bar_border_width
;
2789 HEIGHT(r
->bar
) = bar_height
- 2 * bar_border_width
;
2791 /* Assume region is unfocused when we create the bar. */
2792 r
->bar
->id
= xcb_generate_id(conn
);
2793 wa
[0] = r
->s
->c
[SWM_S_COLOR_BAR
].pixel
;
2794 wa
[1] = r
->s
->c
[SWM_S_COLOR_BAR_BORDER_UNFOCUS
].pixel
;
2795 wa
[2] = XCB_EVENT_MASK_EXPOSURE
| XCB_EVENT_MASK_POINTER_MOTION
|
2796 XCB_EVENT_MASK_POINTER_MOTION_HINT
;
2798 xcb_create_window(conn
, XCB_COPY_FROM_PARENT
, r
->bar
->id
, r
->s
->root
,
2799 X(r
->bar
), Y(r
->bar
), WIDTH(r
->bar
), HEIGHT(r
->bar
),
2800 bar_border_width
, XCB_WINDOW_CLASS_INPUT_OUTPUT
,
2801 XCB_COPY_FROM_PARENT
, XCB_CW_BACK_PIXEL
| XCB_CW_BORDER_PIXEL
2802 | XCB_CW_EVENT_MASK
, wa
);
2804 /* Stack bar window above region window to start. */
2806 wa
[1] = XCB_STACK_MODE_ABOVE
;
2808 xcb_configure_window(conn
, r
->bar
->id
, XCB_CONFIG_WINDOW_SIBLING
|
2809 XCB_CONFIG_WINDOW_STACK_MODE
, wa
);
2811 r
->bar
->buffer
= xcb_generate_id(conn
);
2812 xcb_create_pixmap(conn
, screen
->root_depth
, r
->bar
->buffer
, r
->bar
->id
,
2813 WIDTH(r
->bar
), HEIGHT(r
->bar
));
2816 xcb_randr_select_input(conn
, r
->bar
->id
,
2817 XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE
);
2820 xcb_map_window(conn
, r
->bar
->id
);
2822 DNPRINTF(SWM_D_BAR
, "bar_setup: win %#x, (x,y) w x h: (%d,%d) "
2823 "%d x %d\n", WINID(r
->bar
), X(r
->bar
), Y(r
->bar
), WIDTH(r
->bar
),
2830 bar_cleanup(struct swm_region
*r
)
2834 xcb_destroy_window(conn
, r
->bar
->id
);
2835 xcb_free_pixmap(conn
, r
->bar
->buffer
);
2841 set_win_state(struct ws_win
*win
, uint8_t state
)
2843 uint16_t data
[2] = { state
, XCB_ATOM_NONE
};
2845 DNPRINTF(SWM_D_EVENT
, "set_win_state: win %#x, state: %u\n",
2851 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
, a_state
,
2852 a_state
, 32, 2, data
);
2856 get_win_state(xcb_window_t w
)
2858 xcb_get_property_reply_t
*r
;
2859 xcb_get_property_cookie_t c
;
2860 uint32_t result
= 0;
2862 c
= xcb_get_property(conn
, 0, w
, a_state
, a_state
, 0L, 2L);
2863 r
= xcb_get_property_reply(conn
, c
, NULL
);
2865 if (r
->type
== a_state
&& r
->format
== 32 && r
->length
== 2)
2866 result
= *((uint32_t *)xcb_get_property_value(r
));
2870 DNPRINTF(SWM_D_MISC
, "get_win_state property: win %#x state %u\n", w
,
2876 version(struct swm_region
*r
, union arg
*args
)
2878 /* suppress unused warnings since vars are needed */
2882 bar_version
= !bar_version
;
2884 snprintf(bar_vertext
, sizeof bar_vertext
,
2885 "Version: %s Build: %s", SPECTRWM_VERSION
, buildstr
);
2887 strlcpy(bar_vertext
, "", sizeof bar_vertext
);
2894 client_msg(struct ws_win
*win
, xcb_atom_t a
, xcb_timestamp_t t
)
2896 xcb_client_message_event_t ev
;
2904 name
= get_atom_name(a
);
2905 DNPRINTF(SWM_D_EVENT
, "client_msg: win %#x, atom: %s(%u), "
2907 win
->id
, name
, a
, t
);
2911 bzero(&ev
, sizeof ev
);
2912 ev
.response_type
= XCB_CLIENT_MESSAGE
;
2913 ev
.window
= win
->id
;
2916 ev
.data
.data32
[0] = a
;
2917 ev
.data
.data32
[1] = t
;
2919 xcb_send_event(conn
, 0, win
->id
,
2920 XCB_EVENT_MASK_NO_EVENT
, (const char *)&ev
);
2923 /* synthetic response to a ConfigureRequest when not making a change */
2925 config_win(struct ws_win
*win
, xcb_configure_request_event_t
*ev
)
2927 xcb_configure_notify_event_t ce
;
2932 /* send notification of unchanged state. */
2933 bzero(&ce
, sizeof(ce
));
2934 ce
.response_type
= XCB_CONFIGURE_NOTIFY
;
2937 ce
.width
= WIDTH(win
);
2938 ce
.height
= HEIGHT(win
);
2939 ce
.override_redirect
= 0;
2944 ce
.window
= win
->id
;
2945 ce
.border_width
= BORDER(win
);
2946 ce
.above_sibling
= XCB_WINDOW_NONE
;
2949 ce
.event
= ev
->window
;
2950 ce
.window
= ev
->window
;
2952 /* make response appear more WM_SIZE_HINTS-compliant */
2953 if (win
->sh
.flags
) {
2954 DNPRINTF(SWM_D_MISC
, "config_win: hints: win %#x,"
2955 " sh.flags: %u, min: %d x %d, max: %d x %d, inc: "
2956 "%d x %d\n", win
->id
, win
->sh
.flags
, SH_MIN_W(win
),
2957 SH_MIN_H(win
), SH_MAX_W(win
), SH_MAX_H(win
),
2958 SH_INC_W(win
), SH_INC_H(win
));
2963 /* the hint may be set... to 0! */
2964 if (SH_MIN_W(win
) > 0 && ce
.width
< SH_MIN_W(win
))
2965 ce
.width
= SH_MIN_W(win
);
2966 if (SH_MIN_H(win
) > 0 && ce
.height
< SH_MIN_H(win
))
2967 ce
.height
= SH_MIN_H(win
);
2972 /* may also be advertized as 0 */
2973 if (SH_MAX_W(win
) > 0 && ce
.width
> SH_MAX_W(win
))
2974 ce
.width
= SH_MAX_W(win
);
2975 if (SH_MAX_H(win
) > 0 && ce
.height
> SH_MAX_H(win
))
2976 ce
.height
= SH_MAX_H(win
);
2979 /* resize increment. */
2981 if (SH_INC_W(win
) > 1 && ce
.width
> SH_INC_W(win
))
2982 ce
.width
-= (ce
.width
- SH_MIN_W(win
)) %
2984 if (SH_INC_H(win
) > 1 && ce
.height
> SH_INC_H(win
))
2985 ce
.height
-= (ce
.height
- SH_MIN_H(win
)) %
2989 /* adjust x and y for requested border_width. */
2990 ce
.x
+= BORDER(win
) - ev
->border_width
;
2991 ce
.y
+= BORDER(win
) - ev
->border_width
;
2992 ce
.border_width
= ev
->border_width
;
2993 ce
.above_sibling
= ev
->sibling
;
2996 DNPRINTF(SWM_D_MISC
, "config_win: ewmh: %s, win %#x, (x,y) w x h: "
2997 "(%d,%d) %d x %d, border: %d\n", YESNO(ev
== NULL
), win
->id
, ce
.x
,
2998 ce
.y
, ce
.width
, ce
.height
, ce
.border_width
);
3000 xcb_send_event(conn
, 0, win
->id
, XCB_EVENT_MASK_STRUCTURE_NOTIFY
,
3005 count_win(struct workspace
*ws
, bool count_transient
)
3010 TAILQ_FOREACH(win
, &ws
->winlist
, entry
) {
3011 if (!count_transient
&& FLOATING(win
))
3017 DNPRINTF(SWM_D_MISC
, "count_win: %d\n", count
);
3023 quit(struct swm_region
*r
, union arg
*args
)
3025 /* suppress unused warnings since vars are needed */
3029 DNPRINTF(SWM_D_MISC
, "quit\n");
3034 lower_window(struct ws_win
*win
)
3036 struct ws_win
*target
= NULL
;
3037 struct workspace
*ws
;
3044 DNPRINTF(SWM_D_EVENT
, "lower_window: win %#x\n", win
->id
);
3046 TAILQ_FOREACH(target
, &ws
->stack
, stack_entry
) {
3047 if (target
== win
|| ICONIC(target
))
3049 if (ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
3052 if (win
->transient
== target
->transient
)
3054 if (win
->transient
== target
->id
)
3057 if (FULLSCREEN(target
))
3059 if (FULLSCREEN(win
))
3061 if (MAXIMIZED(target
))
3065 if (ABOVE(target
) || TRANS(target
))
3067 if (ABOVE(win
) || TRANS(win
))
3071 /* Change stack position. */
3072 TAILQ_REMOVE(&ws
->stack
, win
, stack_entry
);
3074 TAILQ_INSERT_BEFORE(target
, win
, stack_entry
);
3076 TAILQ_INSERT_TAIL(&ws
->stack
, win
, stack_entry
);
3078 update_win_stacking(win
);
3081 if (swm_debug
& SWM_D_STACK
) {
3082 DPRINTF("=== stacking order (top down) === \n");
3083 TAILQ_FOREACH(target
, &ws
->stack
, stack_entry
) {
3084 DPRINTF("win %#x, fs: %s, maximized: %s, above: %s, "
3085 "iconic: %s\n", target
->id
, YESNO(FULLSCREEN(target
)),
3086 YESNO(MAXIMIZED(target
)), YESNO(ABOVE(target
)),
3087 YESNO(ICONIC(target
)));
3091 DNPRINTF(SWM_D_EVENT
, "lower_window: done\n");
3095 raise_window(struct ws_win
*win
)
3097 struct ws_win
*target
= NULL
;
3098 struct workspace
*ws
;
3104 DNPRINTF(SWM_D_EVENT
, "raise_window: win %#x\n", win
->id
);
3106 TAILQ_FOREACH(target
, &ws
->stack
, stack_entry
) {
3107 if (target
== win
|| ICONIC(target
))
3109 if (ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
3111 if (TRANS(win
) && (win
->transient
== target
->transient
||
3112 win
->transient
== target
->id
))
3114 if (FULLSCREEN(win
))
3116 if (FULLSCREEN(target
))
3120 if (MAXIMIZED(target
))
3122 if (ABOVE(win
) || TRANS(win
) ||
3123 (win
->ws
->focus
== win
&& ws
->always_raise
))
3125 if (!ABOVE(target
) && !TRANS(target
))
3129 TAILQ_REMOVE(&ws
->stack
, win
, stack_entry
);
3131 TAILQ_INSERT_BEFORE(target
, win
, stack_entry
);
3133 TAILQ_INSERT_TAIL(&ws
->stack
, win
, stack_entry
);
3135 update_win_stacking(win
);
3138 if (swm_debug
& SWM_D_STACK
) {
3139 DPRINTF("=== stacking order (top down) === \n");
3140 TAILQ_FOREACH(target
, &ws
->stack
, stack_entry
) {
3141 DPRINTF("win %#x, fs: %s, maximized: %s, above: %s, "
3142 "iconic: %s\n", target
->id
, YESNO(FULLSCREEN(target
)),
3143 YESNO(MAXIMIZED(target
)), YESNO(ABOVE(target
)),
3144 YESNO(ICONIC(target
)));
3148 DNPRINTF(SWM_D_EVENT
, "raise_window: done\n");
3152 update_win_stacking(struct ws_win
*win
)
3154 struct ws_win
*sibling
;
3155 struct swm_region
*r
;
3158 if (win
== NULL
|| (r
= win
->ws
->r
) == NULL
)
3161 sibling
= TAILQ_NEXT(win
, stack_entry
);
3162 if (sibling
!= NULL
&& (FLOATING(win
) == FLOATING(sibling
) ||
3163 (win
->ws
->always_raise
&& win
->ws
->focus
== win
)))
3164 val
[0] = sibling
->id
;
3165 else if (FLOATING(win
) || (win
->ws
->always_raise
&&
3166 win
->ws
->focus
== win
))
3167 val
[0] = r
->bar
->id
;
3171 DNPRINTF(SWM_D_EVENT
, "update_win_stacking: %#x, sibling %#x\n",
3174 val
[1] = XCB_STACK_MODE_ABOVE
;
3176 xcb_configure_window(conn
, win
->id
, XCB_CONFIG_WINDOW_SIBLING
|
3177 XCB_CONFIG_WINDOW_STACK_MODE
, val
);
3181 map_window(struct ws_win
*win
)
3186 DNPRINTF(SWM_D_EVENT
, "map_window: win %#x, mapped: %s\n",
3187 win
->id
, YESNO(win
->mapped
));
3192 xcb_map_window(conn
, win
->id
);
3193 set_win_state(win
, XCB_ICCCM_WM_STATE_NORMAL
);
3198 unmap_window(struct ws_win
*win
)
3203 DNPRINTF(SWM_D_EVENT
, "unmap_window: win %#x, mapped: %s\n", win
->id
,
3204 YESNO(win
->mapped
));
3209 xcb_unmap_window(conn
, win
->id
);
3210 set_win_state(win
, XCB_ICCCM_WM_STATE_ICONIC
);
3211 win
->mapped
= false;
3218 int i
, j
, num_screens
;
3220 num_screens
= get_screen_count();
3221 for (i
= 0; i
< num_screens
; i
++)
3222 for (j
= 0; j
< workspace_limit
; j
++)
3223 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
3228 fake_keypress(struct ws_win
*win
, xcb_keysym_t keysym
, uint16_t modifiers
)
3230 xcb_key_press_event_t event
;
3231 xcb_keycode_t
*keycode
;
3236 keycode
= xcb_key_symbols_get_keycode(syms
, keysym
);
3238 DNPRINTF(SWM_D_MISC
, "fake_keypress: win %#x, keycode %u\n",
3241 bzero(&event
, sizeof(event
));
3242 event
.event
= win
->id
;
3243 event
.root
= win
->s
->root
;
3244 event
.child
= XCB_WINDOW_NONE
;
3245 event
.time
= XCB_CURRENT_TIME
;
3246 event
.event_x
= X(win
);
3247 event
.event_y
= Y(win
);
3250 event
.same_screen
= 1;
3251 event
.detail
= *keycode
;
3252 event
.state
= modifiers
;
3254 event
.response_type
= XCB_KEY_PRESS
;
3255 xcb_send_event(conn
, 1, win
->id
,
3256 XCB_EVENT_MASK_KEY_PRESS
, (const char *)&event
);
3258 event
.response_type
= XCB_KEY_RELEASE
;
3259 xcb_send_event(conn
, 1, win
->id
,
3260 XCB_EVENT_MASK_KEY_RELEASE
, (const char *)&event
);
3266 restart(struct swm_region
*r
, union arg
*args
)
3268 /* suppress unused warning since var is needed */
3272 DNPRINTF(SWM_D_MISC
, "restart: %s\n", start_argv
[0]);
3276 execvp(start_argv
[0], start_argv
);
3277 warn("execvp failed");
3282 get_pointer_win(xcb_window_t root
)
3284 struct ws_win
*win
= NULL
;
3285 xcb_query_pointer_reply_t
*r
;
3287 DNPRINTF(SWM_D_EVENT
, "get_pointer_win: root: %#x.\n", root
);
3289 r
= xcb_query_pointer_reply(conn
, xcb_query_pointer(conn
, root
), NULL
);
3291 win
= find_window(r
->child
);
3293 DNPRINTF(SWM_D_EVENT
, "get_pointer_win: %#x.\n",
3296 DNPRINTF(SWM_D_EVENT
, "get_pointer_win: none.\n");
3305 center_pointer(struct swm_region
*r
)
3309 if (!warp_pointer
|| r
== NULL
)
3314 DNPRINTF(SWM_D_EVENT
, "center_pointer: win %#x.\n", WINID(win
));
3316 if (win
&& win
->mapped
)
3317 xcb_warp_pointer(conn
, XCB_NONE
, win
->id
, 0, 0, 0, 0,
3318 WIDTH(win
) / 2, HEIGHT(win
) / 2);
3320 xcb_warp_pointer(conn
, XCB_NONE
, r
->id
, 0, 0, 0, 0,
3321 WIDTH(r
) / 2, HEIGHT(r
) / 2);
3325 root_to_region(xcb_window_t root
, int check
)
3328 struct swm_region
*r
= NULL
;
3330 xcb_query_pointer_reply_t
*qpr
;
3331 xcb_get_input_focus_reply_t
*gifr
;
3333 DNPRINTF(SWM_D_MISC
, "root_to_region: win %#x\n", root
);
3335 num_screens
= get_screen_count();
3336 for (i
= 0; i
< num_screens
; i
++)
3337 if (screens
[i
].root
== root
)
3340 if (check
& SWM_CK_REGION
)
3341 r
= screens
[i
].r_focus
;
3343 if (r
== NULL
&& check
& SWM_CK_FOCUS
) {
3344 /* Try to find an actively focused window */
3345 gifr
= xcb_get_input_focus_reply(conn
,
3346 xcb_get_input_focus(conn
), NULL
);
3348 cfw
= find_window(gifr
->focus
);
3349 if (cfw
&& cfw
->ws
->r
)
3356 if (r
== NULL
&& check
& SWM_CK_POINTER
) {
3357 /* No region with an active focus; try to use pointer. */
3358 qpr
= xcb_query_pointer_reply(conn
, xcb_query_pointer(conn
,
3359 screens
[i
].root
), NULL
);
3361 DNPRINTF(SWM_D_MISC
, "root_to_region: pointer: "
3362 "(%d,%d)\n", qpr
->root_x
, qpr
->root_y
);
3363 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
3364 if (X(r
) <= qpr
->root_x
&&
3365 qpr
->root_x
< MAX_X(r
) &&
3366 Y(r
) <= qpr
->root_y
&&
3367 qpr
->root_y
< MAX_Y(r
))
3374 if (r
== NULL
&& check
& SWM_CK_FALLBACK
)
3375 r
= TAILQ_FIRST(&screens
[i
].rl
);
3377 DNPRINTF(SWM_D_MISC
, "root_to_region: idx: %d\n", get_region_index(r
));
3383 find_unmanaged_window(xcb_window_t id
)
3386 int i
, j
, num_screens
;
3388 num_screens
= get_screen_count();
3389 for (i
= 0; i
< num_screens
; i
++)
3390 for (j
= 0; j
< workspace_limit
; j
++)
3391 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].unmanagedlist
,
3399 find_window(xcb_window_t id
)
3402 int i
, j
, num_screens
;
3403 xcb_query_tree_reply_t
*r
;
3405 num_screens
= get_screen_count();
3406 for (i
= 0; i
< num_screens
; i
++)
3407 for (j
= 0; j
< workspace_limit
; j
++)
3408 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
3412 r
= xcb_query_tree_reply(conn
, xcb_query_tree(conn
, id
), NULL
);
3416 /* if we were looking for the parent return that window instead */
3417 if (r
->parent
== 0 || r
->root
== r
->parent
) {
3422 /* look for parent */
3423 for (i
= 0; i
< num_screens
; i
++)
3424 for (j
= 0; j
< workspace_limit
; j
++)
3425 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
3426 if (r
->parent
== win
->id
) {
3436 spawn(int ws_idx
, union arg
*args
, bool close_fd
)
3441 DNPRINTF(SWM_D_MISC
, "spawn: %s\n", args
->argv
[0]);
3443 close(xcb_get_file_descriptor(conn
));
3445 setenv("LD_PRELOAD", SWM_LIB
, 1);
3447 if (asprintf(&ret
, "%d", ws_idx
) == -1) {
3448 warn("spawn: asprintf SWM_WS");
3451 setenv("_SWM_WS", ret
, 1);
3455 if (asprintf(&ret
, "%d", getpid()) == -1) {
3456 warn("spawn: asprintf _SWM_PID");
3459 setenv("_SWM_PID", ret
, 1);
3463 if (setsid() == -1) {
3464 warn("spawn: setsid");
3470 * close stdin and stdout to prevent interaction between apps
3471 * and the baraction script
3472 * leave stderr open to record errors
3474 if ((fd
= open(_PATH_DEVNULL
, O_RDWR
, 0)) == -1) {
3475 warn("spawn: open");
3478 dup2(fd
, STDIN_FILENO
);
3479 dup2(fd
, STDOUT_FILENO
);
3484 execvp(args
->argv
[0], args
->argv
);
3486 warn("spawn: execvp");
3491 kill_refs(struct ws_win
*win
)
3493 int i
, x
, num_screens
;
3494 struct swm_region
*r
;
3495 struct workspace
*ws
;
3500 num_screens
= get_screen_count();
3501 for (i
= 0; i
< num_screens
; i
++)
3502 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
3503 for (x
= 0; x
< workspace_limit
; x
++) {
3505 if (win
== ws
->focus
)
3507 if (win
== ws
->focus_prev
)
3508 ws
->focus_prev
= NULL
;
3513 validate_win(struct ws_win
*testwin
)
3516 struct workspace
*ws
;
3517 struct swm_region
*r
;
3518 int i
, x
, num_screens
;
3520 if (testwin
== NULL
)
3523 num_screens
= get_screen_count();
3524 for (i
= 0; i
< num_screens
; i
++)
3525 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
3526 for (x
= 0; x
< workspace_limit
; x
++) {
3528 TAILQ_FOREACH(win
, &ws
->winlist
, entry
)
3536 validate_ws(struct workspace
*testws
)
3538 struct swm_region
*r
;
3539 struct workspace
*ws
;
3540 int i
, x
, num_screens
;
3542 /* validate all ws */
3543 num_screens
= get_screen_count();
3544 for (i
= 0; i
< num_screens
; i
++)
3545 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
3546 for (x
= 0; x
< workspace_limit
; x
++) {
3555 unfocus_win(struct ws_win
*win
)
3557 xcb_window_t none
= XCB_WINDOW_NONE
;
3559 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: win %#x\n", WINID(win
));
3564 if (win
->ws
== NULL
) {
3565 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: NULL ws.\n");
3569 if (validate_ws(win
->ws
)) {
3570 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: invalid ws.\n");
3574 if (win
->ws
->r
== NULL
) {
3575 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: NULL region.\n");
3579 if (validate_win(win
)) {
3580 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: invalid win.\n");
3585 if (win
->ws
->focus
== win
) {
3586 win
->ws
->focus
= NULL
;
3587 win
->ws
->focus_prev
= win
;
3590 if (validate_win(win
->ws
->focus
)) {
3591 kill_refs(win
->ws
->focus
);
3592 win
->ws
->focus
= NULL
;
3595 if (validate_win(win
->ws
->focus_prev
)) {
3596 kill_refs(win
->ws
->focus_prev
);
3597 win
->ws
->focus_prev
= NULL
;
3600 update_window_color(win
);
3602 /* Raise window to "top unfocused position." */
3603 if (win
->ws
->always_raise
)
3606 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->s
->root
,
3607 ewmh
[_NET_ACTIVE_WINDOW
].atom
, XCB_ATOM_WINDOW
, 32, 1, &none
);
3609 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: done.\n");
3613 focus_win(struct ws_win
*win
)
3615 struct ws_win
*cfw
= NULL
, *parent
= NULL
, *w
, *tmpw
;
3616 struct workspace
*ws
;
3617 xcb_get_input_focus_reply_t
*gifr
;
3619 DNPRINTF(SWM_D_FOCUS
, "focus_win: win %#x\n", WINID(win
));
3621 if (win
== NULL
|| win
->ws
== NULL
|| !win
->mapped
)
3626 if (validate_ws(ws
))
3629 if (validate_win(win
)) {
3634 gifr
= xcb_get_input_focus_reply(conn
, xcb_get_input_focus(conn
), NULL
);
3636 cfw
= find_window(gifr
->focus
);
3637 if (cfw
!= NULL
&& cfw
!= win
) {
3638 if (cfw
->ws
!= ws
&& cfw
->ws
->r
!= NULL
) {
3639 /* Change border to unfocused color. */
3640 xcb_change_window_attributes(conn
, cfw
->id
,
3641 XCB_CW_BORDER_PIXEL
,
3642 &cfw
->s
->c
[(MAXIMIZED(cfw
) ?
3643 SWM_S_COLOR_UNFOCUS_MAXIMIZED
:
3644 SWM_S_COLOR_UNFOCUS
)].pixel
);
3652 if (ws
->focus
!= win
) {
3653 if (ws
->focus
&& ws
->focus
!= cfw
)
3654 unfocus_win(ws
->focus
);
3658 /* If this window directs focus to a child window, then clear. */
3659 if (win
->focus_child
)
3660 win
->focus_child
= NULL
;
3662 /* If transient, adjust parent's focus child for focus_magic. */
3664 parent
= find_window(win
->transient
);
3665 if (parent
&& parent
->focus_child
!= win
)
3666 parent
->focus_child
= win
;
3669 if (cfw
!= win
&& ws
->r
!= NULL
) {
3670 /* Set input focus if no input hint, or indicated by hint. */
3671 if (!(win
->hints
.flags
& XCB_ICCCM_WM_HINT_INPUT
) ||
3672 (win
->hints
.flags
& XCB_ICCCM_WM_HINT_INPUT
&&
3674 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
,
3675 win
->id
, last_event_time
);
3677 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
,
3678 ws
->r
->id
, XCB_CURRENT_TIME
);
3680 /* Tell app it can adjust focus to a specific window. */
3681 if (win
->take_focus
) {
3682 /* java is special; always tell parent */
3683 if (TRANS(win
) && win
->java
)
3684 client_msg(parent
, a_takefocus
,
3687 client_msg(win
, a_takefocus
, last_event_time
);
3690 if (ws
->cur_layout
->flags
& SWM_L_MAPONFOCUS
||
3692 /* If a parent exists, map it first. */
3694 raise_window(parent
);
3697 /* Map siblings next. */
3698 TAILQ_FOREACH_SAFE(w
, &ws
->stack
, stack_entry
,
3700 if (w
!= win
&& !ICONIC(w
) &&
3701 w
->transient
== parent
->id
) {
3707 /* Map focused window. */
3711 /* Stack any children of focus window. */
3712 TAILQ_FOREACH_SAFE(w
, &ws
->stack
, stack_entry
, tmpw
)
3713 if (w
->transient
== win
->id
&& !ICONIC(w
)) {
3717 } else if (tile_gap
< 0 && !ABOVE(win
)) {
3719 * Windows overlap in the layout.
3720 * Raise focused win above all tiled wins.
3728 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->s
->root
,
3729 ewmh
[_NET_ACTIVE_WINDOW
].atom
, XCB_ATOM_WINDOW
, 32, 1,
3734 /* Update window border even if workspace is hidden. */
3735 update_window_color(win
);
3740 DNPRINTF(SWM_D_FOCUS
, "focus_win: done.\n");
3743 /* If a child window should have focus instead, return it. */
3745 get_focus_magic(struct ws_win
*win
)
3747 struct ws_win
*parent
= NULL
;
3748 struct ws_win
*child
= NULL
;
3750 DNPRINTF(SWM_D_FOCUS
, "get_focus_magic: win %#x\n", WINID(win
));
3755 parent
= find_window(win
->transient
);
3757 /* If parent prefers focus elsewhere, then try to do so. */
3758 if (parent
&& (child
= parent
->focus_child
)) {
3759 if (validate_win(child
) == 0 && child
->mapped
)
3762 parent
->focus_child
= NULL
;
3766 /* If this window prefers focus elsewhere, then try to do so. */
3767 if ((child
= win
->focus_child
)) {
3768 if (validate_win(child
) == 0 && child
->mapped
)
3771 win
->focus_child
= NULL
;
3778 event_drain(uint8_t rt
)
3780 xcb_generic_event_t
*evt
;
3782 /* ensure all pending requests have been processed before filtering. */
3784 while ((evt
= xcb_poll_for_event(conn
))) {
3785 if (XCB_EVENT_RESPONSE_TYPE(evt
) != rt
)
3793 set_region(struct swm_region
*r
)
3795 struct swm_region
*rf
;
3802 /* Unfocus old region bar. */
3807 xcb_change_window_attributes(conn
, rf
->bar
->id
,
3808 XCB_CW_BORDER_PIXEL
,
3809 &r
->s
->c
[SWM_S_COLOR_BAR_BORDER_UNFOCUS
].pixel
);
3812 if (rf
!= NULL
&& rf
!= r
&& (X(rf
) != X(r
) || Y(rf
) != Y(r
) ||
3813 WIDTH(rf
) != WIDTH(r
) || HEIGHT(rf
) != HEIGHT(r
))) {
3814 /* Set _NET_DESKTOP_GEOMETRY. */
3816 vals
[1] = HEIGHT(r
);
3817 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, r
->s
->root
,
3818 ewmh
[_NET_DESKTOP_GEOMETRY
].atom
, XCB_ATOM_CARDINAL
, 32, 2,
3822 /* Set region bar border to focus_color. */
3823 xcb_change_window_attributes(conn
, r
->bar
->id
,
3824 XCB_CW_BORDER_PIXEL
, &r
->s
->c
[SWM_S_COLOR_BAR_BORDER
].pixel
);
3828 ewmh_update_current_desktop();
3832 focus_region(struct swm_region
*r
)
3835 struct swm_region
*old_r
;
3840 old_r
= r
->s
->r_focus
;
3843 nfw
= get_region_focus(r
);
3847 /* New region is empty; need to manually unfocus win. */
3849 unfocus_win(old_r
->ws
->focus
);
3851 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
, r
->id
,
3854 /* Clear bar since empty. */
3860 switchws(struct swm_region
*r
, union arg
*args
)
3862 struct swm_region
*this_r
, *other_r
;
3864 struct workspace
*new_ws
, *old_ws
;
3865 xcb_window_t none
= XCB_WINDOW_NONE
;
3866 int wsid
= args
->id
;
3867 bool unmap_old
= false;
3872 if (wsid
>= workspace_limit
)
3876 old_ws
= this_r
->ws
;
3877 new_ws
= &this_r
->s
->ws
[wsid
];
3879 DNPRINTF(SWM_D_WS
, "switchws: screen[%d]:%dx%d+%d+%d: %d -> %d\n",
3880 r
->s
->idx
, WIDTH(r
), HEIGHT(r
), X(r
), Y(r
), old_ws
->idx
, wsid
);
3882 if (new_ws
== NULL
|| old_ws
== NULL
)
3884 if (new_ws
== old_ws
)
3887 if ((win
= old_ws
->focus
) != NULL
) {
3888 update_window_color(win
);
3890 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->s
->root
,
3891 ewmh
[_NET_ACTIVE_WINDOW
].atom
, XCB_ATOM_WINDOW
, 32, 1,
3895 other_r
= new_ws
->r
;
3896 if (other_r
== NULL
) {
3897 /* the other workspace is hidden, hide this one */
3901 if (visible_noswap
) {
3902 center_pointer(other_r
);
3906 /* the other ws is visible in another region, exchange them */
3907 other_r
->ws_prior
= new_ws
;
3908 other_r
->ws
= old_ws
;
3909 old_ws
->r
= other_r
;
3911 this_r
->ws_prior
= old_ws
;
3912 this_r
->ws
= new_ws
;
3915 /* Set focus_pending before stacking, if needed. */
3916 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& (!new_ws
->focus_pending
||
3917 validate_win(new_ws
->focus_pending
))) {
3918 new_ws
->focus_pending
= get_region_focus(new_ws
->r
);
3919 new_ws
->focus
= new_ws
->focus_prev
;
3920 new_ws
->focus_prev
= NULL
;
3923 new_ws
->state
= SWM_WS_STATE_MAPPING
;
3926 /* unmap old windows */
3928 TAILQ_FOREACH(win
, &old_ws
->winlist
, entry
)
3930 old_ws
->state
= SWM_WS_STATE_HIDDEN
;
3933 /* if workspaces were swapped, then don't wait to set focus */
3934 if (old_ws
->r
&& focus_mode
!= SWM_FOCUS_FOLLOW
) {
3935 if (new_ws
->focus_pending
) {
3936 focus_win(new_ws
->focus_pending
);
3937 new_ws
->focus_pending
= NULL
;
3941 /* Clear bar and set focus on region input win if new ws is empty. */
3942 if (new_ws
->focus_pending
== NULL
&& new_ws
->focus
== NULL
) {
3943 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
, r
->id
,
3948 ewmh_update_current_desktop();
3952 new_ws
->state
= SWM_WS_STATE_MAPPED
;
3954 DNPRINTF(SWM_D_WS
, "switchws: done.\n");
3958 cyclews(struct swm_region
*r
, union arg
*args
)
3961 struct swm_screen
*s
= r
->s
;
3962 bool cycle_all
= false, mv
= false;
3964 DNPRINTF(SWM_D_WS
, "cyclews: id: %d, screen[%d]:%dx%d+%d+%d, ws: %d\n",
3965 args
->id
, r
->s
->idx
, WIDTH(r
), HEIGHT(r
), X(r
), Y(r
), r
->ws
->idx
);
3971 case SWM_ARG_ID_CYCLEWS_MOVE_UP
:
3974 case SWM_ARG_ID_CYCLEWS_UP_ALL
:
3977 case SWM_ARG_ID_CYCLEWS_UP
:
3978 a
.id
= (a
.id
< workspace_limit
- 1) ? a
.id
+ 1 : 0;
3980 case SWM_ARG_ID_CYCLEWS_MOVE_DOWN
:
3983 case SWM_ARG_ID_CYCLEWS_DOWN_ALL
:
3986 case SWM_ARG_ID_CYCLEWS_DOWN
:
3987 a
.id
= (a
.id
> 0) ? a
.id
- 1 : workspace_limit
- 1;
3994 (!cycle_empty
&& TAILQ_EMPTY(&s
->ws
[a
.id
].winlist
)))
3996 if (!cycle_visible
&& s
->ws
[a
.id
].r
!= NULL
)
4003 } while (a
.id
!= r
->ws
->idx
);
4005 DNPRINTF(SWM_D_FOCUS
, "cyclews: done\n");
4009 priorws(struct swm_region
*r
, union arg
*args
)
4015 DNPRINTF(SWM_D_WS
, "priorws: id: %d, screen[%d]:%dx%d+%d+%d, ws: %d\n",
4016 args
->id
, r
->s
->idx
, WIDTH(r
), HEIGHT(r
), X(r
), Y(r
), r
->ws
->idx
);
4018 if (r
->ws_prior
== NULL
)
4021 a
.id
= r
->ws_prior
->idx
;
4023 DNPRINTF(SWM_D_FOCUS
, "priorws: done\n");
4027 focusrg(struct swm_region
*r
, union arg
*args
)
4029 int ridx
= args
->id
, i
, num_screens
;
4030 struct swm_region
*rr
= NULL
;
4032 num_screens
= get_screen_count();
4033 /* do nothing if we don't have more than one screen */
4034 if (!(num_screens
> 1 || outputs
> 1))
4037 DNPRINTF(SWM_D_FOCUS
, "focusrg: id: %d\n", ridx
);
4039 rr
= TAILQ_FIRST(&r
->s
->rl
);
4040 for (i
= 0; i
< ridx
&& rr
!= NULL
; ++i
)
4041 rr
= TAILQ_NEXT(rr
, entry
);
4049 DNPRINTF(SWM_D_FOCUS
, "focusrg: done\n");
4053 cyclerg(struct swm_region
*r
, union arg
*args
)
4056 struct swm_region
*rr
= NULL
;
4059 num_screens
= get_screen_count();
4060 /* do nothing if we don't have more than one screen */
4061 if (!(num_screens
> 1 || outputs
> 1))
4065 DNPRINTF(SWM_D_FOCUS
, "cyclerg: id: %d, region: %d\n", args
->id
, i
);
4068 case SWM_ARG_ID_CYCLERG_UP
:
4069 case SWM_ARG_ID_CYCLERG_MOVE_UP
:
4070 rr
= TAILQ_NEXT(r
, entry
);
4072 rr
= TAILQ_FIRST(&screens
[i
].rl
);
4074 case SWM_ARG_ID_CYCLERG_DOWN
:
4075 case SWM_ARG_ID_CYCLERG_MOVE_DOWN
:
4076 rr
= TAILQ_PREV(r
, swm_region_list
, entry
);
4078 rr
= TAILQ_LAST(&screens
[i
].rl
, swm_region_list
);
4087 case SWM_ARG_ID_CYCLERG_UP
:
4088 case SWM_ARG_ID_CYCLERG_DOWN
:
4093 case SWM_ARG_ID_CYCLERG_MOVE_UP
:
4094 case SWM_ARG_ID_CYCLERG_MOVE_DOWN
:
4102 DNPRINTF(SWM_D_FOCUS
, "cyclerg: done\n");
4105 /* Sorts transients after parent. */
4107 sort_windows(struct ws_win_list
*wl
)
4109 struct ws_win
*win
, *parent
, *nxt
;
4114 for (win
= TAILQ_FIRST(wl
); win
!= TAILQ_END(wl
); win
= nxt
) {
4115 nxt
= TAILQ_NEXT(win
, entry
);
4117 parent
= find_window(win
->transient
);
4118 if (parent
== NULL
) {
4119 warnx("not possible bug");
4122 TAILQ_REMOVE(wl
, win
, entry
);
4123 TAILQ_INSERT_AFTER(wl
, parent
, win
, entry
);
4129 swapwin(struct swm_region
*r
, union arg
*args
)
4131 struct ws_win
*target
, *source
;
4132 struct ws_win
*cur_focus
;
4133 struct ws_win_list
*wl
;
4135 DNPRINTF(SWM_D_WS
, "swapwin: id: %d, screen[%d]:%dx%d+%d+%d, ws: %d\n",
4136 args
->id
, r
->s
->idx
, WIDTH(r
), HEIGHT(r
), X(r
), Y(r
), r
->ws
->idx
);
4138 cur_focus
= r
->ws
->focus
;
4139 if (cur_focus
== NULL
|| FULLSCREEN(cur_focus
))
4142 /* Adjust stacking in floating layer. */
4143 if (ABOVE(cur_focus
)) {
4145 case SWM_ARG_ID_SWAPPREV
:
4146 target
= TAILQ_PREV(cur_focus
, ws_win_stack
,
4148 if (target
!= NULL
&& FLOATING(target
)) {
4149 TAILQ_REMOVE(&cur_focus
->ws
->stack
, cur_focus
,
4151 TAILQ_INSERT_BEFORE(target
, cur_focus
,
4153 update_win_stacking(cur_focus
);
4157 case SWM_ARG_ID_SWAPNEXT
:
4158 target
= TAILQ_NEXT(cur_focus
, stack_entry
);
4159 if (target
!= NULL
&& FLOATING(target
)) {
4160 TAILQ_REMOVE(&cur_focus
->ws
->stack
, cur_focus
,
4162 TAILQ_INSERT_AFTER(&cur_focus
->ws
->stack
,
4163 target
, cur_focus
, stack_entry
);
4164 update_win_stacking(cur_focus
);
4172 if (r
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
4175 clear_maximized(r
->ws
);
4178 wl
= &source
->ws
->winlist
;
4181 case SWM_ARG_ID_SWAPPREV
:
4183 source
= find_window(source
->transient
);
4184 target
= TAILQ_PREV(source
, ws_win_list
, entry
);
4185 if (target
&& target
->transient
)
4186 target
= find_window(target
->transient
);
4187 TAILQ_REMOVE(wl
, source
, entry
);
4189 TAILQ_INSERT_TAIL(wl
, source
, entry
);
4191 TAILQ_INSERT_BEFORE(target
, source
, entry
);
4193 case SWM_ARG_ID_SWAPNEXT
:
4194 target
= TAILQ_NEXT(source
, entry
);
4195 /* move the parent and let the sort handle the move */
4197 source
= find_window(source
->transient
);
4198 TAILQ_REMOVE(wl
, source
, entry
);
4200 TAILQ_INSERT_HEAD(wl
, source
, entry
);
4202 TAILQ_INSERT_AFTER(wl
, target
, source
, entry
);
4204 case SWM_ARG_ID_SWAPMAIN
:
4205 target
= TAILQ_FIRST(wl
);
4206 if (target
== source
) {
4207 if (source
->ws
->focus_prev
!= NULL
&&
4208 source
->ws
->focus_prev
!= target
)
4209 source
= source
->ws
->focus_prev
;
4213 if (target
== NULL
|| source
== NULL
)
4215 source
->ws
->focus_prev
= target
;
4216 TAILQ_REMOVE(wl
, target
, entry
);
4217 TAILQ_INSERT_BEFORE(source
, target
, entry
);
4218 TAILQ_REMOVE(wl
, source
, entry
);
4219 TAILQ_INSERT_HEAD(wl
, source
, entry
);
4221 case SWM_ARG_ID_MOVELAST
:
4222 TAILQ_REMOVE(wl
, source
, entry
);
4223 TAILQ_INSERT_TAIL(wl
, source
, entry
);
4226 DNPRINTF(SWM_D_MOVE
, "swapwin: invalid id: %d\n", args
->id
);
4231 ewmh_update_client_list();
4237 DNPRINTF(SWM_D_MOVE
, "swapwin: done\n");
4241 get_focus_prev(struct ws_win
*win
)
4243 struct ws_win
*winfocus
= NULL
;
4244 struct ws_win
*cur_focus
= NULL
;
4245 struct ws_win_list
*wl
= NULL
;
4246 struct workspace
*ws
= NULL
;
4248 if (!(win
&& win
->ws
))
4253 cur_focus
= ws
->focus
;
4255 DNPRINTF(SWM_D_FOCUS
, "get_focus_prev: win %#x, cur_focus: %#x, "
4256 "focus_prev: %#x\n", WINID(win
), WINID(cur_focus
),
4257 WINID(ws
->focus_prev
));
4259 /* pickle, just focus on whatever */
4260 if (cur_focus
== NULL
) {
4261 /* use prev_focus if valid */
4262 if (ws
->focus_prev
&& find_window(ws
->focus_prev
->id
))
4263 winfocus
= ws
->focus_prev
;
4267 /* if transient focus on parent */
4268 if (TRANS(cur_focus
)) {
4269 winfocus
= find_window(cur_focus
->transient
);
4273 /* if in max_stack try harder */
4274 if ((win
->quirks
& SWM_Q_FOCUSPREV
) ||
4275 (ws
->cur_layout
->flags
& SWM_L_FOCUSPREV
)) {
4276 if (cur_focus
!= ws
->focus_prev
)
4277 winfocus
= ws
->focus_prev
;
4279 winfocus
= TAILQ_PREV(win
, ws_win_list
, entry
);
4284 DNPRINTF(SWM_D_FOCUS
, "get_focus_prev: focus_close: %d\n", focus_close
);
4286 if (winfocus
== NULL
|| winfocus
== win
) {
4287 switch (focus_close
) {
4288 case SWM_STACK_BOTTOM
:
4289 TAILQ_FOREACH(winfocus
, wl
, entry
)
4290 if (!ICONIC(winfocus
) && winfocus
!= cur_focus
)
4294 TAILQ_FOREACH_REVERSE(winfocus
, wl
, ws_win_list
, entry
)
4295 if (!ICONIC(winfocus
) && winfocus
!= cur_focus
)
4298 case SWM_STACK_ABOVE
:
4299 winfocus
= TAILQ_NEXT(cur_focus
, entry
);
4300 while (winfocus
&& ICONIC(winfocus
))
4301 winfocus
= TAILQ_NEXT(winfocus
, entry
);
4303 if (winfocus
== NULL
) {
4304 if (focus_close_wrap
) {
4305 TAILQ_FOREACH(winfocus
, wl
, entry
)
4306 if (!ICONIC(winfocus
) &&
4307 winfocus
!= cur_focus
)
4310 TAILQ_FOREACH_REVERSE(winfocus
, wl
,
4312 if (!ICONIC(winfocus
) &&
4313 winfocus
!= cur_focus
)
4318 case SWM_STACK_BELOW
:
4319 winfocus
= TAILQ_PREV(cur_focus
, ws_win_list
, entry
);
4320 while (winfocus
&& ICONIC(winfocus
))
4321 winfocus
= TAILQ_PREV(winfocus
, ws_win_list
,
4324 if (winfocus
== NULL
) {
4325 if (focus_close_wrap
) {
4326 TAILQ_FOREACH_REVERSE(winfocus
, wl
,
4328 if (!ICONIC(winfocus
) &&
4329 winfocus
!= cur_focus
)
4332 TAILQ_FOREACH(winfocus
, wl
, entry
)
4333 if (!ICONIC(winfocus
) &&
4334 winfocus
!= cur_focus
)
4342 if (winfocus
== NULL
||
4343 (winfocus
&& (ICONIC(winfocus
) || winfocus
== cur_focus
))) {
4344 if (focus_default
== SWM_STACK_TOP
) {
4345 TAILQ_FOREACH_REVERSE(winfocus
, wl
, ws_win_list
, entry
)
4346 if (!ICONIC(winfocus
) && winfocus
!= cur_focus
)
4349 TAILQ_FOREACH(winfocus
, wl
, entry
)
4350 if (!ICONIC(winfocus
) && winfocus
!= cur_focus
)
4357 return get_focus_magic(winfocus
);
4361 get_region_focus(struct swm_region
*r
)
4363 struct ws_win
*winfocus
= NULL
;
4368 if (r
->ws
->focus
&& !ICONIC(r
->ws
->focus
))
4369 winfocus
= r
->ws
->focus
;
4370 else if (r
->ws
->focus_prev
&& !ICONIC(r
->ws
->focus_prev
))
4371 winfocus
= r
->ws
->focus_prev
;
4373 TAILQ_FOREACH(winfocus
, &r
->ws
->winlist
, entry
)
4374 if (!ICONIC(winfocus
))
4377 return get_focus_magic(winfocus
);
4381 focus(struct swm_region
*r
, union arg
*args
)
4383 struct ws_win
*head
, *cur_focus
= NULL
, *winfocus
= NULL
;
4384 struct ws_win_list
*wl
= NULL
;
4385 struct workspace
*ws
= NULL
;
4392 cur_focus
= r
->ws
->focus
;
4396 DNPRINTF(SWM_D_FOCUS
, "focus: id: %d, cur_focus: %#x\n", args
->id
,
4399 /* Make sure an uniconified window has focus, if one exists. */
4400 if (cur_focus
== NULL
) {
4401 cur_focus
= TAILQ_FIRST(wl
);
4402 while (cur_focus
!= NULL
&& ICONIC(cur_focus
))
4403 cur_focus
= TAILQ_NEXT(cur_focus
, entry
);
4405 DNPRINTF(SWM_D_FOCUS
, "focus: new cur_focus: %#x\n",
4410 case SWM_ARG_ID_FOCUSPREV
:
4411 if (cur_focus
== NULL
)
4414 winfocus
= cur_focus
;
4416 winfocus
= TAILQ_PREV(winfocus
, ws_win_list
, entry
);
4417 if (winfocus
== NULL
)
4418 winfocus
= TAILQ_LAST(wl
, ws_win_list
);
4419 if (winfocus
== cur_focus
)
4421 } while (winfocus
&& (ICONIC(winfocus
) ||
4422 winfocus
->id
== cur_focus
->transient
||
4423 (cur_focus
->transient
!= XCB_WINDOW_NONE
&&
4424 winfocus
->transient
== cur_focus
->transient
) ||
4425 (winfocus
->quirks
& SWM_Q_NOFOCUSCYCLE
)));
4427 case SWM_ARG_ID_FOCUSNEXT
:
4428 if (cur_focus
== NULL
)
4431 winfocus
= cur_focus
;
4433 winfocus
= TAILQ_NEXT(winfocus
, entry
);
4434 if (winfocus
== NULL
)
4435 winfocus
= TAILQ_FIRST(wl
);
4436 if (winfocus
== cur_focus
)
4438 } while (winfocus
&& (ICONIC(winfocus
) ||
4439 winfocus
->id
== cur_focus
->transient
||
4440 (cur_focus
->transient
!= XCB_WINDOW_NONE
&&
4441 winfocus
->transient
== cur_focus
->transient
) ||
4442 (winfocus
->quirks
& SWM_Q_NOFOCUSCYCLE
)));
4444 case SWM_ARG_ID_FOCUSMAIN
:
4445 if (cur_focus
== NULL
)
4448 winfocus
= TAILQ_FIRST(wl
);
4449 if (winfocus
== cur_focus
)
4450 winfocus
= cur_focus
->ws
->focus_prev
;
4452 case SWM_ARG_ID_FOCUSURGENT
:
4453 /* Search forward for the next urgent window. */
4457 for (i
= 0; i
<= workspace_limit
; ++i
) {
4459 head
= TAILQ_FIRST(&r
->s
->ws
[(ws
->idx
+ i
) %
4460 workspace_limit
].winlist
);
4463 if (head
== cur_focus
) {
4465 winfocus
= cur_focus
;
4468 } else if (get_urgent(head
)) {
4473 head
= TAILQ_NEXT(head
, entry
);
4480 /* Switch ws if new focus is on a different ws. */
4481 if (winfocus
&& winfocus
->ws
!= ws
) {
4482 a
.id
= winfocus
->ws
->idx
;
4490 if (clear_maximized(ws
) > 0)
4493 focus_win(get_focus_magic(winfocus
));
4498 DNPRINTF(SWM_D_FOCUS
, "focus: done\n");
4502 cycle_layout(struct swm_region
*r
, union arg
*args
)
4504 struct workspace
*ws
= r
->ws
;
4506 /* suppress unused warning since var is needed */
4509 DNPRINTF(SWM_D_EVENT
, "cycle_layout: workspace: %d\n", ws
->idx
);
4512 if (ws
->cur_layout
->l_stack
== NULL
)
4513 ws
->cur_layout
= &layouts
[0];
4515 clear_maximized(ws
);
4520 focus_win(get_region_focus(r
));
4527 stack_config(struct swm_region
*r
, union arg
*args
)
4529 struct workspace
*ws
= r
->ws
;
4531 DNPRINTF(SWM_D_STACK
, "stack_config: id: %d workspace: %d\n",
4534 if (clear_maximized(ws
) > 0)
4537 if (ws
->cur_layout
->l_config
!= NULL
)
4538 ws
->cur_layout
->l_config(ws
, args
->id
);
4540 if (args
->id
!= SWM_ARG_ID_STACKINIT
)
4550 struct swm_geometry g
;
4551 struct swm_region
*r
, *r_prev
= NULL
;
4558 DNPRINTF(SWM_D_STACK
, "stack: begin\n");
4560 num_screens
= get_screen_count();
4561 for (i
= 0; i
< num_screens
; i
++) {
4565 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
) {
4566 /* Adjust stack area for region bar and padding. */
4568 g
.x
+= region_padding
;
4569 g
.y
+= region_padding
;
4570 g
.w
-= 2 * border_width
+ 2 * region_padding
;
4571 g
.h
-= 2 * border_width
+ 2 * region_padding
;
4572 if (bar_enabled
&& r
->ws
->bar_enabled
) {
4578 DNPRINTF(SWM_D_STACK
, "stack: workspace: %d (screen: "
4579 "%d, region: %d), (x,y) WxH: (%d,%d) %d x %d\n",
4580 r
->ws
->idx
, i
, j
++, g
.x
, g
.y
, g
.w
, g
.h
);
4583 /* Stack bar/input relative to prev. region. */
4584 val
[1] = XCB_STACK_MODE_ABOVE
;
4586 val
[0] = r_prev
->id
;
4587 DNPRINTF(SWM_D_STACK
, "stack: region input %#x "
4588 "relative to %#x.\n", r
->id
, val
[0]);
4589 xcb_configure_window(conn
, r
->id
,
4590 XCB_CONFIG_WINDOW_SIBLING
|
4591 XCB_CONFIG_WINDOW_STACK_MODE
, val
);
4593 val
[0] = r_prev
->bar
->id
;
4594 DNPRINTF(SWM_D_STACK
, "stack: region bar %#x "
4595 "relative to %#x.\n", r
->bar
->id
, val
[0]);
4596 xcb_configure_window(conn
, r
->bar
->id
,
4597 XCB_CONFIG_WINDOW_SIBLING
|
4598 XCB_CONFIG_WINDOW_STACK_MODE
, val
);
4601 r
->ws
->cur_layout
->l_stack(r
->ws
, &g
);
4602 r
->ws
->cur_layout
->l_string(r
->ws
);
4603 /* save r so we can track region changes */
4611 DNPRINTF(SWM_D_STACK
, "stack: end\n");
4615 store_float_geom(struct ws_win
*win
)
4617 if (win
== NULL
|| win
->ws
->r
== NULL
)
4620 /* retain window geom and region geom */
4621 win
->g_float
= win
->g
;
4622 win
->g_float
.x
-= X(win
->ws
->r
);
4623 win
->g_float
.y
-= Y(win
->ws
->r
);
4624 win
->g_floatvalid
= true;
4625 DNPRINTF(SWM_D_MISC
, "store_float_geom: win %#x, g: (%d,%d)"
4626 " %d x %d, g_float: (%d,%d) %d x %d\n", win
->id
, X(win
), Y(win
),
4627 WIDTH(win
), HEIGHT(win
), win
->g_float
.x
, win
->g_float
.y
,
4628 win
->g_float
.w
, win
->g_float
.h
);
4632 load_float_geom(struct ws_win
*win
)
4634 if (win
== NULL
|| win
->ws
->r
== NULL
)
4637 if (win
->g_floatvalid
) {
4638 win
->g
= win
->g_float
;
4639 X(win
) += X(win
->ws
->r
);
4640 Y(win
) += Y(win
->ws
->r
);
4641 DNPRINTF(SWM_D_MISC
, "load_float_geom: win %#x, g: (%d,%d)"
4642 "%d x %d\n", win
->id
, X(win
), Y(win
), WIDTH(win
),
4645 DNPRINTF(SWM_D_MISC
, "load_float_geom: win %#x, g_float "
4646 "is not set.\n", win
->id
);
4651 update_floater(struct ws_win
*win
)
4653 struct workspace
*ws
;
4654 struct swm_region
*r
;
4661 if ((r
= ws
->r
) == NULL
)
4664 DNPRINTF(SWM_D_MISC
, "update_floater: win %#x\n", win
->id
);
4666 win
->bordered
= true;
4668 if (FULLSCREEN(win
)) {
4669 /* _NET_WM_FULLSCREEN: fullscreen without border. */
4670 if (!win
->g_floatvalid
)
4671 store_float_geom(win
);
4674 win
->bordered
= false;
4675 } else if (MAXIMIZED(win
)) {
4676 /* Maximize: like a single stacked window. */
4677 if (!win
->g_floatvalid
)
4678 store_float_geom(win
);
4682 if (bar_enabled
&& ws
->bar_enabled
&& !maximize_hide_bar
) {
4684 Y(win
) += bar_height
;
4685 HEIGHT(win
) -= bar_height
;
4686 } else if (disable_border
) {
4687 win
->bordered
= false;
4690 if (win
->bordered
) {
4691 HEIGHT(win
) -= 2 * border_width
;
4692 WIDTH(win
) -= 2 * border_width
;
4695 /* Normal floating window. */
4696 /* Update geometry if new region. */
4698 load_float_geom(win
);
4700 if ((win
->quirks
& SWM_Q_FULLSCREEN
) &&
4701 WIDTH(win
) >= WIDTH(r
) && HEIGHT(win
) >= HEIGHT(r
)) {
4702 /* Remove border for FULLSCREEN quirk. */
4703 win
->bordered
= false;
4704 } else if (!MANUAL(win
)) {
4705 if (TRANS(win
) && (win
->quirks
& SWM_Q_TRANSSZ
)) {
4706 /* Adjust size on TRANSSZ quirk. */
4707 WIDTH(win
) = (double)WIDTH(r
) * dialog_ratio
;
4708 HEIGHT(win
) = (double)HEIGHT(r
) * dialog_ratio
;
4711 if (!(win
->quirks
& SWM_Q_ANYWHERE
)) {
4713 * Floaters and transients are auto-centred
4714 * unless manually moved, resized or ANYWHERE
4717 X(win
) = X(r
) + (WIDTH(r
) - WIDTH(win
)) / 2 -
4719 Y(win
) = Y(r
) + (HEIGHT(r
) - HEIGHT(win
)) / 2 -
4721 store_float_geom(win
);
4726 /* Ensure at least 1 pixel of the window is in the region. */
4727 region_containment(win
, r
, SWM_CW_ALLSIDES
);
4733 * Send keystrokes to terminal to decrease/increase the font size as the
4734 * window size changes.
4737 adjust_font(struct ws_win
*win
)
4739 if (!(win
->quirks
& SWM_Q_XTERM_FONTADJ
) ||
4740 ABOVE(win
) || TRANS(win
))
4743 if (win
->sh
.width_inc
&& win
->last_inc
!= win
->sh
.width_inc
&&
4744 WIDTH(win
) / win
->sh
.width_inc
< term_width
&&
4745 win
->font_steps
< SWM_MAX_FONT_STEPS
) {
4746 win
->font_size_boundary
[win
->font_steps
] =
4747 (win
->sh
.width_inc
* term_width
) + win
->sh
.base_width
;
4750 win
->last_inc
= win
->sh
.width_inc
;
4751 fake_keypress(win
, XK_KP_Subtract
, XCB_MOD_MASK_SHIFT
);
4752 } else if (win
->font_steps
&& win
->last_inc
!= win
->sh
.width_inc
&&
4753 WIDTH(win
) > win
->font_size_boundary
[win
->font_steps
- 1]) {
4756 win
->last_inc
= win
->sh
.width_inc
;
4757 fake_keypress(win
, XK_KP_Add
, XCB_MOD_MASK_SHIFT
);
4761 #define SWAPXY(g) do { \
4763 tmp = (g)->y; (g)->y = (g)->x; (g)->x = tmp; \
4764 tmp = (g)->h; (g)->h = (g)->w; (g)->w = tmp; \
4767 stack_master(struct workspace
*ws
, struct swm_geometry
*g
, int rot
, bool flip
)
4769 struct swm_geometry win_g
, r_g
= *g
;
4771 int i
, j
, s
, stacks
;
4772 int w_inc
= 1, h_inc
, w_base
= 1, h_base
;
4773 int hrh
, extra
= 0, h_slice
, last_h
= 0;
4774 int split
, colno
, winno
, mwin
, msize
, mscale
;
4775 int remain
, missing
, v_slice
;
4776 bool bordered
= true, reconfigure
= false;
4778 DNPRINTF(SWM_D_STACK
, "stack_master: workspace: %d, rot: %s, "
4779 "flip: %s\n", ws
->idx
, YESNO(rot
), YESNO(flip
));
4781 /* Prepare tiling variables, if needed. */
4782 if ((winno
= count_win(ws
, false)) > 0) {
4783 /* Find first tiled window. */
4784 TAILQ_FOREACH(win
, &ws
->winlist
, entry
)
4785 if (!FLOATING(win
) && !ICONIC(win
))
4788 /* Take into account size hints of first tiled window. */
4790 w_inc
= win
->sh
.width_inc
;
4791 w_base
= win
->sh
.base_width
;
4792 mwin
= ws
->l_state
.horizontal_mwin
;
4793 mscale
= ws
->l_state
.horizontal_msize
;
4794 stacks
= ws
->l_state
.horizontal_stacks
;
4797 w_inc
= win
->sh
.height_inc
;
4798 w_base
= win
->sh
.base_height
;
4799 mwin
= ws
->l_state
.vertical_mwin
;
4800 mscale
= ws
->l_state
.vertical_msize
;
4801 stacks
= ws
->l_state
.vertical_stacks
;
4805 if (stacks
> winno
- mwin
)
4806 stacks
= winno
- mwin
;
4810 h_slice
= r_g
.h
/ SWM_H_SLICE
;
4811 if (mwin
&& winno
> mwin
) {
4812 v_slice
= r_g
.w
/ SWM_V_SLICE
;
4816 win_g
.w
= v_slice
* mscale
;
4818 if (w_inc
> 1 && w_inc
< v_slice
) {
4819 /* Adjust for requested size increment. */
4820 remain
= (win_g
.w
- w_base
) % w_inc
;
4826 win_g
.x
+= r_g
.w
- msize
;
4829 colno
= split
= winno
/ stacks
;
4830 win_g
.w
= ((r_g
.w
- (stacks
* 2 * border_width
) +
4831 2 * border_width
) / stacks
);
4833 hrh
= r_g
.h
/ colno
;
4834 extra
= r_g
.h
- (colno
* hrh
);
4835 win_g
.h
= hrh
- 2 * border_width
;
4836 i
= j
= 0, s
= stacks
;
4839 /* Update window geometry. */
4840 TAILQ_FOREACH(win
, &ws
->winlist
, entry
) {
4844 if (FLOATING(win
)) {
4845 update_floater(win
);
4850 if (split
&& i
== split
) {
4851 colno
= (winno
- mwin
) / stacks
;
4852 if (s
<= (winno
- mwin
) % stacks
)
4855 hrh
= r_g
.h
/ colno
;
4856 extra
= r_g
.h
- (colno
* hrh
);
4859 win_g
.x
+= win_g
.w
+ 2 * border_width
+
4862 win_g
.w
= (r_g
.w
- msize
-
4863 (stacks
* (2 * border_width
+ tile_gap
))) / stacks
;
4865 win_g
.w
+= (r_g
.w
- msize
-
4866 (stacks
* (2 * border_width
+ tile_gap
))) %
4870 win_g
.x
-= win_g
.w
+ 2 * border_width
+
4876 win_g
.h
= hrh
- 2 * border_width
- tile_gap
;
4879 h_inc
= win
->sh
.width_inc
;
4880 h_base
= win
->sh
.base_width
;
4882 h_inc
= win
->sh
.height_inc
;
4883 h_base
= win
->sh
.base_height
;
4886 if (j
== colno
- 1) {
4887 win_g
.h
= hrh
+ extra
;
4888 } else if (h_inc
> 1 && h_inc
< h_slice
) {
4889 /* adjust for window's requested size increment */
4890 remain
= (win_g
.h
- h_base
) % h_inc
;
4891 missing
= h_inc
- remain
;
4893 if (missing
<= extra
|| j
== 0) {
4905 win_g
.y
+= last_h
+ 2 * border_width
+ tile_gap
;
4907 if (disable_border
&& !(bar_enabled
&& ws
->bar_enabled
) &&
4910 win_g
.w
+= 2 * border_width
;
4911 win_g
.h
+= 2 * border_width
;
4917 if (X(win
) != win_g
.y
|| Y(win
) != win_g
.x
||
4918 WIDTH(win
) != win_g
.h
|| HEIGHT(win
) != win_g
.w
) {
4922 WIDTH(win
) = win_g
.h
;
4923 HEIGHT(win
) = win_g
.w
;
4926 if (X(win
) != win_g
.x
|| Y(win
) != win_g
.y
||
4927 WIDTH(win
) != win_g
.w
|| HEIGHT(win
) != win_g
.h
) {
4931 WIDTH(win
) = win_g
.w
;
4932 HEIGHT(win
) = win_g
.h
;
4936 if (bordered
!= win
->bordered
) {
4938 win
->bordered
= bordered
;
4951 /* Stack all windows from bottom up. */
4952 TAILQ_FOREACH_REVERSE(win
, &ws
->stack
, ws_win_stack
, stack_entry
)
4954 update_win_stacking(win
);
4956 /* Map all windows from top down. */
4957 TAILQ_FOREACH(win
, &ws
->stack
, stack_entry
)
4961 DNPRINTF(SWM_D_STACK
, "stack_master: done\n");
4965 vertical_config(struct workspace
*ws
, int id
)
4967 DNPRINTF(SWM_D_STACK
, "vertical_config: id: %d, workspace: %d\n",
4971 case SWM_ARG_ID_STACKRESET
:
4972 case SWM_ARG_ID_STACKINIT
:
4973 ws
->l_state
.vertical_msize
= SWM_V_SLICE
/ 2;
4974 ws
->l_state
.vertical_mwin
= 1;
4975 ws
->l_state
.vertical_stacks
= 1;
4977 case SWM_ARG_ID_MASTERSHRINK
:
4978 if (ws
->l_state
.vertical_msize
> 1)
4979 ws
->l_state
.vertical_msize
--;
4981 case SWM_ARG_ID_MASTERGROW
:
4982 if (ws
->l_state
.vertical_msize
< SWM_V_SLICE
- 1)
4983 ws
->l_state
.vertical_msize
++;
4985 case SWM_ARG_ID_MASTERADD
:
4986 ws
->l_state
.vertical_mwin
++;
4988 case SWM_ARG_ID_MASTERDEL
:
4989 if (ws
->l_state
.vertical_mwin
> 0)
4990 ws
->l_state
.vertical_mwin
--;
4992 case SWM_ARG_ID_STACKBALANCE
:
4993 ws
->l_state
.vertical_msize
= SWM_V_SLICE
/ (ws
->l_state
.vertical_stacks
+ 1);
4995 case SWM_ARG_ID_STACKINC
:
4996 ws
->l_state
.vertical_stacks
++;
4998 case SWM_ARG_ID_STACKDEC
:
4999 if (ws
->l_state
.vertical_stacks
> 1)
5000 ws
->l_state
.vertical_stacks
--;
5002 case SWM_ARG_ID_FLIPLAYOUT
:
5003 ws
->l_state
.vertical_flip
= !ws
->l_state
.vertical_flip
;
5011 vertical_stack(struct workspace
*ws
, struct swm_geometry
*g
)
5013 DNPRINTF(SWM_D_STACK
, "vertical_stack: workspace: %d\n", ws
->idx
);
5015 stack_master(ws
, g
, 0, ws
->l_state
.vertical_flip
);
5019 horizontal_config(struct workspace
*ws
, int id
)
5021 DNPRINTF(SWM_D_STACK
, "horizontal_config: workspace: %d\n", ws
->idx
);
5024 case SWM_ARG_ID_STACKRESET
:
5025 case SWM_ARG_ID_STACKINIT
:
5026 ws
->l_state
.horizontal_mwin
= 1;
5027 ws
->l_state
.horizontal_msize
= SWM_H_SLICE
/ 2;
5028 ws
->l_state
.horizontal_stacks
= 1;
5030 case SWM_ARG_ID_MASTERSHRINK
:
5031 if (ws
->l_state
.horizontal_msize
> 1)
5032 ws
->l_state
.horizontal_msize
--;
5034 case SWM_ARG_ID_MASTERGROW
:
5035 if (ws
->l_state
.horizontal_msize
< SWM_H_SLICE
- 1)
5036 ws
->l_state
.horizontal_msize
++;
5038 case SWM_ARG_ID_MASTERADD
:
5039 ws
->l_state
.horizontal_mwin
++;
5041 case SWM_ARG_ID_MASTERDEL
:
5042 if (ws
->l_state
.horizontal_mwin
> 0)
5043 ws
->l_state
.horizontal_mwin
--;
5045 case SWM_ARG_ID_STACKBALANCE
:
5046 ws
->l_state
.horizontal_msize
= SWM_H_SLICE
/ (ws
->l_state
.horizontal_stacks
+ 1);
5048 case SWM_ARG_ID_STACKINC
:
5049 ws
->l_state
.horizontal_stacks
++;
5051 case SWM_ARG_ID_STACKDEC
:
5052 if (ws
->l_state
.horizontal_stacks
> 1)
5053 ws
->l_state
.horizontal_stacks
--;
5055 case SWM_ARG_ID_FLIPLAYOUT
:
5056 ws
->l_state
.horizontal_flip
= !ws
->l_state
.horizontal_flip
;
5064 horizontal_stack(struct workspace
*ws
, struct swm_geometry
*g
)
5066 DNPRINTF(SWM_D_STACK
, "horizontal_stack: workspace: %d\n", ws
->idx
);
5068 stack_master(ws
, g
, 1, ws
->l_state
.horizontal_flip
);
5071 /* fullscreen view */
5073 max_stack(struct workspace
*ws
, struct swm_geometry
*g
)
5075 struct swm_geometry gg
= *g
;
5076 struct ws_win
*w
, *win
= NULL
, *parent
= NULL
, *tmpw
;
5079 DNPRINTF(SWM_D_STACK
, "max_stack: workspace: %d\n", ws
->idx
);
5084 winno
= count_win(ws
, false);
5085 if (winno
== 0 && count_win(ws
, true) == 0)
5088 /* Figure out which top level window should be visible. */
5089 if (ws
->focus_pending
)
5090 win
= ws
->focus_pending
;
5093 else if (ws
->focus_prev
)
5094 win
= ws
->focus_prev
;
5096 win
= TAILQ_FIRST(&ws
->winlist
);
5098 DNPRINTF(SWM_D_STACK
, "max_stack: focus_pending: %#x, focus: %#x, "
5099 "focus_prev: %#x, first: %#x, win: %#x\n", WINID(ws
->focus_pending
),
5100 WINID(ws
->focus
), WINID(ws
->focus_prev
),
5101 WINID(TAILQ_FIRST(&ws
->winlist
)), win
->id
);
5103 /* Update window geometry. */
5104 TAILQ_FOREACH(w
, &ws
->winlist
, entry
) {
5113 /* Set maximized flag for all maxed windows. */
5114 if (!MAXIMIZED(w
)) {
5115 /* Preserve floating geometry. */
5117 store_float_geom(w
);
5119 ewmh_apply_flags(w
, w
->ewmh_flags
| EWMH_F_MAXIMIZED
);
5120 ewmh_update_wm_state(w
);
5123 /* Only reconfigure if necessary. */
5124 if (X(w
) != gg
.x
|| Y(w
) != gg
.y
|| WIDTH(w
) != gg
.w
||
5125 HEIGHT(w
) != gg
.h
) {
5128 if (disable_border
&& !(bar_enabled
&& ws
->bar_enabled
)) {
5129 w
->bordered
= false;
5130 WIDTH(w
) += 2 * border_width
;
5131 HEIGHT(w
) += 2 * border_width
;
5140 /* If transient, stack parent and its children. */
5141 if (TRANS(win
) && (parent
= find_window(win
->transient
))) {
5142 raise_window(parent
);
5144 TAILQ_FOREACH_SAFE(w
, &ws
->stack
, stack_entry
, tmpw
)
5145 if (w
->transient
== parent
->id
)
5149 /* Make sure focus window is on top. */
5152 /* Stack any children of focus window. */
5153 TAILQ_FOREACH_SAFE(w
, &ws
->stack
, stack_entry
, tmpw
)
5154 if (w
->transient
== win
->id
)
5157 /* Map all windows. */
5158 TAILQ_FOREACH(w
, &ws
->stack
, stack_entry
)
5164 send_to_rg(struct swm_region
*r
, union arg
*args
)
5166 int ridx
= args
->id
, i
, num_screens
;
5167 struct swm_region
*rr
= NULL
;
5170 num_screens
= get_screen_count();
5171 /* do nothing if we don't have more than one screen */
5172 if (!(num_screens
> 1 || outputs
> 1))
5175 DNPRINTF(SWM_D_FOCUS
, "send_to_rg: id: %d\n", ridx
);
5177 rr
= TAILQ_FIRST(&r
->s
->rl
);
5178 for (i
= 0; i
< ridx
&& rr
!= NULL
; ++i
)
5179 rr
= TAILQ_NEXT(rr
, entry
);
5190 region_under(struct swm_screen
*s
, int x
, int y
)
5192 struct swm_region
*r
= NULL
;
5194 TAILQ_FOREACH(r
, &s
->rl
, entry
) {
5195 DNPRINTF(SWM_D_MISC
, "region_under: ws: %d, region g: (%d,%d) "
5196 "%d x %d, coords: (%d,%d)\n", r
->ws
->idx
, X(r
), Y(r
),
5197 WIDTH(r
), HEIGHT(r
), x
, y
);
5198 if (X(r
) <= x
&& x
< MAX_X(r
))
5199 if (Y(r
) <= y
&& y
< MAX_Y(r
))
5206 /* Transfer focused window to target workspace and focus. */
5208 send_to_ws(struct swm_region
*r
, union arg
*args
)
5210 int wsid
= args
->id
;
5211 struct ws_win
*win
= NULL
;
5213 if (r
&& r
->ws
&& r
->ws
->focus
)
5218 DNPRINTF(SWM_D_MOVE
, "send_to_ws: win %#x, ws %d\n", win
->id
, wsid
);
5220 if (wsid
< 0 || wsid
>= workspace_limit
)
5223 if (win
->ws
->idx
== wsid
)
5226 win_to_ws(win
, wsid
, true);
5228 /* Set new focus on target ws. */
5229 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
5230 win
->ws
->focus_prev
= win
->ws
->focus
;
5231 win
->ws
->focus
= win
;
5232 win
->ws
->focus_pending
= NULL
;
5234 if (win
->ws
->focus_prev
)
5235 update_window_color(win
->ws
->focus_prev
);
5238 DNPRINTF(SWM_D_STACK
, "send_to_ws: focus_pending: %#x, focus: %#x, "
5239 "focus_prev: %#x, first: %#x, win: %#x\n",
5240 WINID(r
->ws
->focus_pending
), WINID(r
->ws
->focus
),
5241 WINID(r
->ws
->focus_prev
), WINID(TAILQ_FIRST(&r
->ws
->winlist
)),
5244 ewmh_apply_flags(win
, win
->ewmh_flags
& ~EWMH_F_MAXIMIZED
);
5245 ewmh_update_wm_state(win
);
5247 /* Restack and set new focus on current ws. */
5249 load_float_geom(win
);
5253 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
5254 if (r
->ws
->focus
!= NULL
) {
5255 focus_win(r
->ws
->focus
);
5257 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
, r
->id
,
5268 win_to_ws(struct ws_win
*win
, int wsid
, bool unfocus
)
5270 struct ws_win
*parent
;
5271 struct workspace
*ws
, *nws
, *pws
;
5273 if (wsid
< 0 || wsid
>= workspace_limit
)
5276 if (win
->ws
->idx
== wsid
)
5280 nws
= &win
->s
->ws
[wsid
];
5282 DNPRINTF(SWM_D_MOVE
, "win_to_ws: win %#x, ws %d -> %d\n", win
->id
,
5285 /* Cleanup focus on source ws. */
5286 if (focus_mode
!= SWM_FOCUS_FOLLOW
&&
5287 (ws
->focus
== win
|| ws
->focus_pending
== win
))
5288 ws
->focus_pending
= get_focus_prev(win
);
5290 /* Move the parent if this is a transient window. */
5292 parent
= find_window(win
->transient
);
5295 /* Set new focus in parent's ws if needed. */
5296 if (pws
->focus
== parent
) {
5297 if (focus_mode
!= SWM_FOCUS_FOLLOW
)
5298 pws
->focus_pending
=
5299 get_focus_prev(parent
);
5301 unfocus_win(parent
);
5303 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
5304 pws
->focus
= pws
->focus_pending
;
5305 pws
->focus_pending
= NULL
;
5309 /* Don't unmap parent if new ws is visible */
5311 unmap_window(parent
);
5314 TAILQ_REMOVE(&ws
->winlist
, parent
, entry
);
5315 TAILQ_REMOVE(&ws
->stack
, parent
, stack_entry
);
5316 TAILQ_INSERT_TAIL(&nws
->winlist
, parent
, entry
);
5317 TAILQ_INSERT_TAIL(&nws
->stack
, parent
, stack_entry
);
5320 DNPRINTF(SWM_D_PROP
, "win_to_ws: set property: "
5321 "_NET_WM_DESKTOP: %d\n", wsid
);
5322 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5323 parent
->id
, ewmh
[_NET_WM_DESKTOP
].atom
,
5324 XCB_ATOM_CARDINAL
, 32, 1, &wsid
);
5331 if (ws
->focus_prev
== win
)
5332 ws
->focus_prev
= NULL
;
5334 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& ws
->focus_pending
!= NULL
) {
5335 ws
->focus
= ws
->focus_pending
;
5336 ws
->focus_pending
= NULL
;
5339 /* Don't unmap if new ws is visible */
5344 TAILQ_REMOVE(&ws
->winlist
, win
, entry
);
5345 TAILQ_REMOVE(&ws
->stack
, win
, stack_entry
);
5346 TAILQ_INSERT_TAIL(&nws
->winlist
, win
, entry
);
5347 TAILQ_INSERT_TAIL(&nws
->stack
, win
, stack_entry
);
5350 /* Update the window's workspace property: _NET_WM_DESKTOP */
5351 DNPRINTF(SWM_D_PROP
, "win_to_ws: set property: "
5352 "_NET_WM_DESKTOP: %d\n", wsid
);
5353 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
,
5354 ewmh
[_NET_WM_DESKTOP
].atom
, XCB_ATOM_CARDINAL
, 32, 1, &wsid
);
5356 ewmh_update_client_list();
5358 DNPRINTF(SWM_D_MOVE
, "win_to_ws: done.\n");
5362 pressbutton(struct swm_region
*r
, union arg
*args
)
5364 /* suppress unused warning since var is needed */
5367 xcb_test_fake_input(conn
, XCB_BUTTON_PRESS
, args
->id
,
5368 XCB_CURRENT_TIME
, XCB_WINDOW_NONE
, 0, 0, 0);
5369 xcb_test_fake_input(conn
, XCB_BUTTON_RELEASE
, args
->id
,
5370 XCB_CURRENT_TIME
, XCB_WINDOW_NONE
, 0, 0, 0);
5374 raise_toggle(struct swm_region
*r
, union arg
*args
)
5376 /* Suppress warning. */
5379 if (r
== NULL
|| r
->ws
== NULL
)
5382 if (r
->ws
->focus
&& MAXIMIZED(r
->ws
->focus
))
5385 r
->ws
->always_raise
= !r
->ws
->always_raise
;
5387 /* Update focused win stacking order based on new always_raise value. */
5388 raise_window(r
->ws
->focus
);
5394 iconify(struct swm_region
*r
, union arg
*args
)
5398 /* Suppress warning. */
5401 if ((w
= r
->ws
->focus
) == NULL
)
5404 ewmh_apply_flags(w
, w
->ewmh_flags
| EWMH_F_HIDDEN
);
5405 ewmh_update_wm_state(w
);
5413 get_win_name(xcb_window_t win
)
5416 xcb_get_property_cookie_t c
;
5417 xcb_get_property_reply_t
*r
;
5419 /* First try _NET_WM_NAME for UTF-8. */
5420 c
= xcb_get_property(conn
, 0, win
, ewmh
[_NET_WM_NAME
].atom
,
5421 XCB_GET_PROPERTY_TYPE_ANY
, 0, UINT_MAX
);
5422 r
= xcb_get_property_reply(conn
, c
, NULL
);
5423 if (r
&& r
->type
== XCB_NONE
) {
5425 /* Use WM_NAME instead; no UTF-8. */
5426 c
= xcb_get_property(conn
, 0, win
, XCB_ATOM_WM_NAME
,
5427 XCB_GET_PROPERTY_TYPE_ANY
, 0, UINT_MAX
);
5428 r
= xcb_get_property_reply(conn
, c
, NULL
);
5431 if (r
&& r
->type
!= XCB_NONE
&& r
->length
> 0)
5432 name
= strndup(xcb_get_property_value(r
),
5433 xcb_get_property_value_length(r
));
5438 err(1, "get_win_name: failed to allocate memory.");
5446 uniconify(struct swm_region
*r
, union arg
*args
)
5453 DNPRINTF(SWM_D_MISC
, "uniconify\n");
5455 if (r
== NULL
|| r
->ws
== NULL
)
5458 /* make sure we have anything to uniconify */
5459 TAILQ_FOREACH(win
, &r
->ws
->winlist
, entry
) {
5460 if (win
->ws
== NULL
)
5461 continue; /* should never happen */
5467 DNPRINTF(SWM_D_MISC
, "uniconify: count: %d\n", count
);
5473 search_resp_action
= SWM_SEARCH_UNICONIFY
;
5475 spawn_select(r
, args
, "search", &searchpid
);
5477 if ((lfile
= fdopen(select_list_pipe
[1], "w")) == NULL
)
5480 TAILQ_FOREACH(win
, &r
->ws
->winlist
, entry
) {
5481 if (win
->ws
== NULL
)
5482 continue; /* should never happen */
5486 name
= get_win_name(win
->id
);
5487 fprintf(lfile
, "%s.%u\n", name
, win
->id
);
5495 name_workspace(struct swm_region
*r
, union arg
*args
)
5499 DNPRINTF(SWM_D_MISC
, "name_workspace\n");
5505 search_resp_action
= SWM_SEARCH_NAME_WORKSPACE
;
5507 spawn_select(r
, args
, "name_workspace", &searchpid
);
5509 if ((lfile
= fdopen(select_list_pipe
[1], "w")) == NULL
)
5512 fprintf(lfile
, "%s", "");
5517 search_workspace(struct swm_region
*r
, union arg
*args
)
5520 struct workspace
*ws
;
5523 DNPRINTF(SWM_D_MISC
, "search_workspace\n");
5529 search_resp_action
= SWM_SEARCH_SEARCH_WORKSPACE
;
5531 spawn_select(r
, args
, "search", &searchpid
);
5533 if ((lfile
= fdopen(select_list_pipe
[1], "w")) == NULL
)
5536 for (i
= 0; i
< workspace_limit
; i
++) {
5540 fprintf(lfile
, "%d%s%s\n", ws
->idx
+ 1,
5541 (ws
->name
? ":" : ""), (ws
->name
? ws
->name
: ""));
5548 search_win_cleanup(void)
5550 struct search_window
*sw
= NULL
;
5552 while ((sw
= TAILQ_FIRST(&search_wl
)) != NULL
) {
5553 xcb_destroy_window(conn
, sw
->indicator
);
5554 TAILQ_REMOVE(&search_wl
, sw
, entry
);
5560 search_win(struct swm_region
*r
, union arg
*args
)
5562 struct ws_win
*win
= NULL
;
5563 struct search_window
*sw
= NULL
;
5566 xcb_screen_t
*screen
;
5567 int i
, width
, height
;
5575 XRectangle l_ibox
, l_lbox
;
5577 DNPRINTF(SWM_D_MISC
, "search_win\n");
5580 search_resp_action
= SWM_SEARCH_SEARCH_WINDOW
;
5582 spawn_select(r
, args
, "search", &searchpid
);
5584 if ((lfile
= fdopen(select_list_pipe
[1], "w")) == NULL
)
5587 if ((screen
= get_screen(r
->s
->idx
)) == NULL
)
5588 errx(1, "ERROR: can't get screen %d.", r
->s
->idx
);
5590 TAILQ_INIT(&search_wl
);
5593 TAILQ_FOREACH(win
, &r
->ws
->winlist
, entry
) {
5597 sw
= calloc(1, sizeof(struct search_window
));
5599 warn("search_win: calloc");
5601 search_win_cleanup();
5607 snprintf(s
, sizeof s
, "%d", i
);
5610 w
= xcb_generate_id(conn
);
5611 wa
[0] = r
->s
->c
[SWM_S_COLOR_FOCUS
].pixel
;
5612 wa
[1] = r
->s
->c
[SWM_S_COLOR_UNFOCUS
].pixel
;
5613 wa
[2] = screen
->default_colormap
;
5615 if (bar_font_legacy
) {
5616 XmbTextExtents(bar_fs
, s
, len
, &l_ibox
, &l_lbox
);
5617 width
= l_lbox
.width
+ 4;
5618 height
= bar_fs_extents
->max_logical_extent
.height
+ 4;
5620 XftTextExtentsUtf8(display
, bar_font
, (FcChar8
*)s
, len
,
5622 width
= info
.width
+ 4;
5623 height
= bar_font
->height
+ 4;
5626 xcb_create_window(conn
, screen
->root_depth
, w
, win
->id
, 0, 0,
5627 width
, height
, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT
,
5628 screen
->root_visual
, XCB_CW_BACK_PIXEL
|
5629 XCB_CW_BORDER_PIXEL
| XCB_CW_COLORMAP
, wa
);
5631 xcb_map_window(conn
, w
);
5634 TAILQ_INSERT_TAIL(&search_wl
, sw
, entry
);
5636 if (bar_font_legacy
) {
5637 l_gcv
.graphics_exposures
= 0;
5638 l_draw
= XCreateGC(display
, w
, 0, &l_gcv
);
5640 XSetForeground(display
, l_draw
,
5641 r
->s
->c
[SWM_S_COLOR_BAR
].pixel
);
5643 DRAWSTRING(display
, w
, bar_fs
, l_draw
, 2,
5644 (bar_fs_extents
->max_logical_extent
.height
-
5645 l_lbox
.height
) / 2 - l_lbox
.y
, s
, len
);
5647 XFreeGC(display
, l_draw
);
5650 draw
= XftDrawCreate(display
, w
,
5651 DefaultVisual(display
, r
->s
->idx
),
5652 DefaultColormap(display
, r
->s
->idx
));
5654 XftDrawStringUtf8(draw
, &search_font_color
, bar_font
, 2,
5655 (HEIGHT(r
->bar
) + bar_font
->height
) / 2 -
5656 bar_font
->descent
, (FcChar8
*)s
, len
);
5658 XftDrawDestroy(draw
);
5661 DNPRINTF(SWM_D_MISC
, "search_win: mapped win %#x\n", w
);
5663 fprintf(lfile
, "%d\n", i
);
5673 search_resp_uniconify(const char *resp
, size_t len
)
5679 DNPRINTF(SWM_D_MISC
, "search_resp_uniconify: resp: %s\n", resp
);
5681 TAILQ_FOREACH(win
, &search_r
->ws
->winlist
, entry
) {
5684 name
= get_win_name(win
->id
);
5685 if (asprintf(&s
, "%s.%u", name
, win
->id
) == -1) {
5690 if (strncmp(s
, resp
, len
) == 0) {
5691 /* XXX this should be a callback to generalize */
5692 ewmh_apply_flags(win
, win
->ewmh_flags
& ~EWMH_F_HIDDEN
);
5693 ewmh_update_wm_state(win
);
5703 search_resp_name_workspace(const char *resp
, size_t len
)
5705 struct workspace
*ws
;
5707 DNPRINTF(SWM_D_MISC
, "search_resp_name_workspace: resp: %s\n", resp
);
5709 if (search_r
->ws
== NULL
)
5714 free(search_r
->ws
->name
);
5715 search_r
->ws
->name
= NULL
;
5719 ws
->name
= strdup(resp
);
5720 if (ws
->name
== NULL
) {
5721 DNPRINTF(SWM_D_MISC
, "search_resp_name_workspace: "
5722 "strdup: %s", strerror(errno
));
5726 ewmh_update_desktop_names();
5727 ewmh_get_desktop_names();
5732 ewmh_update_desktop_names(void)
5734 char *name_list
= NULL
, *p
;
5735 int num_screens
, i
, j
, len
= 0, tot
= 0;
5737 num_screens
= get_screen_count();
5738 for (i
= 0; i
< num_screens
; ++i
) {
5739 for (j
= 0; j
< workspace_limit
; ++j
) {
5740 if (screens
[i
].ws
[j
].name
!= NULL
)
5741 len
+= strlen(screens
[i
].ws
[j
].name
);
5745 if((name_list
= calloc(len
, sizeof(char))) == NULL
)
5746 err(1, "update_desktop_names: calloc: failed to "
5747 "allocate memory.");
5750 for (j
= 0; j
< workspace_limit
; ++j
) {
5751 if (screens
[i
].ws
[j
].name
!= NULL
) {
5752 len
= strlen(screens
[i
].ws
[j
].name
);
5753 memcpy(p
, screens
[i
].ws
[j
].name
, len
);
5762 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5763 screens
[i
].root
, ewmh
[_NET_DESKTOP_NAMES
].atom
,
5764 a_utf8_string
, 8, tot
, name_list
);
5774 ewmh_get_desktop_names(void)
5777 xcb_get_property_cookie_t c
;
5778 xcb_get_property_reply_t
*r
;
5779 int num_screens
, i
, j
, n
, k
;
5781 num_screens
= get_screen_count();
5782 for (i
= 0; i
< num_screens
; ++i
) {
5783 for (j
= 0; j
< workspace_limit
; ++j
) {
5784 free(screens
[i
].ws
[j
].name
);
5785 screens
[i
].ws
[j
].name
= NULL
;
5788 c
= xcb_get_property(conn
, 0, screens
[i
].root
,
5789 ewmh
[_NET_DESKTOP_NAMES
].atom
,
5790 a_utf8_string
, 0, UINT32_MAX
);
5791 r
= xcb_get_property_reply(conn
, c
, NULL
);
5795 names
= xcb_get_property_value(r
);
5796 n
= xcb_get_property_value_length(r
);
5798 for (j
= 0, k
= 0; j
< n
; ++j
) {
5799 if (*(names
+ j
) != '\0') {
5800 screens
[i
].ws
[k
].name
= strdup(names
+ j
);
5801 j
+= strlen(names
+ j
);
5810 ewmh_update_client_list(void)
5813 int num_screens
, i
, j
, k
= 0, count
= 0;
5816 num_screens
= get_screen_count();
5817 for (i
= 0; i
< num_screens
; ++i
) {
5818 for (j
= 0; j
< workspace_limit
; ++j
)
5819 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
5822 DNPRINTF(SWM_D_PROP
, "ewmh_update_client_list: win count: %d\n",
5828 wins
= calloc(count
, sizeof(xcb_window_t
));
5830 err(1, "ewmh_update_client_list: calloc: failed to "
5831 "allocate memory.");
5833 for (j
= 0, k
= 0; j
< workspace_limit
; ++j
)
5834 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
5835 wins
[k
++] = win
->id
;
5837 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5838 screens
[i
].root
, ewmh
[_NET_CLIENT_LIST
].atom
,
5839 XCB_ATOM_WINDOW
, 32, count
, wins
);
5846 ewmh_update_current_desktop(void)
5850 num_screens
= get_screen_count();
5851 for (i
= 0; i
< num_screens
; ++i
)
5852 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5853 screens
[i
].root
, ewmh
[_NET_CURRENT_DESKTOP
].atom
,
5854 XCB_ATOM_CARDINAL
, 32, 1, &screens
[i
].r_focus
->ws
->idx
);
5858 ewmh_update_desktops(void)
5860 int num_screens
, i
, j
;
5863 vals
= calloc(workspace_limit
* 2, sizeof(uint32_t));
5865 err(1, "ewmh_update_desktops: calloc: failed to allocate "
5868 num_screens
= get_screen_count();
5869 for (i
= 0; i
< num_screens
; i
++) {
5870 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5871 screens
[i
].root
, ewmh
[_NET_NUMBER_OF_DESKTOPS
].atom
,
5872 XCB_ATOM_CARDINAL
, 32, 1, &workspace_limit
);
5874 for (j
= 0; j
< workspace_limit
; ++j
) {
5875 if (screens
[i
].ws
[j
].r
!= NULL
) {
5876 vals
[j
* 2] = X(screens
[i
].ws
[j
].r
);
5877 vals
[j
* 2 + 1] = Y(screens
[i
].ws
[j
].r
);
5878 } else if (screens
[i
].ws
[j
].old_r
!= NULL
) {
5879 vals
[j
* 2] = X(screens
[i
].ws
[j
].old_r
);
5880 vals
[j
* 2 + 1] = Y(screens
[i
].ws
[j
].old_r
);
5882 vals
[j
* 2] = vals
[j
* 2 + 1] = 0;
5886 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5887 screens
[i
].root
, ewmh
[_NET_DESKTOP_VIEWPORT
].atom
,
5888 XCB_ATOM_CARDINAL
, 32, workspace_limit
* 2, vals
);
5895 search_resp_search_workspace(const char *resp
)
5902 DNPRINTF(SWM_D_MISC
, "search_resp_search_workspace: resp: %s\n", resp
);
5906 DNPRINTF(SWM_D_MISC
, "search_resp_search_workspace: strdup: %s",
5913 ws_idx
= (int)strtonum(q
, 1, workspace_limit
, &errstr
);
5915 DNPRINTF(SWM_D_MISC
, "workspace idx is %s: %s",
5922 switchws(search_r
, &a
);
5926 search_resp_search_window(const char *resp
)
5931 struct search_window
*sw
;
5933 DNPRINTF(SWM_D_MISC
, "search_resp_search_window: resp: %s\n", resp
);
5937 DNPRINTF(SWM_D_MISC
, "search_resp_search_window: strdup: %s",
5942 idx
= (int)strtonum(s
, 1, INT_MAX
, &errstr
);
5944 DNPRINTF(SWM_D_MISC
, "window idx is %s: %s",
5951 TAILQ_FOREACH(sw
, &search_wl
, entry
)
5952 if (idx
== sw
->idx
) {
5958 #define MAX_RESP_LEN 1024
5961 search_do_resp(void)
5967 DNPRINTF(SWM_D_MISC
, "search_do_resp:\n");
5972 if ((resp
= calloc(1, MAX_RESP_LEN
+ 1)) == NULL
) {
5973 warn("search: calloc");
5977 rbytes
= read(select_resp_pipe
[0], resp
, MAX_RESP_LEN
);
5979 warn("search: read error");
5982 resp
[rbytes
] = '\0';
5985 * Older versions of dmenu (Atleast pre 4.4.1) do not send a
5986 * newline, so work around that by sanitizing the resp now.
5988 resp
[strcspn(resp
, "\n")] = '\0';
5991 switch (search_resp_action
) {
5992 case SWM_SEARCH_UNICONIFY
:
5993 search_resp_uniconify(resp
, len
);
5995 case SWM_SEARCH_NAME_WORKSPACE
:
5996 search_resp_name_workspace(resp
, len
);
5998 case SWM_SEARCH_SEARCH_WORKSPACE
:
5999 search_resp_search_workspace(resp
);
6001 case SWM_SEARCH_SEARCH_WINDOW
:
6002 search_resp_search_window(resp
);
6007 if (search_resp_action
== SWM_SEARCH_SEARCH_WINDOW
)
6008 search_win_cleanup();
6010 search_resp_action
= SWM_SEARCH_NONE
;
6011 close(select_resp_pipe
[0]);
6018 wkill(struct swm_region
*r
, union arg
*args
)
6020 DNPRINTF(SWM_D_MISC
, "wkill: win %#x, id: %d\n", WINID(r
->ws
->focus
),
6023 if (r
->ws
->focus
== NULL
)
6026 if (args
->id
== SWM_ARG_ID_KILLWINDOW
)
6027 xcb_kill_client(conn
, r
->ws
->focus
->id
);
6029 if (r
->ws
->focus
->can_delete
)
6030 client_msg(r
->ws
->focus
, a_delete
, 0);
6036 clear_maximized(struct workspace
*ws
)
6041 /* Clear any maximized win(s) on ws, from bottom up. */
6042 TAILQ_FOREACH_REVERSE(w
, &ws
->stack
, ws_win_stack
, stack_entry
)
6044 ewmh_apply_flags(w
, w
->ewmh_flags
& ~EWMH_F_MAXIMIZED
);
6045 ewmh_update_wm_state(w
);
6053 maximize_toggle(struct swm_region
*r
, union arg
*args
)
6055 struct ws_win
*w
= r
->ws
->focus
;
6057 /* suppress unused warning since var is needed */
6063 DNPRINTF(SWM_D_MISC
, "maximize_toggle: win %#x\n", w
->id
);
6068 if (w
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
6071 ewmh_apply_flags(w
, w
->ewmh_flags
^ EWMH_F_MAXIMIZED
);
6072 ewmh_update_wm_state(w
);
6076 if (w
== w
->ws
->focus
)
6081 DNPRINTF(SWM_D_MISC
, "maximize_toggle: done\n");
6085 floating_toggle(struct swm_region
*r
, union arg
*args
)
6087 struct ws_win
*w
= r
->ws
->focus
;
6089 /* suppress unused warning since var is needed */
6095 DNPRINTF(SWM_D_MISC
, "floating_toggle: win %#x\n", w
->id
);
6097 if (FULLSCREEN(w
) || TRANS(w
))
6100 if (w
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
6103 ewmh_apply_flags(w
, w
->ewmh_flags
^ EWMH_F_ABOVE
);
6104 ewmh_update_wm_state(w
);
6108 if (w
== w
->ws
->focus
)
6113 DNPRINTF(SWM_D_MISC
, "floating_toggle: done\n");
6117 region_containment(struct ws_win
*win
, struct swm_region
*r
, int opts
)
6119 struct swm_geometry g
= r
->g
;
6120 int rt
, lt
, tp
, bm
, bw
;
6122 bw
= (opts
& SWM_CW_SOFTBOUNDARY
) ? boundary_width
: 0;
6125 * Perpendicular distance of each side of the window to the respective
6126 * side of the region boundary. Positive values indicate the side of
6127 * the window has passed beyond the region boundary.
6129 rt
= opts
& SWM_CW_RIGHT
? MAX_X(win
) + BORDER(win
) - MAX_X(r
) : bw
;
6130 lt
= opts
& SWM_CW_LEFT
? X(r
) - X(win
) + BORDER(win
) : bw
;
6131 bm
= opts
& SWM_CW_BOTTOM
? MAX_Y(win
) + BORDER(win
) - MAX_Y(r
) : bw
;
6132 tp
= opts
& SWM_CW_TOP
? Y(r
) - Y(win
) + BORDER(win
) : bw
;
6134 DNPRINTF(SWM_D_MISC
, "region_containment: win %#x, rt: %d, lt: %d, "
6135 "bm: %d, tp: %d, SOFTBOUNDARY: %s, HARDBOUNDARY: %s\n", win
->id
, rt
,
6136 lt
, bm
, tp
, YESNO(opts
& SWM_CW_SOFTBOUNDARY
),
6137 YESNO(opts
& SWM_CW_HARDBOUNDARY
));
6140 * Disable containment if any of the flagged sides went beyond the
6141 * containment boundary, or if containment is disabled.
6143 if (!(opts
& SWM_CW_HARDBOUNDARY
|| opts
& SWM_CW_SOFTBOUNDARY
) ||
6144 (bw
!= 0 && ((rt
> bw
) || (lt
> bw
) || (bm
> bw
) || (tp
> bw
)))) {
6145 /* Make sure window has at least 1 pixel in the region */
6146 g
.x
+= 1 - WIDTH(win
);
6147 g
.y
+= 1 - HEIGHT(win
);
6148 g
.w
+= 2 * WIDTH(win
) - 2;
6149 g
.h
+= 2 * HEIGHT(win
) - 2;
6152 constrain_window(win
, &g
, &opts
);
6155 /* Move or resize a window so that flagged side(s) fit into the supplied box. */
6157 constrain_window(struct ws_win
*win
, struct swm_geometry
*b
, int *opts
)
6159 DNPRINTF(SWM_D_MISC
, "constrain_window: win %#x, (x,y) w x h: "
6160 "(%d,%d) %d x %d, box: (x,y) w x h: (%d,%d) %d x %d, rt: %s, "
6161 "lt: %s, bt: %s, tp: %s, allow resize: %s\n", win
->id
, X(win
),
6162 Y(win
), WIDTH(win
), HEIGHT(win
), b
->x
, b
->y
, b
->w
, b
->h
,
6163 YESNO(*opts
& SWM_CW_RIGHT
), YESNO(*opts
& SWM_CW_LEFT
),
6164 YESNO(*opts
& SWM_CW_BOTTOM
), YESNO(*opts
& SWM_CW_TOP
),
6165 YESNO(*opts
& SWM_CW_RESIZABLE
));
6167 if ((*opts
& SWM_CW_RIGHT
) && MAX_X(win
) + BORDER(win
) > b
->x
+ b
->w
) {
6168 if (*opts
& SWM_CW_RESIZABLE
)
6169 WIDTH(win
) = b
->x
+ b
->w
- X(win
) - BORDER(win
);
6171 X(win
) = b
->x
+ b
->w
- WIDTH(win
) - BORDER(win
);
6174 if ((*opts
& SWM_CW_LEFT
) && X(win
) + BORDER(win
) < b
->x
) {
6175 if (*opts
& SWM_CW_RESIZABLE
)
6176 WIDTH(win
) -= b
->x
- X(win
) - BORDER(win
);
6178 X(win
) = b
->x
- BORDER(win
);
6181 if ((*opts
& SWM_CW_BOTTOM
) && MAX_Y(win
) + BORDER(win
) > b
->y
+ b
->h
) {
6182 if (*opts
& SWM_CW_RESIZABLE
)
6183 HEIGHT(win
) = b
->y
+ b
->h
- Y(win
) - BORDER(win
);
6185 Y(win
) = b
->y
+ b
->h
- HEIGHT(win
) - BORDER(win
);
6188 if ((*opts
& SWM_CW_TOP
) && Y(win
) + BORDER(win
) < b
->y
) {
6189 if (*opts
& SWM_CW_RESIZABLE
)
6190 HEIGHT(win
) -= b
->y
- Y(win
) - BORDER(win
);
6192 Y(win
) = b
->y
- BORDER(win
);
6195 if (*opts
& SWM_CW_RESIZABLE
) {
6198 if (HEIGHT(win
) < 1)
6204 update_window_color(struct ws_win
*win
)
6208 if (WS_FOCUSED(win
->ws
) && win
->ws
->focus
== win
)
6209 pixel
= MAXIMIZED(win
) ?
6210 &win
->s
->c
[SWM_S_COLOR_FOCUS_MAXIMIZED
].pixel
:
6211 &win
->s
->c
[SWM_S_COLOR_FOCUS
].pixel
;
6213 pixel
= MAXIMIZED(win
) ?
6214 &win
->s
->c
[SWM_S_COLOR_UNFOCUS_MAXIMIZED
].pixel
:
6215 &win
->s
->c
[SWM_S_COLOR_UNFOCUS
].pixel
;
6217 xcb_change_window_attributes(conn
, win
->id
,
6218 XCB_CW_BORDER_PIXEL
, pixel
);
6222 update_window(struct ws_win
*win
)
6227 mask
= XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
|
6228 XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
|
6229 XCB_CONFIG_WINDOW_BORDER_WIDTH
;
6233 wc
[3] = HEIGHT(win
);
6234 wc
[4] = BORDER(win
);
6236 DNPRINTF(SWM_D_EVENT
, "update_window: win %#x, (x,y) w x h: "
6237 "(%d,%d) %d x %d, bordered: %s\n", win
->id
, wc
[0], wc
[1], wc
[2],
6238 wc
[3], YESNO(win
->bordered
));
6240 xcb_configure_window(conn
, win
->id
, mask
, wc
);
6243 #define SWM_RESIZE_STEPS (50)
6246 resize(struct ws_win
*win
, union arg
*args
)
6248 xcb_timestamp_t timestamp
= 0;
6249 struct swm_region
*r
= NULL
;
6250 struct swm_geometry g
;
6252 int top
= 0, left
= 0;
6254 xcb_cursor_t cursor
;
6255 xcb_query_pointer_reply_t
*xpr
= NULL
;
6256 xcb_generic_event_t
*evt
;
6257 xcb_motion_notify_event_t
*mne
;
6264 if (FULLSCREEN(win
))
6267 /* In max_stack mode, should only resize transients. */
6268 if (win
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
] && !TRANS(win
))
6271 DNPRINTF(SWM_D_EVENT
, "resize: win %#x, floating: %s, "
6272 "transient: %#x\n", win
->id
, YESNO(ABOVE(win
)),
6276 store_float_geom(win
);
6277 else if (!(TRANS(win
) || ABOVE(win
)))
6280 ewmh_apply_flags(win
, (win
->ewmh_flags
| SWM_F_MANUAL
| EWMH_F_ABOVE
) &
6282 ewmh_update_wm_state(win
);
6288 /* It's possible for win to have been freed during focus_flush(). */
6289 if (validate_win(win
)) {
6290 DNPRINTF(SWM_D_EVENT
, "resize: invalid win.\n");
6295 case SWM_ARG_ID_WIDTHSHRINK
:
6296 WIDTH(win
) -= SWM_RESIZE_STEPS
;
6299 case SWM_ARG_ID_WIDTHGROW
:
6300 WIDTH(win
) += SWM_RESIZE_STEPS
;
6303 case SWM_ARG_ID_HEIGHTSHRINK
:
6304 HEIGHT(win
) -= SWM_RESIZE_STEPS
;
6307 case SWM_ARG_ID_HEIGHTGROW
:
6308 HEIGHT(win
) += SWM_RESIZE_STEPS
;
6315 region_containment(win
, r
, SWM_CW_ALLSIDES
| SWM_CW_RESIZABLE
|
6316 SWM_CW_HARDBOUNDARY
);
6318 store_float_geom(win
);
6322 region_containment(win
, r
, SWM_CW_ALLSIDES
| SWM_CW_RESIZABLE
|
6323 SWM_CW_SOFTBOUNDARY
);
6326 /* get cursor offset from window root */
6327 xpr
= xcb_query_pointer_reply(conn
, xcb_query_pointer(conn
, win
->id
),
6334 if (xpr
->win_x
< WIDTH(win
) / 2)
6337 if (xpr
->win_y
< HEIGHT(win
) / 2)
6340 if (args
->id
== SWM_ARG_ID_CENTER
)
6341 cursor
= cursors
[XC_SIZING
].cid
;
6343 cursor
= cursors
[left
? XC_TOP_LEFT_CORNER
:
6344 XC_TOP_RIGHT_CORNER
].cid
;
6346 cursor
= cursors
[left
? XC_BOTTOM_LEFT_CORNER
:
6347 XC_BOTTOM_RIGHT_CORNER
].cid
;
6349 xcb_grab_pointer(conn
, 0, win
->id
, MOUSEMASK
,
6350 XCB_GRAB_MODE_ASYNC
, XCB_GRAB_MODE_ASYNC
, XCB_WINDOW_NONE
, cursor
,
6355 while (resizing
&& (evt
= xcb_wait_for_event(conn
))) {
6356 switch (XCB_EVENT_RESPONSE_TYPE(evt
)) {
6357 case XCB_BUTTON_RELEASE
:
6358 DNPRINTF(SWM_D_EVENT
, "resize: BUTTON_RELEASE\n");
6361 case XCB_MOTION_NOTIFY
:
6362 mne
= (xcb_motion_notify_event_t
*)evt
;
6363 /* cursor offset/delta from start of the operation */
6364 dx
= mne
->root_x
- xpr
->root_x
;
6365 dy
= mne
->root_y
- xpr
->root_y
;
6371 if (args
->id
== SWM_ARG_ID_CENTER
) {
6372 if (g
.h
/ 2 + dy
< 1)
6376 HEIGHT(win
) = g
.h
+ 2 * dy
;
6384 HEIGHT(win
) = g
.h
+ dy
;
6391 if (args
->id
== SWM_ARG_ID_CENTER
) {
6392 if (g
.w
/ 2 + dx
< 1)
6396 WIDTH(win
) = g
.w
+ 2 * dx
;
6404 WIDTH(win
) = g
.w
+ dx
;
6407 /* not free, don't sync more than 120 times / second */
6408 if ((mne
->time
- timestamp
) > (1000 / 120) ) {
6409 timestamp
= mne
->time
;
6410 regionize(win
, mne
->root_x
, mne
->root_y
);
6411 region_containment(win
, r
, SWM_CW_ALLSIDES
|
6412 SWM_CW_RESIZABLE
| SWM_CW_HARDBOUNDARY
|
6413 SWM_CW_SOFTBOUNDARY
);
6420 xcb_allow_events(conn
, XCB_ALLOW_ASYNC_KEYBOARD
,
6421 ((xcb_key_press_event_t
*)evt
)->time
);
6427 /* It's possible for win to have been freed above. */
6428 if (validate_win(win
)) {
6429 DNPRINTF(SWM_D_EVENT
, "resize: invalid win.\n");
6437 region_containment(win
, r
, SWM_CW_ALLSIDES
| SWM_CW_RESIZABLE
|
6438 SWM_CW_HARDBOUNDARY
| SWM_CW_SOFTBOUNDARY
);
6442 store_float_geom(win
);
6444 xcb_ungrab_pointer(conn
, XCB_CURRENT_TIME
);
6446 DNPRINTF(SWM_D_EVENT
, "resize: done.\n");
6450 resize_step(struct swm_region
*r
, union arg
*args
)
6452 struct ws_win
*win
= NULL
;
6454 if (r
&& r
->ws
&& r
->ws
->focus
)
6464 /* Try to set window region based on supplied coordinates or window center. */
6466 regionize(struct ws_win
*win
, int x
, int y
)
6468 struct swm_region
*r
= NULL
;
6470 r
= region_under(win
->s
, x
, y
);
6472 r
= region_under(win
->s
, X(win
) + WIDTH(win
) / 2,
6473 Y(win
) + HEIGHT(win
) / 2);
6475 if (r
!= NULL
&& r
!= win
->ws
->r
) {
6476 if (clear_maximized(r
->ws
) > 0)
6479 win_to_ws(win
, r
->ws
->idx
, false);
6481 /* Set focus on new ws. */
6482 unfocus_win(r
->ws
->focus
);
6490 #define SWM_MOVE_STEPS (50)
6493 move(struct ws_win
*win
, union arg
*args
)
6495 struct swm_region
*r
;
6496 xcb_timestamp_t timestamp
= 0;
6498 xcb_query_pointer_reply_t
*qpr
= NULL
;
6499 xcb_generic_event_t
*evt
;
6500 xcb_motion_notify_event_t
*mne
;
6501 bool moving
, restack
= false;
6506 if ((r
= win
->ws
->r
) == NULL
)
6509 if (FULLSCREEN(win
))
6512 DNPRINTF(SWM_D_EVENT
, "move: win %#x, floating: %s, transient: "
6513 "%#x\n", win
->id
, YESNO(ABOVE(win
)), win
->transient
);
6515 /* in max_stack mode should only move transients */
6516 if (win
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
] && !TRANS(win
))
6519 if (!(ABOVE(win
) || TRANS(win
)) || MAXIMIZED(win
)) {
6520 store_float_geom(win
);
6524 ewmh_apply_flags(win
, (win
->ewmh_flags
| SWM_F_MANUAL
| EWMH_F_ABOVE
) &
6526 ewmh_update_wm_state(win
);
6533 /* It's possible for win to have been freed during focus_flush(). */
6534 if (validate_win(win
)) {
6535 DNPRINTF(SWM_D_EVENT
, "move: invalid win.\n");
6541 case SWM_ARG_ID_MOVELEFT
:
6542 X(win
) -= (SWM_MOVE_STEPS
- border_width
);
6545 case SWM_ARG_ID_MOVERIGHT
:
6546 X(win
) += (SWM_MOVE_STEPS
- border_width
);
6549 case SWM_ARG_ID_MOVEUP
:
6550 Y(win
) -= (SWM_MOVE_STEPS
- border_width
);
6553 case SWM_ARG_ID_MOVEDOWN
:
6554 Y(win
) += (SWM_MOVE_STEPS
- border_width
);
6561 regionize(win
, -1, -1);
6562 region_containment(win
, win
->ws
->r
, SWM_CW_ALLSIDES
);
6564 store_float_geom(win
);
6568 xcb_grab_pointer(conn
, 0, win
->id
, MOUSEMASK
,
6569 XCB_GRAB_MODE_ASYNC
, XCB_GRAB_MODE_ASYNC
,
6570 XCB_WINDOW_NONE
, cursors
[XC_FLEUR
].cid
, XCB_CURRENT_TIME
);
6572 /* get cursor offset from window root */
6573 qpr
= xcb_query_pointer_reply(conn
, xcb_query_pointer(conn
, win
->id
),
6576 xcb_ungrab_pointer(conn
, XCB_CURRENT_TIME
);
6580 regionize(win
, qpr
->root_x
, qpr
->root_y
);
6581 region_containment(win
, win
->ws
->r
, SWM_CW_ALLSIDES
|
6582 SWM_CW_SOFTBOUNDARY
);
6586 while (moving
&& (evt
= xcb_wait_for_event(conn
))) {
6587 switch (XCB_EVENT_RESPONSE_TYPE(evt
)) {
6588 case XCB_BUTTON_RELEASE
:
6589 DNPRINTF(SWM_D_EVENT
, "move: BUTTON_RELEASE\n");
6592 case XCB_MOTION_NOTIFY
:
6593 mne
= (xcb_motion_notify_event_t
*)evt
;
6594 DNPRINTF(SWM_D_EVENT
, "motion: root: %#x\n", mne
->root
);
6595 X(win
) = mne
->root_x
- qpr
->win_x
- border_width
;
6596 Y(win
) = mne
->root_y
- qpr
->win_y
- border_width
;
6598 /* not free, don't sync more than 120 times / second */
6599 if ((mne
->time
- timestamp
) > (1000 / 120) ) {
6600 timestamp
= mne
->time
;
6601 regionize(win
, mne
->root_x
, mne
->root_y
);
6602 region_containment(win
, win
->ws
->r
,
6603 SWM_CW_ALLSIDES
| SWM_CW_SOFTBOUNDARY
);
6610 xcb_allow_events(conn
, XCB_ALLOW_ASYNC_KEYBOARD
,
6611 ((xcb_key_press_event_t
*)evt
)->time
);
6617 /* It's possible for win to have been freed above. */
6618 if (validate_win(win
)) {
6619 DNPRINTF(SWM_D_EVENT
, "move: invalid win.\n");
6627 region_containment(win
, win
->ws
->r
, SWM_CW_ALLSIDES
|
6628 SWM_CW_SOFTBOUNDARY
);
6632 store_float_geom(win
);
6634 /* New region set to fullscreen layout. */
6635 if (win
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
]) {
6642 xcb_ungrab_pointer(conn
, XCB_CURRENT_TIME
);
6643 DNPRINTF(SWM_D_EVENT
, "move: done.\n");
6647 move_step(struct swm_region
*r
, union arg
*args
)
6649 struct ws_win
*win
= NULL
;
6651 if (r
&& r
->ws
&& r
->ws
->focus
)
6656 if (!TRANS(win
) && !ABOVE(win
))
6664 /* key definitions */
6666 char name
[SWM_FUNCNAME_LEN
];
6667 void (*func
)(struct swm_region
*r
, union arg
*);
6669 } keyfuncs
[KF_INVALID
+ 1] = {
6670 /* name function argument */
6671 { "bar_toggle", bar_toggle
, {.id
= SWM_ARG_ID_BAR_TOGGLE
} },
6672 { "bar_toggle_ws", bar_toggle
, {.id
= SWM_ARG_ID_BAR_TOGGLE_WS
} },
6673 { "button2", pressbutton
, {2} },
6674 { "cycle_layout", cycle_layout
, {0} },
6675 { "flip_layout", stack_config
, {.id
= SWM_ARG_ID_FLIPLAYOUT
} },
6676 { "float_toggle", floating_toggle
,{0} },
6677 { "focus_main", focus
, {.id
= SWM_ARG_ID_FOCUSMAIN
} },
6678 { "focus_next", focus
, {.id
= SWM_ARG_ID_FOCUSNEXT
} },
6679 { "focus_prev", focus
, {.id
= SWM_ARG_ID_FOCUSPREV
} },
6680 { "focus_urgent", focus
, {.id
= SWM_ARG_ID_FOCUSURGENT
} },
6681 { "maximize_toggle", maximize_toggle
,{0} },
6682 { "height_grow", resize_step
, {.id
= SWM_ARG_ID_HEIGHTGROW
} },
6683 { "height_shrink", resize_step
, {.id
= SWM_ARG_ID_HEIGHTSHRINK
} },
6684 { "iconify", iconify
, {0} },
6685 { "master_shrink", stack_config
, {.id
= SWM_ARG_ID_MASTERSHRINK
} },
6686 { "master_grow", stack_config
, {.id
= SWM_ARG_ID_MASTERGROW
} },
6687 { "master_add", stack_config
, {.id
= SWM_ARG_ID_MASTERADD
} },
6688 { "master_del", stack_config
, {.id
= SWM_ARG_ID_MASTERDEL
} },
6689 { "move_down", move_step
, {.id
= SWM_ARG_ID_MOVEDOWN
} },
6690 { "move_left", move_step
, {.id
= SWM_ARG_ID_MOVELEFT
} },
6691 { "move_right", move_step
, {.id
= SWM_ARG_ID_MOVERIGHT
} },
6692 { "move_up", move_step
, {.id
= SWM_ARG_ID_MOVEUP
} },
6693 { "mvrg_1", send_to_rg
, {.id
= 0} },
6694 { "mvrg_2", send_to_rg
, {.id
= 1} },
6695 { "mvrg_3", send_to_rg
, {.id
= 2} },
6696 { "mvrg_4", send_to_rg
, {.id
= 3} },
6697 { "mvrg_5", send_to_rg
, {.id
= 4} },
6698 { "mvrg_6", send_to_rg
, {.id
= 5} },
6699 { "mvrg_7", send_to_rg
, {.id
= 6} },
6700 { "mvrg_8", send_to_rg
, {.id
= 7} },
6701 { "mvrg_9", send_to_rg
, {.id
= 8} },
6702 { "mvws_1", send_to_ws
, {.id
= 0} },
6703 { "mvws_2", send_to_ws
, {.id
= 1} },
6704 { "mvws_3", send_to_ws
, {.id
= 2} },
6705 { "mvws_4", send_to_ws
, {.id
= 3} },
6706 { "mvws_5", send_to_ws
, {.id
= 4} },
6707 { "mvws_6", send_to_ws
, {.id
= 5} },
6708 { "mvws_7", send_to_ws
, {.id
= 6} },
6709 { "mvws_8", send_to_ws
, {.id
= 7} },
6710 { "mvws_9", send_to_ws
, {.id
= 8} },
6711 { "mvws_10", send_to_ws
, {.id
= 9} },
6712 { "mvws_11", send_to_ws
, {.id
= 10} },
6713 { "mvws_12", send_to_ws
, {.id
= 11} },
6714 { "mvws_13", send_to_ws
, {.id
= 12} },
6715 { "mvws_14", send_to_ws
, {.id
= 13} },
6716 { "mvws_15", send_to_ws
, {.id
= 14} },
6717 { "mvws_16", send_to_ws
, {.id
= 15} },
6718 { "mvws_17", send_to_ws
, {.id
= 16} },
6719 { "mvws_18", send_to_ws
, {.id
= 17} },
6720 { "mvws_19", send_to_ws
, {.id
= 18} },
6721 { "mvws_20", send_to_ws
, {.id
= 19} },
6722 { "mvws_21", send_to_ws
, {.id
= 20} },
6723 { "mvws_22", send_to_ws
, {.id
= 21} },
6724 { "name_workspace", name_workspace
, {0} },
6725 { "quit", quit
, {0} },
6726 { "raise_toggle", raise_toggle
, {0} },
6727 { "restart", restart
, {0} },
6728 { "rg_1", focusrg
, {.id
= 0} },
6729 { "rg_2", focusrg
, {.id
= 1} },
6730 { "rg_3", focusrg
, {.id
= 2} },
6731 { "rg_4", focusrg
, {.id
= 3} },
6732 { "rg_5", focusrg
, {.id
= 4} },
6733 { "rg_6", focusrg
, {.id
= 5} },
6734 { "rg_7", focusrg
, {.id
= 6} },
6735 { "rg_8", focusrg
, {.id
= 7} },
6736 { "rg_9", focusrg
, {.id
= 8} },
6737 { "rg_move_next", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_MOVE_UP
} },
6738 { "rg_move_prev", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_MOVE_DOWN
} },
6739 { "rg_next", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_UP
} },
6740 { "rg_prev", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_DOWN
} },
6741 { "screen_next", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_UP
} },
6742 { "screen_prev", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_DOWN
} },
6743 { "search_win", search_win
, {0} },
6744 { "search_workspace", search_workspace
, {0} },
6745 { "spawn_custom", NULL
, {0} },
6746 { "stack_balance", stack_config
, {.id
= SWM_ARG_ID_STACKBALANCE
} },
6747 { "stack_inc", stack_config
, {.id
= SWM_ARG_ID_STACKINC
} },
6748 { "stack_dec", stack_config
, {.id
= SWM_ARG_ID_STACKDEC
} },
6749 { "stack_reset", stack_config
, {.id
= SWM_ARG_ID_STACKRESET
} },
6750 { "swap_main", swapwin
, {.id
= SWM_ARG_ID_SWAPMAIN
} },
6751 { "swap_next", swapwin
, {.id
= SWM_ARG_ID_SWAPNEXT
} },
6752 { "swap_prev", swapwin
, {.id
= SWM_ARG_ID_SWAPPREV
} },
6753 { "uniconify", uniconify
, {0} },
6754 { "version", version
, {0} },
6755 { "width_grow", resize_step
, {.id
= SWM_ARG_ID_WIDTHGROW
} },
6756 { "width_shrink", resize_step
, {.id
= SWM_ARG_ID_WIDTHSHRINK
} },
6757 { "wind_del", wkill
, {.id
= SWM_ARG_ID_DELETEWINDOW
} },
6758 { "wind_kill", wkill
, {.id
= SWM_ARG_ID_KILLWINDOW
} },
6759 { "ws_1", switchws
, {.id
= 0} },
6760 { "ws_2", switchws
, {.id
= 1} },
6761 { "ws_3", switchws
, {.id
= 2} },
6762 { "ws_4", switchws
, {.id
= 3} },
6763 { "ws_5", switchws
, {.id
= 4} },
6764 { "ws_6", switchws
, {.id
= 5} },
6765 { "ws_7", switchws
, {.id
= 6} },
6766 { "ws_8", switchws
, {.id
= 7} },
6767 { "ws_9", switchws
, {.id
= 8} },
6768 { "ws_10", switchws
, {.id
= 9} },
6769 { "ws_11", switchws
, {.id
= 10} },
6770 { "ws_12", switchws
, {.id
= 11} },
6771 { "ws_13", switchws
, {.id
= 12} },
6772 { "ws_14", switchws
, {.id
= 13} },
6773 { "ws_15", switchws
, {.id
= 14} },
6774 { "ws_16", switchws
, {.id
= 15} },
6775 { "ws_17", switchws
, {.id
= 16} },
6776 { "ws_18", switchws
, {.id
= 17} },
6777 { "ws_19", switchws
, {.id
= 18} },
6778 { "ws_20", switchws
, {.id
= 19} },
6779 { "ws_21", switchws
, {.id
= 20} },
6780 { "ws_22", switchws
, {.id
= 21} },
6781 { "ws_next", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_UP
} },
6782 { "ws_next_all", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_UP_ALL
} },
6783 { "ws_next_move", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_MOVE_UP
} },
6784 { "ws_prev", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_DOWN
} },
6785 { "ws_prev_all", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_DOWN_ALL
} },
6786 { "ws_prev_move", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_MOVE_DOWN
} },
6787 { "ws_prior", priorws
, {0} },
6788 { "dumpwins", dumpwins
, {0} }, /* MUST BE LAST */
6789 { "invalid key func", NULL
, {0} },
6793 key_cmp(struct key
*kp1
, struct key
*kp2
)
6795 if (kp1
->keysym
< kp2
->keysym
)
6797 if (kp1
->keysym
> kp2
->keysym
)
6800 if (kp1
->mod
< kp2
->mod
)
6802 if (kp1
->mod
> kp2
->mod
)
6809 enum { client_click
, root_click
};
6811 unsigned int action
;
6813 unsigned int button
;
6814 void (*func
)(struct ws_win
*, union arg
*);
6817 #define MODKEY_SHIFT MODKEY | XCB_MOD_MASK_SHIFT
6818 /* action key mouse button func args */
6819 { client_click
, MODKEY
, XCB_BUTTON_INDEX_3
, resize
, {.id
= SWM_ARG_ID_DONTCENTER
} },
6820 { client_click
, MODKEY_SHIFT
, XCB_BUTTON_INDEX_3
, resize
, {.id
= SWM_ARG_ID_CENTER
} },
6821 { client_click
, MODKEY
, XCB_BUTTON_INDEX_1
, move
, {0} },
6826 update_modkey(unsigned int mod
)
6832 RB_FOREACH(kp
, key_tree
, &keys
)
6833 if (kp
->mod
& XCB_MOD_MASK_SHIFT
)
6834 kp
->mod
= mod
| XCB_MOD_MASK_SHIFT
;
6838 for (i
= 0; i
< LENGTH(buttons
); i
++)
6839 if (buttons
[i
].mask
& XCB_MOD_MASK_SHIFT
)
6840 buttons
[i
].mask
= mod
| XCB_MOD_MASK_SHIFT
;
6842 buttons
[i
].mask
= mod
;
6846 spawn_expand(struct swm_region
*r
, union arg
*args
, const char *spawn_name
,
6849 struct spawn_prog
*prog
= NULL
;
6851 char *ap
, **real_args
;
6853 /* suppress unused warning since var is needed */
6856 DNPRINTF(SWM_D_SPAWN
, "spawn_expand: %s\n", spawn_name
);
6859 TAILQ_FOREACH(prog
, &spawns
, entry
) {
6860 if (strcasecmp(spawn_name
, prog
->name
) == 0)
6864 warnx("spawn_custom: program %s not found", spawn_name
);
6868 /* make room for expanded args */
6869 if ((real_args
= calloc(prog
->argc
+ 1, sizeof(char *))) == NULL
)
6870 err(1, "spawn_custom: calloc real_args");
6872 /* expand spawn_args into real_args */
6873 for (i
= c
= 0; i
< prog
->argc
; i
++) {
6875 DNPRINTF(SWM_D_SPAWN
, "spawn_custom: raw arg: %s\n", ap
);
6876 if (strcasecmp(ap
, "$bar_border") == 0) {
6878 strdup(r
->s
->c
[SWM_S_COLOR_BAR_BORDER
].name
))
6880 err(1, "spawn_custom border color");
6881 } else if (strcasecmp(ap
, "$bar_color") == 0) {
6883 strdup(r
->s
->c
[SWM_S_COLOR_BAR
].name
))
6885 err(1, "spawn_custom bar color");
6886 } else if (strcasecmp(ap
, "$bar_font") == 0) {
6887 if ((real_args
[c
] = strdup(bar_fonts
))
6889 err(1, "spawn_custom bar fonts");
6890 } else if (strcasecmp(ap
, "$bar_font_color") == 0) {
6892 strdup(r
->s
->c
[SWM_S_COLOR_BAR_FONT
].name
))
6894 err(1, "spawn_custom color font");
6895 } else if (strcasecmp(ap
, "$color_focus") == 0) {
6897 strdup(r
->s
->c
[SWM_S_COLOR_FOCUS
].name
))
6899 err(1, "spawn_custom color focus");
6900 } else if (strcasecmp(ap
, "$color_focus_maximized") == 0) {
6902 strdup(r
->s
->c
[SWM_S_COLOR_FOCUS_MAXIMIZED
].name
))
6904 err(1, "spawn_custom color focus maximized");
6905 } else if (strcasecmp(ap
, "$color_unfocus") == 0) {
6907 strdup(r
->s
->c
[SWM_S_COLOR_UNFOCUS
].name
))
6909 err(1, "spawn_custom color unfocus");
6910 } else if (strcasecmp(ap
, "$color_unfocus_maximized") == 0) {
6912 strdup(r
->s
->c
[SWM_S_COLOR_UNFOCUS_MAXIMIZED
].name
))
6914 err(1, "spawn_custom color unfocus maximized");
6915 } else if (strcasecmp(ap
, "$region_index") == 0) {
6916 if (asprintf(&real_args
[c
], "%d",
6917 get_region_index(r
) + 1) < 1)
6918 err(1, "spawn_custom region index");
6919 } else if (strcasecmp(ap
, "$workspace_index") == 0) {
6920 if (asprintf(&real_args
[c
], "%d", r
->ws
->idx
+ 1) < 1)
6921 err(1, "spawn_custom workspace index");
6922 } else if (strcasecmp(ap
, "$dmenu_bottom") == 0) {
6925 if ((real_args
[c
] = strdup("-b")) == NULL
)
6926 err(1, "spawn_custom workspace index");
6928 /* no match --> copy as is */
6929 if ((real_args
[c
] = strdup(ap
)) == NULL
)
6930 err(1, "spawn_custom strdup(ap)");
6932 DNPRINTF(SWM_D_SPAWN
, "spawn_custom: cooked arg: %s\n",
6938 DNPRINTF(SWM_D_SPAWN
, "spawn_custom: result: ");
6939 for (i
= 0; i
< c
; ++i
)
6940 DPRINTF("\"%s\" ", real_args
[i
]);
6943 *ret_args
= real_args
;
6948 spawn_custom(struct swm_region
*r
, union arg
*args
, const char *spawn_name
)
6954 if ((spawn_argc
= spawn_expand(r
, args
, spawn_name
, &real_args
)) < 0)
6958 spawn(r
->ws
->idx
, &a
, true);
6960 for (i
= 0; i
< spawn_argc
; i
++)
6966 spawn_select(struct swm_region
*r
, union arg
*args
, const char *spawn_name
,
6973 if ((spawn_argc
= spawn_expand(r
, args
, spawn_name
, &real_args
)) < 0)
6977 if (pipe(select_list_pipe
) == -1)
6978 err(1, "pipe error");
6979 if (pipe(select_resp_pipe
) == -1)
6980 err(1, "pipe error");
6982 if (signal(SIGPIPE
, SIG_IGN
) == SIG_ERR
)
6983 err(1, "could not disable SIGPIPE");
6984 switch (*pid
= fork()) {
6986 err(1, "cannot fork");
6989 if (dup2(select_list_pipe
[0], STDIN_FILENO
) == -1)
6991 if (dup2(select_resp_pipe
[1], STDOUT_FILENO
) == -1)
6993 close(select_list_pipe
[1]);
6994 close(select_resp_pipe
[0]);
6995 spawn(r
->ws
->idx
, &a
, false);
6997 default: /* parent */
6998 close(select_list_pipe
[0]);
6999 close(select_resp_pipe
[1]);
7003 for (i
= 0; i
< spawn_argc
; i
++)
7008 /* Argument tokenizer. */
7011 char *arg
, *cp
, *next
;
7012 bool single_quoted
= false, double_quoted
= false;
7017 /* Eat and move characters until end of argument is found. */
7018 for (arg
= next
= cp
= *sp
; *cp
!= '\0'; ++cp
) {
7019 if (!double_quoted
&& *cp
== '\'') {
7020 /* Eat single-quote. */
7021 single_quoted
= !single_quoted
;
7022 } else if (!single_quoted
&& *cp
== '"') {
7023 /* Eat double-quote. */
7024 double_quoted
= !double_quoted
;
7025 } else if (!single_quoted
&& *cp
== '\\' && *(cp
+ 1) == '"') {
7026 /* Eat backslash; copy escaped character to arg. */
7028 } else if (!single_quoted
&& !double_quoted
&& *cp
== '\\' &&
7029 (*(cp
+ 1) == '\'' || *(cp
+ 1) == ' ')) {
7030 /* Eat backslash; move escaped character. */
7032 } else if (!single_quoted
&& !double_quoted
&&
7033 (*cp
== ' ' || *cp
== '\t')) {
7034 /* Terminate argument. */
7036 /* Point sp to beginning of next argument. */
7040 /* Move regular character. */
7045 /* Terminate argument if end of string. */
7055 spawn_insert(const char *name
, const char *args
, int flags
)
7057 struct spawn_prog
*sp
;
7058 char *arg
, *cp
, *ptr
;
7060 DNPRINTF(SWM_D_SPAWN
, "spawn_insert: %s[%s]\n", name
, args
);
7062 if (args
== NULL
|| *args
== '\0')
7065 if ((sp
= calloc(1, sizeof *sp
)) == NULL
)
7066 err(1, "spawn_insert: calloc");
7067 if ((sp
->name
= strdup(name
)) == NULL
)
7068 err(1, "spawn_insert: strdup");
7070 /* Convert the arguments to an argument list. */
7071 if ((ptr
= cp
= strdup(args
)) == NULL
)
7072 err(1, "spawn_insert: strdup");
7073 while ((arg
= argsep(&ptr
)) != NULL
) {
7074 /* Null argument; skip it. */
7079 if ((sp
->argv
= realloc(sp
->argv
, sp
->argc
*
7080 sizeof *sp
->argv
)) == NULL
)
7081 err(1, "spawn_insert: realloc");
7082 if ((sp
->argv
[sp
->argc
- 1] = strdup(arg
)) == NULL
)
7083 err(1, "spawn_insert: strdup");
7089 DNPRINTF(SWM_D_SPAWN
, "arg %d: [%s]\n", sp
->argc
, sp
->argv
[sp
->argc
-1]);
7090 TAILQ_INSERT_TAIL(&spawns
, sp
, entry
);
7091 DNPRINTF(SWM_D_SPAWN
, "spawn_insert: leave\n");
7095 spawn_remove(struct spawn_prog
*sp
)
7099 DNPRINTF(SWM_D_SPAWN
, "spawn_remove: %s\n", sp
->name
);
7101 TAILQ_REMOVE(&spawns
, sp
, entry
);
7102 for (i
= 0; i
< sp
->argc
; i
++)
7108 DNPRINTF(SWM_D_SPAWN
, "spawn_remove: leave\n");
7112 spawn_find(const char *name
)
7114 struct spawn_prog
*sp
;
7116 TAILQ_FOREACH(sp
, &spawns
, entry
)
7117 if (strcasecmp(sp
->name
, name
) == 0)
7124 setspawn(const char *name
, const char *args
, int flags
)
7126 struct spawn_prog
*sp
;
7128 DNPRINTF(SWM_D_SPAWN
, "setspawn: %s\n", name
);
7133 /* Remove any old spawn under the same name. */
7134 if ((sp
= spawn_find(name
)) != NULL
)
7138 spawn_insert(name
, args
, flags
);
7140 warnx("error: setspawn: cannot find program: %s", name
);
7142 DNPRINTF(SWM_D_SPAWN
, "setspawn: leave\n");
7146 setconfspawn(const char *selector
, const char *value
, int flags
)
7150 if (selector
== NULL
|| strlen(selector
) == 0)
7153 args
= expand_tilde(value
);
7155 DNPRINTF(SWM_D_SPAWN
, "setconfspawn: [%s] [%s]\n", selector
, args
);
7157 setspawn(selector
, args
, flags
);
7160 DNPRINTF(SWM_D_SPAWN
, "setconfspawn: done.\n");
7165 validate_spawns(void)
7167 struct spawn_prog
*sp
;
7168 char which
[PATH_MAX
];
7173 RB_FOREACH(kp
, key_tree
, &keys
) {
7174 if (kp
->funcid
!= KF_SPAWN_CUSTOM
)
7178 sp
= spawn_find(kp
->spawn_name
);
7179 if (sp
== NULL
|| sp
->flags
& SWM_SPAWN_OPTIONAL
)
7182 /* verify we have the goods */
7183 snprintf(which
, sizeof which
, "which %s", sp
->argv
[0]);
7184 DNPRINTF(SWM_D_CONF
, "validate_spawns: which %s\n",
7186 for (i
= strlen("which "); i
< strlen(which
); i
++)
7187 if (which
[i
] == ' ') {
7191 if (system(which
) != 0)
7192 add_startup_exception("could not find %s",
7193 &which
[strlen("which ")]);
7200 setconfspawn("lock", "xlock", 0);
7202 setconfspawn("term", "xterm", 0);
7203 setconfspawn("spawn_term", "xterm", 0);
7205 setconfspawn("menu", "dmenu_run"
7209 " -nf $bar_font_color"
7211 " -sf $bar_color", 0);
7213 setconfspawn("search", "dmenu"
7218 " -nf $bar_font_color"
7220 " -sf $bar_color", 0);
7222 setconfspawn("name_workspace", "dmenu"
7227 " -nf $bar_font_color"
7229 " -sf $bar_color", 0);
7231 /* These are not verified for existence, even with a binding set. */
7232 setconfspawn("screenshot_all", "screenshot.sh full", SWM_SPAWN_OPTIONAL
);
7233 setconfspawn("screenshot_wind", "screenshot.sh window", SWM_SPAWN_OPTIONAL
);
7234 setconfspawn("initscr", "initscreen.sh", SWM_SPAWN_OPTIONAL
);
7238 #define SWM_MODNAME_SIZE 32
7239 #define SWM_KEY_WS "\n+ \t"
7241 parsekeys(const char *keystr
, unsigned int currmod
, unsigned int *mod
, KeySym
*ks
)
7243 char *str
, *cp
, *name
;
7246 DNPRINTF(SWM_D_KEY
, "parsekeys: enter [%s]\n", keystr
);
7247 if (mod
== NULL
|| ks
== NULL
) {
7248 DNPRINTF(SWM_D_KEY
, "parsekeys: no mod or key vars\n");
7251 if (keystr
== NULL
|| strlen(keystr
) == 0) {
7252 DNPRINTF(SWM_D_KEY
, "parsekeys: no keystr\n");
7256 if ((cp
= str
= strdup(keystr
)) == NULL
)
7257 err(1, "parsekeys: strdup");
7259 *ks
= XCB_NO_SYMBOL
;
7261 while ((name
= strsep(&cp
, SWM_KEY_WS
)) != NULL
) {
7262 DNPRINTF(SWM_D_KEY
, "parsekeys: key [%s]\n", name
);
7264 cp
+= (long)strspn(cp
, SWM_KEY_WS
);
7265 if (strncasecmp(name
, "MOD", SWM_MODNAME_SIZE
) == 0)
7267 else if (strncasecmp(name
, "Mod1", SWM_MODNAME_SIZE
) == 0)
7268 *mod
|= XCB_MOD_MASK_1
;
7269 else if (strncasecmp(name
, "Mod2", SWM_MODNAME_SIZE
) == 0)
7270 *mod
+= XCB_MOD_MASK_2
;
7271 else if (strncmp(name
, "Mod3", SWM_MODNAME_SIZE
) == 0)
7272 *mod
|= XCB_MOD_MASK_3
;
7273 else if (strncmp(name
, "Mod4", SWM_MODNAME_SIZE
) == 0)
7274 *mod
|= XCB_MOD_MASK_4
;
7275 else if (strncmp(name
, "Mod5", SWM_MODNAME_SIZE
) == 0)
7276 *mod
|= XCB_MOD_MASK_5
;
7277 else if (strncasecmp(name
, "SHIFT", SWM_MODNAME_SIZE
) == 0)
7278 *mod
|= XCB_MOD_MASK_SHIFT
;
7279 else if (strncasecmp(name
, "CONTROL", SWM_MODNAME_SIZE
) == 0)
7280 *mod
|= XCB_MOD_MASK_CONTROL
;
7282 *ks
= XStringToKeysym(name
);
7283 XConvertCase(*ks
, ks
, &uks
);
7284 if (ks
== XCB_NO_SYMBOL
) {
7286 "parsekeys: invalid key %s\n",
7295 DNPRINTF(SWM_D_KEY
, "parsekeys: leave ok\n");
7300 strdupsafe(const char *str
)
7305 return (strdup(str
));
7309 key_insert(unsigned int mod
, KeySym ks
, enum keyfuncid kfid
,
7310 const char *spawn_name
)
7314 DNPRINTF(SWM_D_KEY
, "key_insert: enter %s [%s]\n",
7315 keyfuncs
[kfid
].name
, spawn_name
);
7317 if ((kp
= malloc(sizeof *kp
)) == NULL
)
7318 err(1, "key_insert: malloc");
7323 kp
->spawn_name
= strdupsafe(spawn_name
);
7324 RB_INSERT(key_tree
, &keys
, kp
);
7326 DNPRINTF(SWM_D_KEY
, "key_insert: leave\n");
7330 key_lookup(unsigned int mod
, KeySym ks
)
7337 return (RB_FIND(key_tree
, &keys
, &kp
));
7341 key_remove(struct key
*kp
)
7343 DNPRINTF(SWM_D_KEY
, "key_remove: %s\n", keyfuncs
[kp
->funcid
].name
);
7345 RB_REMOVE(key_tree
, &keys
, kp
);
7346 free(kp
->spawn_name
);
7349 DNPRINTF(SWM_D_KEY
, "key_remove: leave\n");
7353 key_replace(struct key
*kp
, unsigned int mod
, KeySym ks
, enum keyfuncid kfid
,
7354 const char *spawn_name
)
7356 DNPRINTF(SWM_D_KEY
, "key_replace: %s [%s]\n", keyfuncs
[kp
->funcid
].name
,
7360 key_insert(mod
, ks
, kfid
, spawn_name
);
7362 DNPRINTF(SWM_D_KEY
, "key_replace: leave\n");
7366 setkeybinding(unsigned int mod
, KeySym ks
, enum keyfuncid kfid
,
7367 const char *spawn_name
)
7371 DNPRINTF(SWM_D_KEY
, "setkeybinding: enter %s [%s]\n",
7372 keyfuncs
[kfid
].name
, spawn_name
);
7374 if ((kp
= key_lookup(mod
, ks
)) != NULL
) {
7375 if (kfid
== KF_INVALID
)
7378 key_replace(kp
, mod
, ks
, kfid
, spawn_name
);
7379 DNPRINTF(SWM_D_KEY
, "setkeybinding: leave\n");
7382 if (kfid
== KF_INVALID
) {
7383 warnx("bind: Key combination already unbound.");
7384 DNPRINTF(SWM_D_KEY
, "setkeybinding: leave\n");
7388 key_insert(mod
, ks
, kfid
, spawn_name
);
7389 DNPRINTF(SWM_D_KEY
, "setkeybinding: leave\n");
7393 setconfbinding(const char *selector
, const char *value
, int flags
)
7395 enum keyfuncid kfid
;
7398 struct spawn_prog
*sp
;
7400 /* suppress unused warning since var is needed */
7403 DNPRINTF(SWM_D_KEY
, "setconfbinding: enter selector: [%s], "
7404 "value: [%s]\n", selector
, value
);
7405 if (selector
== NULL
|| strlen(selector
) == 0) {
7406 DNPRINTF(SWM_D_KEY
, "setconfbinding: unbind %s\n", value
);
7407 if (parsekeys(value
, mod_key
, &mod
, &ks
) == 0) {
7409 setkeybinding(mod
, ks
, kfid
, NULL
);
7414 /* search by key function name */
7415 for (kfid
= 0; kfid
< KF_INVALID
; (kfid
)++) {
7416 if (strncasecmp(selector
, keyfuncs
[kfid
].name
,
7417 SWM_FUNCNAME_LEN
) == 0) {
7418 DNPRINTF(SWM_D_KEY
, "setconfbinding: %s: match "
7419 "keyfunc\n", selector
);
7420 if (parsekeys(value
, mod_key
, &mod
, &ks
) == 0) {
7421 setkeybinding(mod
, ks
, kfid
, NULL
);
7427 /* search by custom spawn name */
7428 if ((sp
= spawn_find(selector
)) != NULL
) {
7429 DNPRINTF(SWM_D_KEY
, "setconfbinding: %s: match "
7430 "spawn\n", selector
);
7431 if (parsekeys(value
, mod_key
, &mod
, &ks
) == 0) {
7432 setkeybinding(mod
, ks
, KF_SPAWN_CUSTOM
,
7438 DNPRINTF(SWM_D_KEY
, "setconfbinding: no match\n");
7445 #define MODKEY_SHIFT MODKEY | XCB_MOD_MASK_SHIFT
7446 setkeybinding(MODKEY
, XK_b
, KF_BAR_TOGGLE
, NULL
);
7447 setkeybinding(MODKEY_SHIFT
, XK_b
, KF_BAR_TOGGLE_WS
,NULL
);
7448 setkeybinding(MODKEY
, XK_v
, KF_BUTTON2
, NULL
);
7449 setkeybinding(MODKEY
, XK_space
, KF_CYCLE_LAYOUT
,NULL
);
7450 setkeybinding(MODKEY_SHIFT
, XK_backslash
, KF_FLIP_LAYOUT
, NULL
);
7451 setkeybinding(MODKEY
, XK_t
, KF_FLOAT_TOGGLE
,NULL
);
7452 setkeybinding(MODKEY
, XK_m
, KF_FOCUS_MAIN
, NULL
);
7453 setkeybinding(MODKEY
, XK_j
, KF_FOCUS_NEXT
, NULL
);
7454 setkeybinding(MODKEY
, XK_Tab
, KF_FOCUS_NEXT
, NULL
);
7455 setkeybinding(MODKEY
, XK_k
, KF_FOCUS_PREV
, NULL
);
7456 setkeybinding(MODKEY_SHIFT
, XK_Tab
, KF_FOCUS_PREV
, NULL
);
7457 setkeybinding(MODKEY
, XK_u
, KF_FOCUS_URGENT
,NULL
);
7458 setkeybinding(MODKEY
, XK_e
, KF_MAXIMIZE_TOGGLE
,NULL
);
7459 setkeybinding(MODKEY_SHIFT
, XK_equal
, KF_HEIGHT_GROW
,NULL
);
7460 setkeybinding(MODKEY_SHIFT
, XK_minus
, KF_HEIGHT_SHRINK
,NULL
);
7461 setkeybinding(MODKEY
, XK_w
, KF_ICONIFY
, NULL
);
7462 setkeybinding(MODKEY
, XK_h
, KF_MASTER_SHRINK
, NULL
);
7463 setkeybinding(MODKEY
, XK_l
, KF_MASTER_GROW
, NULL
);
7464 setkeybinding(MODKEY
, XK_comma
, KF_MASTER_ADD
, NULL
);
7465 setkeybinding(MODKEY
, XK_period
, KF_MASTER_DEL
, NULL
);
7466 setkeybinding(MODKEY_SHIFT
, XK_bracketright
,KF_MOVE_DOWN
,NULL
);
7467 setkeybinding(MODKEY
, XK_bracketleft
, KF_MOVE_LEFT
,NULL
);
7468 setkeybinding(MODKEY
, XK_bracketright
,KF_MOVE_RIGHT
,NULL
);
7469 setkeybinding(MODKEY_SHIFT
, XK_bracketleft
, KF_MOVE_UP
, NULL
);
7470 setkeybinding(MODKEY_SHIFT
, XK_KP_End
, KF_MVRG_1
, NULL
);
7471 setkeybinding(MODKEY_SHIFT
, XK_KP_Down
, KF_MVRG_2
, NULL
);
7472 setkeybinding(MODKEY_SHIFT
, XK_KP_Next
, KF_MVRG_3
, NULL
);
7473 setkeybinding(MODKEY_SHIFT
, XK_KP_Left
, KF_MVRG_4
, NULL
);
7474 setkeybinding(MODKEY_SHIFT
, XK_KP_Begin
, KF_MVRG_5
, NULL
);
7475 setkeybinding(MODKEY_SHIFT
, XK_KP_Right
, KF_MVRG_6
, NULL
);
7476 setkeybinding(MODKEY_SHIFT
, XK_KP_Home
, KF_MVRG_7
, NULL
);
7477 setkeybinding(MODKEY_SHIFT
, XK_KP_Up
, KF_MVRG_8
, NULL
);
7478 setkeybinding(MODKEY_SHIFT
, XK_KP_Prior
, KF_MVRG_9
, NULL
);
7479 setkeybinding(MODKEY_SHIFT
, XK_1
, KF_MVWS_1
, NULL
);
7480 setkeybinding(MODKEY_SHIFT
, XK_2
, KF_MVWS_2
, NULL
);
7481 setkeybinding(MODKEY_SHIFT
, XK_3
, KF_MVWS_3
, NULL
);
7482 setkeybinding(MODKEY_SHIFT
, XK_4
, KF_MVWS_4
, NULL
);
7483 setkeybinding(MODKEY_SHIFT
, XK_5
, KF_MVWS_5
, NULL
);
7484 setkeybinding(MODKEY_SHIFT
, XK_6
, KF_MVWS_6
, NULL
);
7485 setkeybinding(MODKEY_SHIFT
, XK_7
, KF_MVWS_7
, NULL
);
7486 setkeybinding(MODKEY_SHIFT
, XK_8
, KF_MVWS_8
, NULL
);
7487 setkeybinding(MODKEY_SHIFT
, XK_9
, KF_MVWS_9
, NULL
);
7488 setkeybinding(MODKEY_SHIFT
, XK_0
, KF_MVWS_10
, NULL
);
7489 setkeybinding(MODKEY_SHIFT
, XK_F1
, KF_MVWS_11
, NULL
);
7490 setkeybinding(MODKEY_SHIFT
, XK_F2
, KF_MVWS_12
, NULL
);
7491 setkeybinding(MODKEY_SHIFT
, XK_F3
, KF_MVWS_13
, NULL
);
7492 setkeybinding(MODKEY_SHIFT
, XK_F4
, KF_MVWS_14
, NULL
);
7493 setkeybinding(MODKEY_SHIFT
, XK_F5
, KF_MVWS_15
, NULL
);
7494 setkeybinding(MODKEY_SHIFT
, XK_F6
, KF_MVWS_16
, NULL
);
7495 setkeybinding(MODKEY_SHIFT
, XK_F7
, KF_MVWS_17
, NULL
);
7496 setkeybinding(MODKEY_SHIFT
, XK_F8
, KF_MVWS_18
, NULL
);
7497 setkeybinding(MODKEY_SHIFT
, XK_F9
, KF_MVWS_19
, NULL
);
7498 setkeybinding(MODKEY_SHIFT
, XK_F10
, KF_MVWS_20
, NULL
);
7499 setkeybinding(MODKEY_SHIFT
, XK_F11
, KF_MVWS_21
, NULL
);
7500 setkeybinding(MODKEY_SHIFT
, XK_F12
, KF_MVWS_22
, NULL
);
7501 setkeybinding(MODKEY_SHIFT
, XK_slash
, KF_NAME_WORKSPACE
,NULL
);
7502 setkeybinding(MODKEY_SHIFT
, XK_q
, KF_QUIT
, NULL
);
7503 setkeybinding(MODKEY_SHIFT
, XK_r
, KF_RAISE_TOGGLE
,NULL
);
7504 setkeybinding(MODKEY
, XK_q
, KF_RESTART
, NULL
);
7505 setkeybinding(MODKEY
, XK_KP_End
, KF_RG_1
, NULL
);
7506 setkeybinding(MODKEY
, XK_KP_Down
, KF_RG_2
, NULL
);
7507 setkeybinding(MODKEY
, XK_KP_Next
, KF_RG_3
, NULL
);
7508 setkeybinding(MODKEY
, XK_KP_Left
, KF_RG_4
, NULL
);
7509 setkeybinding(MODKEY
, XK_KP_Begin
, KF_RG_5
, NULL
);
7510 setkeybinding(MODKEY
, XK_KP_Right
, KF_RG_6
, NULL
);
7511 setkeybinding(MODKEY
, XK_KP_Home
, KF_RG_7
, NULL
);
7512 setkeybinding(MODKEY
, XK_KP_Up
, KF_RG_8
, NULL
);
7513 setkeybinding(MODKEY
, XK_KP_Prior
, KF_RG_9
, NULL
);
7514 setkeybinding(MODKEY_SHIFT
, XK_Right
, KF_RG_NEXT
, NULL
);
7515 setkeybinding(MODKEY_SHIFT
, XK_Left
, KF_RG_PREV
, NULL
);
7516 setkeybinding(MODKEY
, XK_f
, KF_SEARCH_WIN
, NULL
);
7517 setkeybinding(MODKEY
, XK_slash
, KF_SEARCH_WORKSPACE
,NULL
);
7518 setkeybinding(MODKEY_SHIFT
, XK_i
, KF_SPAWN_CUSTOM
,"initscr");
7519 setkeybinding(MODKEY_SHIFT
, XK_Delete
, KF_SPAWN_CUSTOM
,"lock");
7520 setkeybinding(MODKEY
, XK_p
, KF_SPAWN_CUSTOM
,"menu");
7521 setkeybinding(MODKEY
, XK_s
, KF_SPAWN_CUSTOM
,"screenshot_all");
7522 setkeybinding(MODKEY_SHIFT
, XK_s
, KF_SPAWN_CUSTOM
,"screenshot_wind");
7523 setkeybinding(MODKEY_SHIFT
, XK_Return
, KF_SPAWN_CUSTOM
,"term");
7524 setkeybinding(MODKEY_SHIFT
, XK_comma
, KF_STACK_INC
, NULL
);
7525 setkeybinding(MODKEY_SHIFT
, XK_period
, KF_STACK_DEC
, NULL
);
7526 setkeybinding(MODKEY_SHIFT
, XK_space
, KF_STACK_RESET
, NULL
);
7527 setkeybinding(MODKEY
, XK_Return
, KF_SWAP_MAIN
, NULL
);
7528 setkeybinding(MODKEY_SHIFT
, XK_j
, KF_SWAP_NEXT
, NULL
);
7529 setkeybinding(MODKEY_SHIFT
, XK_k
, KF_SWAP_PREV
, NULL
);
7530 setkeybinding(MODKEY_SHIFT
, XK_w
, KF_UNICONIFY
, NULL
);
7531 setkeybinding(MODKEY_SHIFT
, XK_v
, KF_VERSION
, NULL
);
7532 setkeybinding(MODKEY
, XK_equal
, KF_WIDTH_GROW
, NULL
);
7533 setkeybinding(MODKEY
, XK_minus
, KF_WIDTH_SHRINK
,NULL
);
7534 setkeybinding(MODKEY
, XK_x
, KF_WIND_DEL
, NULL
);
7535 setkeybinding(MODKEY_SHIFT
, XK_x
, KF_WIND_KILL
, NULL
);
7536 setkeybinding(MODKEY
, XK_1
, KF_WS_1
, NULL
);
7537 setkeybinding(MODKEY
, XK_2
, KF_WS_2
, NULL
);
7538 setkeybinding(MODKEY
, XK_3
, KF_WS_3
, NULL
);
7539 setkeybinding(MODKEY
, XK_4
, KF_WS_4
, NULL
);
7540 setkeybinding(MODKEY
, XK_5
, KF_WS_5
, NULL
);
7541 setkeybinding(MODKEY
, XK_6
, KF_WS_6
, NULL
);
7542 setkeybinding(MODKEY
, XK_7
, KF_WS_7
, NULL
);
7543 setkeybinding(MODKEY
, XK_8
, KF_WS_8
, NULL
);
7544 setkeybinding(MODKEY
, XK_9
, KF_WS_9
, NULL
);
7545 setkeybinding(MODKEY
, XK_0
, KF_WS_10
, NULL
);
7546 setkeybinding(MODKEY
, XK_F1
, KF_WS_11
, NULL
);
7547 setkeybinding(MODKEY
, XK_F2
, KF_WS_12
, NULL
);
7548 setkeybinding(MODKEY
, XK_F3
, KF_WS_13
, NULL
);
7549 setkeybinding(MODKEY
, XK_F4
, KF_WS_14
, NULL
);
7550 setkeybinding(MODKEY
, XK_F5
, KF_WS_15
, NULL
);
7551 setkeybinding(MODKEY
, XK_F6
, KF_WS_16
, NULL
);
7552 setkeybinding(MODKEY
, XK_F7
, KF_WS_17
, NULL
);
7553 setkeybinding(MODKEY
, XK_F8
, KF_WS_18
, NULL
);
7554 setkeybinding(MODKEY
, XK_F9
, KF_WS_19
, NULL
);
7555 setkeybinding(MODKEY
, XK_F10
, KF_WS_20
, NULL
);
7556 setkeybinding(MODKEY
, XK_F11
, KF_WS_21
, NULL
);
7557 setkeybinding(MODKEY
, XK_F12
, KF_WS_22
, NULL
);
7558 setkeybinding(MODKEY
, XK_Right
, KF_WS_NEXT
, NULL
);
7559 setkeybinding(MODKEY
, XK_Left
, KF_WS_PREV
, NULL
);
7560 setkeybinding(MODKEY
, XK_Up
, KF_WS_NEXT_ALL
, NULL
);
7561 setkeybinding(MODKEY
, XK_Down
, KF_WS_PREV_ALL
, NULL
);
7562 setkeybinding(MODKEY_SHIFT
, XK_Up
, KF_WS_NEXT_MOVE
,NULL
);
7563 setkeybinding(MODKEY_SHIFT
, XK_Down
, KF_WS_PREV_MOVE
,NULL
);
7564 setkeybinding(MODKEY
, XK_a
, KF_WS_PRIOR
, NULL
);
7566 setkeybinding(MODKEY_SHIFT
, XK_d
, KF_DUMPWINS
, NULL
);
7576 while (RB_EMPTY(&keys
) == 0) {
7577 kp
= RB_ROOT(&keys
);
7583 setkeymapping(const char *selector
, const char *value
, int flags
)
7585 char *keymapping_file
;
7587 /* suppress unused warnings since vars are needed */
7591 DNPRINTF(SWM_D_KEY
, "setkeymapping: enter\n");
7593 keymapping_file
= expand_tilde(value
);
7596 /* load new key bindings; if it fails, revert to default bindings */
7597 if (conf_load(keymapping_file
, SWM_CONF_KEYMAPPING
)) {
7602 free(keymapping_file
);
7604 DNPRINTF(SWM_D_KEY
, "setkeymapping: leave\n");
7609 updatenumlockmask(void)
7612 xcb_get_modifier_mapping_reply_t
*modmap_r
;
7613 xcb_keycode_t
*modmap
, kc
, *keycode
;
7617 modmap_r
= xcb_get_modifier_mapping_reply(conn
,
7618 xcb_get_modifier_mapping(conn
),
7621 modmap
= xcb_get_modifier_mapping_keycodes(modmap_r
);
7622 for (i
= 0; i
< 8; i
++) {
7623 for (j
= 0; j
< modmap_r
->keycodes_per_modifier
; j
++) {
7624 kc
= modmap
[i
* modmap_r
->keycodes_per_modifier
7626 keycode
= xcb_key_symbols_get_keycode(syms
,
7630 numlockmask
= (1 << i
);
7637 DNPRINTF(SWM_D_MISC
, "updatenumlockmask: %d\n", numlockmask
);
7644 int num_screens
, k
, j
;
7645 unsigned int modifiers
[4];
7646 xcb_keycode_t
*code
;
7648 DNPRINTF(SWM_D_MISC
, "grabkeys\n");
7649 updatenumlockmask();
7652 modifiers
[1] = numlockmask
;
7653 modifiers
[2] = XCB_MOD_MASK_LOCK
;
7654 modifiers
[3] = numlockmask
| XCB_MOD_MASK_LOCK
;
7656 num_screens
= get_screen_count();
7657 for (k
= 0; k
< num_screens
; k
++) {
7658 if (TAILQ_EMPTY(&screens
[k
].rl
))
7660 xcb_ungrab_key(conn
, XCB_GRAB_ANY
, screens
[k
].root
,
7662 RB_FOREACH(kp
, key_tree
, &keys
) {
7663 /* Skip unused ws binds. */
7664 if ((int)kp
->funcid
> KF_WS_1
+ workspace_limit
- 1 &&
7665 kp
->funcid
<= KF_WS_22
)
7668 /* Skip unused mvws binds. */
7669 if ((int)kp
->funcid
> KF_MVWS_1
+ workspace_limit
- 1 &&
7670 kp
->funcid
<= KF_MVWS_22
)
7673 if ((code
= xcb_key_symbols_get_keycode(syms
,
7675 for (j
= 0; j
< LENGTH(modifiers
); j
++)
7676 xcb_grab_key(conn
, 1,
7678 kp
->mod
| modifiers
[j
],
7679 *code
, XCB_GRAB_MODE_SYNC
,
7680 XCB_GRAB_MODE_SYNC
);
7688 grabbuttons(struct ws_win
*win
)
7690 unsigned int modifiers
[4];
7693 DNPRINTF(SWM_D_MOUSE
, "grabbuttons: win %#x\n", win
->id
);
7694 updatenumlockmask();
7697 modifiers
[1] = numlockmask
;
7698 modifiers
[2] = XCB_MOD_MASK_LOCK
;
7699 modifiers
[3] = numlockmask
| XCB_MOD_MASK_LOCK
;
7701 for (i
= 0; i
< LENGTH(buttons
); i
++)
7702 if (buttons
[i
].action
== client_click
)
7703 for (j
= 0; j
< LENGTH(modifiers
); ++j
)
7704 xcb_grab_button(conn
, 0, win
->id
, BUTTONMASK
,
7705 XCB_GRAB_MODE_SYNC
, XCB_GRAB_MODE_ASYNC
,
7706 XCB_WINDOW_NONE
, XCB_CURSOR_NONE
,
7707 buttons
[i
].button
, buttons
[i
].mask
|
7711 const char *quirkname
[] = {
7712 "NONE", /* config string for "no value" */
7720 "FOCUSONMAP_SINGLE",
7727 /* SWM_Q_DELIM: retain '|' for back compat for now (2009-08-11) */
7728 #define SWM_Q_DELIM "\n|+ \t"
7730 parsequirks(const char *qstr
, uint32_t *quirk
, int *ws
)
7732 char *str
, *cp
, *name
;
7735 if (quirk
== NULL
|| qstr
== NULL
)
7738 if ((str
= strdup(qstr
)) == NULL
)
7739 err(1, "parsequirks: strdup");
7743 while ((name
= strsep(&cp
, SWM_Q_DELIM
)) != NULL
) {
7745 cp
+= (long)strspn(cp
, SWM_Q_DELIM
);
7747 if (sscanf(name
, "WS[%d]", ws
) == 1) {
7753 for (i
= 0; i
< LENGTH(quirkname
); i
++) {
7754 if (strncasecmp(name
, quirkname
[i
],
7755 SWM_QUIRK_LEN
) == 0) {
7756 DNPRINTF(SWM_D_QUIRK
,
7757 "parsequirks: %s\n", name
);
7763 *quirk
|= 1 << (i
-1);
7767 if (i
>= LENGTH(quirkname
)) {
7768 DNPRINTF(SWM_D_QUIRK
,
7769 "parsequirks: invalid quirk [%s]\n", name
);
7780 quirk_insert(const char *class, const char *instance
, const char *name
,
7781 uint32_t quirk
, int ws
)
7785 bool failed
= false;
7787 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: class: %s, instance: %s, name: %s,"
7788 " value: %u, ws: %d\n", class, instance
, name
, quirk
, ws
);
7790 if ((qp
= malloc(sizeof *qp
)) == NULL
)
7791 err(1, "quirk_insert: malloc");
7793 if ((qp
->class = strdup(class)) == NULL
)
7794 err(1, "quirk_insert: strdup");
7795 if ((qp
->instance
= strdup(instance
)) == NULL
)
7796 err(1, "quirk_insert: strdup");
7797 if ((qp
->name
= strdup(name
)) == NULL
)
7798 err(1, "quirk_insert: strdup");
7800 if (asprintf(&str
, "^%s$", class) == -1)
7801 err(1, "quirk_insert: asprintf");
7802 if (regcomp(&qp
->regex_class
, str
, REG_EXTENDED
| REG_NOSUB
)) {
7803 add_startup_exception("regex failed to compile quirk 'class' "
7804 "field: %s", class);
7807 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: compiled: %s\n", str
);
7810 if (asprintf(&str
, "^%s$", instance
) == -1)
7811 err(1, "quirk_insert: asprintf");
7812 if (regcomp(&qp
->regex_instance
, str
, REG_EXTENDED
| REG_NOSUB
)) {
7813 add_startup_exception("regex failed to compile quirk 'instance'"
7814 " field: %s", instance
);
7817 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: compiled: %s\n", str
);
7820 if (asprintf(&str
, "^%s$", name
) == -1)
7821 err(1, "quirk_insert: asprintf");
7822 if (regcomp(&qp
->regex_name
, str
, REG_EXTENDED
| REG_NOSUB
)) {
7823 add_startup_exception("regex failed to compile quirk 'name' "
7827 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: compiled: %s\n", str
);
7831 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: regex error; skipping.\n");
7836 TAILQ_INSERT_TAIL(&quirks
, qp
, entry
);
7838 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: leave\n");
7842 quirk_remove(struct quirk
*qp
)
7844 DNPRINTF(SWM_D_QUIRK
, "quirk_remove: %s:%s [%u]\n", qp
->class,
7845 qp
->name
, qp
->quirk
);
7847 TAILQ_REMOVE(&quirks
, qp
, entry
);
7850 DNPRINTF(SWM_D_QUIRK
, "quirk_remove: leave\n");
7854 quirk_free(struct quirk
*qp
)
7856 regfree(&qp
->regex_class
);
7857 regfree(&qp
->regex_instance
);
7858 regfree(&qp
->regex_name
);
7866 quirk_replace(struct quirk
*qp
, const char *class, const char *instance
,
7867 const char *name
, uint32_t quirk
, int ws
)
7869 DNPRINTF(SWM_D_QUIRK
, "quirk_replace: %s:%s:%s [%u], ws: %d\n", qp
->class,
7870 qp
->instance
, qp
->name
, qp
->quirk
, qp
->ws
);
7873 quirk_insert(class, instance
, name
, quirk
, ws
);
7875 DNPRINTF(SWM_D_QUIRK
, "quirk_replace: leave\n");
7879 setquirk(const char *class, const char *instance
, const char *name
,
7880 uint32_t quirk
, int ws
)
7884 DNPRINTF(SWM_D_QUIRK
, "setquirk: enter %s:%s:%s [%u], ws: %d\n", class,
7885 instance
, name
, quirk
, ws
);
7887 /* Remove/replace existing quirk. */
7888 TAILQ_FOREACH(qp
, &quirks
, entry
) {
7889 if (strcmp(qp
->class, class) == 0 &&
7890 strcmp(qp
->instance
, instance
) == 0 &&
7891 strcmp(qp
->name
, name
) == 0) {
7892 if (quirk
== 0 && ws
== -1)
7895 quirk_replace(qp
, class, instance
, name
, quirk
,
7897 DNPRINTF(SWM_D_QUIRK
, "setquirk: leave\n");
7902 /* Only insert if quirk is not NONE or forced ws is set. */
7903 if (quirk
|| ws
!= -1)
7904 quirk_insert(class, instance
, name
, quirk
, ws
);
7906 DNPRINTF(SWM_D_QUIRK
, "setquirk: leave\n");
7909 /* Eat '\' in str used to escape square brackets and colon. */
7911 unescape_selector(char *str
)
7915 for (cp
= str
; *str
!= '\0'; ++str
, ++cp
) {
7916 if (*str
== '\\' && (*(str
+ 1) == ':' || *(str
+ 1) == ']' ||
7926 setconfquirk(const char *selector
, const char *value
, int flags
)
7928 char *str
, *cp
, *class;
7929 char *instance
= NULL
, *name
= NULL
;
7930 int retval
, count
= 0, ws
= -1;
7933 /* suppress unused warning since var is needed */
7936 if (selector
== NULL
|| strlen(selector
) == 0)
7939 if ((str
= strdup(selector
)) == NULL
)
7940 err(1, "setconfquirk: strdup");
7942 /* Find non-escaped colon. */
7949 for (++cp
; *cp
!= '\0'; ++cp
) {
7950 if (*cp
== ':' && *(cp
- 1) != '\\') {
7956 unescape_selector(class);
7958 instance
= class + strlen(class) + 1;
7959 unescape_selector(instance
);
7965 name
= instance
+ strlen(instance
) + 1;
7966 unescape_selector(name
);
7971 DNPRINTF(SWM_D_CONF
, "setconfquirk: class: %s, instance: %s, "
7972 "name: %s\n", class, instance
, name
);
7974 if ((retval
= parsequirks(value
, &qrks
, &ws
)) == 0)
7975 setquirk(class, instance
, name
, qrks
, ws
);
7984 setquirk("MPlayer", "xv", ".*",
7985 SWM_Q_FLOAT
| SWM_Q_FULLSCREEN
| SWM_Q_FOCUSPREV
, -1);
7986 setquirk("OpenOffice.org 3.2", "VCLSalFrame", ".*",
7988 setquirk("Firefox-bin", "firefox-bin", ".*",
7990 setquirk("Firefox", "Dialog", ".*",
7992 setquirk("Gimp", "gimp", ".*",
7993 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
7994 setquirk("XTerm", "xterm", ".*",
7995 SWM_Q_XTERM_FONTADJ
, -1);
7996 setquirk("xine", "Xine Window", ".*",
7997 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
7998 setquirk("Xitk", "Xitk Combo", ".*",
7999 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
8000 setquirk("xine", "xine Panel", ".*",
8001 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
8002 setquirk("Xitk", "Xine Window", ".*",
8003 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
8004 setquirk("xine", "xine Video Fullscreen Window", ".*",
8005 SWM_Q_FULLSCREEN
| SWM_Q_FLOAT
, -1);
8006 setquirk("pcb", "pcb", ".*",
8008 setquirk("SDL_App", "SDL_App", ".*",
8009 SWM_Q_FLOAT
| SWM_Q_FULLSCREEN
, -1);
8012 /* conf file stuff */
8013 #define SWM_CONF_FILE "spectrwm.conf"
8014 #define SWM_CONF_FILE_OLD "scrotwm.conf"
8018 SWM_S_BAR_AT_BOTTOM
,
8019 SWM_S_BAR_BORDER_WIDTH
,
8022 SWM_S_BAR_ENABLED_WS
,
8027 SWM_S_BOUNDARY_WIDTH
,
8028 SWM_S_CLOCK_ENABLED
,
8031 SWM_S_CYCLE_VISIBLE
,
8033 SWM_S_DISABLE_BORDER
,
8035 SWM_S_FOCUS_CLOSE_WRAP
,
8036 SWM_S_FOCUS_DEFAULT
,
8038 SWM_S_ICONIC_ENABLED
,
8039 SWM_S_JAVA_WORKAROUND
,
8040 SWM_S_MAXIMIZE_HIDE_BAR
,
8041 SWM_S_REGION_PADDING
,
8046 SWM_S_STACK_ENABLED
,
8049 SWM_S_URGENT_COLLAPSE
,
8050 SWM_S_URGENT_ENABLED
,
8051 SWM_S_VERBOSE_LAYOUT
,
8052 SWM_S_VISIBLE_NOSWAP
,
8054 SWM_S_WINDOW_CLASS_ENABLED
,
8055 SWM_S_WINDOW_INSTANCE_ENABLED
,
8056 SWM_S_WINDOW_NAME_ENABLED
,
8057 SWM_S_WORKSPACE_LIMIT
,
8058 SWM_S_WORKSPACE_NAME
,
8062 setconfvalue(const char *selector
, const char *value
, int flags
)
8064 struct workspace
*ws
;
8065 int i
, ws_id
, num_screens
;
8066 char *b
, *str
, s
[1024];
8069 case SWM_S_BAR_ACTION
:
8071 if ((bar_argv
[0] = expand_tilde(value
)) == NULL
)
8072 err(1, "setconfvalue: bar_action");
8074 case SWM_S_BAR_AT_BOTTOM
:
8075 bar_at_bottom
= (atoi(value
) != 0);
8077 case SWM_S_BAR_BORDER_WIDTH
:
8078 bar_border_width
= atoi(value
);
8079 if (bar_border_width
< 0)
8080 bar_border_width
= 0;
8082 case SWM_S_BAR_DELAY
:
8083 /* No longer needed; leave to not break old conf files. */
8085 case SWM_S_BAR_ENABLED
:
8086 bar_enabled
= (atoi(value
) != 0);
8088 case SWM_S_BAR_ENABLED_WS
:
8089 ws_id
= atoi(selector
) - 1;
8090 if (ws_id
< 0 || ws_id
>= workspace_limit
)
8091 errx(1, "setconfvalue: bar_enabled_ws: invalid "
8092 "workspace %d.", ws_id
+ 1);
8094 num_screens
= get_screen_count();
8095 for (i
= 0; i
< num_screens
; i
++) {
8096 ws
= (struct workspace
*)&screens
[i
].ws
;
8097 ws
[ws_id
].bar_enabled
= (atoi(value
) != 0);
8100 case SWM_S_BAR_FONT
:
8102 if (asprintf(&bar_fonts
, "%s,%s", value
, bar_fonts
) == -1)
8103 err(1, "setconfvalue: asprintf: failed to allocate "
8104 "memory for bar_fonts.");
8107 /* If already in xft mode, then we are done. */
8108 if (!bar_font_legacy
)
8111 if ((str
= strdup(value
)) == NULL
)
8112 err(1, "setconfvalue: strdup");
8114 /* If there are any non-XLFD entries, switch to Xft mode. */
8115 while ((b
= strsep(&str
, ",")) != NULL
) {
8119 bar_font_legacy
= false;
8126 case SWM_S_BAR_FORMAT
:
8128 if ((bar_format
= strdup(value
)) == NULL
)
8129 err(1, "setconfvalue: bar_format");
8131 case SWM_S_BAR_JUSTIFY
:
8132 if (strcmp(value
, "left") == 0)
8133 bar_justify
= SWM_BAR_JUSTIFY_LEFT
;
8134 else if (strcmp(value
, "center") == 0)
8135 bar_justify
= SWM_BAR_JUSTIFY_CENTER
;
8136 else if (strcmp(value
, "right") == 0)
8137 bar_justify
= SWM_BAR_JUSTIFY_RIGHT
;
8139 errx(1, "invalid bar_justify");
8141 case SWM_S_BORDER_WIDTH
:
8142 border_width
= atoi(value
);
8143 if (border_width
< 0)
8146 case SWM_S_BOUNDARY_WIDTH
:
8147 boundary_width
= atoi(value
);
8148 if (boundary_width
< 0)
8151 case SWM_S_CLOCK_ENABLED
:
8152 clock_enabled
= (atoi(value
) != 0);
8154 case SWM_S_CLOCK_FORMAT
:
8155 #ifndef SWM_DENY_CLOCK_FORMAT
8157 if ((clock_format
= strdup(value
)) == NULL
)
8158 err(1, "setconfvalue: clock_format");
8161 case SWM_S_CYCLE_EMPTY
:
8162 cycle_empty
= (atoi(value
) != 0);
8164 case SWM_S_CYCLE_VISIBLE
:
8165 cycle_visible
= (atoi(value
) != 0);
8167 case SWM_S_DIALOG_RATIO
:
8168 dialog_ratio
= atof(value
);
8169 if (dialog_ratio
> 1.0 || dialog_ratio
<= .3)
8172 case SWM_S_DISABLE_BORDER
:
8173 disable_border
= (atoi(value
) != 0);
8175 case SWM_S_FOCUS_CLOSE
:
8176 if (strcmp(value
, "first") == 0)
8177 focus_close
= SWM_STACK_BOTTOM
;
8178 else if (strcmp(value
, "last") == 0)
8179 focus_close
= SWM_STACK_TOP
;
8180 else if (strcmp(value
, "next") == 0)
8181 focus_close
= SWM_STACK_ABOVE
;
8182 else if (strcmp(value
, "previous") == 0)
8183 focus_close
= SWM_STACK_BELOW
;
8185 errx(1, "focus_close");
8187 case SWM_S_FOCUS_CLOSE_WRAP
:
8188 focus_close_wrap
= (atoi(value
) != 0);
8190 case SWM_S_FOCUS_DEFAULT
:
8191 if (strcmp(value
, "last") == 0)
8192 focus_default
= SWM_STACK_TOP
;
8193 else if (strcmp(value
, "first") == 0)
8194 focus_default
= SWM_STACK_BOTTOM
;
8196 errx(1, "focus_default");
8198 case SWM_S_FOCUS_MODE
:
8199 if (strcmp(value
, "default") == 0)
8200 focus_mode
= SWM_FOCUS_DEFAULT
;
8201 else if (strcmp(value
, "follow") == 0 ||
8202 strcmp(value
, "follow_cursor") == 0)
8203 focus_mode
= SWM_FOCUS_FOLLOW
;
8204 else if (strcmp(value
, "manual") == 0)
8205 focus_mode
= SWM_FOCUS_MANUAL
;
8207 errx(1, "focus_mode");
8209 case SWM_S_ICONIC_ENABLED
:
8210 iconic_enabled
= (atoi(value
) != 0);
8212 case SWM_S_JAVA_WORKAROUND
:
8213 java_workaround
= (atoi(value
) != 0);
8215 case SWM_S_MAXIMIZE_HIDE_BAR
:
8216 maximize_hide_bar
= atoi(value
);
8218 case SWM_S_REGION_PADDING
:
8219 region_padding
= atoi(value
);
8220 if (region_padding
< 0)
8223 case SWM_S_SPAWN_ORDER
:
8224 if (strcmp(value
, "first") == 0)
8225 spawn_position
= SWM_STACK_BOTTOM
;
8226 else if (strcmp(value
, "last") == 0)
8227 spawn_position
= SWM_STACK_TOP
;
8228 else if (strcmp(value
, "next") == 0)
8229 spawn_position
= SWM_STACK_ABOVE
;
8230 else if (strcmp(value
, "previous") == 0)
8231 spawn_position
= SWM_STACK_BELOW
;
8233 errx(1, "spawn_position");
8235 case SWM_S_SPAWN_TERM
:
8236 setconfspawn("term", value
, 0);
8237 setconfspawn("spawn_term", value
, 0);
8240 /* No longer needed; leave to not break old conf files. */
8242 case SWM_S_SS_ENABLED
:
8243 /* No longer needed; leave to not break old conf files. */
8245 case SWM_S_STACK_ENABLED
:
8246 stack_enabled
= (atoi(value
) != 0);
8248 case SWM_S_TERM_WIDTH
:
8249 term_width
= atoi(value
);
8253 case SWM_S_TILE_GAP
:
8254 tile_gap
= atoi(value
);
8256 case SWM_S_URGENT_COLLAPSE
:
8257 urgent_collapse
= (atoi(value
) != 0);
8259 case SWM_S_URGENT_ENABLED
:
8260 urgent_enabled
= (atoi(value
) != 0);
8262 case SWM_S_VERBOSE_LAYOUT
:
8263 verbose_layout
= (atoi(value
) != 0);
8264 for (i
= 0; layouts
[i
].l_stack
!= NULL
; i
++) {
8266 layouts
[i
].l_string
= fancy_stacker
;
8268 layouts
[i
].l_string
= plain_stacker
;
8271 case SWM_S_VISIBLE_NOSWAP
:
8272 visible_noswap
= (atoi(value
) != 0);
8274 case SWM_S_WARP_POINTER
:
8275 warp_pointer
= (atoi(value
) != 0);
8277 case SWM_S_WINDOW_CLASS_ENABLED
:
8278 window_class_enabled
= (atoi(value
) != 0);
8280 case SWM_S_WINDOW_INSTANCE_ENABLED
:
8281 window_instance_enabled
= (atoi(value
) != 0);
8283 case SWM_S_WINDOW_NAME_ENABLED
:
8284 window_name_enabled
= (atoi(value
) != 0);
8286 case SWM_S_WORKSPACE_LIMIT
:
8287 workspace_limit
= atoi(value
);
8288 if (workspace_limit
> SWM_WS_MAX
)
8289 workspace_limit
= SWM_WS_MAX
;
8290 else if (workspace_limit
< 1)
8291 workspace_limit
= 1;
8293 ewmh_update_desktops();
8295 case SWM_S_WORKSPACE_NAME
:
8296 if (getenv("SWM_STARTED") != NULL
)
8300 if (sscanf(value
, "ws[%d]:%1023c", &ws_id
, s
) != 2)
8301 errx(1, "invalid entry, should be 'ws[<idx>]:name'");
8303 if (ws_id
< 0 || ws_id
>= workspace_limit
)
8304 errx(1, "setconfvalue: workspace_name: invalid "
8305 "workspace %d.", ws_id
+ 1);
8307 num_screens
= get_screen_count();
8308 for (i
= 0; i
< num_screens
; ++i
) {
8309 ws
= (struct workspace
*)&screens
[i
].ws
;
8311 if (strlen(s
) > 0) {
8312 free(ws
[ws_id
].name
);
8313 if ((ws
[ws_id
].name
= strdup(s
)) == NULL
)
8314 err(1, "setconfvalue: workspace_name.");
8316 ewmh_update_desktop_names();
8317 ewmh_get_desktop_names();
8328 setconfmodkey(const char *selector
, const char *value
, int flags
)
8330 /* suppress unused warnings since vars are needed */
8334 if (strncasecmp(value
, "Mod1", strlen("Mod1")) == 0)
8335 update_modkey(XCB_MOD_MASK_1
);
8336 else if (strncasecmp(value
, "Mod2", strlen("Mod2")) == 0)
8337 update_modkey(XCB_MOD_MASK_2
);
8338 else if (strncasecmp(value
, "Mod3", strlen("Mod3")) == 0)
8339 update_modkey(XCB_MOD_MASK_3
);
8340 else if (strncasecmp(value
, "Mod4", strlen("Mod4")) == 0)
8341 update_modkey(XCB_MOD_MASK_4
);
8342 else if (strncasecmp(value
, "Mod5", strlen("Mod5")) == 0)
8343 update_modkey(XCB_MOD_MASK_5
);
8350 setconfcolor(const char *selector
, const char *value
, int flags
)
8352 int first
, last
, i
= 0, num_screens
;
8354 num_screens
= get_screen_count();
8356 /* conf screen indices begin at 1; treat vals <= 0 as 'all screens.' */
8357 if (selector
== NULL
|| strlen(selector
) == 0 ||
8358 (last
= atoi(selector
) - 1) < 0) {
8360 last
= num_screens
- 1;
8365 if (last
>= num_screens
) {
8366 add_startup_exception("invalid screen index: %d out of bounds "
8367 "(maximum %d)", last
+ 1, num_screens
);
8371 for (i
= first
; i
<= last
; ++i
) {
8372 setscreencolor(value
, i
, flags
);
8375 * When setting focus/unfocus colors, we need to also
8376 * set maximize colors to match if they haven't been customized.
8378 if (flags
== SWM_S_COLOR_FOCUS
&&
8379 !screens
[i
].c
[SWM_S_COLOR_FOCUS_MAXIMIZED
].manual
)
8380 setscreencolor(value
, i
, SWM_S_COLOR_FOCUS_MAXIMIZED
);
8381 else if (flags
== SWM_S_COLOR_UNFOCUS
&&
8382 !screens
[i
].c
[SWM_S_COLOR_UNFOCUS_MAXIMIZED
].manual
)
8383 setscreencolor(value
, i
, SWM_S_COLOR_UNFOCUS_MAXIMIZED
);
8385 screens
[i
].c
[flags
].manual
= 1;
8392 setconfregion(const char *selector
, const char *value
, int flags
)
8394 /* suppress unused warnings since vars are needed */
8398 custom_region(value
);
8403 setautorun(const char *selector
, const char *value
, int flags
)
8413 /* suppress unused warnings since vars are needed */
8417 if (getenv("SWM_STARTED"))
8421 if (sscanf(value
, "ws[%d]:%1023c", &ws_id
, s
) != 2)
8422 errx(1, "invalid autorun entry, should be 'ws[<idx>]:command'");
8424 if (ws_id
< 0 || ws_id
>= workspace_limit
)
8425 errx(1, "autorun: invalid workspace %d", ws_id
+ 1);
8427 sp
= expand_tilde((char *)&s
);
8430 * This is a little intricate
8432 * If the pid already exists we simply reuse it because it means it was
8433 * used before AND not claimed by manage_window. We get away with
8434 * altering it in the parent after INSERT because this can not be a race
8437 while ((ap
= strsep(&sp
, " \t")) != NULL
) {
8440 DNPRINTF(SWM_D_SPAWN
, "setautorun: arg [%s]\n", ap
);
8442 if ((a
.argv
= realloc(a
.argv
, argc
* sizeof(char *))) == NULL
)
8443 err(1, "setautorun: realloc");
8444 a
.argv
[argc
- 1] = ap
;
8448 if ((a
.argv
= realloc(a
.argv
, (argc
+ 1) * sizeof(char *))) == NULL
)
8449 err(1, "setautorun: realloc");
8450 a
.argv
[argc
] = NULL
;
8452 if ((pid
= fork()) == 0) {
8453 spawn(ws_id
, &a
, true);
8462 p
= calloc(1, sizeof *p
);
8465 TAILQ_INSERT_TAIL(&pidlist
, p
, entry
);
8475 setlayout(const char *selector
, const char *value
, int flags
)
8477 struct workspace
*ws
;
8478 int ws_id
, i
, x
, mg
, ma
, si
, ar
;
8479 int st
= SWM_V_STACK
, num_screens
;
8483 /* suppress unused warnings since vars are needed */
8487 if (getenv("SWM_STARTED"))
8491 if (sscanf(value
, "ws[%d]:%d:%d:%d:%d:%1023c",
8492 &ws_id
, &mg
, &ma
, &si
, &ar
, s
) != 6)
8493 errx(1, "invalid layout entry, should be 'ws[<idx>]:"
8494 "<master_grow>:<master_add>:<stack_inc>:<always_raise>:"
8497 if (ws_id
< 0 || ws_id
>= workspace_limit
)
8498 errx(1, "layout: invalid workspace %d", ws_id
+ 1);
8500 if (strcasecmp(s
, "vertical") == 0)
8502 else if (strcasecmp(s
, "vertical_flip") == 0) {
8505 } else if (strcasecmp(s
, "horizontal") == 0)
8507 else if (strcasecmp(s
, "horizontal_flip") == 0) {
8510 } else if (strcasecmp(s
, "fullscreen") == 0)
8513 errx(1, "invalid layout entry, should be 'ws[<idx>]:"
8514 "<master_grow>:<master_add>:<stack_inc>:<always_raise>:"
8517 num_screens
= get_screen_count();
8518 for (i
= 0; i
< num_screens
; i
++) {
8519 ws
= (struct workspace
*)&screens
[i
].ws
;
8520 ws
[ws_id
].cur_layout
= &layouts
[st
];
8522 ws
[ws_id
].always_raise
= (ar
!= 0);
8523 if (st
== SWM_MAX_STACK
)
8527 for (x
= 0; x
< abs(mg
); x
++) {
8528 ws
[ws_id
].cur_layout
->l_config(&ws
[ws_id
],
8529 mg
>= 0 ? SWM_ARG_ID_MASTERGROW
:
8530 SWM_ARG_ID_MASTERSHRINK
);
8533 for (x
= 0; x
< abs(ma
); x
++) {
8534 ws
[ws_id
].cur_layout
->l_config(&ws
[ws_id
],
8535 ma
>= 0 ? SWM_ARG_ID_MASTERADD
:
8536 SWM_ARG_ID_MASTERDEL
);
8539 for (x
= 0; x
< abs(si
); x
++) {
8540 ws
[ws_id
].cur_layout
->l_config(&ws
[ws_id
],
8541 si
>= 0 ? SWM_ARG_ID_STACKINC
:
8542 SWM_ARG_ID_STACKDEC
);
8546 ws
[ws_id
].cur_layout
->l_config(&ws
[ws_id
],
8547 SWM_ARG_ID_FLIPLAYOUT
);
8554 /* config options */
8555 struct config_option
{
8557 int (*func
)(const char*, const char*, int);
8560 struct config_option configopt
[] = {
8561 { "autorun", setautorun
, 0 },
8562 { "bar_action", setconfvalue
, SWM_S_BAR_ACTION
},
8563 { "bar_at_bottom", setconfvalue
, SWM_S_BAR_AT_BOTTOM
},
8564 { "bar_border", setconfcolor
, SWM_S_COLOR_BAR_BORDER
},
8565 { "bar_border_unfocus", setconfcolor
, SWM_S_COLOR_BAR_BORDER_UNFOCUS
},
8566 { "bar_border_width", setconfvalue
, SWM_S_BAR_BORDER_WIDTH
},
8567 { "bar_color", setconfcolor
, SWM_S_COLOR_BAR
},
8568 { "bar_delay", setconfvalue
, SWM_S_BAR_DELAY
},
8569 { "bar_enabled", setconfvalue
, SWM_S_BAR_ENABLED
},
8570 { "bar_enabled_ws", setconfvalue
, SWM_S_BAR_ENABLED_WS
},
8571 { "bar_font", setconfvalue
, SWM_S_BAR_FONT
},
8572 { "bar_font_color", setconfcolor
, SWM_S_COLOR_BAR_FONT
},
8573 { "bar_format", setconfvalue
, SWM_S_BAR_FORMAT
},
8574 { "bar_justify", setconfvalue
, SWM_S_BAR_JUSTIFY
},
8575 { "bind", setconfbinding
, 0 },
8576 { "border_width", setconfvalue
, SWM_S_BORDER_WIDTH
},
8577 { "boundary_width", setconfvalue
, SWM_S_BOUNDARY_WIDTH
},
8578 { "clock_enabled", setconfvalue
, SWM_S_CLOCK_ENABLED
},
8579 { "clock_format", setconfvalue
, SWM_S_CLOCK_FORMAT
},
8580 { "color_focus", setconfcolor
, SWM_S_COLOR_FOCUS
},
8581 { "color_focus_maximized", setconfcolor
, SWM_S_COLOR_FOCUS_MAXIMIZED
},
8582 { "color_unfocus", setconfcolor
, SWM_S_COLOR_UNFOCUS
},
8583 { "color_unfocus_maximized", setconfcolor
, SWM_S_COLOR_UNFOCUS_MAXIMIZED
},
8584 { "cycle_empty", setconfvalue
, SWM_S_CYCLE_EMPTY
},
8585 { "cycle_visible", setconfvalue
, SWM_S_CYCLE_VISIBLE
},
8586 { "dialog_ratio", setconfvalue
, SWM_S_DIALOG_RATIO
},
8587 { "disable_border", setconfvalue
, SWM_S_DISABLE_BORDER
},
8588 { "focus_close", setconfvalue
, SWM_S_FOCUS_CLOSE
},
8589 { "focus_close_wrap", setconfvalue
, SWM_S_FOCUS_CLOSE_WRAP
},
8590 { "focus_default", setconfvalue
, SWM_S_FOCUS_DEFAULT
},
8591 { "focus_mode", setconfvalue
, SWM_S_FOCUS_MODE
},
8592 { "iconic_enabled", setconfvalue
, SWM_S_ICONIC_ENABLED
},
8593 { "java_workaround", setconfvalue
, SWM_S_JAVA_WORKAROUND
},
8594 { "keyboard_mapping", setkeymapping
, 0 },
8595 { "layout", setlayout
, 0 },
8596 { "maximize_hide_bar", setconfvalue
, SWM_S_MAXIMIZE_HIDE_BAR
},
8597 { "modkey", setconfmodkey
, 0 },
8598 { "program", setconfspawn
, 0 },
8599 { "quirk", setconfquirk
, 0 },
8600 { "region", setconfregion
, 0 },
8601 { "region_padding", setconfvalue
, SWM_S_REGION_PADDING
},
8602 { "screenshot_app", setconfvalue
, SWM_S_SS_APP
},
8603 { "screenshot_enabled", setconfvalue
, SWM_S_SS_ENABLED
},
8604 { "spawn_position", setconfvalue
, SWM_S_SPAWN_ORDER
},
8605 { "spawn_term", setconfvalue
, SWM_S_SPAWN_TERM
},
8606 { "stack_enabled", setconfvalue
, SWM_S_STACK_ENABLED
},
8607 { "term_width", setconfvalue
, SWM_S_TERM_WIDTH
},
8608 { "tile_gap", setconfvalue
, SWM_S_TILE_GAP
},
8609 { "title_class_enabled", setconfvalue
, SWM_S_WINDOW_CLASS_ENABLED
}, /* For backwards compat. */
8610 { "title_name_enabled", setconfvalue
, SWM_S_WINDOW_INSTANCE_ENABLED
}, /* For backwards compat. */
8611 { "urgent_collapse", setconfvalue
, SWM_S_URGENT_COLLAPSE
},
8612 { "urgent_enabled", setconfvalue
, SWM_S_URGENT_ENABLED
},
8613 { "verbose_layout", setconfvalue
, SWM_S_VERBOSE_LAYOUT
},
8614 { "visible_noswap", setconfvalue
, SWM_S_VISIBLE_NOSWAP
},
8615 { "warp_pointer", setconfvalue
, SWM_S_WARP_POINTER
},
8616 { "window_class_enabled", setconfvalue
, SWM_S_WINDOW_CLASS_ENABLED
},
8617 { "window_instance_enabled", setconfvalue
, SWM_S_WINDOW_INSTANCE_ENABLED
},
8618 { "window_name_enabled", setconfvalue
, SWM_S_WINDOW_NAME_ENABLED
},
8619 { "workspace_limit", setconfvalue
, SWM_S_WORKSPACE_LIMIT
},
8620 { "name", setconfvalue
, SWM_S_WORKSPACE_NAME
},
8624 _add_startup_exception(const char *fmt
, va_list ap
)
8626 if (vasprintf(&startup_exception
, fmt
, ap
) == -1)
8627 warn("%s: asprintf", __func__
);
8631 add_startup_exception(const char *fmt
, ...)
8637 if (startup_exception
)
8640 /* force bar to be enabled due to exception */
8644 _add_startup_exception(fmt
, ap
);
8649 conf_load(const char *filename
, int keymapping
)
8652 char *line
= NULL
, *cp
, *ce
, *optsub
, *optval
= NULL
;
8653 size_t linelen
, lineno
= 0;
8654 int wordlen
, i
, optidx
, count
;
8655 struct config_option
*opt
= NULL
;
8657 DNPRINTF(SWM_D_CONF
, "conf_load: begin\n");
8659 if (filename
== NULL
) {
8660 warnx("conf_load: no filename");
8664 DNPRINTF(SWM_D_CONF
, "conf_load: open %s\n", filename
);
8666 if ((config
= fopen(filename
, "r")) == NULL
) {
8667 warn("conf_load: fopen: %s", filename
);
8671 while (!feof(config
)) {
8675 if ((line
= fparseln(config
, &linelen
, &lineno
, NULL
,
8676 FPARSELN_UNESCCOMM
| FPARSELN_UNESCCONT
)) == NULL
) {
8678 err(1, "%s", filename
);
8683 cp
+= strspn(cp
, " \t\n"); /* eat whitespace */
8684 if (cp
[0] == '\0') {
8688 /* get config option */
8689 wordlen
= strcspn(cp
, "=[ \t\n");
8691 add_startup_exception("%s: line %zd: no option found",
8696 for (i
= 0; i
< LENGTH(configopt
); i
++) {
8697 opt
= &configopt
[i
];
8698 if (strncasecmp(cp
, opt
->optname
, wordlen
) == 0 &&
8699 (int)strlen(opt
->optname
) == wordlen
) {
8705 add_startup_exception("%s: line %zd: unknown option "
8706 "%.*s", filename
, lineno
, wordlen
, cp
);
8709 if (keymapping
&& opt
&& strcmp(opt
->optname
, "bind")) {
8710 add_startup_exception("%s: line %zd: invalid option "
8711 "%.*s", filename
, lineno
, wordlen
, cp
);
8715 cp
+= strspn(cp
, " \t\n"); /* eat whitespace */
8717 /* get [selector] if any */
8722 /* Get length of selector. */
8723 for (ce
= ++cp
; *ce
!= '\0'; ++ce
) {
8724 /* Find matching (not escaped) bracket. */
8725 if (*ce
== ']' && *(ce
- 1) != '\\') {
8732 add_startup_exception("%s: line %zd: syntax "
8733 "error: unterminated selector", filename
,
8738 /* ce points at ']'; terminate optsub. */
8743 cp
+= strspn(cp
, "= \t\n"); /* eat trailing */
8746 if (strlen(optval
) == 0) {
8747 add_startup_exception("%s: line %zd: must supply value "
8748 "to %s", filename
, lineno
,
8749 configopt
[optidx
].optname
);
8752 /* call function to deal with it all */
8753 if (configopt
[optidx
].func(optsub
, optval
,
8754 configopt
[optidx
].funcflags
) != 0) {
8755 add_startup_exception("%s: line %zd: invalid data for "
8756 "%s", filename
, lineno
, configopt
[optidx
].optname
);
8764 DNPRINTF(SWM_D_CONF
, "conf_load: end\n");
8770 set_child_transient(struct ws_win
*win
, xcb_window_t
*trans
)
8772 struct ws_win
*parent
, *w
;
8773 struct swm_region
*r
;
8774 struct workspace
*ws
;
8775 xcb_icccm_wm_hints_t wmh
;
8777 parent
= find_window(win
->transient
);
8779 parent
->focus_child
= win
;
8781 DNPRINTF(SWM_D_MISC
, "set_child_transient: parent doesn't exist"
8782 " for %#x trans %#x\n", win
->id
, win
->transient
);
8784 r
= root_to_region(win
->s
->root
, SWM_CK_ALL
);
8786 /* parent doen't exist in our window list */
8787 TAILQ_FOREACH(w
, &ws
->winlist
, entry
) {
8788 if (xcb_icccm_get_wm_hints_reply(conn
,
8789 xcb_icccm_get_wm_hints(conn
, w
->id
),
8791 warnx("can't get hints for %#x", w
->id
);
8795 if (win
->hints
.window_group
!= wmh
.window_group
)
8798 w
->focus_child
= win
;
8799 win
->transient
= w
->id
;
8801 DNPRINTF(SWM_D_MISC
, "set_child_transient: adjusting "
8802 "transient to %#x\n", win
->transient
);
8809 window_get_pid(xcb_window_t win
)
8814 xcb_get_property_cookie_t pc
;
8815 xcb_get_property_reply_t
*pr
;
8817 apid
= get_atom_from_string("_NET_WM_PID");
8818 if (apid
== XCB_ATOM_NONE
)
8821 pc
= xcb_get_property(conn
, 0, win
, apid
, XCB_ATOM_CARDINAL
, 0, 1);
8822 pr
= xcb_get_property_reply(conn
, pc
, NULL
);
8825 if (pr
->type
!= XCB_ATOM_CARDINAL
) {
8830 if (pr
->type
== apid
&& pr
->format
== 32)
8831 ret
= *((pid_t
*)xcb_get_property_value(pr
));
8837 apid
= get_atom_from_string("_SWM_PID");
8838 pc
= xcb_get_property(conn
, 0, win
, apid
, XCB_ATOM_STRING
,
8840 pr
= xcb_get_property_reply(conn
, pc
, NULL
);
8843 if (pr
->type
!= apid
) {
8848 ret
= (pid_t
)strtonum(xcb_get_property_value(pr
), 0, INT_MAX
, &errstr
);
8855 get_swm_ws(xcb_window_t id
)
8861 xcb_get_property_reply_t
*gpr
;
8863 gpr
= xcb_get_property_reply(conn
,
8864 xcb_get_property(conn
, 0, id
, a_swm_ws
,
8865 XCB_ATOM_STRING
, 0, SWM_PROPLEN
),
8870 proplen
= xcb_get_property_value_length(gpr
);
8872 prop
= malloc(proplen
+ 1);
8875 xcb_get_property_value(gpr
),
8877 prop
[proplen
] = '\0';
8884 DNPRINTF(SWM_D_PROP
, "get_swm_ws: _SWM_WS: %s\n", prop
);
8885 ws_idx
= (int)strtonum(prop
, 0, workspace_limit
- 1, &errstr
);
8887 DNPRINTF(SWM_D_PROP
, "get_swm_ws: win #%s: %s",
8897 get_ws_idx(struct ws_win
*win
)
8899 xcb_get_property_reply_t
*gpr
;
8905 gpr
= xcb_get_property_reply(conn
,
8906 xcb_get_property(conn
, 0, win
->id
, ewmh
[_NET_WM_DESKTOP
].atom
,
8907 XCB_ATOM_CARDINAL
, 0, 1),
8910 if (gpr
->type
== XCB_ATOM_CARDINAL
&& gpr
->format
== 32)
8911 ws_idx
= *((int *)xcb_get_property_value(gpr
));
8915 if (ws_idx
== -1 && !(win
->quirks
& SWM_Q_IGNORESPAWNWS
))
8916 ws_idx
= get_swm_ws(win
->id
);
8918 if (ws_idx
> workspace_limit
- 1 || ws_idx
< -1)
8921 DNPRINTF(SWM_D_PROP
, "get_ws_idx: win %#x, ws_idx: %d\n", win
->id
,
8928 manage_window(xcb_window_t id
, int spawn_pos
, bool mapped
)
8930 struct ws_win
*win
, *ww
;
8931 struct swm_region
*r
;
8934 xcb_get_geometry_reply_t
*gr
;
8935 xcb_window_t trans
= XCB_WINDOW_NONE
;
8936 uint32_t i
, wa
[2], new_flags
;
8937 int ws_idx
, force_ws
= -1;
8938 char *class, *instance
, *name
;
8940 if ((win
= find_window(id
)) != NULL
) {
8941 DNPRINTF(SWM_D_MISC
, "manage_window: win %#x already "
8942 "managed; skipping.)\n", id
);
8943 return (win
); /* Already managed. */
8946 /* See if window is on the unmanaged list. */
8947 if ((win
= find_unmanaged_window(id
)) != NULL
) {
8948 DNPRINTF(SWM_D_MISC
, "manage_window: win %#x found on "
8949 "unmanaged list.\n", id
);
8950 TAILQ_REMOVE(&win
->ws
->unmanagedlist
, win
, entry
);
8953 set_child_transient(win
, &trans
);
8957 DNPRINTF(SWM_D_MISC
, "manage_window: win %#x is new.\n", id
);
8960 /* Try to get initial window geometry. */
8961 gr
= xcb_get_geometry_reply(conn
, xcb_get_geometry(conn
, id
), NULL
);
8963 DNPRINTF(SWM_D_MISC
, "manage_window: get geometry failed.\n");
8967 /* Create and initialize ws_win object. */
8968 if ((win
= calloc(1, sizeof(struct ws_win
))) == NULL
)
8969 err(1, "manage_window: calloc: failed to allocate memory for "
8974 /* Figureout which region the window belongs to. */
8975 r
= root_to_region(gr
->root
, SWM_CK_ALL
);
8977 /* Ignore window border if there is one. */
8978 WIDTH(win
) = gr
->width
;
8979 HEIGHT(win
) = gr
->height
;
8980 X(win
) = gr
->x
+ gr
->border_width
- border_width
;
8981 Y(win
) = gr
->y
+ gr
->border_width
- border_width
;
8982 win
->bordered
= true;
8983 win
->mapped
= mapped
;
8984 win
->s
= r
->s
; /* this never changes */
8988 /* Select which X events to monitor and set border pixel color. */
8989 wa
[0] = win
->s
->c
[SWM_S_COLOR_UNFOCUS
].pixel
;
8990 wa
[1] = XCB_EVENT_MASK_ENTER_WINDOW
| XCB_EVENT_MASK_PROPERTY_CHANGE
|
8991 XCB_EVENT_MASK_STRUCTURE_NOTIFY
;
8993 wa
[1] |= XCB_EVENT_MASK_LEAVE_WINDOW
| XCB_EVENT_MASK_FOCUS_CHANGE
;
8996 xcb_change_window_attributes(conn
, win
->id
, XCB_CW_BORDER_PIXEL
|
8997 XCB_CW_EVENT_MASK
, wa
);
8999 /* Get WM_SIZE_HINTS. */
9000 xcb_icccm_get_wm_normal_hints_reply(conn
,
9001 xcb_icccm_get_wm_normal_hints(conn
, win
->id
),
9005 xcb_icccm_get_wm_hints_reply(conn
,
9006 xcb_icccm_get_wm_hints(conn
, win
->id
),
9009 /* Get WM_TRANSIENT_FOR; see if window is a transient. */
9010 xcb_icccm_get_wm_transient_for_reply(conn
,
9011 xcb_icccm_get_wm_transient_for(conn
, win
->id
),
9014 win
->transient
= trans
;
9015 set_child_transient(win
, &win
->transient
);
9018 /* Get WM_PROTOCOLS. */
9019 get_wm_protocols(win
);
9021 /* Set initial quirks based on EWMH. */
9022 ewmh_autoquirk(win
);
9024 /* Determine initial quirks. */
9025 xcb_icccm_get_wm_class_reply(conn
,
9026 xcb_icccm_get_wm_class(conn
, win
->id
),
9029 class = win
->ch
.class_name
? win
->ch
.class_name
: "";
9030 instance
= win
->ch
.instance_name
? win
->ch
.instance_name
: "";
9031 name
= get_win_name(win
->id
);
9033 DNPRINTF(SWM_D_CLASS
, "manage_window: class: %s, instance: %s, "
9034 "name: %s\n", class, instance
, name
);
9036 /* java is retarded so treat it special */
9037 if (strstr(instance
, "sun-awt")) {
9038 DNPRINTF(SWM_D_CLASS
, "manage_window: java window detected.\n");
9042 TAILQ_FOREACH(qp
, &quirks
, entry
) {
9043 if (regexec(&qp
->regex_class
, class, 0, NULL
, 0) == 0 &&
9044 regexec(&qp
->regex_instance
, instance
, 0, NULL
, 0) == 0 &&
9045 regexec(&qp
->regex_name
, name
, 0, NULL
, 0) == 0) {
9046 DNPRINTF(SWM_D_CLASS
, "manage_window: matched "
9047 "quirk: %s:%s:%s mask: %#x, ws: %d\n", qp
->class,
9048 qp
->instance
, qp
->name
, qp
->quirk
, qp
->ws
);
9049 win
->quirks
= qp
->quirk
;
9050 if (qp
->ws
>= 0 && qp
->ws
< workspace_limit
)
9057 /* Reset font sizes (the bruteforce way; no default keybinding). */
9058 if (win
->quirks
& SWM_Q_XTERM_FONTADJ
) {
9059 for (i
= 0; i
< SWM_MAX_FONT_STEPS
; i
++)
9060 fake_keypress(win
, XK_KP_Subtract
, XCB_MOD_MASK_SHIFT
);
9061 for (i
= 0; i
< SWM_MAX_FONT_STEPS
; i
++)
9062 fake_keypress(win
, XK_KP_Add
, XCB_MOD_MASK_SHIFT
);
9065 /* Figure out which workspace the window belongs to. */
9066 if (!(win
->quirks
& SWM_Q_IGNOREPID
) &&
9067 (p
= find_pid(window_get_pid(win
->id
))) != NULL
) {
9068 win
->ws
= &r
->s
->ws
[p
->ws
];
9069 TAILQ_REMOVE(&pidlist
, p
, entry
);
9072 } else if ((ws_idx
= get_ws_idx(win
)) != -1 &&
9074 /* _SWM_WS is set; use that. */
9075 win
->ws
= &r
->s
->ws
[ws_idx
];
9076 } else if (trans
&& (ww
= find_window(trans
)) != NULL
) {
9077 /* Launch transients in the same ws as parent. */
9084 win
->ws
= &r
->s
->ws
[force_ws
];
9086 /* Set the _NET_WM_DESKTOP atom. */
9087 DNPRINTF(SWM_D_PROP
, "manage_window: set _NET_WM_DESKTOP: %d\n",
9089 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
,
9090 ewmh
[_NET_WM_DESKTOP
].atom
, XCB_ATOM_CARDINAL
, 32, 1, &win
->ws
->idx
);
9092 /* Remove any _SWM_WS now that we set _NET_WM_DESKTOP. */
9093 xcb_delete_property(conn
, win
->id
, a_swm_ws
);
9095 /* WS must already be set for this to work. */
9096 store_float_geom(win
);
9098 /* Make sure window is positioned inside its region, if its active. */
9100 region_containment(win
, r
, SWM_CW_ALLSIDES
|
9101 SWM_CW_HARDBOUNDARY
);
9106 /* Figure out where to insert the window in the workspace list. */
9107 if (trans
&& (ww
= find_window(trans
)))
9108 TAILQ_INSERT_AFTER(&win
->ws
->winlist
, ww
, win
, entry
);
9109 else if (win
->ws
->focus
&& spawn_pos
== SWM_STACK_ABOVE
)
9110 TAILQ_INSERT_AFTER(&win
->ws
->winlist
, win
->ws
->focus
, win
,
9112 else if (win
->ws
->focus
&& spawn_pos
== SWM_STACK_BELOW
)
9113 TAILQ_INSERT_BEFORE(win
->ws
->focus
, win
, entry
);
9114 else switch (spawn_pos
) {
9117 case SWM_STACK_ABOVE
:
9118 TAILQ_INSERT_TAIL(&win
->ws
->winlist
, win
, entry
);
9120 case SWM_STACK_BOTTOM
:
9121 case SWM_STACK_BELOW
:
9122 TAILQ_INSERT_HEAD(&win
->ws
->winlist
, win
, entry
);
9125 ewmh_update_client_list();
9127 TAILQ_INSERT_HEAD(&win
->ws
->stack
, win
, stack_entry
);
9130 /* Get/apply initial _NET_WM_STATE */
9131 ewmh_get_wm_state(win
);
9134 new_flags
= win
->ewmh_flags
;
9136 if (win
->quirks
& SWM_Q_FLOAT
)
9137 new_flags
|= EWMH_F_ABOVE
;
9139 if (win
->quirks
& SWM_Q_ANYWHERE
)
9140 new_flags
|= SWM_F_MANUAL
;
9142 ewmh_apply_flags(win
, new_flags
);
9143 ewmh_update_wm_state(win
);
9145 /* Set initial _NET_WM_ALLOWED_ACTIONS */
9146 ewmh_update_actions(win
);
9150 DNPRINTF(SWM_D_MISC
, "manage_window: done. win %#x, (x,y) w x h: "
9151 "(%d,%d) %d x %d, ws: %d, iconic: %s, transient: %#x\n", win
->id
,
9152 X(win
), Y(win
), WIDTH(win
), HEIGHT(win
), win
->ws
->idx
,
9153 YESNO(ICONIC(win
)), win
->transient
);
9159 free_window(struct ws_win
*win
)
9161 DNPRINTF(SWM_D_MISC
, "free_window: win %#x\n", win
->id
);
9166 TAILQ_REMOVE(&win
->ws
->unmanagedlist
, win
, entry
);
9168 xcb_icccm_get_wm_class_reply_wipe(&win
->ch
);
9173 memset(win
, 0xff, sizeof *win
); /* XXX kill later */
9176 DNPRINTF(SWM_D_MISC
, "free_window: done.\n");
9180 unmanage_window(struct ws_win
*win
)
9182 struct ws_win
*parent
;
9187 DNPRINTF(SWM_D_MISC
, "unmanage_window: win %#x\n", win
->id
);
9190 parent
= find_window(win
->transient
);
9192 parent
->focus_child
= NULL
;
9195 TAILQ_REMOVE(&win
->ws
->stack
, win
, stack_entry
);
9196 TAILQ_REMOVE(&win
->ws
->winlist
, win
, entry
);
9197 TAILQ_INSERT_TAIL(&win
->ws
->unmanagedlist
, win
, entry
);
9199 ewmh_update_client_list();
9203 expose(xcb_expose_event_t
*e
)
9206 struct swm_region
*r
;
9208 DNPRINTF(SWM_D_EVENT
, "expose: win %#x\n", e
->window
);
9210 num_screens
= get_screen_count();
9211 for (i
= 0; i
< num_screens
; i
++)
9212 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
9213 if (e
->window
== WINID(r
->bar
))
9221 focusin(xcb_focus_in_event_t
*e
)
9223 DNPRINTF(SWM_D_EVENT
, "focusin: win %#x, mode: %s(%u), "
9224 "detail: %s(%u)\n", e
->event
, get_notify_mode_label(e
->mode
),
9225 e
->mode
, get_notify_detail_label(e
->detail
), e
->detail
);
9229 focusout(xcb_focus_out_event_t
*e
)
9231 DNPRINTF(SWM_D_EVENT
, "focusout: win %#x, mode: %s(%u), "
9232 "detail: %s(%u)\n", e
->event
, get_notify_mode_label(e
->mode
),
9233 e
->mode
, get_notify_detail_label(e
->detail
), e
->detail
);
9238 keypress(xcb_key_press_event_t
*e
)
9240 xcb_keysym_t keysym
;
9243 keysym
= xcb_key_press_lookup_keysym(syms
, e
, 0);
9245 DNPRINTF(SWM_D_EVENT
, "keypress: keysym: %u, win (x,y): %#x (%d,%d), "
9246 "detail: %u, time: %u, root (x,y): %#x (%d,%d), child: %#x, "
9247 "state: %u, same_screen: %s\n", keysym
, e
->event
, e
->event_x
,
9248 e
->event_y
, e
->detail
, e
->time
, e
->root
, e
->root_x
, e
->root_y
,
9249 e
->child
, e
->state
, YESNO(e
->same_screen
));
9251 if ((kp
= key_lookup(CLEANMASK(e
->state
), keysym
)) == NULL
)
9254 last_event_time
= e
->time
;
9256 if (kp
->funcid
== KF_SPAWN_CUSTOM
)
9257 spawn_custom(root_to_region(e
->root
, SWM_CK_ALL
),
9258 &(keyfuncs
[kp
->funcid
].args
), kp
->spawn_name
);
9259 else if (keyfuncs
[kp
->funcid
].func
)
9260 keyfuncs
[kp
->funcid
].func(root_to_region(e
->root
, SWM_CK_ALL
),
9261 &(keyfuncs
[kp
->funcid
].args
));
9264 /* Unfreeze grab events. */
9265 xcb_allow_events(conn
, XCB_ALLOW_ASYNC_KEYBOARD
, e
->time
);
9268 DNPRINTF(SWM_D_EVENT
, "keypress: done.\n");
9272 buttonpress(xcb_button_press_event_t
*e
)
9274 struct ws_win
*win
= NULL
;
9275 struct swm_region
*r
, *old_r
;
9277 bool handled
= false;
9279 DNPRINTF(SWM_D_EVENT
, "buttonpress: win (x,y): %#x (%d,%d), "
9280 "detail: %u, time: %u, root (x,y): %#x (%d,%d), child: %#x, "
9281 "state: %u, same_screen: %s\n", e
->event
, e
->event_x
, e
->event_y
,
9282 e
->detail
, e
->time
, e
->root
, e
->root_x
, e
->root_y
, e
->child
,
9283 e
->state
, YESNO(e
->same_screen
));
9285 if (e
->event
== e
->root
) {
9286 if (e
->child
!= 0) {
9287 win
= find_window(e
->child
);
9288 /* Pass ButtonPress to window if it isn't managed. */
9292 /* Focus on empty region */
9293 /* If no windows on region if its empty. */
9294 r
= root_to_region(e
->root
, SWM_CK_POINTER
);
9296 DNPRINTF(SWM_D_EVENT
, "buttonpress: "
9297 "NULL region; ignoring.\n");
9301 if (TAILQ_EMPTY(&r
->ws
->winlist
)) {
9302 old_r
= root_to_region(e
->root
, SWM_CK_FOCUS
);
9303 if (old_r
&& old_r
!= r
)
9304 unfocus_win(old_r
->ws
->focus
);
9306 xcb_set_input_focus(conn
,
9307 XCB_INPUT_FOCUS_PARENT
, e
->root
, e
->time
);
9309 /* Clear bar since empty. */
9317 win
= find_window(e
->event
);
9323 last_event_time
= e
->time
;
9325 focus_win(get_focus_magic(win
));
9327 for (i
= 0; i
< LENGTH(buttons
); i
++)
9328 if (client_click
== buttons
[i
].action
&& buttons
[i
].func
&&
9329 buttons
[i
].button
== e
->detail
&&
9330 CLEANMASK(buttons
[i
].mask
) == CLEANMASK(e
->state
)) {
9331 buttons
[i
].func(win
, &buttons
[i
].args
);
9337 DNPRINTF(SWM_D_EVENT
, "buttonpress: passing to window.\n");
9338 /* Replay event to event window */
9339 xcb_allow_events(conn
, XCB_ALLOW_REPLAY_POINTER
, e
->time
);
9341 DNPRINTF(SWM_D_EVENT
, "buttonpress: handled.\n");
9342 /* Unfreeze grab events. */
9343 xcb_allow_events(conn
, XCB_ALLOW_SYNC_POINTER
, e
->time
);
9351 print_win_geom(xcb_window_t w
)
9353 xcb_get_geometry_reply_t
*wa
;
9355 wa
= xcb_get_geometry_reply(conn
, xcb_get_geometry(conn
, w
), NULL
);
9357 DNPRINTF(SWM_D_MISC
, "print_win_geom: window not found: %#x\n",
9362 DNPRINTF(SWM_D_MISC
, "print_win_geom: win %#x, root: %#x, "
9363 "depth: %u, (x,y) w x h: (%d,%d) %d x %d, border: %d\n",
9364 w
, wa
->root
, wa
->depth
, wa
->x
, wa
->y
, wa
->width
, wa
->height
,
9373 get_stack_mode_name(uint8_t mode
)
9378 case XCB_STACK_MODE_ABOVE
:
9381 case XCB_STACK_MODE_BELOW
:
9384 case XCB_STACK_MODE_TOP_IF
:
9387 case XCB_STACK_MODE_BOTTOM_IF
:
9390 case XCB_STACK_MODE_OPPOSITE
:
9402 configurerequest(xcb_configure_request_event_t
*e
)
9405 struct swm_region
*r
= NULL
;
9407 uint32_t wc
[7] = {0};
9411 if ((win
= find_window(e
->window
)) == NULL
)
9412 if ((win
= find_unmanaged_window(e
->window
)) == NULL
)
9416 if (swm_debug
& SWM_D_EVENT
) {
9417 print_win_geom(e
->window
);
9419 DNPRINTF(SWM_D_EVENT
, "configurerequest: win %#x, "
9420 "parent: %#x, new: %s, value_mask: %u { ", e
->window
,
9421 e
->parent
, YESNO(new), e
->value_mask
);
9422 if (e
->value_mask
& XCB_CONFIG_WINDOW_X
)
9423 DPRINTF("X: %d ", e
->x
);
9424 if (e
->value_mask
& XCB_CONFIG_WINDOW_Y
)
9425 DPRINTF("Y: %d ", e
->y
);
9426 if (e
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
9427 DPRINTF("W: %u ", e
->width
);
9428 if (e
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
9429 DPRINTF("H: %u ", e
->height
);
9430 if (e
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
9431 DPRINTF("Border: %u ", e
->border_width
);
9432 if (e
->value_mask
& XCB_CONFIG_WINDOW_SIBLING
)
9433 DPRINTF("Sibling: %#x ", e
->sibling
);
9434 if (e
->value_mask
& XCB_CONFIG_WINDOW_STACK_MODE
)
9435 DPRINTF("StackMode: %s(%u) ",
9436 get_stack_mode_name(e
->stack_mode
), e
->stack_mode
);
9442 if (e
->value_mask
& XCB_CONFIG_WINDOW_X
) {
9443 mask
|= XCB_CONFIG_WINDOW_X
;
9446 if (e
->value_mask
& XCB_CONFIG_WINDOW_Y
) {
9447 mask
|= XCB_CONFIG_WINDOW_Y
;
9450 if (e
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
) {
9451 mask
|= XCB_CONFIG_WINDOW_WIDTH
;
9454 if (e
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
) {
9455 mask
|= XCB_CONFIG_WINDOW_HEIGHT
;
9456 wc
[i
++] = e
->height
;
9458 if (e
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
) {
9459 mask
|= XCB_CONFIG_WINDOW_BORDER_WIDTH
;
9460 wc
[i
++] = e
->border_width
;
9462 if (e
->value_mask
& XCB_CONFIG_WINDOW_SIBLING
) {
9463 mask
|= XCB_CONFIG_WINDOW_SIBLING
;
9464 wc
[i
++] = e
->sibling
;
9466 if (e
->value_mask
& XCB_CONFIG_WINDOW_STACK_MODE
) {
9467 mask
|= XCB_CONFIG_WINDOW_STACK_MODE
;
9468 wc
[i
++] = e
->stack_mode
;
9472 xcb_configure_window(conn
, e
->window
, mask
, wc
);
9475 } else if ((!MANUAL(win
) || win
->quirks
& SWM_Q_ANYWHERE
) &&
9476 !FULLSCREEN(win
) && !MAXIMIZED(win
)) {
9479 else if (win
->ws
->old_r
)
9482 /* windows are centered unless ANYWHERE quirk is set. */
9483 if (win
->quirks
& SWM_Q_ANYWHERE
) {
9484 if (e
->value_mask
& XCB_CONFIG_WINDOW_X
) {
9485 win
->g_float
.x
= e
->x
;
9487 win
->g_float
.x
-= X(r
);
9490 if (e
->value_mask
& XCB_CONFIG_WINDOW_Y
) {
9491 win
->g_float
.y
= e
->y
;
9493 win
->g_float
.y
-= Y(r
);
9497 if (e
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
9498 win
->g_float
.w
= e
->width
;
9500 if (e
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
9501 win
->g_float
.h
= e
->height
;
9503 win
->g_floatvalid
= true;
9505 if (!MAXIMIZED(win
) && !FULLSCREEN(win
) &&
9506 (TRANS(win
) || (ABOVE(win
) &&
9507 win
->ws
->cur_layout
!= &layouts
[SWM_MAX_STACK
]))) {
9508 WIDTH(win
) = win
->g_float
.w
;
9509 HEIGHT(win
) = win
->g_float
.h
;
9512 update_floater(win
);
9527 DNPRINTF(SWM_D_EVENT
, "configurerequest: done.\n");
9531 configurenotify(xcb_configure_notify_event_t
*e
)
9535 DNPRINTF(SWM_D_EVENT
, "configurenotify: win %#x, event win: %#x, "
9536 "(x,y) WxH: (%d,%d) %ux%u, border: %u, above_sibling: %#x, "
9537 "override_redirect: %s\n", e
->window
, e
->event
, e
->x
, e
->y
,
9538 e
->width
, e
->height
, e
->border_width
, e
->above_sibling
,
9539 YESNO(e
->override_redirect
));
9541 win
= find_window(e
->window
);
9543 xcb_icccm_get_wm_normal_hints_reply(conn
,
9544 xcb_icccm_get_wm_normal_hints(conn
, win
->id
),
9547 if (font_adjusted
) {
9555 destroynotify(xcb_destroy_notify_event_t
*e
)
9559 DNPRINTF(SWM_D_EVENT
, "destroynotify: win %#x\n", e
->window
);
9561 if ((win
= find_window(e
->window
)) == NULL
) {
9562 if ((win
= find_unmanaged_window(e
->window
)) == NULL
)
9568 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
9569 /* If we were focused, make sure we focus on something else. */
9570 if (win
== win
->ws
->focus
)
9571 win
->ws
->focus_pending
= get_focus_prev(win
);
9574 unmanage_window(win
);
9577 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& WS_FOCUSED(win
->ws
)) {
9578 if (win
->ws
->focus_pending
) {
9579 focus_win(win
->ws
->focus_pending
);
9580 win
->ws
->focus_pending
= NULL
;
9581 } else if (win
== win
->ws
->focus
) {
9582 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
,
9583 win
->ws
->r
->id
, XCB_CURRENT_TIME
);
9594 get_notify_detail_label(uint8_t detail
)
9599 case XCB_NOTIFY_DETAIL_ANCESTOR
:
9602 case XCB_NOTIFY_DETAIL_VIRTUAL
:
9605 case XCB_NOTIFY_DETAIL_INFERIOR
:
9608 case XCB_NOTIFY_DETAIL_NONLINEAR
:
9609 label
= "Nonlinear";
9611 case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL
:
9612 label
= "NonlinearVirtual";
9614 case XCB_NOTIFY_DETAIL_POINTER
:
9617 case XCB_NOTIFY_DETAIL_POINTER_ROOT
:
9618 label
= "PointerRoot";
9620 case XCB_NOTIFY_DETAIL_NONE
:
9631 get_notify_mode_label(uint8_t mode
)
9636 case XCB_NOTIFY_MODE_NORMAL
:
9639 case XCB_NOTIFY_MODE_GRAB
:
9642 case XCB_NOTIFY_MODE_UNGRAB
:
9645 case XCB_NOTIFY_MODE_WHILE_GRABBED
:
9646 label
= "WhileGrabbed";
9657 enternotify(xcb_enter_notify_event_t
*e
)
9660 struct swm_region
*r
;
9662 DNPRINTF(SWM_D_FOCUS
, "enternotify: time: %u, win (x,y): %#x "
9663 "(%d,%d), mode: %s(%d), detail: %s(%d), root (x,y): %#x (%d,%d), "
9664 "child: %#x, same_screen_focus: %s, state: %d\n",
9665 e
->time
, e
->event
, e
->event_x
, e
->event_y
,
9666 get_notify_mode_label(e
->mode
), e
->mode
,
9667 get_notify_detail_label(e
->detail
), e
->detail
,
9668 e
->root
, e
->root_x
, e
->root_y
, e
->child
,
9669 YESNO(e
->same_screen_focus
), e
->state
);
9671 if (focus_mode
== SWM_FOCUS_MANUAL
&&
9672 e
->mode
== XCB_NOTIFY_MODE_NORMAL
) {
9673 DNPRINTF(SWM_D_EVENT
, "enternotify: manual focus; ignoring.\n");
9677 if (focus_mode
!= SWM_FOCUS_FOLLOW
&&
9678 e
->mode
== XCB_NOTIFY_MODE_UNGRAB
) {
9679 DNPRINTF(SWM_D_EVENT
, "enternotify: ungrab; ignoring.\n");
9683 last_event_time
= e
->time
;
9685 if ((win
= find_window(e
->event
)) == NULL
) {
9686 if (e
->event
== e
->root
) {
9687 /* If no windows on pointer region, then focus root. */
9688 r
= root_to_region(e
->root
, SWM_CK_POINTER
);
9690 DNPRINTF(SWM_D_EVENT
, "enternotify: "
9691 "NULL region; ignoring.\n");
9697 DNPRINTF(SWM_D_EVENT
, "enternotify: window is NULL; "
9702 if (e
->mode
== XCB_NOTIFY_MODE_NORMAL
&&
9703 e
->detail
== XCB_NOTIFY_DETAIL_INFERIOR
) {
9704 DNPRINTF(SWM_D_EVENT
, "enternotify: entering from "
9705 "inferior; ignoring\n");
9709 focus_win(get_focus_magic(win
));
9717 leavenotify(xcb_leave_notify_event_t
*e
)
9719 DNPRINTF(SWM_D_FOCUS
, "leavenotify: time: %u, win (x,y): %#x "
9720 "(%d,%d), mode: %s(%d), detail: %s(%d), root (x,y): %#x (%d,%d), "
9721 "child: %#x, same_screen_focus: %s, state: %d\n",
9722 e
->time
, e
->event
, e
->event_x
, e
->event_y
,
9723 get_notify_mode_label(e
->mode
), e
->mode
,
9724 get_notify_detail_label(e
->detail
), e
->detail
,
9725 e
->root
, e
->root_x
, e
->root_y
, e
->child
,
9726 YESNO(e
->same_screen_focus
), e
->state
);
9731 mapnotify(xcb_map_notify_event_t
*e
)
9733 struct ws_win
*win
, *parent
= NULL
;
9734 struct workspace
*ws
;
9736 DNPRINTF(SWM_D_EVENT
, "mapnotify: win %#x\n", e
->window
);
9738 if ((win
= manage_window(e
->window
, spawn_position
, true)) == NULL
)
9742 /* Need to know if win was mapped due to ws switch. */
9743 if (ws
->state
== SWM_WS_STATE_MAPPED
) {
9744 if (ws
->focus_pending
&& TRANS(ws
->focus_pending
))
9745 parent
= find_window(win
->transient
);
9747 /* If window's parent is maximized, don't clear it. */
9748 if ((parent
== NULL
) || !MAXIMIZED(parent
))
9749 if (clear_maximized(ws
) > 0)
9754 set_win_state(win
, XCB_ICCCM_WM_STATE_NORMAL
);
9756 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& WS_FOCUSED(win
->ws
)) {
9757 if (ws
->focus_pending
== win
) {
9759 ws
->focus_pending
= NULL
;
9760 center_pointer(win
->ws
->r
);
9769 mappingnotify(xcb_mapping_notify_event_t
*e
)
9772 int i
, j
, num_screens
;
9774 xcb_refresh_keyboard_mapping(syms
, e
);
9776 if (e
->request
== XCB_MAPPING_KEYBOARD
) {
9779 /* Regrab buttons on all managed windows. */
9780 num_screens
= get_screen_count();
9781 for (i
= 0; i
< num_screens
; i
++)
9782 for (j
= 0; j
< workspace_limit
; j
++)
9783 TAILQ_FOREACH(w
, &screens
[i
].ws
[j
].winlist
,
9790 maprequest(xcb_map_request_event_t
*e
)
9792 struct ws_win
*win
, *w
= NULL
;
9793 xcb_get_window_attributes_reply_t
*war
;
9795 DNPRINTF(SWM_D_EVENT
, "maprequest: win %#x\n",
9798 war
= xcb_get_window_attributes_reply(conn
,
9799 xcb_get_window_attributes(conn
, e
->window
),
9802 DNPRINTF(SWM_D_EVENT
, "maprequest: window lost.\n");
9806 if (war
->override_redirect
) {
9807 DNPRINTF(SWM_D_EVENT
, "maprequest: override_redirect; "
9812 win
= manage_window(e
->window
, spawn_position
,
9813 (war
->map_state
== XCB_MAP_STATE_VIEWABLE
));
9817 /* The new window should get focus; prepare. */
9818 if (focus_mode
!= SWM_FOCUS_FOLLOW
&&
9819 !(win
->quirks
& SWM_Q_NOFOCUSONMAP
) &&
9820 (!(win
->hints
.flags
& XCB_ICCCM_WM_HINT_INPUT
) ||
9821 (win
->hints
.flags
& XCB_ICCCM_WM_HINT_INPUT
&&
9822 win
->hints
.input
))) {
9823 if (win
->quirks
& SWM_Q_FOCUSONMAP_SINGLE
) {
9824 /* See if other wins of same type are already mapped. */
9825 TAILQ_FOREACH(w
, &win
->ws
->winlist
, entry
) {
9826 if (w
== win
|| !w
->mapped
)
9829 if (w
->ch
.class_name
&&
9830 win
->ch
.class_name
&&
9831 strcmp(w
->ch
.class_name
,
9832 win
->ch
.class_name
) == 0 &&
9833 w
->ch
.instance_name
&&
9834 win
->ch
.instance_name
&&
9835 strcmp(w
->ch
.instance_name
,
9836 win
->ch
.instance_name
) == 0)
9842 win
->ws
->focus_pending
= get_focus_magic(win
);
9845 /* All windows need to be mapped if they are in the current workspace.*/
9849 /* Ignore EnterNotify to handle the mapnotify without interference. */
9850 if (focus_mode
== SWM_FOCUS_DEFAULT
)
9851 event_drain(XCB_ENTER_NOTIFY
);
9854 DNPRINTF(SWM_D_EVENT
, "maprequest: done.\n");
9858 motionnotify(xcb_motion_notify_event_t
*e
)
9860 struct swm_region
*r
= NULL
;
9863 DNPRINTF(SWM_D_FOCUS
, "motionnotify: time: %u, win (x,y): %#x "
9864 "(%d,%d), detail: %s(%d), root (x,y): %#x (%d,%d), "
9865 "child: %#x, same_screen_focus: %s, state: %d\n",
9866 e
->time
, e
->event
, e
->event_x
, e
->event_y
,
9867 get_notify_detail_label(e
->detail
), e
->detail
,
9868 e
->root
, e
->root_x
, e
->root_y
, e
->child
,
9869 YESNO(e
->same_screen
), e
->state
);
9871 last_event_time
= e
->time
;
9873 if (focus_mode
== SWM_FOCUS_MANUAL
)
9876 num_screens
= get_screen_count();
9877 for (i
= 0; i
< num_screens
; i
++)
9878 if (screens
[i
].root
== e
->root
)
9881 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
9882 if (X(r
) <= e
->root_x
&& e
->root_x
< MAX_X(r
) &&
9883 Y(r
) <= e
->root_y
&& e
->root_y
< MAX_Y(r
))
9891 get_atom_name(xcb_atom_t atom
)
9894 #ifdef SWM_DEBUG_ATOM_NAMES
9896 * This should be disabled during most debugging since
9897 * xcb_get_* causes an xcb_flush.
9900 xcb_get_atom_name_reply_t
*r
;
9902 r
= xcb_get_atom_name_reply(conn
,
9903 xcb_get_atom_name(conn
, atom
),
9906 len
= xcb_get_atom_name_name_length(r
);
9908 name
= malloc(len
+ 1);
9910 memcpy(name
, xcb_get_atom_name_name(r
), len
);
9924 propertynotify(xcb_property_notify_event_t
*e
)
9927 struct workspace
*ws
;
9931 name
= get_atom_name(e
->atom
);
9932 DNPRINTF(SWM_D_EVENT
, "propertynotify: win %#x, atom: %s(%u), "
9933 "time: %#x, state: %u\n", e
->window
, name
, e
->atom
, e
->time
,
9937 win
= find_window(e
->window
);
9943 last_event_time
= e
->time
;
9945 if (e
->atom
== a_state
) {
9946 /* State just changed, make sure it gets focused if mapped. */
9947 if (e
->state
== XCB_PROPERTY_NEW_VALUE
) {
9948 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& WS_FOCUSED(ws
)) {
9950 ws
->focus_pending
== win
) {
9951 focus_win(ws
->focus_pending
);
9952 ws
->focus_pending
= NULL
;
9956 } else if (e
->atom
== XCB_ATOM_WM_CLASS
||
9957 e
->atom
== XCB_ATOM_WM_NAME
) {
9959 } else if (e
->atom
== a_prot
) {
9960 get_wm_protocols(win
);
9967 unmapnotify(xcb_unmap_notify_event_t
*e
)
9970 struct workspace
*ws
;
9972 DNPRINTF(SWM_D_EVENT
, "unmapnotify: win %#x\n", e
->window
);
9974 /* If we aren't managing the window, then ignore. */
9975 win
= find_window(e
->window
);
9976 if (win
== NULL
|| win
->id
!= e
->window
)
9979 /* Do nothing if already withdrawn. */
9980 if (!win
->mapped
&& !ICONIC(win
))
9984 win
->mapped
= false;
9986 /* If win was focused, make sure to focus on something else. */
9987 if (win
== ws
->focus
) {
9988 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
9989 ws
->focus_pending
= get_focus_prev(win
);
9990 DNPRINTF(SWM_D_EVENT
, "unmapnotify: "
9991 "focus_pending: %#x\n",
9992 WINID(ws
->focus_pending
));
10000 set_win_state(win
, XCB_ICCCM_WM_STATE_ICONIC
);
10003 set_win_state(win
, XCB_ICCCM_WM_STATE_WITHDRAWN
);
10004 unmanage_window(win
);
10010 /* Update focus if ws is active. */
10011 if (WS_FOCUSED(ws
)) {
10012 if (focus_mode
== SWM_FOCUS_FOLLOW
) {
10013 focus_win(get_pointer_win(ws
->r
->s
->root
));
10014 } else if (ws
->focus_pending
) {
10015 focus_win(ws
->focus_pending
);
10016 ws
->focus_pending
= NULL
;
10017 } else if (ws
->focus
== NULL
) {
10018 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
,
10019 ws
->r
->id
, XCB_CURRENT_TIME
);
10023 center_pointer(ws
->r
);
10029 get_source_type_label(uint32_t type
)
10034 case EWMH_SOURCE_TYPE_NONE
:
10037 case EWMH_SOURCE_TYPE_NORMAL
:
10040 case EWMH_SOURCE_TYPE_OTHER
:
10052 clientmessage(xcb_client_message_event_t
*e
)
10054 struct ws_win
*win
;
10055 struct swm_region
*r
= NULL
;
10058 int num_screens
, i
;
10059 xcb_map_request_event_t mre
;
10063 name
= get_atom_name(e
->type
);
10064 DNPRINTF(SWM_D_EVENT
, "clientmessage: win %#x, atom: %s(%u)\n",
10065 e
->window
, name
, e
->type
);
10069 if (e
->type
== ewmh
[_NET_CURRENT_DESKTOP
].atom
) {
10070 num_screens
= get_screen_count();
10071 for (i
= 0; i
< num_screens
; i
++)
10072 if (screens
[i
].root
== e
->window
) {
10073 r
= screens
[i
].r_focus
;
10077 if (r
&& e
->data
.data32
[0] < (uint32_t)workspace_limit
) {
10078 a
.id
= e
->data
.data32
[0];
10086 win
= find_window(e
->window
);
10088 if (e
->type
== ewmh
[_NET_ACTIVE_WINDOW
].atom
) {
10089 /* Manage the window with maprequest. */
10090 DNPRINTF(SWM_D_EVENT
, "clientmessage: request focus on "
10091 "unmanaged window.\n");
10092 mre
.window
= e
->window
;
10098 if (e
->type
== ewmh
[_NET_ACTIVE_WINDOW
].atom
) {
10099 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_ACTIVE_WINDOW, "
10100 "source_type: %s(%d)\n",
10101 get_source_type_label(e
->data
.data32
[0]),
10102 e
->data
.data32
[0]);
10105 * Allow focus changes that are a result of direct user
10106 * action and from applications that use the old EWMH spec.
10108 if (e
->data
.data32
[0] != EWMH_SOURCE_TYPE_NORMAL
||
10109 win
->quirks
& SWM_Q_OBEYAPPFOCUSREQ
) {
10110 if (WS_FOCUSED(win
->ws
))
10113 win
->ws
->focus_pending
= win
;
10115 } else if (e
->type
== ewmh
[_NET_CLOSE_WINDOW
].atom
) {
10116 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_CLOSE_WINDOW\n");
10117 if (win
->can_delete
)
10118 client_msg(win
, a_delete
, 0);
10120 xcb_kill_client(conn
, win
->id
);
10121 } else if (e
->type
== ewmh
[_NET_MOVERESIZE_WINDOW
].atom
) {
10122 DNPRINTF(SWM_D_EVENT
,
10123 "clientmessage: _NET_MOVERESIZE_WINDOW\n");
10125 if (e
->data
.data32
[0] & (1<<8)) /* x */
10126 X(win
) = e
->data
.data32
[1];
10127 if (e
->data
.data32
[0] & (1<<9)) /* y */
10128 Y(win
) = e
->data
.data32
[2];
10129 if (e
->data
.data32
[0] & (1<<10)) /* width */
10130 WIDTH(win
) = e
->data
.data32
[3];
10131 if (e
->data
.data32
[0] & (1<<11)) /* height */
10132 HEIGHT(win
) = e
->data
.data32
[4];
10134 update_window(win
);
10136 /* Notify no change was made. */
10137 config_win(win
, NULL
);
10138 /* TODO: Change stack sizes */
10140 } else if (e
->type
== ewmh
[_NET_RESTACK_WINDOW
].atom
) {
10141 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_RESTACK_WINDOW\n");
10142 val
[0] = e
->data
.data32
[1]; /* Sibling window. */
10143 val
[1] = e
->data
.data32
[2]; /* Stack mode detail. */
10145 xcb_configure_window(conn
, win
->id
, XCB_CONFIG_WINDOW_SIBLING
|
10146 XCB_CONFIG_WINDOW_STACK_MODE
, val
);
10147 } else if (e
->type
== ewmh
[_NET_WM_STATE
].atom
) {
10148 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_WM_STATE\n");
10149 ewmh_change_wm_state(win
, e
->data
.data32
[1], e
->data
.data32
[0]);
10150 if (e
->data
.data32
[2])
10151 ewmh_change_wm_state(win
, e
->data
.data32
[2],
10152 e
->data
.data32
[0]);
10154 ewmh_update_wm_state(win
);
10156 } else if (e
->type
== ewmh
[_NET_WM_DESKTOP
].atom
) {
10157 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_WM_DESKTOP\n");
10160 win_to_ws(win
, e
->data
.data32
[0], true);
10162 /* Restack if either the source or destination ws is mapped. */
10163 if (r
!= NULL
|| win
->ws
->r
!= NULL
) {
10165 load_float_geom(win
);
10177 int errcode
= xcb_connection_has_error(conn
);
10178 #ifdef XCB_CONN_ERROR
10181 case XCB_CONN_ERROR
:
10182 s
= "Socket error, pipe error or other stream error.";
10184 case XCB_CONN_CLOSED_EXT_NOTSUPPORTED
:
10185 s
= "Extension not supported.";
10187 case XCB_CONN_CLOSED_MEM_INSUFFICIENT
:
10188 s
= "Insufficient memory.";
10190 case XCB_CONN_CLOSED_REQ_LEN_EXCEED
:
10191 s
= "Request length was exceeded.";
10193 case XCB_CONN_CLOSED_PARSE_ERR
:
10194 s
= "Error parsing display string.";
10197 s
= "Unknown error.";
10200 errx(errcode
, "X CONNECTION ERROR: %s", s
);
10203 errx(errcode
, "X CONNECTION ERROR");
10210 int num_screens
, i
;
10211 const uint32_t val
= XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT
|
10212 XCB_EVENT_MASK_ENTER_WINDOW
;
10214 xcb_void_cookie_t wac
;
10215 xcb_generic_error_t
*error
;
10217 /* this causes an error if some other window manager is running */
10218 num_screens
= get_screen_count();
10219 for (i
= 0; i
< num_screens
; i
++) {
10220 if ((sc
= get_screen(i
)) == NULL
)
10221 errx(1, "ERROR: can't get screen %d.", i
);
10222 DNPRINTF(SWM_D_INIT
, "enable_wm: screen %d, root: %#x\n",
10224 wac
= xcb_change_window_attributes_checked(conn
, sc
->root
,
10225 XCB_CW_EVENT_MASK
, &val
);
10226 if ((error
= xcb_request_check(conn
, wac
))) {
10227 DNPRINTF(SWM_D_INIT
, "enable_wm: error_code: %u\n",
10228 error
->error_code
);
10233 /* click to focus on empty region */
10234 xcb_grab_button(conn
, 1, sc
->root
, BUTTONMASK
,
10235 XCB_GRAB_MODE_SYNC
, XCB_GRAB_MODE_ASYNC
, XCB_WINDOW_NONE
,
10236 XCB_CURSOR_NONE
, XCB_BUTTON_INDEX_1
, XCB_BUTTON_MASK_ANY
);
10243 new_region(struct swm_screen
*s
, int x
, int y
, int w
, int h
)
10245 struct swm_region
*r
= NULL
, *n
;
10246 struct workspace
*ws
= NULL
;
10250 DNPRINTF(SWM_D_MISC
, "new region: screen[%d]:%dx%d+%d+%d\n",
10251 s
->idx
, w
, h
, x
, y
);
10253 /* remove any conflicting regions */
10254 n
= TAILQ_FIRST(&s
->rl
);
10257 n
= TAILQ_NEXT(r
, entry
);
10258 if (X(r
) < (x
+ w
) && (X(r
) + WIDTH(r
)) > x
&&
10259 Y(r
) < (y
+ h
) && (Y(r
) + HEIGHT(r
)) > y
) {
10260 if (r
->ws
->r
!= NULL
)
10261 r
->ws
->old_r
= r
->ws
->r
;
10264 xcb_destroy_window(conn
, r
->id
);
10265 TAILQ_REMOVE(&s
->rl
, r
, entry
);
10266 TAILQ_INSERT_TAIL(&s
->orl
, r
, entry
);
10270 /* search old regions for one to reuse */
10272 /* size + location match */
10273 TAILQ_FOREACH(r
, &s
->orl
, entry
)
10274 if (X(r
) == x
&& Y(r
) == y
&&
10275 HEIGHT(r
) == h
&& WIDTH(r
) == w
)
10279 TAILQ_FOREACH(r
, &s
->orl
, entry
)
10280 if (HEIGHT(r
) == h
&& WIDTH(r
) == w
)
10284 TAILQ_REMOVE(&s
->orl
, r
, entry
);
10285 /* try to use old region's workspace */
10286 if (r
->ws
->r
== NULL
)
10289 if ((r
= calloc(1, sizeof(struct swm_region
))) == NULL
)
10290 err(1, "new_region: calloc: failed to allocate memory "
10293 /* if we don't have a workspace already, find one */
10295 for (i
= 0; i
< workspace_limit
; i
++)
10296 if (s
->ws
[i
].r
== NULL
) {
10303 errx(1, "new_region: no free workspaces");
10305 if (ws
->state
== SWM_WS_STATE_HIDDEN
)
10306 ws
->state
= SWM_WS_STATE_MAPPING
;
10314 r
->ws_prior
= NULL
;
10317 TAILQ_INSERT_TAIL(&s
->rl
, r
, entry
);
10319 /* Invisible region window to detect pointer events on empty regions. */
10320 r
->id
= xcb_generate_id(conn
);
10321 wa
[0] = XCB_EVENT_MASK_POINTER_MOTION
|
10322 XCB_EVENT_MASK_POINTER_MOTION_HINT
;
10324 xcb_create_window(conn
, XCB_COPY_FROM_PARENT
, r
->id
, r
->s
->root
,
10325 X(r
), Y(r
), WIDTH(r
), HEIGHT(r
), 0, XCB_WINDOW_CLASS_INPUT_ONLY
,
10326 XCB_COPY_FROM_PARENT
, XCB_CW_EVENT_MASK
, wa
);
10328 /* Make sure region input is at the bottom. */
10329 wa
[0] = XCB_STACK_MODE_BELOW
;
10330 xcb_configure_window(conn
, r
->id
, XCB_CONFIG_WINDOW_STACK_MODE
, wa
);
10332 xcb_map_window(conn
, r
->id
);
10336 scan_randr(int idx
)
10338 #ifdef SWM_XRR_HAS_CRTC
10341 #endif /* SWM_XRR_HAS_CRTC */
10342 struct swm_region
*r
;
10343 struct ws_win
*win
;
10345 xcb_randr_get_screen_resources_current_cookie_t src
;
10346 xcb_randr_get_screen_resources_current_reply_t
*srr
;
10347 xcb_randr_get_crtc_info_cookie_t cic
;
10348 xcb_randr_get_crtc_info_reply_t
*cir
= NULL
;
10349 xcb_randr_crtc_t
*crtc
;
10350 xcb_screen_t
*screen
;
10352 DNPRINTF(SWM_D_MISC
, "scan_randr: screen: %d\n", idx
);
10354 if ((screen
= get_screen(idx
)) == NULL
)
10355 errx(1, "ERROR: can't get screen %d.", idx
);
10357 num_screens
= get_screen_count();
10358 if (idx
>= num_screens
)
10359 errx(1, "scan_randr: invalid screen");
10361 /* remove any old regions */
10362 while ((r
= TAILQ_FIRST(&screens
[idx
].rl
)) != NULL
) {
10363 r
->ws
->old_r
= r
->ws
->r
= NULL
;
10365 xcb_destroy_window(conn
, r
->id
);
10366 TAILQ_REMOVE(&screens
[idx
].rl
, r
, entry
);
10367 TAILQ_INSERT_TAIL(&screens
[idx
].orl
, r
, entry
);
10371 /* map virtual screens onto physical screens */
10372 #ifdef SWM_XRR_HAS_CRTC
10373 if (randr_support
) {
10374 src
= xcb_randr_get_screen_resources_current(conn
,
10375 screens
[idx
].root
);
10376 srr
= xcb_randr_get_screen_resources_current_reply(conn
, src
,
10379 new_region(&screens
[idx
], 0, 0,
10380 screen
->width_in_pixels
,
10381 screen
->height_in_pixels
);
10384 ncrtc
= srr
->num_crtcs
;
10386 crtc
= xcb_randr_get_screen_resources_current_crtcs(srr
);
10387 for (c
= 0; c
< ncrtc
; c
++) {
10388 cic
= xcb_randr_get_crtc_info(conn
, crtc
[c
],
10390 cir
= xcb_randr_get_crtc_info_reply(conn
, cic
, NULL
);
10393 if (cir
->num_outputs
== 0) {
10398 if (cir
->mode
== 0)
10399 new_region(&screens
[idx
], 0, 0,
10400 screen
->width_in_pixels
,
10401 screen
->height_in_pixels
);
10403 new_region(&screens
[idx
],
10404 cir
->x
, cir
->y
, cir
->width
, cir
->height
);
10409 #endif /* SWM_XRR_HAS_CRTC */
10411 /* If detection failed, create a single region that spans the screen. */
10412 if (TAILQ_EMPTY(&screens
[idx
].rl
))
10413 new_region(&screens
[idx
], 0, 0, screen
->width_in_pixels
,
10414 screen
->height_in_pixels
);
10417 /* Cleanup unused previously visible workspaces. */
10418 TAILQ_FOREACH(r
, &screens
[idx
].orl
, entry
) {
10419 TAILQ_FOREACH(win
, &r
->ws
->winlist
, entry
)
10421 r
->ws
->state
= SWM_WS_STATE_HIDDEN
;
10423 /* The screen shouldn't focus on an unused region. */
10424 if (screens
[idx
].r_focus
== r
)
10425 screens
[idx
].r_focus
= NULL
;
10428 DNPRINTF(SWM_D_MISC
, "scan_randr: done.\n");
10432 screenchange(xcb_randr_screen_change_notify_event_t
*e
)
10434 struct swm_region
*r
;
10435 int i
, num_screens
;
10437 DNPRINTF(SWM_D_EVENT
, "screenchange: root: %#x\n", e
->root
);
10439 num_screens
= get_screen_count();
10440 /* silly event doesn't include the screen index */
10441 for (i
= 0; i
< num_screens
; i
++)
10442 if (screens
[i
].root
== e
->root
)
10444 if (i
>= num_screens
)
10445 errx(1, "screenchange: screen not found");
10447 /* brute force for now, just re-enumerate the regions */
10451 print_win_geom(e
->root
);
10453 /* add bars to all regions */
10454 for (i
= 0; i
< num_screens
; i
++) {
10455 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
10461 /* Make sure a region has focus on each screen. */
10462 for (i
= 0; i
< num_screens
; i
++) {
10463 if (screens
[i
].r_focus
== NULL
) {
10464 r
= TAILQ_FIRST(&screens
[i
].rl
);
10473 /* Update workspace state on all regions. */
10474 for (i
= 0; i
< num_screens
; i
++)
10475 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
10476 r
->ws
->state
= SWM_WS_STATE_MAPPED
;
10482 struct swm_region
*r
= NULL
;
10483 xcb_window_t
*wins
= NULL
, trans
, *cwins
= NULL
;
10484 int i
, j
, k
, n
, no
, num_screens
;
10486 bool manage
, mapped
;
10488 xcb_query_tree_cookie_t qtc
;
10489 xcb_query_tree_reply_t
*qtr
;
10490 xcb_get_window_attributes_cookie_t gac
;
10491 xcb_get_window_attributes_reply_t
*gar
;
10492 xcb_get_property_cookie_t pc
;
10493 xcb_get_property_reply_t
*pr
;
10495 DNPRINTF(SWM_D_INIT
, "grab_windows: begin\n");
10496 num_screens
= get_screen_count();
10497 for (i
= 0; i
< num_screens
; i
++) {
10498 qtc
= xcb_query_tree(conn
, screens
[i
].root
);
10499 qtr
= xcb_query_tree_reply(conn
, qtc
, NULL
);
10502 wins
= xcb_query_tree_children(qtr
);
10503 no
= xcb_query_tree_children_length(qtr
);
10505 /* Try to sort windows according to _NET_CLIENT_LIST. */
10506 pr
= xcb_get_property_reply(conn
, xcb_get_property(conn
, 0,
10507 screens
[i
].root
, ewmh
[_NET_CLIENT_LIST
].atom
,
10508 XCB_ATOM_WINDOW
, 0, UINT32_MAX
), NULL
);
10510 cwins
= xcb_get_property_value(pr
);
10511 n
= xcb_get_property_value_length(pr
) /
10512 sizeof(xcb_atom_t
);
10514 for (j
= 0; j
< n
; ++j
) {
10515 for (k
= j
; k
< no
; ++k
) {
10516 if (wins
[k
] == cwins
[j
]) {
10517 /* Swap wins j and k. */
10519 wins
[j
] = cwins
[j
];
10527 /* attach windows to a region */
10528 /* normal windows */
10529 DNPRINTF(SWM_D_INIT
, "grab_windows: grab top level windows.\n");
10530 for (j
= 0; j
< no
; j
++) {
10531 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
) {
10532 if (r
->id
== wins
[j
]) {
10533 DNPRINTF(SWM_D_INIT
, "grab_windows: "
10534 "skip %#x; region input window.\n",
10537 } else if (r
->bar
->id
== wins
[j
]) {
10538 DNPRINTF(SWM_D_INIT
, "grab_windows: "
10539 "skip %#x; region bar.\n",
10548 gac
= xcb_get_window_attributes(conn
, wins
[j
]);
10549 gar
= xcb_get_window_attributes_reply(conn
, gac
, NULL
);
10551 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10552 "doesn't exist.\n", wins
[j
]);
10556 if (gar
->override_redirect
) {
10557 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10558 "override_redirect set.\n", wins
[j
]);
10563 pc
= xcb_icccm_get_wm_transient_for(conn
, wins
[j
]);
10564 if (xcb_icccm_get_wm_transient_for_reply(conn
, pc
,
10566 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10567 "is transient for %#x.\n", wins
[j
], trans
);
10572 state
= get_win_state(wins
[j
]);
10573 manage
= state
!= XCB_ICCCM_WM_STATE_WITHDRAWN
;
10574 mapped
= gar
->map_state
== XCB_MAP_STATE_VIEWABLE
;
10575 if (mapped
|| manage
)
10576 manage_window(wins
[j
], SWM_STACK_TOP
, mapped
);
10579 /* transient windows */
10580 DNPRINTF(SWM_D_INIT
, "grab_windows: grab transient windows.\n");
10581 for (j
= 0; j
< no
; j
++) {
10582 gac
= xcb_get_window_attributes(conn
, wins
[j
]);
10583 gar
= xcb_get_window_attributes_reply(conn
, gac
, NULL
);
10585 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10586 "doesn't exist.\n", wins
[j
]);
10590 if (gar
->override_redirect
) {
10591 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10592 "override_redirect set.\n", wins
[j
]);
10597 state
= get_win_state(wins
[j
]);
10598 manage
= state
!= XCB_ICCCM_WM_STATE_WITHDRAWN
;
10599 mapped
= gar
->map_state
== XCB_MAP_STATE_VIEWABLE
;
10600 pc
= xcb_icccm_get_wm_transient_for(conn
, wins
[j
]);
10601 if (xcb_icccm_get_wm_transient_for_reply(conn
, pc
,
10602 &trans
, NULL
) && manage
)
10603 manage_window(wins
[j
], SWM_STACK_TOP
, mapped
);
10608 DNPRINTF(SWM_D_INIT
, "grab_windows: done.\n");
10612 setup_screens(void)
10614 int i
, j
, k
, num_screens
;
10615 struct workspace
*ws
;
10616 uint32_t gcv
[1], wa
[1];
10617 const xcb_query_extension_reply_t
*qep
;
10618 xcb_screen_t
*screen
;
10619 xcb_randr_query_version_cookie_t c
;
10620 xcb_randr_query_version_reply_t
*r
;
10622 num_screens
= get_screen_count();
10623 if ((screens
= calloc(num_screens
,
10624 sizeof(struct swm_screen
))) == NULL
)
10625 err(1, "setup_screens: calloc: failed to allocate memory for "
10628 /* Initial RandR setup. */
10629 randr_support
= false;
10630 qep
= xcb_get_extension_data(conn
, &xcb_randr_id
);
10631 if (qep
->present
) {
10632 c
= xcb_randr_query_version(conn
, 1, 1);
10633 r
= xcb_randr_query_version_reply(conn
, c
, NULL
);
10635 if (r
->major_version
>= 1) {
10636 randr_support
= true;
10637 randr_eventbase
= qep
->first_event
;
10643 wa
[0] = cursors
[XC_LEFT_PTR
].cid
;
10645 /* map physical screens */
10646 for (i
= 0; i
< num_screens
; i
++) {
10647 DNPRINTF(SWM_D_WS
, "setup_screens: init screen: %d\n", i
);
10648 screens
[i
].idx
= i
;
10649 screens
[i
].r_focus
= NULL
;
10651 TAILQ_INIT(&screens
[i
].rl
);
10652 TAILQ_INIT(&screens
[i
].orl
);
10653 if ((screen
= get_screen(i
)) == NULL
)
10654 errx(1, "ERROR: can't get screen %d.", i
);
10655 screens
[i
].root
= screen
->root
;
10657 /* set default colors */
10658 setscreencolor("red", i
, SWM_S_COLOR_FOCUS
);
10659 setscreencolor("rgb:88/88/88", i
, SWM_S_COLOR_UNFOCUS
);
10660 setscreencolor("rgb:00/80/80", i
, SWM_S_COLOR_BAR_BORDER
);
10661 setscreencolor("rgb:00/40/40", i
,
10662 SWM_S_COLOR_BAR_BORDER_UNFOCUS
);
10663 setscreencolor("black", i
, SWM_S_COLOR_BAR
);
10664 setscreencolor("rgb:a0/a0/a0", i
, SWM_S_COLOR_BAR_FONT
);
10665 setscreencolor("red", i
, SWM_S_COLOR_FOCUS_MAXIMIZED
);
10666 setscreencolor("rgb:88/88/88", i
,
10667 SWM_S_COLOR_UNFOCUS_MAXIMIZED
);
10669 /* create graphics context on screen */
10670 screens
[i
].bar_gc
= xcb_generate_id(conn
);
10672 xcb_create_gc(conn
, screens
[i
].bar_gc
, screens
[i
].root
,
10673 XCB_GC_GRAPHICS_EXPOSURES
, gcv
);
10675 /* set default cursor */
10676 xcb_change_window_attributes(conn
, screens
[i
].root
,
10677 XCB_CW_CURSOR
, wa
);
10679 /* init all workspaces */
10680 /* XXX these should be dynamically allocated too */
10681 for (j
= 0; j
< SWM_WS_MAX
; j
++) {
10682 ws
= &screens
[i
].ws
[j
];
10685 ws
->bar_enabled
= true;
10687 ws
->focus_prev
= NULL
;
10688 ws
->focus_pending
= NULL
;
10691 ws
->state
= SWM_WS_STATE_HIDDEN
;
10692 TAILQ_INIT(&ws
->stack
);
10693 TAILQ_INIT(&ws
->winlist
);
10694 TAILQ_INIT(&ws
->unmanagedlist
);
10696 for (k
= 0; layouts
[k
].l_stack
!= NULL
; k
++)
10697 if (layouts
[k
].l_config
!= NULL
)
10698 layouts
[k
].l_config(ws
,
10699 SWM_ARG_ID_STACKINIT
);
10700 ws
->cur_layout
= &layouts
[0];
10701 ws
->cur_layout
->l_string(ws
);
10707 xcb_randr_select_input(conn
, screens
[i
].root
,
10708 XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE
);
10713 setup_globals(void)
10715 if ((bar_fonts
= strdup(SWM_BAR_FONTS
)) == NULL
)
10716 err(1, "setup_globals: strdup: failed to allocate memory.");
10718 if ((clock_format
= strdup("%a %b %d %R %Z %Y")) == NULL
)
10719 err(1, "setup_globals: strdup: failed to allocate memory.");
10721 if ((syms
= xcb_key_symbols_alloc(conn
)) == NULL
)
10722 errx(1, "unable to allocate key symbols");
10724 a_state
= get_atom_from_string("WM_STATE");
10725 a_prot
= get_atom_from_string("WM_PROTOCOLS");
10726 a_delete
= get_atom_from_string("WM_DELETE_WINDOW");
10727 a_net_supported
= get_atom_from_string("_NET_SUPPORTED");
10728 a_net_wm_check
= get_atom_from_string("_NET_SUPPORTING_WM_CHECK");
10729 a_takefocus
= get_atom_from_string("WM_TAKE_FOCUS");
10730 a_utf8_string
= get_atom_from_string("UTF8_STRING");
10731 a_swm_ws
= get_atom_from_string("_SWM_WS");
10735 shutdown_cleanup(void)
10737 int i
, num_screens
;
10739 /* disable alarm because the following code may not be interrupted */
10741 if (signal(SIGALRM
, SIG_IGN
) == SIG_ERR
)
10742 err(1, "can't disable alarm");
10751 num_screens
= get_screen_count();
10752 for (i
= 0; i
< num_screens
; ++i
) {
10753 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_POINTER_ROOT
,
10754 screens
[i
].root
, XCB_CURRENT_TIME
);
10756 if (screens
[i
].bar_gc
!= XCB_NONE
)
10757 xcb_free_gc(conn
, screens
[i
].bar_gc
);
10758 if (!bar_font_legacy
) {
10759 XftColorFree(display
, DefaultVisual(display
, i
),
10760 DefaultColormap(display
, i
), &bar_font_color
);
10761 XftColorFree(display
, DefaultVisual(display
, i
),
10762 DefaultColormap(display
, i
), &search_font_color
);
10766 if (bar_font_legacy
)
10767 XFreeFontSet(display
, bar_fs
);
10769 XftFontClose(display
, bar_font
);
10772 xcb_key_symbols_free(syms
);
10774 xcb_disconnect(conn
);
10778 event_error(xcb_generic_error_t
*e
)
10782 DNPRINTF(SWM_D_EVENT
, "event_error: %s(%u) from %s(%u), sequence: %u, "
10783 "resource_id: %u, minor_code: %u\n",
10784 xcb_event_get_error_label(e
->error_code
), e
->error_code
,
10785 xcb_event_get_request_label(e
->major_code
), e
->major_code
,
10786 e
->sequence
, e
->resource_id
, e
->minor_code
);
10790 event_handle(xcb_generic_event_t
*evt
)
10792 uint8_t type
= XCB_EVENT_RESPONSE_TYPE(evt
);
10794 DNPRINTF(SWM_D_EVENT
, "XCB Event: %s(%d), seq %u\n",
10795 xcb_event_get_label(XCB_EVENT_RESPONSE_TYPE(evt
)),
10796 XCB_EVENT_RESPONSE_TYPE(evt
), evt
->sequence
);
10799 #define EVENT(type, callback) case type: callback((void *)evt); return
10800 EVENT(0, event_error
);
10801 EVENT(XCB_BUTTON_PRESS
, buttonpress
);
10802 /*EVENT(XCB_BUTTON_RELEASE, buttonpress);*/
10803 /*EVENT(XCB_CIRCULATE_NOTIFY, );*/
10804 /*EVENT(XCB_CIRCULATE_REQUEST, );*/
10805 EVENT(XCB_CLIENT_MESSAGE
, clientmessage
);
10806 /*EVENT(XCB_COLORMAP_NOTIFY, );*/
10807 EVENT(XCB_CONFIGURE_NOTIFY
, configurenotify
);
10808 EVENT(XCB_CONFIGURE_REQUEST
, configurerequest
);
10809 /*EVENT(XCB_CREATE_NOTIFY, );*/
10810 EVENT(XCB_DESTROY_NOTIFY
, destroynotify
);
10811 EVENT(XCB_ENTER_NOTIFY
, enternotify
);
10812 EVENT(XCB_EXPOSE
, expose
);
10814 EVENT(XCB_FOCUS_IN
, focusin
);
10815 EVENT(XCB_FOCUS_OUT
, focusout
);
10817 /*EVENT(XCB_GRAPHICS_EXPOSURE, );*/
10818 /*EVENT(XCB_GRAVITY_NOTIFY, );*/
10819 EVENT(XCB_KEY_PRESS
, keypress
);
10820 /*EVENT(XCB_KEY_RELEASE, keypress);*/
10821 /*EVENT(XCB_KEYMAP_NOTIFY, );*/
10823 EVENT(XCB_LEAVE_NOTIFY
, leavenotify
);
10825 EVENT(XCB_MAP_NOTIFY
, mapnotify
);
10826 EVENT(XCB_MAP_REQUEST
, maprequest
);
10827 EVENT(XCB_MAPPING_NOTIFY
, mappingnotify
);
10828 EVENT(XCB_MOTION_NOTIFY
, motionnotify
);
10829 /*EVENT(XCB_NO_EXPOSURE, );*/
10830 EVENT(XCB_PROPERTY_NOTIFY
, propertynotify
);
10831 /*EVENT(XCB_REPARENT_NOTIFY, );*/
10832 /*EVENT(XCB_RESIZE_REQUEST, );*/
10833 /*EVENT(XCB_SELECTION_CLEAR, );*/
10834 /*EVENT(XCB_SELECTION_NOTIFY, );*/
10835 /*EVENT(XCB_SELECTION_REQUEST, );*/
10836 EVENT(XCB_UNMAP_NOTIFY
, unmapnotify
);
10837 /*EVENT(XCB_VISIBILITY_NOTIFY, );*/
10840 if (type
- randr_eventbase
== XCB_RANDR_SCREEN_CHANGE_NOTIFY
)
10841 screenchange((void *)evt
);
10845 main(int argc
, char *argv
[])
10847 struct swm_region
*r
;
10848 char conf
[PATH_MAX
], *cfile
= NULL
;
10850 int xfd
, i
, num_screens
;
10851 struct sigaction sact
;
10852 xcb_generic_event_t
*evt
;
10854 struct pollfd pfd
[2];
10855 bool stdin_ready
= false, startup
= true;
10857 /* suppress unused warning since var is needed */
10861 time_started
= time(NULL
);
10865 warnx("Welcome to spectrwm V%s Build: %s", SPECTRWM_VERSION
, buildstr
);
10866 if (setlocale(LC_CTYPE
, "") == NULL
|| setlocale(LC_TIME
, "") == NULL
)
10867 warnx("no locale support");
10869 /* handle some signals */
10870 bzero(&sact
, sizeof(sact
));
10871 sigemptyset(&sact
.sa_mask
);
10873 sact
.sa_handler
= sighdlr
;
10874 sigaction(SIGINT
, &sact
, NULL
);
10875 sigaction(SIGQUIT
, &sact
, NULL
);
10876 sigaction(SIGTERM
, &sact
, NULL
);
10877 sigaction(SIGHUP
, &sact
, NULL
);
10879 sact
.sa_handler
= sighdlr
;
10880 sact
.sa_flags
= SA_NOCLDSTOP
;
10881 sigaction(SIGCHLD
, &sact
, NULL
);
10883 if ((display
= XOpenDisplay(0)) == NULL
)
10884 errx(1, "can not open display");
10886 conn
= XGetXCBConnection(display
);
10887 if (xcb_connection_has_error(conn
))
10888 errx(1, "can not get XCB connection");
10890 XSetEventQueueOwner(display
, XCBOwnsEventQueue
);
10892 xcb_prefetch_extension_data(conn
, &xcb_randr_id
);
10893 xfd
= xcb_get_file_descriptor(conn
);
10895 /* look for local and global conf file */
10896 pwd
= getpwuid(getuid());
10898 errx(1, "invalid user: %d", getuid());
10900 xcb_grab_server(conn
);
10901 xcb_aux_sync(conn
);
10903 /* flush all events */
10904 while ((evt
= xcb_poll_for_event(conn
))) {
10905 if (XCB_EVENT_RESPONSE_TYPE(evt
) == 0)
10911 errx(1, "another window manager is currently running");
10913 /* Load Xcursors and/or cursorfont glyph cursors. */
10916 xcb_aux_sync(conn
);
10926 for (i
= 0; ; i
++) {
10931 snprintf(conf
, sizeof conf
, "%s/.%s",
10932 pwd
->pw_dir
, SWM_CONF_FILE
);
10936 snprintf(conf
, sizeof conf
, "/etc/%s",
10941 snprintf(conf
, sizeof conf
, "%s/.%s",
10942 pwd
->pw_dir
, SWM_CONF_FILE_OLD
);
10945 /* global compat */
10946 snprintf(conf
, sizeof conf
, "/etc/%s",
10947 SWM_CONF_FILE_OLD
);
10953 if (strlen(conf
) && stat(conf
, &sb
) != -1)
10954 if (S_ISREG(sb
.st_mode
)) {
10961 /* load conf (if any) */
10963 conf_load(cfile
, SWM_CONF_DEFAULT
);
10967 if (getenv("SWM_STARTED") == NULL
)
10968 setenv("SWM_STARTED", "YES", 1);
10970 /* setup all bars */
10971 num_screens
= get_screen_count();
10972 for (i
= 0; i
< num_screens
; i
++)
10973 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
10976 /* Manage existing windows. */
10983 xcb_ungrab_server(conn
);
10986 /* Update state of each newly mapped workspace. */
10987 for (i
= 0; i
< num_screens
; i
++)
10988 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
10989 r
->ws
->state
= SWM_WS_STATE_MAPPED
;
10991 memset(&pfd
, 0, sizeof(pfd
));
10993 pfd
[0].events
= POLLIN
;
10994 pfd
[1].fd
= STDIN_FILENO
;
10995 pfd
[1].events
= POLLIN
;
10998 while ((evt
= xcb_poll_for_event(conn
))) {
11005 /* If just (re)started, set default focus if needed. */
11009 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
11010 r
= TAILQ_FIRST(&screens
[0].rl
);
11019 num_readable
= poll(pfd
, bar_extra
? 2 : 1, 1000);
11020 if (num_readable
== -1) {
11021 DNPRINTF(SWM_D_MISC
, "poll failed: %s", strerror(errno
));
11022 } else if (num_readable
> 0 && bar_extra
&& pfd
[1].revents
& POLLIN
) {
11023 stdin_ready
= true;
11027 restart(NULL
, NULL
);
11036 stdin_ready
= false;
11037 bar_extra_update();
11044 shutdown_cleanup();