summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-10 23:19:29 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-10 23:19:29 +0100
commitf6d2c3ed87b03062dee0bb190aa45ce1f362ada3 (patch)
treee3ca5887c5b75e996a6d0a7a61565986cff4d27e
parent8626e95509c5984c331b23585bd530571239129d (diff)
downloadserenity-f6d2c3ed87b03062dee0bb190aa45ce1f362ada3.zip
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. :^)
-rw-r--r--Kernel/Makefile17
-rw-r--r--Kernel/WindowComposer.cpp25
-rw-r--r--Widgets/Button.cpp3
-rw-r--r--Widgets/Color.cpp4
-rw-r--r--Widgets/EventLoop.cpp18
-rw-r--r--Widgets/EventLoop.h2
-rw-r--r--Widgets/Font.cpp13
-rw-r--r--Widgets/Font.h2
-rw-r--r--Widgets/FrameBuffer.cpp22
-rw-r--r--Widgets/FrameBuffer.h6
-rw-r--r--Widgets/Label.cpp3
-rw-r--r--Widgets/MsgBox.cpp2
-rw-r--r--Widgets/Object.cpp4
-rw-r--r--Widgets/RootWidget.cpp1
-rw-r--r--Widgets/Widget.cpp2
-rw-r--r--Widgets/WindowManager.cpp12
-rw-r--r--Widgets/WindowManager.h2
17 files changed, 116 insertions, 22 deletions
diff --git a/Kernel/Makefile b/Kernel/Makefile
index 590a12d51b..813ce41d7b 100644
--- a/Kernel/Makefile
+++ b/Kernel/Makefile
@@ -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 \
diff --git a/Kernel/WindowComposer.cpp b/Kernel/WindowComposer.cpp
index b6be2f4575..3a884bfffa 100644
--- a/Kernel/WindowComposer.cpp
+++ b/Kernel/WindowComposer.cpp
@@ -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("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");
- for (;;) {
+ loop.exec();
- }
+ ASSERT_NOT_REACHED();
}
diff --git a/Widgets/Button.cpp b/Widgets/Button.cpp
index 5429ad8854..26d4fd6811 100644
--- a/Widgets/Button.cpp
+++ b/Widgets/Button.cpp
@@ -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();
}
diff --git a/Widgets/Color.cpp b/Widgets/Color.cpp
index dd7f5d5f79..f096849285 100644
--- a/Widgets/Color.cpp
+++ b/Widgets/Color.cpp
@@ -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
}
diff --git a/Widgets/EventLoop.cpp b/Widgets/EventLoop.cpp
index 1645eec5e5..15bfb8c5a8 100644
--- a/Widgets/EventLoop.cpp
+++ b/Widgets/EventLoop.cpp
@@ -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,8 +53,15 @@ 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()
diff --git a/Widgets/EventLoop.h b/Widgets/EventLoop.h
index 9b112ab59b..d0982bb751 100644
--- a/Widgets/EventLoop.h
+++ b/Widgets/EventLoop.h
@@ -21,6 +21,8 @@ public:
static EventLoop& main();
+ static void initialize();
+
private:
void waitForEvent();
diff --git a/Widgets/Font.cpp b/Widgets/Font.cpp
index 1eb9999131..f73b62484f 100644
--- a/Widgets/Font.cpp
+++ b/Widgets/Font.cpp
@@ -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)
diff --git a/Widgets/Font.h b/Widgets/Font.h
index b41d371bcf..3c9158f761 100644
--- a/Widgets/Font.h
+++ b/Widgets/Font.h
@@ -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);
diff --git a/Widgets/FrameBuffer.cpp b/Widgets/FrameBuffer.cpp
index 4454dc972e..89e2a57090 100644
--- a/Widgets/FrameBuffer.cpp
+++ b/Widgets/FrameBuffer.cpp
@@ -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)
diff --git a/Widgets/FrameBuffer.h b/Widgets/FrameBuffer.h
index 03da7eab91..56b2f53062 100644
--- a/Widgets/FrameBuffer.h
+++ b/Widgets/FrameBuffer.h
@@ -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
};
diff --git a/Widgets/Label.cpp b/Widgets/Label.cpp
index 7e33147d0c..e23544ae71 100644
--- a/Widgets/Label.cpp
+++ b/Widgets/Label.cpp
@@ -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();
}
diff --git a/Widgets/MsgBox.cpp b/Widgets/MsgBox.cpp
index 9c8a41f1db..06bfbf0643 100644
--- a/Widgets/MsgBox.cpp
+++ b/Widgets/MsgBox.cpp
@@ -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);
diff --git a/Widgets/Object.cpp b/Widgets/Object.cpp
index 3380b4faa9..031d265f4e 100644
--- a/Widgets/Object.cpp
+++ b/Widgets/Object.cpp
@@ -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;
}
diff --git a/Widgets/RootWidget.cpp b/Widgets/RootWidget.cpp
index 644a051fb3..15db5754d0 100644
--- a/Widgets/RootWidget.cpp
+++ b/Widgets/RootWidget.cpp
@@ -4,7 +4,6 @@
#include "Painter.h"
#include "WindowManager.h"
#include "FrameBuffer.h"
-#include <cstdio>
RootWidget::RootWidget()
{
diff --git a/Widgets/Widget.cpp b/Widgets/Widget.cpp
index 4014072eb9..eccf5ecbb8 100644
--- a/Widgets/Widget.cpp
+++ b/Widgets/Widget.cpp
@@ -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()
diff --git a/Widgets/WindowManager.cpp b/Widgets/WindowManager.cpp
index b5dcdbd429..8aeacaf5f0 100644
--- a/Widgets/WindowManager.cpp
+++ b/Widgets/WindowManager.cpp
@@ -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()
diff --git a/Widgets/WindowManager.h b/Widgets/WindowManager.h
index 074558105c..5d6365b75c 100644
--- a/Widgets/WindowManager.h
+++ b/Widgets/WindowManager.h
@@ -34,6 +34,8 @@ public:
void repaint();
void move_to_front(Window&);
+ static void initialize();
+
private:
WindowManager();
~WindowManager();