Remote: forward the physical keyboard and hide the phone OSK while typing
CI / test (push) Failing after 1m7s

The web UI now sends key events without opening the KB bar, and releases
held keys on blur, hide or disconnect. The first remote keystroke (web or
VNC) turns the on-screen keyboard off; it comes back when the last typing
client disconnects, unless the user toggled it by hand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Opus 5.5 committed 2026-11-29 14:27:17 -08:00
1 parent 5e62f1b8cb
commit 0356413bb2
7 files changed
+411 -26

No files matched your search

+100 -4
View File
@@ -264,6 +264,10 @@ typedef struct {
int fd;
RemoteApp *app;
uint32_t held_mods;
uint32_t mod_keys_mask;
uint32_t down_ev[16];
int down_ev_len;
int osk_suppressed;
uint32_t acked_id;
uint32_t next_frame_id;
int quality;
@@ -282,6 +286,55 @@ static void ws_send_status(WsState *ws) {
}
}
static uint32_t ws_mods_from_mask(uint32_t m) {
return ((m & 0x03u) ? 1u : 0u) |
((m & 0x0Cu) ? 4u : 0u) |
((m & 0x30u) ? 8u : 0u) |
((m & 0xC0u) ? 64u : 0u);
}
static int ws_mod_evdev_bit(uint32_t ev) {
switch (ev) {
case 42u: return 0;
case 54u: return 1;
case 29u: return 2;
case 97u: return 3;
case 56u: return 4;
case 100u: return 5;
case 125u: return 6;
case 126u: return 7;
default: return -1;
}
}
static void ws_release_all(WsState *ws) {
char cmd[64];
for (int i = 0; i < ws->down_ev_len; i++) {
snprintf(cmd, sizeof cmd, "input-key %u 0", ws->down_ev[i]);
ctl_fire(&ws->app->ctl, cmd);
}
ws->down_ev_len = 0;
static const uint32_t mod_evdevs[8] = { 42u, 54u, 29u, 97u, 56u, 100u, 125u, 126u };
for (int i = 0; i < 8; i++) {
if (ws->mod_keys_mask & (1u << i)) {
snprintf(cmd, sizeof cmd, "input-key %u 0", mod_evdevs[i]);
ctl_fire(&ws->app->ctl, cmd);
}
}
int had_mods = (ws->mod_keys_mask != 0 || ws->held_mods != 0);
ws->mod_keys_mask = 0;
ws->held_mods = 0;
if (had_mods) ctl_fire(&ws->app->ctl, "input-mods 0 0 0 0");
}
static void ws_note_key_activity(WsState *ws) {
if (!ws->osk_suppressed) {
remote_osk_suppress_acquire(ws->app, &ws->osk_suppressed);
ws->last_status_json[0] = 0;
ws_send_status(ws);
}
}
static void ws_handle_text(WsState *ws, const char *msg) {
char type[32] = {0};
if (!json_get_str(msg, "t", type, sizeof type)) return;
@@ -346,9 +399,14 @@ static void ws_handle_text(WsState *ws, const char *msg) {
}
return;
}
if (strcmp(type, "release") == 0) {
ws_release_all(ws);
return;
}
if (strcmp(type, "ktap") == 0) {
long code = 0, mods = 0;
if (json_get_int(msg, "c", &code) && code > 0) {
ws_note_key_activity(ws);
json_get_int(msg, "m", &mods);
char cmd[64];
snprintf(cmd, sizeof cmd, "input-key-tap %ld %ld", code, mods);
@@ -360,19 +418,51 @@ static void ws_handle_text(WsState *ws, const char *msg) {
long sym = 0, down = 1;
if (!json_get_int(msg, "k", &sym)) return;
json_get_int(msg, "d", &down);
if (down) ws_note_key_activity(ws);
uint32_t ev = 0, uc = 0;
int sh = 0, mod_bit = 0;
if (!keysym_to_evdev((uint32_t)sym, &ev, &sh, &mod_bit, &uc)) return;
if (uc != 0) {
if (down) remote_send_codepoint(&ws->app->ctl, uc);
return;
}
if (mod_bit == 2) { /* CapsLock */
char cmd[64];
snprintf(cmd, sizeof cmd, "input-key %u %d", ev, down ? 1 : 0);
ctl_fire(&ws->app->ctl, cmd);
return;
}
if (mod_bit) {
if (down) ws->held_mods |= (uint32_t)mod_bit;
else ws->held_mods &= ~(uint32_t)mod_bit;
int bit = ws_mod_evdev_bit(ev);
if (bit >= 0) {
if (down) ws->mod_keys_mask |= (1u << bit);
else ws->mod_keys_mask &= ~(1u << bit);
}
ws->held_mods = ws_mods_from_mask(ws->mod_keys_mask);
char cmd[64];
snprintf(cmd, sizeof cmd, "input-mods %u 0 0 0", ws->held_mods);
ctl_fire(&ws->app->ctl, cmd);
snprintf(cmd, sizeof cmd, "input-key %u %d", ev, down ? 1 : 0);
ctl_fire(&ws->app->ctl, cmd);
} else if (ev) {
uint32_t em = ws->held_mods | (sh ? 1u : 0u);
if (down) {
int found = 0;
for (int i = 0; i < ws->down_ev_len; i++) {
if (ws->down_ev[i] == ev) { found = 1; break; }
}
if (!found && ws->down_ev_len < 16) ws->down_ev[ws->down_ev_len++] = ev;
} else {
for (int i = 0; i < ws->down_ev_len; i++) {
if (ws->down_ev[i] == ev) {
for (int j = i + 1; j < ws->down_ev_len; j++) ws->down_ev[j - 1] = ws->down_ev[j];
ws->down_ev_len--;
break;
}
}
}
uint32_t em = (sym > 0x20 && sym <= 0x7E && (ws->held_mods & ~1u) == 0)
? (sh ? 1u : 0u)
: (ws->held_mods | (sh ? 1u : 0u));
char cmd[64];
if (em != ws->held_mods) {
snprintf(cmd, sizeof cmd, "input-mods %u 0 0 0", em);
@@ -390,6 +480,7 @@ static void ws_handle_text(WsState *ws, const char *msg) {
if (strcmp(type, "text") == 0) {
char txt[1024] = {0};
if (json_get_str(msg, "s", txt, sizeof txt) && txt[0]) {
ws_note_key_activity(ws);
remote_send_utf8_text(&ws->app->ctl, txt);
}
return;
@@ -411,6 +502,10 @@ static void ws_handle_text(WsState *ws, const char *msg) {
if (strcmp(type, "ctl") == 0) {
char cstr[128] = {0};
if (json_get_str(msg, "cmd", cstr, sizeof cstr) && ctl_command_allowed(cstr)) {
if (strncmp(cstr, "osk ", 4) == 0) {
remote_osk_manual_override(ws->app);
ws->osk_suppressed = 1;
}
ctl_fire(&ws->app->ctl, cstr);
ws->last_status_json[0] = 0;
ws_send_status(ws);
@@ -602,7 +697,8 @@ static void ws_loop(RemoteApp *app, int fd) {
}
out:
if (ws.held_mods) ctl_fire(&app->ctl, "input-mods 0 0 0 0");
ws_release_all(&ws);
remote_osk_suppress_release(app, &ws.osk_suppressed);
if (tj) tjDestroy(tj);
fb_reader_close(&fb);
free(scratch);