Reopen the window on a double-click of the tray icon (#113)

- A double-click (WM_LBUTTONDBLCLK) or Enter/Space (NIN_KEYSELECT) opens the
  window; a single click does nothing, so its first click no longer reopens it
- The right-click menu is unchanged
- The notice and the user guide say to double-click

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
nessarandClaude Haiku 5.5 authored and TO committed 2026-11-25 20:04:32 +01:00
1 parent 98a8a14343
commit e81611371f
2 files changed
+44 -7

No files matched your search

+43 -6
View File
@@ -32,8 +32,24 @@ const NIN_KEYSELECT: u32 = NIN_SELECT | 1;
pub const UNAVAILABLE: &str =
"La zone de notification est indisponible. La fenêtre reste accessible.";
const NOTICE_TITLE: &str = "Arena Tracker reste ouvert";
const NOTICE_TEXT: &str = "L’application continue dans la zone de notification. Cliquez sur \
son icône pour la rouvrir, ou faites un clic droit pour la quitter.";
const NOTICE_TEXT: &str = "L’application continue dans la zone de notification. Double-cliquez \
sur son icône pour la rouvrir, ou faites un clic droit pour la quitter.";
/// What a notification icon event asks for. A single click does nothing: the shell also sends
/// it for the first click of a double-click, and opening on it would show the window twice.
#[derive(Debug, PartialEq, Eq)]
enum TrayAction {
Open,
Menu,
}
fn tray_action(event: u32) -> Option<TrayAction> {
match event {
WM_LBUTTONDBLCLK | NIN_KEYSELECT => Some(TrayAction::Open),
WM_CONTEXTMENU => Some(TrayAction::Menu),
_ => None,
}
}
pub(crate) fn window_hwnd(window: &Window) -> Option<HWND> {
let RawWindowHandle::Win32(handle) = HasWindowHandle::window_handle(window).ok()?.as_raw()
@@ -404,10 +420,10 @@ unsafe extern "system" fn window_proc(
}
TRAY_MESSAGE => {
if tray.hidden.get() && (lparam.0 as u32 >> 16) == ICON_ID {
match lparam.0 as u32 & 0xffff {
WM_CONTEXTMENU => tray.show_menu(),
NIN_SELECT | NIN_KEYSELECT => tray.open(),
_ => {}
match tray_action(lparam.0 as u32 & 0xffff) {
Some(TrayAction::Open) => tray.open(),
Some(TrayAction::Menu) => tray.show_menu(),
None => {}
}
}
return LRESULT(0);
@@ -430,3 +446,24 @@ unsafe extern "system" fn window_proc(
}
unsafe { DefSubclassProc(hwnd, message, wparam, lparam) }
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_double_click_and_the_keyboard_open_the_window() {
assert_eq!(tray_action(WM_LBUTTONDBLCLK), Some(TrayAction::Open));
assert_eq!(tray_action(NIN_KEYSELECT), Some(TrayAction::Open));
}
#[test]
fn a_single_click_does_nothing() {
assert_eq!(tray_action(NIN_SELECT), None);
}
#[test]
fn a_right_click_opens_the_menu() {
assert_eq!(tray_action(WM_CONTEXTMENU), Some(TrayAction::Menu));
}
}