Skip to content

Instantly share code, notes, and snippets.

@SergKolo
Created July 12, 2016 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SergKolo/f642c2e12bd1df6611ce1921002bc5fb to your computer and use it in GitHub Desktop.
Save SergKolo/f642c2e12bd1df6611ce1921002bc5fb to your computer and use it in GitHub Desktop.
from gi.repository import GdkX11,Gdk
import subprocess
import time
def run_sh(cmd):
# run shell commands
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
out = p.stdout.read().strip()
return out
def get_window_xid():
for item in run_sh("xwininfo -int").split("\n"):
if "Window id" in item:
return item.split()[3]
user_selection = get_window_xid()
screen = Gdk.Screen.get_default()
while True :
time.sleep(0.25)
active_window = screen.get_active_window()
if int(active_window.get_xid()) == int(user_selection):
active_window.iconify()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment