Skip to content

Instantly share code, notes, and snippets.

@shrx
Forked from Jacob-Vlijm/w_resize.py
Created October 4, 2016 09:41
Show Gist options
  • Save shrx/6262dfedd060eae385b272c877adeaac to your computer and use it in GitHub Desktop.
Save shrx/6262dfedd060eae385b272c877adeaac to your computer and use it in GitHub Desktop.
window resize script for XFCE (Xubuntu), depends on wmctrl
#!/usr/bin/env python3
import subprocess
import sys
titleHeight = 12
arg = sys.argv[1]
def get(command):
return subprocess.check_output(["/bin/bash", "-c", command]).decode("utf-8")
def command(coords):
return "wmctrl -ir "+frontmost+" -e 0,"+(",").join(coords)
def execute(command):
subprocess.Popen(["/bin/bash", "-c", command])
xprop_data = get("xprop -root").split()
w_id = xprop_data[xprop_data.index("_NET_ACTIVE_WINDOW(WINDOW):")+4].replace(",", "")
frontmost = w_id[:2]+"0"+w_id[2:]
w_data = [l for l in get("wmctrl -lG").splitlines() if frontmost in l][0].split()
old_G = w_data[2:6]
new_G = ["-1", "-1", "-1", "-1"]
execute("wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz")
if "left" in arg:
execute(command([
new_G[0],
new_G[1],
str(int(int(old_G[2])/2)),
new_G[3]
]))
if "right" in arg:
execute(command([
str(int(int(old_G[0])+int(old_G[2])/2)),
new_G[1],
str(int(int(old_G[2])/2)),
new_G[3]
]))
if "up" in arg:
execute(command([
new_G[0],
new_G[1],
new_G[2],
str(int(int(old_G[3])/2) - titleHeight - 1)
]))
if "down" in arg:
execute(command([
new_G[0],
str(int(int(old_G[1]) + int(old_G[3])/2) - titleHeight),
new_G[2],
str(int(int(old_G[3])/2) - titleHeight - 1)
]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment