Skip to content

Commit 7b087cd

Browse files
committed
Merge upstream pull requests
chjj#320 chjj#362 chjj#379
2 parents eef2a3b + 930a152 commit 7b087cd

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

bin/compton-trans

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fi
114114
if test x"$action" = x'reset'; then
115115
xwininfo -root -tree \
116116
| sed -n 's/^ \(0x[[:xdigit:]]*\).*/\1/p' \
117-
| while IFS=$'\n' read wid; do
117+
| while IFS=$(printf '\n') read wid; do
118118
xprop -id "$wid" -remove _NET_WM_WINDOW_OPACITY
119119
done
120120
exit 0

src/compton.c

+33-9
Original file line numberDiff line numberDiff line change
@@ -2277,6 +2277,8 @@ static void
22772277
unmap_win(session_t *ps, win *w) {
22782278
if (!w || IsUnmapped == w->a.map_state) return;
22792279

2280+
if (w->destroyed) return;
2281+
22802282
// One last synchronization
22812283
if (w->paint.pixmap)
22822284
xr_sync(ps, w->paint.pixmap, &w->fence);
@@ -3204,17 +3206,18 @@ circulate_win(session_t *ps, XCirculateEvent *ce) {
32043206
}
32053207

32063208
static void
3207-
finish_destroy_win(session_t *ps, Window id) {
3208-
win **prev = NULL, *w = NULL;
3209+
finish_destroy_win(session_t *ps, win *w) {
3210+
assert(w->destroyed);
3211+
win **prev = NULL, *i = NULL;
32093212

32103213
#ifdef DEBUG_EVENTS
3211-
printf_dbgf("(%#010lx): Starting...\n", id);
3214+
printf_dbgf("(%#010lx): Starting...\n", w->id);
32123215
#endif
32133216

3214-
for (prev = &ps->list; (w = *prev); prev = &w->next) {
3215-
if (w->id == id && w->destroyed) {
3217+
for (prev = &ps->list; (i = *prev); prev = &i->next) {
3218+
if (w == i) {
32163219
#ifdef DEBUG_EVENTS
3217-
printf_dbgf("(%#010lx \"%s\"): %p\n", id, w->name, w);
3220+
printf_dbgf("(%#010lx \"%s\"): %p\n", w->id, w->name, w);
32183221
#endif
32193222

32203223
finish_unmap_win(ps, w);
@@ -3240,7 +3243,7 @@ finish_destroy_win(session_t *ps, Window id) {
32403243

32413244
static void
32423245
destroy_callback(session_t *ps, win *w) {
3243-
finish_destroy_win(ps, w->id);
3246+
finish_destroy_win(ps, w);
32443247
}
32453248

32463249
static void
@@ -3320,7 +3323,8 @@ xerror(Display __attribute__((unused)) *dpy, XErrorEvent *ev) {
33203323

33213324
if (ev->request_code == ps->composite_opcode
33223325
&& ev->minor_code == X_CompositeRedirectSubwindows) {
3323-
fprintf(stderr, "Another composite manager is already running\n");
3326+
fprintf(stderr, "Another composite manager is already running "
3327+
"(and does not handle _NET_WM_CM_Sn correctly)\n");
33243328
exit(1);
33253329
}
33263330

@@ -4348,6 +4352,16 @@ ev_screen_change_notify(session_t *ps,
43484352
}
43494353
}
43504354

4355+
inline static void
4356+
ev_selection_clear(session_t *ps,
4357+
XSelectionClearEvent __attribute__((unused)) *ev) {
4358+
// The only selection we own is the _NET_WM_CM_Sn selection.
4359+
// If we lose that one, we should exit.
4360+
fprintf(stderr, "Another composite manager started and "
4361+
"took the _NET_WM_CM_Sn selection.\n");
4362+
exit(1);
4363+
}
4364+
43514365
#if defined(DEBUG_EVENTS) || defined(DEBUG_RESTACK)
43524366
/**
43534367
* Get a window's name from window ID.
@@ -4440,6 +4454,9 @@ ev_handle(session_t *ps, XEvent *ev) {
44404454
case PropertyNotify:
44414455
ev_property_notify(ps, (XPropertyEvent *)ev);
44424456
break;
4457+
case SelectionClear:
4458+
ev_selection_clear(ps, (XSelectionClearEvent *)ev);
4459+
break;
44434460
default:
44444461
if (ps->shape_exists && ev->type == ps->shape_event) {
44454462
ev_shape_notify(ps, (XShapeEvent *) ev);
@@ -4892,6 +4909,7 @@ register_cm(session_t *ps) {
48924909
if (!ps->o.no_x_selection) {
48934910
unsigned len = strlen(REGISTER_PROP) + 2;
48944911
int s = ps->scr;
4912+
Atom atom;
48954913

48964914
while (s >= 10) {
48974915
++len;
@@ -4901,7 +4919,13 @@ register_cm(session_t *ps) {
49014919
char *buf = malloc(len);
49024920
snprintf(buf, len, REGISTER_PROP "%d", ps->scr);
49034921
buf[len - 1] = '\0';
4904-
XSetSelectionOwner(ps->dpy, get_atom(ps, buf), ps->reg_win, 0);
4922+
atom = get_atom(ps, buf);
4923+
4924+
if (XGetSelectionOwner(ps->dpy, atom) != None) {
4925+
fprintf(stderr, "Another composite manager is already running\n");
4926+
return false;
4927+
}
4928+
XSetSelectionOwner(ps->dpy, atom, ps->reg_win, 0);
49054929
free(buf);
49064930
}
49074931

src/compton.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ static void
919919
circulate_win(session_t *ps, XCirculateEvent *ce);
920920

921921
static void
922-
finish_destroy_win(session_t *ps, Window id);
922+
finish_destroy_win(session_t *ps, win *w);
923923

924924
static void
925925
destroy_callback(session_t *ps, win *w);

0 commit comments

Comments
 (0)