When creating a Window in XLib
SetWindowAttributes.event_mask
The first three are well-documented, I think.
To determine whether the mouse is over your window, listen to Enter and Leave events. The xev utility is a great way to understand what events exist in the X window system, and when they are sent.
xev