如何从xid获取Gdk窗口? [英] How to get Gdk window from xid?

查看:282
本文介绍了如何从xid获取Gdk窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在版本3中迷路了.在python2 + gdk2中是:

I'm lost in version 3.. in python2+gdk2 is:

#!/usr/bin/env python2
import gtk

gtk.gdk.window_process_all_updates()
window_xid = 54525964
gdk_window = gtk.gdk.window_foreign_new(window_xid)

这很简单.但是然后,恐怖:

which is pretty much straight forward. But then, the horror:

#!/usr/bin/env python3
from gi.repository import xlib
from gi.repository import Gdk
from gi.repository import GdkX11

Gdk.Window.process_all_updates()
xlib_window = "???????"
gdk_display = GdkX11.X11Display.get_default()
gdk_window = GdkX11.X11Window.foreign_new_for_display(gdk_display, xlib_window)

xlib杀死了我.我无法对其进行任何处理.以前有人使用过吗?

the xlib is killing me.. I'm unable to do anything with it. Has anybody worked with it before??

我已经浏览过几次的文档是: Gdk3 Xlib

The documentation I've through several times already is: Gdk3, Xlib

从xid获取窗口是在python2中获取屏幕截图的最快方法.我想我会在python3中尝试另一种方法.也许从根窗口的peek_children?但是,我怎么知道这是我想要的窗户?

Getting the window from its xid was the fastest way to get a screenshot in python2 I guess I'll have try another way in python3.. any ideas? maybe peek_children from root window?? but then, how do I know if it's the window I want?

推荐答案

X11中的WindowXID相同.彼此之间只有一个typedef.

A Window in X11 is the same as an XID. There's just a typedef from one to the other.

因此,在C代码中,gdk_x11_window_foreign_new_for_display()仅接受WindowXID,这基本上是一个整数.这在使用自省的python中也适用:

So in C code gdk_x11_window_foreign_new_for_display() just accepts an Window or XID, which is basically an integer. This also works in python using introspection:

#!/usr/bin/env python3
from gi.repository import Gdk
from gi.repository import GdkX11

Gdk.Window.process_all_updates()
xlib_window = 0x2a00005 # from xwininfo command
gdk_display = GdkX11.X11Display.get_default()
gdk_window = GdkX11.X11Window.foreign_new_for_display(gdk_display, xlib_window)
print(gdk_window.get_geometry())

这篇关于如何从xid获取Gdk窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