source: mainline/uspace/srv/hid/display/input.c@ 35cffea

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 35cffea was 8edec53, checked in by Jiri Svoboda <jiri@…>, 4 years ago

Support double-click

Needed to open Navigator entries using the mouse.

  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*
2 * Copyright (c) 2021 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 <inttypes.h>
37#include <io/input.h>
38#include <io/log.h>
39#include <loc.h>
40#include <str_error.h>
41#include "display.h"
42#include "input.h"
43#include "main.h"
44
45static errno_t ds_input_ev_active(input_t *);
46static errno_t ds_input_ev_deactive(input_t *);
47static errno_t ds_input_ev_key(input_t *, kbd_event_type_t, keycode_t, keymod_t, char32_t);
48static errno_t ds_input_ev_move(input_t *, int, int);
49static errno_t ds_input_ev_abs_move(input_t *, unsigned, unsigned, unsigned, unsigned);
50static errno_t ds_input_ev_button(input_t *, int, int);
51static errno_t ds_input_ev_dclick(input_t *, int);
52
53static input_ev_ops_t ds_input_ev_ops = {
54 .active = ds_input_ev_active,
55 .deactive = ds_input_ev_deactive,
56 .key = ds_input_ev_key,
57 .move = ds_input_ev_move,
58 .abs_move = ds_input_ev_abs_move,
59 .button = ds_input_ev_button,
60 .dclick = ds_input_ev_dclick
61};
62
63static errno_t ds_input_ev_active(input_t *input)
64{
65 return EOK;
66}
67
68static errno_t ds_input_ev_deactive(input_t *input)
69{
70 return EOK;
71}
72
73static errno_t ds_input_ev_key(input_t *input, kbd_event_type_t type,
74 keycode_t key, keymod_t mods, char32_t c)
75{
76 ds_display_t *disp = (ds_display_t *) input->user;
77 kbd_event_t event;
78 errno_t rc;
79
80 event.type = type;
81 event.key = key;
82 event.mods = mods;
83 event.c = c;
84
85 ds_display_lock(disp);
86 rc = ds_display_post_kbd_event(disp, &event);
87 ds_display_unlock(disp);
88 return rc;
89}
90
91static errno_t ds_input_ev_move(input_t *input, int dx, int dy)
92{
93 ds_display_t *disp = (ds_display_t *) input->user;
94 ptd_event_t event;
95 errno_t rc;
96
97 event.type = PTD_MOVE;
98 event.dmove.x = dx;
99 event.dmove.y = dy;
100
101 ds_display_lock(disp);
102 rc = ds_display_post_ptd_event(disp, &event);
103 ds_display_unlock(disp);
104 return rc;
105}
106
107static errno_t ds_input_ev_abs_move(input_t *input, unsigned x, unsigned y,
108 unsigned max_x, unsigned max_y)
109{
110 ds_display_t *disp = (ds_display_t *) input->user;
111 ptd_event_t event;
112 errno_t rc;
113
114 event.type = PTD_ABS_MOVE;
115 event.apos.x = x;
116 event.apos.y = y;
117 event.abounds.p0.x = 0;
118 event.abounds.p0.y = 0;
119 event.abounds.p1.x = max_x + 1;
120 event.abounds.p1.y = max_y + 1;
121
122 ds_display_lock(disp);
123 rc = ds_display_post_ptd_event(disp, &event);
124 ds_display_unlock(disp);
125 return rc;
126}
127
128static errno_t ds_input_ev_button(input_t *input, int bnum, int bpress)
129{
130 ds_display_t *disp = (ds_display_t *) input->user;
131 ptd_event_t event;
132 errno_t rc;
133
134 event.type = bpress ? PTD_PRESS : PTD_RELEASE;
135 event.btn_num = bnum;
136 event.dmove.x = 0;
137 event.dmove.y = 0;
138
139 ds_display_lock(disp);
140 rc = ds_display_post_ptd_event(disp, &event);
141 ds_display_unlock(disp);
142 return rc;
143}
144
145static errno_t ds_input_ev_dclick(input_t *input, int bnum)
146{
147 ds_display_t *disp = (ds_display_t *) input->user;
148 ptd_event_t event;
149 errno_t rc;
150
151 event.type = PTD_DCLICK;
152 event.btn_num = bnum;
153 event.dmove.x = 0;
154 event.dmove.y = 0;
155
156 ds_display_lock(disp);
157 rc = ds_display_post_ptd_event(disp, &event);
158 ds_display_unlock(disp);
159 return rc;
160}
161
162/** Open input service.
163 *
164 * @param display Display
165 * @return EOK on success or an error code
166 */
167errno_t ds_input_open(ds_display_t *display)
168{
169 async_sess_t *sess;
170 service_id_t dsid;
171 const char *svc = "hid/input";
172
173 errno_t rc = loc_service_get_id(svc, &dsid, 0);
174 if (rc != EOK) {
175 log_msg(LOG_DEFAULT, LVL_ERROR, "Input service %s not found",
176 svc);
177 return rc;
178 }
179
180 sess = loc_service_connect(dsid, INTERFACE_INPUT, 0);
181 if (sess == NULL) {
182 log_msg(LOG_DEFAULT, LVL_ERROR,
183 "Unable to connect to input service %s", svc);
184 return EIO;
185 }
186
187 rc = input_open(sess, &ds_input_ev_ops, (void *) display,
188 &display->input);
189 if (rc != EOK) {
190 async_hangup(sess);
191 log_msg(LOG_DEFAULT, LVL_ERROR,
192 "Unable to communicate with service %s (%s)",
193 svc, str_error(rc));
194 return rc;
195 }
196
197 input_activate(display->input);
198 return EOK;
199}
200
201void ds_input_close(ds_display_t *display)
202{
203 input_close(display->input);
204 display->input = NULL;
205}
206
207/** @}
208 */
Note: See TracBrowser for help on using the repository browser.