From 00b635983520d780a08ceac00b35ab0ee5e13047 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Tue, 3 Aug 2021 23:43:45 +0200 Subject: [PATCH] xss-lock: provide a dimmer written in Python --- bin/dimmer | 69 +++++++++++++++++++++++++++++++++++++++++++++ bin/xss-lock | 9 +----- dotfiles/picom.conf | 1 + 3 files changed, 71 insertions(+), 8 deletions(-) create mode 100755 bin/dimmer diff --git a/bin/dimmer b/bin/dimmer new file mode 100755 index 0000000..093420e --- /dev/null +++ b/bin/dimmer @@ -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() diff --git a/bin/xss-lock b/bin/xss-lock index 9758974..73b7ca6 100755 --- a/bin/xss-lock +++ b/bin/xss-lock @@ -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) diff --git a/dotfiles/picom.conf b/dotfiles/picom.conf index 4d664e4..ca0526a 100644 --- a/dotfiles/picom.conf +++ b/dotfiles/picom.conf @@ -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"