dialog: support Sandboxed_runtime::Event_handler

This allows applications to get hold of the raw input events,
in particular keyboard input.

Issue #5008
This commit is contained in:
Norman Feske 2023-11-15 18:29:31 +01:00 committed by Christian Helmuth
parent 767ea7f5b1
commit 9fae8a7532
2 changed files with 24 additions and 2 deletions

View File

@ -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<View, Top_level_dialog::Name>;
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_ */

View File

@ -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 });
}