]> git.sesse.net Git - vlc/blobdiff - modules/video_output/msw/events.c
Win32: go fullscreen on the same screen as the vout window
[vlc] / modules / video_output / msw / events.c
index 5467ca5fdd5a8d5562421fc61a1341dd88ea75bf..b0ec026f4ae74dbab53709d20f77ab9c4c7d5064 100644 (file)
  * Preamble: This file contains the functions related to the creation of
  *             a window and the handling of its messages (events).
  *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <errno.h>                                                 /* ENOMEM */
 #include <ctype.h>                                              /* tolower() */
 
 #   define _WIN32_WINNT 0x0500
 #endif
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
 #include <vlc_common.h>
 #include <vlc_interface.h>
 #include <vlc_playlist.h>
 #include "vlc_keys.h"
 #include "vout.h"
 
-#if defined(UNDER_CE) && !defined(__PLUGIN__) /*FIXME*/
-#   define SHFS_SHOWSIPBUTTON 0x0004
+#ifdef UNDER_CE
+#include <aygshell.h>
+    //WINSHELLAPI BOOL WINAPI SHFullScreen(HWND hwndRequester, DWORD dwState);
+#endif
+
+/*#if defined(UNDER_CE) && !defined(__PLUGIN__) /*FIXME*/
+/*#   define SHFS_SHOWSIPBUTTON 0x0004
 #   define SHFS_HIDESIPBUTTON 0x0008
 #   define MENU_HEIGHT 26
     BOOL SHFullScreen(HWND hwndRequester, DWORD dwState);
-#endif
+#endif*/
+
 
 /*****************************************************************************
  * Local prototypes.
@@ -77,15 +83,9 @@ static int Control( vout_thread_t *p_vout, int i_query, va_list args );
 
 static void DirectXPopupMenu( event_thread_t *p_event, bool b_open )
 {
-    playlist_t *p_playlist = vlc_object_find( p_event,
-                                             VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-    if( p_playlist )
-    {
-        vlc_value_t val;
-        val.b_bool = b_open;
-        var_Set( p_playlist, "intf-popupmenu", val );
-        vlc_object_release( p_playlist );
-    }
+    vlc_value_t val;
+    val.b_bool = b_open;
+    var_Set( p_event->p_libvlc, "intf-popupmenu", val );
 }
 
 static int DirectXConvertKey( int i_key );
@@ -98,13 +98,15 @@ 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( event_thread_t *p_event )
+void* EventThread( vlc_object_t *p_this )
 {
+    event_thread_t *p_event = (event_thread_t *)p_this;
     MSG msg;
     POINT old_mouse_pos = {0,0}, mouse_pos;
     vlc_value_t val;
-    int i_width, i_height, i_x, i_y;
+    unsigned int i_width, i_height, i_x, i_y;
     HMODULE hkernel32;
+    int canc = vlc_savecancel ();
 
     /* Initialisation */
     p_event->p_vout->pf_control = Control;
@@ -114,8 +116,8 @@ void EventThread( event_thread_t *p_event )
      * message queue */
     if( DirectXCreateWindow( p_event->p_vout ) )
     {
-        msg_Err( p_event, "out of memory" );
-        p_event->b_dead = true;
+        vlc_restorecancel (canc);
+        return NULL;
     }
 
     /* Signal the creation of the window */
@@ -140,10 +142,10 @@ void EventThread( event_thread_t *p_event )
 
     /* Main loop */
     /* GetMessage will sleep if there's no message in the queue */
-    while( !p_event->b_die && GetMessage( &msg, 0, 0, 0 ) )
+    while( vlc_object_alive (p_event) && GetMessage( &msg, 0, 0, 0 ) )
     {
         /* Check if we are asked to exit */
-        if( p_event->b_die )
+        if( !vlc_object_alive (p_event) )
             break;
 
         switch( msg.message )
@@ -384,6 +386,8 @@ void EventThread( event_thread_t *p_event )
     p_event->p_vout->p_sys->i_changes = 0;
 
     DirectXCloseWindow( p_event->p_vout );
+    vlc_restorecancel (canc);
+    return NULL;
 }
 
 
@@ -870,12 +874,11 @@ static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
     /* the user wants to close the window */
     case WM_CLOSE:
     {
-        playlist_t * p_playlist = vlc_object_find( p_vout,
-                                                  VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
+        playlist_t * p_playlist = pl_Hold( p_vout );
         if( p_playlist )
         {
             playlist_Stop( p_playlist );
-            vlc_object_release( p_playlist );
+            pl_Release( p_vout );
         }
         return 0;
     }
@@ -915,16 +918,16 @@ static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
         if( !p_vout->p_sys->b_parent_focus ) GXSuspend();
 #endif
 #ifdef UNDER_CE
-        if( hWnd == p_vout->p_sys->hfswnd )
+        if( hwnd == p_vout->p_sys->hfswnd )
         {
             HWND htbar = FindWindow( _T("HHTaskbar"), NULL );
             ShowWindow( htbar, SW_SHOW );
         }
 
         if( !p_vout->p_sys->hparent ||
-            hWnd == p_vout->p_sys->hfswnd )
+            hwnd == p_vout->p_sys->hfswnd )
         {
-            SHFullScreen( hWnd, SHFS_SHOWSIPBUTTON );
+            SHFullScreen( hwnd, SHFS_SHOWSIPBUTTON );
         }
 #endif
         return 0;
@@ -936,19 +939,19 @@ static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
 #endif
 #ifdef UNDER_CE
         if( p_vout->p_sys->hparent &&
-            hWnd != p_vout->p_sys->hfswnd && p_vout->b_fullscreen )
+            hwnd != p_vout->p_sys->hfswnd && p_vout->b_fullscreen )
             p_vout->p_sys->i_changes |= VOUT_FULLSCREEN_CHANGE;
 
-        if( hWnd == p_vout->p_sys->hfswnd )
+        if( hwnd == p_vout->p_sys->hfswnd )
         {
             HWND htbar = FindWindow( _T("HHTaskbar"), NULL );
             ShowWindow( htbar, SW_HIDE );
         }
 
         if( !p_vout->p_sys->hparent ||
-            hWnd == p_vout->p_sys->hfswnd )
+            hwnd == p_vout->p_sys->hfswnd )
         {
-            SHFullScreen( hWnd, SHFS_HIDESIPBUTTON );
+            SHFullScreen( hwnd, SHFS_HIDESIPBUTTON );
         }
 #endif
         return 0;
@@ -1034,6 +1037,7 @@ 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;
 
@@ -1129,7 +1133,7 @@ static int Control( vout_thread_t *p_vout, int i_query, va_list args )
 
 #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 +1146,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,
@@ -1169,11 +1179,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 +1197,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,7 +1223,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 );
+#else
             HWND topLevelParent = GetAncestor( p_vout->p_sys->hparent, GA_ROOT );
+#endif
             ShowWindow( topLevelParent, SW_HIDE );
         }
 
@@ -1216,7 +1240,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 )
         {
@@ -1227,7 +1251,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 );
+#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 );