devilhorns pushed a commit to branch devs/devilhorns/wayland.

commit a9a2742ef4b78402c49f396ec073c2dd7b8991cf
Author: Chris Michael <[email protected]>
Date:   Fri Mar 8 12:43:03 2013 +0000

    Fix surface attach callback to use x/y now.
    Add a draw_done callback (from evas) so we can tell the wayland
    clients that their frame has been drawn.
    Start on event handling (focus_in, focus_out, etc).
    When we get the surface_attach callback, set the pending geometry.
    When we get the surface_damage callback, call the configure function
    if the surface is not mapped yet.
    Process damages after the surface has been mapped in the commit
    callback.
    
    Signed-off-by: Chris Michael <[email protected]>
---
 src/bin/e_comp_wl.c | 219 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 190 insertions(+), 29 deletions(-)

diff --git a/src/bin/e_comp_wl.c b/src/bin/e_comp_wl.c
index 402cee6..d264276 100644
--- a/src/bin/e_comp_wl.c
+++ b/src/bin/e_comp_wl.c
@@ -11,13 +11,14 @@ static void _e_comp_wl_cb_region_create(struct wl_client 
*client, struct wl_reso
 static void _e_comp_wl_cb_region_destroy(struct wl_resource *resource);
 
 static void _e_comp_wl_surface_cb_destroy(struct wl_client *client 
EINA_UNUSED, struct wl_resource *resource);
-static void _e_comp_wl_surface_cb_attach(struct wl_client *client EINA_UNUSED, 
struct wl_resource *resource, struct wl_resource *buffer, int x EINA_UNUSED, 
int y EINA_UNUSED);
+static void _e_comp_wl_surface_cb_attach(struct wl_client *client EINA_UNUSED, 
struct wl_resource *resource, struct wl_resource *buffer, int x, int y);
 static void _e_comp_wl_surface_cb_damage(struct wl_client *client EINA_UNUSED, 
struct wl_resource *resource, int x, int y, int w, int h);
 static void _e_comp_wl_surface_cb_frame(struct wl_client *client, struct 
wl_resource *resource, unsigned int callback);
 static void _e_comp_wl_surface_cb_opaque_region_set(struct wl_client *client 
EINA_UNUSED, struct wl_resource *resource, struct wl_resource *region);
 static void _e_comp_wl_surface_cb_input_region_set(struct wl_client *client 
EINA_UNUSED, struct wl_resource *resource, struct wl_resource *region);
 static void _e_comp_wl_surface_cb_commit(struct wl_client *client EINA_UNUSED, 
struct wl_resource *resource);
 static void _e_comp_wl_surface_cb_pending_buffer_destroy(struct wl_listener 
*listener, void *data EINA_UNUSED);
+static void _e_comp_wl_surface_cb_draw_done(void *data, Evas *evas 
EINA_UNUSED, void *event EINA_UNUSED);
 
 static void _e_comp_wl_region_cb_destroy(struct wl_client *client EINA_UNUSED, 
struct wl_resource *resource);
 static void _e_comp_wl_region_cb_add(struct wl_client *client EINA_UNUSED, 
struct wl_resource *resource, int x, int y, int w, int h);
@@ -27,6 +28,16 @@ static void _e_comp_wl_frame_cb_destroy(struct wl_resource 
*resource);
 
 static void _e_comp_wl_cb_init_job(void *data EINA_UNUSED);
 
+static Eina_Bool _e_comp_wl_cb_window_focus_in(void *data, int type 
EINA_UNUSED, void *event);
+static Eina_Bool _e_comp_wl_cb_window_focus_out(void *data, int type 
EINA_UNUSED, void *event);
+
+/* static Eina_Bool _e_comp_wl_cb_mouse_in(void *data EINA_UNUSED, int type 
EINA_UNUSED, void *event); */
+/* static Eina_Bool _e_comp_wl_cb_mouse_out(void *data EINA_UNUSED, int type 
EINA_UNUSED, void *event); */
+/* static Eina_Bool _e_comp_wl_cb_mouse_down(void *data EINA_UNUSED, int type 
EINA_UNUSED, void *event); */
+/* static Eina_Bool _e_comp_wl_cb_mouse_up(void *data EINA_UNUSED, int type 
EINA_UNUSED, void *event); */
+/* static Eina_Bool _e_comp_wl_cb_key_down(void *data EINA_UNUSED, int type 
EINA_UNUSED, void *event); */
+/* static Eina_Bool _e_comp_wl_cb_key_up(void *data EINA_UNUSED, int type 
EINA_UNUSED, void *event); */
+
 /* local wayland interfaces */
 static const struct wl_compositor_interface _e_wl_comp_interface = 
 {
@@ -55,6 +66,7 @@ static const struct wl_region_interface 
_e_wl_region_interface =
 
 /* local variables */
 static Ecore_Job *_init_job = NULL;
+static Eina_List *_hdlrs = NULL;
 
 /* external variables */
 E_Wayland_Compositor *_e_wl_comp;
@@ -117,9 +129,6 @@ e_comp_wl_init(void)
    if (wl_display_init_shm(_e_wl_comp->wl.display) < 0)
      ERR("Could not intiialize SHM !!!");
 
-   /* TODO: startup the wl_shell module so we have a shell available for 
-    * wayland clients */
-
    /* setup a job handler so we can load the wl_shell module after 
     * init has completed */
    _init_job = ecore_job_add(_e_comp_wl_cb_init_job, NULL);
@@ -135,6 +144,19 @@ e_comp_wl_init(void)
      ecore_main_fd_handler_add(fd, ECORE_FD_READ, 
                                _e_comp_wl_cb_fd_handle, NULL, NULL, NULL);
 
+   /* E_LIST_HANDLER_APPEND(_hdlrs, ECORE_X_EVENT_MOUSE_IN,  */
+   /*                       _e_comp_wl_cb_mouse_in, NULL); */
+   /* E_LIST_HANDLER_APPEND(_hdlrs, ECORE_X_EVENT_MOUSE_OUT,  */
+   /*                       _e_comp_wl_cb_mouse_out, NULL); */
+   /* E_LIST_HANDLER_APPEND(_hdlrs, ECORE_EVENT_MOUSE_BUTTON_DOWN,  */
+   /*                       _e_comp_wl_cb_mouse_down, NULL); */
+   /* E_LIST_HANDLER_APPEND(_hdlrs, ECORE_EVENT_MOUSE_BUTTON_UP,  */
+   /*                       _e_comp_wl_cb_mouse_up, NULL); */
+   /* E_LIST_HANDLER_APPEND(_hdlrs, ECORE_EVENT_KEY_DOWN,  */
+   /*                       _e_comp_wl_cb_key_down, NULL); */
+   /* E_LIST_HANDLER_APPEND(_hdlrs, ECORE_EVENT_KEY_UP,  */
+   /*                       _e_comp_wl_cb_key_up, NULL); */
+
    return EINA_TRUE;
 
 err:
@@ -157,9 +179,9 @@ e_comp_wl_shutdown(void)
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
 
-   /* disable wl_shell module */
-   if ((mod = e_module_find("wl_shell")))
-     e_module_disable(mod);
+   /* E_FREE_LIST(_hdlrs, ecore_event_handler_del); */
+
+   wl_signal_emit(&_e_wl_comp->wl.signals.destroy, _e_wl_comp);
 
    if (_e_wl_comp->fd_handler)
      ecore_main_fd_handler_del(_e_wl_comp->fd_handler);
@@ -169,6 +191,10 @@ e_comp_wl_shutdown(void)
 
    /* free the allocated structure */
    free(_e_wl_comp);
+
+   /* disable wl_shell module */
+   if ((mod = e_module_find("wl_shell")))
+     e_module_disable(mod);
 }
 
 /* local functions */
@@ -221,20 +247,29 @@ _e_comp_wl_cb_surface_create(struct wl_client *client, 
struct wl_resource *resou
    ews->pending.buffer_destroy.notify = 
      _e_comp_wl_surface_cb_pending_buffer_destroy;
 
-   ews->width = 700;
-   ews->height = 400;
+   /* ews->width = 700; */
+   /* ews->height = 400; */
+
+   E_LIST_HANDLER_APPEND(ews->handlers, E_EVENT_BORDER_FOCUS_IN, 
+                         _e_comp_wl_cb_window_focus_in, ews);
+   E_LIST_HANDLER_APPEND(ews->handlers, E_EVENT_BORDER_FOCUS_OUT, 
+                         _e_comp_wl_cb_window_focus_out, ews);
 
    ews->win = e_win_new(e_container_current_get(e_manager_current_get()));
    e_win_borderless_set(ews->win, EINA_TRUE);
    e_win_shaped_set(ews->win, EINA_TRUE);
-   e_win_move_resize(ews->win, 0, 0, ews->width, ews->height);
-   e_win_show(ews->win);
+   /* e_win_move_resize(ews->win, 0, 0, ews->width, ews->height); */
+   /* e_object_data_set(E_OBJECT(ews->win), ews); */
 
    ews->img = evas_object_image_filled_add(e_win_evas_get(ews->win));
    evas_object_move(ews->img, 0, 0);
-   evas_object_resize(ews->img, ews->width, ews->height);
+   /* evas_object_resize(ews->img, ews->width, ews->height); */
    evas_object_show(ews->img);
 
+   evas_event_callback_add(e_win_evas_get(ews->win), 
+                           EVAS_CALLBACK_RENDER_FLUSH_POST, 
+                           _e_comp_wl_surface_cb_draw_done, ews);
+
    ews->wl.surface.resource.destroy = _e_comp_wl_cb_surface_destroy;
    ews->wl.surface.resource.object.id = id;
    ews->wl.surface.resource.object.interface = &wl_surface_interface;
@@ -255,6 +290,8 @@ _e_comp_wl_cb_surface_destroy(struct wl_resource *resource)
 
    ews = container_of(resource, E_Wayland_Surface, wl.surface.resource);
 
+   E_FREE_LIST(ews->handlers, ecore_event_handler_del);
+
    /* loop surface pending frame callbacks and destroy them */
    wl_list_for_each_safe(cb, next, &ews->pending.frames, wl.link)
      wl_resource_destroy(&cb->wl.resource);
@@ -264,7 +301,14 @@ _e_comp_wl_cb_surface_destroy(struct wl_resource *resource)
 
    /* actually destroy the surface */
    if (ews->img) evas_object_del(ews->img);
-   if (ews->win) e_object_del(E_OBJECT(ews->win));
+   if (ews->win) 
+     {
+        evas_event_callback_del(e_win_evas_get(ews->win), 
+                                EVAS_CALLBACK_RENDER_FLUSH_POST, 
+                                _e_comp_wl_surface_cb_draw_done);
+
+        e_object_del(E_OBJECT(ews->win));
+     }
 
    /* free any input region */
 //   if (ews->input) wl_resource_destroy(&ews->input->wl.resource);
@@ -326,7 +370,7 @@ _e_comp_wl_surface_cb_destroy(struct wl_client *client 
EINA_UNUSED, struct wl_re
 }
 
 static void 
-_e_comp_wl_surface_cb_attach(struct wl_client *client EINA_UNUSED, struct 
wl_resource *resource, struct wl_resource *buffer, int x EINA_UNUSED, int y 
EINA_UNUSED)
+_e_comp_wl_surface_cb_attach(struct wl_client *client EINA_UNUSED, struct 
wl_resource *resource, struct wl_resource *buffer, int x, int y)
 {
    E_Wayland_Surface *ews = NULL;
    struct wl_buffer *buff = NULL;
@@ -340,6 +384,11 @@ _e_comp_wl_surface_cb_attach(struct wl_client *client 
EINA_UNUSED, struct wl_res
    if (ews->pending.buffer)
      wl_list_remove(&ews->pending.buffer_destroy.link);
 
+   if ((buff) && (ews->pending.buffer != buff))
+     ews->pending.new_buffer = EINA_TRUE;
+
+   ews->pending.x = x;
+   ews->pending.y = y;
    ews->pending.buffer = buff;
 
    if (buff)
@@ -363,7 +412,13 @@ _e_comp_wl_surface_cb_damage(struct wl_client *client 
EINA_UNUSED, struct wl_res
 
    if (!(ews = resource->data)) return;
 
-   if (!ews->damages) ews->damages = eina_tiler_new(ews->width, ews->height);
+   if (!ews->damages) 
+     {
+        if ((ews->geometry.w != 0) && (ews->geometry.h != 0))
+          ews->damages = eina_tiler_new(ews->geometry.w, ews->geometry.h);
+     }
+
+   if (!ews->damages) return;
 
    if (!(r = eina_rectangle_new(x, y, w, h))) return;
 
@@ -461,21 +516,13 @@ _e_comp_wl_surface_cb_commit(struct wl_client *client 
EINA_UNUSED, struct wl_res
         return;
      }
 
-   if (ews->damages)
-     {
-        Eina_Iterator *itr;
-        Eina_Rectangle *r;
-
-        itr = eina_tiler_iterator_new(ews->damages);
-        EINA_ITERATOR_FOREACH(itr, r)
-          evas_object_image_data_update_add(ews->img, r->x, r->y, 
-                                            r->w, r->h);
-        /* _e_comp_win_damage(ews->win->border->cw,  */
-        /*                    r->x, r->y, r->w, r->h, EINA_FALSE); */
-        eina_iterator_free(itr);
+   if ((ews->configure) && (ews->pending.new_buffer))
+     ews->configure(ews, ews->pending.x, ews->pending.y, 
+                    ews->pending.buffer->width, ews->pending.buffer->height);
 
-        eina_tiler_clear(ews->damages);
-     }
+   ews->pending.x = 0;
+   ews->pending.y = 0;
+   ews->pending.new_buffer = EINA_FALSE;
 
    if (ews->pending.buffer)
      {
@@ -504,6 +551,22 @@ _e_comp_wl_surface_cb_commit(struct wl_client *client 
EINA_UNUSED, struct wl_res
         evas_object_image_data_set(ews->img, data);
      }
 
+   if (ews->damages)
+     {
+        Eina_Iterator *itr;
+        Eina_Rectangle *r;
+
+        itr = eina_tiler_iterator_new(ews->damages);
+
+        EINA_ITERATOR_FOREACH(itr, r)
+          evas_object_image_data_update_add(ews->img, r->x, r->y, 
+                                            r->w, r->h);
+
+        eina_iterator_free(itr);
+
+        eina_tiler_clear(ews->damages);
+     }
+
    wl_list_insert_list(&ews->wl.frames, &ews->pending.frames);
    wl_list_init(&ews->pending.frames);
 }
@@ -521,6 +584,30 @@ _e_comp_wl_surface_cb_pending_buffer_destroy(struct 
wl_listener *listener, void
 }
 
 static void 
+_e_comp_wl_surface_cb_draw_done(void *data, Evas *evas EINA_UNUSED, void 
*event EINA_UNUSED)
+{
+   E_Wayland_Surface *ews = NULL;
+   E_Wayland_Frame_Cb *cb = NULL, *ncb;
+   struct timeval tm;
+   unsigned int secs = 0;
+
+   LOGFN(__FILE__, __LINE__, __FUNCTION__);
+
+   if (!(ews = data)) return;
+
+   gettimeofday(&tm, NULL);
+   secs = (tm.tv_sec * 1000 + tm.tv_usec / 1000);
+
+   /* NB: Hmmm, do we need an event_loop_dispatch here ?? */
+
+   wl_list_for_each_safe(cb, ncb, &ews->wl.frames, wl.link)
+     {
+        wl_callback_send_done(&cb->wl.resource, secs);
+        wl_resource_destroy(&cb->wl.resource);
+     }
+}
+
+static void 
 _e_comp_wl_region_cb_destroy(struct wl_client *client EINA_UNUSED, struct 
wl_resource *resource)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
@@ -586,3 +673,77 @@ _e_comp_wl_cb_init_job(void *data EINA_UNUSED)
    if (_init_job) ecore_job_del(_init_job);
    _init_job = NULL;
 }
+
+static Eina_Bool 
+_e_comp_wl_cb_window_focus_in(void *data, int type EINA_UNUSED, void *event)
+{
+   E_Wayland_Surface *ews = NULL;
+   E_Event_Border_Focus_In *ev;
+
+   if (!(ews = data)) return ECORE_CALLBACK_PASS_ON;
+   if (!(ev = event)) return ECORE_CALLBACK_PASS_ON;
+
+   if ((!ews->win) || (!ews->win->border)) return ECORE_CALLBACK_PASS_ON;
+   if (ev->border != ews->win->border) return ECORE_CALLBACK_PASS_ON;
+
+   /* TODO */
+
+   printf("Focus This Wayland Surface !!\n");
+
+   return ECORE_CALLBACK_PASS_ON;
+}
+
+static Eina_Bool 
+_e_comp_wl_cb_window_focus_out(void *data, int type EINA_UNUSED, void *event)
+{
+   E_Wayland_Surface *ews = NULL;
+   E_Event_Border_Focus_Out *ev;
+
+   if (!(ews = data)) return ECORE_CALLBACK_PASS_ON;
+   if (!(ev = event)) return ECORE_CALLBACK_PASS_ON;
+
+   if ((!ews->win) || (!ews->win->border)) return ECORE_CALLBACK_PASS_ON;
+   if (ev->border != ews->win->border) return ECORE_CALLBACK_PASS_ON;
+
+   /* TODO */
+
+   printf("Unfocus This Wayland Surface !!\n");
+
+   return ECORE_CALLBACK_PASS_ON;
+}
+
+static Eina_Bool 
+_e_comp_wl_cb_mouse_in(void *data EINA_UNUSED, int type EINA_UNUSED, void 
*event)
+{
+   return ECORE_CALLBACK_PASS_ON;
+}
+
+static Eina_Bool 
+_e_comp_wl_cb_mouse_out(void *data EINA_UNUSED, int type EINA_UNUSED, void 
*event)
+{
+   return ECORE_CALLBACK_PASS_ON;
+}
+
+static Eina_Bool 
+_e_comp_wl_cb_mouse_down(void *data EINA_UNUSED, int type EINA_UNUSED, void 
*event)
+{
+   return ECORE_CALLBACK_PASS_ON;
+}
+
+static Eina_Bool 
+_e_comp_wl_cb_mouse_up(void *data EINA_UNUSED, int type EINA_UNUSED, void 
*event)
+{
+   return ECORE_CALLBACK_PASS_ON;
+}
+
+static Eina_Bool 
+_e_comp_wl_cb_key_down(void *data EINA_UNUSED, int type EINA_UNUSED, void 
*event)
+{
+   return ECORE_CALLBACK_PASS_ON;
+}
+
+static Eina_Bool 
+_e_comp_wl_cb_key_up(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
+{
+   return ECORE_CALLBACK_PASS_ON;
+}

-- 

------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report. 
http://p.sf.net/sfu/symantec-dev2dev

Reply via email to