Commit Graph

542 Commits

Author SHA1 Message Date
Elias Naur 7751d73740 app: [Wayland] don't change cursor when there is no pointer
Fixes: https://todo.sr.ht/~eliasnaur/gio/333
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-01-04 18:24:05 +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
Elias Naur 72b2f2c1bf app: ensure SetDriver is called before sending events
This used to not matter, but a follow-up change will require a valid
driver to process events.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-01-04 15:48:01 +01:00
Elias Naur 787295a6e8 app: fix typo
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-01-03 16:23:37 +01:00
Inkeliz 6913c856a2 app: [android] fix vulkan crash when activity/surface is recreated
On Android it's possible that the Activity/View must be restore. But,
before that patch, an new VkSurfaceKHR is created but never used and
that may lead to crash, in an attempt to destroy/use one invalid
surface.

Fixes: https://todo.sr.ht/~eliasnaur/gio/327
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-12-30 09:50:11 +01:00
Pierre Curto 3a20330d82 app: detect fullscreen mode for macOS and Windows
When an application goes into or out of fullscreen mode,
Gio now emits a ConfigEvent with the current window mode.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-12-26 10:20:54 +01:00
Pierre Curto 0117de71d3 app: add String method to WindowMode and Orientation
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-12-21 10:09:45 +01:00
Jeff Williams f5c9d2725c app: X11 clipboard: write to primary selection
This change is to augment the X11 clipboard write behaviour.
When writing to the clipboard both the primary and clipboard
selections are published so that non-GIO applications that read
the primary selection (i.e. such as terminal emulators using
middle-mouse clicks) can read the data from a GIO app.

Signed-off-by: Jeff Williams <kanobe@gmail.com>
2021-12-14 11:49:07 +01:00
Inkeliz 2a32ece084 app: [iOS] replace ViewEvent.View with add ViewController field
For mixing native UI with Gio UI, the UIViewController is sometimes
needed, not just the UIView. This change replace the View field of
ViewEvent with ViewController.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-12-10 06:16:26 +01:00
Elias Naur e6e69812af app: expose semantic information to Android platforms
Previous changes added semantic API and semantic information to Gio
widgets. This change maps the information to Android accessibility
classes so that TalkBack can traverse and interact with Gio programs.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-12-01 17:57:04 +01:00
Pierre Curto ebb7f40e9d app: implement Window.Close for Wayland
This is a followup from a question sent to the mailing list.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-11-26 22:28:47 +01:00
Pierre Curto a699f771c6 app: add Maximize and Center methods support for macOS and X11
Commit 9835cd59 added support for the Window.Maximize and
Window.Center methods for Windows only.
This patch also adds support for macOS and X11.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-11-16 18:41:22 +01:00
Inkeliz f4c82adeff app/internal/windows: don't crash on app.Fullscreen on windows/386
Before this patch, use of `app.Fullscreen` would result in "Failed to
find SetWindowLongPtrW procedure in user32.dll" when running on 32 bit
Windows.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-11-16 16:31:13 +01:00
Inkeliz 40bc2e1f88 app: [iOS] implement ViewEvent
ViewEvent exposes native window handle for platform specific uses. This
change implements ViewEvent for iOS.

Fixes gio#305

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-11-13 10:36:44 +01:00
Jan Kåre Vatne 9835cd5996 app: add Window.Maximize and Center, add Windows implementation
Signed-off-by: Jan Kare Vatne <jkvatne@online.no>
2021-11-10 17:03:23 +01:00
Elias Naur 1d0769ae89 app: use tabs consistently in GioView.java
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-11-03 14:12:31 +01:00
Dylan Staley 4d22a926a9 app: [android] handle touch events from stylus
Fixes gio#291

Signed-off-by: Dylan Staley <88163+dstaley@users.noreply.github.com>
2021-10-16 08:43:51 +02:00
Elias Naur ebad5afdf3 app: [Vulkan] don't exit early on VK_SUBOPTIMAL_KHR
The mapErr helper may map the error to nil, in which case the caller
should continue, not exit.

This change split up error mapping into mapErr which never maps to nil,
and mapSurfaceErr which handles the VK_KHR_swapchain errors and may map
to nil.

Maybe fixes gio#287

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-10-09 10:46:37 +02:00
Elias Naur d6e6ca848a app: don't miss driver defers
Fixes gio#281

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-30 18:21:18 +02:00
Elias Naur 6c1f9c19f5 app,internal/vk: [Vulkan] skip frame with stale window dimensions
While here, add a missing nil check.

