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. */
684 #define SWM_Q_NOFOCUSCYCLE (1<<11) /* Remove from normal focus cycle. */
686 TAILQ_HEAD(quirk_list
, quirk
);
687 struct quirk_list quirks
= TAILQ_HEAD_INITIALIZER(quirks
);
690 * Supported EWMH hints should be added to
691 * both the enum and the ewmh array
697 _NET_CURRENT_DESKTOP
,
698 _NET_DESKTOP_GEOMETRY
,
700 _NET_DESKTOP_VIEWPORT
,
701 _NET_MOVERESIZE_WINDOW
,
702 _NET_NUMBER_OF_DESKTOPS
,
704 _NET_WM_ACTION_ABOVE
,
705 _NET_WM_ACTION_CLOSE
,
706 _NET_WM_ACTION_FULLSCREEN
,
708 _NET_WM_ACTION_RESIZE
,
709 _NET_WM_ALLOWED_ACTIONS
,
711 _NET_WM_FULL_PLACEMENT
,
715 _NET_WM_STATE_FULLSCREEN
,
716 _NET_WM_STATE_HIDDEN
,
717 _NET_WM_STATE_MAXIMIZED_VERT
,
718 _NET_WM_STATE_MAXIMIZED_HORZ
,
719 _NET_WM_STATE_SKIP_PAGER
,
720 _NET_WM_STATE_SKIP_TASKBAR
,
722 _NET_WM_WINDOW_TYPE_DIALOG
,
723 _NET_WM_WINDOW_TYPE_DOCK
,
724 _NET_WM_WINDOW_TYPE_NORMAL
,
725 _NET_WM_WINDOW_TYPE_SPLASH
,
726 _NET_WM_WINDOW_TYPE_TOOLBAR
,
727 _NET_WM_WINDOW_TYPE_UTILITY
,
728 _SWM_WM_STATE_MANUAL
,
735 } ewmh
[SWM_EWMH_HINT_MAX
] = {
736 /* must be in same order as in the enum */
737 {"_NET_ACTIVE_WINDOW", XCB_ATOM_NONE
},
738 {"_NET_CLIENT_LIST", XCB_ATOM_NONE
},
739 {"_NET_CLOSE_WINDOW", XCB_ATOM_NONE
},
740 {"_NET_CURRENT_DESKTOP", XCB_ATOM_NONE
},
741 {"_NET_DESKTOP_GEOMETRY", XCB_ATOM_NONE
},
742 {"_NET_DESKTOP_NAMES", XCB_ATOM_NONE
},
743 {"_NET_DESKTOP_VIEWPORT", XCB_ATOM_NONE
},
744 {"_NET_MOVERESIZE_WINDOW", XCB_ATOM_NONE
},
745 {"_NET_NUMBER_OF_DESKTOPS", XCB_ATOM_NONE
},
746 {"_NET_RESTACK_WINDOW", XCB_ATOM_NONE
},
747 {"_NET_WM_ACTION_ABOVE", XCB_ATOM_NONE
},
748 {"_NET_WM_ACTION_CLOSE", XCB_ATOM_NONE
},
749 {"_NET_WM_ACTION_FULLSCREEN", XCB_ATOM_NONE
},
750 {"_NET_WM_ACTION_MOVE", XCB_ATOM_NONE
},
751 {"_NET_WM_ACTION_RESIZE", XCB_ATOM_NONE
},
752 {"_NET_WM_ALLOWED_ACTIONS", XCB_ATOM_NONE
},
753 {"_NET_WM_DESKTOP", XCB_ATOM_NONE
},
754 {"_NET_WM_FULL_PLACEMENT", XCB_ATOM_NONE
},
755 {"_NET_WM_NAME", XCB_ATOM_NONE
},
756 {"_NET_WM_STATE", XCB_ATOM_NONE
},
757 {"_NET_WM_STATE_ABOVE", XCB_ATOM_NONE
},
758 {"_NET_WM_STATE_FULLSCREEN", XCB_ATOM_NONE
},
759 {"_NET_WM_STATE_HIDDEN", XCB_ATOM_NONE
},
760 {"_NET_WM_STATE_MAXIMIZED_VERT", XCB_ATOM_NONE
},
761 {"_NET_WM_STATE_MAXIMIZED_HORZ", XCB_ATOM_NONE
},
762 {"_NET_WM_STATE_SKIP_PAGER", XCB_ATOM_NONE
},
763 {"_NET_WM_STATE_SKIP_TASKBAR", XCB_ATOM_NONE
},
764 {"_NET_WM_WINDOW_TYPE", XCB_ATOM_NONE
},
765 {"_NET_WM_WINDOW_TYPE_DIALOG", XCB_ATOM_NONE
},
766 {"_NET_WM_WINDOW_TYPE_DOCK", XCB_ATOM_NONE
},
767 {"_NET_WM_WINDOW_TYPE_NORMAL", XCB_ATOM_NONE
},
768 {"_NET_WM_WINDOW_TYPE_SPLASH", XCB_ATOM_NONE
},
769 {"_NET_WM_WINDOW_TYPE_TOOLBAR", XCB_ATOM_NONE
},
770 {"_NET_WM_WINDOW_TYPE_UTILITY", XCB_ATOM_NONE
},
771 {"_SWM_WM_STATE_MANUAL", XCB_ATOM_NONE
},
774 /* EWMH source type */
776 EWMH_SOURCE_TYPE_NONE
= 0,
777 EWMH_SOURCE_TYPE_NORMAL
= 1,
778 EWMH_SOURCE_TYPE_OTHER
= 2,
785 XC_BOTTOM_LEFT_CORNER
,
786 XC_BOTTOM_RIGHT_CORNER
,
794 char *name
; /* Name used by Xcursor .*/
795 uint8_t cf_char
; /* cursorfont index. */
797 } cursors
[XC_MAX
] = {
798 {"fleur", XC_fleur
, XCB_CURSOR_NONE
},
799 {"left_ptr", XC_left_ptr
, XCB_CURSOR_NONE
},
800 {"bottom_left_corner", XC_bottom_left_corner
, XCB_CURSOR_NONE
},
801 {"bottom_right_corner", XC_bottom_right_corner
, XCB_CURSOR_NONE
},
802 {"sizing", XC_sizing
, XCB_CURSOR_NONE
},
803 {"top_left_corner", XC_top_left_corner
, XCB_CURSOR_NONE
},
804 {"top_right_corner", XC_top_right_corner
, XCB_CURSOR_NONE
},
807 #define SWM_SPAWN_OPTIONAL 0x1
811 TAILQ_ENTRY(spawn_prog
) entry
;
817 TAILQ_HEAD(spawn_list
, spawn_prog
);
818 struct spawn_list spawns
= TAILQ_HEAD_INITIALIZER(spawns
);
820 /* user/key callable function IDs */
937 KF_DUMPWINS
, /* MUST BE LAST */
945 enum keyfuncid funcid
;
948 RB_HEAD(key_tree
, key
);
950 /* function prototypes */
951 void adjust_font(struct ws_win
*);
952 char *argsep(char **);
953 void bar_cleanup(struct swm_region
*);
954 void bar_extra_setup(void);
955 void bar_extra_stop(void);
956 int bar_extra_update(void);
957 void bar_fmt(const char *, char *, struct swm_region
*, size_t);
958 void bar_fmt_expand(char *, size_t);
960 void bar_print(struct swm_region
*, const char *);
961 void bar_print_legacy(struct swm_region
*, const char *);
962 void bar_replace(char *, char *, struct swm_region
*, size_t);
963 void bar_replace_pad(char *, int *, size_t);
964 char *bar_replace_seq(char *, char *, struct swm_region
*, size_t *, size_t);
965 void bar_setup(struct swm_region
*);
966 void bar_toggle(struct swm_region
*, union arg
*);
967 void bar_urgent(char *, size_t);
968 void bar_window_class(char *, size_t, struct swm_region
*);
969 void bar_window_class_instance(char *, size_t, struct swm_region
*);
970 void bar_window_float(char *, size_t, struct swm_region
*);
971 void bar_window_instance(char *, size_t, struct swm_region
*);
972 void bar_window_name(char *, size_t, struct swm_region
*);
973 void bar_window_state(char *, size_t, struct swm_region
*);
974 void bar_workspace_name(char *, size_t, struct swm_region
*);
975 void buttonpress(xcb_button_press_event_t
*);
976 void center_pointer(struct swm_region
*);
977 void check_conn(void);
978 void clear_keys(void);
979 int clear_maximized(struct workspace
*);
980 void clientmessage(xcb_client_message_event_t
*);
981 void client_msg(struct ws_win
*, xcb_atom_t
, xcb_timestamp_t
);
982 int conf_load(const char *, int);
983 void configurenotify(xcb_configure_notify_event_t
*);
984 void configurerequest(xcb_configure_request_event_t
*);
985 void config_win(struct ws_win
*, xcb_configure_request_event_t
*);
986 void constrain_window(struct ws_win
*, struct swm_geometry
*, int *);
987 int count_win(struct workspace
*, bool);
988 void cursors_cleanup(void);
989 void cursors_load(void);
990 void custom_region(const char *);
991 void cyclerg(struct swm_region
*, union arg
*);
992 void cyclews(struct swm_region
*, union arg
*);
993 void cycle_layout(struct swm_region
*, union arg
*);
994 void destroynotify(xcb_destroy_notify_event_t
*);
995 void dumpwins(struct swm_region
*, union arg
*);
997 void enternotify(xcb_enter_notify_event_t
*);
998 void event_drain(uint8_t);
999 void event_error(xcb_generic_error_t
*);
1000 void event_handle(xcb_generic_event_t
*);
1001 void ewmh_apply_flags(struct ws_win
*, uint32_t);
1002 void ewmh_autoquirk(struct ws_win
*);
1003 void ewmh_get_desktop_names(void);
1004 void ewmh_get_wm_state(struct ws_win
*);
1005 void ewmh_update_actions(struct ws_win
*);
1006 void ewmh_update_client_list(void);
1007 void ewmh_update_current_desktop(void);
1008 void ewmh_update_desktop_names(void);
1009 void ewmh_update_desktops(void);
1010 void ewmh_change_wm_state(struct ws_win
*, xcb_atom_t
, long);
1011 void ewmh_update_wm_state(struct ws_win
*);
1012 char *expand_tilde(const char *);
1013 void expose(xcb_expose_event_t
*);
1014 void fake_keypress(struct ws_win
*, xcb_keysym_t
, uint16_t);
1015 struct pid_e
*find_pid(pid_t
);
1016 struct ws_win
*find_unmanaged_window(xcb_window_t
);
1017 struct ws_win
*find_window(xcb_window_t
);
1018 void floating_toggle(struct swm_region
*, union arg
*);
1019 void focus(struct swm_region
*, union arg
*);
1021 void focusin(xcb_focus_in_event_t
*);
1022 void focusout(xcb_focus_out_event_t
*);
1024 void focus_flush(void);
1025 void focus_region(struct swm_region
*);
1026 void focusrg(struct swm_region
*, union arg
*);
1027 void focus_win(struct ws_win
*);
1028 void fontset_init(void);
1029 void free_window(struct ws_win
*);
1030 xcb_atom_t
get_atom_from_string(const char *);
1032 char *get_atom_name(xcb_atom_t
);
1034 struct ws_win
*get_focus_magic(struct ws_win
*);
1035 struct ws_win
*get_focus_prev(struct ws_win
*);
1037 char *get_notify_detail_label(uint8_t);
1038 char *get_notify_mode_label(uint8_t);
1040 struct ws_win
*get_pointer_win(xcb_window_t
);
1041 struct ws_win
*get_region_focus(struct swm_region
*);
1042 int get_region_index(struct swm_region
*);
1043 xcb_screen_t
*get_screen(int);
1044 int get_screen_count(void);
1046 char *get_source_type_label(uint32_t);
1047 char *get_stack_mode_name(uint8_t);
1049 int32_t get_swm_ws(xcb_window_t
);
1050 bool get_urgent(struct ws_win
*);
1051 char *get_win_name(xcb_window_t
);
1052 uint8_t get_win_state(xcb_window_t
);
1053 void get_wm_protocols(struct ws_win
*);
1054 int get_ws_idx(struct ws_win
*);
1055 void grabbuttons(struct ws_win
*);
1056 void grabkeys(void);
1057 void grab_windows(void);
1058 void iconify(struct swm_region
*, union arg
*);
1059 bool isxlfd(char *);
1060 void keypress(xcb_key_press_event_t
*);
1061 int key_cmp(struct key
*, struct key
*);
1062 void key_insert(unsigned int, KeySym
, enum keyfuncid
, const char *);
1063 struct key
*key_lookup(unsigned int, KeySym
);
1064 void key_remove(struct key
*);
1065 void key_replace(struct key
*, unsigned int, KeySym
, enum keyfuncid
,
1067 void kill_bar_extra_atexit(void);
1068 void kill_refs(struct ws_win
*);
1070 void leavenotify(xcb_leave_notify_event_t
*);
1072 void load_float_geom(struct ws_win
*);
1073 void lower_window(struct ws_win
*);
1074 struct ws_win
*manage_window(xcb_window_t
, int, bool);
1075 void map_window(struct ws_win
*);
1076 void mapnotify(xcb_map_notify_event_t
*);
1077 void mappingnotify(xcb_mapping_notify_event_t
*);
1078 void maprequest(xcb_map_request_event_t
*);
1079 void maximize_toggle(struct swm_region
*, union arg
*);
1080 void motionnotify(xcb_motion_notify_event_t
*);
1081 void move(struct ws_win
*, union arg
*);
1082 void move_step(struct swm_region
*, union arg
*);
1083 uint32_t name_to_pixel(int, const char *);
1084 void name_workspace(struct swm_region
*, union arg
*);
1085 void new_region(struct swm_screen
*, int, int, int, int);
1086 int parsekeys(const char *, unsigned int, unsigned int *, KeySym
*);
1087 int parsequirks(const char *, uint32_t *, int *);
1088 int parse_rgb(const char *, uint16_t *, uint16_t *, uint16_t *);
1089 void pressbutton(struct swm_region
*, union arg
*);
1090 void priorws(struct swm_region
*, union arg
*);
1092 void print_win_geom(xcb_window_t
);
1094 void propertynotify(xcb_property_notify_event_t
*);
1095 void quirk_free(struct quirk
*);
1096 void quirk_insert(const char *, const char *, const char *, uint32_t, int);
1097 void quirk_remove(struct quirk
*);
1098 void quirk_replace(struct quirk
*, const char *, const char *, const char *,
1100 void quit(struct swm_region
*, union arg
*);
1101 void raise_toggle(struct swm_region
*, union arg
*);
1102 void raise_window(struct ws_win
*);
1103 void region_containment(struct ws_win
*, struct swm_region
*, int);
1104 struct swm_region
*region_under(struct swm_screen
*, int, int);
1105 void regionize(struct ws_win
*, int, int);
1106 void resize(struct ws_win
*, union arg
*);
1107 void resize_step(struct swm_region
*, union arg
*);
1108 void restart(struct swm_region
*, union arg
*);
1109 struct swm_region
*root_to_region(xcb_window_t
, int);
1110 void screenchange(xcb_randr_screen_change_notify_event_t
*);
1111 void scan_randr(int);
1112 void search_do_resp(void);
1113 void search_resp_name_workspace(const char *, size_t);
1114 void search_resp_search_window(const char *);
1115 void search_resp_search_workspace(const char *);
1116 void search_resp_uniconify(const char *, size_t);
1117 void search_win(struct swm_region
*, union arg
*);
1118 void search_win_cleanup(void);
1119 void search_workspace(struct swm_region
*, union arg
*);
1120 void send_to_rg(struct swm_region
*, union arg
*);
1121 void send_to_ws(struct swm_region
*, union arg
*);
1122 void set_region(struct swm_region
*);
1123 int setautorun(const char *, const char *, int);
1124 int setconfbinding(const char *, const char *, int);
1125 int setconfcolor(const char *, const char *, int);
1126 int setconfmodkey(const char *, const char *, int);
1127 int setconfmousebuttonmove(const char *, const char *, int);
1128 int setconfmousebuttonresize(const char *, const char *, int);
1129 int setconfquirk(const char *, const char *, int);
1130 int setconfregion(const char *, const char *, int);
1131 int setconfspawn(const char *, const char *, int);
1132 int setconfvalue(const char *, const char *, int);
1133 void setkeybinding(unsigned int, KeySym
, enum keyfuncid
, const char *);
1134 int setkeymapping(const char *, const char *, int);
1135 int setlayout(const char *, const char *, int);
1136 void setquirk(const char *, const char *, const char *, uint32_t, int);
1137 void setscreencolor(const char *, int, int);
1138 void setspawn(const char *, const char *, int);
1139 void setup_ewmh(void);
1140 void setup_globals(void);
1141 void setup_keys(void);
1142 void setup_quirks(void);
1143 void setup_screens(void);
1144 void setup_spawn(void);
1145 void set_child_transient(struct ws_win
*, xcb_window_t
*);
1146 void set_win_state(struct ws_win
*, uint8_t);
1147 void shutdown_cleanup(void);
1149 void socket_setnonblock(int);
1150 void sort_windows(struct ws_win_list
*);
1151 void spawn(int, union arg
*, bool);
1152 void spawn_custom(struct swm_region
*, union arg
*, const char *);
1153 int spawn_expand(struct swm_region
*, union arg
*, const char *, char ***);
1154 void spawn_insert(const char *, const char *, int);
1155 struct spawn_prog
*spawn_find(const char *);
1156 void spawn_remove(struct spawn_prog
*);
1157 void spawn_replace(struct spawn_prog
*, const char *, const char *, int);
1158 void spawn_select(struct swm_region
*, union arg
*, const char *, int *);
1159 void stack_config(struct swm_region
*, union arg
*);
1160 void stack_master(struct workspace
*, struct swm_geometry
*, int, bool);
1161 void store_float_geom(struct ws_win
*);
1162 char *strdupsafe(const char *);
1163 void swapwin(struct swm_region
*, union arg
*);
1164 void switchws(struct swm_region
*, union arg
*);
1165 void teardown_ewmh(void);
1166 void unescape_selector(char *);
1167 void unfocus_win(struct ws_win
*);
1168 void uniconify(struct swm_region
*, union arg
*);
1169 void unmanage_window(struct ws_win
*);
1170 void unmapnotify(xcb_unmap_notify_event_t
*);
1171 void unmap_all(void);
1172 void unmap_window(struct ws_win
*);
1173 void updatenumlockmask(void);
1174 void update_floater(struct ws_win
*);
1175 void update_modkey(unsigned int);
1176 unsigned char update_mousebutton(unsigned char, unsigned int);
1177 void update_win_stacking(struct ws_win
*);
1178 void update_window(struct ws_win
*);
1179 void update_window_color(struct ws_win
*);
1180 void update_wm_state(struct ws_win
*win
);
1181 void validate_spawns(void);
1182 int validate_win(struct ws_win
*);
1183 int validate_ws(struct workspace
*);
1184 void version(struct swm_region
*, union arg
*);
1185 void win_to_ws(struct ws_win
*, int, bool);
1186 pid_t
window_get_pid(xcb_window_t
);
1187 void wkill(struct swm_region
*, union arg
*);
1188 void update_ws_stack(struct workspace
*);
1189 void xft_init(struct swm_region
*);
1190 void _add_startup_exception(const char *, va_list);
1191 void add_startup_exception(const char *, ...);
1193 RB_PROTOTYPE(key_tree
, key
, entry
, key_cmp
);
1194 RB_GENERATE(key_tree
, key
, entry
, key_cmp
);
1195 struct key_tree keys
;
1200 xcb_font_t cf
= XCB_NONE
;
1203 for (i
= 0; i
< LENGTH(cursors
); ++i
) {
1204 /* try to load Xcursor first. */
1205 cursors
[i
].cid
= XcursorLibraryLoadCursor(display
,
1208 /* fallback to cursorfont. */
1209 if (cursors
[i
].cid
== XCB_CURSOR_NONE
) {
1210 if (cf
== XCB_NONE
) {
1211 cf
= xcb_generate_id(conn
);
1212 xcb_open_font(conn
, cf
, strlen("cursor"),
1216 cursors
[i
].cid
= xcb_generate_id(conn
);
1217 xcb_create_glyph_cursor(conn
, cursors
[i
].cid
, cf
, cf
,
1218 cursors
[i
].cf_char
, cursors
[i
].cf_char
+ 1, 0, 0, 0,
1219 0xffff, 0xffff, 0xffff);
1225 xcb_close_font(conn
, cf
);
1229 cursors_cleanup(void)
1232 for (i
= 0; i
< LENGTH(cursors
); ++i
)
1233 xcb_free_cursor(conn
, cursors
[i
].cid
);
1237 expand_tilde(const char *s
)
1239 struct passwd
*ppwd
;
1247 errx(1, "expand_tilde: NULL string.");
1250 result
= strdup(sc
);
1256 if ((max
= sysconf(_SC_LOGIN_NAME_MAX
)) == -1)
1257 errx(1, "expand_tilde: sysconf");
1259 if ((user
= calloc(1, max
+ 1)) == NULL
)
1260 errx(1, "expand_tilde: calloc");
1262 for (i
= 0; s
[i
] != '/' && s
[i
] != '\0'; ++i
)
1267 ppwd
= strlen(user
) == 0 ? getpwuid(getuid()) : getpwnam(user
);
1271 result
= strdup(sc
);
1273 if (asprintf(&result
, "%s%s", ppwd
->pw_dir
, s
) == -1)
1277 errx(1, "expand_tilde: failed to allocate memory.");
1283 parse_rgb(const char *rgb
, uint16_t *rr
, uint16_t *gg
, uint16_t *bb
)
1285 unsigned int tmpr
, tmpg
, tmpb
;
1287 if (sscanf(rgb
, "rgb:%x/%x/%x", &tmpr
, &tmpg
, &tmpb
) != 3)
1290 *rr
= RGB_8_TO_16(tmpr
);
1291 *gg
= RGB_8_TO_16(tmpg
);
1292 *bb
= RGB_8_TO_16(tmpb
);
1298 get_screen(int screen
)
1300 const xcb_setup_t
*r
;
1301 xcb_screen_iterator_t iter
;
1303 if ((r
= xcb_get_setup(conn
)) == NULL
) {
1304 DNPRINTF(SWM_D_MISC
, "get_screen: xcb_get_setup\n");
1308 iter
= xcb_setup_roots_iterator(r
);
1309 for (; iter
.rem
; --screen
, xcb_screen_next(&iter
))
1317 get_screen_count(void)
1319 const xcb_setup_t
*r
;
1321 if ((r
= xcb_get_setup(conn
)) == NULL
) {
1322 DNPRINTF(SWM_D_MISC
, "get_screen_count: xcb_get_setup\n");
1326 return xcb_setup_roots_length(r
);
1330 get_region_index(struct swm_region
*r
)
1332 struct swm_region
*rr
;
1338 TAILQ_FOREACH(rr
, &r
->s
->rl
, entry
) {
1353 if (focus_mode
== SWM_FOCUS_DEFAULT
)
1354 event_drain(XCB_ENTER_NOTIFY
);
1360 get_atom_from_string(const char *str
)
1362 xcb_intern_atom_cookie_t c
;
1363 xcb_intern_atom_reply_t
*r
;
1366 c
= xcb_intern_atom(conn
, 0, strlen(str
), str
);
1367 r
= xcb_intern_atom_reply(conn
, c
, NULL
);
1375 return (XCB_ATOM_NONE
);
1379 get_wm_protocols(struct ws_win
*win
) {
1381 xcb_icccm_get_wm_protocols_reply_t wpr
;
1383 if (xcb_icccm_get_wm_protocols_reply(conn
,
1384 xcb_icccm_get_wm_protocols(conn
, win
->id
, a_prot
),
1386 for (i
= 0; i
< (int)wpr
.atoms_len
; i
++) {
1387 if (wpr
.atoms
[i
] == a_takefocus
)
1388 win
->take_focus
= true;
1389 if (wpr
.atoms
[i
] == a_delete
)
1390 win
->can_delete
= true;
1392 xcb_icccm_get_wm_protocols_reply_wipe(&wpr
);
1399 xcb_window_t root
, win
;
1400 int i
, j
, num_screens
;
1402 for (i
= 0; i
< LENGTH(ewmh
); i
++)
1403 ewmh
[i
].atom
= get_atom_from_string(ewmh
[i
].name
);
1405 num_screens
= get_screen_count();
1406 for (i
= 0; i
< num_screens
; i
++) {
1407 root
= screens
[i
].root
;
1409 /* Set up _NET_SUPPORTING_WM_CHECK. */
1410 win
= xcb_generate_id(conn
);
1411 xcb_create_window(conn
, XCB_COPY_FROM_PARENT
, win
, root
,
1412 0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT
,
1413 XCB_COPY_FROM_PARENT
, 0, NULL
);
1415 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, root
,
1416 a_net_wm_check
, XCB_ATOM_WINDOW
, 32, 1, &win
);
1417 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
,
1418 a_net_wm_check
, XCB_ATOM_WINDOW
, 32, 1, &win
);
1421 * Impersonate LG3D non-reparenting WM, written by Sun, to
1422 * workaround a Java GUI rendering issue.
1424 if (java_workaround
)
1425 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
,
1426 ewmh
[_NET_WM_NAME
].atom
, a_utf8_string
,
1427 8, strlen("LG3D"), "LG3D");
1429 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
,
1430 ewmh
[_NET_WM_NAME
].atom
, a_utf8_string
,
1431 8, strlen("spectrwm"), "spectrwm");
1433 /* Report supported atoms */
1434 xcb_delete_property(conn
, root
, a_net_supported
);
1435 for (j
= 0; j
< LENGTH(ewmh
); j
++)
1436 xcb_change_property(conn
, XCB_PROP_MODE_APPEND
, root
,
1437 a_net_supported
, XCB_ATOM_ATOM
, 32, 1,
1442 ewmh_update_desktops();
1443 ewmh_get_desktop_names();
1451 xcb_get_property_cookie_t pc
;
1452 xcb_get_property_reply_t
*pr
;
1454 num_screens
= get_screen_count();
1456 for (i
= 0; i
< num_screens
; i
++) {
1457 /* Get the support check window and destroy it */
1458 pc
= xcb_get_property(conn
, 0, screens
[i
].root
, a_net_wm_check
,
1459 XCB_ATOM_WINDOW
, 0, 1);
1460 pr
= xcb_get_property_reply(conn
, pc
, NULL
);
1463 if (pr
->format
== a_net_wm_check
) {
1464 id
= *((xcb_window_t
*)xcb_get_property_value(pr
));
1466 xcb_destroy_window(conn
, id
);
1467 xcb_delete_property(conn
, screens
[i
].root
,
1469 xcb_delete_property(conn
, screens
[i
].root
,
1477 ewmh_autoquirk(struct ws_win
*win
)
1479 xcb_get_property_reply_t
*r
;
1480 xcb_get_property_cookie_t c
;
1484 c
= xcb_get_property(conn
, 0, win
->id
,
1485 ewmh
[_NET_WM_WINDOW_TYPE
].atom
, XCB_ATOM_ATOM
, 0, UINT32_MAX
);
1486 r
= xcb_get_property_reply(conn
, c
, NULL
);
1490 type
= xcb_get_property_value(r
);
1491 n
= xcb_get_property_value_length(r
) / sizeof(xcb_atom_t
);
1493 for (i
= 0; i
< n
; i
++) {
1494 if (type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_NORMAL
].atom
)
1496 if (type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_DOCK
].atom
||
1497 type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_TOOLBAR
].atom
||
1498 type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_UTILITY
].atom
) {
1499 win
->quirks
= SWM_Q_FLOAT
| SWM_Q_ANYWHERE
;
1502 if (type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_SPLASH
].atom
||
1503 type
[i
] == ewmh
[_NET_WM_WINDOW_TYPE_DIALOG
].atom
) {
1504 win
->quirks
= SWM_Q_FLOAT
;
1512 ewmh_update_actions(struct ws_win
*win
)
1514 xcb_atom_t actions
[SWM_EWMH_ACTION_COUNT_MAX
];
1520 actions
[n
++] = ewmh
[_NET_WM_ACTION_CLOSE
].atom
;
1523 actions
[n
++] = ewmh
[_NET_WM_ACTION_MOVE
].atom
;
1524 actions
[n
++] = ewmh
[_NET_WM_ACTION_RESIZE
].atom
;
1525 actions
[n
++] = ewmh
[_NET_WM_ACTION_ABOVE
].atom
;
1528 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
,
1529 ewmh
[_NET_WM_ALLOWED_ACTIONS
].atom
, XCB_ATOM_ATOM
, 32, 1, actions
);
1532 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1533 #define _NET_WM_STATE_ADD 1 /* add/set property */
1534 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1537 ewmh_change_wm_state(struct ws_win
*win
, xcb_atom_t state
, long action
)
1544 name
= get_atom_name(state
);
1545 DNPRINTF(SWM_D_PROP
, "ewmh_change_wm_state: win %#x, state: %s, "
1546 "action: %ld\n", WINID(win
), name
, action
);
1552 if (state
== ewmh
[_NET_WM_STATE_FULLSCREEN
].atom
)
1553 flag
= EWMH_F_FULLSCREEN
;
1554 else if (state
== ewmh
[_NET_WM_STATE_ABOVE
].atom
)
1555 flag
= EWMH_F_ABOVE
;
1556 else if (state
== ewmh
[_NET_WM_STATE_HIDDEN
].atom
)
1557 flag
= EWMH_F_HIDDEN
;
1558 else if (state
== ewmh
[_NET_WM_STATE_MAXIMIZED_VERT
].atom
||
1559 state
== ewmh
[_NET_WM_STATE_MAXIMIZED_HORZ
].atom
)
1560 flag
= EWMH_F_MAXIMIZED
;
1561 else if (state
== ewmh
[_SWM_WM_STATE_MANUAL
].atom
)
1562 flag
= SWM_F_MANUAL
;
1563 else if (state
== ewmh
[_NET_WM_STATE_SKIP_PAGER
].atom
)
1564 flag
= EWMH_F_SKIP_PAGER
;
1565 else if (state
== ewmh
[_NET_WM_STATE_SKIP_TASKBAR
].atom
)
1566 flag
= EWMH_F_SKIP_TASKBAR
;
1568 /* Disallow unfloating transients. */
1569 if (TRANS(win
) && flag
== EWMH_F_ABOVE
)
1572 new_flags
= win
->ewmh_flags
;
1575 case _NET_WM_STATE_REMOVE
:
1578 case _NET_WM_STATE_ADD
:
1581 case _NET_WM_STATE_TOGGLE
:
1586 ewmh_apply_flags(win
, new_flags
);
1589 DNPRINTF(SWM_D_PROP
, "ewmh_change_wm_state: done.\n");
1593 ewmh_apply_flags(struct ws_win
*win
, uint32_t pending
)
1595 struct workspace
*ws
;
1598 changed
= win
->ewmh_flags
^ pending
;
1602 DNPRINTF(SWM_D_PROP
, "ewmh_apply_flags: pending: %d\n", pending
);
1604 win
->ewmh_flags
= pending
;
1607 if (changed
& EWMH_F_HIDDEN
) {
1609 if (focus_mode
!= SWM_FOCUS_FOLLOW
)
1610 ws
->focus_pending
= get_focus_prev(win
);
1615 /* Reload floating geometry in case region changed. */
1617 load_float_geom(win
);
1619 /* The window is no longer iconic, prepare focus. */
1620 if (focus_mode
!= SWM_FOCUS_FOLLOW
)
1621 ws
->focus_pending
= get_focus_magic(win
);
1626 if (changed
& EWMH_F_ABOVE
) {
1627 if (ws
->cur_layout
!= &layouts
[SWM_MAX_STACK
]) {
1629 load_float_geom(win
);
1630 else if (!MAXIMIZED(win
))
1631 store_float_geom(win
);
1633 win
->ewmh_flags
&= ~EWMH_F_MAXIMIZED
;
1634 changed
&= ~EWMH_F_MAXIMIZED
;
1638 win
->ewmh_flags
^= EWMH_F_ABOVE
& pending
;
1642 if (changed
& EWMH_F_MAXIMIZED
) {
1643 /* VERT and/or HORZ changed. */
1645 if (!MAXIMIZED(win
))
1646 load_float_geom(win
);
1648 store_float_geom(win
);
1651 if (MAXIMIZED(win
)) {
1652 if (focus_mode
!= SWM_FOCUS_FOLLOW
&&
1653 ws
->cur_layout
!= &layouts
[SWM_MAX_STACK
]) {
1657 ws
->focus_pending
= win
;
1661 update_window_color(win
);
1665 if (changed
& EWMH_F_FULLSCREEN
) {
1666 if (FULLSCREEN(win
)) {
1667 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
1671 ws
->focus_pending
= win
;
1674 load_float_geom(win
);
1677 win
->ewmh_flags
&= ~EWMH_F_MAXIMIZED
;
1681 DNPRINTF(SWM_D_PROP
, "ewmh_apply_flags: done.\n");
1685 ewmh_update_wm_state(struct ws_win
*win
) {
1686 xcb_atom_t vals
[SWM_EWMH_ACTION_COUNT_MAX
];
1690 vals
[n
++] = ewmh
[_NET_WM_STATE_HIDDEN
].atom
;
1691 if (FULLSCREEN(win
))
1692 vals
[n
++] = ewmh
[_NET_WM_STATE_FULLSCREEN
].atom
;
1693 if (MAXIMIZED_VERT(win
))
1694 vals
[n
++] = ewmh
[_NET_WM_STATE_MAXIMIZED_VERT
].atom
;
1695 if (MAXIMIZED_HORZ(win
))
1696 vals
[n
++] = ewmh
[_NET_WM_STATE_MAXIMIZED_HORZ
].atom
;
1697 if (win
->ewmh_flags
& EWMH_F_SKIP_PAGER
)
1698 vals
[n
++] = ewmh
[_NET_WM_STATE_SKIP_PAGER
].atom
;
1699 if (win
->ewmh_flags
& EWMH_F_SKIP_TASKBAR
)
1700 vals
[n
++] = ewmh
[_NET_WM_STATE_SKIP_TASKBAR
].atom
;
1701 if (win
->ewmh_flags
& EWMH_F_ABOVE
)
1702 vals
[n
++] = ewmh
[_NET_WM_STATE_ABOVE
].atom
;
1703 if (win
->ewmh_flags
& SWM_F_MANUAL
)
1704 vals
[n
++] = ewmh
[_SWM_WM_STATE_MANUAL
].atom
;
1707 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
,
1708 ewmh
[_NET_WM_STATE
].atom
, XCB_ATOM_ATOM
, 32, n
, vals
);
1710 xcb_delete_property(conn
, win
->id
, ewmh
[_NET_WM_STATE
].atom
);
1714 ewmh_get_wm_state(struct ws_win
*win
)
1717 xcb_get_property_cookie_t c
;
1718 xcb_get_property_reply_t
*r
;
1724 win
->ewmh_flags
= 0;
1726 c
= xcb_get_property(conn
, 0, win
->id
, ewmh
[_NET_WM_STATE
].atom
,
1727 XCB_ATOM_ATOM
, 0, UINT32_MAX
);
1728 r
= xcb_get_property_reply(conn
, c
, NULL
);
1732 states
= xcb_get_property_value(r
);
1733 n
= xcb_get_property_value_length(r
) / sizeof(xcb_atom_t
);
1735 for (i
= 0; i
< n
; i
++)
1736 ewmh_change_wm_state(win
, states
[i
], _NET_WM_STATE_ADD
);
1744 dumpwins(struct swm_region
*r
, union arg
*args
)
1748 xcb_get_window_attributes_cookie_t c
;
1749 xcb_get_window_attributes_reply_t
*wa
;
1751 /* suppress unused warning since var is needed */
1754 if (r
->ws
== NULL
) {
1755 DPRINTF("dumpwins: invalid workspace\n");
1759 DPRINTF("=== managed window list ws %02d ===\n", r
->ws
->idx
);
1760 TAILQ_FOREACH(w
, &r
->ws
->winlist
, entry
) {
1761 state
= get_win_state(w
->id
);
1762 c
= xcb_get_window_attributes(conn
, w
->id
);
1763 wa
= xcb_get_window_attributes_reply(conn
, c
, NULL
);
1765 DPRINTF("win %#x, map_state: %d, state: %u, "
1766 "transient: %#x\n", w
->id
, wa
->map_state
,
1767 state
, w
->transient
);
1770 DPRINTF("win %#x, failed xcb_get_window_attributes\n",
1774 DPRINTF("=== stacking order (top down) === \n");
1775 TAILQ_FOREACH(w
, &r
->ws
->stack
, stack_entry
) {
1776 DPRINTF("win %#x, fs: %s, maximized: %s, above: %s, "
1777 "iconic: %s\n", w
->id
, YESNO(FULLSCREEN(w
)),
1778 YESNO(MAXIMIZED(w
)), YESNO(ABOVE(w
)), YESNO(ICONIC(w
)));
1781 DPRINTF("===== unmanaged window list =====\n");
1782 TAILQ_FOREACH(w
, &r
->ws
->unmanagedlist
, entry
) {
1783 state
= get_win_state(w
->id
);
1784 c
= xcb_get_window_attributes(conn
, w
->id
);
1785 wa
= xcb_get_window_attributes_reply(conn
, c
, NULL
);
1787 DPRINTF("win %#x, map_state: %d, state: %u, "
1788 "transient: %#x\n", w
->id
, wa
->map_state
,
1789 state
, w
->transient
);
1792 DPRINTF("win %#x, failed xcb_get_window_attributes\n",
1796 DPRINTF("=================================\n");
1800 dumpwins(struct swm_region
*r
, union arg
*s
)
1805 #endif /* SWM_DEBUG */
1810 int saved_errno
, status
;
1813 saved_errno
= errno
;
1817 while ((pid
= waitpid(WAIT_ANY
, &status
, WNOHANG
)) != 0) {
1822 if (errno
!= ECHILD
)
1823 warn("sighdlr: waitpid");
1824 #endif /* SWM_DEBUG */
1827 if (pid
== searchpid
)
1831 if (WIFEXITED(status
)) {
1832 if (WEXITSTATUS(status
) != 0)
1833 warnx("sighdlr: child exit status: %d",
1834 WEXITSTATUS(status
));
1836 warnx("sighdlr: child is terminated "
1838 #endif /* SWM_DEBUG */
1852 errno
= saved_errno
;
1858 struct pid_e
*p
= NULL
;
1860 DNPRINTF(SWM_D_MISC
, "find_pid: %d\n", pid
);
1865 TAILQ_FOREACH(p
, &pidlist
, entry
) {
1874 name_to_pixel(int sidx
, const char *colorname
)
1876 uint32_t result
= 0;
1877 char cname
[32] = "#";
1878 xcb_screen_t
*screen
;
1879 xcb_colormap_t cmap
;
1880 xcb_alloc_color_reply_t
*cr
;
1881 xcb_alloc_named_color_reply_t
*nr
;
1882 uint16_t rr
, gg
, bb
;
1884 screen
= get_screen(sidx
);
1885 cmap
= screen
->default_colormap
;
1887 /* color is in format rgb://rr/gg/bb */
1888 if (strncmp(colorname
, "rgb:", 4) == 0) {
1889 if (parse_rgb(colorname
, &rr
, &gg
, &bb
) == -1)
1890 warnx("could not parse rgb %s", colorname
);
1892 cr
= xcb_alloc_color_reply(conn
,
1893 xcb_alloc_color(conn
, cmap
, rr
, gg
, bb
),
1899 warnx("color '%s' not found", colorname
);
1902 nr
= xcb_alloc_named_color_reply(conn
,
1903 xcb_alloc_named_color(conn
, cmap
, strlen(colorname
),
1906 strlcat(cname
, colorname
+ 2, sizeof cname
- 1);
1907 nr
= xcb_alloc_named_color_reply(conn
,
1908 xcb_alloc_named_color(conn
, cmap
, strlen(cname
),
1915 warnx("color '%s' not found", colorname
);
1922 setscreencolor(const char *val
, int i
, int c
)
1924 if (i
< 0 || i
>= get_screen_count())
1927 screens
[i
].c
[c
].pixel
= name_to_pixel(i
, val
);
1928 free(screens
[i
].c
[c
].name
);
1929 if ((screens
[i
].c
[c
].name
= strdup(val
)) == NULL
)
1934 fancy_stacker(struct workspace
*ws
)
1936 strlcpy(ws
->stacker
, "[ ]", sizeof ws
->stacker
);
1937 if (ws
->cur_layout
->l_stack
== vertical_stack
)
1938 snprintf(ws
->stacker
, sizeof ws
->stacker
,
1939 ws
->l_state
.vertical_flip
? "[%d>%d]" : "[%d|%d]",
1940 ws
->l_state
.vertical_mwin
, ws
->l_state
.vertical_stacks
);
1941 else if (ws
->cur_layout
->l_stack
== horizontal_stack
)
1942 snprintf(ws
->stacker
, sizeof ws
->stacker
,
1943 ws
->l_state
.horizontal_flip
? "[%dv%d]" : "[%d-%d]",
1944 ws
->l_state
.horizontal_mwin
, ws
->l_state
.horizontal_stacks
);
1948 plain_stacker(struct workspace
*ws
)
1950 strlcpy(ws
->stacker
, "[ ]", sizeof ws
->stacker
);
1951 if (ws
->cur_layout
->l_stack
== vertical_stack
)
1952 strlcpy(ws
->stacker
, ws
->l_state
.vertical_flip
? "[>]" : "[|]",
1953 sizeof ws
->stacker
);
1954 else if (ws
->cur_layout
->l_stack
== horizontal_stack
)
1955 strlcpy(ws
->stacker
, ws
->l_state
.horizontal_flip
? "[v]" : "[-]",
1956 sizeof ws
->stacker
);
1960 custom_region(const char *val
)
1962 unsigned int x
, y
, w
, h
;
1963 int sidx
, num_screens
;
1964 xcb_screen_t
*screen
;
1966 num_screens
= get_screen_count();
1967 if (sscanf(val
, "screen[%d]:%ux%u+%u+%u", &sidx
, &w
, &h
, &x
, &y
) != 5)
1968 errx(1, "invalid custom region, "
1969 "should be 'screen[<n>]:<n>x<n>+<n>+<n>");
1970 if (sidx
< 1 || sidx
> num_screens
)
1971 errx(1, "invalid screen index: %d out of bounds (maximum %d)",
1975 if ((screen
= get_screen(sidx
)) == NULL
)
1976 errx(1, "ERROR: can't get screen %d.", sidx
);
1979 errx(1, "region %ux%u+%u+%u too small", w
, h
, x
, y
);
1981 if (x
> screen
->width_in_pixels
||
1982 y
> screen
->height_in_pixels
||
1983 w
+ x
> screen
->width_in_pixels
||
1984 h
+ y
> screen
->height_in_pixels
) {
1985 warnx("ignoring region %ux%u+%u+%u - not within screen "
1986 "boundaries (%ux%u)", w
, h
, x
, y
,
1987 screen
->width_in_pixels
, screen
->height_in_pixels
);
1991 new_region(&screens
[sidx
], x
, y
, w
, h
);
1995 socket_setnonblock(int fd
)
1999 if ((flags
= fcntl(fd
, F_GETFL
, 0)) == -1)
2000 err(1, "fcntl F_GETFL");
2001 flags
|= O_NONBLOCK
;
2002 if ((flags
= fcntl(fd
, F_SETFL
, flags
)) == -1)
2003 err(1, "fcntl F_SETFL");
2007 bar_print_legacy(struct swm_region
*r
, const char *s
)
2009 xcb_rectangle_t rect
;
2014 XRectangle ibox
, lbox
;
2018 XmbTextExtents(bar_fs
, s
, len
, &ibox
, &lbox
);
2020 switch (bar_justify
) {
2021 case SWM_BAR_JUSTIFY_LEFT
:
2024 case SWM_BAR_JUSTIFY_CENTER
:
2025 x
= (WIDTH(r
) - lbox
.width
) / 2;
2027 case SWM_BAR_JUSTIFY_RIGHT
:
2028 x
= WIDTH(r
) - lbox
.width
- SWM_BAR_OFFSET
;
2032 if (x
< SWM_BAR_OFFSET
)
2037 rect
.width
= WIDTH(r
->bar
);
2038 rect
.height
= HEIGHT(r
->bar
);
2040 /* clear back buffer */
2041 gcv
[0] = r
->s
->c
[SWM_S_COLOR_BAR
].pixel
;
2042 xcb_change_gc(conn
, r
->s
->bar_gc
, XCB_GC_FOREGROUND
, gcv
);
2043 xcb_poly_fill_rectangle(conn
, r
->bar
->buffer
, r
->s
->bar_gc
, 1, &rect
);
2045 /* draw back buffer */
2046 gcvd
.graphics_exposures
= 0;
2047 draw
= XCreateGC(display
, r
->bar
->buffer
, GCGraphicsExposures
, &gcvd
);
2048 XSetForeground(display
, draw
, r
->s
->c
[SWM_S_COLOR_BAR_FONT
].pixel
);
2049 DRAWSTRING(display
, r
->bar
->buffer
, bar_fs
, draw
,
2050 x
, (bar_fs_extents
->max_logical_extent
.height
- lbox
.height
) / 2 -
2052 XFreeGC(display
, draw
);
2055 xcb_copy_area(conn
, r
->bar
->buffer
, r
->bar
->id
, r
->s
->bar_gc
, 0, 0,
2056 0, 0, WIDTH(r
->bar
), HEIGHT(r
->bar
));
2060 bar_print(struct swm_region
*r
, const char *s
)
2063 xcb_rectangle_t rect
;
2071 XftTextExtentsUtf8(display
, bar_font
, (FcChar8
*)s
, len
, &info
);
2073 switch (bar_justify
) {
2074 case SWM_BAR_JUSTIFY_LEFT
:
2077 case SWM_BAR_JUSTIFY_CENTER
:
2078 x
= (WIDTH(r
) - info
.width
) / 2;
2080 case SWM_BAR_JUSTIFY_RIGHT
:
2081 x
= WIDTH(r
) - info
.width
- SWM_BAR_OFFSET
;
2085 if (x
< SWM_BAR_OFFSET
)
2090 rect
.width
= WIDTH(r
->bar
);
2091 rect
.height
= HEIGHT(r
->bar
);
2093 /* clear back buffer */
2094 gcv
[0] = r
->s
->c
[SWM_S_COLOR_BAR
].pixel
;
2095 xcb_change_gc(conn
, r
->s
->bar_gc
, XCB_GC_FOREGROUND
, gcv
);
2096 xcb_poly_fill_rectangle(conn
, r
->bar
->buffer
, r
->s
->bar_gc
, 1, &rect
);
2098 /* draw back buffer */
2099 draw
= XftDrawCreate(display
, r
->bar
->buffer
,
2100 DefaultVisual(display
, r
->s
->idx
),
2101 DefaultColormap(display
, r
->s
->idx
));
2103 XftDrawStringUtf8(draw
, &bar_font_color
, bar_font
, x
,
2104 (HEIGHT(r
->bar
) + bar_font
->height
) / 2 - bar_font
->descent
,
2107 XftDrawDestroy(draw
);
2110 xcb_copy_area(conn
, r
->bar
->buffer
, r
->bar
->id
, r
->s
->bar_gc
, 0, 0,
2111 0, 0, WIDTH(r
->bar
), HEIGHT(r
->bar
));
2115 bar_extra_stop(void)
2119 bzero(bar_pipe
, sizeof bar_pipe
);
2122 kill(bar_pid
, SIGTERM
);
2125 strlcpy(bar_ext
, "", sizeof bar_ext
);
2130 bar_window_class(char *s
, size_t sz
, struct swm_region
*r
)
2132 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2134 if (r
->ws
->focus
->ch
.class_name
!= NULL
)
2135 strlcat(s
, r
->ws
->focus
->ch
.class_name
, sz
);
2139 bar_window_instance(char *s
, size_t sz
, struct swm_region
*r
)
2141 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2143 if (r
->ws
->focus
->ch
.instance_name
!= NULL
)
2144 strlcat(s
, r
->ws
->focus
->ch
.instance_name
, sz
);
2148 bar_window_class_instance(char *s
, size_t sz
, struct swm_region
*r
)
2150 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2153 bar_window_class(s
, sz
, r
);
2154 strlcat(s
, ":", sz
);
2155 bar_window_instance(s
, sz
, r
);
2159 bar_window_state(char *s
, size_t sz
, struct swm_region
*r
)
2161 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2163 if (MAXIMIZED(r
->ws
->focus
))
2164 strlcat(s
, "(m)", sz
);
2165 else if (ABOVE(r
->ws
->focus
))
2166 strlcat(s
, "(f)", sz
);
2170 bar_window_name(char *s
, size_t sz
, struct swm_region
*r
)
2174 if (r
== NULL
|| r
->ws
== NULL
|| r
->ws
->focus
== NULL
)
2177 title
= get_win_name(r
->ws
->focus
->id
);
2178 strlcat(s
, title
, sz
);
2183 get_urgent(struct ws_win
*win
)
2185 xcb_icccm_wm_hints_t hints
;
2186 xcb_get_property_cookie_t c
;
2187 bool urgent
= false;
2190 c
= xcb_icccm_get_wm_hints(conn
, win
->id
);
2191 if (xcb_icccm_get_wm_hints_reply(conn
, c
, &hints
, NULL
))
2192 urgent
= xcb_icccm_wm_hints_get_urgency(&hints
);
2199 bar_urgent(char *s
, size_t sz
)
2202 int i
, j
, num_screens
;
2203 bool urgent
[SWM_WS_MAX
];
2206 for (i
= 0; i
< workspace_limit
; i
++)
2209 num_screens
= get_screen_count();
2210 for (i
= 0; i
< num_screens
; i
++)
2211 for (j
= 0; j
< workspace_limit
; j
++)
2212 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
2213 if (get_urgent(win
))
2216 for (i
= 0; i
< workspace_limit
; i
++) {
2218 snprintf(b
, sizeof b
, "%d ", i
+ 1);
2220 } else if (!urgent_collapse
) {
2221 strlcat(s
, "- ", sz
);
2227 bar_workspace_name(char *s
, size_t sz
, struct swm_region
*r
)
2229 if (r
== NULL
|| r
->ws
== NULL
)
2231 if (r
->ws
->name
!= NULL
)
2232 strlcat(s
, r
->ws
->name
, sz
);
2235 /* build the default bar format according to the defined enabled options */
2237 bar_fmt(const char *fmtexp
, char *fmtnew
, struct swm_region
*r
, size_t sz
)
2241 /* if format provided, just copy the buffers */
2242 if (bar_format
!= NULL
) {
2243 strlcpy(fmtnew
, fmtexp
, sz
);
2247 /* reset the output buffer */
2250 strlcat(fmtnew
, "+N:+I ", sz
);
2252 strlcat(fmtnew
, "+S", sz
);
2253 strlcat(fmtnew
, " ", sz
);
2255 /* only show the workspace name if there's actually one */
2256 if (r
!= NULL
&& r
->ws
!= NULL
&& r
->ws
->name
!= NULL
)
2257 strlcat(fmtnew
, "<+D>", sz
);
2259 /* If enabled, only show the iconic count if there are iconic wins. */
2260 if (iconic_enabled
&& r
!= NULL
&& r
->ws
!= NULL
)
2261 TAILQ_FOREACH(w
, &r
->ws
->winlist
, entry
)
2263 strlcat(fmtnew
, "{+M}", sz
);
2267 strlcat(fmtnew
, "+3<", sz
);
2269 if (clock_enabled
) {
2270 strlcat(fmtnew
, fmtexp
, sz
);
2271 strlcat(fmtnew
, "+4<", sz
);
2274 /* bar_urgent already adds the space before the last asterisk */
2276 strlcat(fmtnew
, "* +U*+4<", sz
);
2278 if (window_class_enabled
) {
2279 strlcat(fmtnew
, "+C", sz
);
2280 if (!window_instance_enabled
)
2281 strlcat(fmtnew
, "+4<", sz
);
2284 /* checks needed by the colon and floating strlcat(3) calls below */
2285 if (r
!= NULL
&& r
->ws
!= NULL
&& r
->ws
->focus
!= NULL
) {
2286 if (window_instance_enabled
) {
2287 if (window_class_enabled
)
2288 strlcat(fmtnew
, ":", sz
);
2289 strlcat(fmtnew
, "+T+4<", sz
);
2291 if (window_name_enabled
) {
2292 if (ABOVE(r
->ws
->focus
) || MAXIMIZED(r
->ws
->focus
))
2293 strlcat(fmtnew
, "+F ", sz
);
2294 strlcat(fmtnew
, "+64W ", sz
);
2298 /* finally add the action script output and the version */
2299 strlcat(fmtnew
, "+4<+A+4<+V", sz
);
2303 bar_replace_pad(char *tmp
, int *limit
, size_t sz
)
2305 /* special case; no limit given, pad one space, instead */
2306 if (*limit
== (int)sz
- 1)
2308 snprintf(tmp
, sz
, "%*s", *limit
, " ");
2311 /* replaces the bar format character sequences (like in tmux(1)) */
2313 bar_replace_seq(char *fmt
, char *fmtrep
, struct swm_region
*r
, size_t *offrep
,
2318 char tmp
[SWM_BAR_MAX
];
2319 int limit
, size
, count
;
2322 /* reset strlcat(3) buffer */
2325 /* get number, if any */
2328 if (sscanf(fmt
, "%d%n", &limit
, &size
) != 1)
2329 limit
= sizeof tmp
- 1;
2330 if (limit
<= 0 || limit
>= (int)sizeof tmp
)
2331 limit
= sizeof tmp
- 1;
2333 /* there is nothing to replace (ie EOL) */
2340 bar_replace_pad(tmp
, &limit
, sizeof tmp
);
2343 snprintf(tmp
, sizeof tmp
, "%s", bar_ext
);
2346 bar_window_class(tmp
, sizeof tmp
, r
);
2349 bar_workspace_name(tmp
, sizeof tmp
, r
);
2352 bar_window_state(tmp
, sizeof tmp
, r
);
2355 snprintf(tmp
, sizeof tmp
, "%d", r
->ws
->idx
+ 1);
2359 TAILQ_FOREACH(w
, &r
->ws
->winlist
, entry
)
2363 snprintf(tmp
, sizeof tmp
, "%d", count
);
2366 snprintf(tmp
, sizeof tmp
, "%d", r
->s
->idx
+ 1);
2369 bar_window_class_instance(tmp
, sizeof tmp
, r
);
2372 snprintf(tmp
, sizeof tmp
, "%s", r
->ws
->stacker
);
2375 bar_window_instance(tmp
, sizeof tmp
, r
);
2378 bar_urgent(tmp
, sizeof tmp
);
2381 snprintf(tmp
, sizeof tmp
, "%s", bar_vertext
);
2384 bar_window_name(tmp
, sizeof tmp
, r
);
2387 /* unknown character sequence; copy as-is */
2388 snprintf(tmp
, sizeof tmp
, "+%c", *fmt
);
2394 if ((int)len
< limit
)
2396 while (limit
-- > 0) {
2397 if (*offrep
>= sz
- 1)
2399 fmtrep
[(*offrep
)++] = *ptr
++;
2407 bar_replace(char *fmt
, char *fmtrep
, struct swm_region
*r
, size_t sz
)
2412 while (*fmt
!= '\0') {
2414 /* skip ordinary characters */
2417 fmtrep
[off
++] = *fmt
++;
2421 /* character sequence found; replace it */
2422 fmt
= bar_replace_seq(fmt
, fmtrep
, r
, &off
, sz
);
2431 bar_fmt_expand(char *fmtexp
, size_t sz
)
2438 /* start by grabbing the current time and date */
2440 localtime_r(&tmt
, &tm
);
2442 /* figure out what to expand */
2443 if (bar_format
!= NULL
)
2445 else if (bar_format
== NULL
&& clock_enabled
)
2447 /* if nothing to expand bail out */
2453 /* copy as-is, just in case the format shouldn't be expanded below */
2454 strlcpy(fmtexp
, fmt
, sz
);
2455 /* finally pass the string through strftime(3) */
2456 #ifndef SWM_DENY_CLOCK_FORMAT
2457 if ((len
= strftime(fmtexp
, sz
, fmt
, &tm
)) == 0)
2458 warnx("format too long");
2463 /* Redraws the bar; need to follow with xcb_flush() or focus_flush(). */
2467 char fmtexp
[SWM_BAR_MAX
], fmtnew
[SWM_BAR_MAX
];
2468 char fmtrep
[SWM_BAR_MAX
];
2470 struct swm_region
*r
;
2472 /* expand the format by first passing it through strftime(3) */
2473 bar_fmt_expand(fmtexp
, sizeof fmtexp
);
2475 num_screens
= get_screen_count();
2476 for (i
= 0; i
< num_screens
; i
++) {
2477 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
) {
2481 if (bar_enabled
&& r
->ws
->bar_enabled
)
2482 xcb_map_window(conn
, r
->bar
->id
);
2484 xcb_unmap_window(conn
, r
->bar
->id
);
2488 if (startup_exception
)
2489 snprintf(fmtrep
, sizeof fmtrep
, "total "
2490 "exceptions: %d, first exception: %s",
2494 bar_fmt(fmtexp
, fmtnew
, r
, sizeof fmtnew
);
2495 bar_replace(fmtnew
, fmtrep
, r
, sizeof fmtrep
);
2497 if (bar_font_legacy
)
2498 bar_print_legacy(r
, fmtrep
);
2500 bar_print(r
, fmtrep
);
2506 * Reads external script output; call when stdin is readable.
2507 * Returns 1 if bar_ext was updated; otherwise 0.
2510 bar_extra_update(void)
2513 char b
[SWM_BAR_MAX
];
2514 bool changed
= false;
2519 while (fgets(b
, sizeof(b
), stdin
) != NULL
) {
2522 if (b
[len
- 1] == '\n') {
2523 /* Remove newline. */
2526 /* "Clear" bar_ext. */
2529 /* Flush buffered output. */
2530 strlcpy(bar_ext
, bar_ext_buf
, sizeof(bar_ext
));
2531 bar_ext_buf
[0] = '\0';
2533 /* Append new output to bar. */
2534 strlcat(bar_ext
, b
, sizeof(bar_ext
));
2538 /* Buffer output. */
2539 strlcat(bar_ext_buf
, b
, sizeof(bar_ext_buf
));
2544 if (errno
!= EAGAIN
) {
2545 warn("bar_action failed");
2554 bar_toggle(struct swm_region
*r
, union arg
*args
)
2556 struct swm_region
*tmpr
;
2559 /* suppress unused warnings since vars are needed */
2563 DNPRINTF(SWM_D_BAR
, "bar_toggle\n");
2566 case SWM_ARG_ID_BAR_TOGGLE_WS
:
2567 /* Only change if master switch is enabled. */
2569 r
->ws
->bar_enabled
= !r
->ws
->bar_enabled
;
2571 bar_enabled
= r
->ws
->bar_enabled
= true;
2573 case SWM_ARG_ID_BAR_TOGGLE
:
2574 bar_enabled
= !bar_enabled
;
2578 /* update bars as necessary */
2579 num_screens
= get_screen_count();
2580 for (i
= 0; i
< num_screens
; i
++)
2581 TAILQ_FOREACH(tmpr
, &screens
[i
].rl
, entry
)
2583 if (bar_enabled
&& tmpr
->ws
->bar_enabled
)
2584 xcb_map_window(conn
, tmpr
->bar
->id
);
2586 xcb_unmap_window(conn
, tmpr
->bar
->id
);
2591 /* must be after stack */
2598 bar_extra_setup(void)
2600 /* do this here because the conf file is in memory */
2601 if (!bar_extra
&& bar_argv
[0]) {
2602 /* launch external status app */
2604 if (pipe(bar_pipe
) == -1)
2605 err(1, "pipe error");
2606 socket_setnonblock(bar_pipe
[0]);
2607 socket_setnonblock(bar_pipe
[1]); /* XXX hmmm, really? */
2609 /* Set stdin to read from the pipe. */
2610 if (dup2(bar_pipe
[0], STDIN_FILENO
) == -1)
2613 /* Set stdout to write to the pipe. */
2614 if (dup2(bar_pipe
[1], STDOUT_FILENO
) == -1)
2617 if (signal(SIGPIPE
, SIG_IGN
) == SIG_ERR
)
2618 err(1, "could not disable SIGPIPE");
2619 switch (bar_pid
= fork()) {
2621 err(1, "cannot fork");
2625 execvp(bar_argv
[0], bar_argv
);
2626 err(1, "%s external app failed", bar_argv
[0]);
2628 default: /* parent */
2633 atexit(kill_bar_extra_atexit
);
2638 kill_bar_extra_atexit(void)
2641 kill(bar_pid
, SIGTERM
);
2649 while ((s
= index(s
, '-'))) {
2654 return (count
== 14);
2660 char *default_string
;
2661 char **missing_charsets
;
2662 int num_missing_charsets
= 0;
2666 XFreeFontSet(display
, bar_fs
);
2670 DNPRINTF(SWM_D_INIT
, "fontset_init: loading bar_fonts: %s\n", bar_fonts
);
2672 bar_fs
= XCreateFontSet(display
, bar_fonts
, &missing_charsets
,
2673 &num_missing_charsets
, &default_string
);
2675 if (num_missing_charsets
> 0) {
2676 warnx("Unable to load charset(s):");
2678 for (i
= 0; i
< num_missing_charsets
; ++i
)
2679 warnx("%s", missing_charsets
[i
]);
2681 XFreeStringList(missing_charsets
);
2683 if (strcmp(default_string
, ""))
2684 warnx("Glyphs from those sets will be replaced "
2685 "by '%s'.", default_string
);
2687 warnx("Glyphs from those sets won't be drawn.");
2691 errx(1, "Error creating font set structure.");
2693 bar_fs_extents
= XExtentsOfFontSet(bar_fs
);
2695 bar_height
= bar_fs_extents
->max_logical_extent
.height
+
2696 2 * bar_border_width
;
2703 xft_init(struct swm_region
*r
)
2705 char *font
, *d
, *search
;
2708 if (bar_font
== NULL
) {
2709 if ((d
= strdup(bar_fonts
)) == NULL
)
2710 errx(1, "insufficient memory.");
2712 while ((font
= strsep(&search
, ",")) != NULL
) {
2716 DNPRINTF(SWM_D_INIT
, "xft_init: try font %s\n", font
);
2719 bar_font
= XftFontOpenXlfd(display
, r
->s
->idx
,
2722 bar_font
= XftFontOpenName(display
, r
->s
->idx
,
2726 if (bar_font
== NULL
) {
2727 warnx("unable to load font %s", font
);
2730 DNPRINTF(SWM_D_INIT
, "successfully opened "
2738 if (bar_font
== NULL
)
2739 errx(1, "unable to open a font");
2741 PIXEL_TO_XRENDERCOLOR(r
->s
->c
[SWM_S_COLOR_BAR_FONT
].pixel
, color
);
2743 if (!XftColorAllocValue(display
, DefaultVisual(display
, r
->s
->idx
),
2744 DefaultColormap(display
, r
->s
->idx
), &color
, &bar_font_color
))
2745 warn("Xft error: unable to allocate color.");
2747 PIXEL_TO_XRENDERCOLOR(r
->s
->c
[SWM_S_COLOR_BAR
].pixel
, color
);
2749 if (!XftColorAllocValue(display
, DefaultVisual(display
, r
->s
->idx
),
2750 DefaultColormap(display
, r
->s
->idx
), &color
, &search_font_color
))
2751 warn("Xft error: unable to allocate color.");
2753 bar_height
= bar_font
->height
+ 2 * bar_border_width
;
2760 bar_setup(struct swm_region
*r
)
2762 xcb_screen_t
*screen
;
2765 DNPRINTF(SWM_D_BAR
, "bar_setup: screen %d.\n",
2768 if ((screen
= get_screen(r
->s
->idx
)) == NULL
)
2769 errx(1, "ERROR: can't get screen %d.", r
->s
->idx
);
2774 if ((r
->bar
= calloc(1, sizeof(struct swm_bar
))) == NULL
)
2775 err(1, "bar_setup: calloc: failed to allocate memory.");
2777 if (bar_font_legacy
)
2783 Y(r
->bar
) = bar_at_bottom
? (Y(r
) + HEIGHT(r
) - bar_height
) : Y(r
);
2784 WIDTH(r
->bar
) = WIDTH(r
) - 2 * bar_border_width
;
2785 HEIGHT(r
->bar
) = bar_height
- 2 * bar_border_width
;
2787 /* Assume region is unfocused when we create the bar. */
2788 r
->bar
->id
= xcb_generate_id(conn
);
2789 wa
[0] = r
->s
->c
[SWM_S_COLOR_BAR
].pixel
;
2790 wa
[1] = r
->s
->c
[SWM_S_COLOR_BAR_BORDER_UNFOCUS
].pixel
;
2791 wa
[2] = XCB_EVENT_MASK_EXPOSURE
| XCB_EVENT_MASK_POINTER_MOTION
|
2792 XCB_EVENT_MASK_POINTER_MOTION_HINT
;
2794 xcb_create_window(conn
, XCB_COPY_FROM_PARENT
, r
->bar
->id
, r
->s
->root
,
2795 X(r
->bar
), Y(r
->bar
), WIDTH(r
->bar
), HEIGHT(r
->bar
),
2796 bar_border_width
, XCB_WINDOW_CLASS_INPUT_OUTPUT
,
2797 XCB_COPY_FROM_PARENT
, XCB_CW_BACK_PIXEL
| XCB_CW_BORDER_PIXEL
2798 | XCB_CW_EVENT_MASK
, wa
);
2800 /* Stack bar window above region window to start. */
2802 wa
[1] = XCB_STACK_MODE_ABOVE
;
2804 xcb_configure_window(conn
, r
->bar
->id
, XCB_CONFIG_WINDOW_SIBLING
|
2805 XCB_CONFIG_WINDOW_STACK_MODE
, wa
);
2807 r
->bar
->buffer
= xcb_generate_id(conn
);
2808 xcb_create_pixmap(conn
, screen
->root_depth
, r
->bar
->buffer
, r
->bar
->id
,
2809 WIDTH(r
->bar
), HEIGHT(r
->bar
));
2812 xcb_randr_select_input(conn
, r
->bar
->id
,
2813 XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE
);
2816 xcb_map_window(conn
, r
->bar
->id
);
2818 DNPRINTF(SWM_D_BAR
, "bar_setup: win %#x, (x,y) w x h: (%d,%d) "
2819 "%d x %d\n", WINID(r
->bar
), X(r
->bar
), Y(r
->bar
), WIDTH(r
->bar
),
2826 bar_cleanup(struct swm_region
*r
)
2830 xcb_destroy_window(conn
, r
->bar
->id
);
2831 xcb_free_pixmap(conn
, r
->bar
->buffer
);
2837 set_win_state(struct ws_win
*win
, uint8_t state
)
2839 uint16_t data
[2] = { state
, XCB_ATOM_NONE
};
2841 DNPRINTF(SWM_D_EVENT
, "set_win_state: win %#x, state: %u\n",
2847 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
, a_state
,
2848 a_state
, 32, 2, data
);
2852 get_win_state(xcb_window_t w
)
2854 xcb_get_property_reply_t
*r
;
2855 xcb_get_property_cookie_t c
;
2856 uint32_t result
= 0;
2858 c
= xcb_get_property(conn
, 0, w
, a_state
, a_state
, 0L, 2L);
2859 r
= xcb_get_property_reply(conn
, c
, NULL
);
2861 if (r
->type
== a_state
&& r
->format
== 32 && r
->length
== 2)
2862 result
= *((uint32_t *)xcb_get_property_value(r
));
2866 DNPRINTF(SWM_D_MISC
, "get_win_state property: win %#x state %u\n", w
,
2872 version(struct swm_region
*r
, union arg
*args
)
2874 /* suppress unused warnings since vars are needed */
2878 bar_version
= !bar_version
;
2880 snprintf(bar_vertext
, sizeof bar_vertext
,
2881 "Version: %s Build: %s", SPECTRWM_VERSION
, buildstr
);
2883 strlcpy(bar_vertext
, "", sizeof bar_vertext
);
2890 client_msg(struct ws_win
*win
, xcb_atom_t a
, xcb_timestamp_t t
)
2892 xcb_client_message_event_t ev
;
2900 name
= get_atom_name(a
);
2901 DNPRINTF(SWM_D_EVENT
, "client_msg: win %#x, atom: %s(%u), "
2903 win
->id
, name
, a
, t
);
2907 bzero(&ev
, sizeof ev
);
2908 ev
.response_type
= XCB_CLIENT_MESSAGE
;
2909 ev
.window
= win
->id
;
2912 ev
.data
.data32
[0] = a
;
2913 ev
.data
.data32
[1] = t
;
2915 xcb_send_event(conn
, 0, win
->id
,
2916 XCB_EVENT_MASK_NO_EVENT
, (const char *)&ev
);
2919 /* synthetic response to a ConfigureRequest when not making a change */
2921 config_win(struct ws_win
*win
, xcb_configure_request_event_t
*ev
)
2923 xcb_configure_notify_event_t ce
;
2928 /* send notification of unchanged state. */
2929 bzero(&ce
, sizeof(ce
));
2930 ce
.response_type
= XCB_CONFIGURE_NOTIFY
;
2933 ce
.width
= WIDTH(win
);
2934 ce
.height
= HEIGHT(win
);
2935 ce
.override_redirect
= 0;
2940 ce
.window
= win
->id
;
2941 ce
.border_width
= BORDER(win
);
2942 ce
.above_sibling
= XCB_WINDOW_NONE
;
2945 ce
.event
= ev
->window
;
2946 ce
.window
= ev
->window
;
2948 /* make response appear more WM_SIZE_HINTS-compliant */
2949 if (win
->sh
.flags
) {
2950 DNPRINTF(SWM_D_MISC
, "config_win: hints: win %#x,"
2951 " sh.flags: %u, min: %d x %d, max: %d x %d, inc: "
2952 "%d x %d\n", win
->id
, win
->sh
.flags
, SH_MIN_W(win
),
2953 SH_MIN_H(win
), SH_MAX_W(win
), SH_MAX_H(win
),
2954 SH_INC_W(win
), SH_INC_H(win
));
2959 /* the hint may be set... to 0! */
2960 if (SH_MIN_W(win
) > 0 && ce
.width
< SH_MIN_W(win
))
2961 ce
.width
= SH_MIN_W(win
);
2962 if (SH_MIN_H(win
) > 0 && ce
.height
< SH_MIN_H(win
))
2963 ce
.height
= SH_MIN_H(win
);
2968 /* may also be advertized as 0 */
2969 if (SH_MAX_W(win
) > 0 && ce
.width
> SH_MAX_W(win
))
2970 ce
.width
= SH_MAX_W(win
);
2971 if (SH_MAX_H(win
) > 0 && ce
.height
> SH_MAX_H(win
))
2972 ce
.height
= SH_MAX_H(win
);
2975 /* resize increment. */
2977 if (SH_INC_W(win
) > 1 && ce
.width
> SH_INC_W(win
))
2978 ce
.width
-= (ce
.width
- SH_MIN_W(win
)) %
2980 if (SH_INC_H(win
) > 1 && ce
.height
> SH_INC_H(win
))
2981 ce
.height
-= (ce
.height
- SH_MIN_H(win
)) %
2985 /* adjust x and y for requested border_width. */
2986 ce
.x
+= BORDER(win
) - ev
->border_width
;
2987 ce
.y
+= BORDER(win
) - ev
->border_width
;
2988 ce
.border_width
= ev
->border_width
;
2989 ce
.above_sibling
= ev
->sibling
;
2992 DNPRINTF(SWM_D_MISC
, "config_win: ewmh: %s, win %#x, (x,y) w x h: "
2993 "(%d,%d) %d x %d, border: %d\n", YESNO(ev
== NULL
), win
->id
, ce
.x
,
2994 ce
.y
, ce
.width
, ce
.height
, ce
.border_width
);
2996 xcb_send_event(conn
, 0, win
->id
, XCB_EVENT_MASK_STRUCTURE_NOTIFY
,
3001 count_win(struct workspace
*ws
, bool count_transient
)
3006 TAILQ_FOREACH(win
, &ws
->winlist
, entry
) {
3007 if (!count_transient
&& FLOATING(win
))
3013 DNPRINTF(SWM_D_MISC
, "count_win: %d\n", count
);
3019 quit(struct swm_region
*r
, union arg
*args
)
3021 /* suppress unused warnings since vars are needed */
3025 DNPRINTF(SWM_D_MISC
, "quit\n");
3030 lower_window(struct ws_win
*win
)
3032 struct ws_win
*target
= NULL
;
3033 struct workspace
*ws
;
3040 DNPRINTF(SWM_D_EVENT
, "lower_window: win %#x\n", win
->id
);
3042 TAILQ_FOREACH(target
, &ws
->stack
, stack_entry
) {
3043 if (target
== win
|| ICONIC(target
))
3045 if (ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
3048 if (win
->transient
== target
->transient
)
3050 if (win
->transient
== target
->id
)
3053 if (FULLSCREEN(target
))
3055 if (FULLSCREEN(win
))
3057 if (MAXIMIZED(target
))
3061 if (ABOVE(target
) || TRANS(target
))
3063 if (ABOVE(win
) || TRANS(win
))
3067 /* Change stack position. */
3068 TAILQ_REMOVE(&ws
->stack
, win
, stack_entry
);
3070 TAILQ_INSERT_BEFORE(target
, win
, stack_entry
);
3072 TAILQ_INSERT_TAIL(&ws
->stack
, win
, stack_entry
);
3074 update_win_stacking(win
);
3077 if (swm_debug
& SWM_D_STACK
) {
3078 DPRINTF("=== stacking order (top down) === \n");
3079 TAILQ_FOREACH(target
, &ws
->stack
, stack_entry
) {
3080 DPRINTF("win %#x, fs: %s, maximized: %s, above: %s, "
3081 "iconic: %s\n", target
->id
, YESNO(FULLSCREEN(target
)),
3082 YESNO(MAXIMIZED(target
)), YESNO(ABOVE(target
)),
3083 YESNO(ICONIC(target
)));
3087 DNPRINTF(SWM_D_EVENT
, "lower_window: done\n");
3091 raise_window(struct ws_win
*win
)
3093 struct ws_win
*target
= NULL
;
3094 struct workspace
*ws
;
3100 DNPRINTF(SWM_D_EVENT
, "raise_window: win %#x\n", win
->id
);
3102 TAILQ_FOREACH(target
, &ws
->stack
, stack_entry
) {
3103 if (target
== win
|| ICONIC(target
))
3105 if (ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
3107 if (TRANS(win
) && (win
->transient
== target
->transient
||
3108 win
->transient
== target
->id
))
3110 if (FULLSCREEN(win
))
3112 if (FULLSCREEN(target
))
3116 if (MAXIMIZED(target
))
3118 if (ABOVE(win
) || TRANS(win
) ||
3119 (win
->ws
->focus
== win
&& ws
->always_raise
))
3121 if (!ABOVE(target
) && !TRANS(target
))
3125 TAILQ_REMOVE(&ws
->stack
, win
, stack_entry
);
3127 TAILQ_INSERT_BEFORE(target
, win
, stack_entry
);
3129 TAILQ_INSERT_TAIL(&ws
->stack
, win
, stack_entry
);
3131 update_win_stacking(win
);
3134 if (swm_debug
& SWM_D_STACK
) {
3135 DPRINTF("=== stacking order (top down) === \n");
3136 TAILQ_FOREACH(target
, &ws
->stack
, stack_entry
) {
3137 DPRINTF("win %#x, fs: %s, maximized: %s, above: %s, "
3138 "iconic: %s\n", target
->id
, YESNO(FULLSCREEN(target
)),
3139 YESNO(MAXIMIZED(target
)), YESNO(ABOVE(target
)),
3140 YESNO(ICONIC(target
)));
3144 DNPRINTF(SWM_D_EVENT
, "raise_window: done\n");
3148 update_win_stacking(struct ws_win
*win
)
3150 struct ws_win
*sibling
;
3151 struct swm_region
*r
;
3154 if (win
== NULL
|| (r
= win
->ws
->r
) == NULL
)
3157 sibling
= TAILQ_NEXT(win
, stack_entry
);
3158 if (sibling
!= NULL
&& (FLOATING(win
) == FLOATING(sibling
) ||
3159 (win
->ws
->always_raise
&& win
->ws
->focus
== win
)))
3160 val
[0] = sibling
->id
;
3161 else if (FLOATING(win
) || (win
->ws
->always_raise
&&
3162 win
->ws
->focus
== win
))
3163 val
[0] = r
->bar
->id
;
3167 DNPRINTF(SWM_D_EVENT
, "update_win_stacking: %#x, sibling %#x\n",
3170 val
[1] = XCB_STACK_MODE_ABOVE
;
3172 xcb_configure_window(conn
, win
->id
, XCB_CONFIG_WINDOW_SIBLING
|
3173 XCB_CONFIG_WINDOW_STACK_MODE
, val
);
3177 map_window(struct ws_win
*win
)
3182 DNPRINTF(SWM_D_EVENT
, "map_window: win %#x, mapped: %s\n",
3183 win
->id
, YESNO(win
->mapped
));
3188 xcb_map_window(conn
, win
->id
);
3189 set_win_state(win
, XCB_ICCCM_WM_STATE_NORMAL
);
3194 unmap_window(struct ws_win
*win
)
3199 DNPRINTF(SWM_D_EVENT
, "unmap_window: win %#x, mapped: %s\n", win
->id
,
3200 YESNO(win
->mapped
));
3205 xcb_unmap_window(conn
, win
->id
);
3206 set_win_state(win
, XCB_ICCCM_WM_STATE_ICONIC
);
3207 win
->mapped
= false;
3214 int i
, j
, num_screens
;
3216 num_screens
= get_screen_count();
3217 for (i
= 0; i
< num_screens
; i
++)
3218 for (j
= 0; j
< workspace_limit
; j
++)
3219 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
3224 fake_keypress(struct ws_win
*win
, xcb_keysym_t keysym
, uint16_t modifiers
)
3226 xcb_key_press_event_t event
;
3227 xcb_keycode_t
*keycode
;
3232 keycode
= xcb_key_symbols_get_keycode(syms
, keysym
);
3234 DNPRINTF(SWM_D_MISC
, "fake_keypress: win %#x, keycode %u\n",
3237 bzero(&event
, sizeof(event
));
3238 event
.event
= win
->id
;
3239 event
.root
= win
->s
->root
;
3240 event
.child
= XCB_WINDOW_NONE
;
3241 event
.time
= XCB_CURRENT_TIME
;
3242 event
.event_x
= X(win
);
3243 event
.event_y
= Y(win
);
3246 event
.same_screen
= 1;
3247 event
.detail
= *keycode
;
3248 event
.state
= modifiers
;
3250 event
.response_type
= XCB_KEY_PRESS
;
3251 xcb_send_event(conn
, 1, win
->id
,
3252 XCB_EVENT_MASK_KEY_PRESS
, (const char *)&event
);
3254 event
.response_type
= XCB_KEY_RELEASE
;
3255 xcb_send_event(conn
, 1, win
->id
,
3256 XCB_EVENT_MASK_KEY_RELEASE
, (const char *)&event
);
3262 restart(struct swm_region
*r
, union arg
*args
)
3264 /* suppress unused warning since var is needed */
3268 DNPRINTF(SWM_D_MISC
, "restart: %s\n", start_argv
[0]);
3272 execvp(start_argv
[0], start_argv
);
3273 warn("execvp failed");
3278 get_pointer_win(xcb_window_t root
)
3280 struct ws_win
*win
= NULL
;
3281 xcb_query_pointer_reply_t
*r
;
3283 DNPRINTF(SWM_D_EVENT
, "get_pointer_win: root: %#x.\n", root
);
3285 r
= xcb_query_pointer_reply(conn
, xcb_query_pointer(conn
, root
), NULL
);
3287 win
= find_window(r
->child
);
3289 DNPRINTF(SWM_D_EVENT
, "get_pointer_win: %#x.\n",
3292 DNPRINTF(SWM_D_EVENT
, "get_pointer_win: none.\n");
3301 center_pointer(struct swm_region
*r
)
3305 if (!warp_pointer
|| r
== NULL
)
3310 DNPRINTF(SWM_D_EVENT
, "center_pointer: win %#x.\n", WINID(win
));
3312 if (win
&& win
->mapped
)
3313 xcb_warp_pointer(conn
, XCB_NONE
, win
->id
, 0, 0, 0, 0,
3314 WIDTH(win
) / 2, HEIGHT(win
) / 2);
3316 xcb_warp_pointer(conn
, XCB_NONE
, r
->id
, 0, 0, 0, 0,
3317 WIDTH(r
) / 2, HEIGHT(r
) / 2);
3321 root_to_region(xcb_window_t root
, int check
)
3324 struct swm_region
*r
= NULL
;
3326 xcb_query_pointer_reply_t
*qpr
;
3327 xcb_get_input_focus_reply_t
*gifr
;
3329 DNPRINTF(SWM_D_MISC
, "root_to_region: win %#x\n", root
);
3331 num_screens
= get_screen_count();
3332 for (i
= 0; i
< num_screens
; i
++)
3333 if (screens
[i
].root
== root
)
3336 if (check
& SWM_CK_REGION
)
3337 r
= screens
[i
].r_focus
;
3339 if (r
== NULL
&& check
& SWM_CK_FOCUS
) {
3340 /* Try to find an actively focused window */
3341 gifr
= xcb_get_input_focus_reply(conn
,
3342 xcb_get_input_focus(conn
), NULL
);
3344 cfw
= find_window(gifr
->focus
);
3345 if (cfw
&& cfw
->ws
->r
)
3352 if (r
== NULL
&& check
& SWM_CK_POINTER
) {
3353 /* No region with an active focus; try to use pointer. */
3354 qpr
= xcb_query_pointer_reply(conn
, xcb_query_pointer(conn
,
3355 screens
[i
].root
), NULL
);
3357 DNPRINTF(SWM_D_MISC
, "root_to_region: pointer: "
3358 "(%d,%d)\n", qpr
->root_x
, qpr
->root_y
);
3359 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
3360 if (X(r
) <= qpr
->root_x
&&
3361 qpr
->root_x
< MAX_X(r
) &&
3362 Y(r
) <= qpr
->root_y
&&
3363 qpr
->root_y
< MAX_Y(r
))
3370 if (r
== NULL
&& check
& SWM_CK_FALLBACK
)
3371 r
= TAILQ_FIRST(&screens
[i
].rl
);
3373 DNPRINTF(SWM_D_MISC
, "root_to_region: idx: %d\n", get_region_index(r
));
3379 find_unmanaged_window(xcb_window_t id
)
3382 int i
, j
, num_screens
;
3384 num_screens
= get_screen_count();
3385 for (i
= 0; i
< num_screens
; i
++)
3386 for (j
= 0; j
< workspace_limit
; j
++)
3387 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].unmanagedlist
,
3395 find_window(xcb_window_t id
)
3398 int i
, j
, num_screens
;
3399 xcb_query_tree_reply_t
*r
;
3401 num_screens
= get_screen_count();
3402 for (i
= 0; i
< num_screens
; i
++)
3403 for (j
= 0; j
< workspace_limit
; j
++)
3404 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
3408 r
= xcb_query_tree_reply(conn
, xcb_query_tree(conn
, id
), NULL
);
3412 /* if we were looking for the parent return that window instead */
3413 if (r
->parent
== 0 || r
->root
== r
->parent
) {
3418 /* look for parent */
3419 for (i
= 0; i
< num_screens
; i
++)
3420 for (j
= 0; j
< workspace_limit
; j
++)
3421 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
3422 if (r
->parent
== win
->id
) {
3432 spawn(int ws_idx
, union arg
*args
, bool close_fd
)
3437 DNPRINTF(SWM_D_MISC
, "spawn: %s\n", args
->argv
[0]);
3439 close(xcb_get_file_descriptor(conn
));
3441 setenv("LD_PRELOAD", SWM_LIB
, 1);
3443 if (asprintf(&ret
, "%d", ws_idx
) == -1) {
3444 warn("spawn: asprintf SWM_WS");
3447 setenv("_SWM_WS", ret
, 1);
3451 if (asprintf(&ret
, "%d", getpid()) == -1) {
3452 warn("spawn: asprintf _SWM_PID");
3455 setenv("_SWM_PID", ret
, 1);
3459 if (setsid() == -1) {
3460 warn("spawn: setsid");
3466 * close stdin and stdout to prevent interaction between apps
3467 * and the baraction script
3468 * leave stderr open to record errors
3470 if ((fd
= open(_PATH_DEVNULL
, O_RDWR
, 0)) == -1) {
3471 warn("spawn: open");
3474 dup2(fd
, STDIN_FILENO
);
3475 dup2(fd
, STDOUT_FILENO
);
3480 execvp(args
->argv
[0], args
->argv
);
3482 warn("spawn: execvp");
3487 kill_refs(struct ws_win
*win
)
3489 int i
, x
, num_screens
;
3490 struct swm_region
*r
;
3491 struct workspace
*ws
;
3496 num_screens
= get_screen_count();
3497 for (i
= 0; i
< num_screens
; i
++)
3498 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
3499 for (x
= 0; x
< workspace_limit
; x
++) {
3501 if (win
== ws
->focus
)
3503 if (win
== ws
->focus_prev
)
3504 ws
->focus_prev
= NULL
;
3509 validate_win(struct ws_win
*testwin
)
3512 struct workspace
*ws
;
3513 struct swm_region
*r
;
3514 int i
, x
, num_screens
;
3516 if (testwin
== NULL
)
3519 num_screens
= get_screen_count();
3520 for (i
= 0; i
< num_screens
; i
++)
3521 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
3522 for (x
= 0; x
< workspace_limit
; x
++) {
3524 TAILQ_FOREACH(win
, &ws
->winlist
, entry
)
3532 validate_ws(struct workspace
*testws
)
3534 struct swm_region
*r
;
3535 struct workspace
*ws
;
3536 int i
, x
, num_screens
;
3538 /* validate all ws */
3539 num_screens
= get_screen_count();
3540 for (i
= 0; i
< num_screens
; i
++)
3541 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
3542 for (x
= 0; x
< workspace_limit
; x
++) {
3551 unfocus_win(struct ws_win
*win
)
3553 xcb_window_t none
= XCB_WINDOW_NONE
;
3555 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: win %#x\n", WINID(win
));
3560 if (win
->ws
== NULL
) {
3561 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: NULL ws.\n");
3565 if (validate_ws(win
->ws
)) {
3566 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: invalid ws.\n");
3570 if (win
->ws
->r
== NULL
) {
3571 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: NULL region.\n");
3575 if (validate_win(win
)) {
3576 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: invalid win.\n");
3581 if (win
->ws
->focus
== win
) {
3582 win
->ws
->focus
= NULL
;
3583 win
->ws
->focus_prev
= win
;
3586 if (validate_win(win
->ws
->focus
)) {
3587 kill_refs(win
->ws
->focus
);
3588 win
->ws
->focus
= NULL
;
3591 if (validate_win(win
->ws
->focus_prev
)) {
3592 kill_refs(win
->ws
->focus_prev
);
3593 win
->ws
->focus_prev
= NULL
;
3596 update_window_color(win
);
3598 /* Raise window to "top unfocused position." */
3599 if (win
->ws
->always_raise
)
3602 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->s
->root
,
3603 ewmh
[_NET_ACTIVE_WINDOW
].atom
, XCB_ATOM_WINDOW
, 32, 1, &none
);
3605 DNPRINTF(SWM_D_FOCUS
, "unfocus_win: done.\n");
3609 focus_win(struct ws_win
*win
)
3611 struct ws_win
*cfw
= NULL
, *parent
= NULL
, *w
, *tmpw
;
3612 struct workspace
*ws
;
3613 xcb_get_input_focus_reply_t
*gifr
;
3615 DNPRINTF(SWM_D_FOCUS
, "focus_win: win %#x\n", WINID(win
));
3617 if (win
== NULL
|| win
->ws
== NULL
|| !win
->mapped
)
3622 if (validate_ws(ws
))
3625 if (validate_win(win
)) {
3630 gifr
= xcb_get_input_focus_reply(conn
, xcb_get_input_focus(conn
), NULL
);
3632 cfw
= find_window(gifr
->focus
);
3633 if (cfw
!= NULL
&& cfw
!= win
) {
3634 if (cfw
->ws
!= ws
&& cfw
->ws
->r
!= NULL
) {
3635 /* Change border to unfocused color. */
3636 xcb_change_window_attributes(conn
, cfw
->id
,
3637 XCB_CW_BORDER_PIXEL
,
3638 &cfw
->s
->c
[(MAXIMIZED(cfw
) ?
3639 SWM_S_COLOR_UNFOCUS_MAXIMIZED
:
3640 SWM_S_COLOR_UNFOCUS
)].pixel
);
3648 if (ws
->focus
!= win
) {
3649 if (ws
->focus
&& ws
->focus
!= cfw
)
3650 unfocus_win(ws
->focus
);
3654 /* If this window directs focus to a child window, then clear. */
3655 if (win
->focus_child
)
3656 win
->focus_child
= NULL
;
3658 /* If transient, adjust parent's focus child for focus_magic. */
3660 parent
= find_window(win
->transient
);
3661 if (parent
&& parent
->focus_child
!= win
)
3662 parent
->focus_child
= win
;
3665 if (cfw
!= win
&& ws
->r
!= NULL
) {
3666 /* Set input focus if no input hint, or indicated by hint. */
3667 if (!(win
->hints
.flags
& XCB_ICCCM_WM_HINT_INPUT
) ||
3668 (win
->hints
.flags
& XCB_ICCCM_WM_HINT_INPUT
&&
3670 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
,
3671 win
->id
, last_event_time
);
3673 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
,
3674 ws
->r
->id
, XCB_CURRENT_TIME
);
3676 /* Tell app it can adjust focus to a specific window. */
3677 if (win
->take_focus
) {
3678 /* java is special; always tell parent */
3679 if (TRANS(win
) && win
->java
)
3680 client_msg(parent
, a_takefocus
,
3683 client_msg(win
, a_takefocus
, last_event_time
);
3686 if (ws
->cur_layout
->flags
& SWM_L_MAPONFOCUS
||
3688 /* If a parent exists, map it first. */
3690 raise_window(parent
);
3693 /* Map siblings next. */
3694 TAILQ_FOREACH_SAFE(w
, &ws
->stack
, stack_entry
,
3696 if (w
!= win
&& !ICONIC(w
) &&
3697 w
->transient
== parent
->id
) {
3703 /* Map focused window. */
3707 /* Stack any children of focus window. */
3708 TAILQ_FOREACH_SAFE(w
, &ws
->stack
, stack_entry
, tmpw
)
3709 if (w
->transient
== win
->id
&& !ICONIC(w
)) {
3713 } else if (tile_gap
< 0 && !ABOVE(win
)) {
3715 * Windows overlap in the layout.
3716 * Raise focused win above all tiled wins.
3724 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->s
->root
,
3725 ewmh
[_NET_ACTIVE_WINDOW
].atom
, XCB_ATOM_WINDOW
, 32, 1,
3730 /* Update window border even if workspace is hidden. */
3731 update_window_color(win
);
3736 DNPRINTF(SWM_D_FOCUS
, "focus_win: done.\n");
3739 /* If a child window should have focus instead, return it. */
3741 get_focus_magic(struct ws_win
*win
)
3743 struct ws_win
*parent
= NULL
;
3744 struct ws_win
*child
= NULL
;
3746 DNPRINTF(SWM_D_FOCUS
, "get_focus_magic: win %#x\n", WINID(win
));
3751 parent
= find_window(win
->transient
);
3753 /* If parent prefers focus elsewhere, then try to do so. */
3754 if (parent
&& (child
= parent
->focus_child
)) {
3755 if (validate_win(child
) == 0 && child
->mapped
)
3758 parent
->focus_child
= NULL
;
3762 /* If this window prefers focus elsewhere, then try to do so. */
3763 if ((child
= win
->focus_child
)) {
3764 if (validate_win(child
) == 0 && child
->mapped
)
3767 win
->focus_child
= NULL
;
3774 event_drain(uint8_t rt
)
3776 xcb_generic_event_t
*evt
;
3778 /* ensure all pending requests have been processed before filtering. */
3780 while ((evt
= xcb_poll_for_event(conn
))) {
3781 if (XCB_EVENT_RESPONSE_TYPE(evt
) != rt
)
3789 set_region(struct swm_region
*r
)
3791 struct swm_region
*rf
;
3798 /* Unfocus old region bar. */
3803 xcb_change_window_attributes(conn
, rf
->bar
->id
,
3804 XCB_CW_BORDER_PIXEL
,
3805 &r
->s
->c
[SWM_S_COLOR_BAR_BORDER_UNFOCUS
].pixel
);
3808 if (rf
!= NULL
&& rf
!= r
&& (X(rf
) != X(r
) || Y(rf
) != Y(r
) ||
3809 WIDTH(rf
) != WIDTH(r
) || HEIGHT(rf
) != HEIGHT(r
))) {
3810 /* Set _NET_DESKTOP_GEOMETRY. */
3812 vals
[1] = HEIGHT(r
);
3813 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, r
->s
->root
,
3814 ewmh
[_NET_DESKTOP_GEOMETRY
].atom
, XCB_ATOM_CARDINAL
, 32, 2,
3818 /* Set region bar border to focus_color. */
3819 xcb_change_window_attributes(conn
, r
->bar
->id
,
3820 XCB_CW_BORDER_PIXEL
, &r
->s
->c
[SWM_S_COLOR_BAR_BORDER
].pixel
);
3824 ewmh_update_current_desktop();
3828 focus_region(struct swm_region
*r
)
3831 struct swm_region
*old_r
;
3836 old_r
= r
->s
->r_focus
;
3839 nfw
= get_region_focus(r
);
3843 /* New region is empty; need to manually unfocus win. */
3845 unfocus_win(old_r
->ws
->focus
);
3847 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
, r
->id
,
3850 /* Clear bar since empty. */
3856 switchws(struct swm_region
*r
, union arg
*args
)
3858 struct swm_region
*this_r
, *other_r
;
3860 struct workspace
*new_ws
, *old_ws
;
3861 xcb_window_t none
= XCB_WINDOW_NONE
;
3862 int wsid
= args
->id
;
3863 bool unmap_old
= false;
3868 if (wsid
>= workspace_limit
)
3872 old_ws
= this_r
->ws
;
3873 new_ws
= &this_r
->s
->ws
[wsid
];
3875 DNPRINTF(SWM_D_WS
, "switchws: screen[%d]:%dx%d+%d+%d: %d -> %d\n",
3876 r
->s
->idx
, WIDTH(r
), HEIGHT(r
), X(r
), Y(r
), old_ws
->idx
, wsid
);
3878 if (new_ws
== NULL
|| old_ws
== NULL
)
3880 if (new_ws
== old_ws
)
3883 if ((win
= old_ws
->focus
) != NULL
) {
3884 update_window_color(win
);
3886 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->s
->root
,
3887 ewmh
[_NET_ACTIVE_WINDOW
].atom
, XCB_ATOM_WINDOW
, 32, 1,
3891 other_r
= new_ws
->r
;
3892 if (other_r
== NULL
) {
3893 /* the other workspace is hidden, hide this one */
3897 /* the other ws is visible in another region, exchange them */
3898 other_r
->ws_prior
= new_ws
;
3899 other_r
->ws
= old_ws
;
3900 old_ws
->r
= other_r
;
3902 this_r
->ws_prior
= old_ws
;
3903 this_r
->ws
= new_ws
;
3906 /* Set focus_pending before stacking, if needed. */
3907 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& (!new_ws
->focus_pending
||
3908 validate_win(new_ws
->focus_pending
))) {
3909 new_ws
->focus_pending
= get_region_focus(new_ws
->r
);
3910 new_ws
->focus
= new_ws
->focus_prev
;
3911 new_ws
->focus_prev
= NULL
;
3914 new_ws
->state
= SWM_WS_STATE_MAPPING
;
3917 /* unmap old windows */
3919 TAILQ_FOREACH(win
, &old_ws
->winlist
, entry
)
3921 old_ws
->state
= SWM_WS_STATE_HIDDEN
;
3924 /* if workspaces were swapped, then don't wait to set focus */
3925 if (old_ws
->r
&& focus_mode
!= SWM_FOCUS_FOLLOW
) {
3926 if (new_ws
->focus_pending
) {
3927 focus_win(new_ws
->focus_pending
);
3928 new_ws
->focus_pending
= NULL
;
3932 /* Clear bar and set focus on region input win if new ws is empty. */
3933 if (new_ws
->focus_pending
== NULL
&& new_ws
->focus
== NULL
) {
3934 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
, r
->id
,
3939 ewmh_update_current_desktop();
3943 new_ws
->state
= SWM_WS_STATE_MAPPED
;
3945 DNPRINTF(SWM_D_WS
, "switchws: done.\n");
3949 cyclews(struct swm_region
*r
, union arg
*args
)
3952 struct swm_screen
*s
= r
->s
;
3953 bool cycle_all
= false, mv
= false;
3955 DNPRINTF(SWM_D_WS
, "cyclews: id: %d, screen[%d]:%dx%d+%d+%d, ws: %d\n",
3956 args
->id
, r
->s
->idx
, WIDTH(r
), HEIGHT(r
), X(r
), Y(r
), r
->ws
->idx
);
3962 case SWM_ARG_ID_CYCLEWS_MOVE_UP
:
3965 case SWM_ARG_ID_CYCLEWS_UP_ALL
:
3968 case SWM_ARG_ID_CYCLEWS_UP
:
3969 a
.id
= (a
.id
< workspace_limit
- 1) ? a
.id
+ 1 : 0;
3971 case SWM_ARG_ID_CYCLEWS_MOVE_DOWN
:
3974 case SWM_ARG_ID_CYCLEWS_DOWN_ALL
:
3977 case SWM_ARG_ID_CYCLEWS_DOWN
:
3978 a
.id
= (a
.id
> 0) ? a
.id
- 1 : workspace_limit
- 1;
3985 (!cycle_empty
&& TAILQ_EMPTY(&s
->ws
[a
.id
].winlist
)))
3987 if (!cycle_visible
&& s
->ws
[a
.id
].r
!= NULL
)
3994 } while (a
.id
!= r
->ws
->idx
);
3996 DNPRINTF(SWM_D_FOCUS
, "cyclews: done\n");
4000 priorws(struct swm_region
*r
, union arg
*args
)
4006 DNPRINTF(SWM_D_WS
, "priorws: id: %d, screen[%d]:%dx%d+%d+%d, ws: %d\n",
4007 args
->id
, r
->s
->idx
, WIDTH(r
), HEIGHT(r
), X(r
), Y(r
), r
->ws
->idx
);
4009 if (r
->ws_prior
== NULL
)
4012 a
.id
= r
->ws_prior
->idx
;
4014 DNPRINTF(SWM_D_FOCUS
, "priorws: done\n");
4018 focusrg(struct swm_region
*r
, union arg
*args
)
4020 int ridx
= args
->id
, i
, num_screens
;
4021 struct swm_region
*rr
= NULL
;
4023 num_screens
= get_screen_count();
4024 /* do nothing if we don't have more than one screen */
4025 if (!(num_screens
> 1 || outputs
> 1))
4028 DNPRINTF(SWM_D_FOCUS
, "focusrg: id: %d\n", ridx
);
4030 rr
= TAILQ_FIRST(&r
->s
->rl
);
4031 for (i
= 0; i
< ridx
&& rr
!= NULL
; ++i
)
4032 rr
= TAILQ_NEXT(rr
, entry
);
4040 DNPRINTF(SWM_D_FOCUS
, "focusrg: done\n");
4044 cyclerg(struct swm_region
*r
, union arg
*args
)
4046 struct swm_region
*rr
= NULL
;
4049 num_screens
= get_screen_count();
4050 /* do nothing if we don't have more than one screen */
4051 if (!(num_screens
> 1 || outputs
> 1))
4055 DNPRINTF(SWM_D_FOCUS
, "cyclerg: id: %d, region: %d\n", args
->id
, i
);
4058 case SWM_ARG_ID_CYCLERG_UP
:
4059 rr
= TAILQ_NEXT(r
, entry
);
4061 rr
= TAILQ_FIRST(&screens
[i
].rl
);
4063 case SWM_ARG_ID_CYCLERG_DOWN
:
4064 rr
= TAILQ_PREV(r
, swm_region_list
, entry
);
4066 rr
= TAILQ_LAST(&screens
[i
].rl
, swm_region_list
);
4077 DNPRINTF(SWM_D_FOCUS
, "cyclerg: done\n");
4080 /* Sorts transients after parent. */
4082 sort_windows(struct ws_win_list
*wl
)
4084 struct ws_win
*win
, *parent
, *nxt
;
4089 for (win
= TAILQ_FIRST(wl
); win
!= TAILQ_END(wl
); win
= nxt
) {
4090 nxt
= TAILQ_NEXT(win
, entry
);
4092 parent
= find_window(win
->transient
);
4093 if (parent
== NULL
) {
4094 warnx("not possible bug");
4097 TAILQ_REMOVE(wl
, win
, entry
);
4098 TAILQ_INSERT_AFTER(wl
, parent
, win
, entry
);
4104 swapwin(struct swm_region
*r
, union arg
*args
)
4106 struct ws_win
*target
, *source
;
4107 struct ws_win
*cur_focus
;
4108 struct ws_win_list
*wl
;
4110 DNPRINTF(SWM_D_WS
, "swapwin: id: %d, screen[%d]:%dx%d+%d+%d, ws: %d\n",
4111 args
->id
, r
->s
->idx
, WIDTH(r
), HEIGHT(r
), X(r
), Y(r
), r
->ws
->idx
);
4113 cur_focus
= r
->ws
->focus
;
4114 if (cur_focus
== NULL
|| FULLSCREEN(cur_focus
))
4117 /* Adjust stacking in floating layer. */
4118 if (ABOVE(cur_focus
)) {
4120 case SWM_ARG_ID_SWAPPREV
:
4121 target
= TAILQ_PREV(cur_focus
, ws_win_stack
,
4123 if (target
!= NULL
&& FLOATING(target
)) {
4124 TAILQ_REMOVE(&cur_focus
->ws
->stack
, cur_focus
,
4126 TAILQ_INSERT_BEFORE(target
, cur_focus
,
4128 update_win_stacking(cur_focus
);
4132 case SWM_ARG_ID_SWAPNEXT
:
4133 target
= TAILQ_NEXT(cur_focus
, stack_entry
);
4134 if (target
!= NULL
&& FLOATING(target
)) {
4135 TAILQ_REMOVE(&cur_focus
->ws
->stack
, cur_focus
,
4137 TAILQ_INSERT_AFTER(&cur_focus
->ws
->stack
,
4138 target
, cur_focus
, stack_entry
);
4139 update_win_stacking(cur_focus
);
4147 if (r
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
4150 clear_maximized(r
->ws
);
4153 wl
= &source
->ws
->winlist
;
4156 case SWM_ARG_ID_SWAPPREV
:
4158 source
= find_window(source
->transient
);
4159 target
= TAILQ_PREV(source
, ws_win_list
, entry
);
4160 if (target
&& target
->transient
)
4161 target
= find_window(target
->transient
);
4162 TAILQ_REMOVE(wl
, source
, entry
);
4164 TAILQ_INSERT_TAIL(wl
, source
, entry
);
4166 TAILQ_INSERT_BEFORE(target
, source
, entry
);
4168 case SWM_ARG_ID_SWAPNEXT
:
4169 target
= TAILQ_NEXT(source
, entry
);
4170 /* move the parent and let the sort handle the move */
4172 source
= find_window(source
->transient
);
4173 TAILQ_REMOVE(wl
, source
, entry
);
4175 TAILQ_INSERT_HEAD(wl
, source
, entry
);
4177 TAILQ_INSERT_AFTER(wl
, target
, source
, entry
);
4179 case SWM_ARG_ID_SWAPMAIN
:
4180 target
= TAILQ_FIRST(wl
);
4181 if (target
== source
) {
4182 if (source
->ws
->focus_prev
!= NULL
&&
4183 source
->ws
->focus_prev
!= target
)
4184 source
= source
->ws
->focus_prev
;
4188 if (target
== NULL
|| source
== NULL
)
4190 source
->ws
->focus_prev
= target
;
4191 TAILQ_REMOVE(wl
, target
, entry
);
4192 TAILQ_INSERT_BEFORE(source
, target
, entry
);
4193 TAILQ_REMOVE(wl
, source
, entry
);
4194 TAILQ_INSERT_HEAD(wl
, source
, entry
);
4196 case SWM_ARG_ID_MOVELAST
:
4197 TAILQ_REMOVE(wl
, source
, entry
);
4198 TAILQ_INSERT_TAIL(wl
, source
, entry
);
4201 DNPRINTF(SWM_D_MOVE
, "swapwin: invalid id: %d\n", args
->id
);
4206 ewmh_update_client_list();
4212 DNPRINTF(SWM_D_MOVE
, "swapwin: done\n");
4216 get_focus_prev(struct ws_win
*win
)
4218 struct ws_win
*winfocus
= NULL
;
4219 struct ws_win
*cur_focus
= NULL
;
4220 struct ws_win_list
*wl
= NULL
;
4221 struct workspace
*ws
= NULL
;
4223 if (!(win
&& win
->ws
))
4228 cur_focus
= ws
->focus
;
4230 DNPRINTF(SWM_D_FOCUS
, "get_focus_prev: win %#x, cur_focus: %#x, "
4231 "focus_prev: %#x\n", WINID(win
), WINID(cur_focus
),
4232 WINID(ws
->focus_prev
));
4234 /* pickle, just focus on whatever */
4235 if (cur_focus
== NULL
) {
4236 /* use prev_focus if valid */
4237 if (ws
->focus_prev
&& find_window(ws
->focus_prev
->id
))
4238 winfocus
= ws
->focus_prev
;
4242 /* if transient focus on parent */
4243 if (TRANS(cur_focus
)) {
4244 winfocus
= find_window(cur_focus
->transient
);
4248 /* if in max_stack try harder */
4249 if ((win
->quirks
& SWM_Q_FOCUSPREV
) ||
4250 (ws
->cur_layout
->flags
& SWM_L_FOCUSPREV
)) {
4251 if (cur_focus
!= ws
->focus_prev
)
4252 winfocus
= ws
->focus_prev
;
4254 winfocus
= TAILQ_PREV(win
, ws_win_list
, entry
);
4259 DNPRINTF(SWM_D_FOCUS
, "get_focus_prev: focus_close: %d\n", focus_close
);
4261 if (winfocus
== NULL
|| winfocus
== win
) {
4262 switch (focus_close
) {
4263 case SWM_STACK_BOTTOM
:
4264 TAILQ_FOREACH(winfocus
, wl
, entry
)
4265 if (!ICONIC(winfocus
) && winfocus
!= cur_focus
)
4269 TAILQ_FOREACH_REVERSE(winfocus
, wl
, ws_win_list
, entry
)
4270 if (!ICONIC(winfocus
) && winfocus
!= cur_focus
)
4273 case SWM_STACK_ABOVE
:
4274 winfocus
= TAILQ_NEXT(cur_focus
, entry
);
4275 while (winfocus
&& ICONIC(winfocus
))
4276 winfocus
= TAILQ_NEXT(winfocus
, entry
);
4278 if (winfocus
== NULL
) {
4279 if (focus_close_wrap
) {
4280 TAILQ_FOREACH(winfocus
, wl
, entry
)
4281 if (!ICONIC(winfocus
) &&
4282 winfocus
!= cur_focus
)
4285 TAILQ_FOREACH_REVERSE(winfocus
, wl
,
4287 if (!ICONIC(winfocus
) &&
4288 winfocus
!= cur_focus
)
4293 case SWM_STACK_BELOW
:
4294 winfocus
= TAILQ_PREV(cur_focus
, ws_win_list
, entry
);
4295 while (winfocus
&& ICONIC(winfocus
))
4296 winfocus
= TAILQ_PREV(winfocus
, ws_win_list
,
4299 if (winfocus
== NULL
) {
4300 if (focus_close_wrap
) {
4301 TAILQ_FOREACH_REVERSE(winfocus
, wl
,
4303 if (!ICONIC(winfocus
) &&
4304 winfocus
!= cur_focus
)
4307 TAILQ_FOREACH(winfocus
, wl
, entry
)
4308 if (!ICONIC(winfocus
) &&
4309 winfocus
!= cur_focus
)
4317 if (winfocus
== NULL
||
4318 (winfocus
&& (ICONIC(winfocus
) || winfocus
== cur_focus
))) {
4319 if (focus_default
== SWM_STACK_TOP
) {
4320 TAILQ_FOREACH_REVERSE(winfocus
, wl
, ws_win_list
, entry
)
4321 if (!ICONIC(winfocus
) && winfocus
!= cur_focus
)
4324 TAILQ_FOREACH(winfocus
, wl
, entry
)
4325 if (!ICONIC(winfocus
) && winfocus
!= cur_focus
)
4332 return get_focus_magic(winfocus
);
4336 get_region_focus(struct swm_region
*r
)
4338 struct ws_win
*winfocus
= NULL
;
4343 if (r
->ws
->focus
&& !ICONIC(r
->ws
->focus
))
4344 winfocus
= r
->ws
->focus
;
4345 else if (r
->ws
->focus_prev
&& !ICONIC(r
->ws
->focus_prev
))
4346 winfocus
= r
->ws
->focus_prev
;
4348 TAILQ_FOREACH(winfocus
, &r
->ws
->winlist
, entry
)
4349 if (!ICONIC(winfocus
))
4352 return get_focus_magic(winfocus
);
4356 focus(struct swm_region
*r
, union arg
*args
)
4358 struct ws_win
*head
, *cur_focus
= NULL
, *winfocus
= NULL
;
4359 struct ws_win_list
*wl
= NULL
;
4360 struct workspace
*ws
= NULL
;
4367 cur_focus
= r
->ws
->focus
;
4371 DNPRINTF(SWM_D_FOCUS
, "focus: id: %d, cur_focus: %#x\n", args
->id
,
4374 /* Make sure an uniconified window has focus, if one exists. */
4375 if (cur_focus
== NULL
) {
4376 cur_focus
= TAILQ_FIRST(wl
);
4377 while (cur_focus
!= NULL
&& ICONIC(cur_focus
))
4378 cur_focus
= TAILQ_NEXT(cur_focus
, entry
);
4380 DNPRINTF(SWM_D_FOCUS
, "focus: new cur_focus: %#x\n",
4385 case SWM_ARG_ID_FOCUSPREV
:
4386 if (cur_focus
== NULL
)
4389 winfocus
= cur_focus
;
4391 winfocus
= TAILQ_PREV(winfocus
, ws_win_list
, entry
);
4392 if (winfocus
== NULL
)
4393 winfocus
= TAILQ_LAST(wl
, ws_win_list
);
4394 if (winfocus
== cur_focus
)
4396 } while (winfocus
&& (ICONIC(winfocus
) ||
4397 winfocus
->id
== cur_focus
->transient
||
4398 (cur_focus
->transient
!= XCB_WINDOW_NONE
&&
4399 winfocus
->transient
== cur_focus
->transient
) ||
4400 (winfocus
->quirks
& SWM_Q_NOFOCUSCYCLE
)));
4402 case SWM_ARG_ID_FOCUSNEXT
:
4403 if (cur_focus
== NULL
)
4406 winfocus
= cur_focus
;
4408 winfocus
= TAILQ_NEXT(winfocus
, entry
);
4409 if (winfocus
== NULL
)
4410 winfocus
= TAILQ_FIRST(wl
);
4411 if (winfocus
== cur_focus
)
4413 } while (winfocus
&& (ICONIC(winfocus
) ||
4414 winfocus
->id
== cur_focus
->transient
||
4415 (cur_focus
->transient
!= XCB_WINDOW_NONE
&&
4416 winfocus
->transient
== cur_focus
->transient
) ||
4417 (winfocus
->quirks
& SWM_Q_NOFOCUSCYCLE
)));
4419 case SWM_ARG_ID_FOCUSMAIN
:
4420 if (cur_focus
== NULL
)
4423 winfocus
= TAILQ_FIRST(wl
);
4424 if (winfocus
== cur_focus
)
4425 winfocus
= cur_focus
->ws
->focus_prev
;
4427 case SWM_ARG_ID_FOCUSURGENT
:
4428 /* Search forward for the next urgent window. */
4432 for (i
= 0; i
<= workspace_limit
; ++i
) {
4434 head
= TAILQ_FIRST(&r
->s
->ws
[(ws
->idx
+ i
) %
4435 workspace_limit
].winlist
);
4438 if (head
== cur_focus
) {
4440 winfocus
= cur_focus
;
4443 } else if (get_urgent(head
)) {
4448 head
= TAILQ_NEXT(head
, entry
);
4455 /* Switch ws if new focus is on a different ws. */
4456 if (winfocus
&& winfocus
->ws
!= ws
) {
4457 a
.id
= winfocus
->ws
->idx
;
4465 if (clear_maximized(ws
) > 0)
4468 focus_win(get_focus_magic(winfocus
));
4473 DNPRINTF(SWM_D_FOCUS
, "focus: done\n");
4477 cycle_layout(struct swm_region
*r
, union arg
*args
)
4479 struct workspace
*ws
= r
->ws
;
4481 /* suppress unused warning since var is needed */
4484 DNPRINTF(SWM_D_EVENT
, "cycle_layout: workspace: %d\n", ws
->idx
);
4487 if (ws
->cur_layout
->l_stack
== NULL
)
4488 ws
->cur_layout
= &layouts
[0];
4490 clear_maximized(ws
);
4495 focus_win(get_region_focus(r
));
4502 stack_config(struct swm_region
*r
, union arg
*args
)
4504 struct workspace
*ws
= r
->ws
;
4506 DNPRINTF(SWM_D_STACK
, "stack_config: id: %d workspace: %d\n",
4509 if (clear_maximized(ws
) > 0)
4512 if (ws
->cur_layout
->l_config
!= NULL
)
4513 ws
->cur_layout
->l_config(ws
, args
->id
);
4515 if (args
->id
!= SWM_ARG_ID_STACKINIT
)
4525 struct swm_geometry g
;
4526 struct swm_region
*r
, *r_prev
= NULL
;
4533 DNPRINTF(SWM_D_STACK
, "stack: begin\n");
4535 num_screens
= get_screen_count();
4536 for (i
= 0; i
< num_screens
; i
++) {
4540 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
) {
4541 /* Adjust stack area for region bar and padding. */
4543 g
.x
+= region_padding
;
4544 g
.y
+= region_padding
;
4545 g
.w
-= 2 * border_width
+ 2 * region_padding
;
4546 g
.h
-= 2 * border_width
+ 2 * region_padding
;
4547 if (bar_enabled
&& r
->ws
->bar_enabled
) {
4553 DNPRINTF(SWM_D_STACK
, "stack: workspace: %d (screen: "
4554 "%d, region: %d), (x,y) WxH: (%d,%d) %d x %d\n",
4555 r
->ws
->idx
, i
, j
++, g
.x
, g
.y
, g
.w
, g
.h
);
4558 /* Stack bar/input relative to prev. region. */
4559 val
[1] = XCB_STACK_MODE_ABOVE
;
4561 val
[0] = r_prev
->id
;
4562 DNPRINTF(SWM_D_STACK
, "stack: region input %#x "
4563 "relative to %#x.\n", r
->id
, val
[0]);
4564 xcb_configure_window(conn
, r
->id
,
4565 XCB_CONFIG_WINDOW_SIBLING
|
4566 XCB_CONFIG_WINDOW_STACK_MODE
, val
);
4568 val
[0] = r_prev
->bar
->id
;
4569 DNPRINTF(SWM_D_STACK
, "stack: region bar %#x "
4570 "relative to %#x.\n", r
->bar
->id
, val
[0]);
4571 xcb_configure_window(conn
, r
->bar
->id
,
4572 XCB_CONFIG_WINDOW_SIBLING
|
4573 XCB_CONFIG_WINDOW_STACK_MODE
, val
);
4576 r
->ws
->cur_layout
->l_stack(r
->ws
, &g
);
4577 r
->ws
->cur_layout
->l_string(r
->ws
);
4578 /* save r so we can track region changes */
4586 DNPRINTF(SWM_D_STACK
, "stack: end\n");
4590 store_float_geom(struct ws_win
*win
)
4592 if (win
== NULL
|| win
->ws
->r
== NULL
)
4595 /* retain window geom and region geom */
4596 win
->g_float
= win
->g
;
4597 win
->g_float
.x
-= X(win
->ws
->r
);
4598 win
->g_float
.y
-= Y(win
->ws
->r
);
4599 win
->g_floatvalid
= true;
4600 DNPRINTF(SWM_D_MISC
, "store_float_geom: win %#x, g: (%d,%d)"
4601 " %d x %d, g_float: (%d,%d) %d x %d\n", win
->id
, X(win
), Y(win
),
4602 WIDTH(win
), HEIGHT(win
), win
->g_float
.x
, win
->g_float
.y
,
4603 win
->g_float
.w
, win
->g_float
.h
);
4607 load_float_geom(struct ws_win
*win
)
4609 if (win
== NULL
|| win
->ws
->r
== NULL
)
4612 if (win
->g_floatvalid
) {
4613 win
->g
= win
->g_float
;
4614 X(win
) += X(win
->ws
->r
);
4615 Y(win
) += Y(win
->ws
->r
);
4616 DNPRINTF(SWM_D_MISC
, "load_float_geom: win %#x, g: (%d,%d)"
4617 "%d x %d\n", win
->id
, X(win
), Y(win
), WIDTH(win
),
4620 DNPRINTF(SWM_D_MISC
, "load_float_geom: win %#x, g_float "
4621 "is not set.\n", win
->id
);
4626 update_floater(struct ws_win
*win
)
4628 struct workspace
*ws
;
4629 struct swm_region
*r
;
4636 if ((r
= ws
->r
) == NULL
)
4639 DNPRINTF(SWM_D_MISC
, "update_floater: win %#x\n", win
->id
);
4641 win
->bordered
= true;
4643 if (FULLSCREEN(win
)) {
4644 /* _NET_WM_FULLSCREEN: fullscreen without border. */
4645 if (!win
->g_floatvalid
)
4646 store_float_geom(win
);
4649 win
->bordered
= false;
4650 } else if (MAXIMIZED(win
)) {
4651 /* Maximize: like a single stacked window. */
4652 if (!win
->g_floatvalid
)
4653 store_float_geom(win
);
4657 if (bar_enabled
&& ws
->bar_enabled
) {
4659 Y(win
) += bar_height
;
4660 HEIGHT(win
) -= bar_height
;
4661 } else if (disable_border
) {
4662 win
->bordered
= false;
4665 if (win
->bordered
) {
4666 HEIGHT(win
) -= 2 * border_width
;
4667 WIDTH(win
) -= 2 * border_width
;
4670 /* Normal floating window. */
4671 /* Update geometry if new region. */
4673 load_float_geom(win
);
4675 if ((win
->quirks
& SWM_Q_FULLSCREEN
) &&
4676 WIDTH(win
) >= WIDTH(r
) && HEIGHT(win
) >= HEIGHT(r
)) {
4677 /* Remove border for FULLSCREEN quirk. */
4678 win
->bordered
= false;
4679 } else if (!MANUAL(win
)) {
4680 if (TRANS(win
) && (win
->quirks
& SWM_Q_TRANSSZ
)) {
4681 /* Adjust size on TRANSSZ quirk. */
4682 WIDTH(win
) = (double)WIDTH(r
) * dialog_ratio
;
4683 HEIGHT(win
) = (double)HEIGHT(r
) * dialog_ratio
;
4686 if (!(win
->quirks
& SWM_Q_ANYWHERE
)) {
4688 * Floaters and transients are auto-centred
4689 * unless manually moved, resized or ANYWHERE
4692 X(win
) = X(r
) + (WIDTH(r
) - WIDTH(win
)) / 2 -
4694 Y(win
) = Y(r
) + (HEIGHT(r
) - HEIGHT(win
)) / 2 -
4696 store_float_geom(win
);
4701 /* Ensure at least 1 pixel of the window is in the region. */
4702 region_containment(win
, r
, SWM_CW_ALLSIDES
);
4708 * Send keystrokes to terminal to decrease/increase the font size as the
4709 * window size changes.
4712 adjust_font(struct ws_win
*win
)
4714 if (!(win
->quirks
& SWM_Q_XTERM_FONTADJ
) ||
4715 ABOVE(win
) || TRANS(win
))
4718 if (win
->sh
.width_inc
&& win
->last_inc
!= win
->sh
.width_inc
&&
4719 WIDTH(win
) / win
->sh
.width_inc
< term_width
&&
4720 win
->font_steps
< SWM_MAX_FONT_STEPS
) {
4721 win
->font_size_boundary
[win
->font_steps
] =
4722 (win
->sh
.width_inc
* term_width
) + win
->sh
.base_width
;
4725 win
->last_inc
= win
->sh
.width_inc
;
4726 fake_keypress(win
, XK_KP_Subtract
, XCB_MOD_MASK_SHIFT
);
4727 } else if (win
->font_steps
&& win
->last_inc
!= win
->sh
.width_inc
&&
4728 WIDTH(win
) > win
->font_size_boundary
[win
->font_steps
- 1]) {
4731 win
->last_inc
= win
->sh
.width_inc
;
4732 fake_keypress(win
, XK_KP_Add
, XCB_MOD_MASK_SHIFT
);
4736 #define SWAPXY(g) do { \
4738 tmp = (g)->y; (g)->y = (g)->x; (g)->x = tmp; \
4739 tmp = (g)->h; (g)->h = (g)->w; (g)->w = tmp; \
4742 stack_master(struct workspace
*ws
, struct swm_geometry
*g
, int rot
, bool flip
)
4744 struct swm_geometry win_g
, r_g
= *g
;
4746 int i
, j
, s
, stacks
;
4747 int w_inc
= 1, h_inc
, w_base
= 1, h_base
;
4748 int hrh
, extra
= 0, h_slice
, last_h
= 0;
4749 int split
, colno
, winno
, mwin
, msize
, mscale
;
4750 int remain
, missing
, v_slice
;
4751 bool bordered
= true, reconfigure
= false;
4753 DNPRINTF(SWM_D_STACK
, "stack_master: workspace: %d, rot: %s, "
4754 "flip: %s\n", ws
->idx
, YESNO(rot
), YESNO(flip
));
4756 /* Prepare tiling variables, if needed. */
4757 if ((winno
= count_win(ws
, false)) > 0) {
4758 /* Find first tiled window. */
4759 TAILQ_FOREACH(win
, &ws
->winlist
, entry
)
4760 if (!FLOATING(win
) && !ICONIC(win
))
4763 /* Take into account size hints of first tiled window. */
4765 w_inc
= win
->sh
.width_inc
;
4766 w_base
= win
->sh
.base_width
;
4767 mwin
= ws
->l_state
.horizontal_mwin
;
4768 mscale
= ws
->l_state
.horizontal_msize
;
4769 stacks
= ws
->l_state
.horizontal_stacks
;
4772 w_inc
= win
->sh
.height_inc
;
4773 w_base
= win
->sh
.base_height
;
4774 mwin
= ws
->l_state
.vertical_mwin
;
4775 mscale
= ws
->l_state
.vertical_msize
;
4776 stacks
= ws
->l_state
.vertical_stacks
;
4780 if (stacks
> winno
- mwin
)
4781 stacks
= winno
- mwin
;
4785 h_slice
= r_g
.h
/ SWM_H_SLICE
;
4786 if (mwin
&& winno
> mwin
) {
4787 v_slice
= r_g
.w
/ SWM_V_SLICE
;
4791 win_g
.w
= v_slice
* mscale
;
4793 if (w_inc
> 1 && w_inc
< v_slice
) {
4794 /* Adjust for requested size increment. */
4795 remain
= (win_g
.w
- w_base
) % w_inc
;
4801 win_g
.x
+= r_g
.w
- msize
;
4804 colno
= split
= winno
/ stacks
;
4805 win_g
.w
= ((r_g
.w
- (stacks
* 2 * border_width
) +
4806 2 * border_width
) / stacks
);
4808 hrh
= r_g
.h
/ colno
;
4809 extra
= r_g
.h
- (colno
* hrh
);
4810 win_g
.h
= hrh
- 2 * border_width
;
4811 i
= j
= 0, s
= stacks
;
4814 /* Update window geometry. */
4815 TAILQ_FOREACH(win
, &ws
->winlist
, entry
) {
4819 if (FLOATING(win
)) {
4820 update_floater(win
);
4825 if (split
&& i
== split
) {
4826 colno
= (winno
- mwin
) / stacks
;
4827 if (s
<= (winno
- mwin
) % stacks
)
4830 hrh
= r_g
.h
/ colno
;
4831 extra
= r_g
.h
- (colno
* hrh
);
4834 win_g
.x
+= win_g
.w
+ 2 * border_width
+
4837 win_g
.w
= (r_g
.w
- msize
-
4838 (stacks
* (2 * border_width
+ tile_gap
))) / stacks
;
4840 win_g
.w
+= (r_g
.w
- msize
-
4841 (stacks
* (2 * border_width
+ tile_gap
))) %
4845 win_g
.x
-= win_g
.w
+ 2 * border_width
+
4851 win_g
.h
= hrh
- 2 * border_width
- tile_gap
;
4854 h_inc
= win
->sh
.width_inc
;
4855 h_base
= win
->sh
.base_width
;
4857 h_inc
= win
->sh
.height_inc
;
4858 h_base
= win
->sh
.base_height
;
4861 if (j
== colno
- 1) {
4862 win_g
.h
= hrh
+ extra
;
4863 } else if (h_inc
> 1 && h_inc
< h_slice
) {
4864 /* adjust for window's requested size increment */
4865 remain
= (win_g
.h
- h_base
) % h_inc
;
4866 missing
= h_inc
- remain
;
4868 if (missing
<= extra
|| j
== 0) {
4880 win_g
.y
+= last_h
+ 2 * border_width
+ tile_gap
;
4882 if (disable_border
&& !(bar_enabled
&& ws
->bar_enabled
) &&
4885 win_g
.w
+= 2 * border_width
;
4886 win_g
.h
+= 2 * border_width
;
4892 if (X(win
) != win_g
.y
|| Y(win
) != win_g
.x
||
4893 WIDTH(win
) != win_g
.h
|| HEIGHT(win
) != win_g
.w
) {
4897 WIDTH(win
) = win_g
.h
;
4898 HEIGHT(win
) = win_g
.w
;
4901 if (X(win
) != win_g
.x
|| Y(win
) != win_g
.y
||
4902 WIDTH(win
) != win_g
.w
|| HEIGHT(win
) != win_g
.h
) {
4906 WIDTH(win
) = win_g
.w
;
4907 HEIGHT(win
) = win_g
.h
;
4911 if (bordered
!= win
->bordered
) {
4913 win
->bordered
= bordered
;
4926 /* Stack all windows from bottom up. */
4927 TAILQ_FOREACH_REVERSE(win
, &ws
->stack
, ws_win_stack
, stack_entry
)
4929 update_win_stacking(win
);
4931 /* Map all windows from top down. */
4932 TAILQ_FOREACH(win
, &ws
->stack
, stack_entry
)
4936 DNPRINTF(SWM_D_STACK
, "stack_master: done\n");
4940 vertical_config(struct workspace
*ws
, int id
)
4942 DNPRINTF(SWM_D_STACK
, "vertical_config: id: %d, workspace: %d\n",
4946 case SWM_ARG_ID_STACKRESET
:
4947 case SWM_ARG_ID_STACKINIT
:
4948 ws
->l_state
.vertical_msize
= SWM_V_SLICE
/ 2;
4949 ws
->l_state
.vertical_mwin
= 1;
4950 ws
->l_state
.vertical_stacks
= 1;
4952 case SWM_ARG_ID_STACKBALANCE
:
4953 ws
->l_state
.vertical_msize
= SWM_V_SLICE
/ (ws
->l_state
.vertical_stacks
+ 1);
4955 case SWM_ARG_ID_MASTERSHRINK
:
4956 if (ws
->l_state
.vertical_msize
> 1)
4957 ws
->l_state
.vertical_msize
--;
4959 case SWM_ARG_ID_MASTERGROW
:
4960 if (ws
->l_state
.vertical_msize
< SWM_V_SLICE
- 1)
4961 ws
->l_state
.vertical_msize
++;
4963 case SWM_ARG_ID_MASTERADD
:
4964 ws
->l_state
.vertical_mwin
++;
4966 case SWM_ARG_ID_MASTERDEL
:
4967 if (ws
->l_state
.vertical_mwin
> 0)
4968 ws
->l_state
.vertical_mwin
--;
4970 case SWM_ARG_ID_STACKINC
:
4971 ws
->l_state
.vertical_stacks
++;
4973 case SWM_ARG_ID_STACKDEC
:
4974 if (ws
->l_state
.vertical_stacks
> 1)
4975 ws
->l_state
.vertical_stacks
--;
4977 case SWM_ARG_ID_FLIPLAYOUT
:
4978 ws
->l_state
.vertical_flip
= !ws
->l_state
.vertical_flip
;
4986 vertical_stack(struct workspace
*ws
, struct swm_geometry
*g
)
4988 DNPRINTF(SWM_D_STACK
, "vertical_stack: workspace: %d\n", ws
->idx
);
4990 stack_master(ws
, g
, 0, ws
->l_state
.vertical_flip
);
4994 horizontal_config(struct workspace
*ws
, int id
)
4996 DNPRINTF(SWM_D_STACK
, "horizontal_config: workspace: %d\n", ws
->idx
);
4999 case SWM_ARG_ID_STACKRESET
:
5000 case SWM_ARG_ID_STACKINIT
:
5001 ws
->l_state
.horizontal_mwin
= 1;
5002 ws
->l_state
.horizontal_msize
= SWM_H_SLICE
/ 2;
5003 ws
->l_state
.horizontal_stacks
= 1;
5005 case SWM_ARG_ID_STACKBALANCE
:
5006 ws
->l_state
.horizontal_msize
= SWM_H_SLICE
/ (ws
->l_state
.horizontal_stacks
+ 1);
5008 case SWM_ARG_ID_MASTERSHRINK
:
5009 if (ws
->l_state
.horizontal_msize
> 1)
5010 ws
->l_state
.horizontal_msize
--;
5012 case SWM_ARG_ID_MASTERGROW
:
5013 if (ws
->l_state
.horizontal_msize
< SWM_H_SLICE
- 1)
5014 ws
->l_state
.horizontal_msize
++;
5016 case SWM_ARG_ID_MASTERADD
:
5017 ws
->l_state
.horizontal_mwin
++;
5019 case SWM_ARG_ID_MASTERDEL
:
5020 if (ws
->l_state
.horizontal_mwin
> 0)
5021 ws
->l_state
.horizontal_mwin
--;
5023 case SWM_ARG_ID_STACKINC
:
5024 ws
->l_state
.horizontal_stacks
++;
5026 case SWM_ARG_ID_STACKDEC
:
5027 if (ws
->l_state
.horizontal_stacks
> 1)
5028 ws
->l_state
.horizontal_stacks
--;
5030 case SWM_ARG_ID_FLIPLAYOUT
:
5031 ws
->l_state
.horizontal_flip
= !ws
->l_state
.horizontal_flip
;
5039 horizontal_stack(struct workspace
*ws
, struct swm_geometry
*g
)
5041 DNPRINTF(SWM_D_STACK
, "horizontal_stack: workspace: %d\n", ws
->idx
);
5043 stack_master(ws
, g
, 1, ws
->l_state
.horizontal_flip
);
5046 /* fullscreen view */
5048 max_stack(struct workspace
*ws
, struct swm_geometry
*g
)
5050 struct swm_geometry gg
= *g
;
5051 struct ws_win
*w
, *win
= NULL
, *parent
= NULL
, *tmpw
;
5054 DNPRINTF(SWM_D_STACK
, "max_stack: workspace: %d\n", ws
->idx
);
5059 winno
= count_win(ws
, false);
5060 if (winno
== 0 && count_win(ws
, true) == 0)
5063 /* Figure out which top level window should be visible. */
5064 if (ws
->focus_pending
)
5065 win
= ws
->focus_pending
;
5068 else if (ws
->focus_prev
)
5069 win
= ws
->focus_prev
;
5071 win
= TAILQ_FIRST(&ws
->winlist
);
5073 DNPRINTF(SWM_D_STACK
, "max_stack: focus_pending: %#x, focus: %#x, "
5074 "focus_prev: %#x, first: %#x, win: %#x\n", WINID(ws
->focus_pending
),
5075 WINID(ws
->focus
), WINID(ws
->focus_prev
),
5076 WINID(TAILQ_FIRST(&ws
->winlist
)), win
->id
);
5078 /* Update window geometry. */
5079 TAILQ_FOREACH(w
, &ws
->winlist
, entry
) {
5088 /* Set maximized flag for all maxed windows. */
5089 if (!MAXIMIZED(w
)) {
5090 /* Preserve floating geometry. */
5092 store_float_geom(w
);
5094 ewmh_apply_flags(w
, w
->ewmh_flags
| EWMH_F_MAXIMIZED
);
5095 ewmh_update_wm_state(w
);
5098 /* Only reconfigure if necessary. */
5099 if (X(w
) != gg
.x
|| Y(w
) != gg
.y
|| WIDTH(w
) != gg
.w
||
5100 HEIGHT(w
) != gg
.h
) {
5103 if (disable_border
&& !(bar_enabled
&& ws
->bar_enabled
)) {
5104 w
->bordered
= false;
5105 WIDTH(w
) += 2 * border_width
;
5106 HEIGHT(w
) += 2 * border_width
;
5115 /* If transient, stack parent and its children. */
5116 if (TRANS(win
) && (parent
= find_window(win
->transient
))) {
5117 raise_window(parent
);
5119 TAILQ_FOREACH_SAFE(w
, &ws
->stack
, stack_entry
, tmpw
)
5120 if (w
->transient
== parent
->id
)
5124 /* Make sure focus window is on top. */
5127 /* Stack any children of focus window. */
5128 TAILQ_FOREACH_SAFE(w
, &ws
->stack
, stack_entry
, tmpw
)
5129 if (w
->transient
== win
->id
)
5132 /* Map all windows. */
5133 TAILQ_FOREACH(w
, &ws
->stack
, stack_entry
)
5139 send_to_rg(struct swm_region
*r
, union arg
*args
)
5141 int ridx
= args
->id
, i
, num_screens
;
5142 struct swm_region
*rr
= NULL
;
5145 num_screens
= get_screen_count();
5146 /* do nothing if we don't have more than one screen */
5147 if (!(num_screens
> 1 || outputs
> 1))
5150 DNPRINTF(SWM_D_FOCUS
, "send_to_rg: id: %d\n", ridx
);
5152 rr
= TAILQ_FIRST(&r
->s
->rl
);
5153 for (i
= 0; i
< ridx
&& rr
!= NULL
; ++i
)
5154 rr
= TAILQ_NEXT(rr
, entry
);
5165 region_under(struct swm_screen
*s
, int x
, int y
)
5167 struct swm_region
*r
= NULL
;
5169 TAILQ_FOREACH(r
, &s
->rl
, entry
) {
5170 DNPRINTF(SWM_D_MISC
, "region_under: ws: %d, region g: (%d,%d) "
5171 "%d x %d, coords: (%d,%d)\n", r
->ws
->idx
, X(r
), Y(r
),
5172 WIDTH(r
), HEIGHT(r
), x
, y
);
5173 if (X(r
) <= x
&& x
< MAX_X(r
))
5174 if (Y(r
) <= y
&& y
< MAX_Y(r
))
5181 /* Transfer focused window to target workspace and focus. */
5183 send_to_ws(struct swm_region
*r
, union arg
*args
)
5185 int wsid
= args
->id
;
5186 struct ws_win
*win
= NULL
;
5188 if (r
&& r
->ws
&& r
->ws
->focus
)
5193 DNPRINTF(SWM_D_MOVE
, "send_to_ws: win %#x, ws %d\n", win
->id
, wsid
);
5195 if (wsid
< 0 || wsid
>= workspace_limit
)
5198 if (win
->ws
->idx
== wsid
)
5201 win_to_ws(win
, wsid
, true);
5203 /* Set new focus on target ws. */
5204 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
5205 win
->ws
->focus_prev
= win
->ws
->focus
;
5206 win
->ws
->focus
= win
;
5207 win
->ws
->focus_pending
= NULL
;
5209 if (win
->ws
->focus_prev
)
5210 update_window_color(win
->ws
->focus_prev
);
5213 DNPRINTF(SWM_D_STACK
, "send_to_ws: focus_pending: %#x, focus: %#x, "
5214 "focus_prev: %#x, first: %#x, win: %#x\n",
5215 WINID(r
->ws
->focus_pending
), WINID(r
->ws
->focus
),
5216 WINID(r
->ws
->focus_prev
), WINID(TAILQ_FIRST(&r
->ws
->winlist
)),
5219 ewmh_apply_flags(win
, win
->ewmh_flags
& ~EWMH_F_MAXIMIZED
);
5220 ewmh_update_wm_state(win
);
5222 /* Restack and set new focus on current ws. */
5224 load_float_geom(win
);
5228 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
5229 if (r
->ws
->focus
!= NULL
) {
5230 focus_win(r
->ws
->focus
);
5232 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
, r
->id
,
5243 win_to_ws(struct ws_win
*win
, int wsid
, bool unfocus
)
5245 struct ws_win
*parent
;
5246 struct workspace
*ws
, *nws
, *pws
;
5248 if (wsid
< 0 || wsid
>= workspace_limit
)
5251 if (win
->ws
->idx
== wsid
)
5255 nws
= &win
->s
->ws
[wsid
];
5257 DNPRINTF(SWM_D_MOVE
, "win_to_ws: win %#x, ws %d -> %d\n", win
->id
,
5260 /* Cleanup focus on source ws. */
5261 if (focus_mode
!= SWM_FOCUS_FOLLOW
&&
5262 (ws
->focus
== win
|| ws
->focus_pending
== win
))
5263 ws
->focus_pending
= get_focus_prev(win
);
5265 /* Move the parent if this is a transient window. */
5267 parent
= find_window(win
->transient
);
5270 /* Set new focus in parent's ws if needed. */
5271 if (pws
->focus
== parent
) {
5272 if (focus_mode
!= SWM_FOCUS_FOLLOW
)
5273 pws
->focus_pending
=
5274 get_focus_prev(parent
);
5276 unfocus_win(parent
);
5278 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
5279 pws
->focus
= pws
->focus_pending
;
5280 pws
->focus_pending
= NULL
;
5284 /* Don't unmap parent if new ws is visible */
5286 unmap_window(parent
);
5289 TAILQ_REMOVE(&ws
->winlist
, parent
, entry
);
5290 TAILQ_REMOVE(&ws
->stack
, parent
, stack_entry
);
5291 TAILQ_INSERT_TAIL(&nws
->winlist
, parent
, entry
);
5292 TAILQ_INSERT_TAIL(&nws
->stack
, parent
, stack_entry
);
5295 DNPRINTF(SWM_D_PROP
, "win_to_ws: set property: "
5296 "_NET_WM_DESKTOP: %d\n", wsid
);
5297 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5298 parent
->id
, ewmh
[_NET_WM_DESKTOP
].atom
,
5299 XCB_ATOM_CARDINAL
, 32, 1, &wsid
);
5306 if (ws
->focus_prev
== win
)
5307 ws
->focus_prev
= NULL
;
5309 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& ws
->focus_pending
!= NULL
) {
5310 ws
->focus
= ws
->focus_pending
;
5311 ws
->focus_pending
= NULL
;
5314 /* Don't unmap if new ws is visible */
5319 TAILQ_REMOVE(&ws
->winlist
, win
, entry
);
5320 TAILQ_REMOVE(&ws
->stack
, win
, stack_entry
);
5321 TAILQ_INSERT_TAIL(&nws
->winlist
, win
, entry
);
5322 TAILQ_INSERT_TAIL(&nws
->stack
, win
, stack_entry
);
5325 /* Update the window's workspace property: _NET_WM_DESKTOP */
5326 DNPRINTF(SWM_D_PROP
, "win_to_ws: set property: "
5327 "_NET_WM_DESKTOP: %d\n", wsid
);
5328 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
,
5329 ewmh
[_NET_WM_DESKTOP
].atom
, XCB_ATOM_CARDINAL
, 32, 1, &wsid
);
5331 ewmh_update_client_list();
5333 DNPRINTF(SWM_D_MOVE
, "win_to_ws: done.\n");
5337 pressbutton(struct swm_region
*r
, union arg
*args
)
5339 /* suppress unused warning since var is needed */
5342 xcb_test_fake_input(conn
, XCB_BUTTON_PRESS
, args
->id
,
5343 XCB_CURRENT_TIME
, XCB_WINDOW_NONE
, 0, 0, 0);
5344 xcb_test_fake_input(conn
, XCB_BUTTON_RELEASE
, args
->id
,
5345 XCB_CURRENT_TIME
, XCB_WINDOW_NONE
, 0, 0, 0);
5349 raise_toggle(struct swm_region
*r
, union arg
*args
)
5351 /* Suppress warning. */
5354 if (r
== NULL
|| r
->ws
== NULL
)
5357 if (r
->ws
->focus
&& MAXIMIZED(r
->ws
->focus
))
5360 r
->ws
->always_raise
= !r
->ws
->always_raise
;
5362 /* Update focused win stacking order based on new always_raise value. */
5363 raise_window(r
->ws
->focus
);
5369 iconify(struct swm_region
*r
, union arg
*args
)
5373 /* Suppress warning. */
5376 if ((w
= r
->ws
->focus
) == NULL
)
5379 ewmh_apply_flags(w
, w
->ewmh_flags
| EWMH_F_HIDDEN
);
5380 ewmh_update_wm_state(w
);
5388 get_win_name(xcb_window_t win
)
5391 xcb_get_property_cookie_t c
;
5392 xcb_get_property_reply_t
*r
;
5394 /* First try _NET_WM_NAME for UTF-8. */
5395 c
= xcb_get_property(conn
, 0, win
, ewmh
[_NET_WM_NAME
].atom
,
5396 XCB_GET_PROPERTY_TYPE_ANY
, 0, UINT_MAX
);
5397 r
= xcb_get_property_reply(conn
, c
, NULL
);
5398 if (r
&& r
->type
== XCB_NONE
) {
5400 /* Use WM_NAME instead; no UTF-8. */
5401 c
= xcb_get_property(conn
, 0, win
, XCB_ATOM_WM_NAME
,
5402 XCB_GET_PROPERTY_TYPE_ANY
, 0, UINT_MAX
);
5403 r
= xcb_get_property_reply(conn
, c
, NULL
);
5406 if (r
&& r
->type
!= XCB_NONE
&& r
->length
> 0)
5407 name
= strndup(xcb_get_property_value(r
),
5408 xcb_get_property_value_length(r
));
5413 err(1, "get_win_name: failed to allocate memory.");
5421 uniconify(struct swm_region
*r
, union arg
*args
)
5428 DNPRINTF(SWM_D_MISC
, "uniconify\n");
5430 if (r
== NULL
|| r
->ws
== NULL
)
5433 /* make sure we have anything to uniconify */
5434 TAILQ_FOREACH(win
, &r
->ws
->winlist
, entry
) {
5435 if (win
->ws
== NULL
)
5436 continue; /* should never happen */
5442 DNPRINTF(SWM_D_MISC
, "uniconify: count: %d\n", count
);
5448 search_resp_action
= SWM_SEARCH_UNICONIFY
;
5450 spawn_select(r
, args
, "search", &searchpid
);
5452 if ((lfile
= fdopen(select_list_pipe
[1], "w")) == NULL
)
5455 TAILQ_FOREACH(win
, &r
->ws
->winlist
, entry
) {
5456 if (win
->ws
== NULL
)
5457 continue; /* should never happen */
5461 name
= get_win_name(win
->id
);
5462 fprintf(lfile
, "%s.%u\n", name
, win
->id
);
5470 name_workspace(struct swm_region
*r
, union arg
*args
)
5474 DNPRINTF(SWM_D_MISC
, "name_workspace\n");
5480 search_resp_action
= SWM_SEARCH_NAME_WORKSPACE
;
5482 spawn_select(r
, args
, "name_workspace", &searchpid
);
5484 if ((lfile
= fdopen(select_list_pipe
[1], "w")) == NULL
)
5487 fprintf(lfile
, "%s", "");
5492 search_workspace(struct swm_region
*r
, union arg
*args
)
5495 struct workspace
*ws
;
5498 DNPRINTF(SWM_D_MISC
, "search_workspace\n");
5504 search_resp_action
= SWM_SEARCH_SEARCH_WORKSPACE
;
5506 spawn_select(r
, args
, "search", &searchpid
);
5508 if ((lfile
= fdopen(select_list_pipe
[1], "w")) == NULL
)
5511 for (i
= 0; i
< workspace_limit
; i
++) {
5515 fprintf(lfile
, "%d%s%s\n", ws
->idx
+ 1,
5516 (ws
->name
? ":" : ""), (ws
->name
? ws
->name
: ""));
5523 search_win_cleanup(void)
5525 struct search_window
*sw
= NULL
;
5527 while ((sw
= TAILQ_FIRST(&search_wl
)) != NULL
) {
5528 xcb_destroy_window(conn
, sw
->indicator
);
5529 TAILQ_REMOVE(&search_wl
, sw
, entry
);
5535 search_win(struct swm_region
*r
, union arg
*args
)
5537 struct ws_win
*win
= NULL
;
5538 struct search_window
*sw
= NULL
;
5541 xcb_screen_t
*screen
;
5542 int i
, width
, height
;
5550 XRectangle l_ibox
, l_lbox
;
5552 DNPRINTF(SWM_D_MISC
, "search_win\n");
5555 search_resp_action
= SWM_SEARCH_SEARCH_WINDOW
;
5557 spawn_select(r
, args
, "search", &searchpid
);
5559 if ((lfile
= fdopen(select_list_pipe
[1], "w")) == NULL
)
5562 if ((screen
= get_screen(r
->s
->idx
)) == NULL
)
5563 errx(1, "ERROR: can't get screen %d.", r
->s
->idx
);
5565 TAILQ_INIT(&search_wl
);
5568 TAILQ_FOREACH(win
, &r
->ws
->winlist
, entry
) {
5572 sw
= calloc(1, sizeof(struct search_window
));
5574 warn("search_win: calloc");
5576 search_win_cleanup();
5582 snprintf(s
, sizeof s
, "%d", i
);
5585 w
= xcb_generate_id(conn
);
5586 wa
[0] = r
->s
->c
[SWM_S_COLOR_FOCUS
].pixel
;
5587 wa
[1] = r
->s
->c
[SWM_S_COLOR_UNFOCUS
].pixel
;
5588 wa
[2] = screen
->default_colormap
;
5590 if (bar_font_legacy
) {
5591 XmbTextExtents(bar_fs
, s
, len
, &l_ibox
, &l_lbox
);
5592 width
= l_lbox
.width
+ 4;
5593 height
= bar_fs_extents
->max_logical_extent
.height
+ 4;
5595 XftTextExtentsUtf8(display
, bar_font
, (FcChar8
*)s
, len
,
5597 width
= info
.width
+ 4;
5598 height
= bar_font
->height
+ 4;
5601 xcb_create_window(conn
, screen
->root_depth
, w
, win
->id
, 0, 0,
5602 width
, height
, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT
,
5603 screen
->root_visual
, XCB_CW_BACK_PIXEL
|
5604 XCB_CW_BORDER_PIXEL
| XCB_CW_COLORMAP
, wa
);
5606 xcb_map_window(conn
, w
);
5609 TAILQ_INSERT_TAIL(&search_wl
, sw
, entry
);
5611 if (bar_font_legacy
) {
5612 l_gcv
.graphics_exposures
= 0;
5613 l_draw
= XCreateGC(display
, w
, 0, &l_gcv
);
5615 XSetForeground(display
, l_draw
,
5616 r
->s
->c
[SWM_S_COLOR_BAR
].pixel
);
5618 DRAWSTRING(display
, w
, bar_fs
, l_draw
, 2,
5619 (bar_fs_extents
->max_logical_extent
.height
-
5620 l_lbox
.height
) / 2 - l_lbox
.y
, s
, len
);
5622 XFreeGC(display
, l_draw
);
5625 draw
= XftDrawCreate(display
, w
,
5626 DefaultVisual(display
, r
->s
->idx
),
5627 DefaultColormap(display
, r
->s
->idx
));
5629 XftDrawStringUtf8(draw
, &search_font_color
, bar_font
, 2,
5630 (HEIGHT(r
->bar
) + bar_font
->height
) / 2 -
5631 bar_font
->descent
, (FcChar8
*)s
, len
);
5633 XftDrawDestroy(draw
);
5636 DNPRINTF(SWM_D_MISC
, "search_win: mapped win %#x\n", w
);
5638 fprintf(lfile
, "%d\n", i
);
5648 search_resp_uniconify(const char *resp
, size_t len
)
5654 DNPRINTF(SWM_D_MISC
, "search_resp_uniconify: resp: %s\n", resp
);
5656 TAILQ_FOREACH(win
, &search_r
->ws
->winlist
, entry
) {
5659 name
= get_win_name(win
->id
);
5660 if (asprintf(&s
, "%s.%u", name
, win
->id
) == -1) {
5665 if (strncmp(s
, resp
, len
) == 0) {
5666 /* XXX this should be a callback to generalize */
5667 ewmh_apply_flags(win
, win
->ewmh_flags
& ~EWMH_F_HIDDEN
);
5668 ewmh_update_wm_state(win
);
5678 search_resp_name_workspace(const char *resp
, size_t len
)
5680 struct workspace
*ws
;
5682 DNPRINTF(SWM_D_MISC
, "search_resp_name_workspace: resp: %s\n", resp
);
5684 if (search_r
->ws
== NULL
)
5689 free(search_r
->ws
->name
);
5690 search_r
->ws
->name
= NULL
;
5694 ws
->name
= strdup(resp
);
5695 if (ws
->name
== NULL
) {
5696 DNPRINTF(SWM_D_MISC
, "search_resp_name_workspace: "
5697 "strdup: %s", strerror(errno
));
5701 ewmh_update_desktop_names();
5702 ewmh_get_desktop_names();
5707 ewmh_update_desktop_names(void)
5709 char *name_list
= NULL
, *p
;
5710 int num_screens
, i
, j
, len
= 0, tot
= 0;
5712 num_screens
= get_screen_count();
5713 for (i
= 0; i
< num_screens
; ++i
) {
5714 for (j
= 0; j
< workspace_limit
; ++j
) {
5715 if (screens
[i
].ws
[j
].name
!= NULL
)
5716 len
+= strlen(screens
[i
].ws
[j
].name
);
5720 if((name_list
= calloc(len
, sizeof(char))) == NULL
)
5721 err(1, "update_desktop_names: calloc: failed to "
5722 "allocate memory.");
5725 for (j
= 0; j
< workspace_limit
; ++j
) {
5726 if (screens
[i
].ws
[j
].name
!= NULL
) {
5727 len
= strlen(screens
[i
].ws
[j
].name
);
5728 memcpy(p
, screens
[i
].ws
[j
].name
, len
);
5737 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5738 screens
[i
].root
, ewmh
[_NET_DESKTOP_NAMES
].atom
,
5739 a_utf8_string
, 8, tot
, name_list
);
5749 ewmh_get_desktop_names(void)
5752 xcb_get_property_cookie_t c
;
5753 xcb_get_property_reply_t
*r
;
5754 int num_screens
, i
, j
, n
, k
;
5756 num_screens
= get_screen_count();
5757 for (i
= 0; i
< num_screens
; ++i
) {
5758 for (j
= 0; j
< workspace_limit
; ++j
) {
5759 free(screens
[i
].ws
[j
].name
);
5760 screens
[i
].ws
[j
].name
= NULL
;
5763 c
= xcb_get_property(conn
, 0, screens
[i
].root
,
5764 ewmh
[_NET_DESKTOP_NAMES
].atom
,
5765 a_utf8_string
, 0, UINT32_MAX
);
5766 r
= xcb_get_property_reply(conn
, c
, NULL
);
5770 names
= xcb_get_property_value(r
);
5771 n
= xcb_get_property_value_length(r
);
5773 for (j
= 0, k
= 0; j
< n
; ++j
) {
5774 if (*(names
+ j
) != '\0') {
5775 screens
[i
].ws
[k
].name
= strdup(names
+ j
);
5776 j
+= strlen(names
+ j
);
5785 ewmh_update_client_list(void)
5788 int num_screens
, i
, j
, k
= 0, count
= 0;
5791 num_screens
= get_screen_count();
5792 for (i
= 0; i
< num_screens
; ++i
) {
5793 for (j
= 0; j
< workspace_limit
; ++j
)
5794 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
5797 DNPRINTF(SWM_D_PROP
, "ewmh_update_client_list: win count: %d\n",
5803 wins
= calloc(count
, sizeof(xcb_window_t
));
5805 err(1, "ewmh_update_client_list: calloc: failed to "
5806 "allocate memory.");
5808 for (j
= 0, k
= 0; j
< workspace_limit
; ++j
)
5809 TAILQ_FOREACH(win
, &screens
[i
].ws
[j
].winlist
, entry
)
5810 wins
[k
++] = win
->id
;
5812 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5813 screens
[i
].root
, ewmh
[_NET_CLIENT_LIST
].atom
,
5814 XCB_ATOM_WINDOW
, 32, count
, wins
);
5821 ewmh_update_current_desktop(void)
5825 num_screens
= get_screen_count();
5826 for (i
= 0; i
< num_screens
; ++i
)
5827 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5828 screens
[i
].root
, ewmh
[_NET_CURRENT_DESKTOP
].atom
,
5829 XCB_ATOM_CARDINAL
, 32, 1, &screens
[i
].r_focus
->ws
->idx
);
5833 ewmh_update_desktops(void)
5835 int num_screens
, i
, j
;
5838 vals
= calloc(workspace_limit
* 2, sizeof(uint32_t));
5840 err(1, "ewmh_update_desktops: calloc: failed to allocate "
5843 num_screens
= get_screen_count();
5844 for (i
= 0; i
< num_screens
; i
++) {
5845 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5846 screens
[i
].root
, ewmh
[_NET_NUMBER_OF_DESKTOPS
].atom
,
5847 XCB_ATOM_CARDINAL
, 32, 1, &workspace_limit
);
5849 for (j
= 0; j
< workspace_limit
; ++j
) {
5850 if (screens
[i
].ws
[j
].r
!= NULL
) {
5851 vals
[j
* 2] = X(screens
[i
].ws
[j
].r
);
5852 vals
[j
* 2 + 1] = Y(screens
[i
].ws
[j
].r
);
5853 } else if (screens
[i
].ws
[j
].old_r
!= NULL
) {
5854 vals
[j
* 2] = X(screens
[i
].ws
[j
].old_r
);
5855 vals
[j
* 2 + 1] = Y(screens
[i
].ws
[j
].old_r
);
5857 vals
[j
* 2] = vals
[j
* 2 + 1] = 0;
5861 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
,
5862 screens
[i
].root
, ewmh
[_NET_DESKTOP_VIEWPORT
].atom
,
5863 XCB_ATOM_CARDINAL
, 32, workspace_limit
* 2, vals
);
5870 search_resp_search_workspace(const char *resp
)
5877 DNPRINTF(SWM_D_MISC
, "search_resp_search_workspace: resp: %s\n", resp
);
5881 DNPRINTF(SWM_D_MISC
, "search_resp_search_workspace: strdup: %s",
5888 ws_idx
= (int)strtonum(q
, 1, workspace_limit
, &errstr
);
5890 DNPRINTF(SWM_D_MISC
, "workspace idx is %s: %s",
5897 switchws(search_r
, &a
);
5901 search_resp_search_window(const char *resp
)
5906 struct search_window
*sw
;
5908 DNPRINTF(SWM_D_MISC
, "search_resp_search_window: resp: %s\n", resp
);
5912 DNPRINTF(SWM_D_MISC
, "search_resp_search_window: strdup: %s",
5917 idx
= (int)strtonum(s
, 1, INT_MAX
, &errstr
);
5919 DNPRINTF(SWM_D_MISC
, "window idx is %s: %s",
5926 TAILQ_FOREACH(sw
, &search_wl
, entry
)
5927 if (idx
== sw
->idx
) {
5933 #define MAX_RESP_LEN 1024
5936 search_do_resp(void)
5942 DNPRINTF(SWM_D_MISC
, "search_do_resp:\n");
5947 if ((resp
= calloc(1, MAX_RESP_LEN
+ 1)) == NULL
) {
5948 warn("search: calloc");
5952 rbytes
= read(select_resp_pipe
[0], resp
, MAX_RESP_LEN
);
5954 warn("search: read error");
5957 resp
[rbytes
] = '\0';
5960 * Older versions of dmenu (Atleast pre 4.4.1) do not send a
5961 * newline, so work around that by sanitizing the resp now.
5963 resp
[strcspn(resp
, "\n")] = '\0';
5966 switch (search_resp_action
) {
5967 case SWM_SEARCH_UNICONIFY
:
5968 search_resp_uniconify(resp
, len
);
5970 case SWM_SEARCH_NAME_WORKSPACE
:
5971 search_resp_name_workspace(resp
, len
);
5973 case SWM_SEARCH_SEARCH_WORKSPACE
:
5974 search_resp_search_workspace(resp
);
5976 case SWM_SEARCH_SEARCH_WINDOW
:
5977 search_resp_search_window(resp
);
5982 if (search_resp_action
== SWM_SEARCH_SEARCH_WINDOW
)
5983 search_win_cleanup();
5985 search_resp_action
= SWM_SEARCH_NONE
;
5986 close(select_resp_pipe
[0]);
5993 wkill(struct swm_region
*r
, union arg
*args
)
5995 DNPRINTF(SWM_D_MISC
, "wkill: win %#x, id: %d\n", WINID(r
->ws
->focus
),
5998 if (r
->ws
->focus
== NULL
)
6001 if (args
->id
== SWM_ARG_ID_KILLWINDOW
)
6002 xcb_kill_client(conn
, r
->ws
->focus
->id
);
6004 if (r
->ws
->focus
->can_delete
)
6005 client_msg(r
->ws
->focus
, a_delete
, 0);
6011 clear_maximized(struct workspace
*ws
)
6016 /* Clear any maximized win(s) on ws, from bottom up. */
6017 TAILQ_FOREACH_REVERSE(w
, &ws
->stack
, ws_win_stack
, stack_entry
)
6019 ewmh_apply_flags(w
, w
->ewmh_flags
& ~EWMH_F_MAXIMIZED
);
6020 ewmh_update_wm_state(w
);
6028 maximize_toggle(struct swm_region
*r
, union arg
*args
)
6030 struct ws_win
*w
= r
->ws
->focus
;
6032 /* suppress unused warning since var is needed */
6038 DNPRINTF(SWM_D_MISC
, "maximize_toggle: win %#x\n", w
->id
);
6043 if (w
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
6046 ewmh_apply_flags(w
, w
->ewmh_flags
^ EWMH_F_MAXIMIZED
);
6047 ewmh_update_wm_state(w
);
6051 if (w
== w
->ws
->focus
)
6056 DNPRINTF(SWM_D_MISC
, "maximize_toggle: done\n");
6060 floating_toggle(struct swm_region
*r
, union arg
*args
)
6062 struct ws_win
*w
= r
->ws
->focus
;
6064 /* suppress unused warning since var is needed */
6070 DNPRINTF(SWM_D_MISC
, "floating_toggle: win %#x\n", w
->id
);
6072 if (FULLSCREEN(w
) || TRANS(w
))
6075 if (w
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
])
6078 ewmh_apply_flags(w
, w
->ewmh_flags
^ EWMH_F_ABOVE
);
6079 ewmh_update_wm_state(w
);
6083 if (w
== w
->ws
->focus
)
6088 DNPRINTF(SWM_D_MISC
, "floating_toggle: done\n");
6092 region_containment(struct ws_win
*win
, struct swm_region
*r
, int opts
)
6094 struct swm_geometry g
= r
->g
;
6095 int rt
, lt
, tp
, bm
, bw
;
6097 bw
= (opts
& SWM_CW_SOFTBOUNDARY
) ? boundary_width
: 0;
6100 * Perpendicular distance of each side of the window to the respective
6101 * side of the region boundary. Positive values indicate the side of
6102 * the window has passed beyond the region boundary.
6104 rt
= opts
& SWM_CW_RIGHT
? MAX_X(win
) + BORDER(win
) - MAX_X(r
) : bw
;
6105 lt
= opts
& SWM_CW_LEFT
? X(r
) - X(win
) + BORDER(win
) : bw
;
6106 bm
= opts
& SWM_CW_BOTTOM
? MAX_Y(win
) + BORDER(win
) - MAX_Y(r
) : bw
;
6107 tp
= opts
& SWM_CW_TOP
? Y(r
) - Y(win
) + BORDER(win
) : bw
;
6109 DNPRINTF(SWM_D_MISC
, "region_containment: win %#x, rt: %d, lt: %d, "
6110 "bm: %d, tp: %d, SOFTBOUNDARY: %s, HARDBOUNDARY: %s\n", win
->id
, rt
,
6111 lt
, bm
, tp
, YESNO(opts
& SWM_CW_SOFTBOUNDARY
),
6112 YESNO(opts
& SWM_CW_HARDBOUNDARY
));
6115 * Disable containment if any of the flagged sides went beyond the
6116 * containment boundary, or if containment is disabled.
6118 if (!(opts
& SWM_CW_HARDBOUNDARY
|| opts
& SWM_CW_SOFTBOUNDARY
) ||
6119 (bw
!= 0 && ((rt
> bw
) || (lt
> bw
) || (bm
> bw
) || (tp
> bw
)))) {
6120 /* Make sure window has at least 1 pixel in the region */
6121 g
.x
+= 1 - WIDTH(win
);
6122 g
.y
+= 1 - HEIGHT(win
);
6123 g
.w
+= 2 * WIDTH(win
) - 2;
6124 g
.h
+= 2 * HEIGHT(win
) - 2;
6127 constrain_window(win
, &g
, &opts
);
6130 /* Move or resize a window so that flagged side(s) fit into the supplied box. */
6132 constrain_window(struct ws_win
*win
, struct swm_geometry
*b
, int *opts
)
6134 DNPRINTF(SWM_D_MISC
, "constrain_window: win %#x, (x,y) w x h: "
6135 "(%d,%d) %d x %d, box: (x,y) w x h: (%d,%d) %d x %d, rt: %s, "
6136 "lt: %s, bt: %s, tp: %s, allow resize: %s\n", win
->id
, X(win
),
6137 Y(win
), WIDTH(win
), HEIGHT(win
), b
->x
, b
->y
, b
->w
, b
->h
,
6138 YESNO(*opts
& SWM_CW_RIGHT
), YESNO(*opts
& SWM_CW_LEFT
),
6139 YESNO(*opts
& SWM_CW_BOTTOM
), YESNO(*opts
& SWM_CW_TOP
),
6140 YESNO(*opts
& SWM_CW_RESIZABLE
));
6142 if ((*opts
& SWM_CW_RIGHT
) && MAX_X(win
) + BORDER(win
) > b
->x
+ b
->w
) {
6143 if (*opts
& SWM_CW_RESIZABLE
)
6144 WIDTH(win
) = b
->x
+ b
->w
- X(win
) - BORDER(win
);
6146 X(win
) = b
->x
+ b
->w
- WIDTH(win
) - BORDER(win
);
6149 if ((*opts
& SWM_CW_LEFT
) && X(win
) + BORDER(win
) < b
->x
) {
6150 if (*opts
& SWM_CW_RESIZABLE
)
6151 WIDTH(win
) -= b
->x
- X(win
) - BORDER(win
);
6153 X(win
) = b
->x
- BORDER(win
);
6156 if ((*opts
& SWM_CW_BOTTOM
) && MAX_Y(win
) + BORDER(win
) > b
->y
+ b
->h
) {
6157 if (*opts
& SWM_CW_RESIZABLE
)
6158 HEIGHT(win
) = b
->y
+ b
->h
- Y(win
) - BORDER(win
);
6160 Y(win
) = b
->y
+ b
->h
- HEIGHT(win
) - BORDER(win
);
6163 if ((*opts
& SWM_CW_TOP
) && Y(win
) + BORDER(win
) < b
->y
) {
6164 if (*opts
& SWM_CW_RESIZABLE
)
6165 HEIGHT(win
) -= b
->y
- Y(win
) - BORDER(win
);
6167 Y(win
) = b
->y
- BORDER(win
);
6170 if (*opts
& SWM_CW_RESIZABLE
) {
6173 if (HEIGHT(win
) < 1)
6179 update_window_color(struct ws_win
*win
)
6183 if (WS_FOCUSED(win
->ws
) && win
->ws
->focus
== win
)
6184 pixel
= MAXIMIZED(win
) ?
6185 &win
->s
->c
[SWM_S_COLOR_FOCUS_MAXIMIZED
].pixel
:
6186 &win
->s
->c
[SWM_S_COLOR_FOCUS
].pixel
;
6188 pixel
= MAXIMIZED(win
) ?
6189 &win
->s
->c
[SWM_S_COLOR_UNFOCUS_MAXIMIZED
].pixel
:
6190 &win
->s
->c
[SWM_S_COLOR_UNFOCUS
].pixel
;
6192 xcb_change_window_attributes(conn
, win
->id
,
6193 XCB_CW_BORDER_PIXEL
, pixel
);
6197 update_window(struct ws_win
*win
)
6202 mask
= XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
|
6203 XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
|
6204 XCB_CONFIG_WINDOW_BORDER_WIDTH
;
6208 wc
[3] = HEIGHT(win
);
6209 wc
[4] = BORDER(win
);
6211 DNPRINTF(SWM_D_EVENT
, "update_window: win %#x, (x,y) w x h: "
6212 "(%d,%d) %d x %d, bordered: %s\n", win
->id
, wc
[0], wc
[1], wc
[2],
6213 wc
[3], YESNO(win
->bordered
));
6215 xcb_configure_window(conn
, win
->id
, mask
, wc
);
6218 #define SWM_RESIZE_STEPS (50)
6221 resize(struct ws_win
*win
, union arg
*args
)
6223 xcb_timestamp_t timestamp
= 0;
6224 struct swm_region
*r
= NULL
;
6225 struct swm_geometry g
;
6227 int top
= 0, left
= 0;
6229 xcb_cursor_t cursor
;
6230 xcb_query_pointer_reply_t
*xpr
= NULL
;
6231 xcb_generic_event_t
*evt
;
6232 xcb_motion_notify_event_t
*mne
;
6239 if (FULLSCREEN(win
))
6242 /* In max_stack mode, should only resize transients. */
6243 if (win
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
] && !TRANS(win
))
6246 DNPRINTF(SWM_D_EVENT
, "resize: win %#x, floating: %s, "
6247 "transient: %#x\n", win
->id
, YESNO(ABOVE(win
)),
6251 store_float_geom(win
);
6252 else if (!(TRANS(win
) || ABOVE(win
)))
6255 ewmh_apply_flags(win
, (win
->ewmh_flags
| SWM_F_MANUAL
| EWMH_F_ABOVE
) &
6257 ewmh_update_wm_state(win
);
6263 /* It's possible for win to have been freed during focus_flush(). */
6264 if (validate_win(win
)) {
6265 DNPRINTF(SWM_D_EVENT
, "resize: invalid win.\n");
6270 case SWM_ARG_ID_WIDTHSHRINK
:
6271 WIDTH(win
) -= SWM_RESIZE_STEPS
;
6274 case SWM_ARG_ID_WIDTHGROW
:
6275 WIDTH(win
) += SWM_RESIZE_STEPS
;
6278 case SWM_ARG_ID_HEIGHTSHRINK
:
6279 HEIGHT(win
) -= SWM_RESIZE_STEPS
;
6282 case SWM_ARG_ID_HEIGHTGROW
:
6283 HEIGHT(win
) += SWM_RESIZE_STEPS
;
6290 region_containment(win
, r
, SWM_CW_ALLSIDES
| SWM_CW_RESIZABLE
|
6291 SWM_CW_HARDBOUNDARY
);
6293 store_float_geom(win
);
6297 region_containment(win
, r
, SWM_CW_ALLSIDES
| SWM_CW_RESIZABLE
|
6298 SWM_CW_SOFTBOUNDARY
);
6301 /* get cursor offset from window root */
6302 xpr
= xcb_query_pointer_reply(conn
, xcb_query_pointer(conn
, win
->id
),
6309 if (xpr
->win_x
< WIDTH(win
) / 2)
6312 if (xpr
->win_y
< HEIGHT(win
) / 2)
6315 if (args
->id
== SWM_ARG_ID_CENTER
)
6316 cursor
= cursors
[XC_SIZING
].cid
;
6318 cursor
= cursors
[left
? XC_TOP_LEFT_CORNER
:
6319 XC_TOP_RIGHT_CORNER
].cid
;
6321 cursor
= cursors
[left
? XC_BOTTOM_LEFT_CORNER
:
6322 XC_BOTTOM_RIGHT_CORNER
].cid
;
6324 xcb_grab_pointer(conn
, 0, win
->id
, MOUSEMASK
,
6325 XCB_GRAB_MODE_ASYNC
, XCB_GRAB_MODE_ASYNC
, XCB_WINDOW_NONE
, cursor
,
6330 while (resizing
&& (evt
= xcb_wait_for_event(conn
))) {
6331 switch (XCB_EVENT_RESPONSE_TYPE(evt
)) {
6332 case XCB_BUTTON_RELEASE
:
6333 DNPRINTF(SWM_D_EVENT
, "resize: BUTTON_RELEASE\n");
6336 case XCB_MOTION_NOTIFY
:
6337 mne
= (xcb_motion_notify_event_t
*)evt
;
6338 /* cursor offset/delta from start of the operation */
6339 dx
= mne
->root_x
- xpr
->root_x
;
6340 dy
= mne
->root_y
- xpr
->root_y
;
6346 if (args
->id
== SWM_ARG_ID_CENTER
) {
6347 if (g
.h
/ 2 + dy
< 1)
6351 HEIGHT(win
) = g
.h
+ 2 * dy
;
6359 HEIGHT(win
) = g
.h
+ dy
;
6366 if (args
->id
== SWM_ARG_ID_CENTER
) {
6367 if (g
.w
/ 2 + dx
< 1)
6371 WIDTH(win
) = g
.w
+ 2 * dx
;
6379 WIDTH(win
) = g
.w
+ dx
;
6382 /* not free, don't sync more than 120 times / second */
6383 if ((mne
->time
- timestamp
) > (1000 / 120) ) {
6384 timestamp
= mne
->time
;
6385 regionize(win
, mne
->root_x
, mne
->root_y
);
6386 region_containment(win
, r
, SWM_CW_ALLSIDES
|
6387 SWM_CW_RESIZABLE
| SWM_CW_HARDBOUNDARY
|
6388 SWM_CW_SOFTBOUNDARY
);
6395 xcb_allow_events(conn
, XCB_ALLOW_ASYNC_KEYBOARD
,
6396 ((xcb_key_press_event_t
*)evt
)->time
);
6402 /* It's possible for win to have been freed above. */
6403 if (validate_win(win
)) {
6404 DNPRINTF(SWM_D_EVENT
, "resize: invalid win.\n");
6412 region_containment(win
, r
, SWM_CW_ALLSIDES
| SWM_CW_RESIZABLE
|
6413 SWM_CW_HARDBOUNDARY
| SWM_CW_SOFTBOUNDARY
);
6417 store_float_geom(win
);
6419 xcb_ungrab_pointer(conn
, XCB_CURRENT_TIME
);
6421 DNPRINTF(SWM_D_EVENT
, "resize: done.\n");
6425 resize_step(struct swm_region
*r
, union arg
*args
)
6427 struct ws_win
*win
= NULL
;
6429 if (r
&& r
->ws
&& r
->ws
->focus
)
6439 /* Try to set window region based on supplied coordinates or window center. */
6441 regionize(struct ws_win
*win
, int x
, int y
)
6443 struct swm_region
*r
= NULL
;
6445 r
= region_under(win
->s
, x
, y
);
6447 r
= region_under(win
->s
, X(win
) + WIDTH(win
) / 2,
6448 Y(win
) + HEIGHT(win
) / 2);
6450 if (r
!= NULL
&& r
!= win
->ws
->r
) {
6451 if (clear_maximized(r
->ws
) > 0)
6454 win_to_ws(win
, r
->ws
->idx
, false);
6456 /* Set focus on new ws. */
6457 unfocus_win(r
->ws
->focus
);
6465 #define SWM_MOVE_STEPS (50)
6468 move(struct ws_win
*win
, union arg
*args
)
6470 struct swm_region
*r
;
6471 xcb_timestamp_t timestamp
= 0;
6473 xcb_query_pointer_reply_t
*qpr
= NULL
;
6474 xcb_generic_event_t
*evt
;
6475 xcb_motion_notify_event_t
*mne
;
6476 bool moving
, restack
= false;
6481 if ((r
= win
->ws
->r
) == NULL
)
6484 if (FULLSCREEN(win
))
6487 DNPRINTF(SWM_D_EVENT
, "move: win %#x, floating: %s, transient: "
6488 "%#x\n", win
->id
, YESNO(ABOVE(win
)), win
->transient
);
6490 /* in max_stack mode should only move transients */
6491 if (win
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
] && !TRANS(win
))
6494 if (!(ABOVE(win
) || TRANS(win
)) || MAXIMIZED(win
)) {
6495 store_float_geom(win
);
6499 ewmh_apply_flags(win
, (win
->ewmh_flags
| SWM_F_MANUAL
| EWMH_F_ABOVE
) &
6501 ewmh_update_wm_state(win
);
6508 /* It's possible for win to have been freed during focus_flush(). */
6509 if (validate_win(win
)) {
6510 DNPRINTF(SWM_D_EVENT
, "move: invalid win.\n");
6516 case SWM_ARG_ID_MOVELEFT
:
6517 X(win
) -= (SWM_MOVE_STEPS
- border_width
);
6520 case SWM_ARG_ID_MOVERIGHT
:
6521 X(win
) += (SWM_MOVE_STEPS
- border_width
);
6524 case SWM_ARG_ID_MOVEUP
:
6525 Y(win
) -= (SWM_MOVE_STEPS
- border_width
);
6528 case SWM_ARG_ID_MOVEDOWN
:
6529 Y(win
) += (SWM_MOVE_STEPS
- border_width
);
6536 regionize(win
, -1, -1);
6537 region_containment(win
, win
->ws
->r
, SWM_CW_ALLSIDES
);
6539 store_float_geom(win
);
6543 xcb_grab_pointer(conn
, 0, win
->id
, MOUSEMASK
,
6544 XCB_GRAB_MODE_ASYNC
, XCB_GRAB_MODE_ASYNC
,
6545 XCB_WINDOW_NONE
, cursors
[XC_FLEUR
].cid
, XCB_CURRENT_TIME
);
6547 /* get cursor offset from window root */
6548 qpr
= xcb_query_pointer_reply(conn
, xcb_query_pointer(conn
, win
->id
),
6551 xcb_ungrab_pointer(conn
, XCB_CURRENT_TIME
);
6555 regionize(win
, qpr
->root_x
, qpr
->root_y
);
6556 region_containment(win
, win
->ws
->r
, SWM_CW_ALLSIDES
|
6557 SWM_CW_SOFTBOUNDARY
);
6561 while (moving
&& (evt
= xcb_wait_for_event(conn
))) {
6562 switch (XCB_EVENT_RESPONSE_TYPE(evt
)) {
6563 case XCB_BUTTON_RELEASE
:
6564 DNPRINTF(SWM_D_EVENT
, "move: BUTTON_RELEASE\n");
6567 case XCB_MOTION_NOTIFY
:
6568 mne
= (xcb_motion_notify_event_t
*)evt
;
6569 DNPRINTF(SWM_D_EVENT
, "motion: root: %#x\n", mne
->root
);
6570 X(win
) = mne
->root_x
- qpr
->win_x
- border_width
;
6571 Y(win
) = mne
->root_y
- qpr
->win_y
- border_width
;
6573 /* not free, don't sync more than 120 times / second */
6574 if ((mne
->time
- timestamp
) > (1000 / 120) ) {
6575 timestamp
= mne
->time
;
6576 regionize(win
, mne
->root_x
, mne
->root_y
);
6577 region_containment(win
, win
->ws
->r
,
6578 SWM_CW_ALLSIDES
| SWM_CW_SOFTBOUNDARY
);
6585 xcb_allow_events(conn
, XCB_ALLOW_ASYNC_KEYBOARD
,
6586 ((xcb_key_press_event_t
*)evt
)->time
);
6592 /* It's possible for win to have been freed above. */
6593 if (validate_win(win
)) {
6594 DNPRINTF(SWM_D_EVENT
, "move: invalid win.\n");
6602 region_containment(win
, win
->ws
->r
, SWM_CW_ALLSIDES
|
6603 SWM_CW_SOFTBOUNDARY
);
6607 store_float_geom(win
);
6609 /* New region set to fullscreen layout. */
6610 if (win
->ws
->cur_layout
== &layouts
[SWM_MAX_STACK
]) {
6617 xcb_ungrab_pointer(conn
, XCB_CURRENT_TIME
);
6618 DNPRINTF(SWM_D_EVENT
, "move: done.\n");
6622 move_step(struct swm_region
*r
, union arg
*args
)
6624 struct ws_win
*win
= NULL
;
6626 if (r
&& r
->ws
&& r
->ws
->focus
)
6631 if (!TRANS(win
) && !ABOVE(win
))
6639 /* key definitions */
6641 char name
[SWM_FUNCNAME_LEN
];
6642 void (*func
)(struct swm_region
*r
, union arg
*);
6644 } keyfuncs
[KF_INVALID
+ 1] = {
6645 /* name function argument */
6646 { "bar_toggle", bar_toggle
, {.id
= SWM_ARG_ID_BAR_TOGGLE
} },
6647 { "bar_toggle_ws", bar_toggle
, {.id
= SWM_ARG_ID_BAR_TOGGLE_WS
} },
6648 { "button2", pressbutton
, {2} },
6649 { "cycle_layout", cycle_layout
, {0} },
6650 { "flip_layout", stack_config
, {.id
= SWM_ARG_ID_FLIPLAYOUT
} },
6651 { "float_toggle", floating_toggle
,{0} },
6652 { "focus_main", focus
, {.id
= SWM_ARG_ID_FOCUSMAIN
} },
6653 { "focus_next", focus
, {.id
= SWM_ARG_ID_FOCUSNEXT
} },
6654 { "focus_prev", focus
, {.id
= SWM_ARG_ID_FOCUSPREV
} },
6655 { "focus_urgent", focus
, {.id
= SWM_ARG_ID_FOCUSURGENT
} },
6656 { "maximize_toggle", maximize_toggle
,{0} },
6657 { "height_grow", resize_step
, {.id
= SWM_ARG_ID_HEIGHTGROW
} },
6658 { "height_shrink", resize_step
, {.id
= SWM_ARG_ID_HEIGHTSHRINK
} },
6659 { "iconify", iconify
, {0} },
6660 { "master_shrink", stack_config
, {.id
= SWM_ARG_ID_MASTERSHRINK
} },
6661 { "master_grow", stack_config
, {.id
= SWM_ARG_ID_MASTERGROW
} },
6662 { "master_add", stack_config
, {.id
= SWM_ARG_ID_MASTERADD
} },
6663 { "master_del", stack_config
, {.id
= SWM_ARG_ID_MASTERDEL
} },
6664 { "move_down", move_step
, {.id
= SWM_ARG_ID_MOVEDOWN
} },
6665 { "move_left", move_step
, {.id
= SWM_ARG_ID_MOVELEFT
} },
6666 { "move_right", move_step
, {.id
= SWM_ARG_ID_MOVERIGHT
} },
6667 { "move_up", move_step
, {.id
= SWM_ARG_ID_MOVEUP
} },
6668 { "mvrg_1", send_to_rg
, {.id
= 0} },
6669 { "mvrg_2", send_to_rg
, {.id
= 1} },
6670 { "mvrg_3", send_to_rg
, {.id
= 2} },
6671 { "mvrg_4", send_to_rg
, {.id
= 3} },
6672 { "mvrg_5", send_to_rg
, {.id
= 4} },
6673 { "mvrg_6", send_to_rg
, {.id
= 5} },
6674 { "mvrg_7", send_to_rg
, {.id
= 6} },
6675 { "mvrg_8", send_to_rg
, {.id
= 7} },
6676 { "mvrg_9", send_to_rg
, {.id
= 8} },
6677 { "mvws_1", send_to_ws
, {.id
= 0} },
6678 { "mvws_2", send_to_ws
, {.id
= 1} },
6679 { "mvws_3", send_to_ws
, {.id
= 2} },
6680 { "mvws_4", send_to_ws
, {.id
= 3} },
6681 { "mvws_5", send_to_ws
, {.id
= 4} },
6682 { "mvws_6", send_to_ws
, {.id
= 5} },
6683 { "mvws_7", send_to_ws
, {.id
= 6} },
6684 { "mvws_8", send_to_ws
, {.id
= 7} },
6685 { "mvws_9", send_to_ws
, {.id
= 8} },
6686 { "mvws_10", send_to_ws
, {.id
= 9} },
6687 { "mvws_11", send_to_ws
, {.id
= 10} },
6688 { "mvws_12", send_to_ws
, {.id
= 11} },
6689 { "mvws_13", send_to_ws
, {.id
= 12} },
6690 { "mvws_14", send_to_ws
, {.id
= 13} },
6691 { "mvws_15", send_to_ws
, {.id
= 14} },
6692 { "mvws_16", send_to_ws
, {.id
= 15} },
6693 { "mvws_17", send_to_ws
, {.id
= 16} },
6694 { "mvws_18", send_to_ws
, {.id
= 17} },
6695 { "mvws_19", send_to_ws
, {.id
= 18} },
6696 { "mvws_20", send_to_ws
, {.id
= 19} },
6697 { "mvws_21", send_to_ws
, {.id
= 20} },
6698 { "mvws_22", send_to_ws
, {.id
= 21} },
6699 { "name_workspace", name_workspace
, {0} },
6700 { "quit", quit
, {0} },
6701 { "raise_toggle", raise_toggle
, {0} },
6702 { "restart", restart
, {0} },
6703 { "rg_1", focusrg
, {.id
= 0} },
6704 { "rg_2", focusrg
, {.id
= 1} },
6705 { "rg_3", focusrg
, {.id
= 2} },
6706 { "rg_4", focusrg
, {.id
= 3} },
6707 { "rg_5", focusrg
, {.id
= 4} },
6708 { "rg_6", focusrg
, {.id
= 5} },
6709 { "rg_7", focusrg
, {.id
= 6} },
6710 { "rg_8", focusrg
, {.id
= 7} },
6711 { "rg_9", focusrg
, {.id
= 8} },
6712 { "rg_next", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_UP
} },
6713 { "rg_prev", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_DOWN
} },
6714 { "screen_next", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_UP
} },
6715 { "screen_prev", cyclerg
, {.id
= SWM_ARG_ID_CYCLERG_DOWN
} },
6716 { "search_win", search_win
, {0} },
6717 { "search_workspace", search_workspace
, {0} },
6718 { "spawn_custom", NULL
, {0} },
6719 { "stack_inc", stack_config
, {.id
= SWM_ARG_ID_STACKINC
} },
6720 { "stack_dec", stack_config
, {.id
= SWM_ARG_ID_STACKDEC
} },
6721 { "stack_reset", stack_config
, {.id
= SWM_ARG_ID_STACKRESET
} },
6722 { "stack_balance", stack_config
, {.id
= SWM_ARG_ID_STACKBALANCE
} },
6723 { "swap_main", swapwin
, {.id
= SWM_ARG_ID_SWAPMAIN
} },
6724 { "swap_next", swapwin
, {.id
= SWM_ARG_ID_SWAPNEXT
} },
6725 { "swap_prev", swapwin
, {.id
= SWM_ARG_ID_SWAPPREV
} },
6726 { "uniconify", uniconify
, {0} },
6727 { "version", version
, {0} },
6728 { "width_grow", resize_step
, {.id
= SWM_ARG_ID_WIDTHGROW
} },
6729 { "width_shrink", resize_step
, {.id
= SWM_ARG_ID_WIDTHSHRINK
} },
6730 { "wind_del", wkill
, {.id
= SWM_ARG_ID_DELETEWINDOW
} },
6731 { "wind_kill", wkill
, {.id
= SWM_ARG_ID_KILLWINDOW
} },
6732 { "ws_1", switchws
, {.id
= 0} },
6733 { "ws_2", switchws
, {.id
= 1} },
6734 { "ws_3", switchws
, {.id
= 2} },
6735 { "ws_4", switchws
, {.id
= 3} },
6736 { "ws_5", switchws
, {.id
= 4} },
6737 { "ws_6", switchws
, {.id
= 5} },
6738 { "ws_7", switchws
, {.id
= 6} },
6739 { "ws_8", switchws
, {.id
= 7} },
6740 { "ws_9", switchws
, {.id
= 8} },
6741 { "ws_10", switchws
, {.id
= 9} },
6742 { "ws_11", switchws
, {.id
= 10} },
6743 { "ws_12", switchws
, {.id
= 11} },
6744 { "ws_13", switchws
, {.id
= 12} },
6745 { "ws_14", switchws
, {.id
= 13} },
6746 { "ws_15", switchws
, {.id
= 14} },
6747 { "ws_16", switchws
, {.id
= 15} },
6748 { "ws_17", switchws
, {.id
= 16} },
6749 { "ws_18", switchws
, {.id
= 17} },
6750 { "ws_19", switchws
, {.id
= 18} },
6751 { "ws_20", switchws
, {.id
= 19} },
6752 { "ws_21", switchws
, {.id
= 20} },
6753 { "ws_22", switchws
, {.id
= 21} },
6754 { "ws_next", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_UP
} },
6755 { "ws_next_all", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_UP_ALL
} },
6756 { "ws_next_move", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_MOVE_UP
} },
6757 { "ws_prev", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_DOWN
} },
6758 { "ws_prev_all", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_DOWN_ALL
} },
6759 { "ws_prev_move", cyclews
, {.id
= SWM_ARG_ID_CYCLEWS_MOVE_DOWN
} },
6760 { "ws_prior", priorws
, {0} },
6761 { "dumpwins", dumpwins
, {0} }, /* MUST BE LAST */
6762 { "invalid key func", NULL
, {0} },
6766 key_cmp(struct key
*kp1
, struct key
*kp2
)
6768 if (kp1
->keysym
< kp2
->keysym
)
6770 if (kp1
->keysym
> kp2
->keysym
)
6773 if (kp1
->mod
< kp2
->mod
)
6775 if (kp1
->mod
> kp2
->mod
)
6782 enum { client_click
, root_click
};
6784 unsigned int action
;
6786 unsigned int button
;
6787 void (*func
)(struct ws_win
*, union arg
*);
6790 #define MODKEY_SHIFT MODKEY | XCB_MOD_MASK_SHIFT
6791 /* action key mouse button func args */
6792 { client_click
, MODKEY
, XCB_BUTTON_INDEX_3
, resize
, {.id
= SWM_ARG_ID_DONTCENTER
} },
6793 { client_click
, MODKEY_SHIFT
, XCB_BUTTON_INDEX_3
, resize
, {.id
= SWM_ARG_ID_CENTER
} },
6794 { client_click
, MODKEY
, XCB_BUTTON_INDEX_1
, move
, {0} },
6799 update_modkey(unsigned int mod
)
6805 RB_FOREACH(kp
, key_tree
, &keys
)
6806 if (kp
->mod
& XCB_MOD_MASK_SHIFT
)
6807 kp
->mod
= mod
| XCB_MOD_MASK_SHIFT
;
6811 for (i
= 0; i
< LENGTH(buttons
); i
++)
6812 if (buttons
[i
].mask
& XCB_MOD_MASK_SHIFT
)
6813 buttons
[i
].mask
= mod
| XCB_MOD_MASK_SHIFT
;
6815 buttons
[i
].mask
= mod
;
6819 update_mousebutton(unsigned char type
, unsigned int but
)
6825 mouse_button_move
= but
;
6828 mouse_button_resize
= but
;
6832 for (i
= 0; i
< LENGTH(buttons
); i
++) {
6833 if (buttons
[i
].func
== move
)
6834 buttons
[i
].button
= mouse_button_move
;
6836 if (buttons
[i
].func
== resize
)
6837 buttons
[i
].button
= mouse_button_resize
;
6844 spawn_expand(struct swm_region
*r
, union arg
*args
, const char *spawn_name
,
6847 struct spawn_prog
*prog
= NULL
;
6849 char *ap
, **real_args
;
6851 /* suppress unused warning since var is needed */
6854 DNPRINTF(SWM_D_SPAWN
, "spawn_expand: %s\n", spawn_name
);
6857 TAILQ_FOREACH(prog
, &spawns
, entry
) {
6858 if (strcasecmp(spawn_name
, prog
->name
) == 0)
6862 warnx("spawn_custom: program %s not found", spawn_name
);
6866 /* make room for expanded args */
6867 if ((real_args
= calloc(prog
->argc
+ 1, sizeof(char *))) == NULL
)
6868 err(1, "spawn_custom: calloc real_args");
6870 /* expand spawn_args into real_args */
6871 for (i
= c
= 0; i
< prog
->argc
; i
++) {
6873 DNPRINTF(SWM_D_SPAWN
, "spawn_custom: raw arg: %s\n", ap
);
6874 if (strcasecmp(ap
, "$bar_border") == 0) {
6876 strdup(r
->s
->c
[SWM_S_COLOR_BAR_BORDER
].name
))
6878 err(1, "spawn_custom border color");
6879 } else if (strcasecmp(ap
, "$bar_color") == 0) {
6881 strdup(r
->s
->c
[SWM_S_COLOR_BAR
].name
))
6883 err(1, "spawn_custom bar color");
6884 } else if (strcasecmp(ap
, "$bar_font") == 0) {
6885 if ((real_args
[c
] = strdup(bar_fonts
))
6887 err(1, "spawn_custom bar fonts");
6888 } else if (strcasecmp(ap
, "$bar_font_color") == 0) {
6890 strdup(r
->s
->c
[SWM_S_COLOR_BAR_FONT
].name
))
6892 err(1, "spawn_custom color font");
6893 } else if (strcasecmp(ap
, "$color_focus") == 0) {
6895 strdup(r
->s
->c
[SWM_S_COLOR_FOCUS
].name
))
6897 err(1, "spawn_custom color focus");
6898 } else if (strcasecmp(ap
, "$color_focus_maximized") == 0) {
6900 strdup(r
->s
->c
[SWM_S_COLOR_FOCUS_MAXIMIZED
].name
))
6902 err(1, "spawn_custom color focus maximized");
6903 } else if (strcasecmp(ap
, "$color_unfocus") == 0) {
6905 strdup(r
->s
->c
[SWM_S_COLOR_UNFOCUS
].name
))
6907 err(1, "spawn_custom color unfocus");
6908 } else if (strcasecmp(ap
, "$color_unfocus_maximized") == 0) {
6910 strdup(r
->s
->c
[SWM_S_COLOR_UNFOCUS_MAXIMIZED
].name
))
6912 err(1, "spawn_custom color unfocus maximized");
6913 } else if (strcasecmp(ap
, "$region_index") == 0) {
6914 if (asprintf(&real_args
[c
], "%d",
6915 get_region_index(r
) + 1) < 1)
6916 err(1, "spawn_custom region index");
6917 } else if (strcasecmp(ap
, "$workspace_index") == 0) {
6918 if (asprintf(&real_args
[c
], "%d", r
->ws
->idx
+ 1) < 1)
6919 err(1, "spawn_custom workspace index");
6920 } else if (strcasecmp(ap
, "$dmenu_bottom") == 0) {
6923 if ((real_args
[c
] = strdup("-b")) == NULL
)
6924 err(1, "spawn_custom workspace index");
6926 /* no match --> copy as is */
6927 if ((real_args
[c
] = strdup(ap
)) == NULL
)
6928 err(1, "spawn_custom strdup(ap)");
6930 DNPRINTF(SWM_D_SPAWN
, "spawn_custom: cooked arg: %s\n",
6936 DNPRINTF(SWM_D_SPAWN
, "spawn_custom: result: ");
6937 for (i
= 0; i
< c
; ++i
)
6938 DPRINTF("\"%s\" ", real_args
[i
]);
6941 *ret_args
= real_args
;
6946 spawn_custom(struct swm_region
*r
, union arg
*args
, const char *spawn_name
)
6952 if ((spawn_argc
= spawn_expand(r
, args
, spawn_name
, &real_args
)) < 0)
6956 spawn(r
->ws
->idx
, &a
, true);
6958 for (i
= 0; i
< spawn_argc
; i
++)
6964 spawn_select(struct swm_region
*r
, union arg
*args
, const char *spawn_name
,
6971 if ((spawn_argc
= spawn_expand(r
, args
, spawn_name
, &real_args
)) < 0)
6975 if (pipe(select_list_pipe
) == -1)
6976 err(1, "pipe error");
6977 if (pipe(select_resp_pipe
) == -1)
6978 err(1, "pipe error");
6980 if (signal(SIGPIPE
, SIG_IGN
) == SIG_ERR
)
6981 err(1, "could not disable SIGPIPE");
6982 switch (*pid
= fork()) {
6984 err(1, "cannot fork");
6987 if (dup2(select_list_pipe
[0], STDIN_FILENO
) == -1)
6989 if (dup2(select_resp_pipe
[1], STDOUT_FILENO
) == -1)
6991 close(select_list_pipe
[1]);
6992 close(select_resp_pipe
[0]);
6993 spawn(r
->ws
->idx
, &a
, false);
6995 default: /* parent */
6996 close(select_list_pipe
[0]);
6997 close(select_resp_pipe
[1]);
7001 for (i
= 0; i
< spawn_argc
; i
++)
7006 /* Argument tokenizer. */
7009 char *arg
, *cp
, *next
;
7010 bool single_quoted
= false, double_quoted
= false;
7015 /* Eat and move characters until end of argument is found. */
7016 for (arg
= next
= cp
= *sp
; *cp
!= '\0'; ++cp
) {
7017 if (!double_quoted
&& *cp
== '\'') {
7018 /* Eat single-quote. */
7019 single_quoted
= !single_quoted
;
7020 } else if (!single_quoted
&& *cp
== '"') {
7021 /* Eat double-quote. */
7022 double_quoted
= !double_quoted
;
7023 } else if (!single_quoted
&& *cp
== '\\' && *(cp
+ 1) == '"') {
7024 /* Eat backslash; copy escaped character to arg. */
7026 } else if (!single_quoted
&& !double_quoted
&& *cp
== '\\' &&
7027 (*(cp
+ 1) == '\'' || *(cp
+ 1) == ' ')) {
7028 /* Eat backslash; move escaped character. */
7030 } else if (!single_quoted
&& !double_quoted
&&
7031 (*cp
== ' ' || *cp
== '\t')) {
7032 /* Terminate argument. */
7034 /* Point sp to beginning of next argument. */
7038 /* Move regular character. */
7043 /* Terminate argument if end of string. */
7053 spawn_insert(const char *name
, const char *args
, int flags
)
7055 struct spawn_prog
*sp
;
7056 char *arg
, *cp
, *ptr
;
7058 DNPRINTF(SWM_D_SPAWN
, "spawn_insert: %s[%s]\n", name
, args
);
7060 if (args
== NULL
|| *args
== '\0')
7063 if ((sp
= calloc(1, sizeof *sp
)) == NULL
)
7064 err(1, "spawn_insert: calloc");
7065 if ((sp
->name
= strdup(name
)) == NULL
)
7066 err(1, "spawn_insert: strdup");
7068 /* Convert the arguments to an argument list. */
7069 if ((ptr
= cp
= strdup(args
)) == NULL
)
7070 err(1, "spawn_insert: strdup");
7071 while ((arg
= argsep(&ptr
)) != NULL
) {
7072 /* Null argument; skip it. */
7077 if ((sp
->argv
= realloc(sp
->argv
, sp
->argc
*
7078 sizeof *sp
->argv
)) == NULL
)
7079 err(1, "spawn_insert: realloc");
7080 if ((sp
->argv
[sp
->argc
- 1] = strdup(arg
)) == NULL
)
7081 err(1, "spawn_insert: strdup");
7087 DNPRINTF(SWM_D_SPAWN
, "arg %d: [%s]\n", sp
->argc
, sp
->argv
[sp
->argc
-1]);
7088 TAILQ_INSERT_TAIL(&spawns
, sp
, entry
);
7089 DNPRINTF(SWM_D_SPAWN
, "spawn_insert: leave\n");
7093 spawn_remove(struct spawn_prog
*sp
)
7097 DNPRINTF(SWM_D_SPAWN
, "spawn_remove: %s\n", sp
->name
);
7099 TAILQ_REMOVE(&spawns
, sp
, entry
);
7100 for (i
= 0; i
< sp
->argc
; i
++)
7106 DNPRINTF(SWM_D_SPAWN
, "spawn_remove: leave\n");
7110 spawn_find(const char *name
)
7112 struct spawn_prog
*sp
;
7114 TAILQ_FOREACH(sp
, &spawns
, entry
)
7115 if (strcasecmp(sp
->name
, name
) == 0)
7122 setspawn(const char *name
, const char *args
, int flags
)
7124 struct spawn_prog
*sp
;
7126 DNPRINTF(SWM_D_SPAWN
, "setspawn: %s\n", name
);
7131 /* Remove any old spawn under the same name. */
7132 if ((sp
= spawn_find(name
)) != NULL
)
7136 spawn_insert(name
, args
, flags
);
7138 warnx("error: setspawn: cannot find program: %s", name
);
7140 DNPRINTF(SWM_D_SPAWN
, "setspawn: leave\n");
7144 setconfspawn(const char *selector
, const char *value
, int flags
)
7148 if (selector
== NULL
|| strlen(selector
) == 0)
7151 args
= expand_tilde(value
);
7153 DNPRINTF(SWM_D_SPAWN
, "setconfspawn: [%s] [%s]\n", selector
, args
);
7155 setspawn(selector
, args
, flags
);
7158 DNPRINTF(SWM_D_SPAWN
, "setconfspawn: done.\n");
7163 validate_spawns(void)
7165 struct spawn_prog
*sp
;
7166 char which
[PATH_MAX
];
7171 RB_FOREACH(kp
, key_tree
, &keys
) {
7172 if (kp
->funcid
!= KF_SPAWN_CUSTOM
)
7176 sp
= spawn_find(kp
->spawn_name
);
7177 if (sp
== NULL
|| sp
->flags
& SWM_SPAWN_OPTIONAL
)
7180 /* verify we have the goods */
7181 snprintf(which
, sizeof which
, "which %s", sp
->argv
[0]);
7182 DNPRINTF(SWM_D_CONF
, "validate_spawns: which %s\n",
7184 for (i
= strlen("which "); i
< strlen(which
); i
++)
7185 if (which
[i
] == ' ') {
7189 if (system(which
) != 0)
7190 add_startup_exception("could not find %s",
7191 &which
[strlen("which ")]);
7198 setconfspawn("lock", "xlock", 0);
7200 setconfspawn("term", "xterm", 0);
7201 setconfspawn("spawn_term", "xterm", 0);
7203 setconfspawn("menu", "dmenu_run"
7207 " -nf $bar_font_color"
7209 " -sf $bar_color", 0);
7211 setconfspawn("search", "dmenu"
7216 " -nf $bar_font_color"
7218 " -sf $bar_color", 0);
7220 setconfspawn("name_workspace", "dmenu"
7225 " -nf $bar_font_color"
7227 " -sf $bar_color", 0);
7229 /* These are not verified for existence, even with a binding set. */
7230 setconfspawn("screenshot_all", "screenshot.sh full", SWM_SPAWN_OPTIONAL
);
7231 setconfspawn("screenshot_wind", "screenshot.sh window", SWM_SPAWN_OPTIONAL
);
7232 setconfspawn("initscr", "initscreen.sh", SWM_SPAWN_OPTIONAL
);
7236 #define SWM_MODNAME_SIZE 32
7237 #define SWM_KEY_WS "\n+ \t"
7239 parsekeys(const char *keystr
, unsigned int currmod
, unsigned int *mod
, KeySym
*ks
)
7241 char *str
, *cp
, *name
;
7244 DNPRINTF(SWM_D_KEY
, "parsekeys: enter [%s]\n", keystr
);
7245 if (mod
== NULL
|| ks
== NULL
) {
7246 DNPRINTF(SWM_D_KEY
, "parsekeys: no mod or key vars\n");
7249 if (keystr
== NULL
|| strlen(keystr
) == 0) {
7250 DNPRINTF(SWM_D_KEY
, "parsekeys: no keystr\n");
7254 if ((cp
= str
= strdup(keystr
)) == NULL
)
7255 err(1, "parsekeys: strdup");
7257 *ks
= XCB_NO_SYMBOL
;
7259 while ((name
= strsep(&cp
, SWM_KEY_WS
)) != NULL
) {
7260 DNPRINTF(SWM_D_KEY
, "parsekeys: key [%s]\n", name
);
7262 cp
+= (long)strspn(cp
, SWM_KEY_WS
);
7263 if (strncasecmp(name
, "MOD", SWM_MODNAME_SIZE
) == 0)
7265 else if (strncasecmp(name
, "Mod1", SWM_MODNAME_SIZE
) == 0)
7266 *mod
|= XCB_MOD_MASK_1
;
7267 else if (strncasecmp(name
, "Mod2", SWM_MODNAME_SIZE
) == 0)
7268 *mod
+= XCB_MOD_MASK_2
;
7269 else if (strncmp(name
, "Mod3", SWM_MODNAME_SIZE
) == 0)
7270 *mod
|= XCB_MOD_MASK_3
;
7271 else if (strncmp(name
, "Mod4", SWM_MODNAME_SIZE
) == 0)
7272 *mod
|= XCB_MOD_MASK_4
;
7273 else if (strncmp(name
, "Mod5", SWM_MODNAME_SIZE
) == 0)
7274 *mod
|= XCB_MOD_MASK_5
;
7275 else if (strncasecmp(name
, "SHIFT", SWM_MODNAME_SIZE
) == 0)
7276 *mod
|= XCB_MOD_MASK_SHIFT
;
7277 else if (strncasecmp(name
, "CONTROL", SWM_MODNAME_SIZE
) == 0)
7278 *mod
|= XCB_MOD_MASK_CONTROL
;
7280 *ks
= XStringToKeysym(name
);
7281 XConvertCase(*ks
, ks
, &uks
);
7282 if (ks
== XCB_NO_SYMBOL
) {
7284 "parsekeys: invalid key %s\n",
7293 DNPRINTF(SWM_D_KEY
, "parsekeys: leave ok\n");
7298 strdupsafe(const char *str
)
7303 return (strdup(str
));
7307 key_insert(unsigned int mod
, KeySym ks
, enum keyfuncid kfid
,
7308 const char *spawn_name
)
7312 DNPRINTF(SWM_D_KEY
, "key_insert: enter %s [%s]\n",
7313 keyfuncs
[kfid
].name
, spawn_name
);
7315 if ((kp
= malloc(sizeof *kp
)) == NULL
)
7316 err(1, "key_insert: malloc");
7321 kp
->spawn_name
= strdupsafe(spawn_name
);
7322 RB_INSERT(key_tree
, &keys
, kp
);
7324 DNPRINTF(SWM_D_KEY
, "key_insert: leave\n");
7328 key_lookup(unsigned int mod
, KeySym ks
)
7335 return (RB_FIND(key_tree
, &keys
, &kp
));
7339 key_remove(struct key
*kp
)
7341 DNPRINTF(SWM_D_KEY
, "key_remove: %s\n", keyfuncs
[kp
->funcid
].name
);
7343 RB_REMOVE(key_tree
, &keys
, kp
);
7344 free(kp
->spawn_name
);
7347 DNPRINTF(SWM_D_KEY
, "key_remove: leave\n");
7351 key_replace(struct key
*kp
, unsigned int mod
, KeySym ks
, enum keyfuncid kfid
,
7352 const char *spawn_name
)
7354 DNPRINTF(SWM_D_KEY
, "key_replace: %s [%s]\n", keyfuncs
[kp
->funcid
].name
,
7358 key_insert(mod
, ks
, kfid
, spawn_name
);
7360 DNPRINTF(SWM_D_KEY
, "key_replace: leave\n");
7364 setkeybinding(unsigned int mod
, KeySym ks
, enum keyfuncid kfid
,
7365 const char *spawn_name
)
7369 DNPRINTF(SWM_D_KEY
, "setkeybinding: enter %s [%s]\n",
7370 keyfuncs
[kfid
].name
, spawn_name
);
7372 if ((kp
= key_lookup(mod
, ks
)) != NULL
) {
7373 if (kfid
== KF_INVALID
)
7376 key_replace(kp
, mod
, ks
, kfid
, spawn_name
);
7377 DNPRINTF(SWM_D_KEY
, "setkeybinding: leave\n");
7380 if (kfid
== KF_INVALID
) {
7381 warnx("bind: Key combination already unbound.");
7382 DNPRINTF(SWM_D_KEY
, "setkeybinding: leave\n");
7386 key_insert(mod
, ks
, kfid
, spawn_name
);
7387 DNPRINTF(SWM_D_KEY
, "setkeybinding: leave\n");
7391 setconfbinding(const char *selector
, const char *value
, int flags
)
7393 enum keyfuncid kfid
;
7396 struct spawn_prog
*sp
;
7398 /* suppress unused warning since var is needed */
7401 DNPRINTF(SWM_D_KEY
, "setconfbinding: enter selector: [%s], "
7402 "value: [%s]\n", selector
, value
);
7403 if (selector
== NULL
|| strlen(selector
) == 0) {
7404 DNPRINTF(SWM_D_KEY
, "setconfbinding: unbind %s\n", value
);
7405 if (parsekeys(value
, mod_key
, &mod
, &ks
) == 0) {
7407 setkeybinding(mod
, ks
, kfid
, NULL
);
7412 /* search by key function name */
7413 for (kfid
= 0; kfid
< KF_INVALID
; (kfid
)++) {
7414 if (strncasecmp(selector
, keyfuncs
[kfid
].name
,
7415 SWM_FUNCNAME_LEN
) == 0) {
7416 DNPRINTF(SWM_D_KEY
, "setconfbinding: %s: match "
7417 "keyfunc\n", selector
);
7418 if (parsekeys(value
, mod_key
, &mod
, &ks
) == 0) {
7419 setkeybinding(mod
, ks
, kfid
, NULL
);
7425 /* search by custom spawn name */
7426 if ((sp
= spawn_find(selector
)) != NULL
) {
7427 DNPRINTF(SWM_D_KEY
, "setconfbinding: %s: match "
7428 "spawn\n", selector
);
7429 if (parsekeys(value
, mod_key
, &mod
, &ks
) == 0) {
7430 setkeybinding(mod
, ks
, KF_SPAWN_CUSTOM
,
7436 DNPRINTF(SWM_D_KEY
, "setconfbinding: no match\n");
7443 #define MODKEY_SHIFT MODKEY | XCB_MOD_MASK_SHIFT
7444 setkeybinding(MODKEY
, XK_b
, KF_BAR_TOGGLE
, NULL
);
7445 setkeybinding(MODKEY_SHIFT
, XK_b
, KF_BAR_TOGGLE_WS
,NULL
);
7446 setkeybinding(MODKEY
, XK_v
, KF_BUTTON2
, NULL
);
7447 setkeybinding(MODKEY
, XK_space
, KF_CYCLE_LAYOUT
,NULL
);
7448 setkeybinding(MODKEY_SHIFT
, XK_backslash
, KF_FLIP_LAYOUT
, NULL
);
7449 setkeybinding(MODKEY
, XK_t
, KF_FLOAT_TOGGLE
,NULL
);
7450 setkeybinding(MODKEY
, XK_m
, KF_FOCUS_MAIN
, NULL
);
7451 setkeybinding(MODKEY
, XK_j
, KF_FOCUS_NEXT
, NULL
);
7452 setkeybinding(MODKEY
, XK_Tab
, KF_FOCUS_NEXT
, NULL
);
7453 setkeybinding(MODKEY
, XK_k
, KF_FOCUS_PREV
, NULL
);
7454 setkeybinding(MODKEY_SHIFT
, XK_Tab
, KF_FOCUS_PREV
, NULL
);
7455 setkeybinding(MODKEY
, XK_u
, KF_FOCUS_URGENT
,NULL
);
7456 setkeybinding(MODKEY
, XK_e
, KF_MAXIMIZE_TOGGLE
,NULL
);
7457 setkeybinding(MODKEY_SHIFT
, XK_equal
, KF_HEIGHT_GROW
,NULL
);
7458 setkeybinding(MODKEY_SHIFT
, XK_minus
, KF_HEIGHT_SHRINK
,NULL
);
7459 setkeybinding(MODKEY
, XK_w
, KF_ICONIFY
, NULL
);
7460 setkeybinding(MODKEY
, XK_h
, KF_MASTER_SHRINK
, NULL
);
7461 setkeybinding(MODKEY
, XK_l
, KF_MASTER_GROW
, NULL
);
7462 setkeybinding(MODKEY
, XK_comma
, KF_MASTER_ADD
, NULL
);
7463 setkeybinding(MODKEY
, XK_period
, KF_MASTER_DEL
, NULL
);
7464 setkeybinding(MODKEY_SHIFT
, XK_bracketright
,KF_MOVE_DOWN
,NULL
);
7465 setkeybinding(MODKEY
, XK_bracketleft
, KF_MOVE_LEFT
,NULL
);
7466 setkeybinding(MODKEY
, XK_bracketright
,KF_MOVE_RIGHT
,NULL
);
7467 setkeybinding(MODKEY_SHIFT
, XK_bracketleft
, KF_MOVE_UP
, NULL
);
7468 setkeybinding(MODKEY_SHIFT
, XK_KP_End
, KF_MVRG_1
, NULL
);
7469 setkeybinding(MODKEY_SHIFT
, XK_KP_Down
, KF_MVRG_2
, NULL
);
7470 setkeybinding(MODKEY_SHIFT
, XK_KP_Next
, KF_MVRG_3
, NULL
);
7471 setkeybinding(MODKEY_SHIFT
, XK_KP_Left
, KF_MVRG_4
, NULL
);
7472 setkeybinding(MODKEY_SHIFT
, XK_KP_Begin
, KF_MVRG_5
, NULL
);
7473 setkeybinding(MODKEY_SHIFT
, XK_KP_Right
, KF_MVRG_6
, NULL
);
7474 setkeybinding(MODKEY_SHIFT
, XK_KP_Home
, KF_MVRG_7
, NULL
);
7475 setkeybinding(MODKEY_SHIFT
, XK_KP_Up
, KF_MVRG_8
, NULL
);
7476 setkeybinding(MODKEY_SHIFT
, XK_KP_Prior
, KF_MVRG_9
, NULL
);
7477 setkeybinding(MODKEY_SHIFT
, XK_1
, KF_MVWS_1
, NULL
);
7478 setkeybinding(MODKEY_SHIFT
, XK_2
, KF_MVWS_2
, NULL
);
7479 setkeybinding(MODKEY_SHIFT
, XK_3
, KF_MVWS_3
, NULL
);
7480 setkeybinding(MODKEY_SHIFT
, XK_4
, KF_MVWS_4
, NULL
);
7481 setkeybinding(MODKEY_SHIFT
, XK_5
, KF_MVWS_5
, NULL
);
7482 setkeybinding(MODKEY_SHIFT
, XK_6
, KF_MVWS_6
, NULL
);
7483 setkeybinding(MODKEY_SHIFT
, XK_7
, KF_MVWS_7
, NULL
);
7484 setkeybinding(MODKEY_SHIFT
, XK_8
, KF_MVWS_8
, NULL
);
7485 setkeybinding(MODKEY_SHIFT
, XK_9
, KF_MVWS_9
, NULL
);
7486 setkeybinding(MODKEY_SHIFT
, XK_0
, KF_MVWS_10
, NULL
);
7487 setkeybinding(MODKEY_SHIFT
, XK_F1
, KF_MVWS_11
, NULL
);
7488 setkeybinding(MODKEY_SHIFT
, XK_F2
, KF_MVWS_12
, NULL
);
7489 setkeybinding(MODKEY_SHIFT
, XK_F3
, KF_MVWS_13
, NULL
);
7490 setkeybinding(MODKEY_SHIFT
, XK_F4
, KF_MVWS_14
, NULL
);
7491 setkeybinding(MODKEY_SHIFT
, XK_F5
, KF_MVWS_15
, NULL
);
7492 setkeybinding(MODKEY_SHIFT
, XK_F6
, KF_MVWS_16
, NULL
);
7493 setkeybinding(MODKEY_SHIFT
, XK_F7
, KF_MVWS_17
, NULL
);
7494 setkeybinding(MODKEY_SHIFT
, XK_F8
, KF_MVWS_18
, NULL
);
7495 setkeybinding(MODKEY_SHIFT
, XK_F9
, KF_MVWS_19
, NULL
);
7496 setkeybinding(MODKEY_SHIFT
, XK_F10
, KF_MVWS_20
, NULL
);
7497 setkeybinding(MODKEY_SHIFT
, XK_F11
, KF_MVWS_21
, NULL
);
7498 setkeybinding(MODKEY_SHIFT
, XK_F12
, KF_MVWS_22
, NULL
);
7499 setkeybinding(MODKEY_SHIFT
, XK_slash
, KF_NAME_WORKSPACE
,NULL
);
7500 setkeybinding(MODKEY_SHIFT
, XK_q
, KF_QUIT
, NULL
);
7501 setkeybinding(MODKEY_SHIFT
, XK_r
, KF_RAISE_TOGGLE
,NULL
);
7502 setkeybinding(MODKEY
, XK_q
, KF_RESTART
, NULL
);
7503 setkeybinding(MODKEY
, XK_KP_End
, KF_RG_1
, NULL
);
7504 setkeybinding(MODKEY
, XK_KP_Down
, KF_RG_2
, NULL
);
7505 setkeybinding(MODKEY
, XK_KP_Next
, KF_RG_3
, NULL
);
7506 setkeybinding(MODKEY
, XK_KP_Left
, KF_RG_4
, NULL
);
7507 setkeybinding(MODKEY
, XK_KP_Begin
, KF_RG_5
, NULL
);
7508 setkeybinding(MODKEY
, XK_KP_Right
, KF_RG_6
, NULL
);
7509 setkeybinding(MODKEY
, XK_KP_Home
, KF_RG_7
, NULL
);
7510 setkeybinding(MODKEY
, XK_KP_Up
, KF_RG_8
, NULL
);
7511 setkeybinding(MODKEY
, XK_KP_Prior
, KF_RG_9
, NULL
);
7512 setkeybinding(MODKEY_SHIFT
, XK_Right
, KF_RG_NEXT
, NULL
);
7513 setkeybinding(MODKEY_SHIFT
, XK_Left
, KF_RG_PREV
, NULL
);
7514 setkeybinding(MODKEY
, XK_f
, KF_SEARCH_WIN
, NULL
);
7515 setkeybinding(MODKEY
, XK_slash
, KF_SEARCH_WORKSPACE
,NULL
);
7516 setkeybinding(MODKEY_SHIFT
, XK_i
, KF_SPAWN_CUSTOM
,"initscr");
7517 setkeybinding(MODKEY_SHIFT
, XK_Delete
, KF_SPAWN_CUSTOM
,"lock");
7518 setkeybinding(MODKEY
, XK_p
, KF_SPAWN_CUSTOM
,"menu");
7519 setkeybinding(MODKEY
, XK_s
, KF_SPAWN_CUSTOM
,"screenshot_all");
7520 setkeybinding(MODKEY_SHIFT
, XK_s
, KF_SPAWN_CUSTOM
,"screenshot_wind");
7521 setkeybinding(MODKEY_SHIFT
, XK_Return
, KF_SPAWN_CUSTOM
,"term");
7522 setkeybinding(MODKEY_SHIFT
, XK_comma
, KF_STACK_INC
, NULL
);
7523 setkeybinding(MODKEY_SHIFT
, XK_period
, KF_STACK_DEC
, NULL
);
7524 setkeybinding(MODKEY_SHIFT
, XK_space
, KF_STACK_RESET
, NULL
);
7525 setkeybinding(MODKEY_SHIFT
, XK_h
, KF_STACK_BALANCE
, NULL
);
7526 setkeybinding(MODKEY
, XK_Return
, KF_SWAP_MAIN
, NULL
);
7527 setkeybinding(MODKEY_SHIFT
, XK_j
, KF_SWAP_NEXT
, NULL
);
7528 setkeybinding(MODKEY_SHIFT
, XK_k
, KF_SWAP_PREV
, NULL
);
7529 setkeybinding(MODKEY_SHIFT
, XK_w
, KF_UNICONIFY
, NULL
);
7530 setkeybinding(MODKEY_SHIFT
, XK_v
, KF_VERSION
, NULL
);
7531 setkeybinding(MODKEY
, XK_equal
, KF_WIDTH_GROW
, NULL
);
7532 setkeybinding(MODKEY
, XK_minus
, KF_WIDTH_SHRINK
,NULL
);
7533 setkeybinding(MODKEY
, XK_x
, KF_WIND_DEL
, NULL
);
7534 setkeybinding(MODKEY_SHIFT
, XK_x
, KF_WIND_KILL
, NULL
);
7535 setkeybinding(MODKEY
, XK_1
, KF_WS_1
, NULL
);
7536 setkeybinding(MODKEY
, XK_2
, KF_WS_2
, NULL
);
7537 setkeybinding(MODKEY
, XK_3
, KF_WS_3
, NULL
);
7538 setkeybinding(MODKEY
, XK_4
, KF_WS_4
, NULL
);
7539 setkeybinding(MODKEY
, XK_5
, KF_WS_5
, NULL
);
7540 setkeybinding(MODKEY
, XK_6
, KF_WS_6
, NULL
);
7541 setkeybinding(MODKEY
, XK_7
, KF_WS_7
, NULL
);
7542 setkeybinding(MODKEY
, XK_8
, KF_WS_8
, NULL
);
7543 setkeybinding(MODKEY
, XK_9
, KF_WS_9
, NULL
);
7544 setkeybinding(MODKEY
, XK_0
, KF_WS_10
, NULL
);
7545 setkeybinding(MODKEY
, XK_F1
, KF_WS_11
, NULL
);
7546 setkeybinding(MODKEY
, XK_F2
, KF_WS_12
, NULL
);
7547 setkeybinding(MODKEY
, XK_F3
, KF_WS_13
, NULL
);
7548 setkeybinding(MODKEY
, XK_F4
, KF_WS_14
, NULL
);
7549 setkeybinding(MODKEY
, XK_F5
, KF_WS_15
, NULL
);
7550 setkeybinding(MODKEY
, XK_F6
, KF_WS_16
, NULL
);
7551 setkeybinding(MODKEY
, XK_F7
, KF_WS_17
, NULL
);
7552 setkeybinding(MODKEY
, XK_F8
, KF_WS_18
, NULL
);
7553 setkeybinding(MODKEY
, XK_F9
, KF_WS_19
, NULL
);
7554 setkeybinding(MODKEY
, XK_F10
, KF_WS_20
, NULL
);
7555 setkeybinding(MODKEY
, XK_F11
, KF_WS_21
, NULL
);
7556 setkeybinding(MODKEY
, XK_F12
, KF_WS_22
, NULL
);
7557 setkeybinding(MODKEY
, XK_Right
, KF_WS_NEXT
, NULL
);
7558 setkeybinding(MODKEY
, XK_Left
, KF_WS_PREV
, NULL
);
7559 setkeybinding(MODKEY
, XK_Up
, KF_WS_NEXT_ALL
, NULL
);
7560 setkeybinding(MODKEY
, XK_Down
, KF_WS_PREV_ALL
, NULL
);
7561 setkeybinding(MODKEY_SHIFT
, XK_Up
, KF_WS_NEXT_MOVE
,NULL
);
7562 setkeybinding(MODKEY_SHIFT
, XK_Down
, KF_WS_PREV_MOVE
,NULL
);
7563 setkeybinding(MODKEY
, XK_a
, KF_WS_PRIOR
, NULL
);
7565 setkeybinding(MODKEY_SHIFT
, XK_d
, KF_DUMPWINS
, NULL
);
7575 while (RB_EMPTY(&keys
) == 0) {
7576 kp
= RB_ROOT(&keys
);
7582 setkeymapping(const char *selector
, const char *value
, int flags
)
7584 char *keymapping_file
;
7586 /* suppress unused warnings since vars are needed */
7590 DNPRINTF(SWM_D_KEY
, "setkeymapping: enter\n");
7592 keymapping_file
= expand_tilde(value
);
7595 /* load new key bindings; if it fails, revert to default bindings */
7596 if (conf_load(keymapping_file
, SWM_CONF_KEYMAPPING
)) {
7601 free(keymapping_file
);
7603 DNPRINTF(SWM_D_KEY
, "setkeymapping: leave\n");
7608 updatenumlockmask(void)
7611 xcb_get_modifier_mapping_reply_t
*modmap_r
;
7612 xcb_keycode_t
*modmap
, kc
, *keycode
;
7616 modmap_r
= xcb_get_modifier_mapping_reply(conn
,
7617 xcb_get_modifier_mapping(conn
),
7620 modmap
= xcb_get_modifier_mapping_keycodes(modmap_r
);
7621 for (i
= 0; i
< 8; i
++) {
7622 for (j
= 0; j
< modmap_r
->keycodes_per_modifier
; j
++) {
7623 kc
= modmap
[i
* modmap_r
->keycodes_per_modifier
7625 keycode
= xcb_key_symbols_get_keycode(syms
,
7629 numlockmask
= (1 << i
);
7636 DNPRINTF(SWM_D_MISC
, "updatenumlockmask: %d\n", numlockmask
);
7643 int num_screens
, k
, j
;
7644 unsigned int modifiers
[4];
7645 xcb_keycode_t
*code
;
7647 DNPRINTF(SWM_D_MISC
, "grabkeys\n");
7648 updatenumlockmask();
7651 modifiers
[1] = numlockmask
;
7652 modifiers
[2] = XCB_MOD_MASK_LOCK
;
7653 modifiers
[3] = numlockmask
| XCB_MOD_MASK_LOCK
;
7655 num_screens
= get_screen_count();
7656 for (k
= 0; k
< num_screens
; k
++) {
7657 if (TAILQ_EMPTY(&screens
[k
].rl
))
7659 xcb_ungrab_key(conn
, XCB_GRAB_ANY
, screens
[k
].root
,
7661 RB_FOREACH(kp
, key_tree
, &keys
) {
7662 /* Skip unused ws binds. */
7663 if ((int)kp
->funcid
> KF_WS_1
+ workspace_limit
- 1 &&
7664 kp
->funcid
<= KF_WS_22
)
7667 /* Skip unused mvws binds. */
7668 if ((int)kp
->funcid
> KF_MVWS_1
+ workspace_limit
- 1 &&
7669 kp
->funcid
<= KF_MVWS_22
)
7672 if ((code
= xcb_key_symbols_get_keycode(syms
,
7674 for (j
= 0; j
< LENGTH(modifiers
); j
++)
7675 xcb_grab_key(conn
, 1,
7677 kp
->mod
| modifiers
[j
],
7678 *code
, XCB_GRAB_MODE_SYNC
,
7679 XCB_GRAB_MODE_SYNC
);
7687 grabbuttons(struct ws_win
*win
)
7689 unsigned int modifiers
[4];
7692 DNPRINTF(SWM_D_MOUSE
, "grabbuttons: win %#x\n", win
->id
);
7693 updatenumlockmask();
7696 modifiers
[1] = numlockmask
;
7697 modifiers
[2] = XCB_MOD_MASK_LOCK
;
7698 modifiers
[3] = numlockmask
| XCB_MOD_MASK_LOCK
;
7700 for (i
= 0; i
< LENGTH(buttons
); i
++)
7701 if (buttons
[i
].action
== client_click
)
7702 for (j
= 0; j
< LENGTH(modifiers
); ++j
)
7703 xcb_grab_button(conn
, 0, win
->id
, BUTTONMASK
,
7704 XCB_GRAB_MODE_SYNC
, XCB_GRAB_MODE_ASYNC
,
7705 XCB_WINDOW_NONE
, XCB_CURSOR_NONE
,
7706 buttons
[i
].button
, buttons
[i
].mask
|
7710 const char *quirkname
[] = {
7711 "NONE", /* config string for "no value" */
7719 "FOCUSONMAP_SINGLE",
7726 /* SWM_Q_DELIM: retain '|' for back compat for now (2009-08-11) */
7727 #define SWM_Q_DELIM "\n|+ \t"
7729 parsequirks(const char *qstr
, uint32_t *quirk
, int *ws
)
7731 char *str
, *cp
, *name
;
7734 if (quirk
== NULL
|| qstr
== NULL
)
7737 if ((str
= strdup(qstr
)) == NULL
)
7738 err(1, "parsequirks: strdup");
7742 while ((name
= strsep(&cp
, SWM_Q_DELIM
)) != NULL
) {
7744 cp
+= (long)strspn(cp
, SWM_Q_DELIM
);
7746 if (sscanf(name
, "WS[%d]", ws
) == 1) {
7752 for (i
= 0; i
< LENGTH(quirkname
); i
++) {
7753 if (strncasecmp(name
, quirkname
[i
],
7754 SWM_QUIRK_LEN
) == 0) {
7755 DNPRINTF(SWM_D_QUIRK
,
7756 "parsequirks: %s\n", name
);
7762 *quirk
|= 1 << (i
-1);
7766 if (i
>= LENGTH(quirkname
)) {
7767 DNPRINTF(SWM_D_QUIRK
,
7768 "parsequirks: invalid quirk [%s]\n", name
);
7779 quirk_insert(const char *class, const char *instance
, const char *name
,
7780 uint32_t quirk
, int ws
)
7784 bool failed
= false;
7786 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: class: %s, instance: %s, name: %s,"
7787 " value: %u, ws: %d\n", class, instance
, name
, quirk
, ws
);
7789 if ((qp
= malloc(sizeof *qp
)) == NULL
)
7790 err(1, "quirk_insert: malloc");
7792 if ((qp
->class = strdup(class)) == NULL
)
7793 err(1, "quirk_insert: strdup");
7794 if ((qp
->instance
= strdup(instance
)) == NULL
)
7795 err(1, "quirk_insert: strdup");
7796 if ((qp
->name
= strdup(name
)) == NULL
)
7797 err(1, "quirk_insert: strdup");
7799 if (asprintf(&str
, "^%s$", class) == -1)
7800 err(1, "quirk_insert: asprintf");
7801 if (regcomp(&qp
->regex_class
, str
, REG_EXTENDED
| REG_NOSUB
)) {
7802 add_startup_exception("regex failed to compile quirk 'class' "
7803 "field: %s", class);
7806 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: compiled: %s\n", str
);
7809 if (asprintf(&str
, "^%s$", instance
) == -1)
7810 err(1, "quirk_insert: asprintf");
7811 if (regcomp(&qp
->regex_instance
, str
, REG_EXTENDED
| REG_NOSUB
)) {
7812 add_startup_exception("regex failed to compile quirk 'instance'"
7813 " field: %s", instance
);
7816 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: compiled: %s\n", str
);
7819 if (asprintf(&str
, "^%s$", name
) == -1)
7820 err(1, "quirk_insert: asprintf");
7821 if (regcomp(&qp
->regex_name
, str
, REG_EXTENDED
| REG_NOSUB
)) {
7822 add_startup_exception("regex failed to compile quirk 'name' "
7826 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: compiled: %s\n", str
);
7830 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: regex error; skipping.\n");
7835 TAILQ_INSERT_TAIL(&quirks
, qp
, entry
);
7837 DNPRINTF(SWM_D_QUIRK
, "quirk_insert: leave\n");
7841 quirk_remove(struct quirk
*qp
)
7843 DNPRINTF(SWM_D_QUIRK
, "quirk_remove: %s:%s [%u]\n", qp
->class,
7844 qp
->name
, qp
->quirk
);
7846 TAILQ_REMOVE(&quirks
, qp
, entry
);
7849 DNPRINTF(SWM_D_QUIRK
, "quirk_remove: leave\n");
7853 quirk_free(struct quirk
*qp
)
7855 regfree(&qp
->regex_class
);
7856 regfree(&qp
->regex_instance
);
7857 regfree(&qp
->regex_name
);
7865 quirk_replace(struct quirk
*qp
, const char *class, const char *instance
,
7866 const char *name
, uint32_t quirk
, int ws
)
7868 DNPRINTF(SWM_D_QUIRK
, "quirk_replace: %s:%s:%s [%u], ws: %d\n", qp
->class,
7869 qp
->instance
, qp
->name
, qp
->quirk
, qp
->ws
);
7872 quirk_insert(class, instance
, name
, quirk
, ws
);
7874 DNPRINTF(SWM_D_QUIRK
, "quirk_replace: leave\n");
7878 setquirk(const char *class, const char *instance
, const char *name
,
7879 uint32_t quirk
, int ws
)
7883 DNPRINTF(SWM_D_QUIRK
, "setquirk: enter %s:%s:%s [%u], ws: %d\n", class,
7884 instance
, name
, quirk
, ws
);
7886 /* Remove/replace existing quirk. */
7887 TAILQ_FOREACH(qp
, &quirks
, entry
) {
7888 if (strcmp(qp
->class, class) == 0 &&
7889 strcmp(qp
->instance
, instance
) == 0 &&
7890 strcmp(qp
->name
, name
) == 0) {
7891 if (quirk
== 0 && ws
== -1)
7894 quirk_replace(qp
, class, instance
, name
, quirk
,
7896 DNPRINTF(SWM_D_QUIRK
, "setquirk: leave\n");
7901 /* Only insert if quirk is not NONE or forced ws is set. */
7902 if (quirk
|| ws
!= -1)
7903 quirk_insert(class, instance
, name
, quirk
, ws
);
7905 DNPRINTF(SWM_D_QUIRK
, "setquirk: leave\n");
7908 /* Eat '\' in str used to escape square brackets and colon. */
7910 unescape_selector(char *str
)
7914 for (cp
= str
; *str
!= '\0'; ++str
, ++cp
) {
7915 if (*str
== '\\' && (*(str
+ 1) == ':' || *(str
+ 1) == ']' ||
7925 setconfquirk(const char *selector
, const char *value
, int flags
)
7927 char *str
, *cp
, *class;
7928 char *instance
= NULL
, *name
= NULL
;
7929 int retval
, count
= 0, ws
= -1;
7932 /* suppress unused warning since var is needed */
7935 if (selector
== NULL
|| strlen(selector
) == 0)
7938 if ((str
= strdup(selector
)) == NULL
)
7939 err(1, "setconfquirk: strdup");
7941 /* Find non-escaped colon. */
7948 for (++cp
; *cp
!= '\0'; ++cp
) {
7949 if (*cp
== ':' && *(cp
- 1) != '\\') {
7955 unescape_selector(class);
7957 instance
= class + strlen(class) + 1;
7958 unescape_selector(instance
);
7964 name
= instance
+ strlen(instance
) + 1;
7965 unescape_selector(name
);
7970 DNPRINTF(SWM_D_CONF
, "setconfquirk: class: %s, instance: %s, "
7971 "name: %s\n", class, instance
, name
);
7973 if ((retval
= parsequirks(value
, &qrks
, &ws
)) == 0)
7974 setquirk(class, instance
, name
, qrks
, ws
);
7983 setquirk("MPlayer", "xv", ".*",
7984 SWM_Q_FLOAT
| SWM_Q_FULLSCREEN
| SWM_Q_FOCUSPREV
, -1);
7985 setquirk("OpenOffice.org 3.2", "VCLSalFrame", ".*",
7987 setquirk("Firefox-bin", "firefox-bin", ".*",
7989 setquirk("Firefox", "Dialog", ".*",
7991 setquirk("Gimp", "gimp", ".*",
7992 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
7993 setquirk("XTerm", "xterm", ".*",
7994 SWM_Q_XTERM_FONTADJ
, -1);
7995 setquirk("xine", "Xine Window", ".*",
7996 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
7997 setquirk("Xitk", "Xitk Combo", ".*",
7998 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
7999 setquirk("xine", "xine Panel", ".*",
8000 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
8001 setquirk("Xitk", "Xine Window", ".*",
8002 SWM_Q_FLOAT
| SWM_Q_ANYWHERE
, -1);
8003 setquirk("xine", "xine Video Fullscreen Window", ".*",
8004 SWM_Q_FULLSCREEN
| SWM_Q_FLOAT
, -1);
8005 setquirk("pcb", "pcb", ".*",
8007 setquirk("SDL_App", "SDL_App", ".*",
8008 SWM_Q_FLOAT
| SWM_Q_FULLSCREEN
, -1);
8011 /* conf file stuff */
8012 #define SWM_CONF_FILE "spectrwm.conf"
8013 #define SWM_CONF_FILE_OLD "scrotwm.conf"
8017 SWM_S_BAR_AT_BOTTOM
,
8018 SWM_S_BAR_BORDER_WIDTH
,
8021 SWM_S_BAR_ENABLED_WS
,
8026 SWM_S_BOUNDARY_WIDTH
,
8027 SWM_S_CLOCK_ENABLED
,
8030 SWM_S_CYCLE_VISIBLE
,
8032 SWM_S_DISABLE_BORDER
,
8034 SWM_S_FOCUS_CLOSE_WRAP
,
8035 SWM_S_FOCUS_DEFAULT
,
8037 SWM_S_ICONIC_ENABLED
,
8038 SWM_S_JAVA_WORKAROUND
,
8039 SWM_S_REGION_PADDING
,
8044 SWM_S_STACK_ENABLED
,
8047 SWM_S_URGENT_COLLAPSE
,
8048 SWM_S_URGENT_ENABLED
,
8049 SWM_S_VERBOSE_LAYOUT
,
8051 SWM_S_WINDOW_CLASS_ENABLED
,
8052 SWM_S_WINDOW_INSTANCE_ENABLED
,
8053 SWM_S_WINDOW_NAME_ENABLED
,
8054 SWM_S_WORKSPACE_LIMIT
,
8055 SWM_S_WORKSPACE_NAME
,
8059 setconfvalue(const char *selector
, const char *value
, int flags
)
8061 struct workspace
*ws
;
8062 int i
, ws_id
, num_screens
;
8063 char *b
, *str
, s
[1024];
8066 case SWM_S_BAR_ACTION
:
8068 if ((bar_argv
[0] = expand_tilde(value
)) == NULL
)
8069 err(1, "setconfvalue: bar_action");
8071 case SWM_S_BAR_AT_BOTTOM
:
8072 bar_at_bottom
= (atoi(value
) != 0);
8074 case SWM_S_BAR_BORDER_WIDTH
:
8075 bar_border_width
= atoi(value
);
8076 if (bar_border_width
< 0)
8077 bar_border_width
= 0;
8079 case SWM_S_BAR_DELAY
:
8080 /* No longer needed; leave to not break old conf files. */
8082 case SWM_S_BAR_ENABLED
:
8083 bar_enabled
= (atoi(value
) != 0);
8085 case SWM_S_BAR_ENABLED_WS
:
8086 ws_id
= atoi(selector
) - 1;
8087 if (ws_id
< 0 || ws_id
>= workspace_limit
)
8088 errx(1, "setconfvalue: bar_enabled_ws: invalid "
8089 "workspace %d.", ws_id
+ 1);
8091 num_screens
= get_screen_count();
8092 for (i
= 0; i
< num_screens
; i
++) {
8093 ws
= (struct workspace
*)&screens
[i
].ws
;
8094 ws
[ws_id
].bar_enabled
= (atoi(value
) != 0);
8097 case SWM_S_BAR_FONT
:
8099 if (asprintf(&bar_fonts
, "%s,%s", value
, bar_fonts
) == -1)
8100 err(1, "setconfvalue: asprintf: failed to allocate "
8101 "memory for bar_fonts.");
8104 /* If already in xft mode, then we are done. */
8105 if (!bar_font_legacy
)
8108 if ((str
= strdup(value
)) == NULL
)
8109 err(1, "setconfvalue: strdup");
8111 /* If there are any non-XLFD entries, switch to Xft mode. */
8112 while ((b
= strsep(&str
, ",")) != NULL
) {
8116 bar_font_legacy
= false;
8123 case SWM_S_BAR_FORMAT
:
8125 if ((bar_format
= strdup(value
)) == NULL
)
8126 err(1, "setconfvalue: bar_format");
8128 case SWM_S_BAR_JUSTIFY
:
8129 if (strcmp(value
, "left") == 0)
8130 bar_justify
= SWM_BAR_JUSTIFY_LEFT
;
8131 else if (strcmp(value
, "center") == 0)
8132 bar_justify
= SWM_BAR_JUSTIFY_CENTER
;
8133 else if (strcmp(value
, "right") == 0)
8134 bar_justify
= SWM_BAR_JUSTIFY_RIGHT
;
8136 errx(1, "invalid bar_justify");
8138 case SWM_S_BORDER_WIDTH
:
8139 border_width
= atoi(value
);
8140 if (border_width
< 0)
8143 case SWM_S_BOUNDARY_WIDTH
:
8144 boundary_width
= atoi(value
);
8145 if (boundary_width
< 0)
8148 case SWM_S_CLOCK_ENABLED
:
8149 clock_enabled
= (atoi(value
) != 0);
8151 case SWM_S_CLOCK_FORMAT
:
8152 #ifndef SWM_DENY_CLOCK_FORMAT
8154 if ((clock_format
= strdup(value
)) == NULL
)
8155 err(1, "setconfvalue: clock_format");
8158 case SWM_S_CYCLE_EMPTY
:
8159 cycle_empty
= (atoi(value
) != 0);
8161 case SWM_S_CYCLE_VISIBLE
:
8162 cycle_visible
= (atoi(value
) != 0);
8164 case SWM_S_DIALOG_RATIO
:
8165 dialog_ratio
= atof(value
);
8166 if (dialog_ratio
> 1.0 || dialog_ratio
<= .3)
8169 case SWM_S_DISABLE_BORDER
:
8170 disable_border
= (atoi(value
) != 0);
8172 case SWM_S_FOCUS_CLOSE
:
8173 if (strcmp(value
, "first") == 0)
8174 focus_close
= SWM_STACK_BOTTOM
;
8175 else if (strcmp(value
, "last") == 0)
8176 focus_close
= SWM_STACK_TOP
;
8177 else if (strcmp(value
, "next") == 0)
8178 focus_close
= SWM_STACK_ABOVE
;
8179 else if (strcmp(value
, "previous") == 0)
8180 focus_close
= SWM_STACK_BELOW
;
8182 errx(1, "focus_close");
8184 case SWM_S_FOCUS_CLOSE_WRAP
:
8185 focus_close_wrap
= (atoi(value
) != 0);
8187 case SWM_S_FOCUS_DEFAULT
:
8188 if (strcmp(value
, "last") == 0)
8189 focus_default
= SWM_STACK_TOP
;
8190 else if (strcmp(value
, "first") == 0)
8191 focus_default
= SWM_STACK_BOTTOM
;
8193 errx(1, "focus_default");
8195 case SWM_S_FOCUS_MODE
:
8196 if (strcmp(value
, "default") == 0)
8197 focus_mode
= SWM_FOCUS_DEFAULT
;
8198 else if (strcmp(value
, "follow") == 0 ||
8199 strcmp(value
, "follow_cursor") == 0)
8200 focus_mode
= SWM_FOCUS_FOLLOW
;
8201 else if (strcmp(value
, "manual") == 0)
8202 focus_mode
= SWM_FOCUS_MANUAL
;
8204 errx(1, "focus_mode");
8206 case SWM_S_ICONIC_ENABLED
:
8207 iconic_enabled
= (atoi(value
) != 0);
8209 case SWM_S_JAVA_WORKAROUND
:
8210 java_workaround
= (atoi(value
) != 0);
8212 case SWM_S_REGION_PADDING
:
8213 region_padding
= atoi(value
);
8214 if (region_padding
< 0)
8217 case SWM_S_SPAWN_ORDER
:
8218 if (strcmp(value
, "first") == 0)
8219 spawn_position
= SWM_STACK_BOTTOM
;
8220 else if (strcmp(value
, "last") == 0)
8221 spawn_position
= SWM_STACK_TOP
;
8222 else if (strcmp(value
, "next") == 0)
8223 spawn_position
= SWM_STACK_ABOVE
;
8224 else if (strcmp(value
, "previous") == 0)
8225 spawn_position
= SWM_STACK_BELOW
;
8227 errx(1, "spawn_position");
8229 case SWM_S_SPAWN_TERM
:
8230 setconfspawn("term", value
, 0);
8231 setconfspawn("spawn_term", value
, 0);
8234 /* No longer needed; leave to not break old conf files. */
8236 case SWM_S_SS_ENABLED
:
8237 /* No longer needed; leave to not break old conf files. */
8239 case SWM_S_STACK_ENABLED
:
8240 stack_enabled
= (atoi(value
) != 0);
8242 case SWM_S_TERM_WIDTH
:
8243 term_width
= atoi(value
);
8247 case SWM_S_TILE_GAP
:
8248 tile_gap
= atoi(value
);
8250 case SWM_S_URGENT_COLLAPSE
:
8251 urgent_collapse
= (atoi(value
) != 0);
8253 case SWM_S_URGENT_ENABLED
:
8254 urgent_enabled
= (atoi(value
) != 0);
8256 case SWM_S_VERBOSE_LAYOUT
:
8257 verbose_layout
= (atoi(value
) != 0);
8258 for (i
= 0; layouts
[i
].l_stack
!= NULL
; i
++) {
8260 layouts
[i
].l_string
= fancy_stacker
;
8262 layouts
[i
].l_string
= plain_stacker
;
8265 case SWM_S_WARP_POINTER
:
8266 warp_pointer
= (atoi(value
) != 0);
8268 case SWM_S_WINDOW_CLASS_ENABLED
:
8269 window_class_enabled
= (atoi(value
) != 0);
8271 case SWM_S_WINDOW_INSTANCE_ENABLED
:
8272 window_instance_enabled
= (atoi(value
) != 0);
8274 case SWM_S_WINDOW_NAME_ENABLED
:
8275 window_name_enabled
= (atoi(value
) != 0);
8277 case SWM_S_WORKSPACE_LIMIT
:
8278 workspace_limit
= atoi(value
);
8279 if (workspace_limit
> SWM_WS_MAX
)
8280 workspace_limit
= SWM_WS_MAX
;
8281 else if (workspace_limit
< 1)
8282 workspace_limit
= 1;
8284 ewmh_update_desktops();
8286 case SWM_S_WORKSPACE_NAME
:
8287 if (getenv("SWM_STARTED") != NULL
)
8291 if (sscanf(value
, "ws[%d]:%1023c", &ws_id
, s
) != 2)
8292 errx(1, "invalid entry, should be 'ws[<idx>]:name'");
8294 if (ws_id
< 0 || ws_id
>= workspace_limit
)
8295 errx(1, "setconfvalue: workspace_name: invalid "
8296 "workspace %d.", ws_id
+ 1);
8298 num_screens
= get_screen_count();
8299 for (i
= 0; i
< num_screens
; ++i
) {
8300 ws
= (struct workspace
*)&screens
[i
].ws
;
8302 if (strlen(s
) > 0) {
8303 free(ws
[ws_id
].name
);
8304 if ((ws
[ws_id
].name
= strdup(s
)) == NULL
)
8305 err(1, "setconfvalue: workspace_name.");
8307 ewmh_update_desktop_names();
8308 ewmh_get_desktop_names();
8319 setconfmodkey(const char *selector
, const char *value
, int flags
)
8321 /* suppress unused warnings since vars are needed */
8325 if (strncasecmp(value
, "Mod1", strlen("Mod1")) == 0)
8326 update_modkey(XCB_MOD_MASK_1
);
8327 else if (strncasecmp(value
, "Mod2", strlen("Mod2")) == 0)
8328 update_modkey(XCB_MOD_MASK_2
);
8329 else if (strncasecmp(value
, "Mod3", strlen("Mod3")) == 0)
8330 update_modkey(XCB_MOD_MASK_3
);
8331 else if (strncasecmp(value
, "Mod4", strlen("Mod4")) == 0)
8332 update_modkey(XCB_MOD_MASK_4
);
8333 else if (strncasecmp(value
, "Mod5", strlen("Mod5")) == 0)
8334 update_modkey(XCB_MOD_MASK_5
);
8341 setconfmousebuttonmove(const char *selector
, const char *value
, int flags
)
8343 /* suppress unused warnings since vars are needed */
8347 if (strncasecmp(value
, "But1", strlen("But1")) == 0) {
8348 if (!update_mousebutton(0, XCB_BUTTON_INDEX_1
))
8350 } else if (strncasecmp(value
, "But2", strlen("But2")) == 0) {
8351 if (!update_mousebutton(0, XCB_BUTTON_INDEX_2
))
8353 } else if (strncasecmp(value
, "But3", strlen("But3")) == 0) {
8354 if (!update_mousebutton(0, XCB_BUTTON_INDEX_3
))
8362 setconfmousebuttonresize(const char *selector
, const char *value
, int flags
)
8364 /* suppress unused warnings since vars are needed */
8368 if (strncasecmp(value
, "But1", strlen("But1")) == 0) {
8369 if (!update_mousebutton(1, XCB_BUTTON_INDEX_1
))
8371 } else if (strncasecmp(value
, "But2", strlen("But2")) == 0) {
8372 if (!update_mousebutton(1, XCB_BUTTON_INDEX_2
))
8374 } else if (strncasecmp(value
, "But3", strlen("But3")) == 0) {
8375 if (!update_mousebutton(1, XCB_BUTTON_INDEX_3
))
8383 setconfcolor(const char *selector
, const char *value
, int flags
)
8385 int first
, last
, i
= 0, num_screens
;
8387 num_screens
= get_screen_count();
8389 /* conf screen indices begin at 1; treat vals <= 0 as 'all screens.' */
8390 if (selector
== NULL
|| strlen(selector
) == 0 ||
8391 (last
= atoi(selector
) - 1) < 0) {
8393 last
= num_screens
- 1;
8398 if (last
>= num_screens
) {
8399 add_startup_exception("invalid screen index: %d out of bounds "
8400 "(maximum %d)", last
+ 1, num_screens
);
8404 for (i
= first
; i
<= last
; ++i
) {
8405 setscreencolor(value
, i
, flags
);
8408 * When setting focus/unfocus colors, we need to also
8409 * set maximize colors to match if they haven't been customized.
8411 if (flags
== SWM_S_COLOR_FOCUS
&&
8412 !screens
[i
].c
[SWM_S_COLOR_FOCUS_MAXIMIZED
].manual
)
8413 setscreencolor(value
, i
, SWM_S_COLOR_FOCUS_MAXIMIZED
);
8414 else if (flags
== SWM_S_COLOR_UNFOCUS
&&
8415 !screens
[i
].c
[SWM_S_COLOR_UNFOCUS_MAXIMIZED
].manual
)
8416 setscreencolor(value
, i
, SWM_S_COLOR_UNFOCUS_MAXIMIZED
);
8418 screens
[i
].c
[flags
].manual
= 1;
8425 setconfregion(const char *selector
, const char *value
, int flags
)
8427 /* suppress unused warnings since vars are needed */
8431 custom_region(value
);
8436 setautorun(const char *selector
, const char *value
, int flags
)
8446 /* suppress unused warnings since vars are needed */
8450 if (getenv("SWM_STARTED"))
8454 if (sscanf(value
, "ws[%d]:%1023c", &ws_id
, s
) != 2)
8455 errx(1, "invalid autorun entry, should be 'ws[<idx>]:command'");
8457 if (ws_id
< 0 || ws_id
>= workspace_limit
)
8458 errx(1, "autorun: invalid workspace %d", ws_id
+ 1);
8460 sp
= expand_tilde((char *)&s
);
8463 * This is a little intricate
8465 * If the pid already exists we simply reuse it because it means it was
8466 * used before AND not claimed by manage_window. We get away with
8467 * altering it in the parent after INSERT because this can not be a race
8470 while ((ap
= strsep(&sp
, " \t")) != NULL
) {
8473 DNPRINTF(SWM_D_SPAWN
, "setautorun: arg [%s]\n", ap
);
8475 if ((a
.argv
= realloc(a
.argv
, argc
* sizeof(char *))) == NULL
)
8476 err(1, "setautorun: realloc");
8477 a
.argv
[argc
- 1] = ap
;
8481 if ((a
.argv
= realloc(a
.argv
, (argc
+ 1) * sizeof(char *))) == NULL
)
8482 err(1, "setautorun: realloc");
8483 a
.argv
[argc
] = NULL
;
8485 if ((pid
= fork()) == 0) {
8486 spawn(ws_id
, &a
, true);
8495 p
= calloc(1, sizeof *p
);
8498 TAILQ_INSERT_TAIL(&pidlist
, p
, entry
);
8508 setlayout(const char *selector
, const char *value
, int flags
)
8510 struct workspace
*ws
;
8511 int ws_id
, i
, x
, mg
, ma
, si
, ar
;
8512 int st
= SWM_V_STACK
, num_screens
;
8516 /* suppress unused warnings since vars are needed */
8520 if (getenv("SWM_STARTED"))
8524 if (sscanf(value
, "ws[%d]:%d:%d:%d:%d:%1023c",
8525 &ws_id
, &mg
, &ma
, &si
, &ar
, s
) != 6)
8526 errx(1, "invalid layout entry, should be 'ws[<idx>]:"
8527 "<master_grow>:<master_add>:<stack_inc>:<always_raise>:"
8530 if (ws_id
< 0 || ws_id
>= workspace_limit
)
8531 errx(1, "layout: invalid workspace %d", ws_id
+ 1);
8533 if (strcasecmp(s
, "vertical") == 0)
8535 else if (strcasecmp(s
, "vertical_flip") == 0) {
8538 } else if (strcasecmp(s
, "horizontal") == 0)
8540 else if (strcasecmp(s
, "horizontal_flip") == 0) {
8543 } else if (strcasecmp(s
, "fullscreen") == 0)
8546 errx(1, "invalid layout entry, should be 'ws[<idx>]:"
8547 "<master_grow>:<master_add>:<stack_inc>:<always_raise>:"
8550 num_screens
= get_screen_count();
8551 for (i
= 0; i
< num_screens
; i
++) {
8552 ws
= (struct workspace
*)&screens
[i
].ws
;
8553 ws
[ws_id
].cur_layout
= &layouts
[st
];
8555 ws
[ws_id
].always_raise
= (ar
!= 0);
8556 if (st
== SWM_MAX_STACK
)
8560 for (x
= 0; x
< abs(mg
); x
++) {
8561 ws
[ws_id
].cur_layout
->l_config(&ws
[ws_id
],
8562 mg
>= 0 ? SWM_ARG_ID_MASTERGROW
:
8563 SWM_ARG_ID_MASTERSHRINK
);
8566 for (x
= 0; x
< abs(ma
); x
++) {
8567 ws
[ws_id
].cur_layout
->l_config(&ws
[ws_id
],
8568 ma
>= 0 ? SWM_ARG_ID_MASTERADD
:
8569 SWM_ARG_ID_MASTERDEL
);
8572 for (x
= 0; x
< abs(si
); x
++) {
8573 ws
[ws_id
].cur_layout
->l_config(&ws
[ws_id
],
8574 si
>= 0 ? SWM_ARG_ID_STACKINC
:
8575 SWM_ARG_ID_STACKDEC
);
8579 ws
[ws_id
].cur_layout
->l_config(&ws
[ws_id
],
8580 SWM_ARG_ID_FLIPLAYOUT
);
8587 /* config options */
8588 struct config_option
{
8590 int (*func
)(const char*, const char*, int);
8593 struct config_option configopt
[] = {
8594 { "autorun", setautorun
, 0 },
8595 { "bar_action", setconfvalue
, SWM_S_BAR_ACTION
},
8596 { "bar_at_bottom", setconfvalue
, SWM_S_BAR_AT_BOTTOM
},
8597 { "bar_border", setconfcolor
, SWM_S_COLOR_BAR_BORDER
},
8598 { "bar_border_unfocus", setconfcolor
, SWM_S_COLOR_BAR_BORDER_UNFOCUS
},
8599 { "bar_border_width", setconfvalue
, SWM_S_BAR_BORDER_WIDTH
},
8600 { "bar_color", setconfcolor
, SWM_S_COLOR_BAR
},
8601 { "bar_delay", setconfvalue
, SWM_S_BAR_DELAY
},
8602 { "bar_enabled", setconfvalue
, SWM_S_BAR_ENABLED
},
8603 { "bar_enabled_ws", setconfvalue
, SWM_S_BAR_ENABLED_WS
},
8604 { "bar_font", setconfvalue
, SWM_S_BAR_FONT
},
8605 { "bar_font_color", setconfcolor
, SWM_S_COLOR_BAR_FONT
},
8606 { "bar_format", setconfvalue
, SWM_S_BAR_FORMAT
},
8607 { "bar_justify", setconfvalue
, SWM_S_BAR_JUSTIFY
},
8608 { "bind", setconfbinding
, 0 },
8609 { "border_width", setconfvalue
, SWM_S_BORDER_WIDTH
},
8610 { "boundary_width", setconfvalue
, SWM_S_BOUNDARY_WIDTH
},
8611 { "clock_enabled", setconfvalue
, SWM_S_CLOCK_ENABLED
},
8612 { "clock_format", setconfvalue
, SWM_S_CLOCK_FORMAT
},
8613 { "color_focus", setconfcolor
, SWM_S_COLOR_FOCUS
},
8614 { "color_focus_maximized", setconfcolor
, SWM_S_COLOR_FOCUS_MAXIMIZED
},
8615 { "color_unfocus", setconfcolor
, SWM_S_COLOR_UNFOCUS
},
8616 { "color_unfocus_maximized", setconfcolor
, SWM_S_COLOR_UNFOCUS_MAXIMIZED
},
8617 { "cycle_empty", setconfvalue
, SWM_S_CYCLE_EMPTY
},
8618 { "cycle_visible", setconfvalue
, SWM_S_CYCLE_VISIBLE
},
8619 { "dialog_ratio", setconfvalue
, SWM_S_DIALOG_RATIO
},
8620 { "disable_border", setconfvalue
, SWM_S_DISABLE_BORDER
},
8621 { "focus_close", setconfvalue
, SWM_S_FOCUS_CLOSE
},
8622 { "focus_close_wrap", setconfvalue
, SWM_S_FOCUS_CLOSE_WRAP
},
8623 { "focus_default", setconfvalue
, SWM_S_FOCUS_DEFAULT
},
8624 { "focus_mode", setconfvalue
, SWM_S_FOCUS_MODE
},
8625 { "iconic_enabled", setconfvalue
, SWM_S_ICONIC_ENABLED
},
8626 { "java_workaround", setconfvalue
, SWM_S_JAVA_WORKAROUND
},
8627 { "keyboard_mapping", setkeymapping
, 0 },
8628 { "layout", setlayout
, 0 },
8629 { "modkey", setconfmodkey
, 0 },
8630 { "move_button", setconfmousebuttonmove
, 0 },
8631 { "resize_button", setconfmousebuttonresize
, 0 },
8632 { "program", setconfspawn
, 0 },
8633 { "quirk", setconfquirk
, 0 },
8634 { "region", setconfregion
, 0 },
8635 { "region_padding", setconfvalue
, SWM_S_REGION_PADDING
},
8636 { "screenshot_app", setconfvalue
, SWM_S_SS_APP
},
8637 { "screenshot_enabled", setconfvalue
, SWM_S_SS_ENABLED
},
8638 { "spawn_position", setconfvalue
, SWM_S_SPAWN_ORDER
},
8639 { "spawn_term", setconfvalue
, SWM_S_SPAWN_TERM
},
8640 { "stack_enabled", setconfvalue
, SWM_S_STACK_ENABLED
},
8641 { "term_width", setconfvalue
, SWM_S_TERM_WIDTH
},
8642 { "tile_gap", setconfvalue
, SWM_S_TILE_GAP
},
8643 { "title_class_enabled", setconfvalue
, SWM_S_WINDOW_CLASS_ENABLED
}, /* For backwards compat. */
8644 { "title_name_enabled", setconfvalue
, SWM_S_WINDOW_INSTANCE_ENABLED
}, /* For backwards compat. */
8645 { "urgent_collapse", setconfvalue
, SWM_S_URGENT_COLLAPSE
},
8646 { "urgent_enabled", setconfvalue
, SWM_S_URGENT_ENABLED
},
8647 { "verbose_layout", setconfvalue
, SWM_S_VERBOSE_LAYOUT
},
8648 { "warp_pointer", setconfvalue
, SWM_S_WARP_POINTER
},
8649 { "window_class_enabled", setconfvalue
, SWM_S_WINDOW_CLASS_ENABLED
},
8650 { "window_instance_enabled", setconfvalue
, SWM_S_WINDOW_INSTANCE_ENABLED
},
8651 { "window_name_enabled", setconfvalue
, SWM_S_WINDOW_NAME_ENABLED
},
8652 { "workspace_limit", setconfvalue
, SWM_S_WORKSPACE_LIMIT
},
8653 { "name", setconfvalue
, SWM_S_WORKSPACE_NAME
},
8657 _add_startup_exception(const char *fmt
, va_list ap
)
8659 if (vasprintf(&startup_exception
, fmt
, ap
) == -1)
8660 warn("%s: asprintf", __func__
);
8664 add_startup_exception(const char *fmt
, ...)
8670 if (startup_exception
)
8673 /* force bar to be enabled due to exception */
8677 _add_startup_exception(fmt
, ap
);
8682 conf_load(const char *filename
, int keymapping
)
8685 char *line
= NULL
, *cp
, *ce
, *optsub
, *optval
= NULL
;
8686 size_t linelen
, lineno
= 0;
8687 int wordlen
, i
, optidx
, count
;
8688 struct config_option
*opt
= NULL
;
8690 DNPRINTF(SWM_D_CONF
, "conf_load: begin\n");
8692 if (filename
== NULL
) {
8693 warnx("conf_load: no filename");
8697 DNPRINTF(SWM_D_CONF
, "conf_load: open %s\n", filename
);
8699 if ((config
= fopen(filename
, "r")) == NULL
) {
8700 warn("conf_load: fopen: %s", filename
);
8704 while (!feof(config
)) {
8708 if ((line
= fparseln(config
, &linelen
, &lineno
, NULL
,
8709 FPARSELN_UNESCCOMM
| FPARSELN_UNESCCONT
)) == NULL
) {
8711 err(1, "%s", filename
);
8716 cp
+= strspn(cp
, " \t\n"); /* eat whitespace */
8717 if (cp
[0] == '\0') {
8721 /* get config option */
8722 wordlen
= strcspn(cp
, "=[ \t\n");
8724 add_startup_exception("%s: line %zd: no option found",
8729 for (i
= 0; i
< LENGTH(configopt
); i
++) {
8730 opt
= &configopt
[i
];
8731 if (strncasecmp(cp
, opt
->optname
, wordlen
) == 0 &&
8732 (int)strlen(opt
->optname
) == wordlen
) {
8738 add_startup_exception("%s: line %zd: unknown option "
8739 "%.*s", filename
, lineno
, wordlen
, cp
);
8742 if (keymapping
&& opt
&& strcmp(opt
->optname
, "bind")) {
8743 add_startup_exception("%s: line %zd: invalid option "
8744 "%.*s", filename
, lineno
, wordlen
, cp
);
8748 cp
+= strspn(cp
, " \t\n"); /* eat whitespace */
8750 /* get [selector] if any */
8755 /* Get length of selector. */
8756 for (ce
= ++cp
; *ce
!= '\0'; ++ce
) {
8757 /* Find matching (not escaped) bracket. */
8758 if (*ce
== ']' && *(ce
- 1) != '\\') {
8765 add_startup_exception("%s: line %zd: syntax "
8766 "error: unterminated selector", filename
,
8771 /* ce points at ']'; terminate optsub. */
8776 cp
+= strspn(cp
, "= \t\n"); /* eat trailing */
8779 if (strlen(optval
) == 0) {
8780 add_startup_exception("%s: line %zd: must supply value "
8781 "to %s", filename
, lineno
,
8782 configopt
[optidx
].optname
);
8785 /* call function to deal with it all */
8786 if (configopt
[optidx
].func(optsub
, optval
,
8787 configopt
[optidx
].funcflags
) != 0) {
8788 add_startup_exception("%s: line %zd: invalid data for "
8789 "%s", filename
, lineno
, configopt
[optidx
].optname
);
8798 if (mouse_button_move
== mouse_button_resize
) {
8799 add_startup_exception("%s: move and resize mouse buttons match",
8803 DNPRINTF(SWM_D_CONF
, "conf_load: end\n");
8809 set_child_transient(struct ws_win
*win
, xcb_window_t
*trans
)
8811 struct ws_win
*parent
, *w
;
8812 struct swm_region
*r
;
8813 struct workspace
*ws
;
8814 xcb_icccm_wm_hints_t wmh
;
8816 parent
= find_window(win
->transient
);
8818 parent
->focus_child
= win
;
8820 DNPRINTF(SWM_D_MISC
, "set_child_transient: parent doesn't exist"
8821 " for %#x trans %#x\n", win
->id
, win
->transient
);
8823 r
= root_to_region(win
->s
->root
, SWM_CK_ALL
);
8825 /* parent doen't exist in our window list */
8826 TAILQ_FOREACH(w
, &ws
->winlist
, entry
) {
8827 if (xcb_icccm_get_wm_hints_reply(conn
,
8828 xcb_icccm_get_wm_hints(conn
, w
->id
),
8830 warnx("can't get hints for %#x", w
->id
);
8834 if (win
->hints
.window_group
!= wmh
.window_group
)
8837 w
->focus_child
= win
;
8838 win
->transient
= w
->id
;
8840 DNPRINTF(SWM_D_MISC
, "set_child_transient: adjusting "
8841 "transient to %#x\n", win
->transient
);
8848 window_get_pid(xcb_window_t win
)
8853 xcb_get_property_cookie_t pc
;
8854 xcb_get_property_reply_t
*pr
;
8856 apid
= get_atom_from_string("_NET_WM_PID");
8857 if (apid
== XCB_ATOM_NONE
)
8860 pc
= xcb_get_property(conn
, 0, win
, apid
, XCB_ATOM_CARDINAL
, 0, 1);
8861 pr
= xcb_get_property_reply(conn
, pc
, NULL
);
8864 if (pr
->type
!= XCB_ATOM_CARDINAL
) {
8869 if (pr
->type
== apid
&& pr
->format
== 32)
8870 ret
= *((pid_t
*)xcb_get_property_value(pr
));
8876 apid
= get_atom_from_string("_SWM_PID");
8877 pc
= xcb_get_property(conn
, 0, win
, apid
, XCB_ATOM_STRING
,
8879 pr
= xcb_get_property_reply(conn
, pc
, NULL
);
8882 if (pr
->type
!= apid
) {
8887 ret
= (pid_t
)strtonum(xcb_get_property_value(pr
), 0, INT_MAX
, &errstr
);
8894 get_swm_ws(xcb_window_t id
)
8900 xcb_get_property_reply_t
*gpr
;
8902 gpr
= xcb_get_property_reply(conn
,
8903 xcb_get_property(conn
, 0, id
, a_swm_ws
,
8904 XCB_ATOM_STRING
, 0, SWM_PROPLEN
),
8909 proplen
= xcb_get_property_value_length(gpr
);
8911 prop
= malloc(proplen
+ 1);
8914 xcb_get_property_value(gpr
),
8916 prop
[proplen
] = '\0';
8923 DNPRINTF(SWM_D_PROP
, "get_swm_ws: _SWM_WS: %s\n", prop
);
8924 ws_idx
= (int)strtonum(prop
, 0, workspace_limit
- 1, &errstr
);
8926 DNPRINTF(SWM_D_PROP
, "get_swm_ws: win #%s: %s",
8936 get_ws_idx(struct ws_win
*win
)
8938 xcb_get_property_reply_t
*gpr
;
8944 gpr
= xcb_get_property_reply(conn
,
8945 xcb_get_property(conn
, 0, win
->id
, ewmh
[_NET_WM_DESKTOP
].atom
,
8946 XCB_ATOM_CARDINAL
, 0, 1),
8949 if (gpr
->type
== XCB_ATOM_CARDINAL
&& gpr
->format
== 32)
8950 ws_idx
= *((int *)xcb_get_property_value(gpr
));
8954 if (ws_idx
== -1 && !(win
->quirks
& SWM_Q_IGNORESPAWNWS
))
8955 ws_idx
= get_swm_ws(win
->id
);
8957 if (ws_idx
> workspace_limit
- 1 || ws_idx
< -1)
8960 DNPRINTF(SWM_D_PROP
, "get_ws_idx: win %#x, ws_idx: %d\n", win
->id
,
8967 manage_window(xcb_window_t id
, int spawn_pos
, bool mapped
)
8969 struct ws_win
*win
, *ww
;
8970 struct swm_region
*r
;
8973 xcb_get_geometry_reply_t
*gr
;
8974 xcb_window_t trans
= XCB_WINDOW_NONE
;
8975 uint32_t i
, wa
[2], new_flags
;
8976 int ws_idx
, force_ws
= -1;
8977 char *class, *instance
, *name
;
8979 if ((win
= find_window(id
)) != NULL
) {
8980 DNPRINTF(SWM_D_MISC
, "manage_window: win %#x already "
8981 "managed; skipping.)\n", id
);
8982 return (win
); /* Already managed. */
8985 /* See if window is on the unmanaged list. */
8986 if ((win
= find_unmanaged_window(id
)) != NULL
) {
8987 DNPRINTF(SWM_D_MISC
, "manage_window: win %#x found on "
8988 "unmanaged list.\n", id
);
8989 TAILQ_REMOVE(&win
->ws
->unmanagedlist
, win
, entry
);
8992 set_child_transient(win
, &trans
);
8996 DNPRINTF(SWM_D_MISC
, "manage_window: win %#x is new.\n", id
);
8999 /* Try to get initial window geometry. */
9000 gr
= xcb_get_geometry_reply(conn
, xcb_get_geometry(conn
, id
), NULL
);
9002 DNPRINTF(SWM_D_MISC
, "manage_window: get geometry failed.\n");
9006 /* Create and initialize ws_win object. */
9007 if ((win
= calloc(1, sizeof(struct ws_win
))) == NULL
)
9008 err(1, "manage_window: calloc: failed to allocate memory for "
9013 /* Figureout which region the window belongs to. */
9014 r
= root_to_region(gr
->root
, SWM_CK_ALL
);
9016 /* Ignore window border if there is one. */
9017 WIDTH(win
) = gr
->width
;
9018 HEIGHT(win
) = gr
->height
;
9019 X(win
) = gr
->x
+ gr
->border_width
- border_width
;
9020 Y(win
) = gr
->y
+ gr
->border_width
- border_width
;
9021 win
->bordered
= true;
9022 win
->mapped
= mapped
;
9023 win
->s
= r
->s
; /* this never changes */
9027 /* Select which X events to monitor and set border pixel color. */
9028 wa
[0] = win
->s
->c
[SWM_S_COLOR_UNFOCUS
].pixel
;
9029 wa
[1] = XCB_EVENT_MASK_ENTER_WINDOW
| XCB_EVENT_MASK_PROPERTY_CHANGE
|
9030 XCB_EVENT_MASK_STRUCTURE_NOTIFY
;
9032 wa
[1] |= XCB_EVENT_MASK_LEAVE_WINDOW
| XCB_EVENT_MASK_FOCUS_CHANGE
;
9035 xcb_change_window_attributes(conn
, win
->id
, XCB_CW_BORDER_PIXEL
|
9036 XCB_CW_EVENT_MASK
, wa
);
9038 /* Get WM_SIZE_HINTS. */
9039 xcb_icccm_get_wm_normal_hints_reply(conn
,
9040 xcb_icccm_get_wm_normal_hints(conn
, win
->id
),
9044 xcb_icccm_get_wm_hints_reply(conn
,
9045 xcb_icccm_get_wm_hints(conn
, win
->id
),
9048 /* Get WM_TRANSIENT_FOR; see if window is a transient. */
9049 xcb_icccm_get_wm_transient_for_reply(conn
,
9050 xcb_icccm_get_wm_transient_for(conn
, win
->id
),
9053 win
->transient
= trans
;
9054 set_child_transient(win
, &win
->transient
);
9057 /* Get WM_PROTOCOLS. */
9058 get_wm_protocols(win
);
9060 /* Set initial quirks based on EWMH. */
9061 ewmh_autoquirk(win
);
9063 /* Determine initial quirks. */
9064 xcb_icccm_get_wm_class_reply(conn
,
9065 xcb_icccm_get_wm_class(conn
, win
->id
),
9068 class = win
->ch
.class_name
? win
->ch
.class_name
: "";
9069 instance
= win
->ch
.instance_name
? win
->ch
.instance_name
: "";
9070 name
= get_win_name(win
->id
);
9072 DNPRINTF(SWM_D_CLASS
, "manage_window: class: %s, instance: %s, "
9073 "name: %s\n", class, instance
, name
);
9075 /* java is retarded so treat it special */
9076 if (strstr(instance
, "sun-awt")) {
9077 DNPRINTF(SWM_D_CLASS
, "manage_window: java window detected.\n");
9081 TAILQ_FOREACH(qp
, &quirks
, entry
) {
9082 if (regexec(&qp
->regex_class
, class, 0, NULL
, 0) == 0 &&
9083 regexec(&qp
->regex_instance
, instance
, 0, NULL
, 0) == 0 &&
9084 regexec(&qp
->regex_name
, name
, 0, NULL
, 0) == 0) {
9085 DNPRINTF(SWM_D_CLASS
, "manage_window: matched "
9086 "quirk: %s:%s:%s mask: %#x, ws: %d\n", qp
->class,
9087 qp
->instance
, qp
->name
, qp
->quirk
, qp
->ws
);
9088 win
->quirks
= qp
->quirk
;
9089 if (qp
->ws
>= 0 && qp
->ws
< workspace_limit
)
9096 /* Reset font sizes (the bruteforce way; no default keybinding). */
9097 if (win
->quirks
& SWM_Q_XTERM_FONTADJ
) {
9098 for (i
= 0; i
< SWM_MAX_FONT_STEPS
; i
++)
9099 fake_keypress(win
, XK_KP_Subtract
, XCB_MOD_MASK_SHIFT
);
9100 for (i
= 0; i
< SWM_MAX_FONT_STEPS
; i
++)
9101 fake_keypress(win
, XK_KP_Add
, XCB_MOD_MASK_SHIFT
);
9104 /* Figure out which workspace the window belongs to. */
9105 if (!(win
->quirks
& SWM_Q_IGNOREPID
) &&
9106 (p
= find_pid(window_get_pid(win
->id
))) != NULL
) {
9107 win
->ws
= &r
->s
->ws
[p
->ws
];
9108 TAILQ_REMOVE(&pidlist
, p
, entry
);
9111 } else if ((ws_idx
= get_ws_idx(win
)) != -1 &&
9113 /* _SWM_WS is set; use that. */
9114 win
->ws
= &r
->s
->ws
[ws_idx
];
9115 } else if (trans
&& (ww
= find_window(trans
)) != NULL
) {
9116 /* Launch transients in the same ws as parent. */
9123 win
->ws
= &r
->s
->ws
[force_ws
];
9125 /* Set the _NET_WM_DESKTOP atom. */
9126 DNPRINTF(SWM_D_PROP
, "manage_window: set _NET_WM_DESKTOP: %d\n",
9128 xcb_change_property(conn
, XCB_PROP_MODE_REPLACE
, win
->id
,
9129 ewmh
[_NET_WM_DESKTOP
].atom
, XCB_ATOM_CARDINAL
, 32, 1, &win
->ws
->idx
);
9131 /* Remove any _SWM_WS now that we set _NET_WM_DESKTOP. */
9132 xcb_delete_property(conn
, win
->id
, a_swm_ws
);
9134 /* WS must already be set for this to work. */
9135 store_float_geom(win
);
9137 /* Make sure window is positioned inside its region, if its active. */
9139 region_containment(win
, r
, SWM_CW_ALLSIDES
|
9140 SWM_CW_HARDBOUNDARY
);
9145 /* Figure out where to insert the window in the workspace list. */
9146 if (trans
&& (ww
= find_window(trans
)))
9147 TAILQ_INSERT_AFTER(&win
->ws
->winlist
, ww
, win
, entry
);
9148 else if (win
->ws
->focus
&& spawn_pos
== SWM_STACK_ABOVE
)
9149 TAILQ_INSERT_AFTER(&win
->ws
->winlist
, win
->ws
->focus
, win
,
9151 else if (win
->ws
->focus
&& spawn_pos
== SWM_STACK_BELOW
)
9152 TAILQ_INSERT_BEFORE(win
->ws
->focus
, win
, entry
);
9153 else switch (spawn_pos
) {
9156 case SWM_STACK_ABOVE
:
9157 TAILQ_INSERT_TAIL(&win
->ws
->winlist
, win
, entry
);
9159 case SWM_STACK_BOTTOM
:
9160 case SWM_STACK_BELOW
:
9161 TAILQ_INSERT_HEAD(&win
->ws
->winlist
, win
, entry
);
9164 ewmh_update_client_list();
9166 TAILQ_INSERT_HEAD(&win
->ws
->stack
, win
, stack_entry
);
9169 /* Get/apply initial _NET_WM_STATE */
9170 ewmh_get_wm_state(win
);
9173 new_flags
= win
->ewmh_flags
;
9175 if (win
->quirks
& SWM_Q_FLOAT
)
9176 new_flags
|= EWMH_F_ABOVE
;
9178 if (win
->quirks
& SWM_Q_ANYWHERE
)
9179 new_flags
|= SWM_F_MANUAL
;
9181 ewmh_apply_flags(win
, new_flags
);
9182 ewmh_update_wm_state(win
);
9184 /* Set initial _NET_WM_ALLOWED_ACTIONS */
9185 ewmh_update_actions(win
);
9189 DNPRINTF(SWM_D_MISC
, "manage_window: done. win %#x, (x,y) w x h: "
9190 "(%d,%d) %d x %d, ws: %d, iconic: %s, transient: %#x\n", win
->id
,
9191 X(win
), Y(win
), WIDTH(win
), HEIGHT(win
), win
->ws
->idx
,
9192 YESNO(ICONIC(win
)), win
->transient
);
9198 free_window(struct ws_win
*win
)
9200 DNPRINTF(SWM_D_MISC
, "free_window: win %#x\n", win
->id
);
9205 TAILQ_REMOVE(&win
->ws
->unmanagedlist
, win
, entry
);
9207 xcb_icccm_get_wm_class_reply_wipe(&win
->ch
);
9212 memset(win
, 0xff, sizeof *win
); /* XXX kill later */
9215 DNPRINTF(SWM_D_MISC
, "free_window: done.\n");
9219 unmanage_window(struct ws_win
*win
)
9221 struct ws_win
*parent
;
9226 DNPRINTF(SWM_D_MISC
, "unmanage_window: win %#x\n", win
->id
);
9229 parent
= find_window(win
->transient
);
9231 parent
->focus_child
= NULL
;
9234 TAILQ_REMOVE(&win
->ws
->stack
, win
, stack_entry
);
9235 TAILQ_REMOVE(&win
->ws
->winlist
, win
, entry
);
9236 TAILQ_INSERT_TAIL(&win
->ws
->unmanagedlist
, win
, entry
);
9238 ewmh_update_client_list();
9242 expose(xcb_expose_event_t
*e
)
9245 struct swm_region
*r
;
9247 DNPRINTF(SWM_D_EVENT
, "expose: win %#x\n", e
->window
);
9249 num_screens
= get_screen_count();
9250 for (i
= 0; i
< num_screens
; i
++)
9251 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
9252 if (e
->window
== WINID(r
->bar
))
9260 focusin(xcb_focus_in_event_t
*e
)
9262 DNPRINTF(SWM_D_EVENT
, "focusin: win %#x, mode: %s(%u), "
9263 "detail: %s(%u)\n", e
->event
, get_notify_mode_label(e
->mode
),
9264 e
->mode
, get_notify_detail_label(e
->detail
), e
->detail
);
9268 focusout(xcb_focus_out_event_t
*e
)
9270 DNPRINTF(SWM_D_EVENT
, "focusout: win %#x, mode: %s(%u), "
9271 "detail: %s(%u)\n", e
->event
, get_notify_mode_label(e
->mode
),
9272 e
->mode
, get_notify_detail_label(e
->detail
), e
->detail
);
9277 keypress(xcb_key_press_event_t
*e
)
9279 xcb_keysym_t keysym
;
9282 keysym
= xcb_key_press_lookup_keysym(syms
, e
, 0);
9284 DNPRINTF(SWM_D_EVENT
, "keypress: keysym: %u, win (x,y): %#x (%d,%d), "
9285 "detail: %u, time: %u, root (x,y): %#x (%d,%d), child: %#x, "
9286 "state: %u, same_screen: %s\n", keysym
, e
->event
, e
->event_x
,
9287 e
->event_y
, e
->detail
, e
->time
, e
->root
, e
->root_x
, e
->root_y
,
9288 e
->child
, e
->state
, YESNO(e
->same_screen
));
9290 if ((kp
= key_lookup(CLEANMASK(e
->state
), keysym
)) == NULL
)
9293 last_event_time
= e
->time
;
9295 if (kp
->funcid
== KF_SPAWN_CUSTOM
)
9296 spawn_custom(root_to_region(e
->root
, SWM_CK_ALL
),
9297 &(keyfuncs
[kp
->funcid
].args
), kp
->spawn_name
);
9298 else if (keyfuncs
[kp
->funcid
].func
)
9299 keyfuncs
[kp
->funcid
].func(root_to_region(e
->root
, SWM_CK_ALL
),
9300 &(keyfuncs
[kp
->funcid
].args
));
9303 /* Unfreeze grab events. */
9304 xcb_allow_events(conn
, XCB_ALLOW_ASYNC_KEYBOARD
, e
->time
);
9307 DNPRINTF(SWM_D_EVENT
, "keypress: done.\n");
9311 buttonpress(xcb_button_press_event_t
*e
)
9313 struct ws_win
*win
= NULL
;
9314 struct swm_region
*r
, *old_r
;
9316 bool handled
= false;
9318 DNPRINTF(SWM_D_EVENT
, "buttonpress: win (x,y): %#x (%d,%d), "
9319 "detail: %u, time: %u, root (x,y): %#x (%d,%d), child: %#x, "
9320 "state: %u, same_screen: %s\n", e
->event
, e
->event_x
, e
->event_y
,
9321 e
->detail
, e
->time
, e
->root
, e
->root_x
, e
->root_y
, e
->child
,
9322 e
->state
, YESNO(e
->same_screen
));
9324 if (e
->event
== e
->root
) {
9325 if (e
->child
!= 0) {
9326 win
= find_window(e
->child
);
9327 /* Pass ButtonPress to window if it isn't managed. */
9331 /* Focus on empty region */
9332 /* If no windows on region if its empty. */
9333 r
= root_to_region(e
->root
, SWM_CK_POINTER
);
9335 DNPRINTF(SWM_D_EVENT
, "buttonpress: "
9336 "NULL region; ignoring.\n");
9340 if (TAILQ_EMPTY(&r
->ws
->winlist
)) {
9341 old_r
= root_to_region(e
->root
, SWM_CK_FOCUS
);
9342 if (old_r
&& old_r
!= r
)
9343 unfocus_win(old_r
->ws
->focus
);
9345 xcb_set_input_focus(conn
,
9346 XCB_INPUT_FOCUS_PARENT
, e
->root
, e
->time
);
9348 /* Clear bar since empty. */
9356 win
= find_window(e
->event
);
9362 last_event_time
= e
->time
;
9364 focus_win(get_focus_magic(win
));
9366 for (i
= 0; i
< LENGTH(buttons
); i
++)
9367 if (client_click
== buttons
[i
].action
&& buttons
[i
].func
&&
9368 buttons
[i
].button
== e
->detail
&&
9369 CLEANMASK(buttons
[i
].mask
) == CLEANMASK(e
->state
)) {
9370 buttons
[i
].func(win
, &buttons
[i
].args
);
9376 DNPRINTF(SWM_D_EVENT
, "buttonpress: passing to window.\n");
9377 /* Replay event to event window */
9378 xcb_allow_events(conn
, XCB_ALLOW_REPLAY_POINTER
, e
->time
);
9380 DNPRINTF(SWM_D_EVENT
, "buttonpress: handled.\n");
9381 /* Unfreeze grab events. */
9382 xcb_allow_events(conn
, XCB_ALLOW_SYNC_POINTER
, e
->time
);
9390 print_win_geom(xcb_window_t w
)
9392 xcb_get_geometry_reply_t
*wa
;
9394 wa
= xcb_get_geometry_reply(conn
, xcb_get_geometry(conn
, w
), NULL
);
9396 DNPRINTF(SWM_D_MISC
, "print_win_geom: window not found: %#x\n",
9401 DNPRINTF(SWM_D_MISC
, "print_win_geom: win %#x, root: %#x, "
9402 "depth: %u, (x,y) w x h: (%d,%d) %d x %d, border: %d\n",
9403 w
, wa
->root
, wa
->depth
, wa
->x
, wa
->y
, wa
->width
, wa
->height
,
9412 get_stack_mode_name(uint8_t mode
)
9417 case XCB_STACK_MODE_ABOVE
:
9420 case XCB_STACK_MODE_BELOW
:
9423 case XCB_STACK_MODE_TOP_IF
:
9426 case XCB_STACK_MODE_BOTTOM_IF
:
9429 case XCB_STACK_MODE_OPPOSITE
:
9441 configurerequest(xcb_configure_request_event_t
*e
)
9444 struct swm_region
*r
= NULL
;
9446 uint32_t wc
[7] = {0};
9450 if ((win
= find_window(e
->window
)) == NULL
)
9451 if ((win
= find_unmanaged_window(e
->window
)) == NULL
)
9455 if (swm_debug
& SWM_D_EVENT
) {
9456 print_win_geom(e
->window
);
9458 DNPRINTF(SWM_D_EVENT
, "configurerequest: win %#x, "
9459 "parent: %#x, new: %s, value_mask: %u { ", e
->window
,
9460 e
->parent
, YESNO(new), e
->value_mask
);
9461 if (e
->value_mask
& XCB_CONFIG_WINDOW_X
)
9462 DPRINTF("X: %d ", e
->x
);
9463 if (e
->value_mask
& XCB_CONFIG_WINDOW_Y
)
9464 DPRINTF("Y: %d ", e
->y
);
9465 if (e
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
9466 DPRINTF("W: %u ", e
->width
);
9467 if (e
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
9468 DPRINTF("H: %u ", e
->height
);
9469 if (e
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
9470 DPRINTF("Border: %u ", e
->border_width
);
9471 if (e
->value_mask
& XCB_CONFIG_WINDOW_SIBLING
)
9472 DPRINTF("Sibling: %#x ", e
->sibling
);
9473 if (e
->value_mask
& XCB_CONFIG_WINDOW_STACK_MODE
)
9474 DPRINTF("StackMode: %s(%u) ",
9475 get_stack_mode_name(e
->stack_mode
), e
->stack_mode
);
9481 if (e
->value_mask
& XCB_CONFIG_WINDOW_X
) {
9482 mask
|= XCB_CONFIG_WINDOW_X
;
9485 if (e
->value_mask
& XCB_CONFIG_WINDOW_Y
) {
9486 mask
|= XCB_CONFIG_WINDOW_Y
;
9489 if (e
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
) {
9490 mask
|= XCB_CONFIG_WINDOW_WIDTH
;
9493 if (e
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
) {
9494 mask
|= XCB_CONFIG_WINDOW_HEIGHT
;
9495 wc
[i
++] = e
->height
;
9497 if (e
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
) {
9498 mask
|= XCB_CONFIG_WINDOW_BORDER_WIDTH
;
9499 wc
[i
++] = e
->border_width
;
9501 if (e
->value_mask
& XCB_CONFIG_WINDOW_SIBLING
) {
9502 mask
|= XCB_CONFIG_WINDOW_SIBLING
;
9503 wc
[i
++] = e
->sibling
;
9505 if (e
->value_mask
& XCB_CONFIG_WINDOW_STACK_MODE
) {
9506 mask
|= XCB_CONFIG_WINDOW_STACK_MODE
;
9507 wc
[i
++] = e
->stack_mode
;
9511 xcb_configure_window(conn
, e
->window
, mask
, wc
);
9514 } else if ((!MANUAL(win
) || win
->quirks
& SWM_Q_ANYWHERE
) &&
9515 !FULLSCREEN(win
) && !MAXIMIZED(win
)) {
9518 else if (win
->ws
->old_r
)
9521 /* windows are centered unless ANYWHERE quirk is set. */
9522 if (win
->quirks
& SWM_Q_ANYWHERE
) {
9523 if (e
->value_mask
& XCB_CONFIG_WINDOW_X
) {
9524 win
->g_float
.x
= e
->x
;
9526 win
->g_float
.x
-= X(r
);
9529 if (e
->value_mask
& XCB_CONFIG_WINDOW_Y
) {
9530 win
->g_float
.y
= e
->y
;
9532 win
->g_float
.y
-= Y(r
);
9536 if (e
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
9537 win
->g_float
.w
= e
->width
;
9539 if (e
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
9540 win
->g_float
.h
= e
->height
;
9542 win
->g_floatvalid
= true;
9544 if (!MAXIMIZED(win
) && !FULLSCREEN(win
) &&
9545 (TRANS(win
) || (ABOVE(win
) &&
9546 win
->ws
->cur_layout
!= &layouts
[SWM_MAX_STACK
]))) {
9547 WIDTH(win
) = win
->g_float
.w
;
9548 HEIGHT(win
) = win
->g_float
.h
;
9551 update_floater(win
);
9566 DNPRINTF(SWM_D_EVENT
, "configurerequest: done.\n");
9570 configurenotify(xcb_configure_notify_event_t
*e
)
9574 DNPRINTF(SWM_D_EVENT
, "configurenotify: win %#x, event win: %#x, "
9575 "(x,y) WxH: (%d,%d) %ux%u, border: %u, above_sibling: %#x, "
9576 "override_redirect: %s\n", e
->window
, e
->event
, e
->x
, e
->y
,
9577 e
->width
, e
->height
, e
->border_width
, e
->above_sibling
,
9578 YESNO(e
->override_redirect
));
9580 win
= find_window(e
->window
);
9582 xcb_icccm_get_wm_normal_hints_reply(conn
,
9583 xcb_icccm_get_wm_normal_hints(conn
, win
->id
),
9586 if (font_adjusted
) {
9594 destroynotify(xcb_destroy_notify_event_t
*e
)
9598 DNPRINTF(SWM_D_EVENT
, "destroynotify: win %#x\n", e
->window
);
9600 if ((win
= find_window(e
->window
)) == NULL
) {
9601 if ((win
= find_unmanaged_window(e
->window
)) == NULL
)
9607 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
9608 /* If we were focused, make sure we focus on something else. */
9609 if (win
== win
->ws
->focus
)
9610 win
->ws
->focus_pending
= get_focus_prev(win
);
9613 unmanage_window(win
);
9616 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& WS_FOCUSED(win
->ws
)) {
9617 if (win
->ws
->focus_pending
) {
9618 focus_win(win
->ws
->focus_pending
);
9619 win
->ws
->focus_pending
= NULL
;
9620 } else if (win
== win
->ws
->focus
) {
9621 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
,
9622 win
->ws
->r
->id
, XCB_CURRENT_TIME
);
9633 get_notify_detail_label(uint8_t detail
)
9638 case XCB_NOTIFY_DETAIL_ANCESTOR
:
9641 case XCB_NOTIFY_DETAIL_VIRTUAL
:
9644 case XCB_NOTIFY_DETAIL_INFERIOR
:
9647 case XCB_NOTIFY_DETAIL_NONLINEAR
:
9648 label
= "Nonlinear";
9650 case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL
:
9651 label
= "NonlinearVirtual";
9653 case XCB_NOTIFY_DETAIL_POINTER
:
9656 case XCB_NOTIFY_DETAIL_POINTER_ROOT
:
9657 label
= "PointerRoot";
9659 case XCB_NOTIFY_DETAIL_NONE
:
9670 get_notify_mode_label(uint8_t mode
)
9675 case XCB_NOTIFY_MODE_NORMAL
:
9678 case XCB_NOTIFY_MODE_GRAB
:
9681 case XCB_NOTIFY_MODE_UNGRAB
:
9684 case XCB_NOTIFY_MODE_WHILE_GRABBED
:
9685 label
= "WhileGrabbed";
9696 enternotify(xcb_enter_notify_event_t
*e
)
9699 struct swm_region
*r
;
9701 DNPRINTF(SWM_D_FOCUS
, "enternotify: time: %u, win (x,y): %#x "
9702 "(%d,%d), mode: %s(%d), detail: %s(%d), root (x,y): %#x (%d,%d), "
9703 "child: %#x, same_screen_focus: %s, state: %d\n",
9704 e
->time
, e
->event
, e
->event_x
, e
->event_y
,
9705 get_notify_mode_label(e
->mode
), e
->mode
,
9706 get_notify_detail_label(e
->detail
), e
->detail
,
9707 e
->root
, e
->root_x
, e
->root_y
, e
->child
,
9708 YESNO(e
->same_screen_focus
), e
->state
);
9710 if (focus_mode
== SWM_FOCUS_MANUAL
&&
9711 e
->mode
== XCB_NOTIFY_MODE_NORMAL
) {
9712 DNPRINTF(SWM_D_EVENT
, "enternotify: manual focus; ignoring.\n");
9716 if (focus_mode
!= SWM_FOCUS_FOLLOW
&&
9717 e
->mode
== XCB_NOTIFY_MODE_UNGRAB
) {
9718 DNPRINTF(SWM_D_EVENT
, "enternotify: ungrab; ignoring.\n");
9722 last_event_time
= e
->time
;
9724 if ((win
= find_window(e
->event
)) == NULL
) {
9725 if (e
->event
== e
->root
) {
9726 /* If no windows on pointer region, then focus root. */
9727 r
= root_to_region(e
->root
, SWM_CK_POINTER
);
9729 DNPRINTF(SWM_D_EVENT
, "enternotify: "
9730 "NULL region; ignoring.\n");
9736 DNPRINTF(SWM_D_EVENT
, "enternotify: window is NULL; "
9741 if (e
->mode
== XCB_NOTIFY_MODE_NORMAL
&&
9742 e
->detail
== XCB_NOTIFY_DETAIL_INFERIOR
) {
9743 DNPRINTF(SWM_D_EVENT
, "enternotify: entering from "
9744 "inferior; ignoring\n");
9748 focus_win(get_focus_magic(win
));
9756 leavenotify(xcb_leave_notify_event_t
*e
)
9758 DNPRINTF(SWM_D_FOCUS
, "leavenotify: time: %u, win (x,y): %#x "
9759 "(%d,%d), mode: %s(%d), detail: %s(%d), root (x,y): %#x (%d,%d), "
9760 "child: %#x, same_screen_focus: %s, state: %d\n",
9761 e
->time
, e
->event
, e
->event_x
, e
->event_y
,
9762 get_notify_mode_label(e
->mode
), e
->mode
,
9763 get_notify_detail_label(e
->detail
), e
->detail
,
9764 e
->root
, e
->root_x
, e
->root_y
, e
->child
,
9765 YESNO(e
->same_screen_focus
), e
->state
);
9770 mapnotify(xcb_map_notify_event_t
*e
)
9772 struct ws_win
*win
, *parent
= NULL
;
9773 struct workspace
*ws
;
9775 DNPRINTF(SWM_D_EVENT
, "mapnotify: win %#x\n", e
->window
);
9777 if ((win
= manage_window(e
->window
, spawn_position
, true)) == NULL
)
9781 /* Need to know if win was mapped due to ws switch. */
9782 if (ws
->state
== SWM_WS_STATE_MAPPED
) {
9783 if (ws
->focus_pending
&& TRANS(ws
->focus_pending
))
9784 parent
= find_window(win
->transient
);
9786 /* If window's parent is maximized, don't clear it. */
9787 if ((parent
== NULL
) || !MAXIMIZED(parent
))
9788 if (clear_maximized(ws
) > 0)
9793 set_win_state(win
, XCB_ICCCM_WM_STATE_NORMAL
);
9795 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& WS_FOCUSED(win
->ws
)) {
9796 if (ws
->focus_pending
== win
) {
9798 ws
->focus_pending
= NULL
;
9799 center_pointer(win
->ws
->r
);
9808 mappingnotify(xcb_mapping_notify_event_t
*e
)
9811 int i
, j
, num_screens
;
9813 xcb_refresh_keyboard_mapping(syms
, e
);
9815 if (e
->request
== XCB_MAPPING_KEYBOARD
) {
9818 /* Regrab buttons on all managed windows. */
9819 num_screens
= get_screen_count();
9820 for (i
= 0; i
< num_screens
; i
++)
9821 for (j
= 0; j
< workspace_limit
; j
++)
9822 TAILQ_FOREACH(w
, &screens
[i
].ws
[j
].winlist
,
9829 maprequest(xcb_map_request_event_t
*e
)
9831 struct ws_win
*win
, *w
= NULL
;
9832 xcb_get_window_attributes_reply_t
*war
;
9834 DNPRINTF(SWM_D_EVENT
, "maprequest: win %#x\n",
9837 war
= xcb_get_window_attributes_reply(conn
,
9838 xcb_get_window_attributes(conn
, e
->window
),
9841 DNPRINTF(SWM_D_EVENT
, "maprequest: window lost.\n");
9845 if (war
->override_redirect
) {
9846 DNPRINTF(SWM_D_EVENT
, "maprequest: override_redirect; "
9851 win
= manage_window(e
->window
, spawn_position
,
9852 (war
->map_state
== XCB_MAP_STATE_VIEWABLE
));
9856 /* The new window should get focus; prepare. */
9857 if (focus_mode
!= SWM_FOCUS_FOLLOW
&&
9858 !(win
->quirks
& SWM_Q_NOFOCUSONMAP
) &&
9859 (!(win
->hints
.flags
& XCB_ICCCM_WM_HINT_INPUT
) ||
9860 (win
->hints
.flags
& XCB_ICCCM_WM_HINT_INPUT
&&
9861 win
->hints
.input
))) {
9862 if (win
->quirks
& SWM_Q_FOCUSONMAP_SINGLE
) {
9863 /* See if other wins of same type are already mapped. */
9864 TAILQ_FOREACH(w
, &win
->ws
->winlist
, entry
) {
9865 if (w
== win
|| !w
->mapped
)
9868 if (w
->ch
.class_name
&&
9869 win
->ch
.class_name
&&
9870 strcmp(w
->ch
.class_name
,
9871 win
->ch
.class_name
) == 0 &&
9872 w
->ch
.instance_name
&&
9873 win
->ch
.instance_name
&&
9874 strcmp(w
->ch
.instance_name
,
9875 win
->ch
.instance_name
) == 0)
9881 win
->ws
->focus_pending
= get_focus_magic(win
);
9884 /* All windows need to be mapped if they are in the current workspace.*/
9888 /* Ignore EnterNotify to handle the mapnotify without interference. */
9889 if (focus_mode
== SWM_FOCUS_DEFAULT
)
9890 event_drain(XCB_ENTER_NOTIFY
);
9893 DNPRINTF(SWM_D_EVENT
, "maprequest: done.\n");
9897 motionnotify(xcb_motion_notify_event_t
*e
)
9899 struct swm_region
*r
= NULL
;
9902 DNPRINTF(SWM_D_FOCUS
, "motionnotify: time: %u, win (x,y): %#x "
9903 "(%d,%d), detail: %s(%d), root (x,y): %#x (%d,%d), "
9904 "child: %#x, same_screen_focus: %s, state: %d\n",
9905 e
->time
, e
->event
, e
->event_x
, e
->event_y
,
9906 get_notify_detail_label(e
->detail
), e
->detail
,
9907 e
->root
, e
->root_x
, e
->root_y
, e
->child
,
9908 YESNO(e
->same_screen
), e
->state
);
9910 last_event_time
= e
->time
;
9912 if (focus_mode
== SWM_FOCUS_MANUAL
)
9915 num_screens
= get_screen_count();
9916 for (i
= 0; i
< num_screens
; i
++)
9917 if (screens
[i
].root
== e
->root
)
9920 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
9921 if (X(r
) <= e
->root_x
&& e
->root_x
< MAX_X(r
) &&
9922 Y(r
) <= e
->root_y
&& e
->root_y
< MAX_Y(r
))
9930 get_atom_name(xcb_atom_t atom
)
9933 #ifdef SWM_DEBUG_ATOM_NAMES
9935 * This should be disabled during most debugging since
9936 * xcb_get_* causes an xcb_flush.
9939 xcb_get_atom_name_reply_t
*r
;
9941 r
= xcb_get_atom_name_reply(conn
,
9942 xcb_get_atom_name(conn
, atom
),
9945 len
= xcb_get_atom_name_name_length(r
);
9947 name
= malloc(len
+ 1);
9949 memcpy(name
, xcb_get_atom_name_name(r
), len
);
9963 propertynotify(xcb_property_notify_event_t
*e
)
9966 struct workspace
*ws
;
9970 name
= get_atom_name(e
->atom
);
9971 DNPRINTF(SWM_D_EVENT
, "propertynotify: win %#x, atom: %s(%u), "
9972 "time: %#x, state: %u\n", e
->window
, name
, e
->atom
, e
->time
,
9976 win
= find_window(e
->window
);
9982 last_event_time
= e
->time
;
9984 if (e
->atom
== a_state
) {
9985 /* State just changed, make sure it gets focused if mapped. */
9986 if (e
->state
== XCB_PROPERTY_NEW_VALUE
) {
9987 if (focus_mode
!= SWM_FOCUS_FOLLOW
&& WS_FOCUSED(ws
)) {
9989 ws
->focus_pending
== win
) {
9990 focus_win(ws
->focus_pending
);
9991 ws
->focus_pending
= NULL
;
9995 } else if (e
->atom
== XCB_ATOM_WM_CLASS
||
9996 e
->atom
== XCB_ATOM_WM_NAME
) {
9998 } else if (e
->atom
== a_prot
) {
9999 get_wm_protocols(win
);
10006 unmapnotify(xcb_unmap_notify_event_t
*e
)
10008 struct ws_win
*win
;
10009 struct workspace
*ws
;
10011 DNPRINTF(SWM_D_EVENT
, "unmapnotify: win %#x\n", e
->window
);
10013 /* If we aren't managing the window, then ignore. */
10014 win
= find_window(e
->window
);
10015 if (win
== NULL
|| win
->id
!= e
->window
)
10018 /* Do nothing if already withdrawn. */
10019 if (!win
->mapped
&& !ICONIC(win
))
10023 win
->mapped
= false;
10025 /* If win was focused, make sure to focus on something else. */
10026 if (win
== ws
->focus
) {
10027 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
10028 ws
->focus_pending
= get_focus_prev(win
);
10029 DNPRINTF(SWM_D_EVENT
, "unmapnotify: "
10030 "focus_pending: %#x\n",
10031 WINID(ws
->focus_pending
));
10039 set_win_state(win
, XCB_ICCCM_WM_STATE_ICONIC
);
10042 set_win_state(win
, XCB_ICCCM_WM_STATE_WITHDRAWN
);
10043 unmanage_window(win
);
10049 /* Update focus if ws is active. */
10050 if (WS_FOCUSED(ws
)) {
10051 if (focus_mode
== SWM_FOCUS_FOLLOW
) {
10052 focus_win(get_pointer_win(ws
->r
->s
->root
));
10053 } else if (ws
->focus_pending
) {
10054 focus_win(ws
->focus_pending
);
10055 ws
->focus_pending
= NULL
;
10056 } else if (ws
->focus
== NULL
) {
10057 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_PARENT
,
10058 ws
->r
->id
, XCB_CURRENT_TIME
);
10062 center_pointer(ws
->r
);
10068 get_source_type_label(uint32_t type
)
10073 case EWMH_SOURCE_TYPE_NONE
:
10076 case EWMH_SOURCE_TYPE_NORMAL
:
10079 case EWMH_SOURCE_TYPE_OTHER
:
10091 clientmessage(xcb_client_message_event_t
*e
)
10093 struct ws_win
*win
;
10094 struct swm_region
*r
= NULL
;
10097 int num_screens
, i
;
10098 xcb_map_request_event_t mre
;
10102 name
= get_atom_name(e
->type
);
10103 DNPRINTF(SWM_D_EVENT
, "clientmessage: win %#x, atom: %s(%u)\n",
10104 e
->window
, name
, e
->type
);
10108 if (e
->type
== ewmh
[_NET_CURRENT_DESKTOP
].atom
) {
10109 num_screens
= get_screen_count();
10110 for (i
= 0; i
< num_screens
; i
++)
10111 if (screens
[i
].root
== e
->window
) {
10112 r
= screens
[i
].r_focus
;
10116 if (r
&& e
->data
.data32
[0] < (uint32_t)workspace_limit
) {
10117 a
.id
= e
->data
.data32
[0];
10125 win
= find_window(e
->window
);
10127 if (e
->type
== ewmh
[_NET_ACTIVE_WINDOW
].atom
) {
10128 /* Manage the window with maprequest. */
10129 DNPRINTF(SWM_D_EVENT
, "clientmessage: request focus on "
10130 "unmanaged window.\n");
10131 mre
.window
= e
->window
;
10137 if (e
->type
== ewmh
[_NET_ACTIVE_WINDOW
].atom
) {
10138 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_ACTIVE_WINDOW, "
10139 "source_type: %s(%d)\n",
10140 get_source_type_label(e
->data
.data32
[0]),
10141 e
->data
.data32
[0]);
10144 * Allow focus changes that are a result of direct user
10145 * action and from applications that use the old EWMH spec.
10147 if (e
->data
.data32
[0] != EWMH_SOURCE_TYPE_NORMAL
||
10148 win
->quirks
& SWM_Q_OBEYAPPFOCUSREQ
) {
10149 if (WS_FOCUSED(win
->ws
))
10152 win
->ws
->focus_pending
= win
;
10154 } else if (e
->type
== ewmh
[_NET_CLOSE_WINDOW
].atom
) {
10155 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_CLOSE_WINDOW\n");
10156 if (win
->can_delete
)
10157 client_msg(win
, a_delete
, 0);
10159 xcb_kill_client(conn
, win
->id
);
10160 } else if (e
->type
== ewmh
[_NET_MOVERESIZE_WINDOW
].atom
) {
10161 DNPRINTF(SWM_D_EVENT
,
10162 "clientmessage: _NET_MOVERESIZE_WINDOW\n");
10164 if (e
->data
.data32
[0] & (1<<8)) /* x */
10165 X(win
) = e
->data
.data32
[1];
10166 if (e
->data
.data32
[0] & (1<<9)) /* y */
10167 Y(win
) = e
->data
.data32
[2];
10168 if (e
->data
.data32
[0] & (1<<10)) /* width */
10169 WIDTH(win
) = e
->data
.data32
[3];
10170 if (e
->data
.data32
[0] & (1<<11)) /* height */
10171 HEIGHT(win
) = e
->data
.data32
[4];
10173 update_window(win
);
10175 /* Notify no change was made. */
10176 config_win(win
, NULL
);
10177 /* TODO: Change stack sizes */
10179 } else if (e
->type
== ewmh
[_NET_RESTACK_WINDOW
].atom
) {
10180 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_RESTACK_WINDOW\n");
10181 val
[0] = e
->data
.data32
[1]; /* Sibling window. */
10182 val
[1] = e
->data
.data32
[2]; /* Stack mode detail. */
10184 xcb_configure_window(conn
, win
->id
, XCB_CONFIG_WINDOW_SIBLING
|
10185 XCB_CONFIG_WINDOW_STACK_MODE
, val
);
10186 } else if (e
->type
== ewmh
[_NET_WM_STATE
].atom
) {
10187 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_WM_STATE\n");
10188 ewmh_change_wm_state(win
, e
->data
.data32
[1], e
->data
.data32
[0]);
10189 if (e
->data
.data32
[2])
10190 ewmh_change_wm_state(win
, e
->data
.data32
[2],
10191 e
->data
.data32
[0]);
10193 ewmh_update_wm_state(win
);
10195 } else if (e
->type
== ewmh
[_NET_WM_DESKTOP
].atom
) {
10196 DNPRINTF(SWM_D_EVENT
, "clientmessage: _NET_WM_DESKTOP\n");
10199 win_to_ws(win
, e
->data
.data32
[0], true);
10201 /* Restack if either the source or destination ws is mapped. */
10202 if (r
!= NULL
|| win
->ws
->r
!= NULL
) {
10204 load_float_geom(win
);
10216 int errcode
= xcb_connection_has_error(conn
);
10217 #ifdef XCB_CONN_ERROR
10220 case XCB_CONN_ERROR
:
10221 s
= "Socket error, pipe error or other stream error.";
10223 case XCB_CONN_CLOSED_EXT_NOTSUPPORTED
:
10224 s
= "Extension not supported.";
10226 case XCB_CONN_CLOSED_MEM_INSUFFICIENT
:
10227 s
= "Insufficient memory.";
10229 case XCB_CONN_CLOSED_REQ_LEN_EXCEED
:
10230 s
= "Request length was exceeded.";
10232 case XCB_CONN_CLOSED_PARSE_ERR
:
10233 s
= "Error parsing display string.";
10236 s
= "Unknown error.";
10239 errx(errcode
, "X CONNECTION ERROR: %s", s
);
10242 errx(errcode
, "X CONNECTION ERROR");
10249 int num_screens
, i
;
10250 const uint32_t val
= XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT
|
10251 XCB_EVENT_MASK_ENTER_WINDOW
;
10253 xcb_void_cookie_t wac
;
10254 xcb_generic_error_t
*error
;
10256 /* this causes an error if some other window manager is running */
10257 num_screens
= get_screen_count();
10258 for (i
= 0; i
< num_screens
; i
++) {
10259 if ((sc
= get_screen(i
)) == NULL
)
10260 errx(1, "ERROR: can't get screen %d.", i
);
10261 DNPRINTF(SWM_D_INIT
, "enable_wm: screen %d, root: %#x\n",
10263 wac
= xcb_change_window_attributes_checked(conn
, sc
->root
,
10264 XCB_CW_EVENT_MASK
, &val
);
10265 if ((error
= xcb_request_check(conn
, wac
))) {
10266 DNPRINTF(SWM_D_INIT
, "enable_wm: error_code: %u\n",
10267 error
->error_code
);
10272 /* click to focus on empty region */
10273 xcb_grab_button(conn
, 1, sc
->root
, BUTTONMASK
,
10274 XCB_GRAB_MODE_SYNC
, XCB_GRAB_MODE_ASYNC
, XCB_WINDOW_NONE
,
10275 XCB_CURSOR_NONE
, XCB_BUTTON_INDEX_1
, XCB_BUTTON_MASK_ANY
);
10282 new_region(struct swm_screen
*s
, int x
, int y
, int w
, int h
)
10284 struct swm_region
*r
= NULL
, *n
;
10285 struct workspace
*ws
= NULL
;
10289 DNPRINTF(SWM_D_MISC
, "new region: screen[%d]:%dx%d+%d+%d\n",
10290 s
->idx
, w
, h
, x
, y
);
10292 /* remove any conflicting regions */
10293 n
= TAILQ_FIRST(&s
->rl
);
10296 n
= TAILQ_NEXT(r
, entry
);
10297 if (X(r
) < (x
+ w
) && (X(r
) + WIDTH(r
)) > x
&&
10298 Y(r
) < (y
+ h
) && (Y(r
) + HEIGHT(r
)) > y
) {
10299 if (r
->ws
->r
!= NULL
)
10300 r
->ws
->old_r
= r
->ws
->r
;
10303 xcb_destroy_window(conn
, r
->id
);
10304 TAILQ_REMOVE(&s
->rl
, r
, entry
);
10305 TAILQ_INSERT_TAIL(&s
->orl
, r
, entry
);
10309 /* search old regions for one to reuse */
10311 /* size + location match */
10312 TAILQ_FOREACH(r
, &s
->orl
, entry
)
10313 if (X(r
) == x
&& Y(r
) == y
&&
10314 HEIGHT(r
) == h
&& WIDTH(r
) == w
)
10318 TAILQ_FOREACH(r
, &s
->orl
, entry
)
10319 if (HEIGHT(r
) == h
&& WIDTH(r
) == w
)
10323 TAILQ_REMOVE(&s
->orl
, r
, entry
);
10324 /* try to use old region's workspace */
10325 if (r
->ws
->r
== NULL
)
10328 if ((r
= calloc(1, sizeof(struct swm_region
))) == NULL
)
10329 err(1, "new_region: calloc: failed to allocate memory "
10332 /* if we don't have a workspace already, find one */
10334 for (i
= 0; i
< workspace_limit
; i
++)
10335 if (s
->ws
[i
].r
== NULL
) {
10342 errx(1, "new_region: no free workspaces");
10344 if (ws
->state
== SWM_WS_STATE_HIDDEN
)
10345 ws
->state
= SWM_WS_STATE_MAPPING
;
10353 r
->ws_prior
= NULL
;
10356 TAILQ_INSERT_TAIL(&s
->rl
, r
, entry
);
10358 /* Invisible region window to detect pointer events on empty regions. */
10359 r
->id
= xcb_generate_id(conn
);
10360 wa
[0] = XCB_EVENT_MASK_POINTER_MOTION
|
10361 XCB_EVENT_MASK_POINTER_MOTION_HINT
;
10363 xcb_create_window(conn
, XCB_COPY_FROM_PARENT
, r
->id
, r
->s
->root
,
10364 X(r
), Y(r
), WIDTH(r
), HEIGHT(r
), 0, XCB_WINDOW_CLASS_INPUT_ONLY
,
10365 XCB_COPY_FROM_PARENT
, XCB_CW_EVENT_MASK
, wa
);
10367 /* Make sure region input is at the bottom. */
10368 wa
[0] = XCB_STACK_MODE_BELOW
;
10369 xcb_configure_window(conn
, r
->id
, XCB_CONFIG_WINDOW_STACK_MODE
, wa
);
10371 xcb_map_window(conn
, r
->id
);
10375 scan_randr(int idx
)
10377 #ifdef SWM_XRR_HAS_CRTC
10380 #endif /* SWM_XRR_HAS_CRTC */
10381 struct swm_region
*r
;
10382 struct ws_win
*win
;
10384 xcb_randr_get_screen_resources_current_cookie_t src
;
10385 xcb_randr_get_screen_resources_current_reply_t
*srr
;
10386 xcb_randr_get_crtc_info_cookie_t cic
;
10387 xcb_randr_get_crtc_info_reply_t
*cir
= NULL
;
10388 xcb_randr_crtc_t
*crtc
;
10389 xcb_screen_t
*screen
;
10391 DNPRINTF(SWM_D_MISC
, "scan_randr: screen: %d\n", idx
);
10393 if ((screen
= get_screen(idx
)) == NULL
)
10394 errx(1, "ERROR: can't get screen %d.", idx
);
10396 num_screens
= get_screen_count();
10397 if (idx
>= num_screens
)
10398 errx(1, "scan_randr: invalid screen");
10400 /* remove any old regions */
10401 while ((r
= TAILQ_FIRST(&screens
[idx
].rl
)) != NULL
) {
10402 r
->ws
->old_r
= r
->ws
->r
= NULL
;
10404 xcb_destroy_window(conn
, r
->id
);
10405 TAILQ_REMOVE(&screens
[idx
].rl
, r
, entry
);
10406 TAILQ_INSERT_TAIL(&screens
[idx
].orl
, r
, entry
);
10410 /* map virtual screens onto physical screens */
10411 #ifdef SWM_XRR_HAS_CRTC
10412 if (randr_support
) {
10413 src
= xcb_randr_get_screen_resources_current(conn
,
10414 screens
[idx
].root
);
10415 srr
= xcb_randr_get_screen_resources_current_reply(conn
, src
,
10418 new_region(&screens
[idx
], 0, 0,
10419 screen
->width_in_pixels
,
10420 screen
->height_in_pixels
);
10423 ncrtc
= srr
->num_crtcs
;
10425 crtc
= xcb_randr_get_screen_resources_current_crtcs(srr
);
10426 for (c
= 0; c
< ncrtc
; c
++) {
10427 cic
= xcb_randr_get_crtc_info(conn
, crtc
[c
],
10429 cir
= xcb_randr_get_crtc_info_reply(conn
, cic
, NULL
);
10432 if (cir
->num_outputs
== 0) {
10437 if (cir
->mode
== 0)
10438 new_region(&screens
[idx
], 0, 0,
10439 screen
->width_in_pixels
,
10440 screen
->height_in_pixels
);
10442 new_region(&screens
[idx
],
10443 cir
->x
, cir
->y
, cir
->width
, cir
->height
);
10448 #endif /* SWM_XRR_HAS_CRTC */
10450 /* If detection failed, create a single region that spans the screen. */
10451 if (TAILQ_EMPTY(&screens
[idx
].rl
))
10452 new_region(&screens
[idx
], 0, 0, screen
->width_in_pixels
,
10453 screen
->height_in_pixels
);
10456 /* Cleanup unused previously visible workspaces. */
10457 TAILQ_FOREACH(r
, &screens
[idx
].orl
, entry
) {
10458 TAILQ_FOREACH(win
, &r
->ws
->winlist
, entry
)
10460 r
->ws
->state
= SWM_WS_STATE_HIDDEN
;
10462 /* The screen shouldn't focus on an unused region. */
10463 if (screens
[idx
].r_focus
== r
)
10464 screens
[idx
].r_focus
= NULL
;
10467 DNPRINTF(SWM_D_MISC
, "scan_randr: done.\n");
10471 screenchange(xcb_randr_screen_change_notify_event_t
*e
)
10473 struct swm_region
*r
;
10474 int i
, num_screens
;
10476 DNPRINTF(SWM_D_EVENT
, "screenchange: root: %#x\n", e
->root
);
10478 num_screens
= get_screen_count();
10479 /* silly event doesn't include the screen index */
10480 for (i
= 0; i
< num_screens
; i
++)
10481 if (screens
[i
].root
== e
->root
)
10483 if (i
>= num_screens
)
10484 errx(1, "screenchange: screen not found");
10486 /* brute force for now, just re-enumerate the regions */
10490 print_win_geom(e
->root
);
10492 /* add bars to all regions */
10493 for (i
= 0; i
< num_screens
; i
++) {
10494 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
10500 /* Make sure a region has focus on each screen. */
10501 for (i
= 0; i
< num_screens
; i
++) {
10502 if (screens
[i
].r_focus
== NULL
) {
10503 r
= TAILQ_FIRST(&screens
[i
].rl
);
10512 /* Update workspace state on all regions. */
10513 for (i
= 0; i
< num_screens
; i
++)
10514 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
10515 r
->ws
->state
= SWM_WS_STATE_MAPPED
;
10521 struct swm_region
*r
= NULL
;
10522 xcb_window_t
*wins
= NULL
, trans
, *cwins
= NULL
;
10523 int i
, j
, k
, n
, no
, num_screens
;
10525 bool manage
, mapped
;
10527 xcb_query_tree_cookie_t qtc
;
10528 xcb_query_tree_reply_t
*qtr
;
10529 xcb_get_window_attributes_cookie_t gac
;
10530 xcb_get_window_attributes_reply_t
*gar
;
10531 xcb_get_property_cookie_t pc
;
10532 xcb_get_property_reply_t
*pr
;
10534 DNPRINTF(SWM_D_INIT
, "grab_windows: begin\n");
10535 num_screens
= get_screen_count();
10536 for (i
= 0; i
< num_screens
; i
++) {
10537 qtc
= xcb_query_tree(conn
, screens
[i
].root
);
10538 qtr
= xcb_query_tree_reply(conn
, qtc
, NULL
);
10541 wins
= xcb_query_tree_children(qtr
);
10542 no
= xcb_query_tree_children_length(qtr
);
10544 /* Try to sort windows according to _NET_CLIENT_LIST. */
10545 pr
= xcb_get_property_reply(conn
, xcb_get_property(conn
, 0,
10546 screens
[i
].root
, ewmh
[_NET_CLIENT_LIST
].atom
,
10547 XCB_ATOM_WINDOW
, 0, UINT32_MAX
), NULL
);
10549 cwins
= xcb_get_property_value(pr
);
10550 n
= xcb_get_property_value_length(pr
) /
10551 sizeof(xcb_atom_t
);
10553 for (j
= 0; j
< n
; ++j
) {
10554 for (k
= j
; k
< no
; ++k
) {
10555 if (wins
[k
] == cwins
[j
]) {
10556 /* Swap wins j and k. */
10558 wins
[j
] = cwins
[j
];
10566 /* attach windows to a region */
10567 /* normal windows */
10568 DNPRINTF(SWM_D_INIT
, "grab_windows: grab top level windows.\n");
10569 for (j
= 0; j
< no
; j
++) {
10570 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
) {
10571 if (r
->id
== wins
[j
]) {
10572 DNPRINTF(SWM_D_INIT
, "grab_windows: "
10573 "skip %#x; region input window.\n",
10576 } else if (r
->bar
->id
== wins
[j
]) {
10577 DNPRINTF(SWM_D_INIT
, "grab_windows: "
10578 "skip %#x; region bar.\n",
10587 gac
= xcb_get_window_attributes(conn
, wins
[j
]);
10588 gar
= xcb_get_window_attributes_reply(conn
, gac
, NULL
);
10590 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10591 "doesn't exist.\n", wins
[j
]);
10595 if (gar
->override_redirect
) {
10596 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10597 "override_redirect set.\n", wins
[j
]);
10602 pc
= xcb_icccm_get_wm_transient_for(conn
, wins
[j
]);
10603 if (xcb_icccm_get_wm_transient_for_reply(conn
, pc
,
10605 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10606 "is transient for %#x.\n", wins
[j
], trans
);
10611 state
= get_win_state(wins
[j
]);
10612 manage
= state
!= XCB_ICCCM_WM_STATE_WITHDRAWN
;
10613 mapped
= gar
->map_state
== XCB_MAP_STATE_VIEWABLE
;
10614 if (mapped
|| manage
)
10615 manage_window(wins
[j
], SWM_STACK_TOP
, mapped
);
10618 /* transient windows */
10619 DNPRINTF(SWM_D_INIT
, "grab_windows: grab transient windows.\n");
10620 for (j
= 0; j
< no
; j
++) {
10621 gac
= xcb_get_window_attributes(conn
, wins
[j
]);
10622 gar
= xcb_get_window_attributes_reply(conn
, gac
, NULL
);
10624 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10625 "doesn't exist.\n", wins
[j
]);
10629 if (gar
->override_redirect
) {
10630 DNPRINTF(SWM_D_INIT
, "grab_windows: skip %#x; "
10631 "override_redirect set.\n", wins
[j
]);
10636 state
= get_win_state(wins
[j
]);
10637 manage
= state
!= XCB_ICCCM_WM_STATE_WITHDRAWN
;
10638 mapped
= gar
->map_state
== XCB_MAP_STATE_VIEWABLE
;
10639 pc
= xcb_icccm_get_wm_transient_for(conn
, wins
[j
]);
10640 if (xcb_icccm_get_wm_transient_for_reply(conn
, pc
,
10641 &trans
, NULL
) && manage
)
10642 manage_window(wins
[j
], SWM_STACK_TOP
, mapped
);
10647 DNPRINTF(SWM_D_INIT
, "grab_windows: done.\n");
10651 setup_screens(void)
10653 int i
, j
, k
, num_screens
;
10654 struct workspace
*ws
;
10655 uint32_t gcv
[1], wa
[1];
10656 const xcb_query_extension_reply_t
*qep
;
10657 xcb_screen_t
*screen
;
10658 xcb_randr_query_version_cookie_t c
;
10659 xcb_randr_query_version_reply_t
*r
;
10661 num_screens
= get_screen_count();
10662 if ((screens
= calloc(num_screens
,
10663 sizeof(struct swm_screen
))) == NULL
)
10664 err(1, "setup_screens: calloc: failed to allocate memory for "
10667 /* Initial RandR setup. */
10668 randr_support
= false;
10669 qep
= xcb_get_extension_data(conn
, &xcb_randr_id
);
10670 if (qep
->present
) {
10671 c
= xcb_randr_query_version(conn
, 1, 1);
10672 r
= xcb_randr_query_version_reply(conn
, c
, NULL
);
10674 if (r
->major_version
>= 1) {
10675 randr_support
= true;
10676 randr_eventbase
= qep
->first_event
;
10682 wa
[0] = cursors
[XC_LEFT_PTR
].cid
;
10684 /* map physical screens */
10685 for (i
= 0; i
< num_screens
; i
++) {
10686 DNPRINTF(SWM_D_WS
, "setup_screens: init screen: %d\n", i
);
10687 screens
[i
].idx
= i
;
10688 screens
[i
].r_focus
= NULL
;
10690 TAILQ_INIT(&screens
[i
].rl
);
10691 TAILQ_INIT(&screens
[i
].orl
);
10692 if ((screen
= get_screen(i
)) == NULL
)
10693 errx(1, "ERROR: can't get screen %d.", i
);
10694 screens
[i
].root
= screen
->root
;
10696 /* set default colors */
10697 setscreencolor("red", i
, SWM_S_COLOR_FOCUS
);
10698 setscreencolor("rgb:88/88/88", i
, SWM_S_COLOR_UNFOCUS
);
10699 setscreencolor("rgb:00/80/80", i
, SWM_S_COLOR_BAR_BORDER
);
10700 setscreencolor("rgb:00/40/40", i
,
10701 SWM_S_COLOR_BAR_BORDER_UNFOCUS
);
10702 setscreencolor("black", i
, SWM_S_COLOR_BAR
);
10703 setscreencolor("rgb:a0/a0/a0", i
, SWM_S_COLOR_BAR_FONT
);
10704 setscreencolor("red", i
, SWM_S_COLOR_FOCUS_MAXIMIZED
);
10705 setscreencolor("rgb:88/88/88", i
,
10706 SWM_S_COLOR_UNFOCUS_MAXIMIZED
);
10708 /* create graphics context on screen */
10709 screens
[i
].bar_gc
= xcb_generate_id(conn
);
10711 xcb_create_gc(conn
, screens
[i
].bar_gc
, screens
[i
].root
,
10712 XCB_GC_GRAPHICS_EXPOSURES
, gcv
);
10714 /* set default cursor */
10715 xcb_change_window_attributes(conn
, screens
[i
].root
,
10716 XCB_CW_CURSOR
, wa
);
10718 /* init all workspaces */
10719 /* XXX these should be dynamically allocated too */
10720 for (j
= 0; j
< SWM_WS_MAX
; j
++) {
10721 ws
= &screens
[i
].ws
[j
];
10724 ws
->bar_enabled
= true;
10726 ws
->focus_prev
= NULL
;
10727 ws
->focus_pending
= NULL
;
10730 ws
->state
= SWM_WS_STATE_HIDDEN
;
10731 TAILQ_INIT(&ws
->stack
);
10732 TAILQ_INIT(&ws
->winlist
);
10733 TAILQ_INIT(&ws
->unmanagedlist
);
10735 for (k
= 0; layouts
[k
].l_stack
!= NULL
; k
++)
10736 if (layouts
[k
].l_config
!= NULL
)
10737 layouts
[k
].l_config(ws
,
10738 SWM_ARG_ID_STACKINIT
);
10739 ws
->cur_layout
= &layouts
[0];
10740 ws
->cur_layout
->l_string(ws
);
10746 xcb_randr_select_input(conn
, screens
[i
].root
,
10747 XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE
);
10752 setup_globals(void)
10754 if ((bar_fonts
= strdup(SWM_BAR_FONTS
)) == NULL
)
10755 err(1, "setup_globals: strdup: failed to allocate memory.");
10757 if ((clock_format
= strdup("%a %b %d %R %Z %Y")) == NULL
)
10758 err(1, "setup_globals: strdup: failed to allocate memory.");
10760 if ((syms
= xcb_key_symbols_alloc(conn
)) == NULL
)
10761 errx(1, "unable to allocate key symbols");
10763 a_state
= get_atom_from_string("WM_STATE");
10764 a_prot
= get_atom_from_string("WM_PROTOCOLS");
10765 a_delete
= get_atom_from_string("WM_DELETE_WINDOW");
10766 a_net_supported
= get_atom_from_string("_NET_SUPPORTED");
10767 a_net_wm_check
= get_atom_from_string("_NET_SUPPORTING_WM_CHECK");
10768 a_takefocus
= get_atom_from_string("WM_TAKE_FOCUS");
10769 a_utf8_string
= get_atom_from_string("UTF8_STRING");
10770 a_swm_ws
= get_atom_from_string("_SWM_WS");
10774 shutdown_cleanup(void)
10776 int i
, num_screens
;
10778 /* disable alarm because the following code may not be interrupted */
10780 if (signal(SIGALRM
, SIG_IGN
) == SIG_ERR
)
10781 err(1, "can't disable alarm");
10790 num_screens
= get_screen_count();
10791 for (i
= 0; i
< num_screens
; ++i
) {
10792 xcb_set_input_focus(conn
, XCB_INPUT_FOCUS_POINTER_ROOT
,
10793 screens
[i
].root
, XCB_CURRENT_TIME
);
10795 if (screens
[i
].bar_gc
!= XCB_NONE
)
10796 xcb_free_gc(conn
, screens
[i
].bar_gc
);
10797 if (!bar_font_legacy
) {
10798 XftColorFree(display
, DefaultVisual(display
, i
),
10799 DefaultColormap(display
, i
), &bar_font_color
);
10800 XftColorFree(display
, DefaultVisual(display
, i
),
10801 DefaultColormap(display
, i
), &search_font_color
);
10805 if (bar_font_legacy
)
10806 XFreeFontSet(display
, bar_fs
);
10808 XftFontClose(display
, bar_font
);
10811 xcb_key_symbols_free(syms
);
10813 xcb_disconnect(conn
);
10817 event_error(xcb_generic_error_t
*e
)
10821 DNPRINTF(SWM_D_EVENT
, "event_error: %s(%u) from %s(%u), sequence: %u, "
10822 "resource_id: %u, minor_code: %u\n",
10823 xcb_event_get_error_label(e
->error_code
), e
->error_code
,
10824 xcb_event_get_request_label(e
->major_code
), e
->major_code
,
10825 e
->sequence
, e
->resource_id
, e
->minor_code
);
10829 event_handle(xcb_generic_event_t
*evt
)
10831 uint8_t type
= XCB_EVENT_RESPONSE_TYPE(evt
);
10833 DNPRINTF(SWM_D_EVENT
, "XCB Event: %s(%d), seq %u\n",
10834 xcb_event_get_label(XCB_EVENT_RESPONSE_TYPE(evt
)),
10835 XCB_EVENT_RESPONSE_TYPE(evt
), evt
->sequence
);
10838 #define EVENT(type, callback) case type: callback((void *)evt); return
10839 EVENT(0, event_error
);
10840 EVENT(XCB_BUTTON_PRESS
, buttonpress
);
10841 /*EVENT(XCB_BUTTON_RELEASE, buttonpress);*/
10842 /*EVENT(XCB_CIRCULATE_NOTIFY, );*/
10843 /*EVENT(XCB_CIRCULATE_REQUEST, );*/
10844 EVENT(XCB_CLIENT_MESSAGE
, clientmessage
);
10845 /*EVENT(XCB_COLORMAP_NOTIFY, );*/
10846 EVENT(XCB_CONFIGURE_NOTIFY
, configurenotify
);
10847 EVENT(XCB_CONFIGURE_REQUEST
, configurerequest
);
10848 /*EVENT(XCB_CREATE_NOTIFY, );*/
10849 EVENT(XCB_DESTROY_NOTIFY
, destroynotify
);
10850 EVENT(XCB_ENTER_NOTIFY
, enternotify
);
10851 EVENT(XCB_EXPOSE
, expose
);
10853 EVENT(XCB_FOCUS_IN
, focusin
);
10854 EVENT(XCB_FOCUS_OUT
, focusout
);
10856 /*EVENT(XCB_GRAPHICS_EXPOSURE, );*/
10857 /*EVENT(XCB_GRAVITY_NOTIFY, );*/
10858 EVENT(XCB_KEY_PRESS
, keypress
);
10859 /*EVENT(XCB_KEY_RELEASE, keypress);*/
10860 /*EVENT(XCB_KEYMAP_NOTIFY, );*/
10862 EVENT(XCB_LEAVE_NOTIFY
, leavenotify
);
10864 EVENT(XCB_MAP_NOTIFY
, mapnotify
);
10865 EVENT(XCB_MAP_REQUEST
, maprequest
);
10866 EVENT(XCB_MAPPING_NOTIFY
, mappingnotify
);
10867 EVENT(XCB_MOTION_NOTIFY
, motionnotify
);
10868 /*EVENT(XCB_NO_EXPOSURE, );*/
10869 EVENT(XCB_PROPERTY_NOTIFY
, propertynotify
);
10870 /*EVENT(XCB_REPARENT_NOTIFY, );*/
10871 /*EVENT(XCB_RESIZE_REQUEST, );*/
10872 /*EVENT(XCB_SELECTION_CLEAR, );*/
10873 /*EVENT(XCB_SELECTION_NOTIFY, );*/
10874 /*EVENT(XCB_SELECTION_REQUEST, );*/
10875 EVENT(XCB_UNMAP_NOTIFY
, unmapnotify
);
10876 /*EVENT(XCB_VISIBILITY_NOTIFY, );*/
10879 if (type
- randr_eventbase
== XCB_RANDR_SCREEN_CHANGE_NOTIFY
)
10880 screenchange((void *)evt
);
10884 main(int argc
, char *argv
[])
10886 struct swm_region
*r
;
10887 char conf
[PATH_MAX
], *cfile
= NULL
;
10889 int xfd
, i
, num_screens
;
10890 struct sigaction sact
;
10891 xcb_generic_event_t
*evt
;
10893 struct pollfd pfd
[2];
10894 bool stdin_ready
= false, startup
= true;
10896 /* suppress unused warning since var is needed */
10900 time_started
= time(NULL
);
10904 warnx("Welcome to spectrwm V%s Build: %s", SPECTRWM_VERSION
, buildstr
);
10905 if (setlocale(LC_CTYPE
, "") == NULL
|| setlocale(LC_TIME
, "") == NULL
)
10906 warnx("no locale support");
10908 /* handle some signals */
10909 bzero(&sact
, sizeof(sact
));
10910 sigemptyset(&sact
.sa_mask
);
10912 sact
.sa_handler
= sighdlr
;
10913 sigaction(SIGINT
, &sact
, NULL
);
10914 sigaction(SIGQUIT
, &sact
, NULL
);
10915 sigaction(SIGTERM
, &sact
, NULL
);
10916 sigaction(SIGHUP
, &sact
, NULL
);
10918 sact
.sa_handler
= sighdlr
;
10919 sact
.sa_flags
= SA_NOCLDSTOP
;
10920 sigaction(SIGCHLD
, &sact
, NULL
);
10922 if ((display
= XOpenDisplay(0)) == NULL
)
10923 errx(1, "can not open display");
10925 conn
= XGetXCBConnection(display
);
10926 if (xcb_connection_has_error(conn
))
10927 errx(1, "can not get XCB connection");
10929 XSetEventQueueOwner(display
, XCBOwnsEventQueue
);
10931 xcb_prefetch_extension_data(conn
, &xcb_randr_id
);
10932 xfd
= xcb_get_file_descriptor(conn
);
10934 /* look for local and global conf file */
10935 pwd
= getpwuid(getuid());
10937 errx(1, "invalid user: %d", getuid());
10939 xcb_grab_server(conn
);
10940 xcb_aux_sync(conn
);
10942 /* flush all events */
10943 while ((evt
= xcb_poll_for_event(conn
))) {
10944 if (XCB_EVENT_RESPONSE_TYPE(evt
) == 0)
10950 errx(1, "another window manager is currently running");
10952 /* Load Xcursors and/or cursorfont glyph cursors. */
10955 xcb_aux_sync(conn
);
10965 for (i
= 0; ; i
++) {
10970 snprintf(conf
, sizeof conf
, "%s/.%s",
10971 pwd
->pw_dir
, SWM_CONF_FILE
);
10975 snprintf(conf
, sizeof conf
, "/etc/%s",
10980 snprintf(conf
, sizeof conf
, "%s/.%s",
10981 pwd
->pw_dir
, SWM_CONF_FILE_OLD
);
10984 /* global compat */
10985 snprintf(conf
, sizeof conf
, "/etc/%s",
10986 SWM_CONF_FILE_OLD
);
10992 if (strlen(conf
) && stat(conf
, &sb
) != -1)
10993 if (S_ISREG(sb
.st_mode
)) {
11000 /* load conf (if any) */
11002 conf_load(cfile
, SWM_CONF_DEFAULT
);
11006 if (getenv("SWM_STARTED") == NULL
)
11007 setenv("SWM_STARTED", "YES", 1);
11009 /* setup all bars */
11010 num_screens
= get_screen_count();
11011 for (i
= 0; i
< num_screens
; i
++)
11012 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
11015 /* Manage existing windows. */
11022 xcb_ungrab_server(conn
);
11025 /* Update state of each newly mapped workspace. */
11026 for (i
= 0; i
< num_screens
; i
++)
11027 TAILQ_FOREACH(r
, &screens
[i
].rl
, entry
)
11028 r
->ws
->state
= SWM_WS_STATE_MAPPED
;
11030 memset(&pfd
, 0, sizeof(pfd
));
11032 pfd
[0].events
= POLLIN
;
11033 pfd
[1].fd
= STDIN_FILENO
;
11034 pfd
[1].events
= POLLIN
;
11037 while ((evt
= xcb_poll_for_event(conn
))) {
11044 /* If just (re)started, set default focus if needed. */
11048 if (focus_mode
!= SWM_FOCUS_FOLLOW
) {
11049 r
= TAILQ_FIRST(&screens
[0].rl
);
11058 num_readable
= poll(pfd
, bar_extra
? 2 : 1, 1000);
11059 if (num_readable
== -1) {
11060 DNPRINTF(SWM_D_MISC
, "poll failed: %s", strerror(errno
));
11061 } else if (num_readable
> 0 && bar_extra
&& pfd
[1].revents
& POLLIN
) {
11062 stdin_ready
= true;
11066 restart(NULL
, NULL
);
11075 stdin_ready
= false;
11076 bar_extra_update();
11083 shutdown_cleanup();