summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-03-05 16:54:47 +0100
committerRémi Verschelde <rverschelde@gmail.com>2024-03-05 16:54:47 +0100
commit39f90600bc553f2273e72708eb2a8d37a8517e86 (patch)
tree8e9827b4df7089c4d575f09d580a86155ea7b5ea
parentbee7e12c8c1997a3c432b6d97187cd3d2693b1b2 (diff)
parente63de52bdba895266726b988d8158cfb573bc8b8 (diff)
downloadredot-engine-39f90600bc553f2273e72708eb2a8d37a8517e86.tar.gz
Merge pull request #89181 from akien-mga/displayserver-check-support-before-setting-icon
Check if DisplayServer supports icons before attempting setting it
-rw-r--r--doc/classes/DisplayServer.xml2
-rw-r--r--main/main.cpp10
2 files changed, 7 insertions, 5 deletions
diff --git a/doc/classes/DisplayServer.xml b/doc/classes/DisplayServer.xml
index d3c76737db..5e8f5b540a 100644
--- a/doc/classes/DisplayServer.xml
+++ b/doc/classes/DisplayServer.xml
@@ -1148,6 +1148,7 @@
<param index="0" name="image" type="Image" />
<description>
Sets the window icon (usually displayed in the top-left corner) with an [Image]. To use icons in the operating system's native format, use [method set_native_icon] instead.
+ [b]Note:[/b] Requires support for [constant FEATURE_ICON].
</description>
</method>
<method name="set_native_icon">
@@ -1155,6 +1156,7 @@
<param index="0" name="filename" type="String" />
<description>
Sets the window icon (usually displayed in the top-left corner) in the operating system's [i]native[/i] format. The file at [param filename] must be in [code].ico[/code] format on Windows or [code].icns[/code] on macOS. By using specially crafted [code].ico[/code] or [code].icns[/code] icons, [method set_native_icon] allows specifying different icons depending on the size the icon is displayed at. This size is determined by the operating system and user preferences (including the display scale factor). To use icons in other formats, use [method set_icon] instead.
+ [b]Note:[/b] Requires support for [constant FEATURE_NATIVE_ICON].
</description>
</method>
<method name="set_system_theme_change_callback">
diff --git a/main/main.cpp b/main/main.cpp
index 91ccbe6766..ec66d47901 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -2885,7 +2885,7 @@ Error Main::setup2() {
}
#if defined(TOOLS_ENABLED) && defined(MACOS_ENABLED)
- if (OS::get_singleton()->get_bundle_icon_path().is_empty()) {
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_ICON) && OS::get_singleton()->get_bundle_icon_path().is_empty()) {
Ref<Image> icon = memnew(Image(app_icon_png));
DisplayServer::get_singleton()->set_icon(icon);
}
@@ -3802,7 +3802,7 @@ bool Main::start() {
#ifdef MACOS_ENABLED
String mac_icon_path = GLOBAL_GET("application/config/macos_native_icon");
- if (!mac_icon_path.is_empty()) {
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_ICON) && !mac_icon_path.is_empty()) {
DisplayServer::get_singleton()->set_native_icon(mac_icon_path);
has_icon = true;
}
@@ -3810,14 +3810,14 @@ bool Main::start() {
#ifdef WINDOWS_ENABLED
String win_icon_path = GLOBAL_GET("application/config/windows_native_icon");
- if (!win_icon_path.is_empty()) {
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_ICON) && !win_icon_path.is_empty()) {
DisplayServer::get_singleton()->set_native_icon(win_icon_path);
has_icon = true;
}
#endif
String icon_path = GLOBAL_GET("application/config/icon");
- if ((!icon_path.is_empty()) && (!has_icon)) {
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_ICON) && !icon_path.is_empty() && !has_icon) {
Ref<Image> icon;
icon.instantiate();
if (ImageLoader::load_image(icon_path, icon) == OK) {
@@ -3850,7 +3850,7 @@ bool Main::start() {
#endif
}
- if (!has_icon && OS::get_singleton()->get_bundle_icon_path().is_empty()) {
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_ICON) && !has_icon && OS::get_singleton()->get_bundle_icon_path().is_empty()) {
Ref<Image> icon = memnew(Image(app_icon_png));
DisplayServer::get_singleton()->set_icon(icon);
}