mirror of
https://github.com/swaywm/sway.git
synced 2026-04-23 06:46:27 -04:00
contrib: add active and inactive opacity overrides.
This commit is contained in:
parent
503d47ea27
commit
023fa263ea
1 changed files with 40 additions and 21 deletions
|
|
@ -15,13 +15,23 @@ from functools import partial
|
||||||
|
|
||||||
class Opts:
|
class Opts:
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
self.ignore = args.ignore
|
self.active_opacity = args.active_opacity
|
||||||
self.active_opacities = json.loads(args.active_opacities)
|
self.active_opacities = json.loads(args.active_opacities)
|
||||||
self.inactive_opacity = args.opacity
|
self.inactive_opacity = args.inactive_opacity
|
||||||
|
self.inactive_opacities = json.loads(args.inactive_opacities)
|
||||||
|
self.ignore = args.ignore
|
||||||
|
|
||||||
|
|
||||||
def set_focused_opacity(window, opts):
|
def set_opacity(window, opts, active=True):
|
||||||
opacity = opts.active_opacities.get(window.app_id, 1)
|
app = window.app_id
|
||||||
|
opacity = None
|
||||||
|
if app in opts.ignore:
|
||||||
|
opacity = 1.0
|
||||||
|
else:
|
||||||
|
if active:
|
||||||
|
opacity = opts.active_opacities.get(app, opts.active_opacity)
|
||||||
|
else:
|
||||||
|
opacity = opts.inactive_opacities.get(app, opts.inactive_opacity)
|
||||||
cmd = "opacity {}".format(opacity)
|
cmd = "opacity {}".format(opacity)
|
||||||
window.command(cmd)
|
window.command(cmd)
|
||||||
return
|
return
|
||||||
|
|
@ -40,10 +50,9 @@ def on_window_focus(opts, ipc, event):
|
||||||
workspace = focused_workspace.workspace().num
|
workspace = focused_workspace.workspace().num
|
||||||
|
|
||||||
if focused.id != prev_focused.id: # https://github.com/swaywm/sway/issues/2859
|
if focused.id != prev_focused.id: # https://github.com/swaywm/sway/issues/2859
|
||||||
set_focused_opacity(focused, opts);
|
set_opacity(focused, opts, active=True);
|
||||||
if workspace == prev_workspace:
|
if workspace == prev_workspace:
|
||||||
if not window.app_id in opts.ignore:
|
set_opacity(prev_focused, opts, active=False)
|
||||||
prev_focused.command("opacity " + opts.inactive_opacity)
|
|
||||||
prev_focused = focused
|
prev_focused = focused
|
||||||
prev_workspace = workspace
|
prev_workspace = workspace
|
||||||
|
|
||||||
|
|
@ -57,31 +66,42 @@ def remove_opacity(ipc):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
transparency_val = "0.80"
|
|
||||||
|
|
||||||
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 windows in sway."
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--opacity",
|
"--active_opacity",
|
||||||
"-o",
|
"-a",
|
||||||
type=str,
|
type=str,
|
||||||
default=transparency_val,
|
default=1,
|
||||||
help="set opacity value in range 0...1",
|
help="The default opacity for active windows.",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--active-opacities",
|
"--active-opacities",
|
||||||
"-a",
|
"-A",
|
||||||
type=str,
|
type=str,
|
||||||
default="{}",
|
default="{}",
|
||||||
help="A dictionary of applications and their active opacities."
|
help="A dictionary of applications and their active opacities."
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--ignore",
|
"--inactive_opacity",
|
||||||
"-i",
|
"-i",
|
||||||
type=str,
|
type=str,
|
||||||
|
default=0.8,
|
||||||
|
help="The default opacity for inactive windows.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--inactive_opacities",
|
||||||
|
"-I",
|
||||||
|
type=str,
|
||||||
|
default="{}",
|
||||||
|
help="A dictionary of applications and their inactive opacities."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--ignore",
|
||||||
|
type=str,
|
||||||
default=[],
|
default=[],
|
||||||
help="List of ignored processes.",
|
help="List of applications to be ignored.",
|
||||||
nargs="+"
|
nargs="+"
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
@ -94,8 +114,7 @@ if __name__ == "__main__":
|
||||||
for window in ipc.get_tree():
|
for window in ipc.get_tree():
|
||||||
if window.focused:
|
if window.focused:
|
||||||
prev_focused = window
|
prev_focused = window
|
||||||
elif not window.app_id in opts.ignore:
|
set_opacity(window, opts, active=False)
|
||||||
window.command("opacity " + args.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, opts))
|
ipc.on("window::focus", partial(on_window_focus, opts))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue