Commit Graph

39 Commits

Author SHA1 Message Date
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
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
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 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 65078cdece app/internal/window: [macOS] simplify NewWindow
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-07 14:48:54 +02:00
Elias Naur 483084f4be app/internal/window: [macOS] delay window creation until ready
Fixes #128

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-07 08:42:36 +02:00
Elias Naur 144a5a9cf5 app/internal/window: [macOS] introduce serious cascading
This time without arbitrary offsets and with support for multiple
windows.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-06 19:27:25 +02:00
Elias Naur 4408c2a695 app/internal/window: [macOS] support more than one window
Updates #19

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-06 19:09:02 +02:00
Elias Naur 476bf8d263 app/internal/window: [macOS] only terminate app when last window closes
Updates #19

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-05 12:10:23 +02:00
Elias Naur 9efdc3409c app/internal/window: [macOS] remove window reference from app delegate
Updates #19

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-05 12:10:23 +02:00
Elias Naur 7c22a888b1 app/internal/window: [macOS] make GioDelegate window-independent
Updates #19

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-05 12:10:23 +02:00
Elias Naur 278e9bc334 app/internal/window: [macOS] remove useless retain/release
The window and its view is guaranteed to outlast the display link.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-03 21:20:06 +02:00
Elias Naur c225daa845 app/internal/window: [macOS] use regular map for view-to-window lookups
All accesses to the view map now happens on the main thread, so
there is no need for a sync.Map anymore.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-03 21:20:02 +02:00
Gordon Klaus e188d0e6ff io/pointer,gesture,app/internal/window: add pointer.Scroll event type
Signed-off-by: Gordon Klaus <gordon.klaus@gmail.com>
2020-06-03 10:08:22 +02:00
Elias Naur 4cb96ccad9 app/internal/window: [macOS] always draw synchronously
Asynchronous draws introduces flickering on resizes.

Fixes #123

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-02 15:07:04 +02:00
Elias Naur 1377bea3cd app/internal/window: [macOS,iOS] reduce display link starting and stopping
Recent changes to the macOS threading exposed a problem where a
window's display link may fail to start after being started and stopped
in rapid succession.

Introduce a displayLink type that waits a while after the last stop
request before stopping its display link. That seems to be the way
other projects are using display links.

As a bonus, the new implementation avoids the potentially expensive
overhead of frequent starting and stopping the underlying OS thread.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-30 14:42:00 +02:00
Elias Naur 33146961f4 app/internal/window: [macOS] avoid racy access to window width, height, scale
The macOS redraw callback is not invoked on the main thread, so its
access to window fields must be synchronized.

An alternative would be to schedule the asynchronous redraws on the main
thread, but I believe frame callbacks are performance-sensitive enough
to warrant the extra locking complexity.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-27 16:12:57 +02:00
Elias Naur 5c6ff659bf app/internal/window: [macOS] don't call Cococa from non-main thread
Only the synchronous draws from the main thread may involve changing
width, height and scale. Introduce cached window.width and window.height
fields and limits updates to main-thread draws.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-27 16:07:40 +02:00
Elias Naur 9534337a43 app/internal/window: macOS clipboard support
Updates gio#31

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-17 15:43:12 +02:00
Elias Naur 10a81bf217 app/internal/window: [macOS] fold header files into Cgo preambles
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-17 15:43:12 +02:00
Elias Naur 85a75ee265 app/internal/window: [macOS] move main thread dispatching to Go
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-17 15:43:12 +02:00
Elias Naur a3dc2d6cdc app/internal/window: [macOS] run most callbacks on the main thread
Before this change, we had a viewDo that serialized a function on a view
on a single goroutine. For better or worse, most callbacks in Cocoa
happen on the main thread, so we might as well use that.

The only exception is the frame callback from the CADisplayLink.
We could force that through the main thread as well, but for
efficiency settle with making the view-to-window map synchronized.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-17 15:43:12 +02:00
Elias Naur 3569b0f31b app/internal/window: [macOS] assume valid view in synchronous draws
Asynchronous drawing happens only in onFrameCallback, where we have to
check for disappearing views. onDraw however, is synchronous and should
always have a valid view.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-17 15:43:12 +02:00
Elias Naur 533bf953f9 app/internal/cocoainit: enable multithread support in Cocoa
According to

https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html#//apple_ref/doc/uid/20000738-125024

Cocoa is by default not multithread-safe for programs that use the posix
api for creating threads:

"
For multithreaded applications, Cocoa frameworks use locks and other
forms of internal synchronization to ensure they behave correctly. To
prevent these locks from degrading performance in the single-threaded
case, however, Cocoa does not create them until the application spawns
its first new thread using the NSThread class. If you spawn threads
using only POSIX thread routines, Cocoa does not receive the
notifications it needs to know that your application is now
multithreaded. When that happens, operations involving the Cocoa
frameworks may destabilize or crash your application.
"

That includes Go programs.

The fix, as discovered by Steeve Morin, is to create and launch
an empty NSThread.

Add a package that does that, and use it everywhere Cocoa is used.

Sigh.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-23 21:13:19 +02:00
Larry Clapp 65bc7be256 app/internal/window: allow punctuation as keycode events
Allows things like "ctrl-{" and ".".

All punctuation is returned as-is, e.g. "!" is "!", not "shift-1", and
"{" is "{", not "shift-[".

Also add the Enter key as a known key (fn-return on my Mac).

Signed-off-by: Larry Clapp <larry@theclapp.org>
2019-11-24 19:41:11 +01:00
Larry Clapp f8de7545f4 several: add modifiers to mouse events and clicks
macOS only, for the os-specific bits.

Signed-off-by: Larry Clapp <larry@theclapp.org>
2019-11-18 15:38:09 +01:00
Elias Naur dc7f9bab23 io/pointer,gesture: report right and middle mouse button events
Updates gio#60

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-09 17:41:39 +01:00
Elias Naur dca25a7708 app/internal/window: map "Backtab" to Shift-Tab
Updates gio#62

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-09 15:47:06 +01:00
Elias Naur de7d6b28fa io/key: add support for the Tab and Space keys
Fixes gio#62

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-09 11:57:36 +01:00
Elias Naur cc43588aba io/key: switch Event.Name to be a string and add function keys
Function keys don't have a natural rune representation so switch
Event.Name to be a string to fit "F1"-"F12".

Fixes gio#59

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-08 22:20:17 +01:00
Elias Naur c833c98fd7 io/key: add ModAlt, ModSuper
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-08 18:39:21 +01:00
Elias Naur 396a538afe app/internal/window: don't second guess UI scale
Before this change, Gio tries hard to come up with a reasonable UI scale
factor on desktop OSes derived from the physical dimensions and
resolution of connected monitors. Gio also attempts to detect the user
specified system UI scale and apply it.

However, all that is complex and misguided:

- The UI scale should not depend on whatever monitor is connected at
program startup - For multiple monitors, it's unclear which one to base
the scale off.  - Applying both a monitor derived scale *and* the user
specified scale is wrong, because the user scale is relative to some
fixed scale, not Gio's derived scale.  - With an automatic scale, Gio
does not respect user preference and will not have a similar scale to
other programs on the desktop.

Get rid of the the automatic UI scale detection and rely only on the
user scale.

Updates gio#53

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-04 15:13:37 +01:00
Elias Naur 439d3e652c app/internal: consolidate CFLAGS and move -Werror to #cgo directives
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-28 13:30:51 +01:00
Elias Naur 10c1b2cb8d app,internal/window: extract native window code to separate package
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-14 16:39:32 +02:00