aboutsummaryrefslogtreecommitdiff
path: root/src/x11_support.c
diff options
context:
space:
mode:
authorJames Magahern <james@magahern.com>2019-01-19 20:17:41 -0800
committerJames Magahern <james@magahern.com>2019-01-19 20:17:41 -0800
commit5087ea7538c32d953705f0352227648ecd8e33f0 (patch)
tree397d9b897a1eae9fb38648788c3eb49bfd68ac1b /src/x11_support.c
parentAuthentication now works (diff)
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.
Diffstat (limited to 'src/x11_support.c')
-rw-r--r--src/x11_support.c40
1 files changed, 29 insertions, 11 deletions
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);