>From cca56bd4be920957f0320bf6485c8814ee96a4dc Mon Sep 17 00:00:00 2001
From: Erwan Tulou <erwan10@videolan.org>
Date: Sun, 13 Jun 2010 15:42:28 +0200
Subject: [PATCH] vout_window_t: extend api

---
 include/vlc_vout_window.h |   64 +++++++++++++++++++++++++++++++++++++++++++-
 src/video_output/window.c |   54 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 115 insertions(+), 3 deletions(-)

diff --git a/include/vlc_vout_window.h b/include/vlc_vout_window.h
index 84d78ee..ecd1dcf 100644
--- a/include/vlc_vout_window.h
+++ b/include/vlc_vout_window.h
@@ -35,6 +35,8 @@
 /* */
 typedef struct vout_window_t vout_window_t;
 typedef struct vout_window_sys_t vout_window_sys_t;
+typedef struct vout_window_owner_t vout_window_owner_t;
+typedef struct vout_window_owner_sys_t vout_window_owner_sys_t;
 
 
 /**
@@ -54,9 +56,19 @@ enum {
     VOUT_WINDOW_SET_FULLSCREEN, /* int b_fullscreen */
 };
 
+/**
+ * Event from vout_window_t
+ */
+enum {
+    VOUT_WINDOW_EVENT_SETUP,     /* */
+    VOUT_WINDOW_EVENT_CLEANUP,   /* */
+    VOUT_WINDOW_EVENT_KEY,       /* */
+};
+
 typedef struct {
     /* If true, a standalone window is requested */
     bool is_standalone;
+    bool use_desktop;
 
     /* Window handle type */
     int type;
@@ -69,12 +81,30 @@ typedef struct {
     unsigned width;
     unsigned height;
 
+    /* fullscreen hint */
+    bool fullscreen;
+
+    /* setup function (to be called by the module) */
+    void (*setup)( void* data, void* hwnd );
+    void (*cleanup)( void* data );
+    void* data;
+
 } vout_window_cfg_t;
 
+
 /**
- * FIXME do we need an event system in the window too ?
- * or the window user will take care of it ?
+ * Vout owner structures
  */
+struct vout_window_owner_t {
+    /* Private place holder for the vout_window_t creator
+     */
+    vout_window_owner_sys_t *sys;
+
+    /* */
+    void            (*event)(vout_window_t *, int, va_list);
+};
+
+
 struct vout_window_t {
     VLC_COMMON_MEMBERS
 
@@ -108,6 +138,12 @@ struct vout_window_t {
      * A module is free to use it as it wishes.
      */
     vout_window_sys_t *sys;
+
+    /* Reserved for the vout_window_t owner.
+     *
+     * It must not be overwritten nor used directly by a module.
+     */
+    vout_window_owner_t owner;
 };
 
 /** 
@@ -158,5 +194,29 @@ static inline int vout_window_SetFullScreen(vout_window_t *window, bool full)
     return vout_window_Control(window, VOUT_WINDOW_SET_FULLSCREEN, full);
 }
 
+
+static inline void vout_window_SendEvent(vout_window_t *window, int query, ...)
+{
+    va_list args;
+    va_start(args, query);
+    window->owner.event(window, query, args);
+    va_end(args);
+}
+
+static inline void vout_window_SendEventSetup(vout_window_t *vd)
+{
+    vout_window_SendEvent(vd, VOUT_WINDOW_EVENT_SETUP );
+}
+
+static inline void vout_window_SendEventCleanup(vout_window_t *vd)
+{
+    vout_window_SendEvent(vd, VOUT_WINDOW_EVENT_CLEANUP );
+}
+
+static inline void vout_window_SendEventKey(vout_window_t *window, int key)
+{
+    vout_window_SendEvent(window, VOUT_WINDOW_EVENT_KEY, key);
+}
+
 #endif /* VLC_VOUT_WINDOW_H */
 
diff --git a/src/video_output/window.c b/src/video_output/window.c
index a8ef797..81f46c5 100644
--- a/src/video_output/window.c
+++ b/src/video_output/window.c
@@ -41,6 +41,13 @@ typedef struct
     vlc_inhibit_t *inhibit;
 } window_t;
 
+struct vout_window_owner_sys_t
+{
+    vout_window_cfg_t cfg;
+};
+
+static void VoutWindowEvent(vout_window_t *window, int event, va_list args);
+
 vout_window_t *vout_window_New(vlc_object_t *obj,
                                const char *module,
                                const vout_window_cfg_t *cfg)
@@ -49,11 +56,23 @@ vout_window_t *vout_window_New(vlc_object_t *obj,
     window_t *w = vlc_custom_create(obj, sizeof(*w), VLC_OBJECT_GENERIC, name);
     vout_window_t *window = &w->wnd;
 
-    window->cfg = cfg;
+    vout_window_cfg_t* cfg0 = calloc( 1, sizeof( *cfg ) );
+    *cfg0 = *cfg;
+
+    window->cfg = cfg0;
+
     memset(&window->handle, 0, sizeof(window->handle));
     window->control = NULL;
     window->sys = NULL;
 
+    vout_window_owner_sys_t* osys = calloc( 1, sizeof( *osys ) );
+    if( !osys )
+        abort();
+
+    window->owner.event = VoutWindowEvent;
+    window->owner.sys = osys;
+    osys->cfg = *cfg;
+
     vlc_object_attach(window, obj);
 
     const char *type;
@@ -103,6 +122,8 @@ void vout_window_Delete(vout_window_t *window)
 
     module_unneed(window, w->module);
 
+    free( window->cfg );
+
     vlc_object_release(window);
 }
 
@@ -116,3 +137,34 @@ int vout_window_Control(vout_window_t *window, int query, ...)
     return ret;
 }
 
+
+static void VoutWindowEvent(vout_window_t *window, int event, va_list args)
+{
+    vout_window_owner_sys_t *osys = window->owner.sys;
+
+    switch (event) {
+    case VOUT_WINDOW_EVENT_SETUP: {
+        msg_Dbg(window, "VoutWindowEvent 'Setup'");
+        if( osys->cfg.setup )
+            osys->cfg.setup( osys->cfg.data, window->handle.hwnd );
+        break;
+    }
+    case VOUT_WINDOW_EVENT_CLEANUP: {
+        msg_Dbg(window, "VoutWindowEvent 'cleanup'");
+        if( osys->cfg.cleanup )
+            osys->cfg.cleanup( osys->cfg.data );
+        break;
+    }
+    case VOUT_WINDOW_EVENT_KEY: {
+        const int key = (int)va_arg(args, int);
+        msg_Dbg(window, "VoutWindowEvent 'key' 0x%2.2x", key);
+        // vout_SendEventKey(osys->vout, key);
+        // vout_display_SendEventKey(osys->vout, key);
+        break;
+    }
+    default:
+        msg_Err(window, "VoutWindowEvent received event %d", event);
+        /* TODO add an assert when all event are handled */
+        break;
+    }
+}
-- 
1.5.6.5


