- // See if there are any definitely events waiting to be processed
- // or a screen redraw to do. If so, do not wait if there is no
- // I/O coming in.
- synchronized (drainEventQueue) {
- if (drainEventQueue.size() > 0) {
- timeout = 0;
+ // If I've got no updates to render, wait for something from the
+ // backend or a timer.
+ if (!repaint
+ && ((mouseX == oldMouseX) && (mouseY == oldMouseY))
+ ) {
+ // Never sleep longer than 100 millis, to get windows with
+ // background tasks an opportunity to update the display.
+ timeout = getSleepTime(100);
+
+ // See if there are any definitely events waiting to be
+ // processed. If so, do not wait -- either there is I/O
+ // coming in or the primary/secondary threads are still
+ // working.
+ synchronized (drainEventQueue) {
+ if (drainEventQueue.size() > 0) {
+ timeout = 0;
+ }
+ }
+ synchronized (fillEventQueue) {
+ if (fillEventQueue.size() > 0) {
+ timeout = 0;
+ }