2010-06-27 70 views
2

我試圖捕獲每個窗口的配置事件來創建一個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)>)]

+0

我遇到同樣的問題。我認爲這可能是一個gtk錯誤。 – simonzack 2014-01-12 05:18:31

+0

我在這裏提交了一個bug:https://bugzilla.gnome.org/show_bug.cgi?id = 722027 – simonzack 2014-01-12 05:34:22

回答

1

快速搜索發現this頁面,這雖然用C寫的,通信的基礎知識還算不錯(你必須grep它找到「移動窗口」)

的配置,事件被綁定到你的應用程序窗口。

要做你想要做的事情,你還必須找出屏幕尺寸,它位於gtk.gdk.screen,記錄在here

+1

感謝您的鏈接,我正在尋找一種方法來監聽所有**配置所有事件現有和未來的窗口。您的方法僅在創建新窗口時適用。 – 2010-08-19 14:15:52

+0

我雖然在你自己的應用程序內說話。你可以隨時叉e16 :) – new123456 2010-08-21 18:08:27