Commit Graph

202 Commits

Author SHA1 Message Date
Inkeliz 689b317de9 app/internal/window: add support for system.CommandBack on wasm
To get the `popstate` we need to create a new entry into
the browser history. Then, Gio will handle the "back" and
"forward" of the page.

In some browsers (Chrome 87/Edge 87): The user must
click inside the window/page at least one time. It will not
work if the user leaves the page  (clicking back button)
without interaction with Gio.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2020-11-21 16:52:48 +01:00
Raffaele Sena 8a3ff4abcb app/internal/window: implement key.Press and key.Release on macOS
Update key.State documentation and add State.String while here. Also
update Event.String to include State.

Signed-off-by: Raffaele Sena <raff367@gmail.com>
2020-11-21 09:10:14 +01:00
Inkeliz e195309d55 app/internal/window: mitigate keyboard issue on WASM iOS
That change mitigates the issue gio#150 and gio#166. The
iOS can only `focus()` as a response to touchstart/click
events. We can't `focus()` at random, without user interaction.

The `w.requestFocus` will try to focus on the next `touchstart`,
which may need some "double click" in some cases. That mitigates
the issue, but doesn't fixes completely, but open the keyboard. (:

I didn't notice any side-effect of that change on Android and on
Windows.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2020-11-21 09:09:47 +01:00
Inkeliz fb15547b7a app/internal/window: remove context-menu (right-click) for wasm
The context-menu seems useless. The only action available, on the
context-menu is to "Save image": which gives a black image.

I think it's better to remove it. The right-click still work and still
provide `pointer.Event`.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2020-11-21 09:09:35 +01:00
Inkeliz 7ca00d5d34 app/internal/window: fix enter-key for android
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2020-11-19 20:54:19 +01:00
Elias Naur 01e8308a83 app/internal/window: add missing period after sentence
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-11-16 16:51:12 +01:00
Egon Elbre a55302a498 app/internal/window: use keyed fields
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2020-11-01 17:13:00 +01:00
Josiah Niedrauer 42e568775c io/key: implement key.Release state
Implement key state for the following platforms:
js, wayland, windows, x11.

Unsupported platforms will continue to function as before, sending
key.Press for all key events.

Signed-off-by: Josiah Niedrauer <josiah@niedrauer.com>
2020-11-01 17:13:00 +01:00
Elias Naur 3740f89171 app/internal/window: [Windows] properly handle WM_QUIT
First, don't filter on HWND in GetMessage and PeekMessage, lest
thread-specific messages may get lost. See

https://devblogs.microsoft.com/oldnewthing/20050209-00/?p=36493

Second, replace the dead status with the detection of WM_QUIT; it's
what it's there for.

