Commit Graph

635 Commits

Author SHA1 Message Date
Elias Naur d22ec125ea app: replace Config.center with Perform(ActionCenter)
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-04-24 11:51:20 +02:00
Elias Naur 1a833ab0a4 app: replace driver.Raise with Perform(ActionRaise)
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-04-24 11:36:06 +02:00
Elias Naur 6ede60d84e app: [Android] avoid out-of-bounds access in getCursorCapsMode
Fixes: https://todo.sr.ht/~eliasnaur/gio/404
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-04-24 10:50:48 +02:00
Elias Naur 0273203743 app,io/router: expand IME snippets if a new range overlaps the old
Instead of cmpletely replacing the IME snippet for every update, expand
the old range if there is overlap. This change avoids never-ending
restarts of the IME on Android where snippets are expanded in two
calls, one for expanding before the selection and one for exanding after
the selection.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-04-23 13:20:46 +02:00
Elias Naur f3265e56b9 app: [Android] take snippet offset into account for getCursorCapsMode
References: https://todo.sr.ht/~eliasnaur/gio/404
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-04-23 11:40:43 +02:00
Elias Naur 6c76fa6dec app,io/key,io/system: [API] replace system.CommandEvent with key.Event
It's much simpler to map the Android back button to a key.Event and
let the usual key filtering determine whether to block its default
behaviour.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-04-19 08:47:15 +02:00
Elias Naur ad7c1eb78d app,io/key: introduce keys for directional navigation
This change adds key.NameUp/Down/Left/Right and maps the Android TV
remote directional keys to them. As a side-effect a key.InputOp can
now receive directional keys (and block their focus movement).

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-04-14 19:09:08 +02:00
Elias Naur d37197f45b app: give key handlers a chance to process Tab and Shift-Tab
Before this change, Tab and Shift-Tab would always result in focus
movement. This this change, a key.InputOp with a matching Keys set
will block focus movement and deliver the events to it.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-04-14 19:09:08 +02:00
Elias Naur dc25afda07 app: don't panic when the client doesn't call FrameEvent.Frame
Fixes: https://todo.sr.ht/~eliasnaur/gio/396
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-04-14 09:16:49 +02:00
Elias Naur 43865ddabd app: don't delay FrameEvent.Frame by v-sync latency
We should return as soon as possible from FrameEvent.Frame to allow the main
goroutine to continue processing other tasks.  Whereas GPU.Frame may touch
the frame ops, GPU.Present will not, so this change moves Present to after
returning from FrameEvent.Frame.

This is a variant of 38ff78df5d that
works on OpenGL where context locking is required.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-04-13 16:05:28 +02:00
Elias Naur 405215f862 Revert "app: don't delay FrameEvent.Frame by v-sync latency"
This reverts commit 38ff78df5d, because
it broke OpenGL by moving eglSwapBuffers outside the MakeCurrent
context scope.

Fixes: https://todo.sr.ht/~eliasnaur/gio/393
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-04-13 16:01:25 +02:00
Elias Naur 38ff78df5d app: don't delay FrameEvent.Frame by v-sync latency
We should return as soon as possible from FrameEvent.Frame to
allow the main goroutine to continue processing other tasks.
Whereas GPU.Frame may touch the frame ops, GPU.Present will not,
so this change moves Present to after returning from FrameEvent.Frame.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-04-12 18:21:23 +02:00
Elias Naur 49bd5787e4 app: [macOS] fix caret position calculation after IME text insert
Fixes: https://todo.sr.ht/~eliasnaur/gio/385
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-04-08 13:05:27 +02:00
Jack Mordaunt 4e488f4c70 app: [API] don't relay raw input events from app.Window
Avoid sending raw inputs events over the window channel.

If the caller wants to access events, they should be
using input handlers and querying for events.

This change avoids saturating the channel with less important
messages which can affect frame event latency, especially in
the case of custom rendering.

See also

https://lists.sr.ht/~eliasnaur/gio/%3CCAFcc3FQNTp_UXr7oA97SsVPD7D91jSw30ZtALcT9vmopFDTeZQ%40mail.gmail.com%3E

Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
2022-04-07 13:18:59 +02:00
Elias Naur f07537335a app: clip client area
On Wayland, app.Window provides fallback window decorations but clients
are not prohibited from drawing over the decorations or capturing events.
This change adds a clip operation to ensure no unwanted interaction between
client content and decorations.

Fixes issue described in

