Skip to content

[X11] Implemented automatic fps detection#18558

Merged
MrJul merged 5 commits into
masterfrom
feature/x11-detect-refresh-rate
Jun 24, 2026
Merged

[X11] Implemented automatic fps detection#18558
MrJul merged 5 commits into
masterfrom
feature/x11-detect-refresh-rate

Conversation

@kekekeks

Copy link
Copy Markdown
Member

Get monitor refresh rates from randr and update the timer accordingly.

jmacato
jmacato previously approved these changes Mar 31, 2025

@jmacato jmacato left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 11.3.999-cibuild0055842-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maotovisk

Copy link
Copy Markdown

just wanted to add that i've tested this pr on wayland (xwayland) and it works well

tested dragging between monitors, and it synced to the correct refresh rates

144hz monitor 180hz monitor
image image

@kekekeks kekekeks force-pushed the feature/x11-detect-refresh-rate branch from 5737b95 to 66289d9 Compare June 22, 2026 08:17
@MrJul MrJul added this to the 12.1 milestone Jun 22, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0066688-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul

MrJul commented Jun 22, 2026

Copy link
Copy Markdown
Member

Tested: it works as expected.

@MrJul

MrJul commented Jun 22, 2026

Copy link
Copy Markdown
Member

Further testing: Glx/Egl/Vulkan rendering modes are all okay: the FPS match the refresh rate of the current monitor (and changes when dragging the window over another monitor).

Software mode seems broken, the FPS is uncapped on all monitors. It's not really uncapped, just that WaitOne only has millisecond precision, causing more FPS than desired. With other modes, VSync kicks in.

Comment thread src/Avalonia.X11/Screens/X11Screens.cs Outdated
}

internal int MaxRefreshRate => _impl is IX11RawScreenInfoProviderWithRefreshRate refreshProvider
? Math.Max(60, refreshProvider.MaxRefreshRate)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have 60 hardcoded in 6 different places over X11Screens.cs, X11Screen.Providers.cs and X11Platform. Please introduce a constant and use it everywhere.

Comment thread src/Avalonia.X11/X11Platform.cs Outdated
/// <summary>
/// Query for display refresh rates from RANDR. May or may not use the refresh rate of your best display.
/// </summary>
public bool AllowHighRefreshRate { get; set; }

@MrJul MrJul Jun 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider setting that property to true by default. On platforms such as Windows, we do use high refresh rates by default (in WinUIComposition mode) without asking the user.

@kekekeks

Copy link
Copy Markdown
Member Author

the FPS match the refresh rate of the current monitor

That's VSync backpressure, the PR doesn't attempt to detect window/monitor matching

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0066692-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul marked this pull request as ready for review June 24, 2026 12:11
@MrJul MrJul enabled auto-merge June 24, 2026 12:28
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0066884-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added this pull request to the merge queue Jun 24, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 24, 2026
@MrJul MrJul added this pull request to the merge queue Jun 24, 2026
Merged via the queue into master with commit fe01ba3 Jun 24, 2026
10 checks passed
@MrJul MrJul deleted the feature/x11-detect-refresh-rate branch June 24, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants