mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-08 02:45:38 +00:00
app/internal/wm: remove gio_ prefixes from static (local) C functions
Static C functions don't pollute the global namespace. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -15,16 +15,16 @@ __attribute__ ((visibility ("hidden"))) void gio_hideCursor();
|
|||||||
__attribute__ ((visibility ("hidden"))) void gio_showCursor();
|
__attribute__ ((visibility ("hidden"))) void gio_showCursor();
|
||||||
__attribute__ ((visibility ("hidden"))) void gio_setCursor(NSUInteger curID);
|
__attribute__ ((visibility ("hidden"))) void gio_setCursor(NSUInteger curID);
|
||||||
|
|
||||||
static bool gio_isMainThread() {
|
static bool isMainThread() {
|
||||||
return [NSThread isMainThread];
|
return [NSThread isMainThread];
|
||||||
}
|
}
|
||||||
|
|
||||||
static NSUInteger gio_nsstringLength(CFTypeRef cstr) {
|
static NSUInteger nsstringLength(CFTypeRef cstr) {
|
||||||
NSString *str = (__bridge NSString *)cstr;
|
NSString *str = (__bridge NSString *)cstr;
|
||||||
return [str length];
|
return [str length];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gio_nsstringGetCharacters(CFTypeRef cstr, unichar *chars, NSUInteger loc, NSUInteger length) {
|
static void nsstringGetCharacters(CFTypeRef cstr, unichar *chars, NSUInteger loc, NSUInteger length) {
|
||||||
NSString *str = (__bridge NSString *)cstr;
|
NSString *str = (__bridge NSString *)cstr;
|
||||||
[str getCharacters:chars range:NSMakeRange(loc, length)];
|
[str getCharacters:chars range:NSMakeRange(loc, length)];
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ var mainFuncs = make(chan func(), 1)
|
|||||||
|
|
||||||
// runOnMain runs the function on the main thread.
|
// runOnMain runs the function on the main thread.
|
||||||
func runOnMain(f func()) {
|
func runOnMain(f func()) {
|
||||||
if C.gio_isMainThread() {
|
if C.isMainThread() {
|
||||||
f()
|
f()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -96,12 +96,12 @@ func nsstringToString(str C.CFTypeRef) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
defer C.CFRelease(str)
|
defer C.CFRelease(str)
|
||||||
n := C.gio_nsstringLength(str)
|
n := C.nsstringLength(str)
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
chars := make([]uint16, n)
|
chars := make([]uint16, n)
|
||||||
C.gio_nsstringGetCharacters(str, (*C.unichar)(unsafe.Pointer(&chars[0])), 0, n)
|
C.nsstringGetCharacters(str, (*C.unichar)(unsafe.Pointer(&chars[0])), 0, n)
|
||||||
utf8 := utf16.Decode(chars)
|
utf8 := utf16.Decode(chars)
|
||||||
return string(utf8)
|
return string(utf8)
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-16
@@ -18,7 +18,7 @@ struct drawParams {
|
|||||||
CGFloat top, right, bottom, left;
|
CGFloat top, right, bottom, left;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void gio_writeClipboard(unichar *chars, NSUInteger length) {
|
static void writeClipboard(unichar *chars, NSUInteger length) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSString *s = [NSString string];
|
NSString *s = [NSString string];
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
@@ -29,42 +29,42 @@ static void gio_writeClipboard(unichar *chars, NSUInteger length) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static CFTypeRef gio_readClipboard(void) {
|
static CFTypeRef readClipboard(void) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
UIPasteboard *p = UIPasteboard.generalPasteboard;
|
UIPasteboard *p = UIPasteboard.generalPasteboard;
|
||||||
return (__bridge_retained CFTypeRef)p.string;
|
return (__bridge_retained CFTypeRef)p.string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gio_showTextInput(CFTypeRef viewRef) {
|
static void showTextInput(CFTypeRef viewRef) {
|
||||||
UIView *view = (__bridge UIView *)viewRef;
|
UIView *view = (__bridge UIView *)viewRef;
|
||||||
[view becomeFirstResponder];
|
[view becomeFirstResponder];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gio_hideTextInput(CFTypeRef viewRef) {
|
static void hideTextInput(CFTypeRef viewRef) {
|
||||||
UIView *view = (__bridge UIView *)viewRef;
|
UIView *view = (__bridge UIView *)viewRef;
|
||||||
[view resignFirstResponder];
|
[view resignFirstResponder];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gio_addLayerToView(CFTypeRef viewRef, CFTypeRef layerRef) {
|
static void addLayerToView(CFTypeRef viewRef, CFTypeRef layerRef) {
|
||||||
UIView *view = (__bridge UIView *)viewRef;
|
UIView *view = (__bridge UIView *)viewRef;
|
||||||
CALayer *layer = (__bridge CALayer *)layerRef;
|
CALayer *layer = (__bridge CALayer *)layerRef;
|
||||||
[view.layer addSublayer:layer];
|
[view.layer addSublayer:layer];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gio_updateView(CFTypeRef viewRef, CFTypeRef layerRef) {
|
static void updateView(CFTypeRef viewRef, CFTypeRef layerRef) {
|
||||||
UIView *view = (__bridge UIView *)viewRef;
|
UIView *view = (__bridge UIView *)viewRef;
|
||||||
CAEAGLLayer *layer = (__bridge CAEAGLLayer *)layerRef;
|
CAEAGLLayer *layer = (__bridge CAEAGLLayer *)layerRef;
|
||||||
layer.contentsScale = view.contentScaleFactor;
|
layer.contentsScale = view.contentScaleFactor;
|
||||||
layer.bounds = view.bounds;
|
layer.bounds = view.bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gio_removeLayer(CFTypeRef layerRef) {
|
static void removeLayer(CFTypeRef layerRef) {
|
||||||
CALayer *layer = (__bridge CALayer *)layerRef;
|
CALayer *layer = (__bridge CALayer *)layerRef;
|
||||||
[layer removeFromSuperlayer];
|
[layer removeFromSuperlayer];
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct drawParams gio_viewDrawParams(CFTypeRef viewRef) {
|
static struct drawParams viewDrawParams(CFTypeRef viewRef) {
|
||||||
UIView *v = (__bridge UIView *)viewRef;
|
UIView *v = (__bridge UIView *)viewRef;
|
||||||
struct drawParams params;
|
struct drawParams params;
|
||||||
CGFloat scale = v.layer.contentsScale;
|
CGFloat scale = v.layer.contentsScale;
|
||||||
@@ -147,7 +147,7 @@ func onCreate(view C.CFTypeRef) {
|
|||||||
w.w.SetDriver(w)
|
w.w.SetDriver(w)
|
||||||
w.visible.Store(false)
|
w.visible.Store(false)
|
||||||
w.layer = C.CFTypeRef(layerFactory())
|
w.layer = C.CFTypeRef(layerFactory())
|
||||||
C.gio_addLayerToView(view, w.layer)
|
C.addLayerToView(view, w.layer)
|
||||||
views[view] = w
|
views[view] = w
|
||||||
w.w.Event(system.StageEvent{Stage: system.StagePaused})
|
w.w.Event(system.StageEvent{Stage: system.StagePaused})
|
||||||
}
|
}
|
||||||
@@ -159,13 +159,13 @@ func gio_onDraw(view C.CFTypeRef) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) draw(sync bool) {
|
func (w *window) draw(sync bool) {
|
||||||
params := C.gio_viewDrawParams(w.view)
|
params := C.viewDrawParams(w.view)
|
||||||
if params.width == 0 || params.height == 0 {
|
if params.width == 0 || params.height == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
wasVisible := w.isVisible()
|
wasVisible := w.isVisible()
|
||||||
w.visible.Store(true)
|
w.visible.Store(true)
|
||||||
C.gio_updateView(w.view, w.layer)
|
C.updateView(w.view, w.layer)
|
||||||
if !wasVisible {
|
if !wasVisible {
|
||||||
w.w.Event(system.StageEvent{Stage: system.StageRunning})
|
w.w.Event(system.StageEvent{Stage: system.StageRunning})
|
||||||
}
|
}
|
||||||
@@ -205,7 +205,7 @@ func onDestroy(view C.CFTypeRef) {
|
|||||||
delete(views, view)
|
delete(views, view)
|
||||||
w.w.Event(system.DestroyEvent{})
|
w.w.Event(system.DestroyEvent{})
|
||||||
w.displayLink.Close()
|
w.displayLink.Close()
|
||||||
C.gio_removeLayer(w.layer)
|
C.removeLayer(w.layer)
|
||||||
C.CFRelease(w.layer)
|
C.CFRelease(w.layer)
|
||||||
w.layer = 0
|
w.layer = 0
|
||||||
w.view = 0
|
w.view = 0
|
||||||
@@ -284,7 +284,7 @@ func onTouch(last C.int, view, touchRef C.CFTypeRef, phase C.NSInteger, x, y C.C
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) ReadClipboard() {
|
func (w *window) ReadClipboard() {
|
||||||
content := nsstringToString(C.gio_readClipboard())
|
content := nsstringToString(C.readClipboard())
|
||||||
go w.w.Event(clipboard.Event{Text: content})
|
go w.w.Event(clipboard.Event{Text: content})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,7 +294,7 @@ func (w *window) WriteClipboard(s string) {
|
|||||||
if len(u16) > 0 {
|
if len(u16) > 0 {
|
||||||
chars = (*C.unichar)(unsafe.Pointer(&u16[0]))
|
chars = (*C.unichar)(unsafe.Pointer(&u16[0]))
|
||||||
}
|
}
|
||||||
C.gio_writeClipboard(chars, C.NSUInteger(len(u16)))
|
C.writeClipboard(chars, C.NSUInteger(len(u16)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) Option(opts *Options) {}
|
func (w *window) Option(opts *Options) {}
|
||||||
@@ -351,9 +351,9 @@ func (w *window) isVisible() bool {
|
|||||||
|
|
||||||
func (w *window) ShowTextInput(show bool) {
|
func (w *window) ShowTextInput(show bool) {
|
||||||
if show {
|
if show {
|
||||||
C.gio_showTextInput(w.view)
|
C.showTextInput(w.view)
|
||||||
} else {
|
} else {
|
||||||
C.gio_hideTextInput(w.view)
|
C.hideTextInput(w.view)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+42
-42
@@ -29,16 +29,16 @@ import (
|
|||||||
|
|
||||||
#include <AppKit/AppKit.h>
|
#include <AppKit/AppKit.h>
|
||||||
|
|
||||||
#define GIO_MOUSE_MOVE 1
|
#define MOUSE_MOVE 1
|
||||||
#define GIO_MOUSE_UP 2
|
#define MOUSE_UP 2
|
||||||
#define GIO_MOUSE_DOWN 3
|
#define MOUSE_DOWN 3
|
||||||
#define GIO_MOUSE_SCROLL 4
|
#define MOUSE_SCROLL 4
|
||||||
|
|
||||||
__attribute__ ((visibility ("hidden"))) void gio_main(void);
|
__attribute__ ((visibility ("hidden"))) void gio_main(void);
|
||||||
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createView(void);
|
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createView(void);
|
||||||
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createWindow(CFTypeRef viewRef, const char *title, CGFloat width, CGFloat height, CGFloat minWidth, CGFloat minHeight, CGFloat maxWidth, CGFloat maxHeight);
|
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createWindow(CFTypeRef viewRef, const char *title, CGFloat width, CGFloat height, CGFloat minWidth, CGFloat minHeight, CGFloat maxWidth, CGFloat maxHeight);
|
||||||
|
|
||||||
static void gio_writeClipboard(unichar *chars, NSUInteger length) {
|
static void writeClipboard(unichar *chars, NSUInteger length) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSString *s = [NSString string];
|
NSString *s = [NSString string];
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
@@ -50,7 +50,7 @@ static void gio_writeClipboard(unichar *chars, NSUInteger length) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static CFTypeRef gio_readClipboard(void) {
|
static CFTypeRef readClipboard(void) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSPasteboard *p = NSPasteboard.generalPasteboard;
|
NSPasteboard *p = NSPasteboard.generalPasteboard;
|
||||||
NSString *content = [p stringForType:NSPasteboardTypeString];
|
NSString *content = [p stringForType:NSPasteboardTypeString];
|
||||||
@@ -58,72 +58,72 @@ static CFTypeRef gio_readClipboard(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static CGFloat gio_viewHeight(CFTypeRef viewRef) {
|
static CGFloat viewHeight(CFTypeRef viewRef) {
|
||||||
NSView *view = (__bridge NSView *)viewRef;
|
NSView *view = (__bridge NSView *)viewRef;
|
||||||
return [view bounds].size.height;
|
return [view bounds].size.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CGFloat gio_viewWidth(CFTypeRef viewRef) {
|
static CGFloat viewWidth(CFTypeRef viewRef) {
|
||||||
NSView *view = (__bridge NSView *)viewRef;
|
NSView *view = (__bridge NSView *)viewRef;
|
||||||
return [view bounds].size.width;
|
return [view bounds].size.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CGFloat gio_getScreenBackingScale(void) {
|
static CGFloat getScreenBackingScale(void) {
|
||||||
return [NSScreen.mainScreen backingScaleFactor];
|
return [NSScreen.mainScreen backingScaleFactor];
|
||||||
}
|
}
|
||||||
|
|
||||||
static CGFloat gio_getViewBackingScale(CFTypeRef viewRef) {
|
static CGFloat getViewBackingScale(CFTypeRef viewRef) {
|
||||||
NSView *view = (__bridge NSView *)viewRef;
|
NSView *view = (__bridge NSView *)viewRef;
|
||||||
return [view.window backingScaleFactor];
|
return [view.window backingScaleFactor];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gio_setNeedsDisplay(CFTypeRef viewRef) {
|
static void setNeedsDisplay(CFTypeRef viewRef) {
|
||||||
NSView *view = (__bridge NSView *)viewRef;
|
NSView *view = (__bridge NSView *)viewRef;
|
||||||
[view setNeedsDisplay:YES];
|
[view setNeedsDisplay:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
static NSPoint gio_cascadeTopLeftFromPoint(CFTypeRef windowRef, NSPoint topLeft) {
|
static NSPoint cascadeTopLeftFromPoint(CFTypeRef windowRef, NSPoint topLeft) {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
return [window cascadeTopLeftFromPoint:topLeft];
|
return [window cascadeTopLeftFromPoint:topLeft];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gio_makeKeyAndOrderFront(CFTypeRef windowRef) {
|
static void makeKeyAndOrderFront(CFTypeRef windowRef) {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
[window makeKeyAndOrderFront:nil];
|
[window makeKeyAndOrderFront:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gio_toggleFullScreen(CFTypeRef windowRef) {
|
static void toggleFullScreen(CFTypeRef windowRef) {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
[window toggleFullScreen:nil];
|
[window toggleFullScreen:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gio_close(CFTypeRef windowRef) {
|
static void closeWindow(CFTypeRef windowRef) {
|
||||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||||
[window performClose:nil];
|
[window performClose:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gio_setSize(CFTypeRef windowRef, CGFloat width, CGFloat height) {
|
static void setSize(CFTypeRef windowRef, CGFloat width, CGFloat height) {
|
||||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||||
NSSize size = NSMakeSize(width, height);
|
NSSize size = NSMakeSize(width, height);
|
||||||
[window setContentSize:size];
|
[window setContentSize:size];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gio_setMinSize(CFTypeRef windowRef, CGFloat width, CGFloat height) {
|
static void setMinSize(CFTypeRef windowRef, CGFloat width, CGFloat height) {
|
||||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||||
window.contentMinSize = NSMakeSize(width, height);
|
window.contentMinSize = NSMakeSize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gio_setMaxSize(CFTypeRef windowRef, CGFloat width, CGFloat height) {
|
static void setMaxSize(CFTypeRef windowRef, CGFloat width, CGFloat height) {
|
||||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||||
window.contentMaxSize = NSMakeSize(width, height);
|
window.contentMaxSize = NSMakeSize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gio_setTitle(CFTypeRef windowRef, const char *title) {
|
static void setTitle(CFTypeRef windowRef, const char *title) {
|
||||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||||
window.title = [NSString stringWithUTF8String: title];
|
window.title = [NSString stringWithUTF8String: title];
|
||||||
}
|
}
|
||||||
|
|
||||||
static CFTypeRef gio_layerForView(CFTypeRef viewRef) {
|
static CFTypeRef layerForView(CFTypeRef viewRef) {
|
||||||
NSView *view = (__bridge NSView *)viewRef;
|
NSView *view = (__bridge NSView *)viewRef;
|
||||||
return (__bridge CFTypeRef)view.layer;
|
return (__bridge CFTypeRef)view.layer;
|
||||||
}
|
}
|
||||||
@@ -197,7 +197,7 @@ func (w *window) contextView() C.CFTypeRef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) ReadClipboard() {
|
func (w *window) ReadClipboard() {
|
||||||
content := nsstringToString(C.gio_readClipboard())
|
content := nsstringToString(C.readClipboard())
|
||||||
go w.w.Event(clipboard.Event{Text: content})
|
go w.w.Event(clipboard.Event{Text: content})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,11 +207,11 @@ func (w *window) WriteClipboard(s string) {
|
|||||||
if len(u16) > 0 {
|
if len(u16) > 0 {
|
||||||
chars = (*C.unichar)(unsafe.Pointer(&u16[0]))
|
chars = (*C.unichar)(unsafe.Pointer(&u16[0]))
|
||||||
}
|
}
|
||||||
C.gio_writeClipboard(chars, C.NSUInteger(len(u16)))
|
C.writeClipboard(chars, C.NSUInteger(len(u16)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) Option(opts *Options) {
|
func (w *window) Option(opts *Options) {
|
||||||
screenScale := float32(C.gio_getScreenBackingScale())
|
screenScale := float32(C.getScreenBackingScale())
|
||||||
cfg := configFor(screenScale)
|
cfg := configFor(screenScale)
|
||||||
val := func(v unit.Value) float32 {
|
val := func(v unit.Value) float32 {
|
||||||
return float32(cfg.Px(v)) / screenScale
|
return float32(cfg.Px(v)) / screenScale
|
||||||
@@ -220,27 +220,27 @@ func (w *window) Option(opts *Options) {
|
|||||||
width := val(o.Width)
|
width := val(o.Width)
|
||||||
height := val(o.Height)
|
height := val(o.Height)
|
||||||
if width > 0 || height > 0 {
|
if width > 0 || height > 0 {
|
||||||
C.gio_setSize(w.window, C.CGFloat(width), C.CGFloat(height))
|
C.setSize(w.window, C.CGFloat(width), C.CGFloat(height))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if o := opts.MinSize; o != nil {
|
if o := opts.MinSize; o != nil {
|
||||||
width := val(o.Width)
|
width := val(o.Width)
|
||||||
height := val(o.Height)
|
height := val(o.Height)
|
||||||
if width > 0 || height > 0 {
|
if width > 0 || height > 0 {
|
||||||
C.gio_setMinSize(w.window, C.CGFloat(width), C.CGFloat(height))
|
C.setMinSize(w.window, C.CGFloat(width), C.CGFloat(height))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if o := opts.MaxSize; o != nil {
|
if o := opts.MaxSize; o != nil {
|
||||||
width := val(o.Width)
|
width := val(o.Width)
|
||||||
height := val(o.Height)
|
height := val(o.Height)
|
||||||
if width > 0 || height > 0 {
|
if width > 0 || height > 0 {
|
||||||
C.gio_setMaxSize(w.window, C.CGFloat(width), C.CGFloat(height))
|
C.setMaxSize(w.window, C.CGFloat(width), C.CGFloat(height))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if o := opts.Title; o != nil {
|
if o := opts.Title; o != nil {
|
||||||
title := C.CString(*o)
|
title := C.CString(*o)
|
||||||
defer C.free(unsafe.Pointer(title))
|
defer C.free(unsafe.Pointer(title))
|
||||||
C.gio_setTitle(w.window, title)
|
C.setTitle(w.window, title)
|
||||||
}
|
}
|
||||||
if o := opts.WindowMode; o != nil {
|
if o := opts.WindowMode; o != nil {
|
||||||
w.SetWindowMode(*o)
|
w.SetWindowMode(*o)
|
||||||
@@ -251,7 +251,7 @@ func (w *window) SetWindowMode(mode WindowMode) {
|
|||||||
switch mode {
|
switch mode {
|
||||||
case w.mode:
|
case w.mode:
|
||||||
case Windowed, Fullscreen:
|
case Windowed, Fullscreen:
|
||||||
C.gio_toggleFullScreen(w.window)
|
C.toggleFullScreen(w.window)
|
||||||
w.mode = mode
|
w.mode = mode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -283,12 +283,12 @@ func (w *window) runOnMain(f func()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) Close() {
|
func (w *window) Close() {
|
||||||
// gio_close immediately calls gio_onClose which sends events
|
// close immediately calls gio_onClose which sends events
|
||||||
// causing a deadlock because Close is called during an event.
|
// causing a deadlock because Close is called during an event.
|
||||||
// Break the deadlock by deferring the close, making Close more
|
// Break the deadlock by deferring the close, making Close more
|
||||||
// akin to a message like the other platforms.
|
// akin to a message like the other platforms.
|
||||||
go runOnMain(func() {
|
go runOnMain(func() {
|
||||||
C.gio_close(w.window)
|
C.closeWindow(w.window)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,13 +331,13 @@ func gio_onText(view C.CFTypeRef, cstr *C.char) {
|
|||||||
func gio_onMouse(view C.CFTypeRef, cdir C.int, cbtns C.NSUInteger, x, y, dx, dy C.CGFloat, ti C.double, mods C.NSUInteger) {
|
func gio_onMouse(view C.CFTypeRef, cdir C.int, cbtns C.NSUInteger, x, y, dx, dy C.CGFloat, ti C.double, mods C.NSUInteger) {
|
||||||
var typ pointer.Type
|
var typ pointer.Type
|
||||||
switch cdir {
|
switch cdir {
|
||||||
case C.GIO_MOUSE_MOVE:
|
case C.MOUSE_MOVE:
|
||||||
typ = pointer.Move
|
typ = pointer.Move
|
||||||
case C.GIO_MOUSE_UP:
|
case C.MOUSE_UP:
|
||||||
typ = pointer.Release
|
typ = pointer.Release
|
||||||
case C.GIO_MOUSE_DOWN:
|
case C.MOUSE_DOWN:
|
||||||
typ = pointer.Press
|
typ = pointer.Press
|
||||||
case C.GIO_MOUSE_SCROLL:
|
case C.MOUSE_SCROLL:
|
||||||
typ = pointer.Scroll
|
typ = pointer.Scroll
|
||||||
default:
|
default:
|
||||||
panic("invalid direction")
|
panic("invalid direction")
|
||||||
@@ -387,8 +387,8 @@ func gio_onChangeScreen(view C.CFTypeRef, did uint64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) draw() {
|
func (w *window) draw() {
|
||||||
w.scale = float32(C.gio_getViewBackingScale(w.view))
|
w.scale = float32(C.getViewBackingScale(w.view))
|
||||||
wf, hf := float32(C.gio_viewWidth(w.view)), float32(C.gio_viewHeight(w.view))
|
wf, hf := float32(C.viewWidth(w.view)), float32(C.viewHeight(w.view))
|
||||||
if wf == 0 || hf == 0 {
|
if wf == 0 || hf == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -478,11 +478,11 @@ func NewWindow(win Callbacks, opts *Options) error {
|
|||||||
if nextTopLeft.x == 0 && nextTopLeft.y == 0 {
|
if nextTopLeft.x == 0 && nextTopLeft.y == 0 {
|
||||||
// cascadeTopLeftFromPoint treats (0, 0) as a no-op,
|
// cascadeTopLeftFromPoint treats (0, 0) as a no-op,
|
||||||
// and just returns the offset we need for the first window.
|
// and just returns the offset we need for the first window.
|
||||||
nextTopLeft = C.gio_cascadeTopLeftFromPoint(w.window, nextTopLeft)
|
nextTopLeft = C.cascadeTopLeftFromPoint(w.window, nextTopLeft)
|
||||||
}
|
}
|
||||||
nextTopLeft = C.gio_cascadeTopLeftFromPoint(w.window, nextTopLeft)
|
nextTopLeft = C.cascadeTopLeftFromPoint(w.window, nextTopLeft)
|
||||||
C.gio_makeKeyAndOrderFront(w.window)
|
C.makeKeyAndOrderFront(w.window)
|
||||||
layer := C.gio_layerForView(w.view)
|
layer := C.layerForView(w.view)
|
||||||
w.w.Event(ViewEvent{View: uintptr(w.view), Layer: uintptr(layer)})
|
w.w.Event(ViewEvent{View: uintptr(w.view), Layer: uintptr(layer)})
|
||||||
})
|
})
|
||||||
return <-errch
|
return <-errch
|
||||||
@@ -493,14 +493,14 @@ func newWindow(opts *Options) (*window, error) {
|
|||||||
if view == 0 {
|
if view == 0 {
|
||||||
return nil, errors.New("CreateWindow: failed to create view")
|
return nil, errors.New("CreateWindow: failed to create view")
|
||||||
}
|
}
|
||||||
scale := float32(C.gio_getViewBackingScale(view))
|
scale := float32(C.getViewBackingScale(view))
|
||||||
w := &window{
|
w := &window{
|
||||||
view: view,
|
view: view,
|
||||||
scale: scale,
|
scale: scale,
|
||||||
}
|
}
|
||||||
dl, err := NewDisplayLink(func() {
|
dl, err := NewDisplayLink(func() {
|
||||||
w.runOnMain(func() {
|
w.runOnMain(func() {
|
||||||
C.gio_setNeedsDisplay(w.view)
|
C.setNeedsDisplay(w.view)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
w.displayLink = dl
|
w.displayLink = dl
|
||||||
|
|||||||
@@ -62,33 +62,33 @@ static void handleMouse(NSView *view, NSEvent *event, int typ, CGFloat dx, CGFlo
|
|||||||
gio_onDraw((__bridge CFTypeRef)self);
|
gio_onDraw((__bridge CFTypeRef)self);
|
||||||
}
|
}
|
||||||
- (void)mouseDown:(NSEvent *)event {
|
- (void)mouseDown:(NSEvent *)event {
|
||||||
handleMouse(self, event, GIO_MOUSE_DOWN, 0, 0);
|
handleMouse(self, event, MOUSE_DOWN, 0, 0);
|
||||||
}
|
}
|
||||||
- (void)mouseUp:(NSEvent *)event {
|
- (void)mouseUp:(NSEvent *)event {
|
||||||
handleMouse(self, event, GIO_MOUSE_UP, 0, 0);
|
handleMouse(self, event, MOUSE_UP, 0, 0);
|
||||||
}
|
}
|
||||||
- (void)middleMouseDown:(NSEvent *)event {
|
- (void)middleMouseDown:(NSEvent *)event {
|
||||||
handleMouse(self, event, GIO_MOUSE_DOWN, 0, 0);
|
handleMouse(self, event, MOUSE_DOWN, 0, 0);
|
||||||
}
|
}
|
||||||
- (void)middletMouseUp:(NSEvent *)event {
|
- (void)middletMouseUp:(NSEvent *)event {
|
||||||
handleMouse(self, event, GIO_MOUSE_UP, 0, 0);
|
handleMouse(self, event, MOUSE_UP, 0, 0);
|
||||||
}
|
}
|
||||||
- (void)rightMouseDown:(NSEvent *)event {
|
- (void)rightMouseDown:(NSEvent *)event {
|
||||||
handleMouse(self, event, GIO_MOUSE_DOWN, 0, 0);
|
handleMouse(self, event, MOUSE_DOWN, 0, 0);
|
||||||
}
|
}
|
||||||
- (void)rightMouseUp:(NSEvent *)event {
|
- (void)rightMouseUp:(NSEvent *)event {
|
||||||
handleMouse(self, event, GIO_MOUSE_UP, 0, 0);
|
handleMouse(self, event, MOUSE_UP, 0, 0);
|
||||||
}
|
}
|
||||||
- (void)mouseMoved:(NSEvent *)event {
|
- (void)mouseMoved:(NSEvent *)event {
|
||||||
handleMouse(self, event, GIO_MOUSE_MOVE, 0, 0);
|
handleMouse(self, event, MOUSE_MOVE, 0, 0);
|
||||||
}
|
}
|
||||||
- (void)mouseDragged:(NSEvent *)event {
|
- (void)mouseDragged:(NSEvent *)event {
|
||||||
handleMouse(self, event, GIO_MOUSE_MOVE, 0, 0);
|
handleMouse(self, event, MOUSE_MOVE, 0, 0);
|
||||||
}
|
}
|
||||||
- (void)scrollWheel:(NSEvent *)event {
|
- (void)scrollWheel:(NSEvent *)event {
|
||||||
CGFloat dx = -event.scrollingDeltaX;
|
CGFloat dx = -event.scrollingDeltaX;
|
||||||
CGFloat dy = -event.scrollingDeltaY;
|
CGFloat dy = -event.scrollingDeltaY;
|
||||||
handleMouse(self, event, GIO_MOUSE_SCROLL, dx, dy);
|
handleMouse(self, event, MOUSE_SCROLL, dx, dy);
|
||||||
}
|
}
|
||||||
- (void)keyDown:(NSEvent *)event {
|
- (void)keyDown:(NSEvent *)event {
|
||||||
NSString *keys = [event charactersIgnoringModifiers];
|
NSString *keys = [event charactersIgnoringModifiers];
|
||||||
|
|||||||
Reference in New Issue
Block a user