diff --git a/README.md b/README.md index 1c8d24e..d49ed02 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,11 @@ Here some of the things you may be interested in: the wallpaper per screen and therefore, the script may seem a bit useless but I keep it. - - I am using `xss-lock` with `i3lock` as a screensaver. It relies on - standard X screensaver handling (and therefore is easy for - application to disable) and also supports systemd - inhibitors. Nothing fancy but I reuse the wallpaper built above. A - notification is sent 10 seconds before starting. + - I am using `xss-lock` with `xsecurelock` as a screensaver. It + relies on standard X screensaver handling (and therefore is easy + for application to disable) and also supports systemd inhibitors. + Nothing fancy but I reuse the wallpaper built above. A notification + is sent 10 seconds before starting. - There is an `i3-companion` (in `bin/`) which I use to implement whatever does not match what I want in i3. I prefer to not have diff --git a/bin/xsecurelock-saver b/bin/xsecurelock-saver new file mode 100755 index 0000000..f55fcb2 --- /dev/null +++ b/bin/xsecurelock-saver @@ -0,0 +1,71 @@ +#!/usr/bin/python3 + +"""Saver module for xsecurelock. + +It displays a background image, clock and weather. Configuration is +done through environment variables: + + - XSECURELOCK_BACKGROUND_IMAGE: path to the background image to use + +""" + +import os +import gi + +gi.require_version("Gtk", "3.0") +from gi.repository import Gtk, Gdk, GdkX11, GLib, GdkPixbuf +import cairo + + +def on_win_realize(widget, position): + """On realization, embed into XSCREENSAVER_WINDOW and remember parent position.""" + parent_wid = int(os.getenv("XSCREENSAVER_WINDOW", 0)) + if not parent_wid: + return + parent = GdkX11.X11Window.foreign_new_for_display(widget.get_display(), parent_wid) + x, y, w, h = parent.get_geometry() + window = widget.get_window() + window.resize(w, h) + window.reparent(parent, 0, 0) + [*position] = x, y + + +def on_win_draw(widget, ctx, background, position): + """Draw background image.""" + ctx.set_operator(cairo.OPERATOR_SOURCE) + if not background: + ctx.set_source_rgba(0, 0, 0, opacity) + ctx.paint() + return + + x, y = position + wwidth, wheight = widget.get_size() + scale = widget.get_scale_factor() + bg = background.new_subpixbuf(x * scale, y * scale, wwidth * scale, wheight * scale) + ctx.scale(1 / scale, 1 / scale) + Gdk.cairo_set_source_pixbuf(ctx, bg, 0, 0) + ctx.paint() + + +if __name__ == "__main__": + background_image = os.getenv("XSECURELOCK_BACKGROUND_IMAGE", None) + + background = None + if background_image: + try: + background = GdkPixbuf.Pixbuf.new_from_file(background_image) + except Exception: + pass + position = [0, 0] + + window = Gtk.Window() + window.set_app_paintable(True) + window.set_visual(window.get_screen().get_rgba_visual()) + window.connect("realize", on_win_realize, position) + window.connect("draw", on_win_draw, background, position) + window.connect("delete-event", Gtk.main_quit) + + window.show_all() + + # Main loop + Gtk.main() diff --git a/bin/xss-dimmer b/bin/xss-dimmer index 9e2bf2f..d6ce98f 100755 --- a/bin/xss-dimmer +++ b/bin/xss-dimmer @@ -134,7 +134,7 @@ if __name__ == "__main__": add("--step", type=float, default=0.1, help="step for changing opacity") add("--delay", type=float, default=10, help="delay from start to end") add("--font", default="DejaVu Sans", help="font for countdown") - add("--locker", default="i3lock", help="quit if window class detected") + add("--locker", default="xsecurelock", help="quit if window class detected") add("--background", help="use a background instead of black") add( "--easing-function", diff --git a/bin/xss-lock b/bin/xss-lock index 53653e4..c62c2f0 100755 --- a/bin/xss-lock +++ b/bin/xss-lock @@ -34,11 +34,11 @@ case "$1" in playerctl -a pause dunstctl set-paused true # Then, lock screen - i3lock -n -e -i $XDG_RUNTIME_DIR/i3/current-wallpaper.png -t -f - # Alternative if we prefer videos: - # XSECURELOCK_SAVER=saver_mpv - # XSECURELOCK_LIST_VIDEOS_COMMAND="ls -1 ~/.config/i3/wallpapers/*.mp4" - # xsecurelock + env XSECURELOCK_SAVER=$HOME/.config/i3/bin/xsecurelock-saver \ + XSECURELOCK_NO_XRANDR15=1 \ + XSECURELOCK_BACKGROUND_IMAGE=$XDG_RUNTIME_DIR/i3/current-wallpaper.png \ + XSECURELOCK_FONT="Iosevka" \ + xsecurelock echo "lock: unlock screen" # After unlocking screen, stop dimmer, restore notifications dimmer stop