add Jtk_CheckEvent()

This commit is contained in:
Josh Holtrop 2017-10-14 11:36:07 -04:00
parent 3a594b5355
commit 49c34907f5
2 changed files with 44 additions and 35 deletions

View File

@ -335,17 +335,15 @@ static bool ProcessXEvent(XEvent * x_event, Jtk_Event * event)
return false;
}
void Jtk_WaitEvent(Jtk_Event * event)
bool Jtk_CheckEvent(Jtk_Event * event)
{
for (;;)
{
/* First check for an X event. */
while (XPending(g_display) > 0)
{
XEvent x_event;
XNextEvent(g_display, &x_event);
if (ProcessXEvent(&x_event, event))
return;
return true;
}
/* Next check if any timer has expired. */
@ -372,10 +370,20 @@ void Jtk_WaitEvent(Jtk_Event * event)
}
#endif
Jtk_ServiceTimer(timer_id);
return;
return true;
}
/* Finally, wait for something to happen. */
return false;
}
void Jtk_WaitEvent(Jtk_Event * event)
{
for (;;)
{
if (Jtk_CheckEvent(event))
return;
/* Wait for something to happen. */
uint64_t time_to_wait = Jtk_TimeToNextTimerExpiration();
if (time_to_wait > MAX_WAIT_TIME)
{

View File

@ -52,6 +52,7 @@ typedef struct
};
} Jtk_Event;
bool Jtk_CheckEvent(Jtk_Event * event);
void Jtk_WaitEvent(Jtk_Event * event);
#if 0
void Jtk_BeginKeyRepeat(Jtk_KeyEvent * key_event, uint32_t delay, uint32_t interval);