aboutsummaryrefslogtreecommitdiff
path: root/bin/i3ws
blob: a1c487a353773dca2607cd8e19888a63fd1ea7af (plain) (blame)
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
#!/usr/bin/env python3
from functools import partial
import json
from subprocess import check_output
import sys

def get_unique(func, wss):
    return list(set(map(func, wss)))

def get_unique_key(key, wss):
    return get_unique(lambda ws: ws[key], wss)

def show_workspace(ws):
    color = 'f00' if ws['urgent'] else \
            '00fcff' if ws['focused'] else \
            '6aa3f8' if ws['visible'] else \
            '777'
    return '<fc=#%s>%s</fc>' % (color, ws['name'])

def show_output(wss, op):
    wss = list(filter(lambda ws: ws['output'] == op, wss))
    wss.sort(key=lambda ws: ws['name'])

    return op + ' ' + ' '.join(map(show_workspace, wss))

def main():
    i3ws = check_output(['i3-msg', '-t', 'get_workspaces']).decode('utf-8')
    wss = json.loads(i3ws)
    
    outputs = sorted(get_unique_key('output', wss))
    print(' * '.join(map(partial(show_output, wss), outputs)))

if __name__ == '__main__':
    main()