Skip to content

Commit d702cb6

Browse files
committed
break screen: x11 keyboard locking: move threading
concentrate all the threading logic within the one method. everything else runs on the main thread
1 parent 785db28 commit d702cb6

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

safeeyes/ui/break_screen.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def close(self) -> None:
143143
self.__release_keyboard_x11()
144144

145145
# Destroy other windows if exists
146-
GLib.idle_add(lambda: self.__destroy_all_screens())
146+
self.__destroy_all_screens()
147147

148148
def __show_break_screen(
149149
self,
@@ -298,18 +298,21 @@ def __lock_keyboard_x11(self) -> None:
298298
event.detail == self.keycode_shortcut_skip
299299
and self.show_skip_button
300300
):
301-
self.skip_break()
301+
utility.execute_main_thread(lambda: self.skip_break())
302302
break
303303
elif (
304304
event.detail == self.keycode_shortcut_postpone
305305
and self.show_postpone_button
306306
):
307-
self.postpone_break()
307+
utility.execute_main_thread(lambda: self.postpone_break())
308308
break
309309
else:
310310
# Reduce the CPU usage by sleeping for a second
311311
time.sleep(1)
312312

313+
self.x11_display.ungrab_keyboard(X.CurrentTime)
314+
self.x11_display.flush()
315+
313316
def on_key_pressed_wayland(
314317
self, event_controller_key, keyval, keycode, state
315318
) -> bool:
@@ -325,13 +328,8 @@ def on_key_pressed_wayland(
325328

326329
def __release_keyboard_x11(self) -> None:
327330
"""Release the locked keyboard."""
328-
if self.x11_display is None:
329-
return
330-
331331
logging.info("Unlock the keyboard")
332332
self.lock_keyboard = False
333-
self.x11_display.ungrab_keyboard(X.CurrentTime)
334-
self.x11_display.flush()
335333

336334
def __destroy_all_screens(self) -> None:
337335
"""Close all the break screens."""

0 commit comments

Comments
 (0)