1.1 --- a/pkg/landfall-examples/input_event_client/input_event_client.cc Fri May 18 22:34:51 2018 +0200
1.2 +++ b/pkg/landfall-examples/input_event_client/input_event_client.cc Fri May 18 23:41:51 2018 +0200
1.3 @@ -51,6 +51,7 @@
1.4
1.5 #include <l4/re/c/util/video/goos_fb.h>
1.6 #include <l4/re/c/video/view.h>
1.7 +
1.8 #include <l4/re/env>
1.9 #include <l4/re/event>
1.10 #include <l4/re/event_enums.h>
1.11 @@ -141,7 +142,7 @@
1.12 static uint8_t row = 0;
1.13 static uint32_t text_x = 0, text_y = 0, next_y = 0;
1.14
1.15 -static void handler(L4Re::Event_buffer::Event &event, void *priv)
1.16 +static void show_key_code(L4Re::Event_buffer::Event &event)
1.17 {
1.18 uint32_t colsize = view_info.width / 10,
1.19 rowsize = view_info.height / 20;
1.20 @@ -150,26 +151,28 @@
1.21
1.22 /* Convert the key code into a bit pattern. */
1.23
1.24 - if (!priv)
1.25 - {
1.26 - for (column = 0, mask = (1 << 9); column < 10; column++, mask >>= 1)
1.27 - _screen->draw_box(Rect(Point(column * colsize, row * rowsize),
1.28 - Area(colsize, rowsize)),
1.29 - event.payload.code & mask ? (
1.30 - event.payload.value ? Rgb32::Color(0, 255, 0)
1.31 - : Rgb32::Color(255, 0, 0))
1.32 - : Rgb32::Color(0, 0, 0));
1.33 + for (column = 0, mask = (1 << 9); column < 10; column++, mask >>= 1)
1.34 + _screen->draw_box(Rect(Point(column * colsize, row * rowsize),
1.35 + Area(colsize, rowsize)),
1.36 + event.payload.code & mask ? (
1.37 + event.payload.value ? Rgb32::Color(0, 255, 0)
1.38 + : Rgb32::Color(255, 0, 0))
1.39 + : Rgb32::Color(0, 0, 0));
1.40 +
1.41 + /* Advance to the next row, wrapping around. */
1.42
1.43 - /* Advance to the next row, wrapping around. */
1.44 + row = (row + 1) % 20;
1.45
1.46 - row = (row + 1) % 20;
1.47 - }
1.48 + /* Refresh the display. */
1.49
1.50 - /* Or produce a string. */
1.51 + l4re_util_video_goos_fb_refresh(&gfb, 0, 0, view_info.width, view_info.height);
1.52 +}
1.53
1.54 - else if (event.payload.value)
1.55 +static void show_key_label(L4Re::Event_buffer::Event &event)
1.56 +{
1.57 + if (event.payload.value)
1.58 {
1.59 - const char *s = ((const char *(*)(int)) priv)(event.payload.code);
1.60 + const char *s = key_to_string(event.payload.code);
1.61 Rgba32::Color col;
1.62
1.63 if (!s)
1.64 @@ -226,12 +229,6 @@
1.65
1.66
1.67
1.68 -/* Event buffer memory. */
1.69 -
1.70 -static void *evmem = 0;
1.71 -
1.72 -
1.73 -
1.74 /* Arguments: [ chars ] */
1.75
1.76 int main(int argc, char *argv[])
1.77 @@ -272,11 +269,12 @@
1.78
1.79 L4::Cap<L4Re::Dataspace> mem = L4Re::Util::cap_alloc.alloc<L4Re::Dataspace>();
1.80 if (!mem.is_valid()) return 1;
1.81 -
1.82 if (event_server->get_buffer(mem)) return 1;
1.83
1.84 /* Attach the event buffer to this task. */
1.85
1.86 + void *evmem = 0;
1.87 +
1.88 if (L4Re::Env::env()->rm()->attach(&evmem, mem->size(), L4Re::Rm::Search_addr,
1.89 L4::Ipc::make_cap_rw(mem)))
1.90 return 1;
1.91 @@ -292,16 +290,18 @@
1.92
1.93 if (event_server->bind(0, irq)) return 1;
1.94
1.95 - /* Private data for the handler function. */
1.96 + /* Create an event handler. */
1.97
1.98 - void *priv = 0;
1.99 + Input_event_loop loop(event_buffer, irq);
1.100 +
1.101 + /* Attach the handler function. */
1.102
1.103 if ((argc > 1) && (!strcmp(argv[1], "chars")))
1.104 - priv = (void *) key_to_string;
1.105 + loop.attach(show_key_label);
1.106 + else
1.107 + loop.attach(show_key_code);
1.108
1.109 - /* Create an event handler and wait for events. */
1.110 -
1.111 - Input_event_loop loop(handler, priv, event_buffer, irq);
1.112 + /* Wait for events. */
1.113
1.114 loop.start();
1.115 l4_sleep_forever();