From ecdccefdb7c3b555a08fc8f9078e3edc07473cac Mon Sep 17 00:00:00 2001
From: Rob Bradford <rob@linux.intel.com>
Date: Wed, 30 May 2012 13:01:02 +0100
Subject: [PATCH 2/2] elementary/window: Add support for setting the cursor
 under Wayland

* Add support for setting the cursor under Wayland:
* Introduce a configure option and #define to as per other engines
* Add always-built API function to allow identification of running under
Wayland (like for X11)
* Call into Ecore to set the cursor when the mouse enters the desired widget.
---
 ChangeLog            |   10 ++++++++++
 configure.ac         |   25 +++++++++++++++++++++++++
 src/lib/elm_priv.h   |    3 +++
 src/lib/elm_win.c    |   32 ++++++++++++++++++++++++++++++++
 src/lib/elm_win.h    |   12 ++++++++++++
 src/lib/els_cursor.c |   27 ++++++++++++++++++++++-----
 6 files changed, 104 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3c17893..d8526fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -148,3 +148,13 @@
 2012-05-29 Rob Bradford
 	* Move X related cursor items into their own substruct of Elm_Cursor
 	to make supporting cursors on other platforms cleaner.
+
+2012-05-30 Rob Bradford
+
+	* Add support for setting the cursor under Wayland:
+	* Introduce a configure option and #define to as per other engines
+	* Add always-built API function to allow identification of running
+	under Wayland (like for X11)
+	* Call into Ecore to set the cursor when the mouse enters the desired
+	widget.
+
diff --git a/configure.ac b/configure.ac
index 7b5785a..9998c4c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -444,6 +444,30 @@ if test "x$want_elementary_wince" = "xyes" -a "x$have_elementary_wince" = "xno";
     AC_MSG_ERROR([ecore-wince support requested, but not found by pkg-config.])
 fi
 
+
+have_elementary_wayland="no"
+want_elementary_wayland="auto"
+AC_ARG_ENABLE([ecore-x],
+   [AC_HELP_STRING([--disable-ecore-wayland], [disable ecore-wayland support. @<:@default=detect@:>@])],
+   [want_elementary_wayland=$enableval], [])
+
+if test "x$want_elementary_wayland" != "xno"; then
+   PKG_CHECK_MODULES([ELEMENTARY_WAYLAND],
+      [ecore-wayland],
+      [
+       AC_DEFINE(HAVE_ELEMENTARY_WAYLAND, 1, [Wayland support for Elementary])
+       have_elementary_wayland="yes"
+       requirement_elm="ecore-wayland ${requirement_elm}"
+      ],
+      [have_elementary_wayland="no"]
+   )
+else
+    have_elementary_wayland="no"
+fi
+if test "x$want_elementary_wayland" = "xyes" -a "x$have_elementary_wayland" = "xno"; then
+    AC_MSG_ERROR([ecore-x support requested, but not found by pkg-config.])
+fi
+
 ELM_EDBUS_DEF="#undef"
 have_elementary_edbus="no"
 want_elementary_edbus="auto"
@@ -752,6 +776,7 @@ echo "    SDL....................: ${have_elementary_sdl}"
 echo "    Cocoa..................: ${have_elementary_cocoa}"
 echo "    Windows XP.............: ${have_elementary_win32}"
 echo "    Windows CE.............: ${have_elementary_wince}"
+echo "    Wayland...............:. ${have_elementary_wayland}"
 echo
 echo "  Features:"
 echo "    Ecore_IMF..............: ${have_ecore_imf}"
diff --git a/src/lib/elm_priv.h b/src/lib/elm_priv.h
index ae6c20c..d62ed1f 100644
--- a/src/lib/elm_priv.h
+++ b/src/lib/elm_priv.h
@@ -12,6 +12,9 @@
 #ifdef HAVE_ELEMENTARY_WINCE
 #include <Ecore_WinCE.h>
 #endif
+#ifdef HAVE_ELEMENTARY_WAYLAND
+#include <Ecore_Wayland.h>
+#endif
 
 #include "elm_widget.h"
 
diff --git a/src/lib/elm_win.c b/src/lib/elm_win.c
index 7e4ece0..11b14a3 100644
--- a/src/lib/elm_win.c
+++ b/src/lib/elm_win.c
@@ -50,6 +50,13 @@ struct _Elm_Win_Smart_Data
       Ecore_Event_Handler           *client_message_handler;
    } x;
 #endif
+#ifdef HAVE_ELEMENTARY_WAYLAND
+   struct
+   {
+     Ecore_Wl_Window             *win;
+   } wl;
+#endif
+
    Ecore_Job                     *deferred_resize_job;
    Ecore_Job                     *deferred_child_eval_job;
 
