unicode: Reduce compose sequence size (#285)

This patch reduces the compose sequence size by making use of keysyms a-z.
This is mainly done to improve support for programs with broken XCompose logic
(i.e chrome). A consequence of this is that the user will need to be using
the standard US layout on their display server to make use of unicode support.
master
Raheman Vaiya 4 years ago
parent b3af741cd0
commit 2507ac7d7e
  1. BIN
      data/keyd-application-mapper.1.gz
  2. BIN
      data/keyd.1.gz
  3. 68984
      data/keyd.compose
  4. 6
      docs/keyd.scdoc
  5. 17
      scripts/generate_xcompose
  6. 2
      src/config.c
  7. 4
      src/daemon.c
  8. 31
      src/keyboard.c
  9. 2
      src/unicode.c
  10. 6
      src/unicode.h

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

@ -310,7 +310,11 @@ E.G
ln -s /usr/share/keyd/keyd.compose ~/.XCompose ln -s /usr/share/keyd/keyd.compose ~/.XCompose
*Note:* You may have to restart your applications for this to take effect. **Additionally you will need to be using the default US layout on your
display server.** Users of non-english layouts are advised to set their layout
within keyd (see **Layouts**).
**Note:** You may have to restart your applications for this to take effect.
## Aliases ## Aliases

@ -15,12 +15,25 @@ for line in open('data/unicode.txt').readlines(): # Original source: https://www
except: except:
pass pass
# We use the base36 encoded index as the compose sequence to minimize
# the total number of keysyms required.
def base36(n):
chars = '0123456789abcdefghijklmnopqrstuvwxyz'
s = ''
s += chars[n // (len(chars)*len(chars)) % len(chars)]
s += chars[n // len(chars) % len(chars)]
s += chars[n % len(chars)]
return s
# Generate the compose file # Generate the compose file
data = '' data = ''
for n, code in enumerate(codes): for n, code in enumerate(codes):
data += '<Cancel> ' data += '<Cancel> '
data += ' '.join(f'<{c}>' for c in ('%05d' % n)) data += ' '.join(f'<{c}>' for c in base36(n))
data += f' : "{chr(code)}"\n' data += f' : "{chr(code)}"\n'
open('data/keyd.compose', 'w').write(data) open('data/keyd.compose', 'w').write(data)
@ -39,7 +52,7 @@ open('src/unicode.c', 'w').write(f'''
uint32_t unicode_table[] = {{ {','.join(map(str, codes))} }}; uint32_t unicode_table[] = {{ {','.join(map(str, codes))} }};
int lookup_xcompose_code(uint32_t codepoint) {{ int lookup_xcompose_index(uint32_t codepoint) {{
size_t i = 0; size_t i = 0;
for(i = 0; i < sizeof(unicode_table)/sizeof(unicode_table[0]); i++) {{ for(i = 0; i < sizeof(unicode_table)/sizeof(unicode_table[0]); i++) {{

@ -498,7 +498,7 @@ int parse_macro_expression(const char *s, struct macro *macro)
break; break;
} }
} }
} else if ((xcode = lookup_xcompose_code(codepoint)) > 0) } else if ((xcode = lookup_xcompose_index(codepoint)) > 0)
ADD_ENTRY(MACRO_UNICODE, xcode); ADD_ENTRY(MACRO_UNICODE, xcode);
tok += chrsz; tok += chrsz;

@ -210,7 +210,7 @@ static void reload()
static void send_success(int con) static void send_success(int con)
{ {
struct ipc_message msg; struct ipc_message msg = {0};
msg.type = IPC_SUCCESS;; msg.type = IPC_SUCCESS;;
msg.sz = 0; msg.sz = 0;
@ -221,7 +221,7 @@ static void send_success(int con)
static void send_fail(int con, const char *fmt, ...) static void send_fail(int con, const char *fmt, ...)
{ {
struct ipc_message msg; struct ipc_message msg = {0};
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);

@ -156,6 +156,21 @@ static void update_mods(struct keyboard *kbd, int excluded_layer_idx, uint8_t mo
set_mods(kbd, mods); set_mods(kbd, mods);
} }
static void generate_unicode_sequence(int idx, uint8_t codes[3])
{
uint8_t chars[] = {
KEYD_0, KEYD_1, KEYD_2, KEYD_3, KEYD_4, KEYD_5, KEYD_6, KEYD_7,
KEYD_8, KEYD_9, KEYD_A, KEYD_B, KEYD_C, KEYD_D, KEYD_E, KEYD_F,
KEYD_G, KEYD_H, KEYD_I, KEYD_J, KEYD_K, KEYD_L, KEYD_M, KEYD_N,
KEYD_O, KEYD_P, KEYD_Q, KEYD_R, KEYD_S, KEYD_T, KEYD_U, KEYD_V,
KEYD_W, KEYD_X, KEYD_Y, KEYD_Z
};
codes[0] = chars[idx / (36 * 36) % 36];
codes[1] = chars[idx / 36 % 36];
codes[2] = chars[idx % 36];
}
static void execute_macro(struct keyboard *kbd, int dl, const struct macro *macro) static void execute_macro(struct keyboard *kbd, int dl, const struct macro *macro)
{ {
size_t i; size_t i;
@ -166,7 +181,8 @@ static void execute_macro(struct keyboard *kbd, int dl, const struct macro *macr
switch (ent->type) { switch (ent->type) {
size_t j; size_t j;
uint16_t n; uint16_t idx;
uint8_t codes[3];
uint8_t code, mods; uint8_t code, mods;
case MACRO_HOLD: case MACRO_HOLD:
@ -191,20 +207,19 @@ static void execute_macro(struct keyboard *kbd, int dl, const struct macro *macr
} }
break; break;
case MACRO_UNICODE: case MACRO_UNICODE:
n = ent->data; idx = ent->data;
set_mods(kbd, 0); set_mods(kbd, 0);
send_key(kbd, KEYD_CANCEL, 1); send_key(kbd, KEYD_CANCEL, 1);
send_key(kbd, KEYD_CANCEL, 0); send_key(kbd, KEYD_CANCEL, 0);
for (j = 10000; j; j /= 10) { generate_unicode_sequence(idx, codes);
int digit = n / j;
code = digit == 0 ? KEYD_0 : digit - 1 + KEYD_1;
send_key(kbd, code, 1); for (i = 0; i < 3; i++) {
send_key(kbd, code, 0); send_key(kbd, codes[i], 1);
n %= j; send_key(kbd, codes[i], 0);
} }
break; break;
case MACRO_KEYSEQUENCE: case MACRO_KEYSEQUENCE:
code = ent->data; code = ent->data;

File diff suppressed because one or more lines are too long

@ -47,8 +47,8 @@
* In order to satisfy the above constraints, we create an XCompose file * In order to satisfy the above constraints, we create an XCompose file
* mapping each codepoint's index in a lookup table to the desired utf8 * mapping each codepoint's index in a lookup table to the desired utf8
* sequence. The use of a table index instead of the codepoint value ensures * sequence. The use of a table index instead of the codepoint value ensures
* all codepoints consist of a maximum of 5 decimal digits (since there are * all codepoints consist of a maximum of 3 base36 encoded digits (since there are
* <35k of them). Each codepoint is zero-left padded to 5 characters to avoid * <35k of them). Each codepoint is zero-left padded to 3 characters to avoid
* the subset issue. * the subset issue.
* *
* Finally, we use cancel as our compose prefix so the user doesn't have to * Finally, we use cancel as our compose prefix so the user doesn't have to
@ -60,6 +60,6 @@
*/ */
int lookup_xcompose_code(uint32_t codepoint); int lookup_xcompose_index(uint32_t codepoint);
#endif #endif

Loading…
Cancel
Save