summaryrefslogtreecommitdiffstats
path: root/py3status
diff options
context:
space:
mode:
authorUltrabug <ultrabug@gentoo.org>2015-01-04 18:23:23 +0100
committerUltrabug <ultrabug@gentoo.org>2015-01-04 18:23:23 +0100
commitdeef0cdbdfe3a8c2a3cf5db84a5449de6043bd71 (patch)
tree359cb5af866b10a5f0db32fbf6b0aeaf038cdc3e /py3status
parentb0c36785e0ed59a3dba04991e8a72a4a9f1ba1ca (diff)
add an automatic and rate limited module and i3status module refresh when using on_click commands
Diffstat (limited to 'py3status')
-rwxr-xr-xpy3status/__init__.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/py3status/__init__.py b/py3status/__init__.py
index 096ab69..d698ab6 100755
--- a/py3status/__init__.py
+++ b/py3status/__init__.py
@@ -511,6 +511,8 @@ class Events(Thread):
def refresh(self, module_name):
"""
Force a cache expiration for all the methods of the given module.
+
+ We rate limit the i3status refresh to 1/s for obvious abusive behavior.
"""
module = self.modules.get(module_name)
if module is not None:
@@ -518,6 +520,15 @@ class Events(Thread):
syslog(LOG_INFO, 'refresh module {}'.format(module_name))
for obj in module.methods.values():
obj['cached_until'] = time()
+ else:
+ if time() > (self.last_refresh_ts + 1):
+ if self.config['debug']:
+ syslog(
+ LOG_INFO,
+ 'refresh i3status for module {}'.format(module_name)
+ )
+ call(['killall', '-s', 'USR1', 'i3status'])
+ self.last_refresh_ts = time()
def refresh_all(self, module_name):
"""
@@ -547,6 +558,10 @@ class Events(Thread):
# this is a i3 message
self.i3_msg(module_name, command)
+ # to make the bar more responsive to users we ask for a refresh
+ # of the module or of i3status if the module is an i3status one
+ self.refresh(module_name)
+
@staticmethod
def i3_msg(module_name, command):
"""