@@ -7,6 +7,7 @@ module Karm.App;
77import Karm.Core;
88import Karm.Gfx;
99import Karm.Sys;
10+ import Karm.Ref;
1011import Strata.Protos;
1112import Karm.Logger;
1213
@@ -58,22 +59,20 @@ struct SkiftWindow : Window {
5859};
5960
6061struct SkiftApplication : Application {
61- Rc<Sys::Endpoint> _endpoint;
62- Sys::Port _shell;
62+ Sys::IpcClient _shell;
6363 Map<usize, SkiftWindow*> _windows;
6464 bool _exited = false ;
6565
66- explicit SkiftApplication (Rc< Sys::Endpoint> endpoint, Sys::Port shell)
67- : _endpoint(endpoint), _shell(shell) {}
66+ explicit SkiftApplication (Sys::IpcClient shell)
67+ : _shell(std::move( shell) ) {}
6868
6969 void detachWindow (Strata::IShell::WindowId id) {
70- (void )_endpoint-> send ( _shell, Strata::IShell::WindowDestroy{id});
70+ (void )_shell. notify ( Strata::IShell::WindowDestroy{id});
7171 _windows.del ((usize)id);
7272 }
7373
7474 Async::Task<Rc<Window>> createWindowAsync (WindowProps const & props, Async::CancellationToken ct) override {
75- auto [id, actual] = co_trya$(_endpoint->callAsync (
76- _shell,
75+ auto [id, actual] = co_trya$(_shell.callAsync (
7776 Strata::IShell::WindowCreate{
7877 props.size ,
7978 App::formFactor
@@ -85,8 +84,7 @@ struct SkiftApplication : Application {
8584
8685 auto surface = co_try$(Strata::Protos::Surface::create (actual.size ));
8786
88- co_trya$(_endpoint->callAsync (
89- _shell,
87+ co_trya$(_shell.callAsync (
9088 Strata::IShell::WindowAttach{
9189 id,
9290 surface,
@@ -100,7 +98,7 @@ struct SkiftApplication : Application {
10098 co_return Ok (window);
10199 }
102100
103- Res<> _handleWindowEvent (Sys::Message & message, Rc<Handler> handler) {
101+ Res<> _handleWindowEvent (Sys::IpcMessage & message, Rc<Handler> handler) {
104102 auto [windowId, payload] = try $(message.unpack <Strata::IShell::WindowEvent>());
105103 payload.visit ([&]<typename E>(E const & event) {
106104 using T = Meta::RemoveConstVolatileRef<E>;
@@ -114,7 +112,7 @@ struct SkiftApplication : Application {
114112 return Ok ();
115113 }
116114
117- Res<> _handleWindowUpdate (Sys::Message & message, Rc<Handler> handler) {
115+ Res<> _handleWindowUpdate (Sys::IpcMessage & message, Rc<Handler> handler) {
118116 auto [windowId, props] = try $(message.unpack <Strata::IShell::WindowUpdate>());
119117 auto * window = try $(_windows.tryGet (windowId).okOr (Error::invalidInput (" no such window" )));
120118 // FIXME: We should probably have a separated hello message that pass stuff like color scheme and form factor
@@ -127,7 +125,7 @@ struct SkiftApplication : Application {
127125 }
128126
129127 Res<> _pollMessages (Rc<Handler> handler) {
130- while (auto maybeMessage = _endpoint-> tryRecv ()) {
128+ while (auto maybeMessage = _shell. poll ()) {
131129 auto & message = maybeMessage.unwrap ();
132130 if (message.is <Strata::IShell::WindowEvent>())
133131 try $(_handleWindowEvent (message, handler));
@@ -153,8 +151,7 @@ struct SkiftApplication : Application {
153151
154152 auto newSurface = co_try$(Strata::Protos::Surface::create (size));
155153
156- co_trya$(_endpoint->callAsync (
157- _shell,
154+ co_trya$(_shell.callAsync (
158155 Strata::IShell::WindowAttach{
159156 id,
160157 newSurface,
@@ -188,8 +185,7 @@ struct SkiftApplication : Application {
188185 if (not window->_dirty )
189186 continue ;
190187
191- co_trya$(_endpoint->callAsync (
192- _shell,
188+ co_trya$(_shell.callAsync (
193189 Strata::IShell::WindowFlip{
194190 id,
195191 window->bound (),
@@ -220,30 +216,16 @@ void SkiftWindow::releaseSurface(Slice<Math::Recti>) {
220216
221217void SkiftWindow::drag (DragEvent e) {
222218 if (e.type == DragEvent::START)
223- (void )_application._endpoint -> send (_application. _shell , Strata::IShell::WindowMove{_id});
219+ (void )_application._shell . notify ( Strata::IShell::WindowMove{_id});
224220}
225221
226222void SkiftWindow::snap (Snap s) {
227- (void )_application._endpoint -> send (_application. _shell , Strata::IShell::WindowSnap{_id, s});
223+ (void )_application._shell . notify ( Strata::IShell::WindowSnap{_id, s});
228224}
229225
230- Async::Task<Rc<Application>> createAppAsync (Sys::Context& ctx, ApplicationProps const &, Async::CancellationToken ct) {
231- auto endpoint = makeRc<Sys::Endpoint>(
232- std::move (Sys::useChannel (ctx).con )
233- );
234-
235- auto maybeShellPort = co_await endpoint->callAsync (
236- Sys::Port::BUS,
237- Strata::IBus::Locate{
238- " strata-shell" s,
239- },
240- ct
241- );
242-
243- if (not maybeShellPort)
244- co_return maybeShellPort.none ();
245-
246- co_return Ok (makeRc<SkiftApplication>(endpoint, maybeShellPort.unwrap ()));
226+ Async::Task<Rc<Application>> createAppAsync (Sys::Context&, ApplicationProps const &, Async::CancellationToken ct) {
227+ auto shell = co_trya$(Sys::IpcClient::connectAsync (" ipc://strata-shell" _url, ct));
228+ co_return Ok (makeRc<SkiftApplication>(std::move (shell)));
247229}
248230
249231} // namespace Karm::App::_Embed
0 commit comments