diff --git a/src/node.cpp b/src/node.cpp index 23bb39e..e5b82d5 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -565,8 +565,11 @@ bool Node::is_child(Node* o) const void Node::mouse_capture() { - auto& c = root()->current_mouse_capture; - auto& s = root()->m_capture_stack; + auto root = App::I->layout.get_ref("main"); + if (!root) return; + + auto& c = root->current_mouse_capture; + auto& s = root->m_capture_stack; // already owner of capture if (c.get() == this || std::find_if(s.begin(), s.end(), @@ -607,8 +610,11 @@ void Node::mouse_release() if (!m_parent) return; - auto& c = root()->current_mouse_capture; - auto& s = root()->m_capture_stack; + auto root = App::I->layout.get_ref("main"); + if (!root) return; + + auto& c = root->current_mouse_capture; + auto& s = root->m_capture_stack; s.erase(std::remove_if(s.begin(), s.end(), [this](const auto& a) { return a.get() == this; }), s.end()); @@ -633,13 +639,20 @@ void Node::key_capture() if (!m_parent) return; - root()->current_key_capture = shared_from_this(); + auto root = App::I->layout.get_ref("main"); + if (!root) return; + + root->current_key_capture = shared_from_this(); m_key_captured = true; } void Node::key_release() { - root()->current_key_capture = nullptr; + auto root = App::I->layout.get_ref("main"); + if (!root) return; + + if (root->current_key_capture.get() == this) + root->current_key_capture = nullptr; m_key_captured = false; }