summaryrefslogtreecommitdiffstats
path: root/platform/macos
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2024-05-27 10:52:59 +0300
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2024-05-31 15:50:14 +0300
commit5168647530141bb08a75fb6bddc702295c45a052 (patch)
treedf911c560456315136254f85ad9eb1a9f585cef3 /platform/macos
parent705b7a0b0bd535c95e4e8fb439f3d84b3fb4f427 (diff)
downloadredot-engine-5168647530141bb08a75fb6bddc702295c45a052.tar.gz
Use current mouse button state instead of saved values.
Diffstat (limited to 'platform/macos')
-rw-r--r--platform/macos/display_server_macos.h2
-rw-r--r--platform/macos/display_server_macos.mm22
-rw-r--r--platform/macos/godot_content_view.mm24
3 files changed, 24 insertions, 24 deletions
diff --git a/platform/macos/display_server_macos.h b/platform/macos/display_server_macos.h
index 608c34edc6..b4741dc08f 100644
--- a/platform/macos/display_server_macos.h
+++ b/platform/macos/display_server_macos.h
@@ -164,7 +164,6 @@ private:
CGEventSourceRef event_source;
MouseMode mouse_mode = MOUSE_MODE_VISIBLE;
- BitField<MouseButtonMask> last_button_state;
bool drop_events = false;
bool in_dispatch_input_event = false;
@@ -302,7 +301,6 @@ public:
bool update_mouse_wrap(WindowData &p_wd, NSPoint &r_delta, NSPoint &r_mpos, NSTimeInterval p_timestamp);
virtual void warp_mouse(const Point2i &p_position) override;
virtual Point2i mouse_get_position() const override;
- void mouse_set_button_state(BitField<MouseButtonMask> p_state);
virtual BitField<MouseButtonMask> mouse_get_button_state() const override;
virtual void clipboard_set(const String &p_text) override;
diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm
index 0ccce1ad6a..50313cfe67 100644
--- a/platform/macos/display_server_macos.mm
+++ b/platform/macos/display_server_macos.mm
@@ -1421,11 +1421,25 @@ Point2i DisplayServerMacOS::mouse_get_position() const {
return Vector2i();
}
-void DisplayServerMacOS::mouse_set_button_state(BitField<MouseButtonMask> p_state) {
- last_button_state = p_state;
-}
-
BitField<MouseButtonMask> DisplayServerMacOS::mouse_get_button_state() const {
+ BitField<MouseButtonMask> last_button_state = 0;
+
+ NSUInteger buttons = [NSEvent pressedMouseButtons];
+ if (buttons & (1 << 0)) {
+ last_button_state.set_flag(MouseButtonMask::LEFT);
+ }
+ if (buttons & (1 << 1)) {
+ last_button_state.set_flag(MouseButtonMask::RIGHT);
+ }
+ if (buttons & (1 << 2)) {
+ last_button_state.set_flag(MouseButtonMask::MIDDLE);
+ }
+ if (buttons & (1 << 3)) {
+ last_button_state.set_flag(MouseButtonMask::MB_XBUTTON1);
+ }
+ if (buttons & (1 << 4)) {
+ last_button_state.set_flag(MouseButtonMask::MB_XBUTTON2);
+ }
return last_button_state;
}
diff --git a/platform/macos/godot_content_view.mm b/platform/macos/godot_content_view.mm
index 7dcb1ac9db..77f3a28ae7 100644
--- a/platform/macos/godot_content_view.mm
+++ b/platform/macos/godot_content_view.mm
@@ -370,16 +370,6 @@
}
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
- BitField<MouseButtonMask> last_button_state = ds->mouse_get_button_state();
-
- MouseButtonMask mask = mouse_button_to_mask(index);
-
- if (pressed) {
- last_button_state.set_flag(mask);
- } else {
- last_button_state.clear_flag(mask);
- }
- ds->mouse_set_button_state(last_button_state);
Ref<InputEventMouseButton> mb;
mb.instantiate();
@@ -394,7 +384,7 @@
mb->set_pressed(pressed);
mb->set_position(wd.mouse_pos);
mb->set_global_position(wd.mouse_pos);
- mb->set_button_mask(last_button_state);
+ mb->set_button_mask(ds->mouse_get_button_state());
if (!outofstream && index == MouseButton::LEFT && pressed) {
mb->set_double_click([event clickCount] == 2);
}
@@ -745,7 +735,6 @@
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
MouseButtonMask mask = mouse_button_to_mask(button);
- BitField<MouseButtonMask> last_button_state = ds->mouse_get_button_state();
Ref<InputEventMouseButton> sc;
sc.instantiate();
@@ -757,9 +746,9 @@
sc->set_pressed(true);
sc->set_position(wd.mouse_pos);
sc->set_global_position(wd.mouse_pos);
- last_button_state.set_flag(mask);
- sc->set_button_mask(last_button_state);
- ds->mouse_set_button_state(last_button_state);
+ BitField<MouseButtonMask> scroll_mask = ds->mouse_get_button_state();
+ scroll_mask.set_flag(mask);
+ sc->set_button_mask(scroll_mask);
Input::get_singleton()->parse_input_event(sc);
@@ -770,9 +759,8 @@
sc->set_pressed(false);
sc->set_position(wd.mouse_pos);
sc->set_global_position(wd.mouse_pos);
- last_button_state.clear_flag(mask);
- sc->set_button_mask(last_button_state);
- ds->mouse_set_button_state(last_button_state);
+ scroll_mask.clear_flag(mask);
+ sc->set_button_mask(scroll_mask);
Input::get_singleton()->parse_input_event(sc);
}