我试图捕获每个窗口的配置事件,以创建Windows7风格的快照功能。我知道有涉及compiz fusion的解决方案,但我的安装是在vmware中运行的,没有硬件加速来运行compiz。我想一个简单的python脚本可以做我想做的事情,但是我似乎找不到合适的地方来绑定configure事件。
如何/如何绑定配置事件回调,或者是否需要监视其他事件?我试过使用get_root_window()将它绑定到屏幕和根窗口,但没有成功。
编辑2
现在我可以捕获所有事件,问题是返回的每个事件都是gdk_nothing类型,所以我无法区分焦点事件、移动事件、关闭事件等。

#!/usr/bin/python
import pygtk
pygtk.require('2.0')
import gtk, wnck
import inspect

def move_event(e):
    print e.type, e.window
    print inspect.getmembers(e)
    return gtk.gdk.FILTER_CONTINUE

def bind_win(screen, win):
    w = gtk.gdk.window_foreign_new(win.get_xid())
    if w:
        w.set_events(w.get_events() | gtk.gdk.ALL_EVENTS_MASK)
        w.add_filter(move_event)


if __name__ == "__main__":
    screen = wnck.screen_get_default()
    screen.connect("window_opened", bind_win)
    gtk.main()

拖动窗口时移动事件(e)的一次迭代:
<enum GDK_NOTHING of type GdkEventType> <gtk.gdk.Window object at 0x7f38f72f8730 (GdkWindow at 0x196ce20)>[('copy', <built-in method copy of gtk.gdk.Event object at 0x7f3900513d00>), ('free', <built-in method free of gtk.gdk.Event object at 0x7f3900513d00>), ('get_axis', <built-in method get_axis of gtk.gdk.Event object at 0x7f3900513d00>), ('get_coords', <built-in method get_coords of gtk.gdk.Event object at 0x7f3900513d00>), ('get_root_coords', <built-in method get_root_coords of gtk.gdk.Event object at 0x7f3900513d00>), ('get_screen', <built-in method get_screen of gtk.gdk.Event object at 0x7f3900513d00>), ('get_state', <built-in method get_state of gtk.gdk.Event object at 0x7f3900513d00>), ('get_time', <built-in method get_time of gtk.gdk.Event object at 0x7f3900513d00>), ('put', <built-in method put of gtk.gdk.Event object at 0x7f3900513d00>), ('send_client_message', <built-in method send_client_message of gtk.gdk.Event object at 0x7f3900513d00>), ('send_clientmessage_toall', <built-in method send_clientmessage_toall of gtk.gdk.Event object at 0x7f3900513d00>), ('send_event', 1), ('set_screen', <built-in method set_screen of gtk.gdk.Event object at 0x7f3900513d00>), ('type', <enum GDK_NOTHING of type GdkEventType>), ('window', <gtk.gdk.Window object at 0x7f38f72f8730 (GdkWindow at 0x196ce20)>)]

最佳答案

快速搜索会显示this页面,虽然它是用c编写的,但它很好地传达了基本信息(您必须grep它才能找到“移动窗口”)。
配置事件绑定到应用程序的窗口。
要做您想做的事情,您还必须找出屏幕大小,它位于gtk.gdk.screen中,文档中有here

关于python - pyGTK检测所有窗口移动事件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3128536/

10-11 21:01