Is it possible to call Gdk.Seat.grab() in GJS?

284 views Asked by At

It seems when I call Gdk.Seat.grab() in GJS I get an error:

Gjs-WARNING **: JS ERROR: TypeError: Gdk.Seat.grab is not a function

This function and class is listed in the GJS Docs, but maybe I'm calling it wrong? If I call typeof on Gdk.Seat.grab it comes back undefined. Is this not possible, or is there another way I can grab focus in this way?

My use case is gathering a keybinding from a user, for which I can use Gtk.CellRendererAccel, but I would prefer not to use a Gtk.TreeView. The docs say about CellRenderers that:

These objects are used primarily by the GtkTreeView widget, though they aren’t tied to them in any specific way.

and...

The primary use of a GtkCellRenderer is for drawing a certain graphical elements on a cairo_t.

Which implies I could use it outside of TreeView, but with no hints as to how.

1

There are 1 answers

1
ptomato On BEST ANSWER

grab() is a method of Gdk.Seat, so you need a Gdk.Seat object to call it on. It looks like you're calling it as a static method, Gdk.Seat.grab(). So, you'll need something like Gdk.DeviceManager.get().get_default_display().get_default_seat() or you can get a Gdk.Seat object from a Gdk.Event.

It's not clear from the described use case what you are trying to do with the grab, but there may be an easier way to accomplish it.