From c73911790a7f5a1d1f4dc66b81329abdb0f0b328 Mon Sep 17 00:00:00 2001 From: VAN BOSSUYT Nicolas Date: Thu, 26 Dec 2024 23:02:58 +0100 Subject: [PATCH] hrund-device: Initial implementation of mouse event broadcast. --- src/srvs/grund-bus/bus.cpp | 29 ++++++++----- src/srvs/grund-bus/bus.h | 2 + src/srvs/grund-device/ps2.cpp | 3 ++ src/srvs/grund-seat/main.cpp | 1 - src/srvs/grund-shell/main.cpp | 76 +++++++++++++++++++++++------------ 5 files changed, 73 insertions(+), 38 deletions(-) diff --git a/src/srvs/grund-bus/bus.cpp b/src/srvs/grund-bus/bus.cpp index 75c755462a7..bc27d051cde 100644 --- a/src/srvs/grund-bus/bus.cpp +++ b/src/srvs/grund-bus/bus.cpp @@ -179,27 +179,34 @@ Karm::Res<> Bus::attach(Strong endpoint) { return Ok(); } -Res<> Bus::dispatch(Sys::Message &msg) { +void Bus::_broadcast(Sys::Message &msg) { for (auto &endpoint : _endpoints) { - bool broadcast = msg.header().to == Sys::Port::BROADCAST and - msg.header().from != endpoint->port(); + if (msg.header().from != endpoint->port()) { + auto res = endpoint->send(msg); + if (not res) + logError("{}: send failed: {}", endpoint->id(), res); + } + } +} + +Res<> Bus::dispatch(Sys::Message &msg) { + if (msg.header().to == Sys::Port::BROADCAST) { + _broadcast(msg); + return Ok(); + } - if (broadcast or endpoint->port() == msg.header().to) { + for (auto &endpoint : _endpoints) { + if (endpoint->port() == msg.header().to) { auto res = endpoint->send(msg); if (not res) { logError("{}: send failed: {}", endpoint->id(), res); - if (not broadcast) - return res; + return res; } - if (not broadcast) - return Ok(); + return Ok(); } } - if (msg.header().to == Sys::Port::BROADCAST) - return Ok(); - return Error::notFound("service not found"); } diff --git a/src/srvs/grund-bus/bus.h b/src/srvs/grund-bus/bus.h index 368efac974a..b395c8b431f 100644 --- a/src/srvs/grund-bus/bus.h +++ b/src/srvs/grund-bus/bus.h @@ -76,6 +76,8 @@ struct Bus : public Meta::Pinned { Res<> attach(Strong endpoint); + void _broadcast(Sys::Message &msg); + Res<> dispatch(Sys::Message &msg); Res<> startService(Str id); diff --git a/src/srvs/grund-device/ps2.cpp b/src/srvs/grund-device/ps2.cpp index e5a8b1f0740..45a5ece4be3 100644 --- a/src/srvs/grund-device/ps2.cpp +++ b/src/srvs/grund-device/ps2.cpp @@ -186,7 +186,10 @@ Res<> Mouse::decode() { if (_hasWheel) scroll = (i8)_buf[3]; + auto event = App::makeEvent(App::MouseEvent::MOVE, 0, scroll, Math::Vec2i{offx, offy}); logInfo("ps2: mouse move {} {} {}", offx, offy, scroll); + try$(bubble(*event)); + return Ok(); } diff --git a/src/srvs/grund-seat/main.cpp b/src/srvs/grund-seat/main.cpp index 5f04d7cea79..b40549cfc27 100644 --- a/src/srvs/grund-seat/main.cpp +++ b/src/srvs/grund-seat/main.cpp @@ -9,7 +9,6 @@ Async::Task<> serv(Sys::Context &ctx) { logInfo("service started"); while (true) { co_trya$(rpc.recvAsync()); - logDebug("received message from system"); } } diff --git a/src/srvs/grund-shell/main.cpp b/src/srvs/grund-shell/main.cpp index 0760348e00d..6f97062b76d 100644 --- a/src/srvs/grund-shell/main.cpp +++ b/src/srvs/grund-shell/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -16,31 +17,54 @@ #include "host.h" -Async::Task<> entryPointAsync(Sys::Context &ctx) { - Hideo::Shell::State state = { - .isMobile = false, - .dateTime = Sys::dateTime(), - .background = co_try$(Image::loadOrFallback("bundle://hideo-shell/wallpaper.qoi"_url)), - .noti = {}, - .manifests = { - makeStrong(Mdi::INFORMATION_OUTLINE, "About"s, Gfx::BLUE_RAMP), - makeStrong(Mdi::CALCULATOR, "Calculator"s, Gfx::ORANGE_RAMP), - makeStrong(Mdi::PALETTE_SWATCH, "Color Picker"s, Gfx::RED_RAMP), - makeStrong(Mdi::COUNTER, "Counter"s, Gfx::GREEN_RAMP), - makeStrong(Mdi::DUCK, "Demos"s, Gfx::YELLOW_RAMP), - makeStrong(Mdi::FILE, "Files"s, Gfx::ORANGE_RAMP), - makeStrong(Mdi::FORMAT_FONT, "Fonts"s, Gfx::BLUE_RAMP), - makeStrong(Mdi::EMOTICON, "Hello World"s, Gfx::RED_RAMP), - makeStrong(Mdi::IMAGE, "Icons"s, Gfx::GREEN_RAMP), - makeStrong(Mdi::IMAGE, "Image Viewer"s, Gfx::YELLOW_RAMP), - makeStrong(Mdi::COG, "Settings"s, Gfx::ZINC_RAMP), - makeStrong(Mdi::TABLE, "Spreadsheet"s, Gfx::GREEN_RAMP), - makeStrong(Mdi::WIDGETS, "Widget Gallery"s, Gfx::BLUE_RAMP), - }, - .instances = {} - }; +namespace Grund::Shell { + +Async::Task<> servAsync(Sys::Context &ctx) { + auto rpc = Sys::Rpc::create(ctx); - auto app = Hideo::Shell::app(std::move(state)); - auto host = co_try$(Grund::Shell::makeHost(ctx, app)); - co_return host->run(); + while (true) { + auto msg = co_trya$(rpc.recvAsync()); + + if (msg.is()) { + auto event = msg.unpack(); + logDebug("mouse event!"); + } else if (msg.is()) { + auto event = msg.unpack(); + logDebug("keyboard event!"); + } else { + logWarn("unsupported event: {}", msg.header()); + } + } +} + +} // namespace Grund::Shell + +Async::Task<> entryPointAsync(Sys::Context &ctx) { + return Grund::Shell::servAsync(ctx); + // Hideo::Shell::State state = { + // .isMobile = false, + // .dateTime = Sys::dateTime(), + // .background = co_try$(Image::loadOrFallback("bundle://hideo-shell/wallpaper.qoi"_url)), + // .noti = {}, + // .manifests = { + // makeStrong(Mdi::INFORMATION_OUTLINE, "About"s, Gfx::BLUE_RAMP), + // makeStrong(Mdi::CALCULATOR, "Calculator"s, Gfx::ORANGE_RAMP), + // makeStrong(Mdi::PALETTE_SWATCH, "Color Picker"s, Gfx::RED_RAMP), + // makeStrong(Mdi::COUNTER, "Counter"s, Gfx::GREEN_RAMP), + // makeStrong(Mdi::DUCK, "Demos"s, Gfx::YELLOW_RAMP), + // makeStrong(Mdi::FILE, "Files"s, Gfx::ORANGE_RAMP), + // makeStrong(Mdi::FORMAT_FONT, "Fonts"s, Gfx::BLUE_RAMP), + // makeStrong(Mdi::EMOTICON, "Hello World"s, Gfx::RED_RAMP), + // makeStrong(Mdi::IMAGE, "Icons"s, Gfx::GREEN_RAMP), + // makeStrong(Mdi::IMAGE, "Image Viewer"s, Gfx::YELLOW_RAMP), + // makeStrong(Mdi::COG, "Settings"s, Gfx::ZINC_RAMP), + // makeStrong(Mdi::TABLE, "Spreadsheet"s, Gfx::GREEN_RAMP), + // makeStrong(Mdi::WIDGETS, "Widget Gallery"s, Gfx::BLUE_RAMP), + // }, + // .instances = {} + // }; + // + // auto app = Hideo::Shell::app(std::move(state)); + // auto host = co_try$(Grund::Shell::makeHost(ctx, app)); + // co_return host->run(); }