2013-02-20 18:11:17 +01:00
|
|
|
local setmetatable = setmetatable
|
|
|
|
local print , pairs = print , pairs
|
|
|
|
local ipairs , type = ipairs , type
|
2013-06-23 00:12:08 +02:00
|
|
|
local string , unpack= string,unpack
|
2013-02-20 18:11:17 +01:00
|
|
|
local awful = require("awful")
|
|
|
|
|
2014-03-30 07:21:24 +02:00
|
|
|
local capi = {client = client , tag = tag , awesome = awesome,
|
|
|
|
screen = screen , mouse = mouse }
|
2013-02-20 18:11:17 +01:00
|
|
|
|
|
|
|
-------------------------------INIT------------------------------
|
|
|
|
|
2014-04-19 05:04:13 +02:00
|
|
|
local signals,module,class_client,tags_hash,settings,sn_callback,fallbacks,prop = {
|
2013-06-24 03:51:06 +02:00
|
|
|
"exclusive" , "init" , "volatile" , "focus_new" , "instances" ,
|
|
|
|
"match" , "class" , "spawn" , "position" , "force_screen" ,
|
|
|
|
"max_clients" , "exec_once" , "clone_on" , "clone_of" , "no_focus_stealing",
|
2014-04-16 02:46:27 +02:00
|
|
|
"fallback" , "no_focus_stealing_out","no_focus_stealing_in"
|
2014-04-19 05:04:13 +02:00
|
|
|
},{},{},{},{},{},{},awful.tag.getproperty
|
2013-06-24 03:51:06 +02:00
|
|
|
|
2013-03-05 22:17:13 +01:00
|
|
|
for _,sig in ipairs(signals) do
|
2013-06-24 03:51:06 +02:00
|
|
|
capi.tag.add_signal("property::"..sig)
|
2013-02-20 18:11:17 +01:00
|
|
|
end
|
|
|
|
|
2013-06-24 03:51:06 +02:00
|
|
|
----------------------TYRANNICAL LOGIC--------------------------
|
2013-02-20 18:11:17 +01:00
|
|
|
|
2013-03-08 06:33:34 +01:00
|
|
|
--Called when a tag is selected/unselected
|
|
|
|
local function on_selected_change(tag,data)
|
2014-04-13 02:31:58 +02:00
|
|
|
if data and data.exec_once and tag.selected then
|
|
|
|
for _,v in ipairs(type(data.exec_once) == "string" and {data.exec_once} or data.exec_once) do
|
|
|
|
awful.util.spawn_with_shell("ps -ef | grep -v grep | grep '" .. v .. "' > /dev/null || (" .. v .. ")")
|
2013-03-08 06:33:34 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-20 18:11:17 +01:00
|
|
|
--Load tags, this cannot be undone
|
2013-03-22 03:10:21 +01:00
|
|
|
local function load_tags(tyrannical_tags)
|
|
|
|
for k,v in ipairs(tyrannical_tags) do
|
2013-02-20 18:11:17 +01:00
|
|
|
if v.init ~= false then
|
|
|
|
local stype = type(v.screen)
|
|
|
|
if stype == "table" then
|
2013-06-02 21:36:33 +02:00
|
|
|
local screens = v.screen
|
|
|
|
for k2,v2 in pairs(screens) do
|
2013-02-20 18:11:17 +01:00
|
|
|
if v2 <= capi.screen.count() then
|
|
|
|
v.screen = v2
|
2013-05-22 04:43:07 +02:00
|
|
|
awful.tag.add(v.name,v)
|
2013-02-20 18:11:17 +01:00
|
|
|
end
|
|
|
|
end
|
2013-06-02 21:36:33 +02:00
|
|
|
v.screen = screens
|
2013-02-20 18:11:17 +01:00
|
|
|
elseif (v.screen or 1) <= capi.screen.count() then
|
2013-05-22 04:43:07 +02:00
|
|
|
awful.tag.add(v.name,v)
|
2013-02-20 18:11:17 +01:00
|
|
|
end
|
|
|
|
elseif v.volatile == nil then
|
|
|
|
v.volatile = true
|
|
|
|
end
|
2013-06-24 03:51:06 +02:00
|
|
|
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
|
2013-05-17 07:46:29 +02:00
|
|
|
tags_hash[v.name or "N/A"] = v
|
2013-02-20 18:11:17 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--Load property
|
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-24 03:51:06 +02:00
|
|
|
--Apply all properties
|
|
|
|
local function apply_properties(c,override,normal)
|
2014-04-19 05:04:13 +02:00
|
|
|
local props = awful.util.table.join(normal,override)
|
2013-06-24 03:51:06 +02:00
|
|
|
--Set all 'c.something' properties
|
2014-04-19 05:04:13 +02:00
|
|
|
for k,_ in pairs(props) do
|
|
|
|
props[k] = (override[v] ~= nil) and override[k] or normal[k]
|
|
|
|
c[k] = props[k]
|
2013-06-24 03:51:06 +02:00
|
|
|
end
|
|
|
|
--Force floating state, if necessary
|
2014-04-19 05:04:13 +02:00
|
|
|
if props.floating ~= nil then
|
|
|
|
awful.client.floating.set(c, props.floating)
|
2013-06-24 03:51:06 +02:00
|
|
|
end
|
|
|
|
--Center client
|
2014-04-19 05:04:13 +02:00
|
|
|
if props.centered == true then
|
2013-06-24 03:51:06 +02:00
|
|
|
awful.placement.centered(c, nil)
|
|
|
|
end
|
|
|
|
--Focus new client
|
2014-04-19 05:04:13 +02:00
|
|
|
if props.focus_new ~= false and (c.transient_for and not settings.block_transient_for_focus_stealing) then
|
2013-06-24 03:51:06 +02:00
|
|
|
capi.client.focus = c
|
|
|
|
end
|
|
|
|
--Add to the current tag if the client is intrusive, ignore exclusive
|
2014-04-19 05:04:13 +02:00
|
|
|
if props.intrusive == true or (settings.force_odd_as_intrusive and c.type ~= "normal") then
|
2013-06-24 03:51:06 +02:00
|
|
|
local tag = awful.tag.selected(c.screen)
|
|
|
|
if not tag then
|
|
|
|
awful.tag.viewonly(awful.tag.gettags(c.screen)[1])
|
|
|
|
end
|
|
|
|
tag = awful.tag.selected(c.screen)
|
|
|
|
if tag then --Can be false if there is no tags
|
|
|
|
return c:tags({tag})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-20 18:11:17 +01:00
|
|
|
--Match client
|
|
|
|
local function match_client(c, startup)
|
|
|
|
if not c then return end
|
2014-03-30 07:21:24 +02:00
|
|
|
local startup = startup == nil and capi.awesome.startup or startup
|
2013-10-11 06:08:58 +02:00
|
|
|
if c.startup_id and sn_callback[c.startup_id] and sn_callback[c.startup_id](c,startup) then return end
|
2013-02-20 18:11:17 +01:00
|
|
|
local low = string.lower(c.class or "N/A")
|
|
|
|
local rules = class_client[low]
|
2013-06-14 06:24:55 +02:00
|
|
|
if c.transient_for and settings.group_children == true then
|
|
|
|
c.sticky = c.transient_for.sticky or false
|
2013-08-23 16:40:11 +02:00
|
|
|
c:tags(c.transient_for:tags())
|
|
|
|
capi.client.focus = c
|
|
|
|
return
|
2013-06-14 06:24:55 +02:00
|
|
|
elseif rules then
|
2013-06-24 03:51:06 +02:00
|
|
|
local ret = apply_properties(c,{},rules.properties)
|
2013-08-26 14:04:51 +02:00
|
|
|
if ret then
|
|
|
|
if not rules.properties.no_autofocus then
|
|
|
|
capi.client.focus = c
|
|
|
|
end
|
|
|
|
return ret
|
|
|
|
end
|
2013-02-20 18:11:17 +01:00
|
|
|
--Add to matches
|
2013-06-23 00:12:08 +02:00
|
|
|
local tags,tags_src,fav_scr,c_src,mouse_s = {},{},false,c.screen,capi.mouse.screen
|
2013-02-20 18:11:17 +01:00
|
|
|
for j=1,#(rules.tags or {}) do
|
2013-06-23 00:12:08 +02:00
|
|
|
local tag,cache = rules.tags[j],rules.tags[j].screen
|
|
|
|
tag.instances,has_screen = tag.instances or {},(type(tag.screen)=="table" and awful.util.table.hasitem(tag.screen,c_src)~=nil)
|
|
|
|
tag.screen = (tag.force_screen ~= true and c_src) or (has_screen and c_src or type(tag.screen)=="table" and tag.screen[1] or tag.screen)
|
2014-04-19 05:04:13 +02:00
|
|
|
tag.screen,match = (tag.screen <= capi.screen.count()) and tag.screen or mouse_s,tag.instances[tag.screen]
|
|
|
|
if (not match and not (fav_scr == true and mouse_s ~= tag.screen)) or (match and (prop(match,"max_clients") or 999) <= #match:clients()) then
|
2013-06-23 00:12:08 +02:00
|
|
|
awful.tag.add(tag.name,tag)
|
2013-02-20 18:11:17 +01:00
|
|
|
end
|
2013-06-23 00:12:08 +02:00
|
|
|
tags_src[tag.screen],fav_scr = tags_src[tag.screen] or {},fav_scr or (tag.screen == mouse_s) --Reset if a better screen is found
|
|
|
|
tags_src[tag.screen][#tags_src[tag.screen]+1] = tag.instances[tag.screen]
|
|
|
|
tag.screen = cache
|
2013-02-20 18:11:17 +01:00
|
|
|
end
|
2014-04-19 04:47:30 +02:00
|
|
|
for k,t in ipairs(tags_src[mouse_s] or tags_src[c_src] or select(2,next(tags_src)) or awful.util.table.join(unpack(tags_src))) do
|
2014-04-19 05:04:13 +02:00
|
|
|
tags[#tags+1] = prop(t,"locked") ~= true and t or nil --Do not add to locked tags
|
2014-04-19 04:47:30 +02:00
|
|
|
end
|
2013-06-23 00:12:08 +02:00
|
|
|
c.screen = tags[1] and awful.tag.getscreen(tags[1]) or c_src
|
2014-04-19 04:47:30 +02:00
|
|
|
if #tags > 0 then
|
2013-02-20 18:11:17 +01:00
|
|
|
c:tags(tags)
|
2014-04-19 05:04:13 +02:00
|
|
|
if prop(tags[1],"focus_new") ~= false and not (c.transient_for and settings.block_transient_for_focus_stealing)
|
|
|
|
and not prop(tags[1],"no_focus_stealing_in") then
|
2013-02-20 18:11:17 +01:00
|
|
|
awful.tag.viewonly(tags[1])
|
|
|
|
end
|
2013-08-23 16:40:11 +02:00
|
|
|
if not rules.properties.no_autofocus then
|
|
|
|
capi.client.focus = c
|
|
|
|
end
|
2013-02-20 18:11:17 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
--Add to the current tag if not exclusive
|
2013-03-09 07:47:42 +01:00
|
|
|
local cur_tag = awful.tag.selected(c.screen)
|
2014-04-19 05:04:13 +02:00
|
|
|
if cur_tag and prop(cur_tag,"exclusive") ~= true and prop(cur_tag,"locked") ~= true then
|
2013-08-23 16:40:11 +02:00
|
|
|
c:tags({cur_tag})
|
|
|
|
capi.client.focus = c
|
|
|
|
return true
|
2013-03-09 07:47:42 +01:00
|
|
|
end
|
2014-04-13 08:00:59 +02:00
|
|
|
--Add to the fallback tags
|
|
|
|
if #c:tags((function(arr) for k,v in ipairs(fallbacks) do
|
|
|
|
arr[#arr+1]=awful.tag.getscreen(v) == c.screen and v or nil
|
|
|
|
end; return arr
|
2014-04-16 02:46:27 +02:00
|
|
|
end)({})) > 0 then -- Select the first fallback tag if the current tag isn't a fallback
|
|
|
|
return (not awful.util.table.hasitem(c:tags(), awful.tag.selected(c.screen or 1))) and awful.tag.viewonly(c:tags()[1])
|
|
|
|
end
|
2013-02-20 18:11:17 +01:00
|
|
|
--Last resort, create a new tag
|
|
|
|
class_client[low] = class_client[low] or {tags={},properties={}}
|
2013-11-26 13:35:57 +01:00
|
|
|
local tmp,tag = class_client[low],awful.tag.add(c.class or "N/A",{name=c.class or "N/A",volatile=true,exclusive=true,screen=(c.screen <= capi.screen.count())
|
2013-06-14 07:01:59 +02:00
|
|
|
and c.screen or 1,layout=settings.default_layout or awful.layout.suit.max})
|
2013-11-26 13:35:57 +01:00
|
|
|
tmp.tags[#tmp.tags+1] = {name=c.class or "N/A",instances = {[c.screen]=tag},volatile=true,screen=c.screen,exclusive=true}
|
2013-02-20 18:11:17 +01:00
|
|
|
c:tags({tag})
|
2014-04-19 05:04:13 +02:00
|
|
|
if prop(tag,"focus_on_new") ~= false then
|
2013-03-22 03:10:21 +01:00
|
|
|
awful.tag.viewonly(tag)
|
|
|
|
end
|
2013-02-20 18:11:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
capi.client.connect_signal("manage", match_client)
|
|
|
|
|
|
|
|
capi.client.connect_signal("untagged", function (c, t)
|
2014-04-19 05:04:13 +02:00
|
|
|
if prop(t,"volatile") == true and #t:clients() == 0 then
|
2013-02-20 18:11:17 +01:00
|
|
|
local rules = class_client[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
|
|
|
|
awful.tag.delete(t)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2013-03-08 06:33:34 +01:00
|
|
|
awful.tag.withcurrent,awful.tag._add = function(c, startup)
|
2013-02-20 18:11:17 +01:00
|
|
|
local tags,old_tags = {},c:tags()
|
|
|
|
--Safety to prevent
|
|
|
|
for k, t in ipairs(old_tags) do
|
2013-08-09 00:28:06 +02:00
|
|
|
tags[#tags+1] = (awful.tag.getscreen(t) == c.screen) and t or nil
|
2013-02-20 18:11:17 +01:00
|
|
|
end
|
|
|
|
--Necessary when dragging clients
|
|
|
|
if startup == nil and old_tags[1] and old_tags[1].screen ~= c.screen then --nil != false
|
|
|
|
local sellist = awful.tag.selectedlist(c.screen)
|
|
|
|
if #sellist > 0 then --Use already selected tag
|
|
|
|
tags = sellist
|
|
|
|
else --Select a tag
|
|
|
|
match_client(c, startup)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
c:tags(tags)
|
2013-03-08 06:33:34 +01:00
|
|
|
end,awful.tag.add
|
|
|
|
|
2013-03-09 07:27:06 +01:00
|
|
|
awful.tag.add,awful.tag._setscreen = function(tag,props)
|
2013-08-09 00:28:06 +02:00
|
|
|
props.screen,props.instances = props.screen or capi.mouse.screen,props.instances or {}
|
|
|
|
props.mwfact,props.layout = props.mwfact or settings.mwfact,props.layout or settings.default_layout or awful.layout.max
|
2013-03-08 06:33:34 +01:00
|
|
|
local t = awful.tag._add(tag,props)
|
2014-04-19 05:04:13 +02:00
|
|
|
if prop(t,"clone_on") and prop(t,"clone_on") ~= t.screen then
|
|
|
|
local t3 = awful.tag._add(tag,{screen = prop(t,"clone_on"), clone_of = t,icon=awful.tag.geticon(t)})
|
2013-03-09 07:27:06 +01:00
|
|
|
--TODO prevent clients from being added to the clone
|
|
|
|
end
|
2014-04-13 08:00:59 +02:00
|
|
|
fallbacks[#fallbacks+1] = props.fallback and t or nil
|
2013-05-16 21:19:52 +02:00
|
|
|
t:connect_signal("property::selected", function(t) on_selected_change(t,props or {}) end)
|
2013-05-24 17:22:36 +02:00
|
|
|
t.selected = props.selected or false
|
2013-06-02 21:36:33 +02:00
|
|
|
props.instances[props.screen] = t
|
2013-03-08 06:33:34 +01:00
|
|
|
return t
|
2013-03-09 07:27:06 +01:00
|
|
|
end,awful.tag.setscreen
|
|
|
|
|
2014-03-30 07:21:24 +02:00
|
|
|
awful.tag._viewonly = awful.tag.viewonly
|
|
|
|
|
|
|
|
-- Check is Awesome is 3.5.3+
|
|
|
|
if capi.awesome.startup == nil then
|
|
|
|
-- Monkey patch a bug fixed in 3.5.3
|
|
|
|
awful.tag.setscreen = function(tag,screen)
|
|
|
|
if not tag or type(tag) ~= "tag" then return end
|
|
|
|
awful.tag._setscreen(tag,screen)
|
|
|
|
for k,c in ipairs(tag:clients()) do
|
|
|
|
c.screen = screen or 1 --Move all clients
|
|
|
|
c:tags({tag}) --Prevent some very strange side effects, does create some issue with multitag clients
|
|
|
|
end
|
|
|
|
awful.tag.history.restore(tag.screen,1)
|
2013-03-09 07:27:06 +01:00
|
|
|
end
|
2014-03-30 07:21:24 +02:00
|
|
|
else
|
|
|
|
-- Restore the old behavior in newer Awesome
|
|
|
|
require("tyrannical.extra.request")
|
|
|
|
end
|
2013-03-09 07:27:06 +01:00
|
|
|
|
|
|
|
awful.tag.viewonly = function(t)
|
2013-06-14 06:24:55 +02:00
|
|
|
if not t then return end
|
2013-11-26 13:35:57 +01:00
|
|
|
if not awful.tag.getscreen(t) then awful.tag.setscreen(capi.mouse.screen) end
|
2013-03-09 07:27:06 +01:00
|
|
|
awful.tag._viewonly(t)
|
2014-04-19 05:04:13 +02:00
|
|
|
if prop(t,"clone_of") then
|
|
|
|
awful.tag.swap(t,prop(t,"clone_of"))
|
|
|
|
awful.tag.viewonly(prop(t,"clone_of"))
|
2013-03-09 07:27:06 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
awful.tag.swap = function(tag1,tag2)
|
|
|
|
local idx1,idx2,scr2 = awful.tag.getidx(tag1),awful.tag.getidx(tag2),awful.tag.getscreen(tag2)
|
|
|
|
awful.tag.setscreen(tag2,awful.tag.getscreen(tag1))
|
|
|
|
awful.tag.move(idx1,tag2)
|
|
|
|
awful.tag.setscreen(tag1,scr2)
|
|
|
|
awful.tag.move(idx2,tag1)
|
2013-02-20 18:11:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------OBJECT GEARS---------------------------
|
2013-06-14 06:24:55 +02:00
|
|
|
local getter = {properties = setmetatable({}, {__newindex = function(table,k,v) load_property(k,v) end}),
|
2013-10-11 06:08:58 +02:00
|
|
|
settings = settings, tags_by_name = tags_hash, sn_callback = sn_callback}
|
2013-06-14 06:24:55 +02:00
|
|
|
local setter = {tags = load_tags}
|
2013-02-20 18:11:17 +01:00
|
|
|
|
2013-08-23 16:40:11 +02:00
|
|
|
return setmetatable(module,{__index=function(t,k) return getter[k] end,__newindex=function(t,k,v) if setter[k] then return setter[k](v) end end})
|