2017-09-01 87 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更適合我的需求。謝謝你的回覆。 –

相關問題