2010-11-03 27 views
3

編程與X11庫C,是如果有一個新的窗口出現時獲取通知的方式?我發現XSetAfterFunction但其僅用於調試目的...X11編程:如果出現新窗口會收到通知?

感謝您的幫助!

海因裏希

@edit:

此代碼解決我的問題

int main() {  
Display* display = XOpenDisplay(":2"); 

XSetWindowAttributes attributes; 
attributes.event_mask = SubstructureNotifyMask | StructureNotifyMask; 

XChangeWindowAttributes(display, 0x100, CWEventMask, &attributes); 

while (true) { 
    XEvent event; 
    XNextEvent(display, &event); 
    std::cout << "Event occured" << std::endl; 
} 

return 0; 
} 
+1

您使用的窗口管理器?哪一個? – 2010-11-03 14:40:47

+0

我沒有使用窗口管理器。只是Xvfb。 – Erik 2010-11-03 15:57:24

回答

2

從內存中,你可以使用XChangeWindowAttributes從根窗口監聽事件,然後XMapEvent作用(或XCreateWindowEvent或任何事件取決於你的「新窗口出現」的定義)。

+0

我貼我上面的代碼在我的線程,它不是真正的工作。我也嘗試過使用XSelectInput()。 – Erik 2010-11-03 15:57:55

+0

嗯,它現在可行!非常感謝! – Erik 2010-11-03 16:06:54