From 57df0113cab4146ec8d3d42b271bd0df63eadf1b Mon Sep 17 00:00:00 2001 From: JezerM Date: Mon, 13 Sep 2021 10:55:18 -0600 Subject: [PATCH] Xlib display error now catched, and fixed window size when no window manager --- web-greeter/browser/browser.py | 9 ++++++++- web-greeter/utils/screensaver.py | 19 ++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/web-greeter/browser/browser.py b/web-greeter/browser/browser.py index f7da972..5a52ca9 100644 --- a/web-greeter/browser/browser.py +++ b/web-greeter/browser/browser.py @@ -52,7 +52,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 +from utils.screensaver import reset_screensaver, set_screensaver, init_display import resources # Typing Helpers @@ -121,6 +121,11 @@ class Application: if web_greeter_config["app"]["frame"]: self._init_menu_bar() + screen_size = self.desktop.screen().size() + + self.window.setBaseSize(screen_size) + self.window.resize(screen_size) + state = self.states['NORMAL'] if web_greeter_config["app"]["fullscreen"]: state = self.states["FULLSCREEN"] @@ -132,6 +137,8 @@ class Application: self.window.setCursor(Qt.CursorShape.ArrowCursor) + init_display() + timeout = web_greeter_config["config"]["greeter"]["screensaver_timeout"] set_screensaver(timeout or 300) diff --git a/web-greeter/utils/screensaver.py b/web-greeter/utils/screensaver.py index 34d8630..6d339f8 100644 --- a/web-greeter/utils/screensaver.py +++ b/web-greeter/utils/screensaver.py @@ -3,12 +3,21 @@ from Xlib.display import Display saved_data: dict[str, int] saved = False +available = False -display = Display() +display = None + +def init_display(): + global display, available + try: + display = Display() + available = True + except Exception as err: + logger.error(f"Xlib error: {err}") def set_screensaver(timeout: int): - global saved_data, saved - if saved: + global saved_data, saved, available, display + if saved or not available: return display.sync() data: dict[str, int] = display.get_screen_saver()._data or {} @@ -20,8 +29,8 @@ def set_screensaver(timeout: int): logger.debug("Screensaver timeout set") def reset_screensaver(): - global saved_data, saved - if not saved: + global saved_data, saved, available, display + if not saved or not available: return display.sync() display.set_screen_saver(saved_data["timeout"], saved_data["interval"], saved_data["prefer_blanking"], saved_data["allow_exposures"])