Search code examples
c++xlib

How to get the event window from an event in xlib


I'm trying to implement a feature that changes the color of a child window when the user hovers over it. To do this, I need to receive EnterNotify events for specific child windows. I'm getting the EnterNotify events with no problem, but I can't figure out how to distinguish between which child window the EnterNotify event is coming from. How do I get the event window from an event?

if (event.type == EnterNotify && event.xcrossing.window == w11) {
            std::cout << "ENTER WINDOW" << std::endl;
        }

This is what I have tried with w11 being the child window. Nothing is sent to output when the EnterNotify events come in, but if I change the event.xcrossing.window equivalency to win (the parent window), as shown below, it will produce output as the EnterNotify events roll in. Thanks.

if (event.type == EnterNotify && event.xcrossing.window == win) {
            std::cout << "ENTER WINDOW" << std::endl;
        }

Solution

  • It turns out that when you create a child window using XCreateSimpleWindow, the parent window's mask input is not carried over to the child window. All I had to do was update each child window to receive EnterWindowMask events.