Skip to content

Commit 862cef1

Browse files
MattHagpfps
authored andcommitted
hidpp20_constants: Refactor Gesture into enum
Replace Gesture NamedInts with enum. Related pwr-Solaar#2273
1 parent a19461b commit 862cef1

File tree

4 files changed

+133
-133
lines changed

4 files changed

+133
-133
lines changed

lib/logitech_receiver/hidpp20.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
from .common import NamedInt
4545
from .hidpp20_constants import CHARGE_STATUS
4646
from .hidpp20_constants import DEVICE_KIND
47-
from .hidpp20_constants import GESTURE
4847
from .hidpp20_constants import ChargeLevel
4948
from .hidpp20_constants import ChargeType
5049
from .hidpp20_constants import ErrorCode
50+
from .hidpp20_constants import GestureId
5151
from .hidpp20_constants import ParamId
5252
from .hidpp20_constants import SupportedFeature
5353

@@ -676,7 +676,7 @@ class Gesture:
676676
def __init__(self, device, low, high, next_index, next_diversion_index):
677677
self._device = device
678678
self.id = low
679-
self.gesture = GESTURE[low]
679+
self.gesture = GestureId(low)
680680
self.can_be_enabled = high & 0x01
681681
self.can_be_diverted = high & 0x02
682682
self.show_in_ui = high & 0x04

lib/logitech_receiver/hidpp20_constants.py

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -213,70 +213,70 @@ class ErrorCode(IntEnum):
213213
UNSUPPORTED = 0x09
214214

215215

