forked from conformal/spectrwm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspectrwm.c
13952 lines (12018 loc) · 340 KB
/
spectrwm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2009-2019 Marco Peereboom <[email protected]>
* Copyright (c) 2009-2011 Ryan McBride <[email protected]>
* Copyright (c) 2009 Darrin Chandler <[email protected]>
* Copyright (c) 2009 Pierre-Yves Ritschard <[email protected]>
* Copyright (c) 2010 Tuukka Kataja <[email protected]>
* Copyright (c) 2011 Jason L. Wright <[email protected]>
* Copyright (c) 2011-2021 Reginald Kennedy <[email protected]>
* Copyright (c) 2011-2012 Lawrence Teo <[email protected]>
* Copyright (c) 2011-2012 Tiago Cunha <[email protected]>
* Copyright (c) 2012-2015 David Hill <[email protected]>
* Copyright (c) 2014-2015 Yuri D'Elia <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* kernel includes */
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/queue.h>
#if !defined(__OpenBSD__)
#include "queue_compat.h"
#endif
#include <sys/param.h>
#include <sys/select.h>
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/tree.h>
#else
#include "tree.h"
#endif
/* /usr/includes */
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <poll.h>
#include <fcntl.h>
#include <locale.h>
#include <paths.h>
#include <pwd.h>
#include <regex.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#if defined(__FreeBSD__)
#include <libutil.h>
#else
#include <util.h>
#endif
#include <X11/cursorfont.h>
#include <X11/extensions/Xrandr.h>
#include <X11/Xcursor/Xcursor.h>
#include <X11/Xft/Xft.h>
#include <X11/Xlib-xcb.h>
#include <xcb/xcb.h>
#include <xcb/xcb_atom.h>
#include <xcb/xcb_aux.h>
#include <xcb/xcb_event.h>
#include <xcb/xcb_icccm.h>
#include <xcb/xcb_keysyms.h>
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#include <xcb/xinput.h>
#define SWM_XCB_HAS_XINPUT
#endif
#include <xcb/xtest.h>
#include <xcb/randr.h>
/* local includes */
#include "version.h"
#ifdef __OSX__
#include <osx.h>
#endif
/* singly-linked tail queue macros appeared in OpenBSD 6.9 */
#ifndef STAILQ_HEAD
#define STAILQ_HEAD SIMPLEQ_HEAD
#define STAILQ_HEAD_INITIALIZER SIMPLEQ_HEAD_INITIALIZER
#define STAILQ_ENTRY SIMPLEQ_ENTRY
#define STAILQ_FIRST SIMPLEQ_FIRST
#define STAILQ_END SIMPLEQ_END
#define STAILQ_EMPTY SIMPLEQ_EMPTY
#define STAILQ_NEXT SIMPLEQ_NEXT
#define STAILQ_FOREACH SIMPLEQ_FOREACH
#define STAILQ_FOREACH_SAFE SIMPLEQ_FOREACH_SAFE
#define STAILQ_INIT SIMPLEQ_INIT
#define STAILQ_INSERT_HEAD SIMPLEQ_INSERT_HEAD
#define STAILQ_INSERT_TAIL SIMPLEQ_INSERT_TAIL
#define STAILQ_INSERT_AFTER SIMPLEQ_INSERT_AFTER
#define STAILQ_REMOVE_HEAD SIMPLEQ_REMOVE_HEAD
#define STAILQ_REMOVE_AFTER SIMPLEQ_REMOVE_AFTER
/*#define STAILQ_REMOVE*/
#define STAILQ_CONCAT SIMPLEQ_CONCAT
/*#define STAILQ_LAST*/
#endif
#ifdef SPECTRWM_BUILDSTR
static const char *buildstr = SPECTRWM_BUILDSTR;
#else
static const char *buildstr = SPECTRWM_VERSION;
#endif
#if !defined(__CYGWIN__) /* cygwin chokes on randr stuff */
# if RANDR_MAJOR < 1
# error RandR versions less than 1.0 are not supported
#endif
# if RANDR_MAJOR >= 1
# if RANDR_MINOR >= 2
# define SWM_XRR_HAS_CRTC
# endif
# endif
#endif /* __CYGWIN__ */
#ifndef XCB_ICCCM_NUM_WM_HINTS_ELEMENTS
#define XCB_ICCCM_SIZE_HINT_P_MIN_SIZE XCB_SIZE_HINT_P_MIN_SIZE
#define XCB_ICCCM_SIZE_HINT_P_MAX_SIZE XCB_SIZE_HINT_P_MAX_SIZE
#define XCB_ICCCM_SIZE_HINT_P_RESIZE_INC XCB_SIZE_HINT_P_RESIZE_INC
#define XCB_ICCCM_WM_HINT_INPUT XCB_WM_HINT_INPUT
#define XCB_ICCCM_WM_HINT_X_URGENCY XCB_WM_HINT_X_URGENCY
#define XCB_ICCCM_WM_STATE_ICONIC XCB_WM_STATE_ICONIC
#define XCB_ICCCM_WM_STATE_WITHDRAWN XCB_WM_STATE_WITHDRAWN
#define XCB_ICCCM_WM_STATE_NORMAL XCB_WM_STATE_NORMAL
#define xcb_icccm_get_text_property_reply_t xcb_get_text_property_reply_t
#define xcb_icccm_get_text_property_reply_wipe xcb_get_text_property_reply_wipe
#define xcb_icccm_get_wm_class xcb_get_wm_class
#define xcb_icccm_get_wm_class_reply xcb_get_wm_class_reply
#define xcb_icccm_get_wm_class_reply_t xcb_get_wm_class_reply_t
#define xcb_icccm_get_wm_class_reply_wipe xcb_get_wm_class_reply_wipe
#define xcb_icccm_get_wm_hints xcb_get_wm_hints
#define xcb_icccm_wm_hints_get_urgency xcb_wm_hints_get_urgency
#define xcb_icccm_get_wm_hints_reply xcb_get_wm_hints_reply
#define xcb_icccm_get_wm_name xcb_get_wm_name
#define xcb_icccm_get_wm_name_reply xcb_get_wm_name_reply
#define xcb_icccm_get_wm_normal_hints xcb_get_wm_normal_hints
#define xcb_icccm_get_wm_normal_hints_reply xcb_get_wm_normal_hints_reply
#define xcb_icccm_get_wm_protocols xcb_get_wm_protocols
#define xcb_icccm_get_wm_protocols_reply xcb_get_wm_protocols_reply
#define xcb_icccm_get_wm_protocols_reply_t xcb_get_wm_protocols_reply_t
#define xcb_icccm_get_wm_protocols_reply_wipe xcb_get_wm_protocols_reply_wipe
#define xcb_icccm_get_wm_transient_for xcb_get_wm_transient_for
#define xcb_icccm_get_wm_transient_for_reply xcb_get_wm_transient_for_reply
#define xcb_icccm_wm_hints_t xcb_wm_hints_t
#endif
/*#define SWM_DEBUG*/
#ifdef SWM_DEBUG
#define DPRINTF(x...) do { \
if (swm_debug) \
fprintf(stderr, x); \
} while (0)
#define DNPRINTF(n, fmt, args...) do { \
if (swm_debug & n) \
fprintf(stderr, "%ld %s: " fmt, \
(long)(time(NULL) - time_started), __func__, ## args); \
} while (0)
#define SWM_D_MISC 0x0001
#define SWM_D_EVENT 0x0002
#define SWM_D_WS 0x0004
#define SWM_D_FOCUS 0x0008
#define SWM_D_MOVE 0x0010
#define SWM_D_STACK 0x0020
#define SWM_D_MOUSE 0x0040
#define SWM_D_PROP 0x0080
#define SWM_D_CLASS 0x0100
#define SWM_D_KEY 0x0200
#define SWM_D_QUIRK 0x0400
#define SWM_D_SPAWN 0x0800
#define SWM_D_EVENTQ 0x1000
#define SWM_D_CONF 0x2000
#define SWM_D_BAR 0x4000
#define SWM_D_INIT 0x8000
uint32_t swm_debug = 0
| SWM_D_MISC
| SWM_D_EVENT
| SWM_D_WS
| SWM_D_FOCUS
| SWM_D_MOVE
| SWM_D_STACK
| SWM_D_MOUSE
| SWM_D_PROP
| SWM_D_CLASS
| SWM_D_KEY
| SWM_D_QUIRK
| SWM_D_SPAWN
| SWM_D_EVENTQ
| SWM_D_CONF
| SWM_D_BAR
| SWM_D_INIT
;
#else
#define DPRINTF(x...)
#define DNPRINTF(n,x...)
#endif
#define ALLOCSTR(s, x...) do { \
if (s && asprintf(s, x) == -1) \
err(1, "asprintf"); \
} while (0)
#define SWM_EWMH_ACTION_COUNT_MAX (8)
#define EWMH_F_FULLSCREEN (0x001)
#define EWMH_F_ABOVE (0x002)
#define EWMH_F_HIDDEN (0x004)
#define EWMH_F_MAXIMIZED_VERT (0x008)
#define EWMH_F_MAXIMIZED_HORZ (0x010)
#define EWMH_F_SKIP_PAGER (0x020)
#define EWMH_F_SKIP_TASKBAR (0x040)
#define SWM_F_MANUAL (0x080)
#define EWMH_F_MAXIMIZED (EWMH_F_MAXIMIZED_VERT | EWMH_F_MAXIMIZED_HORZ)
/* convert 8-bit to 16-bit */
#define RGB_8_TO_16(col) (((col) << 8) + (col))
#define PIXEL_TO_XRENDERCOLOR(px, xrc) \
xrc.red = RGB_8_TO_16((px) >> 16 & 0xff); \
xrc.green = RGB_8_TO_16((px) >> 8 & 0xff); \
xrc.blue = RGB_8_TO_16((px) & 0xff); \
xrc.alpha = 0xffff;
#define LENGTH(x) (int)(sizeof (x) / sizeof (x)[0])
#define MODKEY XCB_MOD_MASK_1
#define ANYMOD XCB_MOD_MASK_ANY
#define CLEANMASK(mask) ((mask) & (XCB_KEY_BUT_MASK_SHIFT | \
XCB_KEY_BUT_MASK_CONTROL | XCB_KEY_BUT_MASK_MOD_1 | \
XCB_KEY_BUT_MASK_MOD_2 | XCB_KEY_BUT_MASK_MOD_3 | \
XCB_KEY_BUT_MASK_MOD_4 | XCB_KEY_BUT_MASK_MOD_5) & ~(numlockmask))
#define BUTTONMASK (XCB_EVENT_MASK_BUTTON_PRESS | \
XCB_EVENT_MASK_BUTTON_RELEASE)
#define MOUSEMASK (BUTTONMASK|XCB_EVENT_MASK_POINTER_MOTION)
#define SWM_PROPLEN (16)
#define SWM_FUNCNAME_LEN (32)
#define SWM_QUIRK_LEN (64)
#define X(r) ((r)->g.x)
#define Y(r) ((r)->g.y)
#define WIDTH(r) ((r)->g.w)
#define HEIGHT(r) ((r)->g.h)
#define MAX_X(r) ((r)->g.x + (r)->g.w)
#define MAX_Y(r) ((r)->g.y + (r)->g.h)
#define SH_MIN(w) ((w)->sh.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE)
#define SH_MIN_W(w) ((w)->sh.min_width)
#define SH_MIN_H(w) ((w)->sh.min_height)
#define SH_MAX(w) ((w)->sh.flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE)
#define SH_MAX_W(w) ((w)->sh.max_width)
#define SH_MAX_H(w) ((w)->sh.max_height)
#define SH_INC(w) ((w)->sh.flags & XCB_ICCCM_SIZE_HINT_P_RESIZE_INC)
#define SH_INC_W(w) ((w)->sh.width_inc)
#define SH_INC_H(w) ((w)->sh.height_inc)
#define SWM_MAX_FONT_STEPS (3)
#define WINID(w) ((w) ? (w)->id : XCB_WINDOW_NONE)
#define ACCEPTS_FOCUS(w) (!((w)->hints.flags & XCB_ICCCM_WM_HINT_INPUT) \
|| ((w)->hints.input))
#define WS_FOCUSED(ws) ((ws)->r && (ws)->r->s->r_focus == (ws)->r)
#define YESNO(x) ((x) ? "yes" : "no")
#define ICONIC(w) ((w)->ewmh_flags & EWMH_F_HIDDEN)
#define ABOVE(w) ((w)->ewmh_flags & EWMH_F_ABOVE)
#define FULLSCREEN(w) ((w)->ewmh_flags & EWMH_F_FULLSCREEN)
#define MAXIMIZED_VERT(w) ((w)->ewmh_flags & EWMH_F_MAXIMIZED_VERT)
#define MAXIMIZED_HORZ(w) ((w)->ewmh_flags & EWMH_F_MAXIMIZED_HORZ)
#define MAXIMIZED(w) (MAXIMIZED_VERT(w) || MAXIMIZED_HORZ(w))
#define MANUAL(w) ((w)->ewmh_flags & SWM_F_MANUAL)
#define TRANS(w) ((w)->transient != XCB_WINDOW_NONE)
#define FLOATING(w) (ABOVE(w) || TRANS(w) || FULLSCREEN(w) || \
MAXIMIZED(w))
/* Constrain Window flags */
#define SWM_CW_RESIZABLE (0x01)
#define SWM_CW_SOFTBOUNDARY (0x02)
#define SWM_CW_HARDBOUNDARY (0x04)
#define SWM_CW_RIGHT (0x10)
#define SWM_CW_LEFT (0x20)
#define SWM_CW_BOTTOM (0x40)
#define SWM_CW_TOP (0x80)
#define SWM_CW_ALLSIDES (0xf0)
#define SWM_FOCUS_DEFAULT (0)
#define SWM_FOCUS_FOLLOW (1)
#define SWM_FOCUS_MANUAL (2)
#define SWM_COUNT_TILED (1 << 0)
#define SWM_COUNT_FLOATING (1 << 1)
#define SWM_COUNT_ICONIC (1 << 2)
#define SWM_COUNT_NORMAL (SWM_COUNT_TILED | SWM_COUNT_FLOATING)
#define SWM_COUNT_ALL (SWM_COUNT_NORMAL | SWM_COUNT_ICONIC)
#define SWM_WIN_UNFOCUS (1 << 0)
#define SWM_WIN_NOUNMAP (1 << 1)
#define SWM_CK_ALL (0xf)
#define SWM_CK_FOCUS (0x1)
#define SWM_CK_POINTER (0x2)
#define SWM_CK_FALLBACK (0x4)
#define SWM_CK_REGION (0x8)
#define SWM_WSI_LISTCURRENT (0x001)
#define SWM_WSI_LISTACTIVE (0x002)
#define SWM_WSI_LISTEMPTY (0x004)
#define SWM_WSI_LISTNAMED (0x008)
#define SWM_WSI_LISTURGENT (0x010)
#define SWM_WSI_LISTALL (0x0ff)
#define SWM_WSI_HIDECURRENT (0x100)
#define SWM_WSI_MARKCURRENT (0x200)
#define SWM_WSI_MARKURGENT (0x400)
#define SWM_WSI_MARKACTIVE (0x800)
#define SWM_WSI_MARKEMPTY (0x1000)
#define SWM_WSI_PRINTNAMES (0x2000)
#define SWM_WSI_NOINDEXES (0x4000)
#define SWM_WSI_DEFAULT (SWM_WSI_LISTCURRENT | SWM_WSI_LISTACTIVE | \
SWM_WSI_MARKCURRENT | SWM_WSI_PRINTNAMES)
#define SWM_WM_CLASS_INSTANCE "spectrwm"
#define SWM_WM_CLASS_BAR "panel"
#define SWM_CONF_DEFAULT (0)
#define SWM_CONF_KEYMAPPING (1)
#ifndef SWM_LIB
#define SWM_LIB "/usr/local/lib/libswmhack.so"
#endif
char **start_argv;
xcb_atom_t a_state;
xcb_atom_t a_prot;
xcb_atom_t a_delete;
xcb_atom_t a_net_frame_extents;
xcb_atom_t a_net_wm_check;
xcb_atom_t a_net_supported;
xcb_atom_t a_takefocus;
xcb_atom_t a_utf8_string;
xcb_atom_t a_swm_ws;
volatile sig_atomic_t running = 1;
volatile sig_atomic_t restart_wm = 0;
xcb_timestamp_t last_event_time = 0;
int outputs = 0;
bool randr_support = false;
int randr_eventbase;
unsigned int numlockmask = 0;
bool xinput2_support = false;
Display *display;
xcb_connection_t *conn;
xcb_key_symbols_t *syms;
int boundary_width = 50;
bool cycle_empty = false;
bool cycle_visible = false;
int term_width = 0;
int font_adjusted = 0;
uint16_t mod_key = MODKEY;
bool warp_focus = false;
bool warp_pointer = false;
bool workspace_clamp = false;
/* dmenu search */
struct swm_region *search_r;
int select_list_pipe[2];
int select_resp_pipe[2];
pid_t searchpid;
volatile sig_atomic_t search_resp;
int search_resp_action;
struct search_window {
TAILQ_ENTRY(search_window) entry;
int idx;
struct ws_win *win;
xcb_gcontext_t gc;
xcb_window_t indicator;
};
TAILQ_HEAD(search_winlist, search_window) search_wl =
TAILQ_HEAD_INITIALIZER(search_wl);
/* search actions */
enum {
SWM_SEARCH_NONE,
SWM_SEARCH_UNICONIFY,
SWM_SEARCH_NAME_WORKSPACE,
SWM_SEARCH_SEARCH_WORKSPACE,
SWM_SEARCH_SEARCH_WINDOW
};
#define SWM_STACK_TOP (0)
#define SWM_STACK_BOTTOM (1)
#define SWM_STACK_ABOVE (2)
#define SWM_STACK_BELOW (3)
/* dialog windows */
double dialog_ratio = 0.6;
/* status bar */
#define SWM_BAR_MAX (1024)
#define SWM_BAR_JUSTIFY_LEFT (0)
#define SWM_BAR_JUSTIFY_CENTER (1)
#define SWM_BAR_JUSTIFY_RIGHT (2)
#define SWM_BAR_OFFSET (4)
#define SWM_BAR_FONTS "-*-terminus-medium-*-*-*-12-*-*-*-*-*-*-*," \
"-*-profont-*-*-*-*-12-*-*-*-*-*-*-*," \
"-*-times-medium-r-*-*-12-*-*-*-*-*-*-*," \
"-misc-fixed-medium-r-*-*-12-*-*-*-*-*-*-*," \
"-*-*-*-r-*-*-*-*-*-*-*-*-*-*"
#define SWM_BAR_MAX_FONTS (10)
#define SWM_BAR_MAX_COLORS (10)
#ifdef X_HAVE_UTF8_STRING
#define DRAWSTRING(x...) Xutf8DrawString(x)
#define TEXTEXTENTS(x...) Xutf8TextExtents(x)
#else
#define DRAWSTRING(x...) XmbDrawString(x)
#define TEXTEXTENTS(x...) XmbTextExtents(x)
#endif
char *bar_argv[] = { NULL, NULL };
int bar_pipe[2];
char bar_ext[SWM_BAR_MAX];
char bar_ext_buf[SWM_BAR_MAX];
char bar_vertext[SWM_BAR_MAX];
bool bar_version = false;
bool bar_enabled = true;
int bar_border_width = 1;
bool bar_at_bottom = false;
bool bar_extra = false;
int bar_height = 0;
int bar_justify = SWM_BAR_JUSTIFY_LEFT;
char *bar_format = NULL;
bool bar_action_expand = false;
bool stack_enabled = true;
bool clock_enabled = true;
bool iconic_enabled = false;
bool maximize_hide_bar = false;
bool urgent_enabled = false;
bool urgent_collapse = false;
char *clock_format = NULL;
bool window_class_enabled = false;
bool window_instance_enabled = false;
bool window_name_enabled = false;
uint32_t workspace_indicator = SWM_WSI_DEFAULT;
int focus_mode = SWM_FOCUS_DEFAULT;
int focus_close = SWM_STACK_BELOW;
bool focus_close_wrap = true;
int focus_default = SWM_STACK_TOP;
int spawn_position = SWM_STACK_TOP;
bool disable_border = false;
bool disable_border_always = false;
int border_width = 1;
int region_padding = 0;
int tile_gap = 0;
bool verbose_layout = false;
#ifdef SWM_DEBUG
bool debug_enabled;
time_t time_started;
#endif
pid_t bar_pid;
XFontSet bar_fs = NULL;
XFontSetExtents *bar_fs_extents;
char *bar_fontnames[SWM_BAR_MAX_FONTS];
XftFont *bar_xftfonts[SWM_BAR_MAX_FONTS + 1];
int num_xftfonts;
char *bar_fontname_pua;
int font_pua_index;
bool bar_font_legacy = true;
char *bar_fonts = NULL;
XftColor bar_fg_colors[SWM_BAR_MAX_COLORS];
int num_fg_colors = 1;
int num_bg_colors = 1;
XftColor search_font_color;
char *startup_exception = NULL;
unsigned int nr_exceptions = 0;
char *workspace_mark_current = NULL;
char *workspace_mark_urgent = NULL;
char *workspace_mark_active = NULL;
char *workspace_mark_empty = NULL;
char *stack_mark_max = NULL;
char *stack_mark_vertical = NULL;
char *stack_mark_vertical_flip = NULL;
char *stack_mark_horizontal = NULL;
char *stack_mark_horizontal_flip = NULL;
/* layout manager data */
struct swm_geometry {
int x;
int y;
int w;
int h;
};
struct swm_screen;
struct workspace;
struct swm_bar {
xcb_window_t id;
xcb_pixmap_t buffer;
struct swm_geometry g;
struct swm_region *r; /* Associated region. */
};
/* virtual "screens" */
struct swm_region {
TAILQ_ENTRY(swm_region) entry;
xcb_window_t id;
struct swm_geometry g;
struct workspace *ws; /* current workspace on this region */
struct workspace *ws_prior; /* prior workspace on this region */
struct swm_screen *s; /* screen idx */
struct swm_bar *bar;
};
TAILQ_HEAD(swm_region_list, swm_region);
enum {
SWM_WIN_STATE_REPARENTING,
SWM_WIN_STATE_REPARENTED,
SWM_WIN_STATE_UNPARENTING,
SWM_WIN_STATE_UNPARENTED,
};
struct ws_win {
TAILQ_ENTRY(ws_win) entry;
TAILQ_ENTRY(ws_win) stack_entry;
xcb_window_t id;
xcb_window_t frame;
xcb_window_t transient;
xcb_visualid_t visual;
struct ws_win *focus_redirect;/* focus on transient */
struct swm_geometry g; /* current geometry */
struct swm_geometry g_prev; /* prev configured geometry */
struct swm_geometry g_float; /* region coordinates */
bool g_floatvalid; /* g_float geometry validity */
bool mapped;
uint8_t state;
bool bordered;
uint32_t ewmh_flags;
int font_size_boundary[SWM_MAX_FONT_STEPS];
int font_steps;
int last_inc;
bool can_delete;
bool take_focus;
uint32_t quirks;
struct workspace *ws; /* always valid */
struct swm_screen *s; /* always valid, never changes */
xcb_size_hints_t sh;
xcb_icccm_get_wm_class_reply_t ch;
xcb_icccm_wm_hints_t hints;
#ifdef SWM_DEBUG
xcb_window_t debug;
#endif
};
TAILQ_HEAD(ws_win_list, ws_win);
TAILQ_HEAD(ws_win_stack, ws_win);
/* pid goo */
struct pid_e {
TAILQ_ENTRY(pid_e) entry;
pid_t pid;
int ws;
};
TAILQ_HEAD(pid_list, pid_e) pidlist = TAILQ_HEAD_INITIALIZER(pidlist);
/* layout handlers */
void stack(struct swm_region *);
void vertical_config(struct workspace *, int);
void vertical_stack(struct workspace *, struct swm_geometry *);
void horizontal_config(struct workspace *, int);
void horizontal_stack(struct workspace *, struct swm_geometry *);
void max_stack(struct workspace *, struct swm_geometry *);
void plain_stacker(struct workspace *);
void fancy_stacker(struct workspace *);
struct layout {
void (*l_stack)(struct workspace *, struct swm_geometry *);
void (*l_config)(struct workspace *, int);
uint32_t flags;
#define SWM_L_FOCUSPREV (1 << 0)
#define SWM_L_MAPONFOCUS (1 << 1)
void (*l_string)(struct workspace *);
} layouts[] = {
/* stack, configure */
{ vertical_stack, vertical_config, 0, plain_stacker },
{ horizontal_stack, horizontal_config, 0, plain_stacker },
{ max_stack, NULL,
SWM_L_MAPONFOCUS | SWM_L_FOCUSPREV, plain_stacker },
{ NULL, NULL, 0, NULL },
};
/* position of max_stack mode in the layouts array, index into layouts! */
#define SWM_V_STACK (0)
#define SWM_H_STACK (1)
#define SWM_MAX_STACK (2)
#define SWM_H_SLICE (32)
#define SWM_V_SLICE (32)
/* define work spaces */
struct workspace {
int idx; /* workspace index */
char *name; /* workspace name */
bool always_raise; /* raise windows on focus */
bool bar_enabled; /* bar visibility */
struct layout *cur_layout; /* current layout handlers */
struct ws_win *focus; /* may be NULL */
struct ws_win *focus_prev; /* may be NULL */
struct ws_win *focus_pending; /* may be NULL */
struct ws_win *focus_raise; /* may be NULL */
struct swm_region *r; /* may be NULL */
struct swm_region *old_r; /* may be NULL */
struct ws_win_list winlist; /* list of windows in ws */
struct ws_win_stack stack; /* stacking order */
int state; /* mapping state */
char stacker[10]; /* display stacker and layout */
/* stacker state */
struct {
int horizontal_msize;
int horizontal_mwin;
int horizontal_stacks;
bool horizontal_flip;
int vertical_msize;
int vertical_mwin;
int vertical_stacks;
bool vertical_flip;
} l_state;
};
enum {
SWM_WS_STATE_HIDDEN,
SWM_WS_STATE_MAPPING,
SWM_WS_STATE_MAPPED,
};
enum {
SWM_S_COLOR_BAR,
SWM_S_COLOR_BAR1,
SWM_S_COLOR_BAR2,
SWM_S_COLOR_BAR3,
SWM_S_COLOR_BAR4,
SWM_S_COLOR_BAR5,
SWM_S_COLOR_BAR6,
SWM_S_COLOR_BAR7,
SWM_S_COLOR_BAR8,
SWM_S_COLOR_BAR9,
SWM_S_COLOR_BAR_SELECTED,
SWM_S_COLOR_BAR_BORDER,
SWM_S_COLOR_BAR_BORDER_UNFOCUS,
SWM_S_COLOR_BAR_FONT,
SWM_S_COLOR_BAR_FONT1,
SWM_S_COLOR_BAR_FONT2,
SWM_S_COLOR_BAR_FONT3,
SWM_S_COLOR_BAR_FONT4,
SWM_S_COLOR_BAR_FONT5,
SWM_S_COLOR_BAR_FONT6,
SWM_S_COLOR_BAR_FONT7,
SWM_S_COLOR_BAR_FONT8,
SWM_S_COLOR_BAR_FONT9,
SWM_S_COLOR_BAR_FONT_SELECTED,
SWM_S_COLOR_FOCUS,
SWM_S_COLOR_FOCUS_MAXIMIZED,
SWM_S_COLOR_UNFOCUS,
SWM_S_COLOR_UNFOCUS_MAXIMIZED,
SWM_S_COLOR_MAX
};
/* physical screen mapping */
#define SWM_WS_MAX (22) /* hard limit */
int workspace_limit = 10; /* soft limit */
#define SWM_RATE_DEFAULT (60) /* Default for swm_screen. */
struct swm_screen {
int idx; /* screen index */
struct swm_region_list rl; /* list of regions on this screen */
struct swm_region_list orl; /* list of old regions */
xcb_window_t root;
struct workspace ws[SWM_WS_MAX];
struct swm_region *r_focus;
/* colors */
struct {
uint32_t pixel;
char *name;
int manual;
} c[SWM_S_COLOR_MAX];
uint8_t depth;
xcb_timestamp_t rate; /* Max updates/sec for move and resize */
xcb_visualid_t visual;
Visual *xvisual; /* Needed for Xft. */
xcb_colormap_t colormap;
xcb_gcontext_t gc;
};
struct swm_screen *screens;
/* args to functions */
union arg {
int id;
#define SWM_ARG_ID_FOCUSNEXT (0)
#define SWM_ARG_ID_FOCUSPREV (1)
#define SWM_ARG_ID_FOCUSMAIN (2)
#define SWM_ARG_ID_FOCUSURGENT (3)
#define SWM_ARG_ID_SWAPNEXT (10)
#define SWM_ARG_ID_SWAPPREV (11)
#define SWM_ARG_ID_SWAPMAIN (12)
#define SWM_ARG_ID_MOVELAST (13)
#define SWM_ARG_ID_MASTERSHRINK (20)
#define SWM_ARG_ID_MASTERGROW (21)
#define SWM_ARG_ID_MASTERADD (22)
#define SWM_ARG_ID_MASTERDEL (23)
#define SWM_ARG_ID_FLIPLAYOUT (24)
#define SWM_ARG_ID_STACKRESET (30)
#define SWM_ARG_ID_STACKINIT (31)
#define SWM_ARG_ID_STACKBALANCE (32)
#define SWM_ARG_ID_CYCLEWS_UP (40)
#define SWM_ARG_ID_CYCLEWS_DOWN (41)
#define SWM_ARG_ID_CYCLERG_UP (42)
#define SWM_ARG_ID_CYCLERG_DOWN (43)
#define SWM_ARG_ID_CYCLEWS_UP_ALL (44)
#define SWM_ARG_ID_CYCLEWS_DOWN_ALL (45)
#define SWM_ARG_ID_CYCLEWS_MOVE_UP (46)
#define SWM_ARG_ID_CYCLEWS_MOVE_DOWN (47)
#define SWM_ARG_ID_STACKINC (50)
#define SWM_ARG_ID_STACKDEC (51)
#define SWM_ARG_ID_CYCLE_LAYOUT (60)
#define SWM_ARG_ID_LAYOUT_VERTICAL (61)
#define SWM_ARG_ID_LAYOUT_HORIZONTAL (62)
#define SWM_ARG_ID_LAYOUT_MAX (63)
#define SWM_ARG_ID_DONTCENTER (70)
#define SWM_ARG_ID_CENTER (71)
#define SWM_ARG_ID_KILLWINDOW (80)
#define SWM_ARG_ID_DELETEWINDOW (81)
#define SWM_ARG_ID_WIDTHGROW (90)
#define SWM_ARG_ID_WIDTHSHRINK (91)
#define SWM_ARG_ID_HEIGHTGROW (92)
#define SWM_ARG_ID_HEIGHTSHRINK (93)
#define SWM_ARG_ID_MOVEUP (100)
#define SWM_ARG_ID_MOVEDOWN (101)
#define SWM_ARG_ID_MOVELEFT (102)
#define SWM_ARG_ID_MOVERIGHT (103)
#define SWM_ARG_ID_BAR_TOGGLE (110)
#define SWM_ARG_ID_BAR_TOGGLE_WS (111)
#define SWM_ARG_ID_CYCLERG_MOVE_UP (112)
#define SWM_ARG_ID_CYCLERG_MOVE_DOWN (113)
#define SWM_ARG_ID_WS_EMPTY (120)
#define SWM_ARG_ID_WS_EMPTY_MOVE (121)
#define SWM_ARG_ID_RESTARTOFDAY (130)
char **argv;
};
/* quirks */
struct quirk {
TAILQ_ENTRY(quirk) entry;
char *class; /* WM_CLASS:class */
char *instance; /* WM_CLASS:instance */
char *name; /* WM_NAME */
regex_t regex_class;
regex_t regex_instance;
regex_t regex_name;
uint32_t quirk;
int ws; /* Initial workspace. */
#define SWM_Q_FLOAT (1 << 0) /* Float this window. */
#define SWM_Q_TRANSSZ (1 << 1) /* Transient window size too small. */
#define SWM_Q_ANYWHERE (1 << 2) /* Don't position this window */
#define SWM_Q_XTERM_FONTADJ (1 << 3) /* Adjust xterm fonts when resizing. */
#define SWM_Q_FULLSCREEN (1 << 4) /* Remove border when fullscreen. */
#define SWM_Q_FOCUSPREV (1 << 5) /* Focus on caller. */
#define SWM_Q_NOFOCUSONMAP (1 << 6) /* Don't focus on window when mapped.*/
#define SWM_Q_FOCUSONMAP_SINGLE (1 << 7) /* Only focus if single win of type. */
#define SWM_Q_OBEYAPPFOCUSREQ (1 << 8) /* Focus when applications ask. */
#define SWM_Q_IGNOREPID (1 << 9) /* Ignore PID when determining ws. */
#define SWM_Q_IGNORESPAWNWS (1 << 10)/* Ignore _SWM_WS when managing win. */
#define SWM_Q_NOFOCUSCYCLE (1 << 11)/* Remove from normal focus cycle. */
#define SWM_Q_MINIMALBORDER (1 << 12)/* No border when floating/unfocused.*/
};
TAILQ_HEAD(quirk_list, quirk) quirks = TAILQ_HEAD_INITIALIZER(quirks);
/*
* Supported EWMH hints should be added to
* both the enum and the ewmh array
*/
enum {
_NET_ACTIVE_WINDOW,
_NET_CLIENT_LIST,
_NET_CLOSE_WINDOW,
_NET_CURRENT_DESKTOP,
_NET_DESKTOP_GEOMETRY,
_NET_DESKTOP_NAMES,
_NET_DESKTOP_VIEWPORT,
_NET_MOVERESIZE_WINDOW,
_NET_NUMBER_OF_DESKTOPS,
_NET_REQUEST_FRAME_EXTENTS,
_NET_RESTACK_WINDOW,
_NET_WM_ACTION_ABOVE,
_NET_WM_ACTION_CLOSE,
_NET_WM_ACTION_FULLSCREEN,
_NET_WM_ACTION_MOVE,
_NET_WM_ACTION_RESIZE,
_NET_WM_ALLOWED_ACTIONS,
_NET_WM_DESKTOP,
_NET_WM_FULL_PLACEMENT,
_NET_WM_NAME,
_NET_WM_STATE,
_NET_WM_STATE_ABOVE,
_NET_WM_STATE_FULLSCREEN,
_NET_WM_STATE_HIDDEN,
_NET_WM_STATE_MAXIMIZED_VERT,
_NET_WM_STATE_MAXIMIZED_HORZ,
_NET_WM_STATE_SKIP_PAGER,
_NET_WM_STATE_SKIP_TASKBAR,
_NET_WM_WINDOW_TYPE,
_NET_WM_WINDOW_TYPE_DIALOG,
_NET_WM_WINDOW_TYPE_DOCK,
_NET_WM_WINDOW_TYPE_NORMAL,
_NET_WM_WINDOW_TYPE_SPLASH,
_NET_WM_WINDOW_TYPE_TOOLBAR,
_NET_WM_WINDOW_TYPE_UTILITY,
_SWM_WM_STATE_MANUAL,
SWM_EWMH_HINT_MAX
};
struct ewmh_hint {
char *name;
xcb_atom_t atom;
} ewmh[SWM_EWMH_HINT_MAX] = {
/* must be in same order as in the enum */
{"_NET_ACTIVE_WINDOW", XCB_ATOM_NONE},
{"_NET_CLIENT_LIST", XCB_ATOM_NONE},
{"_NET_CLOSE_WINDOW", XCB_ATOM_NONE},
{"_NET_CURRENT_DESKTOP", XCB_ATOM_NONE},
{"_NET_DESKTOP_GEOMETRY", XCB_ATOM_NONE},
{"_NET_DESKTOP_NAMES", XCB_ATOM_NONE},
{"_NET_DESKTOP_VIEWPORT", XCB_ATOM_NONE},
{"_NET_MOVERESIZE_WINDOW", XCB_ATOM_NONE},
{"_NET_NUMBER_OF_DESKTOPS", XCB_ATOM_NONE},
{"_NET_REQUEST_FRAME_EXTENTS", XCB_ATOM_NONE},
{"_NET_RESTACK_WINDOW", XCB_ATOM_NONE},
{"_NET_WM_ACTION_ABOVE", XCB_ATOM_NONE},
{"_NET_WM_ACTION_CLOSE", XCB_ATOM_NONE},
{"_NET_WM_ACTION_FULLSCREEN", XCB_ATOM_NONE},
{"_NET_WM_ACTION_MOVE", XCB_ATOM_NONE},
{"_NET_WM_ACTION_RESIZE", XCB_ATOM_NONE},
{"_NET_WM_ALLOWED_ACTIONS", XCB_ATOM_NONE},
{"_NET_WM_DESKTOP", XCB_ATOM_NONE},
{"_NET_WM_FULL_PLACEMENT", XCB_ATOM_NONE},
{"_NET_WM_NAME", XCB_ATOM_NONE},
{"_NET_WM_STATE", XCB_ATOM_NONE},
{"_NET_WM_STATE_ABOVE", XCB_ATOM_NONE},
{"_NET_WM_STATE_FULLSCREEN", XCB_ATOM_NONE},
{"_NET_WM_STATE_HIDDEN", XCB_ATOM_NONE},
{"_NET_WM_STATE_MAXIMIZED_VERT", XCB_ATOM_NONE},
{"_NET_WM_STATE_MAXIMIZED_HORZ", XCB_ATOM_NONE},
{"_NET_WM_STATE_SKIP_PAGER", XCB_ATOM_NONE},
{"_NET_WM_STATE_SKIP_TASKBAR", XCB_ATOM_NONE},
{"_NET_WM_WINDOW_TYPE", XCB_ATOM_NONE},
{"_NET_WM_WINDOW_TYPE_DIALOG", XCB_ATOM_NONE},
{"_NET_WM_WINDOW_TYPE_DOCK", XCB_ATOM_NONE},
{"_NET_WM_WINDOW_TYPE_NORMAL", XCB_ATOM_NONE},
{"_NET_WM_WINDOW_TYPE_SPLASH", XCB_ATOM_NONE},
{"_NET_WM_WINDOW_TYPE_TOOLBAR", XCB_ATOM_NONE},
{"_NET_WM_WINDOW_TYPE_UTILITY", XCB_ATOM_NONE},
{"_SWM_WM_STATE_MANUAL", XCB_ATOM_NONE},
};
/* EWMH source type */
enum {
EWMH_SOURCE_TYPE_NONE = 0,
EWMH_SOURCE_TYPE_NORMAL = 1,
EWMH_SOURCE_TYPE_OTHER = 2,
};
/* Cursors */
enum {
XC_FLEUR,
XC_LEFT_PTR,
XC_BOTTOM_LEFT_CORNER,
XC_BOTTOM_RIGHT_CORNER,
XC_SIZING,
XC_TOP_LEFT_CORNER,
XC_TOP_RIGHT_CORNER,
XC_MAX
};
struct cursors {
char *name; /* Name used by Xcursor .*/
uint8_t cf_char; /* cursorfont index. */
xcb_cursor_t cid;
} cursors[XC_MAX] = {
{"fleur", XC_fleur, XCB_CURSOR_NONE},
{"left_ptr", XC_left_ptr, XCB_CURSOR_NONE},
{"bottom_left_corner", XC_bottom_left_corner, XCB_CURSOR_NONE},
{"bottom_right_corner", XC_bottom_right_corner, XCB_CURSOR_NONE},
{"sizing", XC_sizing, XCB_CURSOR_NONE},
{"top_left_corner", XC_top_left_corner, XCB_CURSOR_NONE},
{"top_right_corner", XC_top_right_corner, XCB_CURSOR_NONE},
};
#define SWM_TEXTFRAGS_MAX (SWM_BAR_MAX/4)
struct text_fragment {
char *text;
int length;
int font;
int width;
int fg;
int bg;
};
/* bar section */
struct bar_section {
char fmtrep[SWM_BAR_MAX * 2];
char fmtsplit[SWM_BAR_MAX * 2];
struct text_fragment frag[SWM_TEXTFRAGS_MAX];
bool fit_to_text;
int justify;
int weight;
int start;
int width;
int text_start;
int text_width;
int nfrags;
/* Needed for legacy font */
int height;
int ypos;
};
struct bar_section *bsect = NULL;
int maxsect = 0;
int numsect;
#define SWM_SPAWN_OPTIONAL 0x1
/* spawn */
struct spawn_prog {
TAILQ_ENTRY(spawn_prog) entry;
char *name;
int argc;
char **argv;
int flags;
};
TAILQ_HEAD(spawn_list, spawn_prog) spawns = TAILQ_HEAD_INITIALIZER(spawns);
enum {
FN_F_NOREPLAY = 0x1,
};
/* User callable function IDs. */
enum actionid {
FN_BAR_TOGGLE,
FN_BAR_TOGGLE_WS,
FN_BUTTON2,
FN_CYCLE_LAYOUT,
FN_FLIP_LAYOUT,
FN_FLOAT_TOGGLE,
FN_FOCUS,
FN_FOCUS_MAIN,
FN_FOCUS_NEXT,
FN_FOCUS_PREV,
FN_FOCUS_URGENT,
FN_FULLSCREEN_TOGGLE,
FN_MAXIMIZE_TOGGLE,
FN_HEIGHT_GROW,
FN_HEIGHT_SHRINK,
FN_ICONIFY,
FN_LAYOUT_VERTICAL,
FN_LAYOUT_HORIZONTAL,
FN_LAYOUT_MAX,
FN_MASTER_SHRINK,
FN_MASTER_GROW,
FN_MASTER_ADD,
FN_MASTER_DEL,
FN_MOVE,
FN_MOVE_DOWN,
FN_MOVE_LEFT,
FN_MOVE_RIGHT,
FN_MOVE_UP,
FN_MVRG_1,
FN_MVRG_2,
FN_MVRG_3,
FN_MVRG_4,
FN_MVRG_5,
FN_MVRG_6,
FN_MVRG_7,
FN_MVRG_8,
FN_MVRG_9,
KF_MVRG_NEXT,
KF_MVRG_PREV,
FN_MVWS_1,
FN_MVWS_2,