]> git.sesse.net Git - vlc/blobdiff - modules/video_output/msw/events.c
Privatized i_window_x/y/w/h in msw.
[vlc] / modules / video_output / msw / events.c
index 92cb62800e87fe4a23ced1af3d6892c774cde100..33a5bf8e9075ea39ccc02dc00e552a384076be28 100644 (file)
 #include <vlc_keys.h>
 #include "vout.h"
 
-#ifndef UNDER_CE
-#include <vlc_windows_interfaces.h>
-#endif
-
 #ifdef UNDER_CE
 #include <aygshell.h>
     //WINSHELLAPI BOOL WINAPI SHFullScreen(HWND hwndRequester, DWORD dwState);
     BOOL SHFullScreen(HWND hwndRequester, DWORD dwState);
 #endif*/
 
-
 /*****************************************************************************
  * Local prototypes.
  *****************************************************************************/
-static int  DirectXCreateWindow( vout_thread_t *p_vout );
+struct event_thread_t
+{
+    vout_thread_t *p_vout;
+
+    /* */
+    vlc_thread_t thread;
+    vlc_mutex_t  lock;
+    vlc_cond_t   wait;
+    bool         b_ready;
+    bool         b_done;
+    bool         b_error;
+
+    /* 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;
+
+    /* */
+    unsigned i_changes;
+
+};
+
+static int  DirectXCreateWindow( event_thread_t * );
 static void DirectXCloseWindow ( vout_thread_t *p_vout );
 static long FAR PASCAL DirectXEventProc( HWND, UINT, WPARAM, LPARAM );
 
-static int Control( vout_thread_t *p_vout, int i_query, va_list args );
-static int vaControlParentWindow( vout_thread_t *, int, va_list );
-
 static void DirectXPopupMenu( event_thread_t *p_event, bool b_open )
 {
     vlc_value_t val;
     val.b_bool = b_open;
-    var_Set( p_event->p_libvlc, "intf-popupmenu", val );
+    var_Set( p_event->p_vout->p_libvlc, "intf-popupmenu", val );
 }
 
 static int DirectXConvertKey( int i_key );
@@ -105,9 +125,10 @@ static int DirectXConvertKey( int i_key );
  * The main goal of this thread is to isolate the Win32 PeekMessage function
  * because this one can block for a long time.
  *****************************************************************************/
-void* EventThread( vlc_object_t *p_this )
+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;
     MSG msg;
     POINT old_mouse_pos = {0,0}, mouse_pos;
     vlc_value_t val;
@@ -115,21 +136,25 @@ void* EventThread( vlc_object_t *p_this )
     HMODULE hkernel32;
     int canc = vlc_savecancel ();
 
-    /* Initialisation */
-    p_event->p_vout->pf_control = Control;
-
+    vlc_mutex_lock( &p_event->lock );
     /* 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;
+    vlc_cond_signal( &p_event->wait );
+
+    const bool b_error = p_event->b_error;
+    vlc_mutex_unlock( &p_event->lock );
+
+    if( b_error )
     {
-        vlc_restorecancel (canc);
+        vlc_restorecancel( canc );
         return NULL;
     }
 
-    /* Signal the creation of the window */
-    SetEvent( p_event->window_ready );
-
 #ifndef UNDER_CE
     /* Set power management stuff */
     if( (hkernel32 = GetModuleHandle( _T("KERNEL32") ) ) )
@@ -143,26 +168,40 @@ void* EventThread( vlc_object_t *p_this )
             /* Prevent monitor from powering off */
             OurSetThreadExecutionState( ES_DISPLAY_REQUIRED | ES_CONTINUOUS );
         else
-            msg_Dbg( p_event, "no support for SetThreadExecutionState()" );
+            msg_Dbg( p_vout, "no support for SetThreadExecutionState()" );
     }
 #endif
 
     /* Main loop */
     /* GetMessage will sleep if there's no message in the queue */
