From e3b164ae934e96fa62bde8e2dab721b234a9f49a Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Mon, 8 May 2023 19:43:58 +1000 Subject: [PATCH] [v3 windows] Systray callback handlers --- v3/pkg/application/systemtray.go | 32 ++++++++++++++++++++++++ v3/pkg/application/systemtray_windows.go | 28 +++++++++++++++------ v3/pkg/w32/constants.go | 1 + 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/v3/pkg/application/systemtray.go b/v3/pkg/application/systemtray.go index 1cfb8327..285b959f 100644 --- a/v3/pkg/application/systemtray.go +++ b/v3/pkg/application/systemtray.go @@ -36,6 +36,8 @@ type SystemTray struct { rightButtonClickHandler func() leftButtonDoubleClickHandler func() rightButtonDoubleClickHandler func() + mouseEnterHandler func() + mouseLeaveHandler func() // Platform specific implementation impl systemTrayImpl @@ -133,3 +135,33 @@ func (s *SystemTray) Destroy() { } s.impl.destroy() } + +func (s *SystemTray) OnLeftButtonClick(handler func()) *SystemTray { + s.leftButtonClickHandler = handler + return s +} + +func (s *SystemTray) OnRightButtonClick(handler func()) *SystemTray { + s.rightButtonClickHandler = handler + return s +} + +func (s *SystemTray) OnLeftButtonDoubleClick(handler func()) *SystemTray { + s.leftButtonDoubleClickHandler = handler + return s +} + +func (s *SystemTray) OnRightButtonDoubleClick(handler func()) *SystemTray { + s.rightButtonDoubleClickHandler = handler + return s +} + +func (s *SystemTray) OnMouseEnter(handler func()) *SystemTray { + s.mouseEnterHandler = handler + return s +} + +func (s *SystemTray) OnMouseLeave(handler func()) *SystemTray { + s.mouseLeaveHandler = handler + return s +} diff --git a/v3/pkg/application/systemtray_windows.go b/v3/pkg/application/systemtray_windows.go index 87f53864..4c10d859 100644 --- a/v3/pkg/application/systemtray_windows.go +++ b/v3/pkg/application/systemtray_windows.go @@ -21,17 +21,12 @@ type windowsSystemTray struct { // Platform specific implementation uid uint32 hwnd w32.HWND - appIcon w32.HICON lightModeIcon w32.HICON darkModeIcon w32.HICON currentIcon w32.HICON //menu *w32.PopupMenu } -func (s *windowsSystemTray) setIconPosition(position int) { - // Unsupported - do nothing -} - func (s *windowsSystemTray) setMenu(menu *Menu) { //s.menu = menu panic("implement me") @@ -88,6 +83,11 @@ func (s *windowsSystemTray) run() { // TODO: Set Menu + // Set Default Callbacks + s.parent.leftButtonClickHandler = func() { + println("Left Button Clicked") + } + // Update the icon s.updateIcon() @@ -173,7 +173,7 @@ func (s *windowsSystemTray) destroy() { func (s *windowsSystemTray) wndProc(msg uint32, wParam, lParam uintptr) uintptr { switch msg { case WM_USER_SYSTRAY: - msg := (lParam & 0xffff) + msg := lParam & 0xffff switch msg { case w32.WM_LBUTTONUP: if s.parent.leftButtonClickHandler != nil { @@ -191,9 +191,17 @@ func (s *windowsSystemTray) wndProc(msg uint32, wParam, lParam uintptr) uintptr if s.parent.rightButtonDoubleClickHandler != nil { s.parent.rightButtonDoubleClickHandler() } - default: - println(w32.WMMessageToString(msg)) + case 0x0406: + if s.parent.mouseEnterHandler != nil { + s.parent.mouseEnterHandler() + } + case 0x0407: + if s.parent.mouseLeaveHandler != nil { + s.parent.mouseLeaveHandler() + } } + //println(w32.WMMessageToString(msg)) + // TODO: Menu processing //case w32.WM_COMMAND: // cmdMsgID := int(wparam & 0xffff) @@ -218,3 +226,7 @@ func (s *windowsSystemTray) setLabel(_ string) { func (s *windowsSystemTray) setTemplateIcon(_ []byte) { // Unsupported - do nothing } + +func (s *windowsSystemTray) setIconPosition(position int) { + // Unsupported - do nothing +} diff --git a/v3/pkg/w32/constants.go b/v3/pkg/w32/constants.go index fb8cfe56..8fbcedf3 100644 --- a/v3/pkg/w32/constants.go +++ b/v3/pkg/w32/constants.go @@ -544,6 +544,7 @@ const ( WM_MBUTTONUP = 520 WM_MBUTTONDBLCLK = 521 WM_MOUSEWHEEL = 522 + WM_MOUSEHWHEEL = 526 WM_MOUSEFIRST = 512 WM_XBUTTONDOWN = 523 WM_XBUTTONUP = 524