Skip to content

Commit

Permalink
grund-shell: Moving cursor.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Dec 26, 2024
1 parent 1fdfb0a commit f54540e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/kernel/hjert-core/syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,8 @@ Res<> doPoll(Task &self, Hj::Cap cap, UserSlice<MutSlice<Hj::Event>> events, Use

try$(self.block([&] {
auto events = obj->pollEvents();
if (events.len() > 0) {
if (events.len() > 0)
return TimeStamp::epoch();
}
return until;
}));

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

auto event = App::makeEvent<App::MouseEvent>(App::MouseEvent::MOVE, 0, scroll, Math::Vec2i{offx, offy});
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));

Expand Down
10 changes: 7 additions & 3 deletions src/srvs/grund-shell/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@

namespace Grund::Shell {

Res<Strong<RootHost>> makeHost(Sys::Context &ctx, Ui::Child root) {
Res<Gfx::MutPixels> openFramebuffer(Sys::Context &ctx) {
auto &handover = useHandover(ctx);

auto *fb = handover.findTag(Handover::Tag::FB);
auto fbVmo = try$(Hj::Vmo::create(Hj::ROOT, fb->start, fb->size, Hj::VmoFlags::DMA));
try$(fbVmo.label("framebuffer"));

static auto fbRange = try$(Hj::map(fbVmo, Hj::MapFlags::READ | Hj::MapFlags::WRITE));

logInfo("fb: {x}-{x} {}x{}, {} stride", fbRange.range().start, fbRange.range().end(), fb->fb.width, fb->fb.height, fb->fb.pitch);

Gfx::MutPixels front = {
return Ok(Gfx::MutPixels{
fbRange.mutBytes().buf(),
{fb->fb.width, fb->fb.height},
fb->fb.pitch,
Gfx::BGRA8888,
};
});
}

Res<Strong<RootHost>> makeHost(Sys::Context &ctx, Ui::Child root) {
Gfx::MutPixels front = try$(openFramebuffer(ctx));
auto back = Gfx::Surface::alloc(
front.size(), Gfx::BGRA8888
);
Expand Down
2 changes: 2 additions & 0 deletions src/srvs/grund-shell/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ struct RootHost :
}
};

Res<Gfx::MutPixels> openFramebuffer(Sys::Context &ctx);

Res<Strong<RootHost>> makeHost(Sys::Context &ctx, Ui::Child root);

} // namespace Grund::Shell
19 changes: 18 additions & 1 deletion src/srvs/grund-shell/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,29 @@ namespace Grund::Shell {

Async::Task<> servAsync(Sys::Context &ctx) {
auto rpc = Sys::Rpc::create(ctx);
auto fontbuffer = co_try$(openFramebuffer(ctx));

auto backbuffer = Gfx::Surface::alloc(fontbuffer.size(), Gfx::BGRA8888);
Gfx::CpuCanvas g;

Math::Vec2i mouspos = fontbuffer.size() / 2;

while (true) {
g.begin(*backbuffer);
g.clear(Ui::GRAY950);
g.beginPath();
g.fillStyle(Gfx::WHITE.withOpacity(0.25));
g.ellipse(Math::Ellipsef{mouspos.cast<f64>(), {16, 16}});
g.fill(Gfx::FillRule::EVENODD);
g.end();

Gfx::blitUnsafe(fontbuffer, *backbuffer);

auto msg = co_trya$(rpc.recvAsync());

if (msg.is<App::MouseEvent>()) {
auto event = msg.unpack<App::MouseEvent>();
auto event = msg.unpack<App::MouseEvent>().unwrap();
mouspos = mouspos + event.delta;
logDebug("mouse event!");
} else if (msg.is<App::KeyboardEvent>()) {
auto event = msg.unpack<App::MouseEvent>();
Expand Down

0 comments on commit f54540e

Please sign in to comment.