Skip to content

Commit

Permalink
[macos][nativewindowing] Factor mouse button events into a common Sen…
Browse files Browse the repository at this point in the history
…dXBMCMouseButtonEvent
  • Loading branch information
enen92 committed Aug 24, 2023
1 parent 1fa0709 commit 10af763
Showing 1 changed file with 56 additions and 72 deletions.
128 changes: 56 additions & 72 deletions xbmc/windowing/osx/WinEventsOSXImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -202,86 +202,50 @@ - (NSEvent*)InputEventHandler:(NSEvent*)nsEvent
// handle mouse events and transform them into the xbmc event world
case NSEventTypeLeftMouseUp:
{
auto location = [self TranslateMouseLocation:nsEvent];
if (location.has_value())
{
NSPoint locationCoordinates = location.value();
newEvent.type = XBMC_MOUSEBUTTONUP;
newEvent.button.button = XBMC_BUTTON_LEFT;
newEvent.button.x = locationCoordinates.x;
newEvent.button.y = locationCoordinates.y;
[self MessagePush:&newEvent];
}
[self SendXBMCMouseButtonEvent:nsEvent
xbmcEvent:newEvent
mouseEventType:XBMC_MOUSEBUTTONUP
buttonCode:XBMC_BUTTON_LEFT];
break;
}
case NSEventTypeLeftMouseDown:
{
auto location = [self TranslateMouseLocation:nsEvent];
if (location.has_value())
{
NSPoint locationCoordinates = location.value();
newEvent.type = XBMC_MOUSEBUTTONDOWN;
newEvent.button.button = XBMC_BUTTON_LEFT;
newEvent.button.x = locationCoordinates.x;
newEvent.button.y = locationCoordinates.y;
[self MessagePush:&newEvent];
}
[self SendXBMCMouseButtonEvent:nsEvent
xbmcEvent:newEvent
mouseEventType:XBMC_MOUSEBUTTONDOWN
buttonCode:XBMC_BUTTON_LEFT];
break;
}
case NSEventTypeRightMouseUp:
{
auto location = [self TranslateMouseLocation:nsEvent];
if (location.has_value())
{
NSPoint locationCoordinates = location.value();
newEvent.type = XBMC_MOUSEBUTTONUP;
newEvent.button.button = XBMC_BUTTON_RIGHT;
newEvent.button.x = locationCoordinates.x;
newEvent.button.y = locationCoordinates.y;
[self MessagePush:&newEvent];
}
[self SendXBMCMouseButtonEvent:nsEvent
xbmcEvent:newEvent
mouseEventType:XBMC_MOUSEBUTTONUP
buttonCode:XBMC_BUTTON_RIGHT];
break;
}
case NSEventTypeRightMouseDown:
{
auto location = [self TranslateMouseLocation:nsEvent];
if (location.has_value())
{
NSPoint locationCoordinates = location.value();
newEvent.type = XBMC_MOUSEBUTTONDOWN;
newEvent.button.button = XBMC_BUTTON_RIGHT;
newEvent.button.x = locationCoordinates.x;
newEvent.button.y = locationCoordinates.y;
[self MessagePush:&newEvent];
}
[self SendXBMCMouseButtonEvent:nsEvent
xbmcEvent:newEvent
mouseEventType:XBMC_MOUSEBUTTONDOWN
buttonCode:XBMC_BUTTON_RIGHT];
break;
}
case NSEventTypeOtherMouseUp:
{
auto location = [self TranslateMouseLocation:nsEvent];
if (location.has_value())
{
NSPoint locationCoordinates = location.value();
newEvent.type = XBMC_MOUSEBUTTONUP;
newEvent.button.button = XBMC_BUTTON_MIDDLE;
newEvent.button.x = locationCoordinates.x;
newEvent.button.y = locationCoordinates.y;
[self MessagePush:&newEvent];
}
[self SendXBMCMouseButtonEvent:nsEvent
xbmcEvent:newEvent
mouseEventType:XBMC_MOUSEBUTTONUP
buttonCode:XBMC_BUTTON_MIDDLE];
break;
}
case NSEventTypeOtherMouseDown:
{
auto location = [self TranslateMouseLocation:nsEvent];
if (location.has_value())
{
NSPoint locationCoordinates = location.value();
newEvent.type = XBMC_MOUSEBUTTONDOWN;
newEvent.button.button = XBMC_BUTTON_MIDDLE;
newEvent.button.x = locationCoordinates.x;
newEvent.button.y = locationCoordinates.y;
[self MessagePush:&newEvent];
}
[self SendXBMCMouseButtonEvent:nsEvent
xbmcEvent:newEvent
mouseEventType:XBMC_MOUSEBUTTONDOWN
buttonCode:XBMC_BUTTON_MIDDLE];
break;
}
case NSEventTypeMouseMoved:
Expand All @@ -306,19 +270,17 @@ - (NSEvent*)InputEventHandler:(NSEvent*)nsEvent
// with a zero deltaY. This reverses our scroll which is WTF? anoying. Trap them out here.
if (nsEvent.deltaY != 0.0)
{
auto location = [self TranslateMouseLocation:nsEvent];
if (location.has_value())
auto button = nsEvent.scrollingDeltaY > 0 ? XBMC_BUTTON_WHEELUP : XBMC_BUTTON_WHEELDOWN;
if ([self SendXBMCMouseButtonEvent:nsEvent
xbmcEvent:newEvent
mouseEventType:XBMC_MOUSEBUTTONDOWN
buttonCode:button])
{
NSPoint locationCoordinates = location.value();
newEvent.type = XBMC_MOUSEBUTTONDOWN;
newEvent.button.x = locationCoordinates.x;
newEvent.button.y = locationCoordinates.y;
newEvent.button.button =
nsEvent.scrollingDeltaY > 0 ? XBMC_BUTTON_WHEELUP : XBMC_BUTTON_WHEELDOWN;
[self MessagePush:&newEvent];

newEvent.type = XBMC_MOUSEBUTTONUP;
[self MessagePush:&newEvent];
// scrollwhell need a subsquent button press with no button code
[self SendXBMCMouseButtonEvent:nsEvent
xbmcEvent:newEvent
mouseEventType:XBMC_MOUSEBUTTONUP
buttonCode:std::nullopt];
}
}
break;
Expand Down Expand Up @@ -389,6 +351,28 @@ - (XBMC_Event)keyPressEvent:(NSEvent*)nsEvent
return newEvent;
}

- (BOOL)SendXBMCMouseButtonEvent:(NSEvent*)nsEvent
xbmcEvent:(XBMC_Event&)xbmcEvent
mouseEventType:(uint8_t)mouseEventType
buttonCode:(std::optional<uint8_t>)buttonCode
{
auto location = [self TranslateMouseLocation:nsEvent];
if (location.has_value())
{
NSPoint locationCoordinates = location.value();
xbmcEvent.type = mouseEventType;
if (buttonCode.has_value())
{
xbmcEvent.button.button = buttonCode.value();
}
xbmcEvent.button.x = locationCoordinates.x;
xbmcEvent.button.y = locationCoordinates.y;
[self MessagePush:&xbmcEvent];
return true;
}
return false;
}

- (std::optional<NSPoint>)TranslateMouseLocation:(NSEvent*)nsEvent
{
NSPoint location = nsEvent.locationInWindow;
Expand Down

0 comments on commit 10af763

Please sign in to comment.