mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-07-10 10:14:20 +02:00
xss-lock: provide a dimmer written in Python
This commit is contained in:
parent
7283f44742
commit
00b6359835
3 changed files with 71 additions and 8 deletions
69
bin/dimmer
Executable file
69
bin/dimmer
Executable file
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env -S python3 -W ignore::DeprecationWarning
|
||||
|
||||
"""Simple dimmer for xss-lock."""
|
||||
|
||||
# It assumes we are using a compositor and the application gets killed
|
||||
# as soon as there is a movement.
|
||||
|
||||
import gi ; gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk, Gdk, GLib
|
||||
import cairo
|
||||
import argparse
|
||||
|
||||
|
||||
def expose_draw(widget, event, options, current):
|
||||
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:
|
||||
dim(once=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Parse arguments
|
||||
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 = []
|
||||
|
||||
# Create window
|
||||
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())
|
||||
|
||||
window.connect("draw", expose_draw, options, [])
|
||||
window.connect("delete-event", Gtk.main_quit)
|
||||
|
||||
window.show_all()
|
||||
window.move(geom.x, geom.y)
|
||||
|
||||
Gtk.main()
|
|
@ -20,16 +20,9 @@ case "$1" in
|
|||
;;
|
||||
dim|notify)
|
||||
echo "notify: start (idle: $(xprintidle))"
|
||||
systemctl --user kill -s STOP redshift.service
|
||||
trap "systemctl --user kill -s CONT redshift.service" EXIT
|
||||
trap 'echo notify: user activity; kill %% 2> /dev/null; exit 0' HUP # user activity
|
||||
trap 'echo notify: locker started; kill %% 2> /dev/null; exit 0' TERM # locker started
|
||||
outputs=($(xrandr --current | sed -n 's/\([^ ]*\) connected .*/\1/p'))
|
||||
for out in ${outputs[@]}; do
|
||||
xrandr --output $out --brightness 0.2
|
||||
done
|
||||
sleep infinity &
|
||||
wait
|
||||
~/.config/i3/bin/dimmer --delay $notify
|
||||
echo "notify: end"
|
||||
;;
|
||||
lock)
|
||||
|
|
|
@ -26,6 +26,7 @@ opacity-rule = [
|
|||
"100:window_type = 'dropdown_menu'",
|
||||
"100:window_type = 'menu'",
|
||||
"100:window_type = 'popup_menu'",
|
||||
"100:window_type = 'splash'",
|
||||
"100:window_type = 'tooltip'",
|
||||
"100:window_type = 'utility'",
|
||||
"85:!focused"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue