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

Add exception option for inactive-windows-transparency.py #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 21 additions & 8 deletions inactive-windows-transparency.py
100755 → 100644
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(inactive_opacity, exception, ipc, event):
global prev_focused
global prev_workspace

Expand All @@ -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):
Expand All @@ -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."
Expand All @@ -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()
Expand All @@ -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()
ipc.on("window::focus", partial(on_window_focus, args.opacity, args.exception))
ipc.on("window::mark", on_window_mark)
ipc.main()
Loading