diff --git a/.changes/linux-global-shortcut.md b/.changes/linux-global-shortcut.md new file mode 100644 index 000000000..706ff5d7e --- /dev/null +++ b/.changes/linux-global-shortcut.md @@ -0,0 +1,5 @@ +--- +"tao": "patch" +--- + +On Linux, fix global shortcut are never triggered when a Lock key is ON, eg. NumLock, CapsLock ...etc \ No newline at end of file diff --git a/examples/system_tray.rs b/examples/system_tray.rs index 5e279089b..dee856286 100644 --- a/examples/system_tray.rs +++ b/examples/system_tray.rs @@ -24,7 +24,7 @@ fn main() { // it to Tao. But on Windows, you will have to account for screen scaling. Here we use 32px, // since it seems to work well enough in most cases. Be careful about going too high, or // you'll be bitten by the low-quality downscaling built into the WM. - let path = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/icon.png"); + let path = "icon.png"; let main_tray_id = TrayId::new("main-tray"); let second_tray_id = TrayId::new("2nd-tray"); @@ -38,7 +38,7 @@ fn main() { .set_icon(icon.clone()); } - let quit = tray_menu.add_item(MenuItemAttributes::new("Quit")); + let mut quit = tray_menu.add_item(MenuItemAttributes::new("Quit")); #[cfg(target_os = "linux")] let system_tray = SystemTrayBuilder::new(icon.clone(), Some(tray_menu)) @@ -73,9 +73,10 @@ fn main() { } => { if menu_id == quit.clone().id() { // drop the system tray before exiting to remove the icon from system tray on Windows - drop(&system_tray); - drop(&second_system_tray); - *control_flow = ControlFlow::Exit; + quit.set_title("Hell"); + // drop(&system_tray); + // drop(&second_system_tray); + // *control_flow = ControlFlow::Exit; } else if menu_id == log.clone().id() { println!("Log clicked"); } diff --git a/src/platform_impl/linux/global_shortcut.rs b/src/platform_impl/linux/global_shortcut.rs index e6b4f6e0e..52d3b2fc9 100644 --- a/src/platform_impl/linux/global_shortcut.rs +++ b/src/platform_impl/linux/global_shortcut.rs @@ -62,7 +62,9 @@ impl ShortcutManager { (xlib.XNextEvent)(display, &mut event); if let xlib::KeyRelease = event.get_type() { let keycode = event.key.keycode; - let modifiers = event.key.state; + // X11 sends masks for Lock keys also and we only care about the 4 below + let modifiers = event.key.state + & (xlib::ControlMask | xlib::ShiftMask |= xlib::Mod4Mask | xlib::Mod1Mask); if let Some(hotkey_id) = hotkey_map.lock().unwrap().get(&(keycode as i32, modifiers)) { event_loop_channel diff --git a/src/platform_impl/windows/menu.rs b/src/platform_impl/windows/menu.rs index 9009a2a42..76177d04c 100644 --- a/src/platform_impl/windows/menu.rs +++ b/src/platform_impl/windows/menu.rs @@ -4,7 +4,7 @@ use std::{collections::HashMap, fmt, ptr, sync::Mutex}; use windows::{ - core::{PCWSTR, PWSTR}, + core::{PCWSTR, PWSTR, PSTR}, Win32::{ Foundation::{HWND, LPARAM, LRESULT, WPARAM}, UI::{ @@ -123,14 +123,15 @@ impl MenuItemAttributes { title.push_str(accelerator.to_string().as_str()); } unsafe { - let info = MENUITEMINFOW { - cbSize: std::mem::size_of::() as _, - fMask: MIIM_STRING, - dwTypeData: PWSTR(util::encode_wide(title).as_mut_ptr()), + let info = MENUITEMINFOA { + cbSize: std::mem::size_of::() as _, + fMask: MIIM_TYPE, + fType: MFT_STRING, + dwTypeData: PSTR(util::encode_wide(title).as_mut_ptr() as _), ..Default::default() }; - SetMenuItemInfoW(self.1, self.0 as u32, false, &info); + SetMenuItemInfoA(self.1, self.0 as u32, false, &info); } } pub fn set_selected(&mut self, selected: bool) {