Last active
November 7, 2016 14:12
-
-
Save gourytch/42ee1d115a1f29a0db12f8d47c673ecd to your computer and use it in GitHub Desktop.
This file contains hidden or 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/env python2.7 | |
| import subprocess | |
| import threading | |
| import re | |
| import tempfile | |
| import os | |
| tmpdir = tempfile.mkdtemp() | |
| luafile = tmpdir + "/dump.lua" | |
| file(luafile, "wt").write(''' | |
| -- dump windows -- | |
| t = get_window_type() | |
| pid = get_window_property("_NET_WM_PID") | |
| xid = get_window_xid() | |
| x,y,w,h = get_window_geometry() | |
| dtp = tonumber(get_window_property("_NET_WM_DESKTOP")) | |
| if (dtp > 9000) then | |
| dtp = 9999 -- sticky on all desktops | |
| end | |
| name = get_window_name() | |
| app = get_application_name() | |
| cls = get_class_instance_name() | |
| role = get_window_role() | |
| if (t == 'WINDOW_TYPE_NORMAL' or t == 'WINDOW_TYPE_DIALOG') then | |
| debug_print("WINDOW " .. x .. " " .. y .. " " .. w .. " " .. h .. | |
| " DESK{" .. dtp .. | |
| "} PID{" .. pid .. | |
| "} XID{" .. xid .. | |
| "} CLS{" .. cls .. | |
| "} RLE{" .. role .. | |
| "} APP{" .. app .. | |
| "} NME{".. name .. | |
| "}") | |
| end | |
| ''') | |
| proc = subprocess.Popen(["devilspie2", "-def", tmpdir], | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE) | |
| timer = threading.Timer(1, proc.kill) | |
| try: | |
| timer.start() | |
| stdout, stderr = proc.communicate() | |
| finally: | |
| timer.cancel() | |
| os.unlink(luafile) | |
| os.rmdir(tmpdir) | |
| print("--- stderr ---\n%s\n" % stderr) | |
| print("--- dump ---\n%s\n" % stdout) | |
| rc = re.compile(r'^WINDOW (\d+) (\d+) (\d+) (\d+) DESK{(\d+)} PID{(\d+)} XID{(\d+)} CLS{(.*)} RLE{(.*)} APP{(.*)} NME{(.*)}$') | |
| for s in stdout.splitlines(): | |
| rx = rc.search(s) | |
| if not rx: | |
| continue | |
| x = int(rx.group(1)) | |
| y = int(rx.group(2)) | |
| w = int(rx.group(3)) | |
| h = int(rx.group(4)) | |
| d = int(rx.group(5)) | |
| pid = int(rx.group(6)) | |
| xid = int(rx.group(7)) | |
| cls = rx.group(8) | |
| rle = rx.group(9) | |
| app = rx.group(10) | |
| nme = rx.group(11) | |
| if d == 9999: | |
| deskpart = 'pin_window()' | |
| else: | |
| deskpart = 'set_window_workspace(%d)' % d | |
| fname = "xid_0x%08x.lua" % xid | |
| f = open(fname, "wt") | |
| f.write(''' -- xid: 0x%08x pid: %d | |
| if ( | |
| get_application_name() == '%s' and | |
| get_class_instance_name() == '%s' and | |
| get_window_role() == '%s' and | |
| get_window_name() == '%s' and | |
| true) then | |
| set_window_geometry(%d,%d,%d,%d) | |
| %s | |
| end | |
| ''' % (xid, pid, app, cls, rle, nme, x, y, w, h, deskpart)) | |
| f.close() | |
| print("%s prepared" % fname) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment