#!/usr/bin/env python from json import loads from os import popen from sys import argv def ipcQuery(req="command", msg=""): ans = popen("i3-msg -t " + req + " " + msg).readlines()[0] return loads(ans) def ipcCurrentWindowSize(): id = popen("xdotool getwindowfocus").readlines()[0].rstrip() answer = popen("xwininfo -id "+id+" | grep -E '(Width|Height)'").readlines() width=int(answer[0].rstrip().split()[1]) height=int(answer[1].rstrip().split()[1]) return (width, height) (width, height) = ipcCurrentWindowSize() if width > height: ipcQuery(msg="split h") else: ipcQuery(msg="split v")