-
Notifications
You must be signed in to change notification settings - Fork 0
/
dwl.c
5085 lines (4427 loc) · 157 KB
/
dwl.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
/*
* See LICENSE file for copyright and license details.
*/
#define XWAYLNAD 1
#include <getopt.h>
#include <libinput.h>
#include <limits.h>
#include <linux/input-event-codes.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/backend/libinput.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_fractional_scale_v1.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_drm.h>
#include <wlr/types/wlr_data_control_v1.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_export_dmabuf_v1.h>
#include <wlr/types/wlr_gamma_control_v1.h>
#include <wlr/types/wlr_relative_pointer_v1.h>
#include <wlr/types/wlr_pointer_constraints_v1.h>
#include <wlr/util/region.h>
// #include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_idle_inhibit_v1.h>
#include <wlr/types/wlr_idle_notify_v1.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_input_inhibitor.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_layer_shell_v1.h>
#include <wlr/types/wlr_cursor_shape_v1.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output_management_v1.h>
#include <wlr/types/wlr_pointer.h>
#include <wlr/types/wlr_presentation_time.h>
#include <wlr/types/wlr_primary_selection.h>
#include <wlr/types/wlr_primary_selection_v1.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_screencopy_v1.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_server_decoration.h>
#include <wlr/types/wlr_session_lock_v1.h>
#include <wlr/types/wlr_single_pixel_buffer_v1.h>
#include <wlr/types/wlr_subcompositor.h>
#include <wlr/types/wlr_viewporter.h>
#include <wlr/types/wlr_virtual_keyboard_v1.h>
#include <wlr/types/wlr_virtual_pointer_v1.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_xdg_activation_v1.h>
#include <wlr/types/wlr_xdg_decoration_v1.h>
#include <wlr/types/wlr_xdg_output_v1.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/log.h>
#include <wlr/types/wlr_xdg_foreign_registry.h>
#include <wlr/types/wlr_xdg_foreign_v1.h>
#include <wlr/types/wlr_xdg_foreign_v2.h>
#include <xkbcommon/xkbcommon.h>
#ifdef XWAYLAND
#include <wlr/xwayland.h>
#include <X11/Xlib.h>
#include <xcb/xcb_icccm.h>
#endif
#include "dwl-ipc-unstable-v2-protocol.h"
#include "util.h"
#include "wlr_foreign_toplevel_management_v1.h"
/* macros */
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define CLEANMASK(mask) (mask & ~WLR_MODIFIER_CAPS)
#define VISIBLEON(C, M) ((M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags]))
#define LENGTH(X) (sizeof X / sizeof X[0])
#define END(A) ((A) + LENGTH(A))
#define TAGMASK ((1 << LENGTH(tags)) - 1)
#define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L)))
#define ISFULLSCREEN(A) ((A)->isfullscreen || (A)->isfakefullscreen || (A)->overview_isfakefullscreenbak || (A)->overview_isfullscreenbak)
#define LISTEN_STATIC(E, H) do { static struct wl_listener _l = {.notify = (H)}; wl_signal_add((E), &_l); } while (0)
/* enums */
/* enums */
enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
enum { XDGShell, LayerShell, X11 }; /* client types */
enum { AxisUp, AxisRight, AxisDown, AxisLeft }; //滚轮滚动的方向
enum { LyrBg, LyrBottom, LyrTile, LyrFloat, LyrFS, LyrTop, LyrOverlay,
#ifdef IM
LyrIMPopup,
#endif
LyrBlock, NUM_LAYERS }; /* scene layers */
#ifdef XWAYLAND
enum { NetWMWindowTypeDialog, NetWMWindowTypeSplash, NetWMWindowTypeToolbar,
NetWMWindowTypeUtility, NetLast }; /* EWMH atoms */
#endif
enum { UP, DOWN, LEFT, RIGHT }; /* movewin */
typedef union {
int i;
unsigned int ui;
float f;
const void *v;
} Arg;
typedef struct {
unsigned int mod;
unsigned int button;
void (*func)(const Arg *);
const Arg arg;
} Button; //鼠标按键
typedef struct {
unsigned int mod;
unsigned int dir;
void (*func)(const Arg *);
const Arg arg;
} Axis;
typedef struct Pertag Pertag;
typedef struct Monitor Monitor;
typedef struct {
/* Must keep these three elements in this order */
unsigned int type; /* XDGShell or X11* */
struct wlr_box geom,oldgeom; /* layout-relative, includes border */
Monitor *mon;
struct wlr_scene_tree *scene;
struct wlr_scene_rect *border[4]; /* top, bottom, left, right */
struct wlr_scene_tree *scene_surface;
struct wl_list link;
struct wl_list flink;
union {
struct wlr_xdg_surface *xdg;
struct wlr_xwayland_surface *xwayland;
} surface;
struct wl_listener commit;
struct wl_listener map;
struct wl_listener maximize;
struct wl_listener minimize;
struct wl_listener unmap;
struct wl_listener destroy;
struct wl_listener set_title;
struct wl_listener fullscreen;
struct wlr_box prev; /* layout-relative, includes border */
#ifdef XWAYLAND
struct wl_listener activate;
struct wl_listener associate;
struct wl_listener dissociate;
struct wl_listener configure;
struct wl_listener set_hints;
#endif
unsigned int bw;
unsigned int tags,oldtags;
struct wlr_foreign_toplevel_handle_v1 *foreign_toplevel;
int isfloating, isurgent, isfullscreen, istiled, isminied;
int isfakefullscreen;
int overview_backup_x, overview_backup_y, overview_backup_w,
overview_backup_h, overview_backup_bw;
int fullscreen_backup_x, fullscreen_backup_y, fullscreen_backup_w,
fullscreen_backup_h;
int overview_isfullscreenbak,overview_isfakefullscreenbak,overview_isfloatingbak;
uint32_t resize; /* configure serial of a pending resize */
struct wlr_xdg_toplevel_decoration_v1 *decoration;
struct wl_listener foreign_activate_request;
struct wl_listener foreign_fullscreen_request;
struct wl_listener foreign_close_request;
struct wl_listener foreign_destroy;
struct wl_listener set_decoration_mode;
struct wl_listener destroy_decoration;
unsigned int ignore_clear_fullscreen;
int isnoclip;
int is_in_scratchpad;
int is_scratchpad_show;
int isglobal;
int isnoborder;
int iskilling;
struct wlr_box bounds;
} Client;
typedef struct {
struct wl_list link;
struct wl_resource *resource;
Monitor *monitor;
} DwlIpcOutput;
typedef struct {
uint32_t mod;
xkb_keysym_t keysym;
void (*func)(const Arg *);
const Arg arg;
} Key;
typedef struct {
struct wl_list link;
struct wlr_keyboard *wlr_keyboard;
int nsyms;
const xkb_keysym_t *keysyms; /* invalid if nsyms == 0 */
uint32_t mods; /* invalid if nsyms == 0 */
struct wl_event_source *key_repeat_source;
struct wl_listener modifiers;
struct wl_listener key;
struct wl_listener destroy;
} Keyboard;
typedef struct {
/* Must keep these three elements in this order */
unsigned int type; /* LayerShell */
struct wlr_box geom;
Monitor *mon;
struct wlr_scene_tree *scene;
struct wlr_scene_tree *popups;
struct wlr_scene_layer_surface_v1 *scene_layer;
struct wl_list link;
int mapped;
struct wlr_layer_surface_v1 *layer_surface;
struct wl_listener destroy;
struct wl_listener map;
struct wl_listener unmap;
struct wl_listener surface_commit;
} LayerSurface;
typedef struct {
const char *symbol;
void (*arrange)(Monitor *,unsigned int,unsigned int);
} Layout;
struct Monitor {
struct wl_list link;
struct wlr_output *wlr_output;
struct wlr_scene_output *scene_output;
// struct wlr_scene_rect *fullscreen_bg; /* See createmon() for info */
struct wl_listener frame;
struct wl_listener destroy;
struct wl_listener request_state;
struct wl_listener destroy_lock_surface;
struct wlr_session_lock_surface_v1 *lock_surface;
struct wlr_box m; /* monitor area, layout-relative */
struct wlr_box w; /* window area, layout-relative */
struct wl_list layers[4]; /* LayerSurface::link */
const Layout *lt[2];
unsigned int seltags;
unsigned int sellt;
uint32_t tagset[2];
double mfact;
int nmaster;
char ltsymbol[16];
struct wl_list dwl_ipc_outputs;
int gappih; /* horizontal gap between windows */
int gappiv; /* vertical gap between windows */
int gappoh; /* horizontal outer gaps */
int gappov; /* vertical outer gaps */
Pertag *pertag;
Client *sel;
int isoverview;
int is_in_hotarea;
int gamma_lut_changed;
};
typedef struct {
const char *name;
float mfact;
int nmaster;
float scale;
const Layout *lt;
enum wl_output_transform rr;
int x, y;
} MonitorRule;
typedef struct {
struct wlr_pointer_constraint_v1 *constraint;
struct wl_listener destroy;
} PointerConstraint;
typedef struct {
const char *id;
const char *title;
unsigned int tags;
int isfloating;
int isfullscreen;
int isnoclip;
int isnoborder;
int monitor;
unsigned int width;
unsigned int height;
} Rule;
typedef struct {
struct wlr_scene_tree *scene;
struct wlr_session_lock_v1 *lock;
struct wl_listener new_surface;
struct wl_listener unlock;
struct wl_listener destroy;
} SessionLock;
/* function declarations */
static void logtofile(const char *fmt, ...); //日志函数
static void lognumtofile(unsigned int num); //日志函数
static void applybounds(Client *c, struct wlr_box *bbox); //设置边界规则,能让一些窗口拥有比较适合的大小
static void applyrules(Client *c); //窗口规则应用,应用config.h中定义的窗口规则
static void arrange(Monitor *m); //布局函数,让窗口俺平铺规则移动和重置大小
static void arrangelayer(Monitor *m, struct wl_list *list,
struct wlr_box *usable_area, int exclusive);
static void arrangelayers(Monitor *m);
static void autostartexec(void); //自启动命令执行
static void axisnotify(struct wl_listener *listener, void *data); //滚轮事件处理
static void buttonpress(struct wl_listener *listener, void *data); //鼠标按键事件处理
static void chvt(const Arg *arg);
static void checkidleinhibitor(struct wlr_surface *exclude);
static void cleanup(void); //退出清理
static void cleanupkeyboard(struct wl_listener *listener, void *data); //退出清理
static void cleanupmon(struct wl_listener *listener, void *data); //退出清理
static void closemon(Monitor *m); //退出清理
static void toggle_hotarea(int x_root, int y_root); //触发热区
static void commitlayersurfacenotify(struct wl_listener *listener, void *data);
static void commitnotify(struct wl_listener *listener, void *data);
static void createdecoration(struct wl_listener *listener, void *data);
static void createidleinhibitor(struct wl_listener *listener, void *data);
static void createkeyboard(struct wlr_keyboard *keyboard);
static void requestmonstate(struct wl_listener *listener, void *data);
static void createlayersurface(struct wl_listener *listener, void *data);
static void createlocksurface(struct wl_listener *listener, void *data);
static void createmon(struct wl_listener *listener, void *data);
static void createnotify(struct wl_listener *listener, void *data);
static void createpointer(struct wlr_pointer *pointer);
static void createpointerconstraint(struct wl_listener *listener, void *data);
static void cursorconstrain(struct wlr_pointer_constraint_v1 *constraint);
static void cursorframe(struct wl_listener *listener, void *data);
static void cursorwarptohint(void);
static void destroydecoration(struct wl_listener *listener, void *data);
static void defaultgaps(const Arg *arg);
static void destroydragicon(struct wl_listener *listener, void *data);
static void destroyidleinhibitor(struct wl_listener *listener, void *data);
static void destroylayersurfacenotify(struct wl_listener *listener, void *data);
static void destroylock(SessionLock *lock, int unlocked);
static void destroylocksurface(struct wl_listener *listener, void *data);
static void destroynotify(struct wl_listener *listener, void *data);
static void destroypointerconstraint(struct wl_listener *listener, void *data);
static void destroysessionlock(struct wl_listener *listener, void *data);
static void destroysessionmgr(struct wl_listener *listener, void *data);
static Monitor *dirtomon(enum wlr_direction dir);
static void setcursorshape(struct wl_listener *listener, void *data);
static void dwl_ipc_manager_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id);
static void dwl_ipc_manager_destroy(struct wl_resource *resource);
static void dwl_ipc_manager_get_output(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *output);
static void dwl_ipc_manager_release(struct wl_client *client, struct wl_resource *resource);
static void dwl_ipc_output_destroy(struct wl_resource *resource);
static void dwl_ipc_output_printstatus(Monitor *monitor);
static void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output);
static void dwl_ipc_output_set_client_tags(struct wl_client *client, struct wl_resource *resource, uint32_t and_tags, uint32_t xor_tags);
static void dwl_ipc_output_set_layout(struct wl_client *client, struct wl_resource *resource, uint32_t index);
static void dwl_ipc_output_set_tags(struct wl_client *client, struct wl_resource *resource, uint32_t tagmask, uint32_t toggle_tagset);
static void dwl_ipc_output_release(struct wl_client *client, struct wl_resource *resource);
static void focusclient(Client *c, int lift);
static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg);
static void setborder_color(Client *c);
static Client *focustop(Monitor *m);
static void fullscreennotify(struct wl_listener *listener, void *data);
static void incnmaster(const Arg *arg);
static void incgaps(const Arg *arg);
static void incigaps(const Arg *arg);
static int keyrepeat(void *data);
static void incihgaps(const Arg *arg);
static void incivgaps(const Arg *arg);
static void incogaps(const Arg *arg);
static void incohgaps(const Arg *arg);
static void incovgaps(const Arg *arg);
static void toggleglobal(const Arg *arg);
static void inputdevice(struct wl_listener *listener, void *data);
static int keybinding(uint32_t mods, xkb_keysym_t sym);
static void keypress(struct wl_listener *listener, void *data);
static void keypressmod(struct wl_listener *listener, void *data);
static void killclient(const Arg *arg);
static void locksession(struct wl_listener *listener, void *data);
static void maplayersurfacenotify(struct wl_listener *listener, void *data);
static void mapnotify(struct wl_listener *listener, void *data);
static void maximizenotify(struct wl_listener *listener, void *data);
static void minimizenotify(struct wl_listener *listener, void *data);
static void monocle(Monitor *m);
static void motionabsolute(struct wl_listener *listener, void *data);
static void motionnotify(uint32_t time, struct wlr_input_device *device, double sx,
double sy, double sx_unaccel, double sy_unaccel);
static void motionrelative(struct wl_listener *listener, void *data);
static void moveresize(const Arg *arg);
static void exchange_client(const Arg *arg);
static void reset_foreign_tolevel(Client *c);
static void exchange_two_client(Client *c1, Client *c2);
static void outputmgrapply(struct wl_listener *listener, void *data);
static void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test);
static void outputmgrtest(struct wl_listener *listener, void *data);
static void pointerfocus(Client *c, struct wlr_surface *surface,
double sx, double sy, uint32_t time);
static void printstatus(void);
static void quit(const Arg *arg);
static void quitsignal(int signo);
static void rendermon(struct wl_listener *listener, void *data);
static void requestdecorationmode(struct wl_listener *listener, void *data);
static void requeststartdrag(struct wl_listener *listener, void *data);
static void resize(Client *c, struct wlr_box geo, int interact);
static void resizeclient(Client *c,int x,int y,int w,int h, int interact);
static void run(char *startup_cmd);
static void setcursor(struct wl_listener *listener, void *data);
static void setfloating(Client *c, int floating);
static void setfullscreen(Client *c, int fullscreen);
static void setfakefullscreen(Client *c, int fakefullscreen);
static void setgaps(int oh, int ov, int ih, int iv);
static void setlayout(const Arg *arg);
static void switch_layout(const Arg *arg);
static void setmfact(const Arg *arg);
static void setmon(Client *c, Monitor *m, unsigned int newtags);
static void setpsel(struct wl_listener *listener, void *data);
static void setsel(struct wl_listener *listener, void *data);
static void setup(void);
static void sigchld(int unused);
static void spawn(const Arg *arg);
static void startdrag(struct wl_listener *listener, void *data);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
static void setgamma(struct wl_listener *listener, void *data);
static void tile(Monitor *m, unsigned int gappo, unsigned int uappi);
static void overview(Monitor *m, unsigned int gappo, unsigned int gappi);
static void grid(Monitor *m, unsigned int gappo, unsigned int uappi);
static void togglefloating(const Arg *arg);
static void togglefullscreen(const Arg *arg);
static void togglefakefullscreen(const Arg *arg);
static void togglegaps(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
static void unlocksession(struct wl_listener *listener, void *data);
static void unmaplayersurfacenotify(struct wl_listener *listener, void *data);
static void unmapnotify(struct wl_listener *listener, void *data);
static void updatemons(struct wl_listener *listener, void *data);
static void updatetitle(struct wl_listener *listener, void *data);
static void urgent(struct wl_listener *listener, void *data);
static void view(const Arg *arg);
static void viewtoleft_have_client(const Arg *arg);
static void viewtoright_have_client(const Arg *arg);
static void viewtoleft(const Arg *arg);
static void viewtoright(const Arg *arg);
static void handlesig(int signo);
static void tagtoleft(const Arg *arg);
static void tagtoright(const Arg *arg);
static void virtualkeyboard(struct wl_listener *listener, void *data);
static void virtualpointer(struct wl_listener *listener, void *data);
static void warp_cursor(const Client *c);
static Monitor *xytomon(double x, double y);
static void xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, double *nx, double *ny);
static void zoom(const Arg *arg);
static void clear_fullscreen_flag(Client *c);
static Client *direction_select(const Arg *arg);
static void focusdir(const Arg *arg);
static void toggleoverview(const Arg *arg);
static void warp_cursor_to_selmon(const Monitor *m);
unsigned int want_restore_fullscreen(Client *target_client);
static void overview_restore(Client *c, const Arg *arg);
static void overview_backup(Client *c);
static void applyrulesgeom(Client *c);
static void set_minized(Client *c);
static void minized(const Arg *arg);
static void restore_minized(const Arg *arg);
static void toggle_scratchpad(const Arg *arg);
static void show_scratchpad(Client *c);
static void show_hide_client(Client *c);
static void tag_client(const Arg *arg, Client *target_client);
static void handle_foreign_activate_request(struct wl_listener *listener, void *data);
static void handle_foreign_fullscreen_request(struct wl_listener *listener, void *data);
static void handle_foreign_close_request(struct wl_listener *listener, void *data);
static void handle_foreign_destroy(struct wl_listener *listener, void *data);
static struct wlr_box setclient_coordinate_center(struct wlr_box geom);
static unsigned int get_tags_first_tag(unsigned int tags);
/* variables */
static const char broken[] = "broken";
// static const char *cursor_image = "left_ptr";
static pid_t child_pid = -1;
static int locked;
static void *exclusive_focus;
static struct wl_display *dpy;
static struct wlr_relative_pointer_manager_v1 *pointer_manager;
static struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager;
static struct wlr_backend *backend;
static struct wlr_scene *scene;
static struct wlr_scene_tree *layers[NUM_LAYERS];
static struct wlr_renderer *drw;
static struct wlr_allocator *alloc;
static struct wlr_compositor *compositor;
static struct wlr_gamma_control_manager_v1 *gamma_control_mgr;
static struct wlr_xdg_shell *xdg_shell;
static struct wlr_xdg_activation_v1 *activation;
static struct wlr_xdg_decoration_manager_v1 *xdg_decoration_mgr;
static struct wl_list clients; /* tiling order */
static struct wl_list fstack; /* focus order */
// static struct wlr_idle *idle;
static struct wlr_idle_notifier_v1 *idle_notifier;
static struct wlr_idle_inhibit_manager_v1 *idle_inhibit_mgr;
// static struct wlr_input_inhibit_manager *input_inhibit_mgr;
static struct wlr_layer_shell_v1 *layer_shell;
static struct wlr_output_manager_v1 *output_mgr;
static struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard_mgr;
static struct wlr_virtual_pointer_manager_v1 *virtual_pointer_mgr;
static struct wlr_cursor *cursor;
static struct wlr_xcursor_manager *cursor_mgr;
static struct wlr_session *session;
static struct wlr_session_lock_manager_v1 *session_lock_mgr;
static struct wlr_scene_rect *locked_bg;
static struct wlr_session_lock_v1 *cur_lock;
static const int layermap[] = { LyrBg, LyrBottom, LyrTop, LyrOverlay };
static struct wlr_scene_tree *drag_icon;
static struct wlr_cursor_shape_manager_v1 *cursor_shape_mgr; //这个跟steup obs影响对应
static struct wlr_pointer_constraints_v1 *pointer_constraints;
static struct wlr_relative_pointer_manager_v1 *relative_pointer_mgr;
static struct wlr_pointer_constraint_v1 *active_constraint;
static struct wlr_seat *seat;
static struct wl_list keyboards;
static unsigned int cursor_mode;
static Client *grabc;
static int grabcx, grabcy; /* client-relative */
static struct wlr_output_layout *output_layout;
static struct wlr_box sgeom;
static struct wl_list mons;
static Monitor *selmon;
static int enablegaps = 1; /* enables gaps, used by togglegaps */
/* global event handlers */
static struct zdwl_ipc_manager_v2_interface dwl_manager_implementation = {.release = dwl_ipc_manager_release, .get_output = dwl_ipc_manager_get_output};
static struct zdwl_ipc_output_v2_interface dwl_output_implementation = {.release = dwl_ipc_output_release, .set_tags = dwl_ipc_output_set_tags, .set_layout = dwl_ipc_output_set_layout, .set_client_tags = dwl_ipc_output_set_client_tags};
static struct wl_listener lock_listener = {.notify = locksession};
#ifdef XWAYLAND
static void activatex11(struct wl_listener *listener, void *data);
static void configurex11(struct wl_listener *listener, void *data);
static void createnotifyx11(struct wl_listener *listener, void *data);
static void dissociatex11(struct wl_listener *listener, void *data);
static void associatex11(struct wl_listener *listener, void *data);
static Atom getatom(xcb_connection_t *xc, const char *name);
static void sethints(struct wl_listener *listener, void *data);
static void xwaylandready(struct wl_listener *listener, void *data);
// static struct wl_listener new_xwayland_surface = {.notify = createnotifyx11};
// static struct wl_listener xwayland_ready = {.notify = xwaylandready};
static struct wlr_xwayland *xwayland;
static Atom netatom[NetLast];
#endif
/* configuration, allows nested code to access above variables */
#include "config.h"
/* attempt to encapsulate suck into one file */
#include "client.h"
#ifdef IM
#include "IM.h"
#endif
/* compile-time check if all tags fit into an unsigned int bit array. */
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
struct Pertag {
unsigned int curtag, prevtag; /* current and previous tag */
int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */
const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes */
};
static pid_t *autostart_pids;
static size_t autostart_len;
void //0.5
applybounds(Client *c, struct wlr_box *bbox)
{
/* set minimum possible */
c->geom.width = MAX(1 + 2 * (int)c->bw, c->geom.width);
c->geom.height = MAX(1 + 2 * (int)c->bw, c->geom.height);
if (c->geom.x >= bbox->x + bbox->width)
c->geom.x = bbox->x + bbox->width - c->geom.width;
if (c->geom.y >= bbox->y + bbox->height)
c->geom.y = bbox->y + bbox->height - c->geom.height;
if (c->geom.x + c->geom.width <= bbox->x)
c->geom.x = bbox->x;
if (c->geom.y + c->geom.height <= bbox->y)
c->geom.y = bbox->y;
}
/*清除全屏标志,还原全屏时清0的border*/
void clear_fullscreen_flag(Client *c) {
if (c->isfullscreen || c->isfakefullscreen) {
c->isfullscreen = 0;
c->isfloating = 0;
c->isfakefullscreen = 0;
c->bw = borderpx;
client_set_fullscreen(c, false);
}
}
void //升级忽略
setgamma(struct wl_listener *listener, void *data)
{
struct wlr_gamma_control_manager_v1_set_gamma_event *event = data;
struct wlr_output_state state;
wlr_output_state_init(&state);
if (!wlr_gamma_control_v1_apply(event->control, &state)) {
wlr_output_state_finish(&state);
return;
}
if (!wlr_output_test_state(event->output, &state)) {
wlr_gamma_control_v1_send_failed_and_destroy(event->control);
wlr_output_state_finish(&state);
return;
}
wlr_output_commit_state(event->output, &state);
wlr_output_schedule_frame(event->output);
}
void minized(const Arg *arg) {
if(selmon->sel && !selmon->sel->isminied) {
set_minized(selmon->sel);
}
}
void restore_minized(const Arg *arg) {
Client *c;
wl_list_for_each(c, &clients, link) {
if (c->isminied) {
show_hide_client(c);
c->is_scratchpad_show = 0;
c->is_in_scratchpad = 0;
setborder_color(c);
break;
}
}
}
void show_scratchpad(Client *c) {
c->is_scratchpad_show = 1;
if (c->isfullscreen || c->isfakefullscreen) {
c->isfullscreen = 0; // 清除窗口全屏标志
c->isfakefullscreen = 0;
c->bw = borderpx; // 恢复非全屏的border
}
/* return if fullscreen */
if(!c->isfloating) {
setfloating(c, 1);
c->geom.width = c->mon->w.width * 0.7;
c->geom.height = c->mon->w.height * 0.8;
//重新计算居中的坐标
c->geom = setclient_coordinate_center(c->geom);
resize(c, c->geom, 0);
}
c->oldtags = selmon->tagset[selmon->seltags];
show_hide_client(c);
setborder_color(c);
}
void reset_foreign_tolevel(Client *c) {
wlr_foreign_toplevel_handle_v1_destroy(c->foreign_toplevel);
c->foreign_toplevel = NULL;
// printstatus();
//创建外部顶层窗口的句柄,每一个顶层窗口都有一个
c->foreign_toplevel = wlr_foreign_toplevel_handle_v1_create(foreign_toplevel_manager);
//监听来自外部对于窗口的事件请求
if(c->foreign_toplevel){
LISTEN(&(c->foreign_toplevel->events.request_activate),
&c->foreign_activate_request,handle_foreign_activate_request);
LISTEN(&(c->foreign_toplevel->events.request_fullscreen),
&c->foreign_fullscreen_request,handle_foreign_fullscreen_request);
LISTEN(&(c->foreign_toplevel->events.request_close),
&c->foreign_close_request,handle_foreign_close_request);
LISTEN(&(c->foreign_toplevel->events.destroy),
&c->foreign_destroy,handle_foreign_destroy);
//设置外部顶层句柄的id为应用的id
const char *appid;
appid = client_get_appid(c) ;
if(appid)
wlr_foreign_toplevel_handle_v1_set_app_id(c->foreign_toplevel,appid);
//设置外部顶层句柄的title为应用的title
const char *title;
title = client_get_title(c) ;
if(title)
wlr_foreign_toplevel_handle_v1_set_title(c->foreign_toplevel,title);
//设置外部顶层句柄的显示监视器为当前监视器
wlr_foreign_toplevel_handle_v1_output_enter(
c->foreign_toplevel, c->mon->wlr_output);
}
}
void toggle_scratchpad(const Arg *arg) {
Client *c;
wl_list_for_each(c, &clients, link) {
if(c->mon != selmon) {
continue;
}
if(c->is_in_scratchpad && c->is_scratchpad_show && (selmon->tagset[selmon->seltags] & c->tags) == 0 ) {
unsigned int target = get_tags_first_tag(selmon->tagset[selmon->seltags]);
tag_client(&(Arg){.ui = target},c);
return;
} else if (c->is_in_scratchpad && c->is_scratchpad_show && (selmon->tagset[selmon->seltags] & c->tags) != 0) {
set_minized(c);
return;
} else if ( c && c->is_in_scratchpad && !c->is_scratchpad_show) {
show_scratchpad(c);
return;
}
}
}
void //0.5
handlesig(int signo)
{
if (signo == SIGCHLD) {
#ifdef XWAYLAND
siginfo_t in;
/* wlroots expects to reap the XWayland process itself, so we
* use WNOWAIT to keep the child waitable until we know it's not
* XWayland.
*/
while (!waitid(P_ALL, 0, &in, WEXITED|WNOHANG|WNOWAIT) && in.si_pid
&& (!xwayland || in.si_pid != xwayland->server->pid))
waitpid(in.si_pid, NULL, 0);
#else
while (waitpid(-1, NULL, WNOHANG) > 0);
#endif
} else if (signo == SIGINT || signo == SIGTERM) {
quit(NULL);
}
}
void toggle_hotarea(int x_root, int y_root) {
// 左下角热区坐标计算,兼容多显示屏
Arg arg = {0};
unsigned hx = selmon->m.x + hotarea_size;
unsigned hy = selmon->m.y + selmon->m.height - hotarea_size;
if (enable_hotarea == 1 && selmon->is_in_hotarea == 0 && y_root > hy &&
x_root < hx && x_root >= selmon->m.x &&
y_root <= (selmon->m.y + selmon->m.height)) {
toggleoverview(&arg);
selmon->is_in_hotarea = 1;
} else if (enable_hotarea == 1 && selmon->is_in_hotarea == 1 &&
(y_root <= hy || x_root >= hx || x_root < selmon->m.x ||
y_root > (selmon->m.y + selmon->m.height))) {
selmon->is_in_hotarea = 0;
}
}
struct wlr_box //计算客户端居中坐标
setclient_coordinate_center(struct wlr_box geom){
struct wlr_box tempbox;
tempbox.x = selmon->w.x + (selmon->w.width - geom.width) / 2;
tempbox.y = selmon->w.y + (selmon->w.height - geom.height) / 2;
tempbox.width = geom.width;
tempbox.height = geom.height;
return tempbox;
}
/* function implementations */
void logtofile(const char *fmt, ...) {
char buf[256];
char cmd[256];
va_list ap;
va_start(ap, fmt);
vsprintf((char *)buf, fmt, ap);
va_end(ap);
unsigned int i = strlen((const char *)buf);
sprintf(cmd, "echo '%.*s' >> ~/log", i, buf);
system(cmd);
}
/* function implementations */
void lognumtofile(unsigned int num) {
char cmd[256];
sprintf(cmd, "echo '%x' >> ~/log", num);
system(cmd);
}
void // 0.5
applyrulesgeom(Client *c)
{
/* rule matching */
const char *appid, *title;
const Rule *r;
if (!(appid = client_get_appid(c)))
appid = broken;
if (!(title = client_get_title(c)))
title = broken;
for (r = rules; r < END(rules); r++) {
if ((!r->title || strstr(title, r->title))
&& (!r->id || strstr(appid, r->id)) && r->width !=0 && r->height != 0) {
c->geom.width = r->width;
c->geom.height = r->height;
//重新计算居中的坐标
c->geom = setclient_coordinate_center(c->geom);
break;
}
}
}
void // 17
applyrules(Client *c)
{
/* rule matching */
const char *appid, *title;
uint32_t i, newtags = 0;
const Rule *r;
Monitor *mon = selmon, *m;
c->isfloating = client_is_float_type(c);
if (!(appid = client_get_appid(c)))
appid = broken;
if (!(title = client_get_title(c)))
title = broken;
for (r = rules; r < END(rules); r++) {
if ((!r->title || strstr(title, r->title))
&& (!r->id || strstr(appid, r->id))) {
c->isfloating = r->isfloating;
c->isnoclip = r->isnoclip;
c->isnoborder = r->isnoborder;
newtags |= r->tags;
i = 0;
wl_list_for_each(m, &mons, link)
if (r->monitor == i++)
mon = m;
if(c->isfloating && r->width != 0 && r->height != 0){
c->geom.width = r->width;
c->geom.height = r->height;
//重新计算居中的坐标
c->geom = setclient_coordinate_center(c->geom);
}
if(r->isfullscreen){
c->isfullscreen =1;
c->ignore_clear_fullscreen = 1;
}
break;
}
}
wlr_scene_node_reparent(&c->scene->node, layers[c->isfloating ? LyrFloat : LyrTile]);
setmon(c, mon, newtags);
Client *fc;
// 如果当前的tag中有新创建的非悬浮窗口,就让当前tag中的全屏窗口退出全屏参与平铺
wl_list_for_each(fc, &clients, link)
if (fc && !c->ignore_clear_fullscreen && c->tags & fc->tags && ISFULLSCREEN(fc) && !c->isfloating ) {
clear_fullscreen_flag(fc);
arrange(c->mon);
}else if(c->ignore_clear_fullscreen && c->isfullscreen){
setfullscreen(c,1);
}
if(!(c->tags & ( 1 << (selmon->pertag->curtag - 1) ))){
view(&(Arg){.ui = c->tags});
}
}
void //17
arrange(Monitor *m)
{
Client *c;
if (!m->wlr_output->enabled)
return;
wl_list_for_each(c, &clients, link) {
if(c->mon == m && c->isglobal) {
c->tags = m->tagset[m->seltags];
focusclient(c,1);
}
if (c->mon == m) {
wlr_scene_node_set_enabled(&c->scene->node, VISIBLEON(c, m));
client_set_suspended(c, !VISIBLEON(c, m));
}
}
// 给全屏窗口设置背景为黑色 好像要跟LyrFS图层一起使用,我不用这个图层,所以注释掉
// wlr_scene_node_set_enabled(&m->fullscreen_bg->node,
// (c = focustop(m)) && c->isfullscreen);
if(m->isoverview){
overviewlayout.arrange(m,0,0);
}else if (m && m->lt[m->sellt]->arrange){
m->lt[m->sellt]->arrange(m,gappoh,0);
}
#ifdef IM
if (input_relay && input_relay->popup)
input_popup_update(input_relay->popup);
#endif
motionnotify(0, NULL, 0, 0, 0, 0);
checkidleinhibitor(NULL);
}
void //0.5
arrangelayer(Monitor *m, struct wl_list *list, struct wlr_box *usable_area, int exclusive)
{
LayerSurface *l;
struct wlr_box full_area = m->m;
wl_list_for_each(l, list, link) {
struct wlr_layer_surface_v1 *layer_surface = l->layer_surface;
if (exclusive != (layer_surface->current.exclusive_zone > 0))
continue;
wlr_scene_layer_surface_v1_configure(l->scene_layer, &full_area, usable_area);
wlr_scene_node_set_position(&l->popups->node, l->scene->node.x, l->scene->node.y);
l->geom.x = l->scene->node.x;
l->geom.y = l->scene->node.y;
}
}
Client *direction_select(const Arg *arg) {
Client *c,*tempClients[100];
Client *tc = selmon->sel;
int last = -1;
if(!tc)
return NULL;
if (tc &&
(tc->isfullscreen || tc->isfakefullscreen)) /* no support for focusstack with fullscreen windows */
return NULL;
wl_list_for_each(c, &clients, link)
if (c && (c->tags & c->mon->tagset[c->mon->seltags])){
last++;
tempClients[last] = c;
}
if (last < 0)
return NULL;
int sel_x = tc->geom.x;
int sel_y = tc->geom.y;
long long int distance = LLONG_MAX;
// int temp_focus = 0;
Client *tempFocusClients = NULL;
switch (arg->i) {
case UP:
for (int _i = 0; _i <= last; _i++) {
if (tempClients[_i]->geom.y < sel_y && tempClients[_i]->geom.x == sel_x) {
int dis_x = tempClients[_i]->geom.x - sel_x;
int dis_y = tempClients[_i]->geom.y - sel_y;
long long int tmp_distance = dis_x * dis_x + dis_y * dis_y; // 计算距离
if (tmp_distance < distance) {
distance = tmp_distance;
tempFocusClients = tempClients[_i];
}
}
}
if (!tempFocusClients) {
for (int _i = 0; _i <= last; _i++) {
if (tempClients[_i]->geom.y < sel_y ) {
int dis_x = tempClients[_i]->geom.x - sel_x;
int dis_y = tempClients[_i]->geom.y - sel_y;
long long int tmp_distance = dis_x * dis_x + dis_y * dis_y; // 计算距离
if (tmp_distance < distance) {
distance = tmp_distance;
tempFocusClients = tempClients[_i];
}
}
}
}
break;
case DOWN:
for (int _i = 0; _i <= last; _i++) {
if (tempClients[_i]->geom.y > sel_y && tempClients[_i]->geom.x == sel_x) {
int dis_x = tempClients[_i]->geom.x - sel_x;
int dis_y = tempClients[_i]->geom.y - sel_y;
long long int tmp_distance = dis_x * dis_x + dis_y * dis_y; // 计算距离
if (tmp_distance < distance) {