2016-04-01 09:46:05 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
--- Keep track of the urgent clients.
|
|
|
|
--
|
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2008 Julien Danjou
|
|
|
|
-- @submodule client
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local urgent = {}
|
|
|
|
|
|
|
|
local capi =
|
|
|
|
{
|
|
|
|
client = client,
|
|
|
|
}
|
|
|
|
|
|
|
|
local client
|
|
|
|
do
|
|
|
|
client = setmetatable({}, {
|
|
|
|
__index = function(_, k)
|
|
|
|
client = require("awful.client")
|
|
|
|
return client[k]
|
|
|
|
end,
|
|
|
|
__newindex = error -- Just to be sure in case anything ever does this
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
local data = setmetatable({}, { __mode = 'k' })
|
|
|
|
|
2021-10-17 05:55:21 +02:00
|
|
|
-- Get the first client that got the urgent hint.
|
2016-04-01 09:46:05 +02:00
|
|
|
--
|
|
|
|
-- @function awful.urgent.get
|
|
|
|
-- @treturn client.object The first urgent client.
|
|
|
|
function urgent.get()
|
|
|
|
if #data > 0 then
|
|
|
|
return data[1]
|
|
|
|
else
|
|
|
|
-- fallback behaviour: iterate through clients and get the first urgent
|
|
|
|
local clients = capi.client.get()
|
|
|
|
for _, cl in pairs(clients) do
|
|
|
|
if cl.urgent then
|
|
|
|
return cl
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Jump to the client that received the urgent hint first.
|
|
|
|
--
|
|
|
|
-- @function awful.urgent.jumpto
|
|
|
|
-- @tparam bool|function merge If true then merge tags (select the client's
|
|
|
|
-- first tag additionally) when the client is not visible.
|
|
|
|
-- If it is a function, it will be called with the client as argument.
|
|
|
|
function urgent.jumpto(merge)
|
|
|
|
local c = client.urgent.get()
|
|
|
|
if c then
|
2016-08-10 13:02:02 +02:00
|
|
|
c:jump_to(merge)
|
2016-04-01 09:46:05 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-10-17 05:55:21 +02:00
|
|
|
-- Adds client to urgent stack.
|
2016-04-01 09:46:05 +02:00
|
|
|
--
|
|
|
|
-- @function awful.urgent.add
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c The client object.
|
2016-04-01 09:46:05 +02:00
|
|
|
-- @param prop The property which is updated.
|
2019-12-01 07:53:12 +01:00
|
|
|
-- @request client border active granted When a client becomes active and is no
|
|
|
|
-- longer urgent.
|
|
|
|
-- @request client border inactive granted When a client stop being active and
|
|
|
|
-- is no longer urgent.
|
|
|
|
-- @request client border urgent granted When a client stop becomes urgent.
|
2016-04-01 09:46:05 +02:00
|
|
|
function urgent.add(c, prop)
|
2019-11-11 02:47:43 +01:00
|
|
|
assert(
|
|
|
|
c.urgent ~= nil,
|
|
|
|
"`awful.client.urgent.add()` takes a client as first parameter"
|
|
|
|
)
|
|
|
|
|
|
|
|
if prop == "urgent" and c.urgent then
|
2016-04-01 09:46:05 +02:00
|
|
|
table.insert(data, c)
|
|
|
|
end
|
2019-11-11 02:47:43 +01:00
|
|
|
|
|
|
|
if c.urgent then
|
|
|
|
c:emit_signal("request::border", "urgent", {})
|
|
|
|
else
|
|
|
|
c:emit_signal(
|
|
|
|
"request::border",
|
|
|
|
(c.active and "" or "in").."active",
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
end
|
2016-04-01 09:46:05 +02:00
|
|
|
end
|
|
|
|
|
2021-10-17 05:55:21 +02:00
|
|
|
-- Remove client from urgent stack.
|
2016-04-01 09:46:05 +02:00
|
|
|
--
|
|
|
|
-- @function awful.urgent.delete
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam client c The client object.
|
2016-04-01 09:46:05 +02:00
|
|
|
function urgent.delete(c)
|
|
|
|
for k, cl in ipairs(data) do
|
|
|
|
if c == cl then
|
|
|
|
table.remove(data, k)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
capi.client.connect_signal("property::urgent", urgent.add)
|
|
|
|
capi.client.connect_signal("focus", urgent.delete)
|
2019-11-10 07:12:43 +01:00
|
|
|
capi.client.connect_signal("request::unmanage", urgent.delete)
|
2016-04-01 09:46:05 +02:00
|
|
|
|
|
|
|
return urgent
|
2016-12-31 14:07:13 +01:00
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|