summaryrefslogtreecommitdiff
path: root/sway/otherwindow~
blob: 0a82e72539c481973b679408b6df69ad9a1595fe (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
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3

import sys
import json
import subprocess

direction=bool(sys.argv[1] == 't' or sys.argv[1] == 'T')
swaymsg = subprocess.run(['swaymsg', '-t', 'get_tree'], stdout=subprocess.PIPE)
data = json.loads(swaymsg.stdout)
current = data["nodes"][1]["current_workspace"]

for output in data["nodes"]:
    if "current_workspace" in output:
        for workspace in output["nodes"]:
            if workspace["name"] == output["current_workspace"]:
                #maybe gives all the visible ones in multi monitor mode?
                roi = workspace
                break

#workspace = int(data["nodes"][1]["current_workspace"])-1
#roi = data["nodes"][1]["nodes"][workspace]
#print(roi)
temp = roi
windows = list()

def getNextWindow():
    if focus < len(windows) - 1:
        return focus+1
    else:
        return 0

def getPrevWindow():
    if focus > 0:
        return focus-1
    else:
        return len(windows)-1

def makelist(temp):
    for nodes in "floating_nodes", "nodes":
        for i in range(len(temp[nodes])):
            # print(temp[nodes][i]["name"])
            # print()
            if temp[nodes][i]["name"] is None:
                makelist(temp[nodes][i])
            elif temp[nodes][i]["visible"]:
                windows.append(temp[nodes][i])

def focused(temp_win):
    for i in range(len(temp_win)):
        if temp_win[i]["focused"] == True:
           return i

makelist(temp)
#print(windows)
# print(len(windows))
focus = focused(windows)
if str(sys.argv[1]) == 't' or str(sys.argv[1]) == 'T':
    print(windows[getNextWindow()]["id"])
else:
    print(windows[getPrevWindow()]["id"])