https://lists.sr.ht/~eliasnaur/gio/%3C092fa6a19894af3306fab568fb919c965e98c4da.camel%40gmail.com%3E

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-04-04 10:56:01 +02:00
Elias Naur a1b5ff059c io/router,app: scroll a bit when reaching the end in a focus direction
List was recently changed to include an extra child at each end, to
automatically scroll when reaching the end of a focus direction. However,
if List includes unfocusable children that strategy may fail. This change
adds another fallback where app.Window will scroll a constant amount in
the focus direction, to reveal more children.

For https://github.com/tailscale/tailscale/issues/4278.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-31 12:58:29 +02:00
Elias Naur 4326fee704 app,io/router: scroll focused widgets into view
A focused widget may be partially or completely off-screen in which case
the user will have difficulty interacting with it. This change attempts to
scroll the focused widget into view by issuing synthetic scroll events.

For https://github.com/tailscale/tailscale/issues/4278, but doesn't completely
solve it because layout.Lists won't layout focusable widgets outside its visible
bounds. A follow-up change deals with that.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-31 11:52:31 +02:00
Elias Naur e72c46f13c io/router: use integer coordinates for bounds
There is no need for floating point coordinates, except for transforming
bounds and hit testing.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-30 22:20:27 +02:00
Elias Naur 920e6dd004 io/router,app: move Tab-to-focus conversion to app.Window
This is a refactor to make it easier to add higher level logic to
focus moves. A follow-up will add automatic scrolling to bring
focused widgets into view.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-30 22:20:22 +02:00
Elias Naur e8aa881d40 gpu/internal/vulkan: [Vulkan] replace Device/QueueWaitIdle with fences
vkDeviceWaitIdle and vkQueueWaitIdle are expensive; a vkFence is cheaper
and the usual way to ensure a previous frame has completed before starting
another.

References: https://todo.sr.ht/~eliasnaur/gio/375
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-11 20:34:49 +01:00
Elias Naur b48b1270a3 app: [Android] re-introduce Choreographer for frame pacing
According to #375, change b86928ceec
increased frame pacing jitter. This change effectively reverts it
by re-introducing Choreographer for pacing.

References: https://todo.sr.ht/~eliasnaur/gio/375
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-11 20:34:49 +01:00
Elias Naur f19b16fecc gpu,app: don't call time.Now when not profiling
runtime.nanotime1 shows up in profiles on Android, so avoid calling
time.Now when we can.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-11 20:34:49 +01:00
Elias Naur 083d407b47 app: [macOS] ensure only one redraw request is in flight at any time
After 34f10d9cbb, the display link callback
will never block. However, if the main thread is blocked for another reason,
say a bug in the user program, callback requests will pile up as blocked
goroutines.

This change ensures that a redraw request is queued only if no other request
is pending.

References: https://todo.sr.ht/~eliasnaur/gio/370
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-10 10:25:08 +01:00
Inkeliz b82427d412 app: [windows] fix maximized window size
Previously, the window size is equal to the screen size. That doesn't
consider the size of the taskbar, causing the height be bigger than the
real height. Now, the maximized have the same behavior of windowed,
since both of them must include decorations and taskbar.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2022-03-07 11:02:47 +01:00
Elias Naur c0c25b777b app: replace C-to-Go handle maps with cgo.Handle
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-02 18:27:30 +01:00
Elias Naur 95365d5878 app/internal/windows,app: [Windows] generalize windows.GetPointerLong
We're about to use it to store the Go window cgo.Handle.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-02 18:15:38 +01:00
Elias Naur b9e8a177f0 app: [iOS] disable fallback decorations
Before this change, the iOS backend would not report decoration
support at window creation.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-02 17:55:40 +01:00
Elias Naur fea2f888bb all: replace unsafe slice operations with unsafe.Slice
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-02 16:53:02 +01:00
Elias Naur b0838bf697 app: [Android] avoid a null pointer exception at initialization
GioView.onCreateView may call methods on the imm field of GioView.
Make sure it is initialized before use.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-02 16:42:12 +01:00
Elias Naur 1fa9dd0fd0 app: [macOS] redraw when window moves to a different monitor
The monitor may have a different backing store scale, yet the
system doesn't redraw automatically when that happens

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-01 19:50:12 +01:00
Elias Naur 34f10d9cbb Revert "app: [macOS] pace display link"
This reverts commit 11f39582b8 that
introduced pacing of display link callbacks. Blocking the display link
callback introduced deadlocks with code that updates the display link
display.

Not pacing the display link may introduce extra view invalidations,
but invalidates are consolidated by the system and won't result in
extra redraws.

Fixes: https://todo.sr.ht/~eliasnaur/gio/370
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-01 19:33:26 +01:00
Egon Elbre cdb288d1f9 app,io/pointer: [API] remove CursorNameOp and rename CursorName -> Cursor
It's now possible to directly user pointer.Cursor to add to the ops.

   pointer.CursorText.Add(gtx.Ops)

