downstream: ivi-shell: Implement set_keyboard_focus 02/32702/1
authorJanos Kovacs <jankovac503@gmail.com>
Fri, 19 Dec 2014 14:08:53 +0000 (16:08 +0200)
committerJan Ekström <jan.ekstrom@intel.com>
Mon, 22 Dec 2014 13:24:33 +0000 (15:24 +0200)
This commit implements ivi_layout_set_keyboard_focus_on.

It also extends ivi-layout.h and ivi-layout-export.h to store
keyboard focus on a per-surface basis.

original patch backported to upstream Weston ivi-shell:
dd01ca5 by Jonathan Maw <jonathan.maw@codethink.co.uk> on 24 of Oct 2014

Change-Id: Ib8c49e8c3eee5878bfa0243053f2093458f7ef37

ivi-shell/ivi-layout-export.h
ivi-shell/ivi-layout.c

index f2309d3..ce74ef2 100644 (file)
@@ -81,6 +81,7 @@ struct ivi_layout_surface_properties
        bool visibility;
        int32_t transition_type;
        uint32_t transition_duration;
+       uint32_t has_keyboard_focus;
 };
 
 struct ivi_layout_layer_properties
@@ -116,6 +117,7 @@ enum ivi_layout_notification_mask {
        IVI_NOTIFICATION_ADD         = (1 << 9),
        IVI_NOTIFICATION_REMOVE      = (1 << 10),
        IVI_NOTIFICATION_CONFIGURE   = (1 << 11),
+       IVI_NOTIFICATION_KEYBOARD_FOCUS = (1 << 12),
        IVI_NOTIFICATION_ALL         = 0xFFFF
 };
 
@@ -513,6 +515,20 @@ ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
 wl_fixed_t
 ivi_layout_surface_get_opacity(struct ivi_layout_surface *ivisurf);
 
