@@ -156,6 +156,87 @@ it("leaves already configured files unchanged, without creating a backup", async
156156 expect ( await setup . apply ( preview . id , "niri" ) ) . toEqual ( { backupPath : null , warning : null } ) ;
157157 expect ( await NodeFSP . readdir ( directory ) ) . toEqual ( [ "config.kdl" ] ) ;
158158} ) ;
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+ } ) ;
159240it ( "detects conflicts in included Niri configs without changing either file" , async ( ) => {
160241 await NodeFSP . appendFile ( path , 'include "keys.kdl"\n' ) ;
161242 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
178259 } ;
179260 await NodeFSP . writeFile ( hypr . path , "-- user bindings\n" ) ;
180261 tools . hyprlandBindings . mockResolvedValue ( [
181- { modmask : 5 , key : "2" , dispatcher : "exec " , arg : "kitty " } ,
262+ { modmask : 5 , key : "2" , dispatcher : "__lua " , arg : "92 " } ,
182263 ] ) ;
183264 await expect ( setup . preview ( hypr , install ) ) . rejects . toThrow ( "already used" ) ;
184265 expect ( await NodeFSP . readFile ( hypr . path , "utf8" ) ) . toBe ( "-- user bindings\n" ) ;
0 commit comments