Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: added active vs inactive #30

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions inactive-windows-transparency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -26,33 +26,38 @@ 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."
)
parser.add_argument(
"--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()

Expand All @@ -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()
signal.signal(sig, lambda signal, frame: remove_opacity(ipc, args.focused))
ipc.on("window::focus", partial(on_window_focus, args))
ipc.main()
Loading