mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 23:17:44 +00:00
Make it possible for userspace to alter window title/geometry.
I'm not in love with this syscall API but it allows me to make progress.
This commit is contained in:
parent
8eae89a405
commit
dbe83f3a83
11 changed files with 78 additions and 17 deletions
|
@ -26,7 +26,7 @@ struct GUI_Rect {
|
|||
GUI_Size size;
|
||||
};
|
||||
|
||||
struct GUI_CreateWindowParameters {
|
||||
struct GUI_WindowParameters {
|
||||
GUI_Rect rect;
|
||||
Color background_color;
|
||||
unsigned flags { 0 };
|
||||
|
|
|
@ -192,10 +192,12 @@ public:
|
|||
Unix::clock_t sys$times(Unix::tms*);
|
||||
int sys$utime(const char* pathname, const struct Unix::utimbuf*);
|
||||
|
||||
int gui$create_window(const GUI_CreateWindowParameters*);
|
||||
int gui$create_window(const GUI_WindowParameters*);
|
||||
int gui$destroy_window(int window_id);
|
||||
int gui$get_window_backing_store(int window_id, GUI_WindowBackingStoreInfo*);
|
||||
int gui$invalidate_window(int window_id, const GUI_Rect*);
|
||||
int gui$get_window_parameters(int window_id, GUI_WindowParameters*);
|
||||
int gui$set_window_parameters(int window_id, const GUI_WindowParameters*);
|
||||
|
||||
DisplayInfo get_display_info();
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ static void wait_for_gui_server()
|
|||
sleep(10);
|
||||
}
|
||||
|
||||
int Process::gui$create_window(const GUI_CreateWindowParameters* user_params)
|
||||
int Process::gui$create_window(const GUI_WindowParameters* user_params)
|
||||
{
|
||||
wait_for_gui_server();
|
||||
|
||||
|
@ -122,3 +122,33 @@ int Process::gui$invalidate_window(int window_id, const GUI_Rect* rect)
|
|||
WSEventLoop::the().server_process().request_wakeup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Process::gui$get_window_parameters(int window_id, GUI_WindowParameters* params)
|
||||
{
|
||||
if (window_id < 0)
|
||||
return -EINVAL;
|
||||
if (!validate_write_typed(params))
|
||||
return -EFAULT;
|
||||
auto it = m_windows.find(window_id);
|
||||
if (it == m_windows.end())
|
||||
return -EBADWINDOW;
|
||||
auto& window = *(*it).value;
|
||||
params->rect = window.rect();
|
||||
strcpy(params->title, window.title().characters());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Process::gui$set_window_parameters(int window_id, const GUI_WindowParameters* params)
|
||||
{
|
||||
if (window_id < 0)
|
||||
return -EINVAL;
|
||||
if (!validate_read_typed(params))
|
||||
return -EFAULT;
|
||||
auto it = m_windows.find(window_id);
|
||||
if (it == m_windows.end())
|
||||
return -EBADWINDOW;
|
||||
auto& window = *(*it).value;
|
||||
window.set_rect(params->rect);
|
||||
window.set_title(params->title);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -192,13 +192,17 @@ static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2,
|
|||
case Syscall::SC_sync:
|
||||
return sync();
|
||||
case Syscall::SC_gui_create_window:
|
||||
return current->gui$create_window((const GUI_CreateWindowParameters*)arg1);
|
||||
return current->gui$create_window((const GUI_WindowParameters*)arg1);
|
||||
case Syscall::SC_gui_destroy_window:
|
||||
return current->gui$destroy_window((int)arg1);
|
||||
case Syscall::SC_gui_get_window_backing_store:
|
||||
return current->gui$get_window_backing_store((int)arg1, (GUI_WindowBackingStoreInfo*)arg2);
|
||||
case Syscall::SC_gui_invalidate_window:
|
||||
return current->gui$invalidate_window((int)arg1, (const GUI_Rect*)arg2);
|
||||
case Syscall::SC_gui_set_window_parameters:
|
||||
return current->gui$set_window_parameters((int)arg1, (const GUI_WindowParameters*)arg2);
|
||||
case Syscall::SC_gui_get_window_parameters:
|
||||
return current->gui$get_window_parameters((int)arg1, (GUI_WindowParameters*)arg2);
|
||||
default:
|
||||
kprintf("<%u> int0x80: Unknown function %u requested {%x, %x, %x}\n", current->pid(), function, arg1, arg2, arg3);
|
||||
break;
|
||||
|
|
|
@ -72,6 +72,8 @@
|
|||
__ENUMERATE_SYSCALL(gui_get_window_backing_store) \
|
||||
__ENUMERATE_SYSCALL(gui_invalidate_window) \
|
||||
__ENUMERATE_SYSCALL(select) \
|
||||
__ENUMERATE_SYSCALL(gui_get_window_parameters) \
|
||||
__ENUMERATE_SYSCALL(gui_set_window_parameters) \
|
||||
|
||||
|
||||
struct fd_set;
|
||||
|
|
14
LibC/gui.cpp
14
LibC/gui.cpp
|
@ -3,7 +3,7 @@
|
|||
#include <Kernel/Syscall.h>
|
||||
#include <errno.h>
|
||||
|
||||
int gui_create_window(const GUI_CreateWindowParameters* params)
|
||||
int gui_create_window(const GUI_WindowParameters* params)
|
||||
{
|
||||
int rc = syscall(SC_gui_create_window, params);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
|
@ -20,3 +20,15 @@ int gui_get_window_backing_store(int window_id, GUI_WindowBackingStoreInfo* info
|
|||
int rc = syscall(SC_gui_get_window_backing_store, window_id, info);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int gui_get_window_parameters(int window_id, GUI_WindowParameters* params)
|
||||
{
|
||||
int rc = syscall(SC_gui_get_window_parameters, window_id, params);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int gui_set_window_parameters(int window_id, const GUI_WindowParameters* params)
|
||||
{
|
||||
int rc = syscall(SC_gui_set_window_parameters, window_id, params);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
|
|
@ -5,9 +5,11 @@
|
|||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int gui_create_window(const GUI_CreateWindowParameters* params);
|
||||
int gui_create_window(const GUI_WindowParameters*);
|
||||
int gui_invalidate_window(int window_id, const GUI_Rect*);
|
||||
int gui_get_window_backing_store(int window_id, GUI_WindowBackingStoreInfo* info);
|
||||
int gui_get_window_backing_store(int window_id, GUI_WindowBackingStoreInfo*);
|
||||
int gui_get_window_parameters(int window_id, GUI_WindowParameters*);
|
||||
int gui_set_window_parameters(int window_id, const GUI_WindowParameters*);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ GWindow* GWindow::from_window_id(int window_id)
|
|||
GWindow::GWindow(GObject* parent)
|
||||
: GObject(parent)
|
||||
{
|
||||
GUI_CreateWindowParameters wparams;
|
||||
GUI_WindowParameters wparams;
|
||||
wparams.rect = { { 100, 400 }, { 140, 140 } };
|
||||
wparams.background_color = 0xffc0c0;
|
||||
strcpy(wparams.title, "GWindow");
|
||||
|
@ -55,17 +55,26 @@ GWindow::~GWindow()
|
|||
|
||||
void GWindow::set_title(String&& title)
|
||||
{
|
||||
if (m_title == title)
|
||||
return;
|
||||
|
||||
dbgprintf("GWindow::set_title \"%s\"\n", title.characters());
|
||||
GUI_WindowParameters params;
|
||||
int rc = gui_get_window_parameters(m_window_id, ¶ms);
|
||||
ASSERT(rc == 0);
|
||||
strcpy(params.title, title.characters());;
|
||||
rc = gui_set_window_parameters(m_window_id, ¶ms);
|
||||
ASSERT(rc == 0);
|
||||
m_title = move(title);
|
||||
}
|
||||
|
||||
void GWindow::set_rect(const Rect& rect)
|
||||
{
|
||||
if (m_rect == rect)
|
||||
return;
|
||||
dbgprintf("GWindow::set_rect %d,%d %dx%d\n", m_rect.x(), m_rect.y(), m_rect.width(), m_rect.height());
|
||||
GUI_WindowParameters params;
|
||||
int rc = gui_get_window_parameters(m_window_id, ¶ms);
|
||||
ASSERT(rc == 0);
|
||||
params.rect = rect;
|
||||
rc = gui_set_window_parameters(m_window_id, ¶ms);
|
||||
ASSERT(rc == 0);
|
||||
m_rect = rect;
|
||||
dbgprintf("GWindow::setRect %d,%d %dx%d\n", m_rect.x(), m_rect.y(), m_rect.width(), m_rect.height());
|
||||
}
|
||||
|
||||
void GWindow::event(GEvent& event)
|
||||
|
|
|
@ -14,7 +14,7 @@ void Terminal::create_window()
|
|||
m_pixel_width = m_columns * font().glyph_width() + m_inset * 2;
|
||||
m_pixel_height = (m_rows * (font().glyph_height() + m_line_spacing)) + (m_inset * 2) - m_line_spacing;
|
||||
|
||||
GUI_CreateWindowParameters params;
|
||||
GUI_WindowParameters params;
|
||||
params.rect = { { 300, 300 }, { m_pixel_width, m_pixel_height } };
|
||||
params.background_color = 0x000000;
|
||||
strcpy(params.title, "Terminal");
|
||||
|
|
|
@ -14,7 +14,7 @@ static void paint(GraphicsBitmap& bitmap, int width, int height);
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
GUI_CreateWindowParameters wparams;
|
||||
GUI_WindowParameters wparams;
|
||||
wparams.rect = { { 100, 100 }, { 120, 120 } };
|
||||
wparams.background_color = 0xffc0c0;
|
||||
strcpy(wparams.title, "GUI test app");
|
||||
|
|
|
@ -28,7 +28,7 @@ GWindow* make_font_test_window()
|
|||
{
|
||||
auto* window = new GWindow;
|
||||
window->set_title("Font test");
|
||||
window->set_rect({ 140, 100, 300, 80 });
|
||||
window->set_rect({ 440, 100, 300, 80 });
|
||||
|
||||
auto* widget = new GWidget;
|
||||
window->set_main_widget(widget);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue