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

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

Support absolute movement events from input device

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[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
44static errno_t ds_input_ev_active(input_t *);
45static errno_t ds_input_ev_deactive(input_t *);
46static errno_t ds_input_ev_key(input_t *, kbd_event_type_t, keycode_t, keymod_t, wchar_t);
47static errno_t ds_input_ev_move(input_t *, int, int);
48static errno_t ds_input_ev_abs_move(input_t *, unsigned, unsigned, unsigned, unsigned);
49static errno_t ds_input_ev_button(input_t *, int, int);
50
51static 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
60static errno_t ds_input_ev_active(input_t *input)
61{
62 return EOK;
63}
64
65static errno_t ds_input_ev_deactive(input_t *input)
66{
67 return EOK;
68}
69
70static 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 event.type = type;
77 event.key = key;
78 event.mods = mods;
79 event.c = c;
80
81 return ds_display_post_kbd_event(disp, &event);
82}
83
84static errno_t ds_input_ev_move(input_t *input, int dx, int dy)
85{
[4fbdc3d]86 ds_display_t *disp = (ds_display_t *) input->user;
87 ptd_event_t event;
88
89 event.type = PTD_MOVE;
90 event.dmove.x = dx;
91 event.dmove.y = dy;
92
93 return ds_display_post_ptd_event(disp, &event);
[02f45748]94}
95
96static errno_t ds_input_ev_abs_move(input_t *input, unsigned x, unsigned y,
97 unsigned max_x, unsigned max_y)
98{
[1388f7f0]99 ds_display_t *disp = (ds_display_t *) input->user;
100 ptd_event_t event;
101
102 event.type = PTD_ABS_MOVE;
103 event.apos.x = x;
104 event.apos.y = y;
105 event.abounds.p0.x = 0;
106 event.abounds.p0.y = 0;
107 event.abounds.p1.x = max_x + 1;
108 event.abounds.p1.y = max_y + 1;
109
110 return ds_display_post_ptd_event(disp, &event);
[02f45748]111}
112
113static errno_t ds_input_ev_button(input_t *input, int bnum, int bpress)
114{
[4fbdc3d]115 ds_display_t *disp = (ds_display_t *) input->user;
116 ptd_event_t event;
117
118 event.type = bpress ? PTD_PRESS : PTD_RELEASE;
119 event.btn_num = bnum;
120 event.dmove.x = 0;
121 event.dmove.y = 0;
122
123 return ds_display_post_ptd_event(disp, &event);
[02f45748]124}
125
126/** Open input service.
127 *
128 * @param display Display
129 * @return EOK on success or an error code
130 */
131errno_t ds_input_open(ds_display_t *display)
132{
133 async_sess_t *sess;
134 service_id_t dsid;
135 const char *svc = "hid/input";
136
137 errno_t rc = loc_service_get_id(svc, &dsid, 0);
138 if (rc != EOK) {
139 printf("%s: Input service %s not found\n", NAME, svc);
140 return rc;
141 }
142
143 sess = loc_service_connect(dsid, INTERFACE_INPUT, 0);
144 if (sess == NULL) {
145 printf("%s: Unable to connect to input service %s\n", NAME,
146 svc);
147 return EIO;
148 }
149
150 rc = input_open(sess, &ds_input_ev_ops, (void *) display,
151 &display->input);
152 if (rc != EOK) {
153 async_hangup(sess);
154 printf("%s: Unable to communicate with service %s (%s)\n",
155 NAME, svc, str_error(rc));
156 return rc;
157 }
158
159 input_activate(display->input);
160 return EOK;
161}
162
163void ds_input_close(ds_display_t *display)
164{
165 input_close(display->input);
166 display->input = NULL;
167}
168
169/** @}
170 */
Note: See TracBrowser for help on using the repository browser.