[PATCH weston 16/17] android: add basic evdev input support
Pekka Paalanen
ppaalanen at gmail.com
Thu Jul 5 03:33:13 PDT 2012
Make android_seat based on evdev_seat.
Signed-off-by: Pekka Paalanen <ppaalanen at gmail.com>
---
src/compositor-android.c | 84 +++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 80 insertions(+), 4 deletions(-)
diff --git a/src/compositor-android.c b/src/compositor-android.c
index 1657e9c..d19dcc7 100644
--- a/src/compositor-android.c
+++ b/src/compositor-android.c
@@ -20,10 +20,17 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#define _GNU_SOURCE
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
#include <EGL/egl.h>
#include <GLES2/gl2.h>
@@ -45,7 +52,7 @@ struct android_output {
};
struct android_seat {
- struct weston_seat base;
+ struct evdev_seat evdev;
};
struct android_compositor {
@@ -231,9 +238,67 @@ android_compositor_add_output(struct android_compositor *compositor,
}
static void
+android_seat_open_device(struct android_seat *seat, const char *devnode)
+{
+ struct evdev_input_device *device;
+ int fd;
+
+ /* XXX: check the Android excluded list */
+
+ fd = open(devnode, O_RDWR | O_NONBLOCK | O_CLOEXEC);
+ if (fd < 0) {
+ weston_log_continue(STAMP_SPACE "...failed: %s\n",
+ strerror(errno));
+ return;
+ }
+
+ device = evdev_input_device_create(&seat->evdev, devnode, fd);
+ if (!device) {
+ close(fd);
+ }
+}
+
+static int
+is_dot_or_dotdot(const char *str)
+{
+ return (str[0] == '.' &&
+ (str[1] == 0 || (str[1] == '.' && str[2] == 0)));
+}
+
+static void
+android_seat_scan_devices(struct android_seat *seat, const char *dirpath)
+{
+ int ret;
+ DIR *dir;
+ struct dirent *dent;
+ char *devnode = NULL;
+
+ dir = opendir(dirpath);
+ if (!dir) {
+ weston_log("Could not open input device directory '%s': %s\n",
+ dirpath, strerror(errno));
+ return;
+ }
+
+ while ((dent = readdir(dir)) != NULL) {
+ if (is_dot_or_dotdot(dent->d_name))
+ continue;
+
+ ret = asprintf(&devnode, "%s/%s", dirpath, dent->d_name);
+ if (ret < 0)
+ continue;
+
+ android_seat_open_device(seat, devnode);
+ free(devnode);
+ }
+
+ closedir(dir);
+}
+
+static void
android_seat_destroy(struct android_seat *seat)
{
- weston_seat_release(&seat->base);
+ evdev_seat_release(&seat->evdev);
free(seat);
}
@@ -246,8 +311,17 @@ android_seat_create(struct android_compositor *compositor)
if (!seat)
return NULL;
- weston_seat_init(&seat->base, &compositor->base);
- compositor->base.seat = &seat->base;
+ evdev_seat_init(&seat->evdev, &compositor->base);
+ compositor->base.seat = &seat->evdev.base;
+
+ android_seat_scan_devices(seat, "/dev/input");
+
+ evdev_notify_keyboard_focus(&seat->evdev);
+
+ if (wl_list_empty(&seat->evdev.devices_list))
+ weston_log("Warning: no input devices found.\n");
+
+ /* XXX: implement hotplug support */
return seat;
}
@@ -414,6 +488,8 @@ android_compositor_create(struct wl_display *display, int argc, char *argv[],
struct android_compositor *compositor;
struct android_output *output;
+ weston_log("initializing android backend\n");
+
compositor = calloc(1, sizeof *compositor);
if (compositor == NULL)
return NULL;
--
1.7.8.6
More information about the wayland-devel
mailing list