Better implementation of tag_view_nonempty

The Problem:
The issue will current implementation is that it goes to next tag and
stops only if clients on that tag are more than 0.
So now consider a scenario we have clients on *tag 1,2,5*

With the current implementation if we are on tag 2 and call
lain.util.tag_view_nonempty(1) and then call
awful.tag.history.restore() It will take us to tag 4 instead of tag 2.

This PR solves the problem
This commit is contained in:
Shubham Pawar 2021-08-22 07:48:09 +05:30
parent f55ba48d7a
commit 284a4b61a5
1 changed files with 27 additions and 31 deletions

View File

@ -97,40 +97,36 @@ end
-- Non-empty tag browsing -- Non-empty tag browsing
-- direction in {-1, 1} <-> {previous, next} non-empty tag -- direction in {-1, 1} <-> {previous, next} non-empty tag
function util.tag_view_nonempty(direction,sc) function util.tag_view_nonempty(direction,sc)
local s = sc or awful.screen.focused() direction = direction or 1
local tags = s.tags local s = sc or awful.screen.focused()
local tag = s.selected_tag local tags = s.tags
local idx = awful.tag.getidx() local sel = s.selected_tag
local looputil = function (start,e,inc) local i = sel.index
for i = start, e, inc do repeat
local currentTag = s.tags[i] i = i + direction
if currentTag == tag then
return
end
if currentTag ~= nil then
if #currentTag:clients() > 0 then
currentTag:view_only()
return
end
end
end
return 1
end
if direction == 1 then -- Wrap around when we reach one of the bounds
local r = looputil(idx+1,#tags,1) if i > #tags then
if r then i = i - #tags
looputil(1,idx,1) end
end if i < 1 then
end i = i + #tags
end
if direction == -1 then local t = tags[i]
local r = looputil(idx-1,0,-1)
if r then -- Stop when we get back to where we started
looputil(#tags,idx,-1) if t == sel then
end break
end end
-- If it's The One, view it.
if #t:clients() > 0 then
t:view_only()
return
end
until false
end end
-- {{{ Dynamic tagging -- {{{ Dynamic tagging