Skip to content

Commit 15397f1

Browse files
thomashvmwdtor
authored andcommitted
Input: joydev - don't classify the vmmouse as a joystick
Joydev is currently thinking some absolute mice are joystick, and that messes up games in VMware guests, as the cursor typically gets stuck in the top left corner. Try to detect the event signature of a VMmouse input device and back off for such devices. We're still incorrectly detecting, for example, the VMware absolute USB mouse as a joystick, but adding an event signature matching also that device would be considerably more risky, so defer that to a later merge window. Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 412dbad commit 15397f1

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

‎drivers/input/joydev.c‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,63 @@ static void joydev_cleanup(struct joydev *joydev)
747747
input_close_device(handle);
748748
}
749749

750+
static bool joydev_dev_is_absolute_mouse(struct input_dev *dev)
751+
{
752+
DECLARE_BITMAP(jd_scratch, KEY_CNT);
753+
754+
BUILD_BUG_ON(ABS_CNT > KEY_CNT || EV_CNT > KEY_CNT);
755+
756+
/*
757+
* Virtualization (VMware, etc) and remote management (HP
758+
* ILO2) solutions use absolute coordinates for their virtual
759+
* pointing devices so that there is one-to-one relationship
760+
* between pointer position on the host screen and virtual
761+
* guest screen, and so their mice use ABS_X, ABS_Y and 3
762+
* primary button events. This clashes with what joydev
763+
* considers to be joysticks (a device with at minimum ABS_X
764+
* axis).
765+
*
766+
* Here we are trying to separate absolute mice from
767+
* joysticks. A device is, for joystick detection purposes,
768+
* considered to be an absolute mouse if the following is
769+
* true:
770+
*
771+
* 1) Event types are exactly EV_ABS, EV_KEY and EV_SYN.
772+
* 2) Absolute events are exactly ABS_X and ABS_Y.
773+
* 3) Keys are exactly BTN_LEFT, BTN_RIGHT and BTN_MIDDLE.
774+
* 4) Device is not on "Amiga" bus.
775+
*/
776+
777+
bitmap_zero(jd_scratch, EV_CNT);
778+
__set_bit(EV_ABS, jd_scratch);
779+
__set_bit(EV_KEY, jd_scratch);
780+
__set_bit(EV_SYN, jd_scratch);
781+
if (!bitmap_equal(jd_scratch, dev->evbit, EV_CNT))
782+
return false;
783+
784+
bitmap_zero(jd_scratch, ABS_CNT);
785+
__set_bit(ABS_X, jd_scratch);
786+
__set_bit(ABS_Y, jd_scratch);
787+
if (!bitmap_equal(dev->absbit, jd_scratch, ABS_CNT))
788+
return false;
789+
790+
bitmap_zero(jd_scratch, KEY_CNT);
791+
__set_bit(BTN_LEFT, jd_scratch);
792+
__set_bit(BTN_RIGHT, jd_scratch);
793+
__set_bit(BTN_MIDDLE, jd_scratch);
794+
795+
if (!bitmap_equal(dev->keybit, jd_scratch, KEY_CNT))
796+
return false;
797+
798+
/*
799+
* Amiga joystick (amijoy) historically uses left/middle/right
800+
* button events.
801+
*/
802+
if (dev->id.bustype == BUS_AMIGA)
803+
return false;
804+
805+
return true;
806+
}
750807

751808
static bool joydev_match(struct input_handler *handler, struct input_dev *dev)
752809
{
@@ -758,6 +815,10 @@ static bool joydev_match(struct input_handler *handler, struct input_dev *dev)
758815
if (test_bit(EV_KEY, dev->evbit) && test_bit(BTN_DIGI, dev->keybit))
759816
return false;
760817

818+
/* Avoid absolute mice */
819+
if (joydev_dev_is_absolute_mouse(dev))
820+
return false;
821+
761822
return true;
762823
}
763824

0 commit comments

Comments
 (0)