input: Don't test keyboard/pointer/touch pointers

Keyboards and pointers aren't freed when devices are removed, so we should
really be testing keyboard_device_count and pointer_device_count in most
cases, not the actual pointers. Otherwise we end up with different
behaviour after removing a device than we had before it was inserted.

This commit renames the touch/keyboard/pointer pointers and adds helper
functions to get them that hide this complexity and return NULL when
*_device_count is 0.

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Jonas Ã…dahl <jadahl@gmail.com>
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index 55c85ed..73ba783 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -174,7 +174,9 @@
 static uint32_t
 get_xkb_mod_mask(struct x11_backend *b, uint32_t in)
 {
-	struct weston_xkb_info *info = b->core_seat.keyboard->xkb_info;
+	struct weston_keyboard *keyboard =
+		weston_seat_get_keyboard(&b->core_seat);
+	struct weston_xkb_info *info = keyboard->xkb_info;
 	uint32_t ret = 0;
 
 	if ((in & ShiftMask) && info->shift_mod != XKB_MOD_INVALID)
@@ -206,6 +208,7 @@
 	b->xkb_event_base = 0;
 	return;
 #else
+	struct weston_keyboard *keyboard;
 	const xcb_query_extension_reply_t *ext;
 	xcb_generic_error_t *error;
 	xcb_void_cookie_t select;
@@ -285,7 +288,8 @@
 		return;
 	}
 
-	xkb_state_update_mask(b->core_seat.keyboard->xkb_state.state,
+	keyboard = weston_seat_get_keyboard(&b->core_seat);
+	xkb_state_update_mask(keyboard->xkb_state.state,
 			      get_xkb_mod_mask(b, state_reply->baseMods),
 			      get_xkb_mod_mask(b, state_reply->latchedMods),
 			      get_xkb_mod_mask(b, state_reply->lockedMods),
@@ -975,7 +979,10 @@
 static void
 update_xkb_state(struct x11_backend *b, xcb_xkb_state_notify_event_t *state)
 {
-	xkb_state_update_mask(b->core_seat.keyboard->xkb_state.state,
+	struct weston_keyboard *keyboard =
+		weston_seat_get_keyboard(&b->core_seat);
+
+	xkb_state_update_mask(keyboard->xkb_state.state,
 			      get_xkb_mod_mask(b, state->baseMods),
 			      get_xkb_mod_mask(b, state->latchedMods),
 			      get_xkb_mod_mask(b, state->lockedMods),
@@ -1003,9 +1010,10 @@
 update_xkb_state_from_core(struct x11_backend *b, uint16_t x11_mask)
 {
 	uint32_t mask = get_xkb_mod_mask(b, x11_mask);
-	struct weston_keyboard *keyboard = b->core_seat.keyboard;
+	struct weston_keyboard *keyboard
+		= weston_seat_get_keyboard(&b->core_seat);
 
-	xkb_state_update_mask(b->core_seat.keyboard->xkb_state.state,
+	xkb_state_update_mask(keyboard->xkb_state.state,
 			      keyboard->modifiers.mods_depressed & mask,
 			      keyboard->modifiers.mods_latched & mask,
 			      keyboard->modifiers.mods_locked & mask,