1
0
Fork 0
mirror of https://github.com/lcpz/awesome-copycats.git synced 2025-01-11 02:08:08 +00:00
awesome-copycats/eminent/init.lua

155 lines
4.5 KiB
Lua
Raw Normal View History

2015-05-19 03:55:08 +00:00
----------------------------------------------------------------
2013-09-15 20:00:40 +00:00
-- Effortless wmii-style dynamic tagging.
2015-05-19 03:55:08 +00:00
----------------------------------------------------------------
2013-09-15 20:00:40 +00:00
-- Lucas de Vries <lucas@glacicle.org>
-- Licensed under the WTFPL version 2
-- * http://sam.zoy.org/wtfpl/COPYING
2015-05-19 03:55:08 +00:00
----------------------------------------------------------------
-- To use this module add:
-- require("eminent")
-- to the top of your rc.lua.
--
-- That's it. Through magical monkey-patching, all you need to
-- do to start dynamic tagging is loading it.
--
-- Use awesome like you normally would, you don't need to
-- change a thing.
----------------------------------------------------------------
2013-09-15 20:00:40 +00:00
-- Grab environment
local ipairs = ipairs
2015-05-19 03:55:08 +00:00
local pairs = pairs
2013-09-15 20:00:40 +00:00
local awful = require("awful")
local table = table
local capi = {
2015-05-19 03:55:08 +00:00
tag = tag,
mouse = mouse,
client = client,
2013-09-15 20:00:40 +00:00
screen = screen,
2015-05-19 03:55:08 +00:00
wibox = wibox,
timer = timer,
keygrabber = keygrabber,
2013-09-15 20:00:40 +00:00
}
2015-05-19 03:55:08 +00:00
local getscreen = capi.tag.getscreen
2013-09-15 20:00:40 +00:00
-- Eminent: Effortless wmii-style dynamic tagging
2015-05-19 03:55:08 +00:00
local eminent = {}
--- Create new tag when scrolling right from the last tag
eminent.create_new_tag = true
2013-09-15 20:00:40 +00:00
-- Grab the original functions we're replacing
local deflayout = nil
local orig = {
new = awful.tag.new,
2015-05-19 03:55:08 +00:00
viewidx = awful.tag.viewidx,
2013-09-15 20:00:40 +00:00
taglist = awful.widget.taglist.new,
2015-05-19 03:55:08 +00:00
--label = awful.widget.taglist.label.all,
label = awful.widget.taglist.filter.all,
2013-09-15 20:00:40 +00:00
}
-- Return tags with stuff on them, mark others hidden
function gettags(screen)
local tags = {}
2015-05-19 03:55:08 +00:00
--for k, t in ipairs(capi.screen[screen]:tags()) do
for k, t in ipairs(awful.tag.gettags(screen)) do
2013-09-15 20:00:40 +00:00
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
end
-- Pre-create tags
awful.tag.new = function (names, screen, layout)
deflayout = layout and layout[1] or layout
return orig.new(names, screen, layout)
end
2015-05-19 03:55:08 +00:00
-- View tag by relative index
awful.tag.viewidx = function (i, screen)
-- Hide tags
local s = screen or capi.mouse.screen
--local ctags = capi.screen[s]:tags()
local ctags = awful.tag.gettags(s)
local tags = gettags(s)
local sel = awful.tag.selected()
-- Check if we should "create" a new tag
local selidx = awful.util.table.hasitem(tags, sel)
local tagidx = awful.util.table.hasitem(ctags, sel)
-- Create a new tag if needed
if eminent.create_new_tag and
selidx == #tags and i == 1 and #sel:clients() > 0
then
-- Deselect all
awful.tag.viewnone(s)
if #ctags >= tagidx+1 then
-- Focus next
ctags[tagidx+1].selected = true
awful.tag.setproperty(ctags[tagidx+1], "hide", false)
else
-- Create new
local tag = capi.tag { name = ""..(tagidx+1) }
tag.screen = s
tag.selected = true
awful.tag.setproperty(tag, "layout", deflayout)
end
else
-- Call original
orig.viewidx(i, screen)
end
end
2013-09-15 20:00:40 +00:00
-- Taglist label functions
2015-05-19 03:55:08 +00:00
--awful.widget.taglist.label.all = function (t, args)
2013-09-15 20:00:40 +00:00
awful.widget.taglist.filter.all = function (t, args)
if t.selected or #t:clients() > 0 then
2015-05-19 03:55:08 +00:00
return orig.label(t, args)
2013-09-15 20:00:40 +00:00
end
end
2015-05-19 03:55:08 +00:00
-- Update hidden status
local function uc(c) gettags(c.screen) end
--local function ut(t) gettags(t.screen) end
local function ut(s,t) gettags(s.index) end
capi.client.connect_signal("unmanage", uc)
capi.client.connect_signal("new", function(c)
c:connect_signal("property::screen", uc)
c:connect_signal("property::urgent", uc)
c:connect_signal("tagged", uc)
c:connect_signal("untagged", uc)
c:connect_signal("focus", uc)
c:connect_signal("unfocus", uc)
end)
for screen=1, capi.screen.count() do
awful.tag.attached_connect_signal(screen, "property::selected", ut)
awful.tag.attached_connect_signal(screen, "property::icon", ut)
awful.tag.attached_connect_signal(screen, "property::hide", ut)
awful.tag.attached_connect_signal(screen, "property::name", ut)
awful.tag.attached_connect_signal(screen, "property::activated", ut)
awful.tag.attached_connect_signal(screen, "property::screen", ut)
awful.tag.attached_connect_signal(screen, "property::index", ut)
--awful.tag.attached_connect_signal(screen, "tag::history::update",uc)
capi.screen[screen]:connect_signal("tag::history::update", ut)
--capi.screen[screen]:connect_signal("tag::detach", ut)
end
return eminent