chore: format *.m and *.mm files

This commit is contained in:
sithlord48 2024-12-17 20:42:03 -05:00 committed by Chris Rizzitello
parent af6dac9eee
commit bf4f513d7e
9 changed files with 2042 additions and 2223 deletions

View file

@ -28,6 +28,8 @@ include_files = [
"*.c", "*.c",
"*.hpp", "*.hpp",
"*.cpp", "*.cpp",
"*.m",
"*.mm",
] ]
dirs = ["src"] dirs = ["src"]

View file

@ -5,8 +5,7 @@
@property(strong) IBOutlet NSWindow *window; @property(strong) IBOutlet NSWindow *window;
@end @end
@implementation AppDelegate @implementation AppDelegate {
{
} }
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
@ -17,18 +16,20 @@
#endif #endif
} }
-(BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification{ - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
shouldPresentNotification:(NSUserNotification *)notification
{
return YES; return YES;
} }
#if OSX_DEPLOYMENT_TARGET >= 1014 #if OSX_DEPLOYMENT_TARGET >= 1014
- (void)userNotificationCenter:(UNUserNotificationCenter *)center - (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{ withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
UNNotificationPresentationOptions presentationOptions = {
UNNotificationPresentationOptionSound UNNotificationPresentationOptions presentationOptions = UNNotificationPresentationOptionSound |
| UNNotificationPresentationOptionAlert UNNotificationPresentationOptionAlert |
| UNNotificationPresentationOptionBadge; UNNotificationPresentationOptionBadge;
completionHandler(presentationOptions); completionHandler(presentationOptions);
} }

View file

@ -17,13 +17,13 @@
#import "OSXHelpers.h" #import "OSXHelpers.h"
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import <CoreData/CoreData.h>
#import <Foundation/Foundation.h>
#import <UserNotifications/UNNotification.h> #import <UserNotifications/UNNotification.h>
#import <UserNotifications/UNUserNotificationCenter.h>
#import <UserNotifications/UNNotificationContent.h> #import <UserNotifications/UNNotificationContent.h>
#import <UserNotifications/UNNotificationTrigger.h> #import <UserNotifications/UNNotificationTrigger.h>
#import <UserNotifications/UNUserNotificationCenter.h>
#import <QtGlobal> #import <QtGlobal>
@ -33,8 +33,7 @@
void requestOSXNotificationPermission() void requestOSXNotificationPermission()
{ {
#if OSX_DEPLOYMENT_TARGET >= 1014 #if OSX_DEPLOYMENT_TARGET >= 1014
if (isOSXDevelopmentBuild()) if (isOSXDevelopmentBuild()) {
{
qWarning("Not requesting notification permission in dev build"); qWarning("Not requesting notification permission in dev build");
return; return;
} }
@ -42,30 +41,29 @@ void requestOSXNotificationPermission()
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound) [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound)
completionHandler:^(BOOL granted, NSError *_Nullable error) { completionHandler:^(BOOL granted, NSError *_Nullable error) {
if(error != nil) if (error != nil) {
{ qWarning(
qWarning("Notification permission request error: %s", [[NSString stringWithFormat:@"%@", error] UTF8String]); "Notification permission request error: %s",
[[NSString stringWithFormat:@"%@", error] UTF8String]
);
} }
}]; }];
#endif #endif
} }
bool bool isOSXDevelopmentBuild()
isOSXDevelopmentBuild()
{ {
std::string bundleURL = [[[NSBundle mainBundle] bundleURL].absoluteString UTF8String]; std::string bundleURL = [[[NSBundle mainBundle] bundleURL].absoluteString UTF8String];
return (bundleURL.find("Applications/Deskflow.app") == std::string::npos); return (bundleURL.find("Applications/Deskflow.app") == std::string::npos);
} }
bool bool showOSXNotification(const QString &title, const QString &body)
showOSXNotification(const QString& title, const QString& body)
{ {
#if OSX_DEPLOYMENT_TARGET >= 1014 #if OSX_DEPLOYMENT_TARGET >= 1014
// accessing notification center on unsigned build causes an immidiate // accessing notification center on unsigned build causes an immidiate
// application shutodown (in this case, server) and cannot be caught // application shutodown (in this case, server) and cannot be caught
// to avoid issues with it need to first check if this is a dev build // to avoid issues with it need to first check if this is a dev build
if (isOSXDevelopmentBuild()) if (isOSXDevelopmentBuild()) {
{
qWarning("Not showing notification in dev build"); qWarning("Not showing notification in dev build");
return false; return false;
} }
@ -79,10 +77,13 @@ showOSXNotification(const QString& title, const QString& body)
content.body = body.toNSString(); content.body = body.toNSString();
// Create the request object. // Create the request object.
UNNotificationRequest* request = [UNNotificationRequest UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"SecureInput"
requestWithIdentifier:@"SecureInput" content:content trigger:nil]; content:content
trigger:nil];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { [center
addNotificationRequest:request
withCompletionHandler:^(NSError *_Nullable error) {
if (error != nil) { if (error != nil) {
qWarning("Notification display request error: %s", [[NSString stringWithFormat:@"%@", error] UTF8String]); qWarning("Notification display request error: %s", [[NSString stringWithFormat:@"%@", error] UTF8String]);
} }
@ -98,8 +99,7 @@ showOSXNotification(const QString& title, const QString& body)
return true; return true;
} }
bool bool isOSXInterfaceStyleDark()
isOSXInterfaceStyleDark()
{ {
// Implementation from http://stackoverflow.com/a/26472651 // Implementation from http://stackoverflow.com/a/26472651
NSDictionary *dict = [[NSUserDefaults standardUserDefaults] persistentDomainForName:NSGlobalDomain]; NSDictionary *dict = [[NSUserDefaults standardUserDefaults] persistentDomainForName:NSGlobalDomain];
@ -107,8 +107,7 @@ isOSXInterfaceStyleDark()
return (style && [style isKindOfClass:[NSString class]] && NSOrderedSame == [style caseInsensitiveCompare:@"dark"]); return (style && [style isKindOfClass:[NSString class]] && NSOrderedSame == [style caseInsensitiveCompare:@"dark"]);
} }
IconsTheme IconsTheme getOSXIconsTheme()
getOSXIconsTheme()
{ {
if (@available(macOS 11, *)) if (@available(macOS 11, *))
return IconsTheme::ICONS_TEMPLATE; return IconsTheme::ICONS_TEMPLATE;

View file

@ -16,9 +16,9 @@
#import "platform/OSXDragView.h" #import "platform/OSXDragView.h"
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import <CoreData/CoreData.h>
#import <Foundation/Foundation.h>
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wdeprecated-declarations"
@ -27,15 +27,13 @@ NSWindow* g_dragWindow = NULL;
OSXDragView *g_dragView = NULL; OSXDragView *g_dragView = NULL;
NSString *g_ext = NULL; NSString *g_ext = NULL;
void void runCocoaApp()
runCocoaApp()
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication]; [NSApplication sharedApplication];
NSWindow* window = [[NSWindow alloc] NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 3, 3)
initWithContentRect: NSMakeRect(0, 0, 3, 3)
styleMask:NSBorderlessWindowMask styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:NO]; defer:NO];
@ -56,14 +54,12 @@ runCocoaApp()
[pool release]; [pool release];
} }
void void stopCocoaLoop()
stopCocoaLoop()
{ {
[NSApp stop:g_dragWindow]; [NSApp stop:g_dragWindow];
} }
void void fakeDragging(const char *str, int cursorX, int cursorY)
fakeDragging(const char* str, int cursorX, int cursorY)
{ {
g_ext = [NSString stringWithUTF8String:str]; g_ext = [NSString stringWithUTF8String:str];
@ -88,15 +84,15 @@ fakeDragging(const char* str, int cursorX, int cursorY)
[g_dragView setFileExt:g_ext]; [g_dragView setFileExt:g_ext];
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState); CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
CGEventRef down = CGEventCreateMouseEvent(source, kCGEventLeftMouseDown, CGPointMake(cursorX, cursorY), kCGMouseButtonLeft); CGEventRef down =
CGEventCreateMouseEvent(source, kCGEventLeftMouseDown, CGPointMake(cursorX, cursorY), kCGMouseButtonLeft);
CGEventPost(kCGHIDEventTap, down); CGEventPost(kCGHIDEventTap, down);
CFRelease(down); CFRelease(down);
CFRelease(source); CFRelease(source);
}); });
} }
CFStringRef CFStringRef getCocoaDropTarget()
getCocoaDropTarget()
{ {
// HACK: sleep, wait for cocoa drop target updated first // HACK: sleep, wait for cocoa drop target updated first
usleep(1000000); usleep(1000000);

View file

@ -28,8 +28,7 @@
@dynamic animatesToDestination; @dynamic animatesToDestination;
@dynamic numberOfValidItemsForDrop; @dynamic numberOfValidItemsForDrop;
- (id) - (id)initWithFrame:(NSRect)frame
initWithFrame:(NSRect)frame
{ {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
m_dropTarget = [[NSMutableString alloc] initWithCapacity:0]; m_dropTarget = [[NSMutableString alloc] initWithCapacity:0];
@ -37,25 +36,21 @@ initWithFrame:(NSRect)frame
return self; return self;
} }
- (void) - (void)drawRect:(NSRect)dirtyRect
drawRect:(NSRect)dirtyRect
{ {
} }
- (BOOL) - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
acceptsFirstMouse:(NSEvent *)theEvent
{ {
return YES; return YES;
} }
- (void) - (void)mouseDown:(NSEvent *)theEvent
mouseDown:(NSEvent *)theEvent
{ {
NSLog(@"cocoa mouse down"); NSLog(@"cocoa mouse down");
NSPoint dragPosition; NSPoint dragPosition;
NSRect imageLocation; NSRect imageLocation;
dragPosition = [self convertPoint:[theEvent locationInWindow] dragPosition = [self convertPoint:[theEvent locationInWindow] fromView:nil];
fromView:nil];
dragPosition.x -= 16; dragPosition.x -= 16;
dragPosition.y -= 16; dragPosition.y -= 16;
@ -68,8 +63,7 @@ mouseDown:(NSEvent *)theEvent
event:theEvent]; event:theEvent];
} }
- (NSArray*) - (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination
namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination
{ {
[m_dropTarget setString:@""]; [m_dropTarget setString:@""];
[m_dropTarget appendString:dropDestination.path]; [m_dropTarget appendString:dropDestination.path];
@ -77,14 +71,12 @@ namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination
return nil; return nil;
} }
- (NSDragOperation) - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)flag
draggingSourceOperationMaskForLocal:(BOOL)flag
{ {
return NSDragOperationCopy; return NSDragOperationCopy;
} }
- (CFStringRef) - (CFStringRef)getDropTarget
getDropTarget
{ {
NSMutableString *string; NSMutableString *string;
string = [[NSMutableString alloc] initWithCapacity:0]; string = [[NSMutableString alloc] initWithCapacity:0];
@ -92,14 +84,12 @@ getDropTarget
return (CFStringRef)string; return (CFStringRef)string;
} }
- (void) - (void)clearDropTarget
clearDropTarget
{ {
[m_dropTarget setString:@""]; [m_dropTarget setString:@""];
} }
- (void) - (void)setFileExt:(NSString *)ext
setFileExt:(NSString*) ext
{ {
[ext retain]; [ext retain];
[m_dragFileExt release]; [m_dragFileExt release];
@ -107,14 +97,12 @@ setFileExt:(NSString*) ext
NSLog(@"drag file ext: %@", m_dragFileExt); NSLog(@"drag file ext: %@", m_dragFileExt);
} }
- (NSWindow *) - (NSWindow *)draggingDestinationWindow
draggingDestinationWindow
{ {
return nil; return nil;
} }
- (NSDragOperation) - (NSDragOperation)draggingSourceOperationMask
draggingSourceOperationMask
{ {
return NSDragOperationCopy; return NSDragOperationCopy;
} }
@ -155,12 +143,17 @@ draggingSourceOperationMask
{ {
} }
- (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context - (NSDragOperation)draggingSession:(NSDraggingSession *)session
sourceOperationMaskForDraggingContext:(NSDraggingContext)context
{ {
return NSDragOperationCopy; return NSDragOperationCopy;
} }
- (void)enumerateDraggingItemsWithOptions:(NSDraggingItemEnumerationOptions)enumOpts forView:(NSView *)view classes:(NSArray *)classArray searchOptions:(NSDictionary *)searchOptions usingBlock:(void (^)(NSDraggingItem *draggingItem, NSInteger idx, BOOL *stop))block - (void)enumerateDraggingItemsWithOptions:(NSDraggingItemEnumerationOptions)enumOpts
forView:(NSView *)view
classes:(NSArray *)classArray
searchOptions:(NSDictionary *)searchOptions
usingBlock:(void (^)(NSDraggingItem *draggingItem, NSInteger idx, BOOL *stop))block
{ {
} }

View file

@ -59,8 +59,7 @@ int convertKeyIDToNXKeyType(KeyID id)
return type; return type;
} }
static KeyID static KeyID convertNXKeyTypeToKeyID(uint32_t const type)
convertNXKeyTypeToKeyID(uint32_t const type)
{ {
KeyID id = 0; KeyID id = 0;
@ -95,8 +94,8 @@ convertNXKeyTypeToKeyID(uint32_t const type)
return id; return id;
} }
bool bool isMediaKeyEvent(CGEventRef event)
isMediaKeyEvent(CGEventRef event) { {
NSEvent *nsEvent = nil; NSEvent *nsEvent = nil;
@try { @try {
nsEvent = [NSEvent eventWithCGEvent:event]; nsEvent = [NSEvent eventWithCGEvent:event];
@ -112,9 +111,8 @@ isMediaKeyEvent(CGEventRef event) {
return false; return false;
} }
bool bool getMediaKeyEventInfo(CGEventRef event, KeyID *const keyId, bool *const down, bool *const isRepeat)
getMediaKeyEventInfo(CGEventRef event, KeyID* const keyId, {
bool* const down, bool* const isRepeat) {
NSEvent *nsEvent = nil; NSEvent *nsEvent = nil;
@try { @try {
nsEvent = [NSEvent eventWithCGEvent:event]; nsEvent = [NSEvent eventWithCGEvent:event];
@ -133,20 +131,27 @@ getMediaKeyEventInfo(CGEventRef event, KeyID* const keyId,
return true; return true;
} }
bool bool fakeNativeMediaKey(KeyID id)
fakeNativeMediaKey(KeyID id)
{ {
NSEvent *downRef = [NSEvent otherEventWithType:NSSystemDefined NSEvent *downRef = [NSEvent otherEventWithType:NSSystemDefined
location: NSMakePoint(0, 0) modifierFlags:0xa00 location:NSMakePoint(0, 0)
timestamp:0 windowNumber:0 context:0 subtype:8 modifierFlags:0xa00
timestamp:0
windowNumber:0
context:0
subtype:8
data1:(convertKeyIDToNXKeyType(id) << 16) | ((0xa) << 8) data1:(convertKeyIDToNXKeyType(id) << 16) | ((0xa) << 8)
data2:-1]; data2:-1];
CGEventRef downEvent = [downRef CGEvent]; CGEventRef downEvent = [downRef CGEvent];
NSEvent *upRef = [NSEvent otherEventWithType:NSSystemDefined NSEvent *upRef = [NSEvent otherEventWithType:NSSystemDefined
location: NSMakePoint(0, 0) modifierFlags:0xa00 location:NSMakePoint(0, 0)
timestamp:0 windowNumber:0 context:0 subtype:8 modifierFlags:0xa00
timestamp:0
windowNumber:0
context:0
subtype:8
data1:(convertKeyIDToNXKeyType(id) << 16) | ((0xb) << 8) data1:(convertKeyIDToNXKeyType(id) << 16) | ((0xb) << 8)
data2:-1]; data2:-1];
CGEventRef upEvent = [upRef CGEvent]; CGEventRef upEvent = [upRef CGEvent];

View file

@ -14,15 +14,14 @@
#import "platform/OSXPasteboardPeeker.h" #import "platform/OSXPasteboardPeeker.h"
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import <CoreData/CoreData.h>
#import <Foundation/Foundation.h>
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wdeprecated-declarations"
CFStringRef CFStringRef getDraggedFileURL()
getDraggedFileURL()
{ {
NSString *pbName = NSDragPboard; NSString *pbName = NSDragPboard;
NSPasteboard *pboard = [NSPasteboard pasteboardWithName:pbName]; NSPasteboard *pboard = [NSPasteboard pasteboardWithName:pbName];

File diff suppressed because it is too large Load diff

View file

@ -26,58 +26,49 @@
// teach them about it. // teach them about it.
// //
void* void *screenSaverUtilCreatePool()
screenSaverUtilCreatePool()
{ {
return [[NSAutoreleasePool alloc] init]; return [[NSAutoreleasePool alloc] init];
} }
void void screenSaverUtilReleasePool(void *pool)
screenSaverUtilReleasePool(void* pool)
{ {
[(NSAutoreleasePool *)pool release]; [(NSAutoreleasePool *)pool release];
} }
void* void *screenSaverUtilCreateController()
screenSaverUtilCreateController()
{ {
return [[ScreenSaverController controller] retain]; return [[ScreenSaverController controller] retain];
} }
void void screenSaverUtilReleaseController(void *controller)
screenSaverUtilReleaseController(void* controller)
{ {
[(ScreenSaverController *)controller release]; [(ScreenSaverController *)controller release];
} }
void void screenSaverUtilEnable(void *controller)
screenSaverUtilEnable(void* controller)
{ {
[(ScreenSaverController *)controller setScreenSaverCanRun:YES]; [(ScreenSaverController *)controller setScreenSaverCanRun:YES];
} }
void void screenSaverUtilDisable(void *controller)
screenSaverUtilDisable(void* controller)
{ {
[(ScreenSaverController *)controller setScreenSaverCanRun:NO]; [(ScreenSaverController *)controller setScreenSaverCanRun:NO];
} }
void void screenSaverUtilActivate(void *controller)
screenSaverUtilActivate(void* controller)
{ {
[(ScreenSaverController *)controller setScreenSaverCanRun:YES]; [(ScreenSaverController *)controller setScreenSaverCanRun:YES];
[(ScreenSaverController *)controller screenSaverStartNow]; [(ScreenSaverController *)controller screenSaverStartNow];
} }
void void screenSaverUtilDeactivate(void *controller, int isEnabled)
screenSaverUtilDeactivate(void* controller, int isEnabled)
{ {
[(ScreenSaverController *)controller screenSaverStopNow]; [(ScreenSaverController *)controller screenSaverStopNow];
[(ScreenSaverController *)controller setScreenSaverCanRun:isEnabled]; [(ScreenSaverController *)controller setScreenSaverCanRun:isEnabled];
} }
int int screenSaverUtilIsActive(void *controller)
screenSaverUtilIsActive(void* controller)
{ {
return [(ScreenSaverController *)controller screenSaverIsRunning]; return [(ScreenSaverController *)controller screenSaverIsRunning];
} }