Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/hotkey.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rdev::{listen, EventType, Key};
#[cfg(feature = "unstable_grab")]
use rdev::{grab, Event};
use std::sync::{Arc, Mutex};
use std::sync::{Arc, Mutex, atomic::{AtomicBool, Ordering}};
use std::thread;
use std::time::Duration;

Expand Down Expand Up @@ -145,6 +145,7 @@ fn parse_key(upper: &str) -> Option<Key> {
// Shared signal to open launcher
pub struct HotkeyTrigger {
pub open: Arc<Mutex<bool>>,
stop: Arc<AtomicBool>,
pub key: Key,
pub ctrl: bool,
pub shift: bool,
Expand All @@ -155,6 +156,7 @@ impl HotkeyTrigger {
pub fn new(hotkey: Hotkey) -> Self {
Self {
open: Arc::new(Mutex::new(false)),
stop: Arc::new(AtomicBool::new(false)),
key: hotkey.key,
ctrl: hotkey.ctrl,
shift: hotkey.shift,
Expand All @@ -164,6 +166,7 @@ impl HotkeyTrigger {

pub fn start_listener(&self) {
let open = self.open.clone();
let stop_flag = self.stop.clone();
let watch = self.key;
let need_ctrl = self.ctrl;
let need_shift = self.shift;
Expand Down Expand Up @@ -256,7 +259,7 @@ impl HotkeyTrigger {
}
}

loop {
while !stop_flag.load(Ordering::SeqCst) {
let mut watch_pressed = false;
let mut triggered = false;
let mut ctrl_pressed = false;
Expand Down Expand Up @@ -358,4 +361,8 @@ impl HotkeyTrigger {
false
}
}

pub fn stop(&self) {
self.stop.store(true, Ordering::SeqCst);
}
}
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ fn main() -> anyhow::Result<()> {
if let Some(qt) = &quit_trigger {
if qt.take() {
quit_requested = true;
qt.stop();
trigger.stop();
}
}

Expand Down