diff --git a/inactive-windows-transparency.py b/inactive-windows-transparency.py old mode 100755 new mode 100644 index bf98917..c0f58f2 --- 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(inactive_opacity, exception, ipc, event): global prev_focused global prev_workspace @@ -23,14 +23,18 @@ def on_window_focus(inactive_opacity, ipc, event): return focused = event.container - workspace = focused_workspace.workspace().num if focused.id != prev_focused.id: # https://github.com/swaywm/sway/issues/2859 - focused.command("opacity 1") - if workspace == prev_workspace: + if exception not in focused.marks: + focused.command("opacity 1") + if exception not in prev_focused.marks: prev_focused.command("opacity " + inactive_opacity) prev_focused = focused - prev_workspace = workspace + +def on_window_mark(ipc, event): + global prev_focused + focused = event.container + prev_focused = focused def remove_opacity(ipc): @@ -43,6 +47,7 @@ def remove_opacity(ipc): if __name__ == "__main__": transparency_val = "0.80" + exception_mark = "^" parser = argparse.ArgumentParser( description="This script allows you to set the transparency of unfocused windows in sway." @@ -54,6 +59,13 @@ def remove_opacity(ipc): default=transparency_val, help="set opacity value in range 0...1", ) + parser.add_argument( + "--exception", + "-e", + type=str, + default=exception_mark, + help="set window mark that skip opacity", + ) args = parser.parse_args() ipc = i3ipc.Connection() @@ -63,9 +75,10 @@ def remove_opacity(ipc): for window in ipc.get_tree(): if window.focused: prev_focused = window - else: + elif args.exception not in window.marks: 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 + ipc.on("window::focus", partial(on_window_focus, args.opacity, args.exception)) + ipc.on("window::mark", on_window_mark) + ipc.main()