21 #ifndef GX_EVENT_LOOP_H
22 #define GX_EVENT_LOOP_H
40 Timeval() { ::gettimeofday(&m_timeval,
nullptr) ; }
41 explicit Timeval(
int ) { reset() ; }
42 explicit Timeval(
const struct timeval & tv ) : m_timeval(tv) {}
43 void reset() { m_timeval.tv_sec = 0 ; m_timeval.tv_usec = 0 ; }
44 bool is_set()
const {
return m_timeval.tv_sec != 0 ; }
45 bool operator<(
const Timeval & other )
const
48 m_timeval.tv_sec < other.m_timeval.tv_sec ||
49 ( m_timeval.tv_sec == other.m_timeval.tv_sec && m_timeval.tv_usec < other.m_timeval.tv_usec ) ;
51 bool operator==(
const Timeval & other )
const
53 return m_timeval.tv_sec == other.m_timeval.tv_sec && m_timeval.tv_usec == other.m_timeval.tv_usec ;
55 bool operator>(
const Timeval & other )
const
57 return !((*this)==other) && other < (*
this) ;
59 struct timeval m_timeval ;
64 const bool carry = small.m_timeval.tv_usec > big.m_timeval.tv_usec ;
65 result.m_timeval.tv_usec = (carry?1000000L:0L) + big.m_timeval.tv_usec ;
66 result.m_timeval.tv_usec -= small.m_timeval.tv_usec ;
67 result.m_timeval.tv_sec = big.m_timeval.tv_sec - small.m_timeval.tv_sec - (carry?1:0) ;
70 inline Timeval operator+(
const Timeval & base ,
unsigned long usec )
72 Timeval result = base ;
73 result.m_timeval.tv_usec += ( usec % 1000000UL ) ;
74 result.m_timeval.tv_sec += ( usec / 1000000UL ) ;
75 bool carry = result.m_timeval.tv_usec > 1000000L ;
78 result.m_timeval.tv_usec -= 1000000L ;
79 result.m_timeval.tv_sec++ ;
111 void startTimer(
unsigned int milliseconds ) ;
123 void handle( ::XEvent & ) ;
124 void handleImp( ::XEvent & ) ;
A window class that is-a GX::Drawable and a GX::EventHandler.
void handlePendingEvents()
Handles all pending events.
An event-loop class that delivers Xlib 'Display' events to GX::Window objects via their GX::EventHand...
void startTimer(unsigned int milliseconds)
Starts a timer for runToTimeout().
void runToEmpty()
Processes all events in the queue and then returns.
void runOnce()
Waits for one event and processes it.
void runUntil(int event_type)
Runs the event loop until the given event is received.
void run()
Runs the event loop.
A class that can locate a GX::Window object based on a Xlib window handle.
void runToTimeout()
Processes all events until the timer goes off.
EventLoop(Display &)
Constructor. The display reference is kept.
A thin wrapper for 'struct timeval' providing relational operators etc.