Commit Graph

653 Commits

Author SHA1 Message Date
Elias Naur 9f91fecdb3 app: [Wayland] don't allow changes to decoration mode
We're about to enable platform support for switching native
window decorations on and off. However, the Wayland platform
only supports server-side switching of decoration mode, not
(yet) client-side. Thus, don't switch mode even when asked to.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-06-23 20:33:20 +02:00
Elias Naur 371de3462b app: replace driver.Close with Perform(ActionClose)
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-06-23 19:04:30 +02:00
Elias Naur 43116400d0 app: fix racing app.Window.Perform and app.Window.Option
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-06-23 17:58:45 +02:00
Elias Naur e31aa35622 app: draw fallback decorations on top
Before this change, client-side decorations for Wayland were drawn
before client content, which was prevented from drawing over
decorations with a clip. While visually correct, resize handles would't
work as long as client listeners are near the window edges to swallow
pointer input.

This change makes app.Window draw decorations last, fixing resizing
and saves a clipping operation. This is an alternative to the original
fix for #361, commit 20d4bc2.

References: https://todo.sr.ht/~eliasnaur/gio/361
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-06-23 13:41:34 +02:00
Chris Waldon 6a6ddc3f19 app: [Wayland] scale min/max window size correctly
The xdg_toplevel expects the min/max window size in DP rather
than pixels. The scaling factor would be applied twice because
we supplied pixels that we scaled ourselves, resulting in windows
twice the expected size on HiDPI screens. This bug probably went
for so long without being detected because it only manifests if
you actually set a minimum or maximum size.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-06-23 10:10:22 +02:00
Chris Waldon 55c96adb91 app: [Wayland] handle multiple global registry event orders
Not all wayland compositors advertise the global registry events
in the same order. In particular, river and sway differ in that
sway advertises the data_device_manager before the seat, and river
does it after. This commit updates our code to correctly bind
the data_device so that we can work with the clipboard regardless
of the registry event order.

Special thanks to Isaac Freund (river maintainer) for helping me
find the root of this problem. You can see Isaac's extremely helpful
and detailed analysis here:

https://github.com/riverwm/river/issues/554#issuecomment-1059750874

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-06-23 10:10:11 +02:00
Elias Naur bf6371c8e9 app: restore IME snippet after an EditorReplace
Commit 0273203743 removed the snippet
restore event, which broke IME on macOS and Windows.

Fixes: https://todo.sr.ht/~eliasnaur/gio/424
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-06-15 11:30:12 +02:00
Elias Naur 916efb4612 all: apply suggestions from staticcheck.io
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-06-07 12:28:28 +02:00
Elias Naur b5f12c5f26 f32: [API] unexport Rectangle
There are no public API that uses f32.Rectangle anymore. Move Rectangle
to an internal package for internal use.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-05-31 10:24:09 +02:00
Elias Naur 3d37491342 all: [API] replace unit.Value with separate unit.Dp, unit.Sp types
The unit.Value is a struct and thus more inconvenient to use than its
underlying float32 type. In addition, most uses don't need a general
value, but rather a specific unit given by the context. This change
replaces unit.Value with two float32 units, Dp and Sp. It also changes
variables and parameters of unit.Value to a specific unit type matching
the context. That is, unit.Dp everywhere except for text sizes which are
in Sp.

Switching to typed float32s has multiple advantages

- They can be constants:

const touchSlop = unit.Dp(16)

- Casting untyped constants is no longer necessary:

insets := layout.UniformInset(16)

- Calculation with values is natural:

func (s ScrollbarStyle) Width() unit.Dp {
	return s.Indicator.MinorWidth + s.Track.MinorPadding + s.Track.MinorPadding
}

The main API change is that calls to gtx.Px must be replaced with either
gtx.Dp or gtx.Sp depending on the unit.

Idea by Christophe Meessen.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-05-31 10:24:09 +02:00
Elias Naur a63e0cb44a all: [API] change op.Offset to take integer coordinates
op.Offset is a convenience function most often used by layouts. Layouts
usually operate in integer coordinates, and the float32 version of op.Offset
needlessly force conversions from int to float32. This change makes op.Offset
take integer coordinates, to better match its intended use.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-05-31 10:24:09 +02:00
Egon Elbre cbbb5865e5 app/internal/windows: fix WS_CLIPCHILDREN value
Fixes: https://todo.sr.ht/~eliasnaur/gio/419
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2022-05-31 09:25:12 +02:00
Elias Naur 2a0a196d1a app: don't deadlock if Window.validateAndProcess fails
Fixes: https://todo.sr.ht/~eliasnaur/gio/417
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-05-27 11:31:13 +02:00
Elias Naur 79f037f983 app: lock GPU context during present
The OpenGL backend needs it, but I keep forgetting to test it when
rearranging the window rendering code. The gogio X11 end-to-end test
tests this issue, but unfortunately it is disabled because of flakiness.

Fixes: https://todo.sr.ht/~eliasnaur/gio/412
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-05-17 09:30:35 +02:00
Elias Naur 0e2e02a662 app: don't lock up when using custom renderers
A recent change broke custom rendering by not allowing the client
to continue after calling FrameEvent.Frame. This change makes sure
the client is allowed to continue regardless of rendering mode.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-05-10 21:41:37 +02:00
Mearaj 7ced0d29ab app,widget: use arrow keys for Android navigation
Android doesn't distinguish between the arrow keys on a keyboard and the
directional keys on a remote control, so there's no way to move the caret
in an Editor with arrow keys. This change updates the Android port to map
Android's DPAD_* key codes to the arrow key names, fixing caret movement.
The change also updates Editor to only request arrow keys that actually move
the caret, to keep directional focus movement working.

Fixes: https://todo.sr.ht/~eliasnaur/gio/410
Signed-off-by: Mearaj <mearajbhagad@gmail.com>
2022-05-10 16:41:32 +02:00
Inkeliz c97f976e7d app: [Android] improve keyboard hints
This patch adds support for the following KeyboardHint: Text, Email,
Telephone and URL.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2022-05-06 09:18:06 +02:00
Elias Naur 1071f56119 app: only perform actions and apply options on wakeups
In particular, avoid a race between the setup of the platform window
returned by NewWindow and Window.Perform.

Fixes: https://todo.sr.ht/~eliasnaur/gio/405
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-04-24 12:51:53 +02:00
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