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-wayland.c b/src/compositor-wayland.c
index a8e63e1..1b40e46 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -1479,7 +1479,7 @@
 
 	close(fd);
 
-	if (input->base.keyboard)
+	if (weston_seat_get_keyboard(&input->base))
 		weston_seat_update_keymap(&input->base, keymap);
 	else
 		weston_seat_init_keyboard(&input->base, keymap);
@@ -1569,11 +1569,12 @@
 }
 
 static void
-input_handle_modifiers(void *data, struct wl_keyboard *keyboard,
+input_handle_modifiers(void *data, struct wl_keyboard *wl_keyboard,
 		       uint32_t serial_in, uint32_t mods_depressed,
 		       uint32_t mods_latched, uint32_t mods_locked,
 		       uint32_t group)
 {
+	struct weston_keyboard *keyboard;
 	struct wayland_input *input = data;
 	struct wayland_backend *b = input->backend;
 	uint32_t serial_out;
@@ -1586,7 +1587,8 @@
 	else
 		serial_out = wl_display_next_serial(b->compositor->wl_display);
 
-	xkb_state_update_mask(input->base.keyboard->xkb_state.state,
+	keyboard = weston_seat_get_keyboard(&input->base);
+	xkb_state_update_mask(keyboard->xkb_state.state,
 			      mods_depressed, mods_latched,
 			      mods_locked, 0, 0, group);
 	notify_modifiers(&input->base, serial_out);