From 29b4b665dc12eb613b68e657a28d93fc5ee0f51e Mon Sep 17 00:00:00 2001
From: Jules Aguillon
Date: Thu, 25 Jul 2024 23:40:58 +0200
Subject: Allow Ctrl modmaps in layouts
The 'ctrl' modmap is different from the other modmaps as it also applies
the built-in Ctrl modifier to the resulting character, even if it was
first modified by the custom modmap.
For example, this will map Ctrl+в to Ctrl+V (not to v):
This is intended to add keyboard shortcuts in non-latin layouts.
A caveat is that the latin character appears on the keyboard while Ctrl
is activated.
---
srcs/juloo.keyboard2/KeyModifier.java | 15 ++++++++++++++-
srcs/juloo.keyboard2/KeyboardData.java | 11 ++++++++---
2 files changed, 22 insertions(+), 4 deletions(-)
(limited to 'srcs')
diff --git a/srcs/juloo.keyboard2/KeyModifier.java b/srcs/juloo.keyboard2/KeyModifier.java
index 8d5fbbb..0ea80ab 100644
--- a/srcs/juloo.keyboard2/KeyModifier.java
+++ b/srcs/juloo.keyboard2/KeyModifier.java
@@ -51,7 +51,7 @@ public final class KeyModifier
{
switch (mod)
{
- case CTRL:
+ case CTRL: return apply_ctrl(k);
case ALT:
case META: return turn_into_keyevent(k);
case FN: return apply_fn(k);
@@ -440,6 +440,19 @@ public final class KeyModifier
}
}
+ private static KeyValue apply_ctrl(KeyValue k)
+ {
+ if (_modmap != null)
+ {
+ KeyValue mapped = _modmap.ctrl.get(k);
+ // Do not return the modified character right away, first turn it into a
+ // key event.
+ if (mapped != null)
+ k = mapped;
+ }
+ return turn_into_keyevent(k);
+ }
+
private static KeyValue turn_into_keyevent(KeyValue k)
{
if (k.getKind() != KeyValue.Kind.Char)
diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java
index bd9296e..fdcf512 100644
--- a/srcs/juloo.keyboard2/KeyboardData.java
+++ b/srcs/juloo.keyboard2/KeyboardData.java
@@ -563,18 +563,20 @@ public final class KeyboardData
{
public final Map shift;
public final Map fn;
+ public final Map ctrl;
- public Modmap(Map s, Map f)
+ public Modmap(Map s, Map f, Map c)
{
shift = s;
fn = f;
+ ctrl = c;
}
public static Modmap parse(XmlPullParser parser) throws Exception
{
HashMap shift = new HashMap();
HashMap fn = new HashMap();
-
+ HashMap ctrl = new HashMap();
while (next_tag(parser))
{
switch (parser.getName())
@@ -585,12 +587,15 @@ public final class KeyboardData
case "fn":
parse_mapping(parser, fn);
break;
+ case "ctrl":
+ parse_mapping(parser, ctrl);
+ break;
default:
throw error(parser, "Expecting tag or , got <" + parser.getName() + ">");
}
}
- return new Modmap(shift, fn);
+ return new Modmap(shift, fn, ctrl);
}
private static void parse_mapping(XmlPullParser parser, Map dst) throws Exception
--
cgit v1.2.3