Wakeup touch block (#340)

* Prevent accidental touches on wakeup (DPMS needed)

* fixup

* This is a very old workaround to blank the cursor for the entire X

* Separate cursor change into a procedure

* Check for DPMS FAIL state first
This commit is contained in:
Alfredo Monclus 2021-12-04 14:28:37 -03:00 committed by GitHub
parent 9f2711b506
commit 2c050a649c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 41 deletions

View File

@ -0,0 +1,6 @@
#define emptyCursor_width 1
#define emptyCursor_height 1
#define emptyCursor_x_hot 0
#define emptyCursor_y_hot 0
static unsigned char emptyCursor_bits[] = {
0x00};

View File

@ -1,26 +0,0 @@
import gi
import logging
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk, GLib
from ks_includes.KlippyGcodes import KlippyGcodes
from ks_includes.screen_panel import ScreenPanel
def create_panel(*args):
return ScreenSaverPanel(*args)
class ScreenSaverPanel(ScreenPanel):
def initialize(self, panel_name):
_ = self.lang.gettext
box = Gtk.Box()
box.set_hexpand(True)
box.set_vexpand(True)
box.set_halign(Gtk.Align.CENTER)
label = Gtk.Label(_("Screen will show in less than one second"))
box.add(label)
self.layout = box

View File

@ -120,10 +120,9 @@ class KlipperScreen(Gtk.Window):
self.set_default_size(self.width, self.height)
self.set_resizable(False)
logging.info("Screen resolution: %sx%s" % (self.width, self.height))
self.theme = self._config.get_main_config_option('theme')
self.gtk = KlippyGtk(self, self.width, self.height, self.theme,
self._config.get_main_config().getboolean("show_cursor", fallback=False),
self.show_cursor = self._config.get_main_config().getboolean("show_cursor", fallback=False)
self.gtk = KlippyGtk(self, self.width, self.height, self.theme, self.show_cursor,
self._config.get_main_config_option("font_size", "medium"))
self.keyboard_height = self.gtk.get_keyboard_height()
self.init_style()
@ -132,6 +131,7 @@ class KlipperScreen(Gtk.Window):
self.add(self.base_panel.get())
self.show_all()
self.base_panel.activate()
self.touch_ready = True
self.printer_initializing(_("Initializing"))
@ -139,11 +139,7 @@ class KlipperScreen(Gtk.Window):
# Move mouse to 0,0
os.system("/usr/bin/xdotool mousemove 0 0")
# Change cursor to blank
if self._config.get_main_config().getboolean("show_cursor", fallback=False):
self.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.ARROW))
else:
self.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.BLANK_CURSOR))
self.change_cursor()
printers = self._config.get_printers()
logging.debug("Printers: %s" % printers)
@ -546,12 +542,29 @@ class KlipperScreen(Gtk.Window):
def check_dpms_state(self):
state = functions.get_DPMS_state()
if state == functions.DPMS_State.Off and "screensaver" not in self._cur_panels:
logging.info("### Creating screensaver panel")
self.show_panel("screensaver", "screensaver", "Screen Saver", 1, False)
elif state == functions.DPMS_State.On and "screensaver" in self._cur_panels:
logging.info("### Remove screensaver panel")
self._menu_go_back()
if state == functions.DPMS_State.Fail:
logging.info("DPMS State FAIL -> Showing KlipperScreen, Stopping DPMS Check")
self.show()
self.change_cursor()
return False
visible = self.get_property("visible")
if state != functions.DPMS_State.On and visible:
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
def wake_screen(self):
@ -583,7 +596,7 @@ class KlipperScreen(Gtk.Window):
return
os.system("xset -display :0 dpms 0 %s 0" % time)
if self.dpms_timeout is None and functions.dpms_loaded is True:
self.dpms_timeout = GLib.timeout_add(1000, self.check_dpms_state)
self.dpms_timeout = GLib.timeout_add(500, self.check_dpms_state)
def set_updating(self, updating=False):
if self.updating is True and updating is False:
@ -899,6 +912,17 @@ class KlipperScreen(Gtk.Window):
os.kill(self.keyboard['process'].pid, signal.SIGTERM)
self.keyboard = None
def change_cursor(self, cursortype=None):
if cursortype == "watch":
os.system("xsetroot -cursor_name watch")
elif self.show_cursor:
self.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.ARROW))
os.system("xsetroot -cursor_name arrow")
else:
self.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.BLANK_CURSOR))
os.system("xsetroot -cursor ks_includes/emptyCursor.xbm ks_includes/emptyCursor.xbm")
return
def main():
version = functions.get_software_version()