Commit Graph

70 Commits

Author SHA1 Message Date
inkeliz 7bcb315ee1 app: add custom scheme support
Now, it's possible to launch one Gio app using a custom URI scheme, such as `gio://some/data`.

This feature is supported on Android, iOS, macOS and Windows, issuing a new transfer.URLEvent,
containing the URL launched. If the program is already open, one transfer.URLEvent will be
sent to the current  app.

Limitations:
On Windows, if the program listen to schemes (compiled with `-schemes`), then just a single
instance of the app can be open. In other words, just a single `myprogram.exe` can
be active.

Security:
Deeplinking have the same level of security of clipboard. Any other software can send such
information and read the content, without any restriction. That should not be used to transfer
sensible data, and can't be fully trusted.

Setup/Compiling:
In order to set the custom scheme, you need to use the new `-schemes` flag in `gogio`, using
as `-schemes gio` will listen to `gio://`.

If you are not using gogio you need to defined some values, which varies for each OS:

macOS/iOS - You need to define the following Properly List:
```
<key>CFBundleURLTypes</key>
<array>
  <dict>
        <key>CFBundleURLSchemes</key>
        <array>
          <string>yourCustomScheme</string>
        </array>
  </dict>
</array>
```

Windows - You need to compiling using -X argument:
```
-ldflags="-X "gioui.org/app.schemesURI=yourCustomScheme" -H=windowsgui"
```

Android - You need to add IntentFilter in GioActivity:
```
<intent-filter>
        <action android:name="android.intent.action.VIEW"></action>
        <category android:name="android.intent.category.DEFAULT"></category>
        <category android:name="android.intent.category.BROWSABLE"></category>
        <data android:scheme="yourCustomScheme"></data>
</intent-filter>
```

That assumes that you still using GioActivity and GioAppDelegate, otherwise more
changes are required.

Events are routed to a new app.Events, which are not linked to a specific window.

Signed-off-by: inkeliz <inkeliz@inkeliz.com>
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2025-12-15 22:20:54 +01:00
inkeliz 45963441c1 app: [macOS] run main.main off the main thread when Gio is embedded
When Gio is embedded (such as on Android and iOS), we pretend that the
Go library is the main program by running Go main on the main thread.
To avoid deadlock, `app.Main` returns immediately to relinquish control
of the main thread.

This behaviour is suprising (what if something else runs after `app.Main`?)
and more importantly is not compatible with app global events received
by the main goroutine.

Something had to give, and this change starts a new goroutine for calling
Go's main.

Signed-off-by: inkeliz <inkeliz@inkeliz.com>
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2025-12-15 22:20:24 +01:00
Elias Naur 44ac50506d app: [android] ensure a new frame is always scheduled when visible and animating
Possible fix to #614.

References: https://todo.sr.ht/~eliasnaur/gio/614
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2024-10-25 12:16:54 +02:00
Chris Waldon 4a1b4c2642 app: add cross-platform empty view event detection
Custom rendering applications need to be prepared to handle empty view events,
as an empty view event is sent during window shutdown. However, the current
implementation requires applications to write a platform-specific helper
function for each supported platform in order to check whether a received
view event is empty. This commit provides a safe, convenient, cross-platform
method that applications can use to detect this special view event and respond
to it.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2024-06-28 08:46:36 +02:00
Elias Naur 993ec907be app: introduce Config.Focused that tracks the window focus state
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2024-03-06 20:49:44 +00:00
Elias Naur d58d386b9b app: [API] remove StageEvent and Stage
StageEvent served only redundant purposes:

- To detect whether the window has focus. That is covered by
  key.FocusEvent.
- To detect whether the window is currently visible. That is covered by
  the absence or presence of FrameEvents.
- To detect when the window native handle is valid. That is
  covered by ViewEvent.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2024-02-08 18:52:04 +00:00
Elias Naur f3fc0d62b8 app: [API] make ViewEvent an interface on all platforms
A uniform type allows convenient nil checks and for future window
backends on platforms other than Linux (which already had ViewEvent
as an interface).

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2024-02-08 18:51:38 +00:00
Elias Naur 6879a30582 app: prepare Window for removal of Main and asynchronous FrameEvents
This is mostly a refactor, but there are two user-visible effects:
- Window.NextEvent may be called even after DestroyEvent is returned.
- Window.Invalidate always wakes up a blocking NextEvent, even when a
FrameEvent cannot be generated.

As a nice side-effect, X11, Wayland and Wasm no longer require separate
goroutines for their window loops.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2024-02-08 18:45:15 +00:00
Elias Naur 27ef6dd7a2 io/key: [API] replace key.InputOp with a filter
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2024-02-05 11:09:33 +00:00
Elias Naur d2085ab7c5 io/system,app: [API] move DestroyEvent, StageEvent, Stage to package app
They're only useful at the top-level event loop in combination with an
app.Window.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2024-02-05 10:59:51 +00:00
Elias Naur 676b670119 io/input,io/clipboard: [API] replace ReadOp with command
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2024-02-05 10:59:51 +00:00
Elias Naur d51aea553f io/input,io/clipboard: [API] replace WriteOp with command
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2024-02-05 10:59:51 +00:00
Elias Naur d5a0d2cf60 io/input,io/router: [API] rename package io/router to io/input
The input name better matches its purpose, in particular when we
introduce input.Source.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2024-02-05 10:59:51 +00:00
Elias Naur cb1e605203 app,io/system,layout: [API] move FrameEvent and Insets to package app
In the early days of Gio, FrameEvent was part of package app. It was
moved to package system to enable layout.NewContext be a convenient
short-hand for constructing a layout.

