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

output-layout: fix mode selection with no configured rr #2256

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/core/output-layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ wlr_output_mode *find_matching_mode(wlr_output *output,
{
wlr_output_mode *mode;
wlr_output_mode *best = NULL;

// Pick highest refresh rate by default
int target_refresh = reference.refresh;
if (target_refresh == 0)
{
target_refresh = INT_MAX;
}

wl_list_for_each(mode, &output->modes, link)
{
if ((mode->width == reference.width) && (mode->height == reference.height))
Expand All @@ -68,9 +76,15 @@ wlr_output_mode *find_matching_mode(wlr_output *output,
return mode;
}

const int bestSoFar = best ? std::abs(best->refresh - reference.refresh) : INT_MAX;
const int current = std::abs(mode->refresh - reference.refresh);
if (!best || (bestSoFar > current))
if ((reference.refresh == 0) && mode->preferred)
{
// If there is a preferred mode and there is no refresh configured, pick preferred mode.
return mode;
}

const int best_so_far = best ? std::abs(best->refresh - target_refresh) : INT_MAX;
const int current = std::abs(mode->refresh - target_refresh);
if (!best || (best_so_far > current))
{
best = mode;
}
Expand Down
Loading