Add follow system theme settings

This commit is contained in:
Joseph DiGiovanni 2024-02-14 15:13:30 -05:00
parent 907db8eebc
commit 7eacb6ddbf
5 changed files with 94 additions and 0 deletions

View File

@ -703,6 +703,9 @@
<member name="interface/theme/draw_extra_borders" type="bool" setter="" getter=""> <member name="interface/theme/draw_extra_borders" type="bool" setter="" getter="">
If [code]true[/code], draws additional borders around interactive UI elements in the editor. This is automatically enabled when using the [b]Black (OLED)[/b] theme preset, as this theme preset uses a fully black background. If [code]true[/code], draws additional borders around interactive UI elements in the editor. This is automatically enabled when using the [b]Black (OLED)[/b] theme preset, as this theme preset uses a fully black background.
</member> </member>
<member name="interface/theme/follow_system_theme" type="bool" setter="" getter="">
If [code]true[/code], the editor theme preset will attempt to automatically match the system theme.
</member>
<member name="interface/theme/icon_and_font_color" type="int" setter="" getter=""> <member name="interface/theme/icon_and_font_color" type="int" setter="" getter="">
The icon and font color scheme to use in the editor. The icon and font color scheme to use in the editor.
- [b]Auto[/b] determines the color scheme to use automatically based on [member interface/theme/base_color]. - [b]Auto[/b] determines the color scheme to use automatically based on [member interface/theme/base_color].
@ -722,6 +725,10 @@
<member name="interface/theme/spacing_preset" type="String" setter="" getter=""> <member name="interface/theme/spacing_preset" type="String" setter="" getter="">
The editor theme spacing preset to use. See also [member interface/theme/base_spacing] and [member interface/theme/additional_spacing]. The editor theme spacing preset to use. See also [member interface/theme/base_spacing] and [member interface/theme/additional_spacing].
</member> </member>
<member name="interface/theme/use_system_accent_color" type="bool" setter="" getter="">
If [code]true[/code], set accent color based on system settings.
[b]Note:[/b] This setting is only effective on Windows and MacOS.
</member>
<member name="interface/touchscreen/enable_long_press_as_right_click" type="bool" setter="" getter=""> <member name="interface/touchscreen/enable_long_press_as_right_click" type="bool" setter="" getter="">
If [code]true[/code], long press on touchscreen is treated as right click. If [code]true[/code], long press on touchscreen is treated as right click.
[b]Note:[/b] Defaults to [code]true[/code] on touchscreen devices. [b]Note:[/b] Defaults to [code]true[/code] on touchscreen devices.

View File

