changeset 18079:f57317460375

fixes and cleanup for windows fullscreen switching (restore old position, fullscreen on current monitor).
author reimar
date Wed, 12 Apr 2006 14:11:26 +0000
parents aeb937690d3d
children 7327ead03337
files libvo/vo_gl.c libvo/vo_gl2.c libvo/w32_common.c
diffstat 3 files changed, 77 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/vo_gl.c	Wed Apr 12 11:19:49 2006 +0000
+++ b/libvo/vo_gl.c	Wed Apr 12 14:11:26 2006 +0000
@@ -327,13 +327,7 @@
   }
 #endif
 #ifdef GL_WIN32
-  o_dwidth = d_width;
-  o_dheight = d_height;
-  vo_fs = flags & VOFLAG_FULLSCREEN;
-  vo_vm = flags & VOFLAG_MODESWITCHING;
-  vo_dwidth = d_width;
-  vo_dheight = d_height;
-  if (!createRenderingContext())
+  if (!vo_w32_config(d_width, d_height, flags))
     return -1;
 #else
   if (WinID >= 0) {
--- a/libvo/vo_gl2.c	Wed Apr 12 11:19:49 2006 +0000
+++ b/libvo/vo_gl2.c	Wed Apr 12 14:11:26 2006 +0000
@@ -595,15 +595,7 @@
 #ifdef GL_WIN32
 
 static int config_w32(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) {
-    o_dwidth = d_width;
-    o_dheight = d_height;
-    vo_fs = flags & VOFLAG_FULLSCREEN;
-    vo_vm = flags & VOFLAG_MODESWITCHING;
-    
-    vo_dwidth = d_width;
-    vo_dheight = d_height;
-
-    if (!createRenderingContext())
+    if (!vo_w32_config(d_width, d_height, flags))
 	return -1;
 
     if (vo_fs)
--- a/libvo/w32_common.c	Wed Apr 12 11:19:49 2006 +0000
+++ b/libvo/w32_common.c	Wed Apr 12 14:11:26 2006 +0000
@@ -15,6 +15,16 @@
 int vo_vm = 0;
 HDC vo_hdc = 0;
 
+// last non-fullscreen extends
+int prev_width;
+int prev_height;
+int prev_x;
+int prev_y;
+
+// top left coordinates of current monitor
+int vo_screenx;
+int vo_screeny;
+
 uint32_t o_dwidth;
 uint32_t o_dheight;
 
@@ -23,15 +33,28 @@
 static int cursor = 1;
 static int event_flags;
 
+static HMONITOR (WINAPI* myMonitorFromWindow)(HWND, DWORD);
+static BOOL (WINAPI* myGetMonitorInfo)(HMONITOR, LPMONITORINFO);
+
 static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
+    RECT r;
+    POINT p;
     switch (message) {
 	case WM_PAINT:
 	    event_flags |= VO_EVENT_EXPOSE;
 	    break;
+	case WM_MOVE:
+	    p.x = 0;
+	    p.y = 0;
+	    ClientToScreen(vo_window, &p);
+	    vo_dx = p.x;
+	    vo_dy = p.y;
+	    break;
 	case WM_SIZE:
 	    event_flags |= VO_EVENT_RESIZE;
-	    vo_dwidth = lParam & 0xffff;
-	    vo_dheight = lParam >> 16;
+	    GetClientRect(vo_window, &r);
+	    vo_dwidth = r.right;
+	    vo_dheight = r.bottom;
 	    break;
 	case WM_CLOSE:
 	    mplayer_put_key(KEY_CLOSE_WIN);
@@ -122,6 +145,15 @@
     vo_screenheight = dm.dmPelsHeight;
     vo_depthonscreen = dm.dmBitsPerPel;
     aspect_save_screenres(vo_screenwidth, vo_screenheight);
+    vo_screenx = vo_screeny = 0;
+    if (myMonitorFromWindow && myGetMonitorInfo) {
+        MONITORINFO mi;
+        HMONITOR m = myMonitorFromWindow(vo_window, MONITOR_DEFAULTTOPRIMARY);
+        mi.cbSize = sizeof(mi);
+        myGetMonitorInfo(m, &mi);
+        vo_screenx = mi.rcMonitor.left;
+        vo_screeny = mi.rcMonitor.top;
+    }
 }
 
 static void changeMode(void) {
@@ -162,7 +194,7 @@
     ChangeDisplaySettings(0, 0);
 }
 
-int createRenderingContext(void) {
+static int createRenderingContext(void) {
     HWND layer = HWND_NOTOPMOST;
     PIXELFORMATDESCRIPTOR pfd;
     RECT r;
@@ -187,11 +219,24 @@
     updateScreenProperties();
     ShowWindow(vo_window, SW_HIDE);
     SetWindowLong(vo_window, GWL_STYLE, style);
-    vo_dwidth = vo_fs ? vo_screenwidth : o_dwidth;
-    vo_dheight = vo_fs ? vo_screenheight : o_dheight;
-    r.left = vo_fs ? 0 : vo_dy;
+    if (vo_fs) {
+        prev_width = vo_dwidth;
+        prev_height = vo_dheight;
+        prev_x = vo_dx;
+        prev_y = vo_dy;
+        vo_dwidth = vo_screenwidth;
+        vo_dheight = vo_screenheight;
+        vo_dx = vo_screenx;
+        vo_dy = vo_screeny;
+    } else {
+        vo_dwidth = prev_width;
+        vo_dheight = prev_height;
+        vo_dx = prev_x;
+        vo_dy = prev_y;
+    }
+    r.left = vo_dx;
     r.right = r.left + vo_dwidth;
-    r.top = vo_fs ? 0 : vo_dx;
+    r.top = vo_dy;
     r.bottom = r.top + vo_dheight;
     AdjustWindowRect(&r, style, 0);
     SetWindowPos(vo_window, layer, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_SHOWWINDOW);
@@ -216,9 +261,25 @@
     return 1;
 }
 
+int vo_w32_config(uint32_t width, uint32_t height, uint32_t flags) {
+    // store original size for videomode switching
+    o_dwidth = width;
+    o_dheight = height;
+
+    prev_width = width;
+    prev_height = height;
+    prev_x = vo_dx;
+    prev_y = vo_dy;
+
+    vo_fs = flags & VOFLAG_FULLSCREEN;
+    vo_vm = flags & VOFLAG_MODESWITCHING;
+    return createRenderingContext();
+}
+
 int vo_init(void) {
     HICON 	mplayerIcon = 0;
     char 	exedir[MAX_PATH];
+    HINSTANCE	user32;
 
     if (vo_window)
 	return 1;
@@ -253,6 +314,13 @@
 
     vo_hdc = GetDC(vo_window);
 
+    myMonitorFromWindow = NULL;
+    myGetMonitorInfo = NULL;
+    user32 = GetModuleHandle("user32.dll");
+    if (user32) {
+        myMonitorFromWindow = GetProcAddress(user32, "MonitorFromWindow");
+        myGetMonitorInfo = GetProcAddress(user32, "GetMonitorInfoA");
+    }
     updateScreenProperties();
 
     return 1;