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

[DisplayServer] Add error messages and descriptions to callbacks. #89033

Merged
merged 1 commit into from
May 28, 2024
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
7 changes: 4 additions & 3 deletions doc/classes/DisplayServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<param index="2" name="callback" type="Callable" />
<description>
Creates a new application status indicator with the specified icon, tooltip, and activation callback.
[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]).
</description>
</method>
<method name="cursor_get_shape" qualifiers="const">
Expand Down Expand Up @@ -875,7 +876,7 @@
<param index="1" name="open_callback" type="Callable" />
<param index="2" name="close_callback" type="Callable" />
<description>
Registers callables to emit when the menu is respectively about to show or closed.
Registers callables to emit when the menu is respectively about to show or closed. Callback methods should have zero arguments.
</description>
</method>
<method name="has_feature" qualifiers="const">
Expand Down Expand Up @@ -1187,7 +1188,7 @@
<param index="0" name="id" type="int" />
<param index="1" name="callback" type="Callable" />
<description>
Sets the application status indicator activation callback.
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.
[b]Note:[/b] This method is implemented on macOS and Windows.
</description>
</method>
Expand Down Expand Up @@ -1568,7 +1569,7 @@
<param index="0" name="callback" type="Callable" />
<param index="1" name="window_id" type="int" default="0" />
<description>
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].
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.
[b]Warning:[/b] Advanced users only! Adding such a callback to a [Window] node will override its default implementation, which can introduce bugs.
[b]Note:[/b] This method is implemented on Windows, macOS, Linux (X11/Wayland), and Web.
</description>
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ void EditorNode::_notification(int p_what) {

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

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

/* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */
} break;
Expand Down
7 changes: 6 additions & 1 deletion platform/ios/display_server_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,12 @@

void DisplayServerIOS::emit_system_theme_changed() {
if (system_theme_changed.is_valid()) {
system_theme_changed.call();
Variant ret;
Callable::CallError ce;
system_theme_changed.callp(nullptr, 0, ret, ce);
if (ce.error != Callable::CallError::CALL_OK) {
ERR_PRINT(vformat("Failed to execute system theme changed callback: %s.", Variant::get_callable_error_text(system_theme_changed, nullptr, 0, ce)));
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion platform/linuxbsd/freedesktop_portal_desktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,12 @@ void FreeDesktopPortalDesktop::_thread_monitor(void *p_ud) {

void FreeDesktopPortalDesktop::_system_theme_changed_callback() {
if (system_theme_changed.is_valid()) {
system_theme_changed.call();
Variant ret;
Callable::CallError ce;
system_theme_changed.callp(nullptr, 0, ret, ce);
if (ce.error != Callable::CallError::CALL_OK) {
ERR_PRINT(vformat("Failed to execute system theme changed callback: %s.", Variant::get_callable_error_text(system_theme_changed, nullptr, 0, ce)));
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion platform/linuxbsd/wayland/display_server_wayland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,14 @@ void DisplayServerWayland::process_events() {
WindowData wd = main_window;

if (wd.drop_files_callback.is_valid()) {
wd.drop_files_callback.call(dropfiles_msg->files);
Variant v_files = dropfiles_msg->files;
const Variant *v_args[1] = { &v_files };
Variant ret;
Callable::CallError ce;
wd.drop_files_callback.callp((const Variant **)&v_args, 1, ret, ce);
if (ce.error != Callable::CallError::CALL_OK) {
ERR_PRINT(vformat("Failed to execute drop files callback: %s.", Variant::get_callable_error_text(wd.drop_files_callback, v_args, 1, ce)));
}
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion platform/linuxbsd/x11/display_server_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5008,7 +5008,14 @@ void DisplayServerX11::process_events() {
}

if (windows[window_id].drop_files_callback.is_valid()) {
windows[window_id].drop_files_callback.call(files);
Variant v_files = files;
const Variant *v_args[1] = { &v_files };
Variant ret;
Callable::CallError ce;
windows[window_id].drop_files_callback.callp((const Variant **)&v_args, 1, ret, ce);
if (ce.error != Callable::CallError::CALL_OK) {
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)));
}
}

//Reply that all is well.
Expand Down
7 changes: 6 additions & 1 deletion platform/macos/display_server_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,12 @@

void DisplayServerMacOS::emit_system_theme_changed() {
if (system_theme_changed.is_valid()) {
system_theme_changed.call();
Variant ret;
Callable::CallError ce;
system_theme_changed.callp(nullptr, 0, ret, ce);
if (ce.error != Callable::CallError::CALL_OK) {
ERR_PRINT(vformat("Failed to execute system theme changed callback: %s.", Variant::get_callable_error_text(system_theme_changed, nullptr, 0, ce)));
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion platform/macos/godot_content_view.mm
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,14 @@ - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
NSString *file = [NSURL URLWithString:url].path;
files.push_back(String::utf8([file UTF8String]));
}
wd.drop_files_callback.call(files);
Variant v_files = files;
const Variant *v_args[1] = { &v_files };
Variant ret;
Callable::CallError ce;
wd.drop_files_callback.callp((const Variant **)&v_args, 1, ret, ce);
if (ce.error != Callable::CallError::CALL_OK) {
ERR_PRINT(vformat("Failed to execute drop files callback: %s.", Variant::get_callable_error_text(wd.drop_files_callback, v_args, 1, ce)));
}
}

return NO;
Expand Down
5 changes: 4 additions & 1 deletion platform/macos/godot_status_item.mm
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ - (IBAction)click:(id)sender {
if (cb.is_valid()) {
Variant v_button = index;
Variant v_pos = ds->mouse_get_position();
Variant *v_args[2] = { &v_button, &v_pos };
const Variant *v_args[2] = { &v_button, &v_pos };
Variant ret;
Callable::CallError ce;
cb.callp((const Variant **)&v_args, 2, ret, ce);
if (ce.error != Callable::CallError::CALL_OK) {
ERR_PRINT(vformat("Failed to execute status indicator callback: %s.", Variant::get_callable_error_text(cb, v_args, 2, ce)));
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion platform/web/display_server_web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,14 @@ void DisplayServerWeb::_drop_files_js_callback(const Vector<String> &p_files) {
if (!ds->drop_files_callback.is_valid()) {
return;
}
ds->drop_files_callback.call(p_files);
Variant v_files = p_files;
const Variant *v_args[1] = { &v_files };
Variant ret;
Callable::CallError ce;
ds->drop_files_callback.callp((const Variant **)&v_args, 1, ret, ce);
if (ce.error != Callable::CallError::CALL_OK) {
ERR_PRINT(vformat("Failed to execute drop files callback: %s.", Variant::get_callable_error_text(ds->drop_files_callback, v_args, 1, ce)));
}
}

// Web quit request callback.
Expand Down
21 changes: 18 additions & 3 deletions platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3842,7 +3842,12 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
}
}
if (system_theme_changed.is_valid()) {
system_theme_changed.call();
Variant ret;
Callable::CallError ce;
system_theme_changed.callp(nullptr, 0, ret, ce);
if (ce.error != Callable::CallError::CALL_OK) {
ERR_PRINT(vformat("Failed to execute system theme changed callback: %s.", Variant::get_callable_error_text(system_theme_changed, nullptr, 0, ce)));
}
}
} break;
case WM_THEMECHANGED: {
Expand Down Expand Up @@ -3897,10 +3902,13 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
} else if (indicators[iid].callback.is_valid()) {
Variant v_button = mb;
Variant v_pos = mouse_get_position();
Variant *v_args[2] = { &v_button, &v_pos };
const Variant *v_args[2] = { &v_button, &v_pos };
Variant ret;
Callable::CallError ce;
indicators[iid].callback.callp((const Variant **)&v_args, 2, ret, ce);
if (ce.error != Callable::CallError::CALL_OK) {
ERR_PRINT(vformat("Failed to execute status indicator callback: %s.", Variant::get_callable_error_text(indicators[iid].callback, v_args, 2, ce)));
}
}
}
return 0;
Expand Down Expand Up @@ -4868,7 +4876,14 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
}

if (files.size() && windows[window_id].drop_files_callback.is_valid()) {
windows[window_id].drop_files_callback.call(files);
Variant v_files = files;
const Variant *v_args[1] = { &v_files };
Variant ret;
Callable::CallError ce;
windows[window_id].drop_files_callback.callp((const Variant **)&v_args, 1, ret, ce);
if (ce.error != Callable::CallError::CALL_OK) {
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)));
}
}
} break;
default: {
Expand Down
Loading