可以在 GJS 中调用 Gdk.Seat.grab() 吗?

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

似乎当我在 GJS 中调用 Gdk.Seat.grab() 时出现错误:

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

这个函数和class是listed in the GJS Docs,但也许我调用错了?如果我在 Gdk.Seat.grab 上调用 typeof,它会返回 undefined。这是不可能的,还是有其他方法可以让我以这种方式获得焦点?

我的用例是从用户那里收集键绑定,对此我可以使用 Gtk.CellRendererAccel,但我不想使用 Gtk.TreeView。文档对 CellRenderer 的描述是:

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

和...

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

这意味着我可以在 TreeView 之外使用它,但没有关于如何使用的提示。

grab()Gdk.Seat 的一个方法,所以你需要一个 Gdk.Seat 对象来调用它。看起来您将其作为静态方法调用,Gdk.Seat.grab()。因此,您需要 Gdk.DeviceManager.get().get_default_display().get_default_seat() 之类的东西,或者您可以从 Gdk.Event.

中获取 Gdk.Seat 对象

从所描述的用例中不清楚您试图用抓取做什么,但可能有更简单的方法来完成它。