From d8e50dd3668b217e5a094b340329e6517cfb1ef8 Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Thu, 4 Dec 2014 15:30:38 +0100 Subject: [PATCH] nitpicker: add hover report The hover reports provides information about the session currently pointed-to, i.e., hovered session. It can be enabled by the 'hover' attribute of nitpicker's 'report' configuration element Fixes #1442 --- repos/os/src/server/nitpicker/README | 1 + repos/os/src/server/nitpicker/main.cc | 24 ++++++++++++++-------- repos/os/src/server/nitpicker/user_state.h | 4 +++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/repos/os/src/server/nitpicker/README b/repos/os/src/server/nitpicker/README index d992beb399..f2b6b76198 100644 --- a/repos/os/src/server/nitpicker/README +++ b/repos/os/src/server/nitpicker/README @@ -189,6 +189,7 @@ outside world via report sessions. The reporting can be enabled using the ! ... ! +The 'hover' attribute enables the reporting of the currently hovered session. The 'focus' attribute enables the reporting of the currently focused session. The 'pointer' attribute enables the reporting of the current absolute pointer position. diff --git a/repos/os/src/server/nitpicker/main.cc b/repos/os/src/server/nitpicker/main.cc index e50bbc5f58..bf1794ade1 100644 --- a/repos/os/src/server/nitpicker/main.cc +++ b/repos/os/src/server/nitpicker/main.cc @@ -76,18 +76,18 @@ Framebuffer::Session *tmp_fb; ** Utilities ** ***************/ -static void report_focus(Genode::Reporter &reporter, Session *focused_session) +static void report_session(Genode::Reporter &reporter, Session *session) { if (!reporter.is_enabled()) return; Genode::Reporter::Xml_generator xml(reporter, [&] () { - if (focused_session) { - xml.attribute("label", focused_session->label().string()); - xml.attribute("domain", focused_session->domain_name().string()); + if (session) { + xml.attribute("label", session->label().string()); + xml.attribute("domain", session->domain_name().string()); - Color const color = focused_session->color(); + Color const color = session->color(); char buf[32]; Genode::snprintf(buf, sizeof(buf), "#%02x%02x%02x", color.r, color.g, color.b); @@ -918,7 +918,7 @@ class Nitpicker::Session_component : public Genode::Rpc_object, if (session) session->release(); - report_focus(_focus_reporter, session); + report_session(_focus_reporter, session); } void session_control(Label suffix, Session_control control) override @@ -1152,6 +1152,7 @@ struct Nitpicker::Main Genode::Sliced_heap sliced_heap = { env()->ram_session(), env()->rm_session() }; Genode::Reporter pointer_reporter = { "pointer" }; + Genode::Reporter hover_reporter = { "hover" }; Genode::Reporter focus_reporter = { "focus" }; Genode::Reporter xray_reporter = { "xray" }; @@ -1226,6 +1227,7 @@ void Nitpicker::Main::handle_input(unsigned) do { Point const old_pointer_pos = user_state.pointer_pos(); + ::Session * const old_pointed_session = user_state.pointed_session(); ::Session * const old_focused_session = user_state.Mode::focused_session(); bool const old_kill_mode = user_state.kill(); bool const old_xray_mode = user_state.xray(); @@ -1235,6 +1237,7 @@ void Nitpicker::Main::handle_input(unsigned) import_input_events(ev_buf, input.flush(), user_state); Point const new_pointer_pos = user_state.pointer_pos(); + ::Session * const new_pointed_session = user_state.pointed_session(); ::Session * const new_focused_session = user_state.Mode::focused_session(); bool const new_kill_mode = user_state.kill(); bool const new_xray_mode = user_state.xray(); @@ -1257,9 +1260,13 @@ void Nitpicker::Main::handle_input(unsigned) }); } + /* report hover changes */ + if (old_pointed_session != new_pointed_session) + report_session(hover_reporter, new_pointed_session); + /* report focus changes */ if (old_focused_session != new_focused_session) - report_focus(focus_reporter, new_focused_session); + report_session(focus_reporter, new_focused_session); /* report kill mode */ if (old_kill_mode != new_kill_mode) { @@ -1268,7 +1275,7 @@ void Nitpicker::Main::handle_input(unsigned) report_kill_focus(focus_reporter); if (!new_kill_mode) - report_focus(focus_reporter, new_focused_session); + report_session(focus_reporter, new_focused_session); } /* @@ -1340,6 +1347,7 @@ void Nitpicker::Main::handle_config(unsigned) } catch (...) { } configure_reporter(pointer_reporter); + configure_reporter(hover_reporter); configure_reporter(focus_reporter); configure_reporter(xray_reporter); diff --git a/repos/os/src/server/nitpicker/user_state.h b/repos/os/src/server/nitpicker/user_state.h index 642b481f44..2316e43d1a 100644 --- a/repos/os/src/server/nitpicker/user_state.h +++ b/repos/os/src/server/nitpicker/user_state.h @@ -71,7 +71,9 @@ class User_state : public Mode, public View_stack /** * Accessors */ - Point pointer_pos() { return _pointer_pos; } + Point pointer_pos() { return _pointer_pos; } + Session *pointed_session() { return _pointed_session; } + /** * (Re-)apply origin policy to all views