diff --git ui/gfx/x/connection.cc ui/gfx/x/connection.cc index 8c59d60a30148..6cc6326e65639 100644 --- ui/gfx/x/connection.cc +++ ui/gfx/x/connection.cc @@ -183,6 +183,7 @@ Connection::Connection(const std::string& address) Connection::~Connection() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + window_event_manager_.Reset(); platform_event_source.reset(); } diff --git ui/gfx/x/window_event_manager.cc ui/gfx/x/window_event_manager.cc index 7aee20ec3d2b7..9b5b320402ff8 100644 --- ui/gfx/x/window_event_manager.cc +++ ui/gfx/x/window_event_manager.cc @@ -113,10 +113,18 @@ WindowEventManager::WindowEventManager(Connection* connection) : connection_(connection) {} WindowEventManager::~WindowEventManager() { + Reset(); +} + +void WindowEventManager::Reset() { + if (!connection_) { + return; + } // Clear events still requested by not-yet-deleted ScopedEventSelectors. for (const auto& mask_pair : mask_map_) { SetEventMask(connection_, mask_pair.first, EventMask::NoEvent); } + connection_ = nullptr; } void WindowEventManager::SelectEvents(Window window, EventMask event_mask) { @@ -143,7 +151,9 @@ void WindowEventManager::AfterMaskChanged(Window window, EventMask old_mask) { return; } - SetEventMask(connection_, window, new_mask); + if (connection_) { + SetEventMask(connection_, window, new_mask); + } if (new_mask == EventMask::NoEvent) { mask_map_.erase(window); diff --git ui/gfx/x/window_event_manager.h ui/gfx/x/window_event_manager.h index 4b85f49d3b2cc..c0158edd6901b 100644 --- ui/gfx/x/window_event_manager.h +++ ui/gfx/x/window_event_manager.h @@ -53,6 +53,8 @@ class WindowEventManager { ~WindowEventManager(); + void Reset(); + private: friend class ScopedEventSelector; @@ -70,7 +72,7 @@ class WindowEventManager { // necessary. void AfterMaskChanged(Window window, EventMask old_mask); - const raw_ptr connection_; + raw_ptr connection_; std::map> mask_map_; };