Fix issues waking up screen from a remote connection (#535)

When connected from vnc the screen did not unlock from the remote session click
This also implements an optional disable DPMS for people with issues where DPMS doesn't work as it should (hw issues, driver issues, etc)
Changes #340 almost entirely
This commit is contained in:
Alfredo Monclus 2022-03-07 14:55:24 -03:00 committed by GitHub
parent f9f313f076
commit 708fec4c45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 36 deletions

View File

@ -151,6 +151,8 @@ class KlipperScreenConfig:
"value": "False"}}, "value": "False"}},
{"only_heaters": {"section": "main", "name": _("Hide sensors in Temp."), "type": "binary", {"only_heaters": {"section": "main", "name": _("Hide sensors in Temp."), "type": "binary",
"value": "False", "callback": screen.restart_warning}}, "value": "False", "callback": screen.restart_warning}},
{"use_dpms": {"section": "main", "name": _("Screen DPMS"), "type": "binary",
"value": "True", "callback": screen.set_dpms}},
# {"": {"section": "main", "name": _(""), "type": ""}} # {"": {"section": "main", "name": _(""), "type": ""}}
] ]

100
screen.py
View File

@ -74,6 +74,7 @@ class KlipperScreen(Gtk.Window):
number_tools = 1 number_tools = 1
panels = {} panels = {}
popup_message = None popup_message = None
screensaver = None
printer = None printer = None
printer_select_callbacks = [] printer_select_callbacks = []
printer_select_prepanel = None printer_select_prepanel = None
@ -586,65 +587,92 @@ class KlipperScreen(Gtk.Window):
self.subscriptions.pop(i) self.subscriptions.pop(i)
return return
def show_screensaver(self):
logging.debug("Showing Screensaver")
if self.screensaver is not None:
self.close_screensaver()
close = Gtk.Button()
close.connect("clicked", self.close_screensaver)
box = Gtk.Box()
box.set_size_request(self.width, self.height)
box.pack_start(close, True, True, 0)
box.set_halign(Gtk.Align.CENTER)
box.get_style_context().add_class("screensaver")
cur_panel = self.panels[self._cur_panels[-1]]
self.base_panel.get().put(box, 0, 0)
self.show_all()
self.screensaver = box
def close_screensaver(self, widget=None):
if self.screensaver is None:
return False
logging.debug("Closing Screensaver")
self.base_panel.get().remove(self.screensaver)
self.screensaver = None
if self.use_dpms:
self.wake_screen()
self.show_all()
return False
def check_dpms_state(self): def check_dpms_state(self):
state = functions.get_DPMS_state() state = functions.get_DPMS_state()
if state == functions.DPMS_State.Fail: if state == functions.DPMS_State.Fail:
logging.info("DPMS State FAIL -> Showing KlipperScreen, Stopping DPMS Check") logging.info("DPMS State FAIL: Stopping DPMS Check")
self.show() os.system("xset -display :0 s %s" % self.blanking_time)
self.change_cursor()
return False return False
elif state != functions.DPMS_State.On:
visible = self.get_property("visible") if self.screensaver is None:
if state != functions.DPMS_State.On and visible: self.show_screensaver()
logging.info("DPMS State %s -> Hiding", state)
self.hide()
self.change_cursor("watch")
self.touch_ready = False
elif state == functions.DPMS_State.On and not visible:
if self.touch_ready:
logging.info("DPMS State On -> Showing KlipperScreen")
self.show()
self.change_cursor()
else:
logging.info("DPMS State On -> Screen touched")
self.touch_ready = True
else:
self.touch_ready = False
return True return True
def wake_screen(self): def wake_screen(self):
self.time = self._config.get_main_config_option('screen_blanking')
# Wake the screen (it will go to standby as configured) # Wake the screen (it will go to standby as configured)
if self.time != "off": if self._config.get_main_config_option('screen_blanking') != "off":
logging.debug("Screen wake up") logging.debug("Screen wake up")
os.system("xset -display :0 dpms force on") os.system("xset -display :0 dpms force on")
self.close_screensaver()
def set_dpms(self, use_dpms):
self.use_dpms = use_dpms
logging.info("DPMS set to: %s" % self.use_dpms)
self.set_screenblanking_timeout(self._config.get_main_config_option('screen_blanking'))
def set_screenblanking_timeout(self, time): def set_screenblanking_timeout(self, time):
# The 'blank' flag sets the preference to blank the video (if the hardware can do so) # The 'blank' flag sets the preference to blank the video
# rather than display a background pattern # rather than display a background pattern
os.system("xset -display :0 s blank") os.system("xset -display :0 s blank")
self.use_dpms = self._config.get_main_config().getboolean("use_dpms", fallback=True)
logging.debug("Changing power save to: %s" % time)
if time == "off": if time == "off":
logging.debug("Screen blanking: %s" % time)
if self.dpms_timeout is not None: if self.dpms_timeout is not None:
GLib.source_remove(self.dpms_timeout) GLib.source_remove(self.dpms_timeout)
self.dpms_timeout = None self.dpms_timeout = None
os.system("xset -display :0 -dpms") os.system("xset -display :0 dpms 0 0 0")
os.system("xset -display :0 s off") os.system("xset -display :0 s off")
return return
time = int(time) self.blanking_time = abs(int(time))
if time < 0: logging.debug("Changing screen blanking to: %d" % self.blanking_time)
return if self.use_dpms and functions.dpms_loaded is True:
if functions.dpms_loaded is False: os.system("xset -display :0 +dpms")
logging.info("DPMS functions not loaded. Unable to protect on button press while the screen is blank") if functions.get_DPMS_state() == functions.DPMS_State.Fail:
os.system("xset -display :0 s %s" % time) logging.info("DPMS State FAIL")
return else:
elif self.dpms_timeout is None and functions.dpms_loaded is True: logging.debug("Using DPMS")
self.dpms_timeout = GLib.timeout_add(500, self.check_dpms_state) os.system("xset -display :0 s off")
os.system("xset -display :0 s off") os.system("xset -display :0 dpms 0 %s 0" % self.blanking_time)
os.system("xset -display :0 dpms 0 %s 0" % time) if self.dpms_timeout is None:
self.dpms_timeout = GLib.timeout_add_seconds(1, self.check_dpms_state)
return
# Without dpms just blank the screen
logging.debug("Not using DPMS")
os.system("xset -display :0 dpms 0 0 0")
os.system("xset -display :0 s %s" % self.blanking_time)
def set_updating(self, updating=False): def set_updating(self, updating=False):
if self.updating is True and updating is False: if self.updating is True and updating is False:

View File

@ -457,6 +457,14 @@ popover button {
background-color: #222; background-color: #222;
} }
.screensaver {
background-color: black;
}
.screensaver button:active {
background-color: rgba(0, 0, 0, 0.5);
}
/* Hardcoded values until creation of dynamic CSS updates */ /* Hardcoded values until creation of dynamic CSS updates */
.graph_label_hidden {padding-left: .9em;} /* .4em on top of normal button padding */ .graph_label_hidden {padding-left: .9em;} /* .4em on top of normal button padding */
.graph_label_extruder {border-left-width: .4em; border-left-style: solid;} .graph_label_extruder {border-left-width: .4em; border-left-style: solid;}