有關於如何處理窗口的使用XLIB收盤時,其可以在互聯網上找到許多例子:XLIB:調用XSetWMProtocols後窗口管理器不發送客戶端消息
- http://cboard.cprogramming.com/linux-programming/60466-xwindows-close-window-event.html
- https://en.wikibooks.org/wiki/X_Window_Programming/XLib
- https://john.nachtimwald.com/2009/11/01/x11-intercept-window-close-event/
還有幾個。這就是說我試圖在代碼中實現它們,如下所示。但是當我點擊窗口一角的X時,沒有事件發送到我的消息循環中。這是因爲XChcekWindowEvent
忽略或不處理客戶端消息?如果不是這種情況,我應該尋找一些其他的東西來尋找使用SetWMProtocols
來設置XLib的消息?
m_impl->m_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", False);
if (!XSetWMProtocols(display, window, &m_impl->m_delete_window, 1)) {
std::cout << "Set Window Protocols Failed" << std::endl;
}
...
while (!terminate) {
while (::XCheckWindowEvent(display, window, events::mask, &x_event)) {
if (x_event.type == ClientMessage) {
std::cout << "Client Message" << std::endl;
if ((Atom)x_event.xclient.data.l[0] == m_impl->m_delete_window) {
terminate = true;
}
}
}
}