Skip to content

Commit

Permalink
feat: Implement with_menu_on_left_click on windows (#189)
Browse files Browse the repository at this point in the history
* feat: Implement with_menu_on_left_click on windows

* Update .changes/with_menu_on_left_click_windows.md

---------

Co-authored-by: Amr Bashir <github@amrbashir.me>
  • Loading branch information
htngr and amrbashir authored Sep 2, 2024
1 parent fa4de23 commit e711c1f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/with_menu_on_left_click_windows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tray-icon": "minor"
---

Implemented `TrayIcon::with_menu_on_left_click` on windows
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion src/platform_impl/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct TrayUserData {
tooltip: Option<String>,
entered: bool,
last_position: Option<PhysicalPosition<f64>>,
menu_on_left_click: bool,
}

pub struct TrayIcon {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit e711c1f

Please sign in to comment.