]> git.sesse.net Git - vlc/blobdiff - modules/video_output/msw/events.c
Revert "vout_window_t: simplify via anynomous union"
[vlc] / modules / video_output / msw / events.c
index 6702835b80cb65441ebd87f33efc157cf1255916..81822418e04de633d51890d125d7c0fcf7895934 100644 (file)
 # include "config.h"
 #endif
 
-#include <errno.h>                                                 /* ENOMEM */
-#include <ctype.h>                                              /* tolower() */
-
-#ifndef _WIN32_WINNT
-#   define _WIN32_WINNT 0x0500
-#endif
-
 #include <vlc_common.h>
-#include <vlc_interface.h>
-#include <vlc_playlist.h>
-#include <vlc_vout.h>
+#include <vlc_vout_display.h>
 #include <vlc_vout_window.h>
 
 #include <windows.h>
-#include <tchar.h>
 #include <windowsx.h>
 #include <shellapi.h>
 
+#include <ctype.h>
+
 #ifdef MODULE_NAME_IS_directx
 #include <ddraw.h>
 #endif
 #include <d3d9.h>
 #endif
 #ifdef MODULE_NAME_IS_glwin32
-#include <GL/gl.h>
+#include "../opengl.h"
 #endif
 
 #include <vlc_keys.h>
-#include "vout.h"
+#include "common.h"
 
 #ifdef UNDER_CE
 #include <aygshell.h>
     //WINSHELLAPI BOOL WINAPI SHFullScreen(HWND hwndRequester, DWORD dwState);
+
+UINT GetMenuState(HMENU hMenu, UINT id, UINT flags)
+{
+    MENUITEMINFO info;
+    memset(&info, 0, sizeof(info));
+    info.cbSize = sizeof(info);
+    info.fMask = MIIM_STATE;
+    if (!GetMenuItemInfo(hMenu, id, (flags & MF_BYPOSITION) != 0, &info))
+        return -1;
+    /* XXX Submenu handling is missing... */
+    return info.fState;
+}
 #endif
 
 /*#if defined(UNDER_CE) && !defined(__PLUGIN__) --FIXME*/
     BOOL SHFullScreen(HWND hwndRequester, DWORD dwState);
 #endif*/
 
-
 /*****************************************************************************
  * Local prototypes.
  *****************************************************************************/
-static int  DirectXCreateWindow( vout_thread_t *p_vout );
-static void DirectXCloseWindow ( vout_thread_t *p_vout );
-static long FAR PASCAL DirectXEventProc( HWND, UINT, WPARAM, LPARAM );
+#define WM_VLC_HIDE_MOUSE   (WM_APP + 0)
+#define WM_VLC_SHOW_MOUSE   (WM_APP + 1)
+#define WM_VLC_CHANGE_TEXT  (WM_APP + 2)
 
-static void DirectXPopupMenu( event_thread_t *p_event, bool b_open )
+struct event_thread_t
 {
-    vlc_value_t val;
-    val.b_bool = b_open;
-    var_Set( p_event->p_vout->p_libvlc, "intf-popupmenu", val );
-}
+    vout_display_t *vd;
+
+    /* */
+    vlc_thread_t thread;
+    vlc_mutex_t  lock;
+    vlc_cond_t   wait;
+    bool         b_ready;
+    bool         b_done;
+    bool         b_error;
+
+    /* */
+    bool use_desktop;
+    bool use_overlay;
+
+    /* Mouse */
+    volatile bool    b_cursor_hidden;
+    volatile mtime_t i_lastmoved;
+    mtime_t          i_mouse_hide_timeout;
+
+    /* Title */
+    char *psz_title;
+
+    int               i_window_style;
+    vout_window_cfg_t wnd_cfg;
+
+    /* */
+    vout_window_t *parent_window;
+    HWND hparent;
+    HWND hwnd;
+    HWND hvideownd;
+    HWND hfswnd;
+    video_format_t       source;
+    vout_display_place_t place;
+
+    bool has_moved;
+};
+
+static int  DirectXCreateWindow( event_thread_t * );
+static void DirectXCloseWindow ( event_thread_t * );
+static long FAR PASCAL DirectXEventProc( HWND, UINT, WPARAM, LPARAM );
 
 static int DirectXConvertKey( int i_key );
 
@@ -101,11 +140,9 @@ static int DirectXConvertKey( int i_key );
 static void *EventThread( void *p_this )
 {
     event_thread_t *p_event = (event_thread_t *)p_this;
-    vout_thread_t *p_vout = p_event->p_vout;
+    vout_display_t *vd = p_event->vd;
     MSG msg;
     POINT old_mouse_pos = {0,0}, mouse_pos;
-    vlc_value_t val;
-    unsigned int i_width, i_height, i_x, i_y;
     HMODULE hkernel32;
     int canc = vlc_savecancel ();
 
@@ -113,7 +150,7 @@ static void *EventThread( void *p_this )
     /* Create a window for the video */
     /* Creating a window under Windows also initializes the thread's event
      * message queue */
-    if( DirectXCreateWindow( p_event->p_vout ) )
+    if( DirectXCreateWindow( p_event ) )
         p_event->b_error = true;
 
     p_event->b_ready = true;
@@ -141,7 +178,7 @@ static void *EventThread( void *p_this )
             /* Prevent monitor from powering off */
             OurSetThreadExecutionState( ES_DISPLAY_REQUIRED | ES_CONTINUOUS );
         else
-            msg_Dbg( p_vout, "no support for SetThreadExecutionState()" );
+            msg_Dbg( vd, "no support for SetThreadExecutionState()" );
     }
 #endif
 
