hidpp20_constants: Refactor Gesture into enum

Replace Gesture NamedInts with enum.

Related #2273
This commit is contained in:
MattHag 2024-10-27 21:48:46 +01:00 committed by Peter F. Patel-Schneider
parent a19461b29d
commit 862cef1f77
4 changed files with 133 additions and 133 deletions

View File

@ -44,10 +44,10 @@ from .common import FirmwareKind
from .common import NamedInt from .common import NamedInt
from .hidpp20_constants import CHARGE_STATUS from .hidpp20_constants import CHARGE_STATUS
from .hidpp20_constants import DEVICE_KIND from .hidpp20_constants import DEVICE_KIND
from .hidpp20_constants import GESTURE
from .hidpp20_constants import ChargeLevel from .hidpp20_constants import ChargeLevel
from .hidpp20_constants import ChargeType from .hidpp20_constants import ChargeType
from .hidpp20_constants import ErrorCode from .hidpp20_constants import ErrorCode
from .hidpp20_constants import GestureId
from .hidpp20_constants import ParamId from .hidpp20_constants import ParamId
from .hidpp20_constants import SupportedFeature from .hidpp20_constants import SupportedFeature
@ -676,7 +676,7 @@ class Gesture:
def __init__(self, device, low, high, next_index, next_diversion_index): def __init__(self, device, low, high, next_index, next_diversion_index):
self._device = device self._device = device
self.id = low self.id = low
self.gesture = GESTURE[low] self.gesture = GestureId(low)
self.can_be_enabled = high & 0x01 self.can_be_enabled = high & 0x01
self.can_be_diverted = high & 0x02 self.can_be_diverted = high & 0x02
self.show_in_ui = high & 0x04 self.show_in_ui = high & 0x04

View File

@ -213,70 +213,70 @@ class ErrorCode(IntEnum):
UNSUPPORTED = 0x09 UNSUPPORTED = 0x09
# Gesture Ids for feature GESTURE_2 class GestureId(IntEnum):
GESTURE = NamedInts( """Gesture IDs for feature GESTURE_2."""
Tap1Finger=1, # task Left_Click
Tap2Finger=2, # task Right_Click TAP_1_FINGER = 1 # task Left_Click
Tap3Finger=3, TAP_2_FINGER = 2 # task Right_Click
Click1Finger=4, # task Left_Click TAP_3_FINGER = 3
Click2Finger=5, # task Right_Click CLICK_1_FINGER = 4 # task Left_Click
Click3Finger=6, CLICK_2_FINGER = 5 # task Right_Click
DoubleTap1Finger=10, CLICK_3_FINGER = 6
DoubleTap2Finger=11, DOUBLE_TAP_1_FINGER = 10
DoubleTap3Finger=12, DOUBLE_TAP_2_FINGER = 11
Track1Finger=20, # action MovePointer DOUBLE_TAP_3_FINGER = 12
TrackingAcceleration=21, TRACK_1_FINGER = 20 # action MovePointer
TapDrag1Finger=30, # action Drag TRACKING_ACCELERATION = 21
TapDrag2Finger=31, # action SecondaryDrag TAP_DRAG_1_FINGER = 30 # action Drag
Drag3Finger=32, TAP_DRAG_2_FINGER = 31 # action SecondaryDrag
TapGestures=33, # group all tap gestures under a single UI setting DRAG_3_FINGER = 32
FnClickGestureSuppression=34, # suppresses Tap and Edge gestures, toggled by Fn+Click TAP_GESTURES = 33 # group all tap gestures under a single UI setting
Scroll1Finger=40, # action ScrollOrPageXY / ScrollHorizontal FN_CLICK_GESTURE_SUPPRESSION = 34 # suppresses Tap and Edge gestures, toggled by Fn+Click
Scroll2Finger=41, # action ScrollOrPageXY / ScrollHorizontal SCROLL_1_FINGER = 40 # action ScrollOrPageXY / ScrollHorizontal
Scroll2FingerHoriz=42, # action ScrollHorizontal SCROLL_2_FINGER = 41 # action ScrollOrPageXY / ScrollHorizontal
Scroll2FingerVert=43, # action WheelScrolling SCROLL_2_FINGER_HORIZONTAL = 42 # action ScrollHorizontal
Scroll2FingerStateless=44, SCROLL_2_FINGER_VERTICAL = 43 # action WheelScrolling
NaturalScrolling=45, # affects native HID wheel reporting by gestures, not when diverted SCROLL_2_FINGER_STATELESS = 44
Thumbwheel=46, # action WheelScrolling NATURAL_SCROLLING = 45 # affects native HID wheel reporting by gestures, not when diverted
VScrollInertia=48, THUMBWHEEL = (46,) # action WheelScrolling
VScrollBallistics=49, V_SCROLL_INTERTIA = 48
Swipe2FingerHoriz=50, # action PageScreen V_SCROLL_BALLISTICS = 49
Swipe3FingerHoriz=51, # action PageScreen SWIPE_2_FINGER_HORIZONTAL = 50 # action PageScreen
Swipe4FingerHoriz=52, # action PageScreen SWIPE_3_FINGER_HORIZONTAL = 51 # action PageScreen
Swipe3FingerVert=53, SWIPE_4_FINGER_HORIZONTAL = 52 # action PageScreen
Swipe4FingerVert=54, SWIPE_3_FINGER_VERTICAL = 53
LeftEdgeSwipe1Finger=60, SWIPE_4_FINGER_VERTICAL = 54
RightEdgeSwipe1Finger=61, LEFT_EDGE_SWIPE_1_FINGER = 60
BottomEdgeSwipe1Finger=62, RIGHT_EDGE_SWIPE_1_FINGER = 61
TopEdgeSwipe1Finger=63, BOTTOM_EDGE_SWIPE_1_FINGER = 62
LeftEdgeSwipe1Finger2=64, # task HorzScrollNoRepeatSet TOP_EDGE_SWIPE_1_FINGER = 63
RightEdgeSwipe1Finger2=65, # task 122 ?? LEFT_EDGE_SWIPE_1_FINGER_2 = 64 # task HorzScrollNoRepeatSet
BottomEdgeSwipe1Finger2=66, RIGHT_EDGE_SWIPE_1_FINGER_2 = 65
TopEdgeSwipe1Finger2=67, # task 121 ?? BOTTOM_EDGE_SWIPE_1_FINGER_2 = 66
LeftEdgeSwipe2Finger=70, TOP_EDGE_SWIPE_1_FINGER_2 = 67
RightEdgeSwipe2Finger=71, LEFT_EDGE_SWIPE_2_FINGER = 70
BottomEdgeSwipe2Finger=72, RIGHT_EDGE_SWIPE_2_FINGER = 71
TopEdgeSwipe2Finger=73, BottomEdgeSwipe2Finger = 72
Zoom2Finger=80, # action Zoom BOTTOM_EDGE_SWIPE_2_FINGER = 72
Zoom2FingerPinch=81, # ZoomBtnInSet TOP_EDGE_SWIPE_2_FINGER = 73
Zoom2FingerSpread=82, # ZoomBtnOutSet ZOOM_2_FINGER = 80 # action Zoom
Zoom3Finger=83, ZOOM_2_FINGER_PINCH = 81 # ZoomBtnInSet
Zoom2FingerStateless=84, # action Zoom ZOOM_2_FINGER_SPREAD = 82 # ZoomBtnOutSet
TwoFingersPresent=85, ZOOM_3_FINGER = 83
Rotate2Finger=87, ZOOM_2_FINGER_STATELESS = 84
Finger1=90, TWO_FINGERS_PRESENT = 85
Finger2=91, ROTATE_2_FINGER = 87
Finger3=92, FINGER_1 = 90
Finger4=93, FINGER_2 = 91
Finger5=94, FINGER_3 = 92
Finger6=95, FINGER_4 = 93
Finger7=96, FINGER_5 = 94
Finger8=97, FINGER_6 = 95
Finger9=98, FINGER_7 = 96
Finger10=99, FINGER_8 = 97
DeviceSpecificRawData=100, FINGER_9 = 98
) FINGER_10 = 99
GESTURE._fallback = lambda x: f"unknown:{x:04X}" DEVICE_SPECIFIC_RAW_DATA = 100
class ParamId(IntEnum): class ParamId(IntEnum):

View File

@ -38,6 +38,7 @@ from . import hidpp20_constants
from . import settings from . import settings
from . import special_keys from . import special_keys
from .hidpp10_constants import Registers from .hidpp10_constants import Registers
from .hidpp20_constants import GestureId
from .hidpp20_constants import ParamId from .hidpp20_constants import ParamId
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -46,8 +47,6 @@ _hidpp20 = hidpp20.Hidpp20()
_DK = hidpp10_constants.DEVICE_KIND _DK = hidpp10_constants.DEVICE_KIND
_F = hidpp20_constants.SupportedFeature _F = hidpp20_constants.SupportedFeature
_GG = hidpp20_constants.GESTURE
class State(enum.Enum): class State(enum.Enum):
IDLE = "idle" IDLE = "idle"
@ -1227,72 +1226,72 @@ class ChangeHost(settings.Setting):
_GESTURE2_GESTURES_LABELS = { _GESTURE2_GESTURES_LABELS = {
_GG["Tap1Finger"]: (_("Single tap"), _("Performs a left click.")), GestureId.TAP_1_FINGER: (_("Single tap"), _("Performs a left click.")),
_GG["Tap2Finger"]: (_("Single tap with two fingers"), _("Performs a right click.")), GestureId.TAP_2_FINGER: (_("Single tap with two fingers"), _("Performs a right click.")),
_GG["Tap3Finger"]: (_("Single tap with three fingers"), None), GestureId.TAP_3_FINGER: (_("Single tap with three fingers"), None),
_GG["Click1Finger"]: (None, None), GestureId.CLICK_1_FINGER: (None, None),
_GG["Click2Finger"]: (None, None), GestureId.CLICK_2_FINGER: (None, None),
_GG["Click3Finger"]: (None, None), GestureId.CLICK_3_FINGER: (None, None),
_GG["DoubleTap1Finger"]: (_("Double tap"), _("Performs a double click.")), GestureId.DOUBLE_TAP_1_FINGER: (_("Double tap"), _("Performs a double click.")),
_GG["DoubleTap2Finger"]: (_("Double tap with two fingers"), None), GestureId.DOUBLE_TAP_2_FINGER: (_("Double tap with two fingers"), None),
_GG["DoubleTap3Finger"]: (_("Double tap with three fingers"), None), GestureId.DOUBLE_TAP_3_FINGER: (_("Double tap with three fingers"), None),
_GG["Track1Finger"]: (None, None), GestureId.TRACK_1_FINGER: (None, None),
_GG["TrackingAcceleration"]: (None, None), GestureId.TRACKING_ACCELERATION: (None, None),
_GG["TapDrag1Finger"]: (_("Tap and drag"), _("Drags items by dragging the finger after double tapping.")), GestureId.TAP_DRAG_1_FINGER: (_("Tap and drag"), _("Drags items by dragging the finger after double tapping.")),
_GG["TapDrag2Finger"]: ( GestureId.TAP_DRAG_2_FINGER: (
_("Tap and drag with two fingers"), _("Tap and drag with two fingers"),
_("Drags items by dragging the fingers after double tapping."), _("Drags items by dragging the fingers after double tapping."),
), ),
_GG["Drag3Finger"]: (_("Tap and drag with three fingers"), None), GestureId.DRAG_3_FINGER: (_("Tap and drag with three fingers"), None),
_GG["TapGestures"]: (None, None), GestureId.TAP_GESTURES: (None, None),
_GG["FnClickGestureSuppression"]: ( GestureId.FN_CLICK_GESTURE_SUPPRESSION: (
_("Suppress tap and edge gestures"), _("Suppress tap and edge gestures"),
_("Disables tap and edge gestures (equivalent to pressing Fn+LeftClick)."), _("Disables tap and edge gestures (equivalent to pressing Fn+LeftClick)."),
), ),
_GG["Scroll1Finger"]: (_("Scroll with one finger"), _("Scrolls.")), GestureId.SCROLL_1_FINGER: (_("Scroll with one finger"), _("Scrolls.")),
_GG["Scroll2Finger"]: (_("Scroll with two fingers"), _("Scrolls.")), GestureId.SCROLL_2_FINGER: (_("Scroll with two fingers"), _("Scrolls.")),
_GG["Scroll2FingerHoriz"]: (_("Scroll horizontally with two fingers"), _("Scrolls horizontally.")), GestureId.SCROLL_2_FINGER_HORIZONTAL: (_("Scroll horizontally with two fingers"), _("Scrolls horizontally.")),
_GG["Scroll2FingerVert"]: (_("Scroll vertically with two fingers"), _("Scrolls vertically.")), GestureId.SCROLL_2_FINGER_VERTICAL: (_("Scroll vertically with two fingers"), _("Scrolls vertically.")),
_GG["Scroll2FingerStateless"]: (_("Scroll with two fingers"), _("Scrolls.")), GestureId.SCROLL_2_FINGER_STATELESS: (_("Scroll with two fingers"), _("Scrolls.")),
_GG["NaturalScrolling"]: (_("Natural scrolling"), _("Inverts the scrolling direction.")), GestureId.NATURAL_SCROLLING: (_("Natural scrolling"), _("Inverts the scrolling direction.")),
_GG["Thumbwheel"]: (_("Thumbwheel"), _("Enables the thumbwheel.")), GestureId.THUMBWHEEL: (_("Thumbwheel"), _("Enables the thumbwheel.")),
_GG["VScrollInertia"]: (None, None), GestureId.V_SCROLL_INTERTIA: (None, None),
_GG["VScrollBallistics"]: (None, None), GestureId.V_SCROLL_BALLISTICS: (None, None),
_GG["Swipe2FingerHoriz"]: (None, None), GestureId.SWIPE_2_FINGER_HORIZONTAL: (None, None),
_GG["Swipe3FingerHoriz"]: (None, None), GestureId.SWIPE_3_FINGER_HORIZONTAL: (None, None),
_GG["Swipe4FingerHoriz"]: (None, None), GestureId.SWIPE_4_FINGER_HORIZONTAL: (None, None),
_GG["Swipe3FingerVert"]: (None, None), GestureId.SWIPE_3_FINGER_VERTICAL: (None, None),
_GG["Swipe4FingerVert"]: (None, None), GestureId.SWIPE_4_FINGER_VERTICAL: (None, None),
_GG["LeftEdgeSwipe1Finger"]: (None, None), GestureId.LEFT_EDGE_SWIPE_1_FINGER: (None, None),
_GG["RightEdgeSwipe1Finger"]: (None, None), GestureId.RIGHT_EDGE_SWIPE_1_FINGER: (None, None),
_GG["BottomEdgeSwipe1Finger"]: (None, None), GestureId.BOTTOM_EDGE_SWIPE_1_FINGER: (None, None),
_GG["TopEdgeSwipe1Finger"]: (_("Swipe from the top edge"), None), GestureId.TOP_EDGE_SWIPE_1_FINGER: (_("Swipe from the top edge"), None),
_GG["LeftEdgeSwipe1Finger2"]: (_("Swipe from the left edge"), None), GestureId.LEFT_EDGE_SWIPE_1_FINGER_2: (_("Swipe from the left edge"), None),
_GG["RightEdgeSwipe1Finger2"]: (_("Swipe from the right edge"), None), GestureId.RIGHT_EDGE_SWIPE_1_FINGER_2: (_("Swipe from the right edge"), None),
_GG["BottomEdgeSwipe1Finger2"]: (_("Swipe from the bottom edge"), None), GestureId.BOTTOM_EDGE_SWIPE_1_FINGER_2: (_("Swipe from the bottom edge"), None),
_GG["TopEdgeSwipe1Finger2"]: (_("Swipe from the top edge"), None), GestureId.TOP_EDGE_SWIPE_1_FINGER_2: (_("Swipe from the top edge"), None),
_GG["LeftEdgeSwipe2Finger"]: (_("Swipe two fingers from the left edge"), None), GestureId.LEFT_EDGE_SWIPE_2_FINGER: (_("Swipe two fingers from the left edge"), None),
_GG["RightEdgeSwipe2Finger"]: (_("Swipe two fingers from the right edge"), None), GestureId.RIGHT_EDGE_SWIPE_2_FINGER: (_("Swipe two fingers from the right edge"), None),
_GG["BottomEdgeSwipe2Finger"]: (_("Swipe two fingers from the bottom edge"), None), GestureId.BOTTOM_EDGE_SWIPE_2_FINGER: (_("Swipe two fingers from the bottom edge"), None),
_GG["TopEdgeSwipe2Finger"]: (_("Swipe two fingers from the top edge"), None), GestureId.TOP_EDGE_SWIPE_2_FINGER: (_("Swipe two fingers from the top edge"), None),
_GG["Zoom2Finger"]: (_("Zoom with two fingers."), _("Pinch to zoom out; spread to zoom in.")), GestureId.ZOOM_2_FINGER: (_("Zoom with two fingers."), _("Pinch to zoom out; spread to zoom in.")),
_GG["Zoom2FingerPinch"]: (_("Pinch to zoom out."), _("Pinch to zoom out.")), GestureId.ZOOM_2_FINGER_PINCH: (_("Pinch to zoom out."), _("Pinch to zoom out.")),
_GG["Zoom2FingerSpread"]: (_("Spread to zoom in."), _("Spread to zoom in.")), GestureId.ZOOM_2_FINGER_SPREAD: (_("Spread to zoom in."), _("Spread to zoom in.")),
_GG["Zoom3Finger"]: (_("Zoom with three fingers."), None), GestureId.ZOOM_3_FINGER: (_("Zoom with three fingers."), None),
_GG["Zoom2FingerStateless"]: (_("Zoom with two fingers"), _("Pinch to zoom out; spread to zoom in.")), GestureId.ZOOM_2_FINGER_STATELESS: (_("Zoom with two fingers"), _("Pinch to zoom out; spread to zoom in.")),
_GG["TwoFingersPresent"]: (None, None), GestureId.TWO_FINGERS_PRESENT: (None, None),
_GG["Rotate2Finger"]: (None, None), GestureId.ROTATE_2_FINGER: (None, None),
_GG["Finger1"]: (None, None), GestureId.FINGER_1: (None, None),
_GG["Finger2"]: (None, None), GestureId.FINGER_2: (None, None),
_GG["Finger3"]: (None, None), GestureId.FINGER_3: (None, None),
_GG["Finger4"]: (None, None), GestureId.FINGER_4: (None, None),
_GG["Finger5"]: (None, None), GestureId.FINGER_5: (None, None),
_GG["Finger6"]: (None, None), GestureId.FINGER_6: (None, None),
_GG["Finger7"]: (None, None), GestureId.FINGER_7: (None, None),
_GG["Finger8"]: (None, None), GestureId.FINGER_8: (None, None),
_GG["Finger9"]: (None, None), GestureId.FINGER_9: (None, None),
_GG["Finger10"]: (None, None), GestureId.FINGER_10: (None, None),
_GG["DeviceSpecificRawData"]: (None, None), GestureId.DEVICE_SPECIFIC_RAW_DATA: (None, None),
} }
_GESTURE2_PARAMS_LABELS = { _GESTURE2_PARAMS_LABELS = {
@ -1318,7 +1317,7 @@ class Gesture2Gestures(settings.BitFieldWithOffsetAndMaskSetting):
feature = _F.GESTURE_2 feature = _F.GESTURE_2
rw_options = {"read_fnid": 0x10, "write_fnid": 0x20} rw_options = {"read_fnid": 0x10, "write_fnid": 0x20}
validator_options = {"om_method": hidpp20.Gesture.enable_offset_mask} validator_options = {"om_method": hidpp20.Gesture.enable_offset_mask}
choices_universe = hidpp20_constants.GESTURE choices_universe = hidpp20_constants.GestureId
_labels = _GESTURE2_GESTURES_LABELS _labels = _GESTURE2_GESTURES_LABELS
class validator_class(settings.BitFieldWithOffsetAndMaskValidator): class validator_class(settings.BitFieldWithOffsetAndMaskValidator):
@ -1335,7 +1334,7 @@ class Gesture2Divert(settings.BitFieldWithOffsetAndMaskSetting):
feature = _F.GESTURE_2 feature = _F.GESTURE_2
rw_options = {"read_fnid": 0x30, "write_fnid": 0x40} rw_options = {"read_fnid": 0x30, "write_fnid": 0x40}
validator_options = {"om_method": hidpp20.Gesture.diversion_offset_mask} validator_options = {"om_method": hidpp20.Gesture.diversion_offset_mask}
choices_universe = hidpp20_constants.GESTURE choices_universe = hidpp20_constants.GestureId
_labels = _GESTURE2_GESTURES_LABELS _labels = _GESTURE2_GESTURES_LABELS
class validator_class(settings.BitFieldWithOffsetAndMaskValidator): class validator_class(settings.BitFieldWithOffsetAndMaskValidator):

View File

@ -22,6 +22,7 @@ from logitech_receiver import exceptions
from logitech_receiver import hidpp20 from logitech_receiver import hidpp20
from logitech_receiver import hidpp20_constants from logitech_receiver import hidpp20_constants
from logitech_receiver import special_keys from logitech_receiver import special_keys
from logitech_receiver.hidpp20_constants import GestureId
from . import fake_hidpp from . import fake_hidpp
@ -489,11 +490,11 @@ def test_SubParam(id, length, minimum, maximum, widget, min, max, wid, string):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"device, low, high, next_index, next_diversion_index, name, cbe, si, sdi, eom, dom", "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, 0x01, 0x01, 5, 10, GestureId.TAP_1_FINGER, True, 5, None, (0, 0x20), (None, None)),
(device_standard, 0x03, 0x02, 6, 11, "Tap3Finger", False, None, 11, (None, None), (1, 0x08)), (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) gesture = hidpp20.Gesture(device, low, high, next_index, next_diversion_index)
assert gesture._device == device assert gesture._device == device