-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoto_monitor_window.py
executable file
·124 lines (96 loc) · 3.75 KB
/
goto_monitor_window.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import os
import sys
import json
from wmctrl_window import WmctrlWindow
# wmctrlWindow = WmctrlWindow("0x02a00136 1 0 473 3840 2137 xavier Tilix: teste")
# sys.exit()
# def ls_window
outt = os.popen('wmctrl -dliGu').read()
lines = outt.split("\n")
lines.pop()
windows = []
for line in lines:
windows.append(WmctrlWindow(line))
windows.sort(key=lambda x: x.monitor, reverse=False)
# end
# def current_window
outt = os.popen('/home/danilo/scripts/get_current_window.sh').read()
current_window_id = outt.replace(',', '').split('x')[1]
current_window_id = re.sub(r'(\r\n\t|\n|\r\t|\n)', '', current_window_id)
current_window = None
for line in lines:
if line.find(current_window_id) >= 0:
current_window = WmctrlWindow(line)
# end
# primeiro next_monitor
# descobrir qual é o próximo monitor
# se o próximo não tiver janela ir para o próximo
next_monitor = current_window.monitor
next_windows = []
# buscar no json se há alguma window para esse monitor
# se tiver validar se ela ainda existe senão
# executar o restante
str_json = open("/home/danilo/scripts/flip360_wids.json", "r").read()
jjson = json.loads(str_json)
key_json = ''
type_cycle = sys.argv[1]
if type_cycle == 'next':
if (next_monitor + 1 == 5):
key_json = 'm1{w}'.format(w=current_window.workspace)
else:
key_json = 'm{m}{w}'.format(m=(next_monitor + 1), w=current_window.workspace)
else:
if (next_monitor - 1 == 0):
key_json = 'm5{w}'.format(w=current_window.workspace)
else:
key_json = 'm{m}{w}'.format(m=(next_monitor - 1), w=current_window.workspace)
next_window = jjson.get(key_json)
outt = os.popen('/home/danilo/scripts/get_visible_windows.sh').read()
visible_windows = outt.split("\n")
visible_windows = [int(w, 16) for w in visible_windows if (len(w) > 0)]
if next_window:
next_window = WmctrlWindow(next_window)
if int(next_window.id, 16) in visible_windows:
for line in lines:
if line.find(str(next_window.id)) >= 0:
next_window.set_focus()
title = next_window.name.encode('ascii', 'ignore')
script = '/home/danilo/scripts/dmenu/dzen_monitor.sh'
os.popen("{script} {monitor} '{title}'".format(script=script, monitor=next_window.monitor, title=title)).read()
sys.exit()
limit = 6
while(limit > 0 and len(next_windows) == 0):
if type_cycle == 'next':
next_monitor = next_monitor + 1
if(next_monitor == 5):
next_monitor = 1
else:
next_monitor = next_monitor - 1
if(next_monitor == 0):
next_monitor = 5
next_windows = filter(lambda window: window.monitor == next_monitor and
window.workspace == current_window.workspace and
int(window.id, 16) in visible_windows and
window.valid, windows)
limit = limit - 1
# filtra as telas por monitor
next_windows = filter(lambda window: window.monitor == next_monitor and
window.workspace == current_window.workspace and
int(window.id, 16) in visible_windows and
window.valid, windows)
# focar na window e salvar no json
next_window = next_windows[0]
next_window.set_focus()
# key_json = 'm{m}{w}'.format(m=next_monitor, w=current_window.workspace)
# jjson[key_json] = next_window.str_win
# flip360 = open("/home/danilo/scripts/flip360_wids.json", "w")
# flip360.write(json.dumps(jjson))
# flip360.close()
title = next_window.name.encode('ascii', 'ignore')
script = '/home/danilo/scripts/dmenu/dzen_monitor.sh'
os.popen("{script} {monitor} '{title}'".format(script=script, monitor=next_window.monitor, title=title)).read()
sys.exit()
# wmctrlWindow = WmctrlWindow("0x05600010 1 8504 1388 1641 987 xavier zim - Zim")