fix(wm): enforce virtual desktop validation

This commit fixes a regression introduced in
2e86b607b2
which broke virtual desktop id validation on Windows 10.
This commit is contained in:
LGUG2Z
2021-12-02 09:26:54 -08:00
parent 1fb0a7cd6e
commit 409d374b72
5 changed files with 24 additions and 13 deletions

11
Cargo.lock generated
View File

@@ -563,9 +563,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.107" version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219" checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
[[package]] [[package]]
name = "linked-hash-map" name = "linked-hash-map"
@@ -1049,9 +1049,9 @@ checksum = "61b3909d758bb75c79f23d4736fac9433868679d3ad2ea7a61e3c25cfda9a088"
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.5" version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" checksum = "3c9613b5a66ab9ba26415184cfc41156594925a9cf3a2057e57f31ff145f6568"
[[package]] [[package]]
name = "same-file" name = "same-file"
@@ -1526,8 +1526,7 @@ dependencies = [
[[package]] [[package]]
name = "winvd" name = "winvd"
version = "0.0.20" version = "0.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/Ciantic/VirtualDesktopAccessor?branch=rust#11502c442f0cc0e6b5304e6a45022406ac502842"
checksum = "2bab2d5c745381b9c72797230150ec62244e693064fa0d654b5c4e6c75132a56"
dependencies = [ dependencies = [
"com", "com",
"crossbeam-channel", "crossbeam-channel",

View File

@@ -36,7 +36,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
uds_windows = "1" uds_windows = "1"
which = "4" which = "4"
winput = "0.2" winput = "0.2"
winvd = "0.0.20" winvd = { git = "https://github.com/Ciantic/VirtualDesktopAccessor", branch = "rust" }
miow = "0.4" miow = "0.4"
[dependencies.windows] [dependencies.windows]

View File

@@ -68,7 +68,10 @@ pub fn listen_for_commands(wm: Arc<Mutex<WindowManager>>) {
impl WindowManager { impl WindowManager {
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn process_command(&mut self, message: SocketMessage) -> Result<()> { pub fn process_command(&mut self, message: SocketMessage) -> Result<()> {
self.validate_virtual_desktop_id(); if let Err(error) = self.validate_virtual_desktop_id() {
tracing::info!("{}", error);
return Ok(());
}
match message { match message {
SocketMessage::Promote => self.promote_container_to_front()?, SocketMessage::Promote => self.promote_container_to_front()?,

View File

@@ -51,7 +51,10 @@ impl WindowManager {
return Ok(()); return Ok(());
} }
self.validate_virtual_desktop_id(); if let Err(error) = self.validate_virtual_desktop_id() {
tracing::info!("{}", error);
return Ok(());
}
// Make sure we have the most recently focused monitor from any event // Make sure we have the most recently focused monitor from any event
match event { match event {

View File

@@ -66,6 +66,7 @@ pub struct State {
pub is_paused: bool, pub is_paused: bool,
pub invisible_borders: Rect, pub invisible_borders: Rect,
pub resize_delta: i32, pub resize_delta: i32,
pub virtual_desktop_id: Option<usize>,
pub new_window_behaviour: WindowContainerBehaviour, pub new_window_behaviour: WindowContainerBehaviour,
pub work_area_offset: Option<Rect>, pub work_area_offset: Option<Rect>,
pub focus_follows_mouse: Option<FocusFollowsMouseImplementation>, pub focus_follows_mouse: Option<FocusFollowsMouseImplementation>,
@@ -86,6 +87,7 @@ impl From<&WindowManager> for State {
invisible_borders: wm.invisible_borders, invisible_borders: wm.invisible_borders,
work_area_offset: wm.work_area_offset, work_area_offset: wm.work_area_offset,
resize_delta: wm.resize_delta, resize_delta: wm.resize_delta,
virtual_desktop_id: wm.virtual_desktop_id,
new_window_behaviour: wm.window_container_behaviour, new_window_behaviour: wm.window_container_behaviour,
focus_follows_mouse: wm.focus_follows_mouse.clone(), focus_follows_mouse: wm.focus_follows_mouse.clone(),
mouse_follows_focus: wm.mouse_follows_focus, mouse_follows_focus: wm.mouse_follows_focus,
@@ -467,17 +469,21 @@ impl WindowManager {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn validate_virtual_desktop_id(&self) { pub fn validate_virtual_desktop_id(&self) -> Result<()> {
let virtual_desktop_id = winvd::helpers::get_current_desktop_number().ok(); let virtual_desktop_id = winvd::helpers::get_current_desktop_number().ok();
if let (Some(id), Some(virtual_desktop_id)) = (virtual_desktop_id, self.virtual_desktop_id) if let (Some(id), Some(virtual_desktop_id)) = (virtual_desktop_id, self.virtual_desktop_id)
{ {
if id != virtual_desktop_id { if id != virtual_desktop_id {
tracing::warn!( return Err(anyhow!(
"ignoring events while not on virtual desktop {}", "ignoring events and commands while not on virtual desktop {}",
virtual_desktop_id virtual_desktop_id
); ));
} }
} else {
tracing::warn!("unable to look up virtual desktop id, skipping validation");
} }
Ok(())
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]