From 8dcf324f15f0106ca054658b3f35288f52625ced Mon Sep 17 00:00:00 2001 From: Saphira Kai Date: Wed, 30 Mar 2022 01:34:21 -0300 Subject: [PATCH] add support for arbitrary refresh rates in the select animation --- config.mk | 5 ++++- instantmenu.c | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/config.mk b/config.mk index 6ff31d7..4d714ce 100644 --- a/config.mk +++ b/config.mk @@ -12,6 +12,9 @@ X11LIB = /usr/X11R6/lib XINERAMALIBS = -lXinerama XINERAMAFLAGS = -DXINERAMA +# XRandR +XRANDRLIBS = -lXrandr + # freetype FREETYPELIBS = -lfontconfig -lXft FREETYPEINC = /usr/include/freetype2 @@ -20,7 +23,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_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS) diff --git a/instantmenu.c b/instantmenu.c index 70651c3..89da032 100644 --- a/instantmenu.c +++ b/instantmenu.c @@ -15,6 +15,7 @@ #ifdef XINERAMA #include #endif +#include #include #include #include @@ -727,6 +728,14 @@ void animatesel() { int time; time = 0; drw_setscheme(drw, scheme[SchemeSel]); + + XRRScreenConfiguration *conf = XRRGetScreenInfo(dpy, RootWindow(dpy, 0)); + short refresh_rate = XRRConfigCurrentRate(conf); + + // scale the framerate properly for !=60Hz displays + framecount = framecount * (refresh_rate / 60); + double usecs = (1 / (double)refresh_rate) * 1000000; + while (time < framecount) { // bottom animation @@ -736,7 +745,7 @@ void animatesel() { drw_rect(drw, 0, sely + 4 - (easeOutQuint(((double)time/framecount)) * (sely + 4)), mw, (easeOutQuint(((double)time/framecount)) * sely), 1, 1, 0); drw_map(drw, win, 0, 0, mw, mh); time++; - usleep(19000); + usleep(usecs); } } @@ -755,13 +764,21 @@ void animaterect(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2) time = 0; double timefactor = 0; drw_setscheme(drw, scheme[SchemeSel]); + + XRRScreenConfiguration *conf = XRRGetScreenInfo(dpy, RootWindow(dpy, 0)); + short refresh_rate = XRRConfigCurrentRate(conf); + + // scale the framerate properly for !=60Hz displays + framecount = framecount * (refresh_rate / 60); + double usecs = (1 / (double)refresh_rate) * 1000000; + while (time < framecount) { timefactor = easeOutQuint((double)time/framecount); drw_rect(drw, x1 + (x2 - x1) * timefactor, y1 + (y2 - y1) * timefactor, w1 + (w2 - w1) * timefactor, h1 + (h2 - h1) * timefactor, 1, 1, 0); drw_map(drw, win, 0, 0, mw, mh); time++; - usleep(19000); + usleep(usecs); } }