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

Check if DisplayServer supports icons before attempting setting it #89181

Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions doc/classes/DisplayServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1148,13 +1148,15 @@
<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">
<return type="void" />
<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">
Expand Down
10 changes: 5 additions & 5 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -3802,22 +3802,22 @@ 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;
}
#endif

#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) {
Expand Down Expand Up @@ -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);
}
Expand Down
Loading