Skip to content

Commit c98fef0

Browse files
committed
Merge pull request godotengine#89033 from bruvzg/doc_end_err
[DisplayServer] Add error messages and descriptions to callbacks.
2 parents bc46623 + 714effd commit c98fef0

File tree

11 files changed

+77
-15
lines changed

11 files changed

+77
-15
lines changed

doc/classes/DisplayServer.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<param index="2" name="callback" type="Callable" />
6464
<description>
6565
Creates a new application status indicator with the specified icon, tooltip, and activation callback.
66+
[param callback] should take two arguments: the pressed mouse button (one of the [enum MouseButton] constants) and the click position in screen coordinates (a [Vector2i]).
6667
</description>
6768
</method>
6869
<method name="cursor_get_shape" qualifiers="const">
@@ -875,7 +876,7 @@
875876
<param index="1" name="open_callback" type="Callable" />
876877
<param index="2" name="close_callback" type="Callable" />
877878
<description>
878-
Registers callables to emit when the menu is respectively about to show or closed.
879+
Registers callables to emit when the menu is respectively about to show or closed. Callback methods should have zero arguments.
879880
</description>
880881
</method>
881882
<method name="has_feature" qualifiers="const">
@@ -1187,7 +1188,7 @@
11871188
<param index="0" name="id" type="int" />
11881189
<param index="1" name="callback" type="Callable" />
11891190
<description>
1190-
Sets the application status indicator activation callback.
1191+
Sets the application status indicator activation callback. [param callback] should take two arguments: [int] mouse button index (one of [enum MouseButton] values) and [Vector2i] click position in screen coordinates.
11911192
[b]Note:[/b] This method is implemented on macOS and Windows.
11921193
</description>
11931194
</method>
@@ -1568,7 +1569,7 @@
15681569
<param index="0" name="callback" type="Callable" />
15691570
<param index="1" name="window_id" type="int" default="0" />
15701571
<description>
1571-
Sets the [param callback] that should be called when files are dropped from the operating system's file manager to the window specified by [param window_id].
1572+
Sets the [param callback] that should be called when files are dropped from the operating system's file manager to the window specified by [param window_id]. [param callback] should take one [PackedStringArray] argument, which is the list of dropped files.
15721573
[b]Warning:[/b] Advanced users only! Adding such a callback to a [Window] node will override its default implementation, which can introduce bugs.
15731574
[b]Note:[/b] This method is implemented on Windows, macOS, Linux (X11/Wayland), and Web.
15741575
</description>

editor/editor_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ void EditorNode::_notification(int p_what) {
671671

672672
callable_mp(this, &EditorNode::_begin_first_scan).call_deferred();
673673

674-
DisplayServer::get_singleton()->set_system_theme_change_callback(callable_mp(this, &EditorNode::_update_theme));
674+
DisplayServer::get_singleton()->set_system_theme_change_callback(callable_mp(this, &EditorNode::_update_theme).bind(false));
675675

676676
/* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */
677677
} break;

platform/ios/display_server_ios.mm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,12 @@
399399

400400
void DisplayServerIOS::emit_system_theme_changed() {
401401
if (system_theme_changed.is_valid()) {
402-
system_theme_changed.call();
402+
Variant ret;
403+
Callable::CallError ce;
404+
system_theme_changed.callp(nullptr, 0, ret, ce);
405+
if (ce.error != Callable::CallError::CALL_OK) {
406+
ERR_PRINT(vformat("Failed to execute system theme changed callback: %s.", Variant::get_callable_error_text(system_theme_changed, nullptr, 0, ce)));
407+
}
403408
}
404409
}
405410

platform/linuxbsd/freedesktop_portal_desktop.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,12 @@ void FreeDesktopPortalDesktop::_thread_monitor(void *p_ud) {
597597

598598
void FreeDesktopPortalDesktop::_system_theme_changed_callback() {
599599
if (system_theme_changed.is_valid()) {
600-
system_theme_changed.call();
600+
Variant ret;
601+
Callable::CallError ce;
602+
system_theme_changed.callp(nullptr, 0, ret, ce);
603+
if (ce.error != Callable::CallError::CALL_OK) {
604+
ERR_PRINT(vformat("Failed to execute system theme changed callback: %s.", Variant::get_callable_error_text(system_theme_changed, nullptr, 0, ce)));
605+
}
601606
}
602607
}
603608

platform/linuxbsd/wayland/display_server_wayland.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,14 @@ void DisplayServerWayland::process_events() {
11371137
WindowData wd = main_window;
11381138

11391139
if (wd.drop_files_callback.is_valid()) {
1140-
wd.drop_files_callback.call(dropfiles_msg->files);
1140+
Variant v_files = dropfiles_msg->files;
1141+
const Variant *v_args[1] = { &v_files };
1142+
Variant ret;
1143+
Callable::CallError ce;
1144+
wd.drop_files_callback.callp((const Variant **)&v_args, 1, ret, ce);
1145+
if (ce.error != Callable::CallError::CALL_OK) {
1146+
ERR_PRINT(vformat("Failed to execute drop files callback: %s.", Variant::get_callable_error_text(wd.drop_files_callback, v_args, 1, ce)));
1147+
}
11411148
}
11421149
}
11431150
}

