mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +00:00
Tear out or duplicate what's unique for WindowServer from Widgets.
This turned into a huge refactoring that somehow also includes making locks recursive/reentrant.
This commit is contained in:
parent
e655aebd70
commit
f7ca6d254d
30 changed files with 757 additions and 308 deletions
89
WindowServer/WSWindow.cpp
Normal file
89
WindowServer/WSWindow.cpp
Normal file
|
@ -0,0 +1,89 @@
|
|||
#include "WSWindow.h"
|
||||
#include "WSWindowManager.h"
|
||||
#include "WSEvent.h"
|
||||
#include "WSEventLoop.h"
|
||||
#include "Process.h"
|
||||
|
||||
WSWindow::WSWindow(Process& process, int window_id)
|
||||
: m_process(process)
|
||||
, m_window_id(window_id)
|
||||
{
|
||||
WSWindowManager::the().addWindow(*this);
|
||||
}
|
||||
|
||||
WSWindow::~WSWindow()
|
||||
{
|
||||
WSWindowManager::the().removeWindow(*this);
|
||||
}
|
||||
|
||||
void WSWindow::set_title(String&& title)
|
||||
{
|
||||
if (m_title == title)
|
||||
return;
|
||||
|
||||
m_title = move(title);
|
||||
WSWindowManager::the().notifyTitleChanged(*this);
|
||||
}
|
||||
|
||||
void WSWindow::set_rect(const Rect& rect)
|
||||
{
|
||||
if (m_rect == rect)
|
||||
return;
|
||||
auto oldRect = m_rect;
|
||||
m_rect = rect;
|
||||
m_backing = GraphicsBitmap::create(m_process, m_rect.size());
|
||||
WSWindowManager::the().notifyRectChanged(*this, oldRect, m_rect);
|
||||
}
|
||||
|
||||
// FIXME: Just use the same types.
|
||||
static GUI_MouseButton to_api(MouseButton button)
|
||||
{
|
||||
switch (button) {
|
||||
case MouseButton::None: return GUI_MouseButton::NoButton;
|
||||
case MouseButton::Left: return GUI_MouseButton::Left;
|
||||
case MouseButton::Right: return GUI_MouseButton::Right;
|
||||
case MouseButton::Middle: return GUI_MouseButton::Middle;
|
||||
}
|
||||
}
|
||||
|
||||
void WSWindow::event(WSEvent& event)
|
||||
{
|
||||
GUI_Event gui_event;
|
||||
gui_event.window_id = window_id();
|
||||
|
||||
switch (event.type()) {
|
||||
case WSEvent::Paint:
|
||||
gui_event.type = GUI_Event::Type::Paint;
|
||||
gui_event.paint.rect = static_cast<PaintEvent&>(event).rect();
|
||||
break;
|
||||
case WSEvent::MouseMove:
|
||||
gui_event.type = GUI_Event::Type::MouseMove;
|
||||
gui_event.mouse.position = static_cast<MouseEvent&>(event).position();
|
||||
break;
|
||||
case WSEvent::MouseDown:
|
||||
gui_event.type = GUI_Event::Type::MouseDown;
|
||||
gui_event.mouse.position = static_cast<MouseEvent&>(event).position();
|
||||
gui_event.mouse.button = to_api(static_cast<MouseEvent&>(event).button());
|
||||
break;
|
||||
case WSEvent::MouseUp:
|
||||
gui_event.type = GUI_Event::Type::MouseUp;
|
||||
gui_event.mouse.position = static_cast<MouseEvent&>(event).position();
|
||||
gui_event.mouse.button = to_api(static_cast<MouseEvent&>(event).button());
|
||||
break;
|
||||
case WSEvent::KeyDown:
|
||||
gui_event.type = GUI_Event::Type::KeyDown;
|
||||
gui_event.key.character = static_cast<KeyEvent&>(event).text()[0];
|
||||
break;
|
||||
case WSEvent::WM_Invalidate:
|
||||
WSWindowManager::the().invalidate(*this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (gui_event.type == GUI_Event::Type::Invalid)
|
||||
return;
|
||||
|
||||
{
|
||||
LOCKER(m_process.gui_events_lock());
|
||||
m_process.gui_events().append(move(gui_event));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue