Hook everything up to run the GUI on top of the kernel.

Okay things kinda sorta work. Both Bochs and QEMU now boot into GUI mode.
There's a ton of stuff that doesn't make sense and so many things to rework.

Still it's quite cool to have made it this far. :^)
This commit is contained in:
Andreas Kling 2019-01-10 23:19:29 +01:00
parent 8626e95509
commit f6d2c3ed87
Notes: sideshowbarker 2024-07-19 16:05:11 +09:00
17 changed files with 117 additions and 23 deletions

View file

@ -43,7 +43,22 @@ VFS_OBJS = \
WIDGETS_OBJS = \
../Widgets/Window.o \
../Widgets/Painter.o
../Widgets/Painter.o \
../Widgets/WindowManager.o \
../Widgets/FrameBuffer.o \
../Widgets/GraphicsBitmap.o \
../Widgets/Object.o \
../Widgets/Rect.o \
../Widgets/Widget.o \
../Widgets/Font.o \
../Widgets/Color.o \
../Widgets/CharacterBitmap.o \
../Widgets/EventLoop.o \
../Widgets/RootWidget.o \
../Widgets/Label.o \
../Widgets/Button.o \
../Widgets/MsgBox.o \
../Widgets/AbstractScreen.o
AK_OBJS = \
../AK/String.o \

View file

@ -1,12 +1,33 @@
#include "WindowComposer.h"
#include "Process.h"
#include <Widgets/Font.h>
#include <Widgets/FrameBuffer.h>
#include <Widgets/WindowManager.h>
#include <Widgets/RootWidget.h>
#include <Widgets/EventLoop.h>
#include <Widgets/MsgBox.h>
void WindowComposer_main()
{
Font::initialize();
FrameBuffer::initialize();
EventLoop::initialize();
WindowManager::initialize();
auto info = current->get_display_info();
dbgprintf("Entering WindowComposer main loop.\n");
for (;;) {
dbgprintf("Screen is %ux%ux%ubpp\n", info.width, info.height, info.bpp);
}
FrameBuffer framebuffer((dword*)info.framebuffer, info.width, info.height);
RootWidget rw;
EventLoop loop;
WindowManager::the().setRootWidget(&rw);
MsgBox(nullptr, "Serenity Operating System");
dbgprintf("Entering WindowComposer main loop.\n");
loop.exec();
ASSERT_NOT_REACHED();
}

View file

@ -1,6 +1,5 @@
#include "Button.h"
#include "Painter.h"
#include <cstdio>
Button::Button(Widget* parent)
: Widget(parent)
@ -15,7 +14,7 @@ void Button::setCaption(String&& caption)
{
if (caption == m_caption)
return;
m_caption = std::move(caption);
m_caption = move(caption);
update();
}

View file

@ -6,7 +6,7 @@ Color::Color(byte r, byte g, byte b)
#ifdef USE_SDL
m_value = SDL_MapRGB(FrameBuffer::the().surface()->format, r, g, b);
#else
#error FIXME: Implement
m_value = (r << 16) | (g << 8) | b;
#endif
}
@ -33,6 +33,6 @@ Color::Color(NamedColor named)
#ifdef USE_SDL
m_value = SDL_MapRGB(FrameBuffer::the().surface()->format, rgb.r, rgb.g, rgb.g);
#else
#error FIXME: Implement
m_value = (rgb.r << 16) | (rgb.g << 8) | rgb.b;
#endif
}

View file

