Commit Graph

607 Commits

Author SHA1 Message Date
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
Elias Naur 887ba1b6e9 app: [Android] remove dead code
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-10 11:14:25 +01:00
Elias Naur b162ed56d7 app: [macOS] implement IME support
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-09 21:00:46 +01:00
Elias Naur 98b02176db app: [Android] move UTF-16 to UTF-32 conversion routines to Go
They're easier to test and can be re-used for macOS/Windows.

While here, add a Go 1.18 build tag to app/ime_test.go; it relies
on Go 1.18 fuzzing.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-09 20:45:12 +01:00
Elias Naur ef9e4071e7 app: [macOS,iOS] don't use [NSString UTF8String]
UTF8String is lossy in the presence of nul (\x00) runes.

While here, don't CFRelease the input to nsstringToString; leave it
up to the caller.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-09 17:43:25 +01:00
Elias Naur 9d778d7bde app: ensure derived events are processed
A range loop may not see all items in a slice that is appended to during
iteration. Convert range loop to popping each event off the queue until
it is empty.

Fixes: https://todo.sr.ht/~eliasnaur/gio/356
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-06 11:21:00 +01:00
Elias Naur 58cdb3e1da app,widget: implement Editor IME support, add Android implementation
Fixes: https://todo.sr.ht/~eliasnaur/gio/116
References: https://todo.sr.ht/~eliasnaur/gio/246
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-06 10:31:53 +01:00
Elias Naur 77557edd33 app: [Wayland] make clipboard reads synchronous
app.Window.Event is no longer safe to call for goroutines outside the event
loop. This change ensures that clipboard reads happen on the even loop.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-04 15:40:06 +01:00
Elias Naur 1c2e96bcc7 app: [Wayland] send WaylandViewEvent before DestroyEvent
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-04 14:20:23 +01:00
Elias Naur 12deba2195 app: don't apply fallback decorations when CustomRenderer is set
Fixes the opengl example on client-side decorated Wayland servers.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-01 10:59:58 +01:00
Chris Waldon 7204632c39 app: [API] refactor app.ViewEvent to support wayland
This commit changes the definition of app.ViewEvent on Unix systems
to be an interface implemented by two different concrete types:
X11ViewEvent and WaylandViewEvent. Each provides the necessary fields
for custom rendering on its display protocol.

This is a breaking change for all users of app.ViewEvent on
Linux/BSD, as it now is an interface instead of a concrete type.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-01-31 19:00:29 +01:00
Pierre Curto 74acc90789 app: [API] add Window.Perform, replacing Close, Raise, Centered
This new method performs user related actions on the Window, supporting custom window decorations.
It supersedes the Close and Raise methods as well as the Centered window option.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2022-01-31 18:56:29 +01:00
Elias Naur 6fba94e573 app: [Wayland] update buffer scale immediately
Simpler, and makes sure buffer scaling is set correctly regardless of
the CustomRenderer setting.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-01-31 16:56:52 +01:00
Pierre Curto dcfe36c367 widget/material: split Decorations state and style
Move Decorations to the widget package and
rename material.Decorate to material.Decorations.
This makes decorations in line with how the
other widgets are used.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2022-01-31 14:21:19 +01:00
Jack Mordaunt 4f9d063e13 app: note the implications of custom rendering
Small note to make clear how the window behaviour
changes when you call for custom rendering.

Fixes: https://todo.sr.ht/~eliasnaur/gio/346
Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
2022-01-31 14:16:10 +01:00
Elias Naur 9f1d6f5ebf app: [Wayland] minimize redraws, ack configure events immediately
There's no reason xdg_surface_ack_configure can't be called immediate,
do that. Then, replace calls to window wlWindow.draw with a redraw
field, to ensure only one redraw per event loop iteration.

References: https://todo.sr.ht/~eliasnaur/gio/351
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-01-31 14:08:28 +01:00
Elias Naur ba73227469 app: revert wrong fix for #340
This is effectively a revert of b2a99fddca,
which broke Window.Run.

Fixes: https://todo.sr.ht/~eliasnaur/gio/350
References: https://todo.sr.ht/~eliasnaur/gio/340
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-01-29 13:38:16 +01:00
Elias Naur f23a4f8452 app: delay Window.Close until after event processing
The fix for #340, b2a99fddca, deferred
all driver functions until after event processing. Deferring functions
breaks Window.Run which expects to complete during event processing.
This change is an alternative, more targeted fix, namely deferring just
Window.Close until after event processing.

A follow-up will revert the previous fix.

References: https://todo.sr.ht/~eliasnaur/gio/340
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-01-29 13:30:23 +01:00
Pierre Curto 7648a5e381 app: [macOS] fix initial ConfigEvent.Size
Upon initialization, the reported window size
was incorrect.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2022-01-29 12:41:32 +01:00
Pierre Curto 030fd8a171 widget/material: update Decorations
Fix actions not processed and move the Layout method from
Decorations to DecorationsStyle.

Also clarify the comment for the app.Window.Decorated option.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2022-01-29 12:21:08 +01:00
Pierre Curto 5ce1e98282 app: use material.Decorations on undecorated platforms
This patch implements a mechanism for customizing window
decorations.
If a window is configured with app.Decorated(true), then
the widget/material.Decorations are applied. On Wayland,
the option is automatically set when the server does not
provide window decorations.

Server side decorations are no longer requested.
The Decorated flag is set according to the
server's requests.

Wayland is now the default driver for UNIX platforms.

References: https://todo.sr.ht/~eliasnaur/gio/318
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2022-01-27 15:32:42 +01:00
Elias Naur 90ad0010ec app: disable Vulkan on X11
According to

https://gioui.org/issue/347 and
https://github.com/godotengine/godot/issues/43714

choosing the integrated Intel GPU on a multi-GPU system with NVIDIA
doesn't work well in X11. According to Godot, forcing the use of the
discrete (NVIDIA) GPU works around the problem. This change disables
Vulkan on X11 instead, which is a more conservative and targeted fix.

Disabling Vulkan on X11 will reduce testing of Vulkan, but

- Pierre is making Wayland the default driver on Linux, where Vulkan
is enabled.
- The OpenGL driver will be exercized more.

Fixes: https://todo.sr.ht/~eliasnaur/gio/347
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-01-27 12:32:13 +01:00
Elias Naur 1bad440ef6 app: ensure deferred functions are run outside of FrameEvents
Simplify callbacks.Event a bit while here.

Fixes: https://todo.sr.ht/~eliasnaur/gio/348
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-01-27 12:13:20 +01:00
Pierre Curto 3bb0171e7a layout: reorder fields in Inset to match system.Insets
This makes it simple to convert from one into the other.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2022-01-25 09:54:05 +01:00
Pierre Curto 0010ec1389 app: [Wayland] update the window mode when un-minimized
When a window goes from the Minimized state to Windowed
as the user brings it back up, the internal state needs
to reflect that change and generate the corresponding
Config event.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2022-01-22 08:10:02 +01:00
Jan Kåre Vatne 862fa832c9 app: [Windows] don't include decorations in window sizes
Fixes: https://todo.sr.ht/~eliasnaur/gio/345
Signed-off-by: Jan Kåre Vatne <jkvatne@online.no>
2022-01-21 14:58:44 +01:00
Elias Naur 30daaef4ab app: [Android] implement key release events
Not terribly useful on Android, but easy to do.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-01-20 14:21:44 +01:00
Pierre Curto 8c2d9a9a57 app: apply WindowModes at startup
As reported on slack by Rajiv Kanchan, when a WindowMode
is used with app.NewWindow, it does not get applied.

Delay the Configure method to make sure it is.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2022-01-20 11:05:09 +01:00
Pierre Curto c0f3ec88e9 io/pointer: add new pointers
Add resize pointer cursor names for resize operations
in preparation for the window decorations patch.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2022-01-19 10:39:32 +01:00