Skip to content

Commit

Permalink
Add exception option for inactive-windows-transparency.py
Browse files Browse the repository at this point in the history
  • Loading branch information
pzant authored and OctopusET committed Jan 20, 2024
1 parent 2a132b8 commit 1ce2c02
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 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 @@ -26,11 +26,16 @@ def on_window_focus(inactive_opacity, ipc, event):
workspace = focused_workspace.workspace().num

Check failure on line 26 in inactive-windows-transparency.py

View workflow job for this annotation

GitHub Actions / linux

Ruff (F841)

inactive-windows-transparency.py:26:5: F841 Local variable `workspace` is assigned to but never used

if focused.id != prev_focused.id: # https://github.com/swaywm/sway/issues/2859
focused.command("opacity 1")
if workspace == prev_workspace:
if not exception in focused.marks:

Check failure on line 29 in inactive-windows-transparency.py

View workflow job for this annotation

GitHub Actions / linux

Ruff (E713)

inactive-windows-transparency.py:29:16: E713 Test for membership should be `not in`
focused.command("opacity 1")
if not exception in prev_focused.marks:

Check failure on line 31 in inactive-windows-transparency.py

View workflow job for this annotation

GitHub Actions / linux

Ruff (E713)

inactive-windows-transparency.py:31:16: E713 Test for membership should be `not in`
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 +48,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 +60,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 +76,10 @@ def remove_opacity(ipc):
for window in ipc.get_tree():
if window.focused:
prev_focused = window
else:
elif not args.exception in window.marks:

Check failure on line 79 in inactive-windows-transparency.py

View workflow job for this annotation

GitHub Actions / linux

Ruff (E713)

inactive-windows-transparency.py:79:18: E713 Test for membership should be `not in`
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()

0 comments on commit 1ce2c02

Please sign in to comment.