summaryrefslogtreecommitdiff
path: root/Kernel/ProcessGUI.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-13 01:59:38 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-13 02:02:34 +0100
commit8f8c8d1ca3443ca094ee80beb520110b948a0395 (patch)
tree7784d78a807b7ca178a65d4e3b32f931cb874b15 /Kernel/ProcessGUI.cpp
parentbecc2c7fa5026e96db6d8dde6d85989913a3f794 (diff)
downloadserenity-8f8c8d1ca3443ca094ee80beb520110b948a0395.zip
Start working on a GUI kernel API.
Diffstat (limited to 'Kernel/ProcessGUI.cpp')
-rw-r--r--Kernel/ProcessGUI.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/Kernel/ProcessGUI.cpp b/Kernel/ProcessGUI.cpp
new file mode 100644
index 0000000000..7b19a550e1
--- /dev/null
+++ b/Kernel/ProcessGUI.cpp
@@ -0,0 +1,77 @@
+#include "Process.h"
+#include "MemoryManager.h"
+#include <LibC/errno_numbers.h>
+#include <Widgets/AbstractScreen.h>
+#include <Widgets/FrameBuffer.h>
+#include <Widgets/EventLoop.h>
+#include <Widgets/Font.h>
+#include <Widgets/Widget.h>
+#include <Widgets/Window.h>
+#include <Widgets/WindowManager.h>
+
+void Process::initialize_gui_statics()
+{
+ Font::initialize();
+ FrameBuffer::initialize();
+ EventLoop::initialize();
+ WindowManager::initialize();
+ AbstractScreen::initialize();
+
+ new EventLoop;
+}
+
+static void wait_for_gui_server()
+{
+ // FIXME: Time out after a while and return an error.
+ while (!EventLoop::main().running())
+ sleep(10);
+}
+
+int Process::gui$create_window(const GUI_CreateWindowParameters* user_params)
+{
+ wait_for_gui_server();
+
+ if (!validate_read_typed(user_params))
+ return -EFAULT;
+
+ GUI_CreateWindowParameters params = *user_params;
+ Rect rect { params.rect.x, params.rect.y, params.rect.width, params.rect.height };
+
+ if (rect.is_empty())
+ return -EINVAL;
+
+ ProcessPagingScope scope(EventLoop::main().server_process());
+
+ auto* window = new Window;
+ if (!window)
+ return -ENOMEM;
+
+ int window_id = m_windows.size();
+ m_windows.append(window);
+
+ window->setTitle(params.title);
+ window->setRect(rect);
+
+ auto* main_widget = new Widget;
+ window->setMainWidget(main_widget);
+ main_widget->setWindowRelativeRect({ 0, 0, rect.width(), rect.height() });
+ main_widget->setBackgroundColor(params.background_color);
+ main_widget->setFillWithBackgroundColor(true);
+ dbgprintf("%s<%u> gui$create_window: %d with rect {%d,%d %dx%d}\n", name().characters(), pid(), window_id, rect.x(), rect.y(), rect.width(), rect.height());
+
+ return window_id;
+}
+
+int Process::gui$destroy_window(int window_id)
+{
+ wait_for_gui_server();
+ dbgprintf("%s<%u> gui$destroy_window (window_id=%d)\n", name().characters(), pid(), window_id);
+ if (window_id < 0)
+ return -EINVAL;
+ if (window_id >= static_cast<int>(m_windows.size()))
+ return -EBADWIN;
+ auto* window = m_windows[window_id];
+ m_windows.remove(window_id);
+ window->deleteLater();
+ return 0;
+}