From 086aba87ac99b7c98f56369fef072c34080363ed Mon Sep 17 00:00:00 2001 From: Xemptuous <99044751+Xemptuous@users.noreply.github.com> Date: Sat, 9 Mar 2024 19:51:32 -0800 Subject: [PATCH 1/2] feature: added active vs inactive --- inactive-windows-transparency.py | 34 +++++++++++++++++--------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/inactive-windows-transparency.py b/inactive-windows-transparency.py index bf98917..5904997 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,19 @@ 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 = focused - prev_workspace = workspace - - -def remove_opacity(ipc): + prev_focused.command("opacity " + args.opacity) + prev_focused = focused prev_workspace = workspace +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 +46,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 +68,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() From 6289caf1bb47b0023a1357725304ab896a5cba1d Mon Sep 17 00:00:00 2001 From: Xemptuous <99044751+Xemptuous@users.noreply.github.com> Date: Sun, 10 Mar 2024 14:15:46 -0700 Subject: [PATCH 2/2] fix(ci) ruff indent fix --- inactive-windows-transparency.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/inactive-windows-transparency.py b/inactive-windows-transparency.py index 5904997..478705a 100755 --- a/inactive-windows-transparency.py +++ b/inactive-windows-transparency.py @@ -29,7 +29,10 @@ def on_window_focus(args, ipc, event): focused.command("opacity " + args.focused) if workspace == prev_workspace: prev_focused.command("opacity " + args.opacity) - prev_focused = focused prev_workspace = workspace + prev_focused = focused + prev_workspace = workspace + + def remove_opacity(ipc, focused_opacity): for workspace in ipc.get_tree().workspaces(): for w in workspace: