Skip to content

Commit

Permalink
Fix #6
Browse files Browse the repository at this point in the history
  • Loading branch information
nadimkobeissi committed Apr 3, 2024
1 parent e732648 commit 7b6631a
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use inputbot::KeybdKey::{self, *};
use json::JsonValue;
use regex::Regex;
use std::collections::HashMap;
use winvd::switch_desktop;

use crate::config;

Expand All @@ -29,7 +28,7 @@ pub fn bind_shortcuts() {
.take(shortcut.len() - 1)
.all(|key| key.is_pressed())
{
switch_desktop(i as i32).unwrap();
switch_to_desktop(i, 0);
return inputbot::BlockInput::Block;
}
return inputbot::BlockInput::DontBlock;
Expand All @@ -38,6 +37,24 @@ pub fn bind_shortcuts() {
}
}

fn switch_to_desktop(desktop: u32, tries: u8) {
if tries < 10 {
match winvd::switch_desktop(desktop) {
Ok(_) => {}
Err(_) => {
match winvd::create_desktop() {
Ok(_) => {
switch_to_desktop(desktop, tries + 1);
}
Err(e) => {
println!("Error: {:?}", e);
}
}
}
}
}
}

fn process_shortcut(config: &JsonValue, desktop: &str) -> Vec<KeybdKey> {
let shortcut_sanitized =
sanitize_keyboard_shortcut(config["shortcuts"][desktop].to_string());
Expand Down

0 comments on commit 7b6631a

Please sign in to comment.