|
34 | 34 |
|
35 | 35 | from . import _capi |
36 | 36 | from ._capi.libei import log_handler_t |
| 37 | +from ._capi.loader import LibraryNotFoundError |
37 | 38 | from ._cobject import CObject |
38 | 39 | from .ei import _next_emulating_sequence |
39 | 40 |
|
@@ -347,8 +348,9 @@ def up(self) -> Touch: |
347 | 348 | def cancel(self) -> Touch: |
348 | 349 | """End the touch as cancelled rather than logically released. |
349 | 350 |
|
350 | | - Needs version 2 or later of the ``ei_touchscreen`` interface on |
351 | | - both sides; against an older client this is a noop. |
| 351 | + Requires libei 1.4, and version 2 or later of the |
| 352 | + ``ei_touchscreen`` interface on both sides; against an older client |
| 353 | + it arrives as a plain release. |
352 | 354 | """ |
353 | 355 | _capi.libeis.touch_cancel(self) |
354 | 356 | return self |
@@ -673,9 +675,10 @@ def name(self) -> str: |
673 | 675 | def pid(self) -> int: |
674 | 676 | """The client process's pid, via ``SO_PEERCRED``. |
675 | 677 |
|
676 | | - Socket-backend contexts only -- meaningless for a context set up |
677 | | - with :meth:`Eis.create_for_fd`, where there is no peer socket to |
678 | | - ask. Raises :class:`Error` if the library reports a failure. |
| 678 | + Requires libei 1.5. Socket-backend contexts only -- meaningless |
| 679 | + for a context set up with :meth:`Eis.create_for_fd`, where there is |
| 680 | + no peer socket to ask. Raises :class:`Error` if the library reports |
| 681 | + a failure. |
679 | 682 | """ |
680 | 683 | result = _capi.libeis.backend_socket_get_client_pid(self) |
681 | 684 | if result < 0: |
@@ -907,13 +910,24 @@ def touch_up_event(self) -> TouchUpEvent: |
907 | 910 | """Touch id and cancellation flag for a TOUCH_UP event. |
908 | 911 |
|
909 | 912 | ``is_cancel`` distinguishes a cancelled touch from a logically |
910 | | - released one; it is always False against a client older than |
911 | | - ``ei_touchscreen`` version 2. |
| 913 | + released one. It is False on libei older than 1.4, and against a |
| 914 | + client older than ``ei_touchscreen`` version 2. The touch id is |
| 915 | + available everywhere. |
912 | 916 | """ |
913 | 917 | self._require("touch_up_event", EventType.TOUCH_UP) |
| 918 | + try: |
| 919 | + is_cancel = bool(_capi.libeis.event_touch_get_is_cancel(self)) |
| 920 | + except LibraryNotFoundError: |
| 921 | + # eis_event_touch_get_is_cancel() arrived in libei 1.4. |
| 922 | + # An older library has no way to express cancellation, so every |
| 923 | + # TOUCH_UP it reports really is a plain release: False is the |
| 924 | + # accurate answer, not a failure. Without this the whole |
| 925 | + # accessor would raise on a 1.0-1.3 install, taking the touch |
| 926 | + # id -- which those versions do provide -- down with it. |
| 927 | + is_cancel = False |
914 | 928 | return TouchUpEvent( |
915 | 929 | touchid=_capi.libeis.event_touch_get_id(self), |
916 | | - is_cancel=bool(_capi.libeis.event_touch_get_is_cancel(self)), |
| 930 | + is_cancel=is_cancel, |
917 | 931 | ) |
918 | 932 |
|
919 | 933 | @property |
|
0 commit comments