You are not logged in.
Been trying to obtain this behaviour with Awesome:-
Start off with one tag. When an app is started, push it to the next tag and change tag to that tag.
I've got that part going using this:-
{ rule = { type = "normal" },
except_any = { class = { "Keepassx", "Gmrun" } },
--if clients > 0 then
callback = function(c)
awful.client.movetotag(tags[mouse.screen][awful.tag.getidx()+1], c)
awful.tag.viewonly(tags[mouse.screen][awful.tag.getidx()+1])
end
--end
},So basically it only works on 'normal' windows except windows that I'll probably like to have in the current tag (Gmrun and Keepassx obviously). I use this in conjunction with eminent so as to ensure that I only see as many tags as there are active. Eventually I'd like to maybe use shifty and only generate tags on-the-fly.
What I want to do, however, is for the app to start in the current tag if its empty. For that, I need to detect that state, and I can't seem to do it. This is the code fragment from eminent.lua that seems to do it:-
function gettags(screen)
local tags = {}
for k, t in ipairs(capi.screen[screen]:tags()) do
if t.selected or #t:clients() > 0 then
awful.tag.setproperty(t, "hide", false)
table.insert(tags, t)
else
awful.tag.setproperty(t, "hide", true)
end
end
return tags
endAs far as I can understand, screen[screen]:tags() returns a table of tags. ipairs splits it up into a range of values, and then the :clients() method is called to determine what clients there are. I presume # is for 'number-of' but I'm not sure.
Any advise on how I can achieve this count? I just want to put an 'if' as commented in my first code snippet.
Last edited by ngoonee (2012-09-03 08:05:04)
Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.
Offline
As far as I can understand, screen[screen]:tags() returns a table of tags. ipairs splits it up into a range of values, and then the :clients() method is called to determine what clients there are. I presume # is for 'number-of' but I'm not sure.
"ipairs" is used to iterate over index,value pairs, and # is "number-of" (like "enumerate" and "len" in python), e. g:
$ lua
> t={"a","b","c"}
> print(#t)
3
> for index,value in ipairs(t) do
>> print(index,value)
>> end
1 a
2 b
3 cRegarding this:
Any advise on how I can achieve this count? I just want to put an 'if' as commented in my first code snippet.
If i undestand you correctly, you want a function that returns the number of clients per tag minus gmrun etc. You could take advantage of the matching functions from awful.rules: Iterate over all clients of a given tag and match them against your except_any rule.
function get_client_count(tag,rule)
ret = 0
for _, c in pairs(tag:clients()) do
if not awful.rules.match_any(c, rule) then
ret = ret+1
end
end
return ret
end---
Edit; of course, this would be more efficient for the specific use-case:
function is_empty(tag,rule)
for _, c in pairs(tag:clients()) do
if not awful.rules.match_any(c, rule) then
return false
end
end
return true
endLast edited by Wey (2012-08-30 21:53:54)
Offline
Thanks Wey for pointing the way (no pun intended), after some playing around I've obtained the following:-
-- Function to count number of clients in a tag
function is_empty(tag,client)
count = 0
for _, c in pairs(tag:clients()) do
-- client is used so that won't match against self
if client.class ~= c.class then
count = count + 1
end
end
if count > 0 then
return false
end
return true
endWhich is called by the following callback:-
callback = function(c)
current_tag = tags[mouse.screen][awful.tag.getidx()]
next_tag = tags[mouse.screen][awful.tag.getidx()+1]
if is_empty(current_tag,c) then
tag = current_tag
else
tag = next_tag
end
awful.client.movetotag(tag, c)
awful.tag.viewonly(tag)
endI didn't want to use a rule since I didn't actually manage to figure out how to call rules, and just manually hard-coding c.class etc. seemed easier to me at the time. I realize I'm basically coding lua as if its C, but that's basically all I know programming wise so far
.
I'd also like to set a signal function which would rearrange all clients to lower-numbered tags when a client exist (so say if there are three clients in tag 2, 2 clients in tag 3, 1 client in tag 4 and 1, and the client in tag 1 exits, all three clients from tag 2 move to tag 1, the 2 in tag 3 move to tag 2, etc). This MAY be more easily handled by shifty though, currently don't have the time to look into it unfortunately. Once again, thanks for your help in [solve]ng this question.
Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.
Offline