mirror of
https://github.com/swaywm/sway.git
synced 2026-04-23 06:46:27 -04:00
Script currently has the ability to show multiple windows as active,
wrongly implying that more than one window can be focused at the same
time. It happens when multiple outputs are configured such that multiple
workspaces can be simultaneously shown. Stemming from a conditional to
only change transparency values if the focus change is done on the same
workspace in which the previous focus change was made. (Introduced in:
6235423544.) Commit is somewhat poor in
that it clumps multiple features into one commit, so it's hard to
understand what problem the author attempted to solve with the
conditional. I, for one, can not see any other reason for adding this
arguably incorrect behavior, as it goes directly against the script's
purpose. As such, it's regarded as a bug and the change will remove the
behavior entirely, not making it an option.
69 lines
1.9 KiB
Python
Executable file
69 lines
1.9 KiB
Python
Executable file
#!/usr/bin/python
|
|
|
|
# This script requires i3ipc-python package (install it from a system package manager
|
|
# or pip).
|
|
# It makes inactive windows transparent. Use `transparency_val` variable to control
|
|
# transparency strength in range of 0…1 or use the command line argument -o.
|
|
|
|
import argparse
|
|
import i3ipc
|
|
import signal
|
|
import sys
|
|
from functools import partial
|
|
|
|
def on_window_focus(inactive_opacity, ipc, event):
|
|
global prev_focused
|
|
|
|
focused_workspace = ipc.get_tree().find_focused()
|
|
|
|
if focused_workspace == None:
|
|
return
|
|
|
|
focused = event.container
|
|
|
|
# on_window_focus not called only when focused is changed,
|
|
# but also when a window is moved
|
|
if focused.id != prev_focused.id:
|
|
focused.command("opacity 1")
|
|
prev_focused.command("opacity " + inactive_opacity)
|
|
prev_focused = focused
|
|
|
|
|
|
def remove_opacity(ipc):
|
|
tree = ipc.get_tree()
|
|
for workspace in tree.workspaces():
|
|
for window in workspace:
|
|
window.command("opacity 1")
|
|
for window in tree.scratchpad():
|
|
window.command("opacity 1")
|
|
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",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
ipc = i3ipc.Connection()
|
|
prev_focused = None
|
|
|
|
for window in ipc.get_tree():
|
|
if window.focused:
|
|
prev_focused = window
|
|
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()
|