Add input command

master
Raheman Vaiya 4 years ago
parent 5fc6cde3de
commit 9599960804
  1. 9
      data/keyd.compose
  2. 1
      data/unicode.txt
  3. 21
      scripts/generate_xcompose
  4. 2
      src/config.c
  5. 69
      src/daemon.c
  6. 23
      src/keyboard.c
  7. 1
      src/keyboard.h
  8. 20
      src/keyd.c
  9. 2
      src/keyd.h
  10. 23
      src/unicode.c
  11. 3
      src/unicode.h
  12. 18
      t/macro-unicode-2.t
  13. 16
      t/macro-unicode.t

@ -34486,7 +34486,8 @@
<Cancel> <q> <l> <x> : "󠇭"
<Cancel> <q> <l> <y> : "󠇮"
<Cancel> <q> <l> <z> : "󠇯"
<Cancel> <q> <m> <0> : "󰀀"
<Cancel> <q> <m> <1> : "󿿽"
<Cancel> <q> <m> <2> : "􀀀"
<Cancel> <q> <m> <3> : "􏿽"
<Cancel> <q> <m> <0> : "私"
<Cancel> <q> <m> <1> : "󰀀"
<Cancel> <q> <m> <2> : "󿿽"
<Cancel> <q> <m> <3> : "􀀀"
<Cancel> <q> <m> <4> : "􏿽"

@ -34620,6 +34620,7 @@ E01EC;VARIATION SELECTOR-253;Mn;0;NSM;;;;;N;;;;;
E01ED;VARIATION SELECTOR-254;Mn;0;NSM;;;;;N;;;;;
E01EE;VARIATION SELECTOR-255;Mn;0;NSM;;;;;N;;;;;
E01EF;VARIATION SELECTOR-256;Mn;0;NSM;;;;;N;;;;;
079C1;VARIATION SELECTOR-256;Mn;0;NSM;;;;;N;;;;;
F0000;<Plane 15 Private Use, First>;Co;0;L;;;;;N;;;;;
FFFFD;<Plane 15 Private Use, Last>;Co;0;L;;;;;N;;;;;
100000;<Plane 16 Private Use, First>;Co;0;L;;;;;N;;;;;