@ -665,6 +665,8 @@ void EditorNode::_notification(int p_what) {
callable_mp(this, &EditorNode::_begin_first_scan).call_deferred(); callable_mp(this, &EditorNode::_begin_first_scan).call_deferred();
DisplayServer::get_singleton()->set_system_theme_change_callback(callable_mp(this, &EditorNode::_update_theme));
/* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */ /* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */
} break; } break;
@ -768,6 +770,9 @@ void EditorNode::_notification(int p_what) {
EditorFileDialog::set_default_show_hidden_files(EDITOR_GET("filesystem/file_dialog/show_hidden_files")); EditorFileDialog::set_default_show_hidden_files(EDITOR_GET("filesystem/file_dialog/show_hidden_files"));
EditorFileDialog::set_default_display_mode((EditorFileDialog::DisplayMode)EDITOR_GET("filesystem/file_dialog/display_mode").operator int()); EditorFileDialog::set_default_display_mode((EditorFileDialog::DisplayMode)EDITOR_GET("filesystem/file_dialog/display_mode").operator int());
follow_system_theme = EDITOR_GET("interface/theme/follow_system_theme");
use_system_accent_color = EDITOR_GET("interface/theme/use_system_accent_color");
if (EditorThemeManager::is_generated_theme_outdated()) { if (EditorThemeManager::is_generated_theme_outdated()) {
_update_theme(); _update_theme();
} }
@ -3071,6 +3076,35 @@ void EditorNode::_save_screenshot(NodePath p_path) {
ERR_FAIL_COND_MSG(error != OK, "Cannot save screenshot to file '" + p_path + "'."); ERR_FAIL_COND_MSG(error != OK, "Cannot save screenshot to file '" + p_path + "'.");
} }
void EditorNode::_check_system_theme_changed() {
DisplayServer *display_server = DisplayServer::get_singleton();
bool system_theme_changed = false;
if (follow_system_theme) {
if (display_server->get_base_color() != last_system_base_color) {
system_theme_changed = true;
last_system_base_color = display_server->get_base_color();
}
if (display_server->is_dark_mode_supported() && display_server->is_dark_mode() != last_dark_mode_state) {
system_theme_changed = true;
last_dark_mode_state = display_server->is_dark_mode();
}
}
if (use_system_accent_color) {
if (display_server->get_accent_color() != last_system_accent_color) {
system_theme_changed = true;
last_system_accent_color = display_server->get_accent_color();
}
}
if (system_theme_changed) {
_update_theme();
}
}
void EditorNode::_tool_menu_option(int p_idx) { void EditorNode::_tool_menu_option(int p_idx) {
switch (tool_menu->get_item_id(p_idx)) { switch (tool_menu->get_item_id(p_idx)) {
case TOOLS_ORPHAN_RESOURCES: { case TOOLS_ORPHAN_RESOURCES: {
@ -7527,6 +7561,15 @@ EditorNode::EditorNode() {
String exec = OS::get_singleton()->get_executable_path(); String exec = OS::get_singleton()->get_executable_path();
// Save editor executable path for third-party tools. // Save editor executable path for third-party tools.
EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "executable_path", exec); EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "executable_path", exec);
follow_system_theme = EDITOR_GET("interface/theme/follow_system_theme");
use_system_accent_color = EDITOR_GET("interface/theme/use_system_accent_color");
system_theme_timer = memnew(Timer);
system_theme_timer->set_wait_time(1.0);
system_theme_timer->connect("timeout", callable_mp(this, &EditorNode::_check_system_theme_changed));
add_child(system_theme_timer);
system_theme_timer->set_owner(get_owner());
system_theme_timer->set_autostart(true);
} }
EditorNode::~EditorNode() { EditorNode::~EditorNode() {

View File

@ -357,6 +357,13 @@ private:
Ref<Theme> theme; Ref<Theme> theme;
Timer *system_theme_timer = nullptr;
bool follow_system_theme = false;
bool use_system_accent_color = false;
bool last_dark_mode_state = false;
Color last_system_base_color = Color(0, 0, 0, 0);
Color last_system_accent_color = Color(0, 0, 0, 0);
PopupMenu *recent_scenes = nullptr; PopupMenu *recent_scenes = nullptr;
String _recent_scene; String _recent_scene;
List<String> previous_scenes; List<String> previous_scenes;
@ -533,6 +540,8 @@ private:
void _screenshot(bool p_use_utc = false); void _screenshot(bool p_use_utc = false);
void _save_screenshot(NodePath p_path); void _save_screenshot(NodePath p_path);
void _check_system_theme_changed();
void _tool_menu_option(int p_idx); void _tool_menu_option(int p_idx);
void _export_as_menu_option(int p_idx); void _export_as_menu_option(int p_idx);
void _update_file_menu_opened(); void _update_file_menu_opened();

View File

@ -464,11 +464,13 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/inspector/float_drag_speed", 5.0, "0.1,100,0.01") EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/inspector/float_drag_speed", 5.0, "0.1,100,0.01")
// Theme // Theme
EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_ENUM, "interface/theme/follow_system_theme", false, "")
EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "interface/theme/preset", "Default", "Default,Breeze Dark,Godot 2,Gray,Light,Solarized (Dark),Solarized (Light),Black (OLED),Custom") EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "interface/theme/preset", "Default", "Default,Breeze Dark,Godot 2,Gray,Light,Solarized (Dark),Solarized (Light),Black (OLED),Custom")
EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "interface/theme/spacing_preset", "Default", "Compact,Default,Spacious,Custom") EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "interface/theme/spacing_preset", "Default", "Compact,Default,Spacious,Custom")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/theme/icon_and_font_color", 0, "Auto,Dark,Light") EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/theme/icon_and_font_color", 0, "Auto,Dark,Light")
EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/base_color", Color(0.2, 0.23, 0.31), "") EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/base_color", Color(0.2, 0.23, 0.31), "")
EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/accent_color", Color(0.41, 0.61, 0.91), "") EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/accent_color", Color(0.41, 0.61, 0.91), "")
EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/theme/use_system_accent_color", false, "")
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/contrast", 0.3, "-1,1,0.01") EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/contrast", 0.3, "-1,1,0.01")
EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/theme/draw_extra_borders", false, "") EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/theme/draw_extra_borders", false, "")
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/icon_saturation", 1.0, "0,2,0.01") EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/icon_saturation", 1.0, "0,2,0.01")

View File

@ -252,6 +252,29 @@ EditorThemeManager::ThemeConfiguration EditorThemeManager::_create_theme_config(
// Handle main theme preset. // Handle main theme preset.
{ {
const bool follow_system_theme = EDITOR_GET("interface/theme/follow_system_theme");
const bool use_system_accent_color = EDITOR_GET("interface/theme/use_system_accent_color");
DisplayServer *display_server = DisplayServer::get_singleton();
Color system_base_color = display_server->get_base_color();
Color system_accent_color = display_server->get_accent_color();
if (follow_system_theme) {
String dark_theme = "Default";
String light_theme = "Light";
config.preset = light_theme; // Assume light theme if we can't detect system theme attributes.
if (system_base_color == Color(0, 0, 0, 0)) {
if (display_server->is_dark_mode_supported() && display_server->is_dark_mode()) {
config.preset = dark_theme;
}
} else {
if (system_base_color.get_luminance() < 0.5) {
config.preset = dark_theme;
}
}
}
if (config.preset != "Custom") { if (config.preset != "Custom") {
Color preset_accent_color; Color preset_accent_color;
Color preset_base_color; Color preset_base_color;
@ -308,6 +331,16 @@ EditorThemeManager::ThemeConfiguration EditorThemeManager::_create_theme_config(
EditorSettings::get_singleton()->set_initial_value("interface/theme/draw_extra_borders", config.draw_extra_borders); EditorSettings::get_singleton()->set_initial_value("interface/theme/draw_extra_borders", config.draw_extra_borders);
} }
if (follow_system_theme && system_base_color != Color(0, 0, 0, 0)) {
config.base_color = system_base_color;
config.preset = "Custom";
}
if (use_system_accent_color && system_accent_color != Color(0, 0, 0, 0)) {
config.accent_color = system_accent_color;
config.preset = "Custom";
}
// Enforce values in case they were adjusted or overridden. // Enforce values in case they were adjusted or overridden.
EditorSettings::get_singleton()->set_manually("interface/theme/preset", config.preset); EditorSettings::get_singleton()->set_manually("interface/theme/preset", config.preset);
EditorSettings::get_singleton()->set_manually("interface/theme/accent_color", config.accent_color); EditorSettings::get_singleton()->set_manually("interface/theme/accent_color", config.accent_color);