Move all remaining state into the single store, woot!

This commit is contained in:
Josh Klar
2018-09-03 15:21:34 -07:00
parent b9dfffd2b3
commit ffd47c478f
4 changed files with 139 additions and 34 deletions

View File

@@ -4,18 +4,22 @@ from kmk.common.event_defs import key_down_event, key_up_event
class Keymap:
def __init__(self, map):
self.map = map
self.state = [
[False for _ in row]
for row in self.map
]
def parse(self, matrix, store):
state = store.get_state()
for ridx, row in enumerate(matrix):
for cidx, col in enumerate(row):
if col != self.state[ridx][cidx]:
if col != state.matrix[ridx][cidx]:
if col:
store.dispatch(key_down_event(self.map[ridx][cidx]))
store.dispatch(key_down_event(
row=ridx,
col=cidx,
keycode=self.map[ridx][cidx],
))
else:
store.dispatch(key_up_event(self.map[ridx][cidx]))
self.state = matrix
store.dispatch(key_up_event(
row=ridx,
col=cidx,
keycode=self.map[ridx][cidx],
))