aboutsummaryrefslogtreecommitdiff
path: root/QSCapturaPlugin
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2025-09-15 11:25:11 +0200
committerRuben Beltran del Rio <git@r.bdr.sh>2025-09-15 11:25:11 +0200
commit07195976ce0106a17ed57b08d2fb10d0c3020edb (patch)
tree654e52561e0ca2795a6fde7961822289ef616146 /QSCapturaPlugin
Initial commitHEADmain
Diffstat (limited to 'QSCapturaPlugin')
-rw-r--r--QSCapturaPlugin/Actions/StartRecordingAction.h12
-rw-r--r--QSCapturaPlugin/Actions/StartRecordingAction.m57
-rw-r--r--QSCapturaPlugin/Commands/StartRecordingCommand.h13
-rw-r--r--QSCapturaPlugin/Commands/StartRecordingCommand.m23
-rw-r--r--QSCapturaPlugin/QSCapturaPlugin.h16
-rw-r--r--QSCapturaPlugin/QSCapturaPlugin.m16
-rw-r--r--QSCapturaPlugin/Types/Constants.h3
-rw-r--r--QSCapturaPlugin/Types/Constants.m3
-rw-r--r--QSCapturaPlugin/en.lproj/Localizable.strings1
9 files changed, 144 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
diff --git a/QSCapturaPlugin/Commands/StartRecordingCommand.h b/QSCapturaPlugin/Commands/StartRecordingCommand.h
new file mode 100644
index 0000000..aa6bcab
--- /dev/null
+++ b/QSCapturaPlugin/Commands/StartRecordingCommand.h
@@ -0,0 +1,13 @@
+#import "Constants.h"
+#import <Foundation/Foundation.h>
+#import <QSCore/QSCore.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface StartRecordingCommand : QSActionProvider
+
+- (QSObject *)startRecording:(QSObject *)directObject;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/QSCapturaPlugin/Commands/StartRecordingCommand.m b/QSCapturaPlugin/Commands/StartRecordingCommand.m
new file mode 100644
index 0000000..4a3f1f3
--- /dev/null
+++ b/QSCapturaPlugin/Commands/StartRecordingCommand.m
@@ -0,0 +1,23 @@
+#import "StartRecordingCommand.h"
+#import <ApplicationServices/ApplicationServices.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@implementation StartRecordingCommand
+
+- (QSObject *)startRecording:(QSObject *)directObject
+{
+ NSString *capturaURL = @"captura:?action=record";
+ NSURL *url = [NSURL URLWithString:capturaURL];
+ if (url) {
+ [[NSWorkspace sharedWorkspace] openURL:url];
+ } else {
+ NSLog(@"Failed to create valid URL");
+ }
+
+ return directObject;
+}
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/QSCapturaPlugin/QSCapturaPlugin.h b/QSCapturaPlugin/QSCapturaPlugin.h
new file mode 100644
index 0000000..f0e4383
--- /dev/null
+++ b/QSCapturaPlugin/QSCapturaPlugin.h
@@ -0,0 +1,16 @@
+//
+// QSCapturaPlugin.h
+// Captura Plugin
+//
+// Created by Ruben Beltran del Rio on 2025-09-15.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface QSCapturaPlugin : NSObject
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/QSCapturaPlugin/QSCapturaPlugin.m b/QSCapturaPlugin/QSCapturaPlugin.m
new file mode 100644
index 0000000..e335205
--- /dev/null
+++ b/QSCapturaPlugin/QSCapturaPlugin.m
@@ -0,0 +1,16 @@
+//
+// QSCapturaPlugin.m
+// Captura Plugin
+//
+// Created by Ruben Beltran del Rio on 2025-09-15.
+//
+
+#import "QSCapturaPlugin.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@implementation QSCapturaPlugin
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/QSCapturaPlugin/Types/Constants.h b/QSCapturaPlugin/Types/Constants.h
new file mode 100644
index 0000000..c267fa9
--- /dev/null
+++ b/QSCapturaPlugin/Types/Constants.h
@@ -0,0 +1,3 @@
+#pragma mark - Window Object Types
+
+extern NSString *const kWindowsType;
diff --git a/QSCapturaPlugin/Types/Constants.m b/QSCapturaPlugin/Types/Constants.m
new file mode 100644
index 0000000..dbc1521
--- /dev/null
+++ b/QSCapturaPlugin/Types/Constants.m
@@ -0,0 +1,3 @@
+#pragma mark - Window Object Types
+
+NSString *const kWindowsType = @"WindowsType";
diff --git a/QSCapturaPlugin/en.lproj/Localizable.strings b/QSCapturaPlugin/en.lproj/Localizable.strings
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/QSCapturaPlugin/en.lproj/Localizable.strings
@@ -0,0 +1 @@
+