@@ -2146,6 +2153,10 @@ elm_win_add(Evas_Object *parent,
    _elm_win_xwindow_get(sd);
 #endif
 
+#ifdef HAVE_ELEMENTARY_WAYLAND
+   sd->wl.win = ecore_evas_wayland_window_get(sd->ee);
+#endif
+
    if ((_elm_config->bgpixmap) && (!_elm_config->compositing))
      ecore_evas_avoid_damage_set(sd->ee, ECORE_EVAS_AVOID_DAMAGE_EXPOSE);
    // bg pixmap done by x - has other issues like can be redrawn by x before it
@@ -3384,3 +3395,24 @@ elm_win_xwindow_get(const Evas_Object *obj)
 #endif
    return 0;
 }
+
+EAPI Ecore_Wl_Window *
+elm_win_wl_window_get(const Evas_Object *obj)
+{
+   if (!obj) return NULL;
+
+   if (!evas_object_smart_type_check_ptr(obj, WIN_SMART_NAME))
+     {
+        Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
+        return ecore_evas_wayland_window_get(ee);
+     }
+
+   ELM_WIN_CHECK(obj) NULL;
+   ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
+#if HAVE_ELEMENTARY_WAYLAND
+   if (sd->wl.win) return sd->wl.win;
+   if (sd->parent) return elm_win_wl_window_get(sd->parent);
+#endif
+   return NULL;
+}
+
diff --git a/src/lib/elm_win.h b/src/lib/elm_win.h
index 1f48663..a968119 100644
--- a/src/lib/elm_win.h
+++ b/src/lib/elm_win.h
@@ -1246,6 +1246,18 @@ EAPI Eina_Bool             elm_win_socket_listen(Evas_Object *obj, const char *s
  */
 EAPI Ecore_X_Window elm_win_xwindow_get(const Evas_Object *obj);
 
+/* Wayland specific call - returns NULL on non-Wayland engines */
+/**
+ * Get the Ecore_Wl_Window of and Evas_Object
+ *
+ * @param obj the object
+ *
+ * @return The Ecore_Wl_Window of @p obj
+ *
+ * @ingroup Win
+ */
+EAPI Ecore_Wl_Window *elm_win_wl_window_get(const Evas_Object *obj);
+
 /**
  * @}
  */
diff --git a/src/lib/els_cursor.c b/src/lib/els_cursor.c
index 3cadc31..c44b342 100644
--- a/src/lib/els_cursor.c
+++ b/src/lib/els_cursor.c
@@ -140,6 +140,12 @@ struct _Elm_Cursor
      Ecore_X_Window win;
    } x;
 #endif
+#ifdef HAVE_ELEMENTARY_WAYLAND
+   struct {
+     Ecore_Wl_Window *win;
+   } wl;
+#endif
+
    Eina_Bool visible:1;
    Eina_Bool use_engine:1;
    Eina_Bool engine_only:1;
@@ -220,6 +226,10 @@ _elm_cursor_mouse_in(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSE
         if (cur->x.win)
           ecore_x_window_cursor_set(cur->x.win, cur->x.cursor);
 #endif
+#ifdef HAVE_ELEMENTARY_WAYLAND
+        if (cur->wl.win)
+          ecore_wl_window_cursor_from_name_set(cur->wl.win, cur->cursor_name);
+#endif
      }
    evas_event_thaw(cur->evas);
 }
@@ -260,6 +270,10 @@ _elm_cursor_mouse_out(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUS
         if (cur->x.win)
           ecore_x_window_cursor_set(cur->x.win, ECORE_X_CURSOR_X);
 #endif
+#ifdef HAVE_ELEMENTARY_WAYLAND
+        if (cur->wl.win)
+          ecore_wl_window_cursor_default_restore(cur->wl.win);
+#endif
      }
    evas_event_thaw(cur->evas);
 }
@@ -303,14 +317,14 @@ _elm_cursor_cur_set(Elm_Cursor *cur)
    if (cur->use_engine)
      {
 #ifdef HAVE_ELEMENTARY_X
-        struct _Cursor_Id *cur_id;
-
-        cur_id = bsearch(&(cur->cursor_name), _cursors, _cursors_count,
-                         sizeof(struct _Cursor_Id), _elm_cursor_strcmp);
-
         cur->x.win = elm_win_xwindow_get(cur->eventarea);
         if (cur->x.win)
           {
+             struct _Cursor_Id *cur_id;
+
+             cur_id = bsearch(&(cur->cursor_name), _cursors, _cursors_count,
+                              sizeof(struct _Cursor_Id), _elm_cursor_strcmp);
+
              if (!cur_id)
                {
                   INF("X cursor couldn't be found: %s. Using default.",
@@ -321,6 +335,9 @@ _elm_cursor_cur_set(Elm_Cursor *cur)
                 cur->x.cursor = ecore_x_cursor_shape_get(cur_id->id);
           }
 #endif
+#ifdef HAVE_ELEMENTARY_WAYLAND
+        cur->wl.win = elm_win_wl_window_get(cur->eventarea);
+#endif
      }
 }
 
-- 
1.7.10.2

