[v3 windows] Systray callback handlers

This commit is contained in:
Lea Anthony
2023-05-30 16:31:56 +08:00
committed by Misite Bao
parent d8f58ab20f
commit e3b164ae93
3 changed files with 53 additions and 8 deletions
+32
View File
@@ -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
}
+20 -8
View File
@@ -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
}
+1
View File
@@ -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