Newsletter, April 2024
Window API Simplification

Since the last newsletter, Gio’s window implementation internals and API have been greatly simplified, leading to cleaner code and more predictable interactions.

Sponsorship

These past few months, Gio thanks the following organizations and community members for their ongoing support!

Supporting the whole team:

Supporting a maintainer:

Sponsorship money given to Gio enables Elias and I to cover the costs of running Gio’s infrastructure, to pay for some of our time spent maintaining and improving Gio, and to plan for funding significant feature work. You can support Gio by contributing on OpenCollective or GitHub Sponsors.

gioui.org@v0.6.0

Since v0.5.0, Aman Karmani fixed tvOS builds, Benoit Kugler bumped our go-text/typesetting dependency to a tagged version, and Elias greatly simplified the window API and implementation across all platforms. Elias also improved a lot of macOS-specific window internals.

API Change: Window Initialization

app.Window no longer has a constructor. The zero value is safe to use, and it can also be allocated with the builtin new(app.Window).

Code that previously did:

w := app.NewWindow(app.Title("My App"))

Should instead read:

var w app.Window
w.Option(app.Title("My App"))

API Change: Window Event Method Renamed

app.(*Window).NextEvent is now called app.(*Window).Event. This makes the API more uniform with other Gio event-fetching APIs.

API Change: app.ViewEvent

Applications performing custom rendering use app.ViewEvent to acquire the platform handles necessary to construct their own graphics contexts. Previously the concrete type of app.ViewEvent varied by platform, which made it tricky to write code referring to it. It is now an interface on all platforms (it previously was an interface on Linux). Users can type-assert it to platform-specific concrete types.

API Change: app.StageEvent Removed

StageEvent served only redundant purposes:

  • To detect whether the window has focus. This is tracked by app.ConfigEvent.Focused now.
  • To detect whether the window is currently visible. That is covered by the absence or presence of app.FrameEvents.
  • To detect when the window native handle is valid. That is covered by app.ViewEvent.

It has been removed from the API entirely.

Breaking Changes by Author

Elias Naur:

  • app: [API] make the zero-value Window useful and delete NewWindow. a880d640
  • app: [API] make ViewEvent an interface on all platforms. A uniform type allows convenient nil checks and for future window backends on platforms other than Linux (which already had ViewEvent as an interface). f3fc0d62
  • app: [API] remove StageEvent and Stage. StageEvent served only redundant purposes: d58d386b
  • app: [API] rename Window.NextEvent to Event to match Source.Event. 93ac0b03

Changes by Author

Elias Naur:

  • app: [Wayland] fix reference to most recent metric. 8cb06ffa
  • app: slim down window.go by moving editorState to separate file. 5cda660e
  • app: prepare Window for removal of Main and asynchronous FrameEvents. This is mostly a refactor, but there are two user-visible effects: - Window.NextEvent may be called even after DestroyEvent is returned. - **Window.Invalidate always wakes up a blocking NextEvent, even when a FrameEvent cannot be generated. [6879a305](https`://git.sr.ht/~eliasnaur/gio/commit/6879a305)
  • app: [API] make the zero-value Window useful and delete NewWindow. a880d640
  • app: [iOS] use cgo.Handle for referring to Go windows from native code. 9bca5bfd
  • app: [macOS] use NSNotificationCenter to receive app events. d7528a83
  • app: [macOS] use cgo.Handle for referring to Go windows from native code. 0d7f00c6
  • app: merge with internal log package to remove the separate log.appID. fe1df00d
  • app: [macOS] add missing autoreleasepools. Their absense didn’t make a practical difference so far, but we’re about to refactor the macOS event processing loop where the pools do matter. 390242f2
  • app: [macOS] make gio_trySetPrivateCursor static, remove its prefix. While here, don’t use trySetPrivateCursor for the public openHandCursor and closedHandCursor. caba422d
  • app: [macOS] send ViewEvents when the NSView is attached to a NSWindow. Instead of sending ViewEvents once at construction and once at destruction, it’s better to send them when the underlying NSView changes attachment. 1527e91a
  • app: [macOS] move destruction to NSView.dealloc. The dealloc method is where we’re guaranteed the NSView is no longer used anywhere. 5e5d1649
  • app: [API] make ViewEvent an interface on all platforms. A uniform type allows convenient nil checks and for future window backends on platforms other than Linux (which already had ViewEvent as an interface). f3fc0d62
  • app: [API] remove StageEvent and Stage. StageEvent served only redundant purposes: d58d386b
  • app: [API] rename Window.NextEvent to Event to match Source.Event. 93ac0b03
  • app: [macOS] synchronize rendering with Core Animation for smooth resizes. 35785e9c
  • app: introduce Config.Focused that tracks the window focus state. 993ec907
  • app: update documentation for Window.Run. Window events are no longer asynchronous, so deadlocks are no longer possible when calling Run. 44ede4ec

Chris Waldon:

  • widget: update test expectations. This commit fixes our tests to expect some whitespace-handling changes in upstream go-text. 0558bb3f
  • go.*: update go-text. This picks up some improvements to face splitting and line wrapping within the text stack. 1802761c

Benoit KUGLER:

  • deps: bump go-text/typesetting version to v0.1.0. 78ce5e3a

Aman Karmani:

  • app: [tvOS] fix build failures. Fixes: #567 1be34eec

gioui.org/x@v0.6.0

Siva fixed WASM support for saving files via explorer. Thanks Siva!

Changes by Author

Siva:

  • explorer: make CreateFile API work for WASM. 75d15af
  • explorer: Ensure the ChooseFile API returns in WASM when no file is selected. bd51268

Chris Waldon:

  • go.*,richtext: update to gio v0.6.0. 78bc128

gioui.org/example@v0.6.0

Example was updated to compatibility with core and x v0.6.0.

Changes by Author

Chris Waldon:

  • hello: restore to hello world example. 223d7dc
  • opengl: update button state before layout. This ensures screenshot is actually invoked. Thanks to Aurélien Rainone for the bug report! 2939df5
  • go.*: update to gio and gio-x v0.6.0. d7ff2c1

Elias Naur:

  • all: update to latest Gio API. 6c702d9

giouiorg

Egon updated the website for to account for changes in v0.5.0 and to recommend against using go get -u (which frequently breaks Gio applications when dependencies with unstable APIs change their API).

Changes by Author

Egon Elbre:

  • include/files: update to Gio v0.5.0. eeedd29
  • content/doc: update to Gio v0.5.0. 332390f
  • content/doc/learn: add note about go get. People often end up unknowingly using go get -u for updating modules, however that’s not safe to do. 5a8f55b

Chris Waldon:

  • content/news: fix missing change author name. 78d404a

End

Thanks for reading!

Chris Waldon