Last active
September 16, 2020 18:49
-
-
Save sephamorr/447b15d30180bc151f623f07e87b0c81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#You may have to change some of these values to match display/dock/menubar sizes | |
xscr=1920 | |
yscr=1080 | |
yd=5 | |
xd=80 | |
xstart=0 | |
ystart=44 | |
xmax=xscr-xd | |
ymax=yscr-yd | |
import subprocess,os | |
output = subprocess.Popen(["wmctrl", "-l","-G"], stdout=subprocess.PIPE).communicate()[0].split("\n") | |
class win(): | |
def __init__(self, wid, desktop, x, y, w, h, name): | |
self.wid = wid | |
self.desktop = int(desktop) | |
self.x = int(x) | |
self.y = int(y) | |
self.w = int(w) | |
self.h = int(h) | |
self.name = name | |
def __str__(self): | |
return __repr__(self) | |
def __repr__(self): | |
return "%s (%s): (%d,%d) @ (%d,%d):%d"%(self.name,self.wid,self.w,self.h,self.x,self.y,self.desktop) | |
wins=[] | |
for i in output: | |
f=filter(None,i.split(" ")) | |
if(len(f)<7): | |
continue | |
wins.append(win(f[0], f[1], f[2], f[3], f[4], f[5]," ".join(f[6:]))) | |
for i in wins: | |
if i.x<0 or i.x>xmax or i.y<0 or i.y>ymax: | |
w=min(i.w,xmax-40) | |
h=min(i.h,ymax) | |
x=0 | |
y=0 | |
elif (i.x+i.w)>xscr or (i.y+i.h)>yscr: | |
x=i.x-xstart | |
y=i.y-ystart | |
w=xscr-x-xstart | |
h=yscr-y-ystart | |
else: | |
continue | |
cmd="wmctrl -i -r %s -e 0,%d,%d,%d,%d"%(i.wid,x,y,w,h) | |
os.system(cmd) |
wow it works thanks
I get an error in this line:
output = subprocess.Popen(["wmctrl", "-l","-G"], stdout=subprocess.PIPE).communicate()[0].split("\n")
TypeError: a bytes-like object is required, not 'str'
Any ideas?
@vivekkohar Use python2
I'm on a Mac running Mojave, Python 2.7.
When I run wmfix I get:
$ /usr/local/bin/wmfix
Traceback (most recent call last):
File "/usr/local/bin/wmfix", line 15, in <module>
output = subprocess.Popen(["wmctrl", "-l","-G"], stdout=subprocess.PIPE).communicate()[0].split("\n")
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
The message about line 15 in wmfix, is it trying to say there's something wrong with that line? There's no error message. Or is it just saying that that is line that calls subprocess.py?
I can find my way into the subprocess.py file and see lines 710 and 1335, but I'm not enough of a Python programmer to make sense of it from there.
Any suggestions?
This runs wmctrl which you will need to install for it to work.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you very much! it works like a charm 👍