2017-09-01 113 views
0

看来当我打电话Gdk.Seat.grab()在GJS我得到一个错误:是否可以在GJS中调用Gdk.Seat.grab()?

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

这个函数和类是listed in the GJS Docs,但也许我打电话错了?如果我在Gdk.Seat.grab上拨打typeof,它会返回undefined。这是不可能的,还是有另一种方式可以抓住焦点?

我的用例是收集用户的键绑定,我可以使用Gtk.CellRendererAccel,但我不希望使用Gtk.TreeView。该文件说约CellRenderers说:

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之外,但没有提示如何。

回答

1

grab()是一个方法Gdk.Seat,所以你需要一个Gdk.Seat对象来调用它。您看起来像是将其称为静态方法Gdk.Seat.grab()。所以,你需要类似Gdk.DeviceManager.get().get_default_display().get_default_seat()或者你可以从Gdk.Event得到一个Gdk.Seat对象。

从描述的用例中不清楚你正在尝试使用抓取,但可能有更简单的方法来完成它。

+0

啊,我应该意识到这一点。当我无法找到一个好的GJS例子时,我通常会回想起在C或Vala中找到一个例子(在这种情况下是gnome-control-center),但这实际上并不是我的特长,因此是错误的静态方法。我的用例是一个shell扩展的用户可配置键绑定,但TreeView路由中的CellRendererAccel更适合我的需求。谢谢你的回复。 –

相关问题