AtlatestRepositorysigil-ui

sigil-ui / tree / nativesurface-mode.h

1/* Match wlroots' millihertz conversion, including scan flags and rounding. */
2#ifndef SIGIL_UI_SURFACE_MODE_H
3#define SIGIL_UI_SURFACE_MODE_H
4#include <stdint.h>
5#include <drm/drm_mode.h>
6static int64_t surface_refresh_mhz(const struct drm_mode_modeinfo *mode)
7{
8 if (!mode->clock || !mode->htotal || !mode->vtotal) return 0;
9 int64_t refresh = (mode->clock * INT64_C(1000000) / mode->htotal + mode->vtotal / 2) / mode->vtotal;
10 if (mode->flags & DRM_MODE_FLAG_INTERLACE) refresh *= 2;
11 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) refresh /= 2;
12 if (mode->vscan > 1) refresh /= mode->vscan;
13 return refresh;
15#endif