Skip to content

Instantly share code, notes, and snippets.

@raidzero
Last active April 29, 2018 20:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save raidzero/2e2a947a181de98052f2910a5b79eaf9 to your computer and use it in GitHub Desktop.
Save raidzero/2e2a947a181de98052f2910a5b79eaf9 to your computer and use it in GitHub Desktop.
hide/show windows on given workspace when focusing/unfocusing workspace
#!/usr/bin/env python
import i3ipc
import subprocess
# process all windows on this workspace. hide when leaving and show when entering
# because chrome/ium doesnt consider itself hidden when on an invisible workspace
# this script drops my cpu usage when listening to google music from ~10% to ~3%
MUSIC_WS_INDEX = 6
HIDDEN = '_NET_WM_STATE_HIDDEN'
SHOWN = '_NET_WM_STATE_SHOWN'
def showWindow(windowId):
print "SHOWING"
subprocess.call(["xprop", "-id", str(windowId), "-f",
"_NET_WM_STATE", "32a", "-remove", HIDDEN])
subprocess.call(["xprop", "-id", str(windowId), "-f",
"_NET_WM_STATE", "32a", "-set", "_NET_WM_STATE", SHOWN])
def hideWindow(windowId):
print "HIDING"
subprocess.call(["xprop", "-id", str(windowId), "-f",
"_NET_WM_STATE", "32a", "-remove", SHOWN])
subprocess.call(["xprop", "-id", str(windowId), "-f",
"_NET_WM_STATE", "32a", "-set", "_NET_WM_STATE", HIDDEN])
def process_window(window, ws_event):
print "Processing window: %s (%d)" % (window.name, window.window)
if ws_event.current.num == MUSIC_WS_INDEX:
# music workspace has been focused
showWindow(window.window)
elif ws_event.old.num == MUSIC_WS_INDEX:
# music workspace has been unfocused
hideWindow(window.window)
def onWorkspace(i3, event):
if event.change in ['focus']:
windows = i3.get_tree().leaves()
for window in windows:
if window.workspace().num == MUSIC_WS_INDEX:
process_window(window, event)
i3 = i3ipc.Connection()
i3.on('workspace', onWorkspace)
i3.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment