From 9c1a6473a92ac443cb84a4f335914fb120056a27 Mon Sep 17 00:00:00 2001 From: yuzhiyong Date: Mon, 7 Oct 2024 15:20:32 +0800 Subject: [PATCH] fix: retry after a delay --- .vscode/settings.json | 2 +- src/main.rs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index f26e014..0af7daa 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { "editor.codeActionsOnSave": { - "source.fixAll": true + "source.fixAll": "explicit" }, "eslint.options": { // "overrideConfigFile": "eslint.config.js" diff --git a/src/main.rs b/src/main.rs index 08da108..7bdf4fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::error::Error; +use std::{error::Error, thread, time}; use x11rb::{ connection::Connection, protocol::{ @@ -53,6 +53,18 @@ fn main() -> Result<(), Box> { } else { connection.flush()?; } + } else { + thread::sleep(time::Duration::from_millis(50)); + + let active_window = get_active_window(&connection, root, net_active_window)?; + + if active_window != window_id { + if let Err(err) = connection.unmap_window(window_id) { + eprintln!("Error unmapping window: {:?}", err); + } else { + connection.flush()?; + } + } } } Ok(_) => (),