diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-09-15 11:25:11 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-09-15 11:25:11 +0200 |
| commit | 07195976ce0106a17ed57b08d2fb10d0c3020edb (patch) | |
| tree | 654e52561e0ca2795a6fde7961822289ef616146 /QSCapturaPlugin/Actions | |
Diffstat (limited to 'QSCapturaPlugin/Actions')
| -rw-r--r-- | QSCapturaPlugin/Actions/StartRecordingAction.h | 12 | ||||
| -rw-r--r-- | QSCapturaPlugin/Actions/StartRecordingAction.m | 57 |
2 files changed, 69 insertions, 0 deletions
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 <Foundation/Foundation.h> +#import <QSCore/QSCore.h> + +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 <ApplicationServices/ApplicationServices.h> + +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 |