Get a Firefox's window id (WId) under X11

主宰稳场 提交于 2019-12-12 03:05:02

问题


I'm trying to find out how to get a Firefox's X11 WId (window id) from within a Firefox addon/extension.

Checked out nsIWindowMediator, nsIXULBrowserWindow, nsIXULWindow but haven't found it.

I'd rather not go the usual way of (ab)using Xlib to search the window tree for one that matches the attributes of the current window like title, type and so on.


回答1:


I think that the only place where you can get it is nsIEmbeddingSiteWindow.siteWindow (its type is GtkWidget* on Linux, it should be possible to get the window id from that). Getting an nsIEmbeddingSiteWindow instance for a top-level window is relatively straightforward:

Components.utils.import("resource://gre/modules/Services.jsm");

var embedding = Services.ww.getChromeForWindow(window)
                  .QueryInterface(Components.interfaces.nsIEmbeddingSiteWindow);

The problem is that the siteWindow property is marked with the [noscript] annotator - it isn't accessible from JavaScript. So I had to use a binary XPCOM component (written in C++) to actually retrieve that property. Don't know whether that's an acceptable solution for you. The only alternative should be searching the window tree indeed.



来源:https://stackoverflow.com/questions/11057906/get-a-firefoxs-window-id-wid-under-x11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!