summaryrefslogtreecommitdiffstats
path: root/modules/scratchpad-counter.py
blob: b1cdd731904185d0bd167e911c26c9060dbc95f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import i3
import time
import random
from pprint import pprint

"""
Module showing amount of windows at the scratchpad.

@author shadowprince
@version 1.0
@license Eclipse Public License
"""

CACHED_TIME = 1
POSITION = 1
HIDE_WHEN_NONE = True # hide indicator when there is no windows
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, *args, **kwargs):
        self.count = -1
        super(Py3status).__init__(*args, **kwargs)

    def scratchpadCounter(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

        return (POSITION, {
                    'transformed': transformed,
                    'full_text': '' if HIDE_WHEN_NONE and count == 0 else STRFORMAT.format(count),
                    'name': 'scratchpad-count', 
                    'cached_until': time.time() + CACHED_TIME,
                    })