mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-06-23 02:08:35 +02:00
xss-dimmer: add easing functions
This commit is contained in:
parent
639e4b25cc
commit
dc6c2f05ff
1 changed files with 22 additions and 1 deletions
|
@ -16,6 +16,7 @@ import cairo
|
||||||
import argparse
|
import argparse
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
import math
|
||||||
from Xlib import display, X
|
from Xlib import display, X
|
||||||
from Xlib.error import BadWindow
|
from Xlib.error import BadWindow
|
||||||
from Xlib.protocol.event import MapNotify
|
from Xlib.protocol.event import MapNotify
|
||||||
|
@ -54,7 +55,7 @@ def on_draw(widget, event, options, background, start):
|
||||||
wwidth, wheight = widget.get_size()
|
wwidth, wheight = widget.get_size()
|
||||||
delta = options.end_opacity - options.start_opacity
|
delta = options.end_opacity - options.start_opacity
|
||||||
elapsed = time.monotonic() - start
|
elapsed = time.monotonic() - start
|
||||||
current = elapsed / options.delay
|
current = easing_functions[options.easing_function](elapsed / options.delay)
|
||||||
opacity = delta * current + options.start_opacity
|
opacity = delta * current + options.start_opacity
|
||||||
|
|
||||||
# Background
|
# Background
|
||||||
|
@ -105,6 +106,20 @@ def on_draw(widget, event, options, background, start):
|
||||||
dim(event, once=True)
|
dim(event, once=True)
|
||||||
|
|
||||||
|
|
||||||
|
# See: https://easings.net/
|
||||||
|
easing_functions = {
|
||||||
|
"none": lambda x: x,
|
||||||
|
"ease-out-circ": lambda x: math.sqrt(1 - pow(x - 1, 2)),
|
||||||
|
"ease-out-sine": lambda x: math.sin(x * math.pi / 2),
|
||||||
|
"ease-out-cubic": lambda x: 1 - pow(1 - x, 3),
|
||||||
|
"ease-out-quint": lambda x: 1 - pow(1 - x, 5),
|
||||||
|
"ease-out-expo": lambda x: 1 - pow(2, -10 * x),
|
||||||
|
"ease-out-quad": lambda x: 1 - (1 - x) * (1 - x),
|
||||||
|
"ease-out-elastic": (
|
||||||
|
lambda x: pow(2, -10 * x) * math.sin((x * 10 - 0.75) * (2 * math.pi) / 3) + 1
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
now = time.monotonic()
|
now = time.monotonic()
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
@ -116,6 +131,12 @@ if __name__ == "__main__":
|
||||||
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")
|
add("--background", help="use a background instead of black")
|
||||||
|
add(
|
||||||
|
"--easing-function",
|
||||||
|
default="ease-out-circ",
|
||||||
|
choices=easing_functions.keys(),
|
||||||
|
help="easing function for opacity",
|
||||||
|
)
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
|
|
||||||
background = None
|
background = None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue