mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-06-24 10:48:35 +02:00
xss-dimmer: accept a background
This commit is contained in:
parent
432149fd91
commit
100a79c9e1
2 changed files with 28 additions and 11 deletions
|
@ -11,7 +11,7 @@ will stop itself when the locker window is mapped.
|
||||||
import gi
|
import gi
|
||||||
|
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
from gi.repository import Gtk, Gdk, GLib
|
from gi.repository import Gtk, Gdk, GLib, GdkPixbuf
|
||||||
import cairo
|
import cairo
|
||||||
import argparse
|
import argparse
|
||||||
import threading
|
import threading
|
||||||
|
@ -40,26 +40,33 @@ def on_realize(widget):
|
||||||
window.set_override_redirect(True)
|
window.set_override_redirect(True)
|
||||||
|
|
||||||
|
|
||||||
def on_draw(widget, event, options, elapsed):
|
def on_draw(widget, event, options, background, elapsed):
|
||||||
def _dim():
|
def _dim():
|
||||||
r = cairo.Region(cairo.RectangleInt(0, 0, *widget.get_default_size()))
|
r = cairo.Region(cairo.RectangleInt(0, 0, *widget.get_size()))
|
||||||
dctx = window.begin_draw_frame(r)
|
dctx = window.begin_draw_frame(r)
|
||||||
cctx = dctx.get_cairo_context()
|
cctx = dctx.get_cairo_context()
|
||||||
dim(cctx)
|
dim(cctx)
|
||||||
window.end_draw_frame(dctx)
|
window.end_draw_frame(dctx)
|
||||||
|
|
||||||
def dim(cctx, once=False):
|
def dim(cctx, once=False):
|
||||||
# Background
|
x, y = widget.get_position()
|
||||||
|
wwidth, wheight = widget.get_size()
|
||||||
delta = options.end_opacity - options.start_opacity
|
delta = options.end_opacity - options.start_opacity
|
||||||
current = elapsed[0] / options.delay
|
current = elapsed[0] / options.delay
|
||||||
opacity = delta * current + options.start_opacity
|
opacity = delta * current + options.start_opacity
|
||||||
|
|
||||||
|
# Background
|
||||||
|
if not background:
|
||||||
cctx.set_source_rgba(0, 0, 0, opacity)
|
cctx.set_source_rgba(0, 0, 0, opacity)
|
||||||
cctx.set_operator(cairo.OPERATOR_SOURCE)
|
cctx.set_operator(cairo.OPERATOR_SOURCE)
|
||||||
cctx.paint()
|
cctx.paint()
|
||||||
|
else:
|
||||||
|
bg = background.new_subpixbuf(x, y, wwidth, wheight)
|
||||||
|
Gdk.cairo_set_source_pixbuf(cctx, bg, 0, 0)
|
||||||
|
cctx.paint_with_alpha(opacity)
|
||||||
|
|
||||||
# Remaining time
|
# Remaining time
|
||||||
remaining = str(round(options.delay - elapsed[0]))
|
remaining = str(round(options.delay - elapsed[0]))
|
||||||
wwidth, wheight = widget.get_default_size()
|
|
||||||
cctx.set_source_rgba(1, 1, 1, opacity)
|
cctx.set_source_rgba(1, 1, 1, opacity)
|
||||||
cctx.select_font_face(
|
cctx.select_font_face(
|
||||||
options.font, cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD
|
options.font, cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD
|
||||||
|
@ -68,7 +75,7 @@ def on_draw(widget, event, options, elapsed):
|
||||||
_, _, twidth, theight, _, _ = cctx.text_extents(remaining)
|
_, _, twidth, theight, _, _ = cctx.text_extents(remaining)
|
||||||
cctx.move_to(wwidth // 2 - twidth // 2, wheight // 2 + theight // 2)
|
cctx.move_to(wwidth // 2 - twidth // 2, wheight // 2 + theight // 2)
|
||||||
cctx.show_text(remaining)
|
cctx.show_text(remaining)
|
||||||
cctx.set_source_rgba(0, 0, 0, opacity*2)
|
cctx.set_source_rgba(0, 0, 0, opacity * 2)
|
||||||
cctx.move_to(wwidth // 2 - twidth // 2, wheight // 2 + theight // 2)
|
cctx.move_to(wwidth // 2 - twidth // 2, wheight // 2 + theight // 2)
|
||||||
cctx.text_path(remaining)
|
cctx.text_path(remaining)
|
||||||
cctx.set_line_width(4)
|
cctx.set_line_width(4)
|
||||||
|
@ -99,8 +106,16 @@ if __name__ == "__main__":
|
||||||
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="i3lock", help="quit if window class detected")
|
||||||
|
add("--background", help="use a background instead of black")
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
|
|
||||||
|
background = None
|
||||||
|
if options.background:
|
||||||
|
try:
|
||||||
|
background = GdkPixbuf.Pixbuf.new_from_file(options.background)
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
|
||||||
# Setup dimmer windows on each monitor
|
# Setup dimmer windows on each monitor
|
||||||
gdisplay = Gdk.Display.get_default()
|
gdisplay = Gdk.Display.get_default()
|
||||||
for i in range(gdisplay.get_n_monitors()):
|
for i in range(gdisplay.get_n_monitors()):
|
||||||
|
@ -115,7 +130,7 @@ if __name__ == "__main__":
|
||||||
window.set_default_size(geom.width, geom.height)
|
window.set_default_size(geom.width, geom.height)
|
||||||
window.move(geom.x, geom.y)
|
window.move(geom.x, geom.y)
|
||||||
|
|
||||||
window.connect("draw", on_draw, options, [])
|
window.connect("draw", on_draw, options, background, [])
|
||||||
window.connect("delete-event", Gtk.main_quit)
|
window.connect("delete-event", Gtk.main_quit)
|
||||||
window.connect("realize", on_realize)
|
window.connect("realize", on_realize)
|
||||||
|
|
||||||
|
|
|
@ -2,4 +2,6 @@
|
||||||
Description=Screen dimmer
|
Description=Screen dimmer
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=%h/.config/i3/bin/xss-dimmer --delay=%i --font "Monkey Island 1991"
|
ExecStart=%h/.config/i3/bin/xss-dimmer --delay=%i \
|
||||||
|
--font "Monkey Island 1991" \
|
||||||
|
--background=%h/.cache/i3/current-wallpaper.png
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue