From 07195976ce0106a17ed57b08d2fb10d0c3020edb Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Mon, 15 Sep 2025 11:25:11 +0200 Subject: Initial commit --- QSCapturaPlugin/Actions/StartRecordingAction.h | 12 ++++++ QSCapturaPlugin/Actions/StartRecordingAction.m | 57 ++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 QSCapturaPlugin/Actions/StartRecordingAction.h create mode 100644 QSCapturaPlugin/Actions/StartRecordingAction.m (limited to 'QSCapturaPlugin/Actions') diff --git a/QSCapturaPlugin/Actions/StartRecordingAction.h b/QSCapturaPlugin/Actions/StartRecordingAction.h new file mode 100644 index 0000000..e30c44a --- /dev/null +++ b/QSCapturaPlugin/Actions/StartRecordingAction.h @@ -0,0 +1,12 @@ +#import "Constants.h" +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface StartRecordingAction : QSActionProvider + +- (QSObject *)startRecordingFor:(QSObject *)directObject; +@end + +NS_ASSUME_NONNULL_END diff --git a/QSCapturaPlugin/Actions/StartRecordingAction.m b/QSCapturaPlugin/Actions/StartRecordingAction.m new file mode 100644 index 0000000..a945f29 --- /dev/null +++ b/QSCapturaPlugin/Actions/StartRecordingAction.m @@ -0,0 +1,57 @@ +#import "StartRecordingAction.h" +#import + +NS_ASSUME_NONNULL_BEGIN + +@implementation StartRecordingAction + +- (QSObject *)startRecordingFor:(QSObject *)directObject +{ + id window = [directObject objectForType:kWindowsType]; + + if (!window) { + NSLog(@"Could not get a window ID."); + return directObject; + } + + AXUIElementRef windowElement = (AXUIElementRef)window; + CFTypeRef positionValue = NULL; + CFTypeRef sizeValue = NULL; + + AXError positionError = AXUIElementCopyAttributeValue(windowElement, kAXPositionAttribute, &positionValue); + AXError sizeError = AXUIElementCopyAttributeValue(windowElement, kAXSizeAttribute, &sizeValue); + + if (positionError == kAXErrorSuccess && sizeError == kAXErrorSuccess) { + CGPoint position; + CGSize size; + + if (AXValueGetValue(positionValue, kAXValueCGPointType, &position) && + AXValueGetValue(sizeValue, kAXValueCGSizeType, &size)) { + + CGRect mainDisplayBounds = CGDisplayBounds(CGMainDisplayID()); + CGFloat displayHeight = mainDisplayBounds.size.height; + CGFloat flippedY = displayHeight - position.y - size.height; + + NSString *capturaURL = [NSString stringWithFormat:@"captura:?action=record&auto_start=true&x=%.0f&y=%.0f&width=%.0f&height=%.0f", + position.x, flippedY, size.width, size.height]; + + NSURL *url = [NSURL URLWithString:capturaURL]; + if (url) { + [[NSWorkspace sharedWorkspace] openURL:url]; + } else { + NSLog(@"Failed to create valid URL"); + } + } + } else { + NSLog(@"Could not get size and position of window."); + } + + if (positionValue) CFRelease(positionValue); + if (sizeValue) CFRelease(sizeValue); + + return directObject; +} + +@end + +NS_ASSUME_NONNULL_END -- cgit