From 5542aac772a56a03e862b307f7a0390a6bcf9bc3 Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Tue, 18 Jun 2024 16:30:44 -0400 Subject: [PATCH] app: queue system actions before first call to Event() This commit ensures that attempting to perform a system window action prior to the first call to Event() does not panic. It adopts a similar strategy to handling Option() prior to the first call to Event(): make a slice of the arguments and apply them during window initialization. Fixes: https://todo.sr.ht/~eliasnaur/gio/593 Signed-off-by: Chris Waldon --- app/window.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/window.go b/app/window.go index 70f6a359..09fc8dae 100644 --- a/app/window.go +++ b/app/window.go @@ -41,7 +41,8 @@ type Option func(unit.Metric, *Config) // // More than one Window is not supported on iOS, Android, WebAssembly. type Window struct { - initialOpts []Option + initialOpts []Option + initialActions []system.Action ctx context gpu gpu.GPU @@ -727,6 +728,10 @@ func (w *Window) init() { w.imeState.compose = key.Range{Start: -1, End: -1} w.semantic.ids = make(map[input.SemanticID]input.SemanticNode) newWindow(&callbacks{w}, options) + for _, acts := range w.initialActions { + w.Perform(acts) + } + w.initialActions = nil } func (w *Window) updateCursor() { @@ -826,6 +831,10 @@ func (w *Window) Perform(actions system.Action) { if acts == 0 { return } + if w.basic == nil { + w.initialActions = append(w.initialActions, acts) + return + } w.Run(func() { w.driver.Perform(actions) })