Refactor some of pull request #27 improvments

* Restore the old README column width to avoid issues with some markdown
implementations

* Rename class_client and instance_client to c_rules as the old name isn't
  significative anymore.

* Merge copy/pasted code back into a single block

* Remove the unused `low`, `rules_c` and`rules_i` temporary variables
This commit is contained in:
Emmanuel Lepage Vallee 2014-05-23 13:00:21 -04:00
parent 2f219d13c6
commit b955204bc5
2 changed files with 42 additions and 52 deletions

View File

@ -225,30 +225,31 @@ Then edit this section to fit your needs.
##### The available tag properties are:
| Property | Description | Type |
| ------------------------- | -------------------------------------------------------------- |:----------------:|
| **class** | Match these classes to this tag | array of string |
| **clone_on** | Create a clone on screen(s) | number or array |
| **exclusive** | Allow only client from the "class" attributes | boolean |
| **exec_once** | Execute when the tag is first selected | string (command) |
| **force_screen** | Force a screen | boolean |
| **hide** | Hide this tag from view | boolean |
| **icon** | Tag icon | path |
| **init** | Create when awesome launch | boolean |
| **instance** | Match these instances to this tag. Takes precedence over class | array of string |
| **layout** | The tag layout | layout |
| **mwfact** | Tiled layout master/slave ratio | float(0-1) |
| **ncol** | Number of columns | number |
| **nmaster** | Number of master clients | number |
| **no_focus_stealing_in** | Do not select this tag when a new client is added | boolean |
| **no_focus_stealing_out** | Do not unselect when a new client is added elsewhere | boolean |
| **screen** | Tag screen(s) | number or array |
| **selected** | Select when created | boolean |
| **volatile** | Destroy when the last client is closed | boolean |
| **fallback** | Use this tag for unmatched clients | boolean |
| **locked** | Do not add any more clients to this tag | boolean |
| **max_clients** | Maximum number of clients before creating a new tag | number |
| Property | Description | Type |
| ------------------------- | -----------------------------------------------------|:----------------:|
| **class** | Match these classes to this tag | array of string |
| **instance** | Match these instances to this tag. ★ | array of string |
| **clone_on** | Create a clone on screen(s) | number or array |
| **exclusive** | Allow only client from the "class" attributes | boolean |
| **exec_once** | Execute when the tag is first selected | string (command) |
| **force_screen** | Force a screen | boolean |
| **hide** | Hide this tag from view | boolean |
| **icon** | Tag icon | path |
| **init** | Create when awesome launch | boolean |
| **layout** | The tag layout | layout |
| **mwfact** | Tiled layout master/slave ratio | float(0-1) |
| **ncol** | Number of columns | number |
| **nmaster** | Number of master clients | number |
| **no_focus_stealing_in** | Do not select this tag when a new client is added | boolean |
| **no_focus_stealing_out** | Do not unselect when a new client is added elsewhere | boolean |
| **screen** | Tag screen(s) | number or array |
| **selected** | Select when created | boolean |
| **volatile** | Destroy when the last client is closed | boolean |
| **fallback** | Use this tag for unmatched clients | boolean |
| **locked** | Do not add any more clients to this tag | boolean |
| **max_clients** | Maximum number of clients before creating a new tag | number |
★Takes precedence over class
##### The available client properties are:
@ -325,7 +326,7 @@ configuration wrapper.
#### Is it possible to directly launch clients in the current tag or a new one?
This feature is mostly available for Awesome 3.5.3+, 3.5.6+ is recommanded.
Tyrannical will use the "startup notification" feild in clients that support it
Tyrannical will use the "startup notification" field in clients that support it
to track a spawn request. Some applications, such as GVim and XTerm, doesn't
support this. URxvt, Konsole and Gnome terminal does.

View File

