contrib/inactive-windows-transparency: Add opacity overrides

Adds application specific ovverides for both active and inactive window
opacities. Done by using -I / --inactive-overrides or -A /
--active-overrides with the option syntax 'app_id=opactiy_value'.
For example: -A firefox=0.95 kitty=0.7 -I firefox=0.3
This commit is contained in:
gibbz00 2022-10-03 14:26:55 +02:00
parent 85133395c1
commit 32bcfa5b9a

View file

@ -7,6 +7,7 @@ import argparse
import i3ipc
import signal
import sys
import re
from functools import partial
def on_window_focus(args, ipc, event):
@ -18,20 +19,23 @@ def on_window_focus(args, ipc, event):
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:
if prev_focused.app_id in args.ignore:
prev_focused.command("opacity 1")
elif prev_focused.app_id in args.inactive_overrides.keys():
prev_focused.command("opacity " + args.inactive_overrides[prev_focused.app_id])
else:
prev_focused.command("opacity " + args.inactive_opacity)
if focused.app_id in args.ignore:
focused.command("opacity 1")
elif focused.app_id in args.active_overrides.keys():
focused.command("opacity " + args.active_overrides[focused.app_id])
else:
focused.command("opacity " + args.active_opacity)
prev_focused = focused
@ -67,6 +71,22 @@ if __name__ == "__main__":
default=default_active_opacity,
help="value between 0 and 1 denoting opacity for active windows",
)
parser.add_argument(
"--inactive-overrides",
"-I",
type=str,
default=[],
help="List of appliations with their values that override the inactive opactity settings. (Example: -A firefox=0.9 kitty=0.8)",
nargs="+"
)
parser.add_argument(
"--active-overrides",
"-A",
type=str,
default=[],
help="List of appliations with their values that override the active opactity settings. (Example: -A firefox=0.9 kitty=0.8)",
nargs="+"
)
parser.add_argument(
"--ignore",
type=str,
@ -76,6 +96,22 @@ if __name__ == "__main__":
)
args = parser.parse_args()
# Convert ovveride arguments of format app_id=opacity_value
# to dictionary of format "app_id": "opacity_value"
temp_inactive_overrides_dictionary = {}
for override in args.inactive_overrides:
app_id = re.search('\S*(?==)', override).group(0)
opacity_value = re.search('(?<==)\S*', override).group(0)
temp_inactive_overrides_dictionary[app_id] = opacity_value
args.inactive_overrides = temp_inactive_overrides_dictionary
temp_active_overrides_dictionary = {}
for override in args.active_overrides:
app_id = re.search('\S*(?==)', override).group(0)
opacity_value = re.search('(?<==)\S*', override).group(0)
temp_active_overrides_dictionary[app_id] = opacity_value
args.active_overrides = temp_active_overrides_dictionary
ipc = i3ipc.Connection()
prev_focused = None
@ -84,6 +120,8 @@ if __name__ == "__main__":
prev_focused = window
else:
window.command("opacity " + args.inactive_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))