Skip to content

Do not poll for system theme changes#108705

Merged
Repiteo merged 1 commit into
godotengine:masterfrom
wjt:dont-poll-system-theme
Nov 14, 2025
Merged

Do not poll for system theme changes#108705
Repiteo merged 1 commit into
godotengine:masterfrom
wjt:dont-poll-system-theme

Conversation

@wjt
Copy link
Copy Markdown
Contributor

@wjt wjt commented Jul 17, 2025

The DisplayServer interface has change notification for theme changes. As far as I can tell, all display servers with a concept of system theme also implement the DisplayServer::set_system_theme_change_callback(const Callable &p_callable) method. So there should be no need to poll every second for the system theme.


This change is only lightly tested on a single platform (GNOME 43). I spotted the polling while working on #108704. The cost of polling is not huge, but in the XDG implementation (and possibly others) it's a blocking IPC call – probably better avoided.

Copy link
Copy Markdown
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

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

Works correctly, tested on Windows.

@KoBeWi KoBeWi added this to the 4.6 milestone Jul 17, 2025
Copy link
Copy Markdown
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

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

Should be fine, timer was implemented before DS callback.

@wjt
Copy link
Copy Markdown
Contributor Author

wjt commented Jul 18, 2025

Thanks for those pointers. I noticed that #87384 said “all platforms, except web” so I checked and DisplayServerWeb doesn't implement dark mode etc. at all. I looked into it briefly and based on https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia and https://www.hanselman.com/blog/how-to-detect-if-the-users-os-prefers-dark-mode-and-change-your-site-with-css-and-js it could be implemented with a small amount of JS glue, but that's one for another day.

The DisplayServer interface has change notification for theme changes.
As far as I can tell, all display servers with a concept of system theme
also implement the DisplayServer::set_system_theme_change_callback(const
Callable &p_callable) method. So there should be no need to poll every
second for the system theme.
@wjt wjt force-pushed the dont-poll-system-theme branch from e139099 to f6ee1e1 Compare September 16, 2025 09:58
@Repiteo Repiteo merged commit af30016 into godotengine:master Nov 14, 2025
20 checks passed
@Repiteo
Copy link
Copy Markdown
Contributor

Repiteo commented Nov 14, 2025

Thanks!

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.

4 participants