diff --git a/exp/pkg/application/application.go b/exp/pkg/application/application.go index f3144ea04..d3663a78c 100644 --- a/exp/pkg/application/application.go +++ b/exp/pkg/application/application.go @@ -58,7 +58,8 @@ func (a *App) getSystemTrayID() uint { a.systemTrayID++ return a.systemTrayID } -func (a *App) On(eventID uint, callback func()) { +func (a *App) On(eventType events.ApplicationEventType, callback func()) { + eventID := uint(eventType) a.applicationEventListeners[eventID] = append(a.applicationEventListeners[eventID], callback) } diff --git a/exp/pkg/application/window.go b/exp/pkg/application/window.go index d966a6ae8..944739d33 100644 --- a/exp/pkg/application/window.go +++ b/exp/pkg/application/window.go @@ -4,6 +4,7 @@ import ( "fmt" "sync" + "github.com/wailsapp/wails/exp/pkg/events" "github.com/wailsapp/wails/exp/pkg/options" ) @@ -242,7 +243,8 @@ func (w *Window) Center() { w.impl.center() } -func (w *Window) On(eventID uint, callback func()) { +func (w *Window) On(eventType events.WindowEventType, callback func()) { + eventID := uint(eventType) w.eventListenersLock.Lock() w.eventListeners[eventID] = append(w.eventListeners[eventID], callback) w.eventListenersLock.Unlock() diff --git a/exp/pkg/events/events.go b/exp/pkg/events/events.go index 5ecb93aa1..eaca310f8 100644 --- a/exp/pkg/events/events.go +++ b/exp/pkg/events/events.go @@ -1,101 +1,127 @@ package events +type ApplicationEventType uint +type WindowEventType uint + var Mac = newMacEvents() type macEvents struct { - ApplicationDidBecomeActive uint - ApplicationDidChangeBackingProperties uint - ApplicationDidChangeEffectiveAppearance uint - ApplicationDidChangeIcon uint - ApplicationDidChangeOcclusionState uint - ApplicationDidChangeScreenParameters uint - ApplicationDidChangeStatusBarFrame uint - ApplicationDidChangeStatusBarOrientation uint - ApplicationDidFinishLaunching uint - ApplicationDidHide uint - ApplicationDidResignActive uint - ApplicationDidUnhide uint - ApplicationDidUpdate uint - ApplicationWillBecomeActive uint - ApplicationWillFinishLaunching uint - ApplicationWillHide uint - ApplicationWillResignActive uint - ApplicationWillTerminate uint - ApplicationWillUnhide uint - ApplicationWillUpdate uint - WindowDidBecomeKey uint - WindowDidBecomeMain uint - WindowDidBeginSheet uint - WindowDidChangeAlpha uint - WindowDidChangeBackingLocation uint - WindowDidChangeBackingProperties uint - WindowDidChangeCollectionBehavior uint - WindowDidChangeEffectiveAppearance uint - WindowDidChangeOcclusionState uint - WindowDidChangeOrderingMode uint - WindowDidChangeScreen uint - WindowDidChangeScreenParameters uint - WindowDidChangeScreenProfile uint - WindowDidChangeScreenSpace uint - WindowDidChangeScreenSpaceProperties uint - WindowDidChangeSharingType uint - WindowDidChangeSpace uint - WindowDidChangeSpaceOrderingMode uint - WindowDidChangeTitle uint - WindowDidChangeToolbar uint - WindowDidChangeVisibility uint - WindowDidClose uint - WindowDidDeminiaturize uint - WindowDidEndSheet uint - WindowDidEnterFullScreen uint - WindowDidEnterVersionBrowser uint - WindowDidExitFullScreen uint - WindowDidExitVersionBrowser uint - WindowDidExpose uint - WindowDidFocus uint - WindowDidMiniaturize uint - WindowDidMove uint - WindowDidOrderOffScreen uint - WindowDidOrderOnScreen uint - WindowDidResignKey uint - WindowDidResignMain uint - WindowDidResize uint - WindowDidUnfocus uint - WindowDidUpdate uint - WindowDidUpdateAlpha uint - WindowDidUpdateCollectionBehavior uint - WindowDidUpdateCollectionProperties uint - WindowDidUpdateShadow uint - WindowDidUpdateTitle uint - WindowDidUpdateToolbar uint - WindowDidUpdateVisibility uint - WindowWillBecomeKey uint - WindowWillBecomeMain uint - WindowWillBeginSheet uint - WindowWillChangeOrderingMode uint - WindowWillClose uint - WindowWillDeminiaturize uint - WindowWillEnterFullScreen uint - WindowWillEnterVersionBrowser uint - WindowWillExitFullScreen uint - WindowWillExitVersionBrowser uint - WindowWillFocus uint - WindowWillMiniaturize uint - WindowWillMove uint - WindowWillOrderOffScreen uint - WindowWillOrderOnScreen uint - WindowWillResignMain uint - WindowWillResize uint - WindowWillUnfocus uint - WindowWillUpdate uint - WindowWillUpdateAlpha uint - WindowWillUpdateCollectionBehavior uint - WindowWillUpdateCollectionProperties uint - WindowWillUpdateShadow uint - WindowWillUpdateTitle uint - WindowWillUpdateToolbar uint - WindowWillUpdateVisibility uint - WindowWillUseStandardFrame uint + ApplicationDidBecomeActive ApplicationEventType + ApplicationDidChangeBackingProperties ApplicationEventType + ApplicationDidChangeEffectiveAppearance ApplicationEventType + ApplicationDidChangeIcon ApplicationEventType + ApplicationDidChangeOcclusionState ApplicationEventType + ApplicationDidChangeScreenParameters ApplicationEventType + ApplicationDidChangeStatusBarFrame ApplicationEventType + ApplicationDidChangeStatusBarOrientation ApplicationEventType + ApplicationDidFinishLaunching ApplicationEventType + ApplicationDidHide ApplicationEventType + ApplicationDidResignActive ApplicationEventType + ApplicationDidUnhide ApplicationEventType + ApplicationDidUpdate ApplicationEventType + ApplicationWillBecomeActive ApplicationEventType + ApplicationWillFinishLaunching ApplicationEventType + ApplicationWillHide ApplicationEventType + ApplicationWillResignActive ApplicationEventType + ApplicationWillTerminate ApplicationEventType + ApplicationWillUnhide ApplicationEventType + ApplicationWillUpdate ApplicationEventType + WindowDidBecomeKey WindowEventType + WindowDidBecomeMain WindowEventType + WindowDidBeginSheet WindowEventType + WindowDidChangeAlpha WindowEventType + WindowDidChangeBackingLocation WindowEventType + WindowDidChangeBackingProperties WindowEventType + WindowDidChangeCollectionBehavior WindowEventType + WindowDidChangeEffectiveAppearance WindowEventType + WindowDidChangeOcclusionState WindowEventType + WindowDidChangeOrderingMode WindowEventType + WindowDidChangeScreen WindowEventType + WindowDidChangeScreenParameters WindowEventType + WindowDidChangeScreenProfile WindowEventType + WindowDidChangeScreenSpace WindowEventType + WindowDidChangeScreenSpaceProperties WindowEventType + WindowDidChangeSharingType WindowEventType + WindowDidChangeSpace WindowEventType + WindowDidChangeSpaceOrderingMode WindowEventType + WindowDidChangeTitle WindowEventType + WindowDidChangeToolbar WindowEventType + WindowDidChangeVisibility WindowEventType + WindowDidClose WindowEventType + WindowDidDeminiaturize WindowEventType + WindowDidEndSheet WindowEventType + WindowDidEnterFullScreen WindowEventType + WindowDidEnterVersionBrowser WindowEventType + WindowDidExitFullScreen WindowEventType + WindowDidExitVersionBrowser WindowEventType + WindowDidExpose WindowEventType + WindowDidFocus WindowEventType + WindowDidMiniaturize WindowEventType + WindowDidMove WindowEventType + WindowDidOrderOffScreen WindowEventType + WindowDidOrderOnScreen WindowEventType + WindowDidResignKey WindowEventType + WindowDidResignMain WindowEventType + WindowDidResize WindowEventType + WindowDidUnfocus WindowEventType + WindowDidUpdate WindowEventType + WindowDidUpdateAlpha WindowEventType + WindowDidUpdateCollectionBehavior WindowEventType + WindowDidUpdateCollectionProperties WindowEventType + WindowDidUpdateShadow WindowEventType + WindowDidUpdateTitle WindowEventType + WindowDidUpdateToolbar WindowEventType + WindowDidUpdateVisibility WindowEventType + WindowWillBecomeKey WindowEventType + WindowWillBecomeMain WindowEventType + WindowWillBeginSheet WindowEventType + WindowWillChangeOrderingMode WindowEventType + WindowWillClose WindowEventType + WindowWillDeminiaturize WindowEventType + WindowWillEnterFullScreen WindowEventType + WindowWillEnterVersionBrowser WindowEventType + WindowWillExitFullScreen WindowEventType + WindowWillExitVersionBrowser WindowEventType + WindowWillFocus WindowEventType + WindowWillMiniaturize WindowEventType + WindowWillMove WindowEventType + WindowWillOrderOffScreen WindowEventType + WindowWillOrderOnScreen WindowEventType + WindowWillResignMain WindowEventType + WindowWillResize WindowEventType + WindowWillUnfocus WindowEventType + WindowWillUpdate WindowEventType + WindowWillUpdateAlpha WindowEventType + WindowWillUpdateCollectionBehavior WindowEventType + WindowWillUpdateCollectionProperties WindowEventType + WindowWillUpdateShadow WindowEventType + WindowWillUpdateTitle WindowEventType + WindowWillUpdateToolbar WindowEventType + WindowWillUpdateVisibility WindowEventType + WindowWillUseStandardFrame WindowEventType + MenuWillOpen ApplicationEventType + MenuDidOpen ApplicationEventType + MenuDidClose ApplicationEventType + MenuWillSendAction ApplicationEventType + MenuDidSendAction ApplicationEventType + MenuWillHighlightItem ApplicationEventType + MenuDidHighlightItem ApplicationEventType + MenuWillDisplayItem ApplicationEventType + MenuDidDisplayItem ApplicationEventType + MenuWillAddItem ApplicationEventType + MenuDidAddItem ApplicationEventType + MenuWillRemoveItem ApplicationEventType + MenuDidRemoveItem ApplicationEventType + MenuWillBeginTracking ApplicationEventType + MenuDidBeginTracking ApplicationEventType + MenuWillEndTracking ApplicationEventType + MenuDidEndTracking ApplicationEventType + MenuWillUpdate ApplicationEventType + MenuDidUpdate ApplicationEventType + MenuWillPopUp ApplicationEventType + MenuDidPopUp ApplicationEventType + MenuWillSendActionToItem ApplicationEventType + MenuDidSendActionToItem ApplicationEventType } func newMacEvents() macEvents { @@ -193,5 +219,28 @@ func newMacEvents() macEvents { WindowWillUpdateToolbar: 90, WindowWillUpdateVisibility: 91, WindowWillUseStandardFrame: 92, + MenuWillOpen: 93, + MenuDidOpen: 94, + MenuDidClose: 95, + MenuWillSendAction: 96, + MenuDidSendAction: 97, + MenuWillHighlightItem: 98, + MenuDidHighlightItem: 99, + MenuWillDisplayItem: 100, + MenuDidDisplayItem: 101, + MenuWillAddItem: 102, + MenuDidAddItem: 103, + MenuWillRemoveItem: 104, + MenuDidRemoveItem: 105, + MenuWillBeginTracking: 106, + MenuDidBeginTracking: 107, + MenuWillEndTracking: 108, + MenuDidEndTracking: 109, + MenuWillUpdate: 110, + MenuDidUpdate: 111, + MenuWillPopUp: 112, + MenuDidPopUp: 113, + MenuWillSendActionToItem: 114, + MenuDidSendActionToItem: 115, } } diff --git a/exp/pkg/events/events.h b/exp/pkg/events/events.h index de249b749..85e700a95 100644 --- a/exp/pkg/events/events.h +++ b/exp/pkg/events/events.h @@ -3,8 +3,8 @@ #ifndef _events_h #define _events_h -extern void applicationEventHandler(unsigned int); -extern void windowEventHandler(unsigned int, unsigned int); +extern void processApplicationEvent(unsigned int); +extern void processWindowEvent(unsigned int, unsigned int); #define EventApplicationDidBecomeActive 0 #define EventApplicationDidChangeBackingProperties 1 @@ -99,6 +99,29 @@ extern void windowEventHandler(unsigned int, unsigned int); #define EventWindowWillUpdateToolbar 90 #define EventWindowWillUpdateVisibility 91 #define EventWindowWillUseStandardFrame 92 +#define EventMenuWillOpen 93 +#define EventMenuDidOpen 94 +#define EventMenuDidClose 95 +#define EventMenuWillSendAction 96 +#define EventMenuDidSendAction 97 +#define EventMenuWillHighlightItem 98 +#define EventMenuDidHighlightItem 99 +#define EventMenuWillDisplayItem 100 +#define EventMenuDidDisplayItem 101 +#define EventMenuWillAddItem 102 +#define EventMenuDidAddItem 103 +#define EventMenuWillRemoveItem 104 +#define EventMenuDidRemoveItem 105 +#define EventMenuWillBeginTracking 106 +#define EventMenuDidBeginTracking 107 +#define EventMenuWillEndTracking 108 +#define EventMenuDidEndTracking 109 +#define EventMenuWillUpdate 110 +#define EventMenuDidUpdate 111 +#define EventMenuWillPopUp 112 +#define EventMenuDidPopUp 113 +#define EventMenuWillSendActionToItem 114 +#define EventMenuDidSendActionToItem 115 #endif \ No newline at end of file diff --git a/exp/tasks/events/generate.go b/exp/tasks/events/generate.go index 4b57e8453..6fbd018d0 100644 --- a/exp/tasks/events/generate.go +++ b/exp/tasks/events/generate.go @@ -9,6 +9,9 @@ import ( var eventsGo = `package events +type ApplicationEventType uint +type WindowEventType uint + var Mac = newMacEvents() type macEvents struct { @@ -71,7 +74,11 @@ func main() { // Add to buffer switch platform { case "mac": - macEventsDecl.WriteString("\t" + eventTitle + " uint\n") + eventType := "ApplicationEventType" + if strings.HasPrefix(event, "Window") { + eventType = "WindowEventType" + } + macEventsDecl.WriteString("\t" + eventTitle + " " + eventType + "\n") macEventsValues.WriteString("\t\t" + event + ": " + strconv.Itoa(id) + ",\n") cHeaderEvents.WriteString("#define Event" + eventTitle + " " + strconv.Itoa(id) + "\n") if ignoreEvent {