Skip to content

Commit

Permalink
Remove NamedInts: Convert HorizontalScroll to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
MattHag committed Dec 1, 2024
1 parent 000e131 commit 97e2811
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
13 changes: 8 additions & 5 deletions lib/logitech_receiver/hidpp20.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,13 @@ def _setCidReporting(self, flags: Dict[NamedInt, bool] = None, remap: int = 0):
msg=f'Tried to set mapping flag "{f}" on control "{self.key}" '
+ f'which does not support "{key_flag}" on device {self._device}.'
)
bfield |= int(f) if v else 0
bfield |= int(f) << 1 # The 'Xvalid' bit
bfield |= int(f.value) if v else 0
bfield |= int(f.value) << 1 # The 'Xvalid' bit
if self._mapping_flags: # update flags if already read
if v:
self._mapping_flags |= int(f)
self._mapping_flags |= int(f.value)
else:
self._mapping_flags &= ~int(f)
self._mapping_flags &= ~int(f.value)

if remap != 0 and remap not in self.remappable_to:
raise exceptions.FeatureNotSupported(
Expand Down Expand Up @@ -633,7 +633,10 @@ def _query_key(self, index: int):
elif actionId == special_keys.ACTIONID.Mouse:
remapped = special_keys.MOUSE_BUTTONS[remapped]
elif actionId == special_keys.ACTIONID.Hscroll:
remapped = special_keys.HORIZONTAL_SCROLL[remapped]
try:
remapped = special_keys.HorizontalScroll(remapped)
except ValueError:
remapped = f"unknown horizontal scroll:{remapped:04X}"
elif actionId == special_keys.ACTIONID.Consumer:
remapped = special_keys.HID_CONSUMERCODES[remapped]
elif actionId == special_keys.ACTIONID.Empty: # purge data from empty value
Expand Down
12 changes: 6 additions & 6 deletions lib/logitech_receiver/special_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -1207,11 +1207,11 @@ class CidGroup(IntEnum):
)
MOUSE_BUTTONS._fallback = lambda x: f"unknown mouse button:{x:04X}"

HORIZONTAL_SCROLL = NamedInts(
Horizontal_Scroll_Left=0x4000,
Horizontal_Scroll_Right=0x8000,
)
HORIZONTAL_SCROLL._fallback = lambda x: f"unknown horizontal scroll:{x:04X}"

class HorizontalScroll(IntEnum):
Left = 0x4000
Right = 0x8000


# Construct universe for Persistent Remappable Keys setting (only for supported values)
KEYS = UnsortedNamedInts()
Expand Down Expand Up @@ -1246,7 +1246,7 @@ class CidGroup(IntEnum):
KEYS[(ACTIONID.Mouse << 24) + (int(code) << 8)] = str(code)

# Add Horizontal Scroll
for code in HORIZONTAL_SCROLL:
for code in HorizontalScroll:
KEYS[(ACTIONID.Hscroll << 24) + (int(code) << 8)] = str(code)


Expand Down

0 comments on commit 97e2811

Please sign in to comment.