Updates gio#280

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-30 17:46:23 +02:00
Elias Naur 868ea76acf app: [X11] avoid deadlock when sending initial ConfigEvent
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-24 12:48:10 +02:00
Elias Naur bdafb3564f gpu,app: [Metal] don't store CFTypeRef values in pointer types
CFTypeRefs may not always contain valid pointers, so they must not be
stored in pointer types lest the Go runtime treats them as such.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-23 15:32:58 +02:00
Elias Naur 8c6e3c5fdf app: [Metal] don't wait for completion of presentation command
There's no need to wait; the Metal backend performs the required
synchronization.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-23 15:26:56 +02:00
Elias Naur 94f7fa3218 app: [Vulkan] keep VkSurfaceKHR ownership to platforms
Before this change, it was unclear who owned the platform specific
VkSurfaceKHR object, leading to a double-free in the error path for
devices with no Vulkan support. This change moves the ownership to the
platform specific code.

Add vk.EnumeratePhysicalDevices while here (refactor was part of
debugging of the double-free).

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-23 12:35:26 +02:00
Elias Naur 6665e0ef0f app: [Windows] don't redraw zero-sized windows
Fixes gio#270

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-22 18:55:22 +02:00
Elias Naur 8999747ad2 app,gpu,internal/vk: add Vulkan port for Wayland, X11, Android
This change implements a Vulkan port for the two renderers, old and
compute. Run with GIORENDERER=forcecompute to test the compute renderer.

To shake out bugs faster, it is also made the default on systems that
support it. To disable Vulkan and force the use of OpenGL, use the
`novulkan` tag:

$ go run -tags novulkan gioui.org/example/kitchen

Don't forget to file an issue describing the issue that prompted the use
of the tag.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-21 18:40:05 +02:00
Elias Naur bdd0893dd0 app,gpu: move errDeviceLost from package app to package gpu
The Vulkan backend can return device lost error from more than just
Present.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-21 17:53:58 +02:00
Elias Naur af6770de18 app: add error result to context.RenderTarget
Vulkan may report VK_ERROR_OUT_OF_DATE_KHR which is not a fatal error.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-20 15:13:00 +02:00
Elias Naur 18c2ba8e20 app: replace Window.Config with ConfigEvent
Unlike Raise, Close and other fire-and-forget methods on Window,
Config calls driverRun because it needs to wait for the result.
However, driverRun isn't guaranteed to block in all contexts.

This change avoids the synchronization dance altogether by removing the
Config method and introducing a ConfigEvent event. The event also makes
it clear when the configuration changes.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-20 08:18:03 +02:00
Elias Naur d1b35bf1d7 app: [macOS] trigger redraw on resize for context-less windows
Switching to using a CAMetalLayer as the layer backing our NSView
implementation broke programs such as the opengl example. Somehow, using
ANGLE on top of a CAMetalLayer (but not a CAEAGLLayer) stops resizes
from triggering redraws.

This change invalidates the view in setFrameSize, to force a redraw
and no longer rely on the implicit redraws.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-19 09:16:11 +02:00
Elias Naur c9d85c97e1 app: process driver funcs before queueing more
Window.driverFunc says it can be run from any context. However, running
it from the Window.run event loop may deadlock, at least until an
unrelated event arrives from the driver (e.g. a mouse move).

Example:
Window.Invalidate is called, which caused Window.run to queue a driver
func, and notify the Window.wakeups channel. However, another
Window.Invalidate arrives just in time for Window.run to process that
before Window.wakeups, leading to a deadlock because only one driver
func can be queued.

This change fixes the problem by processing wakeups before potentially
queueing more driver functions.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-16 10:49:42 +02:00
Elias Naur f896a72ea1 app,gpu/internal/opengl: move glFlush to macOS context present
A previous change[0] moved all OpenGL function calls to the internal
opengl package, so that Gio can use desktop OpenGL and OpenGL ES (ANGLE)
in the same program without confusing the function pointers.

However the change also moved the glFlush that constitutes a buffer
swap, or present, on macOS. Other platforms don't need the flush, so
this change moves it back to macOS-specific code, in glContext.Present
where it belongs. It also uses dlopen and dlsym to avoid symbol
confusion between Apple's OpenGL framework and ANGLE's libGLESv2.dylib.

The motivation is that we're getting rid of the desktop OpenGL backend
on macOS in favor of Metal, and so should reduce the number of global
special-cases catering to that platform.

[0] https://gioui.org/commit/476d2269a

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-15 21:12:29 +02:00
Elias Naur d5d0a75a9b app: fix build on FreeBSD
Somehow, the explicit include and library directories needed for OpenBSD
are required for FreeBSD as well.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-10 08:24:18 +02:00
Pierre Curto e92ca233f5 app: ignore app.Size when in fullscreen mode
Setting the window size while in fulscreen mode does not make sense.

