From 72faae2ba9c951fa22ade14dad400137d6e1aa8c Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 4 Sep 2022 17:32:16 +0200 Subject: [PATCH] Update method to disable X11 screensaver On modern systems `xdg-screensaver reset` does not necessarily reset the timer. It depends on DPMS, and according to spec turns off the screensaver (unlock the screen), via `xset dpms force on`. Explicit window suspend/resume make use of DBus org.freedesktop.ScreenSaver.Inhibit, which is not be supported but all systems, so we fall back to good old `XResetScreenSaver` which does reset the activation timer. --- gtk2_ardour/screensaver.cc | 54 +++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/gtk2_ardour/screensaver.cc b/gtk2_ardour/screensaver.cc index e4aab918f4..55058b64d0 100644 --- a/gtk2_ardour/screensaver.cc +++ b/gtk2_ardour/screensaver.cc @@ -65,27 +65,23 @@ ARDOUR_UI_UTILS::inhibit_screensaver (bool inhibit) #else /* Linux / X11 */ -#include +#include "ardour_ui.h" #include "ardour/system_exec.h" +#include + static sigc::connection glib_timer; static bool -xdg_screensaver_reset () +reset_screensaver_timer () { - char** args = (char**) malloc (5 * sizeof(char*)); - args[0] = strdup ("/bin/sh"); - args[1] = strdup ("-c"); - args[2] = strdup ("xdg-screensaver"); - args[3] = strdup ("reset"); - args[4] = 0; - - ARDOUR::SystemExec xdg_exec ("/bin/sh", args); - if (xdg_exec.start ()) { + Display* d = XOpenDisplay (NULL); + if (!d) { return false; } - xdg_exec.wait (); - return true; /* keep going */ + XResetScreenSaver (d); + XCloseDisplay (d); + return true; } void @@ -93,9 +89,37 @@ ARDOUR_UI_UTILS::inhibit_screensaver (bool inhibit) { glib_timer.disconnect (); if (inhibit) { - xdg_screensaver_reset (); - glib_timer = Glib::signal_timeout().connect_seconds (sigc::ptr_fun (&xdg_screensaver_reset), 45, Glib::PRIORITY_DEFAULT_IDLE); + reset_screensaver_timer (); + glib_timer = Glib::signal_timeout().connect_seconds (sigc::ptr_fun (&reset_screensaver_timer), 45, Glib::PRIORITY_DEFAULT_IDLE); } + +#if 0 + Glib::RefPtr win (ARDOUR_UI::instance()->main_window ().get_window ()); + if (!win) { + return; + } + + XID xid = GDK_WINDOW_XWINDOW ((win->gobj())); + char tmp[32]; + snprintf (tmp, sizeof (tmp), "%lu", xid); + + char** args = (char**) malloc (6 * sizeof(char*)); + args[0] = strdup ("/bin/sh"); + args[1] = strdup ("-c"); + args[2] = strdup ("xdg-screensaver"); + if (inhibit) { + args[3] = strdup ("suspend"); + } else { + args[3] = strdup ("resume"); + } + args[4] = strdup (tmp); + args[5] = 0; + + ARDOUR::SystemExec xdg_exec ("/bin/sh", args); + if (!xdg_exec.start ()) { + xdg_exec.wait (); + } +#endif } #endif