-
Notifications
You must be signed in to change notification settings - Fork 0
/
bg.py
47 lines (39 loc) · 1.17 KB
/
bg.py
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
import sys
import json
import i3msg as i3
import os
filename = '.ws.txt'
try:
with open(filename, 'r') as f:
mode = 'restore'
old = json.loads(f.read())
except IOError:
mode = 'hide'
if mode == 'hide':
outputs = i3.send(i3.GET_OUTPUTS)
currentWorkspaces = {}
for output in outputs:
name = output['name']
workspace = output['current_workspace']
print(name)
if workspace is not None:
currentWorkspaces[name] = workspace
i3.send(i3.RUN_COMMAND, 'workspace ' + workspace)
i3.send(i3.RUN_COMMAND, 'workspace ' + output['name'])
f = open(filename, 'w')
f.write(json.dumps(currentWorkspaces))
f.close()
elif mode == 'restore':
outputs = i3.send(i3.GET_OUTPUTS)
for output in outputs:
name = output['name']
workspace = output['current_workspace']
print(name)
if workspace is not None and old.get(name) is not None:
i3.send(i3.RUN_COMMAND, 'workspace ' + workspace)
i3.send(i3.RUN_COMMAND, 'workspace ' + old.get(name))
os.remove(filename)
else:
print('Error... Invalid mode')
sys.exit(1)
sys.exit(0)