diff --git a/Cargo.lock b/Cargo.lock index 2b0e05a..7d71219 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -149,6 +149,7 @@ dependencies = [ "strum_macros", "uinput", "winapi", + "workctl", "x11", ] diff --git a/src/main.rs b/src/main.rs index 2b8f4cc..3cdf264 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, 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!"); } diff --git a/src/modules/external_interface.rs b/src/modules/external_interface.rs index ff68058..8b45fb9 100644 --- a/src/modules/external_interface.rs +++ b/src/modules/external_interface.rs @@ -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) { +pub fn create_keyboard_hooks(channel_tx: crossbeam_channel::Sender, 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) { 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 {