Search code examples
c++xlib

XLib: Windows Manager not Sending Client Message after Calling XSetWMProtocols


There are many examples on how to handle the closing of a window using XLib, which can be found on the internet:

There are several more. That said I have tried to implement them in code, as seen below. However when I click on X in the corner of my window I get no event sent to my message loop. Is this because XChcekWindowEvent ignores or does not process Client Messages? If this is not the case what are some other things I should be looking for to get messages from XLib set using SetWMProtocols?

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;
      }
    }
  }
}

Solution

  • The XCheckWindowEvent() will not return ClientMessage. It returns none of the non maskable ones. Work around:

    while (XPending(display))
    {
        XNextEvent(display, &event);
    

    But could create extra work to filter event by window. BR Pekka