Skip to content

Add focus_wrap action and support NEXT and PREVIOUS directions#151

Open
ArhanChaudhary wants to merge 3 commits into
mogenson:mainfrom
ArhanChaudhary:focus-wrap
Open

Add focus_wrap action and support NEXT and PREVIOUS directions#151
ArhanChaudhary wants to merge 3 commits into
mogenson:mainfrom
ArhanChaudhary:focus-wrap

Conversation

@ArhanChaudhary
Copy link
Copy Markdown
Contributor

I have modified #150 to support infinite window looping with the NEXT and PREVIOUS directions, and refactored it as an action in case people want to call it for whatever reason. I have not added my own test cases, but they pass the existing ones. I might do that later.

For what it is worth, I was testing my implementation on my desktop and ran into a sporadic error that crashed the entire window manager:

2026-03-19 19:55:00: 19:55:00 ERROR:   LuaSkin: hs.application.watcher callback: /Users/arhan/.hammerspoon/Spoons/PaperWM.spoon/windows.lua:217: assertion failed!
stack traceback:
	[C]: in function 'assert'
	/Users/arhan/.hammerspoon/Spoons/PaperWM.spoon/windows.lua:217: in field 'removeWindow'
	/Users/arhan/.hammerspoon/Spoons/PaperWM.spoon/events.lua:99: in field 'windowEventHandler'
	/Users/arhan/.hammerspoon/Spoons/PaperWM.spoon/events.lua:370: in local 'fn'
	...n.app/Contents/Resources/extensions/hs/window_filter.lua:951: in upvalue 'emit'
	...n.app/Contents/Resources/extensions/hs/window_filter.lua:977: in method 'filterEmitEvent'
	...n.app/Contents/Resources/extensions/hs/window_filter.lua:1011: in method 'emitEvent'
	...n.app/Contents/Resources/extensions/hs/window_filter.lua:1129: in method 'notVisible'
	...n.app/Contents/Resources/extensions/hs/window_filter.lua:1143: in method 'hidden'
	...n.app/Contents/Resources/extensions/hs/window_filter.lua:1328: in function <...n.app/Contents/Resources/extensions/hs/window_filter.lua:1324>
	(...tail calls...)
2026-03-19 19:55:00: 19:55:00 ERROR:   LuaSkin: hs.application.watcher callback: /Users/arhan/.hammerspoon/Spoons/PaperWM.spoon/windows.lua:217: assertion failed!
stack traceback:
	[C]: in function 'assert'
	/Users/arhan/.hammerspoon/Spoons/PaperWM.spoon/windows.lua:217: in field 'removeWindow'
	/Users/arhan/.hammerspoon/Spoons/PaperWM.spoon/events.lua:99: in field 'windowEventHandler'
	/Users/arhan/.hammerspoon/Spoons/PaperWM.spoon/events.lua:370: in local 'fn'
	...n.app/Contents/Resources/extensions/hs/window_filter.lua:951: in upvalue 'emit'
	...n.app/Contents/Resources/extensions/hs/window_filter.lua:977: in method 'filterEmitEvent'
	...n.app/Contents/Resources/extensions/hs/window_filter.lua:1011: in method 'emitEvent'
	...n.app/Contents/Resources/extensions/hs/window_filter.lua:1129: in method 'notVisible'
	...n.app/Contents/Resources/extensions/hs/window_filter.lua:1143: in method 'hidden'
	...n.app/Contents/Resources/extensions/hs/window_filter.lua:1328: in function <...n.app/Contents/Resources/extensions/hs/window_filter.lua:1324>
	(...tail calls...)
2026-03-19 19:55:01: 19:55:01 ERROR:   PaperWM: anchor index not found, refreshing windows

So, yeah, I'm not sure if that's related to my changes here or another previously known bug.

(I also fixed the inconsistent spacing in the README in this PR because I didn't think it was worth an entirety separate PR to fix)

Comment thread actions.lua
focus_down = Fnutils.partial(Actions.PaperWM.windows.focusWindow, Direction.DOWN),
focus_prev = Fnutils.partial(Actions.PaperWM.windows.focusWindow, Direction.PREVIOUS),
focus_next = Fnutils.partial(Actions.PaperWM.windows.focusWindow, Direction.NEXT),
focus_wrap = Actions.PaperWM.windows.focusWrap,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be exposed as an action? All the other actions have the necessary arguments provided via Fnutils.partial. This looks like the only action that requires arguments to work, which makes it a bit harder to bind to a hot key.

Comment thread windows.lua
---@param direction Direction use either Direction UP, DOWN, LEFT, RIGHT, PREVIOUS, or NEXT
---@param focused_index Index index of focused window within the windowList
---@return Window?
function Windows.focusWrap(direction, focused_index)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to add some unit tests for this new method to spec/windows_spec.lua

@mogenson
Copy link
Copy Markdown
Owner

Looks good, sorry I'm a bit late on review. Let me know if you can add unit tests for the new focusWrap method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants