feat: restore windows to original position & size after PaperWM stop#155
feat: restore windows to original position & size after PaperWM stop#155dev24hrs wants to merge 2 commits into
Conversation
| -- Support both win:setFrame(f) (passes self as first arg) and win.setFrame(f) | ||
| setFrame = function(self_or_frame, maybe_frame) | ||
| frame = maybe_frame ~= nil and maybe_frame or self_or_frame | ||
| end, |
There was a problem hiding this comment.
thanks for catching this. lets change the signature to setFrame = function(self, new_frame). we should only support the win:setFrame(f) form. win.setFrame(f) is not valid for hammerspoon
| PaperWM.state.init(PaperWM) | ||
| PaperWM.floating.init(PaperWM) | ||
| PaperWM.tiling.init(PaperWM) | ||
| PaperWM.tiling.init(PaperWM) |
| modal:bind({}, "l", nil, actions.focus_right) | ||
| modal:bind({}, "escape", function() modal:exit() end) | ||
| modal:bind({}, "escape", function() | ||
| PaperWM:stop() |
There was a problem hiding this comment.
I don't feel like PaperWM:stop() is needed for this modal example. Otherwise, when using this example the user would have to restart PaperWM.spoon every time the exit the modal layer.
| end | ||
|
|
||
| -- persist to settings for cross-session restore | ||
| hs.settings.set(SavedFramesKey, saved) |
There was a problem hiding this comment.
If the SavedFramesKey setting is overwritten on every PaperWM start, does it need to persist through Hammerspoon launches? It seems like this could just be a regular old Lua table.
| local paperwm = WindowRestore.PaperWM | ||
|
|
||
| -- prefer in-memory snapshot (same session); fall back to persisted data | ||
| local saved = WindowRestore._saved or hs.settings.get(SavedFramesKey) |
There was a problem hiding this comment.
similar to the comment above, if the SavedFramesKey is set on every PaperWM.spoon start, under what condition would SavedFramesKey be set but not WindowRestore._saved?
| -- windowRestore_afterStop: restore window frames to their pre-tiling positions | ||
| self.window_restore.restoreWindowFrames() | ||
|
|
||
| -- ensure any window without a saved frame stays within screen bounds |
There was a problem hiding this comment.
how does this filter out windows with a saved frame? This looks like it will loop over windows within SavedFramesKey / WindowRestore._saved tables again and possibly changed their frames to be within the screen bounds.
|
Hi, I'm glad that this change is helpful for you, but I'm not sure about whether to make this the default behavior for every PaperWM.spoon user. I think that the I think this could be a good stand alone addition to PaperWM.spoon, since it doesn't need access to the tiling internals. It just needs a new hotkey that calls |
|
@mogenson Hi, it's currently just my personal need, i'm not sure if it's necessary for every PaperWM.spoon user.The code runs well on my local machine, and I will continue to update it. If needed, I will make this feature as a standalone addition. |
Hi,
I had a new idea during use. When i stop paperwm or quit hammerspoon,windows released control, but not restored to original position & size after stop or quit.
So i submitted this request. I'm not sure if this request is necessary.
The following are the relevant code changes.
New Files
window_restore.luaCore module with two functions:
and saves each window's {x, y, w, h}, window ID,
and a stable bundleID|title key to both an in-memory snapshot (_saved)
and hs.settings (key: PaperWM_saved_frames)
falling back to bundleID|title (cross-session / after Hammerspoon restart).
Clears the in-memory snapshot after restore
Modified Files
init.luaspec/mocks.luaFixed the setFrame method in mock_window. The original function(new_frame) signature incorrectly received self as the first argument when called as win:setFrame(f), causing the
actual frame to be discarded. Fixed to:
New Test File
spec/window_restore_spec.lua13 tests across two suites:
saveWindowFrames(6 tests)restoreWindowFrames(7 tests)So users can change their
init.luawith this to restore windows to original position & size after PaperWM stop