weston-ivi-shell, ilmControl and ilmCommon: Implement GetKeyboardFocus
authorJonathan Maw <jonathan.maw@codethink.co.uk>
Tue, 12 Aug 2014 10:50:00 +0000 (10:50 +0000)
committerNobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>
Thu, 6 Nov 2014 08:18:34 +0000 (17:18 +0900)
This commit implements ilm_GetKeyboardFocusSurfaceId using the "input
focus" event from the "ivi controller surface" interface.

ilm_types.h has been expanded to store keyboard focus on a per-surface
basis.

Signed-off-by: James Thomas <james.thomas@codethink.co.uk>
ivi-layermanagement-api/ilmCommon/include/ilm_types.h
ivi-layermanagement-api/ilmControl/src/ilm_control_wayland_platform.c
weston-ivi-shell/src/ivi-controller.c

index 0d9a6dd..e9c84b0 100644 (file)
@@ -238,6 +238,7 @@ struct ilmSurfaceProperties
     t_ilm_uint chromaKeyGreen;              /*!< chromakey's green value of the surface */
     t_ilm_uint chromaKeyBlue;               /*!< chromakey's blue value of the surface */
     t_ilm_int  creatorPid;                  /*!< process id of application that created this surface */
+    t_ilm_bool hasKeyboardFocus;            /*!< whether this surface has keyboard focus */
 };
 
 /**
index b1c0787..8585a09 100644 (file)
@@ -765,10 +765,15 @@ controller_surface_listener_input_focus(void *data,
                    uint32_t device,
                    int32_t enabled)
 {
-    (void)data;
-    (void)controller;
-    (void)device;
-    (void)enabled;
+    struct surface_context *ctx_surf = data;
+
+    if (ctx_surf == NULL) {
+        fprintf(stderr, "%s: Invalid surface context\n", __FUNCTION__);
+        return;
+    }
+    if (device & IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD) {
+        ctx_surf->prop.hasKeyboardFocus = enabled;
+    }
 }
 
 static struct ivi_controller_surface_listener controller_surface_listener=
@@ -2153,10 +2158,18 @@ ilm_SetKeyboardFocusOn(t_ilm_surface surfaceId)
 ILM_EXPORT ilmErrorTypes
 ilm_GetKeyboardFocusSurfaceId(t_ilm_surface* pSurfaceId)
 {
-    ilmErrorTypes returnValue = ILM_FAILED;
-    (void)pSurfaceId;
-    returnValue = ILM_SUCCESS;
-    return returnValue;
+    struct ilm_control_context *ctx = sync_and_acquire_instance();
+    struct surface_context *ctx_surf = NULL;
+
+    wl_list_for_each(ctx_surf, &ctx->wl.list_surface, link) {
+        if (ctx_surf->prop.hasKeyboardFocus) {
+            *pSurfaceId = ctx_surf->id_surface;
+            break;
+        }
+    }
+
+    release_instance();
+    return ILM_SUCCESS;
 }
 
 ILM_EXPORT ilmErrorTypes
index 0f152e1..f341454 100755 (executable)
@@ -441,6 +441,11 @@ send_surface_event(struct wl_resource *resource,
         ivi_controller_surface_send_pixelformat(resource,
                                                 prop->pixelformat);
     }
+    if (mask & IVI_NOTIFICATION_KEYBOARD_FOCUS) {
+        ivi_controller_surface_send_input_focus(resource,
+                        IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD,
+                        prop->hasKeyboardFocus);
+    }
     if (mask & IVI_NOTIFICATION_REMOVE) {
         send_surface_add_event(ivisurf, resource, IVI_NOTIFICATION_REMOVE);
     }
@@ -1064,6 +1069,28 @@ controller_surface_destroy(struct wl_client *client,
     wl_resource_destroy(resource);
 }
 
+static void send_all_keyboard_focus(struct ivishell *shell)
+{
+    struct ivi_layout_SurfaceProperties props;
+    struct ivicontroller_surface *ctrlsurf;
+    struct ivisurface *current_surf;
+    uint32_t id_surface;
+
+    wl_list_for_each(current_surf, &shell->list_surface, link) {
+        ivi_layout_getPropertiesOfSurface(current_surf->layout_surface,
+                                          &props);
+        id_surface = ivi_layout_getIdOfSurface(current_surf->layout_surface);
+        wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
+            if (id_surface != ctrlsurf->id_surface) {
+                    continue;
+            }
+            ivi_controller_surface_send_input_focus(ctrlsurf->resource,
+                            IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD,
+                            props.hasKeyboardFocus);
+        }
+    }
+}
+
 static void
 controller_surface_set_input_focus(struct wl_client *client,
               struct wl_resource *resource,
@@ -1076,6 +1103,7 @@ controller_surface_set_input_focus(struct wl_client *client,
     if (device & IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD) {
         if (enabled) {
             ivi_layout_SetKeyboardFocusOn(ivisurf->layout_surface);
+            send_all_keyboard_focus(ivisurf->shell);
         }
     }
 }