dont call x11 methods on wayland
This commit is contained in:
parent
99327b9262
commit
45bd96f6e1
|
@ -44,7 +44,10 @@ class BreakScreen:
|
|||
def __init__(self, context, on_skipped, on_postponed, style_sheet_path):
|
||||
self.context = context
|
||||
self.count_labels = []
|
||||
self.display = Display()
|
||||
|
||||
if not self.context['is_wayland']:
|
||||
self.x11_display = Display()
|
||||
|
||||
self.enable_postpone = False
|
||||
self.enable_shortcut = False
|
||||
self.is_pretified = False
|
||||
|
@ -133,7 +136,9 @@ class BreakScreen:
|
|||
Hide the break screen from active window and destroy all other windows
|
||||
"""
|
||||
logging.info("Close the break screen(s)")
|
||||
self.__release_keyboard()
|
||||
|
||||
if not self.context['is_wayland']:
|
||||
self.__release_keyboard()
|
||||
|
||||
# Destroy other windows if exists
|
||||
GLib.idle_add(lambda: self.__destroy_all_screens())
|
||||
|
@ -151,7 +156,8 @@ class BreakScreen:
|
|||
Show an empty break screen on all screens.
|
||||
"""
|
||||
# Lock the keyboard
|
||||
utility.start_thread(self.__lock_keyboard)
|
||||
if not self.context['is_wayland']:
|
||||
utility.start_thread(self.__lock_keyboard_x11)
|
||||
|
||||
display = Gdk.Display.get_default()
|
||||
monitors = display.get_monitors()
|
||||
|
@ -230,7 +236,7 @@ class BreakScreen:
|
|||
for label in self.count_labels:
|
||||
label.set_text(count)
|
||||
|
||||
def __lock_keyboard(self):
|
||||
def __lock_keyboard_x11(self):
|
||||
"""
|
||||
Lock the keyboard to prevent the user from using keyboard shortcuts
|
||||
"""
|
||||
|
@ -238,15 +244,15 @@ class BreakScreen:
|
|||
self.lock_keyboard = True
|
||||
|
||||
# Grab the keyboard
|
||||
root = self.display.screen().root
|
||||
root = self.x11_display.screen().root
|
||||
root.change_attributes(event_mask=X.KeyPressMask | X.KeyReleaseMask)
|
||||
root.grab_keyboard(True, X.GrabModeAsync, X.GrabModeAsync, X.CurrentTime)
|
||||
|
||||
# Consume keyboard events
|
||||
while self.lock_keyboard:
|
||||
if self.display.pending_events() > 0:
|
||||
if self.x11_display.pending_events() > 0:
|
||||
# Avoid waiting for next event by checking pending events
|
||||
event = self.display.next_event()
|
||||
event = self.x11_display.next_event()
|
||||
if self.enable_shortcut and event.type == X.KeyPress:
|
||||
if event.detail == self.keycode_shortcut_skip and not self.strict_break:
|
||||
self.skip_break()
|
||||
|
@ -258,14 +264,14 @@ class BreakScreen:
|
|||
# Reduce the CPU usage by sleeping for a second
|
||||
time.sleep(1)
|
||||
|
||||
def __release_keyboard(self):
|
||||
def __release_keyboard_x11(self):
|
||||
"""
|
||||
Release the locked keyboard.
|
||||
"""
|
||||
logging.info("Unlock the keyboard")
|
||||
self.lock_keyboard = False
|
||||
self.display.ungrab_keyboard(X.CurrentTime)
|
||||
self.display.flush()
|
||||
self.x11_display.ungrab_keyboard(X.CurrentTime)
|
||||
self.x11_display.flush()
|
||||
|
||||
def __destroy_all_screens(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue