summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorMad Fish <MadFishTheOne@gmail.com>2013-01-20 17:15:37 +0100
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2013-01-20 23:43:21 +0100
commitc9396c0aabb6c1b710e1cdaa3fb123182dc91279 (patch)
tree6b9f7ee38451ff60f5c1fd417b50fe4adb296275 /video
parentec0bd696193093a091da42ec98708a97d3dd1dc7 (diff)
downloadmpv-c9396c0aabb6c1b710e1cdaa3fb123182dc91279.tar.bz2
mpv-c9396c0aabb6c1b710e1cdaa3fb123182dc91279.tar.xz
cocoa_common: improved trackpad scrolling
Diffstat (limited to 'video')
-rw-r--r--video/out/cocoa_common.m50
1 files changed, 45 insertions, 5 deletions
diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m
index d23a439629..217321d593 100644
--- a/video/out/cocoa_common.m
+++ b/video/out/cocoa_common.m
@@ -21,6 +21,7 @@
#import <CoreServices/CoreServices.h> // for CGDisplayHideCursor
#import <IOKit/pwr_mgt/IOPMLib.h>
#include <dlfcn.h>
+#include <libavutil/common.h>
#include "cocoa_common.h"
@@ -59,6 +60,9 @@
- (NSRect)convertRectToBacking:(NSRect)aRect;
- (void)setWantsBestResolutionOpenGLSurface:(BOOL)aBool;
@end
+@interface NSEvent (IntroducedInLion)
+- (BOOL)hasPreciseScrollingDeltas;
+@end
#endif
// add power management assertion not available on OSX versions prior to 10.7
@@ -113,6 +117,8 @@ struct vo_cocoa_state {
bool out_fs_resize;
IOPMAssertionID power_mgmt_assertion;
+
+ CGFloat accumulated_scroll;
};
static int _instances = 0;
@@ -135,15 +141,26 @@ static struct vo_cocoa_state *vo_cocoa_init_state(struct vo *vo)
.display_cursor = 1,
.cursor_autohide_delay = vo->opts->cursor_autohide_delay,
.power_mgmt_assertion = kIOPMNullAssertionID,
+ .accumulated_scroll = 0,
};
if (!vo_border) s->windowed_mask = NSBorderlessWindowMask;
return s;
}
+static bool is_lion_or_above()
+{
+ static bool result = false, checked = false;
+ if (!checked) {
+ result = is_osx_version_at_least(10, 7, 0);
+ checked = true;
+ }
+ return result;
+}
+
static bool supports_hidpi(NSView *view)
{
SEL hdpi_selector = @selector(setWantsBestResolutionOpenGLSurface:);
- return is_osx_version_at_least(10, 7, 0) && view &&
+ return is_lion_or_above() && view &&
[view respondsToSelector:hdpi_selector];
}
@@ -738,10 +755,33 @@ void create_menu()
- (void)scrollWheel:(NSEvent *)theEvent
{
- if ([theEvent deltaY] > 0)
- mplayer_put_key(_vo->key_fifo, MOUSE_BTN3);
- else
- mplayer_put_key(_vo->key_fifo, MOUSE_BTN4);
+ struct vo_cocoa_state *s = _vo->cocoa;
+
+ CGFloat delta;
+ // Use the dimention with the most delta as the scrolling one
+ if (FFABS([theEvent deltaY]) > FFABS([theEvent deltaX])) {
+ delta = [theEvent deltaY];
+ } else {
+ delta = - [theEvent deltaX];
+ }
+
+ if (is_lion_or_above() && [theEvent hasPreciseScrollingDeltas]) {
+ s->accumulated_scroll += delta;
+ static const CGFloat threshold = 10;
+ while (s->accumulated_scroll >= threshold) {
+ s->accumulated_scroll -= threshold;
+ mplayer_put_key(_vo->key_fifo, MOUSE_BTN3);
+ }
+ while (s->accumulated_scroll <= -threshold) {
+ s->accumulated_scroll += threshold;
+ mplayer_put_key(_vo->key_fifo, MOUSE_BTN4);
+ }
+ } else {
+ if (delta > 0)
+ mplayer_put_key(_vo->key_fifo, MOUSE_BTN3);
+ else
+ mplayer_put_key(_vo->key_fifo, MOUSE_BTN4);
+ }
}
- (void)mouseEvent:(NSEvent *)theEvent