This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define EXPECT(anObj, aClass)\ | |
aClass * anObj##_valid = nil;\ | |
BOOL anObj##_isClass = [anObj isKindOfClass:[aClass class]];\ | |
if (! anObj##_isClass) { NSLog(@"Warning: Invalid class, '%s' is %@, expecting %@", #anObj, [anObj class], [aClass class]); }\ | |
if ( anObj##_isClass )\ | |
{ anObj##_valid = (aClass *) anObj; }\ | |
if ( anObj##_isClass ) | |
// ...replaces this: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSWindow *topmostAppWindowAtPoint(CGPoint screenPoint) | |
{ | |
const CGWindowLevel kScreensaverWindowLevel = CGWindowLevelForKey(kCGScreenSaverWindowLevelKey); | |
/* This function returns a pointer to the app's topmost NSWindow that | |
the point `screenPoint` is over. The important distinction here is that | |
this function takes _all_ system windows into consideration and will return | |
`nil` if there is a system window (or NSMenu etc.) that the cursor | |
is over which is atop the app window, which is information that | |
can't otherwise be gleaned by checking against `[NSApp orderedWindows]` etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)mouseDown:(NSEvent *)theEvent | |
{ | |
/* Hard-coding this behavior isn't great, and shouldn't be necessary. (It should | |
be up to OS X to define what a contextual-menu click is/isn't, and we should | |
only care about vending our NSMenu via `menuForEvent:`). But this fixes the | |
discrepancy between control and right clicks in NSView. */ | |
if ((theEvent.modifierFlags & NSControlKeyMask)) | |
{ | |
[NSMenu popUpContextMenu:[self menuForEvent:theEvent] withEvent:theEvent forView:self]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func mouseDown(theEvent: NSEvent) | |
{ | |
/* Hard-coding this behavior isn't great, and shouldn't be necessary. (It should | |
be up to OS X to define what a contextual-menu click is/isn't, and we should | |
only care about vending our NSMenu via `menuForEvent:`). */ | |
let modifierFlags = theEvent.modifierFlags; | |
if (modifierFlags.contains(.ControlKeyMask)) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body, input, textarea, select, button, { | |
text-rendering: optimizeLegibility; | |
-webkit-font-smoothing: antialiased; | |
-moz-osx-font-smoothing: grayscale; | |
-moz-font-feature-settings: "liga", "kern"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)clickAtPoint:(CGPoint)pointInElement thenDragTo:(CGPoint)point2InElement | |
{ | |
CGRect frame = self.frame; | |
CGFloat width = CGRectGetWidth(frame); | |
CGFloat height = CGRectGetHeight(frame); | |
XCUICoordinate *coord1 = [self coordinateWithNormalizedOffset:CGVectorMake(pointInElement.x / width, pointInElement.y / height)]; | |
XCUICoordinate *coord2 = [coord1 coordinateWithOffset:CGVectorMake(point2InElement.x - pointInElement.x, point2InElement.y - pointInElement.y)]; | |
[coord1 clickForDuration:0.1 thenDragToCoordinate:coord2]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Usage example: | |
//XCUIElement *newFileButton = self.app.windows.buttons[@"New File"]; | |
//[self waitForElementToExist:newFileButton timeout:20.0]; | |
//[newFileButton click]; | |
- (void)waitForElementToExist:(XCUIElement *)element timeout:(NSTimeInterval)timeout | |
{ | |
NSPredicate *existsPredicate = [NSPredicate predicateWithFormat:@"exists == 1"]; | |
[self expectationForPredicate:existsPredicate evaluatedWithObject:element handler:nil]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id systemAlertMonitor = [self addUIInterruptionMonitorWithDescription:@"Alert Handler" handler:^BOOL(XCUIElement * _Nonnull interruptingElement) { | |
//Exampe: Check for expected UI indicating a particular system alert | |
if (interruptingElement.staticTexts[@"<Alert text example>"].exists && | |
interruptingElement.buttons[@"OK"].exists) | |
{ | |
//Dismiss the alert (e.g., by calling -click on the target button of interruptingElement) | |
[interruptingElement.buttons[@"OK"] click]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The following code reliably crashes windowserver on macOS 10.13, | |
// forcing logout of the current user. | |
// Setup: Create a simple, default SKView() and present an | |
// SKScene() and add it to a window on macOS | |
let sprite = SKSpriteNode(imageNamed: "mySpriteImage") | |
scene.addChild(sprite) | |
let warpGridSize = 100 | |
func geometryGridPositions(byWarping: Bool) -> [float2] { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Perlin.swift | |
// Created by Matthew Reagan on 8/7/18. | |
// | |
// Quick implementation of the the classic Perlin noise | |
// generation function, useful for creating organic textures | |
// or terrain. Perlin noise can also be easily generated with | |
// Apple's GameplayKit framework, this code is mostly for | |
// experimentation purposes. (Disclaimer: This code is not | |
// optimized, nor particularly elegant, but it can be used as | |
// a jumping off point for writing custom noise functions.) |
OlderNewer