diff options
| author | 2021-11-10 00:54:13 -0500 | |
|---|---|---|
| committer | 2021-11-10 00:54:13 -0500 | |
| commit | beb08eb751fa8e1f72042f263316ab5e5ddb596d (patch) | |
| tree | 3b00df983527648bdae610ac7b88cb639b1f1828 /src/lib/platform/OSXDragSimulator.mm | |
| parent | fbc30002ab3438356c0476e70c4577a0310d52c0 (diff) | |
New upstream version 2.4.0+dfsg.upstream/2.4.0+dfsgupstream
Diffstat (limited to 'src/lib/platform/OSXDragSimulator.mm')
| -rw-r--r-- | src/lib/platform/OSXDragSimulator.mm | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/src/lib/platform/OSXDragSimulator.mm b/src/lib/platform/OSXDragSimulator.mm new file mode 100644 index 0000000..735aa4a --- /dev/null +++ b/src/lib/platform/OSXDragSimulator.mm @@ -0,0 +1,102 @@ +/* + * barrier -- mouse and keyboard sharing utility + * Copyright (C) 2013-2016 Symless Ltd. + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#import "platform/OSXDragSimulator.h" + +#import "platform/OSXDragView.h" + +#import <Foundation/Foundation.h> +#import <CoreData/CoreData.h> +#import <Cocoa/Cocoa.h> + +#if defined(MAC_OS_X_VERSION_10_7) + +NSWindow* g_dragWindow = NULL; +OSXDragView* g_dragView = NULL; +NSString* g_ext = NULL; + +void +runCocoaApp() +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + [NSApplication sharedApplication]; + + NSWindow* window = [[NSWindow alloc] + initWithContentRect: NSMakeRect(0, 0, 3, 3) + styleMask: NSBorderlessWindowMask + backing: NSBackingStoreBuffered + defer: NO]; + [window setTitle: @""]; + [window setAlphaValue:0.1]; + [window makeKeyAndOrderFront:nil]; + + OSXDragView* dragView = [[OSXDragView alloc] initWithFrame:NSMakeRect(0, 0, 3, 3)]; + + g_dragWindow = window; + g_dragView = dragView; + [window setContentView: dragView]; + + NSLog(@"starting cocoa loop"); + [NSApp run]; + + NSLog(@"cocoa: release"); + [pool release]; +} + +void +stopCocoaLoop() +{ + [NSApp stop: g_dragWindow]; +} + +void +fakeDragging(const char* str, int cursorX, int cursorY) +{ + g_ext = [NSString stringWithUTF8String:str]; + + dispatch_async(dispatch_get_main_queue(), ^{ + NSRect screen = [[NSScreen mainScreen] frame]; + NSLog ( @"screen size: width = %f height = %f", screen.size.width, screen.size.height); + NSLog ( @"mouseLocation: %d %d", cursorX, cursorY); + + int newPosX = 0; + int newPosY = 0; + newPosX = cursorX - 1; + newPosY = screen.size.height - cursorY - 1; + + NSRect rect = NSMakeRect(newPosX, newPosY, 3, 3); + NSLog ( @"newPosX: %d", newPosX); + NSLog ( @"newPosY: %d", newPosY); + + [g_dragWindow setFrame:rect display:NO]; + [g_dragWindow makeKeyAndOrderFront:nil]; + [NSApp activateIgnoringOtherApps:YES]; + + [g_dragView setFileExt:g_ext]; + + CGEventRef down = CGEventCreateMouseEvent(CGEventSourceCreate(kCGEventSourceStateHIDSystemState), kCGEventLeftMouseDown, CGPointMake(cursorX, cursorY), kCGMouseButtonLeft); + CGEventPost(kCGHIDEventTap, down); + }); +} + +CFStringRef +getCocoaDropTarget() +{ + // HACK: sleep, wait for cocoa drop target updated first + usleep(1000000); + return [g_dragView getDropTarget]; +} + +#endif |
