Skip to content

Commit 4acb7e1

Browse files
committed
feat: ensure run ropy on X11 active window
1 parent e913fe3 commit 4acb7e1

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/gui/app.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ pub fn launch_app() {
262262
// Initialize X11 control
263263
#[cfg(target_os = "linux")]
264264
if env::var("DISPLAY").is_ok() {
265-
X11.get_or_init(|| X11::new().expect("Failed to connect x11rb"));
265+
let x11 = X11.get_or_init(|| X11::new().expect("Failed to connect x11rb"));
266+
let _ = x11.active_window();
266267
}
267268
});
268269
}

src/gui/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn active_window<T>(_window: &mut Window, _cx: &mut Context<T>) {
5252
#[cfg(target_os = "linux")]
5353
{
5454
if let Some(x11) = crate::gui::app::X11.get() {
55-
if let Err(e) = x11.activate_window() {
55+
if let Err(e) = x11.display_and_activate_window() {
5656
eprintln!("[ropy] Failed to activate window: {e}")
5757
}
5858
}

src/gui/x11.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,21 @@ impl X11 {
109109
self.send_wm_state_and_sync(self.net_wm_state_above, always_on_top, self.root_id)
110110
}
111111

112-
pub fn activate_window(&self) -> Result<(), Box<dyn Error>> {
112+
pub fn display_and_activate_window(&self) -> Result<(), Box<dyn Error>> {
113+
self.display_window()?;
114+
self.active_window()?;
115+
116+
Ok(())
117+
}
118+
119+
pub fn display_window(&self) -> Result<(), Box<dyn Error>> {
113120
self.connection.map_window(self.window_id)?;
114121
self.connection.sync()?;
115122

123+
Ok(())
124+
}
125+
126+
pub fn active_window(&self) -> Result<(), Box<dyn Error>> {
116127
let event = ClientMessageEvent::new(
117128
32,
118129
self.window_id,

0 commit comments

Comments
 (0)