diff options
author | Benji Dial <benji@benjidial.net> | 2024-07-29 19:59:52 -0400 |
---|---|---|
committer | Benji Dial <benji@benjidial.net> | 2024-07-29 19:59:52 -0400 |
commit | e6c3a80b01ffb52079783cddd9be6d392d0f7039 (patch) | |
tree | 148276b9878f287bc81638f90249ec4d7b86eaf0 /applications | |
parent | be691582ee12613278af24cb5a824eeb357f6324 (diff) | |
download | hilbert-os-e6c3a80b01ffb52079783cddd9be6d392d0f7039.tar.gz |
redesign compositor protocol, start widget library
Diffstat (limited to 'applications')
-rw-r--r-- | applications/goldman/source/socket.cpp | 143 | ||||
-rw-r--r-- | applications/goldman/source/window.hpp | 6 | ||||
-rw-r--r-- | applications/hello/makefile | 2 | ||||
-rw-r--r-- | applications/hello/source/main.cpp | 43 |
4 files changed, 88 insertions, 106 deletions
diff --git a/applications/goldman/source/socket.cpp b/applications/goldman/source/socket.cpp index b175fe9..9ebd644 100644 --- a/applications/goldman/source/socket.cpp +++ b/applications/goldman/source/socket.cpp @@ -8,114 +8,95 @@ struct socket_state { euler::syscall::stream_handle socket; - std::vector<window *> windows; - daguerre::hilbert_color window_bg = euler::syscall::encode_color(0, 0, 0); + window *w; - bool try_open_window() { + bool try_show_window() { - struct [[gnu::packed]] { - uint32_t width; - uint32_t height; - } body; - - if (euler::syscall::read_from_stream(socket, sizeof(body), &body) != - euler::syscall::stream_result::success) + if (w->is_shown) return false; - window *w = new window(body.width, body.height); - w->contents.fill(window_bg); + r->lock(); + r->add_window(w); + r->unlock(); + r->dispatch_render(); + return true; - uint16_t wid = 0; + } - while (wid < windows.size()) - if (windows[wid] != 0) - ++wid; - else - break; + bool try_hide_window() { - if (wid == windows.size()) - windows.push_back(w); - else - windows[wid] = w; + if (!w->is_shown) + return false; r->lock(); - r->add_window(w); + r->remove_window(w); r->unlock(); - - struct [[gnu::packed]] { - uint8_t type; - uint16_t the_window; - } response { - .type = 0x00, - .the_window = wid - }; - - return - euler::syscall::write_to_stream(socket, sizeof(response), &response) == - euler::syscall::stream_result::success; + r->dispatch_render(); + return true; } - bool try_update_window_region() { + bool try_set_window_dimensions() { - struct [[gnu::packed]] { - uint16_t window; - uint32_t start_x; - uint32_t start_y; - uint32_t width; - uint32_t height; - } body_head; - - if (euler::syscall::read_from_stream(socket, sizeof(body_head), &body_head) != + struct [[gnu::packed]] { uint32_t width; uint32_t height; } packet; + if (euler::syscall::read_from_stream(socket, sizeof(packet), &packet) != euler::syscall::stream_result::success) return false; - std::vector<daguerre::hilbert_color> data(body_head.width * body_head.height); - - if (euler::syscall::read_from_stream(socket, data.size() * 4, data.data()) != - euler::syscall::stream_result::success) + if (packet.width > __INT_MAX__ || packet.height > __INT_MAX__) return false; - daguerre::image<daguerre::hilbert_color> - data_as_image(body_head.width, body_head.height, data.data(), body_head.width, false); - - if (body_head.window >= windows.size() || !windows[body_head.window]) - return false; + r->lock(); + w->contents = daguerre::image<daguerre::hilbert_color>( + packet.width, packet.height); + r->unlock(); + return true; - window *w = windows[body_head.window]; + } - r->lock(); + bool try_set_window_title() { - if ((int)body_head.start_x + data_as_image.width > w->contents.width || - (int)body_head.start_y + data_as_image.height > w->contents.height) { - r->unlock(); + uint32_t length; + if (euler::syscall::read_from_stream(socket, 4, &length) != + euler::syscall::stream_result::success) return false; - } - w->contents.copy_from(data_as_image, body_head.start_x, body_head.start_y); + std::string title; + title.resize(length); + if (euler::syscall::read_from_stream(socket, length, title.data()) != + euler::syscall::stream_result::success) + return false; + r->lock(); + w->title = std::move(title); r->unlock(); r->dispatch_render(); return true; } - bool try_close_window() { - - uint16_t wid; + bool try_update_window_region() { - if (euler::syscall::read_from_stream(socket, 2, &wid) != + struct [[gnu::packed]] { + uint32_t start_x; uint32_t start_y; uint32_t width; uint32_t height; + } packet; + if (euler::syscall::read_from_stream(socket, sizeof(packet), &packet) != euler::syscall::stream_result::success) return false; - if (wid >= windows.size() || !windows[wid]) + static_assert(__INT_MAX__ <= __UINT64_MAX__); + if ((uint64_t)packet.start_x + packet. width > (uint64_t)w->contents. width || + (uint64_t)packet.start_y + packet.height > (uint64_t)w->contents.height) return false; - r->lock(); - - r->remove_window(windows[wid]); - windows[wid] = 0; + daguerre::image<daguerre::hilbert_color> content(packet.width, packet.height); + if (euler::syscall::read_from_stream( + socket, packet.width * packet.height * 4, content.buffer) != + euler::syscall::stream_result::success) + return false; + r->lock(); + w->contents.copy_from(content, packet.start_x, packet.start_y); r->unlock(); r->dispatch_render(); return true; @@ -130,9 +111,11 @@ struct socket_state { return false; switch (type) { - case 0x00: return try_open_window(); - case 0x01: return try_update_window_region(); - case 0x02: return try_close_window(); + case 0x00: return try_show_window(); + case 0x01: return try_hide_window(); + case 0x02: return try_set_window_dimensions(); + case 0x03: return try_set_window_title(); + case 0x04: return try_update_window_region(); default: return false; } @@ -144,18 +127,20 @@ struct socket_state { euler::syscall::set_thread_name("socket thread"); + window *w = new window(); socket_state *state = new socket_state { - .socket = socket, .windows = {} }; + .socket = socket, .w = w }; + while (state->try_process_request()) ; - r->lock(); - for (unsigned i = 0; i < state->windows.size(); ++i) { - r->remove_window(state->windows[i]); - delete state->windows[i]; + if (w->is_shown) { + r->lock(); + r->remove_window(w); + r->unlock(); } - r->unlock(); delete state; + delete w; euler::syscall::close_stream(socket); euler::syscall::end_this_thread(0); diff --git a/applications/goldman/source/window.hpp b/applications/goldman/source/window.hpp index 008af2f..4d5b0e1 100644 --- a/applications/goldman/source/window.hpp +++ b/applications/goldman/source/window.hpp @@ -9,6 +9,10 @@ struct window { int x; int y; - window(int width, int height) : contents(width, height), x(0), y(0) {} + bool is_shown; + + std::string title; + + window() : x(0), y(0), is_shown(false) {} }; diff --git a/applications/hello/makefile b/applications/hello/makefile index 5e12644..ea0b09a 100644 --- a/applications/hello/makefile +++ b/applications/hello/makefile @@ -6,7 +6,7 @@ build/%.cpp.o: source/%.cpp $(HILBERT_CC) -c $^ -o $@ build/hello.elf: $(SOURCES:%=build/%.o) - $(HILBERT_CC) $^ -ldaguerre -o $@ + $(HILBERT_CC) $^ -ldaguerre -lpake -o $@ clean: rm -rf build diff --git a/applications/hello/source/main.cpp b/applications/hello/source/main.cpp index 3f132c6..1f45407 100644 --- a/applications/hello/source/main.cpp +++ b/applications/hello/source/main.cpp @@ -1,37 +1,30 @@ -#include <goldman/protocol.hpp> +#include <pake/widgets/fixed-text.hpp> #include <daguerre/psf.hpp> +#include <pake/window.hpp> -template <class color_t> -void overlay(color_t &to, const bool &from, const color_t ¶m) { - if (from) - to = param; -} +daguerre::fixed_font<bool> *font; int main(int, char **) { - auto bg = euler::syscall::encode_color(0xaa, 0xaa, 0xaa); - auto fg = euler::syscall::encode_color(0x00, 0x00, 0x00); - - daguerre::image<daguerre::hilbert_color> image(300, 200); - image.fill(bg); + font = new daguerre::fixed_font<bool>( + daguerre::try_load_psf("/assets/terminus-bold-18x10.psf").value()); - auto font = daguerre::try_load_psf("/assets/terminus-bold-18x10.psf"); - image.render_text(*font, fg, 10, 10, "Hello, world!", &overlay); + pake::widgets::fixed_text *text = + new pake::widgets::fixed_text("Hello, world!", font, + euler::syscall::encode_color(0xaa, 0xaa, 0xaa), + euler::syscall::encode_color(0x00, 0x00, 0x00)); - euler::syscall::stream_handle s; - euler::syscall::connect_to_socket("hilbert.compositor", s); + pake::window w(300, 200, "Hello"); + w.set_root(std::unique_ptr<pake::widget>(text)); + w.render_and_send_to_compositor(); + w.show(); - goldman::protocol::send_open_window(s, 300, 200); + //TODO: call event loop + euler::syscall::stream_handle h1, h2; + euler::syscall::create_private_socket(h1, h2); uint8_t byte; - euler::syscall::read_from_stream(s, 1, &byte); - - auto w = goldman::protocol::get_window_opened_body(s); - - goldman::protocol::send_update_window_region( - s, w, 0, 0, 300, 200, image.buffer, image.buffer_pitch); - - euler::syscall::read_from_stream(s, 1, &byte); - __builtin_unreachable(); + while (1) + euler::syscall::read_from_stream(h1, 1, &byte); } |