Skip to content

Commit

Permalink
hrund-device: Initial implementation of mouse event broadcast.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Dec 26, 2024
1 parent 2413bf1 commit c739117
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 38 deletions.
29 changes: 18 additions & 11 deletions src/srvs/grund-bus/bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,27 +179,34 @@ Karm::Res<> Bus::attach(Strong<Endpoint> 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");
}

Expand Down
2 changes: 2 additions & 0 deletions src/srvs/grund-bus/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ struct Bus : public Meta::Pinned {

Res<> attach(Strong<Endpoint> endpoint);

void _broadcast(Sys::Message &msg);

Res<> dispatch(Sys::Message &msg);

Res<> startService(Str id);
Expand Down
3 changes: 3 additions & 0 deletions src/srvs/grund-device/ps2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ Res<> Mouse::decode() {
if (_hasWheel)
scroll = (i8)_buf[3];

auto event = App::makeEvent<App::MouseEvent>(App::MouseEvent::MOVE, 0, scroll, Math::Vec2i{offx, offy});
logInfo("ps2: mouse move {} {} {}", offx, offy, scroll);
try$(bubble(*event));

return Ok();
}

Expand Down
1 change: 0 additions & 1 deletion src/srvs/grund-seat/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Async::Task<> serv(Sys::Context &ctx) {
logInfo("service started");
while (true) {
co_trya$(rpc.recvAsync());
logDebug("received message from system");
}
}

Expand Down
76 changes: 50 additions & 26 deletions src/srvs/grund-shell/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <hideo-shell/app.h>
#include <karm-image/loader.h>
#include <karm-sys/entry.h>
#include <karm-sys/rpc.h>
#include <mdi/calculator.h>
#include <mdi/cog.h>
#include <mdi/counter.h>
Expand All @@ -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<Hideo::Shell::Manifest>(Mdi::INFORMATION_OUTLINE, "About"s, Gfx::BLUE_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::CALCULATOR, "Calculator"s, Gfx::ORANGE_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::PALETTE_SWATCH, "Color Picker"s, Gfx::RED_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::COUNTER, "Counter"s, Gfx::GREEN_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::DUCK, "Demos"s, Gfx::YELLOW_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::FILE, "Files"s, Gfx::ORANGE_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::FORMAT_FONT, "Fonts"s, Gfx::BLUE_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::EMOTICON, "Hello World"s, Gfx::RED_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::IMAGE, "Icons"s, Gfx::GREEN_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::IMAGE, "Image Viewer"s, Gfx::YELLOW_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::COG, "Settings"s, Gfx::ZINC_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::TABLE, "Spreadsheet"s, Gfx::GREEN_RAMP),
makeStrong<Hideo::Shell::Manifest>(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<App::MouseEvent>()) {
auto event = msg.unpack<App::MouseEvent>();
logDebug("mouse event!");
} else if (msg.is<App::KeyboardEvent>()) {
auto event = msg.unpack<App::MouseEvent>();
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<Hideo::Shell::Manifest>(Mdi::INFORMATION_OUTLINE, "About"s, Gfx::BLUE_RAMP),
// makeStrong<Hideo::Shell::Manifest>(Mdi::CALCULATOR, "Calculator"s, Gfx::ORANGE_RAMP),
// makeStrong<Hideo::Shell::Manifest>(Mdi::PALETTE_SWATCH, "Color Picker"s, Gfx::RED_RAMP),
// makeStrong<Hideo::Shell::Manifest>(Mdi::COUNTER, "Counter"s, Gfx::GREEN_RAMP),
// makeStrong<Hideo::Shell::Manifest>(Mdi::DUCK, "Demos"s, Gfx::YELLOW_RAMP),
// makeStrong<Hideo::Shell::Manifest>(Mdi::FILE, "Files"s, Gfx::ORANGE_RAMP),
// makeStrong<Hideo::Shell::Manifest>(Mdi::FORMAT_FONT, "Fonts"s, Gfx::BLUE_RAMP),
// makeStrong<Hideo::Shell::Manifest>(Mdi::EMOTICON, "Hello World"s, Gfx::RED_RAMP),
// makeStrong<Hideo::Shell::Manifest>(Mdi::IMAGE, "Icons"s, Gfx::GREEN_RAMP),
// makeStrong<Hideo::Shell::Manifest>(Mdi::IMAGE, "Image Viewer"s, Gfx::YELLOW_RAMP),
// makeStrong<Hideo::Shell::Manifest>(Mdi::COG, "Settings"s, Gfx::ZINC_RAMP),
// makeStrong<Hideo::Shell::Manifest>(Mdi::TABLE, "Spreadsheet"s, Gfx::GREEN_RAMP),
// makeStrong<Hideo::Shell::Manifest>(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();
}

0 comments on commit c739117

Please sign in to comment.