Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ func (a *Application) Run() error {
os.Exit(1)
}

// Register window focus callback
if a.config.windowFocusCallback != nil {
a.window.SetFocusCallback(func(_ *glfw.Window, focused bool) {
a.config.windowFocusCallback(focused)
})
}

// Register plugins
for _, p := range a.config.plugins {
err = p.InitPlugin(messenger)
Expand Down
9 changes: 9 additions & 0 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type config struct {
windowDimensionLimits windowDimensionLimits
windowMode windowMode
windowAlwaysOnTop bool
windowFocusCallback func(focused bool)

forcePixelRatio float64
keyboardLayout KeyboardShortcuts
Expand Down Expand Up @@ -179,6 +180,14 @@ func WindowAlwaysOnTop(enabled bool) Option {
}
}

// WindowFocusCallback sets the focus callback of the window, which is called
// when the window gains or loses focus.
func WindowFocusCallback(h func(bool)) Option {
return func(c *config) {
c.windowFocusCallback = h
}
}

// AddPlugin adds a plugin to the flutter application.
func AddPlugin(p Plugin) Option {
return func(c *config) {
Expand Down