libweston/data-device: Don't crash when doing dnd operations w/o a keyboard

pointer/touch drag-n-drop operations could happen if there's no keyboard
hooked up or when it is unplugged.

Fixes: #235

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
dev
Marius Vlad 4 years ago committed by Daniel Stone
parent 10c072b3f5
commit 2ab08d8698
  1. 18
      libweston/data-device.c

@ -640,7 +640,8 @@ data_device_end_pointer_drag_grab(struct weston_pointer_drag *drag)
data_device_end_drag_grab(&drag->base, pointer->seat); data_device_end_drag_grab(&drag->base, pointer->seat);
weston_pointer_end_grab(pointer); weston_pointer_end_grab(pointer);
weston_keyboard_end_grab(keyboard); if (keyboard)
weston_keyboard_end_grab(keyboard);
free(drag); free(drag);
} }
@ -740,7 +741,8 @@ data_device_end_touch_drag_grab(struct weston_touch_drag *drag)
data_device_end_drag_grab(&drag->base, touch->seat); data_device_end_drag_grab(&drag->base, touch->seat);
weston_touch_end_grab(touch); weston_touch_end_grab(touch);
weston_keyboard_end_grab(keyboard); if (keyboard)
weston_keyboard_end_grab(keyboard);
free(drag); free(drag);
} }
@ -954,10 +956,12 @@ weston_pointer_start_drag(struct weston_pointer *pointer,
} }
weston_pointer_clear_focus(pointer); weston_pointer_clear_focus(pointer);
weston_keyboard_set_focus(keyboard, NULL); if (keyboard)
weston_keyboard_set_focus(keyboard, NULL);
weston_pointer_start_grab(pointer, &drag->grab); weston_pointer_start_grab(pointer, &drag->grab);
weston_keyboard_start_grab(keyboard, &drag->base.keyboard_grab); if (keyboard)
weston_keyboard_start_grab(keyboard, &drag->base.keyboard_grab);
return 0; return 0;
} }
@ -1014,10 +1018,12 @@ weston_touch_start_drag(struct weston_touch *touch,
&drag->base.data_source_listener); &drag->base.data_source_listener);
} }
weston_keyboard_set_focus(keyboard, NULL); if (keyboard)
weston_keyboard_set_focus(keyboard, NULL);
weston_touch_start_grab(touch, &drag->grab); weston_touch_start_grab(touch, &drag->grab);
weston_keyboard_start_grab(keyboard, &drag->base.keyboard_grab); if (keyboard)
weston_keyboard_start_grab(keyboard, &drag->base.keyboard_grab);
drag_grab_touch_focus(drag); drag_grab_touch_focus(drag);

Loading…
Cancel
Save