+#pragma mark -
+#pragma mark Mouse handling
+
+- (void)mouseDown:(NSEvent *)o_event
+{
+ @synchronized (self) {
+ if (vd) {
+ if ([o_event type] == NSLeftMouseDown && !([o_event modifierFlags] & NSControlKeyMask)) {
+ if ([o_event clickCount] <= 1)
+ vout_display_SendEventMousePressed (vd, MOUSE_BUTTON_LEFT);
+ }
+ }
+ }
+
+ [super mouseDown:o_event];
+}
+
+- (void)otherMouseDown:(NSEvent *)o_event
+{
+ @synchronized (self) {
+ if (vd)
+ vout_display_SendEventMousePressed (vd, MOUSE_BUTTON_CENTER);
+ }
+
+ [super otherMouseDown: o_event];
+}
+
+- (void)mouseUp:(NSEvent *)o_event
+{
+ @synchronized (self) {
+ if (vd) {
+ if ([o_event type] == NSLeftMouseUp)
+ vout_display_SendEventMouseReleased (vd, MOUSE_BUTTON_LEFT);
+ }
+ }
+
+ [super mouseUp: o_event];
+}
+
+- (void)otherMouseUp:(NSEvent *)o_event
+{
+ @synchronized (self) {
+ if (vd)
+ vout_display_SendEventMouseReleased (vd, MOUSE_BUTTON_CENTER);
+ }
+
+ [super otherMouseUp: o_event];
+}
+
+- (void)mouseMoved:(NSEvent *)o_event
+{
+ NSPoint ml;
+ NSRect s_rect;
+ BOOL b_inside;
+
+ /* on HiDPI displays, the point bounds don't equal the actual pixel based bounds */
+ if (OSX_LION)
+ s_rect = [self convertRectToBacking:[self bounds]];
+ else
+ s_rect = [self bounds];
+ ml = [self convertPoint: [o_event locationInWindow] fromView: nil];
+ b_inside = [self mouse: ml inRect: s_rect];
+
+ if (b_inside) {
+ @synchronized (self) {
+ if (vd) {
+ vout_display_place_t place = vd->sys->place;
+
+ if (place.width > 0 && place.height > 0) {
+ const int x = vd->source.i_x_offset +
+ (int64_t)(ml.x - place.x) * vd->source.i_visible_width / place.width;
+ const int y = vd->source.i_y_offset +
+ (int64_t)((int)s_rect.size.height - (int)ml.y - place.y) * vd->source.i_visible_height / place.height;
+
+ vout_display_SendEventMouseMoved (vd, x, y);
+ }
+ }
+ }
+ }
+
+ [super mouseMoved: o_event];
+}
+
+- (void)mouseDragged:(NSEvent *)o_event
+{
+ [self mouseMoved: o_event];
+ [super mouseDragged: o_event];
+}
+
+- (void)otherMouseDragged:(NSEvent *)o_event
+{
+ [self mouseMoved: o_event];
+ [super otherMouseDragged: o_event];
+}
+
+- (void)rightMouseDragged:(NSEvent *)o_event
+{
+ [self mouseMoved: o_event];
+ [super rightMouseDragged: o_event];
+}
+
+- (BOOL)acceptsFirstResponder
+{
+ return YES;
+}
+
+- (BOOL)mouseDownCanMoveWindow