mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-06-27 03:58:51 +02:00
xss-dimmer: play a sound to notice dimmer when not looking at the screen
This commit is contained in:
parent
f8689c512b
commit
398ef9263b
2 changed files with 24 additions and 2 deletions
|
@ -17,10 +17,17 @@ import argparse
|
|||
import threading
|
||||
import time
|
||||
import math
|
||||
import os
|
||||
from Xlib import display, X
|
||||
from Xlib.error import BadWindow
|
||||
from Xlib.protocol.event import MapNotify
|
||||
|
||||
try:
|
||||
os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "hide"
|
||||
import pygame
|
||||
except ImportError:
|
||||
pygame = None
|
||||
|
||||
|
||||
def on_xevent(source, condition, xdisplay, locker):
|
||||
while xdisplay.pending_events():
|
||||
|
@ -89,7 +96,17 @@ def on_refresh(window, options, start):
|
|||
elapsed = time.monotonic() - start
|
||||
if elapsed < options.delay:
|
||||
next_step = min(options.step, options.delay - elapsed)
|
||||
GLib.timeout_add(options.step * 1000, on_refresh, window, options, start)
|
||||
GLib.timeout_add(next_step * 1000, on_refresh, window, options, start)
|
||||
|
||||
|
||||
def on_sound_ticker(options, sound, start):
|
||||
elapsed = time.monotonic() - start
|
||||
if elapsed < options.delay:
|
||||
if sound is None:
|
||||
pygame.mixer.init()
|
||||
sound = pygame.mixer.Sound(options.sound)
|
||||
sound.play()
|
||||
GLib.timeout_add(1000, on_sound_ticker, options, sound, now)
|
||||
|
||||
|
||||
# See: https://easings.net/
|
||||
|
@ -144,6 +161,7 @@ if __name__ == "__main__":
|
|||
choices=easing_functions.keys(),
|
||||
help="easing function for opacity",
|
||||
)
|
||||
add("--sound", help="play a sound for each second elapsed while dimmer running")
|
||||
options = parser.parse_args()
|
||||
|
||||
background = None
|
||||
|
@ -192,5 +210,8 @@ if __name__ == "__main__":
|
|||
)
|
||||
xdisplay.pending_events() # otherwise, socket is inactive
|
||||
|
||||
if options.sound and pygame:
|
||||
GLib.timeout_add(5000, on_sound_ticker, options, None, now)
|
||||
|
||||
# Main loop
|
||||
Gtk.main()
|
||||
|
|
|
@ -3,4 +3,5 @@ Description=Screen dimmer
|
|||
|
||||
[Service]
|
||||
ExecStart=%h/.config/i3/bin/xss-dimmer --delay=%i \
|
||||
--background=%t/i3/current-wallpaper.png
|
||||
--background=%t/i3/current-wallpaper.png \
|
||||
--sound=/usr/share/sounds/freedesktop/stereo/audio-volume-change.oga
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue