1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 03:08:13 +00:00

WindowServer: Begin refactoring towards a fully asynchronous protocol.

In order to move the WindowServer to userspace, I have to eliminate its
dependence on system call facilities. The communication channel with each
client needs to be message-based in both directions.
This commit is contained in:
Andreas Kling 2019-02-13 17:54:30 +01:00
parent 96352ab735
commit 4f98a35beb
18 changed files with 242 additions and 91 deletions

View file

@ -2,6 +2,7 @@
#include <Kernel/Process.h>
#include <AK/Lock.h>
#include <LibC/errno_numbers.h>
#include <WindowServer/WSMessageLoop.h>
//#define GUIEVENTDEVICE_DEBUG
@ -32,7 +33,7 @@ ssize_t GUIEventDevice::read(Process& process, byte* buffer, size_t size)
return size;
}
ssize_t GUIEventDevice::write(Process&, const byte*, size_t)
ssize_t GUIEventDevice::write(Process& process, const byte* data, size_t size)
{
return -EINVAL;
return WSMessageLoop::the().on_receive_from_client(process.gui_client_id(), data, size);
}

View file

@ -1,6 +1,7 @@
#pragma once
#include <Kernel/CharacterDevice.h>
#include <Kernel/DoubleBuffer.h>
class GUIEventDevice final : public CharacterDevice {
public:

View file

@ -68,6 +68,8 @@ struct GUI_Event {
WindowDeactivated,
WindowCloseRequest,
MenuItemActivated,
DidCreateMenubar,
DidDestroyMenubar,
};
Type type { Invalid };
int window_id { -1 };
@ -90,12 +92,30 @@ struct GUI_Event {
bool shift : 1;
} key;
struct {
int menubar_id;
int menu_id;
unsigned identifier;
} menu;
};
};
struct GUI_ClientMessage {
enum Type : unsigned {
Invalid,
CreateMenubar,
DestroyMenubar,
};
Type type { Invalid };
int window_id { -1 };
union {
struct {
int menubar_id;
int menu_id;
} menu;
};
};
inline Rect::Rect(const GUI_Rect& r) : Rect(r.location, r.size) { }
inline Point::Point(const GUI_Point& p) : Point(p.x, p.y) { }
inline Size::Size(const GUI_Size& s) : Size(s.width, s.height) { }

View file

@ -230,8 +230,6 @@ public:
int gui$get_window_rect(int window_id, GUI_Rect*);
int gui$set_window_rect(int window_id, const GUI_Rect*);
int gui$set_global_cursor_tracking_enabled(int window_id, bool enabled);
int gui$menubar_create();
int gui$menubar_destroy(int menubar_id);
int gui$menubar_add_menu(int menubar_id, int menu_id);
int gui$menu_create(const char* name);
int gui$menu_destroy(int menu_id);
@ -313,6 +311,8 @@ public:
bool has_used_fpu() const { return m_has_used_fpu; }
void set_has_used_fpu(bool b) { m_has_used_fpu = b; }
int gui_client_id() const { return (int)this; }
private:
friend class MemoryManager;
friend class Scheduler;
@ -420,7 +420,6 @@ private:
Vector<GUI_Event> m_gui_events;
Lock m_gui_events_lock;
int m_next_window_id { 1 };
bool m_has_created_menus { false };
dword m_wakeup_requested { false };
bool m_has_used_fpu { false };

View file

@ -259,7 +259,7 @@ int Process::gui$set_global_cursor_tracking_enabled(int window_id, bool enabled)
void Process::destroy_all_menus()
{
if (!m_has_created_menus)
if (!WSMessageLoop::the().running())
return;
WSWindowManager::the().destroy_all_menus(*this);
}
@ -292,17 +292,6 @@ DisplayInfo Process::set_video_resolution(int width, int height)
return info;
}
int Process::gui$menubar_create()
{
m_has_created_menus = true;
return WSWindowManager::the().api$menubar_create();
}
int Process::gui$menubar_destroy(int menubar_id)
{
return WSWindowManager::the().api$menubar_destroy(menubar_id);
}
int Process::gui$menubar_add_menu(int menubar_id, int menu_id)
{
return WSWindowManager::the().api$menubar_add_menu(menubar_id, menu_id);
@ -312,7 +301,6 @@ int Process::gui$menu_create(const char* name)
{
if (!validate_read_str(name))
return -EFAULT;
m_has_created_menus = true;
return WSWindowManager::the().api$menu_create(String(name));
}

View file

@ -223,10 +223,6 @@ static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2,
return current->sys$rmdir((const char*)arg1);
case Syscall::SC_chmod:
return current->sys$chmod((const char*)arg1, (mode_t)arg2);
case Syscall::SC_gui_menubar_create:
return current->gui$menubar_create();
case Syscall::SC_gui_menubar_destroy:
return current->gui$menubar_destroy((int)arg1);
case Syscall::SC_gui_menubar_add_menu:
return current->gui$menubar_add_menu((int)arg1, (int)arg2);
case Syscall::SC_gui_menu_create:

View file

@ -85,8 +85,6 @@
__ENUMERATE_SYSCALL(rmdir) \
__ENUMERATE_SYSCALL(chmod) \
__ENUMERATE_SYSCALL(usleep) \
__ENUMERATE_SYSCALL(gui_menubar_create) \
__ENUMERATE_SYSCALL(gui_menubar_destroy) \
__ENUMERATE_SYSCALL(gui_menubar_add_menu) \
__ENUMERATE_SYSCALL(gui_menu_create) \
__ENUMERATE_SYSCALL(gui_menu_destroy) \