Skip to content

Commit a0425a1

Browse files
committed
Attempt to optimize the event look on XWindow
The changes are not tested.
1 parent 23cc35b commit a0425a1

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

agg_platform_support_x11.cpp

+41-9
Original file line numberDiff line numberDiff line change
@@ -801,11 +801,48 @@ void platform_support::update_window()
801801
XSync(xc->display, m_wait_mode);
802802
}
803803

804-
static Bool is_configure_pred(Display *d, XEvent *ev, XPointer arg)
804+
static Bool is_configure_or_expose(Display *d, XEvent *ev, XPointer arg)
805805
{
806-
return ev->type == ConfigureNotify ? True : False;
806+
return (ev->type == ConfigureNotify || ev->type == Expose) ? True : False;
807807
}
808808

809+
struct loop_state {
810+
XEvent config;
811+
XEvent expose;
812+
813+
loop_state() {
814+
config.type = 0;
815+
expose.type = 0;
816+
}
817+
};
818+
819+
static XEvent x_get_event(Display *d, loop_state& current)
820+
{
821+
XEvent xev;
822+
if (current.expose.type == Expose) {
823+
xev = current.expose;
824+
current.expose.type = 0;
825+
return xev;
826+
}
827+
while (XCheckIfEvent(d, &xev, is_configure_or_expose, NULL) == True) {
828+
if (xev.type == ConfigureNotify) {
829+
current.config = xev;
830+
current.expose.type = 0;
831+
} else {
832+
current.expose = xev;
833+
}
834+
}
835+
if (current.config.type == ConfigureNotify) {
836+
xev = current.config;
837+
current.config.type = 0;
838+
} else if (current.expose.type == Expose) {
839+
xev = current.expose;
840+
current.expose.type = 0;
841+
} else {
842+
XNextEvent(d, &xev);
843+
}
844+
return xev;
845+
}
809846

810847
//------------------------------------------------------------------------
811848
int platform_support::run()
@@ -820,6 +857,7 @@ int platform_support::run()
820857

821858
platform_specific *ps = m_specific;
822859

860+
loop_state event_loop;
823861
while(!quit)
824862
{
825863
if(ps->m_update_flag && ps->m_is_mapped)
@@ -835,13 +873,7 @@ int platform_support::run()
835873
if (ps->m_is_mapped)
836874
{
837875
ps->m_mutex.unlock();
838-
XNextEvent(xc->display, &x_event);
839-
if (x_event.type == ConfigureNotify) {
840-
XEvent xpk;
841-
while (XCheckIfEvent(xc->display, &xpk, is_configure_pred, NULL) == True) {
842-
x_event = xpk;
843-
}
844-
}
876+
x_event = x_get_event(xc->display, event_loop);
845877
ps->m_mutex.lock();
846878
}
847879
else

0 commit comments

Comments
 (0)