-    while( vlc_object_alive (p_event) && GetMessage( &msg, 0, 0, 0 ) )
+    for( ;; )
     {
+        if( !GetMessage( &msg, 0, 0, 0 ) )
+        {
+            vlc_mutex_lock( &p_event->lock );
+            p_event->b_done = true;
+            vlc_mutex_unlock( &p_event->lock );
+            break;
+        }
+
         /* Check if we are asked to exit */
-        if( !vlc_object_alive (p_event) )
+        vlc_mutex_lock( &p_event->lock );
+        const bool b_done = p_event->b_done;
+        vlc_mutex_unlock( &p_event->lock );
+        if( b_done )
             break;
 
+        /* */
         switch( msg.message )
         {
 
         case WM_MOUSEMOVE:
+            vlc_mutex_lock( &p_event->lock );
             vout_PlacePicture( p_event->p_vout,
-                               p_event->p_vout->p_sys->i_window_width,
-                               p_event->p_vout->p_sys->i_window_height,
+                               p_event->wnd_cfg.width,
+                               p_event->wnd_cfg.height,
                                &i_x, &i_y, &i_width, &i_height );
+            vlc_mutex_unlock( &p_event->lock );
 
             if( msg.hwnd == p_event->p_vout->p_sys->hvideownd )
             {
@@ -190,26 +229,26 @@ void* EventThread( vlc_object_t *p_this )
                 (abs(mouse_pos.y - old_mouse_pos.y)) > 2 ) )
             {
                 GetCursorPos( &old_mouse_pos );
-                p_event->p_vout->p_sys->i_lastmoved = mdate();
+                p_event->i_lastmoved = mdate();
 
-                if( p_event->p_vout->p_sys->b_cursor_hidden )
+                if( p_event->b_cursor_hidden )
                 {
-                    p_event->p_vout->p_sys->b_cursor_hidden = 0;
+                    p_event->b_cursor_hidden = 0;
                     ShowCursor( TRUE );
                 }
             }
             break;
 
         case WM_VLC_HIDE_MOUSE:
-            if( p_event->p_vout->p_sys->b_cursor_hidden ) break;
-            p_event->p_vout->p_sys->b_cursor_hidden = true;
+            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->p_vout->p_sys->b_cursor_hidden ) break;
-            p_event->p_vout->p_sys->b_cursor_hidden = false;
+            if( !p_event->b_cursor_hidden ) break;
+            p_event->b_cursor_hidden = false;
             GetCursorPos( &old_mouse_pos );
             ShowCursor( TRUE );
             break;
@@ -230,7 +269,9 @@ void* EventThread( vlc_object_t *p_this )
             break;
 
         case WM_LBUTTONDBLCLK:
-            p_event->p_vout->p_sys->i_changes |= VOUT_FULLSCREEN_CHANGE;
+            vlc_mutex_lock( &p_event->lock );
+            p_event->i_changes |= VOUT_FULLSCREEN_CHANGE;
+            vlc_mutex_unlock( &p_event->lock );
             break;
 
         case WM_MBUTTONDOWN:
@@ -287,7 +328,7 @@ void* EventThread( vlc_object_t *p_this )
                     val.i_int |= KEY_MODIFIER_ALT;
                 }
 
-                var_Set( p_event->p_libvlc, "key-pressed", val );
+                var_Set( p_vout->p_libvlc, "key-pressed", val );
             }
             break;
 
@@ -315,55 +356,35 @@ void* EventThread( vlc_object_t *p_this )
                     val.i_int |= KEY_MODIFIER_ALT;
                 }
 
-                var_Set( p_event->p_libvlc, "key-pressed", val );
+                var_Set( p_vout->p_libvlc, "key-pressed", val );
             }
             break;
 
         case WM_VLC_CHANGE_TEXT:
-            var_Get( p_event->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 )
+            {
+                SetWindowText( p_vout->p_sys->hwnd, (LPCTSTR)pwz_title );
+                if( p_vout->p_sys->hfswnd )
+                    SetWindowText( p_vout->p_sys->hfswnd, (LPCTSTR)pwz_title );
+                free( pwz_title );
+            }
             break;
+        }
 
         default:
             /* Messages we don't handle directly are dispatched to the
@@ -379,17 +400,14 @@ void* EventThread( vlc_object_t *p_this )
     /* Check for WM_QUIT if we created the window */
     if( !p_event->p_vout->p_sys->hparent && msg.message == WM_QUIT )
     {
-        msg_Warn( p_event, "WM_QUIT... should not happen!!" );
+        msg_Warn( p_vout, "WM_QUIT... should not happen!!" );
         p_event->p_vout->p_sys->hwnd = NULL; /* Window already destroyed */
     }
 
-    msg_Dbg( p_event, "DirectXEventThread terminating" );
+    msg_Dbg( p_vout, "DirectXEventThread terminating" );
 
     DirectXCloseWindow( p_event->p_vout );
-    vlc_restorecancel (canc);
-
-    /* clear the changes formerly signaled */
-    p_event->p_vout->p_sys->i_changes = EVENT_THREAD_ENDED;
+    vlc_restorecancel(canc);
     return NULL;
 }
 
@@ -403,8 +421,9 @@ void* EventThread( vlc_object_t *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_thread_t *p_vout = p_event->p_vout;
     HINSTANCE  hInstance;
     HMENU      hMenu;
     RECT       rect_window;
@@ -422,16 +441,8 @@ static int DirectXCreateWindow( vout_thread_t *p_vout )
     if( !p_vout->p_sys->b_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 );
+        p_vout->p_sys->parent_window = vout_window_New( VLC_OBJECT(p_vout), NULL, &p_event->wnd_cfg );
         if( p_vout->p_sys->parent_window )
             p_vout->p_sys->hparent = p_vout->p_sys->parent_window->handle.hwnd;
     #ifdef MODULE_NAME_IS_direct3d
@@ -448,9 +459,6 @@ static int DirectXCreateWindow( vout_thread_t *p_vout )
     }
     #endif
 
-    /* We create the window ourself, there is no previous window proc. */
-    p_vout->p_sys->pf_wndproc = NULL;
-
     /* Get the Icon from the main app */
     vlc_icon = NULL;
 #ifndef UNDER_CE
@@ -510,8 +518,8 @@ 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" ) )
     {
@@ -535,7 +543,7 @@ static int DirectXCreateWindow( vout_thread_t *p_vout )
         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 =
@@ -543,10 +551,10 @@ static int DirectXCreateWindow( vout_thread_t *p_vout )
                     _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 */
@@ -635,210 +643,6 @@ static void DirectXCloseWindow( vout_thread_t *p_vout )
      * exit */
 }
 
-/*****************************************************************************
- * UpdateRects: update clipping rectangles
- *****************************************************************************
- * This function is called when the window position or size are changed, and
- * its job is to update the source and destination RECTs used to display the
- * picture.
- *****************************************************************************/
-void UpdateRects( vout_thread_t *p_vout, bool b_force )
-{
-#define rect_src p_vout->p_sys->rect_src
-#define rect_src_clipped p_vout->p_sys->rect_src_clipped
-#define rect_dest p_vout->p_sys->rect_dest
-#define rect_dest_clipped p_vout->p_sys->rect_dest_clipped
-
-    unsigned int i_width, i_height, i_x, i_y;
-
-    RECT  rect;
-    POINT point;
-
-    /* Retrieve the window size */
-    GetClientRect( p_vout->p_sys->hwnd, &rect );
-
-    /* Retrieve the window position */
-    point.x = point.y = 0;
-    ClientToScreen( p_vout->p_sys->hwnd, &point );
-
-    /* If nothing changed, we can return */
-    if( !b_force
-         && p_vout->p_sys->i_window_width == rect.right
-         && p_vout->p_sys->i_window_height == rect.bottom
-         && p_vout->p_sys->i_window_x == point.x
-         && p_vout->p_sys->i_window_y == point.y )
-    {
-        return;
-    }
-
-    /* Update the window position and size */
-    p_vout->p_sys->i_window_x = point.x;
-    p_vout->p_sys->i_window_y = point.y;
-    p_vout->p_sys->i_window_width = rect.right;
-    p_vout->p_sys->i_window_height = rect.bottom;
-
-    vout_PlacePicture( p_vout, rect.right, rect.bottom,
-                       &i_x, &i_y, &i_width, &i_height );
-
-    if( p_vout->p_sys->hvideownd )
-        SetWindowPos( p_vout->p_sys->hvideownd, 0,
-                      i_x, i_y, i_width, i_height,
-                      SWP_NOCOPYBITS|SWP_NOZORDER|SWP_ASYNCWINDOWPOS );
-
-    /* Destination image position and dimensions */
-    rect_dest.left = point.x + i_x;
-    rect_dest.right = rect_dest.left + i_width;
-    rect_dest.top = point.y + i_y;
-    rect_dest.bottom = rect_dest.top + i_height;
-
-#ifdef MODULE_NAME_IS_directx
-    /* Apply overlay hardware constraints */
-    if( p_vout->p_sys->b_using_overlay )
-    {
-        if( p_vout->p_sys->i_align_dest_boundary )
-            rect_dest.left = ( rect_dest.left +
-                p_vout->p_sys->i_align_dest_boundary / 2 ) &
-                ~p_vout->p_sys->i_align_dest_boundary;
-
-        if( p_vout->p_sys->i_align_dest_size )
-            rect_dest.right = (( rect_dest.right - rect_dest.left +
-                p_vout->p_sys->i_align_dest_size / 2 ) &
-                ~p_vout->p_sys->i_align_dest_size) + rect_dest.left;
-    }
-
-    /* UpdateOverlay directdraw function doesn't automatically clip to the
-     * display size so we need to do it otherwise it will fail */
-
-    /* Clip the destination window */
-    if( !IntersectRect( &rect_dest_clipped, &rect_dest,
-                        &p_vout->p_sys->rect_display ) )
-    {
-        SetRectEmpty( &rect_src_clipped );
-        return;
-    }
-
-#ifndef NDEBUG
-    msg_Dbg( p_vout, "DirectXUpdateRects image_dst_clipped coords:"
-                     " %li,%li,%li,%li",
-                     rect_dest_clipped.left, rect_dest_clipped.top,
-                     rect_dest_clipped.right, rect_dest_clipped.bottom );
-#endif
-
-#else /* MODULE_NAME_IS_directx */
-
-    /* AFAIK, there are no clipping constraints in Direct3D, OpenGL and GDI */
-    rect_dest_clipped = rect_dest;
-
-#endif
-
-    /* the 2 following lines are to fix a bug when clicking on the desktop */
-    if( (rect_dest_clipped.right - rect_dest_clipped.left)==0 ||
-        (rect_dest_clipped.bottom - rect_dest_clipped.top)==0 )
-    {
-        SetRectEmpty( &rect_src_clipped );
-        return;
-    }
-
-    /* src image dimensions */
-    rect_src.left = 0;
-    rect_src.top = 0;
-    rect_src.right = p_vout->render.i_width;
-    rect_src.bottom = p_vout->render.i_height;
-
-    /* Clip the source image */
-    rect_src_clipped.left = p_vout->fmt_out.i_x_offset +
-      (rect_dest_clipped.left - rect_dest.left) *
-      p_vout->fmt_out.i_visible_width / (rect_dest.right - rect_dest.left);
-    rect_src_clipped.right = p_vout->fmt_out.i_x_offset +
-      p_vout->fmt_out.i_visible_width -
-      (rect_dest.right - rect_dest_clipped.right) *
-      p_vout->fmt_out.i_visible_width / (rect_dest.right - rect_dest.left);
-    rect_src_clipped.top = p_vout->fmt_out.i_y_offset +
-      (rect_dest_clipped.top - rect_dest.top) *
-      p_vout->fmt_out.i_visible_height / (rect_dest.bottom - rect_dest.top);
-    rect_src_clipped.bottom = p_vout->fmt_out.i_y_offset +
-      p_vout->fmt_out.i_visible_height -
-      (rect_dest.bottom - rect_dest_clipped.bottom) *
-      p_vout->fmt_out.i_visible_height / (rect_dest.bottom - rect_dest.top);
-
-#ifdef MODULE_NAME_IS_directx
-    /* Apply overlay hardware constraints */
-    if( p_vout->p_sys->b_using_overlay )
-    {
-        if( p_vout->p_sys->i_align_src_boundary )
-            rect_src_clipped.left = ( rect_src_clipped.left +
-                p_vout->p_sys->i_align_src_boundary / 2 ) &
-                ~p_vout->p_sys->i_align_src_boundary;
-
-        if( p_vout->p_sys->i_align_src_size )
-            rect_src_clipped.right = (( rect_src_clipped.right -
-                rect_src_clipped.left +
-                p_vout->p_sys->i_align_src_size / 2 ) &
-                ~p_vout->p_sys->i_align_src_size) + rect_src_clipped.left;
-    }
-#endif
-
-#ifndef NDEBUG
-    msg_Dbg( p_vout, "DirectXUpdateRects image_src_clipped"
-                     " coords: %li,%li,%li,%li",
-                     rect_src_clipped.left, rect_src_clipped.top,
-                     rect_src_clipped.right, rect_src_clipped.bottom );
-#endif
-
-#ifdef MODULE_NAME_IS_directx
-    /* The destination coordinates need to be relative to the current
-     * directdraw primary surface (display) */
-    rect_dest_clipped.left -= p_vout->p_sys->rect_display.left;
-    rect_dest_clipped.right -= p_vout->p_sys->rect_display.left;
-    rect_dest_clipped.top -= p_vout->p_sys->rect_display.top;
-    rect_dest_clipped.bottom -= p_vout->p_sys->rect_display.top;
-
-    if( p_vout->p_sys->b_using_overlay )
-        DirectDrawUpdateOverlay( p_vout );
-#endif
-
-#ifndef UNDER_CE
-    /* Windows 7 taskbar thumbnail code */
-    LPTASKBARLIST3 p_taskbl;
-    OSVERSIONINFO winVer;
-    winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-    if( GetVersionEx(&winVer) && winVer.dwMajorVersion > 5 )
-    {
-        CoInitialize( 0 );
-
-        if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
-                    NULL, CLSCTX_INPROC_SERVER,
-                    &IID_ITaskbarList3,
-                    &p_taskbl) )
-        {
-            RECT rect_video, rect_parent, rect_relative;
-            HWND hroot = GetAncestor(p_vout->p_sys->hwnd,GA_ROOT);
-
-            p_taskbl->vt->HrInit(p_taskbl);
-            GetWindowRect(p_vout->p_sys->hvideownd, &rect_video);
-            GetWindowRect(hroot, &rect_parent);
-            rect_relative.left = rect_video.left - rect_parent.left - 8;
-            rect_relative.right = rect_video.right - rect_video.left + rect_relative.left;
-            rect_relative.top = rect_video.top - rect_parent.top - 10;
-            rect_relative.bottom = rect_video.bottom - rect_video.top + rect_relative.top - 25;
-
-            if (S_OK != p_taskbl->vt->SetThumbnailClip(p_taskbl, hroot, &rect_relative))
-                msg_Err( p_vout, "SetThumbNailClip failed");
-
-            p_taskbl->vt->Release(p_taskbl);
-        }
-        CoUninitialize();
-    }
-#endif
-    /* Signal the change in size/position */
-    p_vout->p_sys->i_changes |= DX_POSITION_CHANGE;
-
-#undef rect_src
-#undef rect_src_clipped
-#undef rect_dest
-#undef rect_dest_clipped
-}
-
 /*****************************************************************************
  * DirectXEventProc: This is the window event processing function.
  *****************************************************************************
@@ -975,8 +779,7 @@ static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
 
     case WM_KILLFOCUS:
 #ifdef MODULE_NAME_IS_wingapi
-        p_vout->p_sys->b_focus = false;
-        if( !p_vout->p_sys->b_parent_focus ) GXSuspend();
+        GXSuspend();
 #endif
 #ifdef UNDER_CE
         if( hwnd == p_vout->p_sys->hfswnd )
@@ -995,13 +798,16 @@ static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
 
     case WM_SETFOCUS:
 #ifdef MODULE_NAME_IS_wingapi
-        p_vout->p_sys->b_focus = true;
         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;
+        {
+            vlc_mutex_lock( &p_event->lock );
+            p_event->i_changes |= VOUT_FULLSCREEN_CHANGE;
+            vlc_mutex_unlock( &p_event->lock );
+        }
 
         if( hwnd == p_vout->p_sys->hfswnd )
         {
@@ -1092,252 +898,77 @@ static int DirectXConvertKey( int i_key )
     return 0;
 }
 
-/*****************************************************************************
- * Control: control facility for the vout
- *****************************************************************************/
-static int Control( vout_thread_t *p_vout, int i_query, va_list args )
+void EventThreadMouseAutoHide( event_thread_t *p_event )
 {
-    RECT rect_window;
+    vout_thread_t *p_vout = p_event->p_vout;
 
-    switch( i_query )
+    if( p_vout->b_fullscreen &&
+        !p_event->b_cursor_hidden &&
+        (mdate() - p_event->i_lastmoved) > p_event->i_mouse_hide_timeout )
     {
-    case VOUT_SET_SIZE:
-        if( p_vout->p_sys->parent_window )
-            return vaControlParentWindow( p_vout, i_query, args );
-
-        /* Update dimensions */
-        rect_window.top = rect_window.left = 0;
-        rect_window.right  = va_arg( args, unsigned int );
-        rect_window.bottom = va_arg( args, unsigned int );
-        if( !rect_window.right ) rect_window.right = p_vout->i_window_width;
-        if( !rect_window.bottom ) rect_window.bottom = p_vout->i_window_height;
-        AdjustWindowRect( &rect_window, p_vout->p_sys->i_window_style, 0 );
-
-        SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0,
-                      rect_window.right - rect_window.left,
-                      rect_window.bottom - rect_window.top, SWP_NOMOVE );
-
-        return VLC_SUCCESS;
-
-    case VOUT_SET_STAY_ON_TOP:
-        if( p_vout->p_sys->hparent && !var_GetBool( p_vout, "fullscreen" ) )
-            return vaControlParentWindow( p_vout, i_query, args );
-
-        p_vout->p_sys->b_on_top_change = true;
-        return VLC_SUCCESS;
-
-    default:
-        return VLC_EGENERIC;
-    }
-}
-
+        /* Hide the cursor only if it is inside our window */
+        POINT point;
+        GetCursorPos( &point );
 
