diff --git a/ks_includes/emptyCursor.xbm b/ks_includes/emptyCursor.xbm new file mode 100644 index 00000000..9aa63ade --- /dev/null +++ b/ks_includes/emptyCursor.xbm @@ -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}; diff --git a/panels/screensaver.py b/panels/screensaver.py deleted file mode 100644 index 53a69105..00000000 --- a/panels/screensaver.py +++ /dev/null @@ -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 diff --git a/screen.py b/screen.py index 2247a244..c9a7cca7 100644 --- a/screen.py +++ b/screen.py @@ -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()