fix root mouse/key release

This commit is contained in:
2019-09-24 00:02:47 +02:00
parent b42da0c363
commit 7e732cc9b8

View File

@@ -565,8 +565,11 @@ bool Node::is_child(Node* o) const
void Node::mouse_capture() void Node::mouse_capture()
{ {
auto& c = root()->current_mouse_capture; auto root = App::I->layout.get_ref("main");
auto& s = root()->m_capture_stack; if (!root) return;
auto& c = root->current_mouse_capture;
auto& s = root->m_capture_stack;
// already owner of capture // already owner of capture
if (c.get() == this || std::find_if(s.begin(), s.end(), if (c.get() == this || std::find_if(s.begin(), s.end(),
@@ -607,8 +610,11 @@ void Node::mouse_release()
if (!m_parent) if (!m_parent)
return; return;
auto& c = root()->current_mouse_capture; auto root = App::I->layout.get_ref("main");
auto& s = root()->m_capture_stack; if (!root) return;
auto& c = root->current_mouse_capture;
auto& s = root->m_capture_stack;
s.erase(std::remove_if(s.begin(), s.end(), s.erase(std::remove_if(s.begin(), s.end(),
[this](const auto& a) { return a.get() == this; }), s.end()); [this](const auto& a) { return a.get() == this; }), s.end());
@@ -633,13 +639,20 @@ void Node::key_capture()
if (!m_parent) if (!m_parent)
return; 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; m_key_captured = true;
} }
void Node::key_release() 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; m_key_captured = false;
} }