mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
Let WindowManager send out events for WindowBecame{Active,Inactive}
This commit is contained in:
parent
4775fd88e3
commit
39e236d346
Notes:
sideshowbarker
2024-07-19 16:05:40 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/39e236d346b
3 changed files with 14 additions and 20 deletions
|
@ -35,9 +35,12 @@ public:
|
||||||
KeyUp,
|
KeyUp,
|
||||||
Timer,
|
Timer,
|
||||||
DeferredDestroy,
|
DeferredDestroy,
|
||||||
|
WindowBecameInactive,
|
||||||
|
WindowBecameActive,
|
||||||
};
|
};
|
||||||
|
|
||||||
Event() { }
|
Event() { }
|
||||||
|
explicit Event(Type type) : m_type(type) { }
|
||||||
~Event() { }
|
~Event() { }
|
||||||
|
|
||||||
Type type() const { return m_type; }
|
Type type() const { return m_type; }
|
||||||
|
@ -48,9 +51,6 @@ public:
|
||||||
bool isKeyEvent() const { return m_type == KeyUp || m_type == KeyDown; }
|
bool isKeyEvent() const { return m_type == KeyUp || m_type == KeyDown; }
|
||||||
bool isPaintEvent() const { return m_type == Paint; }
|
bool isPaintEvent() const { return m_type == Paint; }
|
||||||
|
|
||||||
protected:
|
|
||||||
explicit Event(Type type) : m_type(type) { }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Type m_type { Invalid };
|
Type m_type { Invalid };
|
||||||
};
|
};
|
||||||
|
|
|
@ -66,10 +66,9 @@ dword* FrameBufferSDL::scanline(int y)
|
||||||
void FrameBufferSDL::blit(const Point& position, GraphicsBitmap& bitmap)
|
void FrameBufferSDL::blit(const Point& position, GraphicsBitmap& bitmap)
|
||||||
{
|
{
|
||||||
Rect dst_rect(position, bitmap.size());
|
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());
|
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) {
|
for (int y = 0; y < dst_rect.height(); ++y) {
|
||||||
auto* framebuffer_scanline = scanline(position.y() + y);
|
auto* framebuffer_scanline = scanline(position.y() + y);
|
||||||
|
|
|
@ -25,7 +25,7 @@ static inline Rect titleBarRectForWindow(const Window& window)
|
||||||
static inline Rect borderRectForWindow(const Window& window)
|
static inline Rect borderRectForWindow(const Window& window)
|
||||||
{
|
{
|
||||||
auto titleBarRect = titleBarRectForWindow(window);
|
auto titleBarRect = titleBarRectForWindow(window);
|
||||||
return { titleBarRect.x() - 1,
|
return { titleBarRect.x() - 1,
|
||||||
titleBarRect.y() - 1,
|
titleBarRect.y() - 1,
|
||||||
titleBarRect.width() + 2,
|
titleBarRect.width() + 2,
|
||||||
windowFrameWidth + windowTitleBarHeight + window.rect().height() + 4
|
windowFrameWidth + windowTitleBarHeight + window.rect().height() + 4
|
||||||
|
@ -282,10 +282,11 @@ void WindowManager::recompose()
|
||||||
auto& framebuffer = FrameBufferSDL::the();
|
auto& framebuffer = FrameBufferSDL::the();
|
||||||
m_rootWidget->repaint(m_rootWidget->rect());
|
m_rootWidget->repaint(m_rootWidget->rect());
|
||||||
for (auto* window = m_windows_in_order.head(); window; window = window->next()) {
|
for (auto* window = m_windows_in_order.head(); window; window = window->next()) {
|
||||||
|
if (!window->backing())
|
||||||
|
continue;
|
||||||
paintWindowFrame(*window);
|
paintWindowFrame(*window);
|
||||||
if (m_dragWindow.ptr() == window)
|
if (m_dragWindow.ptr() == window)
|
||||||
continue;
|
continue;
|
||||||
ASSERT(window->backing());
|
|
||||||
framebuffer.blit(window->position(), *window->backing());
|
framebuffer.blit(window->position(), *window->backing());
|
||||||
}
|
}
|
||||||
framebuffer.flush();
|
framebuffer.flush();
|
||||||
|
@ -314,7 +315,7 @@ void WindowManager::setRootWidget(Widget* widget)
|
||||||
// FIXME: Should we support switching root widgets?
|
// FIXME: Should we support switching root widgets?
|
||||||
ASSERT(!m_rootWidget);
|
ASSERT(!m_rootWidget);
|
||||||
ASSERT(widget);
|
ASSERT(widget);
|
||||||
|
|
||||||
m_rootWidget = widget;
|
m_rootWidget = widget;
|
||||||
EventLoop::main().postEvent(m_rootWidget, make<ShowEvent>());
|
EventLoop::main().postEvent(m_rootWidget, make<ShowEvent>());
|
||||||
}
|
}
|
||||||
|
@ -324,19 +325,13 @@ void WindowManager::setActiveWindow(Window* window)
|
||||||
if (window == m_activeWindow.ptr())
|
if (window == m_activeWindow.ptr())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto* previouslyActiveWindow = m_activeWindow.ptr();
|
if (auto* previously_active_window = m_activeWindow.ptr())
|
||||||
|
EventLoop::main().postEvent(previously_active_window, make<Event>(Event::WindowBecameInactive));
|
||||||
m_activeWindow = window->makeWeakPtr();
|
m_activeWindow = window->makeWeakPtr();
|
||||||
|
if (m_activeWindow)
|
||||||
|
EventLoop::main().postEvent(m_activeWindow.ptr(), make<Event>(Event::WindowBecameActive));
|
||||||
|
|
||||||
if (previouslyActiveWindow) {
|
recompose();
|
||||||
paintWindowFrame(*previouslyActiveWindow);
|
|
||||||
previouslyActiveWindow->repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_activeWindow) {
|
|
||||||
paintWindowFrame(*m_activeWindow);
|
|
||||||
m_activeWindow->repaint();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WindowManager::isVisible(Window& window) const
|
bool WindowManager::isVisible(Window& window) const
|
||||||
|
|
Loading…
Reference in a new issue