mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
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>
This commit is contained in:
@@ -9,6 +9,12 @@ import (
|
||||
"gioui.org/app/internal/wm"
|
||||
)
|
||||
|
||||
// ViewEvent carries the platform specific window handles for
|
||||
// a Window.
|
||||
//
|
||||
// ViewEvent is implemented on Android and macOS.
|
||||
type ViewEvent = wm.ViewEvent
|
||||
|
||||
// extraArgs contains extra arguments to append to
|
||||
// os.Args. The arguments are separated with |.
|
||||
// Useful for running programs on mobiles where the
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
"gioui.org/app/internal/wm"
|
||||
)
|
||||
|
||||
type ViewEvent = wm.ViewEvent
|
||||
|
||||
// JavaVM returns the global JNI JavaVM.
|
||||
func JavaVM() uintptr {
|
||||
return wm.JavaVM()
|
||||
|
||||
@@ -45,6 +45,7 @@ CFTypeRef gio_createGLContext(void) {
|
||||
void gio_setContextView(CFTypeRef ctxRef, CFTypeRef viewRef) {
|
||||
GioGLContext *ctx = (__bridge GioGLContext *)ctxRef;
|
||||
NSView *view = (__bridge NSView *)viewRef;
|
||||
[view setWantsBestResolutionOpenGLSurface:YES];
|
||||
[ctx setView:view];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:ctx
|
||||
selector:@selector(notifyUpdate:)
|
||||
|
||||
@@ -45,6 +45,8 @@ import (
|
||||
"gioui.org/unit"
|
||||
)
|
||||
|
||||
type ViewEvent struct{}
|
||||
|
||||
type window struct {
|
||||
view C.CFTypeRef
|
||||
w Callbacks
|
||||
@@ -322,3 +324,5 @@ func Main() {
|
||||
func gio_runMain() {
|
||||
runMain()
|
||||
}
|
||||
|
||||
func (_ ViewEvent) ImplementsEvent() {}
|
||||
|
||||
@@ -4,7 +4,6 @@ package wm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gioui.org/internal/f32color"
|
||||
"image"
|
||||
"image/color"
|
||||
"strings"
|
||||
@@ -14,6 +13,8 @@ import (
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"gioui.org/internal/f32color"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/io/clipboard"
|
||||
"gioui.org/io/key"
|
||||
@@ -22,6 +23,8 @@ import (
|
||||
"gioui.org/unit"
|
||||
)
|
||||
|
||||
type ViewEvent struct{}
|
||||
|
||||
type window struct {
|
||||
window js.Value
|
||||
document js.Value
|
||||
@@ -671,3 +674,5 @@ func translateKey(k string) (string, bool) {
|
||||
}
|
||||
return n, true
|
||||
}
|
||||
|
||||
func (_ ViewEvent) ImplementsEvent() {}
|
||||
|
||||
@@ -51,6 +51,7 @@ __attribute__ ((visibility ("hidden"))) void gio_setSize(CFTypeRef windowRef, CG
|
||||
__attribute__ ((visibility ("hidden"))) void gio_setMinSize(CFTypeRef windowRef, CGFloat width, CGFloat height);
|
||||
__attribute__ ((visibility ("hidden"))) void gio_setMaxSize(CFTypeRef windowRef, CGFloat width, CGFloat height);
|
||||
__attribute__ ((visibility ("hidden"))) void gio_setTitle(CFTypeRef windowRef, const char *title);
|
||||
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_layerForView(CFTypeRef viewRef);
|
||||
*/
|
||||
import "C"
|
||||
|
||||
@@ -59,6 +60,15 @@ func init() {
|
||||
runtime.LockOSThread()
|
||||
}
|
||||
|
||||
// ViewEvent notified the client of changes to the window AppKit handles.
|
||||
// The handles are retained until another ViewEvent is sent.
|
||||
type ViewEvent struct {
|
||||
// View is a CFTypeRef for the NSView for the window.
|
||||
View uintptr
|
||||
// Layer is a CFTypeRef of the CALayer of View.
|
||||
Layer uintptr
|
||||
}
|
||||
|
||||
type window struct {
|
||||
view C.CFTypeRef
|
||||
window C.CFTypeRef
|
||||
@@ -335,6 +345,7 @@ func configFor(scale float32) unit.Metric {
|
||||
func gio_onClose(view C.CFTypeRef) {
|
||||
w := mustView(view)
|
||||
w.displayLink.Close()
|
||||
w.w.Event(ViewEvent{})
|
||||
deleteView(view)
|
||||
w.w.Event(system.DestroyEvent{})
|
||||
C.CFRelease(w.view)
|
||||
@@ -395,6 +406,8 @@ func NewWindow(win Callbacks, opts *Options) error {
|
||||
}
|
||||
nextTopLeft = C.gio_cascadeTopLeftFromPoint(w.window, nextTopLeft)
|
||||
C.gio_makeKeyAndOrderFront(w.window)
|
||||
layer := C.gio_layerForView(w.view)
|
||||
w.w.Event(ViewEvent{View: uintptr(w.view), Layer: uintptr(layer)})
|
||||
})
|
||||
return <-errch
|
||||
}
|
||||
@@ -510,3 +523,5 @@ func convertMods(mods C.NSUInteger) key.Modifiers {
|
||||
}
|
||||
return kmods
|
||||
}
|
||||
|
||||
func (_ ViewEvent) ImplementsEvent() {}
|
||||
|
||||
@@ -300,12 +300,16 @@ void gio_setTitle(CFTypeRef windowRef, const char *title) {
|
||||
window.title = [NSString stringWithUTF8String: title];
|
||||
}
|
||||
|
||||
CFTypeRef gio_layerForView(CFTypeRef viewRef) {
|
||||
NSView *view = (__bridge NSView *)viewRef;
|
||||
return (__bridge CFTypeRef)view.layer;
|
||||
}
|
||||
|
||||
CFTypeRef gio_createView(void) {
|
||||
@autoreleasepool {
|
||||
NSRect frame = NSMakeRect(0, 0, 0, 0);
|
||||
GioView* view = [[GioView alloc] initWithFrame:frame];
|
||||
[view setWantsBestResolutionOpenGLSurface:YES];
|
||||
[view setWantsLayer:YES]; // The default in Mojave.
|
||||
[view setWantsLayer:YES];
|
||||
return CFBridgingRetain(view);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
type ViewEvent struct{}
|
||||
|
||||
func Main() {
|
||||
select {}
|
||||
}
|
||||
@@ -37,3 +39,5 @@ func NewWindow(window Callbacks, opts *Options) error {
|
||||
}
|
||||
return errors.New("app: no window driver available")
|
||||
}
|
||||
|
||||
func (_ ViewEvent) ImplementsEvent() {}
|
||||
|
||||
@@ -28,6 +28,8 @@ import (
|
||||
"gioui.org/io/system"
|
||||
)
|
||||
|
||||
type ViewEvent struct{}
|
||||
|
||||
type winConstraints struct {
|
||||
minWidth, minHeight int32
|
||||
maxWidth, maxHeight int32
|
||||
@@ -790,3 +792,5 @@ func configForDPI(dpi int) unit.Metric {
|
||||
PxPerSp: ppdp,
|
||||
}
|
||||
}
|
||||
|
||||
func (_ ViewEvent) ImplementsEvent() {}
|
||||
|
||||
Reference in New Issue
Block a user