Skip to content

Commit

Permalink
fix(wm): handle winvd errors gracefully
Browse files Browse the repository at this point in the history
Of course, the crate built to interact with an undocumented COM API is
not the best candidate for unwrap and expect calls...

fix #15
  • Loading branch information
LGUG2Z committed Aug 19, 2021
1 parent 4e9b294 commit 6f7e877
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
19 changes: 10 additions & 9 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ pub fn listen_for_commands(wm: Arc<Mutex<WindowManager>>) {
impl WindowManager {
#[tracing::instrument(skip(self))]
pub fn process_command(&mut self, message: SocketMessage) -> Result<()> {
let virtual_desktop_id = winvd::helpers::get_current_desktop_number()
.expect("could not determine the current virtual desktop number");

if virtual_desktop_id != self.virtual_desktop_id {
tracing::warn!(
"ignoring commands while not on virtual desktop {}",
self.virtual_desktop_id
);
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 id != virtual_desktop_id {
tracing::warn!(
"ignoring events while not on virtual desktop {:?}",
virtual_desktop_id
);

return Ok(());
return Ok(());
}
}

match message {
Expand Down
21 changes: 11 additions & 10 deletions komorebi/src/process_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ impl WindowManager {
return Ok(());
}

let virtual_desktop_id = winvd::helpers::get_current_desktop_number()
.expect("could not determine the current virtual desktop number");

if virtual_desktop_id != self.virtual_desktop_id {
tracing::warn!(
"ignoring events while not on virtual desktop {}",
self.virtual_desktop_id
);

return 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 id != virtual_desktop_id {
tracing::warn!(
"ignoring events while not on virtual desktop {:?}",
virtual_desktop_id
);

return Ok(());
}
}

// Make sure we have the most recently focused monitor from any event
Expand Down
5 changes: 2 additions & 3 deletions komorebi/src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct WindowManager {
pub command_listener: UnixListener,
pub is_paused: bool,
pub hotwatch: Hotwatch,
pub virtual_desktop_id: usize,
pub virtual_desktop_id: Option<usize>,
}

#[derive(Debug, Serialize)]
Expand Down Expand Up @@ -123,8 +123,7 @@ impl WindowManager {

let listener = UnixListener::bind(&socket)?;

let virtual_desktop_id = winvd::helpers::get_current_desktop_number()
.expect("could not determine the current virtual desktop number");
let virtual_desktop_id = winvd::helpers::get_current_desktop_number().ok();

Ok(Self {
monitors: Ring::default(),
Expand Down

0 comments on commit 6f7e877

Please sign in to comment.