@@ -149,6 +186,9 @@ static void *EventThread( void *p_this )
     /* GetMessage will sleep if there's no message in the queue */
     for( ;; )
     {
+        vout_display_place_t place;
+        video_format_t       source;
+
         if( !GetMessage( &msg, 0, 0, 0 ) )
         {
             vlc_mutex_lock( &p_event->lock );
@@ -167,35 +207,30 @@ static void *EventThread( void *p_this )
         /* */
         switch( msg.message )
         {
-
         case WM_MOUSEMOVE:
-            vout_PlacePicture( p_event->p_vout,
-                               p_event->p_vout->p_sys->i_window_width,
-                               p_event->p_vout->p_sys->i_window_height,
-                               &i_x, &i_y, &i_width, &i_height );
-
-            if( msg.hwnd == p_event->p_vout->p_sys->hvideownd )
-            {
-                /* Child window */
-                i_x = i_y = 0;
-            }
+            vlc_mutex_lock( &p_event->lock );
+            place  = p_event->place;
+            source = p_event->source;
+            vlc_mutex_unlock( &p_event->lock );
 
-            if( i_width && i_height )
+            if( place.width > 0 && place.height > 0 )
             {
-                val.i_int = ( GET_X_LPARAM(msg.lParam) - i_x ) *
-                    p_event->p_vout->fmt_in.i_visible_width / i_width +
-                    p_event->p_vout->fmt_in.i_x_offset;
-                var_Set( p_event->p_vout, "mouse-x", val );
-                val.i_int = ( GET_Y_LPARAM(msg.lParam) - i_y ) *
-                    p_event->p_vout->fmt_in.i_visible_height / i_height +
-                    p_event->p_vout->fmt_in.i_y_offset;
-                var_Set( p_event->p_vout, "mouse-y", val );
-
-                var_SetBool( p_event->p_vout, "mouse-moved", true );
+                if( msg.hwnd == p_event->hvideownd )
+                {
+                    /* Child window */
+                    place.x = 0;
+                    place.y = 0;
+                }
+                const int x = source.i_x_offset +
+                    (int64_t)(GET_X_LPARAM(msg.lParam) - place.x) * source.i_width  / place.width;
+                const int y = source.i_y_offset +
+                    (int64_t)(GET_Y_LPARAM(msg.lParam) - place.y) * source.i_height / place.height;
+                vout_display_SendEventMouseMoved(vd, x, y);
             }
-
+            /* Fall through */
         case WM_NCMOUSEMOVE:
             GetCursorPos( &mouse_pos );
+            /* FIXME, why this >2 limits ? */
             if( (abs(mouse_pos.x - old_mouse_pos.x) > 2 ||
                 (abs(mouse_pos.y - old_mouse_pos.y)) > 2 ) )
             {
@@ -204,176 +239,140 @@ static void *EventThread( void *p_this )
 
                 if( p_event->b_cursor_hidden )
                 {
-                    p_event->b_cursor_hidden = 0;
+                    p_event->b_cursor_hidden = false;
                     ShowCursor( TRUE );
                 }
             }
             break;
 
         case WM_VLC_HIDE_MOUSE:
-            if( p_event->b_cursor_hidden ) break;
+            if( p_event->b_cursor_hidden )
+                break;
             p_event->b_cursor_hidden = true;
             GetCursorPos( &old_mouse_pos );
             ShowCursor( FALSE );
             break;
 
         case WM_VLC_SHOW_MOUSE:
-            if( !p_event->b_cursor_hidden ) break;
+            if( !p_event->b_cursor_hidden )
+                break;
             p_event->b_cursor_hidden = false;
             GetCursorPos( &old_mouse_pos );
             ShowCursor( TRUE );
             break;
 
         case WM_LBUTTONDOWN:
-            var_Get( p_event->p_vout, "mouse-button-down", &val );
-            val.i_int |= 1;
-            var_Set( p_event->p_vout, "mouse-button-down", val );
-            DirectXPopupMenu( p_event, false );
+            vout_display_SendEventMousePressed(vd, MOUSE_BUTTON_LEFT);
             break;
-
         case WM_LBUTTONUP:
-            var_Get( p_event->p_vout, "mouse-button-down", &val );
-            val.i_int &= ~1;
-            var_Set( p_event->p_vout, "mouse-button-down", val );
-
-            var_SetBool( p_event->p_vout, "mouse-clicked", true );
+            vout_display_SendEventMouseReleased(vd, MOUSE_BUTTON_LEFT);
             break;
-
         case WM_LBUTTONDBLCLK:
-            p_event->p_vout->p_sys->i_changes |= VOUT_FULLSCREEN_CHANGE;
+            vout_display_SendEventMouseDoubleClick(vd);
             break;
 
         case WM_MBUTTONDOWN:
-            var_Get( p_event->p_vout, "mouse-button-down", &val );
-            val.i_int |= 2;
-            var_Set( p_event->p_vout, "mouse-button-down", val );
-            DirectXPopupMenu( p_event, false );
+            vout_display_SendEventMousePressed(vd, MOUSE_BUTTON_CENTER);
             break;
-
         case WM_MBUTTONUP:
-            var_Get( p_event->p_vout, "mouse-button-down", &val );
-            val.i_int &= ~2;
-            var_Set( p_event->p_vout, "mouse-button-down", val );
+            vout_display_SendEventMouseReleased(vd, MOUSE_BUTTON_CENTER);
             break;
 
         case WM_RBUTTONDOWN:
-            var_Get( p_event->p_vout, "mouse-button-down", &val );
-            val.i_int |= 4;
-            var_Set( p_event->p_vout, "mouse-button-down", val );
-            DirectXPopupMenu( p_event, false );
+            vout_display_SendEventMousePressed(vd, MOUSE_BUTTON_RIGHT);
             break;
-
         case WM_RBUTTONUP:
-            var_Get( p_event->p_vout, "mouse-button-down", &val );
-            val.i_int &= ~4;
-            var_Set( p_event->p_vout, "mouse-button-down", val );
-            DirectXPopupMenu( p_event, true );
+            vout_display_SendEventMouseReleased(vd, MOUSE_BUTTON_RIGHT);
             break;
 
         case WM_KEYDOWN:
         case WM_SYSKEYDOWN:
+        {
             /* The key events are first processed here and not translated
              * into WM_CHAR events because we need to know the status of the
              * modifier keys. */
-            val.i_int = DirectXConvertKey( msg.wParam );
-            if( !val.i_int )
+            int i_key = DirectXConvertKey( msg.wParam );
+            if( !i_key )
             {
                 /* This appears to be a "normal" (ascii) key */
-                val.i_int = tolower( MapVirtualKey( msg.wParam, 2 ) );
+                i_key = tolower( MapVirtualKey( msg.wParam, 2 ) );
             }
 
-            if( val.i_int )
+            if( i_key )
             {
                 if( GetKeyState(VK_CONTROL) & 0x8000 )
                 {
-                    val.i_int |= KEY_MODIFIER_CTRL;
+                    i_key |= KEY_MODIFIER_CTRL;
                 }
                 if( GetKeyState(VK_SHIFT) & 0x8000 )
                 {
-                    val.i_int |= KEY_MODIFIER_SHIFT;
+                    i_key |= KEY_MODIFIER_SHIFT;
                 }
                 if( GetKeyState(VK_MENU) & 0x8000 )
                 {
-                    val.i_int |= KEY_MODIFIER_ALT;
+                    i_key |= KEY_MODIFIER_ALT;
                 }
 
-                var_Set( p_vout->p_libvlc, "key-pressed", val );
+                vout_display_SendEventKey(vd, i_key);
             }
             break;
+        }
 
         case WM_MOUSEWHEEL:
+        {
+            int i_key;
             if( GET_WHEEL_DELTA_WPARAM( msg.wParam ) > 0 )
             {
-                val.i_int = KEY_MOUSEWHEELUP;
+                i_key = KEY_MOUSEWHEELUP;
             }
             else
             {
-                val.i_int = KEY_MOUSEWHEELDOWN;
+                i_key = KEY_MOUSEWHEELDOWN;
             }
-            if( val.i_int )
+            if( i_key )
             {
                 if( GetKeyState(VK_CONTROL) & 0x8000 )
                 {
-                    val.i_int |= KEY_MODIFIER_CTRL;
+                    i_key |= KEY_MODIFIER_CTRL;
                 }
                 if( GetKeyState(VK_SHIFT) & 0x8000 )
                 {
-                    val.i_int |= KEY_MODIFIER_SHIFT;
+                    i_key |= KEY_MODIFIER_SHIFT;
                 }
                 if( GetKeyState(VK_MENU) & 0x8000 )
                 {
-                    val.i_int |= KEY_MODIFIER_ALT;
+                    i_key |= KEY_MODIFIER_ALT;
                 }
-
-                var_Set( p_vout->p_libvlc, "key-pressed", val );
+                vout_display_SendEventKey(vd, i_key);
             }
             break;
+        }
 
         case WM_VLC_CHANGE_TEXT:
-            var_Get( p_vout, "video-title", &val );
-            if( !val.psz_string || !*val.psz_string ) /* Default video title */
-            {
-                free( val.psz_string );
-
-#ifdef MODULE_NAME_IS_wingdi
-                val.psz_string = strdup( VOUT_TITLE " (WinGDI output)" );
-#endif
-#ifdef MODULE_NAME_IS_wingapi
-                val.psz_string = strdup( VOUT_TITLE " (WinGAPI output)" );
-#endif
-#ifdef MODULE_NAME_IS_glwin32
-                val.psz_string = strdup( VOUT_TITLE " (OpenGL output)" );
-#endif
-#ifdef MODULE_NAME_IS_direct3d
-                val.psz_string = strdup( VOUT_TITLE " (Direct3D output)" );
-#endif
-#ifdef MODULE_NAME_IS_directx
-                if( p_event->p_vout->p_sys->b_using_overlay ) val.psz_string =
-                    strdup( VOUT_TITLE " (hardware YUV overlay DirectX output)" );
-                else if( p_event->p_vout->p_sys->b_hw_yuv ) val.psz_string =
-                    strdup( VOUT_TITLE " (hardware YUV DirectX output)" );
-                else val.psz_string =
-                    strdup( VOUT_TITLE " (software RGB DirectX output)" );
-#endif
-            }
-
+        {
+            vlc_mutex_lock( &p_event->lock );
+            wchar_t *pwz_title = NULL;
+            if( p_event->psz_title )
             {
-                wchar_t *psz_title = malloc( strlen(val.psz_string) * 2 + 2 );
-                if( psz_title )
+                const size_t i_length = strlen(p_event->psz_title);
+                pwz_title = malloc( 2 * (i_length + 1) );
+                if( pwz_title )
                 {
-                    mbstowcs( psz_title, val.psz_string, strlen(val.psz_string)*2);
-                    psz_title[strlen(val.psz_string)] = 0;
-                    free( val.psz_string ); val.psz_string = (char *)psz_title;
+                    mbstowcs( pwz_title, p_event->psz_title, 2 * i_length );
+                    pwz_title[i_length] = 0;
                 }
             }
+            vlc_mutex_unlock( &p_event->lock );
 
-            SetWindowText( p_event->p_vout->p_sys->hwnd,
-                           (LPCTSTR)val.psz_string );
-            if( p_event->p_vout->p_sys->hfswnd )
-                SetWindowText( p_event->p_vout->p_sys->hfswnd,
-                               (LPCTSTR)val.psz_string );
-            free( val.psz_string );
+            if( pwz_title )
+            {
+                SetWindowTextW( p_event->hwnd, (LPCTSTR)pwz_title );
+                if( p_event->hfswnd )
+                    SetWindowTextW( p_event->hfswnd, (LPCTSTR)pwz_title );
+                free( pwz_title );
+            }
             break;
+        }
 
         default:
             /* Messages we don't handle directly are dispatched to the
@@ -387,15 +386,15 @@ static void *EventThread( void *p_this )
     } /* End Main loop */
 
     /* Check for WM_QUIT if we created the window */
-    if( !p_event->p_vout->p_sys->hparent && msg.message == WM_QUIT )
+    if( !p_event->hparent && msg.message == WM_QUIT )
     {
-        msg_Warn( p_vout, "WM_QUIT... should not happen!!" );
-        p_event->p_vout->p_sys->hwnd = NULL; /* Window already destroyed */
+        msg_Warn( vd, "WM_QUIT... should not happen!!" );
+        p_event->hwnd = NULL; /* Window already destroyed */
     }
 
-    msg_Dbg( p_vout, "DirectXEventThread terminating" );
+    msg_Dbg( vd, "DirectXEventThread terminating" );
 
-    DirectXCloseWindow( p_event->p_vout );
+    DirectXCloseWindow( p_event );
     vlc_restorecancel(canc);
     return NULL;
 }
@@ -410,37 +409,32 @@ static void *EventThread( void *p_this )
  * the video will be displayed. This window will also allow us to capture the
  * events.
  *****************************************************************************/
-static int DirectXCreateWindow( vout_thread_t *p_vout )
+static int DirectXCreateWindow( event_thread_t *p_event )
 {
+    vout_display_t *vd = p_event->vd;
     HINSTANCE  hInstance;
     HMENU      hMenu;
     RECT       rect_window;
     WNDCLASS   wc;                            /* window class components */
-    HICON      vlc_icon = NULL;
+    HICON      vlc_icon;
     char       vlc_path[MAX_PATH+1];
     int        i_style, i_stylex;
 
-    msg_Dbg( p_vout, "DirectXCreateWindow" );
+    msg_Dbg( vd, "DirectXCreateWindow" );
 
     /* Get this module's instance */
     hInstance = GetModuleHandle(NULL);
 
     #ifdef MODULE_NAME_IS_direct3d
-    if( !p_vout->p_sys->b_desktop )
+    if( !p_event->use_desktop )
     {
     #endif
-        vout_window_cfg_t wnd_cfg;
-        memset( &wnd_cfg, 0, sizeof(wnd_cfg) );
-        wnd_cfg.type   = VOUT_WINDOW_TYPE_HWND;
-        wnd_cfg.x      = p_vout->p_sys->i_window_x;
-        wnd_cfg.y      = p_vout->p_sys->i_window_y;
-        wnd_cfg.width  = p_vout->p_sys->i_window_width;
-        wnd_cfg.height = p_vout->p_sys->i_window_height;
-
         /* If an external window was specified, we'll draw in it. */
-        p_vout->p_sys->parent_window = vout_window_New( VLC_OBJECT(p_vout), NULL, &wnd_cfg );
-        if( p_vout->p_sys->parent_window )
-            p_vout->p_sys->hparent = p_vout->p_sys->parent_window->handle.hwnd;
+        p_event->parent_window = vout_display_NewWindow(vd, &p_event->wnd_cfg );
+        if( p_event->parent_window )
+            p_event->hparent = p_event->parent_window->handle.hwnd;
+        else
+            p_event->hparent = NULL;
     #ifdef MODULE_NAME_IS_direct3d
     }
     else
@@ -450,8 +444,9 @@ static int DirectXCreateWindow( vout_thread_t *p_vout )
         if( hwnd ) hwnd = FindWindowEx( hwnd, NULL, _T("SHELLDLL_DefView"), NULL );
         if( hwnd ) hwnd = FindWindowEx( hwnd, NULL, _T("SysListView32"), NULL );
         if( !hwnd )
-            msg_Err( p_vout, "Couldn't find desktop icon window. Desktop mode can't be established." );
-        p_vout->p_sys->hparent = hwnd;
+            msg_Err( vd, "Couldn't find desktop icon window. Desktop mode can't be established." );
+        p_event->parent_window = NULL;
+        p_event->hparent = hwnd;
     }
     #endif
 
@@ -487,7 +482,7 @@ static int DirectXCreateWindow( vout_thread_t *p_vout )
          * then fine, otherwise return with an error. */
         if( !GetClassInfo( hInstance, _T("VLC DirectX"), &wndclass ) )
         {
-            msg_Err( p_vout, "DirectXCreateWindow RegisterClass FAILED (err=%lu)", GetLastError() );
+            msg_Err( vd, "DirectXCreateWindow RegisterClass FAILED (err=%lu)", GetLastError() );
             return VLC_EGENERIC;
         }
     }
@@ -503,7 +498,7 @@ static int DirectXCreateWindow( vout_thread_t *p_vout )
          * then fine, otherwise return with an error. */
         if( !GetClassInfo( hInstance, _T("VLC DirectX video"), &wndclass ) )
         {
-            msg_Err( p_vout, "DirectXCreateWindow RegisterClass FAILED (err=%lu)", GetLastError() );
+            msg_Err( vd, "DirectXCreateWindow RegisterClass FAILED (err=%lu)", GetLastError() );
             return VLC_EGENERIC;
         }
     }
@@ -514,10 +509,10 @@ static int DirectXCreateWindow( vout_thread_t *p_vout )
      * the window corresponding to the useable surface we want */
     rect_window.top    = 10;
     rect_window.left   = 10;
-    rect_window.right  = rect_window.left + p_vout->p_sys->i_window_width;
-    rect_window.bottom = rect_window.top + p_vout->p_sys->i_window_height;
+    rect_window.right  = rect_window.left + p_event->wnd_cfg.width;
+    rect_window.bottom = rect_window.top  + p_event->wnd_cfg.height;
 
-    if( var_GetBool( p_vout, "video-deco" ) )
+    if( var_GetBool( vd, "video-deco" ) )
     {
         /* Open with window decoration */
         AdjustWindowRect( &rect_window, WS_OVERLAPPEDWINDOW|WS_SIZEBOX, 0 );
@@ -533,51 +528,51 @@ static int DirectXCreateWindow( vout_thread_t *p_vout )
                       // It messes up the fullscreen window.
     }
 
-    if( p_vout->p_sys->hparent )
+    if( p_event->hparent )
     {
         i_style = WS_VISIBLE|WS_CLIPCHILDREN|WS_CHILD;
         i_stylex = 0;
     }
 
-    p_vout->p_sys->i_window_style = i_style;
+    p_event->i_window_style = i_style;
 
     /* Create the window */
-    p_vout->p_sys->hwnd =
+    p_event->hwnd =
         CreateWindowEx( WS_EX_NOPARENTNOTIFY | i_stylex,
                     _T("VLC DirectX"),               /* name of window class */
                     _T(VOUT_TITLE) _T(" (DirectX Output)"),  /* window title */
                     i_style,                                 /* window style */
-                    (p_vout->p_sys->i_window_x < 0) ? CW_USEDEFAULT :
-                        (UINT)p_vout->p_sys->i_window_x,   /* default X coordinate */
-                    (p_vout->p_sys->i_window_y < 0) ? CW_USEDEFAULT :
-                        (UINT)p_vout->p_sys->i_window_y,   /* default Y coordinate */
+                    (p_event->wnd_cfg.x < 0) ? CW_USEDEFAULT :
+                        (UINT)p_event->wnd_cfg.x,   /* default X coordinate */
+                    (p_event->wnd_cfg.y < 0) ? CW_USEDEFAULT :
+                        (UINT)p_event->wnd_cfg.y,   /* default Y coordinate */
                     rect_window.right - rect_window.left,    /* window width */
                     rect_window.bottom - rect_window.top,   /* window height */
-                    p_vout->p_sys->hparent,                 /* parent window */
+                    p_event->hparent,                       /* parent window */
                     NULL,                          /* no menu in this window */
                     hInstance,            /* handle of this program instance */
-                    (LPVOID)p_vout );            /* send p_vout to WM_CREATE */
+                    (LPVOID)p_event );           /* send vd to WM_CREATE */
 
-    if( !p_vout->p_sys->hwnd )
+    if( !p_event->hwnd )
     {
-        msg_Warn( p_vout, "DirectXCreateWindow create window FAILED (err=%lu)", GetLastError() );
+        msg_Warn( vd, "DirectXCreateWindow create window FAILED (err=%lu)", GetLastError() );
         return VLC_EGENERIC;
     }
 
-    if( p_vout->p_sys->hparent )
+    if( p_event->hparent )
     {
         LONG i_style;
 
         /* We don't want the window owner to overwrite our client area */
-        i_style = GetWindowLong( p_vout->p_sys->hparent, GWL_STYLE );
+        i_style = GetWindowLong( p_event->hparent, GWL_STYLE );
 
         if( !(i_style & WS_CLIPCHILDREN) )
             /* Hmmm, apparently this is a blocking call... */
-            SetWindowLong( p_vout->p_sys->hparent, GWL_STYLE,
+            SetWindowLong( p_event->hparent, GWL_STYLE,
                            i_style | WS_CLIPCHILDREN );
 
         /* Create our fullscreen window */
-        p_vout->p_sys->hfswnd =
+        p_event->hfswnd =
             CreateWindowEx( WS_EX_APPWINDOW, _T("VLC DirectX"),
                             _T(VOUT_TITLE) _T(" (DirectX Output)"),
                             WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN|WS_SIZEBOX,
@@ -585,9 +580,13 @@ static int DirectXCreateWindow( vout_thread_t *p_vout )
                             CW_USEDEFAULT, CW_USEDEFAULT,
                             NULL, NULL, hInstance, NULL );
     }
+    else
+    {
+        p_event->hfswnd = NULL;
+    }
 
     /* Append a "Always On Top" entry in the system menu */
-    hMenu = GetSystemMenu( p_vout->p_sys->hwnd, FALSE );
+    hMenu = GetSystemMenu( p_event->hwnd, FALSE );
     AppendMenu( hMenu, MF_SEPARATOR, 0, _T("") );
     AppendMenu( hMenu, MF_STRING | MF_UNCHECKED,
                        IDM_TOGGLE_ON_TOP, _T("Always on &Top") );
@@ -595,23 +594,24 @@ static int DirectXCreateWindow( vout_thread_t *p_vout )
     /* Create video sub-window. This sub window will always exactly match
      * the size of the video, which allows us to use crazy overlay colorkeys
      * without having them shown outside of the video area. */
-    p_vout->p_sys->hvideownd =
+    /* FIXME vd->source.i_width/i_height seems wrong */
+    p_event->hvideownd =
     CreateWindow( _T("VLC DirectX video"), _T(""),   /* window class */
         WS_CHILD,                   /* window style, not visible initially */
         0, 0,
-        p_vout->render.i_width,         /* default width */
-        p_vout->render.i_height,        /* default height */
-        p_vout->p_sys->hwnd,                    /* parent window */
+        vd->source.i_width,          /* default width */
+        vd->source.i_height,        /* default height */
+        p_event->hwnd,               /* parent window */
         NULL, hInstance,
-        (LPVOID)p_vout );            /* send p_vout to WM_CREATE */
+        (LPVOID)p_event );    /* send vd to WM_CREATE */
 
-    if( !p_vout->p_sys->hvideownd )
-        msg_Warn( p_vout, "can't create video sub-window" );
+    if( !p_event->hvideownd )
+        msg_Warn( vd, "can't create video sub-window" );
     else
-        msg_Dbg( p_vout, "created video sub-window" );
+        msg_Dbg( vd, "created video sub-window" );
 
     /* Now display the window */
