From 61b76df08b7249887467d11295334611172b82fe Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Sat, 19 Mar 2022 21:32:15 +0200 Subject: [PATCH] keep track of focused widget on parent --- src/Widget.cpp | 3 +++ src/Window.cpp | 2 +- src/Window.hpp | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Widget.cpp b/src/Widget.cpp index 192e0e7..3bd01a7 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -97,6 +97,9 @@ void Widget::handle_mouse_move_event(MouseMoveEvent &event) { on_mouse_move(event); on_focus_update(focus_update_event); + if (m_is_focused && m_window) + m_window->set_focused_widget(this); + if (m_consumes_hits) event.accept(); } diff --git a/src/Window.cpp b/src/Window.cpp index 49cc71a..ecc4597 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -75,7 +75,7 @@ bool Window::dispatch_repaint_on_box(Box box) { bool Window::dispatch_full_repaint() { return dispatch_repaint_on_box(m_current_geometry); -} +} void Window::run(bool block) { XEvent e; diff --git a/src/Window.hpp b/src/Window.hpp index f4a652f..32dea83 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -10,7 +10,7 @@ namespace Raven { class Window { private: - Widget *m_hovered_widget { nullptr }; + Widget *m_focused_widget { nullptr }; Widget *m_main_widget { nullptr }; Box m_current_geometry { 0, 0, 800, 600 }; Painter m_painter {}; @@ -23,8 +23,8 @@ public: Painter &get_painter() { return m_painter; } - Widget *get_hovered_widget() { return m_hovered_widget; } - void set_hovered_widget(Widget *hovered_widget) { m_hovered_widget = hovered_widget; } + Widget *get_focused_widget() { return m_focused_widget; } + void set_focused_widget(Widget *focused_widget) { m_focused_widget = focused_widget; } Widget *get_main_widget() { return m_main_widget; } void set_main_widget(Widget *main_widget);