The _X_S_y_n_c function flushes the output buffer and then waits until all requests have been received and processed by the X server. Any errors generated must be handled by the error handler. For each protocol error received by Xlib, _X_S_y_n_c calls the client application's error handling routine (see section 11.8.2). Any events generated by the server are enqueued into the library's event queue.
Finally, if you passed _F_a_l_s_e, _X_S_y_n_c does not discard the events in the queue. If you passed _T_r_u_e, _X_S_y_n_c discards all events in the queue, including those events that were on the queue before _X_S_y_n_c was called. Client applications seldom need to call _X_S_y_n_c.
If mode is _Q_u_e_u_e_d_A_l_r_e_a_d_y, _X_E_v_e_n_t_s_Q_u_e_u_e_d returns the number of events already in the event queue (and never performs a system call). If mode is _Q_u_e_u_e_d_A_f_t_e_r_F_l_u_s_h, _X_E_v_e_n_t_s_Q_u_e_u_e_d returns the number of events already in the queue if the number is nonzero. If there are no events in the queue, _X_E_v_e_n_t_s_Q_u_e_u_e_d flushes the output buffer, attempts to read more events out of the application's connection, and returns the number read. If mode is _Q_u_e_u_e_d_A_f_t_e_r_R_e_a_d_i_n_g, _X_E_v_e_n_t_s_Q_u_e_u_e_d returns the number of events already in the queue if the number is nonzero. If there are no events in the queue, _X_E_v_e_n_t_s_Q_u_e_u_e_d attempts to read more events out of the application's connection without flushing the output buffer and returns the number read.
_X_E_v_e_n_t_s_Q_u_e_u_e_d always returns immediately without I/O if there are events already in the queue. _X_E_v_e_n_t_s_Q_u_e_u_e_d with mode _Q_u_e_u_e_d_A_f_t_e_r_F_l_u_s_h is identical in behavior to _X_P_e_n_d_i_n_g. _X_E_v_e_n_t_s_Q_u_e_u_e_d with mode _Q_u_e_u_e_d_A_l_r_e_a_d_y is identical to the _X_Q_L_e_n_g_t_h function.
The _X_P_e_n_d_i_n_g function returns the number of events that have been received from the X server but have not been removed from the event queue. _X_P_e_n_d_i_n_g is identical to _X_E_v_e_n_t_s_Q_u_e_u_e_d with the mode _Q_u_e_u_e_d_A_f_t_e_r_F_l_u_s_h specified.