我試圖捕獲每個窗口的配置事件來創建一個Windows 7 esque管理功能。我知道有涉及compiz-fusion的解決方案,但是我的安裝在vmware中運行,並且沒有硬件加速來運行compiz。我想到一個簡單的python腳本可以做我想要的,但我似乎無法找到將配置事件綁定到的正確位置。pyGTK檢測所有窗口移動事件
如何/爲什麼綁定configure-event回調,還是有一個我需要注意的不同事件?我已經嘗試使用get_root_window()將它綁定到屏幕和根窗口,但沒有運氣。
EDIT2
現在我可以捕獲所有事件,問題是,返回的每個事件的類型是GDK_NOTHING的,所以我不能告訴焦點事件之間的差別,移動事件,關閉事件,等等。 move_event(e)中的
#!/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()
一次迭代的同時拖動窗口:
<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)>)]
我遇到同樣的問題。我認爲這可能是一個gtk錯誤。 – simonzack 2014-01-12 05:18:31
我在這裏提交了一個bug:https://bugzilla.gnome.org/show_bug.cgi?id = 722027 – simonzack 2014-01-12 05:34:22