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

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

Movement events from input server, display pointer, focus by click again

  • Property mode set to 100644
File size: 4.5 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 <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 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
85static errno_t ds_input_ev_move(input_t *input, int dx, int dy)
86{
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);
96}
97
98static errno_t ds_input_ev_abs_move(input_t *input, unsigned x, unsigned y,
99 unsigned max_x, unsigned max_y)
100{
101 printf("ds_input_ev_abs_move x=%u y=%u mx=%u my=%u\n",
102 x, y, max_x, max_y);
103 return EOK;
104}
105
106static errno_t ds_input_ev_button(input_t *input, int bnum, int bpress)
107{
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);
118}
119
120/** Open input service.
121 *
122 * @param display Display
123 * @return EOK on success or an error code
124 */
125errno_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
159void ds_input_close(ds_display_t *display)
160{
161 input_close(display->input);
162 display->input = NULL;
163}
164
165/** @}
166 */
Note: See TracBrowser for help on using the repository browser.