@ -49,10 +49,12 @@ open('src/unicode.c', 'w').write(f'''
#include <stdint.h>
#include <stdlib.h>
#include "keys.h"
uint32_t unicode_table[] = {{ {','.join(map(str, codes))} }};
int lookup_xcompose_index(uint32_t codepoint) {{
int unicode_lookup_index(uint32_t codepoint)
{{
size_t i = 0;
for(i = 0; i < sizeof(unicode_table)/sizeof(unicode_table[0]); i++) {{
@ -62,6 +64,23 @@ open('src/unicode.c', 'w').write(f'''
return -1;
}}
void unicode_get_sequence(int idx, uint8_t codes[4])
{{
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] = KEYD_CANCEL;
codes[1] = chars[idx / (36 * 36) % 36];
codes[2] = chars[idx / 36 % 36];
codes[3] = chars[idx % 36];
}}
'''
.replace('\n\t', '\n')
.lstrip()

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

@ -242,6 +242,69 @@ static void send_fail(int con, const char *fmt, ...)
va_end(args);
}
static int input(char *buf, size_t sz)
{
size_t i;
uint32_t codepoint;
uint8_t code;
uint8_t codes[4];
int csz;
while ((csz = utf8_read_char(buf, &codepoint))) {
int found = 0;
char s[2];
if (csz == 1) {
uint8_t code, mods;
s[0] = (char)codepoint;
s[1] = 0;
found = 1;
if (!parse_key_sequence(s, &code, &mods)) {
if (mods & MOD_SHIFT) {
vkbd_send_key(vkbd, KEYD_LEFTSHIFT, 1);
vkbd_send_key(vkbd, code, 1);
vkbd_send_key(vkbd, code, 0);
vkbd_send_key(vkbd, KEYD_LEFTSHIFT, 0);
} else {
vkbd_send_key(vkbd, code, 1);
vkbd_send_key(vkbd, code, 0);
}
} else if ((char)codepoint == ' ') {
vkbd_send_key(vkbd, KEYD_SPACE, 1);
vkbd_send_key(vkbd, KEYD_SPACE, 0);
} else if ((char)codepoint == '\n') {
vkbd_send_key(vkbd, KEYD_ENTER, 1);
vkbd_send_key(vkbd, KEYD_ENTER, 0);
} else if ((char)codepoint == '\t') {
vkbd_send_key(vkbd, KEYD_TAB, 1);
vkbd_send_key(vkbd, KEYD_TAB, 0);
} else {
found = 0;
}
}
if (!found) {
int idx = unicode_lookup_index(codepoint);
if (idx < 0) {
err("ERROR: could not find code for \"%.*s\"", csz, buf);
return -1;
}
unicode_get_sequence(idx, codes);
for (i = 0; i < 4; i++) {
vkbd_send_key(vkbd, codes[i], 1);
vkbd_send_key(vkbd, codes[i], 0);
}
}
buf+=csz;
}
return 0;
}
static void handle_client(int con)
{
struct ipc_message msg;
@ -252,6 +315,12 @@ static void handle_client(int con)
struct config_ent *ent;
int success;
case IPC_INPUT:
if (input(msg.data, msg.sz))
send_fail(con, "%s", errstr);
else
send_success(con);
break;
case IPC_RELOAD:
reload();
send_success(con);

@ -156,21 +156,6 @@ static void update_mods(struct keyboard *kbd, int excluded_layer_idx, uint8_t mo
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)
{
size_t i;
@ -182,7 +167,7 @@ static void execute_macro(struct keyboard *kbd, int dl, const struct macro *macr
switch (ent->type) {
size_t j;
uint16_t idx;
uint8_t codes[3];
uint8_t codes[4];
uint8_t code, mods;
case MACRO_HOLD:
@ -210,12 +195,10 @@ static void execute_macro(struct keyboard *kbd, int dl, const struct macro *macr
idx = ent->data;
set_mods(kbd, 0);
send_key(kbd, KEYD_CANCEL, 1);
send_key(kbd, KEYD_CANCEL, 0);
generate_unicode_sequence(idx, codes);
unicode_get_sequence(idx, codes);
for (i = 0; i < 3; i++) {
for (i = 0; i < 4; i++) {
send_key(kbd, codes[i], 1);
send_key(kbd, codes[i], 0);
}

@ -7,6 +7,7 @@
#define KEYBOARD_H
#include "keyd.h"
#include "unicode.h"
#include "config.h"
#include "device.h"

@ -96,6 +96,25 @@ static int add_bindings(int argc, char *argv[])
return ret;
}
static int input(int argc, char *argv[])
{
size_t sz = 0;
char buf[MAX_IPC_MESSAGE_SIZE];
while (1) {
size_t n;
if ((n = read(0, buf+sz, sizeof(buf)-sz)) <= 0)
break;
sz += n;
if (sizeof(buf) == sz)
die("maxiumum input length exceeded");
}
return ipc_exec(IPC_INPUT, buf, sz);
}
static int layer_listen(int argc, char *argv[])
{
struct ipc_message msg;
@ -141,6 +160,7 @@ struct {
/* Keep -e and -m for backward compatibility. TODO: remove these at some point. */
{"monitor", "-m", "--monitor", monitor},
{"bind", "-e", "--expression", add_bindings},
{"input", "", "", input},
{"listen", "", "", layer_listen},

@ -34,6 +34,7 @@
#include "keyboard.h"
#include "keys.h"
#include "vkbd.h"
#include "string.h"
#define MAX_IPC_MESSAGE_SIZE 4096
@ -70,6 +71,7 @@ struct ipc_message {
IPC_FAIL,
IPC_BIND,
IPC_INPUT,
IPC_RELOAD,
IPC_LAYER_LISTEN,
} type;

File diff suppressed because one or more lines are too long

@ -60,6 +60,7 @@
*/
int lookup_xcompose_index(uint32_t codepoint);
int unicode_lookup_index(uint32_t codepoint);
void unicode_get_sequence(int idx, uint8_t codes[4]);
#endif

@ -9,17 +9,11 @@ control up
1 up
cancel down
cancel up
3 down
3 up
2 down
2 up
3 down
3 up
3 down
3 up
4 down
4 up
2 down
2 up
o down
o up
y down
y up
6 down
6 up
control down
control up

@ -3,13 +3,9 @@
cancel down
cancel up
3 down
3 up
2 down
2 up
3 down
3 up
3 down
3 up
4 down
4 up
o down
o up
y down
y up
6 down
6 up

Loading…
Cancel
Save