Skip to content

Commit 7926f2c

Browse files
committed
Fix COSMIC watcher intervention
1 parent 0cdf79f commit 7926f2c

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

watchers/src/watchers/wl_cosmic_toplevel_management.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use cctk::{
1414
};
1515
use std::{sync::Arc, thread};
1616
use tokio::sync::mpsc;
17+
use wayland_client::EventQueue;
1718

1819
struct WindowData {
1920
app_id: String,
@@ -28,22 +29,31 @@ struct ToplevelState {
2829
sender: mpsc::Sender<WindowData>,
2930
}
3031

31-
fn wayland_thread(sender: mpsc::Sender<WindowData>) -> anyhow::Result<()> {
32+
fn initialize_state(
33+
sender: mpsc::Sender<WindowData>,
34+
) -> anyhow::Result<(ToplevelState, EventQueue<ToplevelState>)> {
3235
let conn = Connection::connect_to_env()?;
33-
let (globals, mut event_queue) = registry_queue_init(&conn)?;
34-
let qh = event_queue.handle();
36+
let (globals, event_queue) = registry_queue_init(&conn)?;
37+
let qh: QueueHandle<ToplevelState> = event_queue.handle();
3538

3639
let registry_state = RegistryState::new(&globals);
3740
let toplevel_info_state = ToplevelInfoState::try_new(&registry_state, &qh)
3841
.ok_or_else(|| anyhow!("Required COSMIC toplevel protocols not found"))?;
3942

40-
let mut state = ToplevelState {
43+
let state = ToplevelState {
4144
registry_state,
4245
toplevel_info_state,
4346
active_toplevel_identifier: None,
4447
sender,
4548
};
4649

50+
Ok((state, event_queue))
51+
}
52+
53+
fn wayland_thread(
54+
mut state: ToplevelState,
55+
mut event_queue: EventQueue<ToplevelState>,
56+
) -> anyhow::Result<()> {
4757
log::debug!("Performing initial roundtrip");
4858
event_queue.roundtrip(&mut state)?;
4959
log::debug!("Initial roundtrip completed");
@@ -146,9 +156,10 @@ impl Watcher for WindowWatcher {
146156
// Create a channel to communicate between the new thread and the async runtime.
147157
let (sender, receiver) = mpsc::channel(32);
148158

159+
let (state, event_queue) = initialize_state(sender)?;
149160
// Spawn a dedicated OS thread for all blocking Wayland communication.
150161
thread::spawn(move || {
151-
if let Err(e) = wayland_thread(sender) {
162+
if let Err(e) = wayland_thread(state, event_queue) {
152163
log::error!("Wayland thread failed: {e:?}");
153164
}
154165
});

0 commit comments

Comments
 (0)