Skip to content

Commit

Permalink
PR feedback: replace instance_id with 'touch' attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
dr0id committed Mar 13, 2021
1 parent 68a1f03 commit 5eb2382
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
14 changes: 7 additions & 7 deletions docs/reST/ref/event.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ specific attributes.
ACTIVEEVENT gain, state
KEYDOWN key, mod, unicode, scancode
KEYUP key, mod, unicode, scancode
MOUSEMOTION pos, rel, buttons, instance_id
MOUSEBUTTONUP pos, button, instance_id
MOUSEBUTTONDOWN pos, button, instance_id
MOUSEMOTION pos, rel, buttons, touch
MOUSEBUTTONUP pos, button, touch
MOUSEBUTTONDOWN pos, button, touch
JOYAXISMOTION joy (deprecated), instance_id, axis, value
JOYBALLMOTION joy (deprecated), instance_id, ball, rel
JOYHATMOTION joy (deprecated), instance_id, hat, value
Expand All @@ -90,8 +90,8 @@ specific attributes.

.. versionchanged:: 2.0.1 The ``unicode`` attribute was added to ``KEYUP`` event.

.. versionchanged:: 2.0.2 The ``instance_id`` attribute was added to ``MOUSEMOTION`` event: ``instance_id may be SDL_TOUCH_MOUSEID(-1), for events that were generated by a touch input device, and not a real mouse. You might want to ignore such events, if your application already handles SDL_TouchFingerEvent``, see `SDL MouseMotionEvent <https://wiki.libsdl.org/SDL_MouseMotionEvent?highlight=%29SDL_TOUCH_MOUSEID%29>`__.
.. versionchanged:: 2.0.2 The ``instance_id`` attribute was added to ``MOUSEBUTTONUP``, ``MOUSEBUTTONDOWN`` events: ``instance_id may be SDL_TOUCH_MOUSEID(-1), for events that were generated by a touch input device, and not a real mouse. You might want to ignore such events, if your application already handles SDL_TouchFingerEvent``, see `SDL MouseButtonEvent <https://wiki.libsdl.org/SDL_MouseButtonEvent?highlight=%29SDL_TOUCH_MOUSEID%29>`__.
.. versionchanged:: 2.0.2 The ``touch`` attribute was added to ``MOUSEMOTION`` event: indicates if the events were generated by a touch input device, and not a real mouse. You might want to ignore such events, if your application already handles SDL_TouchFingerEvent, see `SDL MouseMotionEvent <https://wiki.libsdl.org/SDL_MouseMotionEvent?highlight=%29SDL_TOUCH_MOUSEID%29>`__.
.. versionchanged:: 2.0.2 The ``touch`` attribute was added to ``MOUSEBUTTONUP``, ``MOUSEBUTTONDOWN`` events: indicates if the events were generated by a touch input device, and not a real mouse. You might want to ignore such events, if your application already handles SDL_TouchFingerEvent``, see `SDL MouseButtonEvent <https://wiki.libsdl.org/SDL_MouseButtonEvent?highlight=%29SDL_TOUCH_MOUSEID%29>`__.

You can also find a list of constants for keyboard keys
:ref:`here <key-constants-label>`.
Expand Down Expand Up @@ -121,14 +121,14 @@ attributes.
FINGERMOTION touch_id, finger_id, x, y, dx, dy
FINGERDOWN touch_id, finger_id, x, y, dx, dy
FINGERUP touch_id, finger_id, x, y, dx, dy
MOUSEWHEEL which, flipped, x, y, instance_id
MOUSEWHEEL which, flipped, x, y, touch
MULTIGESTURE touch_id, x, y, pinched, rotated, num_fingers
TEXTEDITING text, start, length
TEXTINPUT text

.. versionadded:: 1.9.5

.. versionadded:: 2.0.2 The ``instance_id`` attribute was added to ``MOUSEWHEEL`` event, fixed amount horizontal scroll (x, positive to the right and negative to the left).
.. versionadded:: 2.0.2 The ``touch`` attribute was added to ``MOUSEWHEEL`` event, indicates if the events were generated by a touch input device, and not a real mouse. You might want to ignore such events, if your application already handles SDL_TouchFingerEvent. Fixed amount horizontal scroll (x, positive to the right and negative to the left).

|
Expand Down
11 changes: 8 additions & 3 deletions src_c/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,6 @@ dict_from_event(SDL_Event *event)
_pg_insobj(dict, "scancode", PyInt_FromLong(event->key.keysym.scancode));
break;
case SDL_MOUSEMOTION:
_pg_insobj(dict, "instance_id", PyLong_FromLong(event->motion.which)); // The mouse instance id, or SDL_TOUCH_MOUSEID
obj = Py_BuildValue("(ii)", event->motion.x, event->motion.y);
_pg_insobj(dict, "pos", obj);
obj =
Expand All @@ -1125,13 +1124,18 @@ dict_from_event(SDL_Event *event)
SDL_BUTTON(3)) != 0));
_pg_insobj(dict, "buttons", tuple);
}
_pg_insobj(
dict, "touch",
PyBool_FromLong((event->motion.which == SDL_TOUCH_MOUSEID)));
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
_pg_insobj(dict, "instance_id", PyLong_FromLong(event->button.which)); // The mouse instance id, or SDL_TOUCH_MOUSEID
obj = Py_BuildValue("(ii)", event->button.x, event->button.y);
_pg_insobj(dict, "pos", obj);
_pg_insobj(dict, "button", PyInt_FromLong(event->button.button));
_pg_insobj(
dict, "touch",
PyBool_FromLong((event->button.which == SDL_TOUCH_MOUSEID)));
break;
case SDL_JOYAXISMOTION:
_pg_insobj(dict, "joy", _joy_map_instance(event->jaxis.which));
Expand Down Expand Up @@ -1213,7 +1217,8 @@ dict_from_event(SDL_Event *event)
#endif
_pg_insobj(dict, "y", PyInt_FromLong(event->wheel.y));
_pg_insobj(dict, "x", PyInt_FromLong(event->wheel.x));
_pg_insobj(dict, "which", PyInt_FromLong(event->wheel.which)); // The mouse instance id, or SDL_TOUCH_MOUSEID
_pg_insobj(dict, "touch", PyBool_FromLong((event->wheel.which == SDL_TOUCH_MOUSEID)));

break;
case SDL_TEXTINPUT:
/* https://wiki.libsdl.org/SDL_TextInputEvent */
Expand Down

0 comments on commit 5eb2382

Please sign in to comment.