]> git.sesse.net Git - pistorm/commitdiff
handle keyboard/mouse autoconnect
authorjust nine <nine@aphlor.org>
Wed, 14 Apr 2021 22:17:02 +0000 (23:17 +0100)
committerjust nine <nine@aphlor.org>
Wed, 14 Apr 2021 22:17:02 +0000 (23:17 +0100)
config_file/config_file.c
config_file/config_file.h
default.cfg
emulator.c

index 960d30930501c4c3d8f690746960cfae25332e4a..69ef9f0cbf9c3e9f6a4bf15fcdcb5e7cef738201 100644 (file)
@@ -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, ' ');
index 3af4758bc477b5369a79dbd57c150e7cef98bc8b..54931aece0cb27357bb73105a28defc72ecf2762 100644 (file)
@@ -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;
index bec305a265203459b119ca04d30ceddd02dc1912..76d49e01156de2fa2f81b3b66615c2507c942a24 100644 (file)
@@ -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
index 3fd6ff880c0d0a35dad4471cab90e36c12ad625a..1174bd06f455e61f6fa2852d3214a0b6c5313ecf 100644 (file)
@@ -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);