-/* Internal wrapper over GetWindowPlacement */
-static WINDOWPLACEMENT getWindowState(HWND hwnd)
-{
-    WINDOWPLACEMENT window_placement;
-    window_placement.length = sizeof(WINDOWPLACEMENT);
-    GetWindowPlacement( hwnd, &window_placement );
-    return window_placement;
-}
-
-/* Internal wrapper to call vout_ControlWindow for hparent */
-static int vaControlParentWindow( vout_thread_t *p_vout, int i_query,
-                                   va_list args )
-{
-    switch( i_query )
-    {
-    case VOUT_SET_SIZE:
-    {
-        const unsigned i_width  = va_arg(args, unsigned);
-        const unsigned i_height = va_arg(args, unsigned);
-        return vout_window_SetSize( p_vout->p_sys->parent_window, i_width, i_height );
-    }
-    case VOUT_SET_STAY_ON_TOP:
-    {
-        const bool is_on_top = va_arg(args, int);
-        return vout_window_SetOnTop( p_vout->p_sys->parent_window, is_on_top );
-    }
-    default:
-        return VLC_EGENERIC;
-    }
-}
-
-#if 0
-static int ControlParentWindow( vout_thread_t *p_vout, int i_query, ... )
-{
-    va_list args;
-    int ret;
-
-    va_start( args, i_query );
-    ret = vaControlParentWindow( p_vout, i_query, args );
-    va_end( args );
-    return ret;
-}
-#endif
-
-void Win32ToggleFullscreen( vout_thread_t *p_vout )
-{
-    HWND hwnd = (p_vout->p_sys->hparent && p_vout->p_sys->hfswnd) ?
-        p_vout->p_sys->hfswnd : p_vout->p_sys->hwnd;
-
-    /* Save the current windows placement/placement to restore
-       when fullscreen is over */
-    WINDOWPLACEMENT window_placement = getWindowState( hwnd );
-
-    p_vout->b_fullscreen = ! p_vout->b_fullscreen;
-
-    /* We want to go to Fullscreen */
-    if( p_vout->b_fullscreen )
-    {
-        msg_Dbg( p_vout, "entering fullscreen mode" );
-
-        /* Change window style, no borders and no title bar */
-        int i_style = WS_CLIPCHILDREN | WS_VISIBLE;
-        SetWindowLong( hwnd, GWL_STYLE, i_style );
-
-        if( p_vout->p_sys->hparent )
+        HWND hwnd = WindowFromPoint(point);
+        if( hwnd == p_vout->p_sys->hwnd || hwnd == p_vout->p_sys->hvideownd )
         {
-#ifdef UNDER_CE
-            POINT point = {0,0};
-            RECT rect;
-            ClientToScreen( p_vout->p_sys->hwnd, &point );
-            GetClientRect( p_vout->p_sys->hwnd, &rect );
-            SetWindowPos( hwnd, 0, point.x, point.y,
-                          rect.right, rect.bottom,
-                          SWP_NOZORDER|SWP_FRAMECHANGED );
-#else
-            /* Retrieve current window position so fullscreen will happen
-            *on the right screen */
-            HMONITOR hmon = MonitorFromWindow(p_vout->p_sys->hparent,
-                                            MONITOR_DEFAULTTONEAREST);
-            MONITORINFO mi;
-            if (GetMonitorInfo(hmon, &mi))
-            SetWindowPos( hwnd, 0,
-                            mi.rcMonitor.left,
-                            mi.rcMonitor.top,
-                            mi.rcMonitor.right - mi.rcMonitor.left,
-                            mi.rcMonitor.bottom - mi.rcMonitor.top,
-                            SWP_NOZORDER|SWP_FRAMECHANGED );
-#endif
+            PostMessage( p_vout->p_sys->hwnd, WM_VLC_HIDE_MOUSE, 0, 0 );
         }
         else
         {
-            /* Maximize non embedded window */
-            ShowWindow( hwnd, SW_SHOWMAXIMIZED );
+            p_event->i_lastmoved = mdate();
         }
-
-        if( p_vout->p_sys->hparent )
-        {
-            /* Hide the previous window */
-            RECT rect;
-            GetClientRect( hwnd, &rect );
-            SetParent( p_vout->p_sys->hwnd, hwnd );
-            SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0,
-                          rect.right, rect.bottom,
-                          SWP_NOZORDER|SWP_FRAMECHANGED );
-
-#ifdef UNDER_CE
-            HWND topLevelParent = GetParent( p_vout->p_sys->hparent );
-#else
-            HWND topLevelParent = GetAncestor( p_vout->p_sys->hparent, GA_ROOT );
-#endif
-            ShowWindow( topLevelParent, SW_HIDE );
-        }
-
-        SetForegroundWindow( hwnd );
     }
