device: increase speed for DPI sliding

This commit is contained in:
Peter F. Patel-Schneider 2020-09-26 20:47:17 -04:00
parent ebf7984ad0
commit e6cfd0a0c1
1 changed files with 17 additions and 19 deletions

View File

@ -386,12 +386,13 @@ def _feature_dpi_sliding():
self.movingDpiIdx = None self.movingDpiIdx = None
''' '''
This setting abides by the following FSM. This setting abides by the following FSM.
When the button is pressed, we go into `pressed` state. When the button is pressed, we go into `pressed` state and
If the state is `pressed` and the mouse moves far enough, begin accumulating displacement.
we begin accumulating displacement. Then when it's released, If the button is released in this state we swap DPI slots.
If the state is `pressed` and the mouse moves enough to switch DPI
we go into the `moved` state.
When the button is released in this state
the DPI is set according to the total displacement. the DPI is set according to the total displacement.
If the button is released quickly while still in 'pressed',
we just swap DPI slots.
release release
+---------------------------------------------+ +---------------------------------------------+
@ -399,10 +400,10 @@ def _feature_dpi_sliding():
v moved | v moved |
+------+ press +---------+ enough +-------+ | +------+ press +---------+ enough +-------+ |
| idle |------>| pressed |------->| moved |------+ | idle |------>| pressed |------->| moved |------+
+------+ +---------+ +-------+ move | +------+ +---------+ +-------+
^ release | ^----------+ ^ release | ^ ^
+----------------+ accumulate +----------------+ accumulate
switch DPI slots displacement switch DPI slots displacement
''' '''
def setNewDpi(self, newDpiIdx): def setNewDpi(self, newDpiIdx):
@ -421,6 +422,7 @@ def _feature_dpi_sliding():
if self.fsmState == 'idle': if self.fsmState == 'idle':
if _special_keys.CONTROL.DPI_Switch in cids: if _special_keys.CONTROL.DPI_Switch in cids:
self.fsmState = 'pressed' self.fsmState = 'pressed'
self.dx = 0.
elif self.fsmState == 'pressed': elif self.fsmState == 'pressed':
if _special_keys.CONTROL.DPI_Switch not in cids: if _special_keys.CONTROL.DPI_Switch not in cids:
# Swap DPI slots # Swap DPI slots
@ -437,21 +439,17 @@ def _feature_dpi_sliding():
def handle_move_event(self, dx, dy): def handle_move_event(self, dx, dy):
currDpiIdx = self.dpiSlots[self.dpiSlotChosen] currDpiIdx = self.dpiSlots[self.dpiSlotChosen]
currDpi = self.dpiChoices[currDpiIdx] currDpi = self.dpiChoices[currDpiIdx]
# This yields a more-or-less DPI-independent total dx of 33.3/cm # This multiplier yields a more-or-less DPI-independent total dx of about 5/cm
dx = float(dx) / float(currDpi) * 100. # The multiplier could be configurable to allow adjusting dx
dx = float(dx) / float(currDpi) * 15.
self.dx += dx
if self.fsmState == 'pressed': if self.fsmState == 'pressed':
if abs(dx) > .1: if abs(self.dx) >= 1.:
self.fsmState = 'moved' self.fsmState = 'moved'
self.dx = 0.
self.movingDpiIdx = currDpiIdx self.movingDpiIdx = currDpiIdx
elif self.fsmState == 'moved': elif self.fsmState == 'moved':
self.dx += dx
currIdx = self.dpiSlots[self.dpiSlotChosen] currIdx = self.dpiSlots[self.dpiSlotChosen]
# NOTE(Vtec234): For ultimate power-usage, the '15' should be configurable newMovingDpiIdx = min(max(currIdx + int(self.dx), 0), len(self.dpiChoices) - 1)
# to allow adjusting the DPI-changing speed
idxDiff = int(self.dx / 15.)
newMovingDpiIdx = min(max(currIdx + idxDiff, 0), len(self.dpiChoices) - 1)
if newMovingDpiIdx != self.movingDpiIdx: if newMovingDpiIdx != self.movingDpiIdx:
self.movingDpiIdx = newMovingDpiIdx self.movingDpiIdx = newMovingDpiIdx
self.displayNewDpi(newMovingDpiIdx) self.displayNewDpi(newMovingDpiIdx)