mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
app: [macOS] add missing autoreleasepools
Their absense didn't make a practical difference so far, but we're about to refactor the macOS event processing loop where the pools do matter. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+121
-65
@@ -62,148 +62,204 @@ static CFTypeRef readClipboard(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CGFloat viewHeight(CFTypeRef viewRef) {
|
static CGFloat viewHeight(CFTypeRef viewRef) {
|
||||||
NSView *view = (__bridge NSView *)viewRef;
|
@autoreleasepool {
|
||||||
return [view bounds].size.height;
|
NSView *view = (__bridge NSView *)viewRef;
|
||||||
|
return [view bounds].size.height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static CGFloat viewWidth(CFTypeRef viewRef) {
|
static CGFloat viewWidth(CFTypeRef viewRef) {
|
||||||
NSView *view = (__bridge NSView *)viewRef;
|
@autoreleasepool {
|
||||||
return [view bounds].size.width;
|
NSView *view = (__bridge NSView *)viewRef;
|
||||||
|
return [view bounds].size.width;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static CGFloat getScreenBackingScale(void) {
|
static CGFloat getScreenBackingScale(void) {
|
||||||
return [NSScreen.mainScreen backingScaleFactor];
|
@autoreleasepool {
|
||||||
|
return [NSScreen.mainScreen backingScaleFactor];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static CGFloat getViewBackingScale(CFTypeRef viewRef) {
|
static CGFloat getViewBackingScale(CFTypeRef viewRef) {
|
||||||
NSView *view = (__bridge NSView *)viewRef;
|
@autoreleasepool {
|
||||||
return [view.window backingScaleFactor];
|
NSView *view = (__bridge NSView *)viewRef;
|
||||||
|
return [view.window backingScaleFactor];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setNeedsDisplay(CFTypeRef viewRef) {
|
static void setNeedsDisplay(CFTypeRef viewRef) {
|
||||||
NSView *view = (__bridge NSView *)viewRef;
|
@autoreleasepool {
|
||||||
[view setNeedsDisplay:YES];
|
NSView *view = (__bridge NSView *)viewRef;
|
||||||
|
[view setNeedsDisplay:YES];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static NSPoint cascadeTopLeftFromPoint(CFTypeRef windowRef, NSPoint topLeft) {
|
static NSPoint cascadeTopLeftFromPoint(CFTypeRef windowRef, NSPoint topLeft) {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
return [window cascadeTopLeftFromPoint:topLeft];
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
|
return [window cascadeTopLeftFromPoint:topLeft];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void makeKeyAndOrderFront(CFTypeRef windowRef) {
|
static void makeKeyAndOrderFront(CFTypeRef windowRef) {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
[window makeKeyAndOrderFront:nil];
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
|
[window makeKeyAndOrderFront:nil];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void toggleFullScreen(CFTypeRef windowRef) {
|
static void toggleFullScreen(CFTypeRef windowRef) {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
[window toggleFullScreen:nil];
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
|
[window toggleFullScreen:nil];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static NSWindowStyleMask getWindowStyleMask(CFTypeRef windowRef) {
|
static NSWindowStyleMask getWindowStyleMask(CFTypeRef windowRef) {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
return [window styleMask];
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
|
return [window styleMask];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setWindowStyleMask(CFTypeRef windowRef, NSWindowStyleMask mask) {
|
static void setWindowStyleMask(CFTypeRef windowRef, NSWindowStyleMask mask) {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
window.styleMask = mask;
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
|
window.styleMask = mask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setWindowTitleVisibility(CFTypeRef windowRef, NSWindowTitleVisibility state) {
|
static void setWindowTitleVisibility(CFTypeRef windowRef, NSWindowTitleVisibility state) {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
window.titleVisibility = state;
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
|
window.titleVisibility = state;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setWindowTitlebarAppearsTransparent(CFTypeRef windowRef, int transparent) {
|
static void setWindowTitlebarAppearsTransparent(CFTypeRef windowRef, int transparent) {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
window.titlebarAppearsTransparent = (BOOL)transparent;
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
|
window.titlebarAppearsTransparent = (BOOL)transparent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setWindowStandardButtonHidden(CFTypeRef windowRef, NSWindowButton btn, int hide) {
|
static void setWindowStandardButtonHidden(CFTypeRef windowRef, NSWindowButton btn, int hide) {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
[window standardWindowButton:btn].hidden = (BOOL)hide;
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
|
[window standardWindowButton:btn].hidden = (BOOL)hide;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void performWindowDragWithEvent(CFTypeRef windowRef, CFTypeRef evt) {
|
static void performWindowDragWithEvent(CFTypeRef windowRef, CFTypeRef evt) {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
[window performWindowDragWithEvent:(__bridge NSEvent*)evt];
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
|
[window performWindowDragWithEvent:(__bridge NSEvent*)evt];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void closeWindow(CFTypeRef windowRef) {
|
static void closeWindow(CFTypeRef windowRef) {
|
||||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
[window performClose:nil];
|
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||||
|
[window performClose:nil];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setSize(CFTypeRef windowRef, CGFloat width, CGFloat height) {
|
static void setSize(CFTypeRef windowRef, CGFloat width, CGFloat height) {
|
||||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
NSSize size = NSMakeSize(width, height);
|
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||||
[window setContentSize:size];
|
NSSize size = NSMakeSize(width, height);
|
||||||
|
[window setContentSize:size];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setMinSize(CFTypeRef windowRef, CGFloat width, CGFloat height) {
|
static void setMinSize(CFTypeRef windowRef, CGFloat width, CGFloat height) {
|
||||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
window.contentMinSize = NSMakeSize(width, height);
|
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||||
|
window.contentMinSize = NSMakeSize(width, height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setMaxSize(CFTypeRef windowRef, CGFloat width, CGFloat height) {
|
static void setMaxSize(CFTypeRef windowRef, CGFloat width, CGFloat height) {
|
||||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
window.contentMaxSize = NSMakeSize(width, height);
|
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||||
|
window.contentMaxSize = NSMakeSize(width, height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setScreenFrame(CFTypeRef windowRef, CGFloat x, CGFloat y, CGFloat w, CGFloat h) {
|
static void setScreenFrame(CFTypeRef windowRef, CGFloat x, CGFloat y, CGFloat w, CGFloat h) {
|
||||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
NSRect r = NSMakeRect(x, y, w, h);
|
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||||
[window setFrame:r display:YES];
|
NSRect r = NSMakeRect(x, y, w, h);
|
||||||
|
[window setFrame:r display:YES];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hideWindow(CFTypeRef windowRef) {
|
static void hideWindow(CFTypeRef windowRef) {
|
||||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
[window miniaturize:window];
|
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||||
|
[window miniaturize:window];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void unhideWindow(CFTypeRef windowRef) {
|
static void unhideWindow(CFTypeRef windowRef) {
|
||||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
[window deminiaturize:window];
|
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||||
|
[window deminiaturize:window];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static NSRect getScreenFrame(CFTypeRef windowRef) {
|
static NSRect getScreenFrame(CFTypeRef windowRef) {
|
||||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
return [[window screen] frame];
|
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||||
|
return [[window screen] frame];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setTitle(CFTypeRef windowRef, CFTypeRef titleRef) {
|
static void setTitle(CFTypeRef windowRef, CFTypeRef titleRef) {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
window.title = (__bridge NSString *)titleRef;
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
|
window.title = (__bridge NSString *)titleRef;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int isWindowZoomed(CFTypeRef windowRef) {
|
static int isWindowZoomed(CFTypeRef windowRef) {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
return window.zoomed ? 1 : 0;
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
|
return window.zoomed ? 1 : 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void zoomWindow(CFTypeRef windowRef) {
|
static void zoomWindow(CFTypeRef windowRef) {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
@autoreleasepool {
|
||||||
[window zoom:nil];
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
|
[window zoom:nil];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static CFTypeRef layerForView(CFTypeRef viewRef) {
|
static CFTypeRef layerForView(CFTypeRef viewRef) {
|
||||||
NSView *view = (__bridge NSView *)viewRef;
|
@autoreleasepool {
|
||||||
return (__bridge CFTypeRef)view.layer;
|
NSView *view = (__bridge NSView *)viewRef;
|
||||||
|
return (__bridge CFTypeRef)view.layer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static CFTypeRef windowForView(CFTypeRef viewRef) {
|
static CFTypeRef windowForView(CFTypeRef viewRef) {
|
||||||
NSView *view = (__bridge NSView *)viewRef;
|
@autoreleasepool {
|
||||||
return (__bridge CFTypeRef)view.window;
|
NSView *view = (__bridge NSView *)viewRef;
|
||||||
|
return (__bridge CFTypeRef)view.window;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void raiseWindow(CFTypeRef windowRef) {
|
static void raiseWindow(CFTypeRef windowRef) {
|
||||||
NSRunningApplication *currentApp = [NSRunningApplication currentApplication];
|
@autoreleasepool {
|
||||||
if (![currentApp isActive]) {
|
NSRunningApplication *currentApp = [NSRunningApplication currentApplication];
|
||||||
[currentApp activateWithOptions:(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)];
|
if (![currentApp isActive]) {
|
||||||
|
[currentApp activateWithOptions:(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)];
|
||||||
|
}
|
||||||
|
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||||
|
[window makeKeyAndOrderFront:nil];
|
||||||
}
|
}
|
||||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
|
||||||
[window makeKeyAndOrderFront:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static CFTypeRef createInputContext(CFTypeRef clientRef) {
|
static CFTypeRef createInputContext(CFTypeRef clientRef) {
|
||||||
@@ -215,23 +271,23 @@ static CFTypeRef createInputContext(CFTypeRef clientRef) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void discardMarkedText(CFTypeRef viewRef) {
|
static void discardMarkedText(CFTypeRef viewRef) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
id<NSTextInputClient> view = (__bridge id<NSTextInputClient>)viewRef;
|
id<NSTextInputClient> view = (__bridge id<NSTextInputClient>)viewRef;
|
||||||
NSTextInputContext *ctx = [NSTextInputContext currentInputContext];
|
NSTextInputContext *ctx = [NSTextInputContext currentInputContext];
|
||||||
if (view == [ctx client]) {
|
if (view == [ctx client]) {
|
||||||
[ctx discardMarkedText];
|
[ctx discardMarkedText];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void invalidateCharacterCoordinates(CFTypeRef viewRef) {
|
static void invalidateCharacterCoordinates(CFTypeRef viewRef) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
id<NSTextInputClient> view = (__bridge id<NSTextInputClient>)viewRef;
|
id<NSTextInputClient> view = (__bridge id<NSTextInputClient>)viewRef;
|
||||||
NSTextInputContext *ctx = [NSTextInputContext currentInputContext];
|
NSTextInputContext *ctx = [NSTextInputContext currentInputContext];
|
||||||
if (view == [ctx client]) {
|
if (view == [ctx client]) {
|
||||||
[ctx invalidateCharacterCoordinates];
|
[ctx invalidateCharacterCoordinates];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
@@ -241,7 +297,7 @@ func init() {
|
|||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ViewEvent notified the client of changes to the window AppKit handles.
|
// ViewEvent notifies the client of changes to the window AppKit handles.
|
||||||
// The handles are retained until another ViewEvent is sent.
|
// The handles are retained until another ViewEvent is sent.
|
||||||
type ViewEvent struct {
|
type ViewEvent struct {
|
||||||
// View is a CFTypeRef for the NSView for the window.
|
// View is a CFTypeRef for the NSView for the window.
|
||||||
|
|||||||
+12
-8
@@ -254,14 +254,16 @@ void gio_showCursor() {
|
|||||||
// some cursors are not public, this tries to use a private cursor
|
// some cursors are not public, this tries to use a private cursor
|
||||||
// and uses fallback when the use of private cursor fails.
|
// and uses fallback when the use of private cursor fails.
|
||||||
void gio_trySetPrivateCursor(SEL cursorName, NSCursor* fallback) {
|
void gio_trySetPrivateCursor(SEL cursorName, NSCursor* fallback) {
|
||||||
if ([NSCursor respondsToSelector:cursorName]) {
|
@autoreleasepool {
|
||||||
id object = [NSCursor performSelector:cursorName];
|
if ([NSCursor respondsToSelector:cursorName]) {
|
||||||
if ([object isKindOfClass:[NSCursor class]]) {
|
id object = [NSCursor performSelector:cursorName];
|
||||||
[(NSCursor*)object set];
|
if ([object isKindOfClass:[NSCursor class]]) {
|
||||||
return;
|
[(NSCursor*)object set];
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
[fallback set];
|
||||||
}
|
}
|
||||||
[fallback set];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void gio_setCursor(NSUInteger curID) {
|
void gio_setCursor(NSUInteger curID) {
|
||||||
@@ -401,8 +403,10 @@ CFTypeRef gio_createView(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void gio_viewSetHandle(CFTypeRef viewRef, uintptr_t handle) {
|
void gio_viewSetHandle(CFTypeRef viewRef, uintptr_t handle) {
|
||||||
GioView *v = (__bridge GioView *)viewRef;
|
@autoreleasepool {
|
||||||
v.handle = handle;
|
GioView *v = (__bridge GioView *)viewRef;
|
||||||
|
v.handle = handle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@implementation GioAppDelegate
|
@implementation GioAppDelegate
|
||||||
|
|||||||
Reference in New Issue
Block a user