diff options
| author | Jules Aguillon | 2024-09-29 22:05:54 +0200 |
|---|---|---|
| committer | Jules Aguillon | 2024-09-29 22:05:54 +0200 |
| commit | 700ec23bd465fa74828ffd6dfbc42dfc81731510 (patch) | |
| tree | 46afeeebc8a543cc55493bbc361ca27f106a2ded /srcs/juloo.keyboard2 | |
| parent | fb93d841a575729de355d0d53cc4f5b7acd09410 (diff) | |
| download | unexpected-keyboard-700ec23bd465fa74828ffd6dfbc42dfc81731510.tar.gz unexpected-keyboard-700ec23bd465fa74828ffd6dfbc42dfc81731510.zip | |
Improve Ctrl key labels for Serbian Cyrillic layout
Add the ':char' syntax for defining character keys with a different
symbol.
This new kind of keys is used to implement Ctrl combinations in the
Serbian Cyrillic layout without showing latin letters while the Ctrl
modifier is activated.
Diffstat (limited to 'srcs/juloo.keyboard2')
| -rw-r--r-- | srcs/juloo.keyboard2/KeyValue.java | 9 | ||||
| -rw-r--r-- | srcs/juloo.keyboard2/KeyValueParser.java | 34 |
2 files changed, 24 insertions, 19 deletions
diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java index b6c09d5..320eaaa 100644 --- a/srcs/juloo.keyboard2/KeyValue.java +++ b/srcs/juloo.keyboard2/KeyValue.java @@ -393,7 +393,14 @@ public final class KeyValue implements Comparable<KeyValue> public static KeyValue makeCharKey(char c) { - return new KeyValue(String.valueOf(c), Kind.Char, c, 0); + return makeCharKey(c, null, 0); + } + + public static KeyValue makeCharKey(char c, String symbol, int flags) + { + if (symbol == null) + symbol = String.valueOf(c); + return new KeyValue(symbol, Kind.Char, c, flags); } public static KeyValue makeComposePending(String symbol, int state, int flags) diff --git a/srcs/juloo.keyboard2/KeyValueParser.java b/srcs/juloo.keyboard2/KeyValueParser.java index 178046e..7e4ba26 100644 --- a/srcs/juloo.keyboard2/KeyValueParser.java +++ b/srcs/juloo.keyboard2/KeyValueParser.java @@ -9,21 +9,7 @@ Parse a key definition. The syntax for a key definition is: - If [str] doesn't start with a [:] character, it is interpreted as an arbitrary string key. -[(kind)] specifies the kind of the key, it can be: -- [str]: An arbitrary string key. The payload is the string to output when - typed and is quoted by single quotes ([']). The payload can contain single - quotes if they are escaped with a backslash ([\']). - -The [(attributes)] part is a space-separated list of attributes, all optional, -of the form: [attrname='attrvalue']. - -Attributes can be: -- [flags]: Add flags that change the behavior of the key. - Value is a coma separated list of: - - [dim]: Make the symbol dimmer on the keyboard. - - [small]: Make the symbol smaller on the keyboard. -- [symbol]: Specify the symbol that is rendered on the keyboard. - It can contain single quotes if they are escaped: ([\']). +For the different kinds and attributes, see doc/Possible-key-values.md. Examples: - [:str flags=dim,small symbol='MyKey':'My arbitrary string']. @@ -36,6 +22,7 @@ public final class KeyValueParser static Pattern ATTR_PAT; static Pattern QUOTED_PAT; static Pattern PAYLOAD_START_PAT; + static Pattern SINGLE_CHAR_PAT; static public KeyValue parse(String str) throws ParseError { @@ -73,11 +60,14 @@ public final class KeyValueParser switch (kind) { case "str": - String payload = parseSingleQuotedString(m); + String str_payload = parseSingleQuotedString(m); if (symbol == null) - return KeyValue.makeStringKey(payload, flags); - return KeyValue.makeStringKeyWithSymbol(payload, symbol, flags); + return KeyValue.makeStringKey(str_payload, flags); + return KeyValue.makeStringKeyWithSymbol(str_payload, symbol, flags); + case "char": + char char_payload = parseOneChar(m); + return KeyValue.makeCharKey(char_payload, symbol, flags); default: break; } parseError("Unknown kind '"+kind+"'", m, 1); @@ -91,6 +81,13 @@ public final class KeyValueParser return m.group(1).replace("\\'", "'"); } + static char parseOneChar(Matcher m) throws ParseError + { + if (!match(m, SINGLE_CHAR_PAT)) + parseError("Expected a character", m); + return m.group(0).charAt(0); + } + static int parseFlags(String s, Matcher m) throws ParseError { int flags = 0; @@ -121,6 +118,7 @@ public final class KeyValueParser ATTR_PAT = Pattern.compile("\\s*(\\w+)\\s*="); QUOTED_PAT = Pattern.compile("'(([^'\\\\]+|\\\\')*)'"); PAYLOAD_START_PAT = Pattern.compile("\\s*:"); + SINGLE_CHAR_PAT = Pattern.compile("."); } static void parseError(String msg, Matcher m) throws ParseError |