@ -5,6 +5,11 @@
static EventLoop* s_mainEventLoop;
void EventLoop::initialize()
{
s_mainEventLoop = nullptr;
}
EventLoop::EventLoop()
{
if (!s_mainEventLoop)
@ -26,7 +31,7 @@ int EventLoop::exec()
for (;;) {
if (m_queuedEvents.is_empty())
waitForEvent();
auto events = std::move(m_queuedEvents);
auto events = move(m_queuedEvents);
for (auto& queuedEvent : events) {
auto* receiver = queuedEvent.receiver;
auto& event = *queuedEvent.event;
@ -48,9 +53,16 @@ int EventLoop::exec()
void EventLoop::postEvent(Object* receiver, OwnPtr<Event>&& event)
{
m_queuedEvents.append({ receiver, std::move(event) });
printf("EventLoop::postEvent: {%u} << receiver=%p, event=%p\n", m_queuedEvents.size(), receiver, event.ptr());
m_queuedEvents.append({ receiver, move(event) });
}
#ifdef SERENITY
void EventLoop::waitForEvent()
{
}
#endif
#ifdef USE_SDL
static inline MouseButton toMouseButton(byte sdlButton)
{
@ -119,7 +131,7 @@ void EventLoop::handleKeyEvent(Event::Type type, const SDL_KeyboardEvent& sdlKey
keyEvent->m_ctrl = sdlKey.keysym.mod & KMOD_CTRL;
keyEvent->m_alt = sdlKey.keysym.mod & KMOD_ALT;
postEvent(&WindowManager::the(), std::move(keyEvent));
postEvent(&WindowManager::the(), move(keyEvent));
}
void EventLoop::waitForEvent()

View file

@ -21,6 +21,8 @@ public:
static EventLoop& main();
static void initialize();
private:
void waitForEvent();

View file

@ -1,12 +1,19 @@
#include "Font.h"
#include "Peanut8x10.h"
#include <AK/RetainPtr.h>
#include <cstdio>
static Font* s_default_font;
void Font::initialize()
{
s_default_font = nullptr;
}
Font& Font::defaultFont()
{
static auto* f = adopt(*new Font(Peanut8x10::glyphs, Peanut8x10::glyphWidth, Peanut8x10::glyphHeight, Peanut8x10::firstGlyph, Peanut8x10::lastGlyph)).leakRef();
return *f;
if (!s_default_font)
s_default_font = adopt(*new Font(Peanut8x10::glyphs, Peanut8x10::glyphWidth, Peanut8x10::glyphHeight, Peanut8x10::firstGlyph, Peanut8x10::lastGlyph)).leakRef();
return *s_default_font;
}
Font::Font(const char* const* glyphs, byte glyphWidth, byte glyphHeight, byte firstGlyph, byte lastGlyph)

View file

@ -16,6 +16,8 @@ public:
byte glyphWidth() const { return m_glyphWidth; }
byte glyphHeight() const { return m_glyphHeight; }
static void initialize();
private:
Font(const char* const* glyphs, byte glyphWidth, byte glyphHeight, byte firstGlyph, byte lastGlyph);

View file

@ -2,7 +2,12 @@
#include "GraphicsBitmap.h"
#include <AK/Assertions.h>
FrameBuffer* s_the = nullptr;
FrameBuffer* s_the;
void FrameBuffer::initialize()
{
s_the = nullptr;
}
FrameBuffer& FrameBuffer::the()
{
@ -20,6 +25,17 @@ FrameBuffer::FrameBuffer(unsigned width, unsigned height)
#endif
}
FrameBuffer::FrameBuffer(RGBA32* data, unsigned width, unsigned height)
: AbstractScreen(width, height)
#ifdef SERENITY
, m_data(data)
#endif
{
ASSERT(!s_the);
s_the = this;
}
FrameBuffer::~FrameBuffer()
{
#ifdef USE_SDL
@ -68,6 +84,10 @@ RGBA32* FrameBuffer::scanline(int y)
#ifdef USE_SDL
return reinterpret_cast<RGBA32*>(((byte*)m_surface->pixels) + (y * m_surface->pitch));
#endif
#ifdef SERENITY
unsigned pitch = sizeof(RGBA32) * width();
return reinterpret_cast<RGBA32*>(((byte*)m_data) + (y * pitch));
#endif
}
void FrameBuffer::blit(const Point& position, GraphicsBitmap& bitmap)

View file

@ -12,6 +12,7 @@ class GraphicsBitmap;
class FrameBuffer final : public AbstractScreen {
public:
FrameBuffer(unsigned width, unsigned height);
FrameBuffer(RGBA32*, unsigned width, unsigned height);
virtual ~FrameBuffer() override;
void show();
@ -27,11 +28,16 @@ public:
void blit(const Point&, GraphicsBitmap&);
void flush();
static void initialize();
private:
#ifdef USE_SDL
void initializeSDL();
SDL_Window* m_window { nullptr };
SDL_Surface* m_surface { nullptr };
#endif
#ifdef SERENITY
RGBA32* m_data { nullptr };
#endif
};

View file

@ -1,6 +1,5 @@
#include "Label.h"
#include "Painter.h"
#include <cstdio>
Label::Label(Widget* parent)
: Widget(parent)
@ -15,7 +14,7 @@ void Label::setText(String&& text)
{
if (text == m_text)
return;
m_text = std::move(text);
m_text = move(text);
update();
}

View file

@ -47,7 +47,7 @@ void MsgBox(Window* owner, String&& text)
textWidth,
textHeight
});
label->setText(std::move(text));
label->setText(move(text));
auto* button = new Button(widget);
button->setCaption("OK");
button->setWindowRelativeRect(buttonRect);

View file

@ -18,7 +18,7 @@ Object::~Object()
{
if (m_parent)
m_parent->removeChild(*this);
auto childrenToDelete = std::move(m_children);
auto childrenToDelete = move(m_children);
for (auto* child : childrenToDelete)
delete child;
}
@ -81,7 +81,9 @@ void Object::stopTimer()
{
if (!m_timerID)
return;
#ifdef USE_SDL
SDL_RemoveTimer(m_timerID);
#endif
m_timerID = 0;
}

View file

@ -4,7 +4,6 @@
#include "Painter.h"
#include "WindowManager.h"
#include "FrameBuffer.h"
#include <cstdio>
RootWidget::RootWidget()
{

View file

@ -159,7 +159,7 @@ void Widget::setFont(RetainPtr<Font>&& font)
if (!font)
m_font = Font::defaultFont();
else
m_font = std::move(font);
m_font = move(font);
}
GraphicsBitmap* Widget::backing()

View file

@ -47,10 +47,18 @@ static inline Rect outerRectForWindow(const Window& window)
return rect;
}
static WindowManager* s_the_window_manager;
WindowManager& WindowManager::the()
{
static WindowManager* s_the = new WindowManager;
return *s_the;
if (!s_the_window_manager)
s_the_window_manager = new WindowManager;
return *s_the_window_manager;
}
void WindowManager::initialize()
{
s_the_window_manager = nullptr;
}
WindowManager::WindowManager()

View file

@ -34,6 +34,8 @@ public:
void repaint();
void move_to_front(Window&);
static void initialize();
private:
WindowManager();
~WindowManager();