@ -11,12 +11,12 @@ require("tyrannical.extra.legacy")
-------------------------------INIT------------------------------
local signals,module,class_client,instance_client,tags_hash,settings,sn_callback,fallbacks,prop = {
local signals,module,c_rules,tags_hash,settings,sn_callback,fallbacks,prop = {
"exclusive" , "init" , "volatile" , "focus_new" , "instances" ,
"locked" , "class" , "instance" , "spawn" , "position" , "force_screen" ,
"max_clients" , "exec_once" , "clone_on" , "clone_of" , "no_focus_stealing",
"fallback" , "no_focus_stealing_out","no_focus_stealing_in"
},{},{},{},{},{},awful.spawn and awful.spawn.snid_buffer or {},{},awful.tag.getproperty
},{},{class={},instance={}},{},{},awful.spawn and awful.spawn.snid_buffer or {},{},awful.tag.getproperty
for _,sig in ipairs(signals) do
capi.tag.add_signal("property::"..sig)
@ -53,20 +53,14 @@ local function load_tags(tyrannical_tags)
elseif v.volatile == nil then
v.volatile = true
end
if v.class and class_client then
for i=1,#v.class do
local low = string.lower(v.class[i])
local tmp = class_client[low] or {tags={},properties={}}
tmp.tags[#tmp.tags+1] = v
class_client[low] = tmp
end
end
if v.instance and instance_client then
for i=1,#v.instance do
local low = string.lower(v.instance[i])
local tmp = instance_client[low] or {tags={},properties={}}
tmp.tags[#tmp.tags+1] = v
instance_client[low] = tmp
for _,prop in ipairs {"class","instance"} do
if v[prop] and c_rules[prop] then
for i=1,#v[prop] do
local low = string.lower(v[prop][i])
local tmp = c_rules[prop][low] or {tags={},properties={}}
tmp.tags[#tmp.tags+1] = v
c_rules[prop][low] = tmp
end
end
end
tags_hash[v.name or "N/A"] = v
@ -78,14 +72,14 @@ local function load_property(name,property)
for k2,v2 in pairs(property) do
local key_type = type(k2)
local low = string.lower(key_type == "number" and v2 or k2)
class_client[low] = class_client[low] or {name=low,tags={},properties={}}
class_client[low].properties[name] = key_type == "number" and true or v2
c_rules.class[low] = c_rules.class[low] or {name=low,tags={},properties={}}
c_rules.class[low].properties[name] = key_type == "number" and true or v2
end
end
--Check all focus policies then change focus (Awesome 3.5.3+)
function module.focus_client(c,properties)
local properties = properties or (instance_client[string.lower(c.instance or "N/A")] or {}).properties or (class_client[string.lower(c.class or "N/A")] or {}).properties or {}
local properties = properties or (c_rules.instance[string.lower(c.instance or "N/A")] or {}).properties or (c_rules.class[string.lower(c.class or "N/A")] or {}).properties or {}
if (((not c.transient_for) or (c.transient_for==capi.client.focus) or (not settings.block_children_focus_stealing)) and (not properties.no_autofocus)) then
if not awful.util.table.hasitem(c:tags(), awful.tag.selected(c.screen or 1)) and (not prop(c:tags()[1],"no_focus_stealing_in")) then
awful.tag.viewonly(c:tags()[1])
@ -135,12 +129,7 @@ local function match_client(c, startup)
local props = c.startup_id and sn_callback[tostring(c.startup_id)] or {}
local low_i,low_c,tags = string.lower(c.instance or "N/A"),string.lower(c.class or "N/A"),props.tags or {props.tag}
local rules_i,rules_c = instance_client[low_i],class_client[low_c]
local low,rules = low_i,rules_i
if rules_i == nil then
low,rules = low_c,rules_c
end
local rules = c_rules.instance[low_i] or c_rules.class[low_c]
if #tags == 0 and c.transient_for and settings.group_children == true then
c.sticky = c.transient_for.sticky or false
@ -188,8 +177,8 @@ local function match_client(c, startup)
return module.focus_client(c,props)
end
--Last resort, create a new tag
class_client[low_c] = class_client[low_c] or {tags={},properties={}}
local tmp,tag = class_client[low_c],awful.tag.add(c.class or "N/A",{name=c.class or "N/A",volatile=true,exclusive=true,screen=(c.screen <= capi.screen.count())
c_rules.class[low_c] = c_rules.class[low_c] or {tags={},properties={}}
local tmp,tag = c_rules.class[low_c],awful.tag.add(c.class or "N/A",{name=c.class or "N/A",volatile=true,exclusive=true,screen=(c.screen <= capi.screen.count())
and c.screen or 1,layout=settings.default_layout or awful.layout.suit.max})
tmp.tags[#tmp.tags+1] = {name=c.class or "N/A",instances = setmetatable({[c.screen]=tag}, { __mode = 'v' }),volatile=true,screen=c.screen,exclusive=true}
c:tags({tag})
@ -200,7 +189,7 @@ capi.client.connect_signal("manage", match_client)
capi.client.connect_signal("untagged", function (c, t)
if prop(t,"volatile") == true and #t:clients() == 0 then
local rules = class_client[string.lower(c.class or "N/A")]
local rules = c_rules.class[string.lower(c.class or "N/A")]
for j=1,#(rules and rules.tags or {}) do
rules.tags[j].instances[c.screen] = rules.tags[j].instances[c.screen] ~= t and rules.tags[j].instances[c.screen] or nil
end