mirror of
https://github.com/swaywm/sway.git
synced 2026-04-22 06:46:27 -04:00
contrib: add active window opacities.
This commit is contained in:
parent
fd8b9d1f4d
commit
6f8b31bb8e
1 changed files with 34 additions and 15 deletions
|
|
@ -7,15 +7,27 @@
|
|||
|
||||
import argparse
|
||||
import i3ipc
|
||||
import json
|
||||
import signal
|
||||
import sys
|
||||
from functools import partial
|
||||
|
||||
def ignored(window):
|
||||
global ignore
|
||||
return window.app_id in ignore
|
||||
|
||||
def on_window_focus(inactive_opacity, ipc, event):
|
||||
class Opts:
|
||||
def __init__(self, args):
|
||||
self.ignore = args.ignore
|
||||
self.active_opacities = json.loads(args.active_opacities)
|
||||
self.inactive_opacity = args.opacity
|
||||
|
||||
|
||||
def set_focused_opacity(window, opts):
|
||||
opacity = opts.active_opacities.get(window.app_id, 1)
|
||||
cmd = "opacity {}".format(opacity)
|
||||
window.command(cmd)
|
||||
return
|
||||
|
||||
|
||||
def on_window_focus(opts, ipc, event):
|
||||
global prev_focused
|
||||
global prev_workspace
|
||||
|
||||
|
|
@ -28,20 +40,20 @@ def on_window_focus(inactive_opacity, ipc, event):
|
|||
workspace = focused_workspace.workspace().num
|
||||
|
||||
if focused.id != prev_focused.id: # https://github.com/swaywm/sway/issues/2859
|
||||
focused.command("opacity 1")
|
||||
set_focused_opacity(focused, opts);
|
||||
if workspace == prev_workspace:
|
||||
if not ignored(prev_focused):
|
||||
prev_focused.command("opacity " + inactive_opacity)
|
||||
prev_focused = focused
|
||||
prev_workspace = workspace
|
||||
if not window.app_id in opts.ignore:
|
||||
prev_focused.command("opacity " + opts.inactive_opacity)
|
||||
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)
|
||||
ipc.main_quit()
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
@ -57,6 +69,13 @@ if __name__ == "__main__":
|
|||
default=transparency_val,
|
||||
help="set opacity value in range 0...1",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--active-opacities",
|
||||
"-a",
|
||||
type=str,
|
||||
default="{}",
|
||||
help="A dictionary of applications and their active opacities."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--ignore",
|
||||
"-i",
|
||||
|
|
@ -66,7 +85,7 @@ if __name__ == "__main__":
|
|||
nargs="+"
|
||||
)
|
||||
args = parser.parse_args()
|
||||
ignore = args.ignore
|
||||
opts = Opts(args)
|
||||
|
||||
ipc = i3ipc.Connection()
|
||||
prev_focused = None
|
||||
|
|
@ -75,9 +94,9 @@ if __name__ == "__main__":
|
|||
for window in ipc.get_tree():
|
||||
if window.focused:
|
||||
prev_focused = window
|
||||
elif not ignored(window):
|
||||
elif not window.app_id in opts.ignore:
|
||||
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()
|
||||
ipc.on("window::focus", partial(on_window_focus, opts))
|
||||
ipc.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue