From 3b9e9c4eb787472e2da0263861d67968ebd6733d Mon Sep 17 00:00:00 2001 From: Supasorn Suwajanakorn Date: Tue, 22 Nov 2022 16:07:33 +0700 Subject: [PATCH 1/3] fix 2 bugs. 1. moveresize() randomly crashes because NSWindow's updates are not performed in main queue. 2. move-resize icon not changing. Ventura requires contentView's setNeedsDisplay set to YES --- jitouch/Jitouch/Gesture.m | 53 +++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/jitouch/Jitouch/Gesture.m b/jitouch/Jitouch/Gesture.m index 5058f2c..4cf048c 100644 --- a/jitouch/Jitouch/Gesture.m +++ b/jitouch/Jitouch/Gesture.m @@ -1199,9 +1199,11 @@ static int gestureTrackpadMoveResize(const Finger *data, int nFingers, double ti if (step2 == 0) { if (firstTime) { getMousePosition(&baseX, &baseY); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [cursorWindow orderOut:nil]; - [pool release]; + dispatch_async(dispatch_get_main_queue(), ^{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + [cursorWindow orderOut:nil]; + [pool release]; + }); if (cWindow == nil) cWindow = activateWindowAtPosition(baseX, baseY); @@ -1211,12 +1213,15 @@ static int gestureTrackpadMoveResize(const Finger *data, int nFingers, double ti getWindowPos(cWindow, &appX, &appY); cursorImageType = type - 1; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [cursorWindow display]; - setCursorWindowAtMouse(); - [cursorWindow setLevel:NSScreenSaverWindowLevel]; - [cursorWindow makeKeyAndOrderFront:nil]; - [pool release]; + dispatch_async(dispatch_get_main_queue(), ^{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + [cursorWindow display]; + [[cursorWindow contentView] setNeedsDisplay:YES]; + setCursorWindowAtMouse(); + [cursorWindow setLevel:NSScreenSaverWindowLevel]; + [cursorWindow makeKeyAndOrderFront:nil]; + [pool release]; + }); moveResizeFlag = 1; } @@ -1230,15 +1235,21 @@ static int gestureTrackpadMoveResize(const Finger *data, int nFingers, double ti if (nFingers == 1 && !shouldExitMoveResize) { CGFloat x, y; getMousePosition(&x, &y); - setCursorWindowAtMouse(); + dispatch_async(dispatch_get_main_queue(), ^{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + setCursorWindowAtMouse(); + [pool release]; + }); if (type == 1) { setWindowPos2(cWindow, x, y, baseX, baseY, appX, appY); } else if (type == 2) { if (!setWindowSize2(cWindow, x, y, baseX, baseY)) { type = 0; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [cursorWindow orderOut:nil]; - [pool release]; + dispatch_async(dispatch_get_main_queue(), ^{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + [cursorWindow orderOut:nil]; + [pool release]; + }); CFSafeRelease(cWindow); cWindow = nil; @@ -1279,9 +1290,11 @@ static int gestureTrackpadMoveResize(const Finger *data, int nFingers, double ti type = 0; CFSafeRelease(cWindow); cWindow = nil; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [cursorWindow orderOut:nil]; - [pool release]; + dispatch_async(dispatch_get_main_queue(), ^{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + [cursorWindow orderOut:nil]; + [pool release]; + }); moveResizeFlag = 0; //CGEventTapEnable(eventClick, false); @@ -1363,9 +1376,11 @@ static int gestureTrackpadMoveResize(const Finger *data, int nFingers, double ti type = 0; CFSafeRelease(cWindow); cWindow = nil; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [cursorWindow orderOut:nil]; - [pool release]; + dispatch_async(dispatch_get_main_queue(), ^{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + [cursorWindow orderOut:nil]; + [pool release]; + }); moveResizeFlag = 0; } else if (data[!min].py < fing[1][1]) { From dcab3d4a7e3d1c1d490182e52dc4c8b585839ef4 Mon Sep 17 00:00:00 2001 From: supasorn Date: Tue, 22 Nov 2022 23:04:01 +0700 Subject: [PATCH 2/3] Update jitouch/Jitouch/Gesture.m Co-authored-by: Aaron Kollasch --- jitouch/Jitouch/Gesture.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jitouch/Jitouch/Gesture.m b/jitouch/Jitouch/Gesture.m index 4cf048c..7182be9 100644 --- a/jitouch/Jitouch/Gesture.m +++ b/jitouch/Jitouch/Gesture.m @@ -1200,9 +1200,9 @@ static int gestureTrackpadMoveResize(const Finger *data, int nFingers, double ti if (firstTime) { getMousePosition(&baseX, &baseY); dispatch_async(dispatch_get_main_queue(), ^{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [cursorWindow orderOut:nil]; - [pool release]; + @autoreleasepool { + [cursorWindow orderOut:nil]; + } }); if (cWindow == nil) cWindow = activateWindowAtPosition(baseX, baseY); From 606f0ba1606f78e1c1e7301b47454fb037cc589e Mon Sep 17 00:00:00 2001 From: Supasorn Suwajanakorn Date: Tue, 22 Nov 2022 23:16:13 +0700 Subject: [PATCH 3/3] use autorelease pool --- jitouch/Jitouch/Gesture.m | 77 ++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/jitouch/Jitouch/Gesture.m b/jitouch/Jitouch/Gesture.m index 7182be9..066040d 100644 --- a/jitouch/Jitouch/Gesture.m +++ b/jitouch/Jitouch/Gesture.m @@ -1214,13 +1214,13 @@ static int gestureTrackpadMoveResize(const Finger *data, int nFingers, double ti cursorImageType = type - 1; dispatch_async(dispatch_get_main_queue(), ^{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [cursorWindow display]; - [[cursorWindow contentView] setNeedsDisplay:YES]; - setCursorWindowAtMouse(); - [cursorWindow setLevel:NSScreenSaverWindowLevel]; - [cursorWindow makeKeyAndOrderFront:nil]; - [pool release]; + @autoreleasepool { + [cursorWindow display]; + [[cursorWindow contentView] setNeedsDisplay:YES]; + setCursorWindowAtMouse(); + [cursorWindow setLevel:NSScreenSaverWindowLevel]; + [cursorWindow makeKeyAndOrderFront:nil]; + } }); moveResizeFlag = 1; @@ -1236,9 +1236,9 @@ static int gestureTrackpadMoveResize(const Finger *data, int nFingers, double ti CGFloat x, y; getMousePosition(&x, &y); dispatch_async(dispatch_get_main_queue(), ^{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - setCursorWindowAtMouse(); - [pool release]; + @autoreleasepool { + setCursorWindowAtMouse(); + } }); if (type == 1) { setWindowPos2(cWindow, x, y, baseX, baseY, appX, appY); @@ -1246,9 +1246,9 @@ static int gestureTrackpadMoveResize(const Finger *data, int nFingers, double ti if (!setWindowSize2(cWindow, x, y, baseX, baseY)) { type = 0; dispatch_async(dispatch_get_main_queue(), ^{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [cursorWindow orderOut:nil]; - [pool release]; + @autoreleasepool { + [cursorWindow orderOut:nil]; + } }); CFSafeRelease(cWindow); cWindow = nil; @@ -1291,9 +1291,9 @@ static int gestureTrackpadMoveResize(const Finger *data, int nFingers, double ti CFSafeRelease(cWindow); cWindow = nil; dispatch_async(dispatch_get_main_queue(), ^{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [cursorWindow orderOut:nil]; - [pool release]; + @autoreleasepool { + [cursorWindow orderOut:nil]; + } }); moveResizeFlag = 0; @@ -1377,9 +1377,9 @@ static int gestureTrackpadMoveResize(const Finger *data, int nFingers, double ti CFSafeRelease(cWindow); cWindow = nil; dispatch_async(dispatch_get_main_queue(), ^{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [cursorWindow orderOut:nil]; - [pool release]; + @autoreleasepool { + [cursorWindow orderOut:nil]; + } }); moveResizeFlag = 0; @@ -2389,9 +2389,11 @@ static int gestureMagicMouseV(const Finger *data, int nFingers) { if (nFingers == 0 || nFingers > 2) { CFSafeRelease(cWindow); cWindow = nil; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [cursorWindow orderOut:nil]; - [pool release]; + dispatch_async(dispatch_get_main_queue(), ^{ + @autoreleasepool { + [cursorWindow orderOut:nil]; + } + }); type = 0; firstTouch = 1; reset = 0; @@ -2406,9 +2408,11 @@ static int gestureMagicMouseV(const Finger *data, int nFingers) { if (init) { getMousePosition(&baseX, &baseY); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [cursorWindow orderOut:nil]; - [pool release]; + dispatch_async(dispatch_get_main_queue(), ^{ + @autoreleasepool { + [cursorWindow orderOut:nil]; + } + }); if (cWindow == nil) cWindow = activateWindowAtPosition(baseX, baseY); @@ -2418,12 +2422,15 @@ static int gestureMagicMouseV(const Finger *data, int nFingers) { getWindowPos(cWindow, &appX, &appY); cursorImageType = type - 1; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [cursorWindow display]; - setCursorWindowAtMouse(); - [cursorWindow setLevel:NSScreenSaverWindowLevel]; - [cursorWindow makeKeyAndOrderFront:nil]; - [pool release]; + dispatch_async(dispatch_get_main_queue(), ^{ + @autoreleasepool { + [cursorWindow display]; + [[cursorWindow contentView] setNeedsDisplay:YES]; + setCursorWindowAtMouse(); + [cursorWindow setLevel:NSScreenSaverWindowLevel]; + [cursorWindow makeKeyAndOrderFront:nil]; + } + }); } } if (type) { @@ -2437,9 +2444,11 @@ static int gestureMagicMouseV(const Finger *data, int nFingers) { if (!setWindowSize2(cWindow, x, y, baseX, baseY)) { CFSafeRelease(cWindow); cWindow = nil; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [cursorWindow orderOut:nil]; - [pool release]; + dispatch_async(dispatch_get_main_queue(), ^{ + @autoreleasepool { + [cursorWindow orderOut:nil]; + } + }); type = 0; firstTouch = 1; reset = 0;