Skip to content

(nut-tree/nut.js#505) Adapt changes from bolt to libnut screengrab im… #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions src/macos/highlightwindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,30 @@
#import <Cocoa/Cocoa.h>

void showHighlightWindow(int32_t x, int32_t y, int32_t width, int32_t height, long duration, float opacity) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];

bool appIsRunning = [NSApp isRunning];
NSRect mainScreenFrameRect = [[NSScreen mainScreen] frame];
CGFloat screenHeight = mainScreenFrameRect.size.height;
NSRect frame = NSMakeRect(x, screenHeight - y - height, width, height);
NSUInteger styleMask = NSWindowStyleMaskBorderless;
NSWindow * window = [[[NSWindow alloc] initWithContentRect:frame styleMask:styleMask backing:NSBackingStoreBuffered defer:NO] autorelease];
NSWindow *window = [[[NSWindow alloc] initWithContentRect:frame styleMask:styleMask backing:NSBackingStoreBuffered defer:NO] autorelease];
[window setBackgroundColor:[NSColor redColor]];
[window setAlphaValue:opacity];
[window orderFrontRegardless];

[NSTimer scheduledTimerWithTimeInterval: duration / 1000.0
repeats: NO
block: ^(NSTimer * timer){
[NSApp stop:0];
NSRect f = [window frame];
f.size = CGSizeMake(0, 0);
[window setFrame: f display: YES animate: NO];
}];
[NSApp run];
[NSTimer scheduledTimerWithTimeInterval:duration / 1000.0
repeats:NO
block:^(NSTimer *timer) {
if (!appIsRunning) {
[NSApp stop:nil];
}
NSRect f = [window frame];
f.size = CGSizeMake(0, 0);
[window setFrame:f display:YES animate:NO];
}];
if (!appIsRunning) {
[NSApp run];
}
[pool release];
}
}