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")
|
2010-06-01 11:42:52 +02:00
|
|
|
local tostring = tostring
|
2008-09-29 16:49:18 +02:00
|
|
|
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 =
|
|
|
|
{
|
2009-08-21 15:50:01 +02:00
|
|
|
tag = tag,
|
2008-09-29 16:49:18 +02:00
|
|
|
screen = screen,
|
2009-07-10 14:36:04 +02:00
|
|
|
mouse = mouse,
|
|
|
|
client = client
|
2008-09-29 16:49:18 +02:00
|
|
|
}
|
|
|
|
|
2009-08-28 15:40:01 +02:00
|
|
|
--- Useful functions for tag manipulation.
|
2008-09-29 16:49:18 +02:00
|
|
|
module("awful.tag")
|
|
|
|
|
|
|
|
-- Private data
|
|
|
|
local data = {}
|
|
|
|
data.history = {}
|
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-08-27 16:03:45 +02:00
|
|
|
history.limit = 20
|
2008-09-29 16:49:18 +02:00
|
|
|
|
2010-05-29 01:39:17 +02:00
|
|
|
--- Move a tag to an absolute position in the screen[]:tags() table.
|
|
|
|
-- @param new_index Integer absolute position in the table to insert.
|
|
|
|
function move(new_index, target_tag)
|
|
|
|
local target_tag = target_tag or selected()
|
|
|
|
local scr = target_tag.screen
|
|
|
|
local tmp_tags = capi.screen[scr]:tags()
|
|
|
|
|
|
|
|
if (not new_index) or (new_index < 1) or (new_index > #tmp_tags) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
for i, t in ipairs(tmp_tags) do
|
|
|
|
if t == target_tag then
|
|
|
|
table.remove(tmp_tags, i)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
table.insert(tmp_tags, new_index, target_tag)
|
|
|
|
capi.screen[scr]:tags(tmp_tags)
|
|
|
|
end
|
|
|
|
|
2010-05-28 09:29:23 +02:00
|
|
|
--- Add a tag.
|
|
|
|
-- @param name The tag name, a string
|
|
|
|
-- @param props The tags properties, a table
|
2010-09-08 10:18:21 +02:00
|
|
|
-- @return The created tag
|
2010-05-28 09:29:23 +02:00
|
|
|
function add(name, props)
|
|
|
|
local properties = props or {}
|
|
|
|
local newtag = capi.tag{name = name}
|
|
|
|
newtag.screen = properties.screen or capi.mouse.screen
|
|
|
|
|
|
|
|
for k, v in pairs(properties) do
|
|
|
|
setproperty(newtag, k, v)
|
|
|
|
end
|
|
|
|
|
|
|
|
return newtag
|
|
|
|
end
|
|
|
|
|
2009-08-21 15:50:01 +02:00
|
|
|
--- Create a set of tags and attach it to a screen.
|
|
|
|
-- @param names The tag name, in a table
|
|
|
|
-- @param screen The tag screen, or 1 if not set.
|
2009-10-26 10:58:39 +01:00
|
|
|
-- @param layout The layout or layout table to set for this tags by default.
|
2009-08-21 15:50:01 +02:00
|
|
|
-- @return A table with all created tags.
|
|
|
|
function new(names, screen, layout)
|
|
|
|
local screen = screen or 1
|
|
|
|
local tags = {}
|
|
|
|
for id, name in ipairs(names) do
|
2010-05-28 09:29:23 +02:00
|
|
|
table.insert(tags, id, add(name, {screen = screen,
|
|
|
|
layout = (layout and layout[id]) or
|
|
|
|
layout}))
|
2009-08-21 15:50:01 +02:00
|
|
|
-- Select the first tag.
|
|
|
|
if id == 1 then
|
2010-05-28 09:29:23 +02:00
|
|
|
tags[id].selected = true
|
2009-08-21 15:50:01 +02:00
|
|
|
end
|
|
|
|
end
|
2010-05-28 09:29:23 +02:00
|
|
|
|
2009-08-21 15:50:01 +02:00
|
|
|
return tags
|
|
|
|
end
|
|
|
|
|
2010-08-02 20:25:30 +02:00
|
|
|
--- Find a suitable fallback tag.
|
|
|
|
-- @param screen The screen number to look for a tag on. [mouse.screen]
|
|
|
|
-- @param target A table of tags we consider unacceptable. [selectedlist(scr)]
|
|
|
|
function find_fallback(screen, invalids)
|
|
|
|
local scr = screen or capi.mouse.screen
|
|
|
|
local t = invalids or selectedlist(scr)
|
|
|
|
|
|
|
|
for _, v in pairs(capi.screen[scr]:tags()) do
|
|
|
|
if not util.table.hasitem(t, v) then return v end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Delete a tag.
|
|
|
|
-- @param target_tag Optional tag object to delete. [selected()]
|
|
|
|
-- @param fallback_tag Tag to assign stickied tags to. [~selected()]
|
|
|
|
-- @return Returns true if the tag is successfully deleted, nil otherwise.
|
|
|
|
-- If there are no clients exclusively on this tag then delete it. Any
|
|
|
|
-- stickied clients are assigned to the optional 'fallback_tag'.
|
|
|
|
-- If after deleting the tag there is no selected tag, try and restore from
|
|
|
|
-- history or select the first tag on the screen.
|
|
|
|
function delete(target_tag, fallback_tag)
|
|
|
|
-- abort if no tag is passed or currently selected
|
|
|
|
local target_tag = target_tag or selected()
|
|
|
|
if target_tag == nil then return end
|
|
|
|
|
|
|
|
local ntags = #capi.screen[target_tag.screen]:tags()
|
|
|
|
local target_scr = target_tag.screen
|
|
|
|
|
|
|
|
-- We can't use the target tag as a fallback.
|
|
|
|
local fallback_tag = fallback_tag
|
|
|
|
if fallback_tag == target_tag then return end
|
|
|
|
|
|
|
|
-- No fallback_tag provided, try and get one.
|
|
|
|
if fallback_tag == nil then
|
|
|
|
fallback_tag = find_fallback(target_scr, {target_tag})
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Abort if we would have un-tagged clients.
|
|
|
|
local clients = target_tag:clients()
|
|
|
|
if ( #clients > 0 and ntags <= 1 ) or fallback_tag == nil then return end
|
|
|
|
|
|
|
|
-- Move the clients we can off of this tag.
|
|
|
|
for _, c in pairs(clients) do
|
|
|
|
|
|
|
|
-- If a client has only this tag, or stickied clients with
|
|
|
|
-- nowhere to go, abort.
|
|
|
|
if (not c.sticky and #c:tags() == 1) or
|
|
|
|
(c.sticky and fallback_tag == nil) then
|
|
|
|
return
|
|
|
|
else
|
|
|
|
c:tags({fallback_tag})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- delete the tag
|
|
|
|
target_tag.screen = nil
|
|
|
|
|
|
|
|
-- If no tags are visible, try and view one.
|
|
|
|
if selected(target_scr) == nil and ntags > 0 then
|
|
|
|
history.restore()
|
|
|
|
if selected(target_scr) == nil then
|
|
|
|
capi.screen[target_scr]:tags()[1].selected = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2008-09-29 16:49:18 +02:00
|
|
|
--- Update the tag history.
|
2009-08-27 16:03:45 +02:00
|
|
|
-- @param obj Screen object.
|
|
|
|
function history.update(obj)
|
|
|
|
local s = obj.index
|
|
|
|
-- create history table
|
|
|
|
if not data.history[s] then
|
|
|
|
data.history[s] = {}
|
|
|
|
-- limit history
|
|
|
|
elseif #data.history[s] >= history.limit then
|
|
|
|
for i = history.limit, #data.history[s] do
|
|
|
|
data.history[s][i] = nil
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
2009-08-27 16:03:45 +02:00
|
|
|
-- store previously selected tags in the history table
|
|
|
|
table.insert(data.history[s], 1, data.history[s].current)
|
|
|
|
data.history[s].previous = data.history[s][1]
|
|
|
|
-- store currently selected tags
|
|
|
|
data.history[s].current = setmetatable(selectedlist(s), { __mode = 'v' })
|
2008-09-29 16:49:18 +02:00
|
|
|
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.
|
2009-08-27 16:03:45 +02:00
|
|
|
-- @param idx Index in history. Defaults to "previous" which is a special index
|
|
|
|
-- toggling between last two selected sets of tags. Number (eg 1) will go back
|
|
|
|
-- to the given index in history.
|
|
|
|
function history.restore(screen, idx)
|
2008-09-29 16:49:18 +02:00
|
|
|
local s = screen or capi.mouse.screen
|
2009-08-27 16:03:45 +02:00
|
|
|
local i = idx or "previous"
|
|
|
|
local sel = selectedlist(s)
|
|
|
|
-- do nothing if history empty
|
|
|
|
if not data.history[s] or not data.history[s][i] then return end
|
|
|
|
-- if all tags been deleted, try next entry
|
|
|
|
if #data.history[s][i] == 0 then
|
|
|
|
if i == "previous" then i = 0 end
|
|
|
|
history.restore(s, i + 1)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
-- deselect all tags
|
|
|
|
viewnone(s)
|
|
|
|
-- select tags from the history entry
|
|
|
|
for _, t in ipairs(data.history[s][i]) do
|
|
|
|
t.selected = true
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
2009-08-27 16:03:45 +02:00
|
|
|
-- update currently selected tags table
|
|
|
|
data.history[s].current = data.history[s][i]
|
|
|
|
-- store previously selected tags
|
|
|
|
data.history[s].previous = setmetatable(sel, { __mode = 'v' })
|
|
|
|
-- remove the reverted history entry
|
|
|
|
if i ~= "previous" then table.remove(data.history[s], i) end
|
2008-09-29 16:49:18 +02:00
|
|
|
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)
|
2009-08-25 13:59:34 +02:00
|
|
|
local screen = screen and screen.index or capi.mouse.screen
|
2009-08-24 08:31:44 +02:00
|
|
|
local tags = capi.screen[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
|
2009-08-27 16:03:45 +02:00
|
|
|
capi.screen[screen]:emit_signal("tag::history::update")
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
2010-05-29 01:39:18 +02:00
|
|
|
--- Get a tag's index in the screen[]:tags() table.
|
|
|
|
-- @param query_tag The tag object to find. [selected()]
|
|
|
|
-- @return The index of the tag, nil if the tag is not found.
|
|
|
|
function getidx(query_tag)
|
|
|
|
local query_tag = query_tag or selected()
|
|
|
|
if query_tag == nil then return end
|
|
|
|
|
|
|
|
for i, t in ipairs(capi.screen[query_tag.screen]:tags()) do
|
|
|
|
if t == query_tag then
|
|
|
|
return i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-09-29 16:49:18 +02:00
|
|
|
--- View next tag. This is the same as tag.viewidx(1).
|
2009-08-24 08:31:44 +02:00
|
|
|
-- @param screen The screen number.
|
|
|
|
function viewnext(screen)
|
|
|
|
return viewidx(1, screen)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- View previous tag. This is the same a tag.viewidx(-1).
|
2009-08-24 08:31:44 +02:00
|
|
|
-- @param screen The screen number.
|
|
|
|
function viewprev(screen)
|
|
|
|
return viewidx(-1, screen)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- View only a tag.
|
|
|
|
-- @param t The tag object.
|
|
|
|
function viewonly(t)
|
2009-09-28 11:24:39 +02:00
|
|
|
local tags = capi.screen[t.screen]:tags()
|
|
|
|
-- First, untag everyone except the viewed tag.
|
2009-09-22 14:09:56 +02:00
|
|
|
for _, tag in pairs(tags) do
|
2009-09-28 11:24:39 +02:00
|
|
|
if tag ~= t then
|
|
|
|
tag.selected = false
|
|
|
|
end
|
2009-09-22 14:09:56 +02:00
|
|
|
end
|
2009-09-28 11:24:39 +02:00
|
|
|
-- Then, set this one to selected.
|
|
|
|
-- We need to do that in 2 operations so we avoid flickering and several tag
|
|
|
|
-- selected at the same time.
|
|
|
|
t.selected = true
|
2009-08-27 16:03:45 +02:00
|
|
|
capi.screen[t.screen]:emit_signal("tag::history::update")
|
2008-09-29 16:49:18 +02:00
|
|
|
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)
|
2009-09-22 15:11:40 +02:00
|
|
|
local screen_tags = capi.screen[screen or capi.mouse.screen]:tags()
|
2009-09-28 11:24:39 +02:00
|
|
|
for _, tag in ipairs(screen_tags) do
|
|
|
|
if not util.table.hasitem(tags, tag) then
|
|
|
|
tag.selected = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for _, tag in ipairs(tags) do
|
|
|
|
tag.selected = true
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
2009-08-27 16:03:45 +02:00
|
|
|
capi.screen[screen]:emit_signal("tag::history::update")
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
2009-08-27 17:16:56 +02:00
|
|
|
--- Toggle selection of a tag
|
|
|
|
-- @param tag Tag to be toggled
|
|
|
|
function viewtoggle(t)
|
|
|
|
t.selected = not t.selected
|
|
|
|
capi.screen[t.screen]:emit_signal("tag::history::update")
|
|
|
|
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:tags() == 0 then
|
2009-09-08 16:41:23 +02:00
|
|
|
c:tags(selectedlist(c.screen))
|
2009-02-03 12:20:17 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-09 20:39:55 +02:00
|
|
|
local function attached_connect_signal_screen(screen, sig, func)
|
|
|
|
capi.screen[screen]:connect_signal("tag::attach", function (s, tag)
|
|
|
|
tag:connect_signal(sig, func)
|
2009-08-18 16:44:03 +02:00
|
|
|
end)
|
2009-10-09 20:39:55 +02:00
|
|
|
capi.screen[screen]:connect_signal("tag::detach", function (s, tag)
|
|
|
|
tag:disconnect_signal(sig, func)
|
2009-08-18 16:44:03 +02:00
|
|
|
end)
|
|
|
|
for _, tag in ipairs(capi.screen[screen]:tags()) do
|
2009-10-09 20:39:55 +02:00
|
|
|
tag:connect_signal(sig, func)
|
2009-08-18 16:44:03 +02:00
|
|
|
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.
|
2009-10-09 20:39:55 +02:00
|
|
|
function attached_connect_signal(screen, ...)
|
2009-08-18 16:44:03 +02:00
|
|
|
if screen then
|
2009-10-09 20:39:55 +02:00
|
|
|
attached_connect_signal_screen(screen, ...)
|
2009-08-18 16:44:03 +02:00
|
|
|
else
|
|
|
|
for screen = 1, capi.screen.count() do
|
2009-10-09 20:39:55 +02:00
|
|
|
attached_connect_signal_screen(screen, ...)
|
2009-08-18 16:44:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-11 15:27:31 +02:00
|
|
|
-- Register standards signals
|
2009-10-09 20:39:55 +02:00
|
|
|
capi.client.connect_signal("manage", function(c, startup)
|
2009-09-22 16:09:44 +02:00
|
|
|
-- If we are not managing this application at startup,
|
|
|
|
-- move it to the screen where the mouse is.
|
|
|
|
-- We only do it for "normal" windows (i.e. no dock, etc).
|
|
|
|
if not startup
|
|
|
|
and c.type ~= "desktop"
|
|
|
|
and c.type ~= "dock"
|
|
|
|
and c.type ~= "splash" then
|
2009-09-22 11:57:40 +02:00
|
|
|
if c.transient_for then
|
|
|
|
c.screen = c.transient_for.screen
|
|
|
|
if not c.sticky then
|
|
|
|
c:tags(c.transient_for:tags())
|
|
|
|
end
|
|
|
|
else
|
|
|
|
c.screen = capi.mouse.screen
|
|
|
|
end
|
|
|
|
end
|
2009-10-09 20:39:55 +02:00
|
|
|
c:connect_signal("property::screen", withcurrent)
|
2009-08-24 16:32:19 +02:00
|
|
|
end)
|
2008-09-29 16:49:18 +02:00
|
|
|
|
2009-10-09 20:39:55 +02:00
|
|
|
capi.client.connect_signal("manage", withcurrent)
|
2010-01-08 16:16:37 +01:00
|
|
|
|
2010-08-25 23:00:36 +02:00
|
|
|
capi.tag.add_signal("property::hide")
|
2010-08-26 18:11:13 +02:00
|
|
|
capi.tag.add_signal("property::icon")
|
2010-08-25 23:00:36 +02:00
|
|
|
capi.tag.add_signal("property::layout")
|
|
|
|
capi.tag.add_signal("property::mwfact")
|
|
|
|
capi.tag.add_signal("property::ncol")
|
|
|
|
capi.tag.add_signal("property::nmaster")
|
|
|
|
capi.tag.add_signal("property::windowfact")
|
|
|
|
|
2009-08-27 16:03:45 +02:00
|
|
|
for s = 1, capi.screen.count() do
|
2010-08-25 23:00:36 +02:00
|
|
|
capi.screen[s]:add_signal("tag::history::update")
|
2009-10-09 20:39:55 +02:00
|
|
|
capi.screen[s]:connect_signal("tag::history::update", history.update)
|
2009-08-27 16:03:45 +02:00
|
|
|
end
|
|
|
|
|
2009-08-21 15:50:01 +02:00
|
|
|
setmetatable(_M, { __call = function (_, ...) return new(...) end })
|
|
|
|
|
2008-09-29 16:49:18 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|