Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Wayland improvements #338

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions safeeyes/BreakScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from safeeyes import Utility
from Xlib.display import Display
from Xlib.display import X
from Xlib.error import DisplayNameError

gi.require_version('Gtk', '3.0')
from gi.repository import Gdk
Expand All @@ -43,8 +44,14 @@ class BreakScreen(object):

def __init__(self, context, on_skip, on_postpone, style_sheet_path):
self.context = context

try:
self.display = Display()
except DisplayNameError:
self.display = None
self.context['is_wayland'] = True

self.count_labels = []
self.display = Display()
self.enable_postpone = False
self.enable_shortcut = False
self.is_pretified = False
Expand Down Expand Up @@ -238,10 +245,15 @@ def __update_count_down(self, count):
def __lock_keyboard(self):
"""
Lock the keyboard to prevent the user from using keyboard shortcuts
Dispatch the call to the X method if the display is X11
"""
logging.info("Lock the keyboard")
self.lock_keyboard = True

if not self.context['is_wayland']:
self.__lock_keyboard_X()

def __lock_keyboard_X(self):
# Grab the keyboard
root = self.display.screen().root
root.change_attributes(event_mask=X.KeyPressMask | X.KeyReleaseMask)
Expand Down Expand Up @@ -269,8 +281,9 @@ def __release_keyboard(self):
"""
logging.info("Unlock the keyboard")
self.lock_keyboard = False
self.display.ungrab_keyboard(X.CurrentTime)
self.display.flush()
if not self.context['is_wayland']:
self.display.ungrab_keyboard(X.CurrentTime)
self.display.flush()

def __destroy_all_screens(self):
"""
Expand Down