summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2024-03-01 09:52:21 +0200
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2024-05-28 17:36:54 +0300
commit714effdf077a5be8e4ed34d2d2455e5fb76fae56 (patch)
tree58df55f372d56db983d63943d0c41ebb149f9f2f
parentbe56cab58c056c074d1e02cd0b38641204e39f41 (diff)
downloadredot-engine-714effdf077a5be8e4ed34d2d2455e5fb76fae56.tar.gz
[DisplayServer] Add error messages and descriptions to callbacks.
-rw-r--r--doc/classes/DisplayServer.xml7
-rw-r--r--editor/editor_node.cpp2
-rw-r--r--platform/ios/display_server_ios.mm7
-rw-r--r--platform/linuxbsd/freedesktop_portal_desktop.cpp7
-rw-r--r--platform/linuxbsd/wayland/display_server_wayland.cpp9
-rw-r--r--platform/linuxbsd/x11/display_server_x11.cpp9
-rw-r--r--platform/macos/display_server_macos.mm7
-rw-r--r--platform/macos/godot_content_view.mm9
-rw-r--r--platform/macos/godot_status_item.mm5
-rw-r--r--platform/web/display_server_web.cpp9
-rw-r--r--platform/windows/display_server_windows.cpp21
11 files changed, 77 insertions, 15 deletions
diff --git a/doc/classes/DisplayServer.xml b/doc/classes/DisplayServer.xml
index e157cbb96c..ff1c390b3c 100644
--- a/doc/classes/DisplayServer.xml
+++ b/doc/classes/DisplayServer.xml
@@ -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">
@@ -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">
@@ -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>
@@ -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>
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 949916c2a3..7c312e266d 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -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;
diff --git a/platform/ios/display_server_ios.mm b/platform/ios/display_server_ios.mm
index 5d7af25f28..a454dd5ba0 100644
--- a/platform/ios/display_server_ios.mm
+++ b/platform/ios/display_server_ios.mm
@@ -399,7 +399,12 @@ void DisplayServerIOS::set_system_theme_change_callback(const Callable &p_callab
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)));
+ }
}
}
diff --git a/platform/linuxbsd/freedesktop_portal_desktop.cpp b/platform/linuxbsd/freedesktop_portal_desktop.cpp
index e65404a531..464c0e4286 100644
--- a/platform/linuxbsd/freedesktop_portal_desktop.cpp
+++ b/platform/linuxbsd/freedesktop_portal_desktop.cpp
@@ -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)));
+ }
}
}
diff --git a/platform/linuxbsd/wayland/display_server_wayland.cpp b/platform/linuxbsd/wayland/display_server_wayland.cpp
index ce8a53a856..5e34fc3b93 100644
--- a/platform/linuxbsd/wayland/display_server_wayland.cpp
+++ b/platform/linuxbsd/wayland/display_server_wayland.cpp
@@ -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)));
+ }
}
}
}
diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp
index 2c07acf94f..26655492e5 100644
--- a/platform/linuxbsd/x11/display_server_x11.cpp
+++ b/platform/linuxbsd/x11/display_server_x11.cpp
@@ -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.
diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm
index db71c48eff..7082af3166 100644
--- a/platform/macos/display_server_macos.mm
+++ b/platform/macos/display_server_macos.mm
@@ -907,7 +907,12 @@ void DisplayServerMacOS::set_system_theme_change_callback(const Callable &p_call
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)));
+ }
}
}
diff --git a/platform/macos/godot_content_view.mm b/platform/macos/godot_content_view.mm
index 68a7288ad4..7dcb1ac9db 100644
--- a/platform/macos/godot_content_view.mm
+++ b/platform/macos/godot_content_view.mm
@@ -323,7 +323,14 @@
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;
diff --git a/platform/macos/godot_status_item.mm b/platform/macos/godot_status_item.mm
index 0990a16b2b..1b16d496a2 100644
--- a/platform/macos/godot_status_item.mm
+++ b/platform/macos/godot_status_item.mm
@@ -66,10 +66,13 @@
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)));
+ }
}
}
diff --git a/platform/web/display_server_web.cpp b/platform/web/display_server_web.cpp
index 0420a01533..777980502a 100644
--- a/platform/web/display_server_web.cpp
+++ b/platform/web/display_server_web.cpp
@@ -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.
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp
index 03584977fe..04a7d7f4b8 100644
--- a/platform/windows/display_server_windows.cpp
+++ b/platform/windows/display_server_windows.cpp
@@ -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: {
@@ -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;
@@ -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: {