fixed hanging keyboard hooks

This commit is contained in:
Nickiel12 2021-12-30 15:26:08 -08:00
parent f4161c8dbb
commit 3870a25f87
3 changed files with 9 additions and 5 deletions

1
Cargo.lock generated
View file

@ -149,6 +149,7 @@ dependencies = [
"strum_macros",
"uinput",
"winapi",
"workctl",
"x11",
]

View file

@ -39,10 +39,11 @@ fn main() {
let mut socket = Socket::handle_connections(socket_listener, from_socket_tx);
setup_control_c(control_c_flag_tx);
let (hotkey_close_flag_tx, hotkey_close_flag_rx) = sync_flag::new_syncflag(true);
setup_control_c(control_c_flag_tx, hotkey_close_flag_tx);
let hotkey_handle = thread::spawn(move || {
modules::external_interface::create_keyboard_hooks(hotkey_channel_tx);
modules::external_interface::create_keyboard_hooks(hotkey_channel_tx, hotkey_close_flag_rx);
});
//until control_c is caught, check the queue of incoming
@ -87,9 +88,11 @@ fn handle_instructions(mut instructions: Vec<StateUpdate>, state: &mut StreamSta
}
}
fn setup_control_c(mut control_c_flag_tx: sync_flag::SyncFlagTx) {
fn setup_control_c(mut control_c_flag_tx: sync_flag::SyncFlagTx, mut hotkey_close_flag_tx: sync_flag::SyncFlagTx) {
ctrlc::set_handler(move || {
println!("ctrl c caught");
control_c_flag_tx.set(true);
hotkey_close_flag_tx.set(false);
}).expect("control C handler failed!");
}

View file

@ -4,7 +4,7 @@ use super::stream_states::{state_update::StateUpdate, enums::{SlideChange, SubSc
const AHK_FILES_FOLDER: &str = "./src/ahk_files/";
pub const OPTIONS_PATH: &str = "./options.json";
pub fn create_keyboard_hooks(channel_tx: crossbeam_channel::Sender<String>) {
pub fn create_keyboard_hooks(channel_tx: crossbeam_channel::Sender<String>, close_flag: workctl::sync_flag::SyncFlagRx) {
let tx_1 = channel_tx.clone();
inputbot::KeybdKey::PageUpKey.bind(move || {
@ -16,7 +16,7 @@ pub fn create_keyboard_hooks(channel_tx: crossbeam_channel::Sender<String>) {
tx_2.send(StateUpdate::ChangeSlide(SlideChange::Previous).to_json().to_string()).unwrap();
});
inputbot::handle_input_events();
inputbot::handle_input_events(close_flag);
}
pub struct Hotkeys {