|
@@ -515,38 +515,41 @@ void CocoaDialog(const char *title, cons
|
|
|
{
|
|
|
NSPoint pt = e.locationInWindow;
|
|
|
if ([ e window ] == nil) pt = [ self.window convertRectFromScreen:NSMakeRect(pt.x, pt.y, 0, 0) ].origin;
|
|
|
pt = [ self convertPoint:pt fromView:nil ];
|
|
|
|
|
|
pt.y = self.bounds.size.height - pt.y;
|
|
|
|
|
|
return pt;
|
|
|
}
|
|
|
|
|
|
- (void)internalMouseMoveEvent:(NSEvent *)event
|
|
|
{
|
|
|
if (_cursor.fix_at) {
|
|
|
_cursor.UpdateCursorPositionRelative(event.deltaX, event.deltaY);
|
|
|
} else {
|
|
|
NSPoint pt = [ self mousePositionFromEvent:event ];
|
|
|
_cursor.UpdateCursorPosition(pt.x, pt.y, false);
|
|
|
}
|
|
|
|
|
|
if (_cursor.UpdateCursorPosition(pt.x, pt.y, false) && [ NSApp isActive ]) {
|
|
|
/* Warping cursor when in foreground */
|
|
|
NSPoint warp = [ self convertPoint:NSMakePoint(_cursor.pos.x, self.bounds.size.height - _cursor.pos.y) toView:nil ];
|
|
|
warp = [ self.window convertRectToScreen:NSMakeRect(warp.x, warp.y, 0, 0) ].origin;
|
|
|
warp.y = NSScreen.screens[0].frame.size.height - warp.y;
|
|
|
HandleMouseEvents();
|
|
|
}
|
|
|
|
|
|
/* Do the actual warp */
|
|
|
CGWarpMouseCursorPosition(NSPointToCGPoint(warp));
|
|
|
/* this is the magic call that fixes cursor "freezing" after warp */
|
|
|
CGAssociateMouseAndMouseCursorPosition(true);
|
|
|
}
|
|
|
- (void)internalMouseButtonEvent
|
|
|
{
|
|
|
bool cur_fix = _cursor.fix_at;
|
|
|
HandleMouseEvents();
|
|
|
|
|
|
/* Cursor fix mode was changed, synchronize with OS. */
|
|
|
if (cur_fix != _cursor.fix_at) CGAssociateMouseAndMouseCursorPosition(!_cursor.fix_at);
|
|
|
}
|
|
|
|
|
|
- (BOOL)emulateRightButton:(NSEvent *)event
|
|
|
{
|
|
|
uint32 keymask = 0;
|
|
|
if (_settings_client.gui.right_mouse_btn_emulation == RMBE_COMMAND) keymask |= NSCommandKeyMask;
|
|
|
if (_settings_client.gui.right_mouse_btn_emulation == RMBE_CONTROL) keymask |= NSControlKeyMask;
|
|
|
|
|
|
return (event.modifierFlags & keymask) != 0;
|
|
|
}
|
|
|
|
|
|
- (void)mouseMoved:(NSEvent *)event
|
|
@@ -555,52 +558,52 @@ void CocoaDialog(const char *title, cons
|
|
|
}
|
|
|
|
|
|
- (void)mouseDragged:(NSEvent *)event
|
|
|
{
|
|
|
[ self internalMouseMoveEvent:event ];
|
|
|
}
|
|
|
- (void)mouseDown:(NSEvent *)event
|
|
|
{
|
|
|
if ([ self emulateRightButton:event ]) {
|
|
|
[ self rightMouseDown:event ];
|
|
|
} else {
|
|
|
_left_button_down = true;
|
|
|
[ self internalMouseMoveEvent:event ];
|
|
|
[ self internalMouseButtonEvent ];
|
|
|
}
|
|
|
}
|
|
|
- (void)mouseUp:(NSEvent *)event
|
|
|
{
|
|
|
if ([ self emulateRightButton:event ]) {
|
|
|
[ self rightMouseUp:event ];
|
|
|
} else {
|
|
|
_left_button_down = false;
|
|
|
_left_button_clicked = false;
|
|
|
[ self internalMouseMoveEvent:event ];
|
|
|
[ self internalMouseButtonEvent ];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- (void)rightMouseDragged:(NSEvent *)event
|
|
|
{
|
|
|
[ self internalMouseMoveEvent:event ];
|
|
|
}
|
|
|
- (void)rightMouseDown:(NSEvent *)event
|
|
|
{
|
|
|
_right_button_down = true;
|
|
|
_right_button_clicked = true;
|
|
|
[ self internalMouseMoveEvent:event ];
|
|
|
[ self internalMouseButtonEvent ];
|
|
|
}
|
|
|
- (void)rightMouseUp:(NSEvent *)event
|
|
|
{
|
|
|
_right_button_down = false;
|
|
|
[ self internalMouseMoveEvent:event ];
|
|
|
[ self internalMouseButtonEvent ];
|
|
|
}
|
|
|
|
|
|
- (void)scrollWheel:(NSEvent *)event
|
|
|
{
|
|
|
if ([ event deltaY ] > 0.0) { /* Scroll up */
|
|
|
_cursor.wheel--;
|
|
|
} else if ([ event deltaY ] < 0.0) { /* Scroll down */
|
|
|
_cursor.wheel++;
|
|
|
} /* else: deltaY was 0.0 and we don't want to do anything */
|
|
|
|
|
|
/* Update the scroll count for 2D scrolling */
|
|
|
CGFloat deltaX;
|