From e57093ff65f61768225030f183dd0aa45d72a513 Mon Sep 17 00:00:00 2001 From: Kiall Mac Innes Date: Fri, 5 Apr 2019 20:36:19 +0100 Subject: Linux X11 Input: Fix multiple lightgun support On X11 Linux, every lightgun event was passed onto every lightgun device within MAME. This obviously works for 1 gun, but with 2, it causes both crosshairs to move in the same direction at the same time. --- src/osd/modules/input/input_x11.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/osd/modules/input/input_x11.cpp b/src/osd/modules/input/input_x11.cpp index f7c48a10d87..40df3d528b6 100644 --- a/src/osd/modules/input/input_x11.cpp +++ b/src/osd/modules/input/input_x11.cpp @@ -533,10 +533,34 @@ public: void handle_event(XEvent &xevent) override { - devicelist()->for_each_device([&xevent](auto device) + XID deviceid; + if (xevent.type == motion_type) + { + XDeviceMotionEvent *motion = reinterpret_cast(&xevent); + deviceid = motion->deviceid; + } + else if (xevent.type == button_press_type || xevent.type == button_release_type) + { + XDeviceButtonEvent *button = reinterpret_cast(&xevent); + deviceid = button->deviceid; + } + else { - downcast(device)->queue_events(&xevent, 1); + return; + } + + // Figure out which lightgun this event id destined for + auto target_device = std::find_if(devicelist()->begin(), devicelist()->end(), [deviceid](auto &device) + { + std::unique_ptr &ptr = device; + return downcast(ptr.get())->x11_state.deviceid == deviceid; }); + + // If we find a matching lightgun, dispatch the event to the lightgun + if (target_device != devicelist()->end()) + { + downcast((*target_device).get())->queue_events(&xevent, 1); + } } private: -- cgit v1.2.3