]> git.sesse.net Git - vlc/blobdiff - modules/video_output/msw/events.c
Partially cleanup the vout_window API
[vlc] / modules / video_output / msw / events.c
index e637ccb52489ddc3e3efc1c1da3e584994aadc46..0d603992502cd291c4e3d74f22ccd8a8afeaec2b 100644 (file)
@@ -41,6 +41,7 @@
 #include <vlc_interface.h>
 #include <vlc_playlist.h>
 #include <vlc_vout.h>
+#include <vlc_window.h>
 
 #include <windows.h>
 #include <windowsx.h>
@@ -64,7 +65,7 @@
     //WINSHELLAPI BOOL WINAPI SHFullScreen(HWND hwndRequester, DWORD dwState);
 #endif
 
-/*#if defined(UNDER_CE) && !defined(__PLUGIN__) /*FIXME*/
+/*#if defined(UNDER_CE) && !defined(__PLUGIN__) --FIXME*/
 /*#   define SHFS_SHOWSIPBUTTON 0x0004
 #   define SHFS_HIDESIPBUTTON 0x0008
 #   define MENU_HEIGHT 26
@@ -80,6 +81,7 @@ 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 )
 {
@@ -115,10 +117,13 @@ void* EventThread( vlc_object_t *p_this )
     /* Creating a window under Windows also initializes the thread's event
      * message queue */
     if( DirectXCreateWindow( p_event->p_vout ) )
-        p_event->b_dead = true;
+    {
+        vlc_restorecancel (canc);
+        return NULL;
+    }
 
     /* Signal the creation of the window */
-    vlc_thread_ready( p_event );
+    SetEvent( p_event->window_ready );
 
 #ifndef UNDER_CE
     /* Set power management stuff */
@@ -413,11 +418,12 @@ static int DirectXCreateWindow( vout_thread_t *p_vout )
     hInstance = GetModuleHandle(NULL);
 
     /* If an external window was specified, we'll draw in it. */
-    p_vout->p_sys->hparent =
+    p_vout->p_sys->parent_window =
         vout_RequestWindow( p_vout, &p_vout->p_sys->i_window_x,
                             &p_vout->p_sys->i_window_y,
                             &p_vout->p_sys->i_window_width,
                             &p_vout->p_sys->i_window_height );
+    p_vout->p_sys->hparent = p_vout->p_sys->parent_window->handle;
 
     /* We create the window ourself, there is no previous window proc. */
     p_vout->p_sys->pf_wndproc = NULL;
@@ -595,9 +601,7 @@ static void DirectXCloseWindow( vout_thread_t *p_vout )
     DestroyWindow( p_vout->p_sys->hwnd );
     if( p_vout->p_sys->hfswnd ) DestroyWindow( p_vout->p_sys->hfswnd );
 
