From 290092bdd11c9f5bca52a58630e647d75236ee1b Mon Sep 17 00:00:00 2001 From: Michael Webster Date: Sun, 10 Jul 2022 02:11:58 -0400 Subject: [PATCH] Use xdo to feed escape keycodes into the focused window prior to attempting mouse and keyboard grabs. A frequent barrier to the screensaver starting is a modal window, application popup menu or cinnamon popup being left open when the user steps away from their computer. This will have the effect of cancelling or closing these if they exist. It sends two keystrokes in the event of a popup menu being raised by a modal dialog (the first will cancel the popup, the second the dialog). note: cinnamon popups could be addressed differently (expo/overview modes already are), but this wasn't possible with application popups. Ref: #93 --- debian/control | 1 + src/manager.py | 2 ++ src/util/utils.py | 10 ++++++++++ 3 files changed, 13 insertions(+) diff --git a/debian/control b/debian/control index 31106457..f5c3d267 100644 --- a/debian/control +++ b/debian/control @@ -37,6 +37,7 @@ Depends: python3-gi-cairo, python3-setproctitle, python3-xapp (>= 1.0.1), + python3-xdo, python3-xlib, ${misc:Depends}, ${python3:Depends}, diff --git a/src/manager.py b/src/manager.py index 57db4f49..c859375f 100644 --- a/src/manager.py +++ b/src/manager.py @@ -112,6 +112,7 @@ def set_active(self, active, msg=None): if active: if not status.Active: self.cinnamon_client.exit_expo_and_overview() + utils.maybe_cancel_ui_grab() if self.grab_helper.grab_root(False): if not self.stage: Gio.Application.get_default().hold() @@ -372,6 +373,7 @@ def stage_refreshed(self): if status.Debug: print("manager: stage refresh complete") + utils.maybe_cancel_ui_grab() self.grab_stage() if status.Locked: diff --git a/src/util/utils.py b/src/util/utils.py index bbefdc9b..cdc0cd29 100644 --- a/src/util/utils.py +++ b/src/util/utils.py @@ -5,6 +5,7 @@ import grp import subprocess import xapp.os +import xdo import config import status @@ -148,3 +149,12 @@ def clear_clipboards(widget): def do_quit(): Gtk.main_quit() + + +# Most popup-menu-type actors and widgets can be closed via the escape key, making sure there's +# no active grab when the screensaver starts. +xdo = xdo.xdo() + +def maybe_cancel_ui_grab(): + xdo.send_keysequence_window("Escape") + xdo.send_keysequence_window("Escape")