mirror of
https://github.com/swaywm/sway.git
synced 2026-04-23 06:46:27 -04:00
contrib/inactive-windows-transparency: Add active window opacity
Opacity of active window can now be set with the -a or --active-ocacity flag. Previous inactive opacity flag (-o) has changed to -i or --inactive-opacity. Change will break for users using the old flag.
This commit is contained in:
parent
47023befbf
commit
a5cab2bb5d
1 changed files with 21 additions and 15 deletions
|
|
@ -1,9 +1,7 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
# This script requires i3ipc-python package (install it from a system package manager
|
# This script requires i3ipc-python package (install it from a system package manager or pip).
|
||||||
# or pip).
|
# Use with --help flag for usage isntructions.
|
||||||
# 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 argparse
|
||||||
import i3ipc
|
import i3ipc
|
||||||
|
|
@ -11,7 +9,7 @@ import signal
|
||||||
import sys
|
import sys
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
def on_window_focus(inactive_opacity, ipc, event):
|
def on_window_focus(args, ipc, event):
|
||||||
global prev_focused
|
global prev_focused
|
||||||
|
|
||||||
focused_workspace = ipc.get_tree().find_focused()
|
focused_workspace = ipc.get_tree().find_focused()
|
||||||
|
|
@ -24,8 +22,8 @@ def on_window_focus(inactive_opacity, ipc, event):
|
||||||
# on_window_focus not called only when focused is changed,
|
# on_window_focus not called only when focused is changed,
|
||||||
# but also when a window is moved
|
# but also when a window is moved
|
||||||
if focused.id != prev_focused.id:
|
if focused.id != prev_focused.id:
|
||||||
focused.command("opacity 1")
|
focused.command("opacity " + args.active_opacity)
|
||||||
prev_focused.command("opacity " + inactive_opacity)
|
prev_focused.command("opacity " + args.inactive_opacity)
|
||||||
prev_focused = focused
|
prev_focused = focused
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -41,17 +39,25 @@ def remove_opacity(ipc):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
transparency_val = "0.80"
|
default_inactive_opacity = "0.80"
|
||||||
|
default_active_opacity = "1.0"
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="This script allows you to set the transparency of unfocused windows in sway."
|
description="This script allows you to set the transparency of focused and unfocused windows in sway."
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--opacity",
|
"--inactive-opacity",
|
||||||
"-o",
|
"-i",
|
||||||
type=str,
|
type=str,
|
||||||
default=transparency_val,
|
default=default_inactive_opacity,
|
||||||
help="set opacity value in range 0...1",
|
help="value between 0 and 1 denoting opacity for inactive windows",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--active-opacity",
|
||||||
|
"-a",
|
||||||
|
type=str,
|
||||||
|
default=default_active_opacity,
|
||||||
|
help="value between 0 and 1 denoting opacity for active windows",
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
@ -62,8 +68,8 @@ if __name__ == "__main__":
|
||||||
if window.focused:
|
if window.focused:
|
||||||
prev_focused = window
|
prev_focused = window
|
||||||
else:
|
else:
|
||||||
window.command("opacity " + args.opacity)
|
window.command("opacity " + args.inactive_opacity)
|
||||||
for sig in [signal.SIGINT, signal.SIGTERM]:
|
for sig in [signal.SIGINT, signal.SIGTERM]:
|
||||||
signal.signal(sig, lambda signal, frame: remove_opacity(ipc))
|
signal.signal(sig, lambda signal, frame: remove_opacity(ipc))
|
||||||
ipc.on("window::focus", partial(on_window_focus, args.opacity))
|
ipc.on("window::focus", partial(on_window_focus, args))
|
||||||
ipc.main()
|
ipc.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue