Skip to content

Commit 3b813d0

Browse files
committed
[macOS] Fix warp_mouse in game mode.
1 parent a3b42d8 commit 3b813d0

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

platform/macos/display_server_embedded.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class DisplayServerEmbedded : public DisplayServerMacOSBase {
140140
virtual void mouse_set_mode_override_enabled(bool p_override_enabled) override;
141141
virtual bool mouse_is_mode_override_enabled() const override;
142142

143+
virtual void warp_mouse(const Point2i &p_position) override;
143144
virtual Point2i mouse_get_position() const override;
144145
virtual BitField<MouseButtonMask> mouse_get_button_state() const override;
145146

platform/macos/display_server_embedded.mm

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@
320320
return mouse_mode_override_enabled;
321321
}
322322

323+
void DisplayServerEmbedded::warp_mouse(const Point2i &p_position) {
324+
_THREAD_SAFE_METHOD_
325+
EngineDebugger::get_singleton()->send_message("game_view:warp_mouse", { p_position });
326+
}
327+
323328
Point2i DisplayServerEmbedded::mouse_get_position() const {
324329
_THREAD_SAFE_METHOD_
325330

@@ -470,19 +475,19 @@
470475
#endif
471476
case FEATURE_CURSOR_SHAPE:
472477
case FEATURE_IME:
473-
// case FEATURE_CUSTOM_CURSOR_SHAPE:
478+
case FEATURE_CUSTOM_CURSOR_SHAPE:
474479
// case FEATURE_HIDPI:
475480
// case FEATURE_ICON:
476-
// case FEATURE_MOUSE:
477-
// case FEATURE_MOUSE_WARP:
481+
case FEATURE_MOUSE:
482+
case FEATURE_MOUSE_WARP:
478483
// case FEATURE_NATIVE_DIALOG:
479484
// case FEATURE_NATIVE_ICON:
480485
// case FEATURE_WINDOW_TRANSPARENCY:
481-
// case FEATURE_CLIPBOARD:
486+
case FEATURE_CLIPBOARD:
482487
// case FEATURE_KEEP_SCREEN_ON:
483488
// case FEATURE_ORIENTATION:
484489
// case FEATURE_VIRTUAL_KEYBOARD:
485-
// case FEATURE_TEXT_TO_SPEECH:
490+
case FEATURE_TEXT_TO_SPEECH:
486491
// case FEATURE_TOUCHSCREEN:
487492
return true;
488493
default:

platform/macos/editor/embedded_game_view_plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class GameViewDebuggerMacOS : public GameViewDebugger {
5858
bool _msg_window_set_ime_position(const Array &p_args);
5959
bool _msg_joy_start(const Array &p_args);
6060
bool _msg_joy_stop(const Array &p_args);
61+
bool _msg_warp_mouse(const Array &p_args);
6162

6263
public:
6364
virtual bool capture(const String &p_message, const Array &p_data, int p_session) override;

platform/macos/editor/embedded_game_view_plugin.mm

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
HashMap<String, GameViewDebuggerMacOS::ParseMessageFunc> GameViewDebuggerMacOS::parse_message_handlers;
3939

4040
bool GameViewDebuggerMacOS::_msg_set_context_id(const Array &p_args) {
41-
ERR_FAIL_COND_V_MSG(p_args.size() != 1, false, "set_context_id: invalid number of arguments");
41+
ERR_FAIL_COND_V_MSG(p_args.size() != 1, false, "set_context_id: invalid number of arguments.");
4242

4343
embedded_process->set_context_id(p_args[0]);
4444
return true;
4545
}
4646

4747
bool GameViewDebuggerMacOS::_msg_cursor_set_shape(const Array &p_args) {
48-
ERR_FAIL_COND_V_MSG(p_args.size() != 1, false, "cursor_set_shape: invalid number of arguments");
48+
ERR_FAIL_COND_V_MSG(p_args.size() != 1, false, "cursor_set_shape: invalid number of arguments.");
4949

5050
Control::CursorShape shape = Control::CursorShape(p_args[0]);
5151
embedded_process->get_layer_host()->set_default_cursor_shape(static_cast<Control::CursorShape>(shape));
@@ -54,7 +54,7 @@
5454
}
5555

5656
bool GameViewDebuggerMacOS::_msg_cursor_set_custom_image(const Array &p_args) {
57-
ERR_FAIL_COND_V_MSG(p_args.size() != 3, false, "cursor_set_custom_image: invalid number of arguments");
57+
ERR_FAIL_COND_V_MSG(p_args.size() != 3, false, "cursor_set_custom_image: invalid number of arguments.");
5858

5959
Ref<Image> image;
6060
image.instantiate();
@@ -71,7 +71,7 @@
7171
}
7272

7373
bool GameViewDebuggerMacOS::_msg_mouse_set_mode(const Array &p_args) {
74-
ERR_FAIL_COND_V_MSG(p_args.size() != 1, false, "mouse_set_mode: invalid number of arguments");
74+
ERR_FAIL_COND_V_MSG(p_args.size() != 1, false, "mouse_set_mode: invalid number of arguments.");
7575

7676
DisplayServer::MouseMode mode = DisplayServer::MouseMode(p_args[0]);
7777
embedded_process->mouse_set_mode(mode);
@@ -80,7 +80,7 @@
8080
}
8181

8282
bool GameViewDebuggerMacOS::_msg_window_set_ime_active(const Array &p_args) {
83-
ERR_FAIL_COND_V_MSG(p_args.size() != 1, false, "window_set_ime_active: invalid number of arguments");
83+
ERR_FAIL_COND_V_MSG(p_args.size() != 1, false, "window_set_ime_active: invalid number of arguments.");
8484

8585
bool active = p_args[0];
8686
DisplayServer::WindowID wid = embedded_process->get_window()->get_window_id();
@@ -89,7 +89,7 @@
8989
}
9090

9191
bool GameViewDebuggerMacOS::_msg_window_set_ime_position(const Array &p_args) {
92-
ERR_FAIL_COND_V_MSG(p_args.size() != 1, false, "window_set_ime_position: invalid number of arguments");
92+
ERR_FAIL_COND_V_MSG(p_args.size() != 1, false, "window_set_ime_position: invalid number of arguments.");
9393

9494
Point2i pos = p_args[0];
9595
Point2i xpos = embedded_process->get_layer_host()->get_global_transform_with_canvas().xform(pos);
@@ -99,7 +99,7 @@
9999
}
100100

101101
bool GameViewDebuggerMacOS::_msg_joy_start(const Array &p_args) {
102-
ERR_FAIL_COND_V_MSG(p_args.size() != 3, false, "joy_start: invalid number of arguments");
102+
ERR_FAIL_COND_V_MSG(p_args.size() != 3, false, "joy_start: invalid number of arguments.");
103103

104104
int joy_id = p_args[0];
105105
float duration = p_args[1];
@@ -109,13 +109,21 @@
109109
}
110110

111111
bool GameViewDebuggerMacOS::_msg_joy_stop(const Array &p_args) {
112-
ERR_FAIL_COND_V_MSG(p_args.size() != 1, false, "joy_stop: invalid number of arguments");
112+
ERR_FAIL_COND_V_MSG(p_args.size() != 1, false, "joy_stop: invalid number of arguments.");
113113

114114
int joy_id = p_args[0];
115115
Input::get_singleton()->stop_joy_vibration(joy_id);
116116
return true;
117117
}
118118

119+
bool GameViewDebuggerMacOS::_msg_warp_mouse(const Array &p_args) {
120+
ERR_FAIL_COND_V_MSG(p_args.size() != 1, false, "warp_mouse: invalid number of arguments.");
121+
122+
Vector2i pos = p_args[0];
123+
embedded_process->get_layer_host()->warp_mouse(pos);
124+
return true;
125+
}
126+
119127
void GameViewDebuggerMacOS::_init_capture_message_handlers() {
120128
parse_message_handlers["game_view:set_context_id"] = &GameViewDebuggerMacOS::_msg_set_context_id;
121129
parse_message_handlers["game_view:cursor_set_shape"] = &GameViewDebuggerMacOS::_msg_cursor_set_shape;
@@ -125,6 +133,7 @@
125133
parse_message_handlers["game_view:window_set_ime_position"] = &GameViewDebuggerMacOS::_msg_window_set_ime_position;
126134
parse_message_handlers["game_view:joy_start"] = &GameViewDebuggerMacOS::_msg_joy_start;
127135
parse_message_handlers["game_view:joy_stop"] = &GameViewDebuggerMacOS::_msg_joy_stop;
136+
parse_message_handlers["game_view:warp_mouse"] = &GameViewDebuggerMacOS::_msg_warp_mouse;
128137
}
129138

130139
bool GameViewDebuggerMacOS::capture(const String &p_message, const Array &p_data, int p_session) {

0 commit comments

Comments
 (0)