Commit Graph

347 Commits

Author SHA1 Message Date
Egon Elbre 21ef492cc9 all: use color.NRGBA in public API
color.RGBA has two problems with regards to using it.

First the color values need to be premultiplied, whereas most APIs
have non-premultiplied values. This is mainly to preserve color components
with low alpha values.

Second there are two ways to premultiply with sRGB. One is to premultiply
after sRGB conversion, the other is before. This makes using the API more
confusing.

Using color.NRGBA in sRGB makes it align with CSS.e

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2020-11-19 11:30:11 +01:00
Elias Naur 01e8308a83 app/internal/window: add missing period after sentence
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-11-16 16:51:12 +01:00
Sebastien Binet c15415b0d9 app/permission/camera: fix documentation typo
Signed-off-by: Sebastien Binet <s@sbinet.org>
2020-11-13 15:06:51 +01:00
Elias Naur 002a66f3f3 Revert "app/internal/xkb: fix duplicate edit events for special keys"
This reverts commit e84a2344cf.

The fix is wrong: it's supressing the release key.Event, not key.EditEvents.
The culprit is that Editor fails to ignore release events.

Updates gio#171
2020-11-10 15:27:17 +01:00
Rajiv Kanchan e84a2344cf app/internal/xkb: fix duplicate edit events for special keys
Edit events were being sent twice, once upon key press and again on key release for special keys such as Enter, Arrow keys etc, which resulted in duplicate inputs while pressing these keys. key.EditEvents for special keys now fire once on key press only.

Signed-off-by: Rajiv Kanchan <rajiivkanchan@gmail.com>
2020-11-09 11:00:52 +01:00
Elias Naur 94d242d18c op/paint: remove support for PaintOp.Rect
PaintOp.Rect is the wrong abstraction; it implies a clip operation
better handled by package clip, and not all paints need it (colors).
Furthermore, it's awkward to specify a PaintOp that fills up the
current clip area, regardless of its size.

Redefine PathOp to mean "fill current clip area".

API change. Replace uses of PaintOp.Rect with a TransformOp applied
before the PaintOp.

Leave a TODO for the PathOp infinity area.

Fixes gio#167

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-11-05 16:32:19 +01:00
Elias Naur afb52194d1 app/headless,internal/rendertest: replace PaintOps with Fill/FillShape
We're about to remove PaintOp.Rect. Replacing PaintOps with Fill or
FillShape where possible will ease the transition.

Using Fill in tests exposed a problem with the infinity in paint.Fill.
Adjust it for now; it will be removed later.

Updates gio#167

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-11-05 16:12:39 +01:00
Egon Elbre a55302a498 app/internal/window: use keyed fields
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2020-11-01 17:13:00 +01:00
Josiah Niedrauer 42e568775c io/key: implement key.Release state
Implement key state for the following platforms:
js, wayland, windows, x11.

Unsupported platforms will continue to function as before, sending
key.Press for all key events.

Signed-off-by: Josiah Niedrauer <josiah@niedrauer.com>
2020-11-01 17:13:00 +01:00
Elias Naur ef652f4922 app: move ownership of GPU context to app.Window
The Window creates the context, and should also be responsible for
destroying it.

As a bonus, the wrong release ordering of loop.renderLoop is fixed.
Before this change, the context would be destroyed before the renderer
got a chance to destroy its resources.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-10-30 16:47:05 +01:00
Elias Naur 3740f89171 app/internal/window: [Windows] properly handle WM_QUIT
First, don't filter on HWND in GetMessage and PeekMessage, lest
thread-specific messages may get lost. See

https://devblogs.microsoft.com/oldnewthing/20050209-00/?p=36493

Second, replace the dead status with the detection of WM_QUIT; it's
what it's there for.

May update gio#168

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-10-27 17:57:06 +00:00
Elias Naur 679a34b116 app/internal/window: default to X11 on unix systems
Wayland doesn't guarantee the presence of server-side window decorations
(border, close/maximize/minimize buttons), and Gio doesn't have client-side
decorations either (issue #29). The issue is more than a year old, so it's time
to default to X11 to have a good out-of-the-box experience on unix systems.

Updates gio#29

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-09-27 14:29:31 +02:00
Sebastien Binet 2f67feafc0 app/permission/camera,cmd/gogio: add support for camera permission
Signed-off-by: Sebastien Binet <s@sbinet.org>
2020-09-12 17:32:11 +02:00
Elias Naur 1584f3a64a app/internal/window: [X11] use correct type for setting X properties
32-bit property values are transferred with the C type "long", which
may be 64 bit.

Fixes "invalid atoms" errors from Firefox and Gedit.

While here, add additional clipboard formats to please Gedit.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-08-28 13:34:10 +02:00
aarzilli 4821472ea1 app/internal/xkb: fix events sent when modifier keys are pressed
When modifier keys are active DispatchKey should not send a
key.EditEvent for the key that was pressed. For example when pressing
Ctrl+Alt+e DispatchEvent should not generate a key.EditEvent{Text:"e"}.

Signed-off-by: aarzilli <alessandro.arzilli@gmail.com>
2020-08-25 12:43:53 +02:00
Elias Naur e214191ff7 gpu: don't validate uniform locations
Sufficiently smart GPU drivers can eliminate unused uniforms across
shader types.

Fixes gio#158

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-08-24 19:22:59 +02:00
Elias Naur d3fffef861 app/internal/egl: adjust alpha bit depth to enable sRGB on some GPUs
On my setup:

Extended renderer info (GLX_MESA_query_renderer):
    Vendor: Intel (0x8086)
    Device: Mesa Intel(R) HD Graphics 530 (SKL GT2) (0x1912)
    Version: 20.1.5
    Accelerated: yes
    Video memory: 3072MB
    Unified memory: yes
    Preferred profile: core (0x1)
    Max core profile version: 4.6
    Max compat profile version: 4.6
    Max GLES1 profile version: 1.1
    Max GLES[23] profile version: 3.2

eglCreateWindowSurface with the sRGB flag fails with EGL_BAD_MATCH.
Bumping the ALPHA_SIZE from 1 to 8 seems to make the driver happy
again.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-08-20 14:25:50 +02:00
Elias Naur 3bb1450d0d app: release GPU renderer when done with it
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-08-17 12:14:35 +02:00
Elias Naur 6c30c6386c app,app/internal: [Android] replace Window.Do with ViewEvent
An event reporting the most recent Android View attached to the Window is both
simpler to implement and automatically tracks the Activity lifecycle.

The downside is that buggy programs may hold on to a stale references.
Fortunately, JNI references are handles not pointers so the always-on Android
JNI checks will very likely catch stale references on use.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-08-13 14:41:37 +02:00
Elias Naur 3b95e29183 app/internal/window: [WebAssembly] fix touch event handling
Fixes gio#149

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-26 11:01:30 +02:00
Elias Naur 4a9d97784f app: [Android] don't block the main thread in Window.Do
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-24 19:33:11 +02:00
Elias Naur e381ff40d6 app/internal/window: [Android] work around flickering on ChromeOS
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-22 21:14:35 +02:00
Elias Naur 9ac8c80d15 app/internal/window: fix typos
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-22 20:38:14 +02:00
Elias Naur 86c3fb2f0b app/internal/window: [Android] disable platform focus highlight
Gio apps use a single Android View for the entire UI, rendering the platform
focus highlight unsuitable.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-22 20:07:12 +02:00
Elias Naur 39fd161bea app/internal/window: use GetDpiForWindow if available
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-19 10:41:47 +02:00
Elias Naur e48b85f8d9 app/internal/window,app/internal/egl: replace deprecated MESA_EGL_NO_X11_HEADERS
Fixes gio#147

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-15 12:08:50 +02:00
Elias Naur d572aa23ac op/clip: split Rect into pixel-aligned Rect and rounded RRect
The pixel-aligned Rect is more efficient and easier to use in the common case
of layout clipping.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-09 18:33:00 +02:00
Elias Naur 4818538ef8 op/clip: unexport Rect.Op
It wasn't used anywhere outside Rect.Add.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-09 17:29:31 +02:00
Elias Naur 96da6945a7 app/internal/window: [Wayland] initialize touchFoci map
Fixes gio#145 (I hope)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-08 16:16:44 +02:00
Elias Naur e2278b64c1 app/headless: avoid race between ReleaseCurrent and MakeCurrent
Release context on MakeCurrent failure paths as well.

Fixes gio#144

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-04 17:37:02 +02:00
Elias Naur 30ad63283b app/headless,internal/rendertest: report errors from headless renders
Updates gio#144

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-04 16:36:03 +02:00
Elias Naur d53c92791f app/headless: don't release context while it's current
Updates gio#144

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-04 16:35:58 +02:00
Elias Naur 1513348bf6 app/internal/egl: don't call eglTerminate
A single EGL display may be shared among several contexts. Don't
eglTerminate a context display when destroying the context.

Updates gio#144

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-04 16:26:16 +02:00
Elias Naur 958b19ae22 app/internal/window: [macOS] ignore result from CVDisplayLinkStart
Larry Clapp reported a panic from failing to start the display link.
Ignore the error and hope the error is transient.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-30 11:36:26 +02:00
Elias Naur 2f8833d985 app/internal/window: [X11] avoid -d=checkptr check failures
Casting a *XClientMessageEvent or *XSelectionEvent to *XEvent is
technically incorrect because the union XEvent is the larger structure.

Use an XEvent variable as the backing storage for the specialized
event types instead.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-27 15:29:42 +02:00
Sebastien Binet 6a9a870462 app{,/internal/window}: make app.Main blocking on desktop platforms
This CL implements the app.Main function as a blocking-forever function
for JS, Wayland, Windows and X11.
This works better for applications that can now programmatically close
windows.
2020-06-26 16:20:42 +02:00
Elias Naur 31e8339e1b app/internal/window: [Windows] fix min/max size
Fixes gio#141

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-26 16:14:41 +01:00
Elias Naur d97f7f9093 app/internal/window,cmd/gogio: [iOS] export GioViewController
The Gio GioAppDelegate created the GioViewController programmatically.
When using gogio's -buildmode=archive users may want to use a different
method (for example storyboards) but there can only be one app delegate.

Move the GioAppDelegate to gogio's exe buildmode, and export the
GioViewController for embedding use.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-26 15:47:00 +02:00
Elias Naur 79014a81d5 app/internal/window: [iOS] move logic out of GioAppDelegate
We'd like to remove GioAppDelegate when Gio is embedded with
gogio's -buildmode=archive. Minimize the code in GioAppDelegate.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-26 15:25:40 +02:00
Elias Naur db03b0898d app/internal/window: run main on main thread on Android and iOS
Before this change, Android and iOS were special for two reasons:
app.Main would return immediately, and the program main was invoked from
a goroutine. We can reduce that to one special case by either

- run the program main from the main thread,
- or make app.Main block.

Choose to run main on the main thread.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-25 16:21:28 +02:00
Sebastien Binet 59f07023d4 app/internal: [X11] implement Window.Close
Signed-off-by: Sebastien Binet <s@sbinet.org>
2020-06-22 17:21:39 +02:00
Jason 9cfbdafe14 app/window,app/internal/window: allow min/max window size
The app.MinSize and app.MaxSize options restricts the window size:

w := app.NewWindow(
	app.Size(unit.Dp(600), unit.Dp(596)),
	app.MinSize(unit.Dp(600), unit.Dp(596)),
	app.MaxSize(unit.Dp(600), unit.Dp(596)),
	app.Title(APPNAME),
)

Signed-off-by: Jason <sourcehut@sweatyballs.es>
2020-06-22 13:00:27 +02:00
Egon Elbre 0b713032fb app/internal: [Windows] support Window.Close
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2020-06-19 12:37:21 +02:00
Larry Clapp 602d54dc5e app,app/internal/window: [macOS] add app.Window.Close for closing a window
Recently support was added for multiple top-level windows. Add support
for closing those windows.

macOS only; all others stubbed out.

Signed-off-by: Larry Clapp <larry@theclapp.org>
2020-06-18 14:46:58 +02:00
Elias Naur 596e321610 all: make unit.Converter concrete and rename to Metric
An interface for scaling dp and sp is overkill, at least for all
current uses. Make it a concrete struct type, and rename it to the
shorter and more precise Metric.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-17 11:47:14 +02:00
Jason a3f7eaae08 app/internal/window: set WM_CLASS to binary name
WM_CLASS is used by Linux desktops to provide hints for window
grouping, icons to show and startup notifications.

https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html

This patch set the WM_CLASS to the binary name.

Signed-off-by: Jason <sourcehut@sweatyballs.es>
2020-06-16 16:15:36 +02:00
Elias Naur c2f99fb0e9 app/internal/egl: [Android] fix sRGB on Samsung S9
At least one Samsung S9 device ignores the sRGB setting if the context
wasn't created with alpha in its attributes.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-15 18:06:48 +02:00
Elias Naur 04e605c1b2 app/internal/window: [Android] implement scroll factor fallback for < API 26
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-15 13:40:13 +02:00
Elias Naur feacd1e2df app/internal/window: [Android] implement mouse scrolling
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-13 18:52:29 +02:00
Elias Naur 8688ed95c2 app/internal/window: [Android] replace RegisterFragment with Do
Do is a function for accessing the underlying Android View in a safe
context, the main thread. Do is

- more general than RegisterFragment and may be expanded to other platforms
- simpler to implement (from the Gio side)

and as a bonus, the Do implementation avoids a race condition where
a call to RegisterFragment during an Activity re-create would be ignored.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-13 17:47:58 +02:00