Fixes gio#220

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-09-09 16:24:23 +02:00
Pierre Curto 2f66ed1dc8 app: add Window.Raise to bring a window to the front
Fixes gio#252

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-09-09 07:46:09 +02:00
Elias Naur c5d4e01e3d app: [X11] honour _NET_WM_STATE protocol
The _NET_WM_STATE protocol description[0] states that to change the
window mode for an X11,

"To change the state of a mapped window, a Client MUST send a
_NET_WM_STATE client message to the root window."

and that the window manager in turn

"The Window Manager MUST keep this property updated to reflect the
current state of the window."

However, our X11 implementation did both: send the message _and_ set or
deleted the property.

This change makes it so only the message is sent. It also replaces
toggling the property by setting or clearing, to ensure our mode and the
window manager's mode never gets out of sync.

Maybe fixes gio#265

[0] https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html#idm46515148826720

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-08 13:25:17 +02:00
Pierre Curto b3751dd9ab app: fix invalid NewWindow config on X11
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-09-08 08:20:39 +02:00
Pierre Curto bdc2f3f4e8 app: add Window.Config, export app.Config
A Window configuration with its current option values can now be fetched during a FrameEvent.

The WindowMode and Orientation options have moved to methods on their corresponding types.

Fixes #260

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-09-07 08:06:56 +02:00
Elias Naur 74464f64dc app: use driver defer mechanism for changing animation flag
Now that Window.driverDefer can be run in any context, the special case
of setting the animation flag can use that mechanism instead of a
special purpose channel.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-05 13:58:19 +02:00
Elias Naur 9ffe43bc3a app: delete workarounds for driver callback deadlocks
Driver methods are invoked during event processing, but some of them may
generate events that would in turn deadlock because event processing is
not re-entrant. However, a previous change moved all such calls outside
event processing and so chained events can no longer deadlock.

This change deletes the workarounds.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-05 09:30:47 +02:00
Elias Naur 1796f24a38 app: introduce Window.driverDefer for blocking functions
Window.driverRun is designed to run functions on the driver event
goroutine, to avoid race conditions with internal driver state and,
more importantly, to run on the designated main or UI thread for
platforms that require that.

However, driverRun runs functions during the processing of a driver
event, so if a function in turn triggers another driver event,
deadlock occurs.

This change introduces Window.driverDefer for functions that don't need
to block event processing. Functions passed to driverDefer may
themselves trigger new events.

A few callers of driverRun remain; they need the result of their
functions but are guaranteed not to trigger new events.

Fixes gio#263

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-05 09:27:50 +02:00
Felix Lange 23f6dcb868 app: [Android] simplify invalidate in onFrameCallback
Since onFrameCallback runs on the app UI thread, using plain
invalidate() can be used instead of postInvalidate(). The latter just
schedules a call to invalidate() on the UI thread.

Also, since onFrameCallback is directly called by JNI, there is no need
to set up a new JNI environment to call back into Java.

Signed-off-by: Felix Lange <fjl@twurst.com>
2021-09-04 07:26:47 +02:00
Elias Naur d03f618660 app: [Windows] avoid deadlock when changing window configuration
Some window configurations lead to WM_SIZE messages when changed, which
leads to deadlock because our window proc is not re-entrant. Avoid the
issues by ignoring redundant messages.

Fixes gio#262

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-03 12:11:55 +02:00
Elias Naur 12aa9defe7 app: fix build constraints for nowayland,nox11 on OpenBSD, FreeBSD
While here, add new-style //go:build constraints to generated wayland
glue files.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-30 15:28:44 +02:00
Elias Naur 4f198b3f87 app: render on event loop thread
Before this change, the renderLoop type implemented a rendering
goroutine for rendering off the event thread. However, it's not worth
the complexity, so remove it and render on the event thread.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-29 22:00:24 +02:00
Elias Naur fd008f39af app: [Android] work around broken EGL surfaces on the emulator
The Android emulator creates a broken EGL surface if it is not created
on the same thread as the context is made current.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-29 22:00:24 +02:00
Elias Naur 07e1df3676 app: [Android] detach previous View when another is created
The Android system can in some cases replace the GioView of our Android
Activity before destroying the previous one. This change makes sure the
previous view is ignored, in particular its destroy event.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-29 22:00:24 +02:00
Elias Naur b86928ceec app: [Android] use simpler postInvalidate instead of Choreographer
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-29 22:00:24 +02:00
Elias Naur 45da52cee7 app: merge app/internal/wm into package app
The app and app/internal/wm packages are tightly coupled, requiring
quite a bit of forwarding types, values and constants from the internal
package to export it. Further, no other package imports package wm.

This change merges the two packages.

While here, drop the pre-Go 1.14 SIGPIPE workaround.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-29 22:00:16 +02:00
Pierre Curto 8aac73458a app: set the type of the orientation and Windowed/Fullscreen options
Those variables didn't make it clear that they were Options.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-08-29 08:54:40 +02:00