2021-08-03 23:43:45 +02:00
|
|
|
#!/usr/bin/env -S python3 -W ignore::DeprecationWarning
|
2021-08-04 08:31:17 +02:00
|
|
|
# -*- python -*-
|
2021-08-03 23:43:45 +02:00
|
|
|
|
|
|
|
"""Simple dimmer for xss-lock."""
|
|
|
|
|
2021-08-04 00:04:52 +02:00
|
|
|
# It assumes we are using a compositor.
|
2021-08-03 23:43:45 +02:00
|
|
|
|
|
|
|
import gi ; gi.require_version("Gtk", "3.0")
|
|
|
|
from gi.repository import Gtk, Gdk, GLib
|
|
|
|
import cairo
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
|
2021-08-04 08:31:17 +02:00
|
|
|
def draw(widget, event, options, current):
|
2021-08-03 23:43:45 +02:00
|
|
|
def dim(once=False):
|
|
|
|
cr = Gdk.cairo_create(window)
|
|
|
|
cr.set_source_rgba(0, 0, 0, current[0])
|
|
|
|
cr.set_operator(cairo.OPERATOR_SOURCE)
|
|
|
|
cr.paint()
|
|
|
|
if not once:
|
|
|
|
current[0] += options.step
|
|
|
|
delta = options.max_opacity - options.min_opacity
|
|
|
|
delay = options.delay * options.step * 1000 / delta
|
|
|
|
if current[0] <= options.max_opacity:
|
|
|
|
GLib.timeout_add(delay, dim)
|
|
|
|
|
|
|
|
window = widget.get_window()
|
|
|
|
if not current:
|
|
|
|
# First time we are called.
|
|
|
|
current.append(options.min_opacity)
|
|
|
|
dim()
|
|
|
|
else:
|
2021-08-04 08:31:17 +02:00
|
|
|
# Timers already running, just dim to current value
|
2021-08-03 23:43:45 +02:00
|
|
|
dim(once=True)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("--min-opacity", type=float, default=0.2)
|
|
|
|
parser.add_argument("--max-opacity", type=float, default=1)
|
|
|
|
parser.add_argument("--step", type=float, default=0.02)
|
|
|
|
parser.add_argument("--delay", type=float, default=10)
|
|
|
|
options = parser.parse_args()
|
|
|
|
|
|
|
|
display = Gdk.Display.get_default()
|
|
|
|
for i in range(display.get_n_monitors()):
|
|
|
|
geom = display.get_monitor(i).get_geometry()
|
|
|
|
once = []
|
|
|
|
|
|
|
|
window = Gtk.Window()
|
|
|
|
window.set_wmclass("dimmer", "Dimmer")
|
|
|
|
window.set_app_paintable(True)
|
|
|
|
window.set_skip_pager_hint(True)
|
|
|
|
window.set_skip_taskbar_hint(True)
|
|
|
|
window.set_resizable(False)
|
|
|
|
window.set_decorated(False)
|
|
|
|
window.set_accept_focus(False)
|
|
|
|
window.set_type_hint(Gdk.WindowTypeHint.SPLASHSCREEN)
|
|
|
|
window.set_default_size(geom.width, geom.height)
|
|
|
|
window.set_visual(window.get_screen().get_rgba_visual())
|
|
|
|
|
2021-08-04 08:31:17 +02:00
|
|
|
window.connect("draw", draw, options, [])
|
2021-08-03 23:43:45 +02:00
|
|
|
window.connect("delete-event", Gtk.main_quit)
|
|
|
|
|
|
|
|
window.show_all()
|
|
|
|
window.move(geom.x, geom.y)
|
|
|
|
|
|
|
|
Gtk.main()
|