From e974efe18ea2ea299ad4fddeaefa8bd0cae57604 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Tue, 18 Aug 2020 14:32:46 +0900 Subject: [PATCH] DSWaylandKeyboard: fix to initialze member variable properly, add exception handling on setFocus() Change-Id: I20211a9be278d73bd21baacb230704f347711040 Signed-off-by: Sung-Jin Park --- src/DSWaylandServer/DSWaylandKeyboard.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/DSWaylandServer/DSWaylandKeyboard.cpp b/src/DSWaylandServer/DSWaylandKeyboard.cpp index 85fa455..48ce7f4 100644 --- a/src/DSWaylandServer/DSWaylandKeyboard.cpp +++ b/src/DSWaylandServer/DSWaylandKeyboard.cpp @@ -39,8 +39,8 @@ DSWaylandKeyboardPrivate::DSWaylandKeyboardPrivate(DSWaylandSeat *seat, DSWaylan : DSObjectPrivate(keyboard), __p_ptr(keyboard), __seat(seat), - __xkb(seat->getXkb()), - __compositor(seat->getCompositor()), + __xkb(seat ? (seat->getXkb()) : nullptr), + __compositor(seat ? (seat->getCompositor()) : nullptr), __focusSurface(nullptr), __focusClient(nullptr), __repeatRate(0), @@ -267,18 +267,21 @@ void DSWaylandKeyboard::setFocus(DSWaylandSurface *waylandSurface) if (priv->__focusSurface != waylandSurface) { - if (priv->__focusSurface) + if (priv->__focusSurface && priv->__focusSurface->hasResource()) { struct ::wl_resource *surfaceToLeave = priv->__focusSurface->getWlResource(); priv->sendModifiers(surfaceToLeave); priv->sendLeave(surfaceToLeave); } - struct ::wl_resource *surfaceToEnter = waylandSurface->getWlResource(); - priv->sendEnter(surfaceToEnter); + if (waylandSurface && waylandSurface->hasResource()) + { + struct ::wl_resource *surfaceToEnter = waylandSurface->getWlResource(); + priv->sendEnter(surfaceToEnter); - priv->__focusSurface = waylandSurface; - priv->__focusClient = wl_resource_get_client(waylandSurface->getWlResource()); + priv->__focusSurface = waylandSurface; + priv->__focusClient = wl_resource_get_client(waylandSurface->getWlResource()); + } } } -- 2.7.4