Skip to content

Commit d897740

Browse files
committed
Bug fix #153: Possible fix for a rare timing issue
Possible fix for a very rare timing issue in focus detection. Compton may fail to detect the currently focused window, when a window newly mapped gets focused, we failed to listen to events and get FocusIn from it in time, and a series of focus change events before it happens stay in the event queue and puzzled compton. My choice is to force focus recheck on all focus-related events. More roundtrips to X, but not necessarily worse performance, due to the high cost of focus flipping especially when there's a lot of conditions. Thanks to SlackBox for reporting. (#153)
1 parent 796e2c6 commit d897740

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ ifeq "$(NO_VSYNC_DRM)" ""
4949
CFG += -DCONFIG_VSYNC_DRM
5050
endif
5151

52-
# ==== OpenGL VSync ====
52+
# ==== OpenGL ====
5353
ifeq "$(NO_VSYNC_OPENGL)" ""
5454
CFG += -DCONFIG_VSYNC_OPENGL
5555
# -lGL must precede some other libraries, or it segfaults on FreeBSD (#74)

src/common.h

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
// #define DEBUG_GLX_GLSL 1
3131
// #define DEBUG_GLX_ERR 1
3232
// #define DEBUG_GLX_MARK 1
33+
// #define DEBUG_GLX_PAINTREG 1
3334
// #define MONITOR_REPAINT 1
3435

3536
// Whether to enable PCRE regular expression support in blacklists, enabled

src/compton.c

+8-12
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,12 @@ recheck_focus(session_t *ps) {
781781

782782
win *w = find_win_all(ps, wid);
783783

784+
#ifdef DEBUG_EVENTS
785+
print_timestamp(ps);
786+
printf_dbgf("(): %#010lx (%#010lx \"%s\") focused.\n", wid,
787+
(w ? w->id: None), (w ? w->name: NULL));
788+
#endif
789+
784790
// And we set the focus state here
785791
if (w) {
786792
win_set_focused(ps, w, true);
@@ -3815,12 +3821,7 @@ ev_focus_in(session_t *ps, XFocusChangeEvent *ev) {
38153821
ev_focus_report(ev);
38163822
#endif
38173823

3818-
if (!ev_focus_accept(ev))
3819-
return;
3820-
3821-
win *w = find_win_all(ps, ev->window);
3822-
if (w)
3823-
win_set_focused(ps, w, true);
3824+
recheck_focus(ps);
38243825
}
38253826

38263827
inline static void
@@ -3829,12 +3830,7 @@ ev_focus_out(session_t *ps, XFocusChangeEvent *ev) {
38293830
ev_focus_report(ev);
38303831
#endif
38313832

3832-
if (!ev_focus_accept(ev))
3833-
return;
3834-
3835-
win *w = find_win_all(ps, ev->window);
3836-
if (w)
3837-
win_set_focused(ps, w, false);
3833+
recheck_focus(ps);
38383834
}
38393835

38403836
inline static void

0 commit comments

Comments
 (0)