May update gio#168

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-10-27 17:57:06 +00:00
Elias Naur 679a34b116 app/internal/window: default to X11 on unix systems
Wayland doesn't guarantee the presence of server-side window decorations
(border, close/maximize/minimize buttons), and Gio doesn't have client-side
decorations either (issue #29). The issue is more than a year old, so it's time
to default to X11 to have a good out-of-the-box experience on unix systems.

Updates gio#29

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-09-27 14:29:31 +02:00
Elias Naur 1584f3a64a app/internal/window: [X11] use correct type for setting X properties
32-bit property values are transferred with the C type "long", which
may be 64 bit.

Fixes "invalid atoms" errors from Firefox and Gedit.

While here, add additional clipboard formats to please Gedit.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-08-28 13:34:10 +02:00
Elias Naur 6c30c6386c app,app/internal: [Android] replace Window.Do with ViewEvent
An event reporting the most recent Android View attached to the Window is both
simpler to implement and automatically tracks the Activity lifecycle.

The downside is that buggy programs may hold on to a stale references.
Fortunately, JNI references are handles not pointers so the always-on Android
JNI checks will very likely catch stale references on use.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-08-13 14:41:37 +02:00
Elias Naur 3b95e29183 app/internal/window: [WebAssembly] fix touch event handling
Fixes gio#149

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-26 11:01:30 +02:00
Elias Naur e381ff40d6 app/internal/window: [Android] work around flickering on ChromeOS
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-22 21:14:35 +02:00
Elias Naur 9ac8c80d15 app/internal/window: fix typos
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-22 20:38:14 +02:00
Elias Naur 86c3fb2f0b app/internal/window: [Android] disable platform focus highlight
Gio apps use a single Android View for the entire UI, rendering the platform
focus highlight unsuitable.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-22 20:07:12 +02:00
Elias Naur 39fd161bea app/internal/window: use GetDpiForWindow if available
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-19 10:41:47 +02:00
Elias Naur e48b85f8d9 app/internal/window,app/internal/egl: replace deprecated MESA_EGL_NO_X11_HEADERS
Fixes gio#147

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-15 12:08:50 +02:00
Elias Naur 96da6945a7 app/internal/window: [Wayland] initialize touchFoci map
Fixes gio#145 (I hope)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-08 16:16:44 +02:00
Elias Naur 958b19ae22 app/internal/window: [macOS] ignore result from CVDisplayLinkStart
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>
2020-06-30 11:36:26 +02:00
Elias Naur 2f8833d985 app/internal/window: [X11] avoid -d=checkptr check failures
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>
2020-06-27 15:29:42 +02:00
Sebastien Binet 6a9a870462 app{,/internal/window}: make app.Main blocking on desktop platforms
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.
2020-06-26 16:20:42 +02:00
Elias Naur 31e8339e1b app/internal/window: [Windows] fix min/max size
Fixes gio#141

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-26 16:14:41 +01:00
Elias Naur d97f7f9093 app/internal/window,cmd/gogio: [iOS] export GioViewController
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>
2020-06-26 15:47:00 +02:00
Elias Naur 79014a81d5 app/internal/window: [iOS] move logic out of GioAppDelegate
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>
2020-06-26 15:25:40 +02:00
Elias Naur db03b0898d app/internal/window: run main on main thread on Android and iOS
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>
2020-06-25 16:21:28 +02:00
Sebastien Binet 59f07023d4 app/internal: [X11] implement Window.Close
Signed-off-by: Sebastien Binet <s@sbinet.org>
2020-06-22 17:21:39 +02:00
Jason 9cfbdafe14 app/window,app/internal/window: allow min/max window size
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>
2020-06-22 13:00:27 +02:00
Egon Elbre 0b713032fb app/internal: [Windows] support Window.Close
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2020-06-19 12:37:21 +02:00
Larry Clapp 602d54dc5e app,app/internal/window: [macOS] add app.Window.Close for closing a window
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>
2020-06-18 14:46:58 +02:00
Elias Naur 596e321610 all: make unit.Converter concrete and rename to Metric
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>
2020-06-17 11:47:14 +02:00
Jason a3f7eaae08 app/internal/window: set WM_CLASS to binary name
WM_CLASS is used by Linux desktops to provide hints for window
grouping, icons to show and startup notifications.

https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html

This patch set the WM_CLASS to the binary name.

Signed-off-by: Jason <sourcehut@sweatyballs.es>
2020-06-16 16:15:36 +02:00
Elias Naur 04e605c1b2 app/internal/window: [Android] implement scroll factor fallback for < API 26
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-15 13:40:13 +02:00
Elias Naur feacd1e2df app/internal/window: [Android] implement mouse scrolling
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-13 18:52:29 +02:00
Elias Naur 8688ed95c2 app/internal/window: [Android] replace RegisterFragment with Do
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>
2020-06-13 17:47:58 +02:00
Elias Naur f36674ddb3 app/internal/window: [Android] make runOnThread independent of a valid GioView
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-13 17:47:58 +02:00
Elias Naur 2f521899c9 app/internal/window: [Android] use app context for clipboard access
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>
2020-06-13 16:41:28 +02:00
Elias Naur 65d9a9d1f1 app/internal/window: [Android] skip redraw for destroyed views
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-13 16:41:28 +02:00
Elias Naur 6d5fbcba3f app/internal/window: [Android] unregister focus listener on destroy
Updates github.com/tailscale/tailscale/issues/431

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-11 15:39:33 +02:00
Elias Naur 6380baacb6 all: move Now from system.Config to system.FrameEvent
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>
2020-06-09 23:23:08 +02:00
Elias Naur 6f15275e22 app/internal/window: [macOS] retain NSWindow instance
Updates (maybe fixes) #130

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-08 17:54:44 +02:00
Elias Naur 98a603aed6 app/internal/window: [macOS] don't set callbacks before window is ready
Updates gio#130

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-08 16:34:10 +02:00
Elias Naur 64a516d7c9 app/internal/window: [Windows] avoid race between Main and window closes
While here, replace the window hwnd-to-window map with a sync.Map.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-08 11:39:40 +02:00
Elias Naur d86f96503f app/internal/window: [macOS] fix window sizes for unit.Px values
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-07 17:49:59 +02:00
Elias Naur c2c31a4d00 app/internal/window: [Windows] support multiple windows
Updates gio#19

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-07 16:27:43 +02:00
Elias Naur 65078cdece app/internal/window: [macOS] simplify NewWindow
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-07 14:48:54 +02:00
Elias Naur 483084f4be app/internal/window: [macOS] delay window creation until ready
Fixes #128

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-07 08:42:36 +02:00
Elias Naur 144a5a9cf5 app/internal/window: [macOS] introduce serious cascading
This time without arbitrary offsets and with support for multiple
windows.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-06 19:27:25 +02:00
Elias Naur 4408c2a695 app/internal/window: [macOS] support more than one window
Updates #19

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-06 19:09:02 +02:00
Elias Naur 476bf8d263 app/internal/window: [macOS] only terminate app when last window closes
Updates #19

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-05 12:10:23 +02:00