summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorentin Chary <corentin.chary@gmail.com>2011-06-09 10:21:35 +0200
committerKristian Høgsberg <krh@bitplanet.net>2012-03-27 09:31:56 -0400
commite4b0c11f43e51832108739e95058adf427dc0b98 (patch)
tree116909c4307d6da96dadcdc11afd4bdfdc30894d
parent0929854cbf530d2f5f3a5608c6ce808ed24ad26e (diff)
xwayland: use xf86 drivers for input devices
Signed-off-by: Corentin Chary <corentin.chary@gmail.com>
-rw-r--r--hw/xfree86/xwayland/Makefile.am1
-rw-r--r--hw/xfree86/xwayland/xwayland-client.c12
-rw-r--r--hw/xfree86/xwayland/xwayland-input.c380
-rw-r--r--hw/xfree86/xwayland/xwayland-private.h5
-rw-r--r--hw/xfree86/xwayland/xwayland.c243
5 files changed, 426 insertions, 215 deletions
diff --git a/hw/xfree86/xwayland/Makefile.am b/hw/xfree86/xwayland/Makefile.am
index cb26ff47c..8626d65bf 100644
--- a/hw/xfree86/xwayland/Makefile.am
+++ b/hw/xfree86/xwayland/Makefile.am
@@ -19,6 +19,7 @@ libxwayland_ladir = $(moduledir)/extensions
libxwayland_la_SOURCES = \
xwayland.c \
xwayland-client.c \
+ xwayland-input.c \
xwayland-private.h \
drm-client-protocol.h \
drm-protocol.c
diff --git a/hw/xfree86/xwayland/xwayland-client.c b/hw/xfree86/xwayland/xwayland-client.c
index 5ec1d84e1..7c6a9b4d4 100644
--- a/hw/xfree86/xwayland/xwayland-client.c
+++ b/hw/xfree86/xwayland/xwayland-client.c
@@ -113,7 +113,8 @@ input_device_handle_motion(void *data, struct wl_input_device *input_device,
int32_t x, int32_t y, int32_t sx, int32_t sy)
{
struct xwl_input_device *xwl_input_device = data;
- int32_t dx, dy;
+ struct xwl_screen *xwl_screen = xwl_input_device->xwl_screen;
+ int32_t dx, dy, lx, ly;
xwl_input_device->time = time;
@@ -123,8 +124,11 @@ input_device_handle_motion(void *data, struct wl_input_device *input_device,
dx = xwl_input_device->focus_window->window->drawable.x;
dy = xwl_input_device->focus_window->window->drawable.y;
+ lx = xf86ScaleAxis(sx + dx, 0xFFFF, 0, xwl_screen->scrninfo->virtualX, 0);
+ ly = xf86ScaleAxis(sy + dy, 0xFFFF, 0, xwl_screen->scrninfo->virtualY, 0);
+
xf86PostMotionEvent(xwl_input_device->pointer,
- TRUE, 0, 2, sx + dx, sy + dy);
+ TRUE, 0, 2, lx, ly);
}
static void
@@ -245,6 +249,7 @@ create_input_device(struct xwl_screen *xwl_screen, uint32_t id,
xwl_input_device = xwl_input_device_create(xwl_screen);
xwl_input_device->input_device =
wl_input_device_create (xwl_screen->display, id, 1);
+ xwl_input_device->id = id;
wl_input_device_add_listener(xwl_input_device->input_device,
&input_device_listener,
@@ -272,8 +277,7 @@ global_handler(struct wl_display *display,
&drm_listener, xwl_screen);
#endif
} else if (strcmp (interface, "wl_shm") == 0) {
- xwl_screen->shm = wl_shm_create (xwl_screen->display, id,
- 1);
+ xwl_screen->shm = wl_shm_create (xwl_screen->display, id, 1);
} else if (strcmp (interface, "wl_output") == 0) {
create_output(xwl_screen, id, 1);
} else if (strcmp (interface, "wl_input_device") == 0) {
diff --git a/hw/xfree86/xwayland/xwayland-input.c b/hw/xfree86/xwayland/xwayland-input.c
new file mode 100644
index 000000000..b26e08c4d
--- /dev/null
+++ b/hw/xfree86/xwayland/xwayland-input.c
@@ -0,0 +1,380 @@
+/*
+ * Copyright © 2008 Kristian Høgsberg
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of the
+ * copyright holders not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include "xorg-config.h"
+#endif
+
+#include <stdint.h>
+#include <unistd.h>
+#include <wayland-util.h>
+#include <wayland-client.h>
+#include <X11/extensions/compositeproto.h>
+#include <xserver-properties.h>
+
+#include <compositeext.h>
+#include <selection.h>
+#include <extinit.h>
+#include <input.h>
+#include <inputstr.h>
+#include <exevents.h>
+#include <xkbsrv.h>
+#include <xf86Xinput.h>
+#include <xf86Crtc.h>
+#include <xf86str.h>
+#include <windowstr.h>
+#include <xf86Priv.h>
+#include <mipointrst.h>
+
+#include "xwayland.h"
+#include "xwayland-private.h"
+
+/*
+ * TODO:
+ * - lose X kb focus when wayland surface loses it
+ * - active grabs, grab owner crack
+ */
+
+static void
+xwl_pointer_control(DeviceIntPtr device, PtrCtrl *ctrl)
+{
+ /* Nothing to do, dix handles all settings */
+}
+
+static int
+xwl_pointer_proc(DeviceIntPtr device, int what)
+{
+#define NBUTTONS 10
+#define NAXES 2
+ BYTE map[NBUTTONS + 1];
+ int i = 0;
+ Atom btn_labels[NBUTTONS] = {0};
+ Atom axes_labels[NAXES] = {0};
+
+ fprintf(stderr, "input proc %p %d\n", device, what);
+
+ switch (what) {
+ case DEVICE_INIT:
+ device->public.on = FALSE;
+
+ for (i = 1; i <= NBUTTONS; i++)
+ map[i] = i;
+
+ btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
+ btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
+ btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
+ btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
+ btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
+ btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
+ btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
+ /* don't know about the rest */
+
+ axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
+ axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
+
+ if (!InitValuatorClassDeviceStruct(device, 2, btn_labels,
+ GetMotionHistorySize(), Absolute))
+ return BadValue;
+
+ /* Valuators */
+ InitValuatorAxisStruct(device, 0, axes_labels[0],
+ 0, 0xFFFF, 10000, 0, 10000, Absolute);
+ InitValuatorAxisStruct(device, 1, axes_labels[1],
+ 0, 0xFFFF, 10000, 0, 10000, Absolute);
+
+ if (!InitPtrFeedbackClassDeviceStruct(device, xwl_pointer_control))
+ return BadValue;
+
+ if (!InitButtonClassDeviceStruct(device, 3, btn_labels, map))
+ return BadValue;
+
+ case DEVICE_ON:
+ device->public.on = TRUE;
+ return Success;
+
+ case DEVICE_OFF:
+ case DEVICE_CLOSE:
+ device->public.on = FALSE;
+ return Success;
+ }
+
+ return BadMatch;
+
+#undef NBUTTONS
+#undef NAXES
+}
+
+static void
+xwl_keyboard_control(DeviceIntPtr device, KeybdCtrl *ctrl)
+{
+ /* FIXME: Set keyboard leds based on CAPSFLAG etc being set in
+ * ctrl->leds */
+}
+
+static int
+xwl_keyboard_proc(DeviceIntPtr device, int what)
+{
+ XkbRMLVOSet rmlvo;
+ fprintf(stderr, "keyboard proc %p %d\n", device, what);
+ switch (what) {
+ case DEVICE_INIT:
+ device->public.on = FALSE;
+
+ rmlvo.rules = "evdev";
+ rmlvo.model = "evdev";
+ rmlvo.layout = "us";
+ rmlvo.variant = NULL;
+ rmlvo.options = NULL;
+
+ if (!InitKeyboardDeviceStruct(device, &rmlvo, NULL, xwl_keyboard_control))
+ return BadValue;
+
+ return Success;
+ case DEVICE_ON:
+ device->public.on = TRUE;
+ return Success;
+
+ case DEVICE_OFF:
+ case DEVICE_CLOSE:
+ device->public.on = FALSE;
+ return Success;
+ }
+
+ return BadMatch;
+}
+
+static void
+xwl_keyboard_uninit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
+{
+ xwl_keyboard_proc(pInfo->dev, DEVICE_OFF);
+}
+
+static int
+xwl_keyboard_init(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
+{
+ pInfo->type_name = "xwayland-keyboard";
+ pInfo->device_control = xwl_keyboard_proc;
+ pInfo->read_input = NULL;
+ pInfo->control_proc = NULL;
+ pInfo->switch_mode = NULL;
+ pInfo->fd = -1;
+
+ return Success;
+}
+
+_X_EXPORT InputDriverRec xwl_keyboard_driver = {
+ 1,
+ "xwayland-keyboard",
+ NULL,
+ xwl_keyboard_init,
+ xwl_keyboard_uninit,
+ NULL,
+};
+
+static void
+xwl_pointer_uninit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
+{
+ xwl_pointer_proc(pInfo->dev, DEVICE_OFF);
+}
+
+static int
+xwl_pointer_init(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
+{
+ pInfo->type_name = "xwayland-pointer";
+ pInfo->device_control = xwl_pointer_proc;
+ pInfo->read_input = NULL;
+ pInfo->control_proc = NULL;
+ pInfo->switch_mode = NULL;
+ pInfo->fd = -1;
+
+ return Success;
+}
+
+_X_EXPORT InputDriverRec xwl_pointer_driver = {
+ 1,
+ "xwayland-pointer",
+ NULL,
+ xwl_pointer_init,
+ xwl_pointer_uninit,
+ NULL,
+};
+
+void
+xwl_input_teardown(pointer p)
+{
+}
+
+pointer
+xwl_input_setup(pointer module, pointer opts, int *errmaj, int *errmin)
+{
+ xf86AddInputDriver(&xwl_keyboard_driver, module, 0);
+ xf86AddInputDriver(&xwl_pointer_driver, module, 0);
+
+ return module;
+}
+
+static void
+add_option(InputOption **options, const char *key, const char *value)
+{
+ if (!value || *value == '\0')
+ return;
+
+ for (; *options; options = &(*options)->next)
+ ;
+ *options = calloc(sizeof(**options), 1);
+ if (!*options) /* Yeesh. */
+ return;
+ (*options)->key = strdup(key);
+ (*options)->value = strdup(value);
+ (*options)->next = NULL;
+}
+
+static DeviceIntPtr
+device_added(struct xwl_input_device *xwl_input_device, const char *driver)
+{
+ InputOption *options = NULL, *tmpo = NULL;
+ InputAttributes attrs = {0};
+ DeviceIntPtr dev = NULL;
+ char *config_info = NULL;
+ char *xwl_input_ptr = NULL;
+ char *name = NULL;
+ int rc;
+
+ if (asprintf(&config_info, "%s:%d", driver, xwl_input_device->id) == -1) {
+ config_info = NULL;
+ goto unwind;
+ }
+
+ if (asprintf(&xwl_input_ptr, "%p", xwl_input_device) == -1) {
+ xwl_input_ptr = NULL;
+ goto unwind;
+ }
+
+ name = config_info;
+
+ options = calloc(sizeof(*options), 1);
+ if (!options)
+ return NULL;
+
+ options->key = strdup("_source");
+ options->value = strdup("server/xwayland");
+ if (!options->key || !options->value)
+ goto unwind;
+
+ add_option(&options, "name", name);
+ add_option(&options, "config_info", config_info);
+ add_option(&options, "driver", driver);
+
+ /* Wow ! super ugly ! */
+ add_option(&options, "xwl_input_ptr", xwl_input_ptr);
+
+ if (strstr(driver, "keyboard"))
+ attrs.flags |= ATTR_KEYBOARD;
+ if (strstr(driver, "pointer"))
+ attrs.flags |= ATTR_POINTER;
+
+ LogMessage(X_INFO, "config/xwayland: Adding input device %s\n", name);
+ if ((rc = NewInputDeviceRequest(options, &attrs, &dev)) != Success) {
+ LogMessage(X_ERROR, "config/xwayland: NewInputDeviceRequest failed (%d)\n", rc);
+ }
+
+ if (dev) {
+ InputInfoPtr pInfo = dev->public.devicePrivate;
+ pInfo->private = xwl_input_device;
+ }
+
+ return dev;
+
+unwind:
+ free(config_info);
+ free(xwl_input_ptr);
+ while ((tmpo = options)) {
+ options = tmpo->next;
+ free(tmpo->key); /* NULL if dev != NULL */
+ free(tmpo->value); /* NULL if dev != NULL */
+ free(tmpo);
+ }
+
+ return NULL;
+}
+
+static void
+device_removed(DeviceIntPtr dev)
+{
+ LogMessage(X_INFO, "config/xwayland: removing device %s\n", dev->name);
+
+ OsBlockSignals();
+ ProcessInputEvents();
+ DeleteInputDeviceRequest(dev);
+ OsReleaseSignals();
+}
+
+static void
+add_input_device(struct xwl_input_device *xwl_input_device)
+{
+ if (!xwl_input_device->pointer)
+ xwl_input_device->pointer =
+ device_added(xwl_input_device, "xwayland-pointer");
+ if (!xwl_input_device->keyboard)
+ xwl_input_device->keyboard =
+ device_added(xwl_input_device, "xwayland-keyboard");
+}
+
+static void
+add_input_devices(struct xwl_screen *xwl_screen)
+{
+ struct xwl_input_device *xwl_input_device;
+
+ list_for_each_entry(xwl_input_device,
+ &xwl_screen->input_device_list, link)
+ add_input_device(xwl_input_device);
+}
+
+void
+xwl_input_init(struct xwl_screen *xwl_screen)
+{
+ xwl_screen->input_initialized = 1;
+ add_input_devices(xwl_screen);
+}
+
+struct xwl_input_device *
+xwl_input_device_create(struct xwl_screen *xwl_screen)
+{
+ struct xwl_input_device *xwl_input_device;
+
+ xwl_input_device = calloc(sizeof *xwl_input_device, 1);
+ if (xwl_input_device == NULL) {
+ ErrorF("create_input ENOMEM");
+ return NULL;
+ }
+
+ xwl_input_device->xwl_screen = xwl_screen;
+ list_add(&xwl_input_device->link, &xwl_screen->input_device_list);
+
+ if (xwl_screen->input_initialized)
+ add_input_device(xwl_input_device);
+
+ return xwl_input_device;
+}
diff --git a/hw/xfree86/xwayland/xwayland-private.h b/hw/xfree86/xwayland/xwayland-private.h
index 0e5e1089b..265dc6319 100644
--- a/hw/xfree86/xwayland/xwayland-private.h
+++ b/hw/xfree86/xwayland/xwayland-private.h
@@ -95,6 +95,7 @@ struct xwl_input_device {
int grab;
struct xwl_window *focus_window;
int32_t grab_x, grab_y;
+ uint32_t id;
uint32_t modifiers;
uint32_t time;
struct list link;
@@ -105,6 +106,10 @@ xwl_output_create(struct xwl_screen *xwl_screen);
struct xwl_input_device *
xwl_input_device_create(struct xwl_screen *xwl_screen);
+void xwl_input_teardown(pointer p);
+pointer xwl_input_setup(pointer module, pointer opts, int *errmaj, int *errmin);
+void xwl_input_init(struct xwl_screen *screen);
+
int wayland_screen_init(struct xwl_screen *screen, int use_drm);
int wayland_screen_close(struct xwl_screen *screen);
diff --git a/hw/xfree86/xwayland/xwayland.c b/hw/xfree86/xwayland/xwayland.c
index b439314aa..67d09f14d 100644
--- a/hw/xfree86/xwayland/xwayland.c
+++ b/hw/xfree86/xwayland/xwayland.c
@@ -68,140 +68,6 @@
static DevPrivateKeyRec xwl_window_private_key;
static DevPrivateKeyRec xwl_screen_private_key;
static DevPrivateKeyRec xwl_cursor_private_key;
-static DevPrivateKeyRec xwl_device_private_key;
-
-static int
-input_proc(DeviceIntPtr device, int event)
-{
- switch (event) {
- case DEVICE_INIT:
- break;
- case DEVICE_ON:
- break;
- case DEVICE_OFF:
- break;
- case DEVICE_CLOSE:
- break;
- }
-
- return Success;
-}
-
-static void
-input_ptr_ctrl_proc(DeviceIntPtr device, PtrCtrl *ctrl)
-{
- /* Nothing to do, dix handles all settings */
-}
-
-static void
-input_kbd_ctrl(DeviceIntPtr device, KeybdCtrl *ctrl)
-{
- /* FIXME: Set keyboard leds based on CAPSFLAG etc being set in
- * ctrl->leds */
-}
-
-static int
-input_init_pointer(struct xwl_input_device *d, struct xwl_screen *screen)
-{
- DeviceIntPtr device;
- char *name = "xwayland";
- int i = 0;
- int min_x = 0, min_y = 0;
- int max_x = screen->width, max_y = screen->height;
-#define NBUTTONS 10
-#define NAXES 2
- BYTE map[NBUTTONS + 1];
- Atom btn_labels[NBUTTONS] = {0};
- Atom axes_labels[NAXES] = {0};
- Atom atom;
-
- xf86DrvMsg(screen->scrninfo->scrnIndex, X_INFO, "Initializing Pointer\n");
-
- device = AddInputDevice(serverClient, input_proc, TRUE);
- d->pointer = device;
- dixSetPrivate(&device->devPrivates, &xwl_device_private_key, d);
-
- atom = MakeAtom(name, strlen(name), TRUE);
- AssignTypeAndName(device, atom, name);
-
- device->coreEvents = TRUE;
- device->type = SLAVE;
- device->spriteInfo->spriteOwner = FALSE;
-
- for (i = 1; i <= NBUTTONS; i++)
- map[i] = i;
-
- btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
- btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
- btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
- btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
- btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
- btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
- btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
- /* don't know about the rest */
-
- axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
- axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
-
- if (!InitValuatorClassDeviceStruct(device, 2, btn_labels,
- GetMotionHistorySize(), Absolute))
- return BadValue;
-
- /* Valuators */
- /* FIXME: it may be a good idea to use Relative axis instead of Absolute */
- InitValuatorAxisStruct(device, 0, axes_labels[0],
- min_x, max_x / 2, 10000, 0, 10000, Absolute);
- InitValuatorAxisStruct(device, 1, axes_labels[1],
- min_y, max_y / 2, 10000, 0, 10000, Absolute);
-
- if (!InitPtrFeedbackClassDeviceStruct(device, input_ptr_ctrl_proc))
- return BadValue;
-
- if (!InitButtonClassDeviceStruct(device, 3, btn_labels, map))
- return BadValue;
-
-#undef NBUTTONS
-#undef NAXES
-
- return Success;
-}
-
-static int
-input_init_keyboard(struct xwl_input_device *d,
- struct xwl_screen *screen)
-{
- DeviceIntPtr device;
- CARD32 atom;
- char *name = "xwayland";
- XkbRMLVOSet rmlvo;
-
- xf86DrvMsg(screen->scrninfo->scrnIndex, X_INFO, "Initializing Keyboard\n");
-
- device = AddInputDevice(serverClient, input_proc, TRUE);
- d->keyboard = device;
-
- dixSetPrivate(&device->devPrivates, &xwl_device_private_key, d);
-
- atom = MakeAtom(name, strlen(name), TRUE);
- AssignTypeAndName(device, atom, name);
-
- device->coreEvents = TRUE;
- device->type = SLAVE;
- device->spriteInfo->spriteOwner = FALSE;
-
- rmlvo.rules = "evdev";
- rmlvo.model = "evdev";
- rmlvo.layout = "us";
- rmlvo.variant = NULL;
- rmlvo.options = NULL;
-
- if (!InitKeyboardDeviceStruct(device, &rmlvo, NULL, input_kbd_ctrl))
- return !Success;
-
- ActivateDevice(device, FALSE);
-
- return Success;
-}
static void
crtc_dpms(xf86CrtcPtr drmmode_crtc, int mode)
@@ -367,70 +233,6 @@ xwl_output_create(struct xwl_screen *xwl_screen)
return xwl_output;
}
-static void
-input_init_devices(struct xwl_input_device *xwl_input_device)
-{
- ActivateDevice(xwl_input_device->pointer, TRUE);
- ActivateDevice(xwl_input_device->keyboard, TRUE);
- EnableDevice(xwl_input_device->pointer, TRUE);
- EnableDevice(xwl_input_device->keyboard, TRUE);
-}
-
-static void
-add_input_device(struct xwl_input_device *xwl_input_device)
-{
- input_init_pointer(xwl_input_device, xwl_input_device->xwl_screen);
- input_init_keyboard(xwl_input_device, xwl_input_device->xwl_screen);
- input_init_devices(xwl_input_device);
-}
-
-static void
-add_input_devices(struct xwl_screen *xwl_screen)
-{
- struct xwl_input_device *xwl_input_device;
-
- if (!xwl_screen->input_initialized)
- return ;
-
- list_for_each_entry(xwl_input_device,
- &xwl_screen->input_device_list, link) {
- if (!xwl_input_device->pointer && !xwl_input_device->keyboard)
- add_input_device(xwl_input_device);
- }
-}
-
-static CARD32
-xwl_input_initialize(OsTimerPtr timer, CARD32 time, pointer data)
-{
- struct xwl_screen *xwl_screen = data;
-
- xwl_screen->input_initialized = 1;
- add_input_devices(xwl_screen);
- TimerFree(timer);
-
- return 0;
-}
-
-struct xwl_input_device *
-xwl_input_device_create(struct xwl_screen *xwl_screen)
-{
- struct xwl_input_device *xwl_input_device;
-
- xwl_input_device = calloc(sizeof *xwl_input_device, 1);
- if (xwl_input_device == NULL) {
- ErrorF("create_input ENOMEM");
- return NULL;
- }
-
- xwl_input_device->xwl_screen = xwl_screen;
- list_add(&xwl_input_device->link, &xwl_screen->input_device_list);
-
- if (xwl_screen->input_initialized)
- add_input_device(xwl_input_device);
-
- return xwl_input_device;
-}
-
static Bool
resize(ScrnInfoPtr scrn, int width, int height)
{
@@ -796,18 +598,23 @@ xwl_unrealize_cursor(DeviceIntPtr device,
static void
xwl_set_cursor(DeviceIntPtr device,
- ScreenPtr screen, CursorPtr cursor, int x, int y)
+ ScreenPtr screen, CursorPtr cursor, int x, int y)
{
+ struct xwl_screen *xwl_screen;
struct xwl_input_device *xwl_input_device;
struct wl_buffer *buffer;
if (!cursor)
return;
- xwl_input_device =
- dixGetPrivate(&device->devPrivates, &xwl_device_private_key);
- if (!xwl_input_device)
- return;
+ xwl_screen = dixLookupPrivate(&screen->devPrivates,
+ &xwl_screen_private_key);
+
+ if (!xwl_screen || list_is_empty(&xwl_screen->input_device_list))
+ return ;
+
+ xwl_input_device = list_first_entry(&xwl_screen->input_device_list,
+ struct xwl_input_device, link);
buffer = dixGetPrivate(&cursor->devPrivates, &xwl_cursor_private_key);
@@ -827,7 +634,7 @@ xwl_device_cursor_initialize(DeviceIntPtr device, ScreenPtr screen)
struct xwl_screen *xwl_screen;
xwl_screen = dixLookupPrivate(&screen->devPrivates,
- &xwl_screen_private_key);
+ &xwl_screen_private_key);
return xwl_screen->sprite_funcs->DeviceCursorInitialize(device,
screen);
@@ -839,7 +646,7 @@ xwl_device_cursor_cleanup(DeviceIntPtr device, ScreenPtr screen)
struct xwl_screen *xwl_screen;
xwl_screen = dixLookupPrivate(&screen->devPrivates,
- &xwl_screen_private_key);
+ &xwl_screen_private_key);
xwl_screen->sprite_funcs->DeviceCursorCleanup(device, screen);
}
@@ -854,6 +661,17 @@ static miPointerSpriteFuncRec xwl_pointer_sprite_funcs =
xwl_device_cursor_cleanup
};
+static CARD32
+xwl_input_delayed_init(OsTimerPtr timer, CARD32 time, pointer data)
+{
+ struct xwl_screen *xwl_screen = data;
+
+ xwl_input_init(xwl_screen);
+ TimerFree(timer);
+
+ return 0;
+}
+
int
xwl_screen_init(struct xwl_screen *xwl_screen, ScreenPtr screen)
{
@@ -873,9 +691,6 @@ xwl_screen_init(struct xwl_screen *xwl_screen, ScreenPtr screen)
if (!dixRegisterPrivateKey(&xwl_cursor_private_key, PRIVATE_CURSOR, 0))
return BadAlloc;
- if (!dixRegisterPrivateKey(&xwl_device_private_key, PRIVATE_DEVICE, 0))
- return BadAlloc;
-
dixSetPrivate(&screen->devPrivates,
&xwl_screen_private_key, xwl_screen);
@@ -898,7 +713,7 @@ xwl_screen_init(struct xwl_screen *xwl_screen, ScreenPtr screen)
xwl_screen->sprite_funcs = pointer_priv->spriteFuncs;
pointer_priv->spriteFuncs = &xwl_pointer_sprite_funcs;
- TimerSet(NULL, 0, 1, xwl_input_initialize, xwl_screen);
+ TimerSet(NULL, 0, 1, xwl_input_delayed_init, xwl_screen);
return Success;
}
@@ -1029,7 +844,13 @@ void xwl_screen_post_damage(struct xwl_screen *xwl_screen)
static pointer
xwl_setup(pointer module, pointer opts, int *errmaj, int *errmin)
{
- return (pointer) 1;
+ return xwl_input_setup(module, opts, errmaj, errmin);
+}
+
+static void
+xwl_teardown(pointer p)
+{
+ xwl_input_teardown(p);
}
static XF86ModuleVersionInfo xwl_version_info = {
@@ -1048,7 +869,7 @@ static XF86ModuleVersionInfo xwl_version_info = {
_X_EXPORT const XF86ModuleData xwaylandModuleData = {
&xwl_version_info,
&xwl_setup,
- NULL
+ &xwl_teardown
};
int