-    if( p_vout->p_sys->hparent )
-        vout_ReleaseWindow( p_vout, (void *)p_vout->p_sys->hparent );
-
+    vout_ReleaseWindow( p_vout->p_sys->parent_window );
     p_vout->p_sys->hwnd = NULL;
 
     /* We don't unregister the Window Class because it could lead to race
@@ -871,7 +875,7 @@ static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
     /* the user wants to close the window */
     case WM_CLOSE:
     {
-        playlist_t * p_playlist = pl_Yield( p_vout );
+        playlist_t * p_playlist = pl_Hold( p_vout );
         if( p_playlist )
         {
             playlist_Stop( p_playlist );
@@ -1034,15 +1038,15 @@ static int DirectXConvertKey( int i_key )
 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
 {
     unsigned int *pi_width, *pi_height;
+       bool b_bool;
     RECT rect_window;
     POINT point;
 
     switch( i_query )
     {
     case VOUT_GET_SIZE:
-        if( p_vout->p_sys->hparent )
-            return vout_ControlWindow( p_vout,
-                    (void *)p_vout->p_sys->hparent, i_query, args );
+        if( p_vout->p_sys->parent_window )
+            return vaControlParentWindow( p_vout, i_query, args );
 
         pi_width  = va_arg( args, unsigned int * );
         pi_height = va_arg( args, unsigned int * );
@@ -1054,9 +1058,8 @@ static int Control( vout_thread_t *p_vout, int i_query, va_list args )
         return VLC_SUCCESS;
 
     case VOUT_SET_SIZE:
-        if( p_vout->p_sys->hparent )
-            return vout_ControlWindow( p_vout,
-                    (void *)p_vout->p_sys->hparent, i_query, args );
+        if( p_vout->p_sys->parent_window )
+            return vaControlParentWindow( p_vout, i_query, args );
 
         /* Update dimensions */
         rect_window.top = rect_window.left = 0;
@@ -1117,19 +1120,19 @@ static int Control( vout_thread_t *p_vout, int i_query, va_list args )
                           SWP_FRAMECHANGED );
         }
 
-        return vout_vaControlDefault( p_vout, i_query, args );
+        vout_ReleaseWindow( p_vout->p_sys->parent_window );
+        return VLC_SUCCESS;
 
     case VOUT_SET_STAY_ON_TOP:
         if( p_vout->p_sys->hparent && !var_GetBool( p_vout, "fullscreen" ) )
-            return vout_ControlWindow( p_vout,
-                    (void *)p_vout->p_sys->hparent, i_query, args );
+            return vaControlParentWindow( p_vout, i_query, args );
 
         p_vout->p_sys->b_on_top_change = true;
         return VLC_SUCCESS;
 
 #ifdef MODULE_NAME_IS_wingapi
     case VOUT_SET_FOCUS:
-        b_bool = (bool) va_arg( args, int );
+               b_bool = (bool) va_arg( args, int );
         p_vout->p_sys->b_parent_focus = b_bool;
         if( b_bool ) GXResume();
         else if( !p_vout->p_sys->b_focus ) GXSuspend();
@@ -1142,12 +1145,18 @@ static int Control( vout_thread_t *p_vout, int i_query, va_list args )
 }
 
 
-/* Internal wrapper over GetWindowPlacement / SetWindowPlacement */
-static void SetWindowState(HWND hwnd, int nShowCmd)
+/* 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 over SetWindowPlacement */
+static void SetWindowState(HWND hwnd, int nShowCmd,WINDOWPLACEMENT window_placement)
+{
     window_placement.showCmd = nShowCmd;
     SetWindowPlacement( hwnd, &window_placement );
     SetWindowPos( hwnd, 0, 0, 0, 0, 0,
@@ -1155,13 +1164,21 @@ static void SetWindowState(HWND hwnd, int nShowCmd)
 }
 
 /* Internal wrapper to call vout_ControlWindow for hparent */
-static void ControlParentWindow( vout_thread_t *p_vout, int i_query, ... )
+static int vaControlParentWindow( vout_thread_t *p_vout, int i_query,
+                                   va_list args )
+{
+    return vout_ControlWindow( p_vout->p_sys->parent_window, i_query, args );
+}
+
+static int ControlParentWindow( vout_thread_t *p_vout, int i_query, ... )
 {
     va_list args;
+    int ret;
+
     va_start( args, i_query );
-    vout_ControlWindow( p_vout,
-        (void *)p_vout->p_sys->hparent, i_query, args );
+    ret = vaControlParentWindow( p_vout, i_query, args );
     va_end( args );
+    return ret;
 }
 
 void Win32ToggleFullscreen( vout_thread_t *p_vout )
@@ -1169,11 +1186,17 @@ 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 );
@@ -1181,21 +1204,25 @@ void Win32ToggleFullscreen( vout_thread_t *p_vout )
         if( p_vout->p_sys->hparent )
         {
             /* Retrieve current window position so fullscreen will happen
-            * on the right screen */
-            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 );
+            *on the right screen */
+            HMONITOR hmon = MonitorFromWindow(p_vout->p_sys->hparent,
+                                            MONITOR_DEFAULTTONEAREST);
+            MONITORINFO mi = {sizeof(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 );
         }
 
         /* Maximize window */
-        SetWindowState( hwnd, SW_SHOWMAXIMIZED );
+        SetWindowState( hwnd, SW_SHOWMAXIMIZED, window_placement );
 
         if( p_vout->p_sys->hparent )
         {
+            /* Hide the previous window */
             RECT rect;
             GetClientRect( hwnd, &rect );
             SetParent( p_vout->p_sys->hwnd, hwnd );
@@ -1203,8 +1230,11 @@ void Win32ToggleFullscreen( vout_thread_t *p_vout )
                           rect.right, rect.bottom,
                           SWP_NOZORDER|SWP_FRAMECHANGED );
 
+#ifdef UNDER_CE
             HWND topLevelParent = GetParent( p_vout->p_sys->hparent );
-            //HWND topLevelParent = GetAncestor( p_vout->p_sys->hparent, GA_ROOT );
+#else
+            HWND topLevelParent = GetAncestor( p_vout->p_sys->hparent, GA_ROOT );
+#endif
             ShowWindow( topLevelParent, SW_HIDE );
         }
 
@@ -1217,7 +1247,7 @@ void Win32ToggleFullscreen( vout_thread_t *p_vout )
         SetWindowLong( hwnd, GWL_STYLE, p_vout->p_sys->i_window_style );
 
         /* Normal window */
-        SetWindowState( hwnd, SW_SHOWNORMAL );
+        SetWindowState( hwnd, SW_SHOWNORMAL, window_placement );
 
         if( p_vout->p_sys->hparent )
         {
@@ -1228,8 +1258,11 @@ void Win32ToggleFullscreen( vout_thread_t *p_vout )
                           rect.right, rect.bottom,
                           SWP_NOZORDER|SWP_FRAMECHANGED );
 
+#ifdef UNDER_CE
             HWND topLevelParent = GetParent( p_vout->p_sys->hparent );
-            //HWND topLevelParent = GetAncestor( p_vout->p_sys->hparent, GA_ROOT );
+#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 );