diff --git a/lib/logitech_receiver/hidpp20.py b/lib/logitech_receiver/hidpp20.py index a4a01c65..b2fa67dd 100644 --- a/lib/logitech_receiver/hidpp20.py +++ b/lib/logitech_receiver/hidpp20.py @@ -44,10 +44,10 @@ from .common import FirmwareKind from .common import NamedInt from .hidpp20_constants import CHARGE_STATUS from .hidpp20_constants import DEVICE_KIND -from .hidpp20_constants import GESTURE from .hidpp20_constants import ChargeLevel from .hidpp20_constants import ChargeType from .hidpp20_constants import ErrorCode +from .hidpp20_constants import GestureId from .hidpp20_constants import ParamId from .hidpp20_constants import SupportedFeature @@ -676,7 +676,7 @@ class Gesture: def __init__(self, device, low, high, next_index, next_diversion_index): self._device = device self.id = low - self.gesture = GESTURE[low] + self.gesture = GestureId(low) self.can_be_enabled = high & 0x01 self.can_be_diverted = high & 0x02 self.show_in_ui = high & 0x04 diff --git a/lib/logitech_receiver/hidpp20_constants.py b/lib/logitech_receiver/hidpp20_constants.py index 2e962bca..9071dfb8 100644 --- a/lib/logitech_receiver/hidpp20_constants.py +++ b/lib/logitech_receiver/hidpp20_constants.py @@ -213,70 +213,70 @@ class ErrorCode(IntEnum): UNSUPPORTED = 0x09 -# Gesture Ids for feature GESTURE_2 -GESTURE = NamedInts( - Tap1Finger=1, # task Left_Click - Tap2Finger=2, # task Right_Click - Tap3Finger=3, - Click1Finger=4, # task Left_Click - Click2Finger=5, # task Right_Click - Click3Finger=6, - DoubleTap1Finger=10, - DoubleTap2Finger=11, - DoubleTap3Finger=12, - Track1Finger=20, # action MovePointer - TrackingAcceleration=21, - TapDrag1Finger=30, # action Drag - TapDrag2Finger=31, # action SecondaryDrag - Drag3Finger=32, - TapGestures=33, # group all tap gestures under a single UI setting - FnClickGestureSuppression=34, # suppresses Tap and Edge gestures, toggled by Fn+Click - Scroll1Finger=40, # action ScrollOrPageXY / ScrollHorizontal - Scroll2Finger=41, # action ScrollOrPageXY / ScrollHorizontal - Scroll2FingerHoriz=42, # action ScrollHorizontal - Scroll2FingerVert=43, # action WheelScrolling - Scroll2FingerStateless=44, - NaturalScrolling=45, # affects native HID wheel reporting by gestures, not when diverted - Thumbwheel=46, # action WheelScrolling - VScrollInertia=48, - VScrollBallistics=49, - Swipe2FingerHoriz=50, # action PageScreen - Swipe3FingerHoriz=51, # action PageScreen - Swipe4FingerHoriz=52, # action PageScreen - Swipe3FingerVert=53, - Swipe4FingerVert=54, - LeftEdgeSwipe1Finger=60, - RightEdgeSwipe1Finger=61, - BottomEdgeSwipe1Finger=62, - TopEdgeSwipe1Finger=63, - LeftEdgeSwipe1Finger2=64, # task HorzScrollNoRepeatSet - RightEdgeSwipe1Finger2=65, # task 122 ?? - BottomEdgeSwipe1Finger2=66, - TopEdgeSwipe1Finger2=67, # task 121 ?? - LeftEdgeSwipe2Finger=70, - RightEdgeSwipe2Finger=71, - BottomEdgeSwipe2Finger=72, - TopEdgeSwipe2Finger=73, - Zoom2Finger=80, # action Zoom - Zoom2FingerPinch=81, # ZoomBtnInSet - Zoom2FingerSpread=82, # ZoomBtnOutSet - Zoom3Finger=83, - Zoom2FingerStateless=84, # action Zoom - TwoFingersPresent=85, - Rotate2Finger=87, - Finger1=90, - Finger2=91, - Finger3=92, - Finger4=93, - Finger5=94, - Finger6=95, - Finger7=96, - Finger8=97, - Finger9=98, - Finger10=99, - DeviceSpecificRawData=100, -) -GESTURE._fallback = lambda x: f"unknown:{x:04X}" +class GestureId(IntEnum): + """Gesture IDs for feature GESTURE_2.""" + + TAP_1_FINGER = 1 # task Left_Click + TAP_2_FINGER = 2 # task Right_Click + TAP_3_FINGER = 3 + CLICK_1_FINGER = 4 # task Left_Click + CLICK_2_FINGER = 5 # task Right_Click + CLICK_3_FINGER = 6 + DOUBLE_TAP_1_FINGER = 10 + DOUBLE_TAP_2_FINGER = 11 + DOUBLE_TAP_3_FINGER = 12 + TRACK_1_FINGER = 20 # action MovePointer + TRACKING_ACCELERATION = 21 + TAP_DRAG_1_FINGER = 30 # action Drag + TAP_DRAG_2_FINGER = 31 # action SecondaryDrag + DRAG_3_FINGER = 32 + TAP_GESTURES = 33 # group all tap gestures under a single UI setting + FN_CLICK_GESTURE_SUPPRESSION = 34 # suppresses Tap and Edge gestures, toggled by Fn+Click + SCROLL_1_FINGER = 40 # action ScrollOrPageXY / ScrollHorizontal + SCROLL_2_FINGER = 41 # action ScrollOrPageXY / ScrollHorizontal + SCROLL_2_FINGER_HORIZONTAL = 42 # action ScrollHorizontal + SCROLL_2_FINGER_VERTICAL = 43 # action WheelScrolling + SCROLL_2_FINGER_STATELESS = 44 + NATURAL_SCROLLING = 45 # affects native HID wheel reporting by gestures, not when diverted + THUMBWHEEL = (46,) # action WheelScrolling + V_SCROLL_INTERTIA = 48 + V_SCROLL_BALLISTICS = 49 + SWIPE_2_FINGER_HORIZONTAL = 50 # action PageScreen + SWIPE_3_FINGER_HORIZONTAL = 51 # action PageScreen + SWIPE_4_FINGER_HORIZONTAL = 52 # action PageScreen + SWIPE_3_FINGER_VERTICAL = 53 + SWIPE_4_FINGER_VERTICAL = 54 + LEFT_EDGE_SWIPE_1_FINGER = 60 + RIGHT_EDGE_SWIPE_1_FINGER = 61 + BOTTOM_EDGE_SWIPE_1_FINGER = 62 + TOP_EDGE_SWIPE_1_FINGER = 63 + LEFT_EDGE_SWIPE_1_FINGER_2 = 64 # task HorzScrollNoRepeatSet + RIGHT_EDGE_SWIPE_1_FINGER_2 = 65 + BOTTOM_EDGE_SWIPE_1_FINGER_2 = 66 + TOP_EDGE_SWIPE_1_FINGER_2 = 67 + LEFT_EDGE_SWIPE_2_FINGER = 70 + RIGHT_EDGE_SWIPE_2_FINGER = 71 + BottomEdgeSwipe2Finger = 72 + BOTTOM_EDGE_SWIPE_2_FINGER = 72 + TOP_EDGE_SWIPE_2_FINGER = 73 + ZOOM_2_FINGER = 80 # action Zoom + ZOOM_2_FINGER_PINCH = 81 # ZoomBtnInSet + ZOOM_2_FINGER_SPREAD = 82 # ZoomBtnOutSet + ZOOM_3_FINGER = 83 + ZOOM_2_FINGER_STATELESS = 84 + TWO_FINGERS_PRESENT = 85 + ROTATE_2_FINGER = 87 + FINGER_1 = 90 + FINGER_2 = 91 + FINGER_3 = 92 + FINGER_4 = 93 + FINGER_5 = 94 + FINGER_6 = 95 + FINGER_7 = 96 + FINGER_8 = 97 + FINGER_9 = 98 + FINGER_10 = 99 + DEVICE_SPECIFIC_RAW_DATA = 100 class ParamId(IntEnum): diff --git a/lib/logitech_receiver/settings_templates.py b/lib/logitech_receiver/settings_templates.py index 803a8ccd..ea8179d9 100644 --- a/lib/logitech_receiver/settings_templates.py +++ b/lib/logitech_receiver/settings_templates.py @@ -38,6 +38,7 @@ from . import hidpp20_constants from . import settings from . import special_keys from .hidpp10_constants import Registers +from .hidpp20_constants import GestureId from .hidpp20_constants import ParamId logger = logging.getLogger(__name__) @@ -46,8 +47,6 @@ _hidpp20 = hidpp20.Hidpp20() _DK = hidpp10_constants.DEVICE_KIND _F = hidpp20_constants.SupportedFeature -_GG = hidpp20_constants.GESTURE - class State(enum.Enum): IDLE = "idle" @@ -1227,72 +1226,72 @@ class ChangeHost(settings.Setting): _GESTURE2_GESTURES_LABELS = { - _GG["Tap1Finger"]: (_("Single tap"), _("Performs a left click.")), - _GG["Tap2Finger"]: (_("Single tap with two fingers"), _("Performs a right click.")), - _GG["Tap3Finger"]: (_("Single tap with three fingers"), None), - _GG["Click1Finger"]: (None, None), - _GG["Click2Finger"]: (None, None), - _GG["Click3Finger"]: (None, None), - _GG["DoubleTap1Finger"]: (_("Double tap"), _("Performs a double click.")), - _GG["DoubleTap2Finger"]: (_("Double tap with two fingers"), None), - _GG["DoubleTap3Finger"]: (_("Double tap with three fingers"), None), - _GG["Track1Finger"]: (None, None), - _GG["TrackingAcceleration"]: (None, None), - _GG["TapDrag1Finger"]: (_("Tap and drag"), _("Drags items by dragging the finger after double tapping.")), - _GG["TapDrag2Finger"]: ( + GestureId.TAP_1_FINGER: (_("Single tap"), _("Performs a left click.")), + GestureId.TAP_2_FINGER: (_("Single tap with two fingers"), _("Performs a right click.")), + GestureId.TAP_3_FINGER: (_("Single tap with three fingers"), None), + GestureId.CLICK_1_FINGER: (None, None), + GestureId.CLICK_2_FINGER: (None, None), + GestureId.CLICK_3_FINGER: (None, None), + GestureId.DOUBLE_TAP_1_FINGER: (_("Double tap"), _("Performs a double click.")), + GestureId.DOUBLE_TAP_2_FINGER: (_("Double tap with two fingers"), None), + GestureId.DOUBLE_TAP_3_FINGER: (_("Double tap with three fingers"), None), + GestureId.TRACK_1_FINGER: (None, None), + GestureId.TRACKING_ACCELERATION: (None, None), + GestureId.TAP_DRAG_1_FINGER: (_("Tap and drag"), _("Drags items by dragging the finger after double tapping.")), + GestureId.TAP_DRAG_2_FINGER: ( _("Tap and drag with two fingers"), _("Drags items by dragging the fingers after double tapping."), ), - _GG["Drag3Finger"]: (_("Tap and drag with three fingers"), None), - _GG["TapGestures"]: (None, None), - _GG["FnClickGestureSuppression"]: ( + GestureId.DRAG_3_FINGER: (_("Tap and drag with three fingers"), None), + GestureId.TAP_GESTURES: (None, None), + GestureId.FN_CLICK_GESTURE_SUPPRESSION: ( _("Suppress tap and edge gestures"), _("Disables tap and edge gestures (equivalent to pressing Fn+LeftClick)."), ), - _GG["Scroll1Finger"]: (_("Scroll with one finger"), _("Scrolls.")), - _GG["Scroll2Finger"]: (_("Scroll with two fingers"), _("Scrolls.")), - _GG["Scroll2FingerHoriz"]: (_("Scroll horizontally with two fingers"), _("Scrolls horizontally.")), - _GG["Scroll2FingerVert"]: (_("Scroll vertically with two fingers"), _("Scrolls vertically.")), - _GG["Scroll2FingerStateless"]: (_("Scroll with two fingers"), _("Scrolls.")), - _GG["NaturalScrolling"]: (_("Natural scrolling"), _("Inverts the scrolling direction.")), - _GG["Thumbwheel"]: (_("Thumbwheel"), _("Enables the thumbwheel.")), - _GG["VScrollInertia"]: (None, None), - _GG["VScrollBallistics"]: (None, None), - _GG["Swipe2FingerHoriz"]: (None, None), - _GG["Swipe3FingerHoriz"]: (None, None), - _GG["Swipe4FingerHoriz"]: (None, None), - _GG["Swipe3FingerVert"]: (None, None), - _GG["Swipe4FingerVert"]: (None, None), - _GG["LeftEdgeSwipe1Finger"]: (None, None), - _GG["RightEdgeSwipe1Finger"]: (None, None), - _GG["BottomEdgeSwipe1Finger"]: (None, None), - _GG["TopEdgeSwipe1Finger"]: (_("Swipe from the top edge"), None), - _GG["LeftEdgeSwipe1Finger2"]: (_("Swipe from the left edge"), None), - _GG["RightEdgeSwipe1Finger2"]: (_("Swipe from the right edge"), None), - _GG["BottomEdgeSwipe1Finger2"]: (_("Swipe from the bottom edge"), None), - _GG["TopEdgeSwipe1Finger2"]: (_("Swipe from the top edge"), None), - _GG["LeftEdgeSwipe2Finger"]: (_("Swipe two fingers from the left edge"), None), - _GG["RightEdgeSwipe2Finger"]: (_("Swipe two fingers from the right edge"), None), - _GG["BottomEdgeSwipe2Finger"]: (_("Swipe two fingers from the bottom edge"), None), - _GG["TopEdgeSwipe2Finger"]: (_("Swipe two fingers from the top edge"), None), - _GG["Zoom2Finger"]: (_("Zoom with two fingers."), _("Pinch to zoom out; spread to zoom in.")), - _GG["Zoom2FingerPinch"]: (_("Pinch to zoom out."), _("Pinch to zoom out.")), - _GG["Zoom2FingerSpread"]: (_("Spread to zoom in."), _("Spread to zoom in.")), - _GG["Zoom3Finger"]: (_("Zoom with three fingers."), None), - _GG["Zoom2FingerStateless"]: (_("Zoom with two fingers"), _("Pinch to zoom out; spread to zoom in.")), - _GG["TwoFingersPresent"]: (None, None), - _GG["Rotate2Finger"]: (None, None), - _GG["Finger1"]: (None, None), - _GG["Finger2"]: (None, None), - _GG["Finger3"]: (None, None), - _GG["Finger4"]: (None, None), - _GG["Finger5"]: (None, None), - _GG["Finger6"]: (None, None), - _GG["Finger7"]: (None, None), - _GG["Finger8"]: (None, None), - _GG["Finger9"]: (None, None), - _GG["Finger10"]: (None, None), - _GG["DeviceSpecificRawData"]: (None, None), + GestureId.SCROLL_1_FINGER: (_("Scroll with one finger"), _("Scrolls.")), + GestureId.SCROLL_2_FINGER: (_("Scroll with two fingers"), _("Scrolls.")), + GestureId.SCROLL_2_FINGER_HORIZONTAL: (_("Scroll horizontally with two fingers"), _("Scrolls horizontally.")), + GestureId.SCROLL_2_FINGER_VERTICAL: (_("Scroll vertically with two fingers"), _("Scrolls vertically.")), + GestureId.SCROLL_2_FINGER_STATELESS: (_("Scroll with two fingers"), _("Scrolls.")), + GestureId.NATURAL_SCROLLING: (_("Natural scrolling"), _("Inverts the scrolling direction.")), + GestureId.THUMBWHEEL: (_("Thumbwheel"), _("Enables the thumbwheel.")), + GestureId.V_SCROLL_INTERTIA: (None, None), + GestureId.V_SCROLL_BALLISTICS: (None, None), + GestureId.SWIPE_2_FINGER_HORIZONTAL: (None, None), + GestureId.SWIPE_3_FINGER_HORIZONTAL: (None, None), + GestureId.SWIPE_4_FINGER_HORIZONTAL: (None, None), + GestureId.SWIPE_3_FINGER_VERTICAL: (None, None), + GestureId.SWIPE_4_FINGER_VERTICAL: (None, None), + GestureId.LEFT_EDGE_SWIPE_1_FINGER: (None, None), + GestureId.RIGHT_EDGE_SWIPE_1_FINGER: (None, None), + GestureId.BOTTOM_EDGE_SWIPE_1_FINGER: (None, None), + GestureId.TOP_EDGE_SWIPE_1_FINGER: (_("Swipe from the top edge"), None), + GestureId.LEFT_EDGE_SWIPE_1_FINGER_2: (_("Swipe from the left edge"), None), + GestureId.RIGHT_EDGE_SWIPE_1_FINGER_2: (_("Swipe from the right edge"), None), + GestureId.BOTTOM_EDGE_SWIPE_1_FINGER_2: (_("Swipe from the bottom edge"), None), + GestureId.TOP_EDGE_SWIPE_1_FINGER_2: (_("Swipe from the top edge"), None), + GestureId.LEFT_EDGE_SWIPE_2_FINGER: (_("Swipe two fingers from the left edge"), None), + GestureId.RIGHT_EDGE_SWIPE_2_FINGER: (_("Swipe two fingers from the right edge"), None), + GestureId.BOTTOM_EDGE_SWIPE_2_FINGER: (_("Swipe two fingers from the bottom edge"), None), + GestureId.TOP_EDGE_SWIPE_2_FINGER: (_("Swipe two fingers from the top edge"), None), + GestureId.ZOOM_2_FINGER: (_("Zoom with two fingers."), _("Pinch to zoom out; spread to zoom in.")), + GestureId.ZOOM_2_FINGER_PINCH: (_("Pinch to zoom out."), _("Pinch to zoom out.")), + GestureId.ZOOM_2_FINGER_SPREAD: (_("Spread to zoom in."), _("Spread to zoom in.")), + GestureId.ZOOM_3_FINGER: (_("Zoom with three fingers."), None), + GestureId.ZOOM_2_FINGER_STATELESS: (_("Zoom with two fingers"), _("Pinch to zoom out; spread to zoom in.")), + GestureId.TWO_FINGERS_PRESENT: (None, None), + GestureId.ROTATE_2_FINGER: (None, None), + GestureId.FINGER_1: (None, None), + GestureId.FINGER_2: (None, None), + GestureId.FINGER_3: (None, None), + GestureId.FINGER_4: (None, None), + GestureId.FINGER_5: (None, None), + GestureId.FINGER_6: (None, None), + GestureId.FINGER_7: (None, None), + GestureId.FINGER_8: (None, None), + GestureId.FINGER_9: (None, None), + GestureId.FINGER_10: (None, None), + GestureId.DEVICE_SPECIFIC_RAW_DATA: (None, None), } _GESTURE2_PARAMS_LABELS = { @@ -1318,7 +1317,7 @@ class Gesture2Gestures(settings.BitFieldWithOffsetAndMaskSetting): feature = _F.GESTURE_2 rw_options = {"read_fnid": 0x10, "write_fnid": 0x20} validator_options = {"om_method": hidpp20.Gesture.enable_offset_mask} - choices_universe = hidpp20_constants.GESTURE + choices_universe = hidpp20_constants.GestureId _labels = _GESTURE2_GESTURES_LABELS class validator_class(settings.BitFieldWithOffsetAndMaskValidator): @@ -1335,7 +1334,7 @@ class Gesture2Divert(settings.BitFieldWithOffsetAndMaskSetting): feature = _F.GESTURE_2 rw_options = {"read_fnid": 0x30, "write_fnid": 0x40} validator_options = {"om_method": hidpp20.Gesture.diversion_offset_mask} - choices_universe = hidpp20_constants.GESTURE + choices_universe = hidpp20_constants.GestureId _labels = _GESTURE2_GESTURES_LABELS class validator_class(settings.BitFieldWithOffsetAndMaskValidator): diff --git a/tests/logitech_receiver/test_hidpp20_complex.py b/tests/logitech_receiver/test_hidpp20_complex.py index b52a1a1e..8ebcbec9 100644 --- a/tests/logitech_receiver/test_hidpp20_complex.py +++ b/tests/logitech_receiver/test_hidpp20_complex.py @@ -22,6 +22,7 @@ from logitech_receiver import exceptions from logitech_receiver import hidpp20 from logitech_receiver import hidpp20_constants from logitech_receiver import special_keys +from logitech_receiver.hidpp20_constants import GestureId from . import fake_hidpp @@ -489,11 +490,11 @@ def test_SubParam(id, length, minimum, maximum, widget, min, max, wid, string): @pytest.mark.parametrize( "device, low, high, next_index, next_diversion_index, name, cbe, si, sdi, eom, dom", [ - (device_standard, 0x01, 0x01, 5, 10, "Tap1Finger", True, 5, None, (0, 0x20), (None, None)), - (device_standard, 0x03, 0x02, 6, 11, "Tap3Finger", False, None, 11, (None, None), (1, 0x08)), + (device_standard, 0x01, 0x01, 5, 10, GestureId.TAP_1_FINGER, True, 5, None, (0, 0x20), (None, None)), + (device_standard, 0x03, 0x02, 6, 11, GestureId.TAP_3_FINGER, False, None, 11, (None, None), (1, 0x08)), ], ) -def test_Gesture(device, low, high, next_index, next_diversion_index, name, cbe, si, sdi, eom, dom): +def test_gesture(device, low, high, next_index, next_diversion_index, name, cbe, si, sdi, eom, dom): gesture = hidpp20.Gesture(device, low, high, next_index, next_diversion_index) assert gesture._device == device