1
0
mirror of https://github.com/emersion/kanshi synced 2024-11-23 00:02:16 +01:00

Be tolerant to matching refresh rates that are a few points off.

This commit is contained in:
James Walmsley 2020-01-10 20:09:00 +00:00 committed by Simon Ser
parent c92aa4af0c
commit 3d6b62ff0d

7
main.c

@ -159,12 +159,17 @@ static const struct zwlr_output_configuration_v1_listener config_listener = {
.cancelled = config_handle_cancelled, .cancelled = config_handle_cancelled,
}; };
static bool match_refresh(const struct kanshi_mode *mode, int refresh) {
int v = refresh - mode->refresh;
return abs(v) < 50;
}
static struct kanshi_mode *match_mode(struct kanshi_head *head, static struct kanshi_mode *match_mode(struct kanshi_head *head,
int width, int height, int refresh) { int width, int height, int refresh) {
struct kanshi_mode *mode; struct kanshi_mode *mode;
wl_list_for_each(mode, &head->modes, link) { wl_list_for_each(mode, &head->modes, link) {
if (mode->width == width && mode->height == height && if (mode->width == width && mode->height == height &&
(refresh == 0 || mode->refresh == refresh)) { (refresh == 0 || match_refresh(mode, refresh))) {
return mode; return mode;
} }
} }