diff options
| author | Linnea Gräf <nea@nea.moe> | 2025-10-13 20:14:10 +0200 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2025-10-13 20:14:10 +0200 |
| commit | 0d903f93d35410a81f7be073511487903ff49516 (patch) | |
| tree | 3730d406c936f7dbc794543adb60ac969996bbbd /src/main | |
| parent | a7274d6fea21d5c1d56c2f2dfc896be9007ae6f5 (diff) | |
| download | Firmament-0d903f93d35410a81f7be073511487903ff49516.tar.gz Firmament-0d903f93d35410a81f7be073511487903ff49516.tar.bz2 Firmament-0d903f93d35410a81f7be073511487903ff49516.zip | |
fix: atLeast for modifier buttons not being correct
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/kotlin/keybindings/GenericInputButton.kt | 26 | ||||
| -rw-r--r-- | src/main/kotlin/keybindings/SavedKeyBinding.kt | 1 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/main/kotlin/keybindings/GenericInputButton.kt b/src/main/kotlin/keybindings/GenericInputButton.kt index 53c0e56..ddbf509 100644 --- a/src/main/kotlin/keybindings/GenericInputButton.kt +++ b/src/main/kotlin/keybindings/GenericInputButton.kt @@ -247,18 +247,44 @@ data class InputModifiers( ) } + fun ofKeyCodes(vararg keys: Int): InputModifiers { + var mods = 0 + for (key in keys) { + if (key in superKeys) + mods = mods or GLFW.GLFW_MOD_SUPER + if (key in controlKeys) + mods = mods or GLFW.GLFW_MOD_CONTROL + if (key in altKeys) + mods = mods or GLFW.GLFW_MOD_ALT + if (key in shiftKeys) + mods = mods or GLFW.GLFW_MOD_SHIFT + } + return of(mods) + } + @JvmStatic fun of(modifiers: Int) = InputModifiers(modifiers) fun none(): InputModifiers { return InputModifiers(0) } + + fun ofKey(button: GenericInputButton): InputModifiers { + return when (button) { + is GenericInputButton.KeyCodeButton -> ofKeyCodes(button.keyCode) + else -> none() + } + } } fun isAtLeast(other: InputModifiers): Boolean { return this.modifiers and other.modifiers == this.modifiers } + fun without(other: InputModifiers): InputModifiers { + return InputModifiers(this.modifiers and other.modifiers.inv()) + } + fun isEmpty() = modifiers == 0 fun getFlag(flag: Int) = modifiers and flag != 0 diff --git a/src/main/kotlin/keybindings/SavedKeyBinding.kt b/src/main/kotlin/keybindings/SavedKeyBinding.kt index 48716d3..8f08e5f 100644 --- a/src/main/kotlin/keybindings/SavedKeyBinding.kt +++ b/src/main/kotlin/keybindings/SavedKeyBinding.kt @@ -22,6 +22,7 @@ data class SavedKeyBinding( if (!button.isPressed()) return false val mods = InputModifiers.current() + .without(InputModifiers.ofKey(button)) return mods.matches(this.modifiers, atLeast) } |
