-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistWindows.py
More file actions
executable file
·150 lines (146 loc) · 4.54 KB
/
Copy pathlistWindows.py
File metadata and controls
executable file
·150 lines (146 loc) · 4.54 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#! /usr/bin/env nix-shell
#! nix-shell -i python3.5 -p python35 python35Packages.psutil wmctrl
from wmctrl import Window as W
from subprocess import call
import psutil
import curses
import os
def getStrings():
stdscr.clear()
windows=W.list()
keys=["f","j","d","k","s","l","a"] # keys to chose the window
keyComb=[] # generate a key Combination for each window
if (len(keys)<len(windows)):
count=0
isBreak=False
for i in keys:
for j in keys:
if (count==len(windows)):
break
isBreak=True
keyComb.append(i+j)
count+=1
if isBreak:
break
else:
keyComb=keys[0:len(windows)]
actice= W.get_active() # dont show this program
count=0
for win in windows:
if win == actice:
del windows[count]
break
count+=1
windowNames=[] # get the correct name for programs in terminals
for win in windows:
name=win.wm_name
pids=[win.pid]
if (name=="termite"): # TODO make it portable for other terminals
pids=psutil.Process(pids[0]).children()
if(len(pids)>0 ):
name=pids[0].name()
if (name=="zsh"): # TODO make it portable for other shells
pids=pids[0].children()
if(len(pids)>0 ):
name=pids[0].name()
windowNames.append(name)
ws=[x.desktop for x in windows]
windowNumber=[0]*(max(ws)+1)
for i in (ws):
windowNumber[i]+=1
count=0
countL=0
countWs=0
for i in windowNumber: # print the lines
if(i%2==0):
middle=(i/2)
else:
middle=((i+1)/2)
for j in range(i):
if(j==middle-1):
stdscr.addstr(countL,0,str(countWs)+"| ["+keyComb[count]+"]: "+windowNames[count])
else:
stdscr.addstr(countL,0," | ["+keyComb[count]+"]: "+windowNames[count])
count+=1
countL+=1
if(i!=0):
countL+=1 # print a empty line between workspaces
countWs+=1
stdscr.refresh()
return keyComb , [ x.id for x in windows], ws
stdscr = curses.initscr()
curses.curs_set(0)
curses.noecho()
curses.cbreak()
keyComb, winID, ws = getStrings()
savedWsFile=open("/var/tmp/notifyWindows")
try:
savedWs=eval(savedWsFile.read())
except SyntaxError:
savedWs=[1]
savedWsFile.close()
savedWsFile=open( os.getenv("HOME") + "/scripts/var/notifyWindows", 'w')
while True:
c = stdscr.getch()
if c == ord('q'): # close this programm
savedWsFile.write(str(savedWs))
break
elif c == ord('n'): # focus the next empty workspace
for i in range(0,len(ws)):
if not i in ws:
call(["wmctrl","-s", str(i)])
savedWs[0]=i+1
savedWsFile.write(str(savedWs))
break
break
elif c == ord('x'): # close the window
count=0
if keyComb[0]=="f":
c = stdscr.getch()
for i in keyComb:
if ord(i[0])==c:
call(["wmctrl","-ic", str(winID[count])])
keyComb, winID, ws= getStrings()
break
count+=1
else:
c1 = stdscr.getch()
c2 = stdscr.getch()
for i in keyComb:
if ord(i[0])==c1 and ord(i[1])==c2:
call(["wmctrl","-ic", str(winID[count])])
keyComb, winID, ws= getStrings()
break
count+=1
continue
else: # focus the window
count=0
isBreak=False
if keyComb[0]=="ff":
c1=c
c2=stdscr.getch()
for i in keyComb:
if ord(i[0])==c1 and ord(i[1])==c2:
call(["wmctrl","-ia", winID[count]])
savedWs[0]=ws[count]+1
savedWsFile.write(str(savedWs))
isBreak=True
break
count+=1
else:
for i in keyComb:
if ord(i[0])==c:
stdscr.refresh()
call(["wmctrl","-ia", winID[count]])
savedWs[0]=ws[count]+1
savedWsFile.write(str(savedWs))
isBreak=True
break
count+=1
if isBreak:
break
savedWsFile.close()
curses.nocbreak()
stdscr.keypad(False)
curses.echo()
curses.endwin()