From 06556986c5c2a6c70854403342f9c9c43def4178 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 8 Aug 2021 15:35:20 +0200 Subject: [PATCH] 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 --- app/internal/wm/os_darwin.go | 12 +++--- app/internal/wm/os_ios.go | 32 +++++++------- app/internal/wm/os_macos.go | 84 ++++++++++++++++++------------------ app/internal/wm/os_macos.m | 18 ++++---- 4 files changed, 73 insertions(+), 73 deletions(-) diff --git a/app/internal/wm/os_darwin.go b/app/internal/wm/os_darwin.go index 1aed0609..7e8d3cd5 100644 --- a/app/internal/wm/os_darwin.go +++ b/app/internal/wm/os_darwin.go @@ -15,16 +15,16 @@ __attribute__ ((visibility ("hidden"))) void gio_hideCursor(); __attribute__ ((visibility ("hidden"))) void gio_showCursor(); __attribute__ ((visibility ("hidden"))) void gio_setCursor(NSUInteger curID); -static bool gio_isMainThread() { +static bool isMainThread() { return [NSThread isMainThread]; } -static NSUInteger gio_nsstringLength(CFTypeRef cstr) { +static NSUInteger nsstringLength(CFTypeRef cstr) { NSString *str = (__bridge NSString *)cstr; 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; [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. func runOnMain(f func()) { - if C.gio_isMainThread() { + if C.isMainThread() { f() return } @@ -96,12 +96,12 @@ func nsstringToString(str C.CFTypeRef) string { return "" } defer C.CFRelease(str) - n := C.gio_nsstringLength(str) + n := C.nsstringLength(str) if n == 0 { return "" } 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) return string(utf8) } diff --git a/app/internal/wm/os_ios.go b/app/internal/wm/os_ios.go index 34f6c3e5..05be325e 100644 --- a/app/internal/wm/os_ios.go +++ b/app/internal/wm/os_ios.go @@ -18,7 +18,7 @@ struct drawParams { CGFloat top, right, bottom, left; }; -static void gio_writeClipboard(unichar *chars, NSUInteger length) { +static void writeClipboard(unichar *chars, NSUInteger length) { @autoreleasepool { NSString *s = [NSString string]; 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 { UIPasteboard *p = UIPasteboard.generalPasteboard; return (__bridge_retained CFTypeRef)p.string; } } -static void gio_showTextInput(CFTypeRef viewRef) { +static void showTextInput(CFTypeRef viewRef) { UIView *view = (__bridge UIView *)viewRef; [view becomeFirstResponder]; } -static void gio_hideTextInput(CFTypeRef viewRef) { +static void hideTextInput(CFTypeRef viewRef) { UIView *view = (__bridge UIView *)viewRef; [view resignFirstResponder]; } -static void gio_addLayerToView(CFTypeRef viewRef, CFTypeRef layerRef) { +static void addLayerToView(CFTypeRef viewRef, CFTypeRef layerRef) { UIView *view = (__bridge UIView *)viewRef; CALayer *layer = (__bridge CALayer *)layerRef; [view.layer addSublayer:layer]; } -static void gio_updateView(CFTypeRef viewRef, CFTypeRef layerRef) { +static void updateView(CFTypeRef viewRef, CFTypeRef layerRef) { UIView *view = (__bridge UIView *)viewRef; CAEAGLLayer *layer = (__bridge CAEAGLLayer *)layerRef; layer.contentsScale = view.contentScaleFactor; layer.bounds = view.bounds; } -static void gio_removeLayer(CFTypeRef layerRef) { +static void removeLayer(CFTypeRef layerRef) { CALayer *layer = (__bridge CALayer *)layerRef; [layer removeFromSuperlayer]; } -static struct drawParams gio_viewDrawParams(CFTypeRef viewRef) { +static struct drawParams viewDrawParams(CFTypeRef viewRef) { UIView *v = (__bridge UIView *)viewRef; struct drawParams params; CGFloat scale = v.layer.contentsScale; @@ -147,7 +147,7 @@ func onCreate(view C.CFTypeRef) { w.w.SetDriver(w) w.visible.Store(false) w.layer = C.CFTypeRef(layerFactory()) - C.gio_addLayerToView(view, w.layer) + C.addLayerToView(view, w.layer) views[view] = w w.w.Event(system.StageEvent{Stage: system.StagePaused}) } @@ -159,13 +159,13 @@ func gio_onDraw(view C.CFTypeRef) { } func (w *window) draw(sync bool) { - params := C.gio_viewDrawParams(w.view) + params := C.viewDrawParams(w.view) if params.width == 0 || params.height == 0 { return } wasVisible := w.isVisible() w.visible.Store(true) - C.gio_updateView(w.view, w.layer) + C.updateView(w.view, w.layer) if !wasVisible { w.w.Event(system.StageEvent{Stage: system.StageRunning}) } @@ -205,7 +205,7 @@ func onDestroy(view C.CFTypeRef) { delete(views, view) w.w.Event(system.DestroyEvent{}) w.displayLink.Close() - C.gio_removeLayer(w.layer) + C.removeLayer(w.layer) C.CFRelease(w.layer) w.layer = 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() { - content := nsstringToString(C.gio_readClipboard()) + content := nsstringToString(C.readClipboard()) go w.w.Event(clipboard.Event{Text: content}) } @@ -294,7 +294,7 @@ func (w *window) WriteClipboard(s string) { if len(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) {} @@ -351,9 +351,9 @@ func (w *window) isVisible() bool { func (w *window) ShowTextInput(show bool) { if show { - C.gio_showTextInput(w.view) + C.showTextInput(w.view) } else { - C.gio_hideTextInput(w.view) + C.hideTextInput(w.view) } } diff --git a/app/internal/wm/os_macos.go b/app/internal/wm/os_macos.go index 47689ff8..0c451257 100644 --- a/app/internal/wm/os_macos.go +++ b/app/internal/wm/os_macos.go @@ -29,16 +29,16 @@ import ( #include -#define GIO_MOUSE_MOVE 1 -#define GIO_MOUSE_UP 2 -#define GIO_MOUSE_DOWN 3 -#define GIO_MOUSE_SCROLL 4 +#define MOUSE_MOVE 1 +#define MOUSE_UP 2 +#define MOUSE_DOWN 3 +#define MOUSE_SCROLL 4 __attribute__ ((visibility ("hidden"))) void gio_main(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); -static void gio_writeClipboard(unichar *chars, NSUInteger length) { +static void writeClipboard(unichar *chars, NSUInteger length) { @autoreleasepool { NSString *s = [NSString string]; 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 { NSPasteboard *p = NSPasteboard.generalPasteboard; 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; return [view bounds].size.height; } -static CGFloat gio_viewWidth(CFTypeRef viewRef) { +static CGFloat viewWidth(CFTypeRef viewRef) { NSView *view = (__bridge NSView *)viewRef; return [view bounds].size.width; } -static CGFloat gio_getScreenBackingScale(void) { +static CGFloat getScreenBackingScale(void) { return [NSScreen.mainScreen backingScaleFactor]; } -static CGFloat gio_getViewBackingScale(CFTypeRef viewRef) { +static CGFloat getViewBackingScale(CFTypeRef viewRef) { NSView *view = (__bridge NSView *)viewRef; return [view.window backingScaleFactor]; } -static void gio_setNeedsDisplay(CFTypeRef viewRef) { +static void setNeedsDisplay(CFTypeRef viewRef) { NSView *view = (__bridge NSView *)viewRef; [view setNeedsDisplay:YES]; } -static NSPoint gio_cascadeTopLeftFromPoint(CFTypeRef windowRef, NSPoint topLeft) { +static NSPoint cascadeTopLeftFromPoint(CFTypeRef windowRef, NSPoint topLeft) { NSWindow *window = (__bridge NSWindow *)windowRef; return [window cascadeTopLeftFromPoint:topLeft]; } -static void gio_makeKeyAndOrderFront(CFTypeRef windowRef) { +static void makeKeyAndOrderFront(CFTypeRef windowRef) { NSWindow *window = (__bridge NSWindow *)windowRef; [window makeKeyAndOrderFront:nil]; } -static void gio_toggleFullScreen(CFTypeRef windowRef) { +static void toggleFullScreen(CFTypeRef windowRef) { NSWindow *window = (__bridge NSWindow *)windowRef; [window toggleFullScreen:nil]; } -static void gio_close(CFTypeRef windowRef) { +static void closeWindow(CFTypeRef windowRef) { NSWindow* window = (__bridge NSWindow *)windowRef; [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; NSSize size = NSMakeSize(width, height); [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; 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; 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; window.title = [NSString stringWithUTF8String: title]; } -static CFTypeRef gio_layerForView(CFTypeRef viewRef) { +static CFTypeRef layerForView(CFTypeRef viewRef) { NSView *view = (__bridge NSView *)viewRef; return (__bridge CFTypeRef)view.layer; } @@ -197,7 +197,7 @@ func (w *window) contextView() C.CFTypeRef { } func (w *window) ReadClipboard() { - content := nsstringToString(C.gio_readClipboard()) + content := nsstringToString(C.readClipboard()) go w.w.Event(clipboard.Event{Text: content}) } @@ -207,11 +207,11 @@ func (w *window) WriteClipboard(s string) { if len(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) { - screenScale := float32(C.gio_getScreenBackingScale()) + screenScale := float32(C.getScreenBackingScale()) cfg := configFor(screenScale) val := func(v unit.Value) float32 { return float32(cfg.Px(v)) / screenScale @@ -220,27 +220,27 @@ func (w *window) Option(opts *Options) { width := val(o.Width) height := val(o.Height) 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 { width := val(o.Width) height := val(o.Height) 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 { width := val(o.Width) height := val(o.Height) 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 { title := C.CString(*o) defer C.free(unsafe.Pointer(title)) - C.gio_setTitle(w.window, title) + C.setTitle(w.window, title) } if o := opts.WindowMode; o != nil { w.SetWindowMode(*o) @@ -251,7 +251,7 @@ func (w *window) SetWindowMode(mode WindowMode) { switch mode { case w.mode: case Windowed, Fullscreen: - C.gio_toggleFullScreen(w.window) + C.toggleFullScreen(w.window) w.mode = mode } } @@ -283,12 +283,12 @@ func (w *window) runOnMain(f func()) { } 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. // Break the deadlock by deferring the close, making Close more // akin to a message like the other platforms. 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) { var typ pointer.Type switch cdir { - case C.GIO_MOUSE_MOVE: + case C.MOUSE_MOVE: typ = pointer.Move - case C.GIO_MOUSE_UP: + case C.MOUSE_UP: typ = pointer.Release - case C.GIO_MOUSE_DOWN: + case C.MOUSE_DOWN: typ = pointer.Press - case C.GIO_MOUSE_SCROLL: + case C.MOUSE_SCROLL: typ = pointer.Scroll default: panic("invalid direction") @@ -387,8 +387,8 @@ func gio_onChangeScreen(view C.CFTypeRef, did uint64) { } func (w *window) draw() { - w.scale = float32(C.gio_getViewBackingScale(w.view)) - wf, hf := float32(C.gio_viewWidth(w.view)), float32(C.gio_viewHeight(w.view)) + w.scale = float32(C.getViewBackingScale(w.view)) + wf, hf := float32(C.viewWidth(w.view)), float32(C.viewHeight(w.view)) if wf == 0 || hf == 0 { return } @@ -478,11 +478,11 @@ func NewWindow(win Callbacks, opts *Options) error { if nextTopLeft.x == 0 && nextTopLeft.y == 0 { // cascadeTopLeftFromPoint treats (0, 0) as a no-op, // 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) - C.gio_makeKeyAndOrderFront(w.window) - layer := C.gio_layerForView(w.view) + nextTopLeft = C.cascadeTopLeftFromPoint(w.window, nextTopLeft) + C.makeKeyAndOrderFront(w.window) + layer := C.layerForView(w.view) w.w.Event(ViewEvent{View: uintptr(w.view), Layer: uintptr(layer)}) }) return <-errch @@ -493,14 +493,14 @@ func newWindow(opts *Options) (*window, error) { if view == 0 { return nil, errors.New("CreateWindow: failed to create view") } - scale := float32(C.gio_getViewBackingScale(view)) + scale := float32(C.getViewBackingScale(view)) w := &window{ view: view, scale: scale, } dl, err := NewDisplayLink(func() { w.runOnMain(func() { - C.gio_setNeedsDisplay(w.view) + C.setNeedsDisplay(w.view) }) }) w.displayLink = dl diff --git a/app/internal/wm/os_macos.m b/app/internal/wm/os_macos.m index ac810fb1..61b45da7 100644 --- a/app/internal/wm/os_macos.m +++ b/app/internal/wm/os_macos.m @@ -62,33 +62,33 @@ static void handleMouse(NSView *view, NSEvent *event, int typ, CGFloat dx, CGFlo gio_onDraw((__bridge CFTypeRef)self); } - (void)mouseDown:(NSEvent *)event { - handleMouse(self, event, GIO_MOUSE_DOWN, 0, 0); + handleMouse(self, event, MOUSE_DOWN, 0, 0); } - (void)mouseUp:(NSEvent *)event { - handleMouse(self, event, GIO_MOUSE_UP, 0, 0); + handleMouse(self, event, MOUSE_UP, 0, 0); } - (void)middleMouseDown:(NSEvent *)event { - handleMouse(self, event, GIO_MOUSE_DOWN, 0, 0); + handleMouse(self, event, MOUSE_DOWN, 0, 0); } - (void)middletMouseUp:(NSEvent *)event { - handleMouse(self, event, GIO_MOUSE_UP, 0, 0); + handleMouse(self, event, MOUSE_UP, 0, 0); } - (void)rightMouseDown:(NSEvent *)event { - handleMouse(self, event, GIO_MOUSE_DOWN, 0, 0); + handleMouse(self, event, MOUSE_DOWN, 0, 0); } - (void)rightMouseUp:(NSEvent *)event { - handleMouse(self, event, GIO_MOUSE_UP, 0, 0); + handleMouse(self, event, MOUSE_UP, 0, 0); } - (void)mouseMoved:(NSEvent *)event { - handleMouse(self, event, GIO_MOUSE_MOVE, 0, 0); + handleMouse(self, event, MOUSE_MOVE, 0, 0); } - (void)mouseDragged:(NSEvent *)event { - handleMouse(self, event, GIO_MOUSE_MOVE, 0, 0); + handleMouse(self, event, MOUSE_MOVE, 0, 0); } - (void)scrollWheel:(NSEvent *)event { CGFloat dx = -event.scrollingDeltaX; CGFloat dy = -event.scrollingDeltaY; - handleMouse(self, event, GIO_MOUSE_SCROLL, dx, dy); + handleMouse(self, event, MOUSE_SCROLL, dx, dy); } - (void)keyDown:(NSEvent *)event { NSString *keys = [event charactersIgnoringModifiers];