This is an API change. Use pointer.Cursor directly instead of CursorNameOp.

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2022-03-01 14:05:46 +01:00
Egon Elbre 4172566aad io/pointer: [API] make cursor name into a byte
Add most of the common cursors defined by different systems.

Normalize cursor names to match CSS.

This is API change: some cursor names have changed, and the
underlying type is no longer a string.

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2022-03-01 14:04:21 +01:00
Elias Naur f711e7eaa8 app: ensure Window.Invalidate redraws after delivering events
Events such as system.CommandEvent may result in Invalidate being
called. Ensure animation state is properly updated.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-28 17:28:13 +01:00
Elias Naur 21431975de app,io/router: map Androids' DPAD_CENTER to a click
Mapping it to key.NameReturn confuses widgets such as Editor that
treats clicks separate from return key presses.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-28 17:28:13 +01:00
Elias Naur 73eabb352d io/router,app: add support for directional focus moves
Implement support for up/down/right/left directional focus moves
and map Android directional pad keys to focus moves.

Fixes: https://todo.sr.ht/~eliasnaur/gio/195
References: https://github.com/tailscale/tailscale/issues/1611
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-27 19:01:32 +01:00
Elias Naur eb48b45913 app: [Android] map numpad enter to key.NameReturn
Matches the other platforms by distinguishing NameReturn from NameEnter.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-27 15:31:50 +01:00
Elias Naur 7f90f04c07 app: [macOS] pass key events to system before handling them
This change solves an issue where an editor key press such as
backspace would apply before the IME had a chance to process it.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-23 15:36:39 +01:00
Elias Naur 2e91edafbb app: [Wayland] always refresh frame pacing notification
Apparently, a Wayland server such as Sway and River may not issue
a frame pacing callback created before a top level configure event.
This change ensures the frame pacing callback is always refreshed
when animating, regardless of the reason for the frame.

Fixes: https://todo.sr.ht/~eliasnaur/gio/364
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-22 17:21:16 +01:00
Egon Elbre e9e00994cf app: [macos] add missing cursors
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2022-02-22 10:39:17 +01:00
Egon Elbre b7a42da386 app: [windows] add missing cursors
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2022-02-22 10:39:12 +01:00
Pierre Curto 20d4bc21d5 app: remove defer op in window decorate
Fixes: https://todo.sr.ht/~eliasnaur/gio/361
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2022-02-19 12:04:29 +01:00
Aman Karmani 27762fdd46 app: [Android] handle DPAD_CENTER keycode
see https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_DPAD_CENTER

cc https://github.com/tailscale/tailscale/issues/1611#issuecomment-997622044

Signed-off-by: Aman Karmani <aman@tmm1.net>
2022-02-17 19:48:13 +01:00
Elias Naur 0d32ab3f62 app: [Wayland] process key repeat events properly
The recent IME changes broke Wayland key repeating. This change
fixes it.

Fixes: https://todo.sr.ht/~eliasnaur/gio/359
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-13 20:18:12 +01:00
Elias Naur 31f55232bf app,widget,io: implement IME positioning
This change implements reporting of the caret position from Editor, as well
as Windows, macOS, Android support. As a result, the IME composition window
on Windows and macOS is now positioned correctly.

References: https://todo.sr.ht/~eliasnaur/gio/246
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-13 20:09:06 +01:00
Elias Naur cffa748c6a app: [Windows] simplify GetWindowRect, delete old workaround
Go issue #34474 was fixed in 1.14 and backported to 1.13.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-13 18:52:08 +01:00
Elias Naur 3eeb08b4a1 app: [macOS] don't reset IME snippet when not needed
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-13 18:52:08 +01:00
Elias Naur 27e0b9cc7d app,app/internal/windows: [Windows] implement IME support
References: https://todo.sr.ht/~eliasnaur/gio/246
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-13 18:52:08 +01:00
Elias Naur bace706240 app: remove redundant if check
EditorStateChanged is only called when the old and new states
differ.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-13 18:52:05 +01:00
Elias Naur 216f2c3295 app: always preserve IME snippet replacement text
When a text range in the IME snippet is replaced, the replacement
is discarded if the range don't overlap with the snippet range. However,
the replacement is more relevant than whatever snippet is current.
This change discards the snippet in case of no overlap.

As a bonus, IMEs that leaves the snippet range at [0:0] will have the
snippet track the composing region now.

The FuzzIME test is adjusted to always generate replacements that overlap
Editor content; otherwise the IME snippet and editor state can't be expected
to match.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-12 12:01:10 +01:00