mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 18:32:28 -05:00
LibGUI: Don't consider a GWidget focused if the window is inactive.
This commit is contained in:
parent
25d045dee5
commit
2e370fa4d5
5 changed files with 24 additions and 5 deletions
|
@ -86,6 +86,14 @@ void GEventLoop::handle_paint_event(const GUI_Event& event, GWindow& window)
|
|||
post_event(&window, make<GPaintEvent>(event.paint.rect));
|
||||
}
|
||||
|
||||
void GEventLoop::handle_window_activation_event(const GUI_Event& event, GWindow& window)
|
||||
{
|
||||
#ifdef GEVENTLOOP_DEBUG
|
||||
dbgprintf("WID=%x WindowActivation\n", event.window_id);
|
||||
#endif
|
||||
post_event(&window, make<GEvent>(event.type == GUI_Event::Type::WindowActivated ? GEvent::WindowBecameActive : GEvent::WindowBecameInactive));
|
||||
}
|
||||
|
||||
void GEventLoop::handle_key_event(const GUI_Event& event, GWindow& window)
|
||||
{
|
||||
#ifdef GEVENTLOOP_DEBUG
|
||||
|
@ -162,10 +170,8 @@ void GEventLoop::wait_for_event()
|
|||
handle_mouse_event(event, *window);
|
||||
break;
|
||||
case GUI_Event::Type::WindowActivated:
|
||||
dbgprintf("WID=%x WindowActivated\n", event.window_id);
|
||||
break;
|
||||
case GUI_Event::Type::WindowDeactivated:
|
||||
dbgprintf("WID=%x WindowDeactivated\n", event.window_id);
|
||||
handle_window_activation_event(event, *window);
|
||||
break;
|
||||
case GUI_Event::Type::KeyDown:
|
||||
case GUI_Event::Type::KeyUp:
|
||||
|
|
|
@ -28,6 +28,7 @@ private:
|
|||
void handle_paint_event(const GUI_Event&, GWindow&);
|
||||
void handle_mouse_event(const GUI_Event&, GWindow&);
|
||||
void handle_key_event(const GUI_Event&, GWindow&);
|
||||
void handle_window_activation_event(const GUI_Event&, GWindow&);
|
||||
|
||||
struct QueuedEvent {
|
||||
GObject* receiver { nullptr };
|
||||
|
|
|
@ -145,6 +145,8 @@ bool GWidget::is_focused() const
|
|||
auto* win = window();
|
||||
if (!win)
|
||||
return false;
|
||||
if (!win->is_active())
|
||||
return false;
|
||||
return win->focused_widget() == this;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,6 +81,7 @@ void GWindow::event(GEvent& event)
|
|||
ASSERT(result.widget);
|
||||
return result.widget->event(*local_event);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.is_paint_event()) {
|
||||
|
@ -94,6 +95,7 @@ void GWindow::event(GEvent& event)
|
|||
GUI_Rect gui_rect = rect;
|
||||
int rc = gui_notify_paint_finished(m_window_id, &gui_rect);
|
||||
ASSERT(rc == 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.is_key_event()) {
|
||||
|
@ -102,7 +104,14 @@ void GWindow::event(GEvent& event)
|
|||
return m_focused_widget->event(event);
|
||||
}
|
||||
|
||||
return GObject::event(event);
|
||||
if (event.type() == GEvent::WindowBecameActive || event.type() == GEvent::WindowBecameInactive) {
|
||||
m_is_active = event.type() == GEvent::WindowBecameActive;
|
||||
if (m_focused_widget)
|
||||
m_focused_widget->update();
|
||||
return;
|
||||
}
|
||||
|
||||
GObject::event(event);
|
||||
}
|
||||
|
||||
bool GWindow::is_visible() const
|
||||
|
|
|
@ -32,6 +32,7 @@ public:
|
|||
virtual void event(GEvent&) override;
|
||||
|
||||
bool is_visible() const;
|
||||
bool is_active() const { return m_is_active; }
|
||||
|
||||
void close();
|
||||
|
||||
|
@ -39,7 +40,6 @@ public:
|
|||
const GWidget* main_widget() const { return m_main_widget; }
|
||||
void set_main_widget(GWidget*);
|
||||
|
||||
|
||||
GWidget* focused_widget() { return m_focused_widget; }
|
||||
const GWidget* focused_widget() const { return m_focused_widget; }
|
||||
void set_focused_widget(GWidget*);
|
||||
|
@ -51,6 +51,7 @@ public:
|
|||
private:
|
||||
RetainPtr<GraphicsBitmap> m_backing;
|
||||
int m_window_id { -1 };
|
||||
bool m_is_active { false };
|
||||
GWidget* m_main_widget { nullptr };
|
||||
GWidget* m_focused_widget { nullptr };
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue