AC_SUBST(PEPPER_X11_REQUIRES)
fi
-# doctor
-DOCTOR_REQUIRES="wayland-server pixman-1 libudev"
-PKG_CHECK_MODULES(DOCTOR, [$DOCTOR_REQUIRES])
-
-DOCTOR_CFLAGS="$PEPPER_DIR $PEPPER_DRM_DIR $PEPPER_DESKTOP_SHELL_DIR $DOCTOR_CFLAGS"
-DOCTOR_CFLAGS="$PEPPER_LIBINPUT_DIR $DOCTOR_CFLAGS"
-DOCTOR_LIBS="$PEPPER_LIB $PEPPER_DRM_LIB $PEPPER_DESKTOP_SHELL_LIB $DOCTOR_LIBS"
-DOCTOR_LIBS="$PEPPER_LIBINPUT_LIB $PEPPER_LIBINPUT_LIBS $DOCTOR_LIBS"
-
-AC_SUBST(DOCTOR_CFLAGS)
-AC_SUBST(DOCTOR_LIBS)
-
# shell client
SHELL_CLIENT_REQUIRES="wayland-client pixman-1"
PKG_CHECK_MODULES(SHELL_CLIENT, [$SHELL_CLIENT_REQUIRES])
AC_SUBST(SAMPLES_CFLAGS)
AC_SUBST(SAMPLES_LIBS)
-# headless server and headless client samples
-HEADLESS_SERVER_REQUIRES="wayland-server"
-PKG_CHECK_MODULES(HEADLESS_SERVER, $[HEADLESS_SERVER_REQUIRES])
-HEADLESS_SERVER_CFLAGS="$PEPPER_DIR $PEPPER_EVDEV_DIR $PEPPER_KEYROUTER_DIR $HEADLESS_SERVER_CFLAGS"
-HEADLESS_SERVER_LIBS="$PEPPER_LIB $PEPPER_LIBS $HEADLESS_SERVER_LIBS"
-HEADLESS_SERVER_LIBS="$PEPPER_EVDEV_LIB $PEPPER_EVDEV_LIBS $HEADLESS_SERVER_LIBS"
-HEADLESS_SERVER_LIBS="$PEPPER_KEYROUTER_LIB $PEPPER_KEYROUTER_LIBS $HEADLESS_SERVER_LIBS"
+# doctor (headless server) and headless client samples
+DOCTOR_SERVER_REQUIRES="wayland-server"
+PKG_CHECK_MODULES(DOCTOR_SERVER, $[DOCTOR_SERVER_REQUIRES])
+DOCTOR_SERVER_CFLAGS="$PEPPER_DIR $PEPPER_EVDEV_DIR $PEPPER_KEYROUTER_DIR $DOCTOR_SERVER_CFLAGS"
+DOCTOR_SERVER_LIBS="$PEPPER_LIB $PEPPER_LIBS $DOCTOR_SERVER_LIBS"
+DOCTOR_SERVER_LIBS="$PEPPER_EVDEV_LIB $PEPPER_EVDEV_LIBS $DOCTOR_SERVER_LIBS"
+DOCTOR_SERVER_LIBS="$PEPPER_KEYROUTER_LIB $PEPPER_KEYROUTER_LIBS $DOCTOR_SERVER_LIBS"
-AC_SUBST(HEADLESS_SERVER_CFLAGS)
-AC_SUBST(HEADLESS_SERVER_LIBS)
+AC_SUBST(DOCTOR_SERVER_CFLAGS)
+AC_SUBST(DOCTOR_SERVER_LIBS)
-HEADLESS_CLIENT_REQUIRES="wayland-client tizen-extension-client"
-PKG_CHECK_MODULES(HEADLESS_CLIENT, $[HEADLESS_CLIENT_REQUIRES])
-HEADLESS_CLIENT_CFLAGS="$HEADLESS_CLIENT_CFLAGS"
-HEADLESS_CLIENT_LIBS="$HEADLESS_CLIENT_LIBS"
+DOCTOR_CLIENT_REQUIRES="wayland-client tizen-extension-client"
+PKG_CHECK_MODULES(DOCTOR_CLIENT, $[DOCTOR_CLIENT_REQUIRES])
+DOCTOR_CLIENT_CFLAGS="$DOCTOR_CLIENT_CFLAGS"
+DOCTOR_CLIENT_LIBS="$DOCTOR_CLIENT_LIBS"
-AC_SUBST(HEADLESS_CLIENT_CFLAGS)
-AC_SUBST(HEADLESS_CLIENT_LIBS)
+AC_SUBST(DOCTOR_CLIENT_CFLAGS)
+AC_SUBST(DOCTOR_CLIENT_LIBS)
# sample client
SAMPLE_CLIENT_REQUIRES="wayland-client tizen-extension-client xkbcommon"
###### doctor server
%package doctor
Summary: Doctor server for pepper package
+Requires: pepper pepper-keyrouter pepper-evdev
%description doctor
This package includes doctor server files.
%manifest %{name}.manifest
%defattr(-,root,root,-)
%license COPYING
-%{_bindir}/doctor
+%{_bindir}/doctor*
%files samples
%manifest %{name}.manifest
%defattr(-,root,root,-)
%{_bindir}/*-backend
-%{_bindir}/headless*
%{_bindir}/sample-*
-bin_PROGRAMS = doctor
+bin_PROGRAMS =
-doctor_CFLAGS = $(DOCTOR_CFLAGS)
-doctor_LDADD = $(DOCTOR_LIBS)
+bin_PROGRAMS += doctor doctor-client
+
+doctor_CFLAGS = $(DOCTOR_SERVER_CFLAGS)
+doctor_LDADD = $(DOCTOR_SERVER_LIBS)
+
+doctor_SOURCES = doctor.c
+
+doctor_client_CFLAGS = $(DOCTOR_CLIENT_CFLAGS)
+doctor_client_LDADD = $(DOCTOR_CLIENT_LIBS)
+
+doctor_client_SOURCES = doctor-client.c
-doctor_SOURCES = server.c
--- /dev/null
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <wayland-client.h>
+#include <tizen-extension-client-protocol.h>
+
+#define DEBUG
+#ifdef DEBUG
+#define TRACE(fmt, ...) \
+ do { \
+ printf("[headless-client : %s] "fmt, __FUNCTION__, ##__VA_ARGS__); \
+ } while (0)
+#else
+#define TRACE(fmt, ...)
+ do { \
+ ;
+ } while (0)
+#endif
+
+#define ERROR_CHECK(exp, action, fmt, ...) \
+ do { \
+ if (!(exp)) \
+ { \
+ printf(fmt, ##__VA_ARGS__); \
+ action; \
+ } \
+ } while (0)
+
+typedef struct tizen_keyrouter_notify tizen_keyrouter_notify_t;
+struct tizen_keyrouter_notify
+{
+ unsigned int keycode;
+ unsigned int mode;
+ unsigned int error;
+};
+
+typedef struct headless_info headless_info_t;
+struct headless_info
+{
+ struct wl_display *display;
+ struct wl_seat *seat;
+ struct wl_keyboard *keyboard;
+ struct tizen_keyrouter *tz_keyrouter;
+
+ unsigned int has_keymap:1;
+ unsigned int enter:1;
+ unsigned int caps_updated:1;
+ unsigned int notified:1;
+ unsigned int need_exit:1;
+
+ struct wl_array array;
+};
+
+//function prototype
+static void
+do_action(headless_info_t *headless, int keycode)
+{
+ TRACE("keycode:%d\n", keycode);
+}
+
+// wl_keyboard listener
+static void keyboard_keymap(void *, struct wl_keyboard *, unsigned int, int fd, unsigned int);
+static void keyboard_enter(void *, struct wl_keyboard *, unsigned int, struct wl_surface *, struct wl_array *);
+static void keyboard_leave(void *, struct wl_keyboard *, unsigned int, struct wl_surface *);
+static void keyboard_key(void *, struct wl_keyboard *, unsigned int, unsigned int, unsigned int, unsigned int);
+static void keyboard_modifiers(void *, struct wl_keyboard *, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int);
+static void keyboard_repeat_setup(void *, struct wl_keyboard *, int32_t, int32_t);
+
+// wl_seat listener
+static void seat_handle_capabilities(void *, struct wl_seat *, enum wl_seat_capability);
+static void seat_handle_name(void *data, struct wl_seat *seat, const char *name);
+
+// wl_registry listener
+static void handle_global(void *, struct wl_registry *, unsigned int, const char *, unsigned int);
+static void handle_global_remove(void *, struct wl_registry *, unsigned int);
+
+// tizen_keyrouter listener
+static void keygrab_notify(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, uint32_t key, uint32_t mode, uint32_t error);
+static void keygrab_notify_list(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, struct wl_array *notify_result);
+static void getgrab_notify_list(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, struct wl_array *notify_result);
+static void set_register_none_key(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, uint32_t mode);
+static void keyregister_notify(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t status);
+static void set_input_config(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t status);
+static void key_cancel(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t key);
+
+static const struct wl_registry_listener registry_listener = {
+ handle_global,
+ handle_global_remove,
+};
+
+static const struct wl_seat_listener seat_listener = {
+ seat_handle_capabilities,
+ seat_handle_name,
+};
+
+static const struct wl_keyboard_listener keyboard_listener = {
+ keyboard_keymap,
+ keyboard_enter,
+ keyboard_leave,
+ keyboard_key,
+ keyboard_modifiers,
+ keyboard_repeat_setup,
+};
+
+static const struct tizen_keyrouter_listener keyrouter_listener = {
+ keygrab_notify,
+ keygrab_notify_list,
+ getgrab_notify_list,
+ set_register_none_key,
+ keyregister_notify,
+ set_input_config,
+ key_cancel,
+};
+
+static void
+keyboard_keymap(void *data, struct wl_keyboard *keyboard, unsigned int format, int fd, unsigned int size)
+{
+ headless_info_t *headless = (headless_info_t *)data;
+
+ if (format == WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP)
+ {
+ headless->has_keymap = 0;
+ }
+ else
+ {
+ headless->has_keymap = 1;
+ TRACE("wl_keyboard has keymap...Now the given fd is going to be closed.\n");
+
+ close(fd);
+ }
+
+ TRACE("has_keymap = %s\n", headless->has_keymap ? "true" : "false");
+}
+
+static void
+keyboard_enter(void *data, struct wl_keyboard *keyboard, unsigned int serial, struct wl_surface *surface, struct wl_array *keys)
+{
+ headless_info_t *headless = (headless_info_t *)data;
+
+ headless->enter = 1;
+ TRACE("keyboard enter\n");
+}
+
+static void
+keyboard_leave(void *data, struct wl_keyboard *keyboard, unsigned int serial, struct wl_surface *surface)
+{
+ headless_info_t *headless = (headless_info_t *)data;
+
+ headless->enter = 0;
+ TRACE("keyboard leave\n");
+}
+
+static void
+keyboard_key(void *data, struct wl_keyboard *keyboard, unsigned int serial, unsigned int timestamp, unsigned int keycode, unsigned int state)
+{
+ headless_info_t *headless = (headless_info_t *)data;
+
+ if (!headless->has_keymap)
+ {
+ //TODO : do anything with the given keycode
+ // ex> call application callback(s)
+ TRACE("keycode : %d, state : %d, timestamp : %d\n", keycode, state, timestamp);
+
+ if (state)
+ do_action(headless, keycode);
+ }
+ else
+ {
+ TRACE("keycode(%d) won't be dealt with as there is no keymap.\n", keycode);
+ }
+}
+
+static void
+keyboard_modifiers(void *data, struct wl_keyboard *keyboard, unsigned int serial, unsigned int depressed, unsigned int latched, unsigned int locked, unsigned int group)
+{
+ TRACE("...\n");
+}
+
+static void
+keyboard_repeat_setup(void *data, struct wl_keyboard *keyboard, int32_t rate, int32_t delay)
+{
+ TRACE("...\n");
+}
+
+static void
+seat_handle_capabilities(void *data, struct wl_seat *seat, enum wl_seat_capability caps)
+{
+ headless_info_t *headless = (headless_info_t *)data;
+
+ if ((caps & WL_SEAT_CAPABILITY_KEYBOARD))
+ {
+ if (headless->keyboard)
+ {
+ wl_keyboard_release(headless->keyboard);
+ headless->keyboard = NULL;
+ }
+
+ headless->keyboard = wl_seat_get_keyboard(seat);
+ ERROR_CHECK(headless->keyboard, return, "Failed to get wl_keyboard from a seat !\n");
+
+ wl_keyboard_set_user_data(headless->keyboard, headless);
+ wl_keyboard_add_listener(headless->keyboard, &keyboard_listener, headless);
+ headless->caps_updated = 1;
+
+ TRACE("seat caps update : keyboard added\n");
+ }
+ else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && (headless->keyboard))
+ {
+ wl_keyboard_release(headless->keyboard);
+ headless->keyboard = NULL;
+ headless->caps_updated = 1;
+ }
+}
+
+static void
+seat_handle_name(void *data, struct wl_seat *seat, const char *name)
+{
+ //TODO : handle seat name properly
+}
+
+static void
+keygrab_notify(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, uint32_t key, uint32_t mode, uint32_t error)
+{
+ TRACE("key : %d, mode : %d, error : %d\n", key, mode, error);
+}
+
+static void
+keygrab_notify_list(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, struct wl_array *notify_result)
+{
+ tizen_keyrouter_notify_t *tz_keyrouter_notify;
+ headless_info_t *headless = (headless_info_t *)data;
+
+ wl_array_init(&headless->array);
+ wl_array_copy(&headless->array, notify_result);
+
+ wl_array_for_each(tz_keyrouter_notify, &headless->array)
+ {
+ TRACE("... keygrab result ! (keycode : %d, mode : %d, error : %d)\n",
+ tz_keyrouter_notify->keycode, tz_keyrouter_notify->mode, tz_keyrouter_notify->error);
+ }
+
+ wl_array_release(&headless->array);
+ headless->notified = 1;
+}
+
+static void getgrab_notify_list(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, struct wl_array *notify_result)
+{
+ TRACE("...\n");
+}
+
+static void set_register_none_key(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, uint32_t mode)
+{
+ TRACE("...\n");
+}
+
+static void keyregister_notify(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t status)
+{
+ TRACE("...\n");
+}
+
+static void set_input_config(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t status)
+{
+ TRACE("...\n");
+}
+
+static void key_cancel(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t key)
+{
+ TRACE("...\n");
+}
+
+static void
+handle_global(void *data, struct wl_registry *registry, unsigned int id, const char *interface, unsigned int version)
+{
+ headless_info_t *headless = (headless_info_t *)data;
+
+ if (!strcmp("wl_seat", interface))
+ {
+ headless->seat = wl_registry_bind(registry, id, &wl_seat_interface, 4);
+ wl_seat_add_listener(headless->seat, &seat_listener, headless);
+ wl_seat_set_user_data(headless->seat, headless);
+ }
+ else if (!strcmp("tizen_keyrouter", interface))
+ {
+ headless->tz_keyrouter = wl_registry_bind(registry, id, &tizen_keyrouter_interface, 1);
+ tizen_keyrouter_add_listener(headless->tz_keyrouter, &keyrouter_listener, headless);
+ tizen_keyrouter_set_user_data(headless->tz_keyrouter, headless);
+ }
+ else
+ {
+ TRACE("Unbound global object (id:%d, interface:%s, version:%d)\n", id, interface, version);
+ }
+}
+
+static void
+handle_global_remove(void *data, struct wl_registry *registry, unsigned int id)
+{
+ //TODO : remove/cleanup global and related information
+}
+
+static int
+_grab_wait(headless_info_t *headless)
+{
+ int ret;
+
+ while (!headless->notified)
+ {
+ ret = wl_display_roundtrip(headless->display);
+ if ((0 > ret) && (errno != EAGAIN && (errno != EINVAL)))
+ {
+ TRACE("Wayland socket error ! (errno=%d)\n", errno);
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+static int
+grab_keys(headless_info_t *headless)
+{
+ int ret;
+ unsigned int *uint_ptr = NULL;
+
+ struct wl_array keygrab_array;
+
+ wl_array_init(&keygrab_array);
+
+ //grab information : key(169), mode(OR_EXCLUSIVE) and error
+ uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
+ *uint_ptr = 169;//menu key
+ uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
+ *uint_ptr = TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE;
+ uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
+ *uint_ptr = 0;
+
+ //grab information : key(139), mode(OR_EXCLUSIVE) and error
+ uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
+ *uint_ptr = 139;//home key
+ uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
+ *uint_ptr = TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE;
+ uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
+ *uint_ptr = 0;
+
+ //grab information : key(158), mode(OR_EXCLUSIVE) and error
+ uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
+ *uint_ptr = 158;//back key
+ uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
+ *uint_ptr = TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE;
+ uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
+ *uint_ptr = 0;
+
+ //grab information : key(28), mode(OR_EXCLUSIVE) and error
+ uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
+ *uint_ptr = 28;//enter key on a keyboard
+ uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
+ *uint_ptr = TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE;
+ uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
+ *uint_ptr = 0;
+
+ //grab information : key(57), mode(OR_EXCLUSIVE) and error
+ uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
+ *uint_ptr = 57;//space bar on a keyboard
+ uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
+ *uint_ptr = TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE;
+ uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
+ *uint_ptr = 0;
+
+ TRACE("Waiting for requesting grab for keys...\n");
+ headless->notified = 0;
+ tizen_keyrouter_set_keygrab_list(headless->tz_keyrouter, NULL, &keygrab_array);
+ ret = _grab_wait(headless);
+ TRACE("...done...\n");
+
+ wl_array_release(&keygrab_array);
+
+ return ret;
+}
+
+int main()
+{
+ int ret;
+ const char *socket_name = NULL;
+ headless_info_t *headless = NULL;
+ struct wl_registry *registry = NULL;
+
+ headless = (headless_info_t *)calloc(1, sizeof(headless_info_t));
+ ERROR_CHECK(headless, return 0, "Failed to allocate memory for headless info...\n");
+
+ socket_name = getenv("WAYLAND_DISPLAY");
+
+ if (!socket_name)
+ socket_name = "headless-0";
+
+ if (!getenv("XDG_RUNTIME_DIR"))
+ setenv("XDG_RUNTIME_DIR", "/run", 1);
+
+ headless->display = wl_display_connect(socket_name);
+ ERROR_CHECK(headless->display, return 0, "Failed to connect wayland display ! (socket_name : %s)\n", socket_name);
+
+ registry = wl_display_get_registry(headless->display);
+ ERROR_CHECK(registry, return 0, "Failed to get registry...\n");
+ wl_registry_add_listener(registry, ®istry_listener, headless);
+
+ TRACE("Waiting for tizen_keyrouter interface ...\n");
+ while(!headless->tz_keyrouter)
+ wl_display_roundtrip(headless->display);
+ TRACE("...done...\n");
+
+ TRACE("Waiting wl_seat interface ...\n");
+ while (!headless->seat)
+ wl_display_roundtrip(headless->display);
+ TRACE("...done...\n");
+
+ TRACE("Waiting for capabilities to be updated...\n");
+ while(!headless->caps_updated)
+ wl_display_roundtrip(headless->display);
+ TRACE("...done...\n");
+
+ TRACE("Waiting wl_keyboard interface ...\n");
+ while(!headless->keyboard)
+ wl_display_roundtrip(headless->display);
+ TRACE("...done...\n");
+
+ ret = grab_keys(headless);
+ ERROR_CHECK(ret, headless->need_exit = 1, "Failed to grab keys...\n");
+
+ while ((-1 != wl_display_dispatch(headless->display)) && !headless->need_exit)
+ {
+ ;
+ }
+
+ wl_keyboard_release(headless->keyboard);
+ wl_seat_destroy(headless->seat);
+ tizen_keyrouter_destroy(headless->tz_keyrouter);
+
+ wl_display_disconnect(headless->display);
+
+ free(headless);
+ return 0;
+}
+
--- /dev/null
+#include <pepper.h>
+#include <pepper-input-backend.h>
+#include <pepper-evdev.h>
+#include <pepper-keyrouter.h>
+#include <stdlib.h>
+
+/* basic pepper objects */
+pepper_seat_t *seat = NULL;
+pepper_evdev_t *evdev = NULL;
+pepper_keyrouter_t *keyrouter = NULL;
+pepper_compositor_t *compositor = NULL;
+pepper_input_device_t *input_device = NULL;
+
+/* event listeners */
+pepper_event_listener_t *listener_seat_add = NULL;
+pepper_event_listener_t *listener_input_add = NULL;
+pepper_event_listener_t *listener_input_remove = NULL;
+pepper_event_listener_t *listener_keyboard_add = NULL;
+pepper_event_listener_t *listener_keyboard_event = NULL;
+pepper_event_listener_t *listener_pointer_add = NULL;
+pepper_event_listener_t *listener_pointer_event = NULL;
+pepper_event_listener_t *listener_touch_add = NULL;
+pepper_event_listener_t *listener_touch_event = NULL;
+
+/* pointer event handler */
+static void
+_handle_pointer_event(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
+{
+ pepper_input_event_t *event;
+
+ PEPPER_CHECK((id >= PEPPER_EVENT_POINTER_MOTION && id <= PEPPER_EVENT_POINTER_AXIS), return, "unknown event %d !\n", id);
+ PEPPER_CHECK(info, return, "Invalid event !\n");
+ PEPPER_CHECK(data, return, "Invalid data !\n");
+
+ event = (pepper_input_event_t *)info;
+
+ /* TODO: */
+ (void) event;
+
+ switch (id)
+ {
+ case PEPPER_EVENT_POINTER_MOTION:
+ /* TODO: */
+ PEPPER_TRACE("[%s] PEPPER_EVENT_POINTER_MOTION\n", __FUNCTION__);
+ break;
+ case PEPPER_EVENT_POINTER_MOTION_ABSOLUTE:
+ /* TODO: */
+ PEPPER_TRACE("[%s] PEPPER_EVENT_POINTER_MOTION_ABSOLUTE\n", __FUNCTION__);
+ break;
+ case PEPPER_EVENT_POINTER_BUTTON:
+ /* TODO: */
+ PEPPER_TRACE("[%s] PEPPER_EVENT_POINTER_BUTTON\n", __FUNCTION__);
+ break;
+ case PEPPER_EVENT_POINTER_AXIS:
+ /* TODO: */
+ PEPPER_TRACE("[%s] PEPPER_EVENT_POINTER_AXIS\n", __FUNCTION__);
+ break;
+ default:
+ break;
+ }
+}
+
+/* touch event handler */
+static void
+_handle_touch_event(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
+{
+ pepper_input_event_t *event;
+
+ PEPPER_CHECK((id >= PEPPER_EVENT_TOUCH_DOWN && id <= PEPPER_EVENT_TOUCH_CANCEL), return, "unknown event %d !\n", id);
+ PEPPER_CHECK(info, return, "Invalid event !\n");
+ PEPPER_CHECK(data, return, "Invalid data !\n");
+
+ event = (pepper_input_event_t *)info;
+
+ /* TODO: */
+ (void) event;
+
+ switch (id)
+ {
+ case PEPPER_EVENT_TOUCH_DOWN:
+ /* TODO: */
+ PEPPER_TRACE("[%s] PEPPER_EVENT_TOUCH_DOWN\n", __FUNCTION__);
+ break;
+ case PEPPER_EVENT_TOUCH_UP:
+ /* TODO: */
+ PEPPER_TRACE("[%s] PEPPER_EVENT_TOUCH_UP\n", __FUNCTION__);
+ break;
+ case PEPPER_EVENT_TOUCH_MOTION:
+ /* TODO: */
+ PEPPER_TRACE("[%s] PEPPER_EVENT_TOUCH_MOTION\n", __FUNCTION__);
+ break;
+ case PEPPER_EVENT_TOUCH_FRAME:
+ /* TODO: */
+ PEPPER_TRACE("[%s] PEPPER_EVENT_TOUCH_FRAME\n", __FUNCTION__);
+ break;
+ case PEPPER_EVENT_TOUCH_CANCEL:
+ /* TODO: */
+ PEPPER_TRACE("[%s] PEPPER_EVENT_TOUCH_CANCEL\n", __FUNCTION__);
+ break;
+ default:
+ break;
+ }
+}
+
+/* seat keyboard add event handler */
+static void
+_handle_seat_keyboard_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
+{
+ pepper_keyboard_t *keyboard = (pepper_keyboard_t *)info;
+
+ PEPPER_TRACE("[%s] keyboard added\n", __FUNCTION__);
+
+ pepper_keyboard_set_keymap_info(keyboard, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP, -1, 0);
+
+ listener_keyboard_event = pepper_object_add_event_listener((pepper_object_t *)keyboard,
+ PEPPER_EVENT_KEYBOARD_KEY,
+ 0,
+ pepper_keyrouter_event_handler,
+ (void *)keyrouter);
+}
+
+/* seat pointer add event handler */
+static void
+_handle_seat_pointer_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
+{
+ pepper_pointer_t *pointer = (pepper_pointer_t *)info;
+
+ PEPPER_TRACE("[%s] pointer added\n", __FUNCTION__);
+
+ listener_pointer_event = pepper_object_add_event_listener((pepper_object_t *)pointer,
+ PEPPER_EVENT_POINTER_MOTION
+ | PEPPER_EVENT_POINTER_MOTION_ABSOLUTE
+ | PEPPER_EVENT_POINTER_BUTTON
+ | PEPPER_EVENT_POINTER_AXIS,
+ 0,
+ _handle_pointer_event,
+ /*compositor*/ data);
+}
+
+/* seat touch add event handler */
+static void
+_handle_seat_touch_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
+{
+ pepper_touch_t *touch = (pepper_touch_t *)info;
+
+ PEPPER_TRACE("[%s] touch added\n", __FUNCTION__);
+
+ listener_touch_event = pepper_object_add_event_listener((pepper_object_t *)touch,
+ PEPPER_EVENT_TOUCH_DOWN
+ | PEPPER_EVENT_TOUCH_UP
+ | PEPPER_EVENT_TOUCH_MOTION
+ | PEPPER_EVENT_TOUCH_FRAME
+ | PEPPER_EVENT_TOUCH_CANCEL,
+ 0,
+ _handle_touch_event,
+ /*compositor*/ data);
+}
+
+/* seat add event handler */
+static void
+_handle_seat_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
+{
+ pepper_seat_t *seat = (pepper_seat_t *)info;
+
+ PEPPER_TRACE("[%s] seat added. name:%s\n", __FUNCTION__, pepper_seat_get_name(seat));
+
+ listener_keyboard_add = pepper_object_add_event_listener((pepper_object_t *)seat,
+ PEPPER_EVENT_SEAT_KEYBOARD_ADD,
+ 0,
+ _handle_seat_keyboard_add, /*compositor*/ data);
+
+ listener_pointer_add = pepper_object_add_event_listener((pepper_object_t *)seat,
+ PEPPER_EVENT_SEAT_POINTER_ADD,
+ 0,
+ _handle_seat_pointer_add, /*compositor*/ data);
+
+ listener_touch_add = pepper_object_add_event_listener((pepper_object_t *)seat,
+ PEPPER_EVENT_SEAT_TOUCH_ADD,
+ 0,
+ _handle_seat_touch_add, /*compositor*/ data);
+
+}
+
+/* compositor input device add event handler */
+static void
+_handle_input_device_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
+{
+ pepper_input_device_t *device = (pepper_input_device_t *)info;
+
+ PEPPER_TRACE("[%s] input device added.\n", __FUNCTION__);
+
+ if (seat)
+ pepper_seat_add_input_device(seat, device);
+}
+
+/* compositor input deviec remove event handler */
+static void
+_handle_input_device_remove(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
+{
+ pepper_input_device_t *device = (pepper_input_device_t *)info;
+
+ PEPPER_TRACE("[%s] input device removed.\n", __FUNCTION__);
+
+ if (seat)
+ pepper_seat_remove_input_device(seat, device);
+}
+
+int main(int argc, char *argv[])
+{
+ uint32_t caps = 0;
+ uint32_t probed = 0;
+ int ret = EXIT_SUCCESS;
+
+ const char* socket_name = NULL;
+ const char* seat_name = NULL;
+
+ socket_name = getenv("WAYLAND_DISPLAY");
+
+ if (!socket_name)
+ socket_name = "headless-0";
+
+ if (!getenv("XDG_RUNTIME_DIR"))
+ setenv("XDG_RUNTIME_DIR", "/run", 1);
+
+ /* create pepper compositor */
+ compositor = pepper_compositor_create(socket_name);
+ PEPPER_CHECK(compositor, return EXIT_FAILURE, "Failed to create compositor !\n");
+
+ /* register event listeners */
+ listener_seat_add = pepper_object_add_event_listener((pepper_object_t *)compositor,
+ PEPPER_EVENT_COMPOSITOR_SEAT_ADD,
+ 0, _handle_seat_add, compositor);
+ PEPPER_CHECK(listener_seat_add, goto shutdown_on_failure, "Failed to add seat add listener.\n");
+
+ listener_input_add = pepper_object_add_event_listener((pepper_object_t *)compositor,
+ PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_ADD,
+ 0, _handle_input_device_add, compositor);
+ PEPPER_CHECK(listener_input_add, goto shutdown_on_failure, "Failed to add input device add listener.\n");
+
+ listener_input_remove = pepper_object_add_event_listener((pepper_object_t *)compositor,
+ PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_REMOVE,
+ 0, _handle_input_device_remove, compositor);
+ PEPPER_CHECK(listener_input_remove, goto shutdown_on_failure, "Failed to add input device remove listener.\n");
+
+ /* create pepper keyrouter */
+ keyrouter = pepper_keyrouter_create(compositor);
+ PEPPER_CHECK(keyrouter, goto shutdown_on_failure, "Failed to create keyrouter !\n");
+
+ /* seat add : if there is no seat name, set seat0 as a default seat name */
+ seat_name = getenv("WAYLAND_SEAT");
+
+ if (!seat_name)
+ seat_name = "seat0";
+
+ seat = pepper_compositor_add_seat(compositor, seat_name);
+ PEPPER_CHECK(seat, goto shutdown_on_failure, "Failed to add seat !\n");
+
+ /* get capabilities for a default pepper input device*/
+ if (getenv("WAYLAND_INPUT_KEYBOARD"))
+ caps |= WL_SEAT_CAPABILITY_KEYBOARD;
+ if (getenv("WAYLAND_INPUT_POINTER"))
+ caps |= WL_SEAT_CAPABILITY_POINTER;
+ if (getenv("WAYLAND_INPUT_TOUCH"))
+ caps |= WL_SEAT_CAPABILITY_TOUCH;
+
+ /* if there is no capability, set keyboard capability by default */
+ if (!caps)
+ caps = WL_SEAT_CAPABILITY_KEYBOARD;
+
+ /* create a default pepper input device */
+ input_device = pepper_input_device_create(compositor, caps, NULL, NULL);
+ PEPPER_CHECK(input_device, goto shutdown_on_failure, "Failed to create input device !\n");
+
+ /* create pepper evdev */
+ evdev = pepper_evdev_create(compositor);
+ PEPPER_CHECK(evdev, goto shutdown_on_failure, "Failed to create evdev !\n");
+
+ /* probe evdev input device(s) */
+ probed = pepper_evdev_device_probe(evdev, caps);
+
+ if (!probed)
+ PEPPER_TRACE("No evdev devices have been probed.\n");
+ else
+ PEPPER_TRACE("%d evdev device(s) has been probed.\n", probed);
+
+ /* create server module(s) loader : TODO */
+
+ /* run event loop */
+ wl_display_run(pepper_compositor_get_display(compositor));
+
+ goto shutdown;
+
+shutdown_on_failure:
+ ret = EXIT_FAILURE;
+shutdown:
+
+ /* destroy all remain event listeners */
+ if (listener_seat_add)
+ {
+ pepper_event_listener_remove(listener_seat_add);
+ listener_seat_add = NULL;
+ }
+
+ if (listener_input_add)
+ {
+ pepper_event_listener_remove(listener_input_add);
+ listener_input_add = NULL;
+ }
+
+ if (listener_input_remove)
+ {
+ pepper_event_listener_remove(listener_input_remove);
+ listener_input_remove = NULL;
+ }
+
+ /* destroy input device */
+ if (input_device)
+ {
+ pepper_input_device_destroy(input_device);
+ input_device = NULL;
+ }
+
+ /* destroy seat */
+ if (seat)
+ {
+ pepper_seat_destroy(seat);
+ seat = NULL;
+ }
+
+ /* TODO : clean up any other objects if needed */
+
+ /* destroy keyrouter */
+ if (keyrouter)
+ {
+ pepper_keyrouter_destroy(keyrouter);
+ keyrouter = NULL;
+
+ }
+
+ /* destroy evdev */
+ if (evdev)
+ {
+ pepper_evdev_destroy(evdev);
+ evdev = NULL;
+ }
+
+ /* destroy compositor */
+ if (compositor)
+ {
+ pepper_compositor_destroy(compositor);
+ compositor = NULL;
+ }
+
+ return ret;
+}
+++ /dev/null
-/*
-* Copyright © 2008-2012 Kristian Høgsberg
-* Copyright © 2010-2012 Intel Corporation
-* Copyright © 2011 Benjamin Franzke
-* Copyright © 2012 Collabora, Ltd.
-* Copyright © 2015 S-Core Corporation
-* Copyright © 2015-2016 Samsung Electronics co., Ltd. All Rights Reserved.
-*
-* Permission is hereby granted, free of charge, to any person obtaining a
-* copy of this software and associated documentation files (the "Software"),
-* to deal in the Software without restriction, including without limitation
-* the rights to use, copy, modify, merge, publish, distribute, sublicense,
-* and/or sell copies of the Software, and to permit persons to whom the
-* Software is furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice (including the next
-* paragraph) shall be included in all copies or substantial portions of the
-* Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-* DEALINGS IN THE SOFTWARE.
-*/
-
-#include <pepper.h>
-
-#include <libudev.h>
-#include <pepper-libinput.h>
-#include <pepper-desktop-shell.h>
-
-int
-main(int argc, char **argv)
-{
- struct udev *udev = NULL;
- pepper_libinput_t *input = NULL;
-
- struct wl_display *display;
- pepper_compositor_t *compositor;
- const char* socket_name = NULL;
-
- if (!getenv("XDG_RUNTIME_DIR"))
- setenv("XDG_RUNTIME_DIR", "/run", 1);
-
- socket_name = getenv("WAYLAND_DISPLAY");
-
- if (!socket_name)
- socket_name = "wayland-0";
-
- compositor = pepper_compositor_create(socket_name);
-
- if (!compositor)
- return -1;
-
- display = pepper_compositor_get_display(compositor);
-
- if (!display)
- {
- pepper_compositor_destroy(compositor);
- return -1;
- }
-
- udev = udev_new();
- PEPPER_CHECK(udev, goto shutdown_on_failure, "Failed to get udev !\n");
-
- input = pepper_libinput_create(compositor, udev);
- PEPPER_CHECK(input, goto shutdown_on_failure, "Failed to create pepepr libinput !\n");
-
- if (!pepper_desktop_shell_init(compositor))
- {
- PEPPER_ERROR("Failed to initialize pepper desktop shell !\n");
- goto shutdown_on_failure;
- }
-
- /* Enter main loop. */
- wl_display_run(display);
-
-shutdown_on_failure:
-
- if (input)
- pepper_libinput_destroy(input);
-
- if (udev)
- udev_unref(udev);
-
- if (compositor)
- pepper_compositor_destroy(compositor);
-
- return 0;
-}
x11_backend_SOURCES = x11-backend.c
endif
-bin_PROGRAMS += headless-server headless-client
-
-headless_server_CFLAGS = $(HEADLESS_SERVER_CFLAGS)
-headless_server_LDADD = $(HEADLESS_SERVER_LIBS)
-
-headless_server_SOURCES = headless-server.c
-
-headless_client_CFLAGS = $(HEADLESS_CLIENT_CFLAGS)
-headless_client_LDADD = $(HEADLESS_CLIENT_LIBS)
-
-headless_client_SOURCES = headless-client.c
-
bin_PROGRAMS += sample-server sample-client
sample_server_CFLAGS = $(SAMPLE_SERVER_CFLAGS)
+++ /dev/null
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <wayland-client.h>
-#include <tizen-extension-client-protocol.h>
-
-#define DEBUG
-#ifdef DEBUG
-#define TRACE(fmt, ...) \
- do { \
- printf("[headless-client : %s] "fmt, __FUNCTION__, ##__VA_ARGS__); \
- } while (0)
-#else
-#define TRACE(fmt, ...)
- do { \
- ;
- } while (0)
-#endif
-
-#define ERROR_CHECK(exp, action, fmt, ...) \
- do { \
- if (!(exp)) \
- { \
- printf(fmt, ##__VA_ARGS__); \
- action; \
- } \
- } while (0)
-
-typedef struct tizen_keyrouter_notify tizen_keyrouter_notify_t;
-struct tizen_keyrouter_notify
-{
- unsigned int keycode;
- unsigned int mode;
- unsigned int error;
-};
-
-typedef struct headless_info headless_info_t;
-struct headless_info
-{
- struct wl_display *display;
- struct wl_seat *seat;
- struct wl_keyboard *keyboard;
- struct tizen_keyrouter *tz_keyrouter;
-
- unsigned int has_keymap:1;
- unsigned int enter:1;
- unsigned int caps_updated:1;
- unsigned int notified:1;
- unsigned int need_exit:1;
-
- struct wl_array array;
-};
-
-//function prototype
-static void
-do_action(headless_info_t *headless, int keycode)
-{
- TRACE("keycode:%d\n", keycode);
-}
-
-// wl_keyboard listener
-static void keyboard_keymap(void *, struct wl_keyboard *, unsigned int, int fd, unsigned int);
-static void keyboard_enter(void *, struct wl_keyboard *, unsigned int, struct wl_surface *, struct wl_array *);
-static void keyboard_leave(void *, struct wl_keyboard *, unsigned int, struct wl_surface *);
-static void keyboard_key(void *, struct wl_keyboard *, unsigned int, unsigned int, unsigned int, unsigned int);
-static void keyboard_modifiers(void *, struct wl_keyboard *, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int);
-static void keyboard_repeat_setup(void *, struct wl_keyboard *, int32_t, int32_t);
-
-// wl_seat listener
-static void seat_handle_capabilities(void *, struct wl_seat *, enum wl_seat_capability);
-static void seat_handle_name(void *data, struct wl_seat *seat, const char *name);
-
-// wl_registry listener
-static void handle_global(void *, struct wl_registry *, unsigned int, const char *, unsigned int);
-static void handle_global_remove(void *, struct wl_registry *, unsigned int);
-
-// tizen_keyrouter listener
-static void keygrab_notify(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, uint32_t key, uint32_t mode, uint32_t error);
-static void keygrab_notify_list(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, struct wl_array *notify_result);
-static void getgrab_notify_list(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, struct wl_array *notify_result);
-static void set_register_none_key(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, uint32_t mode);
-static void keyregister_notify(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t status);
-static void set_input_config(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t status);
-static void key_cancel(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t key);
-
-static const struct wl_registry_listener registry_listener = {
- handle_global,
- handle_global_remove,
-};
-
-static const struct wl_seat_listener seat_listener = {
- seat_handle_capabilities,
- seat_handle_name,
-};
-
-static const struct wl_keyboard_listener keyboard_listener = {
- keyboard_keymap,
- keyboard_enter,
- keyboard_leave,
- keyboard_key,
- keyboard_modifiers,
- keyboard_repeat_setup,
-};
-
-static const struct tizen_keyrouter_listener keyrouter_listener = {
- keygrab_notify,
- keygrab_notify_list,
- getgrab_notify_list,
- set_register_none_key,
- keyregister_notify,
- set_input_config,
- key_cancel,
-};
-
-static void
-keyboard_keymap(void *data, struct wl_keyboard *keyboard, unsigned int format, int fd, unsigned int size)
-{
- headless_info_t *headless = (headless_info_t *)data;
-
- if (format == WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP)
- {
- headless->has_keymap = 0;
- }
- else
- {
- headless->has_keymap = 1;
- TRACE("wl_keyboard has keymap...Now the given fd is going to be closed.\n");
-
- close(fd);
- }
-
- TRACE("has_keymap = %s\n", headless->has_keymap ? "true" : "false");
-}
-
-static void
-keyboard_enter(void *data, struct wl_keyboard *keyboard, unsigned int serial, struct wl_surface *surface, struct wl_array *keys)
-{
- headless_info_t *headless = (headless_info_t *)data;
-
- headless->enter = 1;
- TRACE("keyboard enter\n");
-}
-
-static void
-keyboard_leave(void *data, struct wl_keyboard *keyboard, unsigned int serial, struct wl_surface *surface)
-{
- headless_info_t *headless = (headless_info_t *)data;
-
- headless->enter = 0;
- TRACE("keyboard leave\n");
-}
-
-static void
-keyboard_key(void *data, struct wl_keyboard *keyboard, unsigned int serial, unsigned int timestamp, unsigned int keycode, unsigned int state)
-{
- headless_info_t *headless = (headless_info_t *)data;
-
- if (!headless->has_keymap)
- {
- //TODO : do anything with the given keycode
- // ex> call application callback(s)
- TRACE("keycode : %d, state : %d, timestamp : %d\n", keycode, state, timestamp);
-
- if (state)
- do_action(headless, keycode);
- }
- else
- {
- TRACE("keycode(%d) won't be dealt with as there is no keymap.\n", keycode);
- }
-}
-
-static void
-keyboard_modifiers(void *data, struct wl_keyboard *keyboard, unsigned int serial, unsigned int depressed, unsigned int latched, unsigned int locked, unsigned int group)
-{
- TRACE("...\n");
-}
-
-static void
-keyboard_repeat_setup(void *data, struct wl_keyboard *keyboard, int32_t rate, int32_t delay)
-{
- TRACE("...\n");
-}
-
-static void
-seat_handle_capabilities(void *data, struct wl_seat *seat, enum wl_seat_capability caps)
-{
- headless_info_t *headless = (headless_info_t *)data;
-
- if ((caps & WL_SEAT_CAPABILITY_KEYBOARD))
- {
- if (headless->keyboard)
- {
- wl_keyboard_release(headless->keyboard);
- headless->keyboard = NULL;
- }
-
- headless->keyboard = wl_seat_get_keyboard(seat);
- ERROR_CHECK(headless->keyboard, return, "Failed to get wl_keyboard from a seat !\n");
-
- wl_keyboard_set_user_data(headless->keyboard, headless);
- wl_keyboard_add_listener(headless->keyboard, &keyboard_listener, headless);
- headless->caps_updated = 1;
-
- TRACE("seat caps update : keyboard added\n");
- }
- else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && (headless->keyboard))
- {
- wl_keyboard_release(headless->keyboard);
- headless->keyboard = NULL;
- headless->caps_updated = 1;
- }
-}
-
-static void
-seat_handle_name(void *data, struct wl_seat *seat, const char *name)
-{
- //TODO : handle seat name properly
-}
-
-static void
-keygrab_notify(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, uint32_t key, uint32_t mode, uint32_t error)
-{
- TRACE("key : %d, mode : %d, error : %d\n", key, mode, error);
-}
-
-static void
-keygrab_notify_list(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, struct wl_array *notify_result)
-{
- tizen_keyrouter_notify_t *tz_keyrouter_notify;
- headless_info_t *headless = (headless_info_t *)data;
-
- wl_array_init(&headless->array);
- wl_array_copy(&headless->array, notify_result);
-
- wl_array_for_each(tz_keyrouter_notify, &headless->array)
- {
- TRACE("... keygrab result ! (keycode : %d, mode : %d, error : %d)\n",
- tz_keyrouter_notify->keycode, tz_keyrouter_notify->mode, tz_keyrouter_notify->error);
- }
-
- wl_array_release(&headless->array);
- headless->notified = 1;
-}
-
-static void getgrab_notify_list(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, struct wl_array *notify_result)
-{
- TRACE("...\n");
-}
-
-static void set_register_none_key(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, uint32_t mode)
-{
- TRACE("...\n");
-}
-
-static void keyregister_notify(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t status)
-{
- TRACE("...\n");
-}
-
-static void set_input_config(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t status)
-{
- TRACE("...\n");
-}
-
-static void key_cancel(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t key)
-{
- TRACE("...\n");
-}
-
-static void
-handle_global(void *data, struct wl_registry *registry, unsigned int id, const char *interface, unsigned int version)
-{
- headless_info_t *headless = (headless_info_t *)data;
-
- if (!strcmp("wl_seat", interface))
- {
- headless->seat = wl_registry_bind(registry, id, &wl_seat_interface, 4);
- wl_seat_add_listener(headless->seat, &seat_listener, headless);
- wl_seat_set_user_data(headless->seat, headless);
- }
- else if (!strcmp("tizen_keyrouter", interface))
- {
- headless->tz_keyrouter = wl_registry_bind(registry, id, &tizen_keyrouter_interface, 1);
- tizen_keyrouter_add_listener(headless->tz_keyrouter, &keyrouter_listener, headless);
- tizen_keyrouter_set_user_data(headless->tz_keyrouter, headless);
- }
- else
- {
- TRACE("Unbound global object (id:%d, interface:%s, version:%d)\n", id, interface, version);
- }
-}
-
-static void
-handle_global_remove(void *data, struct wl_registry *registry, unsigned int id)
-{
- //TODO : remove/cleanup global and related information
-}
-
-static int
-_grab_wait(headless_info_t *headless)
-{
- int ret;
-
- while (!headless->notified)
- {
- ret = wl_display_roundtrip(headless->display);
- if ((0 > ret) && (errno != EAGAIN && (errno != EINVAL)))
- {
- TRACE("Wayland socket error ! (errno=%d)\n", errno);
- return 0;
- }
- }
-
- return 1;
-}
-
-static int
-grab_keys(headless_info_t *headless)
-{
- int ret;
- unsigned int *uint_ptr = NULL;
-
- struct wl_array keygrab_array;
-
- wl_array_init(&keygrab_array);
-
- //grab informa key(100), mode(OR_EXCLUSIVE) and error
- uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
- *uint_ptr = 169;//menu key in mobile
- uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
- *uint_ptr = TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE;
- uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
- *uint_ptr = 0;
-
- //grab informa key(200), mode(OR_EXCLUSIVE) and error
- uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
- *uint_ptr = 139;//home key in mobile
- uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
- *uint_ptr = TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE;
- uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
- *uint_ptr = 0;
-
- //grab informa key(300), mode(OR_EXCLUSIVE) and error
- uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
- *uint_ptr = 158;//back key in mobile
- uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
- *uint_ptr = TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE;
- uint_ptr = wl_array_add(&keygrab_array, sizeof(unsigned int));
- *uint_ptr = 0;
-
- TRACE("Waiting for requesting grab for keys...\n");
- headless->notified = 0;
- tizen_keyrouter_set_keygrab_list(headless->tz_keyrouter, NULL, &keygrab_array);
- ret = _grab_wait(headless);
- TRACE("...done...\n");
-
- wl_array_release(&keygrab_array);
-
- return ret;
-}
-
-int main()
-{
- int ret;
- const char *socket_name = NULL;
- headless_info_t *headless = NULL;
- struct wl_registry *registry = NULL;
-
- headless = (headless_info_t *)calloc(1, sizeof(headless_info_t));
- ERROR_CHECK(headless, return 0, "Failed to allocate memory for headless info...\n");
-
- socket_name = getenv("WAYLAND_DISPLAY");
-
- if (!socket_name)
- socket_name = "headless-0";
-
- if (!getenv("XDG_RUNTIME_DIR"))
- setenv("XDG_RUNTIME_DIR", "/run", 1);
-
- headless->display = wl_display_connect(socket_name);
- ERROR_CHECK(headless->display, return 0, "Failed to connect wayland display ! (socket_name : %s)\n", socket_name);
-
- registry = wl_display_get_registry(headless->display);
- ERROR_CHECK(registry, return 0, "Failed to get registry...\n");
- wl_registry_add_listener(registry, ®istry_listener, headless);
-
- TRACE("Waiting for tizen_keyrouter interface ...\n");
- while(!headless->tz_keyrouter)
- wl_display_roundtrip(headless->display);
- TRACE("...done...\n");
-
- TRACE("Waiting wl_seat interface ...\n");
- while (!headless->seat)
- wl_display_roundtrip(headless->display);
- TRACE("...done...\n");
-
- TRACE("Waiting for capabilities to be updated...\n");
- while(!headless->caps_updated)
- wl_display_roundtrip(headless->display);
- TRACE("...done...\n");
-
- TRACE("Waiting wl_keyboard interface ...\n");
- while(!headless->keyboard)
- wl_display_roundtrip(headless->display);
- TRACE("...done...\n");
-
- ret = grab_keys(headless);
- ERROR_CHECK(ret, headless->need_exit = 1, "Failed to grab keys...\n");
-
- while ((-1 != wl_display_dispatch(headless->display)) && !headless->need_exit)
- {
- ;
- }
-
- wl_keyboard_release(headless->keyboard);
- wl_seat_destroy(headless->seat);
- tizen_keyrouter_destroy(headless->tz_keyrouter);
-
- wl_display_disconnect(headless->display);
-
- free(headless);
- return 0;
-}
-
+++ /dev/null
-#include <pepper.h>
-#include <pepper-input-backend.h>
-#include <pepper-evdev.h>
-#include <pepper-keyrouter.h>
-#include <stdlib.h>
-
-/* basic pepper objects */
-pepper_seat_t *seat = NULL;
-pepper_evdev_t *evdev = NULL;
-pepper_keyrouter_t *keyrouter = NULL;
-pepper_compositor_t *compositor = NULL;
-pepper_input_device_t *input_device = NULL;
-
-/* event listeners */
-pepper_event_listener_t *listener_seat_add = NULL;
-pepper_event_listener_t *listener_input_add = NULL;
-pepper_event_listener_t *listener_input_remove = NULL;
-pepper_event_listener_t *listener_keyboard_add = NULL;
-pepper_event_listener_t *listener_keyboard_event = NULL;
-pepper_event_listener_t *listener_pointer_add = NULL;
-pepper_event_listener_t *listener_pointer_event = NULL;
-pepper_event_listener_t *listener_touch_add = NULL;
-pepper_event_listener_t *listener_touch_event = NULL;
-
-/* pointer event handler */
-static void
-_handle_pointer_event(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
-{
- pepper_input_event_t *event;
-
- PEPPER_CHECK((id >= PEPPER_EVENT_POINTER_MOTION && id <= PEPPER_EVENT_POINTER_AXIS), return, "unknown event %d !\n", id);
- PEPPER_CHECK(info, return, "Invalid event !\n");
- PEPPER_CHECK(data, return, "Invalid data !\n");
-
- event = (pepper_input_event_t *)info;
-
- /* TODO: */
- (void) event;
-
- switch (id)
- {
- case PEPPER_EVENT_POINTER_MOTION:
- /* TODO: */
- PEPPER_TRACE("[%s] PEPPER_EVENT_POINTER_MOTION\n", __FUNCTION__);
- break;
- case PEPPER_EVENT_POINTER_MOTION_ABSOLUTE:
- /* TODO: */
- PEPPER_TRACE("[%s] PEPPER_EVENT_POINTER_MOTION_ABSOLUTE\n", __FUNCTION__);
- break;
- case PEPPER_EVENT_POINTER_BUTTON:
- /* TODO: */
- PEPPER_TRACE("[%s] PEPPER_EVENT_POINTER_BUTTON\n", __FUNCTION__);
- break;
- case PEPPER_EVENT_POINTER_AXIS:
- /* TODO: */
- PEPPER_TRACE("[%s] PEPPER_EVENT_POINTER_AXIS\n", __FUNCTION__);
- break;
- default:
- break;
- }
-}
-
-/* touch event handler */
-static void
-_handle_touch_event(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
-{
- pepper_input_event_t *event;
-
- PEPPER_CHECK((id >= PEPPER_EVENT_TOUCH_DOWN && id <= PEPPER_EVENT_TOUCH_CANCEL), return, "unknown event %d !\n", id);
- PEPPER_CHECK(info, return, "Invalid event !\n");
- PEPPER_CHECK(data, return, "Invalid data !\n");
-
- event = (pepper_input_event_t *)info;
-
- /* TODO: */
- (void) event;
-
- switch (id)
- {
- case PEPPER_EVENT_TOUCH_DOWN:
- /* TODO: */
- PEPPER_TRACE("[%s] PEPPER_EVENT_TOUCH_DOWN\n", __FUNCTION__);
- break;
- case PEPPER_EVENT_TOUCH_UP:
- /* TODO: */
- PEPPER_TRACE("[%s] PEPPER_EVENT_TOUCH_UP\n", __FUNCTION__);
- break;
- case PEPPER_EVENT_TOUCH_MOTION:
- /* TODO: */
- PEPPER_TRACE("[%s] PEPPER_EVENT_TOUCH_MOTION\n", __FUNCTION__);
- break;
- case PEPPER_EVENT_TOUCH_FRAME:
- /* TODO: */
- PEPPER_TRACE("[%s] PEPPER_EVENT_TOUCH_FRAME\n", __FUNCTION__);
- break;
- case PEPPER_EVENT_TOUCH_CANCEL:
- /* TODO: */
- PEPPER_TRACE("[%s] PEPPER_EVENT_TOUCH_CANCEL\n", __FUNCTION__);
- break;
- default:
- break;
- }
-}
-
-/* seat keyboard add event handler */
-static void
-_handle_seat_keyboard_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
-{
- pepper_keyboard_t *keyboard = (pepper_keyboard_t *)info;
-
- PEPPER_TRACE("[%s] keyboard added\n", __FUNCTION__);
-
- pepper_keyboard_set_keymap_info(keyboard, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP, -1, 0);
-
- listener_keyboard_event = pepper_object_add_event_listener((pepper_object_t *)keyboard,
- PEPPER_EVENT_KEYBOARD_KEY,
- 0,
- pepper_keyrouter_event_handler,
- (void *)keyrouter);
-}
-
-/* seat pointer add event handler */
-static void
-_handle_seat_pointer_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
-{
- pepper_pointer_t *pointer = (pepper_pointer_t *)info;
-
- PEPPER_TRACE("[%s] pointer added\n", __FUNCTION__);
-
- listener_pointer_event = pepper_object_add_event_listener((pepper_object_t *)pointer,
- PEPPER_EVENT_POINTER_MOTION
- | PEPPER_EVENT_POINTER_MOTION_ABSOLUTE
- | PEPPER_EVENT_POINTER_BUTTON
- | PEPPER_EVENT_POINTER_AXIS,
- 0,
- _handle_pointer_event,
- /*compositor*/ data);
-}
-
-/* seat touch add event handler */
-static void
-_handle_seat_touch_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
-{
- pepper_touch_t *touch = (pepper_touch_t *)info;
-
- PEPPER_TRACE("[%s] touch added\n", __FUNCTION__);
-
- listener_touch_event = pepper_object_add_event_listener((pepper_object_t *)touch,
- PEPPER_EVENT_TOUCH_DOWN
- | PEPPER_EVENT_TOUCH_UP
- | PEPPER_EVENT_TOUCH_MOTION
- | PEPPER_EVENT_TOUCH_FRAME
- | PEPPER_EVENT_TOUCH_CANCEL,
- 0,
- _handle_touch_event,
- /*compositor*/ data);
-}
-
-/* seat add event handler */
-static void
-_handle_seat_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
-{
- pepper_seat_t *seat = (pepper_seat_t *)info;
-
- PEPPER_TRACE("[%s] seat added. name:%s\n", __FUNCTION__, pepper_seat_get_name(seat));
-
- listener_keyboard_add = pepper_object_add_event_listener((pepper_object_t *)seat,
- PEPPER_EVENT_SEAT_KEYBOARD_ADD,
- 0,
- _handle_seat_keyboard_add, /*compositor*/ data);
-
- listener_pointer_add = pepper_object_add_event_listener((pepper_object_t *)seat,
- PEPPER_EVENT_SEAT_POINTER_ADD,
- 0,
- _handle_seat_pointer_add, /*compositor*/ data);
-
- listener_touch_add = pepper_object_add_event_listener((pepper_object_t *)seat,
- PEPPER_EVENT_SEAT_TOUCH_ADD,
- 0,
- _handle_seat_touch_add, /*compositor*/ data);
-
-}
-
-/* compositor input device add event handler */
-static void
-_handle_input_device_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
-{
- pepper_input_device_t *device = (pepper_input_device_t *)info;
-
- PEPPER_TRACE("[%s] input device added.\n", __FUNCTION__);
-
- if (seat)
- pepper_seat_add_input_device(seat, device);
-}
-
-/* compositor input deviec remove event handler */
-static void
-_handle_input_device_remove(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
-{
- pepper_input_device_t *device = (pepper_input_device_t *)info;
-
- PEPPER_TRACE("[%s] input device removed.\n", __FUNCTION__);
-
- if (seat)
- pepper_seat_remove_input_device(seat, device);
-}
-
-int main(int argc, char *argv[])
-{
- uint32_t caps = 0;
- uint32_t probed = 0;
- int ret = EXIT_SUCCESS;
-
- const char* socket_name = NULL;
- const char* seat_name = NULL;
-
- socket_name = getenv("WAYLAND_DISPLAY");
-
- if (!socket_name)
- socket_name = "headless-0";
-
- if (!getenv("XDG_RUNTIME_DIR"))
- setenv("XDG_RUNTIME_DIR", "/run", 1);
-
- /* create pepper compositor */
- compositor = pepper_compositor_create(socket_name);
- PEPPER_CHECK(compositor, return EXIT_FAILURE, "Failed to create compositor !\n");
-
- /* register event listeners */
- listener_seat_add = pepper_object_add_event_listener((pepper_object_t *)compositor,
- PEPPER_EVENT_COMPOSITOR_SEAT_ADD,
- 0, _handle_seat_add, compositor);
- PEPPER_CHECK(listener_seat_add, goto shutdown_on_failure, "Failed to add seat add listener.\n");
-
- listener_input_add = pepper_object_add_event_listener((pepper_object_t *)compositor,
- PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_ADD,
- 0, _handle_input_device_add, compositor);
- PEPPER_CHECK(listener_input_add, goto shutdown_on_failure, "Failed to add input device add listener.\n");
-
- listener_input_remove = pepper_object_add_event_listener((pepper_object_t *)compositor,
- PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_REMOVE,
- 0, _handle_input_device_remove, compositor);
- PEPPER_CHECK(listener_input_remove, goto shutdown_on_failure, "Failed to add input device remove listener.\n");
-
- /* create pepper keyrouter */
- keyrouter = pepper_keyrouter_create(compositor);
- PEPPER_CHECK(keyrouter, goto shutdown_on_failure, "Failed to create keyrouter !\n");
-
- /* seat add : if there is no seat name, set seat0 as a default seat name */
- seat_name = getenv("WAYLAND_SEAT");
-
- if (!seat_name)
- seat_name = "seat0";
-
- seat = pepper_compositor_add_seat(compositor, seat_name);
- PEPPER_CHECK(seat, goto shutdown_on_failure, "Failed to add seat !\n");
-
- /* get capabilities for a default pepper input device*/
- if (getenv("WAYLAND_INPUT_KEYBOARD"))
- caps |= WL_SEAT_CAPABILITY_KEYBOARD;
- if (getenv("WAYLAND_INPUT_POINTER"))
- caps |= WL_SEAT_CAPABILITY_POINTER;
- if (getenv("WAYLAND_INPUT_TOUCH"))
- caps |= WL_SEAT_CAPABILITY_TOUCH;
-
- /* if there is no capability, set keyboard capability by default */
- if (!caps)
- caps = WL_SEAT_CAPABILITY_KEYBOARD;
-
- /* create a default pepper input device */
- input_device = pepper_input_device_create(compositor, caps, NULL, NULL);
- PEPPER_CHECK(input_device, goto shutdown_on_failure, "Failed to create input device !\n");
-
- /* create pepper evdev */
- evdev = pepper_evdev_create(compositor);
- PEPPER_CHECK(evdev, goto shutdown_on_failure, "Failed to create evdev !\n");
-
- /* probe evdev input device(s) */
- probed = pepper_evdev_device_probe(evdev, caps);
-
- if (!probed)
- PEPPER_TRACE("No evdev devices have been probed.\n");
- else
- PEPPER_TRACE("%d evdev device(s) has been probed.\n", probed);
-
- /* create server module(s) loader : TODO */
-
- /* run event loop */
- wl_display_run(pepper_compositor_get_display(compositor));
-
- goto shutdown;
-
-shutdown_on_failure:
- ret = EXIT_FAILURE;
-shutdown:
-
- /* destroy all remain event listeners */
- if (listener_seat_add)
- {
- pepper_event_listener_remove(listener_seat_add);
- listener_seat_add = NULL;
- }
-
- if (listener_input_add)
- {
- pepper_event_listener_remove(listener_input_add);
- listener_input_add = NULL;
- }
-
- if (listener_input_remove)
- {
- pepper_event_listener_remove(listener_input_remove);
- listener_input_remove = NULL;
- }
-
- /* destroy input device */
- if (input_device)
- {
- pepper_input_device_destroy(input_device);
- input_device = NULL;
- }
-
- /* destroy seat */
- if (seat)
- {
- pepper_seat_destroy(seat);
- seat = NULL;
- }
-
- /* TODO : clean up any other objects if needed */
-
- /* destroy keyrouter */
- if (keyrouter)
- {
- pepper_keyrouter_destroy(keyrouter);
- keyrouter = NULL;
-
- }
-
- /* destroy evdev */
- if (evdev)
- {
- pepper_evdev_destroy(evdev);
- evdev = NULL;
- }
-
- /* destroy compositor */
- if (compositor)
- {
- pepper_compositor_destroy(compositor);
- compositor = NULL;
- }
-
- return ret;
-}