oxwm

https://git.tonybtw.com/oxwm.git git://git.tonybtw.com/oxwm.git

added fix for overlay not being centered

Commit
1bf30963a2a7fbd19430834e9fcf287cf7173ed3
Parent
d3a909c
Author
tonybtw <tonybtw@tonybtw.com>
Date
2025-12-11 08:57:39

Diff

diff --git a/src/overlay/keybind.rs b/src/overlay/keybind.rs
index f030c14..59d3113 100644
--- a/src/overlay/keybind.rs
+++ b/src/overlay/keybind.rs
@@ -61,6 +61,8 @@ impl KeybindOverlay {
         connection: &RustConnection,
         font: &Font,
         keybindings: &[KeyBinding],
+        monitor_x: i16,
+        monitor_y: i16,
         screen_width: u16,
         screen_height: u16,
     ) -> Result<(), X11Error> {
@@ -93,8 +95,8 @@ impl KeybindOverlay {
         let height =
             title_height + (self.keybindings.len() as u16 * line_height) + (PADDING as u16 * 2);
 
-        let x = ((screen_width - width) / 2) as i16;
-        let y = ((screen_height - height) / 2) as i16;
+        let x = monitor_x + ((screen_width - width) / 2) as i16;
+        let y = monitor_y + ((screen_height - height) / 2) as i16;
 
         self.base.configure(connection, x, y, width, height)?;
 
@@ -113,13 +115,15 @@ impl KeybindOverlay {
         connection: &RustConnection,
         font: &Font,
         keybindings: &[KeyBinding],
+        monitor_x: i16,
+        monitor_y: i16,
         screen_width: u16,
         screen_height: u16,
     ) -> Result<(), X11Error> {
         if self.base.is_visible {
             self.hide(connection)?;
         } else {
-            self.show(connection, font, keybindings, screen_width, screen_height)?;
+            self.show(connection, font, keybindings, monitor_x, monitor_y, screen_width, screen_height)?;
         }
         Ok(())
     }
diff --git a/src/window_manager.rs b/src/window_manager.rs
index 492f271..0beac56 100644
--- a/src/window_manager.rs
+++ b/src/window_manager.rs
@@ -837,6 +837,8 @@ impl WindowManager {
                     &self.connection,
                     &self.font,
                     &self.config.keybindings,
+                    monitor.screen_x as i16,
+                    monitor.screen_y as i16,
                     monitor.screen_width as u16,
                     monitor.screen_height as u16,
                 )?;
@@ -2572,7 +2574,9 @@ impl WindowManager {
                     use crate::keyboard::keysyms;
                     if let Some(mapping) = &self.keyboard_mapping {
                         let keysym = mapping.keycode_to_keysym(e.detail);
-                        if keysym == keysyms::XK_ESCAPE || keysym == keysyms::XK_Q {
+                        let is_escape = keysym == keysyms::XK_ESCAPE;
+                        let is_q = keysym == keysyms::XK_Q || keysym == 0x0051;
+                        if is_escape || is_q {
                             if let Err(error) = self.keybind_overlay.hide(&self.connection) {
                                 eprintln!("Failed to hide keybind overlay: {:?}", error);
                             }
@@ -2582,6 +2586,7 @@ impl WindowManager {
                 return Ok(None);
             }
             Event::ButtonPress(ref e) if e.event == self.keybind_overlay.window() => {
+                self.connection.allow_events(Allow::REPLAY_POINTER, e.time)?;
                 return Ok(None);
             }
             Event::Expose(ref expose_event) if expose_event.window == self.keybind_overlay.window() => {
@@ -2768,6 +2773,12 @@ impl WindowManager {
                 }
             }
             Event::ButtonPress(event) => {
+                if self.keybind_overlay.is_visible() && event.event != self.keybind_overlay.window() {
+                    if let Err(error) = self.keybind_overlay.hide(&self.connection) {
+                        eprintln!("Failed to hide keybind overlay: {:?}", error);
+                    }
+                }
+
                 let is_bar_click = self
                     .bars
                     .iter()