However, it seems the better design to leave FrameEvent (and Insets) in
package app, and move layout.NewContext there as well. More importantly,
the move allows us to replace the event.Queue interface with a concrete
type.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2024-02-05 10:59:51 +00:00
Elias Naur 60bfb9e064 io/router: [API] make SemanticID a uint, not uint64
4 billion semantic IDs should be enough for everyone.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2024-02-05 10:59:51 +00:00
Elias Naur 650ccea28d io/pointer: [API] rename PointerEvent.Type to Kind
Kind is the idiomatic field name for distinguishing a struct without
using separate types.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2023-10-06 19:11:08 -05:00
Chris Waldon 92bc52c25c app: [Android] ensure data dirs are set by window init
This commit alters the android backend to automatically populate some environment
variables as early as possible in application startup. Specifically, this commit
sets the XDG_{CONFIG,CACHE}_HOME environment variables which are necessary for
the text shaper to infer a valid cache file location.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2023-07-19 09:52:09 +02:00
inkeliz 74a87b1092 app/io: [android,js] add password keyboard hint
Fixes: https://todo.sr.ht/~eliasnaur/gio/517

Signed-off-by: inkeliz <inkeliz@inkeliz.com>
2023-07-17 22:49:44 +02:00
Elias Naur ac2c284d16 app: [Android] sanitize IME snippet bounds
Fixes: https://todo.sr.ht/~eliasnaur/gio/473
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2023-01-27 20:36:12 -06:00
Elias Naur b707b199b3 app: make OpenGL default on Android
Like commit dbf6429026, this change
makes the OpenGL backend default for Android.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-10-22 15:10:18 -06:00
Inkeliz 90688fdd17 app,io/system: [API] add StageInactive when window is not in focus
Now, Gio will send one system.StageEvent with system.StageInactive when
the window is not active. It is implemented on macOS and Windows.

This change is not fully backward compatible, if your code compares
the Stage (`stage < system.StageRunning`), you need to consider
the new system.StageInactive.

Signed-off-by: inkeliz <inkeliz@inkeliz.com>
2022-09-19 11:07:41 -06:00
Inkeliz 65a4366e44 app: [android] fix insets
Previously, the Inset could be report wrongly when the bottom inset
is smaller than the top.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2022-08-07 23:26:05 +02:00
Elias Naur 69e4a3cff3 app: guarantee a ConfigEvent for every Window.Configure call
Not only is the client guaranteed a ConfigEvent, but app.Window
can assume that an unsupported decoration change will be corrected
(by a ConfigEvent with Decorated forced to the supported value).

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-06-25 18:41:22 +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 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
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 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 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 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 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 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 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
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 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
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 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 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 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
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
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
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
Jan Kåre Vatne c4f98d3c1e app: [API] add minimized window mode, change methods to options
The window modes are extended, following microsoft conventions.
We have Fullscreen, Overlapping, Maximized and Minimized.
These modes can be set via options when a new window is creates,
or modified later by calling helper functions like w.Maximize() and w.Center()

The window configuration is automatically updated when a user
modifies the window by dragging or clicking the icons on the window's title-bar,
minimizing or maximizing the window.

Any change, either by the user or the application will emit a ConfigChange event.

This is implemented and tested on Windows only.

API change. the app.Window methods Maximize and Center are replaced with similar
options. For example, to maximize a window use

    w.Option(app.Maximized.Option())

Also, Maximize and Center implementations for X11 and macOS are left for a future
change.

Fixes: https://todo.sr.ht/~eliasnaur/gio/315
Signed-off-by: Jan Kåre Vatne <jkvatne@online.no>
2022-01-15 17:30:22 +01:00
Jeff Williams 13183522dd app: send keypress events for modifier keys
This change causes modifier keys (Control, Shift, Alt, Super) to be sent
to the application as key.Event events. These will still continue to be
used as modifiers for other key and pointer events as they are today.

This commit also adds a minor cleanup to use constants for function
keys in the OS-specific keypress handling functions.

Signed-off-by: Jeff Williams <kanobe@gmail.com>
2022-01-15 16:56:47 +01:00
Elias Naur 9209fd9143 app: [Android don't map the empty string to Java null
Map it to the empty string in Java, which is less surprising.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-01-13 19:47:48 +01:00
Elias Naur 4f5baa9a51 app: let drivers control Window directly
Before this change, Window driver callbacks would all go through
channels to be processed by Window.run. However, Window.run may call
into the driver, which again may invoke a Window callback. These
re-entrant calls have been a source of deadlocks and subtle errors,
resulting in increasingly complex channel logic. This change eliminates
the goroutine split between Window and the driver, allowing callbacks
between Window and the driver without restrictions.

The goroutine split between Window and the driver is historical and
was meant to tame the complicated callback logic of drivers into a nice
for-select loop. However, the complexity isn't worth the gain, and there is
no concurrency concerns because there is always a 1:1 correspondance between
a driver goroutine and its Window object.

Fixes: https://todo.sr.ht/~eliasnaur/gio/329
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-01-04 17:01:05 +01:00