diff options
| author | Ultrabug <ultrabug@ultrabug.net> | 2014-05-30 11:47:00 +0200 |
|---|---|---|
| committer | Ultrabug <ultrabug@ultrabug.net> | 2014-05-30 11:47:00 +0200 |
| commit | 5915d144132b9d4c614cb7d2e3a3610777b4548e (patch) | |
| tree | 734e05cee6d6d9e88255bba61764d6c6856f9ac9 /modules/scratchpad-counter.py | |
| parent | f1ea709cd33acecc382e56b02d0f36ba747b8892 (diff) | |
| parent | e42f84cb9954942b3b604a05fb1933b54ecef5f4 (diff) | |
Merge pull request #33 from ShadowPrince/master
new modules keyboard-layout, battery-level, mpd_status, scratchpad-counter and window-title by @ShadowPrince
Diffstat (limited to 'modules/scratchpad-counter.py')
| -rw-r--r-- | modules/scratchpad-counter.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/modules/scratchpad-counter.py b/modules/scratchpad-counter.py new file mode 100644 index 0000000..390745f --- /dev/null +++ b/modules/scratchpad-counter.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- + +import i3 +from time import time + +""" +Module showing amount of windows at the scratchpad. + +@author shadowprince +@license Eclipse Public License +""" + +CACHE_TIMEOUT = 5 +HIDE_WHEN_NONE = False # hide indicator when there is no windows +POSITION = 0 +STRFORMAT = "{} ⌫" # format of indicator. {} replaces with count of windows + + +def find_scratch(tree): + if tree["name"] == "__i3_scratch": + return tree + else: + for x in tree["nodes"]: + result = find_scratch(x) + if result: + return result + return None + + +class Py3status: + def __init__(self): + self.count = -1 + + def scratchpad_counter(self, i3status_output_json, i3status_config): + count = len(find_scratch(i3.get_tree()).get("floating_nodes", [])) + + if self.count != count: + transformed = True + self.count = count + else: + transformed = False + + response = { + 'cached_until': time() + CACHE_TIMEOUT, + 'full_text': '' if HIDE_WHEN_NONE and count == 0 else STRFORMAT.format(count), + 'name': 'scratchpad-counter', + 'transformed': transformed + } + + return (POSITION, response) |
