Browse Source

Added screensaver support

sisyphus
JezerM 3 years ago
parent
commit
6102c66f1f
No known key found for this signature in database
GPG Key ID: 66BBC5D01388C6B5
  1. 1
      README.md
  2. 1
      requirements.txt
  3. 6
      web-greeter/bridge/Greeter.py
  4. 6
      web-greeter/browser/browser.py
  5. 30
      web-greeter/utils/screensaver.py

1
README.md

@ -34,6 +34,7 @@ Gruvbox and Dracula themes!
- PyQt5 - PyQt5
- PyQtWebEngine - PyQtWebEngine
- ruamel.yaml - ruamel.yaml
- python-xlib
Install PIP dependencies with: Install PIP dependencies with:
```sh ```sh

1
requirements.txt

@ -2,3 +2,4 @@ PyGObject
PyQt5 PyQt5
PyQtWebEngine PyQtWebEngine
ruamel.yaml ruamel.yaml
python-xlib

6
web-greeter/bridge/Greeter.py

@ -41,6 +41,7 @@ from PyQt5.QtCore import QFileSystemWatcher, QVariant, QTimer
from config import web_greeter_config from config import web_greeter_config
from utils.battery import Battery from utils.battery import Battery
from utils.screensaver import reset_screensaver
import globals import globals
# This Application # This Application
@ -396,7 +397,10 @@ class Greeter(BridgeObject):
def start_session(self, session): def start_session(self, session):
if not session.strip(): if not session.strip():
return 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) @Bridge.method(result=bool)
def suspend(self): def suspend(self):

6
web-greeter/browser/browser.py

@ -51,6 +51,7 @@ from browser.interceptor import QtUrlRequestInterceptor
from logger import logger from logger import logger
from config import web_greeter_config from config import web_greeter_config
from bridge import Greeter, Config, ThemeUtils from bridge import Greeter, Config, ThemeUtils
from utils.screensaver import reset_screensaver, set_screensaver
import resources import resources
# Typing Helpers # Typing Helpers
@ -119,10 +120,13 @@ class Application:
self.window.setCursor(Qt.CursorShape.ArrowCursor) 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) self.app.aboutToQuit.connect(self._before_exit)
def _before_exit(self): def _before_exit(self):
pass reset_screensaver()
def show(self): def show(self):
self.window.show() self.window.show()

30
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")
Loading…
Cancel
Save