From: just nine Date: Wed, 14 Apr 2021 22:17:02 +0000 (+0100) Subject: handle keyboard/mouse autoconnect X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=3f6d1947e22905f326ab25d06033082015dfabb3;p=pistorm handle keyboard/mouse autoconnect --- diff --git a/config_file/config_file.c b/config_file/config_file.c index 960d309..69ef9f0 100644 --- a/config_file/config_file.c +++ b/config_file/config_file.c @@ -350,6 +350,8 @@ struct emulator_config *load_config_file(char *filename) { strcpy(cfg->mouse_file, cur_cmd); get_next_string(parse_line, cur_cmd, &str_pos, ' '); cfg->mouse_toggle_key = cur_cmd[0]; + get_next_string(parse_line, cur_cmd, &str_pos, ' '); + cfg->mouse_autoconnect = (strcmp(cur_cmd, "autoconnect") == 0) ? 1 : 0; cfg->mouse_enabled = 1; printf("[CFG] Enabled mouse event forwarding from file %s, toggle key %c.\n", cfg->mouse_file, cfg->mouse_toggle_key); break; @@ -358,8 +360,14 @@ struct emulator_config *load_config_file(char *filename) { cfg->keyboard_toggle_key = cur_cmd[0]; get_next_string(parse_line, cur_cmd, &str_pos, ' '); cfg->keyboard_grab = (strcmp(cur_cmd, "grab") == 0) ? 1 : 0; - printf("[CFG] Enabled keyboard event forwarding, toggle key %c, %slocking from host.\n", - cfg->keyboard_toggle_key, cfg->keyboard_grab ? "" : "not "); + get_next_string(parse_line, cur_cmd, &str_pos, ' '); + cfg->keyboard_autoconnect = (strcmp(cur_cmd, "autoconnect") == 0) ? 1 : 0; + printf("[CFG] Enabled keyboard event forwarding, toggle key %c", cfg->keyboard_toggle_key); + if (cfg->keyboard_grab) + printf(", locking from host when connected"); + if (cfg->keyboard_autoconnect) + printf(", connected to guest at startup"); + printf(".\n"); break; case CONFITEM_KBFILE: get_next_string(parse_line, cur_cmd, &str_pos, ' '); diff --git a/config_file/config_file.h b/config_file/config_file.h index 3af4758..54931ae 100644 --- a/config_file/config_file.h +++ b/config_file/config_file.h @@ -68,7 +68,7 @@ struct emulator_config { char *mouse_file, *keyboard_file; char mouse_toggle_key, keyboard_toggle_key; - unsigned char mouse_enabled, keyboard_enabled, keyboard_grab; + unsigned char mouse_enabled, mouse_autoconnect, keyboard_enabled, keyboard_grab, keyboard_autoconnect; unsigned int loop_cycles; unsigned int mapped_low, mapped_high; diff --git a/default.cfg b/default.cfg index bec305a..76d49e0 100644 --- a/default.cfg +++ b/default.cfg @@ -42,14 +42,18 @@ platform amiga # Uncomment this line to enable the (currently non-working) Pi-Net interface. #setvar pi-net -# Forward mouse events to host system, defaults to off unless toggle key is pressed on the Pi. -# Syntax is mouse [device] [toggle key] -#mouse /dev/input/mouse0 m # Forward keyboard events to host system, defaults to off unless toggle key is pressed, toggled off using F12. -# Add the keyword "grab" to steal the keyboard from the Pi, so Amiga input does not appear on the console or in X11. -# (also helps prevent sending any ctrl-alt-del to the Amiga from resetting the Pi) -keyboard k grab +# Syntax: keyboard [grab key] [grab|nograb] [autoconnect|noautoconnect] +# "grab" steals the keyboard from the Pi so Amiga/etc. input is not sent to the Pi +# (also helps prevent sending any ctrl-alt-del to the Amiga from resetting the Pi) +# +# "autoconnect" connects the keyboard to the Amiga/etc. on startup +keyboard k nograb noautoconnect # Select a specific filename for the keyboard event source. # This is typically /dev/input/event1 or event0, but it may be event3 with for instance a wireless keyboard. # Use ls /dev/input/event* to check which event files are available and try until you find the one that works. #kbfile /dev/input/event1 +# Forward mouse events to host system, defaults to off unless toggle key is pressed on the Pi. +# Syntax is mouse [device] [toggle key] [autoconnect|noautoconnect] +# (see "keyboard" above for autoconnect description) +mouse /dev/input/mice m noautoconnect diff --git a/emulator.c b/emulator.c index 3fd6ff8..1174bd0 100644 --- a/emulator.c +++ b/emulator.c @@ -240,7 +240,6 @@ cpu_loop: // printf("CPU emulation reset.\n"); } - if (mouse_hook_enabled && (mouse_extra != 0x00)) { // mouse wheel events have occurred; unlike l/m/r buttons, these are queued as keypresses, so add to end of buffer switch (mouse_extra) { @@ -520,6 +519,12 @@ int main(int argc, char *argv[]) { printf("Failed to open keyboard event source.\n"); } + if (cfg->mouse_autoconnect) + mouse_hook_enabled = 1; + + if (cfg->keyboard_autoconnect) + kb_hook_enabled = 1; + InitGayle(); signal(SIGINT, sigint_handler);