uterm: move input related API to uterm_input.h
[platform/upstream/kmscon.git] / src / uterm_input.h
1 /*
2  * uterm - Linux User-Space Terminal Input Handling
3  *
4  * Copyright (c) 2011-2013 David Herrmann <dh.herrmann@googlemail.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files
8  * (the "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25
26 /*
27  * Input Devices
28  * This input object can combine multiple linux input devices into a single
29  * device and notifies the application about events. It has several different
30  * keyboard backends so the full XKB feature set is available.
31  */
32
33 #ifndef UTERM_UTERM_INPUT_H
34 #define UTERM_UTERM_INPUT_H
35
36 #include <eloop.h>
37 #include <inttypes.h>
38 #include <stdbool.h>
39 #include <stdlib.h>
40
41 struct uterm_input;
42
43 /* keep in sync with shl_xkb_mods */
44 enum uterm_input_modifier {
45         UTERM_SHIFT_MASK        = (1 << 0),
46         UTERM_LOCK_MASK         = (1 << 1),
47         UTERM_CONTROL_MASK      = (1 << 2),
48         UTERM_ALT_MASK          = (1 << 3),
49         UTERM_LOGO_MASK         = (1 << 4),
50 };
51
52 /* keep in sync with TSM_VTE_INVALID */
53 #define UTERM_INPUT_INVALID 0xffffffff
54
55 struct uterm_input_event {
56         bool handled;           /* user-controlled, default is false */
57         uint16_t keycode;       /* linux keycode - KEY_* - linux/input.h */
58         uint32_t ascii;         /* ascii keysym for @keycode */
59         unsigned int mods;      /* active modifiers - uterm_modifier mask */
60
61         unsigned int num_syms;  /* number of keysyms */
62         uint32_t *keysyms;      /* XKB-common keysym-array - XKB_KEY_* */
63         uint32_t *codepoints;   /* ucs4 unicode value or UTERM_INPUT_INVALID */
64 };
65
66 #define UTERM_INPUT_HAS_MODS(_ev, _mods) (((_ev)->mods & (_mods)) == (_mods))
67
68 typedef void (*uterm_input_cb) (struct uterm_input *input,
69                                 struct uterm_input_event *ev,
70                                 void *data);
71
72 int uterm_input_new(struct uterm_input **out, struct ev_eloop *eloop,
73                     const char *model, const char *layout, const char *variant,
74                     const char *options, unsigned int repeat_delay,
75                     unsigned int repeat_rate);
76 void uterm_input_ref(struct uterm_input *input);
77 void uterm_input_unref(struct uterm_input *input);
78
79 void uterm_input_add_dev(struct uterm_input *input, const char *node);
80 void uterm_input_remove_dev(struct uterm_input *input, const char *node);
81
82 int uterm_input_register_cb(struct uterm_input *input, uterm_input_cb cb,
83                             void *data);
84 void uterm_input_unregister_cb(struct uterm_input *input, uterm_input_cb cb,
85                                void *data);
86
87 void uterm_input_sleep(struct uterm_input *input);
88 void uterm_input_wake_up(struct uterm_input *input);
89 bool uterm_input_is_awake(struct uterm_input *input);
90
91 #endif /* UTERM_UTERM_INPUT_H */