2008-09-29 16:49:18 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2008 Julien Danjou
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment we need
|
|
|
|
local util = require("awful.util")
|
|
|
|
local pairs = pairs
|
|
|
|
local ipairs = ipairs
|
2009-05-30 18:11:07 +02:00
|
|
|
local table = table
|
2009-04-11 14:04:51 +02:00
|
|
|
local setmetatable = setmetatable
|
2008-09-29 16:49:18 +02:00
|
|
|
local capi =
|
|
|
|
{
|
|
|
|
screen = screen,
|
2009-07-10 14:36:04 +02:00
|
|
|
mouse = mouse,
|
|
|
|
client = client
|
2008-09-29 16:49:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
--- Tag module for awful
|
|
|
|
module("awful.tag")
|
|
|
|
|
|
|
|
-- Private data
|
|
|
|
local data = {}
|
|
|
|
data.history = {}
|
|
|
|
data.history.past = {}
|
|
|
|
data.history.current = {}
|
2009-04-11 14:04:51 +02:00
|
|
|
data.tags = setmetatable({}, { __mode = 'k' })
|
2008-09-29 16:49:18 +02:00
|
|
|
|
|
|
|
-- History functions
|
|
|
|
history = {}
|
|
|
|
|
2009-01-08 12:26:12 +01:00
|
|
|
-- Compare 2 tables of tags.
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @param a The first table.
|
|
|
|
-- @param b The second table of tags.
|
|
|
|
-- @return True if the tables are identical, false otherwise.
|
|
|
|
local function compare_select(a, b)
|
|
|
|
if not a or not b then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
-- Quick size comparison
|
|
|
|
if #a ~= #b then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
for ka, va in pairs(a) do
|
|
|
|
if b[ka] ~= va.selected then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for kb, vb in pairs(b) do
|
|
|
|
if a[kb].selected ~= vb then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Update the tag history.
|
|
|
|
-- @param screen The screen number.
|
|
|
|
function history.update(screen)
|
|
|
|
local curtags = capi.screen[screen]:tags()
|
|
|
|
if not compare_select(curtags, data.history.current[screen]) then
|
|
|
|
data.history.past[screen] = data.history.current[screen]
|
|
|
|
data.history.current[screen] = {}
|
|
|
|
for k, v in ipairs(curtags) do
|
|
|
|
data.history.current[screen][k] = v.selected
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-04-29 14:58:41 +02:00
|
|
|
--- Revert tag history.
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @param screen The screen number.
|
|
|
|
function history.restore(screen)
|
|
|
|
local s = screen or capi.mouse.screen
|
|
|
|
local tags = capi.screen[s]:tags()
|
|
|
|
for k, t in pairs(tags) do
|
|
|
|
t.selected = data.history.past[s][k]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Return a table with all visible tags
|
|
|
|
-- @param s Screen number.
|
|
|
|
-- @return A table with all selected tags.
|
|
|
|
function selectedlist(s)
|
|
|
|
local screen = s or capi.mouse.screen
|
|
|
|
local tags = capi.screen[screen]:tags()
|
|
|
|
local vtags = {}
|
|
|
|
for i, t in pairs(tags) do
|
|
|
|
if t.selected then
|
|
|
|
vtags[#vtags + 1] = t
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return vtags
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Return only the first visible tag.
|
|
|
|
-- @param s Screen number.
|
|
|
|
function selected(s)
|
|
|
|
return selectedlist(s)[1]
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Set master width factor.
|
|
|
|
-- @param mwfact Master width factor.
|
2008-11-25 17:01:06 +01:00
|
|
|
function setmwfact(mwfact, t)
|
|
|
|
local t = t or selected()
|
2009-01-26 10:37:52 +01:00
|
|
|
if mwfact >= 0 and mwfact <= 1 then
|
|
|
|
setproperty(t, "mwfact", mwfact)
|
|
|
|
end
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Increase master width factor.
|
|
|
|
-- @param add Value to add to master width factor.
|
2008-11-25 17:01:06 +01:00
|
|
|
function incmwfact(add, t)
|
|
|
|
setmwfact(getmwfact(t) + add)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Get master width factor.
|
|
|
|
-- @param t Optional tag.
|
|
|
|
function getmwfact(t)
|
|
|
|
local t = t or selected()
|
|
|
|
return getproperty(t, "mwfact") or 0.5
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Set the number of master windows.
|
|
|
|
-- @param nmaster The number of master windows.
|
2008-11-25 17:01:06 +01:00
|
|
|
-- @param t Optional tag.
|
|
|
|
function setnmaster(nmaster, t)
|
|
|
|
local t = t or selected()
|
2009-01-26 10:37:52 +01:00
|
|
|
if nmaster >= 0 then
|
|
|
|
setproperty(t, "nmaster", nmaster)
|
|
|
|
end
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Get the number of master windows.
|
|
|
|
-- @param t Optional tag.
|
|
|
|
function getnmaster(t)
|
|
|
|
local t = t or selected()
|
|
|
|
return getproperty(t, "nmaster") or 1
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Increase the number of master windows.
|
|
|
|
-- @param add Value to add to number of master windows.
|
2008-11-25 17:01:06 +01:00
|
|
|
function incnmaster(add, t)
|
|
|
|
setnmaster(getnmaster(t) + add)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
2009-01-13 16:04:11 +01:00
|
|
|
|
|
|
|
--- Set the tag icon
|
|
|
|
-- @param icon the icon to set, either path or image object
|
|
|
|
-- @param tag the tag
|
|
|
|
function seticon(icon, tag)
|
|
|
|
local tag = tag or selected()
|
|
|
|
setproperty(tag, "icon", icon)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Get the tag icon
|
|
|
|
-- @param t the tag
|
|
|
|
function geticon(tag)
|
|
|
|
local tag = tag or selected()
|
|
|
|
return getproperty(tag, "icon")
|
|
|
|
end
|
|
|
|
|
2008-09-29 16:49:18 +02:00
|
|
|
--- Set number of column windows.
|
|
|
|
-- @param ncol The number of column.
|
2008-11-25 17:01:06 +01:00
|
|
|
function setncol(ncol, t)
|
|
|
|
local t = t or selected()
|
2009-01-26 10:37:52 +01:00
|
|
|
if ncol >= 1 then
|
|
|
|
setproperty(t, "ncol", ncol)
|
|
|
|
end
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Get number of column windows.
|
|
|
|
-- @param t Optional tag.
|
|
|
|
function getncol(t)
|
|
|
|
local t = t or selected()
|
|
|
|
return getproperty(t, "ncol") or 1
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Increase number of column windows.
|
|
|
|
-- @param add Value to add to number of column windows.
|
2008-11-25 17:01:06 +01:00
|
|
|
function incncol(add, t)
|
|
|
|
setncol(getncol(t) + add)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- View no tag.
|
|
|
|
-- @param Optional screen number.
|
|
|
|
function viewnone(screen)
|
|
|
|
local tags = capi.screen[screen or capi.mouse.screen]:tags()
|
|
|
|
for i, t in pairs(tags) do
|
|
|
|
t.selected = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-05-30 18:11:07 +02:00
|
|
|
--- View a tag by its taglist index.
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @param i The relative index to see.
|
|
|
|
-- @param screen Optional screen number.
|
|
|
|
function viewidx(i, screen)
|
|
|
|
local tags = capi.screen[screen or capi.mouse.screen]:tags()
|
2009-05-30 18:11:07 +02:00
|
|
|
local showntags = {}
|
|
|
|
for k, t in ipairs(tags) do
|
|
|
|
if not getproperty(t, "hide") then
|
|
|
|
table.insert(showntags, t)
|
|
|
|
end
|
|
|
|
end
|
2009-01-17 18:55:03 +01:00
|
|
|
local sel = selected(screen)
|
|
|
|
viewnone(screen)
|
2009-05-30 18:11:07 +02:00
|
|
|
for k, t in ipairs(showntags) do
|
2008-09-29 16:49:18 +02:00
|
|
|
if t == sel then
|
2009-05-30 18:11:07 +02:00
|
|
|
showntags[util.cycle(#showntags, k + i)].selected = true
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- View next tag. This is the same as tag.viewidx(1).
|
|
|
|
function viewnext()
|
|
|
|
return viewidx(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- View previous tag. This is the same a tag.viewidx(-1).
|
|
|
|
function viewprev()
|
|
|
|
return viewidx(-1)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- View only a tag.
|
|
|
|
-- @param t The tag object.
|
|
|
|
function viewonly(t)
|
|
|
|
viewnone(t.screen)
|
|
|
|
t.selected = true
|
|
|
|
end
|
|
|
|
|
|
|
|
--- View only a set of tags.
|
|
|
|
-- @param tags A table with tags to view only.
|
|
|
|
-- @param screen Optional screen number of the tags.
|
|
|
|
function viewmore(tags, screen)
|
|
|
|
viewnone(screen)
|
|
|
|
for i, t in pairs(tags) do
|
|
|
|
t.selected = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-02-24 21:50:46 +01:00
|
|
|
--- Get tag data table.
|
|
|
|
-- @param tag The Tag.
|
|
|
|
-- @return The data table.
|
|
|
|
function getdata(tag)
|
|
|
|
return data.tags[tag]
|
|
|
|
end
|
|
|
|
|
2008-11-25 17:01:06 +01:00
|
|
|
--- Get a tag property.
|
|
|
|
-- @param tag The tag.
|
|
|
|
-- @param prop The property name.
|
|
|
|
-- @return The property.
|
|
|
|
function getproperty(tag, prop)
|
|
|
|
if data.tags[tag] then
|
|
|
|
return data.tags[tag][prop]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Set a tag property.
|
|
|
|
-- This properties are internal to awful. Some are used to draw taglist, or to
|
|
|
|
-- handle layout, etc.
|
|
|
|
-- @param tag The tag.
|
|
|
|
-- @param prop The property name.
|
|
|
|
-- @param value The value.
|
|
|
|
function setproperty(tag, prop, value)
|
2009-04-11 14:04:51 +02:00
|
|
|
if not data.tags[tag] then
|
|
|
|
data.tags[tag] = {}
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
2009-04-11 14:04:51 +02:00
|
|
|
data.tags[tag][prop] = value
|
2009-08-11 15:27:31 +02:00
|
|
|
tag:emit_signal("property::" .. prop)
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
|
|
|
|
2009-02-03 12:20:17 +01:00
|
|
|
--- Tag a client with the set of current tags.
|
|
|
|
-- @param c The client to tag.
|
|
|
|
-- @param startup Optional: don't do anything if true.
|
|
|
|
function withcurrent(c, startup)
|
|
|
|
if startup ~= true and c.sticky == false then
|
|
|
|
if c.transient_for then
|
|
|
|
c.screen = c.transient_for.screen
|
|
|
|
c:tags(c.transient_for:tags())
|
|
|
|
end
|
|
|
|
if #c:tags() == 0 then
|
|
|
|
c:tags(selectedlist(c.screen))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-18 16:44:03 +02:00
|
|
|
local function attached_add_signal_screen(screen, sig, func)
|
|
|
|
capi.screen[screen]:add_signal("tag::attach", function (s, tag)
|
|
|
|
tag:add_signal(sig, func)
|
|
|
|
end)
|
|
|
|
capi.screen[screen]:add_signal("tag::detach", function (s, tag)
|
|
|
|
tag:remove_signal(sig, func)
|
|
|
|
end)
|
|
|
|
for _, tag in ipairs(capi.screen[screen]:tags()) do
|
|
|
|
tag:add_signal(sig, func)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Add a signal to all attached tag and all tag that will be attached in the
|
|
|
|
-- future. When a tag is detach from the screen, its signal is removed.
|
|
|
|
-- @param screen The screen concerned, or all if nil.
|
|
|
|
function attached_add_signal(screen, ...)
|
|
|
|
if screen then
|
|
|
|
attached_add_signal_screen(screen, ...)
|
|
|
|
else
|
|
|
|
for screen = 1, capi.screen.count() do
|
|
|
|
attached_add_signal_screen(screen, ...)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-11 15:27:31 +02:00
|
|
|
-- Register standards signals
|
2009-07-10 14:36:04 +02:00
|
|
|
capi.client.add_signal("manage", withcurrent)
|
2008-09-29 16:49:18 +02:00
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|