diff --git a/Widgets/Event.h b/Widgets/Event.h index 90fa683ba0c..4f1d2a139ef 100644 --- a/Widgets/Event.h +++ b/Widgets/Event.h @@ -35,9 +35,12 @@ public: KeyUp, Timer, DeferredDestroy, + WindowBecameInactive, + WindowBecameActive, }; Event() { } + explicit Event(Type type) : m_type(type) { } ~Event() { } Type type() const { return m_type; } @@ -48,9 +51,6 @@ public: bool isKeyEvent() const { return m_type == KeyUp || m_type == KeyDown; } bool isPaintEvent() const { return m_type == Paint; } -protected: - explicit Event(Type type) : m_type(type) { } - private: Type m_type { Invalid }; }; diff --git a/Widgets/FrameBufferSDL.cpp b/Widgets/FrameBufferSDL.cpp index 74f3c4e115b..4d3b4f6c6b4 100644 --- a/Widgets/FrameBufferSDL.cpp +++ b/Widgets/FrameBufferSDL.cpp @@ -66,10 +66,9 @@ dword* FrameBufferSDL::scanline(int y) void FrameBufferSDL::blit(const Point& position, GraphicsBitmap& bitmap) { Rect dst_rect(position, bitmap.size()); - - printf("blit at %d,%d %dx%d\n", dst_rect.x(), dst_rect.y(), dst_rect.width(), dst_rect.height()); + //printf("blit at %d,%d %dx%d\n", dst_rect.x(), dst_rect.y(), dst_rect.width(), dst_rect.height()); dst_rect.intersect(rect()); - printf(" -> intersection %d,%d %dx%d\n", dst_rect.x(), dst_rect.y(), dst_rect.width(), dst_rect.height()); + //printf(" -> intersection %d,%d %dx%d\n", dst_rect.x(), dst_rect.y(), dst_rect.width(), dst_rect.height()); for (int y = 0; y < dst_rect.height(); ++y) { auto* framebuffer_scanline = scanline(position.y() + y); diff --git a/Widgets/WindowManager.cpp b/Widgets/WindowManager.cpp index 4c731e7238d..4f8c88cc790 100644 --- a/Widgets/WindowManager.cpp +++ b/Widgets/WindowManager.cpp @@ -25,7 +25,7 @@ static inline Rect titleBarRectForWindow(const Window& window) static inline Rect borderRectForWindow(const Window& window) { auto titleBarRect = titleBarRectForWindow(window); - return { titleBarRect.x() - 1, + return { titleBarRect.x() - 1, titleBarRect.y() - 1, titleBarRect.width() + 2, windowFrameWidth + windowTitleBarHeight + window.rect().height() + 4 @@ -282,10 +282,11 @@ void WindowManager::recompose() auto& framebuffer = FrameBufferSDL::the(); m_rootWidget->repaint(m_rootWidget->rect()); for (auto* window = m_windows_in_order.head(); window; window = window->next()) { + if (!window->backing()) + continue; paintWindowFrame(*window); if (m_dragWindow.ptr() == window) continue; - ASSERT(window->backing()); framebuffer.blit(window->position(), *window->backing()); } framebuffer.flush(); @@ -314,7 +315,7 @@ void WindowManager::setRootWidget(Widget* widget) // FIXME: Should we support switching root widgets? ASSERT(!m_rootWidget); ASSERT(widget); - + m_rootWidget = widget; EventLoop::main().postEvent(m_rootWidget, make()); } @@ -324,19 +325,13 @@ void WindowManager::setActiveWindow(Window* window) if (window == m_activeWindow.ptr()) return; - auto* previouslyActiveWindow = m_activeWindow.ptr(); - + if (auto* previously_active_window = m_activeWindow.ptr()) + EventLoop::main().postEvent(previously_active_window, make(Event::WindowBecameInactive)); m_activeWindow = window->makeWeakPtr(); + if (m_activeWindow) + EventLoop::main().postEvent(m_activeWindow.ptr(), make(Event::WindowBecameActive)); - if (previouslyActiveWindow) { - paintWindowFrame(*previouslyActiveWindow); - previouslyActiveWindow->repaint(); - } - - if (m_activeWindow) { - paintWindowFrame(*m_activeWindow); - m_activeWindow->repaint(); - } + recompose(); } bool WindowManager::isVisible(Window& window) const