From 9dab96c5c1a410f1f93ba194bf686f5214947d73 Mon Sep 17 00:00:00 2001 From: thefiddler Date: Sun, 4 May 2014 15:23:24 +0200 Subject: [PATCH] [Mac] Disable momentum scrolling and key pop-ups We might wish to add an option to re-enable momentum scrolling, as this might be useful to some applications for a more native feel. --- Source/OpenTK/Platform/MacOS/Cocoa/Class.cs | 5 +++++ Source/OpenTK/Platform/MacOS/Cocoa/Cocoa.cs | 6 ++++++ .../Platform/MacOS/Cocoa/NSApplication.cs | 19 ++++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Source/OpenTK/Platform/MacOS/Cocoa/Class.cs b/Source/OpenTK/Platform/MacOS/Cocoa/Class.cs index 61bec8ae..6c29bdcf 100644 --- a/Source/OpenTK/Platform/MacOS/Cocoa/Class.cs +++ b/Source/OpenTK/Platform/MacOS/Cocoa/Class.cs @@ -35,6 +35,11 @@ namespace OpenTK.Platform.MacOS { static class Class { + public static readonly IntPtr NSAutoreleasePool = Get("NSAutoreleasePool"); + public static readonly IntPtr NSDictionary = Get("NSDictionary"); + public static readonly IntPtr NSNumber = Get("NSNumber"); + public static readonly IntPtr NSUserDefaults = Get("NSUserDefaults"); + [DllImport (Cocoa.LibObjC)] extern static IntPtr class_getName(IntPtr handle); diff --git a/Source/OpenTK/Platform/MacOS/Cocoa/Cocoa.cs b/Source/OpenTK/Platform/MacOS/Cocoa/Cocoa.cs index 7874d858..5acd11b7 100644 --- a/Source/OpenTK/Platform/MacOS/Cocoa/Cocoa.cs +++ b/Source/OpenTK/Platform/MacOS/Cocoa/Cocoa.cs @@ -57,9 +57,15 @@ namespace OpenTK.Platform.MacOS [DllImport(LibObjC, EntryPoint="objc_msgSend")] public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector, IntPtr intPtr1, IntPtr intPtr2, IntPtr intPtr3); + [DllImport(LibObjC, EntryPoint="objc_msgSend")] + public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector, IntPtr intPtr1, IntPtr intPtr2, IntPtr intPtr3, IntPtr intPtr4, IntPtr intPtr5); + [DllImport(LibObjC, EntryPoint="objc_msgSend")] public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector, IntPtr p1, PointF p2); + [DllImport(LibObjC, EntryPoint="objc_msgSend")] + public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector, bool p1); + [DllImport(LibObjC, EntryPoint="objc_msgSend")] public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector, SizeF p1); diff --git a/Source/OpenTK/Platform/MacOS/Cocoa/NSApplication.cs b/Source/OpenTK/Platform/MacOS/Cocoa/NSApplication.cs index cc0a34f9..16738e46 100644 --- a/Source/OpenTK/Platform/MacOS/Cocoa/NSApplication.cs +++ b/Source/OpenTK/Platform/MacOS/Cocoa/NSApplication.cs @@ -44,7 +44,7 @@ namespace OpenTK.Platform.MacOS internal static void Initialize() { // Create the NSAutoreleasePool - AutoreleasePool = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSAutoreleasePool"), Selector.Alloc), Selector.Init); + AutoreleasePool = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.NSAutoreleasePool, Selector.Alloc), Selector.Init); // Register a Quit method to be called on cmd-q IntPtr nsapp = Class.Get("NSApplication"); @@ -80,6 +80,23 @@ namespace OpenTK.Platform.MacOS // Tell cocoa we're ready to run the application (usually called by [NSApp run]). Cocoa.SendVoid(Handle, Selector.Get("finishLaunching")); + + // Disable momentum scrolling and long-press key pop-ups + IntPtr settings = Cocoa.SendIntPtr(Class.NSDictionary, Selector.Alloc); + IntPtr momentum_scrolling = Cocoa.SendIntPtr(Class.NSNumber, Selector.Get("numberWithBool:"), false); + IntPtr press_and_hold = Cocoa.SendIntPtr(Class.NSNumber, Selector.Get("numberWithBool:"), false); + + // Initialize and register the settings dictionary + settings = + Cocoa.SendIntPtr(settings, Selector.Get("initWithObjectsAndKeys:"), + momentum_scrolling, Cocoa.ToNSString("AppleMomentumScrollSupported"), + press_and_hold, Cocoa.ToNSString("ApplePressAndHoldEnabled"), + IntPtr.Zero); + Cocoa.SendVoid( + Cocoa.SendIntPtr(Class.NSUserDefaults, Selector.Get("standardUserDefaults")), + Selector.Get("registerDefaults:"), + settings); + Cocoa.SendVoid(settings, Selector.Release); } internal static event EventHandler Quit = delegate { };