diff --git a/espanso-ui/src/event.rs b/espanso-ui/src/event.rs index 98a298a..9e8ac89 100644 --- a/espanso-ui/src/event.rs +++ b/espanso-ui/src/event.rs @@ -20,4 +20,5 @@ #[derive(Debug, PartialEq, Clone)] pub enum UIEvent { TrayIconClick, + ContextMenuClick(u32), } diff --git a/espanso-ui/src/win32/mod.rs b/espanso-ui/src/win32/mod.rs index ac1008d..99efe94 100644 --- a/espanso-ui/src/win32/mod.rs +++ b/espanso-ui/src/win32/mod.rs @@ -40,7 +40,7 @@ const MAX_FILE_PATH: usize = 260; const MAX_ICON_COUNT: usize = 3; const UI_EVENT_TYPE_ICON_CLICK: i32 = 1; -//const UI_EVENT_TYPE_CONTEXT_MENU_CLICK: i32 = 2; +const UI_EVENT_TYPE_CONTEXT_MENU_CLICK: i32 = 2; // Take a look at the native.h header file for an explanation of the fields #[repr(C)] @@ -56,6 +56,7 @@ pub struct RawUIOptions { #[repr(C)] pub struct RawUIEvent { pub event_type: i32, + pub context_menu_id: u32, } #[allow(improper_ctypes)] @@ -326,10 +327,12 @@ impl Win32Remote { impl From for Option { fn from(raw: RawUIEvent) -> Option { match raw.event_type { - // Keyboard events UI_EVENT_TYPE_ICON_CLICK => { return Some(UIEvent::TrayIconClick); } + UI_EVENT_TYPE_CONTEXT_MENU_CLICK => { + return Some(UIEvent::ContextMenuClick(raw.context_menu_id)); + } _ => {} } diff --git a/espanso-ui/src/win32/native.cpp b/espanso-ui/src/win32/native.cpp index b8cce2b..e511e30 100644 --- a/espanso-ui/src/win32/native.cpp +++ b/espanso-ui/src/win32/native.cpp @@ -113,9 +113,12 @@ LRESULT CALLBACK ui_window_procedure(HWND window, unsigned int msg, WPARAM wp, L if (flags == 0) { - std::cout << "click menu" << std::flush; - // TODO: click - //context_menu_click_callback(manager_instance, (int32_t)idItem); + event.event_type = UI_EVENT_TYPE_CONTEXT_MENU_CLICK; + event.context_menu_id = (uint32_t) idItem; + if (variables->event_callback && variables->rust_instance) + { + variables->event_callback(variables->rust_instance, event); + } } break; diff --git a/espanso-ui/src/win32/native.h b/espanso-ui/src/win32/native.h index 9586aab..768f34f 100644 --- a/espanso-ui/src/win32/native.h +++ b/espanso-ui/src/win32/native.h @@ -40,6 +40,7 @@ typedef struct { typedef struct { int32_t event_type; + uint32_t context_menu_id; } UIEvent; typedef void (*EventCallback)(void * self, UIEvent data);