mirror of
https://github.com/debauchee/barrier.git
synced 2024-11-23 09:43:24 +03:00
used really drag file extension
This commit is contained in:
parent
de65f71312
commit
7b8cdb6b38
@ -26,7 +26,7 @@ extern "C" {
|
||||
#endif
|
||||
void runCocoaApp();
|
||||
void stopCocoaLoop();
|
||||
void fakeDragging(const char* str, int length, int cursorX, int cursorY);
|
||||
void fakeDragging(const char* str, int cursorX, int cursorY);
|
||||
CFStringRef getCocoaDropTarget();
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
NSWindow* g_dragWindow = NULL;
|
||||
COSXDragView* g_dragView = NULL;
|
||||
NSString* g_ext = NULL;
|
||||
|
||||
void
|
||||
runCocoaApp()
|
||||
@ -61,8 +62,10 @@ stopCocoaLoop()
|
||||
}
|
||||
|
||||
void
|
||||
fakeDragging(const char* str, int length, int cursorX, int cursorY)
|
||||
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: witdh = %f height = %f", screen.size.width, screen.size.height);
|
||||
@ -80,7 +83,9 @@ fakeDragging(const char* str, int length, int cursorX, int cursorY)
|
||||
[g_dragWindow setFrame:rect display:NO];
|
||||
|
||||
[g_dragWindow makeKeyAndOrderFront:nil];
|
||||
|
||||
|
||||
[g_dragView setFileExt:g_ext];
|
||||
|
||||
CGEventRef down = CGEventCreateMouseEvent(CGEventSourceCreate(kCGEventSourceStateHIDSystemState), kCGEventLeftMouseDown, CGPointMake(cursorX, cursorY), kCGMouseButtonLeft);
|
||||
CGEventPost(kCGHIDEventTap, down);
|
||||
});
|
||||
|
@ -22,10 +22,12 @@
|
||||
@interface COSXDragView : NSView<NSDraggingSource,NSDraggingInfo>
|
||||
{
|
||||
NSMutableString* m_dropTarget;
|
||||
NSString* m_dragFileExt;
|
||||
}
|
||||
|
||||
- (CFStringRef)getDropTarget;
|
||||
- (void)clearDropTarget;
|
||||
- (void)setFileExt:(NSString*) ext;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -30,6 +30,7 @@ initWithFrame:(NSRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
m_dropTarget = [[NSMutableString alloc] initWithCapacity:0];
|
||||
m_dragFileExt = [[NSMutableString alloc] initWithCapacity:0];
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -57,7 +58,7 @@ mouseDown:(NSEvent *)theEvent
|
||||
dragPosition.y -= 16;
|
||||
imageLocation.origin = dragPosition;
|
||||
imageLocation.size = NSMakeSize(32,32);
|
||||
[self dragPromisedFilesOfTypes:[NSArray arrayWithObject:@"zip"]
|
||||
[self dragPromisedFilesOfTypes:[NSArray arrayWithObject:m_dragFileExt]
|
||||
fromRect:imageLocation
|
||||
source:self
|
||||
slideBack:NO
|
||||
@ -94,6 +95,13 @@ clearDropTarget
|
||||
[m_dropTarget setString:@""];
|
||||
}
|
||||
|
||||
- (void)
|
||||
setFileExt:(NSString*) ext
|
||||
{
|
||||
m_dragFileExt = [NSString stringWithString:ext];
|
||||
NSLog(@"drag file ext: %@", m_dragFileExt);
|
||||
}
|
||||
|
||||
- (NSWindow *)
|
||||
draggingDestinationWindow
|
||||
{
|
||||
|
@ -2080,7 +2080,7 @@ COSXScreen::fakeDraggingFiles(CString str)
|
||||
m_fakeDraggingStarted = true;
|
||||
#if defined(MAC_OS_X_VERSION_10_7)
|
||||
// TODO: use real file extension
|
||||
fakeDragging("txt", 3, m_xCursor, m_yCursor);
|
||||
fakeDragging(str.c_str(), m_xCursor, m_yCursor);
|
||||
#else
|
||||
LOG((CLOG_WARN "drag drop not supported"));
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user