-
-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wm): add workspace reconciliator module
This commit adds the workspace_reconciliator module which uses a tightly bounded channel (cap: 1) to update the focused workspace in situations where the user or another process has foregrounded a window that is on a different workspace. This most often happens via Alt-Tab, or by clicking a link which opens in another application. workspace_reconciliator::Notification contains the target monitor and workspace indices, which when received allows for the correct workspace to be focused. These notifications are sent in process_event.rs when handling WindowManagerEvent::Show, Manage and Uncloak events. All previous logic pertaining to workspace reconciliation which lived in the handler for these events has been removed and replaced with notifications sent to the reconciliator. As the notifications channel is tightly capped and any notifications which overflow the cap will never be delivered, we are able to avoid the infinite workspace switching loops which happened when using the previous logic, which ran on every single event.
- Loading branch information
Showing
4 changed files
with
111 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use crate::WindowManager; | ||
use crossbeam_channel::Receiver; | ||
use crossbeam_channel::Sender; | ||
use parking_lot::Mutex; | ||
use std::sync::Arc; | ||
use std::sync::OnceLock; | ||
|
||
#[derive(Copy, Clone)] | ||
pub struct Notification { | ||
pub monitor_idx: usize, | ||
pub workspace_idx: usize, | ||
} | ||
|
||
static CHANNEL: OnceLock<(Sender<Notification>, Receiver<Notification>)> = OnceLock::new(); | ||
|
||
pub fn channel() -> &'static (Sender<Notification>, Receiver<Notification>) { | ||
CHANNEL.get_or_init(|| crossbeam_channel::bounded(1)) | ||
} | ||
|
||
pub fn event_tx() -> Sender<Notification> { | ||
channel().0.clone() | ||
} | ||
|
||
pub fn event_rx() -> Receiver<Notification> { | ||
channel().1.clone() | ||
} | ||
|
||
pub fn listen_for_notifications(wm: Arc<Mutex<WindowManager>>) { | ||
tracing::info!("listening"); | ||
let receiver = event_rx(); | ||
|
||
std::thread::spawn(move || -> color_eyre::Result<()> { | ||
for notification in receiver { | ||
tracing::info!("running reconciliation"); | ||
let mut wm = wm.lock(); | ||
let focused_monitor_idx = wm.focused_monitor_idx(); | ||
let focused_workspace_idx = | ||
wm.focused_workspace_idx_for_monitor_idx(focused_monitor_idx)?; | ||
|
||
let focused_pair = (focused_monitor_idx, focused_workspace_idx); | ||
let updated_pair = (notification.monitor_idx, notification.workspace_idx); | ||
|
||
if focused_pair != updated_pair { | ||
wm.focus_monitor(notification.monitor_idx)?; | ||
let mouse_follows_focus = wm.mouse_follows_focus; | ||
|
||
if let Some(monitor) = wm.focused_monitor_mut() { | ||
monitor.focus_workspace(notification.workspace_idx)?; | ||
monitor.load_focused_workspace(mouse_follows_focus)?; | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
}); | ||
} |