source: mainline/uspace/srv/hid/display/input.c@ 7470d97

serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7470d97 was ddb844e, checked in by Jiri Svoboda <jiri@…>, 5 years ago

Resolve merge conflicts

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