Skip to content

Commit

Permalink
buttondialog: simplify keyboard grabbing
Browse files Browse the repository at this point in the history
Following GNOME Control Center. :)

By the way, this does not (and did not) do anything on Wayland, it will
only can only work on Wayland with GDK 4 API.
  • Loading branch information
staticssleever668 committed Sep 24, 2023
1 parent 3411723 commit 3c3e3fc
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions piper/buttondialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,29 +262,21 @@ def _get_button_name_and_description(
return name, description

def _grab_seat(self) -> bool:
# Grabs the keyboard seat. Returns True on success, False on failure.
# Gratefully copied from GNOME Control Center's keyboard panel.
"""
Grabs the keyboard seat. Returns True on success, False on failure.
Gratefully copied from GNOME Control Center's keyboard panel.
"""
window = self.get_window()
if window is None:
return False
assert window is not None
display = window.get_display()
seats = display.list_seats()
if len(seats) == 0:
return False
device = seats[0].get_keyboard()
if device is None:
return False
if device.get_source == Gdk.InputSource.KEYBOARD:
pointer = device.get_associated_device()
if pointer is None:
return False
else:
pointer = device
status = pointer.get_seat().grab(
seat: Gdk.Seat = display.get_default_seat()
status = seat.grab(
window, Gdk.SeatCapabilities.KEYBOARD, False, None, None, None, None
)
if status != Gdk.GrabStatus.SUCCESS:
return False
pointer = seat.get_keyboard()
assert pointer is not None
self._grab_pointer = pointer
self.grab_add()
return True
Expand Down

0 comments on commit 3c3e3fc

Please sign in to comment.