Skip to content

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

fix(linux): map GNOME punctuation hotkeys to X11 keysyms (#1658)

Henry Sua103a4db921b
diff --git a/src/helpers/gnomeShortcut.js b/src/helpers/gnomeShortcut.js
index b5d1a23df..709d99576 100644
--- a/src/helpers/gnomeShortcut.js
+++ b/src/helpers/gnomeShortcut.js
@@ -34,7 +34,7 @@ const KEYBINDING_SCHEMA = "org.gnome.settings-daemon.plugins.media-keys.custom-k
// Valid pattern for GNOME shortcut format using X11 keysym names (case-sensitive).
// Modifiers are case-insensitive (GTK normalizes them), keysyms are exact.
const VALID_SHORTCUT_PATTERN =
- /^(<(Control|Alt|Shift|Super)>)*(F([1-9]|1[0-9]|2[0-4])|[a-z0-9]|space|Escape|Tab|BackSpace|grave|Pause|Scroll_Lock|Insert|Delete|Home|End|Page_Up|Page_Down|Up|Down|Left|Right|Return|Print)$/;
+ /^(<(Control|Alt|Shift|Super)>)*(F([1-9]|1[0-9]|2[0-4])|comma|period|slash|plus|minus|equal|semicolon|apostrophe|backslash|bracketleft|bracketright|asciitilde|exclam|at|numbersign|dollar|percent|asciicircum|ampersand|asterisk|parenleft|parenright|underscore|braceleft|braceright|bar|colon|quotedbl|less|greater|question|[a-z0-9]|space|Escape|Tab|BackSpace|grave|Pause|Scroll_Lock|Insert|Delete|Home|End|Page_Up|Page_Down|Up|Down|Left|Right|Return|Print)$/;
// Map Electron key names (lowercased) to X11 keysym names (case-sensitive).
// Source: X11/keysymdef.h, lookup via XStringToKeysym(3).
@@ -63,6 +63,45 @@ const ELECTRON_TO_GNOME_KEY_MAP = {
down: "Down",
left: "Left",
right: "Right",
+ // Punctuation must be X11 keysyms; a literal "," fails VALID_SHORTCUT_PATTERN.
+ ",": "comma",
+ ".": "period",
+ "/": "slash",
+ "-": "minus",
+ "=": "equal",
+ ";": "semicolon",
+ "'": "apostrophe",
+ "[": "bracketleft",
+ "]": "bracketright",
+ "\\": "backslash",
+ plus: "plus",
+ "+": "plus",
+};
+
+// HotkeyInput stores physical US-QWERTY keys, so Shift must be folded into
+// the keysym GNOME matches rather than retained as a separate modifier.
+const SHIFTED_PUNCTUATION_TO_GNOME_KEY_MAP = {
+ "`": "asciitilde",
+ 1: "exclam",
+ 2: "at",
+ 3: "numbersign",
+ 4: "dollar",
+ 5: "percent",
+ 6: "asciicircum",
+ 7: "ampersand",
+ 8: "asterisk",
+ 9: "parenleft",
+ 0: "parenright",
+ "-": "underscore",
+ "=": "plus",
+ "[": "braceleft",
+ "]": "braceright",
+ "\\": "bar",
+ ";": "colon",
+ "'": "quotedbl",
+ ",": "less",
+ ".": "greater",
+ "/": "question",
};
let dbus = null;
@@ -462,11 +501,16 @@ class GnomeShortcutManager {
}
const key = parts.pop();
+ const keyLower = key.toLowerCase();
+ const shiftedPunctuationKey = parts.some((mod) => mod.toLowerCase() === "shift")
+ ? SHIFTED_PUNCTUATION_TO_GNOME_KEY_MAP[keyLower]
+ : undefined;
const modifiers = parts
.map((mod) => {
const m = mod.toLowerCase();
if (m === "commandorcontrol" || m === "control" || m === "ctrl") return "<Control>";
if (m === "alt") return "<Alt>";
+ if (m === "shift" && shiftedPunctuationKey) return "";
if (m === "shift") return "<Shift>";
if (m === "super" || m === "meta") return "<Super>";
return "";
@@ -474,10 +518,10 @@ class GnomeShortcutManager {
.filter(Boolean)
.join("");
- const keyLower = key.toLowerCase();
-
let gnomeKey;
- if (key === "`" || keyLower === "backquote") {
+ if (shiftedPunctuationKey) {
+ gnomeKey = shiftedPunctuationKey;
+ } else if (key === "`" || keyLower === "backquote") {
gnomeKey = "grave";
} else if (key === " ") {
gnomeKey = "space";
diff --git a/test/helpers/gnomeShortcutFormat.test.js b/test/helpers/gnomeShortcutFormat.test.js
new file mode 100644
index 000000000..6d08097e0
--- /dev/null
+++ b/test/helpers/gnomeShortcutFormat.test.js
@@ -0,0 +1,64 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+
+const GnomeShortcutManager = require("../../src/helpers/gnomeShortcut");
+
+test("letter and function-key shortcuts still convert", () => {
+ assert.equal(GnomeShortcutManager.convertToGnomeFormat("Alt+R"), "<Alt>r");
+ assert.equal(GnomeShortcutManager.isValidShortcut("<Alt>r"), true);
+ assert.equal(GnomeShortcutManager.convertToGnomeFormat("F8"), "F8");
+ assert.equal(GnomeShortcutManager.isValidShortcut("F8"), true);
+});
+
+test("punctuation accelerators map to X11 keysyms", () => {
+ assert.equal(GnomeShortcutManager.convertToGnomeFormat("Control+,"), "<Control>comma");
+ assert.equal(GnomeShortcutManager.isValidShortcut("<Control>comma"), true);
+
+ assert.equal(GnomeShortcutManager.convertToGnomeFormat("Alt+."), "<Alt>period");
+ assert.equal(GnomeShortcutManager.isValidShortcut("<Alt>period"), true);
+
+ assert.equal(GnomeShortcutManager.convertToGnomeFormat("Control+/"), "<Control>slash");
+ assert.equal(GnomeShortcutManager.isValidShortcut("<Control>slash"), true);
+
+ assert.equal(GnomeShortcutManager.convertToGnomeFormat("Control+-"), "<Control>minus");
+ assert.equal(GnomeShortcutManager.isValidShortcut("<Control>minus"), true);
+
+ assert.equal(GnomeShortcutManager.convertToGnomeFormat("Control+Plus"), "<Control>plus");
+ assert.equal(GnomeShortcutManager.isValidShortcut("<Control>plus"), true);
+});
+
+test("UI-emitted shifted punctuation consumes Shift and uses the resulting X11 keysym", () => {
+ const shiftedPunctuationCases = [
+ ["Control+Shift+`", "<Control>asciitilde"],
+ ["Control+Shift+1", "<Control>exclam"],
+ ["Control+Shift+2", "<Control>at"],
+ ["Control+Shift+3", "<Control>numbersign"],
+ ["Control+Shift+4", "<Control>dollar"],
+ ["Control+Shift+5", "<Control>percent"],
+ ["Control+Shift+6", "<Control>asciicircum"],
+ ["Control+Shift+7", "<Control>ampersand"],
+ ["Control+Shift+8", "<Control>asterisk"],
+ ["Control+Shift+9", "<Control>parenleft"],
+ ["Control+Shift+0", "<Control>parenright"],
+ ["Control+Shift+-", "<Control>underscore"],
+ ["Control+Shift+=", "<Control>plus"],
+ ["Control+Shift+[", "<Control>braceleft"],
+ ["Control+Shift+]", "<Control>braceright"],
+ ["Control+Shift+\\", "<Control>bar"],
+ ["Control+Shift+;", "<Control>colon"],
+ ["Control+Shift+'", "<Control>quotedbl"],
+ ["Control+Shift+,", "<Control>less"],
+ ["Control+Shift+.", "<Control>greater"],
+ ["Control+Shift+/", "<Control>question"],
+ ];
+
+ for (const [hotkey, expected] of shiftedPunctuationCases) {
+ assert.equal(GnomeShortcutManager.convertToGnomeFormat(hotkey), expected, hotkey);
+ assert.equal(GnomeShortcutManager.isValidShortcut(expected), true, expected);
+ }
+});
+
+test("raw punctuation strings are rejected by the GNOME validator", () => {
+ assert.equal(GnomeShortcutManager.isValidShortcut("<Control>,"), false);
+ assert.equal(GnomeShortcutManager.isValidShortcut("<Control>plus"), true);
+});