#!/bin/python import i3ipc transparency_val = '0.8'; ipc = i3ipc.Connection() prev_focused = None prev_workspace = ipc.get_tree().find_focused().workspace().num for window in ipc.get_tree(): if window.focused: prev_focused = window else: window.command('opacity ' + transparency_val) def on_window_focus(ipc, event): global prev_focused global prev_workspace focused = event.container wo = ipc.get_tree().find_focused() if wo == None: return workspace = wo.workspace().num if focused.id != prev_focused.id: focused.command('opacity 1') if workspace == prev_workspace: prev_focused.command('opacity ' + transparency_val) prev_focused = focused prev_workspace = workspace ipc.on("window::focus", on_window_focus) ipc.main()