216-
# Gesture Ids for feature GESTURE_2
217-
GESTURE = NamedInts(
218-
Tap1Finger=1, # task Left_Click
219-
Tap2Finger=2, # task Right_Click
220-
Tap3Finger=3,
221-
Click1Finger=4, # task Left_Click
222-
Click2Finger=5, # task Right_Click
223-
Click3Finger=6,
224-
DoubleTap1Finger=10,
225-
DoubleTap2Finger=11,
226-
DoubleTap3Finger=12,
227-
Track1Finger=20, # action MovePointer
228-
TrackingAcceleration=21,
229-
TapDrag1Finger=30, # action Drag
230-
TapDrag2Finger=31, # action SecondaryDrag
231-
Drag3Finger=32,
232-
TapGestures=33, # group all tap gestures under a single UI setting
233-
FnClickGestureSuppression=34, # suppresses Tap and Edge gestures, toggled by Fn+Click
234-
Scroll1Finger=40, # action ScrollOrPageXY / ScrollHorizontal
235-
Scroll2Finger=41, # action ScrollOrPageXY / ScrollHorizontal
236-
Scroll2FingerHoriz=42, # action ScrollHorizontal
237-
Scroll2FingerVert=43, # action WheelScrolling
238-
Scroll2FingerStateless=44,
239-
NaturalScrolling=45, # affects native HID wheel reporting by gestures, not when diverted
240-
Thumbwheel=46, # action WheelScrolling
241-
VScrollInertia=48,
242-
VScrollBallistics=49,
243-
Swipe2FingerHoriz=50, # action PageScreen
244-
Swipe3FingerHoriz=51, # action PageScreen
245-
Swipe4FingerHoriz=52, # action PageScreen
246-
Swipe3FingerVert=53,
247-
Swipe4FingerVert=54,
248-
LeftEdgeSwipe1Finger=60,
249-
RightEdgeSwipe1Finger=61,
250-
BottomEdgeSwipe1Finger=62,
251-
TopEdgeSwipe1Finger=63,
252-
LeftEdgeSwipe1Finger2=64, # task HorzScrollNoRepeatSet
253-
RightEdgeSwipe1Finger2=65, # task 122 ??
254-
BottomEdgeSwipe1Finger2=66,
255-
TopEdgeSwipe1Finger2=67, # task 121 ??
256-
LeftEdgeSwipe2Finger=70,
257-
RightEdgeSwipe2Finger=71,
258-
BottomEdgeSwipe2Finger=72,
259-
TopEdgeSwipe2Finger=73,
260-
Zoom2Finger=80, # action Zoom
261-
Zoom2FingerPinch=81, # ZoomBtnInSet
262-
Zoom2FingerSpread=82, # ZoomBtnOutSet
263-
Zoom3Finger=83,
264-
Zoom2FingerStateless=84, # action Zoom
265-
TwoFingersPresent=85,
266-
Rotate2Finger=87,
267-
Finger1=90,
268-
Finger2=91,
269-
Finger3=92,
270-
Finger4=93,
271-
Finger5=94,
272-
Finger6=95,
273-
Finger7=96,
274-
Finger8=97,
275-
Finger9=98,
276-
Finger10=99,
277-
DeviceSpecificRawData=100,
278-
)
279-
GESTURE._fallback = lambda x: f"unknown:{x:04X}"
216+
class GestureId(IntEnum):
217+
"""Gesture IDs for feature GESTURE_2."""
218+
219+
TAP_1_FINGER = 1 # task Left_Click
220+
TAP_2_FINGER = 2 # task Right_Click
221+
TAP_3_FINGER = 3
222+
CLICK_1_FINGER = 4 # task Left_Click
223+
CLICK_2_FINGER = 5 # task Right_Click
224+
CLICK_3_FINGER = 6
225+
DOUBLE_TAP_1_FINGER = 10
226+
DOUBLE_TAP_2_FINGER = 11
227+
DOUBLE_TAP_3_FINGER = 12
228+
TRACK_1_FINGER = 20 # action MovePointer
229+
TRACKING_ACCELERATION = 21
230+
TAP_DRAG_1_FINGER = 30 # action Drag
231+
TAP_DRAG_2_FINGER = 31 # action SecondaryDrag
232+
DRAG_3_FINGER = 32
233+
TAP_GESTURES = 33 # group all tap gestures under a single UI setting
234+
FN_CLICK_GESTURE_SUPPRESSION = 34 # suppresses Tap and Edge gestures, toggled by Fn+Click
235+
SCROLL_1_FINGER = 40 # action ScrollOrPageXY / ScrollHorizontal
236+
SCROLL_2_FINGER = 41 # action ScrollOrPageXY / ScrollHorizontal
237+
SCROLL_2_FINGER_HORIZONTAL = 42 # action ScrollHorizontal
238+
SCROLL_2_FINGER_VERTICAL = 43 # action WheelScrolling
239+
SCROLL_2_FINGER_STATELESS = 44
240+
NATURAL_SCROLLING = 45 # affects native HID wheel reporting by gestures, not when diverted
241+
THUMBWHEEL = (46,) # action WheelScrolling
242+
V_SCROLL_INTERTIA = 48
243+
V_SCROLL_BALLISTICS = 49
244+
SWIPE_2_FINGER_HORIZONTAL = 50 # action PageScreen
245+
SWIPE_3_FINGER_HORIZONTAL = 51 # action PageScreen
246+
SWIPE_4_FINGER_HORIZONTAL = 52 # action PageScreen
247+
SWIPE_3_FINGER_VERTICAL = 53
248+
SWIPE_4_FINGER_VERTICAL = 54
249+
LEFT_EDGE_SWIPE_1_FINGER = 60
250+
RIGHT_EDGE_SWIPE_1_FINGER = 61
251+
BOTTOM_EDGE_SWIPE_1_FINGER = 62
252+
TOP_EDGE_SWIPE_1_FINGER = 63
253+
LEFT_EDGE_SWIPE_1_FINGER_2 = 64 # task HorzScrollNoRepeatSet
254+
RIGHT_EDGE_SWIPE_1_FINGER_2 = 65
255+
BOTTOM_EDGE_SWIPE_1_FINGER_2 = 66
256+
TOP_EDGE_SWIPE_1_FINGER_2 = 67
257+
LEFT_EDGE_SWIPE_2_FINGER = 70
258+
RIGHT_EDGE_SWIPE_2_FINGER = 71
259+
BottomEdgeSwipe2Finger = 72
260+
BOTTOM_EDGE_SWIPE_2_FINGER = 72
261+
TOP_EDGE_SWIPE_2_FINGER = 73
262+
ZOOM_2_FINGER = 80 # action Zoom
263+
ZOOM_2_FINGER_PINCH = 81 # ZoomBtnInSet
264+
ZOOM_2_FINGER_SPREAD = 82 # ZoomBtnOutSet
265+
ZOOM_3_FINGER = 83
266+
ZOOM_2_FINGER_STATELESS = 84
267+
TWO_FINGERS_PRESENT = 85
268+
ROTATE_2_FINGER = 87
269+
FINGER_1 = 90
270+
FINGER_2 = 91
271+
FINGER_3 = 92
272+
FINGER_4 = 93
273+
FINGER_5 = 94
274+
FINGER_6 = 95
275+
FINGER_7 = 96
276+
FINGER_8 = 97
277+
FINGER_9 = 98
278+
FINGER_10 = 99
279+
DEVICE_SPECIFIC_RAW_DATA = 100
280280

281281

282282
class ParamId(IntEnum):

lib/logitech_receiver/settings_templates.py

Lines changed: 63 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from . import settings
3939
from . import special_keys
4040
from .hidpp10_constants import Registers
41+
from .hidpp20_constants import GestureId
4142
from .hidpp20_constants import ParamId
4243

4344
logger = logging.getLogger(__name__)
@@ -46,8 +47,6 @@
4647
_DK = hidpp10_constants.DEVICE_KIND
4748
_F = hidpp20_constants.SupportedFeature
4849

49-
_GG = hidpp20_constants.GESTURE
50-
5150

5251
class State(enum.Enum):
5352
IDLE = "idle"
@@ -1227,72 +1226,72 @@ def build(cls, setting_class, device):
12271226

12281227

12291228
_GESTURE2_GESTURES_LABELS = {
1230-
_GG["Tap1Finger"]: (_("Single tap"), _("Performs a left click.")),
1231-
_GG["Tap2Finger"]: (_("Single tap with two fingers"), _("Performs a right click.")),
1232-
_GG["Tap3Finger"]: (_("Single tap with three fingers"), None),
1233-
_GG["Click1Finger"]: (None, None),
1234-
_GG["Click2Finger"]: (None, None),
1235-
_GG["Click3Finger"]: (None, None),
1236-
_GG["DoubleTap1Finger"]: (_("Double tap"), _("Performs a double click.")),
1237-
_GG["DoubleTap2Finger"]: (_("Double tap with two fingers"), None),
1238-
_GG["DoubleTap3Finger"]: (_("Double tap with three fingers"), None),
1239-
_GG["Track1Finger"]: (None, None),
1240-
_GG["TrackingAcceleration"]: (None, None),
1241-
_GG["TapDrag1Finger"]: (_("Tap and drag"), _("Drags items by dragging the finger after double tapping.")),
1242-
_GG["TapDrag2Finger"]: (
1229+
GestureId.TAP_1_FINGER: (_("Single tap"), _("Performs a left click.")),
1230+
GestureId.TAP_2_FINGER: (_("Single tap with two fingers"), _("Performs a right click.")),
1231+
GestureId.TAP_3_FINGER: (_("Single tap with three fingers"), None),
1232+
GestureId.CLICK_1_FINGER: (None, None),
1233+
GestureId.CLICK_2_FINGER: (None, None),
1234+
GestureId.CLICK_3_FINGER: (None, None),
1235+
GestureId.DOUBLE_TAP_1_FINGER: (_("Double tap"), _("Performs a double click.")),
1236+
GestureId.DOUBLE_TAP_2_FINGER: (_("Double tap with two fingers"), None),
1237+
GestureId.DOUBLE_TAP_3_FINGER: (_("Double tap with three fingers"), None),
1238+
GestureId.TRACK_1_FINGER: (None, None),
1239+
GestureId.TRACKING_ACCELERATION: (None, None),
1240+
GestureId.TAP_DRAG_1_FINGER: (_("Tap and drag"), _("Drags items by dragging the finger after double tapping.")),
1241+
GestureId.TAP_DRAG_2_FINGER: (
12431242
_("Tap and drag with two fingers"),
12441243
_("Drags items by dragging the fingers after double tapping."),
12451244
),
1246-
_GG["Drag3Finger"]: (_("Tap and drag with three fingers"), None),
1247-
_GG["TapGestures"]: (None, None),
1248-
_GG["FnClickGestureSuppression"]: (
1245+
GestureId.DRAG_3_FINGER: (_("Tap and drag with three fingers"), None),
1246+
GestureId.TAP_GESTURES: (None, None),
1247+
GestureId.FN_CLICK_GESTURE_SUPPRESSION: (
12491248
_("Suppress tap and edge gestures"),
12501249
_("Disables tap and edge gestures (equivalent to pressing Fn+LeftClick)."),
12511250
),
1252-
_GG["Scroll1Finger"]: (_("Scroll with one finger"), _("Scrolls.")),
1253-
_GG["Scroll2Finger"]: (_("Scroll with two fingers"), _("Scrolls.")),
1254-
_GG["Scroll2FingerHoriz"]: (_("Scroll horizontally with two fingers"), _("Scrolls horizontally.")),
1255-
_GG["Scroll2FingerVert"]: (_("Scroll vertically with two fingers"), _("Scrolls vertically.")),
1256-
_GG["Scroll2FingerStateless"]: (_("Scroll with two fingers"), _("Scrolls.")),
1257-
_GG["NaturalScrolling"]: (_("Natural scrolling"), _("Inverts the scrolling direction.")),
1258-
_GG["Thumbwheel"]: (_("Thumbwheel"), _("Enables the thumbwheel.")),
1259-
_GG["VScrollInertia"]: (None, None),
1260-
_GG["VScrollBallistics"]: (None, None),
1261-
_GG["Swipe2FingerHoriz"]: (None, None),
1262-
_GG["Swipe3FingerHoriz"]: (None, None),
1263-
_GG["Swipe4FingerHoriz"]: (None, None),
1264-
_GG["Swipe3FingerVert"]: (None, None),
1265-
_GG["Swipe4FingerVert"]: (None, None),
1266-
_GG["LeftEdgeSwipe1Finger"]: (None, None),
1267-
_GG["RightEdgeSwipe1Finger"]: (None, None),
1268-
_GG["BottomEdgeSwipe1Finger"]: (None, None),
1269-
_GG["TopEdgeSwipe1Finger"]: (_("Swipe from the top edge"), None),
1270-
_GG["LeftEdgeSwipe1Finger2"]: (_("Swipe from the left edge"), None),
1271-
_GG["RightEdgeSwipe1Finger2"]: (_("Swipe from the right edge"), None),
1272-
_GG["BottomEdgeSwipe1Finger2"]: (_("Swipe from the bottom edge"), None),
1273-
_GG["TopEdgeSwipe1Finger2"]: (_("Swipe from the top edge"), None),
1274-
_GG["LeftEdgeSwipe2Finger"]: (_("Swipe two fingers from the left edge"), None),
1275-
_GG["RightEdgeSwipe2Finger"]: (_("Swipe two fingers from the right edge"), None),
1276-
_GG["BottomEdgeSwipe2Finger"]: (_("Swipe two fingers from the bottom edge"), None),
1277-
_GG["TopEdgeSwipe2Finger"]: (_("Swipe two fingers from the top edge"), None),
1278-
_GG["Zoom2Finger"]: (_("Zoom with two fingers."), _("Pinch to zoom out; spread to zoom in.")),
1279-
_GG["Zoom2FingerPinch"]: (_("Pinch to zoom out."), _("Pinch to zoom out.")),
1280-
_GG["Zoom2FingerSpread"]: (_("Spread to zoom in."), _("Spread to zoom in.")),
1281-
_GG["Zoom3Finger"]: (_("Zoom with three fingers."), None),
1282-
_GG["Zoom2FingerStateless"]: (_("Zoom with two fingers"), _("Pinch to zoom out; spread to zoom in.")),
1283-
_GG["TwoFingersPresent"]: (None, None),
1284-
_GG["Rotate2Finger"]: (None, None),
1285-
_GG["Finger1"]: (None, None),
1286-
_GG["Finger2"]: (None, None),
1287-
_GG["Finger3"]: (None, None),
1288-
_GG["Finger4"]: (None, None),
1289-
_GG["Finger5"]: (None, None),
1290-
_GG["Finger6"]: (None, None),
1291-
_GG["Finger7"]: (None, None),
1292-
_GG["Finger8"]: (None, None),
1293-
_GG["Finger9"]: (None, None),
1294-
_GG["Finger10"]: (None, None),
1295-
_GG["DeviceSpecificRawData"]: (None, None),
1251+
GestureId.SCROLL_1_FINGER: (_("Scroll with one finger"), _("Scrolls.")),
1252+
GestureId.SCROLL_2_FINGER: (_("Scroll with two fingers"), _("Scrolls.")),
1253+
GestureId.SCROLL_2_FINGER_HORIZONTAL: (_("Scroll horizontally with two fingers"), _("Scrolls horizontally.")),
1254+
GestureId.SCROLL_2_FINGER_VERTICAL: (_("Scroll vertically with two fingers"), _("Scrolls vertically.")),
1255+
GestureId.SCROLL_2_FINGER_STATELESS: (_("Scroll with two fingers"), _("Scrolls.")),
1256+
GestureId.NATURAL_SCROLLING: (_("Natural scrolling"), _("Inverts the scrolling direction.")),
1257+
GestureId.THUMBWHEEL: (_("Thumbwheel"), _("Enables the thumbwheel.")),
1258+
GestureId.V_SCROLL_INTERTIA: (None, None),
1259+
GestureId.V_SCROLL_BALLISTICS: (None, None),
1260+
GestureId.SWIPE_2_FINGER_HORIZONTAL: (None, None),
1261+
GestureId.SWIPE_3_FINGER_HORIZONTAL: (None, None),
1262+
GestureId.SWIPE_4_FINGER_HORIZONTAL: (None, None),
1263+
GestureId.SWIPE_3_FINGER_VERTICAL: (None, None),
1264+
GestureId.SWIPE_4_FINGER_VERTICAL: (None, None),
1265+
GestureId.LEFT_EDGE_SWIPE_1_FINGER: (None, None),
1266+
GestureId.RIGHT_EDGE_SWIPE_1_FINGER: (None, None),
1267+
GestureId.BOTTOM_EDGE_SWIPE_1_FINGER: (None, None),
1268+
GestureId.TOP_EDGE_SWIPE_1_FINGER: (_("Swipe from the top edge"), None),
1269+
GestureId.LEFT_EDGE_SWIPE_1_FINGER_2: (_("Swipe from the left edge"), None),
1270+
GestureId.RIGHT_EDGE_SWIPE_1_FINGER_2: (_("Swipe from the right edge"), None),
1271+
GestureId.BOTTOM_EDGE_SWIPE_1_FINGER_2: (_("Swipe from the bottom edge"), None),
1272+
GestureId.TOP_EDGE_SWIPE_1_FINGER_2: (_("Swipe from the top edge"), None),
1273+
GestureId.LEFT_EDGE_SWIPE_2_FINGER: (_("Swipe two fingers from the left edge"), None),
1274+
GestureId.RIGHT_EDGE_SWIPE_2_FINGER: (_("Swipe two fingers from the right edge"), None),
1275+
GestureId.BOTTOM_EDGE_SWIPE_2_FINGER: (_("Swipe two fingers from the bottom edge"), None),
1276+
GestureId.TOP_EDGE_SWIPE_2_FINGER: (_("Swipe two fingers from the top edge"), None),
1277+
GestureId.ZOOM_2_FINGER: (_("Zoom with two fingers."), _("Pinch to zoom out; spread to zoom in.")),
1278+
GestureId.ZOOM_2_FINGER_PINCH: (_("Pinch to zoom out."), _("Pinch to zoom out.")),
1279+
GestureId.ZOOM_2_FINGER_SPREAD: (_("Spread to zoom in."), _("Spread to zoom in.")),
1280+
GestureId.ZOOM_3_FINGER: (_("Zoom with three fingers."), None),
1281+
GestureId.ZOOM_2_FINGER_STATELESS: (_("Zoom with two fingers"), _("Pinch to zoom out; spread to zoom in.")),
1282+
GestureId.TWO_FINGERS_PRESENT: (None, None),
1283+
GestureId.ROTATE_2_FINGER: (None, None),
1284+
GestureId.FINGER_1: (None, None),
1285+
GestureId.FINGER_2: (None, None),
1286+
GestureId.FINGER_3: (None, None),
1287+
GestureId.FINGER_4: (None, None),
1288+
GestureId.FINGER_5: (None, None),
1289+
GestureId.FINGER_6: (None, None),
1290+
GestureId.FINGER_7: (None, None),
1291+
GestureId.FINGER_8: (None, None),
1292+
GestureId.FINGER_9: (None, None),
1293+
GestureId.FINGER_10: (None, None),
1294+
GestureId.DEVICE_SPECIFIC_RAW_DATA: (None, None),
12961295
}
12971296

12981297
_GESTURE2_PARAMS_LABELS = {
@@ -1318,7 +1317,7 @@ class Gesture2Gestures(settings.BitFieldWithOffsetAndMaskSetting):
13181317
feature = _F.GESTURE_2
13191318
rw_options = {"read_fnid": 0x10, "write_fnid": 0x20}
13201319
validator_options = {"om_method": hidpp20.Gesture.enable_offset_mask}
1321-
choices_universe = hidpp20_constants.GESTURE
1320+
choices_universe = hidpp20_constants.GestureId
13221321
_labels = _GESTURE2_GESTURES_LABELS
13231322

13241323
class validator_class(settings.BitFieldWithOffsetAndMaskValidator):
@@ -1335,7 +1334,7 @@ class Gesture2Divert(settings.BitFieldWithOffsetAndMaskSetting):
13351334
feature = _F.GESTURE_2
13361335
rw_options = {"read_fnid": 0x30, "write_fnid": 0x40}
13371336
validator_options = {"om_method": hidpp20.Gesture.diversion_offset_mask}
1338-
choices_universe = hidpp20_constants.GESTURE
1337+
choices_universe = hidpp20_constants.GestureId
13391338
_labels = _GESTURE2_GESTURES_LABELS
13401339

13411340
class validator_class(settings.BitFieldWithOffsetAndMaskValidator):

tests/logitech_receiver/test_hidpp20_complex.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from logitech_receiver import hidpp20
2323
from logitech_receiver import hidpp20_constants
2424
from logitech_receiver import special_keys
25+
from logitech_receiver.hidpp20_constants import GestureId
2526

2627
from . import fake_hidpp
2728

@@ -489,11 +490,11 @@ def test_SubParam(id, length, minimum, maximum, widget, min, max, wid, string):
489490
@pytest.mark.parametrize(
490491
"device, low, high, next_index, next_diversion_index, name, cbe, si, sdi, eom, dom",
491492
[
492-
(device_standard, 0x01, 0x01, 5, 10, "Tap1Finger", True, 5, None, (0, 0x20), (None, None)),
493-
(device_standard, 0x03, 0x02, 6, 11, "Tap3Finger", False, None, 11, (None, None), (1, 0x08)),
493+
(device_standard, 0x01, 0x01, 5, 10, GestureId.TAP_1_FINGER, True, 5, None, (0, 0x20), (None, None)),
494+
(device_standard, 0x03, 0x02, 6, 11, GestureId.TAP_3_FINGER, False, None, 11, (None, None), (1, 0x08)),
494495
],
495496
)
496-
def test_Gesture(device, low, high, next_index, next_diversion_index, name, cbe, si, sdi, eom, dom):
497+
def test_gesture(device, low, high, next_index, next_diversion_index, name, cbe, si, sdi, eom, dom):
497498
gesture = hidpp20.Gesture(device, low, high, next_index, next_diversion_index)
498499

499500
assert gesture._device == device

0 commit comments

Comments
 (0)