opt: use nearest refresh for monitor rule

This commit is contained in:
DreamMaoMao 2025-09-17 12:02:14 +08:00
parent d05c2755c3
commit 50e4a49c2e

View file

@ -2506,15 +2506,22 @@ void createlocksurface(struct wl_listener *listener, void *data) {
struct wlr_output_mode *get_output_mode(struct wlr_output *output, int width,
int height, float refresh) {
struct wlr_output_mode *mode;
struct wlr_output_mode *mode, *nearest_mode = NULL;
float min_diff = 99999.0f;
wl_list_for_each(mode, &output->modes, link) {
if (mode->width == width && mode->height == height &&
(int)round(mode->refresh / 1000) == (int)round(refresh)) {
return mode;
if (mode->width == width && mode->height == height) {
float mode_refresh = mode->refresh / 1000.0f;
float diff = fabsf(mode_refresh - refresh);
if (diff < min_diff) {
min_diff = diff;
nearest_mode = mode;
}
}
}
return NULL;
return nearest_mode;
}
void createmon(struct wl_listener *listener, void *data) {