Skip to content

Commit

Permalink
Merge pull request #38 from mogenson/retile-after-non-focus-window-mi…
Browse files Browse the repository at this point in the history
…nimized

Retile space if non-focused window is minimized
  • Loading branch information
mogenson committed Mar 18, 2024
2 parents c759e87 + 753719b commit 12d7cb8
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ end

local pending_window = nil
local function windowEventHandler(window, event, self)
self.logger.df("%s for [%s] id:%d", event, window, window and window:id() or -1)
self.logger.df("%s for [%s] id: %d", event, window, window and window:id() or -1)
local space = nil

--[[ When a new window is created, We first get a windowVisible event but
Expand Down Expand Up @@ -214,7 +214,7 @@ local function windowEventHandler(window, event, self)
return
end
elseif event == "windowNotVisible" then
self:removeWindow(window) -- destroyed windows don't have a space
space = self:removeWindow(window)
elseif event == "windowFullscreened" then
space = self:removeWindow(window, true) -- don't focus new window if fullscreened
elseif event == "AXWindowMoved" or event == "AXWindowResized" then
Expand Down Expand Up @@ -494,9 +494,12 @@ function PaperWM:removeWindow(remove_window, skip_new_window_focus)
end

if not skip_new_window_focus then -- find nearby window to focus
for _, direction in ipairs({
Direction.DOWN, Direction.UP, Direction.LEFT, Direction.RIGHT
}) do if self:focusWindow(direction, remove_index) then break end end
local focused_window = focused_window or Window.focusedWindow()
if focused_window and remove_window:id() == focused_window:id() then
for _, direction in ipairs({
Direction.DOWN, Direction.UP, Direction.LEFT, Direction.RIGHT
}) do if self:focusWindow(direction, remove_index) then break end end
end
end

-- remove window
Expand Down Expand Up @@ -942,9 +945,9 @@ function PaperWM:moveWindowToSpace(index)
return
end

-- cache a local copy, removeWindow() will clear global focused_window
-- cache a copy of focused_window, don't switch focus when removing window
local focused_window = focused_window
local old_space = self:removeWindow(focused_window)
local old_space = self:removeWindow(focused_window, true)
if not old_space then
self.logger.e("can't remove focused window")
return
Expand Down

0 comments on commit 12d7cb8

Please sign in to comment.