diff options
author | Kiall Mac Innes <kiall@macinnes.ie> | 2019-04-05 20:36:19 +0100 |
---|---|---|
committer | Kiall Mac Innes <kiall@macinnes.ie> | 2019-04-05 20:36:19 +0100 |
commit | e57093ff65f61768225030f183dd0aa45d72a513 (patch) | |
tree | c1f0591a493fb04cf900cd27326a8b8c0b2e248c /src/osd | |
parent | 94836248644221eea9d4e6848347031de5a061d5 (diff) |
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.
Diffstat (limited to 'src/osd')
-rw-r--r-- | src/osd/modules/input/input_x11.cpp | 28 |
1 files 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<XDeviceMotionEvent *>(&xevent); + deviceid = motion->deviceid; + } + else if (xevent.type == button_press_type || xevent.type == button_release_type) + { + XDeviceButtonEvent *button = reinterpret_cast<XDeviceButtonEvent *>(&xevent); + deviceid = button->deviceid; + } + else { - downcast<x11_input_device*>(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<device_info> &ptr = device; + return downcast<x11_input_device*>(ptr.get())->x11_state.deviceid == deviceid; }); + + // If we find a matching lightgun, dispatch the event to the lightgun + if (target_device != devicelist()->end()) + { + downcast<x11_input_device*>((*target_device).get())->queue_events(&xevent, 1); + } } private: |