mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:38:10 +00:00
Move windowing stuff from AbstractScreen to WindowManager.
This commit is contained in:
parent
415c4b90c5
commit
02f4d6ef8e
6 changed files with 59 additions and 58 deletions
|
@ -3,6 +3,10 @@
|
|||
#include "Widget.h"
|
||||
#include "Window.h"
|
||||
#include "AbstractScreen.h"
|
||||
#include "TerminalWidget.h"
|
||||
#include "EventLoop.h"
|
||||
|
||||
extern TerminalWidget* g_tw;
|
||||
|
||||
WindowManager& WindowManager::the()
|
||||
{
|
||||
|
@ -26,7 +30,7 @@ void WindowManager::paintWindowFrames()
|
|||
|
||||
void WindowManager::paintWindowFrame(Window& window)
|
||||
{
|
||||
Painter p(*AbstractScreen::the().rootWidget());
|
||||
Painter p(*m_rootWidget);
|
||||
|
||||
printf("WM: paintWindowFrame {%p}, rect: %d,%d %dx%d\n", &window, window.rect().x(), window.rect().y(), window.rect().width(), window.rect().height());
|
||||
|
||||
|
@ -103,3 +107,40 @@ void WindowManager::notifyRectChanged(Window& window, const Rect& oldRect, const
|
|||
newRect.width(),
|
||||
newRect.height());
|
||||
}
|
||||
|
||||
void WindowManager::event(Event& event)
|
||||
{
|
||||
if (event.type() == Event::MouseMove
|
||||
|| event.type() == Event::MouseDown
|
||||
|| event.type() == Event::MouseUp) {
|
||||
auto& me = static_cast<MouseEvent&>(event);
|
||||
|
||||
auto result = m_rootWidget->hitTest(me.x(), me.y());
|
||||
//printf("hit test for %d,%d found: %s{%p} %d,%d\n", me.x(), me.y(), result.widget->className(), result.widget, result.localX, result.localY);
|
||||
auto localEvent = make<MouseEvent>(event.type(), result.localX, result.localY, me.button());
|
||||
result.widget->event(*localEvent);
|
||||
return Object::event(event);
|
||||
}
|
||||
|
||||
if (event.type() == Event::KeyDown || event.type() == Event::KeyUp) {
|
||||
// FIXME: Implement proper focus.
|
||||
Widget* focusedWidget = g_tw;
|
||||
return focusedWidget->event(event);
|
||||
}
|
||||
|
||||
if (event.type() == Event::Paint) {
|
||||
return m_rootWidget->event(event);
|
||||
}
|
||||
|
||||
return Object::event(event);
|
||||
}
|
||||
|
||||
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<ShowEvent>());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue