diff --git a/repos/gems/include/dialog/sandboxed_runtime.h b/repos/gems/include/dialog/sandboxed_runtime.h index 6f4038d60c..ac2f360a1b 100644 --- a/repos/gems/include/dialog/sandboxed_runtime.h +++ b/repos/gems/include/dialog/sandboxed_runtime.h @@ -43,6 +43,17 @@ class Dialog::Sandboxed_runtime : Noncopyable Allocator &_alloc; Sandbox &_sandbox; + struct Optional_event_handler + { + Event_handler_base *_ptr; + + void handle_event(Event const &event) + { + if (_ptr) _ptr->handle_event(event); + } + + } _optional_event_handler { }; + using Views = Dictionary; Event::Seq_number _global_seq_number { 1 }; @@ -184,6 +195,8 @@ class Dialog::Sandboxed_runtime::View : private Views::Element Event::Seq_number &_global_seq_number; + Optional_event_handler &_optional_event_handler; + Top_level_dialog &_dialog; bool _dialog_hovered = false; /* used to cut hover feedback loop */ @@ -346,6 +359,7 @@ class Dialog::Sandboxed_runtime::View : private Views::Element Views::Element(runtime._views, dialog.name), _env(runtime._env), _alloc(runtime._alloc), _global_seq_number(runtime._global_seq_number), + _optional_event_handler(runtime._optional_event_handler), _dialog(dialog), _menu_view_state(dialog.name, Ram_quota { 4*1024*1024 }, Cap_quota { 200 }) { } @@ -361,18 +375,24 @@ class Dialog::Sandboxed_runtime::Event_handler : Event_handler_base { private: + Sandboxed_runtime &_runtime; + T &_obj; + void (T::*_member) (Event const &); void handle_event(Event const &event) override { (_obj.*_member)(event); } public: Event_handler(Sandboxed_runtime &runtime, T &obj, void (T::*member)(Event const &)) - : _obj(obj), _member(member) + : + _runtime(runtime), _obj(obj), _member(member) { /* register event handler at runtime */ - (void)runtime; + _runtime._optional_event_handler._ptr = this; } + + ~Event_handler() { _runtime._optional_event_handler._ptr = nullptr; } }; #endif /* _INCLUDE__DIALOG__SANDBOXED_RUNTIME_H_ */ diff --git a/repos/gems/src/lib/dialog/sandboxed_runtime.cc b/repos/gems/src/lib/dialog/sandboxed_runtime.cc index 3d514049c9..fcaafe016b 100644 --- a/repos/gems/src/lib/dialog/sandboxed_runtime.cc +++ b/repos/gems/src/lib/dialog/sandboxed_runtime.cc @@ -349,6 +349,8 @@ void Sandboxed_runtime::View::_handle_input_event(Input::Event const &event) _clack_seq_number.construct(_global_seq_number); _try_handle_click_and_clack(); + + _optional_event_handler.handle_event(Event { _global_seq_number, event }); }