Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

feat: add push-to-talk support on Linux via evdev

Alcahest712b09037786
diff --git a/main.js b/main.js
index deaec069a..7ddd49200 100644
--- a/main.js
+++ b/main.js
@@ -200,6 +200,7 @@ const UpdateManager = require("./src/updater");
const GlobeKeyManager = require("./src/helpers/globeKeyManager");
const DevServerManager = require("./src/helpers/devServerManager");
const WindowsKeyManager = require("./src/helpers/windowsKeyManager");
+const LinuxKeyManager = require("./src/helpers/linuxKeyManager");
const TextEditMonitor = require("./src/helpers/textEditMonitor");
const WhisperCudaManager = require("./src/helpers/whisperCudaManager");
const GoogleCalendarManager = require("./src/helpers/googleCalendarManager");
@@ -223,6 +224,7 @@ let trayManager = null;
let updateManager = null;
let globeKeyManager = null;
let windowsKeyManager = null;
+let linuxKeyManager = null;
let textEditMonitor = null;
let whisperCudaManager = null;
let googleCalendarManager = null;
@@ -304,6 +306,7 @@ function initializeCoreManagers() {
updateManager = new UpdateManager();
updateManager.setWindowManager(windowManager);
windowsKeyManager = new WindowsKeyManager();
+ linuxKeyManager = new LinuxKeyManager();
textEditMonitor = new TextEditMonitor();
audioTapManager = new AudioTapManager();
windowManager.textEditMonitor = textEditMonitor;
@@ -318,6 +321,7 @@ function initializeCoreManagers() {
windowManager,
updateManager,
windowsKeyManager,
+ linuxKeyManager,
textEditMonitor,
whisperCudaManager,
googleCalendarManager,
@@ -1019,6 +1023,92 @@ async function startApp() {
}
});
}
+
+ if (process.platform === "linux") {
+ debugLogger.debug("[Push-to-Talk] Linux Push-to-Talk setup starting");
+
+ const {
+ isGlobeLikeHotkey: isGlobeLike,
+ isModifierOnlyHotkey,
+ } = require("./src/helpers/hotkeyManager");
+ const isValidHotkey = (hotkey) => hotkey && !isGlobeLike(hotkey);
+
+ const isRightSideMod = (hotkey) =>
+ /^Right(Control|Ctrl|Alt|Option|Shift|Super|Win|Meta|Command|Cmd)$/i.test(hotkey);
+
+ const needsNativeListener = (hotkey, mode) => {
+ if (!isValidHotkey(hotkey)) return false;
+ if (mode === "push") return true;
+ return isRightSideMod(hotkey) || isModifierOnlyHotkey(hotkey);
+ };
+
+ linuxKeyManager.on("key-down", (_key) => {
+ if (!isLiveWindow(windowManager.mainWindow)) return;
+
+ const activationMode = windowManager.getActivationMode();
+ if (activationMode === "push") {
+ windowManager.startWindowsPushToTalk();
+ } else if (activationMode === "tap") {
+ windowManager.sendToggleDictation();
+ }
+ });
+
+ linuxKeyManager.on("key-up", () => {
+ if (!isLiveWindow(windowManager.mainWindow)) return;
+
+ const activationMode = windowManager.getActivationMode();
+ if (activationMode === "push") {
+ windowManager.handleWindowsPushKeyUp();
+ }
+ });
+
+ linuxKeyManager.on("error", (error) => {
+ debugLogger.warn("[Push-to-Talk] Linux key listener error", { error: error.message });
+ });
+
+ linuxKeyManager.on("unavailable", () => {
+ debugLogger.debug(
+ "[Push-to-Talk] Linux key listener not available - falling back to toggle mode"
+ );
+ });
+
+ linuxKeyManager.on("ready", () => {
+ debugLogger.debug("[Push-to-Talk] LinuxKeyManager is ready and listening");
+ });
+
+ const startLinuxKeyListener = () => {
+ if (!isLiveWindow(windowManager.mainWindow)) return;
+ const activationMode = windowManager.getActivationMode();
+ const currentHotkey = hotkeyManager.getCurrentHotkey();
+
+ if (needsNativeListener(currentHotkey, activationMode)) {
+ linuxKeyManager.start(currentHotkey);
+ }
+ };
+
+ const STARTUP_DELAY_MS = 3000;
+ setTimeout(startLinuxKeyListener, STARTUP_DELAY_MS);
+
+ ipcMain.on("activation-mode-changed", (_event, mode) => {
+ windowManager.resetWindowsPushState();
+ const currentHotkey = hotkeyManager.getCurrentHotkey();
+ if (needsNativeListener(currentHotkey, mode)) {
+ linuxKeyManager.start(currentHotkey);
+ } else {
+ linuxKeyManager.stop();
+ }
+ });
+
+ ipcMain.on("hotkey-changed", (_event, hotkey) => {
+ if (!isLiveWindow(windowManager.mainWindow)) return;
+ windowManager.resetWindowsPushState();
+ const activationMode = windowManager.getActivationMode();
+ linuxKeyManager.stop();
+ if (needsNativeListener(hotkey, activationMode)) {
+ linuxKeyManager.start(hotkey);
+ }
+ });
+ }
}
// Listen for usage limit reached from dictation overlay, forward to control panel
@@ -1161,6 +1251,9 @@ if (gotSingleInstanceLock) {
if (windowsKeyManager) {
windowsKeyManager.stop();
}
+ if (linuxKeyManager) {
+ linuxKeyManager.stop();
+ }
if (meetingDetectionEngine) {
meetingDetectionEngine.stop();
}
diff --git a/package.json b/package.json
index 76f9d5927..6fe217489 100644
--- a/package.json
+++ b/package.json
@@ -11,13 +11,14 @@
"compile:globe": "node scripts/build-globe-listener.js",
"compile:fast-paste": "node scripts/build-macos-fast-paste.js",
"compile:winkeys": "node scripts/build-windows-key-listener.js",
+ "compile:linuxkeys": "node scripts/build-linux-key-listener.js",
"compile:text-monitor": "node scripts/build-text-monitor.js",
"compile:winpaste": "node scripts/build-windows-fast-paste.js",
"compile:linux-paste": "node scripts/build-linux-fast-paste.js",
"compile:media-remote": "node scripts/build-media-remote.js",
"compile:mic-listener": "node scripts/build-macos-mic-listener.js",
"compile:audio-tap": "node scripts/build-macos-audio-tap.js",
- "compile:native": "npm run compile:globe && npm run compile:fast-paste && npm run compile:winkeys && npm run compile:winpaste && npm run compile:linux-paste && npm run compile:text-monitor && npm run compile:media-remote && npm run compile:mic-listener && npm run compile:audio-tap",
+ "compile:native": "npm run compile:globe && npm run compile:fast-paste && npm run compile:winkeys && npm run compile:linuxkeys && npm run compile:winpaste && npm run compile:linux-paste && npm run compile:text-monitor && npm run compile:media-remote && npm run compile:mic-listener && npm run compile:audio-tap",
"prestart": "npm run compile:native && npm run download:qdrant && npm run download:embedding-model",
"start": "electron .",
"predev": "npm run compile:native && npm run download:qdrant && npm run download:embedding-model",
diff --git a/resources/linux-key-listener.c b/resources/linux-key-listener.c
new file mode 100644
index 000000000..5011ad83e
--- /dev/null
+++ b/resources/linux-key-listener.c
@@ -0,0 +1,478 @@
+/**
+ * Linux Key Listener for Push-to-Talk
+ *
+ * Uses the evdev subsystem to detect key up/down events across all keyboards.
+ * Accepts a hotkey string as command line argument (same format as Windows variant).
+ * Outputs "KEY_DOWN" and "KEY_UP" to stdout.
+ *
+ * Compile with: gcc -O2 -Wall -Wextra -o linux-key-listener linux-key-listener.c
+ */
+
+#define _GNU_SOURCE
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/input.h>
+#include <signal.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <sys/epoll.h>
+#include <sys/inotify.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#define MAX_DEVICES 64
+#define MAX_EVENTS 16
+#define INPUT_DIR "/dev/input"
+#define KEY_BITS_SIZE (KEY_MAX / 8 + 1)
+
+static volatile sig_atomic_t running = 1;
+static int hotkey_active = 0;
+
+static int require_ctrl = 0;
+static int require_alt = 0;
+static int require_shift = 0;
+static int require_super = 0;
+static int use_modifiers_only = 0;
+static int target_key = 0;
+
+static unsigned char held_keys[KEY_BITS_SIZE];
+
+static int device_fds[MAX_DEVICES];
+static int device_count = 0;
+static int epoll_fd = -1;
+
+static void signal_handler(int sig) {
+ (void)sig;
+ running = 0;
+}
+
+static int is_key_held(int code) {
+ return (held_keys[code / 8] >> (code % 8)) & 1;
+}
+
+static void set_key(int code, int pressed) {
+ if (pressed)
+ held_keys[code / 8] |= (1 << (code % 8));
+ else
+ held_keys[code / 8] &= ~(1 << (code % 8));
+}
+
+static int is_ctrl_held(void) {
+ return is_key_held(KEY_LEFTCTRL) || is_key_held(KEY_RIGHTCTRL);
+}
+
+static int is_alt_held(void) {
+ return is_key_held(KEY_LEFTALT) || is_key_held(KEY_RIGHTALT);
+}
+
+static int is_shift_held(void) {
+ return is_key_held(KEY_LEFTSHIFT) || is_key_held(KEY_RIGHTSHIFT);
+}
+
+static int is_super_held(void) {
+ return is_key_held(KEY_LEFTMETA) || is_key_held(KEY_RIGHTMETA);
+}
+
+static int modifiers_satisfied(void) {
+ if (require_ctrl && !is_ctrl_held()) return 0;
+ if (require_alt && !is_alt_held()) return 0;
+ if (require_shift && !is_shift_held()) return 0;
+ if (require_super && !is_super_held()) return 0;
+ return 1;
+}
+
+static int is_modifier_code(int code) {
+ return code == KEY_LEFTCTRL || code == KEY_RIGHTCTRL ||
+ code == KEY_LEFTALT || code == KEY_RIGHTALT ||
+ code == KEY_LEFTSHIFT || code == KEY_RIGHTSHIFT ||
+ code == KEY_LEFTMETA || code == KEY_RIGHTMETA;
+}
+
+static int is_required_modifier(int code) {
+ if (require_ctrl && (code == KEY_LEFTCTRL || code == KEY_RIGHTCTRL)) return 1;
+ if (require_alt && (code == KEY_LEFTALT || code == KEY_RIGHTALT)) return 1;
+ if (require_shift && (code == KEY_LEFTSHIFT || code == KEY_RIGHTSHIFT)) return 1;
+ if (require_super && (code == KEY_LEFTMETA || code == KEY_RIGHTMETA)) return 1;
+ return 0;
+}
+
+static void emit_key_down(void) {
+ if (!hotkey_active) {
+ hotkey_active = 1;
+ printf("KEY_DOWN\n");
+ fflush(stdout);
+ }
+}
+
+static void emit_key_up(void) {
+ if (hotkey_active) {
+ hotkey_active = 0;
+ printf("KEY_UP\n");
+ fflush(stdout);
+ }
+}
+
+static int map_key_name(const char *name) {
+ if (strcasecmp(name, "F1") == 0) return KEY_F1;
+ if (strcasecmp(name, "F2") == 0) return KEY_F2;
+ if (strcasecmp(name, "F3") == 0) return KEY_F3;
+ if (strcasecmp(name, "F4") == 0) return KEY_F4;
+ if (strcasecmp(name, "F5") == 0) return KEY_F5;
+ if (strcasecmp(name, "F6") == 0) return KEY_F6;
+ if (strcasecmp(name, "F7") == 0) return KEY_F7;
+ if (strcasecmp(name, "F8") == 0) return KEY_F8;
+ if (strcasecmp(name, "F9") == 0) return KEY_F9;
+ if (strcasecmp(name, "F10") == 0) return KEY_F10;
+ if (strcasecmp(name, "F11") == 0) return KEY_F11;
+ if (strcasecmp(name, "F12") == 0) return KEY_F12;
+
+ if (strcasecmp(name, "F13") == 0) return KEY_F13;
+ if (strcasecmp(name, "F14") == 0) return KEY_F14;
+ if (strcasecmp(name, "F15") == 0) return KEY_F15;
+ if (strcasecmp(name, "F16") == 0) return KEY_F16;
+ if (strcasecmp(name, "F17") == 0) return KEY_F17;
+ if (strcasecmp(name, "F18") == 0) return KEY_F18;
+ if (strcasecmp(name, "F19") == 0) return KEY_F19;
+ if (strcasecmp(name, "F20") == 0) return KEY_F20;
+ if (strcasecmp(name, "F21") == 0) return KEY_F21;
+ if (strcasecmp(name, "F22") == 0) return KEY_F22;
+ if (strcasecmp(name, "F23") == 0) return KEY_F23;
+ if (strcasecmp(name, "F24") == 0) return KEY_F24;
+
+ if (strcasecmp(name, "Space") == 0) return KEY_SPACE;
+ if (strcasecmp(name, "Escape") == 0 || strcasecmp(name, "Esc") == 0) return KEY_ESC;
+ if (strcasecmp(name, "Tab") == 0) return KEY_TAB;
+ if (strcasecmp(name, "Pause") == 0) return KEY_PAUSE;
+ if (strcasecmp(name, "ScrollLock") == 0) return KEY_SCROLLLOCK;
+ if (strcasecmp(name, "Insert") == 0) return KEY_INSERT;
+ if (strcasecmp(name, "Home") == 0) return KEY_HOME;
+ if (strcasecmp(name, "End") == 0) return KEY_END;
+ if (strcasecmp(name, "PageUp") == 0) return KEY_PAGEUP;
+ if (strcasecmp(name, "PageDown") == 0) return KEY_PAGEDOWN;
+
+ if (strcmp(name, "`") == 0 || strcasecmp(name, "Backquote") == 0) return KEY_GRAVE;
+
+ if (strcasecmp(name, "RightAlt") == 0 || strcasecmp(name, "RightOption") == 0) return KEY_RIGHTALT;
+ if (strcasecmp(name, "RightControl") == 0 || strcasecmp(name, "RightCtrl") == 0) return KEY_RIGHTCTRL;
+ if (strcasecmp(name, "RightShift") == 0) return KEY_RIGHTSHIFT;
+ if (strcasecmp(name, "RightSuper") == 0 || strcasecmp(name, "RightWin") == 0 ||
+ strcasecmp(name, "RightMeta") == 0 || strcasecmp(name, "RightCommand") == 0 ||
+ strcasecmp(name, "RightCmd") == 0) return KEY_RIGHTMETA;
+
+ if (strlen(name) == 1) {
+ char c = name[0];
+ if (c >= 'a' && c <= 'z') c = c - 'a' + 'A';
+ switch (c) {
+ case 'A': return KEY_A; case 'B': return KEY_B; case 'C': return KEY_C;
+ case 'D': return KEY_D; case 'E': return KEY_E; case 'F': return KEY_F;
+ case 'G': return KEY_G; case 'H': return KEY_H; case 'I': return KEY_I;
+ case 'J': return KEY_J; case 'K': return KEY_K; case 'L': return KEY_L;
+ case 'M': return KEY_M; case 'N': return KEY_N; case 'O': return KEY_O;
+ case 'P': return KEY_P; case 'Q': return KEY_Q; case 'R': return KEY_R;
+ case 'S': return KEY_S; case 'T': return KEY_T; case 'U': return KEY_U;
+ case 'V': return KEY_V; case 'W': return KEY_W; case 'X': return KEY_X;
+ case 'Y': return KEY_Y; case 'Z': return KEY_Z;
+ case '0': return KEY_0; case '1': return KEY_1; case '2': return KEY_2;
+ case '3': return KEY_3; case '4': return KEY_4; case '5': return KEY_5;
+ case '6': return KEY_6; case '7': return KEY_7; case '8': return KEY_8;
+ case '9': return KEY_9;
+ case '-': return KEY_MINUS; case '=': return KEY_EQUAL;
+ case '[': return KEY_LEFTBRACE; case ']': return KEY_RIGHTBRACE;
+ case '\\': return KEY_BACKSLASH; case ';': return KEY_SEMICOLON;
+ case '\'': return KEY_APOSTROPHE; case ',': return KEY_COMMA;
+ case '.': return KEY_DOT; case '/': return KEY_SLASH;
+ }
+ }
+
+ return -1;
+}
+
+static void parse_hotkey(const char *hotkey) {
+ char buf[256];
+ strncpy(buf, hotkey, sizeof(buf) - 1);
+ buf[sizeof(buf) - 1] = '\0';
+
+ require_ctrl = 0;
+ require_alt = 0;
+ require_shift = 0;
+ require_super = 0;
+ use_modifiers_only = 0;
+ target_key = 0;
+
+ char *token = strtok(buf, "+");
+ while (token) {
+ while (*token == ' ') token++;
+ char *end = token + strlen(token) - 1;
+ while (end > token && *end == ' ') *end-- = '\0';
+
+ if (strcasecmp(token, "CommandOrControl") == 0 ||
+ strcasecmp(token, "Control") == 0 ||
+ strcasecmp(token, "Ctrl") == 0 ||
+ strcasecmp(token, "CmdOrCtrl") == 0) {
+ require_ctrl = 1;
+ } else if (strcasecmp(token, "Alt") == 0 ||
+ strcasecmp(token, "Option") == 0) {
+ require_alt = 1;
+ } else if (strcasecmp(token, "Shift") == 0) {
+ require_shift = 1;
+ } else if (strcasecmp(token, "Super") == 0 ||
+ strcasecmp(token, "Meta") == 0 ||
+ strcasecmp(token, "Win") == 0 ||
+ strcasecmp(token, "Command") == 0 ||
+ strcasecmp(token, "Cmd") == 0) {
+ require_super = 1;
+ } else {
+ int code = map_key_name(token);
+ if (code >= 0)
+ target_key = code;
+ }
+
+ token = strtok(NULL, "+");
+ }
+
+ if (target_key == 0 && (require_ctrl || require_alt || require_shift || require_super))
+ use_modifiers_only = 1;
+}
+
+static int is_keyboard_device(int fd) {
+ unsigned long ev_bits = 0;
+ if (ioctl(fd, EVIOCGBIT(0, sizeof(ev_bits)), &ev_bits) < 0)
+ return 0;
+ if (!(ev_bits & (1UL << EV_KEY)))
+ return 0;
+
+ unsigned char key_bits[KEY_BITS_SIZE];
+ memset(key_bits, 0, sizeof(key_bits));
+ if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bits)), key_bits) < 0)
+ return 0;
+
+ return (key_bits[KEY_A / 8] >> (KEY_A % 8)) & 1;
+}
+
+static int add_device(const char *path) {
+ if (device_count >= MAX_DEVICES)
+ return -1;
+
+ int fd = open(path, O_RDONLY | O_NONBLOCK);
+ if (fd < 0) {
+ if (errno == EACCES)
+ fprintf(stderr, "Permission denied: %s (try running with sudo or adding user to 'input' group)\n", path);
+ return -1;
+ }
+
+ if (!is_keyboard_device(fd)) {
+ close(fd);
+ return -1;
+ }
+
+ struct epoll_event ev = { .events = EPOLLIN, .data.fd = fd };
+ if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev) < 0) {
+ close(fd);
+ return -1;
+ }
+
+ device_fds[device_count++] = fd;
+
+ char name[256] = "Unknown";
+ ioctl(fd, EVIOCGNAME(sizeof(name)), name);
+ fprintf(stderr, "Monitoring keyboard: %s (%s)\n", name, path);
+ return fd;
+}
+
+static void remove_device(int fd) {
+ epoll_ctl(epoll_fd, EPOLL_CTL_DEL, fd, NULL);
+ close(fd);
+
+ for (int i = 0; i < device_count; i++) {
+ if (device_fds[i] == fd) {
+ device_fds[i] = device_fds[--device_count];
+ break;
+ }
+ }
+}
+
+static void scan_devices(void) {
+ DIR *dir = opendir(INPUT_DIR);
+ if (!dir) return;
+
+ struct dirent *ent;
+ while ((ent = readdir(dir))) {
+ if (strncmp(ent->d_name, "event", 5) != 0)
+ continue;
+
+ char path[512];
+ snprintf(path, sizeof(path), "%s/%s", INPUT_DIR, ent->d_name);
+
+ int already_open = 0;
+ for (int i = 0; i < device_count; i++) {
+ char fd_path[64], real_path[512];
+ snprintf(fd_path, sizeof(fd_path), "/proc/self/fd/%d", device_fds[i]);
+ ssize_t len = readlink(fd_path, real_path, sizeof(real_path) - 1);
+ if (len > 0) {
+ real_path[len] = '\0';
+ if (strcmp(real_path, path) == 0) {
+ already_open = 1;
+ break;
+ }
+ }
+ }
+ if (!already_open)
+ add_device(path);
+ }
+ closedir(dir);
+}
+
+static void reset_held_keys(void) {
+ memset(held_keys, 0, sizeof(held_keys));
+
+ for (int i = 0; i < device_count; i++) {
+ unsigned char keys[KEY_BITS_SIZE];
+ memset(keys, 0, sizeof(keys));
+ if (ioctl(device_fds[i], EVIOCGKEY(sizeof(keys)), keys) == 0) {
+ for (int b = 0; b < KEY_BITS_SIZE; b++)
+ held_keys[b] |= keys[b];
+ }
+ }
+}
+
+static void handle_key_event(int code, int value) {
+ if (value == 2)
+ return;
+
+ int pressed = (value == 1);
+ set_key(code, pressed);
+
+ if (hotkey_active && !pressed && is_required_modifier(code) && !modifiers_satisfied()) {
+ emit_key_up();
+ return;
+ }
+
+ if (use_modifiers_only) {
+ if (pressed && is_modifier_code(code) && modifiers_satisfied())
+ emit_key_down();
+ else if (!pressed && hotkey_active && !modifiers_satisfied())
+ emit_key_up();
+ return;
+ }
+
+ if (code == target_key) {
+ if (pressed && !hotkey_active && modifiers_satisfied())
+ emit_key_down();
+ else if (!pressed && hotkey_active)
+ emit_key_up();
+ }
+}
+
+int main(int argc, char *argv[]) {
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s <key>\n", argv[0]);
+ fprintf(stderr, "Examples:\n");
+ fprintf(stderr, " %s ` (backtick)\n", argv[0]);
+ fprintf(stderr, " %s F8 (function key)\n", argv[0]);
+ fprintf(stderr, " %s CommandOrControl+F11 (with modifier)\n", argv[0]);
+ fprintf(stderr, " %s Ctrl+Shift+Space (multiple modifiers)\n", argv[0]);
+ fprintf(stderr, " %s Control+Super (modifier-only combo)\n", argv[0]);
+ return 1;
+ }
+
+ parse_hotkey(argv[1]);
+
+ if (target_key == 0 && !use_modifiers_only) {
+ fprintf(stderr, "Error: unrecognized key in '%s'\n", argv[1]);
+ return 1;
+ }
+
+ fprintf(stderr, "Listening for: %s (code=%d, ctrl=%d, alt=%d, shift=%d, super=%d, mod_only=%d)\n",
+ argv[1], target_key, require_ctrl, require_alt, require_shift, require_super, use_modifiers_only);
+
+ struct sigaction sa = { .sa_handler = signal_handler, .sa_flags = 0 };
+ sigemptyset(&sa.sa_mask);
+ sigaction(SIGTERM, &sa, NULL);
+ sigaction(SIGINT, &sa, NULL);
+ signal(SIGPIPE, SIG_IGN);
+
+ epoll_fd = epoll_create1(0);
+ if (epoll_fd < 0) {
+ fprintf(stderr, "Error: epoll_create1 failed: %s\n", strerror(errno));
+ return 1;
+ }
+
+ int inotify_fd = inotify_init1(IN_NONBLOCK);
+ if (inotify_fd < 0) {
+ fprintf(stderr, "Warning: inotify_init1 failed, hotplug detection disabled\n");
+ } else {
+ inotify_add_watch(inotify_fd, INPUT_DIR, IN_CREATE | IN_DELETE);
+ struct epoll_event ev = { .events = EPOLLIN, .data.fd = inotify_fd };
+ epoll_ctl(epoll_fd, EPOLL_CTL_ADD, inotify_fd, &ev);
+ }
+
+ scan_devices();
+
+ if (device_count == 0)
+ fprintf(stderr, "Warning: no keyboard devices found, waiting for hotplug\n");
+
+ printf("READY\n");
+ fflush(stdout);
+
+ struct epoll_event events[MAX_EVENTS];
+
+ while (running) {
+ int nfds = epoll_wait(epoll_fd, events, MAX_EVENTS, 500);
+ if (nfds < 0) {
+ if (errno == EINTR) continue;
+ break;
+ }
+
+ for (int i = 0; i < nfds; i++) {
+ int fd = events[i].data.fd;
+
+ if (fd == inotify_fd) {
+ char inbuf[4096] __attribute__((aligned(__alignof__(struct inotify_event))));
+ ssize_t len = read(inotify_fd, inbuf, sizeof(inbuf));
+ if (len > 0)
+ scan_devices();
+ continue;
+ }
+
+ struct input_event ev;
+ while (1) {
+ ssize_t n = read(fd, &ev, sizeof(ev));
+ if (n < 0) {
+ if (errno == EAGAIN)
+ break;
+ if (errno == ENODEV) {
+ remove_device(fd);
+ reset_held_keys();
+ if (!modifiers_satisfied())
+ emit_key_up();
+ }
+ break;
+ }
+ if (n < (ssize_t)sizeof(ev))
+ break;
+
+ if (ev.type == EV_SYN && ev.code == SYN_DROPPED) {
+ reset_held_keys();
+ if (hotkey_active && !modifiers_satisfied())
+ emit_key_up();
+ continue;
+ }
+
+ if (ev.type == EV_KEY)
+ handle_key_event(ev.code, ev.value);
+ }
+ }
+ }
+
+ emit_key_up();
+
+ for (int i = 0; i < device_count; i++)
+ close(device_fds[i]);
+ if (inotify_fd >= 0)
+ close(inotify_fd);
+ close(epoll_fd);
+
+ return 0;
+}
diff --git a/scripts/build-linux-key-listener.js b/scripts/build-linux-key-listener.js
new file mode 100644
index 000000000..1b0e06cda
--- /dev/null
+++ b/scripts/build-linux-key-listener.js
@@ -0,0 +1,128 @@
+#!/usr/bin/env node
+
+// package.json integration notes:
+// - Add "compile:linux-key-listener": "node scripts/build-linux-key-listener.js" to scripts
+// - Add "npm run compile:linux-key-listener" to the "compile:native" chain
+// - The predev / prestart hooks already run compile:native, so no changes needed there
+
+const { spawnSync } = require("child_process");
+const crypto = require("crypto");
+const fs = require("fs");
+const path = require("path");
+
+const isLinux = process.platform === "linux";
+if (!isLinux) {
+ console.log("[linux-key-listener] Skipping: not on Linux");
+ process.exit(0);
+}
+
+const projectRoot = path.resolve(__dirname, "..");
+const cSource = path.join(projectRoot, "resources", "linux-key-listener.c");
+const outputDir = path.join(projectRoot, "resources", "bin");
+const targetArch = process.arch;
+const outputBinary = path.join(outputDir, `linux-key-listener-${targetArch}`);
+const hashFile = path.join(outputDir, `.linux-key-listener.${targetArch}.hash`);
+
+function log(message) {
+ console.log(`[linux-key-listener] ${message}`);
+}
+
+function ensureDir(dirPath) {
+ if (!fs.existsSync(dirPath)) {
+ fs.mkdirSync(dirPath, { recursive: true });
+ }
+}
+
+if (!fs.existsSync(cSource)) {
+ console.error(`[linux-key-listener] C source not found at ${cSource}`);
+ process.exit(1);
+}
+
+ensureDir(outputDir);
+
+let needsBuild = true;
+if (fs.existsSync(outputBinary)) {
+ try {
+ const binaryStat = fs.statSync(outputBinary);
+ const sourceStat = fs.statSync(cSource);
+ if (binaryStat.mtimeMs >= sourceStat.mtimeMs) {
+ needsBuild = false;
+ }
+ } catch {
+ needsBuild = true;
+ }
+}
+
+function computeBuildHash() {
+ const sourceContent = fs.readFileSync(cSource, "utf8");
+ return crypto.createHash("sha256").update(sourceContent).digest("hex");
+}
+
+if (!needsBuild && fs.existsSync(outputBinary)) {
+ try {
+ const currentHash = computeBuildHash();
+
+ if (fs.existsSync(hashFile)) {
+ const savedHash = fs.readFileSync(hashFile, "utf8").trim();
+ if (savedHash !== currentHash) {
+ log("Source changed, rebuild needed");
+ needsBuild = true;
+ }
+ } else {
+ fs.writeFileSync(hashFile, currentHash);
+ }
+ } catch (err) {
+ log(`Hash check failed: ${err.message}, forcing rebuild`);
+ needsBuild = true;
+ }
+}
+
+if (!needsBuild) {
+ process.exit(0);
+}
+
+function attemptCompile(command, args) {
+ log(`Compiling with ${[command, ...args].join(" ")}`);
+ return spawnSync(command, args, {
+ stdio: "inherit",
+ env: process.env,
+ });
+}
+
+const compileArgs = [
+ "-O2",
+ "-Wall",
+ "-Wextra",
+ cSource,
+ "-o",
+ outputBinary,
+];
+
+let result = attemptCompile("gcc", compileArgs);
+
+if (result.status !== 0) {
+ result = attemptCompile("cc", compileArgs);
+}
+
+if (result.status !== 0) {
+ console.error(
+ "[linux-key-listener] Failed to compile Linux key listener binary.\n" +
+ " Install gcc with: sudo apt install build-essential\n" +
+ " or: sudo dnf install gcc"
+ );
+ process.exit(1);
+}
+
+try {
+ fs.chmodSync(outputBinary, 0o755);
+} catch (error) {
+ console.warn(`[linux-key-listener] Unable to set executable permissions: ${error.message}`);
+}
+
+try {
+ fs.writeFileSync(hashFile, computeBuildHash());
+} catch (err) {
+ log(`Warning: Could not save source hash: ${err.message}`);
+}
+
+log(`Successfully built Linux key listener binary (${targetArch}).`);
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index 1e4ebaa53..b5e121eb3 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -98,6 +98,7 @@ class IPCHandlers {
this.windowManager = managers.windowManager;
this.updateManager = managers.updateManager;
this.windowsKeyManager = managers.windowsKeyManager;
+ this.linuxKeyManager = managers.linuxKeyManager;
this.textEditMonitor = managers.textEditMonitor;
this.getTrayManager = managers.getTrayManager;
this.whisperCudaManager = managers.whisperCudaManager;
@@ -1611,6 +1612,12 @@ class IPCHandlers {
this.windowsKeyManager.stop();
}
+ // On Linux, stop the Linux key listener
+ if (process.platform === "linux" && this.linuxKeyManager) {
+ debugLogger.log("[IPC] Stopping Linux key listener for hotkey capture mode");
+ this.linuxKeyManager.stop();
+ }
+
// On GNOME, unregister all native keybindings during capture
if (hotkeyManager.isUsingGnome() && hotkeyManager.gnomeManager) {
for (const slot of [...hotkeyManager.gnomeManager.registeredSlots]) {
@@ -1680,6 +1687,22 @@ class IPCHandlers {
}
}
+ if (process.platform === "linux" && this.linuxKeyManager) {
+ const activationMode = this.windowManager.getActivationMode();
+ const needsListener =
+ effectiveHotkey &&
+ !isGlobeLikeHotkey(effectiveHotkey) &&
+ (activationMode === "push" ||
+ isModifierOnlyHotkey(effectiveHotkey) ||
+ isRightSideModifier(effectiveHotkey));
+ if (needsListener) {
+ debugLogger.log(`[IPC] Restarting Linux key listener for hotkey: ${effectiveHotkey}`);
+ this.linuxKeyManager.start(effectiveHotkey);
+ } else {
+ this.linuxKeyManager.stop();
+ }
+ }
+
// On GNOME, re-register the keybinding with the effective hotkey
if (hotkeyManager.isUsingGnome() && hotkeyManager.gnomeManager && effectiveHotkey) {
const gnomeHotkey = GnomeShortcutManager.convertToGnomeFormat(effectiveHotkey);
diff --git a/src/helpers/linuxKeyManager.js b/src/helpers/linuxKeyManager.js
new file mode 100644
index 000000000..0133ff9c8
--- /dev/null
+++ b/src/helpers/linuxKeyManager.js
@@ -0,0 +1,241 @@
+/**
+ * LinuxKeyManager - Handles key up/down detection for Push-to-Talk on Linux
+ *
+ * Uses a native Linux keyboard hook to detect when specific keys are
+ * pressed and released, enabling Push-to-Talk functionality.
+ */
+
+const { spawn } = require("child_process");
+const path = require("path");
+const EventEmitter = require("events");
+const fs = require("fs");
+const debugLogger = require("./debugLogger");
+
+class LinuxKeyManager extends EventEmitter {
+ constructor() {
+ super();
+ this.process = null;
+ this.isSupported = process.platform === "linux";
+ this.hasReportedError = false;
+ this.currentKey = null;
+ this.isReady = false;
+ this.watchdogTimer = null;
+ }
+
+ /**
+ * Start listening for the specified key
+ * @param {string} key - The key to listen for (e.g., "`", "F8", "F11", "CommandOrControl+F11")
+ */
+ start(key = "`") {
+ if (!this.isSupported) {
+ return;
+ }
+
+ // If already running with the same key, do nothing
+ if (this.process && this.currentKey === key) {
+ return;
+ }
+
+ // Stop any existing listener
+ this.stop();
+
+ const listenerPath = this.resolveListenerBinary();
+ if (!listenerPath) {
+ // Binary not found - this is OK, Push-to-Talk will use fallback mode
+ this.emit("unavailable", new Error("Linux key listener binary not found"));
+ return;
+ }
+
+ this.hasReportedError = false;
+ this.isReady = false;
+ this.currentKey = key;
+
+ debugLogger.debug("[LinuxKeyManager] Starting key listener", {
+ key,
+ binaryPath: listenerPath,
+ });
+
+ try {
+ this.process = spawn(listenerPath, [key], {
+ stdio: ["ignore", "pipe", "pipe"],
+ });
+ } catch (error) {
+ debugLogger.error("[LinuxKeyManager] Failed to spawn process", { error: error.message });
+ this.reportError(error);
+ return;
+ }
+
+ this.process.stdout.setEncoding("utf8");
+ this.process.stdout.on("data", (chunk) => {
+ chunk
+ .split(/\r?\n/)
+ .map((line) => line.trim())
+ .filter(Boolean)
+ .forEach((line) => {
+ if (line === "READY") {
+ debugLogger.debug("[LinuxKeyManager] Listener ready", { key });
+ this.isReady = true;
+ this.emit("ready");
+ } else if (line === "KEY_DOWN") {
+ debugLogger.debug("[LinuxKeyManager] KEY_DOWN detected", { key });
+ this.watchdogTimer = setTimeout(() => {
+ debugLogger.warn("[LinuxKeyManager] Watchdog: no KEY_UP received within 30s, forcing release");
+ this.emit("key-up", this.currentKey);
+ this.watchdogTimer = null;
+ }, 30000);
+ this.emit("key-down", key);
+ } else if (line === "KEY_UP") {
+ debugLogger.debug("[LinuxKeyManager] KEY_UP detected", { key });
+ if (this.watchdogTimer) {
+ clearTimeout(this.watchdogTimer);
+ this.watchdogTimer = null;
+ }
+ this.emit("key-up", key);
+ } else {
+ // Log unknown output at debug level (could be native binary's stderr info)
+ debugLogger.debug("[LinuxKeyManager] Unknown output", { line });
+ }
+ });
+ });
+
+ this.process.stderr.setEncoding("utf8");
+ this.process.stderr.on("data", (data) => {
+ const message = data.toString().trim();
+ if (message.length > 0) {
+ // Native binary logs to stderr for info messages, don't treat as error
+ debugLogger.debug("[LinuxKeyManager] Native stderr", { message });
+ }
+ });
+
+ const proc = this.process;
+
+ proc.on("error", (error) => {
+ if (this.process === proc) this.process = null;
+ this.reportError(error);
+ });
+
+ proc.on("exit", (code, signal) => {
+ if (this.process === proc) {
+ this.process = null;
+ this.isReady = false;
+ }
+ if (code !== 0) {
+ this.reportError(
+ new Error(
+ `Linux key listener exited with code ${code ?? "null"} signal ${signal ?? "null"}`
+ )
+ );
+ }
+ });
+ }
+
+ /**
+ * Stop the key listener
+ */
+ stop() {
+ if (this.watchdogTimer) {
+ clearTimeout(this.watchdogTimer);
+ this.watchdogTimer = null;
+ }
+ if (this.process) {
+ debugLogger.debug("[LinuxKeyManager] Stopping key listener");
+ try {
+ this.process.kill();
+ } catch {
+ // Ignore kill errors
+ }
+ this.process = null;
+ }
+ this.isReady = false;
+ this.currentKey = null;
+ }
+
+ /**
+ * Check if the listener is available and ready
+ */
+ isAvailable() {
+ return this.resolveListenerBinary() !== null;
+ }
+
+ /**
+ * Report an error (only once per session to avoid log spam)
+ */
+ reportError(error) {
+ if (this.hasReportedError) {
+ return;
+ }
+ this.hasReportedError = true;
+
+ if (this.process) {
+ try {
+ this.process.kill();
+ } catch {
+ // Ignore
+ } finally {
+ this.process = null;
+ }
+ }
+
+ debugLogger.warn("[LinuxKeyManager] Error occurred", { error: error.message });
+ this.emit("error", error);
+ }
+
+ /**
+ * Find the listener binary in various possible locations
+ */
+ resolveListenerBinary() {
+ const arch = process.arch;
+ const binaryNameWithArch = `linux-key-listener-${arch}`;
+ const binaryNameNoArch = "linux-key-listener";
+
+ const candidates = new Set([
+ path.join(__dirname, "..", "..", "resources", "bin", binaryNameWithArch),
+ path.join(__dirname, "..", "..", "resources", binaryNameWithArch),
+ ]);
+
+ if (process.resourcesPath) {
+ [
+ path.join(process.resourcesPath, binaryNameWithArch),
+ path.join(process.resourcesPath, "bin", binaryNameWithArch),
+ path.join(process.resourcesPath, "resources", binaryNameWithArch),
+ path.join(process.resourcesPath, "resources", "bin", binaryNameWithArch),
+ path.join(process.resourcesPath, "app.asar.unpacked", "resources", binaryNameWithArch),
+ path.join(process.resourcesPath, "app.asar.unpacked", "resources", "bin", binaryNameWithArch),
+ ].forEach((candidate) => candidates.add(candidate));
+ }
+
+ // Fallback: same paths without arch suffix
+ [
+ path.join(__dirname, "..", "..", "resources", "bin", binaryNameNoArch),
+ path.join(__dirname, "..", "..", "resources", binaryNameNoArch),
+ ].forEach((candidate) => candidates.add(candidate));
+
+ if (process.resourcesPath) {
+ [
+ path.join(process.resourcesPath, binaryNameNoArch),
+ path.join(process.resourcesPath, "bin", binaryNameNoArch),
+ path.join(process.resourcesPath, "resources", binaryNameNoArch),
+ path.join(process.resourcesPath, "resources", "bin", binaryNameNoArch),
+ path.join(process.resourcesPath, "app.asar.unpacked", "resources", binaryNameNoArch),
+ path.join(process.resourcesPath, "app.asar.unpacked", "resources", "bin", binaryNameNoArch),
+ ].forEach((candidate) => candidates.add(candidate));
+ }
+
+ const candidatePaths = [...candidates];
+
+ for (const candidate of candidatePaths) {
+ try {
+ const stats = fs.statSync(candidate);
+ if (stats.isFile()) {
+ return candidate;
+ }
+ } catch {
+ continue;
+ }
+ }
+
+ return null;
+ }
+}
+
+module.exports = LinuxKeyManager;
diff --git a/src/helpers/windowManager.js b/src/helpers/windowManager.js
index 0c6345ef9..ce5a36900 100644
--- a/src/helpers/windowManager.js
+++ b/src/helpers/windowManager.js
@@ -219,8 +219,8 @@ class WindowManager {
return;
}
- // Windows push mode: always defer to native listener (globalShortcut can't detect key-up)
- if (process.platform === "win32" && activationMode === "push") {
+ // Push mode: defer to native listener (globalShortcut can't detect key-up)
+ if ((process.platform === "win32" || process.platform === "linux") && activationMode === "push") {
return;
}
diff --git a/src/stores/settingsStore.ts b/src/stores/settingsStore.ts
index e92f7a4f4..2c35029eb 100644
--- a/src/stores/settingsStore.ts
+++ b/src/stores/settingsStore.ts
@@ -435,10 +435,8 @@ export const useSettingsStore = create<SettingsState>()((set, get) => ({
},
setActivationMode: (mode: "tap" | "push") => {
- // Linux has no native key listener for push-to-talk — force tap
- const effective = isBrowser && window.electronAPI?.getPlatform?.() === "linux" ? "tap" : mode;
- if (isBrowser) localStorage.setItem("activationMode", effective);
- set({ activationMode: effective });
+ if (isBrowser) localStorage.setItem("activationMode", mode);
+ set({ activationMode: mode });
if (isBrowser) {
window.electronAPI?.notifyActivationModeChanged?.(effective);
}
@@ -762,10 +760,8 @@ export async function initializeSettings(): Promise<void> {
);
}
- // Sync activation mode from main process (Linux forces tap — no native key listener)
try {
let envMode = await window.electronAPI.getActivationMode?.();
- if (window.electronAPI?.getPlatform?.() === "linux") envMode = "tap";
if (envMode && envMode !== state.activationMode) {
if (isBrowser) localStorage.setItem("activationMode", envMode);
useSettingsStore.setState({ activationMode: envMode });