소스 검색

LibGUI: Don't consider a GWidget focused if the window is inactive.

Andreas Kling 6 년 전
부모
커밋
2e370fa4d5
5개의 변경된 파일24개의 추가작업 그리고 5개의 파일을 삭제
  1. 9 3
      LibGUI/GEventLoop.cpp
  2. 1 0
      LibGUI/GEventLoop.h
  3. 2 0
      LibGUI/GWidget.cpp
  4. 10 1
      LibGUI/GWindow.cpp
  5. 2 1
      LibGUI/GWindow.h

+ 9 - 3
LibGUI/GEventLoop.cpp

@@ -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:

+ 1 - 0
LibGUI/GEventLoop.h

@@ -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 };

+ 2 - 0
LibGUI/GWidget.cpp

@@ -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;
 }
 

+ 10 - 1
LibGUI/GWindow.cpp

@@ -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

+ 2 - 1
LibGUI/GWindow.h

@@ -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 };
 };