Browse Source

Mac SDL tweaks for input and drag and drop support

Josh Engebretson 9 years ago
parent
commit
490a7b34b9

+ 48 - 1
Source/ThirdParty/SDL/src/video/cocoa/SDL_cocoaevents.m

@@ -37,6 +37,10 @@
 
 
 - (void)terminate:(id)sender;
 - (void)terminate:(id)sender;
 
 
+// ATOMIC BEGIN
+- (void)sendEvent:(NSEvent *)theEvent;
+// ATOMIC END
+
 @end
 @end
 
 
 @implementation SDLApplication
 @implementation SDLApplication
@@ -47,6 +51,41 @@
     SDL_SendQuit();
     SDL_SendQuit();
 }
 }
 
 
+// ATOMIC: Fixes missing WebView keystrokes on OSX
+// (see https://bugzilla.libsdl.org/show_bug.cgi?id=3107)
+// Dispatch events here so that we can handle events caught by
+// nextEventMatchingMask in SDL, as well as events caught by other
+// processes (such as CEF) that are passed down to NSApp.
+- (void)sendEvent:(NSEvent *)theEvent
+{
+    SDL_VideoDevice *_this = SDL_GetVideoDevice();
+
+    switch ([theEvent type]) {
+        case NSLeftMouseDown:
+        case NSOtherMouseDown:
+        case NSRightMouseDown:
+        case NSLeftMouseUp:
+        case NSOtherMouseUp:
+        case NSRightMouseUp:
+        case NSLeftMouseDragged:
+        case NSRightMouseDragged:
+        case NSOtherMouseDragged: /* usually middle mouse dragged */
+        case NSMouseMoved:
+        case NSScrollWheel:
+            Cocoa_HandleMouseEvent(_this, theEvent);
+            break;
+        case NSKeyDown:
+        case NSKeyUp:
+        case NSFlagsChanged:
+            Cocoa_HandleKeyEvent(_this, theEvent);
+            break;
+        default:
+            break;
+    }
+
+    [super sendEvent:theEvent];
+}
+
 @end // SDLApplication
 @end // SDLApplication
 
 
 /* setAppleMenu disappeared from the headers in 10.4 */
 /* setAppleMenu disappeared from the headers in 10.4 */
@@ -381,6 +420,11 @@ Cocoa_PumpEvents(_THIS)
             break;
             break;
         }
         }
 
 
+// ATOMIC BEGIN
+
+// See note in sendEvent above
+
+/*
         switch ([event type]) {
         switch ([event type]) {
         case NSLeftMouseDown:
         case NSLeftMouseDown:
         case NSOtherMouseDown:
         case NSOtherMouseDown:
@@ -390,7 +434,7 @@ Cocoa_PumpEvents(_THIS)
         case NSRightMouseUp:
         case NSRightMouseUp:
         case NSLeftMouseDragged:
         case NSLeftMouseDragged:
         case NSRightMouseDragged:
         case NSRightMouseDragged:
-        case NSOtherMouseDragged: /* usually middle mouse dragged */
+        case NSOtherMouseDragged:
         case NSMouseMoved:
         case NSMouseMoved:
         case NSScrollWheel:
         case NSScrollWheel:
             Cocoa_HandleMouseEvent(_this, event);
             Cocoa_HandleMouseEvent(_this, event);
@@ -403,6 +447,9 @@ Cocoa_PumpEvents(_THIS)
         default:
         default:
             break;
             break;
         }
         }
+*/
+
+// ATOMIC END
         /* Pass through to NSApp to make sure everything stays in sync */
         /* Pass through to NSApp to make sure everything stays in sync */
         [NSApp sendEvent:event];
         [NSApp sendEvent:event];
     }
     }

+ 34 - 1
Source/ThirdParty/SDL/src/video/cocoa/SDL_cocoawindow.m

@@ -63,10 +63,22 @@
 - (void)sendEvent:(NSEvent *)event;
 - (void)sendEvent:(NSEvent *)event;
 - (void)doCommandBySelector:(SEL)aSelector;
 - (void)doCommandBySelector:(SEL)aSelector;
 
 
+// ATOMIC BEGIN
+
+// disable drag and drop as interferes with Atomic Editor
+// TODO: a more graceful way of handling this
+
+#ifdef ATOMIC_DISABLED
+
 /* Handle drag-and-drop of files onto the SDL window. */
 /* Handle drag-and-drop of files onto the SDL window. */
 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
 - (BOOL)wantsPeriodicDraggingUpdates;
 - (BOOL)wantsPeriodicDraggingUpdates;
+
+// ATOMIC END
+
+#endif
+
 @end
 @end
 
 
 @implementation SDLWindow
 @implementation SDLWindow
@@ -107,6 +119,13 @@
     /*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
     /*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
 }
 }
 
 
+// ATOMIC BEGIN
+
+// disable drag and drop as interferes with Atomic Editor
+// TODO: a more graceful way of handling this
+
+#ifdef ATOMIC_DISABLED
+
 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
 {
 {
     if (([sender draggingSourceOperationMask] & NSDragOperationGeneric) == NSDragOperationGeneric) {
     if (([sender draggingSourceOperationMask] & NSDragOperationGeneric) == NSDragOperationGeneric) {
@@ -173,9 +192,16 @@
     return NO;
     return NO;
 }
 }
 
 
+
+#endif
+
+// ATOMIC END
+
 @end
 @end
 
 
 
 
+
+
 static Uint32 s_moveHack;
 static Uint32 s_moveHack;
 
 
 static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r)
 static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r)
@@ -1271,8 +1297,15 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
     [nswindow setContentView: contentView];
     [nswindow setContentView: contentView];
     [contentView release];
     [contentView release];
 
 
+// ATOMIC BEGIN
+
+    // disable drag and drop as interferes with Atomic Editor
+    // TODO: a more graceful way of handling this
+
     /* Allow files and folders to be dragged onto the window by users */
     /* Allow files and folders to be dragged onto the window by users */
-    [nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
+    // [nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
+
+// ATOMIC END
 
 
     if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
     if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
         [nswindow release];
         [nswindow release];