From 5087ea7538c32d953705f0352227648ecd8e33f0 Mon Sep 17 00:00:00 2001 From: James Magahern Date: Sat, 19 Jan 2019 20:17:41 -0800 Subject: Changes to get it to work with xsecurelock Only thing left to do is to get it to read the screen dimensions, since apparently we don't get window changed events. --- src/x11_support.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'src/x11_support.c') diff --git a/src/x11_support.c b/src/x11_support.c index 87dd1ac..8ab05c1 100644 --- a/src/x11_support.c +++ b/src/x11_support.c @@ -12,6 +12,33 @@ static Window __window = { 0 }; static Display *__display = NULL; +static Window get_window_from_environment_or_make_one(Display *display, int width, int height) +{ + Window window; + + const char *env_window = getenv("XSCREENSAVER_WINDOW"); + if (env_window != NULL && env_window[0] != 0) { + char *endptr = NULL; + unsigned long long number = strtoull(env_window, &endptr, 0); + window = (Window)number; + } else { + // Presumably this is for debugging + Window root_window = DefaultRootWindow(__display); + window = XCreateSimpleWindow( + display, // display + root_window, // parent window + 0, 0, // x, y + width, // width + height, // height + 0, // border_width + 0, // border + 0 // background + ); + } + + return window; +} + cairo_surface_t* x11_helper_acquire_cairo_surface(int width, int height) { __display = XOpenDisplay(NULL); @@ -20,17 +47,8 @@ cairo_surface_t* x11_helper_acquire_cairo_surface(int width, int height) return NULL; } - Window root_window = DefaultRootWindow(__display); - __window = XCreateSimpleWindow( - __display, // display - root_window, // parent window - 0, 0, // x, y - width, // width - height, // height - 0, // border_width - 0, // border - 0 // background - ); + // Create (or get) window + __window = get_window_from_environment_or_make_one(__display, width, height); // Enable key events XSelectInput(__display, __window, ButtonPressMask | KeyPressMask | StructureNotifyMask); -- cgit v1.2.3-54-g00ecf