-    else
-    {
-        msg_Dbg( p_vout, "leaving fullscreen mode" );
-        /* Change window style, no borders and no title bar */
-        SetWindowLong( hwnd, GWL_STYLE, p_vout->p_sys->i_window_style );
-
-        if( p_vout->p_sys->hparent )
-        {
-            RECT rect;
-            GetClientRect( p_vout->p_sys->hparent, &rect );
-            SetParent( p_vout->p_sys->hwnd, p_vout->p_sys->hparent );
-            SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0,
-                          rect.right, rect.bottom,
-                          SWP_NOZORDER|SWP_FRAMECHANGED );
-
-#ifdef UNDER_CE
-            HWND topLevelParent = GetParent( p_vout->p_sys->hparent );
-#else
-            HWND topLevelParent = GetAncestor( p_vout->p_sys->hparent, GA_ROOT );
-#endif
-            ShowWindow( topLevelParent, SW_SHOW );
-            SetForegroundWindow( p_vout->p_sys->hparent );
-            ShowWindow( hwnd, SW_HIDE );
-        }
-        else
-        {
-            /* return to normal window for non embedded vout */
-            SetWindowPlacement( hwnd, &window_placement );
-            ShowWindow( hwnd, SW_SHOWNORMAL );
-        }
+}
+void EventThreadUpdateTitle( event_thread_t *p_event, const char *psz_fallback )
+{
+    char *psz_title = var_GetNonEmptyString( p_event->p_vout, "video-title" );
+    if( !psz_title )
+        psz_title = strdup( psz_fallback );
+    if( !psz_title )
+        return;
 
-        /* Make sure the mouse cursor is displayed */
-        PostMessage( p_vout->p_sys->hwnd, WM_VLC_SHOW_MOUSE, 0, 0 );
-    }
+    vlc_mutex_lock( &p_event->lock );
+    free( p_event->psz_title );
+    p_event->psz_title = psz_title;
+    vlc_mutex_unlock( &p_event->lock );
 
