diff --git a/inactive-windows-transparency.py b/inactive-windows-transparency.py index bf98917..478705a 100755 --- a/inactive-windows-transparency.py +++ b/inactive-windows-transparency.py @@ -13,7 +13,7 @@ import i3ipc -def on_window_focus(inactive_opacity, ipc, event): +def on_window_focus(args, ipc, event): global prev_focused global prev_workspace @@ -26,24 +26,22 @@ def on_window_focus(inactive_opacity, ipc, event): workspace = focused_workspace.workspace().num if focused.id != prev_focused.id: # https://github.com/swaywm/sway/issues/2859 - focused.command("opacity 1") + focused.command("opacity " + args.focused) if workspace == prev_workspace: - prev_focused.command("opacity " + inactive_opacity) + prev_focused.command("opacity " + args.opacity) prev_focused = focused prev_workspace = workspace -def remove_opacity(ipc): +def remove_opacity(ipc, focused_opacity): for workspace in ipc.get_tree().workspaces(): for w in workspace: - w.command("opacity 1") + w.command("opacity " + focused_opacity) ipc.main_quit() sys.exit(0) if __name__ == "__main__": - transparency_val = "0.80" - parser = argparse.ArgumentParser( description="This script allows you to set the transparency of unfocused windows in sway." ) @@ -51,8 +49,15 @@ def remove_opacity(ipc): "--opacity", "-o", type=str, - default=transparency_val, - help="set opacity value in range 0...1", + default="0.80", + help="set inactive opacity value in range 0...1", + ) + parser.add_argument( + "--focused", + "-f", + type=str, + default="1.0", + help="set focused opacity value in range 0...1", ) args = parser.parse_args() @@ -66,6 +71,6 @@ def remove_opacity(ipc): else: window.command("opacity " + args.opacity) for sig in [signal.SIGINT, signal.SIGTERM]: - signal.signal(sig, lambda signal, frame: remove_opacity(ipc)) - ipc.on("window::focus", partial(on_window_focus, args.opacity)) - ipc.main() \ No newline at end of file + signal.signal(sig, lambda signal, frame: remove_opacity(ipc, args.focused)) + ipc.on("window::focus", partial(on_window_focus, args)) + ipc.main()