Commit Graph

334 Commits

Author SHA1 Message Date
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
Elias Naur f36674ddb3 app/internal/window: [Android] make runOnThread independent of a valid GioView
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-13 17:47:58 +02:00
Elias Naur 2f521899c9 app/internal/window: [Android] use app context for clipboard access
The Activity context may not be available, so it's safer and simpler
to use the always available app context.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-13 16:41:28 +02:00
Elias Naur 65d9a9d1f1 app/internal/window: [Android] skip redraw for destroyed views
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-13 16:41:28 +02:00
Elias Naur fda6fbcf84 app: drop Go 1.12 support
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-13 16:41:28 +02:00
Elias Naur 1b944c8e65 app/internal/d3d11: tolerate padded row pitches from D3DDeviceContext::Map
Fixes gio#136 (I think)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-13 11:46:20 +02:00
Elias Naur 6d5fbcba3f app/internal/window: [Android] unregister focus listener on destroy
Updates github.com/tailscale/tailscale/issues/431

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-11 15:39:33 +02:00
Elias Naur 6380baacb6 all: move Now from system.Config to system.FrameEvent
Then, make layout.Context.Now a field, copied from FrameEvent.Now.

API change:

	gofmt -r 'gtx.Now() -> gtx.Now'

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-09 23:23:08 +02:00
Elias Naur 6f15275e22 app/internal/window: [macOS] retain NSWindow instance
Updates (maybe fixes) #130

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-08 17:54:44 +02:00
Elias Naur 98a603aed6 app/internal/window: [macOS] don't set callbacks before window is ready
Updates gio#130

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-08 16:34:10 +02:00
Elias Naur 504664e014 gpu: saturate instead of overflowing depth buffer
Use greater-than-or-equal test and saturate the z depth buffer
when more than 65k objects are drawn.

Fixes gio#127

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-08 16:28:56 +02:00
Elias Naur 64a516d7c9 app/internal/window: [Windows] avoid race between Main and window closes
While here, replace the window hwnd-to-window map with a sync.Map.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-08 11:39:40 +02:00
Elias Naur d86f96503f app/internal/window: [macOS] fix window sizes for unit.Px values
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-07 17:49:59 +02:00
Elias Naur f710bdf8e8 app: update NewWindow docs to reflect multi-window support
Fixes gio#19

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-07 16:31:06 +02:00