Skip to content

Commit

Permalink
Use the XComposite extension when present.
Browse files Browse the repository at this point in the history
Should fix some issues with semi-transparent notification windows.
  • Loading branch information
divVerent committed Oct 8, 2015
1 parent b6f1476 commit ee1825a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ xsecurelock_CPPFLAGS = \
if HAVE_SCRNSAVER
xsecurelock_CPPFLAGS += -DHAVE_SCRNSAVER
endif
if HAVE_COMPOSITE
xsecurelock_CPPFLAGS += -DHAVE_COMPOSITE
endif
if HAVE_XF86MISC
xsecurelock_CPPFLAGS += -DHAVE_XF86MISC
endif
Expand Down
4 changes: 4 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ AC_SEARCH_LIBS(XScreenSaverQueryExtension, Xss,
[have_scrnsaver=true], [have_scrnsaver=false])
AM_CONDITIONAL([HAVE_SCRNSAVER], [test x$have_scrnsaver = xtrue])

AC_SEARCH_LIBS(XCompositeQueryExtension, Xcomposite,
[have_composite=true], [have_composite=false])
AM_CONDITIONAL([HAVE_COMPOSITE], [test x$have_composite = xtrue])

AC_SEARCH_LIBS(XF86MiscSetGrabKeysState, Xxf86misc,
[have_xf86misc=true], [have_xf86misc=false])
AM_CONDITIONAL([HAVE_XF86MISC], [test x$have_xf86misc = xtrue])
Expand Down
34 changes: 32 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ limitations under the License.
#ifdef HAVE_SCRNSAVER
#include <X11/extensions/scrnsaver.h>
#endif
#ifdef HAVE_COMPOSITE
#include <X11/extensions/Xcomposite.h>
#endif
#ifdef HAVE_XF86MISC
#include <X11/extensions/xf86misc.h>
#endif
Expand Down Expand Up @@ -348,13 +351,35 @@ int main(int argc, char **argv) {
coverattrs.cursor =
XCreatePixmapCursor(display, bg, bg, &Black, &Black, 0, 0);

Window parent_window = root_window;

#ifdef HAVE_COMPOSITE
int composite_event_base, composite_error_base,
composite_major_version = 0, composite_minor_version = 0;
int have_composite =
XCompositeQueryExtension(display, &composite_event_base,
&composite_error_base) &&
// Require at least XComposite 0.3.
XCompositeQueryVersion(display, &composite_major_version,
&composite_minor_version) &&
(composite_major_version >= 1 || composite_minor_version >= 3);
Window composite_window;
if (have_composite) {
composite_window = XCompositeGetOverlayWindow(display, root_window);
parent_window = composite_window;
fprintf(stderr, "XComposite using parent window 0x%x.\n", parent_window);
} else {
fprintf(stderr, "XComposite extension not detected.\n");
}
#endif

// Create the two windows.
// grab_window is the outer window which we grab input on.
// saver_window is the "visible" window that the savers will draw on.
// These windows are separated because XScreenSaver's savers might
// XUngrabKeyboard on their window.
Window grab_window = XCreateWindow(
display, root_window, 0, 0, w, h, 0, CopyFromParent, InputOutput,
display, parent_window, 0, 0, w, h, 0, CopyFromParent, InputOutput,
CopyFromParent, CWOverrideRedirect | CWSaveUnder, &coverattrs);
Window saver_window = XCreateWindow(
display, grab_window, 0, 0, w, h, 0, CopyFromParent, InputOutput,
Expand Down Expand Up @@ -534,7 +559,7 @@ int main(int argc, char **argv) {
}
switch (priv.ev.type) {
case ConfigureNotify:
if (priv.ev.xconfigure.window == root_window) {
if (priv.ev.xconfigure.window == parent_window) {
// Root window size changed. Adjust the saver_window window too!
w = priv.ev.xconfigure.width;
h = priv.ev.xconfigure.height;
Expand Down Expand Up @@ -666,6 +691,11 @@ int main(int argc, char **argv) {
// Free our resources, and exit.
XDestroyWindow(display, saver_window);
XDestroyWindow(display, grab_window);
#ifdef HAVE_COMPOSITE
if (have_composite) {
XCompositeReleaseOverlayWindow(display, composite_window);
}
#endif
XFreeCursor(display, coverattrs.cursor);
XFreePixmap(display, bg);

Expand Down

0 comments on commit ee1825a

Please sign in to comment.