summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEduardo Lima (Etrunko) <eduardo.lima@intel.com>2012-11-21 15:45:02 +0000
committerEduardo de Barros Lima <eblima@gmail.com>2012-11-21 15:45:02 +0000
commitd27dc525ebd5553192f258ff9ffeedec2109e990 (patch)
tree426feea72335bdec289f6c7845746c31f46eb00d /src
parent7eab2172998107b1d5aef77d96f12decb19f5b8e (diff)
Added keyboard support for Wayland EGL
Signed-off-by: Eduardo Lima (Etrunko) <eduardo.lima@intel.com> SVN revision: 79515
Diffstat (limited to 'src')
-rw-r--r--src/bin/engine_wayland_egl.c117
1 files changed, 115 insertions, 2 deletions
diff --git a/src/bin/engine_wayland_egl.c b/src/bin/engine_wayland_egl.c
index a81539f..6b91eb6 100644
--- a/src/bin/engine_wayland_egl.c
+++ b/src/bin/engine_wayland_egl.c
@@ -3,6 +3,8 @@
3#include <string.h> 3#include <string.h>
4#include <assert.h> 4#include <assert.h>
5 5
6#include <linux/input.h>
7
6#include <Evas_Engine_Wayland_Egl.h> 8#include <Evas_Engine_Wayland_Egl.h>
7#include <wayland-client.h> 9#include <wayland-client.h>
8#include <wayland-egl.h> 10#include <wayland-egl.h>
@@ -39,6 +41,28 @@ static const struct wl_shell_surface_listener _shell_surface_listener =
39 NULL, /* popup_done */ 41 NULL, /* popup_done */
40}; 42};
41 43
44/* Seat (input) handler */
45static void _seat_handle_capabilities(void *data, struct wl_seat *seat, enum wl_seat_capability caps);
46static const struct wl_seat_listener _seat_listener =
47{
48 _seat_handle_capabilities,
49};
50
51/* Keyboard handler */
52static void _keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format, int fd, uint32_t size);
53static void _keyboard_handle_enter(void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys);
54static void _keyboard_handle_leave(void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface);
55static void _keyboard_handle_key(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state);
56static void _keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group);
57static const struct wl_keyboard_listener _keyboard_listener =
58{
59 _keyboard_handle_keymap, /* keymap */
60 _keyboard_handle_enter, /* enter */
61 _keyboard_handle_leave, /* leave */
62 _keyboard_handle_key,
63 _keyboard_handle_modifiers, /* modifiers */
64};
65
42/* 66/*
43 * API 67 * API
44 */ 68 */
@@ -84,8 +108,7 @@ engine_wayland_egl_args(const char *engine __UNUSED__, int width __UNUSED__, int
84void 108void
85engine_wayland_egl_loop(void) 109engine_wayland_egl_loop(void)
86{ 110{
87 assert(wl_display_dispatch_pending(wl.display) != -1); 111 assert(wl_display_dispatch(wl.display) != -1);
88 wl_display_flush(wl.display);
89} 112}
90 113
91void 114void
@@ -113,6 +136,12 @@ _registry_handle_global(void *data __UNUSED__, struct wl_registry *registry, uns
113 { 136 {
114 wl.shell = wl_registry_bind(registry, id, &wl_shell_interface, 1); 137 wl.shell = wl_registry_bind(registry, id, &wl_shell_interface, 1);
115 } 138 }
139 else if (!strcmp(interface, "wl_seat"))
140 {
141 struct wl_seat *seat;
142 seat = wl_registry_bind(registry, id, &wl_seat_interface, 1);
143 wl_seat_add_listener(seat, &_seat_listener, NULL);
144 }
116} 145}
117 146
118static void 147static void
@@ -120,3 +149,87 @@ _shell_surface_handle_ping(void *data __UNUSED__, struct wl_shell_surface *shell
120{ 149{
121 wl_shell_surface_pong(shell_surface, serial); 150 wl_shell_surface_pong(shell_surface, serial);
122} 151}
152
153static void
154_seat_handle_capabilities(void *data __UNUSED__, struct wl_seat *seat, enum wl_seat_capability caps)
155{
156 static struct wl_keyboard *kbd = NULL;
157
158 if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !kbd)
159 {
160 kbd = wl_seat_get_keyboard(seat);
161 wl_keyboard_add_listener(kbd, &_keyboard_listener, NULL);
162 }
163 else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && kbd)
164 {
165 wl_keyboard_destroy(kbd);
166 kbd = NULL;
167 }
168}
169
170static void
171_keyboard_handle_keymap(void *data __UNUSED__, struct wl_keyboard *keyboard __UNUSED__, uint32_t format __UNUSED__, int fd __UNUSED__, uint32_t size __UNUSED__)
172{
173}
174
175static void
176_keyboard_handle_enter(void *data __UNUSED__, struct wl_keyboard *keyboard __UNUSED__, uint32_t serial __UNUSED__, struct wl_surface *surface __UNUSED__, struct wl_array *keys __UNUSED__)
177{
178}
179
180static void
181_keyboard_handle_leave(void *data __UNUSED__, struct wl_keyboard *keyboard __UNUSED__, uint32_t serial __UNUSED__, struct wl_surface *surface __UNUSED__)
182{
183}
184
185static void
186_keyboard_handle_key(void *data __UNUSED__, struct wl_keyboard *keyboard __UNUSED__, uint32_t serial __UNUSED__, uint32_t time __UNUSED__, uint32_t key, uint32_t state)
187{
188 const char *key_str;
189
190 switch (key)
191 {
192 case KEY_LEFT:
193 key_str = "Left";
194 break;
195
196 case KEY_RIGHT:
197 key_str = "Right";
198 break;
199
200 case KEY_ENTER:
201 case KEY_KPENTER:
202 key_str = "Return";
203 break;
204
205 case KEY_ESC:
206 key_str = "Escape";
207 break;
208
209 default:
210 key_str = NULL;
211 break;
212 }
213
214 if (key_str)
215 {
216 switch (state)
217 {
218 case WL_KEYBOARD_KEY_STATE_RELEASED:
219 evas_event_feed_key_up(evas, key_str, key_str, NULL, NULL, 0, NULL);
220 break;
221
222 case WL_KEYBOARD_KEY_STATE_PRESSED:
223 evas_event_feed_key_down(evas, key_str, key_str, NULL, NULL, 0, NULL);
224 break;
225
226 default:
227 break;
228 }
229 }
230}
231
232static void
233_keyboard_handle_modifiers(void *data __UNUSED__, struct wl_keyboard *keyboard __UNUSED__, uint32_t serial __UNUSED__, uint32_t mods_depressed __UNUSED__, uint32_t mods_latched __UNUSED__, uint32_t mods_locked __UNUSED__, uint32_t group __UNUSED__)
234{
235}