From 8d4f9b32b024abc35d7d31c7760d6b7fbefeeb39 Mon Sep 17 00:00:00 2001 From: zdmgmail <50515839+zdmgmail@users.noreply.github.com> Date: Tue, 6 Jul 2021 10:33:53 +0800 Subject: [PATCH] util.tag_view_nonempty(direction,sc) --- util/init.lua | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/util/init.lua b/util/init.lua index f7d3088..840d2df 100644 --- a/util/init.lua +++ b/util/init.lua @@ -96,15 +96,41 @@ end -- Non-empty tag browsing -- direction in {-1, 1} <-> {previous, next} non-empty tag -function util.tag_view_nonempty(direction, sc) - local s = sc or awful.screen.focused() +function util.tag_view_nonempty(direction,sc) + local s = sc or awful.screen.focused() + local tags = s.tags + local tag = s.selected_tag + local idx = awful.tag.getidx() - for _ = 1, #s.tags do - awful.tag.viewidx(direction, s) - if #s.clients > 0 then - return - end - end + local looputil = function (start,e,inc) + for i = start, e, inc do + local currentTag = s.tags[i] + 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 + local r = looputil(idx+1,#tags,1) + if r then + looputil(1,idx,1) + end + end + + if direction == -1 then + local r = looputil(idx-1,0,-1) + if r then + looputil(#tags,idx,-1) + end + end end -- {{{ Dynamic tagging