From 22204f2845059fed4f51272b25e46f0a73263e0e Mon Sep 17 00:00:00 2001 From: i509VCB Date: Fri, 17 Dec 2021 11:59:19 -0600 Subject: [PATCH] x11: internal window to send close backend event to --- src/backend/x11/mod.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/backend/x11/mod.rs b/src/backend/x11/mod.rs index 5eadebf..c71d305 100644 --- a/src/backend/x11/mod.rs +++ b/src/backend/x11/mod.rs @@ -118,7 +118,10 @@ use x11rb::{ protocol::{ self as x11, dri3::ConnectionExt as _, - xproto::{ColormapAlloc, ConnectionExt, PixmapWrapper, VisualClass}, + xproto::{ + ColormapAlloc, ConnectionExt, CreateWindowAux, PixmapWrapper, VisualClass, WindowClass, + WindowWrapper, + }, ErrorKind, }, rust_connection::{ReplyError, RustConnection}, @@ -216,9 +219,28 @@ impl X11Backend { let atoms = Atoms::new(&*connection)?.reply()?; + // We need to give the X11Source a window we have created, we cannot send the close event to the root + // window (0). To handle this, we will create a window we never map or provide to users to the backend + // can be sent a message for shutdown. + + let close_window = WindowWrapper::create_window( + &*connection, + x11rb::COPY_DEPTH_FROM_PARENT, + screen.root, + 0, + 0, + 1, + 1, + 0, + WindowClass::INPUT_OUTPUT, + x11rb::COPY_FROM_PARENT, + &CreateWindowAux::new(), + )? + .into_window(); + let source = X11Source::new( connection.clone(), - 0, // send the close request to something to ensure we can wake the reader thread for events. + close_window, atoms._SMITHAY_X11_BACKEND_CLOSE, logger.clone(), );