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>
13 * Permission to use, copy, modify, and distribute this software for any
14 * purpose with or without fee is hereby granted, provided that the above
15 * copyright notice and this permission notice appear in all copies.
17 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
18 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
20 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
22 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
23 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 * Much code and ideas taken from dwm under the following license:
27 * MIT/X Consortium License
29 * 2006-2008 Anselm R Garbe <garbeam at gmail dot com>
30 * 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
31 * 2006-2007 Jukka Salmi <jukka at salmi dot ch>
32 * 2007 Premysl Hruby <dfenze at gmail dot com>
33 * 2007 Szabolcs Nagy <nszabolcs at gmail dot com>
34 * 2007 Christof Musik <christof at sendfax dot de>
35 * 2007-2008 Enno Gottox Boland <gottox at s01 dot de>
36 * 2007-2008 Peter Hartlich <sgkkr at hartlich dot com>
37 * 2008 Martin Hurton <martin dot hurton at gmail dot com>
39 * Permission is hereby granted, free of charge, to any person obtaining a
40 * copy of this software and associated documentation files (the "Software"),
41 * to deal in the Software without restriction, including without limitation
42 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
43 * and/or sell copies of the Software, and to permit persons to whom the
44 * Software is furnished to do so, subject to the following conditions:
46 * The above copyright notice and this permission notice shall be included in
47 * all copies or substantial portions of the Software.
49 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
52 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
54 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
55 * DEALINGS IN THE SOFTWARE.
59 #include <sys/types.h>
63 #include <sys/queue.h>
64 #include <sys/param.h>
65 #include <sys/select.h>
66 #if defined(__linux__)
68 #elif defined(__OpenBSD__)
70 #elif defined(__FreeBSD__)
94 #include <X11/cursorfont.h>
95 #include <X11/extensions/Xrandr.h>
96 #include <X11/Xcursor/Xcursor.h>
97 #include <X11/Xft/Xft.h>
98 #include <X11/Xlib-xcb.h>
99 #include <xcb/xcb_atom.h>
100 #include <xcb/xcb_aux.h>
101 #include <xcb/xcb_event.h>
102 #include <xcb/xcb_icccm.h>
103 #include <xcb/xcb_keysyms.h>
104 #include <xcb/xtest.h>
105 #include <xcb/randr.h>
113 #ifdef SPECTRWM_BUILDSTR
114 static const char *buildstr
= SPECTRWM_BUILDSTR
;
116 static const char *buildstr
= SPECTRWM_VERSION
;
119 #if !defined(__CYGWIN__) /* cygwin chokes on randr stuff */
121 # error RandR versions less than 1.0 are not supported
124 # if RANDR_MAJOR >= 1
125 # if RANDR_MINOR >= 2
126 # define SWM_XRR_HAS_CRTC
129 #endif /* __CYGWIN__ */
131 #ifndef XCB_ICCCM_NUM_WM_HINTS_ELEMENTS
132 #define XCB_ICCCM_SIZE_HINT_P_MIN_SIZE XCB_SIZE_HINT_P_MIN_SIZE
133 #define XCB_ICCCM_SIZE_HINT_P_MAX_SIZE XCB_SIZE_HINT_P_MAX_SIZE
134 #define XCB_ICCCM_SIZE_HINT_P_RESIZE_INC XCB_SIZE_HINT_P_RESIZE_INC
135 #define XCB_ICCCM_WM_HINT_INPUT XCB_WM_HINT_INPUT
136 #define XCB_ICCCM_WM_HINT_X_URGENCY XCB_WM_HINT_X_URGENCY
137 #define XCB_ICCCM_WM_STATE_ICONIC XCB_WM_STATE_ICONIC
138 #define XCB_ICCCM_WM_STATE_WITHDRAWN XCB_WM_STATE_WITHDRAWN
139 #define XCB_ICCCM_WM_STATE_NORMAL XCB_WM_STATE_NORMAL
140 #define xcb_icccm_get_text_property_reply_t xcb_get_text_property_reply_t
141 #define xcb_icccm_get_text_property_reply_wipe xcb_get_text_property_reply_wipe
142 #define xcb_icccm_get_wm_class xcb_get_wm_class
143 #define xcb_icccm_get_wm_class_reply xcb_get_wm_class_reply
144 #define xcb_icccm_get_wm_class_reply_t xcb_get_wm_class_reply_t
145 #define xcb_icccm_get_wm_class_reply_wipe xcb_get_wm_class_reply_wipe
146 #define xcb_icccm_get_wm_hints xcb_get_wm_hints
147 #define xcb_icccm_wm_hints_get_urgency xcb_wm_hints_get_urgency
148 #define xcb_icccm_get_wm_hints_reply xcb_get_wm_hints_reply
149 #define xcb_icccm_get_wm_name xcb_get_wm_name
150 #define xcb_icccm_get_wm_name_reply xcb_get_wm_name_reply
151 #define xcb_icccm_get_wm_normal_hints xcb_get_wm_normal_hints
152 #define xcb_icccm_get_wm_normal_hints_reply xcb_get_wm_normal_hints_reply
153 #define xcb_icccm_get_wm_protocols xcb_get_wm_protocols
154 #define xcb_icccm_get_wm_protocols_reply xcb_get_wm_protocols_reply
155 #define xcb_icccm_get_wm_protocols_reply_t xcb_get_wm_protocols_reply_t
156 #define xcb_icccm_get_wm_protocols_reply_wipe xcb_get_wm_protocols_reply_wipe
157 #define xcb_icccm_get_wm_transient_for xcb_get_wm_transient_for
158 #define xcb_icccm_get_wm_transient_for_reply xcb_get_wm_transient_for_reply
159 #define xcb_icccm_wm_hints_t xcb_wm_hints_t
162 /*#define SWM_DEBUG*/
164 #define DPRINTF(x...) do { \
166 fprintf(stderr, x); \
168 #define DNPRINTF(n,x...) do { \
169 if (swm_debug & n) { \
170 fprintf(stderr, "%ld ", (long)(time(NULL) - time_started)); \
171 fprintf(stderr, x); \
174 #define SWM_D_MISC 0x0001
175 #define SWM_D_EVENT 0x0002
176 #define SWM_D_WS 0x0004
177 #define SWM_D_FOCUS 0x0008
178 #define SWM_D_MOVE 0x0010
179 #define SWM_D_STACK 0x0020
180 #define SWM_D_MOUSE 0x0040
181 #define SWM_D_PROP 0x0080
182 #define SWM_D_CLASS 0x0100
183 #define SWM_D_KEY 0x0200
184 #define SWM_D_QUIRK 0x0400
185 #define SWM_D_SPAWN 0x0800
186 #define SWM_D_EVENTQ 0x1000
187 #define SWM_D_CONF 0x2000
188 #define SWM_D_BAR 0x4000
189 #define SWM_D_INIT 0x8000
191 uint32_t swm_debug
= 0
210 #define DPRINTF(x...)
211 #define DNPRINTF(n,x...)
214 #define SWM_EWMH_ACTION_COUNT_MAX (8)
215 #define EWMH_F_FULLSCREEN (0x001)
216 #define EWMH_F_ABOVE (0x002)
217 #define EWMH_F_HIDDEN (0x004)
218 #define EWMH_F_MAXIMIZED_VERT (0x008)
219 #define EWMH_F_MAXIMIZED_HORZ (0x010)
220 #define EWMH_F_SKIP_PAGER (0x020)
221 #define EWMH_F_SKIP_TASKBAR (0x040)
222 #define SWM_F_MANUAL (0x080)
224 #define EWMH_F_MAXIMIZED (EWMH_F_MAXIMIZED_VERT | EWMH_F_MAXIMIZED_HORZ)
226 /* convert 8-bit to 16-bit */
227 #define RGB_8_TO_16(col) (((col) << 8) + (col))
229 #define PIXEL_TO_XRENDERCOLOR(px, xrc) \
230 xrc.red = RGB_8_TO_16((px) >> 16 & 0xff); \
231 xrc.green = RGB_8_TO_16((px) >> 8 & 0xff); \
232 xrc.blue = RGB_8_TO_16((px) & 0xff); \
235 #define LENGTH(x) (int)(sizeof (x) / sizeof (x)[0])
236 #define MODKEY XCB_MOD_MASK_1
237 #define CLEANMASK(mask) ((mask) & ~(numlockmask | XCB_MOD_MASK_LOCK))
238 #define BUTTONMASK (XCB_EVENT_MASK_BUTTON_PRESS | \
239 XCB_EVENT_MASK_BUTTON_RELEASE)
240 #define MOUSEMASK (BUTTONMASK|XCB_EVENT_MASK_POINTER_MOTION)
241 #define SWM_PROPLEN (16)
242 #define SWM_FUNCNAME_LEN (32)
243 #define SWM_KEYS_LEN (255)
244 #define SWM_QUIRK_LEN (64)
245 #define X(r) ((r)->g.x)
246 #define Y(r) ((r)->g.y)
247 #define WIDTH(r) ((r)->g.w)
248 #define HEIGHT(r) ((r)->g.h)
249 #define BORDER(w) ((w)->bordered ? border_width : 0)
250 #define MAX_X(r) ((r)->g.x + (r)->g.w)
251 #define MAX_Y(r) ((r)->g.y + (r)->g.h)
252 #define SH_MIN(w) ((w)->sh.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE)
253 #define SH_MIN_W(w) ((w)->sh.min_width)
254 #define SH_MIN_H(w) ((w)->sh.min_height)
255 #define SH_MAX(w) ((w)->sh.flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE)
256 #define SH_MAX_W(w) ((w)->sh.max_width)
257 #define SH_MAX_H(w) ((w)->sh.max_height)
258 #define SH_INC(w) ((w)->sh.flags & XCB_ICCCM_SIZE_HINT_P_RESIZE_INC)
259 #define SH_INC_W(w) ((w)->sh.width_inc)
260 #define SH_INC_H(w) ((w)->sh.height_inc)
261 #define SWM_MAX_FONT_STEPS (3)
262 #define WINID(w) ((w) ? (w)->id : XCB_WINDOW_NONE)
263 #define WS_FOCUSED(ws) ((ws)->r && (ws)->r->s->r_focus == (ws)->r)
264 #define YESNO(x) ((x) ? "yes" : "no")
265 #define ICONIC(w) ((w)->ewmh_flags & EWMH_F_HIDDEN)
266 #define ABOVE(w) ((w)->ewmh_flags & EWMH_F_ABOVE)
267 #define FULLSCREEN(w) ((w)->ewmh_flags & EWMH_F_FULLSCREEN)
268 #define MAXIMIZED_VERT(w) ((w)->ewmh_flags & EWMH_F_MAXIMIZED_VERT)
269 #define MAXIMIZED_HORZ(w) ((w)->ewmh_flags & EWMH_F_MAXIMIZED_HORZ)
270 #define MAXIMIZED(w) (MAXIMIZED_VERT(w) || MAXIMIZED_HORZ(w))
271 #define MANUAL(w) ((w)->ewmh_flags & SWM_F_MANUAL)
272 #define TRANS(w) ((w)->transient != XCB_WINDOW_NONE)
273 #define FLOATING(w) (ABOVE(w) || TRANS(w) || FULLSCREEN(w) || \
276 /* Constrain Window flags */
277 #define SWM_CW_RESIZABLE (0x01)
278 #define SWM_CW_SOFTBOUNDARY (0x02)
279 #define SWM_CW_HARDBOUNDARY (0x04)
280 #define SWM_CW_RIGHT (0x10)
281 #define SWM_CW_LEFT (0x20)
282 #define SWM_CW_BOTTOM (0x40)
283 #define SWM_CW_TOP (0x80)
284 #define SWM_CW_ALLSIDES (0xf0)
286 #define SWM_FOCUS_DEFAULT (0)
287 #define SWM_FOCUS_FOLLOW (1)
288 #define SWM_FOCUS_MANUAL (2)
290 #define SWM_CK_NONE (0)
291 #define SWM_CK_ALL (0xf)
292 #define SWM_CK_FOCUS (0x1)
293 #define SWM_CK_POINTER (0x2)
294 #define SWM_CK_FALLBACK (0x4)
295 #define SWM_CK_REGION (0x8)
297 #define SWM_G_ALL (0xf)
298 #define SWM_G_SIZE (0x1)
299 #define SWM_G_POS (0x2)
301 #define SWM_CONF_DEFAULT (0)
302 #define SWM_CONF_KEYMAPPING (1)
305 #define SWM_LIB "/usr/local/lib/libswmhack.so"
312 xcb_atom_t a_net_wm_check
;
313 xcb_atom_t a_net_supported
;
314 xcb_atom_t a_takefocus
;
315 xcb_atom_t a_utf8_string
;
317 volatile sig_atomic_t running
= 1;
318 volatile sig_atomic_t restart_wm
= 0;
319 xcb_timestamp_t last_event_time
= 0;
323 unsigned int numlockmask
= 0;
326 xcb_connection_t
*conn
;
327 xcb_key_symbols_t
*syms
;
329 int boundary_width
= 50;
330 bool cycle_empty
= false;
331 bool cycle_visible
= false;
333 int font_adjusted
= 0;
334 unsigned int mod_key
= MODKEY
;
335 bool warp_pointer
= false;
336 unsigned int mouse_button_move
= XCB_BUTTON_INDEX_1
;
337 unsigned int mouse_button_resize
= XCB_BUTTON_INDEX_3
;
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 urgent_enabled
= false;
408 bool urgent_collapse
= false;
409 char *clock_format
= NULL
;
410 bool window_class_enabled
= false;
411 bool window_instance_enabled
= false;
412 bool window_name_enabled
= false;
413 int focus_mode
= SWM_FOCUS_DEFAULT
;
414 int focus_close
= SWM_STACK_BELOW
;
415 bool focus_close_wrap
= true;
416 int focus_default
= SWM_STACK_TOP
;
417 int spawn_position
= SWM_STACK_TOP
;
418 bool disable_border
= false;
419 int border_width
= 1;
420 int region_padding
= 0;
422 bool java_workaround
= true;
423 bool verbose_layout
= false;
429 XFontSetExtents
*bar_fs_extents
;
431 bool bar_font_legacy
= true;
433 XftColor bar_font_color
;
434 XftColor search_font_color
;
436 char *startup_exception
;
437 unsigned int nr_exceptions
= 0;
439 /* layout manager data */
440 struct swm_geometry
{
453 struct swm_geometry g
;
456 /* virtual "screens" */
458 TAILQ_ENTRY(swm_region
) entry
;
460 struct swm_geometry g
;
461 struct workspace
*ws
; /* current workspace on this region */
462 struct workspace
*ws_prior
; /* prior workspace on this region */
463 struct swm_screen
*s
; /* screen idx */
466 TAILQ_HEAD(swm_region_list
, swm_region
);
469 TAILQ_ENTRY(ws_win
) entry
;
470 TAILQ_ENTRY(ws_win
) stack_entry
;
472 xcb_window_t transient
;
473 struct ws_win
*focus_child
; /* focus on child transient */
474 struct swm_geometry g
; /* current geometry */
475 struct swm_geometry g_float
; /* region coordinates */
476 bool g_floatvalid
; /* g_float geometry validity */
480 int font_size_boundary
[SWM_MAX_FONT_STEPS
];
487 struct workspace
*ws
; /* always valid */
488 struct swm_screen
*s
; /* always valid, never changes */
490 xcb_icccm_get_wm_class_reply_t ch
;
491 xcb_icccm_wm_hints_t hints
;
493 TAILQ_HEAD(ws_win_list
, ws_win
);
494 TAILQ_HEAD(ws_win_stack
, ws_win
);
498 TAILQ_ENTRY(pid_e
) entry
;
502 TAILQ_HEAD(pid_list
, pid_e
);
503 struct pid_list pidlist
= TAILQ_HEAD_INITIALIZER(pidlist
);
505 /* layout handlers */
507 void vertical_config(struct workspace
*, int);
508 void vertical_stack(struct workspace
*, struct swm_geometry
*);
509 void horizontal_config(struct workspace
*, int);
510 void horizontal_stack(struct workspace
*, struct swm_geometry
*);
511 void max_stack(struct workspace
*, struct swm_geometry
*);
512 void plain_stacker(struct workspace
*);
513 void fancy_stacker(struct workspace
*);
516 void (*l_stack
)(struct workspace
*, struct swm_geometry
*);
517 void (*l_config
)(struct workspace
*, int);
519 #define SWM_L_FOCUSPREV (1<<0)
520 #define SWM_L_MAPONFOCUS (1<<1)
521 void (*l_string
)(struct workspace
*);
523 /* stack, configure */
524 { vertical_stack
, vertical_config
, 0, plain_stacker
},
525 { horizontal_stack
, horizontal_config
, 0, plain_stacker
},
527 SWM_L_MAPONFOCUS
| SWM_L_FOCUSPREV
, plain_stacker
},
528 { NULL
, NULL
, 0, NULL
},
531 /* position of max_stack mode in the layouts array, index into layouts! */
532 #define SWM_V_STACK (0)
533 #define SWM_H_STACK (1)
534 #define SWM_MAX_STACK (2)
536 #define SWM_H_SLICE (32)
537 #define SWM_V_SLICE (32)
539 /* define work spaces */
541 int idx
; /* workspace index */
542 char *name
; /* workspace name */
543 bool always_raise
; /* raise windows on focus */
544 bool bar_enabled
; /* bar visibility */
545 struct layout
*cur_layout
; /* current layout handlers */
546 struct ws_win
*focus
; /* may be NULL */
547 struct ws_win
*focus_prev
; /* may be NULL */
548 struct ws_win
*focus_pending
; /* may be NULL */
549 struct swm_region
*r
; /* may be NULL */
550 struct swm_region
*old_r
; /* may be NULL */
551 struct ws_win_list winlist
; /* list of windows in ws */
552 struct ws_win_list unmanagedlist
; /* list of dead windows in ws */
553 struct ws_win_stack stack
; /* stacking order */
554 int state
; /* mapping state */
555 char stacker
[10]; /* display stacker and layout */
559 int horizontal_msize
;
561 int horizontal_stacks
;
562 bool horizontal_flip
;
572 SWM_WS_STATE_MAPPING
,
578 SWM_S_COLOR_BAR_BORDER
,
579 SWM_S_COLOR_BAR_BORDER_UNFOCUS
,
580 SWM_S_COLOR_BAR_FONT
,
582 SWM_S_COLOR_FOCUS_MAXIMIZED
,
584 SWM_S_COLOR_UNFOCUS_MAXIMIZED
,
588 /* physical screen mapping */
589 #define SWM_WS_MAX (22) /* hard limit */
590 int workspace_limit
= 10; /* soft limit */
593 int idx
; /* screen index */
594 struct swm_region_list rl
; /* list of regions on this screen */
595 struct swm_region_list orl
; /* list of old regions */
597 struct workspace ws
[SWM_WS_MAX
];
598 struct swm_region
*r_focus
;
605 } c
[SWM_S_COLOR_MAX
];
607 xcb_gcontext_t bar_gc
;
610 struct swm_screen
*screens
;
612 /* args to functions */
615 #define SWM_ARG_ID_FOCUSNEXT (0)
616 #define SWM_ARG_ID_FOCUSPREV (1)
617 #define SWM_ARG_ID_FOCUSMAIN (2)
618 #define SWM_ARG_ID_FOCUSURGENT (3)
619 #define SWM_ARG_ID_SWAPNEXT (10)
620 #define SWM_ARG_ID_SWAPPREV (11)
621 #define SWM_ARG_ID_SWAPMAIN (12)
622 #define SWM_ARG_ID_MOVELAST (13)
623 #define SWM_ARG_ID_MASTERSHRINK (20)
624 #define SWM_ARG_ID_MASTERGROW (21)
625 #define SWM_ARG_ID_MASTERADD (22)
626 #define SWM_ARG_ID_MASTERDEL (23)
627 #define SWM_ARG_ID_FLIPLAYOUT (24)
628 #define SWM_ARG_ID_STACKRESET (30)
629 #define SWM_ARG_ID_STACKINIT (31)
630 #define SWM_ARG_ID_STACKBALANCE (32)
631 #define SWM_ARG_ID_CYCLEWS_UP (40)
632 #define SWM_ARG_ID_CYCLEWS_DOWN (41)
633 #define SWM_ARG_ID_CYCLERG_UP (42)
634 #define SWM_ARG_ID_CYCLERG_DOWN (43)
635 #define SWM_ARG_ID_CYCLEWS_UP_ALL (44)
636 #define SWM_ARG_ID_CYCLEWS_DOWN_ALL (45)
637 #define SWM_ARG_ID_CYCLEWS_MOVE_UP (46)
638 #define SWM_ARG_ID_CYCLEWS_MOVE_DOWN (47)
639 #define SWM_ARG_ID_STACKINC (50)
640 #define SWM_ARG_ID_STACKDEC (51)
641 #define SWM_ARG_ID_SS_ALL (60)
642 #define SWM_ARG_ID_SS_WINDOW (61)
643 #define SWM_ARG_ID_DONTCENTER (70)
644 #define SWM_ARG_ID_CENTER (71)
645 #define SWM_ARG_ID_KILLWINDOW (80)
646 #define SWM_ARG_ID_DELETEWINDOW (81)
647 #define SWM_ARG_ID_WIDTHGROW (90)
648 #define SWM_ARG_ID_WIDTHSHRINK (91)
649 #define SWM_ARG_ID_HEIGHTGROW (92)
650 #define SWM_ARG_ID_HEIGHTSHRINK (93)
651 #define SWM_ARG_ID_MOVEUP (100)
652 #define SWM_ARG_ID_MOVEDOWN (101)
653 #define SWM_ARG_ID_MOVELEFT (102)
654 #define SWM_ARG_ID_MOVERIGHT (103)
655 #define SWM_ARG_ID_RAISE (105)
656 #define SWM_ARG_ID_LOWER (106)
657 #define SWM_ARG_ID_BAR_TOGGLE (110)
658 #define SWM_ARG_ID_BAR_TOGGLE_WS (111)
664 TAILQ_ENTRY(quirk
) entry
;
665 char *class; /* WM_CLASS:class */
666 char *instance
; /* WM_CLASS:instance */
667 char *name
; /* WM_NAME */
669 regex_t regex_instance
;
672 int ws
; /* Initial workspace. */
673 #define SWM_Q_FLOAT (1<<0) /* float this window */
674 #define SWM_Q_TRANSSZ (1<<1) /* transiend window size too small */
675 #define SWM_Q_ANYWHERE (1<<2) /* don't position this window */
676 #define SWM_Q_XTERM_FONTADJ (1<<3) /* adjust xterm fonts when resizing */
677 #define SWM_Q_FULLSCREEN (1<<4) /* remove border */
678 #define SWM_Q_FOCUSPREV (1<<5) /* focus on caller */
679 #define SWM_Q_NOFOCUSONMAP (1<<6) /* Don't focus on window when mapped. */
680 #define SWM_Q_FOCUSONMAP_SINGLE (1<<7) /* Only focus if single win of type. */
681 #define SWM_Q_OBEYAPPFOCUSREQ (1<<8) /* Focus when applications ask. */
682 #define SWM_Q_IGNOREPID (1<<9) /* Ignore PID when determining ws. */
683 #define SWM_Q_IGNORESPAWNWS (1<<10) /* Ignore _SWM_WS when managing win. */
685 TAILQ_HEAD(quirk_list
, quirk
);
686 struct quirk_list quirks
= TAILQ_HEAD_INITIALIZER(quirks
);
689 * Supported EWMH hints should be added to
690 * both the enum and the ewmh array
696 _NET_CURRENT_DESKTOP
,
697 _NET_DESKTOP_GEOMETRY
,
699 _NET_DESKTOP_VIEWPORT
,
700 _NET_MOVERESIZE_WINDOW
,
701 _NET_NUMBER_OF_DESKTOPS
,
703 _NET_WM_ACTION_ABOVE
,
704 _NET_WM_ACTION_CLOSE
,
705 _NET_WM_ACTION_FULLSCREEN
,
707 _NET_WM_ACTION_RESIZE
,
708 _NET_WM_ALLOWED_ACTIONS
,
710 _NET_WM_FULL_PLACEMENT
,
714 _NET_WM_STATE_FULLSCREEN
,
715 _NET_WM_STATE_HIDDEN
,
716 _NET_WM_STATE_MAXIMIZED_VERT
,
717 _NET_WM_STATE_MAXIMIZED_HORZ
,
718 _NET_WM_STATE_SKIP_PAGER
,
719 _NET_WM_STATE_SKIP_TASKBAR
,
721 _NET_WM_WINDOW_TYPE_DIALOG
,
722 _NET_WM_WINDOW_TYPE_DOCK
,
723 _NET_WM_WINDOW_TYPE_NORMAL
,
724 _NET_WM_WINDOW_TYPE_SPLASH
,
725 _NET_WM_WINDOW_TYPE_TOOLBAR
,
726 _NET_WM_WINDOW_TYPE_UTILITY
,
727 _SWM_WM_STATE_MANUAL
,
734 } ewmh
[SWM_EWMH_HINT_MAX
] = {
735 /* must be in same order as in the enum */
736 {"_NET_ACTIVE_WINDOW", XCB_ATOM_NONE
},
737 {"_NET_CLIENT_LIST", XCB_ATOM_NONE
},
738 {"_NET_CLOSE_WINDOW", XCB_ATOM_NONE
},
739 {"_NET_CURRENT_DESKTOP", XCB_ATOM_NONE
},
740 {"_NET_DESKTOP_GEOMETRY", XCB_ATOM_NONE
},
741 {"_NET_DESKTOP_NAMES", XCB_ATOM_NONE
},
742 {"_NET_DESKTOP_VIEWPORT", XCB_ATOM_NONE
},
743 {"_NET_MOVERESIZE_WINDOW", XCB_ATOM_NONE
},
744 {"_NET_NUMBER_OF_DESKTOPS", XCB_ATOM_NONE
},
745 {"_NET_RESTACK_WINDOW", XCB_ATOM_NONE
},
746 {"_NET_WM_ACTION_ABOVE", XCB_ATOM_NONE
},
747 {"_NET_WM_ACTION_CLOSE", XCB_ATOM_NONE
},
748 {"_NET_WM_ACTION_FULLSCREEN", XCB_ATOM_NONE
},
749 {"_NET_WM_ACTION_MOVE", XCB_ATOM_NONE
},
750 {"_NET_WM_ACTION_RESIZE", XCB_ATOM_NONE
},
751 {"_NET_WM_ALLOWED_ACTIONS", XCB_ATOM_NONE
},
752 {"_NET_WM_DESKTOP", XCB_ATOM_NONE
},
753 {"_NET_WM_FULL_PLACEMENT", XCB_ATOM_NONE
},
754 {"_NET_WM_NAME", XCB_ATOM_NONE
},
755 {"_NET_WM_STATE", XCB_ATOM_NONE
},
756 {"_NET_WM_STATE_ABOVE", XCB_ATOM_NONE
},
757 {"_NET_WM_STATE_FULLSCREEN", XCB_ATOM_NONE
},
758 {"_NET_WM_STATE_HIDDEN", XCB_ATOM_NONE
},
759 {"_NET_WM_STATE_MAXIMIZED_VERT", XCB_ATOM_NONE
},
760 {"_NET_WM_STATE_MAXIMIZED_HORZ", XCB_ATOM_NONE
},
761 {"_NET_WM_STATE_SKIP_PAGER", XCB_ATOM_NONE
},
762 {"_NET_WM_STATE_SKIP_TASKBAR", XCB_ATOM_NONE
},
763 {"_NET_WM_WINDOW_TYPE", XCB_ATOM_NONE
},
764 {"_NET_WM_WINDOW_TYPE_DIALOG", XCB_ATOM_NONE
},
765 {"_NET_WM_WINDOW_TYPE_DOCK", XCB_ATOM_NONE
},
766 {"_NET_WM_WINDOW_TYPE_NORMAL", XCB_ATOM_NONE
},
767 {"_NET_WM_WINDOW_TYPE_SPLASH", XCB_ATOM_NONE
},
768 {"_NET_WM_WINDOW_TYPE_TOOLBAR", XCB_ATOM_NONE
},
769 {"_NET_WM_WINDOW_TYPE_UTILITY", XCB_ATOM_NONE
},
770 {"_SWM_WM_STATE_MANUAL", XCB_ATOM_NONE
},
773 /* EWMH source type */
775 EWMH_SOURCE_TYPE_NONE
= 0,
776 EWMH_SOURCE_TYPE_NORMAL
= 1,
777 EWMH_SOURCE_TYPE_OTHER
= 2,
784 XC_BOTTOM_LEFT_CORNER
,
785 XC_BOTTOM_RIGHT_CORNER
,
793 char *name
; /* Name used by Xcursor .*/
794 uint8_t cf_char
; /* cursorfont index. */
796 } cursors
[XC_MAX
] = {
797 {"fleur", XC_fleur
, XCB_CURSOR_NONE
},
798 {"left_ptr", XC_left_ptr
, XCB_CURSOR_NONE
},
799 {"bottom_left_corner", XC_bottom_left_corner
, XCB_CURSOR_NONE
},
800 {"bottom_right_corner", XC_bottom_right_corner
, XCB_CURSOR_NONE
},
801 {"sizing", XC_sizing
, XCB_CURSOR_NONE
},
802 {"top_left_corner", XC_top_left_corner
, XCB_CURSOR_NONE
},
803 {"top_right_corner", XC_top_right_corner
, XCB_CURSOR_NONE
},
806 #define SWM_SPAWN_OPTIONAL 0x1
810 TAILQ_ENTRY(spawn_prog
) entry
;
816 TAILQ_HEAD(spawn_list
, spawn_prog
);
817 struct spawn_list spawns
= TAILQ_HEAD_INITIALIZER(spawns
);
819 /* user/key callable function IDs */
936 KF_DUMPWINS
, /* MUST BE LAST */
944 enum keyfuncid funcid
;
947 RB_HEAD(key_tree
, key
);
949 /* function prototypes */
950 void adjust_font(struct ws_win
*);
951 char *argsep(char **);
952 void bar_cleanup(struct swm_region
*);
953 void bar_extra_setup(void);
954 void bar_extra_stop(void);
955 int bar_extra_update(void);
956 void bar_fmt(const char *, char *, struct swm_region
*, size_t);
957 void bar_fmt_expand(char *, size_t);
959 void bar_print(struct swm_region
*, const char *);
960 void bar_print_legacy(struct swm_region
*, const char *);
961 void bar_replace(char *, char *, struct swm_region
*, size_t);
962 void bar_replace_pad(char *, int *, size_t);
963 char *bar_replace_seq(char *, char *, struct swm_region
*, size_t *, size_t);
964 void bar_setup(struct swm_region
*);
965 void bar_toggle(struct swm_region
*, union arg
*);
966 void bar_urgent(char *, size_t);
967 void bar_window_class(char *, size_t, struct swm_region
*);
968 void bar_window_class_instance(char *, size_t, struct swm_region
*);
969 void bar_window_float(char *, size_t, struct swm_region
*);
970 void bar_window_instance(char *, size_t, struct swm_region
*);
971 void bar_window_name(char *, size_t, struct swm_region
*);
972 void bar_window_state(char *, size_t, struct swm_region
*);
973 void bar_workspace_name(char *, size_t, struct swm_region
*);
974 void buttonpress(xcb_button_press_event_t
*);
975 void center_pointer(struct swm_region
*);
976 void check_conn(void);
977 void clear_keys(void);
978 int clear_maximized(struct workspace
*);
979 void clientmessage(xcb_client_message_event_t
*);
980 void client_msg(struct ws_win
*, xcb_atom_t
, xcb_timestamp_t
);
981 int conf_load(const char *, int);
982 void configurenotify(xcb_configure_notify_event_t
*);
983 void configurerequest(xcb_configure_request_event_t
*);
984 void config_win(struct ws_win
*, xcb_configure_request_event_t
*);
985 void constrain_window(struct ws_win
*, struct swm_geometry
*, int *);
986 int count_win(struct workspace
*, bool);
987 void cursors_cleanup(void);
988 void cursors_load(void);
989 void custom_region(const char *);
990 void cyclerg(struct swm_region
*, union arg
*);
991 void cyclews(struct swm_region
*, union arg
*);
992 void cycle_layout(struct swm_region
*, union arg
*);
993 void destroynotify(xcb_destroy_notify_event_t
*);
994 void dumpwins(struct swm_region
*, union arg
*);
996 void enternotify(xcb_enter_notify_event_t
*);
997 void event_drain(uint8_t);
998 void event_error(xcb_generic_error_t
*);
999 void event_handle(xcb_generic_event_t
*);
1000 void ewmh_apply_flags(struct ws_win
*, uint32_t);
1001 void ewmh_autoquirk(struct ws_win
*);
1002 void ewmh_get_desktop_names(void);
1003 void ewmh_get_wm_state(struct ws_win
*);
1004 void ewmh_update_actions(struct ws_win
*);
1005 void ewmh_update_client_list(void);
1006 void ewmh_update_current_desktop(void);
1007 void ewmh_update_desktop_names(void);
1008 void ewmh_update_desktops(void);
1009 void ewmh_change_wm_state(struct ws_win
*, xcb_atom_t
, long);
1010 void ewmh_update_wm_state(struct ws_win
*);
1011 char *expand_tilde(const char *);
1012 void expose(xcb_expose_event_t
*);
1013 void fake_keypress(struct ws_win
*, xcb_keysym_t
, uint16_t);
1014 struct pid_e
*find_pid(pid_t
);
1015 struct ws_win
*find_unmanaged_window(xcb_window_t
);
1016 struct ws_win
*find_window(xcb_window_t
);
1017 void floating_toggle(struct swm_region
*, union arg
*);
1018 void focus(struct swm_region
*, union arg
*);
1020 void focusin(xcb_focus_in_event_t
*);
1021 void focusout(xcb_focus_out_event_t
*);
1023 void focus_flush(void);
1024 void focus_region(struct swm_region
*);
1025 void focusrg(struct swm_region
*, union arg
*);
1026 void focus_win(struct ws_win
*);
1027 void fontset_init(void);
1028 void free_window(struct ws_win
*);
1029 xcb_atom_t
get_atom_from_string(const char *);
1031 char *get_atom_name(xcb_atom_t
);
1033 struct ws_win
*get_focus_magic(struct ws_win
*);
1034 struct ws_win
*get_focus_prev(struct ws_win
*);
1036 char *get_notify_detail_label(uint8_t);
1037 char *get_notify_mode_label(uint8_t);
1039 struct ws_win
*get_pointer_win(xcb_window_t
);
1040 struct ws_win
*get_region_focus(struct swm_region
*);
1041 int get_region_index(struct swm_region
*);
1042 xcb_screen_t
*get_screen(int);
1043 int get_screen_count(void);
1045 char *get_source_type_label(uint32_t);
1046 char *get_stack_mode_name(uint8_t);
1048 int32_t get_swm_ws(xcb_window_t
);
1049 bool get_urgent(struct ws_win
*);
1050 char *get_win_name(xcb_window_t
);
1051 uint8_t get_win_state(xcb_window_t
);
1052 void get_wm_protocols(struct ws_win
*);
1053 int get_ws_idx(struct ws_win
*);
1054 void grabbuttons(struct ws_win
*);
1055 void grabkeys(void);
1056 void grab_windows(void);
1057 void iconify(struct swm_region
*, union arg
*);
1058 bool isxlfd(char *);
1059 void keypress(xcb_key_press_event_t
*);
1060 int key_cmp(struct key
*, struct key
*);
1061 void key_insert(unsigned int, KeySym
, enum keyfuncid
, const char *);
1062 struct key
*key_lookup(unsigned int, KeySym
);
1063 void key_remove(struct key
*);
1064 void key_replace(struct key
*, unsigned int, KeySym
, enum keyfuncid
,
1066 void kill_bar_extra_atexit(void);
1067 void kill_refs(struct ws_win
*);
1069 void leavenotify(xcb_leave_notify_event_t
*);
1071 void load_float_geom(struct ws_win
*);
1072 void lower_window(struct ws_win
*);
1073 struct ws_win
*manage_window(xcb_window_t
, int, bool);
1074 void map_window(struct ws_win
*);
1075 void mapnotify(xcb_map_notify_event_t
*);
1076 void mappingnotify(xcb_mapping_notify_event_t
*);
1077 void maprequest(xcb_map_request_event_t
*);
1078 void maximize_toggle(struct swm_region
*, union arg
*);
1079 void motionnotify(xcb_motion_notify_event_t
*);
1080 void move(struct ws_win
*, union arg
*);
1081 void move_step(struct swm_region
*, union arg
*);
1082 uint32_t name_to_pixel(int, const char *);
1083 void name_workspace(struct swm_region
*, union arg
*);
1084 void new_region(struct swm_screen
*, int, int, int, int);
1085 int parsekeys(const char *, unsigned int, unsigned int *, KeySym
*);
1086 int parsequirks(const char *, uint32_t *, int *);
1087 int parse_rgb(const char *, uint16_t *, uint16_t *, uint16_t *);
1088 void pressbutton(struct swm_region
*, union arg
*);
1089 void priorws(struct swm_region
*, union arg
*);
1091 void print_win_geom(xcb_window_t
);
1093 void propertynotify(xcb_property_notify_event_t
*);
1094 void quirk_free(struct quirk
*);
1095 void quirk_insert(const char *, const char *, const char *, uint32_t, int);
1096 void quirk_remove(struct quirk
*);
1097 void quirk_replace(struct quirk
*, const char *, const char *, const char *,
1099 void quit(struct swm_region
*, union arg
*);
1100 void raise_toggle(struct swm_region
*, union arg
*);
1101 void raise_window(struct ws_win
*);
1102 void region_containment(struct ws_win
*, struct swm_region
*, int);
1103 struct swm_region
*region_under(struct swm_screen
*, int, int);
1104 void regionize(struct ws_win
*, int, int);
1105 void resize(struct ws_win
*, union arg
*);
1106 void resize_step(struct swm_region
*, union arg
*);
1107 void restart(struct swm_region
*, union arg
*);
1108 struct swm_region
*root_to_region(xcb_window_t
, int);
1109 void screenchange(xcb_randr_screen_change_notify_event_t
*);
1110 void scan_randr(int);
1111 void search_do_resp(void);
1112 void search_resp_name_workspace(const char *, size_t);
1113 void search_resp_search_window(const char *);
1114 void search_resp_search_workspace(const char *);
1115 void search_resp_uniconify(const char *, size_t);
1116 void search_win(struct swm_region
*, union arg
*);
1117 void search_win_cleanup(void);
1118 void search_workspace(struct swm_region
*, union arg
*);
1119 void send_to_rg(struct swm_region
*, union arg
*);
1120 void send_to_ws(struct swm_region
*, union arg
*);
1121 void set_region(struct swm_region
*);
1122 int setautorun(const char *, const char *, int);
1123 int setconfbinding(const char *, const char *, int);
1124 int setconfcolor(const char *, const char *, int);
1125 int setconfmodkey(const char *, const char *, int);
1126 int setconfmousebuttonmove(const char *, const char *, int);
1127 int setconfmousebuttonresize(const char *, const char *, int);
1128 int setconfquirk(const char *, const char *, int);
1129 int setconfregion(const char *, const char *, int);
1130 int setconfspawn(const char *, const char *, int);
1131 int setconfvalue(const char *, const char *, int);
1132 void setkeybinding(unsigned int, KeySym
, enum keyfuncid
, const char *);
1133 int setkeymapping(const char *, const char *, int);
1134 int setlayout(const char *, const char *, int);
1135 void setquirk(const char *, const char *, const char *, uint32_t, int);
1136 void setscreencolor(const char *, int, int);
1137 void setspawn(const char *, const char *, int);
1138 void setup_ewmh(void);
1139 void setup_globals(void);
1140 void setup_keys(void);
1141 void setup_quirks(void);
1142 void setup_screens(void);
1143 void setup_spawn(void);
1144 void set_child_transient(struct ws_win
*, xcb_window_t
*);
1145 void set_win_state(struct ws_win
*, uint8_t);
1146 void shutdown_cleanup(void);
1148 void socket_setnonblock(int);
1149 void sort_windows(struct ws_win_list
*);
1150 void spawn(int, union arg
*, bool);
1151 void spawn_custom(struct swm_region
*, union arg
*, const char *);
1152 int spawn_expand(struct swm_region
*, union arg
*, const char *, char ***);
1153 void spawn_insert(const char *, const char *, int);
1154 struct spawn_prog
*spawn_find(const char *);
1155 void spawn_remove(struct spawn_prog
*);
1156 void spawn_replace(struct spawn_prog
*, const char *, const char *, int);
1157 void spawn_select(struct swm_region
*, union arg
*, const char *, int *);
1158 void stack_config(struct swm_region
*, union arg
*);
1159 void stack_master(struct workspace
*, struct swm_geometry
*, int, bool);
1160 void store_float_geom(struct ws_win
*);
1161 char *strdupsafe(const char *);
1162 void swapwin(struct swm_region
*, union arg
*);
1163 void switchws(struct swm_region
*, union arg
*);
1164 void teardown_ewmh(void);
1165 void unescape_selector(char *);
1166 void unfocus_win(struct ws_win
*);
1167 void uniconify(struct swm_region
*, union arg
*);
1168 void unmanage_window(struct ws_win
*);
1169 void unmapnotify(xcb_unmap_notify_event_t
*);
1170 void unmap_all(void);
1171 void unmap_window(struct ws_win
*);
1172 void updatenumlockmask(void);
1173 void update_floater(struct ws_win
*);
1174 void update_modkey(unsigned int);
1175 unsigned char update_mousebutton(unsigned char, unsigned int);
1176 void update_win_stacking(struct ws_win
*);
1177 void update_window(struct ws_win
*);
1178 void update_window_color(struct ws_win
*);
1179 void update_wm_state(struct ws_win
*win
);
1180 void validate_spawns(void);
1181 int validate_win(struct ws_win
*);
1182 int validate_ws(struct workspace
*);
1183 void version(struct swm_region
*, union arg
*);
1184 void win_to_ws(struct ws_win
*, int, bool);
1185 pid_t
window_get_pid(xcb_window_t
);
1186 void wkill(struct swm_region
*, union arg
*);
1187 void update_ws_stack(struct workspace
*);
1188 void xft_init(struct swm_region
*);
1189 void _add_startup_exception(const char *, va_list);
1190 void add_startup_exception(const char *, ...);
1192 RB_PROTOTYPE(key_tree
, key
, entry
, key_cmp
);
1193 RB_GENERATE(key_tree
, key
, entry
, key_cmp
);
1194 struct key_tree keys
;
1199 xcb_font_t cf
= XCB_NONE
;
1202 for (i
= 0; i
< LENGTH(cursors
); ++i
) {
1203 /* try to load Xcursor first. */
1204 cursors
[i
].cid
= XcursorLibraryLoadCursor(display
,
1207 /* fallback to cursorfont. */
1208 if (cursors
[i
].cid
== XCB_CURSOR_NONE
) {
1209 if (cf
== XCB_NONE
) {
1210 cf
= xcb_generate_id(conn
);
1211 xcb_open_font(conn
, cf
, strlen("cursor"),
1215 cursors
[i
].cid
= xcb_generate_id(conn
);
1216 xcb_create_glyph_cursor(conn
, cursors
[i
].cid
, cf
, cf
,
1217 cursors
[i
].cf_char
, cursors
[i
].cf_char
+ 1, 0, 0, 0,
1218 0xffff, 0xffff, 0xffff);
1224 xcb_close_font(conn
, cf
);
1228 cursors_cleanup(void)
1231 for (i
= 0; i
< LENGTH(cursors
); ++i
)
1232 xcb_free_cursor(conn
, cursors
[i
].cid
);
1236 expand_tilde(const char *s
)
1238 struct passwd
*ppwd
;
1246 errx(1, "expand_tilde: NULL string.");
1249 result
= strdup(sc
);
1255 if ((max
= sysconf(_SC_LOGIN_NAME_MAX
)) == -1)
1256 errx(1, "expand_tilde: sysconf");
1258 if ((user
= calloc(1, max
+ 1)) == NULL
)
1259 errx(1, "expand_tilde: calloc");
1261 for (i
= 0; s
[i
] != '/' && s
[i
] != '\0'; ++i
)
1266 ppwd
= strlen(user
) == 0 ? getpwuid(getuid()) : getpwnam(user
);
1270 result
= strdup(sc
);
1272 if (asprintf(&result
, "%s%s", ppwd
->pw_dir
, s
) == -1)
1276 errx(1, "expand_tilde: failed to allocate memory.");
1282 parse_rgb(const char *rgb
, uint16_t *rr
, uint16_t *gg
, uint16_t *bb
)
1284 unsigned int tmpr
, tmpg
, tmpb
;
1286 if (sscanf(rgb
, "rgb:%x/%x/%x", &tmpr
, &tmpg
, &tmpb
) != 3)
1289 *rr
= RGB_8_TO_16(tmpr
);
1290 *gg
= RGB_8_TO_16(tmpg
);
1291 *bb
= RGB_8_TO_16(tmpb
);
1297 get_screen(int screen
)
1299 const xcb_setup_t
*r
;
1300 xcb_screen_iterator_t iter
;
1302 if ((r
= xcb_get_setup(conn
)) == NULL
) {
1303 DNPRINTF(SWM_D_MISC
, "get_screen: xcb_get_setup\n");
1307 iter
= xcb_setup_roots_iterator(r
);
1308 for (; iter
.rem
; --screen
, xcb_screen_next(&iter
))
1316 get_screen_count(void)
1318 const xcb_setup_t
*r
;
1320 if ((r
= xcb_get_setup(conn
)) == NULL
) {
1321 DNPRINTF(SWM_D_MISC
, "get_screen_count: xcb_get_setup\n");
1325 return xcb_setup_roots_length(r
);
1329 get_region_index(struct swm_region
*r
)
1331 struct swm_region
*rr
;
1337 TAILQ_FOREACH(rr
, &r
->s
->rl
, entry
) {
1352 if (focus_mode
== SWM_FOCUS_DEFAULT
)
1353 event_drain(XCB_ENTER_NOTIFY
);
1359 get_atom_from_string(const char *str
)
1361 xcb_intern_atom_cookie_t c
;
1362 xcb_intern_atom_reply_t
*r
;
1365 c
= xcb_intern_atom(conn
, 0, strlen(str
), str
);
1366 r
= xcb_intern_atom_reply(conn
, c
, NULL
);
1374 return (XCB_ATOM_NONE
);
1378 get_wm_protocols(struct ws_win
*win
) {
1380 xcb_icccm_get_wm_protocols_reply_t wpr
;
1382 if (xcb_icccm_get_wm_protocols_reply(conn
,
1383 xcb_icccm_get_wm_protocols(conn
, win
->id
, a_prot
),
1385 for (i
= 0; i
< (int)wpr
.atoms_len
; i
++) {
1386 if (wpr
.atoms
[i
] == a_takefocus
)
1387 win
->take_focus
= true;
1388 if (wpr
.atoms
[i
] == a_delete
)
1389 win
->can_delete
= true;
1391 xcb_icccm_get_wm_protocols_reply_wipe(&wpr
);
1398 xcb_window_t root
, win
;
1399 int i
, j
, num_screens
;
1401 for (i
= 0; i
< LENGTH(ewmh
); i
++)
1402 ewmh
[i
].atom
= get_atom_from_string(ewmh
[i
].name
);
1404 num_screens
= get_screen_count();
1405 for (i
= 0; i
< num_screens
; i
++) {
1406 root
= screens
[i
].root
;
1408 /* Set up _NET_SUPPORTING_WM_CHECK. */
1409 win
= xcb_generate_id(conn
);
1410 xcb_create_window(conn
, XCB_COPY_FROM_PARENT
, win
, root
,
1411 0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT
,
1412 XCB_COPY_FROM_PARENT
, 0, NULL
);
1414 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, root
,
1415 a_net_wm_check
, XCB_ATOM_WINDOW
, 32, 1, &win
);
1416 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
,
1417 a_net_wm_check
, XCB_ATOM_WINDOW
, 32, 1, &win
);
1420 * Impersonate LG3D non-reparenting WM, written by Sun, to
1421 * workaround a Java GUI rendering issue.
1423 if (java_workaround
)
1424 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
,
1425 ewmh
[_NET_WM_NAME
].atom
, a_utf8_string
,
1426 8, strlen("LG3D"), "LG3D");
1428 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
,
1429 ewmh
[_NET_WM_NAME
].atom
, a_utf8_string
,
1430 8, strlen("spectrwm"), "spectrwm");
1432 /* Report supported atoms */
1433 xcb_delete_property(conn
, root
, a_net_supported
);
1434 for (j
= 0; j
< LENGTH(ewmh
); j
++)
1435 xcb_change_property(conn
, XCB_PROP_MODE_APPEND
, root
,
1436 a_net_supported
, XCB_ATOM_ATOM
, 32, 1,
1441 ewmh_update_desktops();
1442 ewmh_get_desktop_names();
1450 xcb_get_property_cookie_t pc
;
1451 xcb_get_property_reply_t
*pr
;
1453 num_screens
= get_screen_count();
1455 for (i
= 0; i
< num_screens
; i
++) {
1456 /* Get the support check window and destroy it */
1457 pc
= xcb_get_property(conn
, 0, screens
[i
].root
, a_net_wm_check
,
1458 XCB_ATOM_WINDOW
, 0, 1);
1459 pr
= xcb_get_property_reply(conn
, pc
, NULL
);
1462 if (pr
->format
== a_net_wm_check
) {
1463 id
= *((xcb_window_t
*)xcb_get_property_value(pr
));
1465 xcb_destroy_window(conn
, id
);
1466 xcb_delete_property(conn
, screens
[i
].root
,
1468 xcb_delete_property(conn
, screens
[i
].root
,
1476 ewmh_autoquirk(struct ws_win
*win
)
1478 xcb_get_property_reply_t
*r
;
1479 xcb_get_property_cookie_t c
;
1483 c
= xcb_get_property(conn
, 0, win
->id
,
1484 ewmh
[_NET_WM_WINDOW_TYPE
].atom
, XCB_ATOM_ATOM
, 0, UINT32_MAX
);
1485 r
= xcb_get_property_reply(conn
, c
, NULL
);
1489 type
= xcb_get_property_value(r
);
1490 n
= xcb_get_property_value_length(r
) / sizeof(xcb_atom_t
);
1492 for (i
= 0; i
< n
; i
++) {
1493 if (type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_NORMAL
].atom
)
1495 if (type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_DOCK
].atom
||
1496 type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_TOOLBAR
].atom
||
1497 type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_UTILITY
].atom
) {
1498 win
->quirks
= SWM_Q_FLOAT
| SWM_Q_ANYWHERE
;
1501 if (type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_SPLASH
].atom
||
1502 type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_DIALOG
].atom
) {
1503 win
->quirks
= SWM_Q_FLOAT
;
1511 ewmh_update_actions(struct ws_win
*win
)
1513 xcb_atom_t actions
[SWM_EWMH_ACTION_COUNT_MAX
];
1519 actions
[n
++] = ewmh
[_NET_WM_ACTION_CLOSE
].atom
;
1522 actions
[n
++] = ewmh
[_NET_WM_ACTION_MOVE
].atom
;
1523 actions
[n
++] = ewmh
[_NET_WM_ACTION_RESIZE
].atom
;
1524 actions
[n
++] = ewmh
[_NET_WM_ACTION_ABOVE
].atom
;
1527 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
,
1528 ewmh
[_NET_WM_ALLOWED_ACTIONS
].atom
, XCB_ATOM_ATOM
, 32, 1, actions
);
1531 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1532 #define _NET_WM_STATE_ADD 1 /* add/set property */
1533 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1536 ewmh_change_wm_state(struct ws_win
*win
, xcb_atom_t state
, long action
)
1543 name
= get_atom_name(state
);
1544 DNPRINTF(SWM_D_PROP
, "ewmh_change_wm_state: win %#x, state: %s, "
1545 "action: %ld\n", WINID(win
), name
, action
);
1551 if (state
== ewmh
[_NET_WM_STATE_FULLSCREEN
].atom
)
1552 flag
= EWMH_F_FULLSCREEN
;
1553 else if (state
== ewmh
[_NET_WM_STATE_ABOVE
].atom
)
1554 flag
= EWMH_F_ABOVE
;
1555 else if (state
== ewmh
[_NET_WM_STATE_HIDDEN
].atom
)
1556 flag
= EWMH_F_HIDDEN
;
1557 else if (state
== ewmh
[_NET_WM_STATE_MAXIMIZED_VERT
].atom
||
1558 state
== ewmh
[_NET_WM_STATE_MAXIMIZED_HORZ
].atom
)
1559 flag
= EWMH_F_MAXIMIZED
;
1560 else if (state
== ewmh
[_SWM_WM_STATE_MANUAL
].atom
)
1561 flag
= SWM_F_MANUAL
;
1562 else if (state
== ewmh
[_NET_WM_STATE_SKIP_PAGER
].atom
)
1563 flag
= EWMH_F_SKIP_PAGER
;
1564 else if (state
== ewmh
[_NET_WM_STATE_SKIP_TASKBAR
].atom
)
1565 flag
= EWMH_F_SKIP_TASKBAR
;
1567 /* Disallow unfloating transients. */
1568 if (TRANS(win
) && flag
== EWMH_F_ABOVE
)
1571 new_flags
= win
->ewmh_flags
;
1574 case _NET_WM_STATE_REMOVE
:
1577 case _NET_WM_STATE_ADD
:
1580 case _NET_WM_STATE_TOGGLE
:
1585 ewmh_apply_flags(win
, new_flags
);
1588 DNPRINTF(SWM_D_PROP
, "ewmh_change_wm_state: done.\n");
1592 ewmh_apply_flags(struct ws_win
*win
, uint32_t pending
)
1594 struct workspace
*ws
;
1597 changed
= win
->ewmh_flags
^ pending
;
1601 DNPRINTF(SWM_D_PROP
, "ewmh_apply_flags: pending: %d\n", pending
);
1603 win
->ewmh_flags
= pending
;
1606 if (changed
& EWMH_F_HIDDEN
) {
1608 if (focus_mode
!= SWM_FOCUS_FOLLOW
)
1609 ws
->focus_pending
= get_focus_prev(win
);
1614 /* Reload floating geometry in case region changed. */
1616 load_float_geom(win
);
1618 /* The window is no longer iconic, prepare focus. */
1619 if (focus_mode
!= SWM_FOCUS_FOLLOW
)
1620 ws
->focus_pending
= get_focus_magic(win
);
1625 if (changed
& EWMH_F_ABOVE
) {
1626 if (ws
->cur_layout
!= &layouts
[SWM_MAX_STACK
]) {
1628 load_float_geom(win
);
1629 else if (!MAXIMIZED(win
))
1630 store_float_geom(win
);
1632 win
->ewmh_flags
&= ~EWMH_F_MAXIMIZED
;
1633 changed
&= ~EWMH_F_MAXIMIZED
;
1637 win
->ewmh_flags
^= EWMH_F_ABOVE
& pending
;
1641 if (changed
& EWMH_F_MAXIMIZED
) {
1642 /* VERT and/or HORZ changed. */
1644 if (!MAXIMIZED(win
))
1645 load_float_geom(win
);
1647 store_float_geom(win
);
1650 if (MAXIMIZED(win
)) {
1651 if (focus_mode
!= SWM_FOCUS_FOLLOW
&&
1652 ws
->cur_layout
!= &layouts
[SWM_MAX_STACK
]) {
1656 ws
->focus_pending
= win
;
1660 update_window_color(win
);
1664 if (changed
& EWMH_F_FULLSCREEN
) {
1665 if (FULLSCREEN(win
)) {
1666 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
1670 ws
->focus_pending
= win
;
1673 load_float_geom(win
);
1676 win
->ewmh_flags
&= ~EWMH_F_MAXIMIZED
;
1680 DNPRINTF(SWM_D_PROP
, "ewmh_apply_flags: done.\n");
1684 ewmh_update_wm_state(struct ws_win
*win
) {
1685 xcb_atom_t vals
[SWM_EWMH_ACTION_COUNT_MAX
];
1689 vals
[n
++] = ewmh
[_NET_WM_STATE_HIDDEN
].atom
;
1690 if (FULLSCREEN(win
))
1691 vals
[n
++] = ewmh
[_NET_WM_STATE_FULLSCREEN
].atom
;
1692 if (MAXIMIZED_VERT(win
))
1693 vals
[n
++] = ewmh
[_NET_WM_STATE_MAXIMIZED_VERT
].atom
;
1694 if (MAXIMIZED_HORZ(win
))
1695 vals
[n
++] = ewmh
[_NET_WM_STATE_MAXIMIZED_HORZ
].atom
;
1696 if (win
->ewmh_flags
& EWMH_F_SKIP_PAGER
)
1697 vals
[n
++] = ewmh
[_NET_WM_STATE_SKIP_PAGER
].atom
;
1698 if (win
->ewmh_flags
& EWMH_F_SKIP_TASKBAR
)
1699 vals
[n
++] = ewmh
[_NET_WM_STATE_SKIP_TASKBAR
].atom
;
1700 if (win
->ewmh_flags
& EWMH_F_ABOVE
)
1701 vals
[n
++] = ewmh
[_NET_WM_STATE_ABOVE
].atom
;
1702 if (win
->ewmh_flags
& SWM_F_MANUAL
)
1703 vals
[n
++] = ewmh
[_SWM_WM_STATE_MANUAL
].atom
;
1706 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
,
1707 ewmh
[_NET_WM_STATE
].atom
, XCB_ATOM_ATOM
, 32, n
, vals
);
1709 xcb_delete_property(conn
, win
->id
, ewmh
[_NET_WM_STATE
].atom
);
1713 ewmh_get_wm_state(struct ws_win
*win
)
1716 xcb_get_property_cookie_t c
;
1717 xcb_get_property_reply_t
*r
;
1723 win
->ewmh_flags
= 0;
1725 c
= xcb_get_property(conn
, 0, win
->id
, ewmh
[_NET_WM_STATE
].atom
,
1726 XCB_ATOM_ATOM
, 0, UINT32_MAX
);
1727 r
= xcb_get_property_reply(conn
, c
, NULL
);
1731 states
= xcb_get_property_value(r
);
1732 n
= xcb_get_property_value_length(r
) / sizeof(xcb_atom_t
);
1734 for (i
= 0; i
< n
; i
++)
1735 ewmh_change_wm_state(win
, states
[i
], _NET_WM_STATE_ADD
);
1743 dumpwins(struct swm_region
*r
, union arg
*args
)
1747 xcb_get_window_attributes_cookie_t c
;
1748 xcb_get_window_attributes_reply_t
*wa
;
1750 /* suppress unused warning since var is needed */
1753 if (r
->ws
== NULL
) {
1754 DPRINTF("dumpwins: invalid workspace\n");
1758 DPRINTF("=== managed window list ws %02d ===\n", r
->ws
->idx
);
1759 TAILQ_FOREACH(w
, &r
->ws
->winlist
, entry
) {
1760 state
= get_win_state(w
->id
);
1761 c
= xcb_get_window_attributes(conn
, w
->id
);
1762 wa
= xcb_get_window_attributes_reply(conn
, c
, NULL
);
1764 DPRINTF("win %#x, map_state: %d, state: %u, "
1765 "transient: %#x\n", w
->id
, wa
->map_state
,
1766 state
, w
->transient
);
1769 DPRINTF("win %#x, failed xcb_get_window_attributes\n",
1773 DPRINTF("=== stacking order (top down) === \n");
1774 TAILQ_FOREACH(w
, &r
->ws
->stack
, stack_entry
) {
1775 DPRINTF("win %#x, fs: %s, maximized: %s, above: %s, "
1776 "iconic: %s\n", w
->id
, YESNO(FULLSCREEN(w
)),
1777 YESNO(MAXIMIZED(w
)), YESNO(ABOVE(w
)), YESNO(ICONIC(w
)));
1780 DPRINTF("===== unmanaged window list =====\n");
1781 TAILQ_FOREACH(w
, &r
->ws
->unmanagedlist
, entry
) {
1782 state
= get_win_state(w
->id
);
1783 c
= xcb_get_window_attributes(conn
, w
->id
);
1784 wa
= xcb_get_window_attributes_reply(conn
, c
, NULL
);
1786 DPRINTF("win %#x, map_state: %d, state: %u, "
1787 "transient: %#x\n", w
->id
, wa
->map_state
,
1788 state
, w
->transient
);
1791 DPRINTF("win %#x, failed xcb_get_window_attributes\n",
1795 DPRINTF("=================================\n");
1799 dumpwins(struct swm_region
*r
, union arg
*s
)
1804 #endif /* SWM_DEBUG */
1809 int saved_errno
, status
;
1812 saved_errno
= errno
;
1816 while ((pid
= waitpid(WAIT_ANY
, &status
, WNOHANG
)) != 0) {
1821 if (errno
!= ECHILD
)
1822 warn("sighdlr: waitpid");
1823 #endif /* SWM_DEBUG */
1826 if (pid
== searchpid
)
1830 if (WIFEXITED(status
)) {
1831 if (WEXITSTATUS(status
) != 0)
1832 warnx("sighdlr: child exit status: %d",
1833 WEXITSTATUS(status
));
1835 warnx("sighdlr: child is terminated "
1837 #endif /* SWM_DEBUG */
1851 errno
= saved_errno
;
1857 struct pid_e
*p
= NULL
;
1859 DNPRINTF(SWM_D_MISC
, "find_pid: %d\n", pid
);
1864 TAILQ_FOREACH(p
, &pidlist
, entry
) {
1873 name_to_pixel(int sidx
, const char *colorname
)
1875 uint32_t result
= 0;
1876 char cname
[32] = "#";
1877 xcb_screen_t
*screen
;
1878 xcb_colormap_t cmap
;
1879 xcb_alloc_color_reply_t
*cr
;
1880 xcb_alloc_named_color_reply_t
*nr
;
1881 uint16_t rr
, gg
, bb
;
1883 screen
= get_screen(sidx
);
1884 cmap
= screen
->default_colormap
;
1886 /* color is in format rgb://rr/gg/bb */
1887 if (strncmp(colorname
, "rgb:", 4) == 0) {
1888 if (parse_rgb(colorname
, &rr
, &gg
, &bb
) == -1)
1889 warnx("could not parse rgb %s", colorname
);
1891 cr
= xcb_alloc_color_reply(conn
,
1892 xcb_alloc_color(conn
, cmap
, rr
, gg
, bb
),
1898 warnx("color '%s' not found", colorname
);
1901 nr
= xcb_alloc_named_color_reply(conn
,
1902 xcb_alloc_named_color(conn
, cmap
, strlen(colorname
),
1905 strlcat(cname
, colorname
+ 2, sizeof cname
- 1);
1906 nr
= xcb_alloc_named_color_reply(conn
,
1907 xcb_alloc_named_color(conn
, cmap
, strlen(cname
),
1914 warnx("color '%s' not found", colorname
);
1921 setscreencolor(const char *val
, int i
, int c
)
1923 if (i
< 0 || i
>= get_screen_count())
1926 screens
[i
].c
[c
].pixel
= name_to_pixel(i
, val
);
1927 free(screens
[i
].c
[c
].name
);
1928 if ((screens
[i
].c
[c
].name
= strdup(val
)) == NULL
)
1933 fancy_stacker(struct workspace
*ws
)
1935 strlcpy(ws
->stacker
, "[ ]", sizeof ws
->stacker
);
1936 if (ws
->cur_layout
->l_stack
== vertical_stack
)
1937 snprintf(ws
->stacker
, sizeof ws
->stacker
,
1938 ws
->l_state
.vertical_flip
? "[%d>%d]" : "[%d|%d]",
1939 ws
->l_state
.vertical_mwin
, ws
->l_state
.vertical_stacks
);
1940 else if (ws
->cur_layout
->l_stack
== horizontal_stack
)
1941 snprintf(ws
->stacker
, sizeof ws
->stacker
,
1942 ws
->l_state
.horizontal_flip
? "[%dv%d]" : "[%d-%d]",
1943 ws
->l_state
.horizontal_mwin
, ws
->l_state
.horizontal_stacks
);
1947 plain_stacker(struct workspace
*ws
)
1949 strlcpy(ws
->stacker
, "[ ]", sizeof ws
->stacker
);
1950 if (ws
->cur_layout
->l_stack
== vertical_stack
)
1951 strlcpy(ws
->stacker
, ws
->l_state
.vertical_flip
? "[>]" : "[|]",
1952 sizeof ws
->stacker
);
1953 else if (ws
->cur_layout
->l_stack
== horizontal_stack
)
1954 strlcpy(ws
->stacker
, ws
->l_state
.horizontal_flip
? "[v]" : "[-]",
1955 sizeof ws
->stacker
);
1959 custom_region(const char *val
)
1961 unsigned int x
, y
, w
, h
;
1962 int sidx
, num_screens
;
1963 xcb_screen_t
*screen
;
1965 num_screens
= get_screen_count();
1966 if (sscanf(val
, "screen[%d]:%ux%u+%u+%u", &sidx
, &w
, &h
, &x
, &y
) != 5)
1967 errx(1, "invalid custom region, "
1968 "should be 'screen[<n>]:<n>x<n>+<n>+<n>");
1969 if (sidx
< 1 || sidx
> num_screens
)
1970 errx(1, "invalid screen index: %d out of bounds (maximum %d)",
1974 if ((screen
= get_screen(sidx
)) == NULL
)
1975 errx(1, "ERROR: can't get screen %d.", sidx
);
1978 errx(1, "region %ux%u+%u+%u too small", w
, h
, x
, y
);
1980 if (x
> screen
->width_in_pixels
||
1981 y
> screen
->height_in_pixels
||
1982 w
+ x
> screen
->width_in_pixels
||
1983 h
+ y
> screen
->height_in_pixels
) {
1984 warnx("ignoring region %ux%u+%u+%u - not within screen "
1985 "boundaries (%ux%u)", w
, h
, x
, y
,
1986 screen
->width_in_pixels
, screen
->height_in_pixels
);
1990 new_region(&screens
[sidx
], x
, y
, w
, h
);
1994 socket_setnonblock(int fd
)
1998 if ((flags
= fcntl(fd
, F_GETFL
, 0)) == -1)
1999 err(1, "fcntl F_GETFL");
2000 flags
|= O_NONBLOCK
;
2001 if ((flags
= fcntl(fd
, F_SETFL
, flags
)) == -1)
2002 err(1, "fcntl F_SETFL");
2006 bar_print_legacy(struct swm_region
*r
, const char *s
)
2008 xcb_rectangle_t rect
;
2013 XRectangle ibox
, lbox
;
2017 XmbTextExtents(bar_fs
, s
, len
, &ibox
, &lbox
);
2019 switch (bar_justify
) {
2020 case SWM_BAR_JUSTIFY_LEFT
:
2023 case SWM_BAR_JUSTIFY_CENTER
:
2024 x
= (WIDTH(r
) - lbox
.width
) / 2;
2026 case SWM_BAR_JUSTIFY_RIGHT
:
2027 x
= WIDTH(r
) - lbox
.width
- SWM_BAR_OFFSET
;
2031 if (x
< SWM_BAR_OFFSET
)
2036 rect
.width
= WIDTH(r
->bar
);
2037 rect
.height
= HEIGHT(r
->bar
);
2039 /* clear back buffer */
2040 gcv
[0] = r
->s
->c
[SWM_S_COLOR_BAR
].pixel
;
2041 xcb_change_gc(conn
, r
->s
->bar_gc
, XCB_GC_FOREGROUND
, gcv
);
2042 xcb_poly_fill_rectangle(conn
, r
->bar
->buffer
, r
->s
->bar_gc
, 1, &rect
);
2044 /* draw back buffer */
2045 gcvd
.graphics_exposures
= 0;
2046 draw
= XCreateGC(display
, r
->bar
->buffer
, GCGraphicsExposures
, &gcvd
);
2047 XSetForeground(display
, draw
, r
->s
->c
[SWM_S_COLOR_BAR_FONT
].pixel
);
2048 DRAWSTRING(display
, r
->bar
->buffer
, bar_fs
, draw
,
2049 x
, (bar_fs_extents
->max_logical_extent
.height
- lbox
.height
) / 2 -
2051 XFreeGC(display
, draw
);
2054 xcb_copy_area(conn
, r
->bar
->buffer
, r
->bar
->id
, r
->s
->bar_gc
, 0, 0,
2055 0, 0, WIDTH(r
->bar
), HEIGHT(r
->bar
));
2059 bar_print(struct swm_region
*r
, const char *s
)
2062 xcb_rectangle_t rect
;
2070 XftTextExtentsUtf8(display
, bar_font
, (FcChar8
*)s
, len
, &info
);
2072 switch (bar_justify
) {
2073 case SWM_BAR_JUSTIFY_LEFT
:
2076 case SWM_BAR_JUSTIFY_CENTER
:
2077 x
= (WIDTH(r
) - info
.width
) / 2;
2079 case SWM_BAR_JUSTIFY_RIGHT
:
2080 x
= WIDTH(r
) - info
.width
- SWM_BAR_OFFSET
;
2084 if (x
< SWM_BAR_OFFSET
)
2089 rect
.width
= WIDTH(r
->bar
);
2090 rect
.height
= HEIGHT(r
->bar
);
2092 /* clear back buffer */
2093 gcv
[0] = r
->s
->c
[SWM_S_COLOR_BAR
].pixel
;
2094 xcb_change_gc(conn
, r
->s
->bar_gc
, XCB_GC_FOREGROUND
, gcv
);
2095 xcb_poly_fill_rectangle(conn
, r
->bar
->buffer
, r
->s
->bar_gc
, 1, &rect
);
2097 /* draw back buffer */
2098 draw
= XftDrawCreate(display
, r
->bar
->buffer
,
2099 DefaultVisual(display
, r
->s
->idx
),
2100 DefaultColormap(display
, r
->s
->idx
));
2102 XftDrawStringUtf8(draw
, &bar_font_color
, bar_font
, x
,
2103 (HEIGHT(r
->bar
) + bar_font
->height
) / 2 - bar_font
->descent
,
2106 XftDrawDestroy(draw
);
2109 xcb_copy_area(conn
, r
->bar
->buffer
, r
->bar
->id
, r
->s
->bar_gc
, 0, 0,
2110 0, 0, WIDTH(r
->bar
), HEIGHT(r
->bar
));
2114 bar_extra_stop(void)
2118 bzero(bar_pipe
, sizeof bar_pipe
);
2121 kill(bar_pid
, SIGTERM
);
2124 strlcpy(bar_ext
, "", sizeof bar_ext
);
2129 bar_window_class(char *s
, size_t sz
, struct swm_region
*r
)
2131 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2133 if (r
->ws
->focus
->ch
.class_name
!= NULL
)
2134 strlcat(s
, r
->ws
->focus
->ch
.class_name
, sz
);
2138 bar_window_instance(char *s
, size_t sz
, struct swm_region
*r
)
2140 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2142 if (r
->ws
->focus
->ch
.instance_name
!= NULL
)
2143 strlcat(s
, r
->ws
->focus
->ch
.instance_name
, sz
);
2147 bar_window_class_instance(char *s
, size_t sz
, struct swm_region
*r
)
2149 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2152 bar_window_class(s
, sz
, r
);
2153 strlcat(s
, ":", sz
);
2154 bar_window_instance(s
, sz
, r
);
2158 bar_window_state(char *s
, size_t sz
, struct swm_region
*r
)
2160 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2162 if (MAXIMIZED(r
->ws
->focus
))
2163 strlcat(s
, "(m)", sz
);
2164 else if (ABOVE(r
->ws
->focus
))
2165 strlcat(s
, "(f)", sz
);
2169 bar_window_name(char *s
, size_t sz
, struct swm_region
*r
)
2173 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2176 title
= get_win_name(r
->ws
->focus
->id
);
2177 strlcat(s
, title
, sz
);
2182 get_urgent(struct ws_win
*win
)
2184 xcb_icccm_wm_hints_t hints
;
2185 xcb_get_property_cookie_t c
;
2186 bool urgent
= false;
2189 c
= xcb_icccm_get_wm_hints(conn
, win
->id
);
2190 if (xcb_icccm_get_wm_hints_reply(conn
, c
, &hints
, NULL
))
2191 urgent
= xcb_icccm_wm_hints_get_urgency(&hints
);
2198 bar_urgent(char *s
, size_t sz
)
2201 int i
, j
, num_screens
;
2202 bool urgent
[SWM_WS_MAX
];
2205 for (i
= 0; i
< workspace_limit
; i
++)
2208 num_screens
= get_screen_count();
2209 for (i
= 0; i
< num_screens
; i
++)
2210 for (j
= 0; j
< workspace_limit
; j
++)
2211 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
2212 if (get_urgent(win
))
2215 for (i
= 0; i
< workspace_limit
; i
++) {
2217 snprintf(b
, sizeof b
, "%d ", i
+ 1);
2219 } else if (!urgent_collapse
) {
2220 strlcat(s
, "- ", sz
);
2226 bar_workspace_name(char *s
, size_t sz
, struct swm_region
*r
)
2228 if (r
== NULL
|| r
->ws
== NULL
)
2230 if (r
->ws
->name
!= NULL
)
2231 strlcat(s
, r
->ws
->name
, sz
);
2234 /* build the default bar format according to the defined enabled options */
2236 bar_fmt(const char *fmtexp
, char *fmtnew
, struct swm_region
*r
, size_t sz
)
2240 /* if format provided, just copy the buffers */
2241 if (bar_format
!= NULL
) {
2242 strlcpy(fmtnew
, fmtexp
, sz
);
2246 /* reset the output buffer */
2249 strlcat(fmtnew
, "+N:+I ", sz
);
2251 strlcat(fmtnew
, "+S", sz
);
2252 strlcat(fmtnew
, " ", sz
);
2254 /* only show the workspace name if there's actually one */
2255 if (r
!= NULL
&& r
->ws
!= NULL
&& r
->ws
->name
!= NULL
)
2256 strlcat(fmtnew
, "<+D>", sz
);
2258 /* If enabled, only show the iconic count if there are iconic wins. */
2259 if (iconic_enabled
&& r
!= NULL
&& r
->ws
!= NULL
)
2260 TAILQ_FOREACH(w
, &r
->ws
->winlist
, entry
)
2262 strlcat(fmtnew
, "{+M}", sz
);
2266 strlcat(fmtnew
, "+3<", sz
);
2268 if (clock_enabled
) {
2269 strlcat(fmtnew
, fmtexp
, sz
);
2270 strlcat(fmtnew
, "+4<", sz
);
2273 /* bar_urgent already adds the space before the last asterisk */
2275 strlcat(fmtnew
, "* +U*+4<", sz
);
2277 if (window_class_enabled
) {
2278 strlcat(fmtnew
, "+C", sz
);
2279 if (!window_instance_enabled
)
2280 strlcat(fmtnew
, "+4<", sz
);
2283 /* checks needed by the colon and floating strlcat(3) calls below */
2284 if (r
!= NULL
&& r
->ws
!= NULL
&& r
->ws
->focus
!= NULL
) {
2285 if (window_instance_enabled
) {
2286 if (window_class_enabled
)
2287 strlcat(fmtnew
, ":", sz
);
2288 strlcat(fmtnew
, "+T+4<", sz
);
2290 if (window_name_enabled
) {
2291 if (ABOVE(r
->ws
->focus
) || MAXIMIZED(r
->ws
->focus
))
2292 strlcat(fmtnew
, "+F ", sz
);
2293 strlcat(fmtnew
, "+64W ", sz
);
2297 /* finally add the action script output and the version */
2298 strlcat(fmtnew
, "+4<+A+4<+V", sz
);
2302 bar_replace_pad(char *tmp
, int *limit
, size_t sz
)
2304 /* special case; no limit given, pad one space, instead */
2305 if (*limit
== (int)sz
- 1)
2307 snprintf(tmp
, sz
, "%*s", *limit
, " ");
2310 /* replaces the bar format character sequences (like in tmux(1)) */
2312 bar_replace_seq(char *fmt
, char *fmtrep
, struct swm_region
*r
, size_t *offrep
,
2317 char tmp
[SWM_BAR_MAX
];
2318 int limit
, size
, count
;
2321 /* reset strlcat(3) buffer */
2324 /* get number, if any */
2327 if (sscanf(fmt
, "%d%n", &limit
, &size
) != 1)
2328 limit
= sizeof tmp
- 1;
2329 if (limit
<= 0 || limit
>= (int)sizeof tmp
)
2330 limit
= sizeof tmp
- 1;
2332 /* there is nothing to replace (ie EOL) */
2339 bar_replace_pad(tmp
, &limit
, sizeof tmp
);
2342 snprintf(tmp
, sizeof tmp
, "%s", bar_ext
);
2345 bar_window_class(tmp
, sizeof tmp
, r
);
2348 bar_workspace_name(tmp
, sizeof tmp
, r
);
2351 bar_window_state(tmp
, sizeof tmp
, r
);
2354 snprintf(tmp
, sizeof tmp
, "%d", r
->ws
->idx
+ 1);
2358 TAILQ_FOREACH(w
, &r
->ws
->winlist
, entry
)
2362 snprintf(tmp
, sizeof tmp
, "%d", count
);
2365 snprintf(tmp
, sizeof tmp
, "%d", r
->s
->idx
+ 1);
2368 bar_window_class_instance(tmp
, sizeof tmp
, r
);
2371 snprintf(tmp
, sizeof tmp
, "%s", r
->ws
->stacker
);
2374 bar_window_instance(tmp
, sizeof tmp
, r
);
2377 bar_urgent(tmp
, sizeof tmp
);
2380 snprintf(tmp
, sizeof tmp
, "%s", bar_vertext
);
2383 bar_window_name(tmp
, sizeof tmp
, r
);
2386 /* unknown character sequence; copy as-is */
2387 snprintf(tmp
, sizeof tmp
, "+%c", *fmt
);
2393 if ((int)len
< limit
)
2395 while (limit
-- > 0) {
2396 if (*offrep
>= sz
- 1)
2398 fmtrep
[(*offrep
)++] = *ptr
++;
2406 bar_replace(char *fmt
, char *fmtrep
, struct swm_region
*r
, size_t sz
)
2411 while (*fmt
!= '\0') {
2413 /* skip ordinary characters */
2416 fmtrep
[off
++] = *fmt
++;
2420 /* character sequence found; replace it */
2421 fmt
= bar_replace_seq(fmt
, fmtrep
, r
, &off
, sz
);
2430 bar_fmt_expand(char *fmtexp
, size_t sz
)
2437 /* start by grabbing the current time and date */
2439 localtime_r(&tmt
, &tm
);
2441 /* figure out what to expand */
2442 if (bar_format
!= NULL
)
2444 else if (bar_format
== NULL
&& clock_enabled
)
2446 /* if nothing to expand bail out */
2452 /* copy as-is, just in case the format shouldn't be expanded below */
2453 strlcpy(fmtexp
, fmt
, sz
);
2454 /* finally pass the string through strftime(3) */
2455 #ifndef SWM_DENY_CLOCK_FORMAT
2456 if ((len
= strftime(fmtexp
, sz
, fmt
, &tm
)) == 0)
2457 warnx("format too long");
2462 /* Redraws the bar; need to follow with xcb_flush() or focus_flush(). */
2466 char fmtexp
[SWM_BAR_MAX
], fmtnew
[SWM_BAR_MAX
];
2467 char fmtrep
[SWM_BAR_MAX
];
2469 struct swm_region
*r
;
2471 /* expand the format by first passing it through strftime(3) */
2472 bar_fmt_expand(fmtexp
, sizeof fmtexp
);
2474 num_screens
= get_screen_count();
2475 for (i
= 0; i
< num_screens
; i
++) {
2476 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
) {
2480 if (bar_enabled
&& r
->ws
->bar_enabled
)
2481 xcb_map_window(conn
, r
->bar
->id
);
2483 xcb_unmap_window(conn
, r
->bar
->id
);
2487 if (startup_exception
)
2488 snprintf(fmtrep
, sizeof fmtrep
, "total "
2489 "exceptions: %d, first exception: %s",
2493 bar_fmt(fmtexp
, fmtnew
, r
, sizeof fmtnew
);
2494 bar_replace(fmtnew
, fmtrep
, r
, sizeof fmtrep
);
2496 if (bar_font_legacy
)
2497 bar_print_legacy(r
, fmtrep
);
2499 bar_print(r
, fmtrep
);
2505 * Reads external script output; call when stdin is readable.
2506 * Returns 1 if bar_ext was updated; otherwise 0.
2509 bar_extra_update(void)
2512 char b
[SWM_BAR_MAX
];
2513 bool changed
= false;
2518 while (fgets(b
, sizeof(b
), stdin
) != NULL
) {
2521 if (b
[len
- 1] == '\n') {
2522 /* Remove newline. */
2525 /* "Clear" bar_ext. */
2528 /* Flush buffered output. */
2529 strlcpy(bar_ext
, bar_ext_buf
, sizeof(bar_ext
));
2530 bar_ext_buf
[0] = '\0';
2532 /* Append new output to bar. */
2533 strlcat(bar_ext
, b
, sizeof(bar_ext
));
2537 /* Buffer output. */
2538 strlcat(bar_ext_buf
, b
, sizeof(bar_ext_buf
));
2543 if (errno
!= EAGAIN
) {
2544 warn("bar_action failed");
2553 bar_toggle(struct swm_region
*r
, union arg
*args
)
2555 struct swm_region
*tmpr
;
2558 /* suppress unused warnings since vars are needed */
2562 DNPRINTF(SWM_D_BAR
, "bar_toggle\n");
2565 case SWM_ARG_ID_BAR_TOGGLE_WS
:
2566 /* Only change if master switch is enabled. */
2568 r
->ws
->bar_enabled
= !r
->ws
->bar_enabled
;
2570 bar_enabled
= r
->ws
->bar_enabled
= true;
2572 case SWM_ARG_ID_BAR_TOGGLE
:
2573 bar_enabled
= !bar_enabled
;
2577 /* update bars as necessary */
2578 num_screens
= get_screen_count();
2579 for (i
= 0; i
< num_screens
; i
++)
2580 TAILQ_FOREACH(tmpr
, &screens
[i
].rl
, entry
)
2582 if (bar_enabled
&& tmpr
->ws
->bar_enabled
)
2583 xcb_map_window(conn
, tmpr
->bar
->id
);
2585 xcb_unmap_window(conn
, tmpr
->bar
->id
);
2590 /* must be after stack */
2597 bar_extra_setup(void)
2599 /* do this here because the conf file is in memory */
2600 if (!bar_extra
&& bar_argv
[0]) {
2601 /* launch external status app */
2603 if (pipe(bar_pipe
) == -1)
2604 err(1, "pipe error");
2605 socket_setnonblock(bar_pipe
[0]);
2606 socket_setnonblock(bar_pipe
[1]); /* XXX hmmm, really? */
2608 /* Set stdin to read from the pipe. */
2609 if (dup2(bar_pipe
[0], STDIN_FILENO
) == -1)
2612 /* Set stdout to write to the pipe. */
2613 if (dup2(bar_pipe
[1], STDOUT_FILENO
) == -1)
2616 if (signal(SIGPIPE
, SIG_IGN
) == SIG_ERR
)
2617 err(1, "could not disable SIGPIPE");
2618 switch (bar_pid
= fork()) {
2620 err(1, "cannot fork");
2624 execvp(bar_argv
[0], bar_argv
);
2625 err(1, "%s external app failed", bar_argv
[0]);
2627 default: /* parent */
2632 atexit(kill_bar_extra_atexit
);
2637 kill_bar_extra_atexit(void)
2640 kill(bar_pid
, SIGTERM
);
2648 while ((s
= index(s
, '-'))) {
2653 return (count
== 14);
2659 char *default_string
;
2660 char **missing_charsets
;
2661 int num_missing_charsets
= 0;
2665 XFreeFontSet(display
, bar_fs
);
2669 DNPRINTF(SWM_D_INIT
, "fontset_init: loading bar_fonts: %s\n", bar_fonts
);
2671 bar_fs
= XCreateFontSet(display
, bar_fonts
, &missing_charsets
,
2672 &num_missing_charsets
, &default_string
);
2674 if (num_missing_charsets
> 0) {
2675 warnx("Unable to load charset(s):");
2677 for (i
= 0; i
< num_missing_charsets
; ++i
)
2678 warnx("%s", missing_charsets
[i
]);
2680 XFreeStringList(missing_charsets
);
2682 if (strcmp(default_string
, ""))
2683 warnx("Glyphs from those sets will be replaced "
2684 "by '%s'.", default_string
);
2686 warnx("Glyphs from those sets won't be drawn.");
2690 errx(1, "Error creating font set structure.");
2692 bar_fs_extents
= XExtentsOfFontSet(bar_fs
);
2694 bar_height
= bar_fs_extents
->max_logical_extent
.height
+
2695 2 * bar_border_width
;
2702 xft_init(struct swm_region
*r
)
2704 char *font
, *d
, *search
;
2707 if (bar_font
== NULL
) {
2708 if ((d
= strdup(bar_fonts
)) == NULL
)
2709 errx(1, "insufficient memory.");
2711 while ((font
= strsep(&search
, ",")) != NULL
) {
2715 DNPRINTF(SWM_D_INIT
, "xft_init: try font %s\n", font
);
2718 bar_font
= XftFontOpenXlfd(display
, r
->s
->idx
,
2721 bar_font
= XftFontOpenName(display
, r
->s
->idx
,
2725 if (bar_font
== NULL
) {
2726 warnx("unable to load font %s", font
);
2729 DNPRINTF(SWM_D_INIT
, "successfully opened "
2737 if (bar_font
== NULL
)
2738 errx(1, "unable to open a font");
2740 PIXEL_TO_XRENDERCOLOR(r
->s
->c
[SWM_S_COLOR_BAR_FONT
].pixel
, color
);
2742 if (!XftColorAllocValue(display
, DefaultVisual(display
, r
->s
->idx
),
2743 DefaultColormap(display
, r
->s
->idx
), &color
, &bar_font_color
))
2744 warn("Xft error: unable to allocate color.");
2746 PIXEL_TO_XRENDERCOLOR(r
->s
->c
[SWM_S_COLOR_BAR
].pixel
, color
);
2748 if (!XftColorAllocValue(display
, DefaultVisual(display
, r
->s
->idx
),
2749 DefaultColormap(display
, r
->s
->idx
), &color
, &search_font_color
))
2750 warn("Xft error: unable to allocate color.");
2752 bar_height
= bar_font
->height
+ 2 * bar_border_width
;
2759 bar_setup(struct swm_region
*r
)
2761 xcb_screen_t
*screen
;
2764 DNPRINTF(SWM_D_BAR
, "bar_setup: screen %d.\n",
2767 if ((screen
= get_screen(r
->s
->idx
)) == NULL
)
2768 errx(1, "ERROR: can't get screen %d.", r
->s
->idx
);
2773 if ((r
->bar
= calloc(1, sizeof(struct swm_bar
))) == NULL
)
2774 err(1, "bar_setup: calloc: failed to allocate memory.");
2776 if (bar_font_legacy
)
2782 Y(r
->bar
) = bar_at_bottom
? (Y(r
) + HEIGHT(r
) - bar_height
) : Y(r
);
2783 WIDTH(r
->bar
) = WIDTH(r
) - 2 * bar_border_width
;
2784 HEIGHT(r
->bar
) = bar_height
- 2 * bar_border_width
;
2786 /* Assume region is unfocused when we create the bar. */
2787 r
->bar
->id
= xcb_generate_id(conn
);
2788 wa
[0] = r
->s
->c
[SWM_S_COLOR_BAR
].pixel
;
2789 wa
[1] = r
->s
->c
[SWM_S_COLOR_BAR_BORDER_UNFOCUS
].pixel
;
2790 wa
[2] = XCB_EVENT_MASK_EXPOSURE
| XCB_EVENT_MASK_POINTER_MOTION
|
2791 XCB_EVENT_MASK_POINTER_MOTION_HINT
;
2793 xcb_create_window(conn
, XCB_COPY_FROM_PARENT
, r
->bar
->id
, r
->s
->root
,
2794 X(r
->bar
), Y(r
->bar
), WIDTH(r
->bar
), HEIGHT(r
->bar
),
2795 bar_border_width
, XCB_WINDOW_CLASS_INPUT_OUTPUT
,
2796 XCB_COPY_FROM_PARENT
, XCB_CW_BACK_PIXEL
| XCB_CW_BORDER_PIXEL
2797 | XCB_CW_EVENT_MASK
, wa
);
2799 /* Stack bar window above region window to start. */
2801 wa
[1] = XCB_STACK_MODE_ABOVE
;
2803 xcb_configure_window(conn
, r
->bar
->id
, XCB_CONFIG_WINDOW_SIBLING
|
2804 XCB_CONFIG_WINDOW_STACK_MODE
, wa
);
2806 r
->bar
->buffer
= xcb_generate_id(conn
);
2807 xcb_create_pixmap(conn
, screen
->root_depth
, r
->bar
->buffer
, r
->bar
->id
,
2808 WIDTH(r
->bar
), HEIGHT(r
->bar
));
2811 xcb_randr_select_input(conn
, r
->bar
->id
,
2812 XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE
);
2815 xcb_map_window(conn
, r
->bar
->id
);
2817 DNPRINTF(SWM_D_BAR
, "bar_setup: win %#x, (x,y) w x h: (%d,%d) "
2818 "%d x %d\n", WINID(r
->bar
), X(r
->bar
), Y(r
->bar
), WIDTH(r
->bar
),
2825 bar_cleanup(struct swm_region
*r
)
2829 xcb_destroy_window(conn
, r
->bar
->id
);
2830 xcb_free_pixmap(conn
, r
->bar
->buffer
);
2836 set_win_state(struct ws_win
*win
, uint8_t state
)
2838 uint16_t data
[2] = { state
, XCB_ATOM_NONE
};
2840 DNPRINTF(SWM_D_EVENT
, "set_win_state: win %#x, state: %u\n",
2846 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
, a_state
,
2847 a_state
, 32, 2, data
);
2851 get_win_state(xcb_window_t w
)
2853 xcb_get_property_reply_t
*r
;
2854 xcb_get_property_cookie_t c
;
2855 uint32_t result
= 0;
2857 c
= xcb_get_property(conn
, 0, w
, a_state
, a_state
, 0L, 2L);
2858 r
= xcb_get_property_reply(conn
, c
, NULL
);
2860 if (r
->type
== a_state
&& r
->format
== 32 && r
->length
== 2)
2861 result
= *((uint32_t *)xcb_get_property_value(r
));
2865 DNPRINTF(SWM_D_MISC
, "get_win_state property: win %#x state %u\n", w
,
2871 version(struct swm_region
*r
, union arg
*args
)
2873 /* suppress unused warnings since vars are needed */
2877 bar_version
= !bar_version
;
2879 snprintf(bar_vertext
, sizeof bar_vertext
,
2880 "Version: %s Build: %s", SPECTRWM_VERSION
, buildstr
);
2882 strlcpy(bar_vertext
, "", sizeof bar_vertext
);
2889 client_msg(struct ws_win
*win
, xcb_atom_t a
, xcb_timestamp_t t
)
2891 xcb_client_message_event_t ev
;
2899 name
= get_atom_name(a
);
2900 DNPRINTF(SWM_D_EVENT
, "client_msg: win %#x, atom: %s(%u), "
2902 win
->id
, name
, a
, t
);
2906 bzero(&ev
, sizeof ev
);
2907 ev
.response_type
= XCB_CLIENT_MESSAGE
;
2908 ev
.window
= win
->id
;
2911 ev
.data
.data32
[0] = a
;
2912 ev
.data
.data32
[1] = t
;
2914 xcb_send_event(conn
, 0, win
->id
,
2915 XCB_EVENT_MASK_NO_EVENT
, (const char *)&ev
);
2918 /* synthetic response to a ConfigureRequest when not making a change */
2920 config_win(struct ws_win
*win
, xcb_configure_request_event_t
*ev
)
2922 xcb_configure_notify_event_t ce
;
2927 /* send notification of unchanged state. */
2928 bzero(&ce
, sizeof(ce
));
2929 ce
.response_type
= XCB_CONFIGURE_NOTIFY
;
2932 ce
.width
= WIDTH(win
);
2933 ce
.height
= HEIGHT(win
);
2934 ce
.override_redirect
= 0;
2939 ce
.window
= win
->id
;
2940 ce
.border_width
= BORDER(win
);
2941 ce
.above_sibling
= XCB_WINDOW_NONE
;
2944 ce
.event
= ev
->window
;
2945 ce
.window
= ev
->window
;
2947 /* make response appear more WM_SIZE_HINTS-compliant */
2948 if (win
->sh
.flags
) {
2949 DNPRINTF(SWM_D_MISC
, "config_win: hints: win %#x,"
2950 " sh.flags: %u, min: %d x %d, max: %d x %d, inc: "
2951 "%d x %d\n", win
->id
, win
->sh
.flags
, SH_MIN_W(win
),
2952 SH_MIN_H(win
), SH_MAX_W(win
), SH_MAX_H(win
),
2953 SH_INC_W(win
), SH_INC_H(win
));
2958 /* the hint may be set... to 0! */
2959 if (SH_MIN_W(win
) > 0 && ce
.width
< SH_MIN_W(win
))
2960 ce
.width
= SH_MIN_W(win
);
2961 if (SH_MIN_H(win
) > 0 && ce
.height
< SH_MIN_H(win
))
2962 ce
.height
= SH_MIN_H(win
);
2967 /* may also be advertized as 0 */
2968 if (SH_MAX_W(win
) > 0 && ce
.width
> SH_MAX_W(win
))
2969 ce
.width
= SH_MAX_W(win
);
2970 if (SH_MAX_H(win
) > 0 && ce
.height
> SH_MAX_H(win
))
2971 ce
.height
= SH_MAX_H(win
);
2974 /* resize increment. */
2976 if (SH_INC_W(win
) > 1 && ce
.width
> SH_INC_W(win
))
2977 ce
.width
-= (ce
.width
- SH_MIN_W(win
)) %
2979 if (SH_INC_H(win
) > 1 && ce
.height
> SH_INC_H(win
))
2980 ce
.height
-= (ce
.height
- SH_MIN_H(win
)) %
2984 /* adjust x and y for requested border_width. */
2985 ce
.x
+= BORDER(win
) - ev
->border_width
;
2986 ce
.y
+= BORDER(win
) - ev
->border_width
;
2987 ce
.border_width
= ev
->border_width
;
2988 ce
.above_sibling
= ev
->sibling
;
2991 DNPRINTF(SWM_D_MISC
, "config_win: ewmh: %s, win %#x, (x,y) w x h: "
2992 "(%d,%d) %d x %d, border: %d\n", YESNO(ev
== NULL
), win
->id
, ce
.x
,
2993 ce
.y
, ce
.width
, ce
.height
, ce
.border_width
);
2995 xcb_send_event(conn
, 0, win
->id
, XCB_EVENT_MASK_STRUCTURE_NOTIFY
,
3000 count_win(struct workspace
*ws
, bool count_transient
)
3005 TAILQ_FOREACH(win
, &ws
->winlist
, entry
) {
3006 if (!count_transient
&& FLOATING(win
))
3012 DNPRINTF(SWM_D_MISC
, "count_win: %d\n", count
);
3018 quit(struct swm_region
*r
, union arg
*args
)
3020 /* suppress unused warnings since vars are needed */
3024 DNPRINTF(SWM_D_MISC
, "quit\n");
3029 lower_window(struct ws_win
*win
)
3031 struct ws_win
*target
= NULL
;
3032 struct workspace
*ws
;
3039 DNPRINTF(SWM_D_EVENT
, "lower_window: win %#x\n", win
->id
);
3041 TAILQ_FOREACH(target
, &ws
->stack
, stack_entry
) {
3042 if (target
== win
|| ICONIC(target
))
3044 if (ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
3047 if (win
->transient
== target
->transient
)
3049 if (win
->transient
== target
->id
)
3052 if (FULLSCREEN(target
))
3054 if (FULLSCREEN(win
))
3056 if (MAXIMIZED(target
))
3060 if (ABOVE(target
) || TRANS(target
))
3062 if (ABOVE(win
) || TRANS(win
))
3066 /* Change stack position. */
3067 TAILQ_REMOVE(&ws
->stack
, win
, stack_entry
);
3069 TAILQ_INSERT_BEFORE(target
, win
, stack_entry
);
3071 TAILQ_INSERT_TAIL(&ws
->stack
, win
, stack_entry
);
3073 update_win_stacking(win
);
3076 if (swm_debug
& SWM_D_STACK
) {
3077 DPRINTF("=== stacking order (top down) === \n");
3078 TAILQ_FOREACH(target
, &ws
->stack
, stack_entry
) {
3079 DPRINTF("win %#x, fs: %s, maximized: %s, above: %s, "
3080 "iconic: %s\n", target
->id
, YESNO(FULLSCREEN(target
)),
3081 YESNO(MAXIMIZED(target
)), YESNO(ABOVE(target
)),
3082 YESNO(ICONIC(target
)));
3086 DNPRINTF(SWM_D_EVENT
, "lower_window: done\n");
3090 raise_window(struct ws_win
*win
)
3092 struct ws_win
*target
= NULL
;
3093 struct workspace
*ws
;
3099 DNPRINTF(SWM_D_EVENT
, "raise_window: win %#x\n", win
->id
);
3101 TAILQ_FOREACH(target
, &ws
->stack
, stack_entry
) {
3102 if (target
== win
|| ICONIC(target
))
3104 if (ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
3106 if (TRANS(win
) && (win
->transient
== target
->transient
||
3107 win
->transient
== target
->id
))
3109 if (FULLSCREEN(win
))
3111 if (FULLSCREEN(target
))
3115 if (MAXIMIZED(target
))
3117 if (ABOVE(win
) || TRANS(win
) ||
3118 (win
->ws
->focus
== win
&& ws
->always_raise
))
3120 if (!ABOVE(target
) && !TRANS(target
))
3124 TAILQ_REMOVE(&ws
->stack
, win
, stack_entry
);
3126 TAILQ_INSERT_BEFORE(target
, win
, stack_entry
);
3128 TAILQ_INSERT_TAIL(&ws
->stack
, win
, stack_entry
);
3130 update_win_stacking(win
);
3133 if (swm_debug
& SWM_D_STACK
) {
3134 DPRINTF("=== stacking order (top down) === \n");
3135 TAILQ_FOREACH(target
, &ws
->stack
, stack_entry
) {
3136 DPRINTF("win %#x, fs: %s, maximized: %s, above: %s, "
3137 "iconic: %s\n", target
->id
, YESNO(FULLSCREEN(target
)),
3138 YESNO(MAXIMIZED(target
)), YESNO(ABOVE(target
)),
3139 YESNO(ICONIC(target
)));
3143 DNPRINTF(SWM_D_EVENT
, "raise_window: done\n");
3147 update_win_stacking(struct ws_win
*win
)
3149 struct ws_win
*sibling
;
3150 struct swm_region
*r
;
3153 if (win
== NULL
|| (r
= win
->ws
->r
) == NULL
)
3156 sibling
= TAILQ_NEXT(win
, stack_entry
);
3157 if (sibling
!= NULL
&& (FLOATING(win
) == FLOATING(sibling
) ||
3158 (win
->ws
->always_raise
&& win
->ws
->focus
== win
)))
3159 val
[0] = sibling
->id
;
3160 else if (FLOATING(win
) || (win
->ws
->always_raise
&&
3161 win
->ws
->focus
== win
))
3162 val
[0] = r
->bar
->id
;
3166 DNPRINTF(SWM_D_EVENT
, "update_win_stacking: %#x, sibling %#x\n",
3169 val
[1] = XCB_STACK_MODE_ABOVE
;
3171 xcb_configure_window(conn
, win
->id
, XCB_CONFIG_WINDOW_SIBLING
|
3172 XCB_CONFIG_WINDOW_STACK_MODE
, val
);
3176 map_window(struct ws_win
*win
)
3181 DNPRINTF(SWM_D_EVENT
, "map_window: win %#x, mapped: %s\n",
3182 win
->id
, YESNO(win
->mapped
));
3187 xcb_map_window(conn
, win
->id
);
3188 set_win_state(win
, XCB_ICCCM_WM_STATE_NORMAL
);
3193 unmap_window(struct ws_win
*win
)
3198 DNPRINTF(SWM_D_EVENT
, "unmap_window: win %#x, mapped: %s\n", win
->id
,
3199 YESNO(win
->mapped
));
3204 xcb_unmap_window(conn
, win
->id
);
3205 set_win_state(win
, XCB_ICCCM_WM_STATE_ICONIC
);
3206 win
->mapped
= false;
3213 int i
, j
, num_screens
;
3215 num_screens
= get_screen_count();
3216 for (i
= 0; i
< num_screens
; i
++)
3217 for (j
= 0; j
< workspace_limit
; j
++)
3218 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
3223 fake_keypress(struct ws_win
*win
, xcb_keysym_t keysym
, uint16_t modifiers
)
3225 xcb_key_press_event_t event
;
3226 xcb_keycode_t
*keycode
;
3231 keycode
= xcb_key_symbols_get_keycode(syms
, keysym
);
3233 DNPRINTF(SWM_D_MISC
, "fake_keypress: win %#x, keycode %u\n",
3236 bzero(&event
, sizeof(event
));
3237 event
.event
= win
->id
;
3238 event
.root
= win
->s
->root
;
3239 event
.child
= XCB_WINDOW_NONE
;
3240 event
.time
= XCB_CURRENT_TIME
;
3241 event
.event_x
= X(win
);
3242 event
.event_y
= Y(win
);
3245 event
.same_screen
= 1;
3246 event
.detail
= *keycode
;
3247 event
.state
= modifiers
;
3249 event
.response_type
= XCB_KEY_PRESS
;
3250 xcb_send_event(conn
, 1, win
->id
,
3251 XCB_EVENT_MASK_KEY_PRESS
, (const char *)&event
);
3253 event
.response_type
= XCB_KEY_RELEASE
;
3254 xcb_send_event(conn
, 1, win
->id
,
3255 XCB_EVENT_MASK_KEY_RELEASE
, (const char *)&event
);
3261 restart(struct swm_region
*r
, union arg
*args
)
3263 /* suppress unused warning since var is needed */
3267 DNPRINTF(SWM_D_MISC
, "restart: %s\n", start_argv
[0]);
3271 execvp(start_argv
[0], start_argv
);
3272 warn("execvp failed");
3277 get_pointer_win(xcb_window_t root
)
3279 struct ws_win
*win
= NULL
;
3280 xcb_query_pointer_reply_t
*r
;
3282 DNPRINTF(SWM_D_EVENT
, "get_pointer_win: root: %#x.\n", root
);
3284 r
= xcb_query_pointer_reply(conn
, xcb_query_pointer(conn
, root
), NULL
);
3286 win
= find_window(r
->child
);
3288 DNPRINTF(SWM_D_EVENT
, "get_pointer_win: %#x.\n",
3291 DNPRINTF(SWM_D_EVENT
, "get_pointer_win: none.\n");
3300 center_pointer(struct swm_region
*r
)
3304 if (!warp_pointer
|| r
== NULL
)
3309 DNPRINTF(SWM_D_EVENT
, "center_pointer: win %#x.\n", WINID(win
));
3311 if (win
&& win
->mapped
)
3312 xcb_warp_pointer(conn
, XCB_NONE
, win
->id
, 0, 0, 0, 0,
3313 WIDTH(win
) / 2, HEIGHT(win
) / 2);
3315 xcb_warp_pointer(conn
, XCB_NONE
, r
->id
, 0, 0, 0, 0,
3316 WIDTH(r
) / 2, HEIGHT(r
) / 2);
3320 root_to_region(xcb_window_t root
, int check
)
3323 struct swm_region
*r
= NULL
;
3325 xcb_query_pointer_reply_t
*qpr
;
3326 xcb_get_input_focus_reply_t
*gifr
;
3328 DNPRINTF(SWM_D_MISC
, "root_to_region: win %#x\n", root
);
3330 num_screens
= get_screen_count();
3331 for (i
= 0; i
< num_screens
; i
++)
3332 if (screens
[i
].root
== root
)
3335 if (check
& SWM_CK_REGION
)
3336 r
= screens
[i
].r_focus
;
3338 if (r
== NULL
&& check
& SWM_CK_FOCUS
) {
3339 /* Try to find an actively focused window */
3340 gifr
= xcb_get_input_focus_reply(conn
,
3341 xcb_get_input_focus(conn
), NULL
);
3343 cfw
= find_window(gifr
->focus
);
3344 if (cfw
&& cfw
->ws
->r
)
3351 if (r
== NULL
&& check
& SWM_CK_POINTER
) {
3352 /* No region with an active focus; try to use pointer. */
3353 qpr
= xcb_query_pointer_reply(conn
, xcb_query_pointer(conn
,
3354 screens
[i
].root
), NULL
);
3356 DNPRINTF(SWM_D_MISC
, "root_to_region: pointer: "
3357 "(%d,%d)\n", qpr
->root_x
, qpr
->root_y
);
3358 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
3359 if (X(r
) <= qpr
->root_x
&&
3360 qpr
->root_x
< MAX_X(r
) &&
3361 Y(r
) <= qpr
->root_y
&&
3362 qpr
->root_y
< MAX_Y(r
))
3369 if (r
== NULL
&& check
& SWM_CK_FALLBACK
)
3370 r
= TAILQ_FIRST(&screens
[i
].rl
);
3372 DNPRINTF(SWM_D_MISC
, "root_to_region: idx: %d\n", get_region_index(r
));
3378 find_unmanaged_window(xcb_window_t id
)
3381 int i
, j
, num_screens
;
3383 num_screens
= get_screen_count();
3384 for (i
= 0; i
< num_screens
; i
++)
3385 for (j
= 0; j
< workspace_limit
; j
++)
3386 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].unmanagedlist
,
3394 find_window(xcb_window_t id
)
3397 int i
, j
, num_screens
;
3398 xcb_query_tree_reply_t
*r
;
3400 num_screens
= get_screen_count();
3401 for (i
= 0; i
< num_screens
; i
++)
3402 for (j
= 0; j
< workspace_limit
; j
++)
3403 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
3407 r
= xcb_query_tree_reply(conn
, xcb_query_tree(conn
, id
), NULL
);
3411 /* if we were looking for the parent return that window instead */
3412 if (r
->parent
== 0 || r
->root
== r
->parent
) {
3417 /* look for parent */
3418 for (i
= 0; i
< num_screens
; i
++)
3419 for (j
= 0; j
< workspace_limit
; j
++)
3420 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
3421 if (r
->parent
== win
->id
) {
3431 spawn(int ws_idx
, union arg
*args
, bool close_fd
)
3436 DNPRINTF(SWM_D_MISC
, "spawn: %s\n", args
->argv
[0]);
3438 close(xcb_get_file_descriptor(conn
));
3440 setenv("LD_PRELOAD", SWM_LIB
, 1);
3442 if (asprintf(&ret
, "%d", ws_idx
) == -1) {
3443 warn("spawn: asprintf SWM_WS");
3446 setenv("_SWM_WS", ret
, 1);
3450 if (asprintf(&ret
, "%d", getpid()) == -1) {
3451 warn("spawn: asprintf _SWM_PID");
3454 setenv("_SWM_PID", ret
, 1);
3458 if (setsid() == -1) {
3459 warn("spawn: setsid");
3465 * close stdin and stdout to prevent interaction between apps
3466 * and the baraction script
3467 * leave stderr open to record errors
3469 if ((fd
= open(_PATH_DEVNULL
, O_RDWR
, 0)) == -1) {
3470 warn("spawn: open");
3473 dup2(fd
, STDIN_FILENO
);
3474 dup2(fd
, STDOUT_FILENO
);
3479 execvp(args
->argv
[0], args
->argv
);
3481 warn("spawn: execvp");
3486 kill_refs(struct ws_win
*win
)
3488 int i
, x
, num_screens
;
3489 struct swm_region
*r
;
3490 struct workspace
*ws
;
3495 num_screens
= get_screen_count();
3496 for (i
= 0; i
< num_screens
; i
++)
3497 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
3498 for (x
= 0; x
< workspace_limit
; x
++) {
3500 if (win
== ws
->focus
)
3502 if (win
== ws
->focus_prev
)
3503 ws
->focus_prev
= NULL
;
3508 validate_win(struct ws_win
*testwin
)
3511 struct workspace
*ws
;
3512 struct swm_region
*r
;
3513 int i
, x
, num_screens
;
3515 if (testwin
== NULL
)
3518 num_screens
= get_screen_count();
3519 for (i
= 0; i
< num_screens
; i
++)
3520 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
3521 for (x
= 0; x
< workspace_limit
; x
++) {
3523 TAILQ_FOREACH(win
, &ws
->winlist
, entry
)
3531 validate_ws(struct workspace
*testws
)
3533 struct swm_region
*r
;
3534 struct workspace
*ws
;
3535 int i
, x
, num_screens
;
3537 /* validate all ws */
3538 num_screens
= get_screen_count();
3539 for (i
= 0; i
< num_screens
; i
++)
3540 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
3541 for (x
= 0; x
< workspace_limit
; x
++) {
3550 unfocus_win(struct ws_win
*win
)
3552 xcb_window_t none
= XCB_WINDOW_NONE
;
3554 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: win %#x\n", WINID(win
));
3559 if (win
->ws
== NULL
) {
3560 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: NULL ws.\n");
3564 if (validate_ws(win
->ws
)) {
3565 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: invalid ws.\n");
3569 if (win
->ws
->r
== NULL
) {
3570 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: NULL region.\n");
3574 if (validate_win(win
)) {
3575 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: invalid win.\n");
3580 if (win
->ws
->focus
== win
) {
3581 win
->ws
->focus
= NULL
;
3582 win
->ws
->focus_prev
= win
;
3585 if (validate_win(win
->ws
->focus
)) {
3586 kill_refs(win
->ws
->focus
);
3587 win
->ws
->focus
= NULL
;
3590 if (validate_win(win
->ws
->focus_prev
)) {
3591 kill_refs(win
->ws
->focus_prev
);
3592 win
->ws
->focus_prev
= NULL
;
3595 update_window_color(win
);
3597 /* Raise window to "top unfocused position." */
3598 if (win
->ws
->always_raise
)
3601 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->s
->root
,
3602 ewmh
[_NET_ACTIVE_WINDOW
].atom
, XCB_ATOM_WINDOW
, 32, 1, &none
);
3604 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: done.\n");
3608 focus_win(struct ws_win
*win
)
3610 struct ws_win
*cfw
= NULL
, *parent
= NULL
, *w
, *tmpw
;
3611 struct workspace
*ws
;
3612 xcb_get_input_focus_reply_t
*gifr
;
3614 DNPRINTF(SWM_D_FOCUS
, "focus_win: win %#x\n", WINID(win
));
3616 if (win
== NULL
|| win
->ws
== NULL
|| !win
->mapped
)
3621 if (validate_ws(ws
))
3624 if (validate_win(win
)) {
3629 gifr
= xcb_get_input_focus_reply(conn
, xcb_get_input_focus(conn
), NULL
);
3631 cfw
= find_window(gifr
->focus
);
3632 if (cfw
!= NULL
&& cfw
!= win
) {
3633 if (cfw
->ws
!= ws
&& cfw
->ws
->r
!= NULL
) {
3634 /* Change border to unfocused color. */
3635 xcb_change_window_attributes(conn
, cfw
->id
,
3636 XCB_CW_BORDER_PIXEL
,
3637 &cfw
->s
->c
[(MAXIMIZED(cfw
) ?
3638 SWM_S_COLOR_UNFOCUS_MAXIMIZED
:
3639 SWM_S_COLOR_UNFOCUS
)].pixel
);
3647 if (ws
->focus
!= win
) {
3648 if (ws
->focus
&& ws
->focus
!= cfw
)
3649 unfocus_win(ws
->focus
);
3653 /* If this window directs focus to a child window, then clear. */
3654 if (win
->focus_child
)
3655 win
->focus_child
= NULL
;
3657 /* If transient, adjust parent's focus child for focus_magic. */
3659 parent
= find_window(win
->transient
);
3660 if (parent
&& parent
->focus_child
!= win
)
3661 parent
->focus_child
= win
;
3664 if (cfw
!= win
&& ws
->r
!= NULL
) {
3665 /* Set input focus if no input hint, or indicated by hint. */
3666 if (!(win
->hints
.flags
& XCB_ICCCM_WM_HINT_INPUT
) ||
3667 (win
->hints
.flags
& XCB_ICCCM_WM_HINT_INPUT
&&
3669 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
,
3670 win
->id
, last_event_time
);
3672 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
,
3673 ws
->r
->id
, XCB_CURRENT_TIME
);
3675 /* Tell app it can adjust focus to a specific window. */
3676 if (win
->take_focus
) {
3677 /* java is special; always tell parent */
3678 if (TRANS(win
) && win
->java
)
3679 client_msg(parent
, a_takefocus
,
3682 client_msg(win
, a_takefocus
, last_event_time
);
3685 if (ws
->cur_layout
->flags
& SWM_L_MAPONFOCUS
||
3687 /* If a parent exists, map it first. */
3689 raise_window(parent
);
3692 /* Map siblings next. */
3693 TAILQ_FOREACH_SAFE(w
, &ws
->stack
, stack_entry
,
3695 if (w
!= win
&& !ICONIC(w
) &&
3696 w
->transient
== parent
->id
) {
3702 /* Map focused window. */
3706 /* Stack any children of focus window. */
3707 TAILQ_FOREACH_SAFE(w
, &ws
->stack
, stack_entry
, tmpw
)
3708 if (w
->transient
== win
->id
&& !ICONIC(w
)) {
3712 } else if (tile_gap
< 0 && !ABOVE(win
)) {
3714 * Windows overlap in the layout.
3715 * Raise focused win above all tiled wins.
3723 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->s
->root
,
3724 ewmh
[_NET_ACTIVE_WINDOW
].atom
, XCB_ATOM_WINDOW
, 32, 1,
3729 /* Update window border even if workspace is hidden. */
3730 update_window_color(win
);
3735 DNPRINTF(SWM_D_FOCUS
, "focus_win: done.\n");
3738 /* If a child window should have focus instead, return it. */
3740 get_focus_magic(struct ws_win
*win
)
3742 struct ws_win
*parent
= NULL
;
3743 struct ws_win
*child
= NULL
;
3745 DNPRINTF(SWM_D_FOCUS
, "get_focus_magic: win %#x\n", WINID(win
));
3750 parent
= find_window(win
->transient
);
3752 /* If parent prefers focus elsewhere, then try to do so. */
3753 if (parent
&& (child
= parent
->focus_child
)) {
3754 if (validate_win(child
) == 0 && child
->mapped
)
3757 parent
->focus_child
= NULL
;
3761 /* If this window prefers focus elsewhere, then try to do so. */
3762 if ((child
= win
->focus_child
)) {
3763 if (validate_win(child
) == 0 && child
->mapped
)
3766 win
->focus_child
= NULL
;
3773 event_drain(uint8_t rt
)
3775 xcb_generic_event_t
*evt
;
3777 /* ensure all pending requests have been processed before filtering. */
3779 while ((evt
= xcb_poll_for_event(conn
))) {
3780 if (XCB_EVENT_RESPONSE_TYPE(evt
) != rt
)
3788 set_region(struct swm_region
*r
)
3790 struct swm_region
*rf
;
3797 /* Unfocus old region bar. */
3802 xcb_change_window_attributes(conn
, rf
->bar
->id
,
3803 XCB_CW_BORDER_PIXEL
,
3804 &r
->s
->c
[SWM_S_COLOR_BAR_BORDER_UNFOCUS
].pixel
);
3807 if (rf
!= NULL
&& rf
!= r
&& (X(rf
) != X(r
) || Y(rf
) != Y(r
) ||
3808 WIDTH(rf
) != WIDTH(r
) || HEIGHT(rf
) != HEIGHT(r
))) {
3809 /* Set _NET_DESKTOP_GEOMETRY. */
3811 vals
[1] = HEIGHT(r
);
3812 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, r
->s
->root
,
3813 ewmh
[_NET_DESKTOP_GEOMETRY
].atom
, XCB_ATOM_CARDINAL
, 32, 2,
3817 /* Set region bar border to focus_color. */
3818 xcb_change_window_attributes(conn
, r
->bar
->id
,
3819 XCB_CW_BORDER_PIXEL
, &r
->s
->c
[SWM_S_COLOR_BAR_BORDER
].pixel
);
3823 ewmh_update_current_desktop();
3827 focus_region(struct swm_region
*r
)
3830 struct swm_region
*old_r
;
3835 old_r
= r
->s
->r_focus
;
3838 nfw
= get_region_focus(r
);
3842 /* New region is empty; need to manually unfocus win. */
3844 unfocus_win(old_r
->ws
->focus
);
3846 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
, r
->id
,
3849 /* Clear bar since empty. */
3855 switchws(struct swm_region
*r
, union arg
*args
)
3857 struct swm_region
*this_r
, *other_r
;
3859 struct workspace
*new_ws
, *old_ws
;
3860 xcb_window_t none
= XCB_WINDOW_NONE
;
3861 int wsid
= args
->id
;
3862 bool unmap_old
= false;
3867 if (wsid
>= workspace_limit
)
3871 old_ws
= this_r
->ws
;
3872 new_ws
= &this_r
->s
->ws
[wsid
];
3874 DNPRINTF(SWM_D_WS
, "switchws: screen[%d]:%dx%d+%d+%d: %d -> %d\n",
3875 r
->s
->idx
, WIDTH(r
), HEIGHT(r
), X(r
), Y(r
), old_ws
->idx
, wsid
);
3877 if (new_ws
== NULL
|| old_ws
== NULL
)
3879 if (new_ws
== old_ws
)
3882 if ((win
= old_ws
->focus
) != NULL
) {
3883 update_window_color(win
);
3885 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->s
->root
,
3886 ewmh
[_NET_ACTIVE_WINDOW
].atom
, XCB_ATOM_WINDOW
, 32, 1,
3890 other_r
= new_ws
->r
;
3891 if (other_r
== NULL
) {
3892 /* the other workspace is hidden, hide this one */
3896 /* the other ws is visible in another region, exchange them */
3897 other_r
->ws_prior
= new_ws
;
3898 other_r
->ws
= old_ws
;
3899 old_ws
->r
= other_r
;
3901 this_r
->ws_prior
= old_ws
;
3902 this_r
->ws
= new_ws
;
3905 /* Set focus_pending before stacking, if needed. */
3906 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& (!new_ws
->focus_pending
||
3907 validate_win(new_ws
->focus_pending
))) {
3908 new_ws
->focus_pending
= get_region_focus(new_ws
->r
);
3909 new_ws
->focus
= new_ws
->focus_prev
;
3910 new_ws
->focus_prev
= NULL
;
3913 new_ws
->state
= SWM_WS_STATE_MAPPING
;
3916 /* unmap old windows */
3918 TAILQ_FOREACH(win
, &old_ws
->winlist
, entry
)
3920 old_ws
->state
= SWM_WS_STATE_HIDDEN
;
3923 /* if workspaces were swapped, then don't wait to set focus */
3924 if (old_ws
->r
&& focus_mode
!= SWM_FOCUS_FOLLOW
) {
3925 if (new_ws
->focus_pending
) {
3926 focus_win(new_ws
->focus_pending
);
3927 new_ws
->focus_pending
= NULL
;
3931 /* Clear bar and set focus on region input win if new ws is empty. */
3932 if (new_ws
->focus_pending
== NULL
&& new_ws
->focus
== NULL
) {
3933 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
, r
->id
,
3938 ewmh_update_current_desktop();
3942 new_ws
->state
= SWM_WS_STATE_MAPPED
;
3944 DNPRINTF(SWM_D_WS
, "switchws: done.\n");
3948 cyclews(struct swm_region
*r
, union arg
*args
)
3951 struct swm_screen
*s
= r
->s
;
3952 bool cycle_all
= false, mv
= false;
3954 DNPRINTF(SWM_D_WS
, "cyclews: id: %d, screen[%d]:%dx%d+%d+%d, ws: %d\n",
3955 args
->id
, r
->s
->idx
, WIDTH(r
), HEIGHT(r
), X(r
), Y(r
), r
->ws
->idx
);
3961 case SWM_ARG_ID_CYCLEWS_MOVE_UP
:
3964 case SWM_ARG_ID_CYCLEWS_UP_ALL
:
3967 case SWM_ARG_ID_CYCLEWS_UP
:
3968 a
.id
= (a
.id
< workspace_limit
- 1) ? a
.id
+ 1 : 0;
3970 case SWM_ARG_ID_CYCLEWS_MOVE_DOWN
:
3973 case SWM_ARG_ID_CYCLEWS_DOWN_ALL
:
3976 case SWM_ARG_ID_CYCLEWS_DOWN
:
3977 a
.id
= (a
.id
> 0) ? a
.id
- 1 : workspace_limit
- 1;
3984 (!cycle_empty
&& TAILQ_EMPTY(&s
->ws
[a
.id
].winlist
)))
3986 if (!cycle_visible
&& s
->ws
[a
.id
].r
!= NULL
)
3993 } while (a
.id
!= r
->ws
->idx
);
3995 DNPRINTF(SWM_D_FOCUS
, "cyclews: done\n");
3999 priorws(struct swm_region
*r
, union arg
*args
)
4005 DNPRINTF(SWM_D_WS
, "priorws: id: %d, screen[%d]:%dx%d+%d+%d, ws: %d\n",
4006 args
->id
, r
->s
->idx
, WIDTH(r
), HEIGHT(r
), X(r
), Y(r
), r
->ws
->idx
);
4008 if (r
->ws_prior
== NULL
)
4011 a
.id
= r
->ws_prior
->idx
;
4013 DNPRINTF(SWM_D_FOCUS
, "priorws: done\n");
4017 focusrg(struct swm_region
*r
, union arg
*args
)
4019 int ridx
= args
->id
, i
, num_screens
;
4020 struct swm_region
*rr
= NULL
;
4022 num_screens
= get_screen_count();
4023 /* do nothing if we don't have more than one screen */
4024 if (!(num_screens
> 1 || outputs
> 1))
4027 DNPRINTF(SWM_D_FOCUS
, "focusrg: id: %d\n", ridx
);
4029 rr
= TAILQ_FIRST(&r
->s
->rl
);
4030 for (i
= 0; i
< ridx
&& rr
!= NULL
; ++i
)
4031 rr
= TAILQ_NEXT(rr
, entry
);
4039 DNPRINTF(SWM_D_FOCUS
, "focusrg: done\n");
4043 cyclerg(struct swm_region
*r
, union arg
*args
)
4045 struct swm_region
*rr
= NULL
;
4048 num_screens
= get_screen_count();
4049 /* do nothing if we don't have more than one screen */
4050 if (!(num_screens
> 1 || outputs
> 1))
4054 DNPRINTF(SWM_D_FOCUS
, "cyclerg: id: %d, region: %d\n", args
->id
, i
);
4057 case SWM_ARG_ID_CYCLERG_UP
:
4058 rr
= TAILQ_NEXT(r
, entry
);
4060 rr
= TAILQ_FIRST(&screens
[i
].rl
);
4062 case SWM_ARG_ID_CYCLERG_DOWN
:
4063 rr
= TAILQ_PREV(r
, swm_region_list
, entry
);
4065 rr
= TAILQ_LAST(&screens
[i
].rl
, swm_region_list
);
4076 DNPRINTF(SWM_D_FOCUS
, "cyclerg: done\n");
4079 /* Sorts transients after parent. */
4081 sort_windows(struct ws_win_list
*wl
)
4083 struct ws_win
*win
, *parent
, *nxt
;
4088 for (win
= TAILQ_FIRST(wl
); win
!= TAILQ_END(wl
); win
= nxt
) {
4089 nxt
= TAILQ_NEXT(win
, entry
);
4091 parent
= find_window(win
->transient
);
4092 if (parent
== NULL
) {
4093 warnx("not possible bug");
4096 TAILQ_REMOVE(wl
, win
, entry
);
4097 TAILQ_INSERT_AFTER(wl
, parent
, win
, entry
);
4103 swapwin(struct swm_region
*r
, union arg
*args
)
4105 struct ws_win
*target
, *source
;
4106 struct ws_win
*cur_focus
;
4107 struct ws_win_list
*wl
;
4109 DNPRINTF(SWM_D_WS
, "swapwin: id: %d, screen[%d]:%dx%d+%d+%d, ws: %d\n",
4110 args
->id
, r
->s
->idx
, WIDTH(r
), HEIGHT(r
), X(r
), Y(r
), r
->ws
->idx
);
4112 cur_focus
= r
->ws
->focus
;
4113 if (cur_focus
== NULL
|| FULLSCREEN(cur_focus
))
4116 /* Adjust stacking in floating layer. */
4117 if (ABOVE(cur_focus
)) {
4119 case SWM_ARG_ID_SWAPPREV
:
4120 target
= TAILQ_PREV(cur_focus
, ws_win_stack
,
4122 if (target
!= NULL
&& FLOATING(target
)) {
4123 TAILQ_REMOVE(&cur_focus
->ws
->stack
, cur_focus
,
4125 TAILQ_INSERT_BEFORE(target
, cur_focus
,
4127 update_win_stacking(cur_focus
);
4131 case SWM_ARG_ID_SWAPNEXT
:
4132 target
= TAILQ_NEXT(cur_focus
, stack_entry
);
4133 if (target
!= NULL
&& FLOATING(target
)) {
4134 TAILQ_REMOVE(&cur_focus
->ws
->stack
, cur_focus
,
4136 TAILQ_INSERT_AFTER(&cur_focus
->ws
->stack
,
4137 target
, cur_focus
, stack_entry
);
4138 update_win_stacking(cur_focus
);
4146 if (r
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
4149 clear_maximized(r
->ws
);
4152 wl
= &source
->ws
->winlist
;
4155 case SWM_ARG_ID_SWAPPREV
:
4157 source
= find_window(source
->transient
);
4158 target
= TAILQ_PREV(source
, ws_win_list
, entry
);
4159 if (target
&& target
->transient
)
4160 target
= find_window(target
->transient
);
4161 TAILQ_REMOVE(wl
, source
, entry
);
4163 TAILQ_INSERT_TAIL(wl
, source
, entry
);
4165 TAILQ_INSERT_BEFORE(target
, source
, entry
);
4167 case SWM_ARG_ID_SWAPNEXT
:
4168 target
= TAILQ_NEXT(source
, entry
);
4169 /* move the parent and let the sort handle the move */
4171 source
= find_window(source
->transient
);
4172 TAILQ_REMOVE(wl
, source
, entry
);
4174 TAILQ_INSERT_HEAD(wl
, source
, entry
);
4176 TAILQ_INSERT_AFTER(wl
, target
, source
, entry
);
4178 case SWM_ARG_ID_SWAPMAIN
:
4179 target
= TAILQ_FIRST(wl
);
4180 if (target
== source
) {
4181 if (source
->ws
->focus_prev
!= NULL
&&
4182 source
->ws
->focus_prev
!= target
)
4183 source
= source
->ws
->focus_prev
;
4187 if (target
== NULL
|| source
== NULL
)
4189 source
->ws
->focus_prev
= target
;
4190 TAILQ_REMOVE(wl
, target
, entry
);
4191 TAILQ_INSERT_BEFORE(source
, target
, entry
);
4192 TAILQ_REMOVE(wl
, source
, entry
);
4193 TAILQ_INSERT_HEAD(wl
, source
, entry
);
4195 case SWM_ARG_ID_MOVELAST
:
4196 TAILQ_REMOVE(wl
, source
, entry
);
4197 TAILQ_INSERT_TAIL(wl
, source
, entry
);
4200 DNPRINTF(SWM_D_MOVE
, "swapwin: invalid id: %d\n", args
->id
);
4205 ewmh_update_client_list();
4211 DNPRINTF(SWM_D_MOVE
, "swapwin: done\n");
4215 get_focus_prev(struct ws_win
*win
)
4217 struct ws_win
*winfocus
= NULL
;
4218 struct ws_win
*cur_focus
= NULL
;
4219 struct ws_win_list
*wl
= NULL
;
4220 struct workspace
*ws
= NULL
;
4222 if (!(win
&& win
->ws
))
4227 cur_focus
= ws
->focus
;
4229 DNPRINTF(SWM_D_FOCUS
, "get_focus_prev: win %#x, cur_focus: %#x, "
4230 "focus_prev: %#x\n", WINID(win
), WINID(cur_focus
),
4231 WINID(ws
->focus_prev
));
4233 /* pickle, just focus on whatever */
4234 if (cur_focus
== NULL
) {
4235 /* use prev_focus if valid */
4236 if (ws
->focus_prev
&& find_window(ws
->focus_prev
->id
))
4237 winfocus
= ws
->focus_prev
;
4241 /* if transient focus on parent */
4242 if (TRANS(cur_focus
)) {
4243 winfocus
= find_window(cur_focus
->transient
);
4247 /* if in max_stack try harder */
4248 if ((win
->quirks
& SWM_Q_FOCUSPREV
) ||
4249 (ws
->cur_layout
->flags
& SWM_L_FOCUSPREV
)) {
4250 if (cur_focus
!= ws
->focus_prev
)
4251 winfocus
= ws
->focus_prev
;
4253 winfocus
= TAILQ_PREV(win
, ws_win_list
, entry
);
4258 DNPRINTF(SWM_D_FOCUS
, "get_focus_prev: focus_close: %d\n", focus_close
);
4260 if (winfocus
== NULL
|| winfocus
== win
) {
4261 switch (focus_close
) {
4262 case SWM_STACK_BOTTOM
:
4263 TAILQ_FOREACH(winfocus
, wl
, entry
)
4264 if (!ICONIC(winfocus
) && winfocus
!= cur_focus
)
4268 TAILQ_FOREACH_REVERSE(winfocus
, wl
, ws_win_list
, entry
)
4269 if (!ICONIC(winfocus
) && winfocus
!= cur_focus
)
4272 case SWM_STACK_ABOVE
:
4273 winfocus
= TAILQ_NEXT(cur_focus
, entry
);
4274 while (winfocus
&& ICONIC(winfocus
))
4275 winfocus
= TAILQ_NEXT(winfocus
, entry
);
4277 if (winfocus
== NULL
) {
4278 if (focus_close_wrap
) {
4279 TAILQ_FOREACH(winfocus
, wl
, entry
)
4280 if (!ICONIC(winfocus
) &&
4281 winfocus
!= cur_focus
)
4284 TAILQ_FOREACH_REVERSE(winfocus
, wl
,
4286 if (!ICONIC(winfocus
) &&
4287 winfocus
!= cur_focus
)
4292 case SWM_STACK_BELOW
:
4293 winfocus
= TAILQ_PREV(cur_focus
, ws_win_list
, entry
);
4294 while (winfocus
&& ICONIC(winfocus
))
4295 winfocus
= TAILQ_PREV(winfocus
, ws_win_list
,
4298 if (winfocus
== NULL
) {
4299 if (focus_close_wrap
) {
4300 TAILQ_FOREACH_REVERSE(winfocus
, wl
,
4302 if (!ICONIC(winfocus
) &&
4303 winfocus
!= cur_focus
)
4306 TAILQ_FOREACH(winfocus
, wl
, entry
)
4307 if (!ICONIC(winfocus
) &&
4308 winfocus
!= cur_focus
)
4316 if (winfocus
== NULL
||
4317 (winfocus
&& (ICONIC(winfocus
) || winfocus
== cur_focus
))) {
4318 if (focus_default
== SWM_STACK_TOP
) {
4319 TAILQ_FOREACH_REVERSE(winfocus
, wl
, ws_win_list
, entry
)
4320 if (!ICONIC(winfocus
) && winfocus
!= cur_focus
)
4323 TAILQ_FOREACH(winfocus
, wl
, entry
)
4324 if (!ICONIC(winfocus
) && winfocus
!= cur_focus
)
4331 return get_focus_magic(winfocus
);
4335 get_region_focus(struct swm_region
*r
)
4337 struct ws_win
*winfocus
= NULL
;
4342 if (r
->ws
->focus
&& !ICONIC(r
->ws
->focus
))
4343 winfocus
= r
->ws
->focus
;
4344 else if (r
->ws
->focus_prev
&& !ICONIC(r
->ws
->focus_prev
))
4345 winfocus
= r
->ws
->focus_prev
;
4347 TAILQ_FOREACH(winfocus
, &r
->ws
->winlist
, entry
)
4348 if (!ICONIC(winfocus
))
4351 return get_focus_magic(winfocus
);
4355 focus(struct swm_region
*r
, union arg
*args
)
4357 struct ws_win
*head
, *cur_focus
= NULL
, *winfocus
= NULL
;
4358 struct ws_win_list
*wl
= NULL
;
4359 struct workspace
*ws
= NULL
;
4366 cur_focus
= r
->ws
->focus
;
4370 DNPRINTF(SWM_D_FOCUS
, "focus: id: %d, cur_focus: %#x\n", args
->id
,
4373 /* Make sure an uniconified window has focus, if one exists. */
4374 if (cur_focus
== NULL
) {
4375 cur_focus
= TAILQ_FIRST(wl
);
4376 while (cur_focus
!= NULL
&& ICONIC(cur_focus
))
4377 cur_focus
= TAILQ_NEXT(cur_focus
, entry
);
4379 DNPRINTF(SWM_D_FOCUS
, "focus: new cur_focus: %#x\n",
4384 case SWM_ARG_ID_FOCUSPREV
:
4385 if (cur_focus
== NULL
)
4388 winfocus
= cur_focus
;
4390 winfocus
= TAILQ_PREV(winfocus
, ws_win_list
, entry
);
4391 if (winfocus
== NULL
)
4392 winfocus
= TAILQ_LAST(wl
, ws_win_list
);
4393 if (winfocus
== cur_focus
)
4395 } while (winfocus
&& (ICONIC(winfocus
) ||
4396 winfocus
->id
== cur_focus
->transient
||
4397 (cur_focus
->transient
!= XCB_WINDOW_NONE
&&
4398 winfocus
->transient
== cur_focus
->transient
)));
4400 case SWM_ARG_ID_FOCUSNEXT
:
4401 if (cur_focus
== NULL
)
4404 winfocus
= cur_focus
;
4406 winfocus
= TAILQ_NEXT(winfocus
, entry
);
4407 if (winfocus
== NULL
)
4408 winfocus
= TAILQ_FIRST(wl
);
4409 if (winfocus
== cur_focus
)
4411 } while (winfocus
&& (ICONIC(winfocus
) ||
4412 winfocus
->id
== cur_focus
->transient
||
4413 (cur_focus
->transient
!= XCB_WINDOW_NONE
&&
4414 winfocus
->transient
== cur_focus
->transient
)));
4416 case SWM_ARG_ID_FOCUSMAIN
:
4417 if (cur_focus
== NULL
)
4420 winfocus
= TAILQ_FIRST(wl
);
4421 if (winfocus
== cur_focus
)
4422 winfocus
= cur_focus
->ws
->focus_prev
;
4424 case SWM_ARG_ID_FOCUSURGENT
:
4425 /* Search forward for the next urgent window. */
4429 for (i
= 0; i
<= workspace_limit
; ++i
) {
4431 head
= TAILQ_FIRST(&r
->s
->ws
[(ws
->idx
+ i
) %
4432 workspace_limit
].winlist
);
4435 if (head
== cur_focus
) {
4437 winfocus
= cur_focus
;
4440 } else if (get_urgent(head
)) {
4445 head
= TAILQ_NEXT(head
, entry
);
4452 /* Switch ws if new focus is on a different ws. */
4453 if (winfocus
&& winfocus
->ws
!= ws
) {
4454 a
.id
= winfocus
->ws
->idx
;
4462 if (clear_maximized(ws
) > 0)
4465 focus_win(get_focus_magic(winfocus
));
4470 DNPRINTF(SWM_D_FOCUS
, "focus: done\n");
4474 cycle_layout(struct swm_region
*r
, union arg
*args
)
4476 struct workspace
*ws
= r
->ws
;
4478 /* suppress unused warning since var is needed */
4481 DNPRINTF(SWM_D_EVENT
, "cycle_layout: workspace: %d\n", ws
->idx
);
4484 if (ws
->cur_layout
->l_stack
== NULL
)
4485 ws
->cur_layout
= &layouts
[0];
4487 clear_maximized(ws
);
4492 focus_win(get_region_focus(r
));
4499 stack_config(struct swm_region
*r
, union arg
*args
)
4501 struct workspace
*ws
= r
->ws
;
4503 DNPRINTF(SWM_D_STACK
, "stack_config: id: %d workspace: %d\n",
4506 if (clear_maximized(ws
) > 0)
4509 if (ws
->cur_layout
->l_config
!= NULL
)
4510 ws
->cur_layout
->l_config(ws
, args
->id
);
4512 if (args
->id
!= SWM_ARG_ID_STACKINIT
)
4522 struct swm_geometry g
;
4523 struct swm_region
*r
, *r_prev
= NULL
;
4530 DNPRINTF(SWM_D_STACK
, "stack: begin\n");
4532 num_screens
= get_screen_count();
4533 for (i
= 0; i
< num_screens
; i
++) {
4537 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
) {
4538 /* Adjust stack area for region bar and padding. */
4540 g
.x
+= region_padding
;
4541 g
.y
+= region_padding
;
4542 g
.w
-= 2 * border_width
+ 2 * region_padding
;
4543 g
.h
-= 2 * border_width
+ 2 * region_padding
;
4544 if (bar_enabled
&& r
->ws
->bar_enabled
) {
4550 DNPRINTF(SWM_D_STACK
, "stack: workspace: %d (screen: "
4551 "%d, region: %d), (x,y) WxH: (%d,%d) %d x %d\n",
4552 r
->ws
->idx
, i
, j
++, g
.x
, g
.y
, g
.w
, g
.h
);
4555 /* Stack bar/input relative to prev. region. */
4556 val
[1] = XCB_STACK_MODE_ABOVE
;
4558 val
[0] = r_prev
->id
;
4559 DNPRINTF(SWM_D_STACK
, "stack: region input %#x "
4560 "relative to %#x.\n", r
->id
, val
[0]);
4561 xcb_configure_window(conn
, r
->id
,
4562 XCB_CONFIG_WINDOW_SIBLING
|
4563 XCB_CONFIG_WINDOW_STACK_MODE
, val
);
4565 val
[0] = r_prev
->bar
->id
;
4566 DNPRINTF(SWM_D_STACK
, "stack: region bar %#x "
4567 "relative to %#x.\n", r
->bar
->id
, val
[0]);
4568 xcb_configure_window(conn
, r
->bar
->id
,
4569 XCB_CONFIG_WINDOW_SIBLING
|
4570 XCB_CONFIG_WINDOW_STACK_MODE
, val
);
4573 r
->ws
->cur_layout
->l_stack(r
->ws
, &g
);
4574 r
->ws
->cur_layout
->l_string(r
->ws
);
4575 /* save r so we can track region changes */
4583 DNPRINTF(SWM_D_STACK
, "stack: end\n");
4587 store_float_geom(struct ws_win
*win
)
4589 if (win
== NULL
|| win
->ws
->r
== NULL
)
4592 /* retain window geom and region geom */
4593 win
->g_float
= win
->g
;
4594 win
->g_float
.x
-= X(win
->ws
->r
);
4595 win
->g_float
.y
-= Y(win
->ws
->r
);
4596 win
->g_floatvalid
= true;
4597 DNPRINTF(SWM_D_MISC
, "store_float_geom: win %#x, g: (%d,%d)"
4598 " %d x %d, g_float: (%d,%d) %d x %d\n", win
->id
, X(win
), Y(win
),
4599 WIDTH(win
), HEIGHT(win
), win
->g_float
.x
, win
->g_float
.y
,
4600 win
->g_float
.w
, win
->g_float
.h
);
4604 load_float_geom(struct ws_win
*win
)
4606 if (win
== NULL
|| win
->ws
->r
== NULL
)
4609 if (win
->g_floatvalid
) {
4610 win
->g
= win
->g_float
;
4611 X(win
) += X(win
->ws
->r
);
4612 Y(win
) += Y(win
->ws
->r
);
4613 DNPRINTF(SWM_D_MISC
, "load_float_geom: win %#x, g: (%d,%d)"
4614 "%d x %d\n", win
->id
, X(win
), Y(win
), WIDTH(win
),
4617 DNPRINTF(SWM_D_MISC
, "load_float_geom: win %#x, g_float "
4618 "is not set.\n", win
->id
);
4623 update_floater(struct ws_win
*win
)
4625 struct workspace
*ws
;
4626 struct swm_region
*r
;
4633 if ((r
= ws
->r
) == NULL
)
4636 DNPRINTF(SWM_D_MISC
, "update_floater: win %#x\n", win
->id
);
4638 win
->bordered
= true;
4640 if (FULLSCREEN(win
)) {
4641 /* _NET_WM_FULLSCREEN: fullscreen without border. */
4642 if (!win
->g_floatvalid
)
4643 store_float_geom(win
);
4646 win
->bordered
= false;
4647 } else if (MAXIMIZED(win
)) {
4648 /* Maximize: like a single stacked window. */
4649 if (!win
->g_floatvalid
)
4650 store_float_geom(win
);
4654 if (bar_enabled
&& ws
->bar_enabled
) {
4656 Y(win
) += bar_height
;
4657 HEIGHT(win
) -= bar_height
;
4658 } else if (disable_border
) {
4659 win
->bordered
= false;
4662 if (win
->bordered
) {
4663 HEIGHT(win
) -= 2 * border_width
;
4664 WIDTH(win
) -= 2 * border_width
;
4667 /* Normal floating window. */
4668 /* Update geometry if new region. */
4670 load_float_geom(win
);
4672 if ((win
->quirks
& SWM_Q_FULLSCREEN
) &&
4673 WIDTH(win
) >= WIDTH(r
) && HEIGHT(win
) >= HEIGHT(r
)) {
4674 /* Remove border for FULLSCREEN quirk. */
4675 win
->bordered
= false;
4676 } else if (!MANUAL(win
)) {
4677 if (TRANS(win
) && (win
->quirks
& SWM_Q_TRANSSZ
)) {
4678 /* Adjust size on TRANSSZ quirk. */
4679 WIDTH(win
) = (double)WIDTH(r
) * dialog_ratio
;
4680 HEIGHT(win
) = (double)HEIGHT(r
) * dialog_ratio
;
4683 if (!(win
->quirks
& SWM_Q_ANYWHERE
)) {
4685 * Floaters and transients are auto-centred
4686 * unless manually moved, resized or ANYWHERE
4689 X(win
) = X(r
) + (WIDTH(r
) - WIDTH(win
)) / 2 -
4691 Y(win
) = Y(r
) + (HEIGHT(r
) - HEIGHT(win
)) / 2 -
4693 store_float_geom(win
);
4698 /* Ensure at least 1 pixel of the window is in the region. */
4699 region_containment(win
, r
, SWM_CW_ALLSIDES
);
4705 * Send keystrokes to terminal to decrease/increase the font size as the
4706 * window size changes.
4709 adjust_font(struct ws_win
*win
)
4711 if (!(win
->quirks
& SWM_Q_XTERM_FONTADJ
) ||
4712 ABOVE(win
) || TRANS(win
))
4715 if (win
->sh
.width_inc
&& win
->last_inc
!= win
->sh
.width_inc
&&
4716 WIDTH(win
) / win
->sh
.width_inc
< term_width
&&
4717 win
->font_steps
< SWM_MAX_FONT_STEPS
) {
4718 win
->font_size_boundary
[win
->font_steps
] =
4719 (win
->sh
.width_inc
* term_width
) + win
->sh
.base_width
;
4722 win
->last_inc
= win
->sh
.width_inc
;
4723 fake_keypress(win
, XK_KP_Subtract
, XCB_MOD_MASK_SHIFT
);
4724 } else if (win
->font_steps
&& win
->last_inc
!= win
->sh
.width_inc
&&
4725 WIDTH(win
) > win
->font_size_boundary
[win
->font_steps
- 1]) {
4728 win
->last_inc
= win
->sh
.width_inc
;
4729 fake_keypress(win
, XK_KP_Add
, XCB_MOD_MASK_SHIFT
);
4733 #define SWAPXY(g) do { \
4735 tmp = (g)->y; (g)->y = (g)->x; (g)->x = tmp; \
4736 tmp = (g)->h; (g)->h = (g)->w; (g)->w = tmp; \
4739 stack_master(struct workspace
*ws
, struct swm_geometry
*g
, int rot
, bool flip
)
4741 struct swm_geometry win_g
, r_g
= *g
;
4743 int i
, j
, s
, stacks
;
4744 int w_inc
= 1, h_inc
, w_base
= 1, h_base
;
4745 int hrh
, extra
= 0, h_slice
, last_h
= 0;
4746 int split
, colno
, winno
, mwin
, msize
, mscale
;
4747 int remain
, missing
, v_slice
;
4748 bool bordered
= true, reconfigure
= false;
4750 DNPRINTF(SWM_D_STACK
, "stack_master: workspace: %d, rot: %s, "
4751 "flip: %s\n", ws
->idx
, YESNO(rot
), YESNO(flip
));
4753 /* Prepare tiling variables, if needed. */
4754 if ((winno
= count_win(ws
, false)) > 0) {
4755 /* Find first tiled window. */
4756 TAILQ_FOREACH(win
, &ws
->winlist
, entry
)
4757 if (!FLOATING(win
) && !ICONIC(win
))
4760 /* Take into account size hints of first tiled window. */
4762 w_inc
= win
->sh
.width_inc
;
4763 w_base
= win
->sh
.base_width
;
4764 mwin
= ws
->l_state
.horizontal_mwin
;
4765 mscale
= ws
->l_state
.horizontal_msize
;
4766 stacks
= ws
->l_state
.horizontal_stacks
;
4769 w_inc
= win
->sh
.height_inc
;
4770 w_base
= win
->sh
.base_height
;
4771 mwin
= ws
->l_state
.vertical_mwin
;
4772 mscale
= ws
->l_state
.vertical_msize
;
4773 stacks
= ws
->l_state
.vertical_stacks
;
4777 if (stacks
> winno
- mwin
)
4778 stacks
= winno
- mwin
;
4782 h_slice
= r_g
.h
/ SWM_H_SLICE
;
4783 if (mwin
&& winno
> mwin
) {
4784 v_slice
= r_g
.w
/ SWM_V_SLICE
;
4788 win_g
.w
= v_slice
* mscale
;
4790 if (w_inc
> 1 && w_inc
< v_slice
) {
4791 /* Adjust for requested size increment. */
4792 remain
= (win_g
.w
- w_base
) % w_inc
;
4798 win_g
.x
+= r_g
.w
- msize
;
4801 colno
= split
= winno
/ stacks
;
4802 win_g
.w
= ((r_g
.w
- (stacks
* 2 * border_width
) +
4803 2 * border_width
) / stacks
);
4805 hrh
= r_g
.h
/ colno
;
4806 extra
= r_g
.h
- (colno
* hrh
);
4807 win_g
.h
= hrh
- 2 * border_width
;
4808 i
= j
= 0, s
= stacks
;
4811 /* Update window geometry. */
4812 TAILQ_FOREACH(win
, &ws
->winlist
, entry
) {
4816 if (FLOATING(win
)) {
4817 update_floater(win
);
4822 if (split
&& i
== split
) {
4823 colno
= (winno
- mwin
) / stacks
;
4824 if (s
<= (winno
- mwin
) % stacks
)
4827 hrh
= r_g
.h
/ colno
;
4828 extra
= r_g
.h
- (colno
* hrh
);
4831 win_g
.x
+= win_g
.w
+ 2 * border_width
+
4834 win_g
.w
= (r_g
.w
- msize
-
4835 (stacks
* (2 * border_width
+ tile_gap
))) / stacks
;
4837 win_g
.w
+= (r_g
.w
- msize
-
4838 (stacks
* (2 * border_width
+ tile_gap
))) %
4842 win_g
.x
-= win_g
.w
+ 2 * border_width
+
4848 win_g
.h
= hrh
- 2 * border_width
- tile_gap
;
4851 h_inc
= win
->sh
.width_inc
;
4852 h_base
= win
->sh
.base_width
;
4854 h_inc
= win
->sh
.height_inc
;
4855 h_base
= win
->sh
.base_height
;
4858 if (j
== colno
- 1) {
4859 win_g
.h
= hrh
+ extra
;
4860 } else if (h_inc
> 1 && h_inc
< h_slice
) {
4861 /* adjust for window's requested size increment */
4862 remain
= (win_g
.h
- h_base
) % h_inc
;
4863 missing
= h_inc
- remain
;
4865 if (missing
<= extra
|| j
== 0) {
4877 win_g
.y
+= last_h
+ 2 * border_width
+ tile_gap
;
4879 if (disable_border
&& !(bar_enabled
&& ws
->bar_enabled
) &&
4882 win_g
.w
+= 2 * border_width
;
4883 win_g
.h
+= 2 * border_width
;
4889 if (X(win
) != win_g
.y
|| Y(win
) != win_g
.x
||
4890 WIDTH(win
) != win_g
.h
|| HEIGHT(win
) != win_g
.w
) {
4894 WIDTH(win
) = win_g
.h
;
4895 HEIGHT(win
) = win_g
.w
;
4898 if (X(win
) != win_g
.x
|| Y(win
) != win_g
.y
||
4899 WIDTH(win
) != win_g
.w
|| HEIGHT(win
) != win_g
.h
) {
4903 WIDTH(win
) = win_g
.w
;
4904 HEIGHT(win
) = win_g
.h
;
4908 if (bordered
!= win
->bordered
) {
4910 win
->bordered
= bordered
;
4923 /* Stack all windows from bottom up. */
4924 TAILQ_FOREACH_REVERSE(win
, &ws
->stack
, ws_win_stack
, stack_entry
)
4926 update_win_stacking(win
);
4928 /* Map all windows from top down. */
4929 TAILQ_FOREACH(win
, &ws
->stack
, stack_entry
)
4933 DNPRINTF(SWM_D_STACK
, "stack_master: done\n");
4937 vertical_config(struct workspace
*ws
, int id
)
4939 DNPRINTF(SWM_D_STACK
, "vertical_config: id: %d, workspace: %d\n",
4943 case SWM_ARG_ID_STACKRESET
:
4944 case SWM_ARG_ID_STACKINIT
:
4945 ws
->l_state
.vertical_msize
= SWM_V_SLICE
/ 2;
4946 ws
->l_state
.vertical_mwin
= 1;
4947 ws
->l_state
.vertical_stacks
= 1;
4949 case SWM_ARG_ID_STACKBALANCE
:
4950 ws
->l_state
.vertical_msize
= SWM_V_SLICE
/ (ws
->l_state
.vertical_stacks
+ 1);
4952 case SWM_ARG_ID_MASTERSHRINK
:
4953 if (ws
->l_state
.vertical_msize
> 1)
4954 ws
->l_state
.vertical_msize
--;
4956 case SWM_ARG_ID_MASTERGROW
:
4957 if (ws
->l_state
.vertical_msize
< SWM_V_SLICE
- 1)
4958 ws
->l_state
.vertical_msize
++;
4960 case SWM_ARG_ID_MASTERADD
:
4961 ws
->l_state
.vertical_mwin
++;
4963 case SWM_ARG_ID_MASTERDEL
:
4964 if (ws
->l_state
.vertical_mwin
> 0)
4965 ws
->l_state
.vertical_mwin
--;
4967 case SWM_ARG_ID_STACKINC
:
4968 ws
->l_state
.vertical_stacks
++;
4970 case SWM_ARG_ID_STACKDEC
:
4971 if (ws
->l_state
.vertical_stacks
> 1)
4972 ws
->l_state
.vertical_stacks
--;
4974 case SWM_ARG_ID_FLIPLAYOUT
:
4975 ws
->l_state
.vertical_flip
= !ws
->l_state
.vertical_flip
;
4983 vertical_stack(struct workspace
*ws
, struct swm_geometry
*g
)
4985 DNPRINTF(SWM_D_STACK
, "vertical_stack: workspace: %d\n", ws
->idx
);
4987 stack_master(ws
, g
, 0, ws
->l_state
.vertical_flip
);
4991 horizontal_config(struct workspace
*ws
, int id
)
4993 DNPRINTF(SWM_D_STACK
, "horizontal_config: workspace: %d\n", ws
->idx
);
4996 case SWM_ARG_ID_STACKRESET
:
4997 case SWM_ARG_ID_STACKINIT
:
4998 ws
->l_state
.horizontal_mwin
= 1;
4999 ws
->l_state
.horizontal_msize
= SWM_H_SLICE
/ 2;
5000 ws
->l_state
.horizontal_stacks
= 1;
5002 case SWM_ARG_ID_STACKBALANCE
:
5003 ws
->l_state
.horizontal_msize
= SWM_H_SLICE
/ (ws
->l_state
.horizontal_stacks
+ 1);
5005 case SWM_ARG_ID_MASTERSHRINK
:
5006 if (ws
->l_state
.horizontal_msize
> 1)
5007 ws
->l_state
.horizontal_msize
--;
5009 case SWM_ARG_ID_MASTERGROW
:
5010 if (ws
->l_state
.horizontal_msize
< SWM_H_SLICE
- 1)
5011 ws
->l_state
.horizontal_msize
++;
5013 case SWM_ARG_ID_MASTERADD
:
5014 ws
->l_state
.horizontal_mwin
++;
5016 case SWM_ARG_ID_MASTERDEL
:
5017 if (ws
->l_state
.horizontal_mwin
> 0)
5018 ws
->l_state
.horizontal_mwin
--;
5020 case SWM_ARG_ID_STACKINC
:
5021 ws
->l_state
.horizontal_stacks
++;
5023 case SWM_ARG_ID_STACKDEC
:
5024 if (ws
->l_state
.horizontal_stacks
> 1)
5025 ws
->l_state
.horizontal_stacks
--;
5027 case SWM_ARG_ID_FLIPLAYOUT
:
5028 ws
->l_state
.horizontal_flip
= !ws
->l_state
.horizontal_flip
;
5036 horizontal_stack(struct workspace
*ws
, struct swm_geometry
*g
)
5038 DNPRINTF(SWM_D_STACK
, "horizontal_stack: workspace: %d\n", ws
->idx
);
5040 stack_master(ws
, g
, 1, ws
->l_state
.horizontal_flip
);
5043 /* fullscreen view */
5045 max_stack(struct workspace
*ws
, struct swm_geometry
*g
)
5047 struct swm_geometry gg
= *g
;
5048 struct ws_win
*w
, *win
= NULL
, *parent
= NULL
, *tmpw
;
5051 DNPRINTF(SWM_D_STACK
, "max_stack: workspace: %d\n", ws
->idx
);
5056 winno
= count_win(ws
, false);
5057 if (winno
== 0 && count_win(ws
, true) == 0)
5060 /* Figure out which top level window should be visible. */
5061 if (ws
->focus_pending
)
5062 win
= ws
->focus_pending
;
5065 else if (ws
->focus_prev
)
5066 win
= ws
->focus_prev
;
5068 win
= TAILQ_FIRST(&ws
->winlist
);
5070 DNPRINTF(SWM_D_STACK
, "max_stack: focus_pending: %#x, focus: %#x, "
5071 "focus_prev: %#x, first: %#x, win: %#x\n", WINID(ws
->focus_pending
),
5072 WINID(ws
->focus
), WINID(ws
->focus_prev
),
5073 WINID(TAILQ_FIRST(&ws
->winlist
)), win
->id
);
5075 /* Update window geometry. */
5076 TAILQ_FOREACH(w
, &ws
->winlist
, entry
) {
5085 /* Set maximized flag for all maxed windows. */
5086 if (!MAXIMIZED(w
)) {
5087 /* Preserve floating geometry. */
5089 store_float_geom(w
);
5091 ewmh_apply_flags(w
, w
->ewmh_flags
| EWMH_F_MAXIMIZED
);
5092 ewmh_update_wm_state(w
);
5095 /* Only reconfigure if necessary. */
5096 if (X(w
) != gg
.x
|| Y(w
) != gg
.y
|| WIDTH(w
) != gg
.w
||
5097 HEIGHT(w
) != gg
.h
) {
5100 if (disable_border
&& !(bar_enabled
&& ws
->bar_enabled
)) {
5101 w
->bordered
= false;
5102 WIDTH(w
) += 2 * border_width
;
5103 HEIGHT(w
) += 2 * border_width
;
5112 /* If transient, stack parent and its children. */
5113 if (TRANS(win
) && (parent
= find_window(win
->transient
))) {
5114 raise_window(parent
);
5116 TAILQ_FOREACH_SAFE(w
, &ws
->stack
, stack_entry
, tmpw
)
5117 if (w
->transient
== parent
->id
)
5121 /* Make sure focus window is on top. */
5124 /* Stack any children of focus window. */
5125 TAILQ_FOREACH_SAFE(w
, &ws
->stack
, stack_entry
, tmpw
)
5126 if (w
->transient
== win
->id
)
5129 /* Map all windows. */
5130 TAILQ_FOREACH(w
, &ws
->stack
, stack_entry
)
5136 send_to_rg(struct swm_region
*r
, union arg
*args
)
5138 int ridx
= args
->id
, i
, num_screens
;
5139 struct swm_region
*rr
= NULL
;
5142 num_screens
= get_screen_count();
5143 /* do nothing if we don't have more than one screen */
5144 if (!(num_screens
> 1 || outputs
> 1))
5147 DNPRINTF(SWM_D_FOCUS
, "send_to_rg: id: %d\n", ridx
);
5149 rr
= TAILQ_FIRST(&r
->s
->rl
);
5150 for (i
= 0; i
< ridx
&& rr
!= NULL
; ++i
)
5151 rr
= TAILQ_NEXT(rr
, entry
);
5162 region_under(struct swm_screen
*s
, int x
, int y
)
5164 struct swm_region
*r
= NULL
;
5166 TAILQ_FOREACH(r
, &s
->rl
, entry
) {
5167 DNPRINTF(SWM_D_MISC
, "region_under: ws: %d, region g: (%d,%d) "
5168 "%d x %d, coords: (%d,%d)\n", r
->ws
->idx
, X(r
), Y(r
),
5169 WIDTH(r
), HEIGHT(r
), x
, y
);
5170 if (X(r
) <= x
&& x
< MAX_X(r
))
5171 if (Y(r
) <= y
&& y
< MAX_Y(r
))
5178 /* Transfer focused window to target workspace and focus. */
5180 send_to_ws(struct swm_region
*r
, union arg
*args
)
5182 int wsid
= args
->id
;
5183 struct ws_win
*win
= NULL
;
5185 if (r
&& r
->ws
&& r
->ws
->focus
)
5190 DNPRINTF(SWM_D_MOVE
, "send_to_ws: win %#x, ws %d\n", win
->id
, wsid
);
5192 if (wsid
< 0 || wsid
>= workspace_limit
)
5195 if (win
->ws
->idx
== wsid
)
5198 win_to_ws(win
, wsid
, true);
5200 /* Set new focus on target ws. */
5201 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
5202 win
->ws
->focus_prev
= win
->ws
->focus
;
5203 win
->ws
->focus
= win
;
5204 win
->ws
->focus_pending
= NULL
;
5206 if (win
->ws
->focus_prev
)
5207 update_window_color(win
->ws
->focus_prev
);
5210 DNPRINTF(SWM_D_STACK
, "send_to_ws: focus_pending: %#x, focus: %#x, "
5211 "focus_prev: %#x, first: %#x, win: %#x\n",
5212 WINID(r
->ws
->focus_pending
), WINID(r
->ws
->focus
),
5213 WINID(r
->ws
->focus_prev
), WINID(TAILQ_FIRST(&r
->ws
->winlist
)),
5216 ewmh_apply_flags(win
, win
->ewmh_flags
& ~EWMH_F_MAXIMIZED
);
5217 ewmh_update_wm_state(win
);
5219 /* Restack and set new focus on current ws. */
5221 load_float_geom(win
);
5225 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
5226 if (r
->ws
->focus
!= NULL
) {
5227 focus_win(r
->ws
->focus
);
5229 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
, r
->id
,
5240 win_to_ws(struct ws_win
*win
, int wsid
, bool unfocus
)
5242 struct ws_win
*parent
;
5243 struct workspace
*ws
, *nws
, *pws
;
5245 if (wsid
< 0 || wsid
>= workspace_limit
)
5248 if (win
->ws
->idx
== wsid
)
5252 nws
= &win
->s
->ws
[wsid
];
5254 DNPRINTF(SWM_D_MOVE
, "win_to_ws: win %#x, ws %d -> %d\n", win
->id
,
5257 /* Cleanup focus on source ws. */
5258 if (focus_mode
!= SWM_FOCUS_FOLLOW
&&
5259 (ws
->focus
== win
|| ws
->focus_pending
== win
))
5260 ws
->focus_pending
= get_focus_prev(win
);
5262 /* Move the parent if this is a transient window. */
5264 parent
= find_window(win
->transient
);
5267 /* Set new focus in parent's ws if needed. */
5268 if (pws
->focus
== parent
) {
5269 if (focus_mode
!= SWM_FOCUS_FOLLOW
)
5270 pws
->focus_pending
=
5271 get_focus_prev(parent
);
5273 unfocus_win(parent
);
5275 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
5276 pws
->focus
= pws
->focus_pending
;
5277 pws
->focus_pending
= NULL
;
5281 /* Don't unmap parent if new ws is visible */
5283 unmap_window(parent
);
5286 TAILQ_REMOVE(&ws
->winlist
, parent
, entry
);
5287 TAILQ_REMOVE(&ws
->stack
, parent
, stack_entry
);
5288 TAILQ_INSERT_TAIL(&nws
->winlist
, parent
, entry
);
5289 TAILQ_INSERT_TAIL(&nws
->stack
, parent
, stack_entry
);
5292 DNPRINTF(SWM_D_PROP
, "win_to_ws: set property: "
5293 "_NET_WM_DESKTOP: %d\n", wsid
);
5294 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5295 parent
->id
, ewmh
[_NET_WM_DESKTOP
].atom
,
5296 XCB_ATOM_CARDINAL
, 32, 1, &wsid
);
5303 if (ws
->focus_prev
== win
)
5304 ws
->focus_prev
= NULL
;
5306 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& ws
->focus_pending
!= NULL
) {
5307 ws
->focus
= ws
->focus_pending
;
5308 ws
->focus_pending
= NULL
;
5311 /* Don't unmap if new ws is visible */
5316 TAILQ_REMOVE(&ws
->winlist
, win
, entry
);
5317 TAILQ_REMOVE(&ws
->stack
, win
, stack_entry
);
5318 TAILQ_INSERT_TAIL(&nws
->winlist
, win
, entry
);
5319 TAILQ_INSERT_TAIL(&nws
->stack
, win
, stack_entry
);
5322 /* Update the window's workspace property: _NET_WM_DESKTOP */
5323 DNPRINTF(SWM_D_PROP
, "win_to_ws: set property: "
5324 "_NET_WM_DESKTOP: %d\n", wsid
);
5325 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
,
5326 ewmh
[_NET_WM_DESKTOP
].atom
, XCB_ATOM_CARDINAL
, 32, 1, &wsid
);
5328 ewmh_update_client_list();
5330 DNPRINTF(SWM_D_MOVE
, "win_to_ws: done.\n");
5334 pressbutton(struct swm_region
*r
, union arg
*args
)
5336 /* suppress unused warning since var is needed */
5339 xcb_test_fake_input(conn
, XCB_BUTTON_PRESS
, args
->id
,
5340 XCB_CURRENT_TIME
, XCB_WINDOW_NONE
, 0, 0, 0);
5341 xcb_test_fake_input(conn
, XCB_BUTTON_RELEASE
, args
->id
,
5342 XCB_CURRENT_TIME
, XCB_WINDOW_NONE
, 0, 0, 0);
5346 raise_toggle(struct swm_region
*r
, union arg
*args
)
5348 /* Suppress warning. */
5351 if (r
== NULL
|| r
->ws
== NULL
)
5354 if (r
->ws
->focus
&& MAXIMIZED(r
->ws
->focus
))
5357 r
->ws
->always_raise
= !r
->ws
->always_raise
;
5359 /* Update focused win stacking order based on new always_raise value. */
5360 raise_window(r
->ws
->focus
);
5366 iconify(struct swm_region
*r
, union arg
*args
)
5370 /* Suppress warning. */
5373 if ((w
= r
->ws
->focus
) == NULL
)
5376 ewmh_apply_flags(w
, w
->ewmh_flags
| EWMH_F_HIDDEN
);
5377 ewmh_update_wm_state(w
);
5385 get_win_name(xcb_window_t win
)
5388 xcb_get_property_cookie_t c
;
5389 xcb_get_property_reply_t
*r
;
5391 /* First try _NET_WM_NAME for UTF-8. */
5392 c
= xcb_get_property(conn
, 0, win
, ewmh
[_NET_WM_NAME
].atom
,
5393 XCB_GET_PROPERTY_TYPE_ANY
, 0, UINT_MAX
);
5394 r
= xcb_get_property_reply(conn
, c
, NULL
);
5395 if (r
&& r
->type
== XCB_NONE
) {
5397 /* Use WM_NAME instead; no UTF-8. */
5398 c
= xcb_get_property(conn
, 0, win
, XCB_ATOM_WM_NAME
,
5399 XCB_GET_PROPERTY_TYPE_ANY
, 0, UINT_MAX
);
5400 r
= xcb_get_property_reply(conn
, c
, NULL
);
5403 if (r
&& r
->type
!= XCB_NONE
&& r
->length
> 0)
5404 name
= strndup(xcb_get_property_value(r
),
5405 xcb_get_property_value_length(r
));
5410 err(1, "get_win_name: failed to allocate memory.");
5418 uniconify(struct swm_region
*r
, union arg
*args
)
5425 DNPRINTF(SWM_D_MISC
, "uniconify\n");
5427 if (r
== NULL
|| r
->ws
== NULL
)
5430 /* make sure we have anything to uniconify */
5431 TAILQ_FOREACH(win
, &r
->ws
->winlist
, entry
) {
5432 if (win
->ws
== NULL
)
5433 continue; /* should never happen */
5439 DNPRINTF(SWM_D_MISC
, "uniconify: count: %d\n", count
);
5445 search_resp_action
= SWM_SEARCH_UNICONIFY
;
5447 spawn_select(r
, args
, "search", &searchpid
);
5449 if ((lfile
= fdopen(select_list_pipe
[1], "w")) == NULL
)
5452 TAILQ_FOREACH(win
, &r
->ws
->winlist
, entry
) {
5453 if (win
->ws
== NULL
)
5454 continue; /* should never happen */
5458 name
= get_win_name(win
->id
);
5459 fprintf(lfile
, "%s.%u\n", name
, win
->id
);
5467 name_workspace(struct swm_region
*r
, union arg
*args
)
5471 DNPRINTF(SWM_D_MISC
, "name_workspace\n");
5477 search_resp_action
= SWM_SEARCH_NAME_WORKSPACE
;
5479 spawn_select(r
, args
, "name_workspace", &searchpid
);
5481 if ((lfile
= fdopen(select_list_pipe
[1], "w")) == NULL
)
5484 fprintf(lfile
, "%s", "");
5489 search_workspace(struct swm_region
*r
, union arg
*args
)
5492 struct workspace
*ws
;
5495 DNPRINTF(SWM_D_MISC
, "search_workspace\n");
5501 search_resp_action
= SWM_SEARCH_SEARCH_WORKSPACE
;
5503 spawn_select(r
, args
, "search", &searchpid
);
5505 if ((lfile
= fdopen(select_list_pipe
[1], "w")) == NULL
)
5508 for (i
= 0; i
< workspace_limit
; i
++) {
5512 fprintf(lfile
, "%d%s%s\n", ws
->idx
+ 1,
5513 (ws
->name
? ":" : ""), (ws
->name
? ws
->name
: ""));
5520 search_win_cleanup(void)
5522 struct search_window
*sw
= NULL
;
5524 while ((sw
= TAILQ_FIRST(&search_wl
)) != NULL
) {
5525 xcb_destroy_window(conn
, sw
->indicator
);
5526 TAILQ_REMOVE(&search_wl
, sw
, entry
);
5532 search_win(struct swm_region
*r
, union arg
*args
)
5534 struct ws_win
*win
= NULL
;
5535 struct search_window
*sw
= NULL
;
5538 xcb_screen_t
*screen
;
5539 int i
, width
, height
;
5547 XRectangle l_ibox
, l_lbox
;
5549 DNPRINTF(SWM_D_MISC
, "search_win\n");
5552 search_resp_action
= SWM_SEARCH_SEARCH_WINDOW
;
5554 spawn_select(r
, args
, "search", &searchpid
);
5556 if ((lfile
= fdopen(select_list_pipe
[1], "w")) == NULL
)
5559 if ((screen
= get_screen(r
->s
->idx
)) == NULL
)
5560 errx(1, "ERROR: can't get screen %d.", r
->s
->idx
);
5562 TAILQ_INIT(&search_wl
);
5565 TAILQ_FOREACH(win
, &r
->ws
->winlist
, entry
) {
5569 sw
= calloc(1, sizeof(struct search_window
));
5571 warn("search_win: calloc");
5573 search_win_cleanup();
5579 snprintf(s
, sizeof s
, "%d", i
);
5582 w
= xcb_generate_id(conn
);
5583 wa
[0] = r
->s
->c
[SWM_S_COLOR_FOCUS
].pixel
;
5584 wa
[1] = r
->s
->c
[SWM_S_COLOR_UNFOCUS
].pixel
;
5585 wa
[2] = screen
->default_colormap
;
5587 if (bar_font_legacy
) {
5588 XmbTextExtents(bar_fs
, s
, len
, &l_ibox
, &l_lbox
);
5589 width
= l_lbox
.width
+ 4;
5590 height
= bar_fs_extents
->max_logical_extent
.height
+ 4;
5592 XftTextExtentsUtf8(display
, bar_font
, (FcChar8
*)s
, len
,
5594 width
= info
.width
+ 4;
5595 height
= bar_font
->height
+ 4;
5598 xcb_create_window(conn
, screen
->root_depth
, w
, win
->id
, 0, 0,
5599 width
, height
, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT
,
5600 screen
->root_visual
, XCB_CW_BACK_PIXEL
|
5601 XCB_CW_BORDER_PIXEL
| XCB_CW_COLORMAP
, wa
);
5603 xcb_map_window(conn
, w
);
5606 TAILQ_INSERT_TAIL(&search_wl
, sw
, entry
);
5608 if (bar_font_legacy
) {
5609 l_gcv
.graphics_exposures
= 0;
5610 l_draw
= XCreateGC(display
, w
, 0, &l_gcv
);
5612 XSetForeground(display
, l_draw
,
5613 r
->s
->c
[SWM_S_COLOR_BAR
].pixel
);
5615 DRAWSTRING(display
, w
, bar_fs
, l_draw
, 2,
5616 (bar_fs_extents
->max_logical_extent
.height
-
5617 l_lbox
.height
) / 2 - l_lbox
.y
, s
, len
);
5619 XFreeGC(display
, l_draw
);
5622 draw
= XftDrawCreate(display
, w
,
5623 DefaultVisual(display
, r
->s
->idx
),
5624 DefaultColormap(display
, r
->s
->idx
));
5626 XftDrawStringUtf8(draw
, &search_font_color
, bar_font
, 2,
5627 (HEIGHT(r
->bar
) + bar_font
->height
) / 2 -
5628 bar_font
->descent
, (FcChar8
*)s
, len
);
5630 XftDrawDestroy(draw
);
5633 DNPRINTF(SWM_D_MISC
, "search_win: mapped win %#x\n", w
);
5635 fprintf(lfile
, "%d\n", i
);
5645 search_resp_uniconify(const char *resp
, size_t len
)
5651 DNPRINTF(SWM_D_MISC
, "search_resp_uniconify: resp: %s\n", resp
);
5653 TAILQ_FOREACH(win
, &search_r
->ws
->winlist
, entry
) {
5656 name
= get_win_name(win
->id
);
5657 if (asprintf(&s
, "%s.%u", name
, win
->id
) == -1) {
5662 if (strncmp(s
, resp
, len
) == 0) {
5663 /* XXX this should be a callback to generalize */
5664 ewmh_apply_flags(win
, win
->ewmh_flags
& ~EWMH_F_HIDDEN
);
5665 ewmh_update_wm_state(win
);
5675 search_resp_name_workspace(const char *resp
, size_t len
)
5677 struct workspace
*ws
;
5679 DNPRINTF(SWM_D_MISC
, "search_resp_name_workspace: resp: %s\n", resp
);
5681 if (search_r
->ws
== NULL
)
5686 free(search_r
->ws
->name
);
5687 search_r
->ws
->name
= NULL
;
5691 ws
->name
= strdup(resp
);
5692 if (ws
->name
== NULL
) {
5693 DNPRINTF(SWM_D_MISC
, "search_resp_name_workspace: "
5694 "strdup: %s", strerror(errno
));
5698 ewmh_update_desktop_names();
5699 ewmh_get_desktop_names();
5704 ewmh_update_desktop_names(void)
5706 char *name_list
= NULL
, *p
;
5707 int num_screens
, i
, j
, len
= 0, tot
= 0;
5709 num_screens
= get_screen_count();
5710 for (i
= 0; i
< num_screens
; ++i
) {
5711 for (j
= 0; j
< workspace_limit
; ++j
) {
5712 if (screens
[i
].ws
[j
].name
!= NULL
)
5713 len
+= strlen(screens
[i
].ws
[j
].name
);
5717 if((name_list
= calloc(len
, sizeof(char))) == NULL
)
5718 err(1, "update_desktop_names: calloc: failed to "
5719 "allocate memory.");
5722 for (j
= 0; j
< workspace_limit
; ++j
) {
5723 if (screens
[i
].ws
[j
].name
!= NULL
) {
5724 len
= strlen(screens
[i
].ws
[j
].name
);
5725 memcpy(p
, screens
[i
].ws
[j
].name
, len
);
5734 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5735 screens
[i
].root
, ewmh
[_NET_DESKTOP_NAMES
].atom
,
5736 a_utf8_string
, 8, tot
, name_list
);
5746 ewmh_get_desktop_names(void)
5749 xcb_get_property_cookie_t c
;
5750 xcb_get_property_reply_t
*r
;
5751 int num_screens
, i
, j
, n
, k
;
5753 num_screens
= get_screen_count();
5754 for (i
= 0; i
< num_screens
; ++i
) {
5755 for (j
= 0; j
< workspace_limit
; ++j
) {
5756 free(screens
[i
].ws
[j
].name
);
5757 screens
[i
].ws
[j
].name
= NULL
;
5760 c
= xcb_get_property(conn
, 0, screens
[i
].root
,
5761 ewmh
[_NET_DESKTOP_NAMES
].atom
,
5762 a_utf8_string
, 0, UINT32_MAX
);
5763 r
= xcb_get_property_reply(conn
, c
, NULL
);
5767 names
= xcb_get_property_value(r
);
5768 n
= xcb_get_property_value_length(r
);
5770 for (j
= 0, k
= 0; j
< n
; ++j
) {
5771 if (*(names
+ j
) != '\0') {
5772 screens
[i
].ws
[k
].name
= strdup(names
+ j
);
5773 j
+= strlen(names
+ j
);
5782 ewmh_update_client_list(void)
5785 int num_screens
, i
, j
, k
= 0, count
= 0;
5788 num_screens
= get_screen_count();
5789 for (i
= 0; i
< num_screens
; ++i
) {
5790 for (j
= 0; j
< workspace_limit
; ++j
)
5791 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
5794 DNPRINTF(SWM_D_PROP
, "ewmh_update_client_list: win count: %d\n",
5800 wins
= calloc(count
, sizeof(xcb_window_t
));
5802 err(1, "ewmh_update_client_list: calloc: failed to "
5803 "allocate memory.");
5805 for (j
= 0, k
= 0; j
< workspace_limit
; ++j
)
5806 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
5807 wins
[k
++] = win
->id
;
5809 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5810 screens
[i
].root
, ewmh
[_NET_CLIENT_LIST
].atom
,
5811 XCB_ATOM_WINDOW
, 32, count
, wins
);
5818 ewmh_update_current_desktop(void)
5822 num_screens
= get_screen_count();
5823 for (i
= 0; i
< num_screens
; ++i
)
5824 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5825 screens
[i
].root
, ewmh
[_NET_CURRENT_DESKTOP
].atom
,
5826 XCB_ATOM_CARDINAL
, 32, 1, &screens
[i
].r_focus
->ws
->idx
);
5830 ewmh_update_desktops(void)
5832 int num_screens
, i
, j
;
5835 vals
= calloc(workspace_limit
* 2, sizeof(uint32_t));
5837 err(1, "ewmh_update_desktops: calloc: failed to allocate "
5840 num_screens
= get_screen_count();
5841 for (i
= 0; i
< num_screens
; i
++) {
5842 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5843 screens
[i
].root
, ewmh
[_NET_NUMBER_OF_DESKTOPS
].atom
,
5844 XCB_ATOM_CARDINAL
, 32, 1, &workspace_limit
);
5846 for (j
= 0; j
< workspace_limit
; ++j
) {
5847 if (screens
[i
].ws
[j
].r
!= NULL
) {
5848 vals
[j
* 2] = X(screens
[i
].ws
[j
].r
);
5849 vals
[j
* 2 + 1] = Y(screens
[i
].ws
[j
].r
);
5850 } else if (screens
[i
].ws
[j
].old_r
!= NULL
) {
5851 vals
[j
* 2] = X(screens
[i
].ws
[j
].old_r
);
5852 vals
[j
* 2 + 1] = Y(screens
[i
].ws
[j
].old_r
);
5854 vals
[j
* 2] = vals
[j
* 2 + 1] = 0;
5858 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5859 screens
[i
].root
, ewmh
[_NET_DESKTOP_VIEWPORT
].atom
,
5860 XCB_ATOM_CARDINAL
, 32, workspace_limit
* 2, vals
);
5867 search_resp_search_workspace(const char *resp
)
5874 DNPRINTF(SWM_D_MISC
, "search_resp_search_workspace: resp: %s\n", resp
);
5878 DNPRINTF(SWM_D_MISC
, "search_resp_search_workspace: strdup: %s",
5885 ws_idx
= (int)strtonum(q
, 1, workspace_limit
, &errstr
);
5887 DNPRINTF(SWM_D_MISC
, "workspace idx is %s: %s",
5894 switchws(search_r
, &a
);
5898 search_resp_search_window(const char *resp
)
5903 struct search_window
*sw
;
5905 DNPRINTF(SWM_D_MISC
, "search_resp_search_window: resp: %s\n", resp
);
5909 DNPRINTF(SWM_D_MISC
, "search_resp_search_window: strdup: %s",
5914 idx
= (int)strtonum(s
, 1, INT_MAX
, &errstr
);
5916 DNPRINTF(SWM_D_MISC
, "window idx is %s: %s",
5923 TAILQ_FOREACH(sw
, &search_wl
, entry
)
5924 if (idx
== sw
->idx
) {
5930 #define MAX_RESP_LEN 1024
5933 search_do_resp(void)
5939 DNPRINTF(SWM_D_MISC
, "search_do_resp:\n");
5944 if ((resp
= calloc(1, MAX_RESP_LEN
+ 1)) == NULL
) {
5945 warn("search: calloc");
5949 rbytes
= read(select_resp_pipe
[0], resp
, MAX_RESP_LEN
);
5951 warn("search: read error");
5954 resp
[rbytes
] = '\0';
5957 * Older versions of dmenu (Atleast pre 4.4.1) do not send a
5958 * newline, so work around that by sanitizing the resp now.
5960 resp
[strcspn(resp
, "\n")] = '\0';
5963 switch (search_resp_action
) {
5964 case SWM_SEARCH_UNICONIFY
:
5965 search_resp_uniconify(resp
, len
);
5967 case SWM_SEARCH_NAME_WORKSPACE
:
5968 search_resp_name_workspace(resp
, len
);
5970 case SWM_SEARCH_SEARCH_WORKSPACE
:
5971 search_resp_search_workspace(resp
);
5973 case SWM_SEARCH_SEARCH_WINDOW
:
5974 search_resp_search_window(resp
);
5979 if (search_resp_action
== SWM_SEARCH_SEARCH_WINDOW
)
5980 search_win_cleanup();
5982 search_resp_action
= SWM_SEARCH_NONE
;
5983 close(select_resp_pipe
[0]);
5990 wkill(struct swm_region
*r
, union arg
*args
)
5992 DNPRINTF(SWM_D_MISC
, "wkill: win %#x, id: %d\n", WINID(r
->ws
->focus
),
5995 if (r
->ws
->focus
== NULL
)
5998 if (args
->id
== SWM_ARG_ID_KILLWINDOW
)
5999 xcb_kill_client(conn
, r
->ws
->focus
->id
);
6001 if (r
->ws
->focus
->can_delete
)
6002 client_msg(r
->ws
->focus
, a_delete
, 0);
6008 clear_maximized(struct workspace
*ws
)
6013 /* Clear any maximized win(s) on ws, from bottom up. */
6014 TAILQ_FOREACH_REVERSE(w
, &ws
->stack
, ws_win_stack
, stack_entry
)
6016 ewmh_apply_flags(w
, w
->ewmh_flags
& ~EWMH_F_MAXIMIZED
);
6017 ewmh_update_wm_state(w
);
6025 maximize_toggle(struct swm_region
*r
, union arg
*args
)
6027 struct ws_win
*w
= r
->ws
->focus
;
6029 /* suppress unused warning since var is needed */
6035 DNPRINTF(SWM_D_MISC
, "maximize_toggle: win %#x\n", w
->id
);
6040 if (w
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
6043 ewmh_apply_flags(w
, w
->ewmh_flags
^ EWMH_F_MAXIMIZED
);
6044 ewmh_update_wm_state(w
);
6048 if (w
== w
->ws
->focus
)
6053 DNPRINTF(SWM_D_MISC
, "maximize_toggle: done\n");
6057 floating_toggle(struct swm_region
*r
, union arg
*args
)
6059 struct ws_win
*w
= r
->ws
->focus
;
6061 /* suppress unused warning since var is needed */
6067 DNPRINTF(SWM_D_MISC
, "floating_toggle: win %#x\n", w
->id
);
6069 if (FULLSCREEN(w
) || TRANS(w
))
6072 if (w
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
6075 ewmh_apply_flags(w
, w
->ewmh_flags
^ EWMH_F_ABOVE
);
6076 ewmh_update_wm_state(w
);
6080 if (w
== w
->ws
->focus
)
6085 DNPRINTF(SWM_D_MISC
, "floating_toggle: done\n");
6089 region_containment(struct ws_win
*win
, struct swm_region
*r
, int opts
)
6091 struct swm_geometry g
= r
->g
;
6092 int rt
, lt
, tp
, bm
, bw
;
6094 bw
= (opts
& SWM_CW_SOFTBOUNDARY
) ? boundary_width
: 0;
6097 * Perpendicular distance of each side of the window to the respective
6098 * side of the region boundary. Positive values indicate the side of
6099 * the window has passed beyond the region boundary.
6101 rt
= opts
& SWM_CW_RIGHT
? MAX_X(win
) + BORDER(win
) - MAX_X(r
) : bw
;
6102 lt
= opts
& SWM_CW_LEFT
? X(r
) - X(win
) + BORDER(win
) : bw
;
6103 bm
= opts
& SWM_CW_BOTTOM
? MAX_Y(win
) + BORDER(win
) - MAX_Y(r
) : bw
;
6104 tp
= opts
& SWM_CW_TOP
? Y(r
) - Y(win
) + BORDER(win
) : bw
;
6106 DNPRINTF(SWM_D_MISC
, "region_containment: win %#x, rt: %d, lt: %d, "
6107 "bm: %d, tp: %d, SOFTBOUNDARY: %s, HARDBOUNDARY: %s\n", win
->id
, rt
,
6108 lt
, bm
, tp
, YESNO(opts
& SWM_CW_SOFTBOUNDARY
),
6109 YESNO(opts
& SWM_CW_HARDBOUNDARY
));
6112 * Disable containment if any of the flagged sides went beyond the
6113 * containment boundary, or if containment is disabled.
6115 if (!(opts
& SWM_CW_HARDBOUNDARY
|| opts
& SWM_CW_SOFTBOUNDARY
) ||
6116 (bw
!= 0 && ((rt
> bw
) || (lt
> bw
) || (bm
> bw
) || (tp
> bw
)))) {
6117 /* Make sure window has at least 1 pixel in the region */
6118 g
.x
+= 1 - WIDTH(win
);
6119 g
.y
+= 1 - HEIGHT(win
);
6120 g
.w
+= 2 * WIDTH(win
) - 2;
6121 g
.h
+= 2 * HEIGHT(win
) - 2;
6124 constrain_window(win
, &g
, &opts
);
6127 /* Move or resize a window so that flagged side(s) fit into the supplied box. */
6129 constrain_window(struct ws_win
*win
, struct swm_geometry
*b
, int *opts
)
6131 DNPRINTF(SWM_D_MISC
, "constrain_window: win %#x, (x,y) w x h: "
6132 "(%d,%d) %d x %d, box: (x,y) w x h: (%d,%d) %d x %d, rt: %s, "
6133 "lt: %s, bt: %s, tp: %s, allow resize: %s\n", win
->id
, X(win
),
6134 Y(win
), WIDTH(win
), HEIGHT(win
), b
->x
, b
->y
, b
->w
, b
->h
,
6135 YESNO(*opts
& SWM_CW_RIGHT
), YESNO(*opts
& SWM_CW_LEFT
),
6136 YESNO(*opts
& SWM_CW_BOTTOM
), YESNO(*opts
& SWM_CW_TOP
),
6137 YESNO(*opts
& SWM_CW_RESIZABLE
));
6139 if ((*opts
& SWM_CW_RIGHT
) && MAX_X(win
) + BORDER(win
) > b
->x
+ b
->w
) {
6140 if (*opts
& SWM_CW_RESIZABLE
)
6141 WIDTH(win
) = b
->x
+ b
->w
- X(win
) - BORDER(win
);
6143 X(win
) = b
->x
+ b
->w
- WIDTH(win
) - BORDER(win
);
6146 if ((*opts
& SWM_CW_LEFT
) && X(win
) + BORDER(win
) < b
->x
) {
6147 if (*opts
& SWM_CW_RESIZABLE
)
6148 WIDTH(win
) -= b
->x
- X(win
) - BORDER(win
);
6150 X(win
) = b
->x
- BORDER(win
);
6153 if ((*opts
& SWM_CW_BOTTOM
) && MAX_Y(win
) + BORDER(win
) > b
->y
+ b
->h
) {
6154 if (*opts
& SWM_CW_RESIZABLE
)
6155 HEIGHT(win
) = b
->y
+ b
->h
- Y(win
) - BORDER(win
);
6157 Y(win
) = b
->y
+ b
->h
- HEIGHT(win
) - BORDER(win
);
6160 if ((*opts
& SWM_CW_TOP
) && Y(win
) + BORDER(win
) < b
->y
) {
6161 if (*opts
& SWM_CW_RESIZABLE
)
6162 HEIGHT(win
) -= b
->y
- Y(win
) - BORDER(win
);
6164 Y(win
) = b
->y
- BORDER(win
);
6167 if (*opts
& SWM_CW_RESIZABLE
) {
6170 if (HEIGHT(win
) < 1)
6176 update_window_color(struct ws_win
*win
)
6180 if (WS_FOCUSED(win
->ws
) && win
->ws
->focus
== win
)
6181 pixel
= MAXIMIZED(win
) ?
6182 &win
->s
->c
[SWM_S_COLOR_FOCUS_MAXIMIZED
].pixel
:
6183 &win
->s
->c
[SWM_S_COLOR_FOCUS
].pixel
;
6185 pixel
= MAXIMIZED(win
) ?
6186 &win
->s
->c
[SWM_S_COLOR_UNFOCUS_MAXIMIZED
].pixel
:
6187 &win
->s
->c
[SWM_S_COLOR_UNFOCUS
].pixel
;
6189 xcb_change_window_attributes(conn
, win
->id
,
6190 XCB_CW_BORDER_PIXEL
, pixel
);
6194 update_window(struct ws_win
*win
)
6199 mask
= XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
|
6200 XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
|
6201 XCB_CONFIG_WINDOW_BORDER_WIDTH
;
6205 wc
[3] = HEIGHT(win
);
6206 wc
[4] = BORDER(win
);
6208 DNPRINTF(SWM_D_EVENT
, "update_window: win %#x, (x,y) w x h: "
6209 "(%d,%d) %d x %d, bordered: %s\n", win
->id
, wc
[0], wc
[1], wc
[2],
6210 wc
[3], YESNO(win
->bordered
));
6212 xcb_configure_window(conn
, win
->id
, mask
, wc
);
6215 #define SWM_RESIZE_STEPS (50)
6218 resize(struct ws_win
*win
, union arg
*args
)
6220 xcb_timestamp_t timestamp
= 0;
6221 struct swm_region
*r
= NULL
;
6222 struct swm_geometry g
;
6224 int top
= 0, left
= 0;
6226 xcb_cursor_t cursor
;
6227 xcb_query_pointer_reply_t
*xpr
= NULL
;
6228 xcb_generic_event_t
*evt
;
6229 xcb_motion_notify_event_t
*mne
;
6236 if (FULLSCREEN(win
))
6239 /* In max_stack mode, should only resize transients. */
6240 if (win
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
] && !TRANS(win
))
6243 DNPRINTF(SWM_D_EVENT
, "resize: win %#x, floating: %s, "
6244 "transient: %#x\n", win
->id
, YESNO(ABOVE(win
)),
6248 store_float_geom(win
);
6249 else if (!(TRANS(win
) || ABOVE(win
)))
6252 ewmh_apply_flags(win
, (win
->ewmh_flags
| SWM_F_MANUAL
| EWMH_F_ABOVE
) &
6254 ewmh_update_wm_state(win
);
6260 /* It's possible for win to have been freed during focus_flush(). */
6261 if (validate_win(win
)) {
6262 DNPRINTF(SWM_D_EVENT
, "resize: invalid win.\n");
6267 case SWM_ARG_ID_WIDTHSHRINK
:
6268 WIDTH(win
) -= SWM_RESIZE_STEPS
;
6271 case SWM_ARG_ID_WIDTHGROW
:
6272 WIDTH(win
) += SWM_RESIZE_STEPS
;
6275 case SWM_ARG_ID_HEIGHTSHRINK
:
6276 HEIGHT(win
) -= SWM_RESIZE_STEPS
;
6279 case SWM_ARG_ID_HEIGHTGROW
:
6280 HEIGHT(win
) += SWM_RESIZE_STEPS
;
6287 region_containment(win
, r
, SWM_CW_ALLSIDES
| SWM_CW_RESIZABLE
|
6288 SWM_CW_HARDBOUNDARY
);
6290 store_float_geom(win
);
6294 region_containment(win
, r
, SWM_CW_ALLSIDES
| SWM_CW_RESIZABLE
|
6295 SWM_CW_SOFTBOUNDARY
);
6298 /* get cursor offset from window root */
6299 xpr
= xcb_query_pointer_reply(conn
, xcb_query_pointer(conn
, win
->id
),
6306 if (xpr
->win_x
< WIDTH(win
) / 2)
6309 if (xpr
->win_y
< HEIGHT(win
) / 2)
6312 if (args
->id
== SWM_ARG_ID_CENTER
)
6313 cursor
= cursors
[XC_SIZING
].cid
;
6315 cursor
= cursors
[left
? XC_TOP_LEFT_CORNER
:
6316 XC_TOP_RIGHT_CORNER
].cid
;
6318 cursor
= cursors
[left
? XC_BOTTOM_LEFT_CORNER
:
6319 XC_BOTTOM_RIGHT_CORNER
].cid
;
6321 xcb_grab_pointer(conn
, 0, win
->id
, MOUSEMASK
,
6322 XCB_GRAB_MODE_ASYNC
, XCB_GRAB_MODE_ASYNC
, XCB_WINDOW_NONE
, cursor
,
6327 while (resizing
&& (evt
= xcb_wait_for_event(conn
))) {
6328 switch (XCB_EVENT_RESPONSE_TYPE(evt
)) {
6329 case XCB_BUTTON_RELEASE
:
6330 DNPRINTF(SWM_D_EVENT
, "resize: BUTTON_RELEASE\n");
6333 case XCB_MOTION_NOTIFY
:
6334 mne
= (xcb_motion_notify_event_t
*)evt
;
6335 /* cursor offset/delta from start of the operation */
6336 dx
= mne
->root_x
- xpr
->root_x
;
6337 dy
= mne
->root_y
- xpr
->root_y
;
6343 if (args
->id
== SWM_ARG_ID_CENTER
) {
6344 if (g
.h
/ 2 + dy
< 1)
6348 HEIGHT(win
) = g
.h
+ 2 * dy
;
6356 HEIGHT(win
) = g
.h
+ dy
;
6363 if (args
->id
== SWM_ARG_ID_CENTER
) {
6364 if (g
.w
/ 2 + dx
< 1)
6368 WIDTH(win
) = g
.w
+ 2 * dx
;
6376 WIDTH(win
) = g
.w
+ dx
;
6379 /* not free, don't sync more than 120 times / second */
6380 if ((mne
->time
- timestamp
) > (1000 / 120) ) {
6381 timestamp
= mne
->time
;
6382 regionize(win
, mne
->root_x
, mne
->root_y
);
6383 region_containment(win
, r
, SWM_CW_ALLSIDES
|
6384 SWM_CW_RESIZABLE
| SWM_CW_HARDBOUNDARY
|
6385 SWM_CW_SOFTBOUNDARY
);
6392 xcb_allow_events(conn
, XCB_ALLOW_ASYNC_KEYBOARD
,
6393 ((xcb_key_press_event_t
*)evt
)->time
);
6399 /* It's possible for win to have been freed above. */
6400 if (validate_win(win
)) {
6401 DNPRINTF(SWM_D_EVENT
, "resize: invalid win.\n");
6409 region_containment(win
, r
, SWM_CW_ALLSIDES
| SWM_CW_RESIZABLE
|
6410 SWM_CW_HARDBOUNDARY
| SWM_CW_SOFTBOUNDARY
);
6414 store_float_geom(win
);
6416 xcb_ungrab_pointer(conn
, XCB_CURRENT_TIME
);
6418 DNPRINTF(SWM_D_EVENT
, "resize: done.\n");
6422 resize_step(struct swm_region
*r
, union arg
*args
)
6424 struct ws_win
*win
= NULL
;
6426 if (r
&& r
->ws
&& r
->ws
->focus
)
6436 /* Try to set window region based on supplied coordinates or window center. */
6438 regionize(struct ws_win
*win
, int x
, int y
)
6440 struct swm_region
*r
= NULL
;
6442 r
= region_under(win
->s
, x
, y
);
6444 r
= region_under(win
->s
, X(win
) + WIDTH(win
) / 2,
6445 Y(win
) + HEIGHT(win
) / 2);
6447 if (r
!= NULL
&& r
!= win
->ws
->r
) {
6448 if (clear_maximized(r
->ws
) > 0)
6451 win_to_ws(win
, r
->ws
->idx
, false);
6453 /* Set focus on new ws. */
6454 unfocus_win(r
->ws
->focus
);
6462 #define SWM_MOVE_STEPS (50)
6465 move(struct ws_win
*win
, union arg
*args
)
6467 struct swm_region
*r
;
6468 xcb_timestamp_t timestamp
= 0;
6470 xcb_query_pointer_reply_t
*qpr
= NULL
;
6471 xcb_generic_event_t
*evt
;
6472 xcb_motion_notify_event_t
*mne
;
6473 bool moving
, restack
= false;
6478 if ((r
= win
->ws
->r
) == NULL
)
6481 if (FULLSCREEN(win
))
6484 DNPRINTF(SWM_D_EVENT
, "move: win %#x, floating: %s, transient: "
6485 "%#x\n", win
->id
, YESNO(ABOVE(win
)), win
->transient
);
6487 /* in max_stack mode should only move transients */
6488 if (win
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
] && !TRANS(win
))
6491 if (!(ABOVE(win
) || TRANS(win
)) || MAXIMIZED(win
)) {
6492 store_float_geom(win
);
6496 ewmh_apply_flags(win
, (win
->ewmh_flags
| SWM_F_MANUAL
| EWMH_F_ABOVE
) &
6498 ewmh_update_wm_state(win
);
6505 /* It's possible for win to have been freed during focus_flush(). */
6506 if (validate_win(win
)) {
6507 DNPRINTF(SWM_D_EVENT
, "move: invalid win.\n");
6513 case SWM_ARG_ID_MOVELEFT
:
6514 X(win
) -= (SWM_MOVE_STEPS
- border_width
);
6517 case SWM_ARG_ID_MOVERIGHT
:
6518 X(win
) += (SWM_MOVE_STEPS
- border_width
);
6521 case SWM_ARG_ID_MOVEUP
:
6522 Y(win
) -= (SWM_MOVE_STEPS
- border_width
);
6525 case SWM_ARG_ID_MOVEDOWN
:
6526 Y(win
) += (SWM_MOVE_STEPS
- border_width
);
6533 regionize(win
, -1, -1);
6534 region_containment(win
, win
->ws
->r
, SWM_CW_ALLSIDES
);
6536 store_float_geom(win
);
6540 xcb_grab_pointer(conn
, 0, win
->id
, MOUSEMASK
,
6541 XCB_GRAB_MODE_ASYNC
, XCB_GRAB_MODE_ASYNC
,
6542 XCB_WINDOW_NONE
, cursors
[XC_FLEUR
].cid
, XCB_CURRENT_TIME
);
6544 /* get cursor offset from window root */
6545 qpr
= xcb_query_pointer_reply(conn
, xcb_query_pointer(conn
, win
->id
),
6548 xcb_ungrab_pointer(conn
, XCB_CURRENT_TIME
);
6552 regionize(win
, qpr
->root_x
, qpr
->root_y
);
6553 region_containment(win
, win
->ws
->r
, SWM_CW_ALLSIDES
|
6554 SWM_CW_SOFTBOUNDARY
);
6558 while (moving
&& (evt
= xcb_wait_for_event(conn
))) {
6559 switch (XCB_EVENT_RESPONSE_TYPE(evt
)) {
6560 case XCB_BUTTON_RELEASE
:
6561 DNPRINTF(SWM_D_EVENT
, "move: BUTTON_RELEASE\n");
6564 case XCB_MOTION_NOTIFY
:
6565 mne
= (xcb_motion_notify_event_t
*)evt
;
6566 DNPRINTF(SWM_D_EVENT
, "motion: root: %#x\n", mne
->root
);
6567 X(win
) = mne
->root_x
- qpr
->win_x
- border_width
;
6568 Y(win
) = mne
->root_y
- qpr
->win_y
- border_width
;
6570 /* not free, don't sync more than 120 times / second */
6571 if ((mne
->time
- timestamp
) > (1000 / 120) ) {
6572 timestamp
= mne
->time
;
6573 regionize(win
, mne
->root_x
, mne
->root_y
);
6574 region_containment(win
, win
->ws
->r
,
6575 SWM_CW_ALLSIDES
| SWM_CW_SOFTBOUNDARY
);
6582 xcb_allow_events(conn
, XCB_ALLOW_ASYNC_KEYBOARD
,
6583 ((xcb_key_press_event_t
*)evt
)->time
);
6589 /* It's possible for win to have been freed above. */
6590 if (validate_win(win
)) {
6591 DNPRINTF(SWM_D_EVENT
, "move: invalid win.\n");
6599 region_containment(win
, win
->ws
->r
, SWM_CW_ALLSIDES
|
6600 SWM_CW_SOFTBOUNDARY
);
6604 store_float_geom(win
);
6606 /* New region set to fullscreen layout. */
6607 if (win
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
]) {
6614 xcb_ungrab_pointer(conn
, XCB_CURRENT_TIME
);
6615 DNPRINTF(SWM_D_EVENT
, "move: done.\n");
6619 move_step(struct swm_region
*r
, union arg
*args
)
6621 struct ws_win
*win
= NULL
;
6623 if (r
&& r
->ws
&& r
->ws
->focus
)
6628 if (!TRANS(win
) && !ABOVE(win
))
6636 /* key definitions */
6638 char name
[SWM_FUNCNAME_LEN
];
6639 void (*func
)(struct swm_region
*r
, union arg
*);
6641 } keyfuncs
[KF_INVALID
+ 1] = {
6642 /* name function argument */
6643 { "bar_toggle", bar_toggle
, {.id
= SWM_ARG_ID_BAR_TOGGLE
} },
6644 { "bar_toggle_ws", bar_toggle
, {.id
= SWM_ARG_ID_BAR_TOGGLE_WS
} },
6645 { "button2", pressbutton
, {2} },
6646 { "cycle_layout", cycle_layout
, {0} },
6647 { "flip_layout", stack_config
, {.id
= SWM_ARG_ID_FLIPLAYOUT
} },
6648 { "float_toggle", floating_toggle
,{0} },
6649 { "focus_main", focus
, {.id
= SWM_ARG_ID_FOCUSMAIN
} },
6650 { "focus_next", focus
, {.id
= SWM_ARG_ID_FOCUSNEXT
} },
6651 { "focus_prev", focus
, {.id
= SWM_ARG_ID_FOCUSPREV
} },
6652 { "focus_urgent", focus
, {.id
= SWM_ARG_ID_FOCUSURGENT
} },
6653 { "maximize_toggle", maximize_toggle
,{0} },
6654 { "height_grow", resize_step
, {.id
= SWM_ARG_ID_HEIGHTGROW
} },
6655 { "height_shrink", resize_step
, {.id
= SWM_ARG_ID_HEIGHTSHRINK
} },
6656 { "iconify", iconify
, {0} },
6657 { "master_shrink", stack_config
, {.id
= SWM_ARG_ID_MASTERSHRINK
} },
6658 { "master_grow", stack_config
, {.id
= SWM_ARG_ID_MASTERGROW
} },
6659 { "master_add", stack_config
, {.id
= SWM_ARG_ID_MASTERADD
} },
6660 { "master_del", stack_config
, {.id
= SWM_ARG_ID_MASTERDEL
} },
6661 { "move_down", move_step
, {.id
= SWM_ARG_ID_MOVEDOWN
} },
6662 { "move_left", move_step
, {.id
= SWM_ARG_ID_MOVELEFT
} },
6663 { "move_right", move_step
, {.id
= SWM_ARG_ID_MOVERIGHT
} },
6664 { "move_up", move_step
, {.id
= SWM_ARG_ID_MOVEUP
} },
6665 { "mvrg_1", send_to_rg
, {.id
= 0} },
6666 { "mvrg_2", send_to_rg
, {.id
= 1} },
6667 { "mvrg_3", send_to_rg
, {.id
= 2} },
6668 { "mvrg_4", send_to_rg
, {.id
= 3} },
6669 { "mvrg_5", send_to_rg
, {.id
= 4} },
6670 { "mvrg_6", send_to_rg
, {.id
= 5} },
6671 { "mvrg_7", send_to_rg
, {.id
= 6} },
6672 { "mvrg_8", send_to_rg
, {.id
= 7} },
6673 { "mvrg_9", send_to_rg
, {.id
= 8} },
6674 { "mvws_1", send_to_ws
, {.id
= 0} },
6675 { "mvws_2", send_to_ws
, {.id
= 1} },
6676 { "mvws_3", send_to_ws
, {.id
= 2} },
6677 { "mvws_4", send_to_ws
, {.id
= 3} },
6678 { "mvws_5", send_to_ws
, {.id
= 4} },
6679 { "mvws_6", send_to_ws
, {.id
= 5} },
6680 { "mvws_7", send_to_ws
, {.id
= 6} },
6681 { "mvws_8", send_to_ws
, {.id
= 7} },
6682 { "mvws_9", send_to_ws
, {.id
= 8} },
6683 { "mvws_10", send_to_ws
, {.id
= 9} },
6684 { "mvws_11", send_to_ws
, {.id
= 10} },
6685 { "mvws_12", send_to_ws
, {.id
= 11} },
6686 { "mvws_13", send_to_ws
, {.id
= 12} },
6687 { "mvws_14", send_to_ws
, {.id
= 13} },
6688 { "mvws_15", send_to_ws
, {.id
= 14} },
6689 { "mvws_16", send_to_ws
, {.id
= 15} },
6690 { "mvws_17", send_to_ws
, {.id
= 16} },
6691 { "mvws_18", send_to_ws
, {.id
= 17} },
6692 { "mvws_19", send_to_ws
, {.id
= 18} },
6693 { "mvws_20", send_to_ws
, {.id
= 19} },
6694 { "mvws_21", send_to_ws
, {.id
= 20} },
6695 { "mvws_22", send_to_ws
, {.id
= 21} },
6696 { "name_workspace", name_workspace
, {0} },
6697 { "quit", quit
, {0} },
6698 { "raise_toggle", raise_toggle
, {0} },
6699 { "restart", restart
, {0} },
6700 { "rg_1", focusrg
, {.id
= 0} },
6701 { "rg_2", focusrg
, {.id
= 1} },
6702 { "rg_3", focusrg
, {.id
= 2} },
6703 { "rg_4", focusrg
, {.id
= 3} },
6704 { "rg_5", focusrg
, {.id
= 4} },
6705 { "rg_6", focusrg
, {.id
= 5} },
6706 { "rg_7", focusrg
, {.id
= 6} },
6707 { "rg_8", focusrg
, {.id
= 7} },
6708 { "rg_9", focusrg
, {.id
= 8} },
6709 { "rg_next", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_UP
} },
6710 { "rg_prev", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_DOWN
} },
6711 { "screen_next", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_UP
} },
6712 { "screen_prev", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_DOWN
} },
6713 { "search_win", search_win
, {0} },
6714 { "search_workspace", search_workspace
, {0} },
6715 { "spawn_custom", NULL
, {0} },
6716 { "stack_inc", stack_config
, {.id
= SWM_ARG_ID_STACKINC
} },
6717 { "stack_dec", stack_config
, {.id
= SWM_ARG_ID_STACKDEC
} },
6718 { "stack_reset", stack_config
, {.id
= SWM_ARG_ID_STACKRESET
} },
6719 { "stack_balance", stack_config
, {.id
= SWM_ARG_ID_STACKBALANCE
} },
6720 { "swap_main", swapwin
, {.id
= SWM_ARG_ID_SWAPMAIN
} },
6721 { "swap_next", swapwin
, {.id
= SWM_ARG_ID_SWAPNEXT
} },
6722 { "swap_prev", swapwin
, {.id
= SWM_ARG_ID_SWAPPREV
} },
6723 { "uniconify", uniconify
, {0} },
6724 { "version", version
, {0} },
6725 { "width_grow", resize_step
, {.id
= SWM_ARG_ID_WIDTHGROW
} },
6726 { "width_shrink", resize_step
, {.id
= SWM_ARG_ID_WIDTHSHRINK
} },
6727 { "wind_del", wkill
, {.id
= SWM_ARG_ID_DELETEWINDOW
} },
6728 { "wind_kill", wkill
, {.id
= SWM_ARG_ID_KILLWINDOW
} },
6729 { "ws_1", switchws
, {.id
= 0} },
6730 { "ws_2", switchws
, {.id
= 1} },
6731 { "ws_3", switchws
, {.id
= 2} },
6732 { "ws_4", switchws
, {.id
= 3} },
6733 { "ws_5", switchws
, {.id
= 4} },
6734 { "ws_6", switchws
, {.id
= 5} },
6735 { "ws_7", switchws
, {.id
= 6} },
6736 { "ws_8", switchws
, {.id
= 7} },
6737 { "ws_9", switchws
, {.id
= 8} },
6738 { "ws_10", switchws
, {.id
= 9} },
6739 { "ws_11", switchws
, {.id
= 10} },
6740 { "ws_12", switchws
, {.id
= 11} },
6741 { "ws_13", switchws
, {.id
= 12} },
6742 { "ws_14", switchws
, {.id
= 13} },
6743 { "ws_15", switchws
, {.id
= 14} },
6744 { "ws_16", switchws
, {.id
= 15} },
6745 { "ws_17", switchws
, {.id
= 16} },
6746 { "ws_18", switchws
, {.id
= 17} },
6747 { "ws_19", switchws
, {.id
= 18} },
6748 { "ws_20", switchws
, {.id
= 19} },
6749 { "ws_21", switchws
, {.id
= 20} },
6750 { "ws_22", switchws
, {.id
= 21} },
6751 { "ws_next", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_UP
} },
6752 { "ws_next_all", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_UP_ALL
} },
6753 { "ws_next_move", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_MOVE_UP
} },
6754 { "ws_prev", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_DOWN
} },
6755 { "ws_prev_all", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_DOWN_ALL
} },
6756 { "ws_prev_move", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_MOVE_DOWN
} },
6757 { "ws_prior", priorws
, {0} },
6758 { "dumpwins", dumpwins
, {0} }, /* MUST BE LAST */
6759 { "invalid key func", NULL
, {0} },
6763 key_cmp(struct key
*kp1
, struct key
*kp2
)
6765 if (kp1
->keysym
< kp2
->keysym
)
6767 if (kp1
->keysym
> kp2
->keysym
)
6770 if (kp1
->mod
< kp2
->mod
)
6772 if (kp1
->mod
> kp2
->mod
)
6779 enum { client_click
, root_click
};
6781 unsigned int action
;
6783 unsigned int button
;
6784 void (*func
)(struct ws_win
*, union arg
*);
6787 #define MODKEY_SHIFT MODKEY | XCB_MOD_MASK_SHIFT
6788 /* action key mouse button func args */
6789 { client_click
, MODKEY
, XCB_BUTTON_INDEX_3
, resize
, {.id
= SWM_ARG_ID_DONTCENTER
} },
6790 { client_click
, MODKEY_SHIFT
, XCB_BUTTON_INDEX_3
, resize
, {.id
= SWM_ARG_ID_CENTER
} },
6791 { client_click
, MODKEY
, XCB_BUTTON_INDEX_1
, move
, {0} },
6796 update_modkey(unsigned int mod
)
6802 RB_FOREACH(kp
, key_tree
, &keys
)
6803 if (kp
->mod
& XCB_MOD_MASK_SHIFT
)
6804 kp
->mod
= mod
| XCB_MOD_MASK_SHIFT
;
6808 for (i
= 0; i
< LENGTH(buttons
); i
++)
6809 if (buttons
[i
].mask
& XCB_MOD_MASK_SHIFT
)
6810 buttons
[i
].mask
= mod
| XCB_MOD_MASK_SHIFT
;
6812 buttons
[i
].mask
= mod
;
6816 update_mousebutton(unsigned char type
, unsigned int but
)
6822 mouse_button_move
= but
;
6825 mouse_button_resize
= but
;
6829 for (i
= 0; i
< LENGTH(buttons
); i
++) {
6830 if (buttons
[i
].func
== move
)
6831 buttons
[i
].button
= mouse_button_move
;
6833 if (buttons
[i
].func
== resize
)
6834 buttons
[i
].button
= mouse_button_resize
;
6841 spawn_expand(struct swm_region
*r
, union arg
*args
, const char *spawn_name
,
6844 struct spawn_prog
*prog
= NULL
;
6846 char *ap
, **real_args
;
6848 /* suppress unused warning since var is needed */
6851 DNPRINTF(SWM_D_SPAWN
, "spawn_expand: %s\n", spawn_name
);
6854 TAILQ_FOREACH(prog
, &spawns
, entry
) {
6855 if (strcasecmp(spawn_name
, prog
->name
) == 0)
6859 warnx("spawn_custom: program %s not found", spawn_name
);
6863 /* make room for expanded args */
6864 if ((real_args
= calloc(prog
->argc
+ 1, sizeof(char *))) == NULL
)
6865 err(1, "spawn_custom: calloc real_args");
6867 /* expand spawn_args into real_args */
6868 for (i
= c
= 0; i
< prog
->argc
; i
++) {
6870 DNPRINTF(SWM_D_SPAWN
, "spawn_custom: raw arg: %s\n", ap
);
6871 if (strcasecmp(ap
, "$bar_border") == 0) {
6873 strdup(r
->s
->c
[SWM_S_COLOR_BAR_BORDER
].name
))
6875 err(1, "spawn_custom border color");
6876 } else if (strcasecmp(ap
, "$bar_color") == 0) {
6878 strdup(r
->s
->c
[SWM_S_COLOR_BAR
].name
))
6880 err(1, "spawn_custom bar color");
6881 } else if (strcasecmp(ap
, "$bar_font") == 0) {
6882 if ((real_args
[c
] = strdup(bar_fonts
))
6884 err(1, "spawn_custom bar fonts");
6885 } else if (strcasecmp(ap
, "$bar_font_color") == 0) {
6887 strdup(r
->s
->c
[SWM_S_COLOR_BAR_FONT
].name
))
6889 err(1, "spawn_custom color font");
6890 } else if (strcasecmp(ap
, "$color_focus") == 0) {
6892 strdup(r
->s
->c
[SWM_S_COLOR_FOCUS
].name
))
6894 err(1, "spawn_custom color focus");
6895 } else if (strcasecmp(ap
, "$color_focus_maximized") == 0) {
6897 strdup(r
->s
->c
[SWM_S_COLOR_FOCUS_MAXIMIZED
].name
))
6899 err(1, "spawn_custom color focus maximized");
6900 } else if (strcasecmp(ap
, "$color_unfocus") == 0) {
6902 strdup(r
->s
->c
[SWM_S_COLOR_UNFOCUS
].name
))
6904 err(1, "spawn_custom color unfocus");
6905 } else if (strcasecmp(ap
, "$color_unfocus_maximized") == 0) {
6907 strdup(r
->s
->c
[SWM_S_COLOR_UNFOCUS_MAXIMIZED
].name
))
6909 err(1, "spawn_custom color unfocus maximized");
6910 } else if (strcasecmp(ap
, "$region_index") == 0) {
6911 if (asprintf(&real_args
[c
], "%d",
6912 get_region_index(r
) + 1) < 1)
6913 err(1, "spawn_custom region index");
6914 } else if (strcasecmp(ap
, "$workspace_index") == 0) {
6915 if (asprintf(&real_args
[c
], "%d", r
->ws
->idx
+ 1) < 1)
6916 err(1, "spawn_custom workspace index");
6917 } else if (strcasecmp(ap
, "$dmenu_bottom") == 0) {
6920 if ((real_args
[c
] = strdup("-b")) == NULL
)
6921 err(1, "spawn_custom workspace index");
6923 /* no match --> copy as is */
6924 if ((real_args
[c
] = strdup(ap
)) == NULL
)
6925 err(1, "spawn_custom strdup(ap)");
6927 DNPRINTF(SWM_D_SPAWN
, "spawn_custom: cooked arg: %s\n",
6933 DNPRINTF(SWM_D_SPAWN
, "spawn_custom: result: ");
6934 for (i
= 0; i
< c
; ++i
)
6935 DPRINTF("\"%s\" ", real_args
[i
]);
6938 *ret_args
= real_args
;
6943 spawn_custom(struct swm_region
*r
, union arg
*args
, const char *spawn_name
)
6949 if ((spawn_argc
= spawn_expand(r
, args
, spawn_name
, &real_args
)) < 0)
6953 spawn(r
->ws
->idx
, &a
, true);
6955 for (i
= 0; i
< spawn_argc
; i
++)
6961 spawn_select(struct swm_region
*r
, union arg
*args
, const char *spawn_name
,
6968 if ((spawn_argc
= spawn_expand(r
, args
, spawn_name
, &real_args
)) < 0)
6972 if (pipe(select_list_pipe
) == -1)
6973 err(1, "pipe error");
6974 if (pipe(select_resp_pipe
) == -1)
6975 err(1, "pipe error");
6977 if (signal(SIGPIPE
, SIG_IGN
) == SIG_ERR
)
6978 err(1, "could not disable SIGPIPE");
6979 switch (*pid
= fork()) {
6981 err(1, "cannot fork");
6984 if (dup2(select_list_pipe
[0], STDIN_FILENO
) == -1)
6986 if (dup2(select_resp_pipe
[1], STDOUT_FILENO
) == -1)
6988 close(select_list_pipe
[1]);
6989 close(select_resp_pipe
[0]);
6990 spawn(r
->ws
->idx
, &a
, false);
6992 default: /* parent */
6993 close(select_list_pipe
[0]);
6994 close(select_resp_pipe
[1]);
6998 for (i
= 0; i
< spawn_argc
; i
++)
7003 /* Argument tokenizer. */
7006 char *arg
, *cp
, *next
;
7007 bool single_quoted
= false, double_quoted
= false;
7012 /* Eat and move characters until end of argument is found. */
7013 for (arg
= next
= cp
= *sp
; *cp
!= '\0'; ++cp
) {
7014 if (!double_quoted
&& *cp
== '\'') {
7015 /* Eat single-quote. */
7016 single_quoted
= !single_quoted
;
7017 } else if (!single_quoted
&& *cp
== '"') {
7018 /* Eat double-quote. */
7019 double_quoted
= !double_quoted
;
7020 } else if (!single_quoted
&& *cp
== '\\' && *(cp
+ 1) == '"') {
7021 /* Eat backslash; copy escaped character to arg. */
7023 } else if (!single_quoted
&& !double_quoted
&& *cp
== '\\' &&
7024 (*(cp
+ 1) == '\'' || *(cp
+ 1) == ' ')) {
7025 /* Eat backslash; move escaped character. */
7027 } else if (!single_quoted
&& !double_quoted
&&
7028 (*cp
== ' ' || *cp
== '\t')) {
7029 /* Terminate argument. */
7031 /* Point sp to beginning of next argument. */
7035 /* Move regular character. */
7040 /* Terminate argument if end of string. */
7050 spawn_insert(const char *name
, const char *args
, int flags
)
7052 struct spawn_prog
*sp
;
7053 char *arg
, *cp
, *ptr
;
7055 DNPRINTF(SWM_D_SPAWN
, "spawn_insert: %s[%s]\n", name
, args
);
7057 if (args
== NULL
|| *args
== '\0')
7060 if ((sp
= calloc(1, sizeof *sp
)) == NULL
)
7061 err(1, "spawn_insert: calloc");
7062 if ((sp
->name
= strdup(name
)) == NULL
)
7063 err(1, "spawn_insert: strdup");
7065 /* Convert the arguments to an argument list. */
7066 if ((ptr
= cp
= strdup(args
)) == NULL
)
7067 err(1, "spawn_insert: strdup");
7068 while ((arg
= argsep(&ptr
)) != NULL
) {
7069 /* Null argument; skip it. */
7074 if ((sp
->argv
= realloc(sp
->argv
, sp
->argc
*
7075 sizeof *sp
->argv
)) == NULL
)
7076 err(1, "spawn_insert: realloc");
7077 if ((sp
->argv
[sp
->argc
- 1] = strdup(arg
)) == NULL
)
7078 err(1, "spawn_insert: strdup");
7084 DNPRINTF(SWM_D_SPAWN
, "arg %d: [%s]\n", sp
->argc
, sp
->argv
[sp
->argc
-1]);
7085 TAILQ_INSERT_TAIL(&spawns
, sp
, entry
);
7086 DNPRINTF(SWM_D_SPAWN
, "spawn_insert: leave\n");
7090 spawn_remove(struct spawn_prog
*sp
)
7094 DNPRINTF(SWM_D_SPAWN
, "spawn_remove: %s\n", sp
->name
);
7096 TAILQ_REMOVE(&spawns
, sp
, entry
);
7097 for (i
= 0; i
< sp
->argc
; i
++)
7103 DNPRINTF(SWM_D_SPAWN
, "spawn_remove: leave\n");
7107 spawn_find(const char *name
)
7109 struct spawn_prog
*sp
;
7111 TAILQ_FOREACH(sp
, &spawns
, entry
)
7112 if (strcasecmp(sp
->name
, name
) == 0)
7119 setspawn(const char *name
, const char *args
, int flags
)
7121 struct spawn_prog
*sp
;
7123 DNPRINTF(SWM_D_SPAWN
, "setspawn: %s\n", name
);
7128 /* Remove any old spawn under the same name. */
7129 if ((sp
= spawn_find(name
)) != NULL
)
7133 spawn_insert(name
, args
, flags
);
7135 warnx("error: setspawn: cannot find program: %s", name
);
7137 DNPRINTF(SWM_D_SPAWN
, "setspawn: leave\n");
7141 setconfspawn(const char *selector
, const char *value
, int flags
)
7145 if (selector
== NULL
|| strlen(selector
) == 0)
7148 args
= expand_tilde(value
);
7150 DNPRINTF(SWM_D_SPAWN
, "setconfspawn: [%s] [%s]\n", selector
, args
);
7152 setspawn(selector
, args
, flags
);
7155 DNPRINTF(SWM_D_SPAWN
, "setconfspawn: done.\n");
7160 validate_spawns(void)
7162 struct spawn_prog
*sp
;
7163 char which
[PATH_MAX
];
7168 RB_FOREACH(kp
, key_tree
, &keys
) {
7169 if (kp
->funcid
!= KF_SPAWN_CUSTOM
)
7173 sp
= spawn_find(kp
->spawn_name
);
7174 if (sp
== NULL
|| sp
->flags
& SWM_SPAWN_OPTIONAL
)
7177 /* verify we have the goods */
7178 snprintf(which
, sizeof which
, "which %s", sp
->argv
[0]);
7179 DNPRINTF(SWM_D_CONF
, "validate_spawns: which %s\n",
7181 for (i
= strlen("which "); i
< strlen(which
); i
++)
7182 if (which
[i
] == ' ') {
7186 if (system(which
) != 0)
7187 add_startup_exception("could not find %s",
7188 &which
[strlen("which ")]);
7195 setconfspawn("lock", "xlock", 0);
7197 setconfspawn("term", "xterm", 0);
7198 setconfspawn("spawn_term", "xterm", 0);
7200 setconfspawn("menu", "dmenu_run"
7204 " -nf $bar_font_color"
7206 " -sf $bar_color", 0);
7208 setconfspawn("search", "dmenu"
7213 " -nf $bar_font_color"
7215 " -sf $bar_color", 0);
7217 setconfspawn("name_workspace", "dmenu"
7222 " -nf $bar_font_color"
7224 " -sf $bar_color", 0);
7226 /* These are not verified for existence, even with a binding set. */
7227 setconfspawn("screenshot_all", "screenshot.sh full", SWM_SPAWN_OPTIONAL
);
7228 setconfspawn("screenshot_wind", "screenshot.sh window", SWM_SPAWN_OPTIONAL
);
7229 setconfspawn("initscr", "initscreen.sh", SWM_SPAWN_OPTIONAL
);
7233 #define SWM_MODNAME_SIZE 32
7234 #define SWM_KEY_WS "\n+ \t"
7236 parsekeys(const char *keystr
, unsigned int currmod
, unsigned int *mod
, KeySym
*ks
)
7238 char *str
, *cp
, *name
;
7241 DNPRINTF(SWM_D_KEY
, "parsekeys: enter [%s]\n", keystr
);
7242 if (mod
== NULL
|| ks
== NULL
) {
7243 DNPRINTF(SWM_D_KEY
, "parsekeys: no mod or key vars\n");
7246 if (keystr
== NULL
|| strlen(keystr
) == 0) {
7247 DNPRINTF(SWM_D_KEY
, "parsekeys: no keystr\n");
7251 if ((cp
= str
= strdup(keystr
)) == NULL
)
7252 err(1, "parsekeys: strdup");
7254 *ks
= XCB_NO_SYMBOL
;
7256 while ((name
= strsep(&cp
, SWM_KEY_WS
)) != NULL
) {
7257 DNPRINTF(SWM_D_KEY
, "parsekeys: key [%s]\n", name
);
7259 cp
+= (long)strspn(cp
, SWM_KEY_WS
);
7260 if (strncasecmp(name
, "MOD", SWM_MODNAME_SIZE
) == 0)
7262 else if (strncasecmp(name
, "Mod1", SWM_MODNAME_SIZE
) == 0)
7263 *mod
|= XCB_MOD_MASK_1
;
7264 else if (strncasecmp(name
, "Mod2", SWM_MODNAME_SIZE
) == 0)
7265 *mod
+= XCB_MOD_MASK_2
;
7266 else if (strncmp(name
, "Mod3", SWM_MODNAME_SIZE
) == 0)
7267 *mod
|= XCB_MOD_MASK_3
;
7268 else if (strncmp(name
, "Mod4", SWM_MODNAME_SIZE
) == 0)
7269 *mod
|= XCB_MOD_MASK_4
;
7270 else if (strncmp(name
, "Mod5", SWM_MODNAME_SIZE
) == 0)
7271 *mod
|= XCB_MOD_MASK_5
;
7272 else if (strncasecmp(name
, "SHIFT", SWM_MODNAME_SIZE
) == 0)
7273 *mod
|= XCB_MOD_MASK_SHIFT
;
7274 else if (strncasecmp(name
, "CONTROL", SWM_MODNAME_SIZE
) == 0)
7275 *mod
|= XCB_MOD_MASK_CONTROL
;
7277 *ks
= XStringToKeysym(name
);
7278 XConvertCase(*ks
, ks
, &uks
);
7279 if (ks
== XCB_NO_SYMBOL
) {
7281 "parsekeys: invalid key %s\n",
7290 DNPRINTF(SWM_D_KEY
, "parsekeys: leave ok\n");
7295 strdupsafe(const char *str
)
7300 return (strdup(str
));
7304 key_insert(unsigned int mod
, KeySym ks
, enum keyfuncid kfid
,
7305 const char *spawn_name
)
7309 DNPRINTF(SWM_D_KEY
, "key_insert: enter %s [%s]\n",
7310 keyfuncs
[kfid
].name
, spawn_name
);
7312 if ((kp
= malloc(sizeof *kp
)) == NULL
)
7313 err(1, "key_insert: malloc");
7318 kp
->spawn_name
= strdupsafe(spawn_name
);
7319 RB_INSERT(key_tree
, &keys
, kp
);
7321 DNPRINTF(SWM_D_KEY
, "key_insert: leave\n");
7325 key_lookup(unsigned int mod
, KeySym ks
)
7332 return (RB_FIND(key_tree
, &keys
, &kp
));
7336 key_remove(struct key
*kp
)
7338 DNPRINTF(SWM_D_KEY
, "key_remove: %s\n", keyfuncs
[kp
->funcid
].name
);
7340 RB_REMOVE(key_tree
, &keys
, kp
);
7341 free(kp
->spawn_name
);
7344 DNPRINTF(SWM_D_KEY
, "key_remove: leave\n");
7348 key_replace(struct key
*kp
, unsigned int mod
, KeySym ks
, enum keyfuncid kfid
,
7349 const char *spawn_name
)
7351 DNPRINTF(SWM_D_KEY
, "key_replace: %s [%s]\n", keyfuncs
[kp
->funcid
].name
,
7355 key_insert(mod
, ks
, kfid
, spawn_name
);
7357 DNPRINTF(SWM_D_KEY
, "key_replace: leave\n");
7361 setkeybinding(unsigned int mod
, KeySym ks
, enum keyfuncid kfid
,
7362 const char *spawn_name
)
7366 DNPRINTF(SWM_D_KEY
, "setkeybinding: enter %s [%s]\n",
7367 keyfuncs
[kfid
].name
, spawn_name
);
7369 if ((kp
= key_lookup(mod
, ks
)) != NULL
) {
7370 if (kfid
== KF_INVALID
)
7373 key_replace(kp
, mod
, ks
, kfid
, spawn_name
);
7374 DNPRINTF(SWM_D_KEY
, "setkeybinding: leave\n");
7377 if (kfid
== KF_INVALID
) {
7378 warnx("bind: Key combination already unbound.");
7379 DNPRINTF(SWM_D_KEY
, "setkeybinding: leave\n");
7383 key_insert(mod
, ks
, kfid
, spawn_name
);
7384 DNPRINTF(SWM_D_KEY
, "setkeybinding: leave\n");
7388 setconfbinding(const char *selector
, const char *value
, int flags
)
7390 enum keyfuncid kfid
;
7393 struct spawn_prog
*sp
;
7395 /* suppress unused warning since var is needed */
7398 DNPRINTF(SWM_D_KEY
, "setconfbinding: enter selector: [%s], "
7399 "value: [%s]\n", selector
, value
);
7400 if (selector
== NULL
|| strlen(selector
) == 0) {
7401 DNPRINTF(SWM_D_KEY
, "setconfbinding: unbind %s\n", value
);
7402 if (parsekeys(value
, mod_key
, &mod
, &ks
) == 0) {
7404 setkeybinding(mod
, ks
, kfid
, NULL
);
7409 /* search by key function name */
7410 for (kfid
= 0; kfid
< KF_INVALID
; (kfid
)++) {
7411 if (strncasecmp(selector
, keyfuncs
[kfid
].name
,
7412 SWM_FUNCNAME_LEN
) == 0) {
7413 DNPRINTF(SWM_D_KEY
, "setconfbinding: %s: match "
7414 "keyfunc\n", selector
);
7415 if (parsekeys(value
, mod_key
, &mod
, &ks
) == 0) {
7416 setkeybinding(mod
, ks
, kfid
, NULL
);
7422 /* search by custom spawn name */
7423 if ((sp
= spawn_find(selector
)) != NULL
) {
7424 DNPRINTF(SWM_D_KEY
, "setconfbinding: %s: match "
7425 "spawn\n", selector
);
7426 if (parsekeys(value
, mod_key
, &mod
, &ks
) == 0) {
7427 setkeybinding(mod
, ks
, KF_SPAWN_CUSTOM
,
7433 DNPRINTF(SWM_D_KEY
, "setconfbinding: no match\n");
7440 #define MODKEY_SHIFT MODKEY | XCB_MOD_MASK_SHIFT
7441 setkeybinding(MODKEY
, XK_b
, KF_BAR_TOGGLE
, NULL
);
7442 setkeybinding(MODKEY_SHIFT
, XK_b
, KF_BAR_TOGGLE_WS
,NULL
);
7443 setkeybinding(MODKEY
, XK_v
, KF_BUTTON2
, NULL
);
7444 setkeybinding(MODKEY
, XK_space
, KF_CYCLE_LAYOUT
,NULL
);
7445 setkeybinding(MODKEY_SHIFT
, XK_backslash
, KF_FLIP_LAYOUT
, NULL
);
7446 setkeybinding(MODKEY
, XK_t
, KF_FLOAT_TOGGLE
,NULL
);
7447 setkeybinding(MODKEY
, XK_m
, KF_FOCUS_MAIN
, NULL
);
7448 setkeybinding(MODKEY
, XK_j
, KF_FOCUS_NEXT
, NULL
);
7449 setkeybinding(MODKEY
, XK_Tab
, KF_FOCUS_NEXT
, NULL
);
7450 setkeybinding(MODKEY
, XK_k
, KF_FOCUS_PREV
, NULL
);
7451 setkeybinding(MODKEY_SHIFT
, XK_Tab
, KF_FOCUS_PREV
, NULL
);
7452 setkeybinding(MODKEY
, XK_u
, KF_FOCUS_URGENT
,NULL
);
7453 setkeybinding(MODKEY
, XK_e
, KF_MAXIMIZE_TOGGLE
,NULL
);
7454 setkeybinding(MODKEY_SHIFT
, XK_equal
, KF_HEIGHT_GROW
,NULL
);
7455 setkeybinding(MODKEY_SHIFT
, XK_minus
, KF_HEIGHT_SHRINK
,NULL
);
7456 setkeybinding(MODKEY
, XK_w
, KF_ICONIFY
, NULL
);
7457 setkeybinding(MODKEY
, XK_h
, KF_MASTER_SHRINK
, NULL
);
7458 setkeybinding(MODKEY
, XK_l
, KF_MASTER_GROW
, NULL
);
7459 setkeybinding(MODKEY
, XK_comma
, KF_MASTER_ADD
, NULL
);
7460 setkeybinding(MODKEY
, XK_period
, KF_MASTER_DEL
, NULL
);
7461 setkeybinding(MODKEY_SHIFT
, XK_bracketright
,KF_MOVE_DOWN
,NULL
);
7462 setkeybinding(MODKEY
, XK_bracketleft
, KF_MOVE_LEFT
,NULL
);
7463 setkeybinding(MODKEY
, XK_bracketright
,KF_MOVE_RIGHT
,NULL
);
7464 setkeybinding(MODKEY_SHIFT
, XK_bracketleft
, KF_MOVE_UP
, NULL
);
7465 setkeybinding(MODKEY_SHIFT
, XK_KP_End
, KF_MVRG_1
, NULL
);
7466 setkeybinding(MODKEY_SHIFT
, XK_KP_Down
, KF_MVRG_2
, NULL
);
7467 setkeybinding(MODKEY_SHIFT
, XK_KP_Next
, KF_MVRG_3
, NULL
);
7468 setkeybinding(MODKEY_SHIFT
, XK_KP_Left
, KF_MVRG_4
, NULL
);
7469 setkeybinding(MODKEY_SHIFT
, XK_KP_Begin
, KF_MVRG_5
, NULL
);
7470 setkeybinding(MODKEY_SHIFT
, XK_KP_Right
, KF_MVRG_6
, NULL
);
7471 setkeybinding(MODKEY_SHIFT
, XK_KP_Home
, KF_MVRG_7
, NULL
);
7472 setkeybinding(MODKEY_SHIFT
, XK_KP_Up
, KF_MVRG_8
, NULL
);
7473 setkeybinding(MODKEY_SHIFT
, XK_KP_Prior
, KF_MVRG_9
, NULL
);
7474 setkeybinding(MODKEY_SHIFT
, XK_1
, KF_MVWS_1
, NULL
);
7475 setkeybinding(MODKEY_SHIFT
, XK_2
, KF_MVWS_2
, NULL
);
7476 setkeybinding(MODKEY_SHIFT
, XK_3
, KF_MVWS_3
, NULL
);
7477 setkeybinding(MODKEY_SHIFT
, XK_4
, KF_MVWS_4
, NULL
);
7478 setkeybinding(MODKEY_SHIFT
, XK_5
, KF_MVWS_5
, NULL
);
7479 setkeybinding(MODKEY_SHIFT
, XK_6
, KF_MVWS_6
, NULL
);
7480 setkeybinding(MODKEY_SHIFT
, XK_7
, KF_MVWS_7
, NULL
);
7481 setkeybinding(MODKEY_SHIFT
, XK_8
, KF_MVWS_8
, NULL
);
7482 setkeybinding(MODKEY_SHIFT
, XK_9
, KF_MVWS_9
, NULL
);
7483 setkeybinding(MODKEY_SHIFT
, XK_0
, KF_MVWS_10
, NULL
);
7484 setkeybinding(MODKEY_SHIFT
, XK_F1
, KF_MVWS_11
, NULL
);
7485 setkeybinding(MODKEY_SHIFT
, XK_F2
, KF_MVWS_12
, NULL
);
7486 setkeybinding(MODKEY_SHIFT
, XK_F3
, KF_MVWS_13
, NULL
);
7487 setkeybinding(MODKEY_SHIFT
, XK_F4
, KF_MVWS_14
, NULL
);
7488 setkeybinding(MODKEY_SHIFT
, XK_F5
, KF_MVWS_15
, NULL
);
7489 setkeybinding(MODKEY_SHIFT
, XK_F6
, KF_MVWS_16
, NULL
);
7490 setkeybinding(MODKEY_SHIFT
, XK_F7
, KF_MVWS_17
, NULL
);
7491 setkeybinding(MODKEY_SHIFT
, XK_F8
, KF_MVWS_18
, NULL
);
7492 setkeybinding(MODKEY_SHIFT
, XK_F9
, KF_MVWS_19
, NULL
);
7493 setkeybinding(MODKEY_SHIFT
, XK_F10
, KF_MVWS_20
, NULL
);
7494 setkeybinding(MODKEY_SHIFT
, XK_F11
, KF_MVWS_21
, NULL
);
7495 setkeybinding(MODKEY_SHIFT
, XK_F12
, KF_MVWS_22
, NULL
);
7496 setkeybinding(MODKEY_SHIFT
, XK_slash
, KF_NAME_WORKSPACE
,NULL
);
7497 setkeybinding(MODKEY_SHIFT
, XK_q
, KF_QUIT
, NULL
);
7498 setkeybinding(MODKEY_SHIFT
, XK_r
, KF_RAISE_TOGGLE
,NULL
);
7499 setkeybinding(MODKEY
, XK_q
, KF_RESTART
, NULL
);
7500 setkeybinding(MODKEY
, XK_KP_End
, KF_RG_1
, NULL
);
7501 setkeybinding(MODKEY
, XK_KP_Down
, KF_RG_2
, NULL
);
7502 setkeybinding(MODKEY
, XK_KP_Next
, KF_RG_3
, NULL
);
7503 setkeybinding(MODKEY
, XK_KP_Left
, KF_RG_4
, NULL
);
7504 setkeybinding(MODKEY
, XK_KP_Begin
, KF_RG_5
, NULL
);
7505 setkeybinding(MODKEY
, XK_KP_Right
, KF_RG_6
, NULL
);
7506 setkeybinding(MODKEY
, XK_KP_Home
, KF_RG_7
, NULL
);
7507 setkeybinding(MODKEY
, XK_KP_Up
, KF_RG_8
, NULL
);
7508 setkeybinding(MODKEY
, XK_KP_Prior
, KF_RG_9
, NULL
);
7509 setkeybinding(MODKEY_SHIFT
, XK_Right
, KF_RG_NEXT
, NULL
);
7510 setkeybinding(MODKEY_SHIFT
, XK_Left
, KF_RG_PREV
, NULL
);
7511 setkeybinding(MODKEY
, XK_f
, KF_SEARCH_WIN
, NULL
);
7512 setkeybinding(MODKEY
, XK_slash
, KF_SEARCH_WORKSPACE
,NULL
);
7513 setkeybinding(MODKEY_SHIFT
, XK_i
, KF_SPAWN_CUSTOM
,"initscr");
7514 setkeybinding(MODKEY_SHIFT
, XK_Delete
, KF_SPAWN_CUSTOM
,"lock");
7515 setkeybinding(MODKEY
, XK_p
, KF_SPAWN_CUSTOM
,"menu");
7516 setkeybinding(MODKEY
, XK_s
, KF_SPAWN_CUSTOM
,"screenshot_all");
7517 setkeybinding(MODKEY_SHIFT
, XK_s
, KF_SPAWN_CUSTOM
,"screenshot_wind");
7518 setkeybinding(MODKEY_SHIFT
, XK_Return
, KF_SPAWN_CUSTOM
,"term");
7519 setkeybinding(MODKEY_SHIFT
, XK_comma
, KF_STACK_INC
, NULL
);
7520 setkeybinding(MODKEY_SHIFT
, XK_period
, KF_STACK_DEC
, NULL
);
7521 setkeybinding(MODKEY_SHIFT
, XK_space
, KF_STACK_RESET
, NULL
);
7522 setkeybinding(MODKEY_SHIFT
, XK_h
, KF_STACK_BALANCE
, NULL
);
7523 setkeybinding(MODKEY
, XK_Return
, KF_SWAP_MAIN
, NULL
);
7524 setkeybinding(MODKEY_SHIFT
, XK_j
, KF_SWAP_NEXT
, NULL
);
7525 setkeybinding(MODKEY_SHIFT
, XK_k
, KF_SWAP_PREV
, NULL
);
7526 setkeybinding(MODKEY_SHIFT
, XK_w
, KF_UNICONIFY
, NULL
);
7527 setkeybinding(MODKEY_SHIFT
, XK_v
, KF_VERSION
, NULL
);
7528 setkeybinding(MODKEY
, XK_equal
, KF_WIDTH_GROW
, NULL
);
7529 setkeybinding(MODKEY
, XK_minus
, KF_WIDTH_SHRINK
,NULL
);
7530 setkeybinding(MODKEY
, XK_x
, KF_WIND_DEL
, NULL
);
7531 setkeybinding(MODKEY_SHIFT
, XK_x
, KF_WIND_KILL
, NULL
);
7532 setkeybinding(MODKEY
, XK_1
, KF_WS_1
, NULL
);
7533 setkeybinding(MODKEY
, XK_2
, KF_WS_2
, NULL
);
7534 setkeybinding(MODKEY
, XK_3
, KF_WS_3
, NULL
);
7535 setkeybinding(MODKEY
, XK_4
, KF_WS_4
, NULL
);
7536 setkeybinding(MODKEY
, XK_5
, KF_WS_5
, NULL
);
7537 setkeybinding(MODKEY
, XK_6
, KF_WS_6
, NULL
);
7538 setkeybinding(MODKEY
, XK_7
, KF_WS_7
, NULL
);
7539 setkeybinding(MODKEY
, XK_8
, KF_WS_8
, NULL
);
7540 setkeybinding(MODKEY
, XK_9
, KF_WS_9
, NULL
);
7541 setkeybinding(MODKEY
, XK_0
, KF_WS_10
, NULL
);
7542 setkeybinding(MODKEY
, XK_F1
, KF_WS_11
, NULL
);
7543 setkeybinding(MODKEY
, XK_F2
, KF_WS_12
, NULL
);
7544 setkeybinding(MODKEY
, XK_F3
, KF_WS_13
, NULL
);
7545 setkeybinding(MODKEY
, XK_F4
, KF_WS_14
, NULL
);
7546 setkeybinding(MODKEY
, XK_F5
, KF_WS_15
, NULL
);
7547 setkeybinding(MODKEY
, XK_F6
, KF_WS_16
, NULL
);
7548 setkeybinding(MODKEY
, XK_F7
, KF_WS_17
, NULL
);
7549 setkeybinding(MODKEY
, XK_F8
, KF_WS_18
, NULL
);
7550 setkeybinding(MODKEY
, XK_F9
, KF_WS_19
, NULL
);
7551 setkeybinding(MODKEY
, XK_F10
, KF_WS_20
, NULL
);
7552 setkeybinding(MODKEY
, XK_F11
, KF_WS_21
, NULL
);
7553 setkeybinding(MODKEY
, XK_F12
, KF_WS_22
, NULL
);
7554 setkeybinding(MODKEY
, XK_Right
, KF_WS_NEXT
, NULL
);
7555 setkeybinding(MODKEY
, XK_Left
, KF_WS_PREV
, NULL
);
7556 setkeybinding(MODKEY
, XK_Up
, KF_WS_NEXT_ALL
, NULL
);
7557 setkeybinding(MODKEY
, XK_Down
, KF_WS_PREV_ALL
, NULL
);
7558 setkeybinding(MODKEY_SHIFT
, XK_Up
, KF_WS_NEXT_MOVE
,NULL
);
7559 setkeybinding(MODKEY_SHIFT
, XK_Down
, KF_WS_PREV_MOVE
,NULL
);
7560 setkeybinding(MODKEY
, XK_a
, KF_WS_PRIOR
, NULL
);
7562 setkeybinding(MODKEY_SHIFT
, XK_d
, KF_DUMPWINS
, NULL
);
7572 while (RB_EMPTY(&keys
) == 0) {
7573 kp
= RB_ROOT(&keys
);
7579 setkeymapping(const char *selector
, const char *value
, int flags
)
7581 char *keymapping_file
;
7583 /* suppress unused warnings since vars are needed */
7587 DNPRINTF(SWM_D_KEY
, "setkeymapping: enter\n");
7589 keymapping_file
= expand_tilde(value
);
7592 /* load new key bindings; if it fails, revert to default bindings */
7593 if (conf_load(keymapping_file
, SWM_CONF_KEYMAPPING
)) {
7598 free(keymapping_file
);
7600 DNPRINTF(SWM_D_KEY
, "setkeymapping: leave\n");
7605 updatenumlockmask(void)
7608 xcb_get_modifier_mapping_reply_t
*modmap_r
;
7609 xcb_keycode_t
*modmap
, kc
, *keycode
;
7613 modmap_r
= xcb_get_modifier_mapping_reply(conn
,
7614 xcb_get_modifier_mapping(conn
),
7617 modmap
= xcb_get_modifier_mapping_keycodes(modmap_r
);
7618 for (i
= 0; i
< 8; i
++) {
7619 for (j
= 0; j
< modmap_r
->keycodes_per_modifier
; j
++) {
7620 kc
= modmap
[i
* modmap_r
->keycodes_per_modifier
7622 keycode
= xcb_key_symbols_get_keycode(syms
,
7626 numlockmask
= (1 << i
);
7633 DNPRINTF(SWM_D_MISC
, "updatenumlockmask: %d\n", numlockmask
);
7640 int num_screens
, k
, j
;
7641 unsigned int modifiers
[4];
7642 xcb_keycode_t
*code
;
7644 DNPRINTF(SWM_D_MISC
, "grabkeys\n");
7645 updatenumlockmask();
7648 modifiers
[1] = numlockmask
;
7649 modifiers
[2] = XCB_MOD_MASK_LOCK
;
7650 modifiers
[3] = numlockmask
| XCB_MOD_MASK_LOCK
;
7652 num_screens
= get_screen_count();
7653 for (k
= 0; k
< num_screens
; k
++) {
7654 if (TAILQ_EMPTY(&screens
[k
].rl
))
7656 xcb_ungrab_key(conn
, XCB_GRAB_ANY
, screens
[k
].root
,
7658 RB_FOREACH(kp
, key_tree
, &keys
) {
7659 /* Skip unused ws binds. */
7660 if ((int)kp
->funcid
> KF_WS_1
+ workspace_limit
- 1 &&
7661 kp
->funcid
<= KF_WS_22
)
7664 /* Skip unused mvws binds. */
7665 if ((int)kp
->funcid
> KF_MVWS_1
+ workspace_limit
- 1 &&
7666 kp
->funcid
<= KF_MVWS_22
)
7669 if ((code
= xcb_key_symbols_get_keycode(syms
,
7671 for (j
= 0; j
< LENGTH(modifiers
); j
++)
7672 xcb_grab_key(conn
, 1,
7674 kp
->mod
| modifiers
[j
],
7675 *code
, XCB_GRAB_MODE_SYNC
,
7676 XCB_GRAB_MODE_SYNC
);
7684 grabbuttons(struct ws_win
*win
)
7686 unsigned int modifiers
[4];
7689 DNPRINTF(SWM_D_MOUSE
, "grabbuttons: win %#x\n", win
->id
);
7690 updatenumlockmask();
7693 modifiers
[1] = numlockmask
;
7694 modifiers
[2] = XCB_MOD_MASK_LOCK
;
7695 modifiers
[3] = numlockmask
| XCB_MOD_MASK_LOCK
;
7697 for (i
= 0; i
< LENGTH(buttons
); i
++)
7698 if (buttons
[i
].action
== client_click
)
7699 for (j
= 0; j
< LENGTH(modifiers
); ++j
)
7700 xcb_grab_button(conn
, 0, win
->id
, BUTTONMASK
,
7701 XCB_GRAB_MODE_SYNC
, XCB_GRAB_MODE_ASYNC
,
7702 XCB_WINDOW_NONE
, XCB_CURSOR_NONE
,
7703 buttons
[i
].button
, buttons
[i
].mask
|
7707 const char *quirkname
[] = {
7708 "NONE", /* config string for "no value" */
7716 "FOCUSONMAP_SINGLE",
7722 /* SWM_Q_DELIM: retain '|' for back compat for now (2009-08-11) */
7723 #define SWM_Q_DELIM "\n|+ \t"
7725 parsequirks(const char *qstr
, uint32_t *quirk
, int *ws
)
7727 char *str
, *cp
, *name
;
7730 if (quirk
== NULL
|| qstr
== NULL
)
7733 if ((str
= strdup(qstr
)) == NULL
)
7734 err(1, "parsequirks: strdup");
7738 while ((name
= strsep(&cp
, SWM_Q_DELIM
)) != NULL
) {
7740 cp
+= (long)strspn(cp
, SWM_Q_DELIM
);
7742 if (sscanf(name
, "WS[%d]", ws
) == 1) {
7748 for (i
= 0; i
< LENGTH(quirkname
); i
++) {
7749 if (strncasecmp(name
, quirkname
[i
],
7750 SWM_QUIRK_LEN
) == 0) {
7751 DNPRINTF(SWM_D_QUIRK
,
7752 "parsequirks: %s\n", name
);
7758 *quirk
|= 1 << (i
-1);
7762 if (i
>= LENGTH(quirkname
)) {
7763 DNPRINTF(SWM_D_QUIRK
,
7764 "parsequirks: invalid quirk [%s]\n", name
);
7775 quirk_insert(const char *class, const char *instance
, const char *name
,
7776 uint32_t quirk
, int ws
)
7780 bool failed
= false;
7782 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: class: %s, instance: %s, name: %s,"
7783 " value: %u, ws: %d\n", class, instance
, name
, quirk
, ws
);
7785 if ((qp
= malloc(sizeof *qp
)) == NULL
)
7786 err(1, "quirk_insert: malloc");
7788 if ((qp
->class = strdup(class)) == NULL
)
7789 err(1, "quirk_insert: strdup");
7790 if ((qp
->instance
= strdup(instance
)) == NULL
)
7791 err(1, "quirk_insert: strdup");
7792 if ((qp
->name
= strdup(name
)) == NULL
)
7793 err(1, "quirk_insert: strdup");
7795 if (asprintf(&str
, "^%s$", class) == -1)
7796 err(1, "quirk_insert: asprintf");
7797 if (regcomp(&qp
->regex_class
, str
, REG_EXTENDED
| REG_NOSUB
)) {
7798 add_startup_exception("regex failed to compile quirk 'class' "
7799 "field: %s", class);
7802 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: compiled: %s\n", str
);
7805 if (asprintf(&str
, "^%s$", instance
) == -1)
7806 err(1, "quirk_insert: asprintf");
7807 if (regcomp(&qp
->regex_instance
, str
, REG_EXTENDED
| REG_NOSUB
)) {
7808 add_startup_exception("regex failed to compile quirk 'instance'"
7809 " field: %s", instance
);
7812 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: compiled: %s\n", str
);
7815 if (asprintf(&str
, "^%s$", name
) == -1)
7816 err(1, "quirk_insert: asprintf");
7817 if (regcomp(&qp
->regex_name
, str
, REG_EXTENDED
| REG_NOSUB
)) {
7818 add_startup_exception("regex failed to compile quirk 'name' "
7822 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: compiled: %s\n", str
);
7826 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: regex error; skipping.\n");
7831 TAILQ_INSERT_TAIL(&quirks
, qp
, entry
);
7833 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: leave\n");
7837 quirk_remove(struct quirk
*qp
)
7839 DNPRINTF(SWM_D_QUIRK
, "quirk_remove: %s:%s [%u]\n", qp
->class,
7840 qp
->name
, qp
->quirk
);
7842 TAILQ_REMOVE(&quirks
, qp
, entry
);
7845 DNPRINTF(SWM_D_QUIRK
, "quirk_remove: leave\n");
7849 quirk_free(struct quirk
*qp
)
7851 regfree(&qp
->regex_class
);
7852 regfree(&qp
->regex_instance
);
7853 regfree(&qp
->regex_name
);
7861 quirk_replace(struct quirk
*qp
, const char *class, const char *instance
,
7862 const char *name
, uint32_t quirk
, int ws
)
7864 DNPRINTF(SWM_D_QUIRK
, "quirk_replace: %s:%s:%s [%u], ws: %d\n", qp
->class,
7865 qp
->instance
, qp
->name
, qp
->quirk
, qp
->ws
);
7868 quirk_insert(class, instance
, name
, quirk
, ws
);
7870 DNPRINTF(SWM_D_QUIRK
, "quirk_replace: leave\n");
7874 setquirk(const char *class, const char *instance
, const char *name
,
7875 uint32_t quirk
, int ws
)
7879 DNPRINTF(SWM_D_QUIRK
, "setquirk: enter %s:%s:%s [%u], ws: %d\n", class,
7880 instance
, name
, quirk
, ws
);
7882 /* Remove/replace existing quirk. */
7883 TAILQ_FOREACH(qp
, &quirks
, entry
) {
7884 if (strcmp(qp
->class, class) == 0 &&
7885 strcmp(qp
->instance
, instance
) == 0 &&
7886 strcmp(qp
->name
, name
) == 0) {
7887 if (quirk
== 0 && ws
== -1)
7890 quirk_replace(qp
, class, instance
, name
, quirk
,
7892 DNPRINTF(SWM_D_QUIRK
, "setquirk: leave\n");
7897 /* Only insert if quirk is not NONE or forced ws is set. */
7898 if (quirk
|| ws
!= -1)
7899 quirk_insert(class, instance
, name
, quirk
, ws
);
7901 DNPRINTF(SWM_D_QUIRK
, "setquirk: leave\n");
7904 /* Eat '\' in str used to escape square brackets and colon. */
7906 unescape_selector(char *str
)
7910 for (cp
= str
; *str
!= '\0'; ++str
, ++cp
) {
7911 if (*str
== '\\' && (*(str
+ 1) == ':' || *(str
+ 1) == ']' ||
7921 setconfquirk(const char *selector
, const char *value
, int flags
)
7923 char *str
, *cp
, *class;
7924 char *instance
= NULL
, *name
= NULL
;
7925 int retval
, count
= 0, ws
= -1;
7928 /* suppress unused warning since var is needed */
7931 if (selector
== NULL
|| strlen(selector
) == 0)
7934 if ((str
= strdup(selector
)) == NULL
)
7935 err(1, "setconfquirk: strdup");
7937 /* Find non-escaped colon. */
7944 for (++cp
; *cp
!= '\0'; ++cp
) {
7945 if (*cp
== ':' && *(cp
- 1) != '\\') {
7951 unescape_selector(class);
7953 instance
= class + strlen(class) + 1;
7954 unescape_selector(instance
);
7960 name
= instance
+ strlen(instance
) + 1;
7961 unescape_selector(name
);
7966 DNPRINTF(SWM_D_CONF
, "setconfquirk: class: %s, instance: %s, "
7967 "name: %s\n", class, instance
, name
);
7969 if ((retval
= parsequirks(value
, &qrks
, &ws
)) == 0)
7970 setquirk(class, instance
, name
, qrks
, ws
);
7979 setquirk("MPlayer", "xv", ".*",
7980 SWM_Q_FLOAT
| SWM_Q_FULLSCREEN
| SWM_Q_FOCUSPREV
, -1);
7981 setquirk("OpenOffice.org 3.2", "VCLSalFrame", ".*",
7983 setquirk("Firefox-bin", "firefox-bin", ".*",
7985 setquirk("Firefox", "Dialog", ".*",
7987 setquirk("Gimp", "gimp", ".*",
7988 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
7989 setquirk("XTerm", "xterm", ".*",
7990 SWM_Q_XTERM_FONTADJ
, -1);
7991 setquirk("xine", "Xine Window", ".*",
7992 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
7993 setquirk("Xitk", "Xitk Combo", ".*",
7994 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
7995 setquirk("xine", "xine Panel", ".*",
7996 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
7997 setquirk("Xitk", "Xine Window", ".*",
7998 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
7999 setquirk("xine", "xine Video Fullscreen Window", ".*",
8000 SWM_Q_FULLSCREEN
| SWM_Q_FLOAT
, -1);
8001 setquirk("pcb", "pcb", ".*",
8003 setquirk("SDL_App", "SDL_App", ".*",
8004 SWM_Q_FLOAT
| SWM_Q_FULLSCREEN
, -1);
8007 /* conf file stuff */
8008 #define SWM_CONF_FILE "spectrwm.conf"
8009 #define SWM_CONF_FILE_OLD "scrotwm.conf"
8013 SWM_S_BAR_AT_BOTTOM
,
8014 SWM_S_BAR_BORDER_WIDTH
,
8017 SWM_S_BAR_ENABLED_WS
,
8022 SWM_S_BOUNDARY_WIDTH
,
8023 SWM_S_CLOCK_ENABLED
,
8026 SWM_S_CYCLE_VISIBLE
,
8028 SWM_S_DISABLE_BORDER
,
8030 SWM_S_FOCUS_CLOSE_WRAP
,
8031 SWM_S_FOCUS_DEFAULT
,
8033 SWM_S_ICONIC_ENABLED
,
8034 SWM_S_JAVA_WORKAROUND
,
8035 SWM_S_REGION_PADDING
,
8040 SWM_S_STACK_ENABLED
,
8043 SWM_S_URGENT_COLLAPSE
,
8044 SWM_S_URGENT_ENABLED
,
8045 SWM_S_VERBOSE_LAYOUT
,
8047 SWM_S_WINDOW_CLASS_ENABLED
,
8048 SWM_S_WINDOW_INSTANCE_ENABLED
,
8049 SWM_S_WINDOW_NAME_ENABLED
,
8050 SWM_S_WORKSPACE_LIMIT
,
8051 SWM_S_WORKSPACE_NAME
,
8055 setconfvalue(const char *selector
, const char *value
, int flags
)
8057 struct workspace
*ws
;
8058 int i
, ws_id
, num_screens
;
8059 char *b
, *str
, s
[1024];
8062 case SWM_S_BAR_ACTION
:
8064 if ((bar_argv
[0] = expand_tilde(value
)) == NULL
)
8065 err(1, "setconfvalue: bar_action");
8067 case SWM_S_BAR_AT_BOTTOM
:
8068 bar_at_bottom
= (atoi(value
) != 0);
8070 case SWM_S_BAR_BORDER_WIDTH
:
8071 bar_border_width
= atoi(value
);
8072 if (bar_border_width
< 0)
8073 bar_border_width
= 0;
8075 case SWM_S_BAR_DELAY
:
8076 /* No longer needed; leave to not break old conf files. */
8078 case SWM_S_BAR_ENABLED
:
8079 bar_enabled
= (atoi(value
) != 0);
8081 case SWM_S_BAR_ENABLED_WS
:
8082 ws_id
= atoi(selector
) - 1;
8083 if (ws_id
< 0 || ws_id
>= workspace_limit
)
8084 errx(1, "setconfvalue: bar_enabled_ws: invalid "
8085 "workspace %d.", ws_id
+ 1);
8087 num_screens
= get_screen_count();
8088 for (i
= 0; i
< num_screens
; i
++) {
8089 ws
= (struct workspace
*)&screens
[i
].ws
;
8090 ws
[ws_id
].bar_enabled
= (atoi(value
) != 0);
8093 case SWM_S_BAR_FONT
:
8095 if (asprintf(&bar_fonts
, "%s,%s", value
, bar_fonts
) == -1)
8096 err(1, "setconfvalue: asprintf: failed to allocate "
8097 "memory for bar_fonts.");
8100 /* If already in xft mode, then we are done. */
8101 if (!bar_font_legacy
)
8104 if ((str
= strdup(value
)) == NULL
)
8105 err(1, "setconfvalue: strdup");
8107 /* If there are any non-XLFD entries, switch to Xft mode. */
8108 while ((b
= strsep(&str
, ",")) != NULL
) {
8112 bar_font_legacy
= false;
8119 case SWM_S_BAR_FORMAT
:
8121 if ((bar_format
= strdup(value
)) == NULL
)
8122 err(1, "setconfvalue: bar_format");
8124 case SWM_S_BAR_JUSTIFY
:
8125 if (strcmp(value
, "left") == 0)
8126 bar_justify
= SWM_BAR_JUSTIFY_LEFT
;
8127 else if (strcmp(value
, "center") == 0)
8128 bar_justify
= SWM_BAR_JUSTIFY_CENTER
;
8129 else if (strcmp(value
, "right") == 0)
8130 bar_justify
= SWM_BAR_JUSTIFY_RIGHT
;
8132 errx(1, "invalid bar_justify");
8134 case SWM_S_BORDER_WIDTH
:
8135 border_width
= atoi(value
);
8136 if (border_width
< 0)
8139 case SWM_S_BOUNDARY_WIDTH
:
8140 boundary_width
= atoi(value
);
8141 if (boundary_width
< 0)
8144 case SWM_S_CLOCK_ENABLED
:
8145 clock_enabled
= (atoi(value
) != 0);
8147 case SWM_S_CLOCK_FORMAT
:
8148 #ifndef SWM_DENY_CLOCK_FORMAT
8150 if ((clock_format
= strdup(value
)) == NULL
)
8151 err(1, "setconfvalue: clock_format");
8154 case SWM_S_CYCLE_EMPTY
:
8155 cycle_empty
= (atoi(value
) != 0);
8157 case SWM_S_CYCLE_VISIBLE
:
8158 cycle_visible
= (atoi(value
) != 0);
8160 case SWM_S_DIALOG_RATIO
:
8161 dialog_ratio
= atof(value
);
8162 if (dialog_ratio
> 1.0 || dialog_ratio
<= .3)
8165 case SWM_S_DISABLE_BORDER
:
8166 disable_border
= (atoi(value
) != 0);
8168 case SWM_S_FOCUS_CLOSE
:
8169 if (strcmp(value
, "first") == 0)
8170 focus_close
= SWM_STACK_BOTTOM
;
8171 else if (strcmp(value
, "last") == 0)
8172 focus_close
= SWM_STACK_TOP
;
8173 else if (strcmp(value
, "next") == 0)
8174 focus_close
= SWM_STACK_ABOVE
;
8175 else if (strcmp(value
, "previous") == 0)
8176 focus_close
= SWM_STACK_BELOW
;
8178 errx(1, "focus_close");
8180 case SWM_S_FOCUS_CLOSE_WRAP
:
8181 focus_close_wrap
= (atoi(value
) != 0);
8183 case SWM_S_FOCUS_DEFAULT
:
8184 if (strcmp(value
, "last") == 0)
8185 focus_default
= SWM_STACK_TOP
;
8186 else if (strcmp(value
, "first") == 0)
8187 focus_default
= SWM_STACK_BOTTOM
;
8189 errx(1, "focus_default");
8191 case SWM_S_FOCUS_MODE
:
8192 if (strcmp(value
, "default") == 0)
8193 focus_mode
= SWM_FOCUS_DEFAULT
;
8194 else if (strcmp(value
, "follow") == 0 ||
8195 strcmp(value
, "follow_cursor") == 0)
8196 focus_mode
= SWM_FOCUS_FOLLOW
;
8197 else if (strcmp(value
, "manual") == 0)
8198 focus_mode
= SWM_FOCUS_MANUAL
;
8200 errx(1, "focus_mode");
8202 case SWM_S_ICONIC_ENABLED
:
8203 iconic_enabled
= (atoi(value
) != 0);
8205 case SWM_S_JAVA_WORKAROUND
:
8206 java_workaround
= (atoi(value
) != 0);
8208 case SWM_S_REGION_PADDING
:
8209 region_padding
= atoi(value
);
8210 if (region_padding
< 0)
8213 case SWM_S_SPAWN_ORDER
:
8214 if (strcmp(value
, "first") == 0)
8215 spawn_position
= SWM_STACK_BOTTOM
;
8216 else if (strcmp(value
, "last") == 0)
8217 spawn_position
= SWM_STACK_TOP
;
8218 else if (strcmp(value
, "next") == 0)
8219 spawn_position
= SWM_STACK_ABOVE
;
8220 else if (strcmp(value
, "previous") == 0)
8221 spawn_position
= SWM_STACK_BELOW
;
8223 errx(1, "spawn_position");
8225 case SWM_S_SPAWN_TERM
:
8226 setconfspawn("term", value
, 0);
8227 setconfspawn("spawn_term", value
, 0);
8230 /* No longer needed; leave to not break old conf files. */
8232 case SWM_S_SS_ENABLED
:
8233 /* No longer needed; leave to not break old conf files. */
8235 case SWM_S_STACK_ENABLED
:
8236 stack_enabled
= (atoi(value
) != 0);
8238 case SWM_S_TERM_WIDTH
:
8239 term_width
= atoi(value
);
8243 case SWM_S_TILE_GAP
:
8244 tile_gap
= atoi(value
);
8246 case SWM_S_URGENT_COLLAPSE
:
8247 urgent_collapse
= (atoi(value
) != 0);
8249 case SWM_S_URGENT_ENABLED
:
8250 urgent_enabled
= (atoi(value
) != 0);
8252 case SWM_S_VERBOSE_LAYOUT
:
8253 verbose_layout
= (atoi(value
) != 0);
8254 for (i
= 0; layouts
[i
].l_stack
!= NULL
; i
++) {
8256 layouts
[i
].l_string
= fancy_stacker
;
8258 layouts
[i
].l_string
= plain_stacker
;
8261 case SWM_S_WARP_POINTER
:
8262 warp_pointer
= (atoi(value
) != 0);
8264 case SWM_S_WINDOW_CLASS_ENABLED
:
8265 window_class_enabled
= (atoi(value
) != 0);
8267 case SWM_S_WINDOW_INSTANCE_ENABLED
:
8268 window_instance_enabled
= (atoi(value
) != 0);
8270 case SWM_S_WINDOW_NAME_ENABLED
:
8271 window_name_enabled
= (atoi(value
) != 0);
8273 case SWM_S_WORKSPACE_LIMIT
:
8274 workspace_limit
= atoi(value
);
8275 if (workspace_limit
> SWM_WS_MAX
)
8276 workspace_limit
= SWM_WS_MAX
;
8277 else if (workspace_limit
< 1)
8278 workspace_limit
= 1;
8280 ewmh_update_desktops();
8282 case SWM_S_WORKSPACE_NAME
:
8283 if (getenv("SWM_STARTED") != NULL
)
8287 if (sscanf(value
, "ws[%d]:%1023c", &ws_id
, s
) != 2)
8288 errx(1, "invalid entry, should be 'ws[<idx>]:name'");
8290 if (ws_id
< 0 || ws_id
>= workspace_limit
)
8291 errx(1, "setconfvalue: workspace_name: invalid "
8292 "workspace %d.", ws_id
+ 1);
8294 num_screens
= get_screen_count();
8295 for (i
= 0; i
< num_screens
; ++i
) {
8296 ws
= (struct workspace
*)&screens
[i
].ws
;
8298 if (strlen(s
) > 0) {
8299 free(ws
[ws_id
].name
);
8300 if ((ws
[ws_id
].name
= strdup(s
)) == NULL
)
8301 err(1, "setconfvalue: workspace_name.");
8303 ewmh_update_desktop_names();
8304 ewmh_get_desktop_names();
8315 setconfmodkey(const char *selector
, const char *value
, int flags
)
8317 /* suppress unused warnings since vars are needed */
8321 if (strncasecmp(value
, "Mod1", strlen("Mod1")) == 0)
8322 update_modkey(XCB_MOD_MASK_1
);
8323 else if (strncasecmp(value
, "Mod2", strlen("Mod2")) == 0)
8324 update_modkey(XCB_MOD_MASK_2
);
8325 else if (strncasecmp(value
, "Mod3", strlen("Mod3")) == 0)
8326 update_modkey(XCB_MOD_MASK_3
);
8327 else if (strncasecmp(value
, "Mod4", strlen("Mod4")) == 0)
8328 update_modkey(XCB_MOD_MASK_4
);
8329 else if (strncasecmp(value
, "Mod5", strlen("Mod5")) == 0)
8330 update_modkey(XCB_MOD_MASK_5
);
8337 setconfmousebuttonmove(const char *selector
, const char *value
, int flags
)
8339 /* suppress unused warnings since vars are needed */
8343 if (strncasecmp(value
, "But1", strlen("But1")) == 0) {
8344 if (!update_mousebutton(0, XCB_BUTTON_INDEX_1
))
8346 } else if (strncasecmp(value
, "But2", strlen("But2")) == 0) {
8347 if (!update_mousebutton(0, XCB_BUTTON_INDEX_2
))
8349 } else if (strncasecmp(value
, "But3", strlen("But3")) == 0) {
8350 if (!update_mousebutton(0, XCB_BUTTON_INDEX_3
))
8358 setconfmousebuttonresize(const char *selector
, const char *value
, int flags
)
8360 /* suppress unused warnings since vars are needed */
8364 if (strncasecmp(value
, "But1", strlen("But1")) == 0) {
8365 if (!update_mousebutton(1, XCB_BUTTON_INDEX_1
))
8367 } else if (strncasecmp(value
, "But2", strlen("But2")) == 0) {
8368 if (!update_mousebutton(1, XCB_BUTTON_INDEX_2
))
8370 } else if (strncasecmp(value
, "But3", strlen("But3")) == 0) {
8371 if (!update_mousebutton(1, XCB_BUTTON_INDEX_3
))
8379 setconfcolor(const char *selector
, const char *value
, int flags
)
8381 int first
, last
, i
= 0, num_screens
;
8383 num_screens
= get_screen_count();
8385 /* conf screen indices begin at 1; treat vals <= 0 as 'all screens.' */
8386 if (selector
== NULL
|| strlen(selector
) == 0 ||
8387 (last
= atoi(selector
) - 1) < 0) {
8389 last
= num_screens
- 1;
8394 if (last
>= num_screens
) {
8395 add_startup_exception("invalid screen index: %d out of bounds "
8396 "(maximum %d)", last
+ 1, num_screens
);
8400 for (i
= first
; i
<= last
; ++i
) {
8401 setscreencolor(value
, i
, flags
);
8404 * When setting focus/unfocus colors, we need to also
8405 * set maximize colors to match if they haven't been customized.
8407 if (flags
== SWM_S_COLOR_FOCUS
&&
8408 !screens
[i
].c
[SWM_S_COLOR_FOCUS_MAXIMIZED
].manual
)
8409 setscreencolor(value
, i
, SWM_S_COLOR_FOCUS_MAXIMIZED
);
8410 else if (flags
== SWM_S_COLOR_UNFOCUS
&&
8411 !screens
[i
].c
[SWM_S_COLOR_UNFOCUS_MAXIMIZED
].manual
)
8412 setscreencolor(value
, i
, SWM_S_COLOR_UNFOCUS_MAXIMIZED
);
8414 screens
[i
].c
[flags
].manual
= 1;
8421 setconfregion(const char *selector
, const char *value
, int flags
)
8423 /* suppress unused warnings since vars are needed */
8427 custom_region(value
);
8432 setautorun(const char *selector
, const char *value
, int flags
)
8442 /* suppress unused warnings since vars are needed */
8446 if (getenv("SWM_STARTED"))
8450 if (sscanf(value
, "ws[%d]:%1023c", &ws_id
, s
) != 2)
8451 errx(1, "invalid autorun entry, should be 'ws[<idx>]:command'");
8453 if (ws_id
< 0 || ws_id
>= workspace_limit
)
8454 errx(1, "autorun: invalid workspace %d", ws_id
+ 1);
8456 sp
= expand_tilde((char *)&s
);
8459 * This is a little intricate
8461 * If the pid already exists we simply reuse it because it means it was
8462 * used before AND not claimed by manage_window. We get away with
8463 * altering it in the parent after INSERT because this can not be a race
8466 while ((ap
= strsep(&sp
, " \t")) != NULL
) {
8469 DNPRINTF(SWM_D_SPAWN
, "setautorun: arg [%s]\n", ap
);
8471 if ((a
.argv
= realloc(a
.argv
, argc
* sizeof(char *))) == NULL
)
8472 err(1, "setautorun: realloc");
8473 a
.argv
[argc
- 1] = ap
;
8477 if ((a
.argv
= realloc(a
.argv
, (argc
+ 1) * sizeof(char *))) == NULL
)
8478 err(1, "setautorun: realloc");
8479 a
.argv
[argc
] = NULL
;
8481 if ((pid
= fork()) == 0) {
8482 spawn(ws_id
, &a
, true);
8491 p
= calloc(1, sizeof *p
);
8494 TAILQ_INSERT_TAIL(&pidlist
, p
, entry
);
8504 setlayout(const char *selector
, const char *value
, int flags
)
8506 struct workspace
*ws
;
8507 int ws_id
, i
, x
, mg
, ma
, si
, ar
;
8508 int st
= SWM_V_STACK
, num_screens
;
8512 /* suppress unused warnings since vars are needed */
8516 if (getenv("SWM_STARTED"))
8520 if (sscanf(value
, "ws[%d]:%d:%d:%d:%d:%1023c",
8521 &ws_id
, &mg
, &ma
, &si
, &ar
, s
) != 6)
8522 errx(1, "invalid layout entry, should be 'ws[<idx>]:"
8523 "<master_grow>:<master_add>:<stack_inc>:<always_raise>:"
8526 if (ws_id
< 0 || ws_id
>= workspace_limit
)
8527 errx(1, "layout: invalid workspace %d", ws_id
+ 1);
8529 if (strcasecmp(s
, "vertical") == 0)
8531 else if (strcasecmp(s
, "vertical_flip") == 0) {
8534 } else if (strcasecmp(s
, "horizontal") == 0)
8536 else if (strcasecmp(s
, "horizontal_flip") == 0) {
8539 } else if (strcasecmp(s
, "fullscreen") == 0)
8542 errx(1, "invalid layout entry, should be 'ws[<idx>]:"
8543 "<master_grow>:<master_add>:<stack_inc>:<always_raise>:"
8546 num_screens
= get_screen_count();
8547 for (i
= 0; i
< num_screens
; i
++) {
8548 ws
= (struct workspace
*)&screens
[i
].ws
;
8549 ws
[ws_id
].cur_layout
= &layouts
[st
];
8551 ws
[ws_id
].always_raise
= (ar
!= 0);
8552 if (st
== SWM_MAX_STACK
)
8556 for (x
= 0; x
< abs(mg
); x
++) {
8557 ws
[ws_id
].cur_layout
->l_config(&ws
[ws_id
],
8558 mg
>= 0 ? SWM_ARG_ID_MASTERGROW
:
8559 SWM_ARG_ID_MASTERSHRINK
);
8562 for (x
= 0; x
< abs(ma
); x
++) {
8563 ws
[ws_id
].cur_layout
->l_config(&ws
[ws_id
],
8564 ma
>= 0 ? SWM_ARG_ID_MASTERADD
:
8565 SWM_ARG_ID_MASTERDEL
);
8568 for (x
= 0; x
< abs(si
); x
++) {
8569 ws
[ws_id
].cur_layout
->l_config(&ws
[ws_id
],
8570 si
>= 0 ? SWM_ARG_ID_STACKINC
:
8571 SWM_ARG_ID_STACKDEC
);
8575 ws
[ws_id
].cur_layout
->l_config(&ws
[ws_id
],
8576 SWM_ARG_ID_FLIPLAYOUT
);
8583 /* config options */
8584 struct config_option
{
8586 int (*func
)(const char*, const char*, int);
8589 struct config_option configopt
[] = {
8590 { "autorun", setautorun
, 0 },
8591 { "bar_action", setconfvalue
, SWM_S_BAR_ACTION
},
8592 { "bar_at_bottom", setconfvalue
, SWM_S_BAR_AT_BOTTOM
},
8593 { "bar_border", setconfcolor
, SWM_S_COLOR_BAR_BORDER
},
8594 { "bar_border_unfocus", setconfcolor
, SWM_S_COLOR_BAR_BORDER_UNFOCUS
},
8595 { "bar_border_width", setconfvalue
, SWM_S_BAR_BORDER_WIDTH
},
8596 { "bar_color", setconfcolor
, SWM_S_COLOR_BAR
},
8597 { "bar_delay", setconfvalue
, SWM_S_BAR_DELAY
},
8598 { "bar_enabled", setconfvalue
, SWM_S_BAR_ENABLED
},
8599 { "bar_enabled_ws", setconfvalue
, SWM_S_BAR_ENABLED_WS
},
8600 { "bar_font", setconfvalue
, SWM_S_BAR_FONT
},
8601 { "bar_font_color", setconfcolor
, SWM_S_COLOR_BAR_FONT
},
8602 { "bar_format", setconfvalue
, SWM_S_BAR_FORMAT
},
8603 { "bar_justify", setconfvalue
, SWM_S_BAR_JUSTIFY
},
8604 { "bind", setconfbinding
, 0 },
8605 { "border_width", setconfvalue
, SWM_S_BORDER_WIDTH
},
8606 { "boundary_width", setconfvalue
, SWM_S_BOUNDARY_WIDTH
},
8607 { "clock_enabled", setconfvalue
, SWM_S_CLOCK_ENABLED
},
8608 { "clock_format", setconfvalue
, SWM_S_CLOCK_FORMAT
},
8609 { "color_focus", setconfcolor
, SWM_S_COLOR_FOCUS
},
8610 { "color_focus_maximized", setconfcolor
, SWM_S_COLOR_FOCUS_MAXIMIZED
},
8611 { "color_unfocus", setconfcolor
, SWM_S_COLOR_UNFOCUS
},
8612 { "color_unfocus_maximized", setconfcolor
, SWM_S_COLOR_UNFOCUS_MAXIMIZED
},
8613 { "cycle_empty", setconfvalue
, SWM_S_CYCLE_EMPTY
},
8614 { "cycle_visible", setconfvalue
, SWM_S_CYCLE_VISIBLE
},
8615 { "dialog_ratio", setconfvalue
, SWM_S_DIALOG_RATIO
},
8616 { "disable_border", setconfvalue
, SWM_S_DISABLE_BORDER
},
8617 { "focus_close", setconfvalue
, SWM_S_FOCUS_CLOSE
},
8618 { "focus_close_wrap", setconfvalue
, SWM_S_FOCUS_CLOSE_WRAP
},
8619 { "focus_default", setconfvalue
, SWM_S_FOCUS_DEFAULT
},
8620 { "focus_mode", setconfvalue
, SWM_S_FOCUS_MODE
},
8621 { "iconic_enabled", setconfvalue
, SWM_S_ICONIC_ENABLED
},
8622 { "java_workaround", setconfvalue
, SWM_S_JAVA_WORKAROUND
},
8623 { "keyboard_mapping", setkeymapping
, 0 },
8624 { "layout", setlayout
, 0 },
8625 { "modkey", setconfmodkey
, 0 },
8626 { "move_button", setconfmousebuttonmove
, 0 },
8627 { "resize_button", setconfmousebuttonresize
, 0 },
8628 { "program", setconfspawn
, 0 },
8629 { "quirk", setconfquirk
, 0 },
8630 { "region", setconfregion
, 0 },
8631 { "region_padding", setconfvalue
, SWM_S_REGION_PADDING
},
8632 { "screenshot_app", setconfvalue
, SWM_S_SS_APP
},
8633 { "screenshot_enabled", setconfvalue
, SWM_S_SS_ENABLED
},
8634 { "spawn_position", setconfvalue
, SWM_S_SPAWN_ORDER
},
8635 { "spawn_term", setconfvalue
, SWM_S_SPAWN_TERM
},
8636 { "stack_enabled", setconfvalue
, SWM_S_STACK_ENABLED
},
8637 { "term_width", setconfvalue
, SWM_S_TERM_WIDTH
},
8638 { "tile_gap", setconfvalue
, SWM_S_TILE_GAP
},
8639 { "title_class_enabled", setconfvalue
, SWM_S_WINDOW_CLASS_ENABLED
}, /* For backwards compat. */
8640 { "title_name_enabled", setconfvalue
, SWM_S_WINDOW_INSTANCE_ENABLED
}, /* For backwards compat. */
8641 { "urgent_collapse", setconfvalue
, SWM_S_URGENT_COLLAPSE
},
8642 { "urgent_enabled", setconfvalue
, SWM_S_URGENT_ENABLED
},
8643 { "verbose_layout", setconfvalue
, SWM_S_VERBOSE_LAYOUT
},
8644 { "warp_pointer", setconfvalue
, SWM_S_WARP_POINTER
},
8645 { "window_class_enabled", setconfvalue
, SWM_S_WINDOW_CLASS_ENABLED
},
8646 { "window_instance_enabled", setconfvalue
, SWM_S_WINDOW_INSTANCE_ENABLED
},
8647 { "window_name_enabled", setconfvalue
, SWM_S_WINDOW_NAME_ENABLED
},
8648 { "workspace_limit", setconfvalue
, SWM_S_WORKSPACE_LIMIT
},
8649 { "name", setconfvalue
, SWM_S_WORKSPACE_NAME
},
8653 _add_startup_exception(const char *fmt
, va_list ap
)
8655 if (vasprintf(&startup_exception
, fmt
, ap
) == -1)
8656 warn("%s: asprintf", __func__
);
8660 add_startup_exception(const char *fmt
, ...)
8666 if (startup_exception
)
8669 /* force bar to be enabled due to exception */
8673 _add_startup_exception(fmt
, ap
);
8678 conf_load(const char *filename
, int keymapping
)
8681 char *line
= NULL
, *cp
, *ce
, *optsub
, *optval
= NULL
;
8682 size_t linelen
, lineno
= 0;
8683 int wordlen
, i
, optidx
, count
;
8684 struct config_option
*opt
= NULL
;
8686 DNPRINTF(SWM_D_CONF
, "conf_load: begin\n");
8688 if (filename
== NULL
) {
8689 warnx("conf_load: no filename");
8693 DNPRINTF(SWM_D_CONF
, "conf_load: open %s\n", filename
);
8695 if ((config
= fopen(filename
, "r")) == NULL
) {
8696 warn("conf_load: fopen: %s", filename
);
8700 while (!feof(config
)) {
8704 if ((line
= fparseln(config
, &linelen
, &lineno
, NULL
,
8705 FPARSELN_UNESCCOMM
| FPARSELN_UNESCCONT
)) == NULL
) {
8707 err(1, "%s", filename
);
8712 cp
+= strspn(cp
, " \t\n"); /* eat whitespace */
8713 if (cp
[0] == '\0') {
8717 /* get config option */
8718 wordlen
= strcspn(cp
, "=[ \t\n");
8720 add_startup_exception("%s: line %zd: no option found",
8725 for (i
= 0; i
< LENGTH(configopt
); i
++) {
8726 opt
= &configopt
[i
];
8727 if (strncasecmp(cp
, opt
->optname
, wordlen
) == 0 &&
8728 (int)strlen(opt
->optname
) == wordlen
) {
8734 add_startup_exception("%s: line %zd: unknown option "
8735 "%.*s", filename
, lineno
, wordlen
, cp
);
8738 if (keymapping
&& opt
&& strcmp(opt
->optname
, "bind")) {
8739 add_startup_exception("%s: line %zd: invalid option "
8740 "%.*s", filename
, lineno
, wordlen
, cp
);
8744 cp
+= strspn(cp
, " \t\n"); /* eat whitespace */
8746 /* get [selector] if any */
8751 /* Get length of selector. */
8752 for (ce
= ++cp
; *ce
!= '\0'; ++ce
) {
8753 /* Find matching (not escaped) bracket. */
8754 if (*ce
== ']' && *(ce
- 1) != '\\') {
8761 add_startup_exception("%s: line %zd: syntax "
8762 "error: unterminated selector", filename
,
8767 /* ce points at ']'; terminate optsub. */
8772 cp
+= strspn(cp
, "= \t\n"); /* eat trailing */
8775 if (strlen(optval
) == 0) {
8776 add_startup_exception("%s: line %zd: must supply value "
8777 "to %s", filename
, lineno
,
8778 configopt
[optidx
].optname
);
8781 /* call function to deal with it all */
8782 if (configopt
[optidx
].func(optsub
, optval
,
8783 configopt
[optidx
].funcflags
) != 0) {
8784 add_startup_exception("%s: line %zd: invalid data for "
8785 "%s", filename
, lineno
, configopt
[optidx
].optname
);
8794 if (mouse_button_move
== mouse_button_resize
) {
8795 add_startup_exception("%s: move and resize mouse buttons match",
8799 DNPRINTF(SWM_D_CONF
, "conf_load: end\n");
8805 set_child_transient(struct ws_win
*win
, xcb_window_t
*trans
)
8807 struct ws_win
*parent
, *w
;
8808 struct swm_region
*r
;
8809 struct workspace
*ws
;
8810 xcb_icccm_wm_hints_t wmh
;
8812 parent
= find_window(win
->transient
);
8814 parent
->focus_child
= win
;
8816 DNPRINTF(SWM_D_MISC
, "set_child_transient: parent doesn't exist"
8817 " for %#x trans %#x\n", win
->id
, win
->transient
);
8819 r
= root_to_region(win
->s
->root
, SWM_CK_ALL
);
8821 /* parent doen't exist in our window list */
8822 TAILQ_FOREACH(w
, &ws
->winlist
, entry
) {
8823 if (xcb_icccm_get_wm_hints_reply(conn
,
8824 xcb_icccm_get_wm_hints(conn
, w
->id
),
8826 warnx("can't get hints for %#x", w
->id
);
8830 if (win
->hints
.window_group
!= wmh
.window_group
)
8833 w
->focus_child
= win
;
8834 win
->transient
= w
->id
;
8836 DNPRINTF(SWM_D_MISC
, "set_child_transient: adjusting "
8837 "transient to %#x\n", win
->transient
);
8844 window_get_pid(xcb_window_t win
)
8849 xcb_get_property_cookie_t pc
;
8850 xcb_get_property_reply_t
*pr
;
8852 apid
= get_atom_from_string("_NET_WM_PID");
8853 if (apid
== XCB_ATOM_NONE
)
8856 pc
= xcb_get_property(conn
, 0, win
, apid
, XCB_ATOM_CARDINAL
, 0, 1);
8857 pr
= xcb_get_property_reply(conn
, pc
, NULL
);
8860 if (pr
->type
!= XCB_ATOM_CARDINAL
) {
8865 if (pr
->type
== apid
&& pr
->format
== 32)
8866 ret
= *((pid_t
*)xcb_get_property_value(pr
));
8872 apid
= get_atom_from_string("_SWM_PID");
8873 pc
= xcb_get_property(conn
, 0, win
, apid
, XCB_ATOM_STRING
,
8875 pr
= xcb_get_property_reply(conn
, pc
, NULL
);
8878 if (pr
->type
!= apid
) {
8883 ret
= (pid_t
)strtonum(xcb_get_property_value(pr
), 0, INT_MAX
, &errstr
);
8890 get_swm_ws(xcb_window_t id
)
8896 xcb_get_property_reply_t
*gpr
;
8898 gpr
= xcb_get_property_reply(conn
,
8899 xcb_get_property(conn
, 0, id
, a_swm_ws
,
8900 XCB_ATOM_STRING
, 0, SWM_PROPLEN
),
8905 proplen
= xcb_get_property_value_length(gpr
);
8907 prop
= malloc(proplen
+ 1);
8910 xcb_get_property_value(gpr
),
8912 prop
[proplen
] = '\0';
8919 DNPRINTF(SWM_D_PROP
, "get_swm_ws: _SWM_WS: %s\n", prop
);
8920 ws_idx
= (int)strtonum(prop
, 0, workspace_limit
- 1, &errstr
);
8922 DNPRINTF(SWM_D_PROP
, "get_swm_ws: win #%s: %s",
8932 get_ws_idx(struct ws_win
*win
)
8934 xcb_get_property_reply_t
*gpr
;
8940 gpr
= xcb_get_property_reply(conn
,
8941 xcb_get_property(conn
, 0, win
->id
, ewmh
[_NET_WM_DESKTOP
].atom
,
8942 XCB_ATOM_CARDINAL
, 0, 1),
8945 if (gpr
->type
== XCB_ATOM_CARDINAL
&& gpr
->format
== 32)
8946 ws_idx
= *((int *)xcb_get_property_value(gpr
));
8950 if (ws_idx
== -1 && !(win
->quirks
& SWM_Q_IGNORESPAWNWS
))
8951 ws_idx
= get_swm_ws(win
->id
);
8953 if (ws_idx
> workspace_limit
- 1 || ws_idx
< -1)
8956 DNPRINTF(SWM_D_PROP
, "get_ws_idx: win %#x, ws_idx: %d\n", win
->id
,
8963 manage_window(xcb_window_t id
, int spawn_pos
, bool mapped
)
8965 struct ws_win
*win
, *ww
;
8966 struct swm_region
*r
;
8969 xcb_get_geometry_reply_t
*gr
;
8970 xcb_window_t trans
= XCB_WINDOW_NONE
;
8971 uint32_t i
, wa
[2], new_flags
;
8972 int ws_idx
, force_ws
= -1;
8973 char *class, *instance
, *name
;
8975 if ((win
= find_window(id
)) != NULL
) {
8976 DNPRINTF(SWM_D_MISC
, "manage_window: win %#x already "
8977 "managed; skipping.)\n", id
);
8978 return (win
); /* Already managed. */
8981 /* See if window is on the unmanaged list. */
8982 if ((win
= find_unmanaged_window(id
)) != NULL
) {
8983 DNPRINTF(SWM_D_MISC
, "manage_window: win %#x found on "
8984 "unmanaged list.\n", id
);
8985 TAILQ_REMOVE(&win
->ws
->unmanagedlist
, win
, entry
);
8988 set_child_transient(win
, &trans
);
8992 DNPRINTF(SWM_D_MISC
, "manage_window: win %#x is new.\n", id
);
8995 /* Try to get initial window geometry. */
8996 gr
= xcb_get_geometry_reply(conn
, xcb_get_geometry(conn
, id
), NULL
);
8998 DNPRINTF(SWM_D_MISC
, "manage_window: get geometry failed.\n");
9002 /* Create and initialize ws_win object. */
9003 if ((win
= calloc(1, sizeof(struct ws_win
))) == NULL
)
9004 err(1, "manage_window: calloc: failed to allocate memory for "
9009 /* Figureout which region the window belongs to. */
9010 r
= root_to_region(gr
->root
, SWM_CK_ALL
);
9012 /* Ignore window border if there is one. */
9013 WIDTH(win
) = gr
->width
;
9014 HEIGHT(win
) = gr
->height
;
9015 X(win
) = gr
->x
+ gr
->border_width
- border_width
;
9016 Y(win
) = gr
->y
+ gr
->border_width
- border_width
;
9017 win
->bordered
= true;
9018 win
->mapped
= mapped
;
9019 win
->s
= r
->s
; /* this never changes */
9023 /* Select which X events to monitor and set border pixel color. */
9024 wa
[0] = win
->s
->c
[SWM_S_COLOR_UNFOCUS
].pixel
;
9025 wa
[1] = XCB_EVENT_MASK_ENTER_WINDOW
| XCB_EVENT_MASK_PROPERTY_CHANGE
|
9026 XCB_EVENT_MASK_STRUCTURE_NOTIFY
;
9028 wa
[1] |= XCB_EVENT_MASK_LEAVE_WINDOW
| XCB_EVENT_MASK_FOCUS_CHANGE
;
9031 xcb_change_window_attributes(conn
, win
->id
, XCB_CW_BORDER_PIXEL
|
9032 XCB_CW_EVENT_MASK
, wa
);
9034 /* Get WM_SIZE_HINTS. */
9035 xcb_icccm_get_wm_normal_hints_reply(conn
,
9036 xcb_icccm_get_wm_normal_hints(conn
, win
->id
),
9040 xcb_icccm_get_wm_hints_reply(conn
,
9041 xcb_icccm_get_wm_hints(conn
, win
->id
),
9044 /* Get WM_TRANSIENT_FOR; see if window is a transient. */
9045 xcb_icccm_get_wm_transient_for_reply(conn
,
9046 xcb_icccm_get_wm_transient_for(conn
, win
->id
),
9049 win
->transient
= trans
;
9050 set_child_transient(win
, &win
->transient
);
9053 /* Get WM_PROTOCOLS. */
9054 get_wm_protocols(win
);
9056 /* Set initial quirks based on EWMH. */
9057 ewmh_autoquirk(win
);
9059 /* Determine initial quirks. */
9060 xcb_icccm_get_wm_class_reply(conn
,
9061 xcb_icccm_get_wm_class(conn
, win
->id
),
9064 class = win
->ch
.class_name
? win
->ch
.class_name
: "";
9065 instance
= win
->ch
.instance_name
? win
->ch
.instance_name
: "";
9066 name
= get_win_name(win
->id
);
9068 DNPRINTF(SWM_D_CLASS
, "manage_window: class: %s, instance: %s, "
9069 "name: %s\n", class, instance
, name
);
9071 /* java is retarded so treat it special */
9072 if (strstr(instance
, "sun-awt")) {
9073 DNPRINTF(SWM_D_CLASS
, "manage_window: java window detected.\n");
9077 TAILQ_FOREACH(qp
, &quirks
, entry
) {
9078 if (regexec(&qp
->regex_class
, class, 0, NULL
, 0) == 0 &&
9079 regexec(&qp
->regex_instance
, instance
, 0, NULL
, 0) == 0 &&
9080 regexec(&qp
->regex_name
, name
, 0, NULL
, 0) == 0) {
9081 DNPRINTF(SWM_D_CLASS
, "manage_window: matched "
9082 "quirk: %s:%s:%s mask: %#x, ws: %d\n", qp
->class,
9083 qp
->instance
, qp
->name
, qp
->quirk
, qp
->ws
);
9084 win
->quirks
= qp
->quirk
;
9085 if (qp
->ws
>= 0 && qp
->ws
< workspace_limit
)
9092 /* Reset font sizes (the bruteforce way; no default keybinding). */
9093 if (win
->quirks
& SWM_Q_XTERM_FONTADJ
) {
9094 for (i
= 0; i
< SWM_MAX_FONT_STEPS
; i
++)
9095 fake_keypress(win
, XK_KP_Subtract
, XCB_MOD_MASK_SHIFT
);
9096 for (i
= 0; i
< SWM_MAX_FONT_STEPS
; i
++)
9097 fake_keypress(win
, XK_KP_Add
, XCB_MOD_MASK_SHIFT
);
9100 /* Figure out which workspace the window belongs to. */
9101 if (!(win
->quirks
& SWM_Q_IGNOREPID
) &&
9102 (p
= find_pid(window_get_pid(win
->id
))) != NULL
) {
9103 win
->ws
= &r
->s
->ws
[p
->ws
];
9104 TAILQ_REMOVE(&pidlist
, p
, entry
);
9107 } else if ((ws_idx
= get_ws_idx(win
)) != -1 &&
9109 /* _SWM_WS is set; use that. */
9110 win
->ws
= &r
->s
->ws
[ws_idx
];
9111 } else if (trans
&& (ww
= find_window(trans
)) != NULL
) {
9112 /* Launch transients in the same ws as parent. */
9119 win
->ws
= &r
->s
->ws
[force_ws
];
9121 /* Set the _NET_WM_DESKTOP atom. */
9122 DNPRINTF(SWM_D_PROP
, "manage_window: set _NET_WM_DESKTOP: %d\n",
9124 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
,
9125 ewmh
[_NET_WM_DESKTOP
].atom
, XCB_ATOM_CARDINAL
, 32, 1, &win
->ws
->idx
);
9127 /* Remove any _SWM_WS now that we set _NET_WM_DESKTOP. */
9128 xcb_delete_property(conn
, win
->id
, a_swm_ws
);
9130 /* WS must already be set for this to work. */
9131 store_float_geom(win
);
9133 /* Make sure window is positioned inside its region, if its active. */
9135 region_containment(win
, r
, SWM_CW_ALLSIDES
|
9136 SWM_CW_HARDBOUNDARY
);
9141 /* Figure out where to insert the window in the workspace list. */
9142 if (trans
&& (ww
= find_window(trans
)))
9143 TAILQ_INSERT_AFTER(&win
->ws
->winlist
, ww
, win
, entry
);
9144 else if (win
->ws
->focus
&& spawn_pos
== SWM_STACK_ABOVE
)
9145 TAILQ_INSERT_AFTER(&win
->ws
->winlist
, win
->ws
->focus
, win
,
9147 else if (win
->ws
->focus
&& spawn_pos
== SWM_STACK_BELOW
)
9148 TAILQ_INSERT_BEFORE(win
->ws
->focus
, win
, entry
);
9149 else switch (spawn_pos
) {
9152 case SWM_STACK_ABOVE
:
9153 TAILQ_INSERT_TAIL(&win
->ws
->winlist
, win
, entry
);
9155 case SWM_STACK_BOTTOM
:
9156 case SWM_STACK_BELOW
:
9157 TAILQ_INSERT_HEAD(&win
->ws
->winlist
, win
, entry
);
9160 ewmh_update_client_list();
9162 TAILQ_INSERT_HEAD(&win
->ws
->stack
, win
, stack_entry
);
9165 /* Get/apply initial _NET_WM_STATE */
9166 ewmh_get_wm_state(win
);
9169 new_flags
= win
->ewmh_flags
;
9171 if (win
->quirks
& SWM_Q_FLOAT
)
9172 new_flags
|= EWMH_F_ABOVE
;
9174 if (win
->quirks
& SWM_Q_ANYWHERE
)
9175 new_flags
|= SWM_F_MANUAL
;
9177 ewmh_apply_flags(win
, new_flags
);
9178 ewmh_update_wm_state(win
);
9180 /* Set initial _NET_WM_ALLOWED_ACTIONS */
9181 ewmh_update_actions(win
);
9185 DNPRINTF(SWM_D_MISC
, "manage_window: done. win %#x, (x,y) w x h: "
9186 "(%d,%d) %d x %d, ws: %d, iconic: %s, transient: %#x\n", win
->id
,
9187 X(win
), Y(win
), WIDTH(win
), HEIGHT(win
), win
->ws
->idx
,
9188 YESNO(ICONIC(win
)), win
->transient
);
9194 free_window(struct ws_win
*win
)
9196 DNPRINTF(SWM_D_MISC
, "free_window: win %#x\n", win
->id
);
9201 TAILQ_REMOVE(&win
->ws
->unmanagedlist
, win
, entry
);
9203 xcb_icccm_get_wm_class_reply_wipe(&win
->ch
);
9208 memset(win
, 0xff, sizeof *win
); /* XXX kill later */
9211 DNPRINTF(SWM_D_MISC
, "free_window: done.\n");
9215 unmanage_window(struct ws_win
*win
)
9217 struct ws_win
*parent
;
9222 DNPRINTF(SWM_D_MISC
, "unmanage_window: win %#x\n", win
->id
);
9225 parent
= find_window(win
->transient
);
9227 parent
->focus_child
= NULL
;
9230 TAILQ_REMOVE(&win
->ws
->stack
, win
, stack_entry
);
9231 TAILQ_REMOVE(&win
->ws
->winlist
, win
, entry
);
9232 TAILQ_INSERT_TAIL(&win
->ws
->unmanagedlist
, win
, entry
);
9234 ewmh_update_client_list();
9238 expose(xcb_expose_event_t
*e
)
9241 struct swm_region
*r
;
9243 DNPRINTF(SWM_D_EVENT
, "expose: win %#x\n", e
->window
);
9245 num_screens
= get_screen_count();
9246 for (i
= 0; i
< num_screens
; i
++)
9247 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
9248 if (e
->window
== WINID(r
->bar
))
9256 focusin(xcb_focus_in_event_t
*e
)
9258 DNPRINTF(SWM_D_EVENT
, "focusin: win %#x, mode: %s(%u), "
9259 "detail: %s(%u)\n", e
->event
, get_notify_mode_label(e
->mode
),
9260 e
->mode
, get_notify_detail_label(e
->detail
), e
->detail
);
9264 focusout(xcb_focus_out_event_t
*e
)
9266 DNPRINTF(SWM_D_EVENT
, "focusout: win %#x, mode: %s(%u), "
9267 "detail: %s(%u)\n", e
->event
, get_notify_mode_label(e
->mode
),
9268 e
->mode
, get_notify_detail_label(e
->detail
), e
->detail
);
9273 keypress(xcb_key_press_event_t
*e
)
9275 xcb_keysym_t keysym
;
9278 keysym
= xcb_key_press_lookup_keysym(syms
, e
, 0);
9280 DNPRINTF(SWM_D_EVENT
, "keypress: keysym: %u, win (x,y): %#x (%d,%d), "
9281 "detail: %u, time: %u, root (x,y): %#x (%d,%d), child: %#x, "
9282 "state: %u, same_screen: %s\n", keysym
, e
->event
, e
->event_x
,
9283 e
->event_y
, e
->detail
, e
->time
, e
->root
, e
->root_x
, e
->root_y
,
9284 e
->child
, e
->state
, YESNO(e
->same_screen
));
9286 if ((kp
= key_lookup(CLEANMASK(e
->state
), keysym
)) == NULL
)
9289 last_event_time
= e
->time
;
9291 if (kp
->funcid
== KF_SPAWN_CUSTOM
)
9292 spawn_custom(root_to_region(e
->root
, SWM_CK_ALL
),
9293 &(keyfuncs
[kp
->funcid
].args
), kp
->spawn_name
);
9294 else if (keyfuncs
[kp
->funcid
].func
)
9295 keyfuncs
[kp
->funcid
].func(root_to_region(e
->root
, SWM_CK_ALL
),
9296 &(keyfuncs
[kp
->funcid
].args
));
9299 /* Unfreeze grab events. */
9300 xcb_allow_events(conn
, XCB_ALLOW_ASYNC_KEYBOARD
, e
->time
);
9303 DNPRINTF(SWM_D_EVENT
, "keypress: done.\n");
9307 buttonpress(xcb_button_press_event_t
*e
)
9309 struct ws_win
*win
= NULL
;
9310 struct swm_region
*r
, *old_r
;
9312 bool handled
= false;
9314 DNPRINTF(SWM_D_EVENT
, "buttonpress: win (x,y): %#x (%d,%d), "
9315 "detail: %u, time: %u, root (x,y): %#x (%d,%d), child: %#x, "
9316 "state: %u, same_screen: %s\n", e
->event
, e
->event_x
, e
->event_y
,
9317 e
->detail
, e
->time
, e
->root
, e
->root_x
, e
->root_y
, e
->child
,
9318 e
->state
, YESNO(e
->same_screen
));
9320 if (e
->event
== e
->root
) {
9321 if (e
->child
!= 0) {
9322 win
= find_window(e
->child
);
9323 /* Pass ButtonPress to window if it isn't managed. */
9327 /* Focus on empty region */
9328 /* If no windows on region if its empty. */
9329 r
= root_to_region(e
->root
, SWM_CK_POINTER
);
9331 DNPRINTF(SWM_D_EVENT
, "buttonpress: "
9332 "NULL region; ignoring.\n");
9336 if (TAILQ_EMPTY(&r
->ws
->winlist
)) {
9337 old_r
= root_to_region(e
->root
, SWM_CK_FOCUS
);
9338 if (old_r
&& old_r
!= r
)
9339 unfocus_win(old_r
->ws
->focus
);
9341 xcb_set_input_focus(conn
,
9342 XCB_INPUT_FOCUS_PARENT
, e
->root
, e
->time
);
9344 /* Clear bar since empty. */
9352 win
= find_window(e
->event
);
9358 last_event_time
= e
->time
;
9360 focus_win(get_focus_magic(win
));
9362 for (i
= 0; i
< LENGTH(buttons
); i
++)
9363 if (client_click
== buttons
[i
].action
&& buttons
[i
].func
&&
9364 buttons
[i
].button
== e
->detail
&&
9365 CLEANMASK(buttons
[i
].mask
) == CLEANMASK(e
->state
)) {
9366 buttons
[i
].func(win
, &buttons
[i
].args
);
9372 DNPRINTF(SWM_D_EVENT
, "buttonpress: passing to window.\n");
9373 /* Replay event to event window */
9374 xcb_allow_events(conn
, XCB_ALLOW_REPLAY_POINTER
, e
->time
);
9376 DNPRINTF(SWM_D_EVENT
, "buttonpress: handled.\n");
9377 /* Unfreeze grab events. */
9378 xcb_allow_events(conn
, XCB_ALLOW_SYNC_POINTER
, e
->time
);
9386 print_win_geom(xcb_window_t w
)
9388 xcb_get_geometry_reply_t
*wa
;
9390 wa
= xcb_get_geometry_reply(conn
, xcb_get_geometry(conn
, w
), NULL
);
9392 DNPRINTF(SWM_D_MISC
, "print_win_geom: window not found: %#x\n",
9397 DNPRINTF(SWM_D_MISC
, "print_win_geom: win %#x, root: %#x, "
9398 "depth: %u, (x,y) w x h: (%d,%d) %d x %d, border: %d\n",
9399 w
, wa
->root
, wa
->depth
, wa
->x
, wa
->y
, wa
->width
, wa
->height
,
9408 get_stack_mode_name(uint8_t mode
)
9413 case XCB_STACK_MODE_ABOVE
:
9416 case XCB_STACK_MODE_BELOW
:
9419 case XCB_STACK_MODE_TOP_IF
:
9422 case XCB_STACK_MODE_BOTTOM_IF
:
9425 case XCB_STACK_MODE_OPPOSITE
:
9437 configurerequest(xcb_configure_request_event_t
*e
)
9440 struct swm_region
*r
= NULL
;
9442 uint32_t wc
[7] = {0};
9446 if ((win
= find_window(e
->window
)) == NULL
)
9447 if ((win
= find_unmanaged_window(e
->window
)) == NULL
)
9451 if (swm_debug
& SWM_D_EVENT
) {
9452 print_win_geom(e
->window
);
9454 DNPRINTF(SWM_D_EVENT
, "configurerequest: win %#x, "
9455 "parent: %#x, new: %s, value_mask: %u { ", e
->window
,
9456 e
->parent
, YESNO(new), e
->value_mask
);
9457 if (e
->value_mask
& XCB_CONFIG_WINDOW_X
)
9458 DPRINTF("X: %d ", e
->x
);
9459 if (e
->value_mask
& XCB_CONFIG_WINDOW_Y
)
9460 DPRINTF("Y: %d ", e
->y
);
9461 if (e
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
9462 DPRINTF("W: %u ", e
->width
);
9463 if (e
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
9464 DPRINTF("H: %u ", e
->height
);
9465 if (e
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
9466 DPRINTF("Border: %u ", e
->border_width
);
9467 if (e
->value_mask
& XCB_CONFIG_WINDOW_SIBLING
)
9468 DPRINTF("Sibling: %#x ", e
->sibling
);
9469 if (e
->value_mask
& XCB_CONFIG_WINDOW_STACK_MODE
)
9470 DPRINTF("StackMode: %s(%u) ",
9471 get_stack_mode_name(e
->stack_mode
), e
->stack_mode
);
9477 if (e
->value_mask
& XCB_CONFIG_WINDOW_X
) {
9478 mask
|= XCB_CONFIG_WINDOW_X
;
9481 if (e
->value_mask
& XCB_CONFIG_WINDOW_Y
) {
9482 mask
|= XCB_CONFIG_WINDOW_Y
;
9485 if (e
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
) {
9486 mask
|= XCB_CONFIG_WINDOW_WIDTH
;
9489 if (e
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
) {
9490 mask
|= XCB_CONFIG_WINDOW_HEIGHT
;
9491 wc
[i
++] = e
->height
;
9493 if (e
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
) {
9494 mask
|= XCB_CONFIG_WINDOW_BORDER_WIDTH
;
9495 wc
[i
++] = e
->border_width
;
9497 if (e
->value_mask
& XCB_CONFIG_WINDOW_SIBLING
) {
9498 mask
|= XCB_CONFIG_WINDOW_SIBLING
;
9499 wc
[i
++] = e
->sibling
;
9501 if (e
->value_mask
& XCB_CONFIG_WINDOW_STACK_MODE
) {
9502 mask
|= XCB_CONFIG_WINDOW_STACK_MODE
;
9503 wc
[i
++] = e
->stack_mode
;
9507 xcb_configure_window(conn
, e
->window
, mask
, wc
);
9510 } else if ((!MANUAL(win
) || win
->quirks
& SWM_Q_ANYWHERE
) &&
9511 !FULLSCREEN(win
) && !MAXIMIZED(win
)) {
9514 else if (win
->ws
->old_r
)
9517 /* windows are centered unless ANYWHERE quirk is set. */
9518 if (win
->quirks
& SWM_Q_ANYWHERE
) {
9519 if (e
->value_mask
& XCB_CONFIG_WINDOW_X
) {
9520 win
->g_float
.x
= e
->x
;
9522 win
->g_float
.x
-= X(r
);
9525 if (e
->value_mask
& XCB_CONFIG_WINDOW_Y
) {
9526 win
->g_float
.y
= e
->y
;
9528 win
->g_float
.y
-= Y(r
);
9532 if (e
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
9533 win
->g_float
.w
= e
->width
;
9535 if (e
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
9536 win
->g_float
.h
= e
->height
;
9538 win
->g_floatvalid
= true;
9540 if (!MAXIMIZED(win
) && !FULLSCREEN(win
) &&
9541 (TRANS(win
) || (ABOVE(win
) &&
9542 win
->ws
->cur_layout
!= &layouts
[SWM_MAX_STACK
]))) {
9543 WIDTH(win
) = win
->g_float
.w
;
9544 HEIGHT(win
) = win
->g_float
.h
;
9547 update_floater(win
);
9562 DNPRINTF(SWM_D_EVENT
, "configurerequest: done.\n");
9566 configurenotify(xcb_configure_notify_event_t
*e
)
9570 DNPRINTF(SWM_D_EVENT
, "configurenotify: win %#x, event win: %#x, "
9571 "(x,y) WxH: (%d,%d) %ux%u, border: %u, above_sibling: %#x, "
9572 "override_redirect: %s\n", e
->window
, e
->event
, e
->x
, e
->y
,
9573 e
->width
, e
->height
, e
->border_width
, e
->above_sibling
,
9574 YESNO(e
->override_redirect
));
9576 win
= find_window(e
->window
);
9578 xcb_icccm_get_wm_normal_hints_reply(conn
,
9579 xcb_icccm_get_wm_normal_hints(conn
, win
->id
),
9582 if (font_adjusted
) {
9590 destroynotify(xcb_destroy_notify_event_t
*e
)
9594 DNPRINTF(SWM_D_EVENT
, "destroynotify: win %#x\n", e
->window
);
9596 if ((win
= find_window(e
->window
)) == NULL
) {
9597 if ((win
= find_unmanaged_window(e
->window
)) == NULL
)
9603 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
9604 /* If we were focused, make sure we focus on something else. */
9605 if (win
== win
->ws
->focus
)
9606 win
->ws
->focus_pending
= get_focus_prev(win
);
9609 unmanage_window(win
);
9612 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& WS_FOCUSED(win
->ws
)) {
9613 if (win
->ws
->focus_pending
) {
9614 focus_win(win
->ws
->focus_pending
);
9615 win
->ws
->focus_pending
= NULL
;
9616 } else if (win
== win
->ws
->focus
) {
9617 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
,
9618 win
->ws
->r
->id
, XCB_CURRENT_TIME
);
9629 get_notify_detail_label(uint8_t detail
)
9634 case XCB_NOTIFY_DETAIL_ANCESTOR
:
9637 case XCB_NOTIFY_DETAIL_VIRTUAL
:
9640 case XCB_NOTIFY_DETAIL_INFERIOR
:
9643 case XCB_NOTIFY_DETAIL_NONLINEAR
:
9644 label
= "Nonlinear";
9646 case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL
:
9647 label
= "NonlinearVirtual";
9649 case XCB_NOTIFY_DETAIL_POINTER
:
9652 case XCB_NOTIFY_DETAIL_POINTER_ROOT
:
9653 label
= "PointerRoot";
9655 case XCB_NOTIFY_DETAIL_NONE
:
9666 get_notify_mode_label(uint8_t mode
)
9671 case XCB_NOTIFY_MODE_NORMAL
:
9674 case XCB_NOTIFY_MODE_GRAB
:
9677 case XCB_NOTIFY_MODE_UNGRAB
:
9680 case XCB_NOTIFY_MODE_WHILE_GRABBED
:
9681 label
= "WhileGrabbed";
9692 enternotify(xcb_enter_notify_event_t
*e
)
9695 struct swm_region
*r
;
9697 DNPRINTF(SWM_D_FOCUS
, "enternotify: time: %u, win (x,y): %#x "
9698 "(%d,%d), mode: %s(%d), detail: %s(%d), root (x,y): %#x (%d,%d), "
9699 "child: %#x, same_screen_focus: %s, state: %d\n",
9700 e
->time
, e
->event
, e
->event_x
, e
->event_y
,
9701 get_notify_mode_label(e
->mode
), e
->mode
,
9702 get_notify_detail_label(e
->detail
), e
->detail
,
9703 e
->root
, e
->root_x
, e
->root_y
, e
->child
,
9704 YESNO(e
->same_screen_focus
), e
->state
);
9706 if (focus_mode
== SWM_FOCUS_MANUAL
&&
9707 e
->mode
== XCB_NOTIFY_MODE_NORMAL
) {
9708 DNPRINTF(SWM_D_EVENT
, "enternotify: manual focus; ignoring.\n");
9712 if (focus_mode
!= SWM_FOCUS_FOLLOW
&&
9713 e
->mode
== XCB_NOTIFY_MODE_UNGRAB
) {
9714 DNPRINTF(SWM_D_EVENT
, "enternotify: ungrab; ignoring.\n");
9718 last_event_time
= e
->time
;
9720 if ((win
= find_window(e
->event
)) == NULL
) {
9721 if (e
->event
== e
->root
) {
9722 /* If no windows on pointer region, then focus root. */
9723 r
= root_to_region(e
->root
, SWM_CK_POINTER
);
9725 DNPRINTF(SWM_D_EVENT
, "enternotify: "
9726 "NULL region; ignoring.\n");
9732 DNPRINTF(SWM_D_EVENT
, "enternotify: window is NULL; "
9737 if (e
->mode
== XCB_NOTIFY_MODE_NORMAL
&&
9738 e
->detail
== XCB_NOTIFY_DETAIL_INFERIOR
) {
9739 DNPRINTF(SWM_D_EVENT
, "enternotify: entering from "
9740 "inferior; ignoring\n");
9744 focus_win(get_focus_magic(win
));
9752 leavenotify(xcb_leave_notify_event_t
*e
)
9754 DNPRINTF(SWM_D_FOCUS
, "leavenotify: time: %u, win (x,y): %#x "
9755 "(%d,%d), mode: %s(%d), detail: %s(%d), root (x,y): %#x (%d,%d), "
9756 "child: %#x, same_screen_focus: %s, state: %d\n",
9757 e
->time
, e
->event
, e
->event_x
, e
->event_y
,
9758 get_notify_mode_label(e
->mode
), e
->mode
,
9759 get_notify_detail_label(e
->detail
), e
->detail
,
9760 e
->root
, e
->root_x
, e
->root_y
, e
->child
,
9761 YESNO(e
->same_screen_focus
), e
->state
);
9766 mapnotify(xcb_map_notify_event_t
*e
)
9768 struct ws_win
*win
, *parent
= NULL
;
9769 struct workspace
*ws
;
9771 DNPRINTF(SWM_D_EVENT
, "mapnotify: win %#x\n", e
->window
);
9773 if ((win
= manage_window(e
->window
, spawn_position
, true)) == NULL
)
9777 /* Need to know if win was mapped due to ws switch. */
9778 if (ws
->state
== SWM_WS_STATE_MAPPED
) {
9779 if (ws
->focus_pending
&& TRANS(ws
->focus_pending
))
9780 parent
= find_window(win
->transient
);
9782 /* If window's parent is maximized, don't clear it. */
9783 if ((parent
== NULL
) || !MAXIMIZED(parent
))
9784 if (clear_maximized(ws
) > 0)
9789 set_win_state(win
, XCB_ICCCM_WM_STATE_NORMAL
);
9791 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& WS_FOCUSED(win
->ws
)) {
9792 if (ws
->focus_pending
== win
) {
9794 ws
->focus_pending
= NULL
;
9795 center_pointer(win
->ws
->r
);
9804 mappingnotify(xcb_mapping_notify_event_t
*e
)
9807 int i
, j
, num_screens
;
9809 xcb_refresh_keyboard_mapping(syms
, e
);
9811 if (e
->request
== XCB_MAPPING_KEYBOARD
) {
9814 /* Regrab buttons on all managed windows. */
9815 num_screens
= get_screen_count();
9816 for (i
= 0; i
< num_screens
; i
++)
9817 for (j
= 0; j
< workspace_limit
; j
++)
9818 TAILQ_FOREACH(w
, &screens
[i
].ws
[j
].winlist
,
9825 maprequest(xcb_map_request_event_t
*e
)
9827 struct ws_win
*win
, *w
= NULL
;
9828 xcb_get_window_attributes_reply_t
*war
;
9830 DNPRINTF(SWM_D_EVENT
, "maprequest: win %#x\n",
9833 war
= xcb_get_window_attributes_reply(conn
,
9834 xcb_get_window_attributes(conn
, e
->window
),
9837 DNPRINTF(SWM_D_EVENT
, "maprequest: window lost.\n");
9841 if (war
->override_redirect
) {
9842 DNPRINTF(SWM_D_EVENT
, "maprequest: override_redirect; "
9847 win
= manage_window(e
->window
, spawn_position
,
9848 (war
->map_state
== XCB_MAP_STATE_VIEWABLE
));
9852 /* The new window should get focus; prepare. */
9853 if (focus_mode
!= SWM_FOCUS_FOLLOW
&&
9854 !(win
->quirks
& SWM_Q_NOFOCUSONMAP
) &&
9855 (!(win
->hints
.flags
& XCB_ICCCM_WM_HINT_INPUT
) ||
9856 (win
->hints
.flags
& XCB_ICCCM_WM_HINT_INPUT
&&
9857 win
->hints
.input
))) {
9858 if (win
->quirks
& SWM_Q_FOCUSONMAP_SINGLE
) {
9859 /* See if other wins of same type are already mapped. */
9860 TAILQ_FOREACH(w
, &win
->ws
->winlist
, entry
) {
9861 if (w
== win
|| !w
->mapped
)
9864 if (w
->ch
.class_name
&&
9865 win
->ch
.class_name
&&
9866 strcmp(w
->ch
.class_name
,
9867 win
->ch
.class_name
) == 0 &&
9868 w
->ch
.instance_name
&&
9869 win
->ch
.instance_name
&&
9870 strcmp(w
->ch
.instance_name
,
9871 win
->ch
.instance_name
) == 0)
9877 win
->ws
->focus_pending
= get_focus_magic(win
);
9880 /* All windows need to be mapped if they are in the current workspace.*/
9884 /* Ignore EnterNotify to handle the mapnotify without interference. */
9885 if (focus_mode
== SWM_FOCUS_DEFAULT
)
9886 event_drain(XCB_ENTER_NOTIFY
);
9889 DNPRINTF(SWM_D_EVENT
, "maprequest: done.\n");
9893 motionnotify(xcb_motion_notify_event_t
*e
)
9895 struct swm_region
*r
= NULL
;
9898 DNPRINTF(SWM_D_FOCUS
, "motionnotify: time: %u, win (x,y): %#x "
9899 "(%d,%d), detail: %s(%d), root (x,y): %#x (%d,%d), "
9900 "child: %#x, same_screen_focus: %s, state: %d\n",
9901 e
->time
, e
->event
, e
->event_x
, e
->event_y
,
9902 get_notify_detail_label(e
->detail
), e
->detail
,
9903 e
->root
, e
->root_x
, e
->root_y
, e
->child
,
9904 YESNO(e
->same_screen
), e
->state
);
9906 last_event_time
= e
->time
;
9908 if (focus_mode
== SWM_FOCUS_MANUAL
)
9911 num_screens
= get_screen_count();
9912 for (i
= 0; i
< num_screens
; i
++)
9913 if (screens
[i
].root
== e
->root
)
9916 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
9917 if (X(r
) <= e
->root_x
&& e
->root_x
< MAX_X(r
) &&
9918 Y(r
) <= e
->root_y
&& e
->root_y
< MAX_Y(r
))
9926 get_atom_name(xcb_atom_t atom
)
9929 #ifdef SWM_DEBUG_ATOM_NAMES
9931 * This should be disabled during most debugging since
9932 * xcb_get_* causes an xcb_flush.
9935 xcb_get_atom_name_reply_t
*r
;
9937 r
= xcb_get_atom_name_reply(conn
,
9938 xcb_get_atom_name(conn
, atom
),
9941 len
= xcb_get_atom_name_name_length(r
);
9943 name
= malloc(len
+ 1);
9945 memcpy(name
, xcb_get_atom_name_name(r
), len
);
9959 propertynotify(xcb_property_notify_event_t
*e
)
9962 struct workspace
*ws
;
9966 name
= get_atom_name(e
->atom
);
9967 DNPRINTF(SWM_D_EVENT
, "propertynotify: win %#x, atom: %s(%u), "
9968 "time: %#x, state: %u\n", e
->window
, name
, e
->atom
, e
->time
,
9972 win
= find_window(e
->window
);
9978 last_event_time
= e
->time
;
9980 if (e
->atom
== a_state
) {
9981 /* State just changed, make sure it gets focused if mapped. */
9982 if (e
->state
== XCB_PROPERTY_NEW_VALUE
) {
9983 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& WS_FOCUSED(ws
)) {
9985 ws
->focus_pending
== win
) {
9986 focus_win(ws
->focus_pending
);
9987 ws
->focus_pending
= NULL
;
9991 } else if (e
->atom
== XCB_ATOM_WM_CLASS
||
9992 e
->atom
== XCB_ATOM_WM_NAME
) {
9994 } else if (e
->atom
== a_prot
) {
9995 get_wm_protocols(win
);
10002 unmapnotify(xcb_unmap_notify_event_t
*e
)
10004 struct ws_win
*win
;
10005 struct workspace
*ws
;
10007 DNPRINTF(SWM_D_EVENT
, "unmapnotify: win %#x\n", e
->window
);
10009 /* If we aren't managing the window, then ignore. */
10010 win
= find_window(e
->window
);
10011 if (win
== NULL
|| win
->id
!= e
->window
)
10014 /* Do nothing if already withdrawn. */
10015 if (!win
->mapped
&& !ICONIC(win
))
10019 win
->mapped
= false;
10021 /* If win was focused, make sure to focus on something else. */
10022 if (win
== ws
->focus
) {
10023 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
10024 ws
->focus_pending
= get_focus_prev(win
);
10025 DNPRINTF(SWM_D_EVENT
, "unmapnotify: "
10026 "focus_pending: %#x\n",
10027 WINID(ws
->focus_pending
));
10035 set_win_state(win
, XCB_ICCCM_WM_STATE_ICONIC
);
10038 set_win_state(win
, XCB_ICCCM_WM_STATE_WITHDRAWN
);
10039 unmanage_window(win
);
10045 /* Update focus if ws is active. */
10046 if (WS_FOCUSED(ws
)) {
10047 if (focus_mode
== SWM_FOCUS_FOLLOW
) {
10048 focus_win(get_pointer_win(ws
->r
->s
->root
));
10049 } else if (ws
->focus_pending
) {
10050 focus_win(ws
->focus_pending
);
10051 ws
->focus_pending
= NULL
;
10052 } else if (ws
->focus
== NULL
) {
10053 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
,
10054 ws
->r
->id
, XCB_CURRENT_TIME
);
10058 center_pointer(ws
->r
);
10064 get_source_type_label(uint32_t type
)
10069 case EWMH_SOURCE_TYPE_NONE
:
10072 case EWMH_SOURCE_TYPE_NORMAL
:
10075 case EWMH_SOURCE_TYPE_OTHER
:
10087 clientmessage(xcb_client_message_event_t
*e
)
10089 struct ws_win
*win
;
10090 struct swm_region
*r
= NULL
;
10093 int num_screens
, i
;
10094 xcb_map_request_event_t mre
;
10098 name
= get_atom_name(e
->type
);
10099 DNPRINTF(SWM_D_EVENT
, "clientmessage: win %#x, atom: %s(%u)\n",
10100 e
->window
, name
, e
->type
);
10104 if (e
->type
== ewmh
[_NET_CURRENT_DESKTOP
].atom
) {
10105 num_screens
= get_screen_count();
10106 for (i
= 0; i
< num_screens
; i
++)
10107 if (screens
[i
].root
== e
->window
) {
10108 r
= screens
[i
].r_focus
;
10112 if (r
&& e
->data
.data32
[0] < (uint32_t)workspace_limit
) {
10113 a
.id
= e
->data
.data32
[0];
10121 win
= find_window(e
->window
);
10123 if (e
->type
== ewmh
[_NET_ACTIVE_WINDOW
].atom
) {
10124 /* Manage the window with maprequest. */
10125 DNPRINTF(SWM_D_EVENT
, "clientmessage: request focus on "
10126 "unmanaged window.\n");
10127 mre
.window
= e
->window
;
10133 if (e
->type
== ewmh
[_NET_ACTIVE_WINDOW
].atom
) {
10134 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_ACTIVE_WINDOW, "
10135 "source_type: %s(%d)\n",
10136 get_source_type_label(e
->data
.data32
[0]),
10137 e
->data
.data32
[0]);
10140 * Allow focus changes that are a result of direct user
10141 * action and from applications that use the old EWMH spec.
10143 if (e
->data
.data32
[0] != EWMH_SOURCE_TYPE_NORMAL
||
10144 win
->quirks
& SWM_Q_OBEYAPPFOCUSREQ
) {
10145 if (WS_FOCUSED(win
->ws
))
10148 win
->ws
->focus_pending
= win
;
10150 } else if (e
->type
== ewmh
[_NET_CLOSE_WINDOW
].atom
) {
10151 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_CLOSE_WINDOW\n");
10152 if (win
->can_delete
)
10153 client_msg(win
, a_delete
, 0);
10155 xcb_kill_client(conn
, win
->id
);
10156 } else if (e
->type
== ewmh
[_NET_MOVERESIZE_WINDOW
].atom
) {
10157 DNPRINTF(SWM_D_EVENT
,
10158 "clientmessage: _NET_MOVERESIZE_WINDOW\n");
10160 if (e
->data
.data32
[0] & (1<<8)) /* x */
10161 X(win
) = e
->data
.data32
[1];
10162 if (e
->data
.data32
[0] & (1<<9)) /* y */
10163 Y(win
) = e
->data
.data32
[2];
10164 if (e
->data
.data32
[0] & (1<<10)) /* width */
10165 WIDTH(win
) = e
->data
.data32
[3];
10166 if (e
->data
.data32
[0] & (1<<11)) /* height */
10167 HEIGHT(win
) = e
->data
.data32
[4];
10169 update_window(win
);
10171 /* Notify no change was made. */
10172 config_win(win
, NULL
);
10173 /* TODO: Change stack sizes */
10175 } else if (e
->type
== ewmh
[_NET_RESTACK_WINDOW
].atom
) {
10176 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_RESTACK_WINDOW\n");
10177 val
[0] = e
->data
.data32
[1]; /* Sibling window. */
10178 val
[1] = e
->data
.data32
[2]; /* Stack mode detail. */
10180 xcb_configure_window(conn
, win
->id
, XCB_CONFIG_WINDOW_SIBLING
|
10181 XCB_CONFIG_WINDOW_STACK_MODE
, val
);
10182 } else if (e
->type
== ewmh
[_NET_WM_STATE
].atom
) {
10183 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_WM_STATE\n");
10184 ewmh_change_wm_state(win
, e
->data
.data32
[1], e
->data
.data32
[0]);
10185 if (e
->data
.data32
[2])
10186 ewmh_change_wm_state(win
, e
->data
.data32
[2],
10187 e
->data
.data32
[0]);
10189 ewmh_update_wm_state(win
);
10191 } else if (e
->type
== ewmh
[_NET_WM_DESKTOP
].atom
) {
10192 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_WM_DESKTOP\n");
10195 win_to_ws(win
, e
->data
.data32
[0], true);
10197 /* Restack if either the source or destination ws is mapped. */
10198 if (r
!= NULL
|| win
->ws
->r
!= NULL
) {
10200 load_float_geom(win
);
10212 int errcode
= xcb_connection_has_error(conn
);
10213 #ifdef XCB_CONN_ERROR
10216 case XCB_CONN_ERROR
:
10217 s
= "Socket error, pipe error or other stream error.";
10219 case XCB_CONN_CLOSED_EXT_NOTSUPPORTED
:
10220 s
= "Extension not supported.";
10222 case XCB_CONN_CLOSED_MEM_INSUFFICIENT
:
10223 s
= "Insufficient memory.";
10225 case XCB_CONN_CLOSED_REQ_LEN_EXCEED
:
10226 s
= "Request length was exceeded.";
10228 case XCB_CONN_CLOSED_PARSE_ERR
:
10229 s
= "Error parsing display string.";
10232 s
= "Unknown error.";
10235 errx(errcode
, "X CONNECTION ERROR: %s", s
);
10238 errx(errcode
, "X CONNECTION ERROR");
10245 int num_screens
, i
;
10246 const uint32_t val
= XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT
|
10247 XCB_EVENT_MASK_ENTER_WINDOW
;
10249 xcb_void_cookie_t wac
;
10250 xcb_generic_error_t
*error
;
10252 /* this causes an error if some other window manager is running */
10253 num_screens
= get_screen_count();
10254 for (i
= 0; i
< num_screens
; i
++) {
10255 if ((sc
= get_screen(i
)) == NULL
)
10256 errx(1, "ERROR: can't get screen %d.", i
);
10257 DNPRINTF(SWM_D_INIT
, "enable_wm: screen %d, root: %#x\n",
10259 wac
= xcb_change_window_attributes_checked(conn
, sc
->root
,
10260 XCB_CW_EVENT_MASK
, &val
);
10261 if ((error
= xcb_request_check(conn
, wac
))) {
10262 DNPRINTF(SWM_D_INIT
, "enable_wm: error_code: %u\n",
10263 error
->error_code
);
10268 /* click to focus on empty region */
10269 xcb_grab_button(conn
, 1, sc
->root
, BUTTONMASK
,
10270 XCB_GRAB_MODE_SYNC
, XCB_GRAB_MODE_ASYNC
, XCB_WINDOW_NONE
,
10271 XCB_CURSOR_NONE
, XCB_BUTTON_INDEX_1
, XCB_BUTTON_MASK_ANY
);
10278 new_region(struct swm_screen
*s
, int x
, int y
, int w
, int h
)
10280 struct swm_region
*r
= NULL
, *n
;
10281 struct workspace
*ws
= NULL
;
10285 DNPRINTF(SWM_D_MISC
, "new region: screen[%d]:%dx%d+%d+%d\n",
10286 s
->idx
, w
, h
, x
, y
);
10288 /* remove any conflicting regions */
10289 n
= TAILQ_FIRST(&s
->rl
);
10292 n
= TAILQ_NEXT(r
, entry
);
10293 if (X(r
) < (x
+ w
) && (X(r
) + WIDTH(r
)) > x
&&
10294 Y(r
) < (y
+ h
) && (Y(r
) + HEIGHT(r
)) > y
) {
10295 if (r
->ws
->r
!= NULL
)
10296 r
->ws
->old_r
= r
->ws
->r
;
10299 xcb_destroy_window(conn
, r
->id
);
10300 TAILQ_REMOVE(&s
->rl
, r
, entry
);
10301 TAILQ_INSERT_TAIL(&s
->orl
, r
, entry
);
10305 /* search old regions for one to reuse */
10307 /* size + location match */
10308 TAILQ_FOREACH(r
, &s
->orl
, entry
)
10309 if (X(r
) == x
&& Y(r
) == y
&&
10310 HEIGHT(r
) == h
&& WIDTH(r
) == w
)
10314 TAILQ_FOREACH(r
, &s
->orl
, entry
)
10315 if (HEIGHT(r
) == h
&& WIDTH(r
) == w
)
10319 TAILQ_REMOVE(&s
->orl
, r
, entry
);
10320 /* try to use old region's workspace */
10321 if (r
->ws
->r
== NULL
)
10324 if ((r
= calloc(1, sizeof(struct swm_region
))) == NULL
)
10325 err(1, "new_region: calloc: failed to allocate memory "
10328 /* if we don't have a workspace already, find one */
10330 for (i
= 0; i
< workspace_limit
; i
++)
10331 if (s
->ws
[i
].r
== NULL
) {
10338 errx(1, "new_region: no free workspaces");
10340 if (ws
->state
== SWM_WS_STATE_HIDDEN
)
10341 ws
->state
= SWM_WS_STATE_MAPPING
;
10349 r
->ws_prior
= NULL
;
10352 TAILQ_INSERT_TAIL(&s
->rl
, r
, entry
);
10354 /* Invisible region window to detect pointer events on empty regions. */
10355 r
->id
= xcb_generate_id(conn
);
10356 wa
[0] = XCB_EVENT_MASK_POINTER_MOTION
|
10357 XCB_EVENT_MASK_POINTER_MOTION_HINT
;
10359 xcb_create_window(conn
, XCB_COPY_FROM_PARENT
, r
->id
, r
->s
->root
,
10360 X(r
), Y(r
), WIDTH(r
), HEIGHT(r
), 0, XCB_WINDOW_CLASS_INPUT_ONLY
,
10361 XCB_COPY_FROM_PARENT
, XCB_CW_EVENT_MASK
, wa
);
10363 /* Make sure region input is at the bottom. */
10364 wa
[0] = XCB_STACK_MODE_BELOW
;
10365 xcb_configure_window(conn
, r
->id
, XCB_CONFIG_WINDOW_STACK_MODE
, wa
);
10367 xcb_map_window(conn
, r
->id
);
10371 scan_randr(int idx
)
10373 #ifdef SWM_XRR_HAS_CRTC
10376 #endif /* SWM_XRR_HAS_CRTC */
10377 struct swm_region
*r
;
10378 struct ws_win
*win
;
10380 xcb_randr_get_screen_resources_current_cookie_t src
;
10381 xcb_randr_get_screen_resources_current_reply_t
*srr
;
10382 xcb_randr_get_crtc_info_cookie_t cic
;
10383 xcb_randr_get_crtc_info_reply_t
*cir
= NULL
;
10384 xcb_randr_crtc_t
*crtc
;
10385 xcb_screen_t
*screen
;
10387 DNPRINTF(SWM_D_MISC
, "scan_randr: screen: %d\n", idx
);
10389 if ((screen
= get_screen(idx
)) == NULL
)
10390 errx(1, "ERROR: can't get screen %d.", idx
);
10392 num_screens
= get_screen_count();
10393 if (idx
>= num_screens
)
10394 errx(1, "scan_randr: invalid screen");
10396 /* remove any old regions */
10397 while ((r
= TAILQ_FIRST(&screens
[idx
].rl
)) != NULL
) {
10398 r
->ws
->old_r
= r
->ws
->r
= NULL
;
10400 xcb_destroy_window(conn
, r
->id
);
10401 TAILQ_REMOVE(&screens
[idx
].rl
, r
, entry
);
10402 TAILQ_INSERT_TAIL(&screens
[idx
].orl
, r
, entry
);
10406 /* map virtual screens onto physical screens */
10407 #ifdef SWM_XRR_HAS_CRTC
10408 if (randr_support
) {
10409 src
= xcb_randr_get_screen_resources_current(conn
,
10410 screens
[idx
].root
);
10411 srr
= xcb_randr_get_screen_resources_current_reply(conn
, src
,
10414 new_region(&screens
[idx
], 0, 0,
10415 screen
->width_in_pixels
,
10416 screen
->height_in_pixels
);
10419 ncrtc
= srr
->num_crtcs
;
10421 crtc
= xcb_randr_get_screen_resources_current_crtcs(srr
);
10422 for (c
= 0; c
< ncrtc
; c
++) {
10423 cic
= xcb_randr_get_crtc_info(conn
, crtc
[c
],
10425 cir
= xcb_randr_get_crtc_info_reply(conn
, cic
, NULL
);
10428 if (cir
->num_outputs
== 0) {
10433 if (cir
->mode
== 0)
10434 new_region(&screens
[idx
], 0, 0,
10435 screen
->width_in_pixels
,
10436 screen
->height_in_pixels
);
10438 new_region(&screens
[idx
],
10439 cir
->x
, cir
->y
, cir
->width
, cir
->height
);
10444 #endif /* SWM_XRR_HAS_CRTC */
10446 /* If detection failed, create a single region that spans the screen. */
10447 if (TAILQ_EMPTY(&screens
[idx
].rl
))
10448 new_region(&screens
[idx
], 0, 0, screen
->width_in_pixels
,
10449 screen
->height_in_pixels
);
10452 /* Cleanup unused previously visible workspaces. */
10453 TAILQ_FOREACH(r
, &screens
[idx
].orl
, entry
) {
10454 TAILQ_FOREACH(win
, &r
->ws
->winlist
, entry
)
10456 r
->ws
->state
= SWM_WS_STATE_HIDDEN
;
10458 /* The screen shouldn't focus on an unused region. */
10459 if (screens
[idx
].r_focus
== r
)
10460 screens
[idx
].r_focus
= NULL
;
10463 DNPRINTF(SWM_D_MISC
, "scan_randr: done.\n");
10467 screenchange(xcb_randr_screen_change_notify_event_t
*e
)
10469 struct swm_region
*r
;
10470 int i
, num_screens
;
10472 DNPRINTF(SWM_D_EVENT
, "screenchange: root: %#x\n", e
->root
);
10474 num_screens
= get_screen_count();
10475 /* silly event doesn't include the screen index */
10476 for (i
= 0; i
< num_screens
; i
++)
10477 if (screens
[i
].root
== e
->root
)
10479 if (i
>= num_screens
)
10480 errx(1, "screenchange: screen not found");
10482 /* brute force for now, just re-enumerate the regions */
10486 print_win_geom(e
->root
);
10488 /* add bars to all regions */
10489 for (i
= 0; i
< num_screens
; i
++) {
10490 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
10496 /* Make sure a region has focus on each screen. */
10497 for (i
= 0; i
< num_screens
; i
++) {
10498 if (screens
[i
].r_focus
== NULL
) {
10499 r
= TAILQ_FIRST(&screens
[i
].rl
);
10508 /* Update workspace state on all regions. */
10509 for (i
= 0; i
< num_screens
; i
++)
10510 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
10511 r
->ws
->state
= SWM_WS_STATE_MAPPED
;
10517 struct swm_region
*r
= NULL
;
10518 xcb_window_t
*wins
= NULL
, trans
, *cwins
= NULL
;
10519 int i
, j
, k
, n
, no
, num_screens
;
10521 bool manage
, mapped
;
10523 xcb_query_tree_cookie_t qtc
;
10524 xcb_query_tree_reply_t
*qtr
;
10525 xcb_get_window_attributes_cookie_t gac
;
10526 xcb_get_window_attributes_reply_t
*gar
;
10527 xcb_get_property_cookie_t pc
;
10528 xcb_get_property_reply_t
*pr
;
10530 DNPRINTF(SWM_D_INIT
, "grab_windows: begin\n");
10531 num_screens
= get_screen_count();
10532 for (i
= 0; i
< num_screens
; i
++) {
10533 qtc
= xcb_query_tree(conn
, screens
[i
].root
);
10534 qtr
= xcb_query_tree_reply(conn
, qtc
, NULL
);
10537 wins
= xcb_query_tree_children(qtr
);
10538 no
= xcb_query_tree_children_length(qtr
);
10540 /* Try to sort windows according to _NET_CLIENT_LIST. */
10541 pr
= xcb_get_property_reply(conn
, xcb_get_property(conn
, 0,
10542 screens
[i
].root
, ewmh
[_NET_CLIENT_LIST
].atom
,
10543 XCB_ATOM_WINDOW
, 0, UINT32_MAX
), NULL
);
10545 cwins
= xcb_get_property_value(pr
);
10546 n
= xcb_get_property_value_length(pr
) /
10547 sizeof(xcb_atom_t
);
10549 for (j
= 0; j
< n
; ++j
) {
10550 for (k
= j
; k
< no
; ++k
) {
10551 if (wins
[k
] == cwins
[j
]) {
10552 /* Swap wins j and k. */
10554 wins
[j
] = cwins
[j
];
10562 /* attach windows to a region */
10563 /* normal windows */
10564 DNPRINTF(SWM_D_INIT
, "grab_windows: grab top level windows.\n");
10565 for (j
= 0; j
< no
; j
++) {
10566 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
) {
10567 if (r
->id
== wins
[j
]) {
10568 DNPRINTF(SWM_D_INIT
, "grab_windows: "
10569 "skip %#x; region input window.\n",
10572 } else if (r
->bar
->id
== wins
[j
]) {
10573 DNPRINTF(SWM_D_INIT
, "grab_windows: "
10574 "skip %#x; region bar.\n",
10583 gac
= xcb_get_window_attributes(conn
, wins
[j
]);
10584 gar
= xcb_get_window_attributes_reply(conn
, gac
, NULL
);
10586 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10587 "doesn't exist.\n", wins
[j
]);
10591 if (gar
->override_redirect
) {
10592 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10593 "override_redirect set.\n", wins
[j
]);
10598 pc
= xcb_icccm_get_wm_transient_for(conn
, wins
[j
]);
10599 if (xcb_icccm_get_wm_transient_for_reply(conn
, pc
,
10601 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10602 "is transient for %#x.\n", wins
[j
], trans
);
10607 state
= get_win_state(wins
[j
]);
10608 manage
= state
!= XCB_ICCCM_WM_STATE_WITHDRAWN
;
10609 mapped
= gar
->map_state
== XCB_MAP_STATE_VIEWABLE
;
10610 if (mapped
|| manage
)
10611 manage_window(wins
[j
], SWM_STACK_TOP
, mapped
);
10614 /* transient windows */
10615 DNPRINTF(SWM_D_INIT
, "grab_windows: grab transient windows.\n");
10616 for (j
= 0; j
< no
; j
++) {
10617 gac
= xcb_get_window_attributes(conn
, wins
[j
]);
10618 gar
= xcb_get_window_attributes_reply(conn
, gac
, NULL
);
10620 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10621 "doesn't exist.\n", wins
[j
]);
10625 if (gar
->override_redirect
) {
10626 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10627 "override_redirect set.\n", wins
[j
]);
10632 state
= get_win_state(wins
[j
]);
10633 manage
= state
!= XCB_ICCCM_WM_STATE_WITHDRAWN
;
10634 mapped
= gar
->map_state
== XCB_MAP_STATE_VIEWABLE
;
10635 pc
= xcb_icccm_get_wm_transient_for(conn
, wins
[j
]);
10636 if (xcb_icccm_get_wm_transient_for_reply(conn
, pc
,
10637 &trans
, NULL
) && manage
)
10638 manage_window(wins
[j
], SWM_STACK_TOP
, mapped
);
10643 DNPRINTF(SWM_D_INIT
, "grab_windows: done.\n");
10647 setup_screens(void)
10649 int i
, j
, k
, num_screens
;
10650 struct workspace
*ws
;
10651 uint32_t gcv
[1], wa
[1];
10652 const xcb_query_extension_reply_t
*qep
;
10653 xcb_screen_t
*screen
;
10654 xcb_randr_query_version_cookie_t c
;
10655 xcb_randr_query_version_reply_t
*r
;
10657 num_screens
= get_screen_count();
10658 if ((screens
= calloc(num_screens
,
10659 sizeof(struct swm_screen
))) == NULL
)
10660 err(1, "setup_screens: calloc: failed to allocate memory for "
10663 /* Initial RandR setup. */
10664 randr_support
= false;
10665 qep
= xcb_get_extension_data(conn
, &xcb_randr_id
);
10666 if (qep
->present
) {
10667 c
= xcb_randr_query_version(conn
, 1, 1);
10668 r
= xcb_randr_query_version_reply(conn
, c
, NULL
);
10670 if (r
->major_version
>= 1) {
10671 randr_support
= true;
10672 randr_eventbase
= qep
->first_event
;
10678 wa
[0] = cursors
[XC_LEFT_PTR
].cid
;
10680 /* map physical screens */
10681 for (i
= 0; i
< num_screens
; i
++) {
10682 DNPRINTF(SWM_D_WS
, "setup_screens: init screen: %d\n", i
);
10683 screens
[i
].idx
= i
;
10684 screens
[i
].r_focus
= NULL
;
10686 TAILQ_INIT(&screens
[i
].rl
);
10687 TAILQ_INIT(&screens
[i
].orl
);
10688 if ((screen
= get_screen(i
)) == NULL
)
10689 errx(1, "ERROR: can't get screen %d.", i
);
10690 screens
[i
].root
= screen
->root
;
10692 /* set default colors */
10693 setscreencolor("red", i
, SWM_S_COLOR_FOCUS
);
10694 setscreencolor("rgb:88/88/88", i
, SWM_S_COLOR_UNFOCUS
);
10695 setscreencolor("rgb:00/80/80", i
, SWM_S_COLOR_BAR_BORDER
);
10696 setscreencolor("rgb:00/40/40", i
,
10697 SWM_S_COLOR_BAR_BORDER_UNFOCUS
);
10698 setscreencolor("black", i
, SWM_S_COLOR_BAR
);
10699 setscreencolor("rgb:a0/a0/a0", i
, SWM_S_COLOR_BAR_FONT
);
10700 setscreencolor("red", i
, SWM_S_COLOR_FOCUS_MAXIMIZED
);
10701 setscreencolor("rgb:88/88/88", i
,
10702 SWM_S_COLOR_UNFOCUS_MAXIMIZED
);
10704 /* create graphics context on screen */
10705 screens
[i
].bar_gc
= xcb_generate_id(conn
);
10707 xcb_create_gc(conn
, screens
[i
].bar_gc
, screens
[i
].root
,
10708 XCB_GC_GRAPHICS_EXPOSURES
, gcv
);
10710 /* set default cursor */
10711 xcb_change_window_attributes(conn
, screens
[i
].root
,
10712 XCB_CW_CURSOR
, wa
);
10714 /* init all workspaces */
10715 /* XXX these should be dynamically allocated too */
10716 for (j
= 0; j
< SWM_WS_MAX
; j
++) {
10717 ws
= &screens
[i
].ws
[j
];
10720 ws
->bar_enabled
= true;
10722 ws
->focus_prev
= NULL
;
10723 ws
->focus_pending
= NULL
;
10726 ws
->state
= SWM_WS_STATE_HIDDEN
;
10727 TAILQ_INIT(&ws
->stack
);
10728 TAILQ_INIT(&ws
->winlist
);
10729 TAILQ_INIT(&ws
->unmanagedlist
);
10731 for (k
= 0; layouts
[k
].l_stack
!= NULL
; k
++)
10732 if (layouts
[k
].l_config
!= NULL
)
10733 layouts
[k
].l_config(ws
,
10734 SWM_ARG_ID_STACKINIT
);
10735 ws
->cur_layout
= &layouts
[0];
10736 ws
->cur_layout
->l_string(ws
);
10742 xcb_randr_select_input(conn
, screens
[i
].root
,
10743 XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE
);
10748 setup_globals(void)
10750 if ((bar_fonts
= strdup(SWM_BAR_FONTS
)) == NULL
)
10751 err(1, "setup_globals: strdup: failed to allocate memory.");
10753 if ((clock_format
= strdup("%a %b %d %R %Z %Y")) == NULL
)
10754 err(1, "setup_globals: strdup: failed to allocate memory.");
10756 if ((syms
= xcb_key_symbols_alloc(conn
)) == NULL
)
10757 errx(1, "unable to allocate key symbols");
10759 a_state
= get_atom_from_string("WM_STATE");
10760 a_prot
= get_atom_from_string("WM_PROTOCOLS");
10761 a_delete
= get_atom_from_string("WM_DELETE_WINDOW");
10762 a_net_supported
= get_atom_from_string("_NET_SUPPORTED");
10763 a_net_wm_check
= get_atom_from_string("_NET_SUPPORTING_WM_CHECK");
10764 a_takefocus
= get_atom_from_string("WM_TAKE_FOCUS");
10765 a_utf8_string
= get_atom_from_string("UTF8_STRING");
10766 a_swm_ws
= get_atom_from_string("_SWM_WS");
10770 shutdown_cleanup(void)
10772 int i
, num_screens
;
10774 /* disable alarm because the following code may not be interrupted */
10776 if (signal(SIGALRM
, SIG_IGN
) == SIG_ERR
)
10777 err(1, "can't disable alarm");
10786 num_screens
= get_screen_count();
10787 for (i
= 0; i
< num_screens
; ++i
) {
10788 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_POINTER_ROOT
,
10789 screens
[i
].root
, XCB_CURRENT_TIME
);
10791 if (screens
[i
].bar_gc
!= XCB_NONE
)
10792 xcb_free_gc(conn
, screens
[i
].bar_gc
);
10793 if (!bar_font_legacy
) {
10794 XftColorFree(display
, DefaultVisual(display
, i
),
10795 DefaultColormap(display
, i
), &bar_font_color
);
10796 XftColorFree(display
, DefaultVisual(display
, i
),
10797 DefaultColormap(display
, i
), &search_font_color
);
10801 if (bar_font_legacy
)
10802 XFreeFontSet(display
, bar_fs
);
10804 XftFontClose(display
, bar_font
);
10807 xcb_key_symbols_free(syms
);
10809 xcb_disconnect(conn
);
10813 event_error(xcb_generic_error_t
*e
)
10817 DNPRINTF(SWM_D_EVENT
, "event_error: %s(%u) from %s(%u), sequence: %u, "
10818 "resource_id: %u, minor_code: %u\n",
10819 xcb_event_get_error_label(e
->error_code
), e
->error_code
,
10820 xcb_event_get_request_label(e
->major_code
), e
->major_code
,
10821 e
->sequence
, e
->resource_id
, e
->minor_code
);
10825 event_handle(xcb_generic_event_t
*evt
)
10827 uint8_t type
= XCB_EVENT_RESPONSE_TYPE(evt
);
10829 DNPRINTF(SWM_D_EVENT
, "XCB Event: %s(%d), seq %u\n",
10830 xcb_event_get_label(XCB_EVENT_RESPONSE_TYPE(evt
)),
10831 XCB_EVENT_RESPONSE_TYPE(evt
), evt
->sequence
);
10834 #define EVENT(type, callback) case type: callback((void *)evt); return
10835 EVENT(0, event_error
);
10836 EVENT(XCB_BUTTON_PRESS
, buttonpress
);
10837 /*EVENT(XCB_BUTTON_RELEASE, buttonpress);*/
10838 /*EVENT(XCB_CIRCULATE_NOTIFY, );*/
10839 /*EVENT(XCB_CIRCULATE_REQUEST, );*/
10840 EVENT(XCB_CLIENT_MESSAGE
, clientmessage
);
10841 /*EVENT(XCB_COLORMAP_NOTIFY, );*/
10842 EVENT(XCB_CONFIGURE_NOTIFY
, configurenotify
);
10843 EVENT(XCB_CONFIGURE_REQUEST
, configurerequest
);
10844 /*EVENT(XCB_CREATE_NOTIFY, );*/
10845 EVENT(XCB_DESTROY_NOTIFY
, destroynotify
);
10846 EVENT(XCB_ENTER_NOTIFY
, enternotify
);
10847 EVENT(XCB_EXPOSE
, expose
);
10849 EVENT(XCB_FOCUS_IN
, focusin
);
10850 EVENT(XCB_FOCUS_OUT
, focusout
);
10852 /*EVENT(XCB_GRAPHICS_EXPOSURE, );*/
10853 /*EVENT(XCB_GRAVITY_NOTIFY, );*/
10854 EVENT(XCB_KEY_PRESS
, keypress
);
10855 /*EVENT(XCB_KEY_RELEASE, keypress);*/
10856 /*EVENT(XCB_KEYMAP_NOTIFY, );*/
10858 EVENT(XCB_LEAVE_NOTIFY
, leavenotify
);
10860 EVENT(XCB_MAP_NOTIFY
, mapnotify
);
10861 EVENT(XCB_MAP_REQUEST
, maprequest
);
10862 EVENT(XCB_MAPPING_NOTIFY
, mappingnotify
);
10863 EVENT(XCB_MOTION_NOTIFY
, motionnotify
);
10864 /*EVENT(XCB_NO_EXPOSURE, );*/
10865 EVENT(XCB_PROPERTY_NOTIFY
, propertynotify
);
10866 /*EVENT(XCB_REPARENT_NOTIFY, );*/
10867 /*EVENT(XCB_RESIZE_REQUEST, );*/
10868 /*EVENT(XCB_SELECTION_CLEAR, );*/
10869 /*EVENT(XCB_SELECTION_NOTIFY, );*/
10870 /*EVENT(XCB_SELECTION_REQUEST, );*/
10871 EVENT(XCB_UNMAP_NOTIFY
, unmapnotify
);
10872 /*EVENT(XCB_VISIBILITY_NOTIFY, );*/
10875 if (type
- randr_eventbase
== XCB_RANDR_SCREEN_CHANGE_NOTIFY
)
10876 screenchange((void *)evt
);
10880 main(int argc
, char *argv
[])
10882 struct swm_region
*r
;
10883 char conf
[PATH_MAX
], *cfile
= NULL
;
10885 int xfd
, i
, num_screens
;
10886 struct sigaction sact
;
10887 xcb_generic_event_t
*evt
;
10889 struct pollfd pfd
[2];
10890 bool stdin_ready
= false, startup
= true;
10892 /* suppress unused warning since var is needed */
10896 time_started
= time(NULL
);
10900 warnx("Welcome to spectrwm V%s Build: %s", SPECTRWM_VERSION
, buildstr
);
10901 if (setlocale(LC_CTYPE
, "") == NULL
|| setlocale(LC_TIME
, "") == NULL
)
10902 warnx("no locale support");
10904 /* handle some signals */
10905 bzero(&sact
, sizeof(sact
));
10906 sigemptyset(&sact
.sa_mask
);
10908 sact
.sa_handler
= sighdlr
;
10909 sigaction(SIGINT
, &sact
, NULL
);
10910 sigaction(SIGQUIT
, &sact
, NULL
);
10911 sigaction(SIGTERM
, &sact
, NULL
);
10912 sigaction(SIGHUP
, &sact
, NULL
);
10914 sact
.sa_handler
= sighdlr
;
10915 sact
.sa_flags
= SA_NOCLDSTOP
;
10916 sigaction(SIGCHLD
, &sact
, NULL
);
10918 if ((display
= XOpenDisplay(0)) == NULL
)
10919 errx(1, "can not open display");
10921 conn
= XGetXCBConnection(display
);
10922 if (xcb_connection_has_error(conn
))
10923 errx(1, "can not get XCB connection");
10925 XSetEventQueueOwner(display
, XCBOwnsEventQueue
);
10927 xcb_prefetch_extension_data(conn
, &xcb_randr_id
);
10928 xfd
= xcb_get_file_descriptor(conn
);
10930 /* look for local and global conf file */
10931 pwd
= getpwuid(getuid());
10933 errx(1, "invalid user: %d", getuid());
10935 xcb_grab_server(conn
);
10936 xcb_aux_sync(conn
);
10938 /* flush all events */
10939 while ((evt
= xcb_poll_for_event(conn
))) {
10940 if (XCB_EVENT_RESPONSE_TYPE(evt
) == 0)
10946 errx(1, "another window manager is currently running");
10948 /* Load Xcursors and/or cursorfont glyph cursors. */
10951 xcb_aux_sync(conn
);
10961 for (i
= 0; ; i
++) {
10966 snprintf(conf
, sizeof conf
, "%s/.%s",
10967 pwd
->pw_dir
, SWM_CONF_FILE
);
10971 snprintf(conf
, sizeof conf
, "/etc/%s",
10976 snprintf(conf
, sizeof conf
, "%s/.%s",
10977 pwd
->pw_dir
, SWM_CONF_FILE_OLD
);
10980 /* global compat */
10981 snprintf(conf
, sizeof conf
, "/etc/%s",
10982 SWM_CONF_FILE_OLD
);
10988 if (strlen(conf
) && stat(conf
, &sb
) != -1)
10989 if (S_ISREG(sb
.st_mode
)) {
10996 /* load conf (if any) */
10998 conf_load(cfile
, SWM_CONF_DEFAULT
);
11002 if (getenv("SWM_STARTED") == NULL
)
11003 setenv("SWM_STARTED", "YES", 1);
11005 /* setup all bars */
11006 num_screens
= get_screen_count();
11007 for (i
= 0; i
< num_screens
; i
++)
11008 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
11011 /* Manage existing windows. */
11018 xcb_ungrab_server(conn
);
11021 /* Update state of each newly mapped workspace. */
11022 for (i
= 0; i
< num_screens
; i
++)
11023 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
11024 r
->ws
->state
= SWM_WS_STATE_MAPPED
;
11026 memset(&pfd
, 0, sizeof(pfd
));
11028 pfd
[0].events
= POLLIN
;
11029 pfd
[1].fd
= STDIN_FILENO
;
11030 pfd
[1].events
= POLLIN
;
11033 while ((evt
= xcb_poll_for_event(conn
))) {
11040 /* If just (re)started, set default focus if needed. */
11044 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
11045 r
= TAILQ_FIRST(&screens
[0].rl
);
11054 num_readable
= poll(pfd
, bar_extra
? 2 : 1, 1000);
11055 if (num_readable
== -1) {
11056 DNPRINTF(SWM_D_MISC
, "poll failed: %s", strerror(errno
));
11057 } else if (num_readable
> 0 && bar_extra
&& pfd
[1].revents
& POLLIN
) {
11058 stdin_ready
= true;
11062 restart(NULL
, NULL
);
11071 stdin_ready
= false;
11072 bar_extra_update();
11079 shutdown_cleanup();