diff --git a/README.md b/README.md index bd02eef..30a28b5 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Gruvbox and Dracula themes! - PyQt5 - PyQtWebEngine - ruamel.yaml +- python-xlib Install PIP dependencies with: ```sh diff --git a/requirements.txt b/requirements.txt index 636bc57..7b6762f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ PyGObject PyQt5 PyQtWebEngine ruamel.yaml +python-xlib diff --git a/web-greeter/bridge/Greeter.py b/web-greeter/bridge/Greeter.py index ff84c10..6e89e90 100644 --- a/web-greeter/bridge/Greeter.py +++ b/web-greeter/bridge/Greeter.py @@ -41,6 +41,7 @@ from PyQt5.QtCore import QFileSystemWatcher, QVariant, QTimer from config import web_greeter_config from utils.battery import Battery +from utils.screensaver import reset_screensaver import globals # This Application @@ -396,7 +397,10 @@ class Greeter(BridgeObject): def start_session(self, session): if not session.strip(): return - return LightDMGreeter.start_session_sync(session) + started = LightDMGreeter.start_session_sync(session) + if started or self.is_authenticated(): + reset_screensaver() + return started @Bridge.method(result=bool) def suspend(self): diff --git a/web-greeter/browser/browser.py b/web-greeter/browser/browser.py index 86271bf..4bc16b1 100644 --- a/web-greeter/browser/browser.py +++ b/web-greeter/browser/browser.py @@ -51,6 +51,7 @@ from browser.interceptor import QtUrlRequestInterceptor from logger import logger from config import web_greeter_config from bridge import Greeter, Config, ThemeUtils +from utils.screensaver import reset_screensaver, set_screensaver import resources # Typing Helpers @@ -119,10 +120,13 @@ class Application: self.window.setCursor(Qt.CursorShape.ArrowCursor) + timeout = web_greeter_config["config"]["greeter"]["screensaver_timeout"] + set_screensaver(timeout or 300) + self.app.aboutToQuit.connect(self._before_exit) def _before_exit(self): - pass + reset_screensaver() def show(self): self.window.show() diff --git a/web-greeter/utils/screensaver.py b/web-greeter/utils/screensaver.py new file mode 100644 index 0000000..34d8630 --- /dev/null +++ b/web-greeter/utils/screensaver.py @@ -0,0 +1,30 @@ +from logger import logger +from Xlib.display import Display + +saved_data: dict[str, int] +saved = False + +display = Display() + +def set_screensaver(timeout: int): + global saved_data, saved + if saved: + return + display.sync() + data: dict[str, int] = display.get_screen_saver()._data or {} + saved_data = data + saved = True + + display.set_screen_saver(timeout, data["interval"], data["prefer_blanking"], data["allow_exposures"]) + display.flush() + logger.debug("Screensaver timeout set") + +def reset_screensaver(): + global saved_data, saved + if not saved: + return + display.sync() + display.set_screen_saver(saved_data["timeout"], saved_data["interval"], saved_data["prefer_blanking"], saved_data["allow_exposures"]) + display.flush() + saved = False + logger.debug("Screensaver reset")