diff --git a/.changes/with_menu_on_left_click_windows.md b/.changes/with_menu_on_left_click_windows.md new file mode 100644 index 0000000..5ff35b7 --- /dev/null +++ b/.changes/with_menu_on_left_click_windows.md @@ -0,0 +1,5 @@ +--- +"tray-icon": "minor" +--- + +Implemented `TrayIcon::with_menu_on_left_click` on windows diff --git a/src/lib.rs b/src/lib.rs index 23fa4bf..79591e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -147,7 +147,7 @@ pub struct TrayIconAttributes { /// Use the icon as a [template](https://developer.apple.com/documentation/appkit/nsimage/1520017-template?language=objc). **macOS only**. pub icon_is_template: bool, - /// Whether to show the tray menu on left click or not, default is `true`. **macOS only**. + /// Whether to show the tray menu on left click or not, default is `true`. **macOS & Windows only**. pub menu_on_left_click: bool, /// Tray icon title. diff --git a/src/platform_impl/windows/mod.rs b/src/platform_impl/windows/mod.rs index f973015..dbbb7b5 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -59,6 +59,7 @@ struct TrayUserData { tooltip: Option, entered: bool, last_position: Option>, + menu_on_left_click: bool, } pub struct TrayIcon { @@ -93,6 +94,7 @@ impl TrayIcon { tooltip: attrs.tooltip.clone(), entered: false, last_position: None, + menu_on_left_click: attrs.menu_on_left_click, }; let hwnd = CreateWindowExW( @@ -436,7 +438,9 @@ unsafe extern "system" fn tray_proc( TrayIconEvent::send(event); - if lparam as u32 == WM_RBUTTONDOWN { + if lparam as u32 == WM_RBUTTONDOWN + || (userdata.menu_on_left_click && lparam as u32 == WM_LBUTTONDOWN) + { if let Some(menu) = userdata.hpopupmenu { show_tray_menu(hwnd, menu, cursor.x, cursor.y); }