-    ShowWindow( p_vout->p_sys->hwnd, SW_SHOW );
+    ShowWindow( p_event->hwnd, SW_SHOW );
 
     return VLC_SUCCESS;
 }
@@ -621,18 +621,20 @@ static int DirectXCreateWindow( vout_thread_t *p_vout )
  *****************************************************************************
  * This function returns all resources allocated by DirectXCreateWindow.
  *****************************************************************************/
-static void DirectXCloseWindow( vout_thread_t *p_vout )
+static void DirectXCloseWindow( event_thread_t *p_event )
 {
-    msg_Dbg( p_vout, "DirectXCloseWindow" );
+    vout_display_t *vd = p_event->vd;
+    msg_Dbg( vd, "DirectXCloseWindow" );
 
-    DestroyWindow( p_vout->p_sys->hwnd );
-    if( p_vout->p_sys->hfswnd ) DestroyWindow( p_vout->p_sys->hfswnd );
+    DestroyWindow( p_event->hwnd );
+    if( p_event->hfswnd )
+        DestroyWindow( p_event->hfswnd );
 
     #ifdef MODULE_NAME_IS_direct3d
-    if( !p_vout->p_sys->b_desktop )
+    if( !p_event->use_desktop )
     #endif
-        vout_window_Delete( p_vout->p_sys->parent_window );
-    p_vout->p_sys->hwnd = NULL;
+        vout_display_DeleteWindow( vd, p_event->parent_window );
+    p_event->hwnd = NULL;
 
     /* We don't unregister the Window Class because it could lead to race
      * conditions and it will be done anyway by the system when the app will
@@ -653,46 +655,52 @@ static void DirectXCloseWindow( vout_thread_t *p_vout )
 static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
                                          WPARAM wParam, LPARAM lParam )
 {
-    vout_thread_t *p_vout;
+    event_thread_t *p_event;
 
     if( message == WM_CREATE )
     {
-        /* Store p_vout for future use */
-        p_vout = (vout_thread_t *)((CREATESTRUCT *)lParam)->lpCreateParams;
-        SetWindowLongPtr( hwnd, GWLP_USERDATA, (LONG_PTR)p_vout );
+        /* Store vd for future use */
+        p_event = (event_thread_t *)((CREATESTRUCT *)lParam)->lpCreateParams;
+        SetWindowLongPtr( hwnd, GWLP_USERDATA, (LONG_PTR)p_event );
         return TRUE;
     }
     else
     {
         LONG_PTR p_user_data = GetWindowLongPtr( hwnd, GWLP_USERDATA );
-        p_vout = (vout_thread_t *)p_user_data;
-        if( !p_vout )
+        p_event = (event_thread_t *)p_user_data;
+        if( !p_event )
         {
             /* Hmmm mozilla does manage somehow to save the pointer to our
              * windowproc and still calls it after the vout has been closed. */
             return DefWindowProc(hwnd, message, wParam, lParam);
         }
     }
+    vout_display_t *vd = p_event->vd;
 
 #ifndef UNDER_CE
     /* Catch the screensaver and the monitor turn-off */
     if( message == WM_SYSCOMMAND &&
         ( (wParam & 0xFFF0) == SC_SCREENSAVE || (wParam & 0xFFF0) == SC_MONITORPOWER ) )
     {
-        //if( p_vout ) msg_Dbg( p_vout, "WinProc WM_SYSCOMMAND screensaver" );
+        //if( vd ) msg_Dbg( vd, "WinProc WM_SYSCOMMAND screensaver" );
         return 0; /* this stops them from happening */
     }
 #endif
 