-    /* Update the object variable and trigger callback */
-    var_SetBool( p_vout, "fullscreen", p_vout->b_fullscreen );
+    PostMessage( p_event->p_vout->p_sys->hwnd, WM_VLC_CHANGE_TEXT, 0, 0 );
 }
+unsigned EventThreadRetreiveChanges( event_thread_t *p_event )
+{
+    vlc_mutex_lock( &p_event->lock );
+    unsigned i_changes = p_event->i_changes;
+    p_event->i_changes = 0;
+    vlc_mutex_unlock( &p_event->lock );
 
-#ifndef UNDER_CE
-void DisableScreensaver( vout_thread_t *p_vout )
+    return i_changes;
+}
+int EventThreadGetWindowStyle( event_thread_t *p_event )
 {
-    /* disable screensaver by temporarily changing system settings */
-    p_vout->p_sys->i_spi_lowpowertimeout = 0;
-    p_vout->p_sys->i_spi_powerofftimeout = 0;
-    p_vout->p_sys->i_spi_screensavetimeout = 0;
-    if( var_GetBool( p_vout, "disable-screensaver" ) )
-    {
-        msg_Dbg(p_vout, "disabling screen saver");
-        SystemParametersInfo(SPI_GETLOWPOWERTIMEOUT,
-            0, &(p_vout->p_sys->i_spi_lowpowertimeout), 0);
-        if( 0 != p_vout->p_sys->i_spi_lowpowertimeout ) {
-            SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT, 0, NULL, 0);
-        }
-        SystemParametersInfo(SPI_GETPOWEROFFTIMEOUT, 0,
-            &(p_vout->p_sys->i_spi_powerofftimeout), 0);
-        if( 0 != p_vout->p_sys->i_spi_powerofftimeout ) {
-            SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, 0, NULL, 0);
-        }
-        SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0,
-            &(p_vout->p_sys->i_spi_screensavetimeout), 0);
-        if( 0 != p_vout->p_sys->i_spi_screensavetimeout ) {
-            SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, 0, NULL, 0);
-        }
-    }
+    /* No need to lock, it is serialized by EventThreadStart */
+    return p_event->i_window_style;
 }
 
-void RestoreScreensaver( vout_thread_t *p_vout )
+void EventThreadUpdateWindowPosition( event_thread_t *p_event, bool *pb_changed,
+                                      int x, int y, int w, int h )
 {
-    /* restore screensaver system settings */
-    if( 0 != p_vout->p_sys->i_spi_lowpowertimeout ) {
-        SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT,
-            p_vout->p_sys->i_spi_lowpowertimeout, NULL, 0);
-    }
-    if( 0 != p_vout->p_sys->i_spi_powerofftimeout ) {
-        SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT,
-            p_vout->p_sys->i_spi_powerofftimeout, NULL, 0);
-    }
-    if( 0 != p_vout->p_sys->i_spi_screensavetimeout ) {
-        SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT,
-            p_vout->p_sys->i_spi_screensavetimeout, NULL, 0);
-    }
+    vlc_mutex_lock( &p_event->lock );
+    *pb_changed = x != p_event->wnd_cfg.x ||
+                  y != p_event->wnd_cfg.y ||
+                  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  = y;
+    p_event->wnd_cfg.height = h;
+    vlc_mutex_unlock( &p_event->lock );
 }
