Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use display refresh rate for animations #122

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
5 changes: 4 additions & 1 deletion config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ X11LIB = /usr/X11R6/lib
XINERAMALIBS = -lXinerama
XINERAMAFLAGS = -DXINERAMA

# XRandR
XRANDRLIBS = -lXrandr

# freetype
FREETYPELIBS = -lfontconfig -lXft
FREETYPEINC = /usr/include/freetype2
Expand All @@ -23,7 +26,7 @@ FREETYPEINC = /usr/include/freetype2

# includes and libs
INCS = -I${X11INC} -I${FREETYPEINC}
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lm
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${XRANDRLIBS} ${FREETYPELIBS} -lm

# flags
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
Expand Down
11 changes: 10 additions & 1 deletion instantwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#include <X11/extensions/Xrandr.h>
#include <errno.h>
#include <locale.h>
#include <math.h>
Expand Down Expand Up @@ -448,11 +449,19 @@ void animateclient(Client *c, int x, int y, int w, int h, int frames,
width = w ? w : c->w;
height = h ? h : c->h;

XRRScreenConfiguration *conf = XRRGetScreenInfo(dpy, RootWindow(dpy, 0));
short refresh_rate = XRRConfigCurrentRate(conf);

// scale the framerate properly for !=60Hz displays
frames = frames * (refresh_rate / 60);
double usecs = (1 / (double)refresh_rate) * 1000000;

// halve frames if enough events are queried
frames = frames / 1 + (XEventsQueued(dpy, QueuedAlready) > 50);

// No animation if even more events are queried
if (!frames || XEventsQueued(dpy, QueuedAlready) > 100) {
usecs = 0;
if (resetpos)
resize(c, c->x, c->y, width, height, 0);
else
Expand Down Expand Up @@ -487,7 +496,7 @@ void animateclient(Client *c, int x, int y, int w, int h, int frames,
oldy + easeOutCubic(((double)time / frames)) * (y - oldy),
width, height, 1);
time++;
usleep(15000);
usleep(usecs);
}
}
}
Expand Down