Larry Clapp reported a panic from failing to start the display link.
Ignore the error and hope the error is transient.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Casting a *XClientMessageEvent or *XSelectionEvent to *XEvent is
technically incorrect because the union XEvent is the larger structure.
Use an XEvent variable as the backing storage for the specialized
event types instead.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This CL implements the app.Main function as a blocking-forever function
for JS, Wayland, Windows and X11.
This works better for applications that can now programmatically close
windows.
The Gio GioAppDelegate created the GioViewController programmatically.
When using gogio's -buildmode=archive users may want to use a different
method (for example storyboards) but there can only be one app delegate.
Move the GioAppDelegate to gogio's exe buildmode, and export the
GioViewController for embedding use.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
We'd like to remove GioAppDelegate when Gio is embedded with
gogio's -buildmode=archive. Minimize the code in GioAppDelegate.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Before this change, Android and iOS were special for two reasons:
app.Main would return immediately, and the program main was invoked from
a goroutine. We can reduce that to one special case by either
- run the program main from the main thread,
- or make app.Main block.
Choose to run main on the main thread.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
The app.MinSize and app.MaxSize options restricts the window size:
w := app.NewWindow(
app.Size(unit.Dp(600), unit.Dp(596)),
app.MinSize(unit.Dp(600), unit.Dp(596)),
app.MaxSize(unit.Dp(600), unit.Dp(596)),
app.Title(APPNAME),
)
Signed-off-by: Jason <sourcehut@sweatyballs.es>
Recently support was added for multiple top-level windows. Add support
for closing those windows.
macOS only; all others stubbed out.
Signed-off-by: Larry Clapp <larry@theclapp.org>
An interface for scaling dp and sp is overkill, at least for all
current uses. Make it a concrete struct type, and rename it to the
shorter and more precise Metric.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Do is a function for accessing the underlying Android View in a safe
context, the main thread. Do is
- more general than RegisterFragment and may be expanded to other platforms
- simpler to implement (from the Gio side)
and as a bonus, the Do implementation avoids a race condition where
a call to RegisterFragment during an Activity re-create would be ignored.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
The Activity context may not be available, so it's safer and simpler
to use the always available app context.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Then, make layout.Context.Now a field, copied from FrameEvent.Now.
API change:
gofmt -r 'gtx.Now() -> gtx.Now'
Signed-off-by: Elias Naur <mail@eliasnaur.com>
All accesses to the view map now happens on the main thread, so
there is no need for a sync.Map anymore.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Recent changes to the macOS threading exposed a problem where a
window's display link may fail to start after being started and stopped
in rapid succession.
Introduce a displayLink type that waits a while after the last stop
request before stopping its display link. That seems to be the way
other projects are using display links.
As a bonus, the new implementation avoids the potentially expensive
overhead of frequent starting and stopping the underlying OS thread.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
We're about to move the display link to common Go code. To do that,
we need the redraw logic in Go as well.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
The macOS redraw callback is not invoked on the main thread, so its
access to window fields must be synchronized.
An alternative would be to schedule the asynchronous redraws on the main
thread, but I believe frame callbacks are performance-sensitive enough
to warrant the extra locking complexity.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Only the synchronous draws from the main thread may involve changing
width, height and scale. Introduce cached window.width and window.height
fields and limits updates to main-thread draws.
Signed-off-by: Elias Naur <mail@eliasnaur.com>