Skip to content

Commit 4d525fe

Browse files
committed
Replace currentlyPressedCompletedComboSequenceKeys with currentlyPressedCompletedComboKeys
hint2-mode.to.slow-mode=_{slow} +extendedhint1key slow-mode.press.left=+left should not need _{slow} +left
1 parent 4aab544 commit 4d525fe

File tree

3 files changed

+42
-33
lines changed

3 files changed

+42
-33
lines changed

src/main/java/mousemaster/ComboWatcher.java

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ComboWatcher implements ModeListener {
2727
private List<ComboWaitingForLastMoveToComplete> combosWaitingForLastMoveToComplete = new ArrayList<>();
2828
private List<Command> commandsWaitingForAtomicCommandToComplete = new ArrayList<>();
2929

30-
private Set<Key> currentlyPressedCompletedComboSequenceKeys = new HashSet<>();
30+
private Set<Key> currentlyPressedCompletedComboKeys = new HashSet<>();
3131
private Set<Key> currentlyPressedComboKeys = new HashSet<>();
3232

3333
public ComboWatcher(CommandRunner commandRunner, ActiveAppFinder activeAppFinder,
@@ -102,7 +102,7 @@ public ComboWatcherUpdateResult update(double delta) {
102102
.anyMatch(
103103
Command.BreakComboPreparation.class::isInstance))
104104
comboPreparationBreakerKey = combo.sequence().moves().getLast().key();
105-
addCurrentlyPressedCompletedComboSequenceKeys(combo);
105+
addCurrentlyPressedCompletedComboKeys(combo, currentlyPressedComboKeys);
106106
// We tell KeyboardManager that a combo was completed,
107107
// and all the currently pressed keys are part of a completed combo,
108108
// and they should not be regurgitated.
@@ -133,7 +133,7 @@ public ComboWatcherUpdateResult update(double delta) {
133133
if (currentMode != beforeMode && comboPreparationBreakerKey == null) {
134134
PressKeyEventProcessingSet processingSet =
135135
processKeyEventForCurrentMode(null, true);
136-
completedCombos.addAll(processingSet.completedCombos());
136+
completedCombos.addAll(processingSet.partOfCompletedComboSequenceCombos());
137137
}
138138
return new ComboWatcherUpdateResult(completedCombos,
139139
preparationIsNotPrefixAnymore, comboPreparationBreakerKey);
@@ -151,7 +151,7 @@ public PressKeyEventProcessingSet keyEvent(KeyEvent event) {
151151
if (event.isRelease()) {
152152
// The corresponding press event was either part of a combo sequence or part of a combo precondition,
153153
// otherwise this method would not have been called.
154-
currentlyPressedCompletedComboSequenceKeys.remove(event.key());
154+
currentlyPressedCompletedComboKeys.remove(event.key());
155155
currentlyPressedComboKeys.remove(event.key());
156156
}
157157
else {
@@ -235,8 +235,8 @@ private PressKeyEventProcessingSet processKeyEventForCurrentMode(
235235
// even if there is a pressed key that is not in the combo precondition, we
236236
// still consider the combo as completed.
237237
if (!releaseCombo &&
238-
!comboPressedPreconditionSatisfied(combo, currentlyPressedKeys,
239-
currentlyPressedCompletedComboSequenceKeys, matchingMoveCount)) {
238+
satisfiedComboPressedPrecondition(combo, currentlyPressedKeys,
239+
currentlyPressedCompletedComboKeys, matchingMoveCount) == null) {
240240
// Then it's as if the currently pressed precondition key is an unhandled key:
241241
// other keys that are pressed should not even be considered but passed onto other apps.
242242
// logger.info("currentlyPressedPressedComboKeysNotPartOfAlreadyCompletedCombo = " +
@@ -343,13 +343,13 @@ private PressKeyEventProcessingSet processKeyEventForCurrentMode(
343343
}
344344
runCommands(commandsToRun);
345345
if (event != null && event.isPress()) {
346-
if (processingSet.isPartOfComboSequence()) {
346+
boolean atLeastOneComboCompleted = !comboAndCommandsToRun.isEmpty();
347+
if (atLeastOneComboCompleted) {
347348
for (ComboAndCommands comboAndCommands : comboAndCommandsToRun) {
348349
Combo combo = comboAndCommands.combo;
349-
addCurrentlyPressedCompletedComboSequenceKeys(combo);
350+
addCurrentlyPressedCompletedComboKeys(combo,
351+
currentlyPressedKeys);
350352
}
351-
if (processingSet.isPartOfCompletedComboSequence())
352-
currentlyPressedCompletedComboSequenceKeys.add(event.key());
353353
}
354354
}
355355
return processingSet;
@@ -374,10 +374,10 @@ private void runCommands(List<Command> commandsToRun) {
374374
commandsWaitingForAtomicCommandToComplete.addAll(commands);
375375
}
376376

377-
private boolean comboPressedPreconditionSatisfied(Combo combo,
378-
Set<Key> currentlyPressedKeys,
379-
Set<Key> currentlyPressedCompletedComboSequenceKeys,
380-
int matchingMoveCount) {
377+
private Set<Key> satisfiedComboPressedPrecondition(Combo combo,
378+
Set<Key> currentlyPressedKeys,
379+
Set<Key> currentlyPressedCompletedComboKeys,
380+
int matchingMoveCount) {
381381
Set<Set<Key>> preconditionPressedKeySets = combo.precondition()
382382
.keyPrecondition()
383383
.pressedKeySets();
@@ -387,19 +387,19 @@ private boolean comboPressedPreconditionSatisfied(Combo combo,
387387
Set<Key> keysPressedInComboPriorToMove =
388388
combo.keysPressedInComboPriorToMoveOfIndex(preconditionPressedKeySet,
389389
matchingMoveCount - 1);
390-
Set<Key> currentlyPressedKeysNotPartOfAlreadyCompletedComboSequence =
390+
Set<Key> currentlyPressedKeysNotPartOfAlreadyCompletedCombo =
391391
new HashSet<>(currentlyPressedKeys);
392-
for (Key currentlyPressedCompletedComboSequenceKey : currentlyPressedCompletedComboSequenceKeys) {
392+
for (Key currentlyPressedCompletedComboKey : currentlyPressedCompletedComboKeys) {
393393
if (!keysPressedInComboPriorToMove.contains(
394-
currentlyPressedCompletedComboSequenceKey))
395-
currentlyPressedKeysNotPartOfAlreadyCompletedComboSequence.remove(
396-
currentlyPressedCompletedComboSequenceKey);
394+
currentlyPressedCompletedComboKey))
395+
currentlyPressedKeysNotPartOfAlreadyCompletedCombo.remove(
396+
currentlyPressedCompletedComboKey);
397397
}
398-
if (currentlyPressedKeysNotPartOfAlreadyCompletedComboSequence.equals(
398+
if (currentlyPressedKeysNotPartOfAlreadyCompletedCombo.equals(
399399
keysPressedInComboPriorToMove))
400-
return true;
400+
return preconditionPressedKeySet;
401401
}
402-
return false;
402+
return null;
403403
}
404404

405405
private boolean comboUnpressedPreconditionSatisfied(Combo combo,
@@ -416,12 +416,21 @@ private boolean comboUnpressedPreconditionSatisfied(Combo combo,
416416
return true;
417417
}
418418

419-
private void addCurrentlyPressedCompletedComboSequenceKeys(Combo combo) {
420-
Set<Key> keys = combo.keysPressedInComboPriorToMoveOfIndex(
421-
Set.of(), combo.sequence().moves().size() - 1);
422-
// logger.info("Combo completed, pressed keys: " + keys);
423-
currentlyPressedCompletedComboSequenceKeys.addAll(keys);
424-
}
419+
private void addCurrentlyPressedCompletedComboKeys(Combo combo,
420+
Set<Key> currentlyPressedKeys) {
421+
Set<Key> satisfiedPressPreconditionKeys =
422+
satisfiedComboPressedPrecondition(combo, currentlyPressedKeys,
423+
currentlyPressedCompletedComboKeys,
424+
combo.sequence().moves().size());
425+
if (satisfiedPressPreconditionKeys == null)
426+
throw new IllegalStateException();
427+
Set<Key> keys =
428+
combo.keysPressedInComboPriorToMoveOfIndex(
429+
satisfiedPressPreconditionKeys,
430+
combo.sequence().moves().size() - 1);
431+
// logger.info("Combo completed, pressed keys: " + keys);
432+
currentlyPressedCompletedComboKeys.addAll(keys);
433+
}
425434

426435
private static final List<? extends Class<? extends Command>> commandOrder =
427436
List.of(
@@ -472,14 +481,14 @@ public void breakComboPreparation() {
472481
public void reset() {
473482
breakComboPreparation();
474483
// When a mode times out to a new mode, the currentlyPressedComboKeys should not be reset.
475-
currentlyPressedCompletedComboSequenceKeys.clear();
484+
currentlyPressedCompletedComboKeys.clear();
476485
currentlyPressedComboKeys.clear();
477486
}
478487

479488
public void reset(Key comboPreparationBreakerKey) {
480489
breakComboPreparation();
481490
// KeyManager won't notify ComboWatcher of the release of the comboPreparationBreakerKey.
482-
currentlyPressedCompletedComboSequenceKeys.remove(comboPreparationBreakerKey);
491+
currentlyPressedCompletedComboKeys.remove(comboPreparationBreakerKey);
483492
currentlyPressedComboKeys.remove(comboPreparationBreakerKey);
484493
}
485494

src/main/java/mousemaster/KeyboardManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ else if (processingSet.isPartOfComboSequence()) {
122122
}
123123
currentlyPressedKeys.put(key, processingSet);
124124
if (processingSet.isPartOfCompletedComboSequence()) {
125-
markOtherKeysOfTheseCombosAsCompleted(processingSet.completedCombos(), false);
125+
markOtherKeysOfTheseCombosAsCompleted(processingSet.partOfCompletedComboSequenceCombos(), false);
126126
}
127127
if (processingSet.isComboPreparationBreaker()) {
128128
comboWatcher.reset(key);
@@ -165,7 +165,7 @@ else if (releaseProcessingSet.isPartOfCompletedComboSequence()) {
165165
});
166166
}
167167
markOtherKeysOfTheseCombosAsCompleted(
168-
releaseProcessingSet.completedCombos(),
168+
releaseProcessingSet.partOfCompletedComboSequenceCombos(),
169169
false);
170170
keysToRegurgitate = regurgitatePressedKeys(key);
171171
}

src/main/java/mousemaster/PressKeyEventProcessingSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public boolean isPartOfCompletedComboSequence() {
4545
PressKeyEventProcessing::isPartOfCompletedComboSequence);
4646
}
4747

48-
public Set<Combo> completedCombos() {
48+
public Set<Combo> partOfCompletedComboSequenceCombos() {
4949
Set<Combo> completedCombos = new HashSet<>();
5050
for (Map.Entry<Combo, PressKeyEventProcessing> entry : processingByCombo.entrySet()) {
5151
if (entry.getValue().isPartOfCompletedComboSequence()) {

0 commit comments

Comments
 (0)