[02f45748] | 1 | /*
|
---|
| 2 | * Copyright (c) 2019 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup display
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file Input events
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #include <errno.h>
|
---|
| 36 | #include <io/input.h>
|
---|
| 37 | #include <loc.h>
|
---|
| 38 | #include <stdio.h>
|
---|
| 39 | #include <str_error.h>
|
---|
| 40 | #include "display.h"
|
---|
| 41 | #include "input.h"
|
---|
| 42 | #include "main.h"
|
---|
| 43 |
|
---|
| 44 | static errno_t ds_input_ev_active(input_t *);
|
---|
| 45 | static errno_t ds_input_ev_deactive(input_t *);
|
---|
| 46 | static errno_t ds_input_ev_key(input_t *, kbd_event_type_t, keycode_t, keymod_t, wchar_t);
|
---|
| 47 | static errno_t ds_input_ev_move(input_t *, int, int);
|
---|
| 48 | static errno_t ds_input_ev_abs_move(input_t *, unsigned, unsigned, unsigned, unsigned);
|
---|
| 49 | static errno_t ds_input_ev_button(input_t *, int, int);
|
---|
| 50 |
|
---|
| 51 | static input_ev_ops_t ds_input_ev_ops = {
|
---|
| 52 | .active = ds_input_ev_active,
|
---|
| 53 | .deactive = ds_input_ev_deactive,
|
---|
| 54 | .key = ds_input_ev_key,
|
---|
| 55 | .move = ds_input_ev_move,
|
---|
| 56 | .abs_move = ds_input_ev_abs_move,
|
---|
| 57 | .button = ds_input_ev_button
|
---|
| 58 | };
|
---|
| 59 |
|
---|
| 60 | static errno_t ds_input_ev_active(input_t *input)
|
---|
| 61 | {
|
---|
| 62 | return EOK;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | static errno_t ds_input_ev_deactive(input_t *input)
|
---|
| 66 | {
|
---|
| 67 | return EOK;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | static errno_t ds_input_ev_key(input_t *input, kbd_event_type_t type,
|
---|
| 71 | keycode_t key, keymod_t mods, wchar_t c)
|
---|
| 72 | {
|
---|
| 73 | ds_display_t *disp = (ds_display_t *) input->user;
|
---|
| 74 | kbd_event_t event;
|
---|
| 75 |
|
---|
| 76 | printf("ds_input_ev_key\n");
|
---|
| 77 | event.type = type;
|
---|
| 78 | event.key = key;
|
---|
| 79 | event.mods = mods;
|
---|
| 80 | event.c = c;
|
---|
| 81 |
|
---|
| 82 | return ds_display_post_kbd_event(disp, &event);
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | static errno_t ds_input_ev_move(input_t *input, int dx, int dy)
|
---|
| 86 | {
|
---|
[4fbdc3d] | 87 | ds_display_t *disp = (ds_display_t *) input->user;
|
---|
| 88 | ptd_event_t event;
|
---|
| 89 |
|
---|
| 90 | printf("ds_input_ev_move\n");
|
---|
| 91 | event.type = PTD_MOVE;
|
---|
| 92 | event.dmove.x = dx;
|
---|
| 93 | event.dmove.y = dy;
|
---|
| 94 |
|
---|
| 95 | return ds_display_post_ptd_event(disp, &event);
|
---|
[02f45748] | 96 | }
|
---|
| 97 |
|
---|
| 98 | static errno_t ds_input_ev_abs_move(input_t *input, unsigned x, unsigned y,
|
---|
| 99 | unsigned max_x, unsigned max_y)
|
---|
| 100 | {
|
---|
[4fbdc3d] | 101 | printf("ds_input_ev_abs_move x=%u y=%u mx=%u my=%u\n",
|
---|
| 102 | x, y, max_x, max_y);
|
---|
[02f45748] | 103 | return EOK;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | static errno_t ds_input_ev_button(input_t *input, int bnum, int bpress)
|
---|
| 107 | {
|
---|
[4fbdc3d] | 108 | ds_display_t *disp = (ds_display_t *) input->user;
|
---|
| 109 | ptd_event_t event;
|
---|
| 110 |
|
---|
| 111 | printf("ds_input_ev_abs_button\n");
|
---|
| 112 | event.type = bpress ? PTD_PRESS : PTD_RELEASE;
|
---|
| 113 | event.btn_num = bnum;
|
---|
| 114 | event.dmove.x = 0;
|
---|
| 115 | event.dmove.y = 0;
|
---|
| 116 |
|
---|
| 117 | return ds_display_post_ptd_event(disp, &event);
|
---|
[02f45748] | 118 | }
|
---|
| 119 |
|
---|
| 120 | /** Open input service.
|
---|
| 121 | *
|
---|
| 122 | * @param display Display
|
---|
| 123 | * @return EOK on success or an error code
|
---|
| 124 | */
|
---|
| 125 | errno_t ds_input_open(ds_display_t *display)
|
---|
| 126 | {
|
---|
| 127 | async_sess_t *sess;
|
---|
| 128 | service_id_t dsid;
|
---|
| 129 | const char *svc = "hid/input";
|
---|
| 130 |
|
---|
| 131 | printf("ds_input_open\n");
|
---|
| 132 | errno_t rc = loc_service_get_id(svc, &dsid, 0);
|
---|
| 133 | if (rc != EOK) {
|
---|
| 134 | printf("%s: Input service %s not found\n", NAME, svc);
|
---|
| 135 | return rc;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | sess = loc_service_connect(dsid, INTERFACE_INPUT, 0);
|
---|
| 139 | if (sess == NULL) {
|
---|
| 140 | printf("%s: Unable to connect to input service %s\n", NAME,
|
---|
| 141 | svc);
|
---|
| 142 | return EIO;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | rc = input_open(sess, &ds_input_ev_ops, (void *) display,
|
---|
| 146 | &display->input);
|
---|
| 147 | if (rc != EOK) {
|
---|
| 148 | async_hangup(sess);
|
---|
| 149 | printf("%s: Unable to communicate with service %s (%s)\n",
|
---|
| 150 | NAME, svc, str_error(rc));
|
---|
| 151 | return rc;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | input_activate(display->input);
|
---|
| 155 | printf("ds_input_open: DONE\n");
|
---|
| 156 | return EOK;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | void ds_input_close(ds_display_t *display)
|
---|
| 160 | {
|
---|
| 161 | input_close(display->input);
|
---|
| 162 | display->input = NULL;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | /** @}
|
---|
| 166 | */
|
---|