-    if( hwnd == p_vout->p_sys->hvideownd )
+    if( hwnd == p_event->hvideownd )
     {
+#ifdef MODULE_NAME_IS_directx
+        vlc_mutex_lock( &p_event->lock );
+        const bool use_overlay = p_event->use_overlay;
+        vlc_mutex_unlock( &p_event->lock );
+#endif
+
         switch( message )
         {
 #ifdef MODULE_NAME_IS_directx
         case WM_ERASEBKGND:
         /* For overlay, we need to erase background */
-            return !p_vout->p_sys->b_using_overlay ?
-                1 : DefWindowProc(hwnd, message, wParam, lParam);
+            return !use_overlay ? 1 : DefWindowProc(hwnd, message, wParam, lParam);
         case WM_PAINT:
         /*
         ** For overlay, DefWindowProc() will erase dirty regions
@@ -701,7 +709,7 @@ static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
         ** regular interval, therefore dirty regions can be ignored
         ** to minimize repaint.
         */
-            if( !p_vout->p_sys->b_using_overlay )
+            if( !use_overlay )
             {
                 ValidateRect(hwnd, NULL);
             }
@@ -729,24 +737,19 @@ static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
     {
 
     case WM_WINDOWPOSCHANGED:
-        UpdateRects( p_vout, true );
+        vlc_mutex_lock( &p_event->lock );
+        p_event->has_moved = true;
+        vlc_mutex_unlock( &p_event->lock );
         return 0;
 
     /* the user wants to close the window */
     case WM_CLOSE:
-    {
-        playlist_t * p_playlist = pl_Hold( p_vout );
-        if( p_playlist )
-        {
-            playlist_Stop( p_playlist );
-            pl_Release( p_vout );
-        }
+        vout_display_SendEventClose(vd);
         return 0;
-    }
 
     /* the window has been closed so shut down everything now */
     case WM_DESTROY:
-        msg_Dbg( p_vout, "WinProc WM_DESTROY" );
+        msg_Dbg( vd, "WinProc WM_DESTROY" );
         /* just destroy the window */
         PostQuitMessage( 0 );
         return 0;
@@ -754,17 +757,16 @@ static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
     case WM_SYSCOMMAND:
         switch (wParam)
         {
-            case IDM_TOGGLE_ON_TOP:            /* toggle the "on top" status */
-            {
-                vlc_value_t val;
-                msg_Dbg( p_vout, "WinProc WM_SYSCOMMAND: IDM_TOGGLE_ON_TOP");
-
-                /* Change the current value */
-                var_Get( p_vout, "video-on-top", &val );
-                val.b_bool = !val.b_bool;
-                var_Set( p_vout, "video-on-top", val );
-                return 0;
-            }
+        case IDM_TOGGLE_ON_TOP:            /* toggle the "on top" status */
+        {
+            msg_Dbg(vd, "WinProc WM_SYSCOMMAND: IDM_TOGGLE_ON_TOP");
+            HMENU hMenu = GetSystemMenu(vd->sys->hwnd, FALSE);
+            vout_display_SendWindowState(vd, (GetMenuState(hMenu, IDM_TOGGLE_ON_TOP, MF_BYCOMMAND) & MF_CHECKED) ?
+                    VOUT_WINDOW_STATE_NORMAL : VOUT_WINDOW_STATE_ABOVE);
+            return 0;
+        }
+        default:
+            break;
         }
         break;
 
@@ -778,14 +780,14 @@ static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
         GXSuspend();
 #endif
 #ifdef UNDER_CE
-        if( hwnd == p_vout->p_sys->hfswnd )
+        if( hwnd == p_event->hfswnd )
         {
             HWND htbar = FindWindow( _T("HHTaskbar"), NULL );
             ShowWindow( htbar, SW_SHOW );
         }
 
-        if( !p_vout->p_sys->hparent ||
-            hwnd == p_vout->p_sys->hfswnd )
+        if( !p_event->hparent ||
+            hwnd == p_event->hfswnd )
         {
             SHFullScreen( hwnd, SHFS_SHOWSIPBUTTON );
         }
@@ -797,18 +799,20 @@ static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
         GXResume();
 #endif
 #ifdef UNDER_CE
-        if( p_vout->p_sys->hparent &&
-            hwnd != p_vout->p_sys->hfswnd && p_vout->b_fullscreen )
-            p_vout->p_sys->i_changes |= VOUT_FULLSCREEN_CHANGE;
+        /* FIXME vd->cfg is not lock[ed/able] */
+#warning "FIXME: race condition"
+        if( p_event->hparent &&
+            hwnd != p_event->hfswnd && vd->cfg->is_fullscreen )
+            vout_display_SendEventFullscreen(vd, false);
 
-        if( hwnd == p_vout->p_sys->hfswnd )
+        if( hwnd == p_event->hfswnd )
         {
             HWND htbar = FindWindow( _T("HHTaskbar"), NULL );
             ShowWindow( htbar, SW_HIDE );
         }
 
-        if( !p_vout->p_sys->hparent ||
-            hwnd == p_vout->p_sys->hfswnd )
+        if( !p_event->hparent ||
+            hwnd == p_event->hfswnd )
         {
             SHFullScreen( hwnd, SHFS_HIDESIPBUTTON );
         }
@@ -816,7 +820,7 @@ static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
         return 0;
 
     default:
-        //msg_Dbg( p_vout, "WinProc WM Default %i", message );
+        //msg_Dbg( vd, "WinProc WM Default %i", message );
         break;
     }
 
@@ -837,7 +841,7 @@ static struct
     { VK_F12, KEY_F12 },
 
     { VK_RETURN, KEY_ENTER },
-    { VK_SPACE, KEY_SPACE },
+    { VK_SPACE, ' ' },
     { VK_ESCAPE, KEY_ESC },
 
     { VK_LEFT, KEY_LEFT },
@@ -892,10 +896,7 @@ static int DirectXConvertKey( int i_key )
 
 void EventThreadMouseAutoHide( event_thread_t *p_event )
 {
-    vout_thread_t *p_vout = p_event->p_vout;
-
-    if( p_vout->b_fullscreen &&
-        !p_event->b_cursor_hidden &&
+    if (!p_event->b_cursor_hidden &&
         (mdate() - p_event->i_lastmoved) > p_event->i_mouse_hide_timeout )
     {
         /* Hide the cursor only if it is inside our window */
@@ -903,9 +904,9 @@ void EventThreadMouseAutoHide( event_thread_t *p_event )
         GetCursorPos( &point );
 
         HWND hwnd = WindowFromPoint(point);
-        if( hwnd == p_vout->p_sys->hwnd || hwnd == p_vout->p_sys->hvideownd )
+        if( hwnd == p_event->hwnd || hwnd == p_event->hvideownd )
         {
-            PostMessage( p_vout->p_sys->hwnd, WM_VLC_HIDE_MOUSE, 0, 0 );
+            PostMessage( p_event->hwnd, WM_VLC_HIDE_MOUSE, 0, 0 );
         }
         else
         {
@@ -913,8 +914,75 @@ void EventThreadMouseAutoHide( event_thread_t *p_event )
         }
     }
 }
+void EventThreadMouseShow( event_thread_t *p_event )
+{
+    PostMessage( p_event->hwnd, WM_VLC_SHOW_MOUSE, 0, 0 );
+}
+void EventThreadUpdateTitle( event_thread_t *p_event, const char *psz_fallback )
+{
+    char *psz_title = var_GetNonEmptyString( p_event->vd, "video-title" );
+    if( !psz_title )
+        psz_title = strdup( psz_fallback );
+    if( !psz_title )
+        return;
 
-event_thread_t *EventThreadCreate( vout_thread_t *p_vout )
+    vlc_mutex_lock( &p_event->lock );
+    free( p_event->psz_title );
+    p_event->psz_title = psz_title;
+    vlc_mutex_unlock( &p_event->lock );
+
+    PostMessage( p_event->hwnd, WM_VLC_CHANGE_TEXT, 0, 0 );
+}
+int EventThreadGetWindowStyle( event_thread_t *p_event )
+{
+    /* No need to lock, it is serialized by EventThreadStart */
+    return p_event->i_window_style;
+}
+
+void EventThreadUpdateWindowPosition( event_thread_t *p_event,
+                                      bool *pb_moved, bool *pb_resized,
+                                      int x, int y, int w, int h )
+{
+    vlc_mutex_lock( &p_event->lock );
+    *pb_moved   = x != p_event->wnd_cfg.x ||
+                  y != p_event->wnd_cfg.y;
+    *pb_resized = w != p_event->wnd_cfg.width ||
+                  h != p_event->wnd_cfg.height;
+
+    p_event->wnd_cfg.x      = x;
+    p_event->wnd_cfg.y      = y;
+    p_event->wnd_cfg.width  = w;
+    p_event->wnd_cfg.height = h;
+    vlc_mutex_unlock( &p_event->lock );
+}
+
+void EventThreadUpdateSourceAndPlace( event_thread_t *p_event,
+                                      const video_format_t *p_source,
+                                      const vout_display_place_t *p_place )
+{
+    vlc_mutex_lock( &p_event->lock );
+    p_event->source = *p_source;
+    p_event->place  = *p_place;
+    vlc_mutex_unlock( &p_event->lock );
+}
+
+void EventThreadUseOverlay( event_thread_t *p_event, bool b_used )
+{
+    vlc_mutex_lock( &p_event->lock );
+    p_event->use_overlay = b_used;
+    vlc_mutex_unlock( &p_event->lock );
+}
+bool EventThreadGetAndResetHasMoved( event_thread_t *p_event )
+{
+    vlc_mutex_lock( &p_event->lock );
+    const bool has_moved = p_event->has_moved;
+    p_event->has_moved = false;
+    vlc_mutex_unlock( &p_event->lock );
+
+    return has_moved;
+}
+
+event_thread_t *EventThreadCreate( vout_display_t *vd)
 {
      /* Create the Vout EventThread, this thread is created by us to isolate
      * the Win32 PeekMessage function calls. We want to do this because
@@ -923,32 +991,42 @@ event_thread_t *EventThreadCreate( vout_thread_t *p_vout )
      * Vout EventThread will take care of the creation of the video
      * window (because PeekMessage has to be called from the same thread which
      * created the window). */
-    msg_Dbg( p_vout, "creating Vout EventThread" );
+    msg_Dbg( vd, "creating Vout EventThread" );
     event_thread_t *p_event = malloc( sizeof(*p_event) );
     if( !p_event )
         return NULL;
 
-    p_event->p_vout = p_vout;
+    p_event->vd = vd;
     vlc_mutex_init( &p_event->lock );
     vlc_cond_init( &p_event->wait );
 
     p_event->b_cursor_hidden      = false;
     p_event->i_lastmoved          = mdate();
     p_event->i_mouse_hide_timeout =
-        var_GetInteger(p_vout, "mouse-hide-timeout") * 1000;
-   
+        var_GetInteger(vd, "mouse-hide-timeout") * 1000;
+    p_event->psz_title = NULL;
+    p_event->source = vd->source;
+    vout_display_PlacePicture(&p_event->place, &vd->source, vd->cfg, true);
+
     return p_event;
 }
 
 void EventThreadDestroy( event_thread_t *p_event )
 {
+    free( p_event->psz_title );
     vlc_cond_destroy( &p_event->wait );
     vlc_mutex_destroy( &p_event->lock );
     free( p_event );
 }
 
-int EventThreadStart( event_thread_t *p_event )
+int EventThreadStart( event_thread_t *p_event, event_hwnd_t *p_hwnd, const event_cfg_t *p_cfg )
 {
+    p_event->use_desktop = p_cfg->use_desktop;
+    p_event->use_overlay = p_cfg->use_overlay;
+    p_event->wnd_cfg     = p_cfg->win;
+
+    p_event->has_moved = false;
+
     p_event->b_ready = false;
     p_event->b_done  = false;
     p_event->b_error = false;
@@ -956,7 +1034,7 @@ int EventThreadStart( event_thread_t *p_event )
     if( vlc_clone( &p_event->thread, EventThread, p_event,
                    VLC_THREAD_PRIORITY_LOW ) )
     {
-        msg_Err( p_event->p_vout, "cannot create Vout EventThread" );
+        msg_Err( p_event->vd, "cannot create Vout EventThread" );
         return VLC_EGENERIC;
     }
 
@@ -972,7 +1050,14 @@ int EventThreadStart( event_thread_t *p_event )
         p_event->b_ready = false;
         return VLC_EGENERIC;
     }
-    msg_Dbg( p_event->p_vout, "Vout EventThread running" );
+    msg_Dbg( p_event->vd, "Vout EventThread running" );
+
+    /* */
+    p_hwnd->parent_window = p_event->parent_window;
+    p_hwnd->hparent       = p_event->hparent;
+    p_hwnd->hwnd          = p_event->hwnd;
+    p_hwnd->hvideownd     = p_event->hvideownd;
+    p_hwnd->hfswnd        = p_event->hfswnd;
     return VLC_SUCCESS;
 }
 
@@ -987,13 +1072,10 @@ void EventThreadStop( event_thread_t *p_event )
 
     /* we need to be sure Vout EventThread won't stay stuck in
      * GetMessage, so we send a fake message */
-    if( p_event->p_vout->p_sys->hwnd )
-        PostMessage( p_event->p_vout->p_sys->hwnd, WM_NULL, 0, 0);
+    if( p_event->hwnd )
+        PostMessage( p_event->hwnd, WM_NULL, 0, 0);
 
     vlc_join( p_event->thread, NULL );
     p_event->b_ready = false;
-
-    /* clear the changes formerly signaled */
-    p_event->p_vout->p_sys->i_changes = 0;
 }