mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 09:27:35 +00: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));
|
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)
|
void GEventLoop::handle_key_event(const GUI_Event& event, GWindow& window)
|
||||||
{
|
{
|
||||||
#ifdef GEVENTLOOP_DEBUG
|
#ifdef GEVENTLOOP_DEBUG
|
||||||
|
@ -162,10 +170,8 @@ void GEventLoop::wait_for_event()
|
||||||
handle_mouse_event(event, *window);
|
handle_mouse_event(event, *window);
|
||||||
break;
|
break;
|
||||||
case GUI_Event::Type::WindowActivated:
|
case GUI_Event::Type::WindowActivated:
|
||||||
dbgprintf("WID=%x WindowActivated\n", event.window_id);
|
|
||||||
break;
|
|
||||||
case GUI_Event::Type::WindowDeactivated:
|
case GUI_Event::Type::WindowDeactivated:
|
||||||
dbgprintf("WID=%x WindowDeactivated\n", event.window_id);
|
handle_window_activation_event(event, *window);
|
||||||
break;
|
break;
|
||||||
case GUI_Event::Type::KeyDown:
|
case GUI_Event::Type::KeyDown:
|
||||||
case GUI_Event::Type::KeyUp:
|
case GUI_Event::Type::KeyUp:
|
||||||
|
|
|
@ -28,6 +28,7 @@ private:
|
||||||
void handle_paint_event(const GUI_Event&, GWindow&);
|
void handle_paint_event(const GUI_Event&, GWindow&);
|
||||||
void handle_mouse_event(const GUI_Event&, GWindow&);
|
void handle_mouse_event(const GUI_Event&, GWindow&);
|
||||||
void handle_key_event(const GUI_Event&, GWindow&);
|
void handle_key_event(const GUI_Event&, GWindow&);
|
||||||
|
void handle_window_activation_event(const GUI_Event&, GWindow&);
|
||||||
|
|
||||||
struct QueuedEvent {
|
struct QueuedEvent {
|
||||||
GObject* receiver { nullptr };
|
GObject* receiver { nullptr };
|
||||||
|
|
|
@ -145,6 +145,8 @@ bool GWidget::is_focused() const
|
||||||
auto* win = window();
|
auto* win = window();
|
||||||
if (!win)
|
if (!win)
|
||||||
return false;
|
return false;
|
||||||
|
if (!win->is_active())
|
||||||
|
return false;
|
||||||
return win->focused_widget() == this;
|
return win->focused_widget() == this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ void GWindow::event(GEvent& event)
|
||||||
ASSERT(result.widget);
|
ASSERT(result.widget);
|
||||||
return result.widget->event(*local_event);
|
return result.widget->event(*local_event);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.is_paint_event()) {
|
if (event.is_paint_event()) {
|
||||||
|
@ -94,6 +95,7 @@ void GWindow::event(GEvent& event)
|
||||||
GUI_Rect gui_rect = rect;
|
GUI_Rect gui_rect = rect;
|
||||||
int rc = gui_notify_paint_finished(m_window_id, &gui_rect);
|
int rc = gui_notify_paint_finished(m_window_id, &gui_rect);
|
||||||
ASSERT(rc == 0);
|
ASSERT(rc == 0);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.is_key_event()) {
|
if (event.is_key_event()) {
|
||||||
|
@ -102,7 +104,14 @@ void GWindow::event(GEvent& event)
|
||||||
return m_focused_widget->event(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
|
bool GWindow::is_visible() const
|
||||||
|
|
|
@ -32,6 +32,7 @@ public:
|
||||||
virtual void event(GEvent&) override;
|
virtual void event(GEvent&) override;
|
||||||
|
|
||||||
bool is_visible() const;
|
bool is_visible() const;
|
||||||
|
bool is_active() const { return m_is_active; }
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
|
@ -39,7 +40,6 @@ public:
|
||||||
const GWidget* main_widget() const { return m_main_widget; }
|
const GWidget* main_widget() const { return m_main_widget; }
|
||||||
void set_main_widget(GWidget*);
|
void set_main_widget(GWidget*);
|
||||||
|
|
||||||
|
|
||||||
GWidget* focused_widget() { return m_focused_widget; }
|
GWidget* focused_widget() { return m_focused_widget; }
|
||||||
const GWidget* focused_widget() const { return m_focused_widget; }
|
const GWidget* focused_widget() const { return m_focused_widget; }
|
||||||
void set_focused_widget(GWidget*);
|
void set_focused_widget(GWidget*);
|
||||||
|
@ -51,6 +51,7 @@ public:
|
||||||
private:
|
private:
|
||||||
RetainPtr<GraphicsBitmap> m_backing;
|
RetainPtr<GraphicsBitmap> m_backing;
|
||||||
int m_window_id { -1 };
|
int m_window_id { -1 };
|
||||||
|
bool m_is_active { false };
|
||||||
GWidget* m_main_widget { nullptr };
|
GWidget* m_main_widget { nullptr };
|
||||||
GWidget* m_focused_widget { nullptr };
|
GWidget* m_focused_widget { nullptr };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue