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

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

Source display server events from input server

  • Property mode set to 100644
File size: 4.0 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 return EOK;
88}
89
90static errno_t ds_input_ev_abs_move(input_t *input, unsigned x, unsigned y,
91 unsigned max_x, unsigned max_y)
92{
93 return EOK;
94}
95
96static errno_t ds_input_ev_button(input_t *input, int bnum, int bpress)
97{
98 return EOK;
99}
100
101/** Open input service.
102 *
103 * @param display Display
104 * @return EOK on success or an error code
105 */
106errno_t ds_input_open(ds_display_t *display)
107{
108 async_sess_t *sess;
109 service_id_t dsid;
110 const char *svc = "hid/input";
111
112 printf("ds_input_open\n");
113 errno_t rc = loc_service_get_id(svc, &dsid, 0);
114 if (rc != EOK) {
115 printf("%s: Input service %s not found\n", NAME, svc);
116 return rc;
117 }
118
119 sess = loc_service_connect(dsid, INTERFACE_INPUT, 0);
120 if (sess == NULL) {
121 printf("%s: Unable to connect to input service %s\n", NAME,
122 svc);
123 return EIO;
124 }
125
126 rc = input_open(sess, &ds_input_ev_ops, (void *) display,
127 &display->input);
128 if (rc != EOK) {
129 async_hangup(sess);
130 printf("%s: Unable to communicate with service %s (%s)\n",
131 NAME, svc, str_error(rc));
132 return rc;
133 }
134
135 input_activate(display->input);
136 printf("ds_input_open: DONE\n");
137 return EOK;
138}
139
140void ds_input_close(ds_display_t *display)
141{
142 input_close(display->input);
143 display->input = NULL;
144}
145
146/** @}
147 */
Note: See TracBrowser for help on using the repository browser.