Commit Graph

369 Commits

Author SHA1 Message Date
Elias Naur b0b469d540 app/internal/wm: [Android] set up view handle before callbacks
Fixes gio#230 (again)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-07 14:20:24 +02:00
Inkeliz 9b4b91fec0 app, io: [wasm, android] add support for numeric/email keyboard mode
Previously, the on-screen keyboard always displays the text keyboard,
(QWERTY or equivalent).

For optimal user experience, it's possible to specify the keyboard type
using `InputHint`. The on-screen keyboard will provide shortcuts or
restrict what the user can input.

Due to some limitations (gio#116), only numeric and text keyboards are
supported on Android.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-06-05 17:49:08 +02:00
Elias Naur 476d2269a6 gpu/internal/opengl,app/internal/wm: generalize desktop OpenGL support
This changes moves the macOS specific setup for desktop OpenGL to the
portable opengl package. The opengl package already takes care of the
desktop OpenGL setup for sRGB framebuffers, and by moving the code we
avoid calling the wrong OpenGL functions in case both OpenGL.framework
and ANGLE libGLESv2.dylib is linked into the program.

Remove the interface casting expressions for gl.Functions; it wasn't
worth the trouble to keep updated.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-01 18:26:11 +02:00
Elias Naur 5f631209ea app/internal/wm: merge os_android.c into os_android.go
The C functions can then be static, and we save a set of declarations.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-20 10:59:48 +02:00
Elias Naur df0e058ea6 app/internal/wm: [macOS] avoid deadlock in Window.Close
Native window callbacks now run in the same context as the event loop.
However, a call to Close immediately calls onClose which in turn wants
to send events. Break the deadlock by deferring the Close call.

Fixes gio#227

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-19 17:22:24 +02:00
Elias Naur 9ad492e93b app/internal/wm: [Android] make GioView delegate methods public
GioActivity is final to avoid the brittle base class problem. However,
to permit replacement of GioActivity the GioView delegate methods must
be public.

While here fix a function signature, rename lowMemory to onLowMemory and make it
static. Also move view specific setup to GioView, simplifying the host
activity further.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-19 15:30:42 +02:00
Elias Naur 8611894b4b app,app/internal/wm: introduce app.Window.Run and use it internally
app.Window implements a method for safely running functions against the
underlying native window through the driverFuncs channel. However, the
functions still run in a different goroutine than the one driving the
native event loop, which forces the implementations in package wm to do
complicated synchronization.

A previous change added a mechanism to run functions in the native event
loop thread. The macOS port needed this functionality, but with some
care it can be generalized. That's what this change does through the
new Run method.

The advantage is that the thread switch dance is now confined to
app.Window, with the help of a generic wm.Driver.Wakeup method. All
other Driver methods can then assume they run on their event loop
threads.

Run is exported because it is also needed for programs that use
Windows configured with CustomRenderer to control their own rendering.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-18 19:59:01 +01:00
Elias Naur c914935169 app/internal/wm: implement ViewEvent for Windows
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-18 14:27:51 +01:00
Elias Naur 1ec408280e app,app/internal/wm: implement ViewEvent for macOS
Move the deprecated setWantsBestResolutionOpenGLSurface to GL-specific
code while we're here.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-18 14:26:46 +01:00
Elias Naur 413bff8766 app: implement CustomRenderer option
CustomRenderer disables the construction and binding of a GPU
context to the Window. Combined with ViewEvent and gpu.New, a Gio
client can mix Gio UI and custom rendering.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-18 14:26:45 +01:00
Elias Naur 03ee75fd72 gpu/internal/opengl: support sRGB emulation for desktop OpenGL
Desktop OpenGL implements a GL_FRAMEBUFFER_SRGB setting; query that instead
of the frambuffer color encoding.

With this change it is no longer necessary to enable FRAMEBUFFER_SRGB
in the macOS setup; remove it.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-18 14:26:45 +01:00
Elias Naur b622412ac6 gpu: support forced OpenGL ES mode, for ANGLE on macOS
macOS is the only platform where desktop OpenGL is used. To support
foreign ANGLE contexts add a setting to override Gio's selection of
OpenGL implementation.

The bulk of this change is making all function pointers per-context
instead of global, and loading the OpenGL library dynamically. As a side
effect we're closer to Gio tolerating a platform without any OpenGL
implementation. For example, Apple has deprecated OpenGL and OpenGL ES
on its platforms and may remove them in the future.

Note that as a side-effect of this change, Gio needs Go 1.16 or newer to
run on iOS.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-18 14:26:45 +01:00
Elias Naur 163be2ffd4 app/internal/wm: [Windows] handle WM_DESTROY properly
After handling WM_DESTROY, the system will destroy the window for us.
This change makes sure destroy events are sent and handled before the
window can no longer be used.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-18 14:25:12 +01:00
Elias Naur 06477be50f app/internal/wm: [iOS] use proper constructor for gl.Functions
We're about to load OpenGL function pointers into gl.Function structs.
Make sure iOS internally uses the NewFunctions constructor, not just
new(Functions).

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-17 20:29:41 +02:00
Elias Naur 3a0583564b app/internal/wm: [macOS] avoid NSView.isFlipped
When using Gio with ANGLE, the isFlipped coordinate system flip will
apply to rendering as well. Fortunately we're no longer using NSOpenGLView
so isFlipped only applies to mouse events. Convert them manually to avoid
isFlipped and support ANGLE.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-17 10:51:10 +02:00
Elias Naur d5fc7fc8f6 app/internal/wm: [macOS] release context only if it was created
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-16 12:02:42 +02:00
Elias Naur 21c319ace5 gpu/internal/opengl,internal: move sRGB emulation to OpenGL driver
There is only one driver but several backends (EGL, WebGL).

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-16 10:44:45 +02:00
Elias Naur 1d4bf04aa1 app/internal/wm: [macOS] use NSView+NSOpenGLContext, not NSOpenGLContextView
NSOpenGLContextView couples the window manager logic tightly with
OpenGL. Use generic NSViews, and attach NSOpenGLContext just like the
other platforms.

This change prepares for supporting GPU contexts created by clients as
well as a future Metal port.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-14 20:23:06 +02:00
Elias Naur fcca1c11ee app/internal/wm: [iOS] don't destroy context when MakeCurrent fails
The caller should ensure the proper destruction.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-14 16:22:56 +02:00
Inkeliz d51d8b46c3 app, app/internal: [wasm,android] new Option to set Orientation
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-04-25 21:32:54 +02:00
Inkeliz 9dae29844c app, app/internal: [wasm,android] new Option to change navigation/status color
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-04-22 12:15:26 +02:00
pierre 354f5b43d2 app: added missing handling of Options.Size for X11
Signed-off-by: pierre <pierre.curto@gmail.com>
2021-04-20 12:15:55 +02:00
aarzilli 495c690187 app: prevent default Windows event handler from running for WM_SYSKEYUP/DOWN
F10 has a special meaning on Windows, if the default handler runs the
first key press following F10 will not generate a key.Press event and
if the first key press after F10 is space the window menu will be
opened instead.

Fixes #213

Signed-off-by: aarzilli <alessandro.arzilli@gmail.com>
2021-04-10 11:40:05 +02:00
pierre abd6e8f9cd app: support changing Window options at runtime
A Window can now be requested to change its options after
it has been started via its Option method.

All options are supported on macOS, Windows and X11.
On Wayland, only the Size and Title options can be changed
at runtime.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-04-07 09:23:25 +02:00
Inkeliz 96840772c7 app/internal/wm: [js] avoid duplicated-paste
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-04-06 09:21:07 +02:00
pierre ce7f0da06e app/internal/wm: use Option method to initialize windows
Added (*w.window).Option methods to the backends and use them for setting the initial options passed into NewWindow.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-04-02 21:15:42 +02:00
pierre b77c1628f3 app/internal/wm: [macOS] run closure on main thread earlier if possible
Signed-off-by: pierre <pierre.curto@gmail.com>
2021-04-02 18:33:12 +02:00
Elias Naur 662cd2e97a app/internal/log: [Android] don't truncate log lines
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-02 16:13:35 +02:00
pierre 6330caad95 app/internal/wm: change Options fields from values to pointers
Switching to pointer values in Options, including using window manager defaults for size and title, in preparation for updating options on the fly.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-04-02 13:52:52 +02:00
Elias Naur 9d7b57f74a app/internal/wm: delete unused parameter
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-01 16:50:02 +02:00
Elias Naur f3d75f38a9 app/internal/wm: [macOS/iOS] don't release nil strings in nsstringToString
Fixes gio#210

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-29 09:20:24 +02:00
Inkeliz 07802569f7 app: [js] move redraw out of js.FuncOf
Currently, the redraw is called inside js.FuncOf. That PR moves the
redraw to the main function, using channels inside the FuncOf, instead.

The current method (of calling inside the FuncOf) seems to be responsable
to generate `deadlock` errors. It happens even when the wrapped in
goroutines.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-03-26 15:48:15 +01:00
Inkeliz 416094a82c app: [js] support for fullscreen mode
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-03-26 08:15:42 +01:00
pierre 238dd1aa86 app: added support for fullscreen mode
The option field WindowMode allows changing the window mode of an application in either Windowed or Fullscreen.
Only macOS, Windows and X11 platforms are currently supported.

Updates gio#89.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-03-23 23:26:46 +01:00
pierre e0262c20e3 io/key: add NameSpace, report it on Linux
Fixes gio#204.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-03-12 13:18:08 +01:00
Elias Naur 7059b6284a app/internal/wm: rename confusing app/internal/window
Package wm (for "window manager") is a better fit for the package, and
distinguishes it from the low-level package windows for the Windows API.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:28:57 +01:00
Elias Naur 91a14c7fa2 app/internal/window: rename "backends" to "drivers"
"driver" is the new more specific name for gpu backends.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:27:44 +01:00
Elias Naur 7bc0603d7e internal/gl: rename internal/glimpl
Now that the OpenGL driver package is named "opengl", we can finally get
rid of the ugly "glimpl" name.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:27:44 +01:00
Elias Naur 18a6dcf571 gpu/internal/d3d11: make the Direct3D backend internal to package gpu
The package app/internal/d3d11 now contains only the GPU backend on
Direct3D. Move it below package gpu to reflect that.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:26:47 +01:00
Elias Naur 5a9edc9af8 internal/cocoainit: move app/internal/cocoainit
We're about to move app/headless to gpu/headless, and it imports
cocoainit.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:26:47 +01:00
Elias Naur 3af4e6accf internal/egl: move app/internal/egl
We're about to move package app/headless to gpu/headless, and it needs
the egl package.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:26:47 +01:00
Elias Naur 86d17efc2c internal/srgb: move app/internal/srgb
We're about to move app/headless to gpu/headless, and it imports
package srgb indirectly.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:26:47 +01:00
Elias Naur e17dd5bd30 internal/d3d11: extract Direct3D API to separate package
We're about the merge the Direct3D backend into package gpu. Extract the
raw Direct3D API to its own package, just like package glimpl.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:26:25 +01:00
Elias Naur 8ff6546285 gpu,gpu/backend: implement generic backend.NewDevice
NewDevice creates a Device given an API, which is the necessary GPU
resources for a backend.

Convert gpu.New to take an API instead of a backend.Device directly.

In turn, this frees us to later unexport the backend package along with
the backend implementations (for now just gioui.org/gpu/gl for OpenGL).
It also allows programs that embed Gio (such as gioui.org/example/glfw)
to freely choose a backend, not just OpenGL.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:24:09 +01:00
Elias Naur 0e723fa192 app/internal/d3d11: change NewBackend to only require a ID3D11Device
Completing the goal of allowing foreign Direct3D contexts for our
D3D backend, slim down the constructor to take only the device handle.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:23:45 +01:00
Elias Naur c3dde562df app/internal/d3d11: only use passed in ID3D11Device in NewBackend
We're about to enable drawing into foreign Direct3D contexts. In
preparation, NewBackend should only need a device handle.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:22:58 +01:00
Elias Naur 932465d891 app/internal/d3d11: move features from Device to Backend
Continuing the previous change to minimize Device, in preparation
for supporting foreign Direct3D contexts.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:21:51 +01:00
Elias Naur 840b9ffa9b gpu/backend,gpu,app/internal/d3d11: move device state to backend
We'd like to allow Gio to share a Direct3D context with an embedding
program like the GLFW example does for OpenGL. To do that, d3d11.Device
needs to carry only the minimal information needed (ID3D11Device).

This change moves the caches of ID3D11DepthStencilState and
ID3D11BlendState from from d3d11.Device to d3d11.Backend. It also adds a
Release method for freeing them.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:21:51 +01:00
Elias Naur 44991f355c app/internal/d3d11: include depth buffer in current framebuffer query
Fixes rendering on Windows. Thanks to Egon Elbre for noticing.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:21:15 +01:00
Elias Naur 3627df7efa app/internal/d3d11,gpu/gl: simplify BeginFrame implementations
BeginFrame returns the output framebuffer, and need not be as general
as the newly unexported currentFramebuffer methods.

No functional change.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-04 14:08:39 +01:00