As previously reported by respondents, it is system-specific and can be implemented in any case.
If I remember the Windows API rights (many years ago), a “window function” appeared that was called for each event, and I made a lot of choices to choose the right action depending on the type of event.
I think most toolkits abstract this out as Java AWT with its event dispatch queue.
For protocol X, the input events (as well as “your window needs to be drawn”) come in the form of event messages via cable, and the instrumentation library can either convert it to an application function call or add them to the request queue later.
In fact, the X protocol works (mainly) with two byte streams: one from the application ("client") to the system ("server"), one in the other direction. The client sends request packets, the server sends results (for some types of requests), errors (if some request cannot be executed for any reason), and events (when something happens on the display, like a mouse movement, a key press, resizing the window, ...).
For local displays in modern systems, this is usually implemented using some shared memory mechanism, but in principle, it can go through TCP (or today mainly via SSH) for remote connections (thus, "over the cable").
Once I started creating a clean implementation of the Java X client (I didn’t complete it because I found other interesting things), and there I just used Socket with InputStream and OutputStream to connect to the server. Thus, in principle, I used the Socket-InputStream function blocking my own read() to wait for events (and results and errors). I could use java.nio.SocketChannel in non-blocking mode, too, and then basically I would have a polling cycle (by the way, by the way, of course). (Or I could use a selector, waiting for new readable data to appear - this way, blocking too.)
I have no idea what mechanism the AWT-for-X implementation used in the Java and Solaris Java implementations implements, I believe that they are based on some proprietary toolkit, which, in turn, is based on the X-client library ( for C) "Xlib", but I don’t know if there is a poll, wait blocking or someone calling in the database.