Skip to content

Commit

Permalink
fix(windows): send correct position for system tray events, closes #295
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Jan 30, 2022
1 parent 6ade5ea commit f3b6307
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changes/windows-system-tray-event-position.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": "patch"
---

On Windows, send correct position on system tray events.
19 changes: 7 additions & 12 deletions src/platform_impl/windows/system_tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
// SPDX-License-Identifier: Apache-2.0

use super::{
dpi::{dpi_to_scale_factor, hwnd_dpi},
menu::{subclass_proc as menu_subclass_proc, Menu, MenuHandler},
util, OsError,
};
use crate::{
dpi::{LogicalPosition, LogicalSize},
dpi::{PhysicalPosition, PhysicalSize},
error::OsError as RootOsError,
event::{Event, Rectangle, TrayEvent},
event_loop::EventLoopWindowTarget,
Expand Down Expand Up @@ -239,20 +238,16 @@ unsafe extern "system" fn tray_subclass_proc(
};
let icon_rect = Shell_NotifyIconGetRect(&nid).unwrap_or_default();

let dpi = hwnd_dpi(hwnd);
let scale_factor = dpi_to_scale_factor(dpi);

let mut cursor = POINT { x: 0, y: 0 };
GetCursorPos(&mut cursor as _);

let position = LogicalPosition::new(cursor.x, cursor.y).to_physical(scale_factor);
let position = PhysicalPosition::new(cursor.x as f64, cursor.y as f64);
let bounds = Rectangle {
position: LogicalPosition::new(icon_rect.left, icon_rect.top).to_physical(scale_factor),
size: LogicalSize::new(
icon_rect.right - icon_rect.left,
icon_rect.bottom - icon_rect.top,
)
.to_physical(scale_factor),
position: PhysicalPosition::new(icon_rect.left as f64, icon_rect.top as f64),
size: PhysicalSize::new(
(icon_rect.right - icon_rect.left) as f64,
(icon_rect.bottom - icon_rect.top) as f64,
),
};

match lparam.0 as u32 {
Expand Down

0 comments on commit f3b6307

Please sign in to comment.