2018-10-20 20:43:54 +02:00
|
|
|
#!/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
|
2019-12-05 13:15:41 +01:00
|
|
|
# transparency strength in range of 0…1 or use the command line argument -o.
|
2018-10-20 20:43:54 +02:00
|
|
|
|
2019-12-05 13:15:41 +01:00
|
|
|
import argparse
|
2018-10-20 20:43:54 +02:00
|
|
|
import i3ipc
|
2019-12-05 13:15:41 +01:00
|
|
|
import signal
|
|
|
|
import sys
|
2020-01-09 19:50:52 +01:00
|
|
|
from functools import partial
|
2018-10-20 20:43:54 +02:00
|
|
|
|
2020-01-09 19:50:52 +01:00
|
|
|
def on_window_focus(inactive_opacity, ipc, event):
|
2018-10-20 20:43:54 +02:00
|
|
|
global prev_focused
|
2019-12-05 13:15:41 +01:00
|
|
|
global prev_workspace
|
|
|
|
|
2021-02-16 11:38:57 +01:00
|
|
|
focused_workspace = ipc.get_tree().find_focused()
|
|
|
|
|
|
|
|
if focused_workspace == None:
|
|
|
|
return
|
|
|
|
|
2019-12-05 13:15:41 +01:00
|
|
|
focused = event.container
|
2021-02-16 11:38:57 +01:00
|
|
|
workspace = focused_workspace.workspace().num
|
2019-12-05 13:15:41 +01:00
|
|
|
|
|
|
|
if focused.id != prev_focused.id: # https://github.com/swaywm/sway/issues/2859
|
|
|
|
focused.command("opacity 1")
|
|
|
|
if workspace == prev_workspace:
|
2020-01-09 19:50:52 +01:00
|
|
|
prev_focused.command("opacity " + inactive_opacity)
|
2019-12-05 13:15:41 +01:00
|
|
|
prev_focused = focused
|
|
|
|
prev_workspace = workspace
|
|
|
|
|
|
|
|
|
|
|
|
def remove_opacity(ipc):
|
|
|
|
for workspace in ipc.get_tree().workspaces():
|
|
|
|
for w in workspace:
|
|
|
|
w.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
|
|
|
|
prev_workspace = ipc.get_tree().find_focused().workspace().num
|
2018-10-20 20:43:54 +02:00
|
|
|
|
2019-12-05 13:15:41 +01:00
|
|
|
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))
|
2020-01-09 19:50:52 +01:00
|
|
|
ipc.on("window::focus", partial(on_window_focus, args.opacity))
|
|
|
|
ipc.main()
|