Add a bit of scheduling to updates; update every 30 ms instead of waiting

for more events. Smooths out window moving. Interval needs to be
    configurable probably.
This commit is contained in:
Keith Packard 2003-11-10 05:48:23 +00:00
parent 37280d7888
commit 9e767b89cf
2 changed files with 33 additions and 5 deletions

View File

@ -1,3 +1,10 @@
2003-11-09 Keith Packard <keithp@keithp.com>
* xcompmgr.c: (time_in_millis), (main):
Add a bit of scheduling to updates; update every 30 ms
instead of waiting for more events. Smooths out window moving.
Interval needs to be configurable probably.
2003-11-09 Keith Packard <keithp@keithp.com> 2003-11-09 Keith Packard <keithp@keithp.com>
* xcompmgr.c: (root_tile): * xcompmgr.c: (root_tile):

View File

@ -732,6 +732,17 @@ expose_root (Display *dpy, Window root, XRectangle *rects, int nrects)
add_damage (dpy, region); add_damage (dpy, region);
} }
int
time_in_millis ()
{
struct timeval tp;
gettimeofday (&tp, 0);
return(tp.tv_sec * 1000) + (tp.tv_usec / 1000);
}
#define INTERVAL 30
main () main ()
{ {
XEvent ev; XEvent ev;
@ -751,6 +762,9 @@ main ()
int n_expose = 0; int n_expose = 0;
struct pollfd ufd; struct pollfd ufd;
int n; int n;
int last_update;
int now;
int timeout;
dpy = XOpenDisplay (0); dpy = XOpenDisplay (0);
if (!dpy) if (!dpy)
@ -808,6 +822,7 @@ main ()
add_win (dpy, children[i], i ? children[i-1] : None); add_win (dpy, children[i], i ? children[i-1] : None);
XFree (children); XFree (children);
XUngrabServer (dpy); XUngrabServer (dpy);
last_update = time_in_millis ();
for (;;) for (;;)
{ {
/* dump_wins (); */ /* dump_wins (); */
@ -873,11 +888,17 @@ main ()
break; break;
} }
} while (XEventsQueued (dpy, QueuedAfterReading)); } while (XEventsQueued (dpy, QueuedAfterReading));
ufd.fd = ConnectionNumber (dpy); now = time_in_millis ();
ufd.events = POLLIN; timeout = INTERVAL - (now - last_update);
n = poll (&ufd, 1, 30); if (timeout > 0)
if (n > 0 && (ufd.revents & POLLIN) && XEventsQueued (dpy, QueuedAfterReading)) {
continue; ufd.fd = ConnectionNumber (dpy);
ufd.events = POLLIN;
n = poll (&ufd, 1, timeout);
if (n > 0 && (ufd.revents & POLLIN) && XEventsQueued (dpy, QueuedAfterReading))
continue;
}
last_update = time_in_millis();
if (allDamage) if (allDamage)
{ {
paint_all (dpy, allDamage); paint_all (dpy, allDamage);