tony / oxwm

added fix for overlay not being centered Browse files
tonybtw committed 2025-12-11 parent d3a909c commit 1bf30963a2a7fbd19430834e9fcf287cf7173ed3
Showing 2 changed files with 19 additions and 4 deletions. UnifiedSplit
+7 −3 src/overlay/keybind.rs
@@ -61,6 +61,8 @@ impl KeybindOverlay {
61 connection: &RustConnection, 61 connection: &RustConnection,
62 font: &Font, 62 font: &Font,
63 keybindings: &[KeyBinding], 63 keybindings: &[KeyBinding],
64 + monitor_x: i16,
65 + monitor_y: i16,
64 screen_width: u16, 66 screen_width: u16,
65 screen_height: u16, 67 screen_height: u16,
66 ) -> Result<(), X11Error> { 68 ) -> Result<(), X11Error> {
@@ -93,8 +95,8 @@ impl KeybindOverlay {
93 let height = 95 let height =
94 title_height + (self.keybindings.len() as u16 * line_height) + (PADDING as u16 * 2); 96 title_height + (self.keybindings.len() as u16 * line_height) + (PADDING as u16 * 2);
95 97
96 - let x = ((screen_width - width) / 2) as i16; 98 + let x = monitor_x + ((screen_width - width) / 2) as i16;
97 - let y = ((screen_height - height) / 2) as i16; 99 + let y = monitor_y + ((screen_height - height) / 2) as i16;
98 100
99 self.base.configure(connection, x, y, width, height)?; 101 self.base.configure(connection, x, y, width, height)?;
100 102
@@ -113,13 +115,15 @@ impl KeybindOverlay {
113 connection: &RustConnection, 115 connection: &RustConnection,
114 font: &Font, 116 font: &Font,
115 keybindings: &[KeyBinding], 117 keybindings: &[KeyBinding],
118 + monitor_x: i16,
119 + monitor_y: i16,
116 screen_width: u16, 120 screen_width: u16,
117 screen_height: u16, 121 screen_height: u16,
118 ) -> Result<(), X11Error> { 122 ) -> Result<(), X11Error> {
119 if self.base.is_visible { 123 if self.base.is_visible {
120 self.hide(connection)?; 124 self.hide(connection)?;
121 } else { 125 } else {
122 - self.show(connection, font, keybindings, screen_width, screen_height)?; 126 + self.show(connection, font, keybindings, monitor_x, monitor_y, screen_width, screen_height)?;
123 } 127 }
124 Ok(()) 128 Ok(())
125 } 129 }
+12 −1 src/window_manager.rs
@@ -837,6 +837,8 @@ impl WindowManager {
837 &self.connection, 837 &self.connection,
838 &self.font, 838 &self.font,
839 &self.config.keybindings, 839 &self.config.keybindings,
840 + monitor.screen_x as i16,
841 + monitor.screen_y as i16,
840 monitor.screen_width as u16, 842 monitor.screen_width as u16,
841 monitor.screen_height as u16, 843 monitor.screen_height as u16,
842 )?; 844 )?;
@@ -2572,7 +2574,9 @@ impl WindowManager {
2572 use crate::keyboard::keysyms; 2574 use crate::keyboard::keysyms;
2573 if let Some(mapping) = &self.keyboard_mapping { 2575 if let Some(mapping) = &self.keyboard_mapping {
2574 let keysym = mapping.keycode_to_keysym(e.detail); 2576 let keysym = mapping.keycode_to_keysym(e.detail);
2575 - if keysym == keysyms::XK_ESCAPE || keysym == keysyms::XK_Q { 2577 + let is_escape = keysym == keysyms::XK_ESCAPE;
2578 + let is_q = keysym == keysyms::XK_Q || keysym == 0x0051;
2579 + if is_escape || is_q {
2576 if let Err(error) = self.keybind_overlay.hide(&self.connection) { 2580 if let Err(error) = self.keybind_overlay.hide(&self.connection) {
2577 eprintln!("Failed to hide keybind overlay: {:?}", error); 2581 eprintln!("Failed to hide keybind overlay: {:?}", error);
2578 } 2582 }
@@ -2582,6 +2586,7 @@ impl WindowManager {
2582 return Ok(None); 2586 return Ok(None);
2583 } 2587 }
2584 Event::ButtonPress(ref e) if e.event == self.keybind_overlay.window() => { 2588 Event::ButtonPress(ref e) if e.event == self.keybind_overlay.window() => {
2589 + self.connection.allow_events(Allow::REPLAY_POINTER, e.time)?;
2585 return Ok(None); 2590 return Ok(None);
2586 } 2591 }
2587 Event::Expose(ref expose_event) if expose_event.window == self.keybind_overlay.window() => { 2592 Event::Expose(ref expose_event) if expose_event.window == self.keybind_overlay.window() => {
@@ -2768,6 +2773,12 @@ impl WindowManager {
2768 } 2773 }
2769 } 2774 }
2770 Event::ButtonPress(event) => { 2775 Event::ButtonPress(event) => {
2776 + if self.keybind_overlay.is_visible() && event.event != self.keybind_overlay.window() {
2777 + if let Err(error) = self.keybind_overlay.hide(&self.connection) {
2778 + eprintln!("Failed to hide keybind overlay: {:?}", error);
2779 + }
2780 + }
2781 +
2771 let is_bar_click = self 2782 let is_bar_click = self
2772 .bars 2783 .bars
2773 .iter() 2784 .iter()