app: replace Window.Config with ConfigEvent

Unlike Raise, Close and other fire-and-forget methods on Window,
Config calls driverRun because it needs to wait for the result.
However, driverRun isn't guaranteed to block in all contexts.

This change avoids the synchronization dance altogether by removing the
Config method and introducing a ConfigEvent event. The event also makes
it clear when the configuration changes.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-09-19 09:57:41 +02:00
parent 64bcb1ccd5
commit 18c2ba8e20
9 changed files with 102 additions and 108 deletions
+11 -11
View File
@@ -507,19 +507,20 @@ func (w *window) SetAnimating(anim bool) {
}
func (w *window) draw(sync bool) {
width, height := C.ANativeWindow_getWidth(w.win), C.ANativeWindow_getHeight(w.win)
if width == 0 || height == 0 {
size := image.Pt(int(C.ANativeWindow_getWidth(w.win)), int(C.ANativeWindow_getHeight(w.win)))
if size != w.config.Size {
w.config.Size = size
w.callbacks.Event(ConfigEvent{Config: w.config})
}
if size.X == 0 || size.Y == 0 {
return
}
const inchPrDp = 1.0 / 160
ppdp := float32(w.dpi) * inchPrDp
w.callbacks.Event(frameEvent{
FrameEvent: system.FrameEvent{
Now: time.Now(),
Size: image.Point{
X: int(width),
Y: int(height),
},
Now: time.Now(),
Size: w.config.Size,
Insets: w.insets,
Metric: unit.Metric{
PxPerDp: ppdp,
@@ -815,13 +816,12 @@ func (w *window) Configure(options []Option) {
w.config.Mode = Windowed
}
}
if w.config != prev {
w.callbacks.Event(ConfigEvent{Config: w.config})
}
})
}
func (w *window) Config() Config {
return w.config
}
func (w *window) Raise() {}
func (w *window) SetCursor(name pointer.CursorName) {