awful.client.history: allow to disable history tracking

Based on the code from Uli Schlachter at
https://github.com/awesomeWM/awesome/issues/572#issuecomment-160080378.

Fixes https://github.com/awesomeWM/awesome/issues/572.
This commit is contained in:
Daniel Hahler 2016-05-14 16:12:12 +02:00
parent c1d9e58f94
commit 11f3c7b8af
1 changed files with 42 additions and 3 deletions

View File

@ -1130,8 +1130,6 @@ capi.client.add_signal("marked")
-- @signal unmarked
capi.client.add_signal("unmarked")
capi.client.connect_signal("focus", client.focus.history.add)
-- Add clients during startup to focus history.
-- This used to happen through ewmh.activate, but that only handles visible
-- clients now.
@ -1142,9 +1140,50 @@ capi.client.connect_signal("manage", function (c)
end)
capi.client.connect_signal("unmanage", client.focus.history.delete)
capi.client.connect_signal("unmanage", client.floating.delete)
-- Connect to "focus" signal, and allow to disable tracking.
do
local disabled_count = 1
--- Disable history tracking.
--
-- See `awful.client.focus.history.enable_tracking` to enable it again.
-- @treturn int The internal value of `disabled_count` (calls to this
-- function without calling `awful.client.focus.history.enable_tracking`).
-- @function awful.client.focus.history.disable_tracking
function client.focus.history.disable_tracking()
disabled_count = disabled_count + 1
if disabled_count == 1 then
capi.client.disconnect_signal("focus", client.focus.history.add)
end
return disabled_count
end
--- Enable history tracking.
--
-- This is the default, but can be disabled
-- through `awful.client.focus.history.disable_tracking`.
-- @treturn boolean True if history tracking has been enabled.
-- @function awful.client.focus.history.enable_tracking
function client.focus.history.enable_tracking()
assert(disabled_count > 0)
disabled_count = disabled_count - 1
if disabled_count == 0 then
capi.client.connect_signal("focus", client.focus.history.add)
end
return disabled_count == 0
end
--- Is history tracking enabled?
-- @treturn bool True if history tracking is enabled.
-- @treturn int The number of times that tracking has been disabled.
-- @function awful.client.focus.history.is_enabled
function client.focus.history.is_enabled()
return disabled_count == 0, disabled_count
end
end
client.focus.history.enable_tracking()
-- Register persistent properties
client.property.persist("floating", "boolean")