From 3f6b6fd23253e5326d9ba29cac10be36305b3019 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Mon, 1 Apr 2024 22:57:53 +0200 Subject: [PATCH] refactor: Apply the modmap in KeyModifier This makes possible to apply other modifiers to mapped keys and ensures that the modmap really override the shift key behavior. --- srcs/juloo.keyboard2/KeyModifier.java | 11 +++++++++++ srcs/juloo.keyboard2/Keyboard2View.java | 10 +--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/srcs/juloo.keyboard2/KeyModifier.java b/srcs/juloo.keyboard2/KeyModifier.java index 70f7315..a5fcde2 100644 --- a/srcs/juloo.keyboard2/KeyModifier.java +++ b/srcs/juloo.keyboard2/KeyModifier.java @@ -10,6 +10,11 @@ public final class KeyModifier private static HashMap> _cache = new HashMap>(); + /** The optional modmap takes priority over modifiers usual behaviors. Set to + [null] to disable. */ + private static KeyboardData.Modmap _modmap = null; + public static void set_modmap(KeyboardData.Modmap mm) { _modmap = mm; } + /** Modify a key according to modifiers. */ public static KeyValue modify(KeyValue k, Pointers.Modifiers mods) { @@ -130,6 +135,12 @@ public final class KeyModifier private static KeyValue apply_shift(KeyValue k) { + if (_modmap != null) + { + KeyValue mapped = _modmap.shift.get(k); + if (mapped != null) + return mapped; + } switch (k.getKind()) { case Char: diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index 61a62e9..40def60 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -104,6 +104,7 @@ public class Keyboard2View extends View } _compose_kv = KeyValue.getKeyByName("compose"); _compose_key = _keyboard.findKeyWithValue(_compose_kv); + KeyModifier.set_modmap(_keyboard.modmap); reset(); } @@ -137,15 +138,6 @@ public class Keyboard2View extends View public KeyValue modifyKey(KeyValue k, Pointers.Modifiers mods) { - if (_keyboard.modmap != null) - { - if (mods.has(KeyValue.Modifier.SHIFT)) - { - KeyValue km = _keyboard.modmap.shift.get(k); - if (km != null) - return km; - } - } return KeyModifier.modify(k, mods); }