Remove mouse events that closed the popup from queue, to fix pop-up reopening.

This commit is contained in:
bruvzg 2022-05-30 11:06:08 +03:00
parent 6cd730ea98
commit 40b3be7912
No known key found for this signature in database
GPG key ID: 7960FCF39844EC38
6 changed files with 25 additions and 11 deletions

View file

@ -3298,19 +3298,20 @@ void DisplayServerX11::popup_close(WindowID p_window) {
} }
} }
void DisplayServerX11::mouse_process_popups() { bool DisplayServerX11::mouse_process_popups() {
_THREAD_SAFE_METHOD_ _THREAD_SAFE_METHOD_
if (popup_list.is_empty()) { if (popup_list.is_empty()) {
return; return false;
} }
uint64_t delta = OS::get_singleton()->get_ticks_msec() - time_since_popup; uint64_t delta = OS::get_singleton()->get_ticks_msec() - time_since_popup;
if (delta < 250) { if (delta < 250) {
return; return false;
} }
int number_of_screens = XScreenCount(x11_display); int number_of_screens = XScreenCount(x11_display);
bool closed = false;
for (int i = 0; i < number_of_screens; i++) { for (int i = 0; i < number_of_screens; i++) {
Window root, child; Window root, child;
int root_x, root_y, win_x, win_y; int root_x, root_y, win_x, win_y;
@ -3340,6 +3341,7 @@ void DisplayServerX11::mouse_process_popups() {
} }
if (C) { if (C) {
_send_window_event(windows[C->get()], DisplayServerX11::WINDOW_EVENT_CLOSE_REQUEST); _send_window_event(windows[C->get()], DisplayServerX11::WINDOW_EVENT_CLOSE_REQUEST);
closed = true;
} }
} }
} }
@ -3347,6 +3349,7 @@ void DisplayServerX11::mouse_process_popups() {
last_mouse_monitor_pos = pos; last_mouse_monitor_pos = pos;
} }
} }
return closed;
} }
void DisplayServerX11::process_events() { void DisplayServerX11::process_events() {
@ -3357,7 +3360,7 @@ void DisplayServerX11::process_events() {
++frame; ++frame;
#endif #endif
mouse_process_popups(); bool ignore_events = mouse_process_popups();
if (app_focused) { if (app_focused) {
//verify that one of the windows has focus, else send focus out notification //verify that one of the windows has focus, else send focus out notification
@ -3407,6 +3410,10 @@ void DisplayServerX11::process_events() {
for (uint32_t event_index = 0; event_index < events.size(); ++event_index) { for (uint32_t event_index = 0; event_index < events.size(); ++event_index) {
XEvent &event = events[event_index]; XEvent &event = events[event_index];
if (ignore_events) {
XFreeEventData(x11_display, &event.xcookie);
continue;
}
WindowID window_id = MAIN_WINDOW_ID; WindowID window_id = MAIN_WINDOW_ID;

View file

@ -295,7 +295,7 @@ protected:
void _window_changed(XEvent *event); void _window_changed(XEvent *event);
public: public:
void mouse_process_popups(); bool mouse_process_popups();
void popup_open(WindowID p_window); void popup_open(WindowID p_window);
void popup_close(WindowID p_window); void popup_close(WindowID p_window);

View file

@ -208,7 +208,7 @@ public:
void push_to_key_event_buffer(const KeyEvent &p_event); void push_to_key_event_buffer(const KeyEvent &p_event);
void update_im_text(const Point2i &p_selection, const String &p_text); void update_im_text(const Point2i &p_selection, const String &p_text);
void set_last_focused_window(WindowID p_window); void set_last_focused_window(WindowID p_window);
void mouse_process_popups(bool p_close = false); bool mouse_process_popups(bool p_close = false);
void popup_open(WindowID p_window); void popup_open(WindowID p_window);
void popup_close(WindowID p_window); void popup_close(WindowID p_window);
void set_is_resizing(bool p_is_resizing); void set_is_resizing(bool p_is_resizing);

View file

@ -569,9 +569,6 @@ DisplayServerOSX::WindowData &DisplayServerOSX::get_window(WindowID p_window) {
} }
void DisplayServerOSX::send_event(NSEvent *p_event) { void DisplayServerOSX::send_event(NSEvent *p_event) {
if ([p_event type] == NSEventTypeLeftMouseDown || [p_event type] == NSEventTypeRightMouseDown || [p_event type] == NSEventTypeOtherMouseDown) {
mouse_process_popups();
}
// Special case handling of command-period, which is traditionally a special // Special case handling of command-period, which is traditionally a special
// shortcut in macOS and doesn't arrive at our regular keyDown handler. // shortcut in macOS and doesn't arrive at our regular keyDown handler.
if ([p_event type] == NSEventTypeKeyDown) { if ([p_event type] == NSEventTypeKeyDown) {
@ -3085,15 +3082,17 @@ void DisplayServerOSX::popup_close(WindowID p_window) {
} }
} }
void DisplayServerOSX::mouse_process_popups(bool p_close) { bool DisplayServerOSX::mouse_process_popups(bool p_close) {
_THREAD_SAFE_METHOD_ _THREAD_SAFE_METHOD_
bool was_empty = popup_list.is_empty(); bool was_empty = popup_list.is_empty();
bool closed = false;
if (p_close) { if (p_close) {
// Close all popups. // Close all popups.
List<WindowID>::Element *E = popup_list.front(); List<WindowID>::Element *E = popup_list.front();
if (E) { if (E) {
send_window_event(windows[E->get()], DisplayServerOSX::WINDOW_EVENT_CLOSE_REQUEST); send_window_event(windows[E->get()], DisplayServerOSX::WINDOW_EVENT_CLOSE_REQUEST);
closed = true;
} }
if (!was_empty) { if (!was_empty) {
// Inform OS that all popups are closed. // Inform OS that all popups are closed.
@ -3102,7 +3101,7 @@ void DisplayServerOSX::mouse_process_popups(bool p_close) {
} else { } else {
uint64_t delta = OS::get_singleton()->get_ticks_msec() - time_since_popup; uint64_t delta = OS::get_singleton()->get_ticks_msec() - time_since_popup;
if (delta < 250) { if (delta < 250) {
return; return false;
} }
Point2i pos = mouse_get_position(); Point2i pos = mouse_get_position();
@ -3125,12 +3124,14 @@ void DisplayServerOSX::mouse_process_popups(bool p_close) {
} }
if (C) { if (C) {
send_window_event(windows[C->get()], DisplayServerOSX::WINDOW_EVENT_CLOSE_REQUEST); send_window_event(windows[C->get()], DisplayServerOSX::WINDOW_EVENT_CLOSE_REQUEST);
closed = true;
} }
if (!was_empty && popup_list.is_empty()) { if (!was_empty && popup_list.is_empty()) {
// Inform OS that all popups are closed. // Inform OS that all popups are closed.
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"com.apple.HIToolbox.endMenuTrackingNotification" object:@"org.godotengine.godot.popup_window"]; [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"com.apple.HIToolbox.endMenuTrackingNotification" object:@"org.godotengine.godot.popup_window"];
} }
} }
return closed;
} }
DisplayServerOSX::DisplayServerOSX(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { DisplayServerOSX::DisplayServerOSX(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) {

View file

@ -37,6 +37,11 @@
- (void)sendEvent:(NSEvent *)event { - (void)sendEvent:(NSEvent *)event {
DisplayServerOSX *ds = (DisplayServerOSX *)DisplayServer::get_singleton(); DisplayServerOSX *ds = (DisplayServerOSX *)DisplayServer::get_singleton();
if (ds) { if (ds) {
if ([event type] == NSEventTypeLeftMouseDown || [event type] == NSEventTypeRightMouseDown || [event type] == NSEventTypeOtherMouseDown) {
if (ds->mouse_process_popups()) {
return;
}
}
ds->send_event(event); ds->send_event(event);
} }

View file

@ -2199,6 +2199,7 @@ LRESULT DisplayServerWindows::MouseProc(int code, WPARAM wParam, LPARAM lParam)
} }
if (C) { if (C) {
_send_window_event(windows[C->get()], DisplayServerWindows::WINDOW_EVENT_CLOSE_REQUEST); _send_window_event(windows[C->get()], DisplayServerWindows::WINDOW_EVENT_CLOSE_REQUEST);
return 1;
} }
} break; } break;
} }