input: Allocate pointer/keyboard/touch structs
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index e827cec..21304a0 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -865,7 +865,7 @@
update_xkb_state_from_core(struct x11_compositor *c, uint16_t x11_mask)
{
uint32_t mask = get_xkb_mod_mask(c, x11_mask);
- struct weston_keyboard *keyboard = &c->core_seat.keyboard_instance;
+ struct weston_keyboard *keyboard = c->core_seat.keyboard;
xkb_state_update_mask(c->core_seat.xkb_state.state,
keyboard->modifiers.mods_depressed & mask,
diff --git a/src/compositor.h b/src/compositor.h
index b9ca79e..68b388a 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -328,17 +328,10 @@
uint32_t grab_time;
};
+struct weston_pointer *
+weston_pointer_create(void);
void
-weston_seat_set_pointer(struct weston_seat *seat, struct weston_pointer *pointer);
-void
-weston_seat_set_keyboard(struct weston_seat *seat, struct weston_keyboard *keyboard);
-void
-weston_seat_set_touch(struct weston_seat *seat, struct weston_touch *touch);
-
-void
-weston_pointer_init(struct weston_pointer *pointer);
-void
-weston_pointer_release(struct weston_pointer *pointer);
+weston_pointer_destroy(struct weston_pointer *pointer);
void
weston_pointer_set_focus(struct weston_pointer *pointer,
struct wl_surface *surface,
@@ -352,10 +345,10 @@
weston_pointer_set_current(struct weston_pointer *pointer,
struct wl_surface *surface);
+struct weston_keyboard *
+weston_keyboard_create(void);
void
-weston_keyboard_init(struct weston_keyboard *keyboard);
-void
-weston_keyboard_release(struct weston_keyboard *keyboard);
+weston_keyboard_destroy(struct weston_keyboard *keyboard);
void
weston_keyboard_set_focus(struct weston_keyboard *keyboard,
struct wl_surface *surface);
@@ -365,10 +358,10 @@
void
weston_keyboard_end_grab(struct weston_keyboard *keyboard);
+struct weston_touch *
+weston_touch_create(void);
void
-weston_touch_init(struct weston_touch *touch);
-void
-weston_touch_release(struct weston_touch *touch);
+weston_touch_destroy(struct weston_touch *touch);
void
weston_touch_start_grab(struct weston_touch *device,
struct weston_touch_grab *grab);
@@ -440,9 +433,6 @@
struct weston_keyboard *keyboard;
struct weston_touch *touch;
- struct weston_pointer pointer_instance;
- struct weston_keyboard keyboard_instance;
- struct weston_touch touch_instance;
struct wl_signal destroy_signal;
struct weston_compositor *compositor;
diff --git a/src/input.c b/src/input.c
index f0a642e..d0ccc62 100644
--- a/src/input.c
+++ b/src/input.c
@@ -290,9 +290,15 @@
default_grab_modifiers,
};
-WL_EXPORT void
-weston_pointer_init(struct weston_pointer *pointer)
+WL_EXPORT struct weston_pointer *
+weston_pointer_create(void)
{
+ struct weston_pointer *pointer;
+
+ pointer = malloc(sizeof *pointer);
+ if (pointer == NULL)
+ return NULL;
+
memset(pointer, 0, sizeof *pointer);
wl_list_init(&pointer->resource_list);
pointer->focus_listener.notify = lose_pointer_focus;
@@ -304,19 +310,28 @@
/* FIXME: Pick better co-ords. */
pointer->x = wl_fixed_from_int(100);
pointer->y = wl_fixed_from_int(100);
+
+ return pointer;
}
WL_EXPORT void
-weston_pointer_release(struct weston_pointer *pointer)
+weston_pointer_destroy(struct weston_pointer *pointer)
{
/* XXX: What about pointer->resource_list? */
if (pointer->focus_resource)
wl_list_remove(&pointer->focus_listener.link);
+ free(pointer);
}
-WL_EXPORT void
-weston_keyboard_init(struct weston_keyboard *keyboard)
+WL_EXPORT struct weston_keyboard *
+weston_keyboard_create(void)
{
+ struct weston_keyboard *keyboard;
+
+ keyboard = malloc(sizeof *keyboard);
+ if (keyboard == NULL)
+ return NULL;
+
memset(keyboard, 0, sizeof *keyboard);
wl_list_init(&keyboard->resource_list);
wl_array_init(&keyboard->keys);
@@ -325,20 +340,29 @@
keyboard->default_grab.keyboard = keyboard;
keyboard->grab = &keyboard->default_grab;
wl_signal_init(&keyboard->focus_signal);
+
+ return keyboard;
}
WL_EXPORT void
-weston_keyboard_release(struct weston_keyboard *keyboard)
+weston_keyboard_destroy(struct weston_keyboard *keyboard)
{
/* XXX: What about keyboard->resource_list? */
if (keyboard->focus_resource)
wl_list_remove(&keyboard->focus_listener.link);
wl_array_release(&keyboard->keys);
+ free(keyboard);
}
-WL_EXPORT void
-weston_touch_init(struct weston_touch *touch)
+WL_EXPORT struct weston_touch *
+weston_touch_create(void)
{
+ struct weston_touch *touch;
+
+ touch = malloc(sizeof *touch);
+ if (touch == NULL)
+ return NULL;
+
memset(touch, 0, sizeof *touch);
wl_list_init(&touch->resource_list);
touch->focus_listener.notify = lose_touch_focus;
@@ -346,14 +370,17 @@
touch->default_grab.touch = touch;
touch->grab = &touch->default_grab;
wl_signal_init(&touch->focus_signal);
+
+ return touch;
}
WL_EXPORT void
-weston_touch_release(struct weston_touch *touch)
+weston_touch_destroy(struct weston_touch *touch)
{
/* XXX: What about touch->resource_list? */
if (touch->focus_resource)
wl_list_remove(&touch->focus_listener.link);
+ free(touch);
}
static void
@@ -374,53 +401,6 @@
}
WL_EXPORT void
-weston_seat_set_pointer(struct weston_seat *seat,
- struct weston_pointer *pointer)
-{
- if (pointer && (seat->pointer || pointer->seat))
- return; /* XXX: error? */
- if (!pointer && !seat->pointer)
- return;
-
- seat->pointer = pointer;
- if (pointer)
- pointer->seat = seat;
-
- seat_send_updated_caps(seat);
-}
-
-WL_EXPORT void
-weston_seat_set_keyboard(struct weston_seat *seat,
- struct weston_keyboard *keyboard)
-{
- if (keyboard && (seat->keyboard || keyboard->seat))
- return; /* XXX: error? */
- if (!keyboard && !seat->keyboard)
- return;
-
- seat->keyboard = keyboard;
- if (keyboard)
- keyboard->seat = seat;
-
- seat_send_updated_caps(seat);
-}
-
-WL_EXPORT void
-weston_seat_set_touch(struct weston_seat *seat, struct weston_touch *touch)
-{
- if (touch && (seat->touch || touch->seat))
- return; /* XXX: error? */
- if (!touch && !seat->touch)
- return;
-
- seat->touch = touch;
- if (touch)
- touch->seat = seat;
-
- seat_send_updated_caps(seat);
-}
-
-WL_EXPORT void
weston_pointer_set_focus(struct weston_pointer *pointer,
struct wl_surface *surface,
wl_fixed_t sx, wl_fixed_t sy)
@@ -1444,6 +1424,8 @@
WL_EXPORT int
weston_seat_init_keyboard(struct weston_seat *seat, struct xkb_keymap *keymap)
{
+ struct weston_keyboard *keyboard;
+
if (seat->keyboard)
return 0;
@@ -1466,8 +1448,16 @@
seat->xkb_state.leds = 0;
- weston_keyboard_init(&seat->keyboard_instance);
- weston_seat_set_keyboard(seat, &seat->keyboard_instance);
+ keyboard = weston_keyboard_create();
+ if (keyboard == NULL) {
+ weston_log("failed to allocate weston keyboard struct\n");
+ return -1;
+ }
+
+ seat->keyboard = keyboard;
+ keyboard->seat = seat;
+
+ seat_send_updated_caps(seat);
return 0;
}
@@ -1475,21 +1465,37 @@
WL_EXPORT void
weston_seat_init_pointer(struct weston_seat *seat)
{
+ struct weston_pointer *pointer;
+
if (seat->pointer)
return;
- weston_pointer_init(&seat->pointer_instance);
- weston_seat_set_pointer(seat, &seat->pointer_instance);
+ pointer = weston_pointer_create();
+ if (pointer == NULL)
+ return;
+
+ seat->pointer = pointer;
+ pointer->seat = seat;
+
+ seat_send_updated_caps(seat);
}
WL_EXPORT void
weston_seat_init_touch(struct weston_seat *seat)
{
+ struct weston_touch *touch;
+
if (seat->touch)
return;
- weston_touch_init(&seat->touch_instance);
- weston_seat_set_touch(seat, &seat->touch_instance);
+ touch = weston_touch_create();
+ if (touch == NULL)
+ return;
+
+ seat->touch = touch;
+ touch->seat = seat;
+
+ seat_send_updated_caps(seat);
}
WL_EXPORT void
@@ -1536,11 +1542,11 @@
xkb_info_destroy(&seat->xkb_info);
if (seat->pointer)
- weston_pointer_release(seat->pointer);
+ weston_pointer_destroy(seat->pointer);
if (seat->keyboard)
- weston_keyboard_release(seat->keyboard);
+ weston_keyboard_destroy(seat->keyboard);
if (seat->touch)
- weston_touch_release(seat->touch);
+ weston_touch_destroy(seat->touch);
wl_signal_emit(&seat->destroy_signal, seat);
}