Skip to content

Commit

Permalink
Fix windows on x11 sometimes not matching real state, if plugin was l…
Browse files Browse the repository at this point in the history
…aunched when windows already existed
  • Loading branch information
Exidex committed Jan 8, 2025
1 parent 907e743 commit 95b0d0d
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions rust/plugin_runtime/src/plugins/applications/linux/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,19 @@ pub fn listen_on_x11_events(

conn.change_window_attributes(screen.root, &aux)?.check()?;

let _ = fetch_existing_windows(screen.root, &conn, &tokio_handle, &sender, atoms);
let mut init_window_data = Vec::<Window>::new();

let _ = fetch_existing_windows(screen.root, &conn, &tokio_handle, &sender, atoms, &mut init_window_data);

for window_id in init_window_data {
update_properties(
window_id,
&conn,
&tokio_handle,
&sender,
atoms,
);
}

loop {
match conn.wait_for_event()? {
Expand Down Expand Up @@ -314,11 +326,14 @@ fn fetch_existing_windows(
tokio_handle: &Handle,
sender: &Sender<JsX11ApplicationEvent>,
atoms: atoms::Atoms,
init_window_data: &mut Vec<Window>
) -> anyhow::Result<()> {
let query_tree = conn.query_tree(window_id)?.reply()?;

let attributes = conn.get_window_attributes(window_id)?.reply()?;

init_window_data.push(window_id);

send_event(&tokio_handle, &sender, JsX11ApplicationEvent::Init {
id: format!("{}", window_id),
parent_id: format!("{}", query_tree.parent),
Expand All @@ -331,16 +346,8 @@ fn fetch_existing_windows(
},
});

update_properties(
window_id,
&conn,
tokio_handle,
sender,
atoms,
);

for window in query_tree.children {
let _ = fetch_existing_windows(window, conn, tokio_handle, sender, atoms);
let _ = fetch_existing_windows(window, conn, tokio_handle, sender, atoms, init_window_data);
}

Ok(())
Expand Down

0 comments on commit 95b0d0d

Please sign in to comment.