From 11f3c7b8af4e3d5a92e87895a5fc41957a8aae3a Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 14 May 2016 16:12:12 +0200 Subject: [PATCH] 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. --- lib/awful/client.lua | 45 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/lib/awful/client.lua b/lib/awful/client.lua index 60fd9b01..fdad1605 100644 --- a/lib/awful/client.lua +++ b/lib/awful/client.lua @@ -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")