-#endif
-
-int CreateEventThread( vout_thread_t *p_vout )
+event_thread_t *EventThreadCreate( vout_thread_t *p_vout, const vout_window_cfg_t *p_wnd_cfg )
 {
-    if( !( p_vout->p_sys->i_changes & SWITCHING_MODE_FLAG ) )
-        vlc_mutex_init( &p_vout->p_sys->lock );
-
-    /* Create the Vout EventThread, this thread is created by us to isolate
+     /* Create the Vout EventThread, this thread is created by us to isolate
      * the Win32 PeekMessage function calls. We want to do this because
      * Windows can stay blocked inside this call for a long time, and when
      * this happens it thus blocks vlc's video_output thread.
@@ -1345,64 +976,78 @@ int CreateEventThread( vout_thread_t *p_vout )
      * window (because PeekMessage has to be called from the same thread which
      * created the window). */
     msg_Dbg( p_vout, "creating Vout EventThread" );
-    event_thread_t *p_event = p_vout->p_sys->p_event =
-        vlc_object_create( p_vout, sizeof(event_thread_t) );
-    p_event->p_vout = p_vout;
-    p_event->window_ready = CreateEvent( NULL, TRUE, FALSE, NULL );
-    if( vlc_thread_create( p_event, "Vout Events Thread",
-                           EventThread, 0 ) )
-    {
-        msg_Err( p_vout, "cannot create Vout EventThread" );
-        CloseHandle( p_event->window_ready );
-        vlc_object_release( p_event );
-        p_event = NULL;
-        return 0;
-    }
-    WaitForSingleObject( p_event->window_ready, INFINITE );
-    CloseHandle( p_event->window_ready );
-
-    if( p_event->b_error )
-    {
-        msg_Err( p_vout, "Vout EventThread failed" );
-        return 0;
-    }
+    event_thread_t *p_event = malloc( sizeof(*p_event) );
+    if( !p_event )
+        return NULL;
 
-    vlc_object_attach( p_event, p_vout );
+    p_event->p_vout = p_vout;
+    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;
+    p_event->psz_title = NULL;
+    p_event->wnd_cfg = *p_wnd_cfg;
+   
+    return p_event;
+}
 
-    msg_Dbg( p_vout, "Vout EventThread running" );
-    return 1;
+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 );
 }
 
-void StopEventThread( vout_thread_t *p_vout )
+int EventThreadStart( event_thread_t *p_event )
 {
-    if( p_vout->b_fullscreen )
+    p_event->i_changes = 0;
+
+    p_event->b_ready = false;
+    p_event->b_done  = false;
+    p_event->b_error = false;
+
+    if( vlc_clone( &p_event->thread, EventThread, p_event,
+                   VLC_THREAD_PRIORITY_LOW ) )
     {
-        msg_Dbg( p_vout, "Quitting fullscreen" );
-        Win32ToggleFullscreen( p_vout );
-        /* Force fullscreen in the core for the next video */
-        var_SetBool( p_vout, "fullscreen", true );
+        msg_Err( p_event->p_vout, "cannot create Vout EventThread" );
+        return VLC_EGENERIC;
     }
 
-    if( p_vout->p_sys->p_event )
+    vlc_mutex_lock( &p_event->lock );
+    while( !p_event->b_ready )
+        vlc_cond_wait( &p_event->wait, &p_event->lock );
+    const bool b_error = p_event->b_error;
+    vlc_mutex_unlock( &p_event->lock );
+
+    if( b_error )
     {
-        event_thread_t *p_event = p_vout->p_sys->p_event;
-        vlc_object_detach( p_event );
+        vlc_join( p_event->thread, NULL );
+        p_event->b_ready = false;
+        return VLC_EGENERIC;
+    }
+    msg_Dbg( p_event->p_vout, "Vout EventThread running" );
+    return VLC_SUCCESS;
+}
 
-        /* Kill Vout EventThread */
-        vlc_object_kill( p_event );
+void EventThreadStop( event_thread_t *p_event )
+{
+    if( !p_event->b_ready )
+        return;
 
-        /* we need to be sure Vout EventThread won't stay stuck in
-         * GetMessage, so we send a fake message */
-        if( p_vout->p_sys->hwnd )
-        {
-            PostMessage( p_vout->p_sys->hwnd, WM_NULL, 0, 0);
-        }
+    vlc_mutex_lock( &p_event->lock );
+    p_event->b_done = true;
+    vlc_mutex_unlock( &p_event->lock );
 
-        vlc_thread_join( p_event );
-        vlc_object_release( 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_vout->p_sys->i_changes & SWITCHING_MODE_FLAG ) )
-        vlc_mutex_destroy( &p_vout->p_sys->lock );
+    vlc_join( p_event->thread, NULL );
+    p_event->b_ready = false;
 }