From 2ab08d8698567f10db803a1150762da59065cbdc Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Mon, 5 Apr 2021 23:10:50 +0300 Subject: [PATCH] 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 --- libweston/data-device.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/libweston/data-device.c b/libweston/data-device.c index fc4e662c..6ac6f65f 100644 --- a/libweston/data-device.c +++ b/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); weston_pointer_end_grab(pointer); - weston_keyboard_end_grab(keyboard); + if (keyboard) + weston_keyboard_end_grab(keyboard); 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); weston_touch_end_grab(touch); - weston_keyboard_end_grab(keyboard); + if (keyboard) + weston_keyboard_end_grab(keyboard); free(drag); } @@ -954,10 +956,12 @@ weston_pointer_start_drag(struct weston_pointer *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_keyboard_start_grab(keyboard, &drag->base.keyboard_grab); + if (keyboard) + weston_keyboard_start_grab(keyboard, &drag->base.keyboard_grab); return 0; } @@ -1014,10 +1018,12 @@ weston_touch_start_drag(struct weston_touch *touch, &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_keyboard_start_grab(keyboard, &drag->base.keyboard_grab); + if (keyboard) + weston_keyboard_start_grab(keyboard, &drag->base.keyboard_grab); drag_grab_touch_focus(drag);