@devries-cameron20 / t3code-1 / commits / fb331610a8
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(desktop): accept existing Hyprland SnapShot shortcuts (#10658)

Akshar Patel committed Oct 18, 2026 at 15:12 UTC fb331610a8d6fc6c2c83fdcdb49e3fb75e9745d6
2 files changed +96 -5
apps/desktop/src/snapShot/CaptureShortcutConfig.test.ts
+82 -1
@@ -156,6 +156,87 @@ it("leaves already configured files unchanged, without creating a backup", async
156 expect(await setup.apply(preview.id, "niri")).toEqual({ backupPath: null, warning: null });
157 expect(await NodeFSP.readdir(directory)).toEqual(["config.kdl"]);
158 });
159 +it("accepts an unchanged capture shortcut reported as a Lua callback", async () => {
160 + const hypr = {
161 + ...target(),
162 + desktop: "hyprland" as const,
163 + path: NodePath.join(directory, "bindings.lua"),
164 + };
165 + const before = `${captureConfigBinding("hyprland-lua", appId, "Ctrl+Shift+2")}\n`;
166 + await NodeFSP.writeFile(hypr.path, before);
167 + tools.hyprlandBindings.mockResolvedValue([
168 + { modmask: 5, key: "2", dispatcher: "__lua", arg: "92" },
169 + ]);
170 +
171 + const preview = await setup.preview(hypr, install);
172 + expect(preview.after).toBe(before);
173 + expect(preview.shortcut).toBe("Ctrl+Shift+2");
174 + expect(await setup.apply(preview.id, "hyprland")).toEqual({ backupPath: null, warning: null });
175 + expect(await NodeFSP.readFile(hypr.path, "utf8")).toBe(before);
176 + expect((await NodeFSP.readdir(directory)).sort()).toEqual(["bindings.lua", "config.kdl"]);
177 + expect(tools.reloadHyprland).not.toHaveBeenCalled();
178 +
179 + const unchanged = await setup.preview(hypr, install);
180 + await NodeFSP.appendFile(hypr.path, "-- edited elsewhere\n");
181 + await expect(setup.apply(unchanged.id, "hyprland")).rejects.toThrow("changed since");
182 + expect(await NodeFSP.readFile(hypr.path, "utf8")).toBe(before + "-- edited elsewhere\n");
183 +});
184 +it.each(["preview", "apply"] as const)(
185 + "checks unchanged Hyprland .conf shortcuts for conflicts during %s",
186 + async (stage) => {
187 + const hypr = {
188 + ...target(),
189 + desktop: "hyprland" as const,
190 + path: NodePath.join(directory, "hyprland.conf"),
191 + };
192 + const before = `${captureConfigBinding("hyprland", appId, "Ctrl+Shift+2")}\n`;
193 + await NodeFSP.writeFile(hypr.path, before);
194 + const ownBinding = {
195 + modmask: 5,
196 + key: "2",
197 + dispatcher: "global",
198 + arg: `${appId}:capture-window`,
199 + };
200 + tools.hyprlandBindings.mockResolvedValue([ownBinding]);
201 + const unchanged = await setup.preview(hypr, install);
202 + expect(unchanged.after).toBe(before);
203 + expect(await setup.apply(unchanged.id, "hyprland")).toEqual({
204 + backupPath: null,
205 + warning: null,
206 + });
207 +
208 + const preview = stage === "apply" ? await setup.preview(hypr, install) : undefined;
209 + tools.hyprlandBindings.mockResolvedValue([
210 + ownBinding,
211 + { modmask: 5, key: "2", dispatcher: "exec", arg: "kitty" },
212 + ]);
213 + await expect(
214 + preview ? setup.apply(preview.id, "hyprland") : setup.preview(hypr, install),
215 + ).rejects.toThrow("already used");
216 + expect(await NodeFSP.readFile(hypr.path, "utf8")).toBe(before);
217 + expect((await NodeFSP.readdir(directory)).sort()).toEqual(["config.kdl", "hyprland.conf"]);
218 + expect(tools.reloadHyprland).not.toHaveBeenCalled();
219 + },
220 +);
221 +it("rejects changing an existing capture shortcut to keys used by another Lua callback", async () => {
222 + const hypr = {
223 + ...target(),
224 + desktop: "hyprland" as const,
225 + path: NodePath.join(directory, "bindings.lua"),
226 + };
227 + const before = `${captureConfigBinding("hyprland-lua", appId, "Ctrl+Alt+Y")}\n`;
228 + await NodeFSP.writeFile(hypr.path, before);
229 + const request = { ...install, shortcut: "Ctrl+Shift+2" };
230 + const occupied = [{ modmask: 5, key: "2", dispatcher: "__lua", arg: "93" }];
231 + tools.hyprlandBindings.mockResolvedValue(occupied);
232 + await expect(setup.preview(hypr, request)).rejects.toThrow("already used");
233 +
234 + tools.hyprlandBindings.mockResolvedValue([]);
235 + const preview = await setup.preview(hypr, request);
236 + tools.hyprlandBindings.mockResolvedValue(occupied);
237 + await expect(setup.apply(preview.id, "hyprland")).rejects.toThrow("already used");
238 + expect(await NodeFSP.readFile(hypr.path, "utf8")).toBe(before);
239 +});
240 it("detects conflicts in included Niri configs without changing either file", async () => {
241 await NodeFSP.appendFile(path, 'include "keys.kdl"\n');
242 await NodeFSP.writeFile(NodePath.join(directory, "keys.kdl"), "binds { Shift+Ctrl+2 { quit; } }");
@@ -178,7 +259,7 @@ it("rejects a conflict from another Hyprland config or dynamic Lua bind", async
259 };
260 await NodeFSP.writeFile(hypr.path, "-- user bindings\n");
261 tools.hyprlandBindings.mockResolvedValue([
181 - { modmask: 5, key: "2", dispatcher: "exec", arg: "kitty" },
262 + { modmask: 5, key: "2", dispatcher: "__lua", arg: "92" },
263 ]);
264 await expect(setup.preview(hypr, install)).rejects.toThrow("already used");
265 expect(await NodeFSP.readFile(hypr.path, "utf8")).toBe("-- user bindings\n");
apps/desktop/src/snapShot/CaptureShortcutConfig.ts
+14 -4
@@ -95,7 +95,13 @@ const defaultTools = {
95 /** The renderer can apply only the exact proposal retained by the desktop process. */
96 export class CaptureShortcutConfig {
97 private pending:
98 - | { preview: DesktopCaptureConfigPreview; target: Target; files: Snapshot[]; missing: string[] }
98 + | {
99 + preview: DesktopCaptureConfigPreview;
100 + target: Target;
101 + files: Snapshot[];
102 + missing: string[];
103 + checkHyprlandKeys: boolean;
104 + }
105 | undefined;
106 private applying = false;
107 private readonly home: string;
@@ -153,6 +159,10 @@ export class CaptureShortcutConfig {
159 request.operation,
160 request.shortcut,
161 );
162 + // Lua bindings appear as opaque callbacks, including our own unchanged shortcut.
163 + const checkHyprlandKeys =
164 + request.operation === "install" &&
165 + (format === "hyprland" || (format === "hyprland-lua" && edit.after !== root.text));
166 const files = [root];
167 const missing: string[] = [];
168 if (target.desktop === "niri") {
@@ -195,7 +205,7 @@ export class CaptureShortcutConfig {
205 }
206 };
207 await visit(root, 0);
198 - } else if (request.operation === "install") {
208 + } else if (checkHyprlandKeys) {
209 await this.checkHyprlandKeys(target.appId, edit.shortcut);
210 }
211 const preview = {
@@ -207,7 +217,7 @@ export class CaptureShortcutConfig {
217 shortcut: edit.shortcut,
218 operation: request.operation,
219 };
210 - this.pending = { preview, target, files, missing };
220 + this.pending = { preview, target, files, missing, checkHyprlandKeys };
221 return preview;
222 }
223
@@ -255,7 +265,7 @@ export class CaptureShortcutConfig {
265 }
266 };
267 await unchanged();
258 - if (desktop === "hyprland" && preview.operation === "install")
268 + if (pending.checkHyprlandKeys)
269 await this.checkHyprlandKeys(pending.target.appId, preview.shortcut);
270 if (preview.before === preview.after) return { backupPath: null, warning: null };
271 await NodeFSP.writeFile(temporary, preview.after, {