Skip to content

Commit 2aff96d

Browse files
authored
Merge pull request #11 from ZaparooProject/fix/zaparoo-launcher-keyboard-input
fix(zaparoo): forward keyboard input to launcher frontend
2 parents 5d28969 + 0b26291 commit 2aff96d

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

input.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3897,6 +3897,14 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int
38973897
}
38983898

38993899
if (ev->code == KEY_HOMEPAGE) ev->code = KEY_MENU;
3900+
3901+
// Bridge keys to the launcher's uinput instead of the core (see alt_launcher.h).
3902+
if (alt_launcher_kbd_to_frontend(ev->code))
3903+
{
3904+
if (ev->value <= 1) uinp_send_key(ev->code, ev->value);
3905+
return;
3906+
}
3907+
39003908
if (send_key) user_io_kbd(ev->code, ev->value);
39013909
return;
39023910
}
@@ -5528,7 +5536,7 @@ int input_test(int getchar)
55285536
//Works only through cable or USB dongle.
55295537
if (input[n].vid == 0x045e && input[n].pid == 0x0b00) input[n].quirk = QUIRK_SHIFT;
55305538

5531-
ioctl(pool[n].fd, EVIOCGRAB, (grabbed | user_io_osd_is_visible()) ? 1 : 0);
5539+
ioctl(pool[n].fd, EVIOCGRAB, (grabbed | user_io_osd_is_visible() | alt_launcher_kbd_grab(pool[n].fd)) ? 1 : 0);
55325540

55335541
n++;
55345542
if (n >= NUMDEV) break;
@@ -6463,7 +6471,7 @@ void input_switch(int grab)
64636471

64646472
for (int i = 0; i < NUMDEV; i++)
64656473
{
6466-
if (pool[i].fd >= 0) ioctl(pool[i].fd, EVIOCGRAB, (grabbed | user_io_osd_is_visible()) ? 1 : 0);
6474+
if (pool[i].fd >= 0) ioctl(pool[i].fd, EVIOCGRAB, (grabbed | user_io_osd_is_visible() | alt_launcher_kbd_grab(pool[i].fd)) ? 1 : 0);
64676475
}
64686476
}
64696477

support/zaparoo/alt_launcher.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,28 @@ uint16_t alt_launcher_fb_terminal_key(uint32_t mask, bool osd_button)
6565
return 0;
6666
}
6767

68+
// Standard keyboards report letters + ESC; gamepads/mice report BTN_* instead.
69+
static bool fd_is_keyboard(int fd)
70+
{
71+
if (fd < 0) return false;
72+
unsigned char kb[(KEY_MAX + 7) / 8] = {};
73+
if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(kb)), kb) < 0) return false;
74+
#define BIT_SET(b) (kb[(b) / 8] & (1 << ((b) % 8)))
75+
return BIT_SET(KEY_ESC) && BIT_SET(KEY_A) && BIT_SET(KEY_Z);
76+
#undef BIT_SET
77+
}
78+
79+
int alt_launcher_kbd_grab(int fd)
80+
{
81+
return (alt_launcher_active() && fd_is_keyboard(fd)) ? 1 : 0;
82+
}
83+
84+
bool alt_launcher_kbd_to_frontend(uint16_t code)
85+
{
86+
return alt_launcher_active() && !user_io_osd_is_visible()
87+
&& code < 256 && code != KEY_MENU && code != KEY_F12;
88+
}
89+
6890
static pid_t s_pid = 0;
6991
static int s_crash_count = 0;
7092
static unsigned long s_respawn_timer = 0;

support/zaparoo/alt_launcher.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ void alt_launcher_set_v_offset(int8_t v);
2626
void alt_launcher_cfg_apply(void);
2727
uint16_t alt_launcher_fb_terminal_key(uint32_t mask, bool osd_button);
2828

29+
// Input hooks for input.cpp. While the launcher owns the screen its Qt frontend
30+
// reads keyboards directly, so we grab them (kbd_grab) and bridge keys via uinput
31+
// (kbd_to_frontend) to avoid double input; MENU/F12 and OSD-open keys are excluded.
32+
int alt_launcher_kbd_grab(int fd);
33+
bool alt_launcher_kbd_to_frontend(uint16_t code);
34+
2935
bool zaparoo_is_native_core(void);
3036
void zaparoo_alt_launcher_init_for_core(void);
3137
void zaparoo_alt_launcher_init_for_menu(void);

0 commit comments

Comments
 (0)