platform/linuxbsd/x11/display_server_x11.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5011,7 +5011,14 @@ void DisplayServerX11::process_events() {
50115011
}
50125012

50135013
if (windows[window_id].drop_files_callback.is_valid()) {
5014-
windows[window_id].drop_files_callback.call(files);
5014+
Variant v_files = files;
5015+
const Variant *v_args[1] = { &v_files };
5016+
Variant ret;
5017+
Callable::CallError ce;
5018+
windows[window_id].drop_files_callback.callp((const Variant **)&v_args, 1, ret, ce);
5019+
if (ce.error != Callable::CallError::CALL_OK) {
5020+
ERR_PRINT(vformat("Failed to execute drop files callback: %s.", Variant::get_callable_error_text(windows[window_id].drop_files_callback, v_args, 1, ce)));
5021+
}
50155022
}
50165023

50175024
//Reply that all is well.

platform/macos/display_server_macos.mm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,12 @@
907907

908908
void DisplayServerMacOS::emit_system_theme_changed() {
909909
if (system_theme_changed.is_valid()) {
910-
system_theme_changed.call();
910+
Variant ret;
911+
Callable::CallError ce;
912+
system_theme_changed.callp(nullptr, 0, ret, ce);
913+
if (ce.error != Callable::CallError::CALL_OK) {
914+
ERR_PRINT(vformat("Failed to execute system theme changed callback: %s.", Variant::get_callable_error_text(system_theme_changed, nullptr, 0, ce)));
915+
}
911916
}
912917
}
913918

platform/macos/godot_content_view.mm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,14 @@ - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
323323
NSString *file = [NSURL URLWithString:url].path;
324324
files.push_back(String::utf8([file UTF8String]));
325325
}
326-
wd.drop_files_callback.call(files);
326+
Variant v_files = files;
327+
const Variant *v_args[1] = { &v_files };
328+
Variant ret;
329+
Callable::CallError ce;
330+
wd.drop_files_callback.callp((const Variant **)&v_args, 1, ret, ce);
331+
if (ce.error != Callable::CallError::CALL_OK) {
332+
ERR_PRINT(vformat("Failed to execute drop files callback: %s.", Variant::get_callable_error_text(wd.drop_files_callback, v_args, 1, ce)));
333+
}
327334
}
328335

329336
return NO;

platform/macos/godot_status_item.mm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ - (IBAction)click:(id)sender {
6666
if (cb.is_valid()) {
6767
Variant v_button = index;
6868
Variant v_pos = ds->mouse_get_position();
69-
Variant *v_args[2] = { &v_button, &v_pos };
69+
const Variant *v_args[2] = { &v_button, &v_pos };
7070
Variant ret;
7171
Callable::CallError ce;
7272
cb.callp((const Variant **)&v_args, 2, ret, ce);
73+
if (ce.error != Callable::CallError::CALL_OK) {
74+
ERR_PRINT(vformat("Failed to execute status indicator callback: %s.", Variant::get_callable_error_text(cb, v_args, 2, ce)));
75+
}
7376
}
7477
}
7578

platform/web/display_server_web.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,14 @@ void DisplayServerWeb::_drop_files_js_callback(const Vector<String> &p_files) {
112112
if (!ds->drop_files_callback.is_valid()) {
113113
return;
114114
}
115-
ds->drop_files_callback.call(p_files);
115+
Variant v_files = p_files;
116+
const Variant *v_args[1] = { &v_files };
117+
Variant ret;
118+
Callable::CallError ce;
119+
ds->drop_files_callback.callp((const Variant **)&v_args, 1, ret, ce);
120+
if (ce.error != Callable::CallError::CALL_OK) {
121+
ERR_PRINT(vformat("Failed to execute drop files callback: %s.", Variant::get_callable_error_text(ds->drop_files_callback, v_args, 1, ce)));
122+
}
116123
}
117124

118125
// Web quit request callback.

0 commit comments

Comments
 (0)