+
+/**
+ * \brief Set the keyboard focus on a certain surface
+ * To receive keyboard events, 2 conditions must be fulfilled:
+ * 1- The surface must accept events from keyboard. See ilm_UpdateInputEventAcc eptanceOn
+ * 2- The keyboard focus must be set on that surface
+ *
+ * \return 0 if the method call was successful
+ * \return -1 if the method call was failed
+ */
+int32_t
+ivi_layout_set_keyboard_focus_on(struct ivi_layout_surface *ivisurf);
+
+
 /**
  * \brief Set the destination area of a surface within a layer for rendering.
  *
index 9814761..956c9a9 100644 (file)
@@ -2172,6 +2172,49 @@ ivi_layout_surface_get_opacity(struct ivi_layout_surface *ivisurf)
 }
 
 WL_EXPORT int32_t
+ivi_layout_set_keyboard_focus_on(struct ivi_layout_surface *ivisurf)
+{
+       struct ivi_layout *layout = get_layout_instance();
+       struct wl_list *seat_list = &layout->compositor->seat_list;
+       struct wl_list *surface_list = &layout->surface_list;
+       struct ivi_layout_surface *current_surf;
+
+       if (ivisurf == NULL) {
+               weston_log("%s: invalid argument\n", __FUNCTION__);
+               return -1;
+       }
+
+       if (seat_list == NULL) {
+               weston_log("%s: seat list is NULL\n", __FUNCTION__);
+               return -1;
+       }
+
+       if (ivisurf->surface == NULL) {
+               weston_log("%s: ivisurf has no surface\n", __FUNCTION__);
+               return -1;
+       }
+
+       if (surface_list == NULL) {
+               weston_log("%s: surface list is NULL\n", __FUNCTION__);
+               return -1;
+       }
+
+       wl_list_for_each(current_surf, &layout->surface_list, link) {
+               if (current_surf == ivisurf) {
+                       current_surf->prop.has_keyboard_focus = 1;
+                       current_surf->pending.prop.has_keyboard_focus = 1;
+               } else {
+                       current_surf->prop.has_keyboard_focus = 0;
+                       current_surf->pending.prop.has_keyboard_focus = 0;
+               }
+               current_surf->event_mask |= IVI_NOTIFICATION_KEYBOARD_FOCUS;
+       }
+
+       return 0;
+}
+
+
+WL_EXPORT int32_t
 ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
                                             int32_t x, int32_t y,
                                             int32_t width, int32_t height)
@@ -2901,6 +2944,32 @@ static void
 keyboard_grab_key(struct weston_keyboard_grab *grab, uint32_t time,
                  uint32_t key, uint32_t state)
 {
+       struct ivi_layout *layout = get_layout_instance();
+       struct weston_keyboard *keyboard = grab->keyboard;
+       struct wl_display *display = keyboard->seat->compositor->wl_display;
+       struct ivi_layout_surface *surf;
+       struct wl_resource *resource;
+       uint32_t serial;
+
+       wl_list_for_each(surf, &layout->surface_list, link) {
+               if (surf->prop.has_keyboard_focus) {
+                       resource = wl_resource_find_for_client(
+                                       &keyboard->resource_list,
+                                       wl_resource_get_client(surf->surface->resource));
+                       if (!resource)
+                               resource = wl_resource_find_for_client(
+                                               &keyboard->focus_resource_list,
+                                               wl_resource_get_client(surf->surface->resource));
+
+                       if (resource) {
+                               serial = wl_display_next_serial(display);
+                               wl_keyboard_send_key(resource, serial, time, key, state);
+                       } else {
+                               weston_log("%s: No resource found for surface %d\n",
+                                          __FUNCTION__, surf->id_surface);
+                       }
+               }
+       }
 }
 
 static void
@@ -2908,6 +2977,62 @@ keyboard_grab_modifiers(struct weston_keyboard_grab *grab, uint32_t serial,
                        uint32_t mods_depressed, uint32_t mods_latched,
                        uint32_t mods_locked, uint32_t group)
 {
+       struct ivi_layout *layout = get_layout_instance();
+       struct weston_keyboard *keyboard = grab->keyboard;
+       struct ivi_layout_surface *surf;
+       struct wl_resource *resource;
+       int sent_to_pointer_client = 0;
+       struct weston_pointer *pointer = keyboard->seat->pointer;
+
+       /* Send modifiers to focussed surface */
+       wl_list_for_each(surf, &layout->surface_list, link) {
+               if (surf->prop.has_keyboard_focus) {
+                       resource = wl_resource_find_for_client(
+                                       &keyboard->resource_list,
+                                       wl_resource_get_client(surf->surface->resource));
+                       if (!resource)
+                               resource = wl_resource_find_for_client(
+                                               &keyboard->focus_resource_list,
+                                               wl_resource_get_client(surf->surface->resource));
+
+                       if (resource) {
+                               wl_keyboard_send_modifiers(resource, serial,
+                                                          mods_depressed,
+                                                          mods_latched, mods_locked,
+                                                          group);
+                               if (pointer && pointer->focus
+                                   && pointer->focus->surface->resource
+                                   && pointer->focus->surface == surf->surface)
+                                       sent_to_pointer_client = 1;
+                       } else {
+                               weston_log("%s: No resource found for surface %d\n",
+                                          __FUNCTION__, surf->id_surface);
+                       }
+               }
+       }
+
+       /* Send modifiers to pointer's client, if not already sent */
+       if (!sent_to_pointer_client && pointer && pointer->focus
+           && pointer->focus->surface->resource) {
+               struct wl_client *pointer_client =
+                       wl_resource_get_client(pointer->focus->surface->resource);
+               wl_resource_for_each(resource, &keyboard->resource_list) {
+                       if (wl_resource_get_client(resource) == pointer_client) {
+                               sent_to_pointer_client = 1;
+                               wl_keyboard_send_modifiers(resource, serial, mods_depressed,
+                                                          mods_latched, mods_locked, group);
+                               break;
+                       }
+               }
+
+               if (!sent_to_pointer_client) {
+                       wl_resource_for_each(resource, &keyboard->focus_resource_list) {
+                               wl_keyboard_send_modifiers(resource, serial, mods_depressed,
+                                                          mods_latched, mods_locked, group);
+                               break;
+                       }
+               }
+       }
 }
 
 static void