Apply orientation.
authorSung-jae Park <nicesj.park@samsung.com>
Tue, 21 Apr 2015 13:49:43 +0000 (22:49 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Tue, 21 Apr 2015 13:49:43 +0000 (22:49 +0900)
Rotated input event processing.

[model] Redwood,Kiran,B3(Wearable)
[binary_type] AP
[customer] Docomo/Orange/ATT/Open
[issue#] N/A
[problem]
[cause]
[solution]
[team] HomeTF
[request]
[horizontal_expansion]

Change-Id: I4d50f95ec9472642b8e1b790094099ddf0bda2ad

include/widget_internal.h
src/virtual_window.c
src/widget.c

index a498e70..77a74f8 100755 (executable)
@@ -182,6 +182,7 @@ typedef enum widget_system_event {
        WIDGET_SYS_EVENT_RESUMED = 0x0200, /**< widget is resumed. */
        WIDGET_SYS_EVENT_MMC_STATUS_CHANGED = 0x0400, /**< MMC Status change event. */
        WIDGET_SYS_EVENT_DELETED = 0x0800, /**< widget instance is removed from a viewer. */
+       WIDGET_SYS_EVENT_ORIENTATION_CHANGED = 0x01000, /**< Orientation is changed */
 } widget_system_event_e;
 
 /**
index 6b6e352..bc98aef 100644 (file)
@@ -23,6 +23,7 @@
 #include <Evas.h>
 #include <dlfcn.h>
 #include <Eina.h>
+#include <math.h>
 
 #include <X11/Xlib.h>
 
@@ -81,6 +82,8 @@ typedef struct virtual_window_info {
        int resource_cnt;
 
        int pressed;
+
+       int orientation;
 } *vwin_info_t;
 
 static inline Evas_Object *get_highlighted_object(Evas_Object *obj)
@@ -94,6 +97,49 @@ static inline Evas_Object *get_highlighted_object(Evas_Object *obj)
        return ho;
 }
 
+static inline void apply_orientation(int degree, int *x, int *y)
+{
+       int _x;
+       int _y;
+       int _angle;
+
+       switch (degree) {
+       case 0:
+               return;
+       case 90:
+               _x = *x;
+               _y = *y;
+
+               *x = -_y;
+               *y = _x;
+               return;
+       case 180:
+               _x = *x;
+               _y = *y;
+               _angle = degree;
+
+               *x = -_x;
+               *y = -_y;
+               return;
+       case 270:
+               _x = *x;
+               _y = *y;
+               _angle = degree;
+
+               *x = _y;
+               *y = -_x;
+               return;
+       default:
+               _x = *x;
+               _y = *y;
+               _angle = degree;
+
+               *x = (double)_x * cos((double)_angle) - (double)_y * sin((double)_angle);
+               *y = (double)_x * sin((double)_angle) + (double)_y * cos((double)_angle);
+               return;
+       }
+}
+
 /**
  * @note
  * Every user event (mouse) on the buffer will be passed via this event callback
@@ -183,6 +229,8 @@ static int event_handler_cb(widget_buffer_h handler, struct widget_buffer_event_
                evas_event_feed_mouse_out(info->e, timestamp, NULL);
                break;
        case WIDGET_BUFFER_EVENT_DOWN:
+               apply_orientation(info->degree, &event_info->info.pointer.x, &event_info->info.pointer.y);
+
                if (info->pressed) {
                        ErrPrint("MOUSE UP is not called\n");
                        ErrPrint("UP[%s] %dx%d - %lf\n", info->id, event_info->info.pointer.x, event_info->info.pointer.y, timestamp);
@@ -210,6 +258,7 @@ static int event_handler_cb(widget_buffer_h handler, struct widget_buffer_event_
                ErrPrint("DOWN[%s] %dx%d - %lf\n", info->id, event_info->info.pointer.x, event_info->info.pointer.y, timestamp);
                break;
        case WIDGET_BUFFER_EVENT_MOVE:
+               apply_orientation(info->degree, &event_info->info.pointer.x, &event_info->info.pointer.y);
                /**
                 * @note
                 * Calculate the event occurred X & Y on the buffer
@@ -217,6 +266,7 @@ static int event_handler_cb(widget_buffer_h handler, struct widget_buffer_event_
                evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, timestamp, NULL);
                break;
        case WIDGET_BUFFER_EVENT_UP:
+               apply_orientation(info->degree, &event_info->info.pointer.x, &event_info->info.pointer.y);
                evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, timestamp, NULL);
                evas_event_feed_mouse_up(info->e, 1, EVAS_BUTTON_NONE, timestamp, NULL);
                info->pressed = 0;
@@ -863,6 +913,26 @@ static void post_render_cb(void *data, Evas *e, void *event_info)
        }
 }
 
+static void pre_orientation_cb(const char *id, void *data)
+{
+       vwin_info_t info = data;
+       char *path = NULL;
+
+       /* Try provider_app first */
+       if (id) {
+               path = widget_util_uri_to_path(id);
+
+               if (path && strcmp(info->id, path)) {
+                       /* Skip */
+                       DbgPrint("SKIP: Pre orientation event callback is called [%s], %s\n", id, info->id);
+                       return;
+               }
+
+               DbgPrint("Pre orientation event callback is called [%s]\n", id);
+               info->orientation = widget_get_orientation(path);
+       }
+}
+
 static void pre_destroy_cb(const char *id, void *data)
 {
        vwin_info_t info = data;
@@ -1042,6 +1112,9 @@ PUBLIC Evas *widget_get_evas(const char *id)
        evas_event_callback_add(info->e, EVAS_CALLBACK_RENDER_PRE, pre_render_cb, info);
 
        widget_add_pre_callback(WIDGET_PRE_DESTROY_CALLBACK, pre_destroy_cb, info);
+       widget_add_pre_callback(WIDGET_PRE_ORIENTATION_CALLBACK, pre_orientation_cb, info);
+
+       info->orientation = widget_get_orientation(info->id);
 
        return info->e;
 }
index 232232b..bb36c43 100644 (file)
@@ -94,6 +94,9 @@ static struct info {
        int (*request_update_by_id)(const char *uri);
        int (*trigger_update_monitor)(const char *id, int is_gbar);
        int (*update_extra_info)(const char *id, const char *content, const char *title, const char *icon, const char *name);
+       int (*add_pre_callback)(widget_pre_callback_e type, widget_pre_callback_t cb, void *data);
+       int (*del_pre_callback)(widget_pre_callback_e type, widget_pre_callback_t cb, void *data);
+       int (*orientation)(const char *id);
 
        enum load_type {
                LOAD_TYPE_UNKNOWN = -1,
@@ -108,8 +111,6 @@ static struct info {
 
                struct _app {
                        int (*send)(widget_buffer_h handle, int idx, int x, int y, int w, int h, int gbar);
-                       int (*add_pre_callback)(widget_pre_callback_e type, widget_pre_callback_t cb, void *data);
-                       int (*del_pre_callback)(widget_pre_callback_e type, widget_pre_callback_t cb, void *data);
                } app;
        } binder;
 } s_info = {
@@ -117,6 +118,9 @@ static struct info {
        .request_update_by_id = NULL,
        .trigger_update_monitor = NULL,
        .update_extra_info = NULL,
+       .add_pre_callback = NULL,
+       .del_pre_callback = NULL,
+       .orientation = NULL,
        .type = LOAD_TYPE_UNKNOWN,    /* Not initialized */
        .binder = {
                .slave = {
@@ -124,21 +128,22 @@ static struct info {
                },
                .app = {
                        .send = NULL,
-                       .add_pre_callback = NULL,
-                       .del_pre_callback = NULL,
                },
        },
 };
 
 #define FUNC_PREFIX                               "widget_"
-#define FUNC_WIDGET_SEND_UPDATED              FUNC_PREFIX "send_buffer_updated"
-#define FUNC_WIDGET_PROVIDER_APP_UPDATED      FUNC_PREFIX "provider_app_buffer_updated"
-#define FUNC_WIDGET_FIND_PKGNAME              FUNC_PREFIX "find_pkgname"
-#define FUNC_WIDGET_REQUEST_UPDATE_BY_ID      FUNC_PREFIX "request_update_by_id"
-#define FUNC_WIDGET_TRIGGER_UPDATE_MONITOR    FUNC_PREFIX "trigger_update_monitor"
-#define FUNC_WIDGET_UPDATE_EXTRA_INFO         FUNC_PREFIX "update_extra_info"
-#define FUNC_WIDGET_ADD_PRE_CALLBACK          FUNC_PREFIX "provider_app_add_pre_callback"
-#define FUNC_WIDGET_DEL_PRE_CALLBACK          FUNC_PREFIX "provider_app_del_pre_callback"
+#define FUNC_WIDGET_SEND_UPDATED                  FUNC_PREFIX "send_buffer_updated"
+#define FUNC_WIDGET_FIND_PKGNAME                  FUNC_PREFIX "find_pkgname"
+#define FUNC_WIDGET_REQUEST_UPDATE_BY_ID          FUNC_PREFIX "request_update_by_id"
+#define FUNC_WIDGET_TRIGGER_UPDATE_MONITOR        FUNC_PREFIX "trigger_update_monitor"
+#define FUNC_WIDGET_UPDATE_EXTRA_INFO             FUNC_PREFIX "update_extra_info"
+
+#define FUNC_WIDGET_PROVIDER_APP_UPDATED          FUNC_PREFIX "provider_app_buffer_updated"
+
+#define FUNC_WIDGET_PROVIDER_APP_ADD_PRE_CALLBACK FUNC_PREFIX "provider_app_add_pre_callback"
+#define FUNC_WIDGET_PROVIDER_APP_DEL_PRE_CALLBACK FUNC_PREFIX "provider_app_del_pre_callback"
+#define FUNC_WIDGET_PROVIDER_APP_ORIENTATION      FUNC_PREFIX "provider_app_get_orientation"
 
 static inline void load_update_function(void)
 {
@@ -156,34 +161,40 @@ static inline void load_update_function(void)
        }
 }
 
-int widget_add_pre_callback(widget_pre_callback_e type, widget_pre_callback_t cb, void *data)
+PUBLIC int widget_get_orientation(const char *id)
 {
-       static int loaded = 0;
-       if (!loaded && !s_info.binder.app.add_pre_callback) {
-               s_info.binder.app.add_pre_callback = dlsym(RTLD_DEFAULT, FUNC_WIDGET_ADD_PRE_CALLBACK);
-               loaded = 1;
-       }
-
-       if (!s_info.binder.app.add_pre_callback) {
-               return WIDGET_ERROR_NOT_SUPPORTED;
+       if (!s_info.orientation) {
+               s_info.orientation = dlsym(RTLD_DEFAULT, FUNC_WIDGET_PROVIDER_APP_ORIENTATION);
+               if (!s_info.orientation) {
+                       return WIDGET_ERROR_NOT_SUPPORTED;
+               }
        }
 
-       return s_info.binder.app.add_pre_callback(type, cb, data);
+       return s_info.orientation(id);
 }
 
-int widget_del_pre_callback(widget_pre_callback_e type, widget_pre_callback_t cb, void *data)
+PUBLIC int widget_add_pre_callback(widget_pre_callback_e type, widget_pre_callback_t cb, void *data)
 {
-       static int loaded = 0;
-       if (!loaded && !s_info.binder.app.del_pre_callback) {
-               s_info.binder.app.del_pre_callback = dlsym(RTLD_DEFAULT, FUNC_WIDGET_DEL_PRE_CALLBACK);
-               loaded = 1;
+       if (!s_info.add_pre_callback) {
+               s_info.add_pre_callback = dlsym(RTLD_DEFAULT, FUNC_WIDGET_PROVIDER_APP_ADD_PRE_CALLBACK);
+               if (!s_info.add_pre_callback) {
+                       return WIDGET_ERROR_NOT_SUPPORTED;
+               }
        }
 
-       if (!s_info.binder.app.del_pre_callback) {
-               return WIDGET_ERROR_NOT_SUPPORTED;
+       return s_info.add_pre_callback(type, cb, data);
+}
+
+PUBLIC int widget_del_pre_callback(widget_pre_callback_e type, widget_pre_callback_t cb, void *data)
+{
+       if (!s_info.del_pre_callback) {
+               s_info.del_pre_callback = dlsym(RTLD_DEFAULT, FUNC_WIDGET_PROVIDER_APP_DEL_PRE_CALLBACK);
+               if (!s_info.del_pre_callback) {
+                       return WIDGET_ERROR_NOT_SUPPORTED;
+               }
        }
 
-       return s_info.binder.app.del_pre_callback(type, cb, data);
+       return s_info.del_pre_callback(type, cb, data);
 }
 
 static int send_updated(const char *pkgname, const char *id, widget_buffer_h handle, int idx, int x, int y, int w, int h, int gbar, const char *descfile)