events_queued(+Mode, -Number)
     events_queued(+Displayable, +Mode, -Number)

Unify Number with an integer giving the number of events queued for the given Displayable, which if omitted, is the default Display.

If there are currently any events in Xlib's queue, the predicate returns immediately, unifying Number, regardless of the value of Mode. Otherwise, it behaves according to the value of Mode:

Binds Number to 0 and succeeds.
Attempts to read more events from the Display connection to the X server, without flushing the output buffer, and unifies Number to the number of events read.
Like after_reading, but also flushes the output buffer.