-
Notifications
You must be signed in to change notification settings - Fork 2
/
fastcompmgr.c
2726 lines (2323 loc) · 65.5 KB
/
fastcompmgr.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
/*
* fastcompmgr - a _fast_ compositor for X11
*
* based on xcompmgr - copyright (c) 2003, keith packard
* 2008, Dana Jansens
* compton 2011, Christopher Jeffrey
* fastcompmgr 2023, Tycho Kirchner
*
* copyright (c) 2023, Tycho Kirchner
* See LICENSE for more information.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <sys/poll.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <getopt.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/extensions/Xcomposite.h>
#include <X11/extensions/Xdamage.h>
#include <X11/extensions/Xrender.h>
#include "cm-global.h"
#include "cm-root.h"
#include "comp_rect.h"
#include "ringbuffer.h"
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#if COMPOSITE_MAJOR > 0 || COMPOSITE_MINOR >= 2
#define HAS_NAME_WINDOW_PIXMAP 1
#endif
#define CAN_DO_USABLE 0
typedef enum {
WINTYPE_UNKNOWN, // MUST ALWAYS STAY first, due to init optimization in add_win
WINTYPE_DESKTOP,
WINTYPE_DOCK,
WINTYPE_TOOLBAR,
WINTYPE_MENU,
WINTYPE_UTILITY,
WINTYPE_SPLASH,
WINTYPE_DIALOG,
WINTYPE_NORMAL,
WINTYPE_DROPDOWN_MENU,
WINTYPE_POPUP_MENU,
WINTYPE_TOOLTIP,
WINTYPE_NOTIFY,
WINTYPE_COMBO,
WINTYPE_DND,
NUM_WINTYPES
} wintype;
// Cache whether to draw a shadow or not
typedef enum {
SHADOW_UNKNWON, // MUST ALWAYS STAY first, due to init optimization in add_win
SHADOW_YES,
SHADOW_NO
} shadowtype;
typedef struct _ignore {
struct _ignore *next;
unsigned long sequence;
} ignore;
typedef struct _win {
struct _win *next;
Window id;
#if HAS_NAME_WINDOW_PIXMAP
Pixmap pixmap;
#endif
XWindowAttributes a;
#if CAN_DO_USABLE
Bool usable; /* mapped and all damaged at one point */
XRectangle damage_bounds; /* bounds of damage */
#endif
int mode;
int damaged;
Damage damage;
Picture picture;
Picture alpha_pict;
Picture alpha_border_pict;
Picture shadow_pict;
XserverRegion border_size;
XserverRegion extents;
Picture shadow;
int shadow_dx;
int shadow_dy;
int shadow_width;
int shadow_height;
unsigned int opacity;
wintype window_type;
shadowtype shadow_type;
unsigned long damage_sequence; /* sequence when damage was created */
Bool destroyed;
Bool paint_needed;
unsigned int left_width;
unsigned int right_width;
unsigned int top_width;
unsigned int bottom_width;
Bool need_configure;
bool configure_size_changed;
XConfigureEvent queue_configure;
/* for drawing translucent windows */
XserverRegion border_clip;
struct _win *prev_trans;
} win;
typedef struct _conv {
int size;
double *data;
} conv;
typedef struct _fade {
struct _fade *next;
win *w;
double cur;
double finish;
double step;
void (*callback) (Display *dpy, win *w);
Display *dpy;
} fade;
win *list;
fade *fades;
Display *dpy;
Picture black_picture;
Picture root_tile;
XserverRegion all_damage;
XserverRegion g_xregion_tmp;
Bool all_damage_is_dirty;
Bool clip_changed;
#if HAS_NAME_WINDOW_PIXMAP
Bool has_name_pixmap;
#endif
ringBuffer_typedef(ulong, IgnoreErrRingbuf);
IgnoreErrRingbuf ignore_ringbuf;
IgnoreErrRingbuf* p_ignore_ringbuf = &ignore_ringbuf;
int xfixes_event, xfixes_error;
int damage_event, damage_error;
int composite_event, composite_error;
int render_event, render_error;
Bool synchronize;
int composite_opcode;
static Bool g_paint_ignore_region_is_dirty = True;
Atom win_type[NUM_WINTYPES];
double win_type_opacity[NUM_WINTYPES];
Bool win_type_shadow[NUM_WINTYPES];
Bool win_type_fade[NUM_WINTYPES];
#define REGISTER_PROP "_NET_WM_CM_S"
#define OPAQUE 0xffffffff
conv *gaussian_map;
#define WINDOW_SOLID 0
#define WINDOW_TRANS 1
#define WINDOW_ARGB 2
#ifndef DEBUG_REPAINT
#define DEBUG_REPAINT 0
#endif
#ifndef DEBUG_EVENTS
#define DEBUG_EVENTS 0
#endif
#ifndef MONITOR_REPAINT
#define MONITOR_REPAINT 0
#endif
static void
determine_mode(Display *dpy, win *w);
static bool
is_gtk_frame_extent(Display *dpy, Window w);
static double
get_opacity_percent(Display *dpy, win *w);
static void
do_configure_win(Display *dpy, win* w);
static void
set_paint_ignore_region_dirty(void);
static XserverRegion
win_extents(Display *dpy, win *w);
int shadow_radius = 12;
int shadow_offset_x = -15;
int shadow_offset_y = -15;
double shadow_opacity = .75;
double fade_in_step = 0.028;
double fade_out_step = 0.03;
int fade_delta = 10;
int fade_time = 0;
Bool fade_trans = False;
double inactive_opacity = 0;
double frame_opacity = 0;
#define INACTIVE_OPACITY \
(unsigned long)((double)inactive_opacity * OPAQUE)
#define IS_NORMAL_WIN(w) \
((w) && ((w)->window_type == WINTYPE_NORMAL \
|| (w)->window_type == WINTYPE_UTILITY))
#define HAS_FRAME_OPACITY(w) (frame_opacity && (w)->top_width)
/* For shadow precomputation */
int Gsize = -1;
unsigned char *shadow_corner = NULL;
unsigned char *shadow_top = NULL;
int
get_time_in_milliseconds() {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
fade *
find_fade(win *w) {
fade *f;
for (f = fades; f; f = f->next) {
if (f->w == w) return f;
}
return 0;
}
void
dequeue_fade(Display *dpy, fade *f) {
fade **prev;
for (prev = &fades; *prev; prev = &(*prev)->next) {
if (*prev == f) {
*prev = f->next;
if (f->callback) {
(*f->callback)(dpy, f->w);
}
free(f);
break;
}
}
}
void
cleanup_fade(Display *dpy, win *w) {
fade *f = find_fade (w);
if (f) {
dequeue_fade(dpy, f);
}
}
void
enqueue_fade(Display *dpy, fade *f) {
if (!fades) {
fade_time = get_time_in_milliseconds() + fade_delta;
}
f->next = fades;
fades = f;
}
static void
set_fade(Display *dpy, win *w, double start,
double finish, double step,
void(*callback) (Display *dpy, win *w),
Bool exec_callback, Bool override) {
fade *f;
f = find_fade(w);
if (!f) {
f = malloc(sizeof(fade));
f->next = 0;
f->w = w;
f->cur = start;
enqueue_fade(dpy, f);
} else if (!override) {
return;
} else {
if (exec_callback && f->callback) {
(*f->callback)(dpy, f->w);
}
}
if (finish < 0) finish = 0;
if (finish > 1) finish = 1;
f->finish = finish;
if (f->cur < finish) {
f->step = step;
} else if (f->cur > finish) {
f->step = -step;
}
f->callback = callback;
w->opacity = f->cur * OPAQUE;
#if 0
printf("set_fade start %g step %g\n", f->cur, f->step);
#endif
determine_mode(dpy, w);
if (w->shadow) {
// rebuild the shadow
XRenderFreePicture(dpy, w->shadow);
w->shadow = None;
win_extents(dpy, w);
}
/* fading windows need to be drawn, mark
them as damaged. when a window maps,
if it tries to fade in but it already
at the right opacity (map/unmap/map fast)
then it will never get drawn without this
until it repaints */
w->damaged = 1;
}
int
fade_timeout(void) {
int now;
int delta;
if (!fades) return -1;
now = get_time_in_milliseconds();
delta = fade_time - now;
if (delta < 0) delta = 0;
/* printf("timeout %d\n", delta); */
return delta;
}
void
run_fades(Display *dpy) {
int now = get_time_in_milliseconds();
fade *next = fades;
int steps;
Bool need_dequeue;
#if 0
printf("run fades\n");
#endif
if (fade_time - now > 0) return;
steps = 1 + (now - fade_time) / fade_delta;
while (next) {
fade *f = next;
win *w = f->w;
next = f->next;
f->cur += f->step * steps;
if (f->cur >= 1) {
f->cur = 1;
} else if (f->cur < 0) {
f->cur = 0;
}
#if 0
printf("opacity now %g\n", f->cur);
#endif
w->opacity = f->cur * OPAQUE;
need_dequeue = False;
if (f->step > 0) {
if (f->cur >= f->finish) {
w->opacity = f->finish * OPAQUE;
need_dequeue = True;
}
} else {
if (f->cur <= f->finish) {
w->opacity = f->finish * OPAQUE;
need_dequeue = True;
}
}
determine_mode(dpy, w);
if (w->shadow) {
// rebuild the shadow
XRenderFreePicture(dpy, w->shadow);
w->shadow = None;
win_extents(dpy, w);
}
/* Must do this last as it might
destroy f->w in callbacks */
if (need_dequeue) dequeue_fade(dpy, f);
}
fade_time = now + fade_delta;
}
static double
gaussian(double r, double x, double y) {
return ((1 / (sqrt(2 * M_PI * r))) *
exp((- (x * x + y * y)) / (2 * r * r)));
}
static conv *
make_gaussian_map(Display *dpy, double r) {
conv *c;
int size = ((int) ceil((r * 3)) + 1) & ~1;
int center = size / 2;
int x, y;
double t;
double g;
c = malloc(sizeof(conv) + size * size * sizeof(double));
c->size = size;
c->data = (double *) (c + 1);
t = 0.0;
for (y = 0; y < size; y++) {
for (x = 0; x < size; x++) {
g = gaussian(r, (double) (x - center), (double) (y - center));
t += g;
c->data[y * size + x] = g;
}
}
/* printf("gaussian total %f\n", t); */
for (y = 0; y < size; y++) {
for (x = 0; x < size; x++) {
c->data[y * size + x] /= t;
}
}
return c;
}
/*
* A picture will help
*
* -center 0 width width+center
* -center +-----+-------------------+-----+
* | | | |
* | | | |
* 0 +-----+-------------------+-----+
* | | | |
* | | | |
* | | | |
* height +-----+-------------------+-----+
* | | | |
* height+ | | | |
* center +-----+-------------------+-----+
*/
static unsigned char
sum_gaussian(conv *map, double opacity,
int x, int y, int width, int height) {
int fx, fy;
double *g_data;
double *g_line = map->data;
int g_size = map->size;
int center = g_size / 2;
int fx_start, fx_end;
int fy_start, fy_end;
double v;
/*
* Compute set of filter values which are "in range",
* that's the set with:
* 0 <= x + (fx-center) && x + (fx-center) < width &&
* 0 <= y + (fy-center) && y + (fy-center) < height
*
* 0 <= x + (fx - center) x + fx - center < width
* center - x <= fx fx < width + center - x
*/
fx_start = center - x;
if (fx_start < 0) fx_start = 0;
fx_end = width + center - x;
if (fx_end > g_size) fx_end = g_size;
fy_start = center - y;
if (fy_start < 0) fy_start = 0;
fy_end = height + center - y;
if (fy_end > g_size) fy_end = g_size;
g_line = g_line + fy_start * g_size + fx_start;
v = 0;
for (fy = fy_start; fy < fy_end; fy++) {
g_data = g_line;
g_line += g_size;
for (fx = fx_start; fx < fx_end; fx++) {
v += *g_data++;
}
}
if (v > 1) v = 1;
return ((unsigned char) (v * opacity * 255.0));
}
/* precompute shadow corners and sides
to save time for large windows */
static void
presum_gaussian(conv *map) {
int center = map->size/2;
int opacity, x, y;
Gsize = map->size;
if (shadow_corner) free((void *)shadow_corner);
if (shadow_top) free((void *)shadow_top);
shadow_corner = (unsigned char *)(malloc((Gsize + 1) * (Gsize + 1) * 26));
shadow_top = (unsigned char *)(malloc((Gsize + 1) * 26));
for (x = 0; x <= Gsize; x++) {
shadow_top[25 * (Gsize + 1) + x] =
sum_gaussian(map, 1, x - center, center, Gsize * 2, Gsize * 2);
for (opacity = 0; opacity < 25; opacity++) {
shadow_top[opacity * (Gsize + 1) + x] =
shadow_top[25 * (Gsize + 1) + x] * opacity / 25;
}
for (y = 0; y <= x; y++) {
shadow_corner[25 * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x]
= sum_gaussian(map, 1, x - center, y - center, Gsize * 2, Gsize * 2);
shadow_corner[25 * (Gsize + 1) * (Gsize + 1) + x * (Gsize + 1) + y]
= shadow_corner[25 * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x];
for (opacity = 0; opacity < 25; opacity++) {
shadow_corner[opacity * (Gsize + 1) * (Gsize + 1)
+ y * (Gsize + 1) + x]
= shadow_corner[opacity * (Gsize + 1) * (Gsize + 1)
+ x * (Gsize + 1) + y]
= shadow_corner[25 * (Gsize + 1) * (Gsize + 1)
+ y * (Gsize + 1) + x] * opacity / 25;
}
}
}
}
static XImage *
make_shadow(Display *dpy, double opacity,
int width, int height) {
XImage *ximage;
unsigned char *data;
int gsize = gaussian_map->size;
int ylimit, xlimit;
int swidth = width + gsize;
int sheight = height + gsize;
int center = gsize / 2;
int x, y;
unsigned char d;
int x_diff;
int opacity_int = (int)(opacity * 25);
data = malloc(swidth * sheight * sizeof(unsigned char));
if (!data) return 0;
ximage = XCreateImage(
dpy, DefaultVisual(dpy, DefaultScreen(dpy)), 8,
ZPixmap, 0, (char *) data, swidth, sheight, 8,
swidth * sizeof(unsigned char));
if (!ximage) {
free(data);
return 0;
}
/*
* Build the gaussian in sections
*/
/*
* center (fill the complete data array)
*/
if (Gsize > 0) {
d = shadow_top[opacity_int * (Gsize + 1) + Gsize];
} else {
d = sum_gaussian(gaussian_map,
opacity, center, center, width, height);
}
memset(data, d, sheight * swidth);
/*
* corners
*/
ylimit = gsize;
if (ylimit > sheight / 2) ylimit = (sheight + 1) / 2;
xlimit = gsize;
if (xlimit > swidth / 2) xlimit = (swidth + 1) / 2;
for (y = 0; y < ylimit; y++)
for (x = 0; x < xlimit; x++) {
if (xlimit == Gsize && ylimit == Gsize) {
d = shadow_corner[opacity_int * (Gsize + 1) * (Gsize + 1)
+ y * (Gsize + 1) + x];
} else {
d = sum_gaussian(gaussian_map,
opacity, x - center, y - center, width, height);
}
data[y * swidth + x] = d;
data[(sheight - y - 1) * swidth + x] = d;
data[(sheight - y - 1) * swidth + (swidth - x - 1)] = d;
data[y * swidth + (swidth - x - 1)] = d;
}
/*
* top/bottom
*/
x_diff = swidth - (gsize * 2);
if (x_diff > 0 && ylimit > 0) {
for (y = 0; y < ylimit; y++) {
if (ylimit == Gsize) {
d = shadow_top[opacity_int * (Gsize + 1) + y];
} else {
d = sum_gaussian(gaussian_map,
opacity, center, y - center, width, height);
}
memset(&data[y * swidth + gsize], d, x_diff);
memset(&data[(sheight - y - 1) * swidth + gsize], d, x_diff);
}
}
/*
* sides
*/
for (x = 0; x < xlimit; x++) {
if (xlimit == Gsize) {
d = shadow_top[opacity_int * (Gsize + 1) + x];
} else {
d = sum_gaussian(gaussian_map,
opacity, x - center, center, width, height);
}
for (y = gsize; y < sheight - gsize; y++) {
data[y * swidth + x] = d;
data[y * swidth + (swidth - x - 1)] = d;
}
}
return ximage;
}
static Picture
shadow_picture(Display *dpy, double opacity, Picture alpha_pict,
int width, int height, int *wp, int *hp) {
XImage *shadowImage;
Pixmap shadowPixmap;
Picture shadow_picture;
GC gc;
shadowImage = make_shadow(dpy, opacity, width, height);
if (!shadowImage) return None;
shadowPixmap = XCreatePixmap(dpy, root,
shadowImage->width, shadowImage->height, 8);
if (!shadowPixmap) {
XDestroyImage(shadowImage);
return None;
}
shadow_picture = XRenderCreatePicture(dpy, shadowPixmap,
XRenderFindStandardFormat(dpy, PictStandardA8), 0, 0);
if (!shadow_picture) {
XDestroyImage(shadowImage);
XFreePixmap(dpy, shadowPixmap);
return None;
}
gc = XCreateGC(dpy, shadowPixmap, 0, 0);
if (!gc) {
XDestroyImage(shadowImage);
XFreePixmap(dpy, shadowPixmap);
XRenderFreePicture(dpy, shadow_picture);
return None;
}
XPutImage(
dpy, shadowPixmap, gc, shadowImage, 0, 0, 0, 0,
shadowImage->width, shadowImage->height);
*wp = shadowImage->width;
*hp = shadowImage->height;
XFreeGC(dpy, gc);
XDestroyImage(shadowImage);
XFreePixmap(dpy, shadowPixmap);
return shadow_picture;
}
Picture
solid_picture(Display *dpy, Bool argb, double a,
double r, double g, double b) {
Pixmap pixmap;
Picture picture;
XRenderPictureAttributes pa;
XRenderColor c;
pixmap = XCreatePixmap(dpy, root, 1, 1, argb ? 32 : 8);
if (!pixmap) return None;
pa.repeat = True;
picture = XRenderCreatePicture(dpy, pixmap,
XRenderFindStandardFormat(dpy, argb
? PictStandardARGB32 : PictStandardA8),
CPRepeat,
&pa);
if (!picture) {
XFreePixmap(dpy, pixmap);
return None;
}
c.alpha = a * 0xffff;
c.red = r * 0xffff;
c.green = g * 0xffff;
c.blue = b * 0xffff;
XRenderFillRectangle(dpy, PictOpSrc, picture, &c, 0, 0, 1, 1);
XFreePixmap(dpy, pixmap);
return picture;
}
void
discard_ignore(Display *dpy, unsigned long sequence) {
while(! isBufferEmpty(p_ignore_ringbuf)){
ulong buf_seq;
buf_seq = bufferReadPeek(p_ignore_ringbuf);
if ((long) (sequence - buf_seq) > 0) {
bufferReadSkip(p_ignore_ringbuf);
} else {
break;
}
}
}
void
set_ignore(Display *dpy, unsigned long sequence) {
if(unlikely(isBufferFull(p_ignore_ringbuf))) {
bufferIncrease(p_ignore_ringbuf, p_ignore_ringbuf->size*2);
}
bufferWrite(p_ignore_ringbuf, sequence);
}
int
should_ignore(Display *dpy, unsigned long sequence) {
ulong buf_seq;
discard_ignore(dpy, sequence);
if(isBufferEmpty(p_ignore_ringbuf)) return False;
buf_seq = bufferReadPeek(p_ignore_ringbuf);
return buf_seq == sequence;
}
static win *
find_win(Display *dpy, Window id) {
win *w;
for (w = list; w; w = w->next) {
if (w->id == id && !w->destroyed)
return w;
}
return 0;
}
static void
paint_root(Display *dpy) {
if (!root_tile) {
root_tile = root_create_tile();
}
XRenderComposite(
dpy, PictOpSrc, root_tile, None,
root_buffer, 0, 0, 0, 0, 0, 0,
root_width, root_height);
}
static XserverRegion
win_extents(Display *dpy, win *w) {
XRectangle r;
r.x = w->a.x;
r.y = w->a.y;
r.width = w->a.width + w->a.border_width * 2;
r.height = w->a.height + w->a.border_width * 2;
if(unlikely(w->shadow_type)==SHADOW_UNKNWON){
// override_redirect: looking at xlib's documentation for the "Override Redirect Flag", it becomes
// clear that toolkits will typically set this flag for popup windows.
// On the other hand, WINTYPE_NORMAL windows setting override_redirect, are likely
// some kind of special windows, as seen in zoom screenshare. At least in zoom's case,
// the shadow darkens the whole desktop. A better fix might be to render
// four shadow images around the window instead of one huge shadow. But first
// check, why dcompmgr does not have this problem.
// See also: https://github.com/regolith-linux/regolith-compositor-compton-glx/issues/3
bool shadow_yes = (likely(w->window_type)
&& win_type_shadow[w->window_type] &&
(! w->a.override_redirect || w->window_type != WINTYPE_NORMAL) &&
! is_gtk_frame_extent(dpy, w->id));
// Firefox's bookmark-dragging renders a large ugly shadow. Since these as
// well as Tab-popups are ARGB-windows, stay safe and only draw shadows on
// non-solid windows for types normal/dialog . Note that apparently Compiz
// does not draw shadows on any ARGB windows, so nothing unusual here. See
// also https://github.com/chjj/compton/issues/201
// Since we have the -C flag to control for shadows on panels/docks, respect
// this setting by below WINTYPE_DOCK (and above win_type_shadow[])
if (w->mode != WINDOW_SOLID ) {
switch(w->window_type){
case WINTYPE_NORMAL:
case WINTYPE_DIALOG:
case WINTYPE_DOCK:
shadow_yes = shadow_yes && true; break;
default:
shadow_yes = false;
}
}
w->shadow_type = (shadow_yes) ? SHADOW_YES : SHADOW_NO;
}
if (w->shadow_type == SHADOW_YES) {
XRectangle sr;
w->shadow_dx = shadow_offset_x;
w->shadow_dy = shadow_offset_y;
if (!w->shadow) {
double opacity = shadow_opacity;
if (w->mode != WINDOW_SOLID) {
opacity = opacity * ((double)w->opacity) / ((double)OPAQUE);
}
if (HAS_FRAME_OPACITY(w)) {
opacity = opacity * frame_opacity;
}
w->shadow = shadow_picture(
dpy, opacity, w->alpha_pict,
w->a.width + w->a.border_width * 2,
w->a.height + w->a.border_width * 2,
&w->shadow_width, &w->shadow_height);
}
sr.x = w->a.x + w->shadow_dx;
sr.y = w->a.y + w->shadow_dy;
sr.width = w->shadow_width;
sr.height = w->shadow_height;
if (sr.x < r.x) {
r.width = (r.x + r.width) - sr.x;
r.x = sr.x;
}
if (sr.y < r.y) {
r.height = (r.y + r.height) - sr.y;
r.y = sr.y;
}
if (sr.x + sr.width > r.x + r.width) {
r.width = sr.x + sr.width - r.x;
}
if (sr.y + sr.height > r.y + r.height) {
r.height = sr.y + sr.height - r.y;
}
}
if(! w->extents){
w->extents = XFixesCreateRegion(dpy, &r, 1);
} else {
XFixesSetRegion(dpy, w->extents, &r, 1);
}
return w->extents;
}
static XserverRegion
border_size(Display *dpy, win *w) {
XserverRegion border;
/*
* if window doesn't exist anymore, this will generate an error
* as well as not generate a region. Perhaps a better XFixes
* architecture would be to have a request that copies instead
* of creates, that way you'd just end up with an empty region
* instead of an invalid XID.
*/
set_ignore(dpy, NextRequest(dpy));
border = XFixesCreateRegionFromWindow(
dpy, w->id, WindowRegionBounding);
/* translate this */
set_ignore(dpy, NextRequest(dpy));
XFixesTranslateRegion(dpy, border,
w->a.x + w->a.border_width,
w->a.y + w->a.border_width);
return border;
}
static Window
find_client_win(Display *dpy, Window win) {
Window root, parent;
Window *children;
unsigned int nchildren;
unsigned int i;
Atom type = None;
int format;
unsigned long nitems, after;
unsigned char *data = NULL;
Window client = 0;
int res;
res = XGetWindowProperty(
dpy, win, atom_wm_state, 0, 0, False,
AnyPropertyType, &type, &format, &nitems,
&after, &data);
if (likely(res == Success && data != NULL )) {
XFree(data);
if (likely(type)) return win;
}
if (!XQueryTree(dpy, win, &root,
&parent, &children, &nchildren)) {
return 0;
}
for (i = 0; i < nchildren; i++) {
client = find_client_win(dpy, children[i]);
if (client) break;
}
if (children) XFree((char *)children);
return client;
}
static void
get_frame_extents(Display *dpy, Window w,
unsigned int *left,
unsigned int *right,
unsigned int *top,
unsigned int *bottom) {
long *extents;
Atom type;
int format;
unsigned long nitems, after;
unsigned char *data = NULL;
int result;
*left = 0;
*right = 0;
*top = 0;
*bottom = 0;
w = find_client_win(dpy, w);
if (!w) return;
result = XGetWindowProperty(
dpy, w, atom_net_frame_extents,
0L, 4L, False, AnyPropertyType,
&type, &format, &nitems, &after,
(unsigned char **)&data);
if (result == Success) {
if (nitems == 4 && after == 0) {