mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-07-10 10:14:20 +02:00
xsecurelock: replace i3lock
Currently, there is nothing "new". But I plan to do more at some point.
This commit is contained in:
parent
a4bd93b969
commit
4997db033a
4 changed files with 82 additions and 11 deletions
10
README.md
10
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
|
the wallpaper per screen and therefore, the script may seem a bit
|
||||||
useless but I keep it.
|
useless but I keep it.
|
||||||
|
|
||||||
- I am using `xss-lock` with `i3lock` as a screensaver. It relies on
|
- I am using `xss-lock` with `xsecurelock` as a screensaver. It
|
||||||
standard X screensaver handling (and therefore is easy for
|
relies on standard X screensaver handling (and therefore is easy
|
||||||
application to disable) and also supports systemd
|
for application to disable) and also supports systemd inhibitors.
|
||||||
inhibitors. Nothing fancy but I reuse the wallpaper built above. A
|
Nothing fancy but I reuse the wallpaper built above. A notification
|
||||||
notification is sent 10 seconds before starting.
|
is sent 10 seconds before starting.
|
||||||
|
|
||||||
- There is an `i3-companion` (in `bin/`) which I use to implement
|
- 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
|
whatever does not match what I want in i3. I prefer to not have
|
||||||
|
|
71
bin/xsecurelock-saver
Executable file
71
bin/xsecurelock-saver
Executable file
|
@ -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()
|
|
@ -134,7 +134,7 @@ if __name__ == "__main__":
|
||||||
add("--step", type=float, default=0.1, help="step for changing opacity")
|
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("--delay", type=float, default=10, help="delay from start to end")
|
||||||
add("--font", default="DejaVu Sans", help="font for countdown")
|
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("--background", help="use a background instead of black")
|
||||||
add(
|
add(
|
||||||
"--easing-function",
|
"--easing-function",
|
||||||
|
|
10
bin/xss-lock
10
bin/xss-lock
|
@ -34,11 +34,11 @@ case "$1" in
|
||||||
playerctl -a pause
|
playerctl -a pause
|
||||||
dunstctl set-paused true
|
dunstctl set-paused true
|
||||||
# Then, lock screen
|
# Then, lock screen
|
||||||
i3lock -n -e -i $XDG_RUNTIME_DIR/i3/current-wallpaper.png -t -f
|
env XSECURELOCK_SAVER=$HOME/.config/i3/bin/xsecurelock-saver \
|
||||||
# Alternative if we prefer videos:
|
XSECURELOCK_NO_XRANDR15=1 \
|
||||||
# XSECURELOCK_SAVER=saver_mpv
|
XSECURELOCK_BACKGROUND_IMAGE=$XDG_RUNTIME_DIR/i3/current-wallpaper.png \
|
||||||
# XSECURELOCK_LIST_VIDEOS_COMMAND="ls -1 ~/.config/i3/wallpapers/*.mp4"
|
XSECURELOCK_FONT="Iosevka" \
|
||||||
# xsecurelock
|
xsecurelock
|
||||||
echo "lock: unlock screen"
|
echo "lock: unlock screen"
|
||||||
# After unlocking screen, stop dimmer, restore notifications
|
# After unlocking screen, stop dimmer, restore notifications
|
||||||
dimmer stop
|
dimmer stop
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue