2009-02-08 04:27:30 +01:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2007-03-04 14:20:51 +01:00
|
|
|
#include <stdio.h>
|
2003-09-19 16:33:51 +02:00
|
|
|
#include <limits.h>
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
#include <assert.h>
|
2003-09-19 16:33:51 +02:00
|
|
|
#include <windows.h>
|
2007-03-04 14:20:51 +01:00
|
|
|
#include <windowsx.h>
|
2003-09-19 16:33:51 +02:00
|
|
|
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "core/options.h"
|
|
|
|
#include "core/input/keycodes.h"
|
|
|
|
#include "core/input/input.h"
|
|
|
|
#include "core/mp_msg.h"
|
|
|
|
#include "vo.h"
|
2003-09-19 16:33:51 +02:00
|
|
|
#include "aspect.h"
|
|
|
|
#include "w32_common.h"
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "core/mp_fifo.h"
|
2011-12-07 01:36:19 +01:00
|
|
|
#include "osdep/io.h"
|
|
|
|
#include "talloc.h"
|
2003-09-19 16:33:51 +02:00
|
|
|
|
2013-03-23 20:38:22 +01:00
|
|
|
#define WIN_ID_TO_HWND(x) ((HWND)(intptr_t)(x))
|
2012-02-27 19:15:13 +01:00
|
|
|
|
2012-10-11 02:04:08 +02:00
|
|
|
static const wchar_t classname[] = L"mpv";
|
2003-09-19 16:33:51 +02:00
|
|
|
|
2010-04-23 12:22:44 +02:00
|
|
|
static const struct mp_keymap vk_map[] = {
|
2008-12-20 12:52:11 +01:00
|
|
|
// special keys
|
2013-02-12 01:34:04 +01:00
|
|
|
{VK_ESCAPE, MP_KEY_ESC}, {VK_BACK, MP_KEY_BS}, {VK_TAB, MP_KEY_TAB},
|
|
|
|
{VK_RETURN, MP_KEY_ENTER}, {VK_PAUSE, MP_KEY_PAUSE}, {VK_SNAPSHOT, MP_KEY_PRINT},
|
2008-12-20 12:52:11 +01:00
|
|
|
|
|
|
|
// cursor keys
|
2013-02-12 01:34:04 +01:00
|
|
|
{VK_LEFT, MP_KEY_LEFT}, {VK_UP, MP_KEY_UP}, {VK_RIGHT, MP_KEY_RIGHT}, {VK_DOWN, MP_KEY_DOWN},
|
2008-12-20 12:52:11 +01:00
|
|
|
|
|
|
|
// navigation block
|
2013-02-12 01:34:04 +01:00
|
|
|
{VK_INSERT, MP_KEY_INSERT}, {VK_DELETE, MP_KEY_DELETE}, {VK_HOME, MP_KEY_HOME}, {VK_END, MP_KEY_END},
|
|
|
|
{VK_PRIOR, MP_KEY_PAGE_UP}, {VK_NEXT, MP_KEY_PAGE_DOWN},
|
2008-12-20 12:52:11 +01:00
|
|
|
|
2008-12-30 18:00:11 +01:00
|
|
|
// F-keys
|
2013-02-12 01:34:04 +01:00
|
|
|
{VK_F1, MP_KEY_F+1}, {VK_F2, MP_KEY_F+2}, {VK_F3, MP_KEY_F+3}, {VK_F4, MP_KEY_F+4},
|
|
|
|
{VK_F5, MP_KEY_F+5}, {VK_F6, MP_KEY_F+6}, {VK_F7, MP_KEY_F+7}, {VK_F8, MP_KEY_F+8},
|
|
|
|
{VK_F9, MP_KEY_F+9}, {VK_F10, MP_KEY_F+10}, {VK_F11, MP_KEY_F+11}, {VK_F12, MP_KEY_F+12},
|
2008-12-30 18:00:11 +01:00
|
|
|
// numpad
|
2013-02-12 01:34:04 +01:00
|
|
|
{VK_NUMPAD0, MP_KEY_KP0}, {VK_NUMPAD1, MP_KEY_KP1}, {VK_NUMPAD2, MP_KEY_KP2},
|
|
|
|
{VK_NUMPAD3, MP_KEY_KP3}, {VK_NUMPAD4, MP_KEY_KP4}, {VK_NUMPAD5, MP_KEY_KP5},
|
|
|
|
{VK_NUMPAD6, MP_KEY_KP6}, {VK_NUMPAD7, MP_KEY_KP7}, {VK_NUMPAD8, MP_KEY_KP8},
|
|
|
|
{VK_NUMPAD9, MP_KEY_KP9}, {VK_DECIMAL, MP_KEY_KPDEC},
|
2008-12-30 18:00:11 +01:00
|
|
|
|
2008-12-20 12:52:11 +01:00
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
static void add_window_borders(HWND hwnd, RECT *rc)
|
2011-10-28 15:19:51 +02:00
|
|
|
{
|
2012-04-14 13:39:53 +02:00
|
|
|
AdjustWindowRect(rc, GetWindowLong(hwnd, GWL_STYLE), 0);
|
2011-10-28 15:19:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// basically a reverse AdjustWindowRect (win32 doesn't appear to have this)
|
2012-04-14 13:39:53 +02:00
|
|
|
static void subtract_window_borders(HWND hwnd, RECT *rc)
|
2011-10-28 15:19:51 +02:00
|
|
|
{
|
|
|
|
RECT b = { 0, 0, 0, 0 };
|
2012-04-14 13:39:53 +02:00
|
|
|
add_window_borders(hwnd, &b);
|
2011-10-28 15:19:51 +02:00
|
|
|
rc->left -= b.left;
|
|
|
|
rc->top -= b.top;
|
|
|
|
rc->right -= b.right;
|
|
|
|
rc->bottom -= b.bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
// turn a WMSZ_* input value in v into the border that should be resized
|
|
|
|
// returns: 0=left, 1=top, 2=right, 3=bottom, -1=undefined
|
|
|
|
static int get_resize_border(int v) {
|
|
|
|
switch (v) {
|
|
|
|
case WMSZ_LEFT: return 3;
|
|
|
|
case WMSZ_TOP: return 2;
|
|
|
|
case WMSZ_RIGHT: return 3;
|
|
|
|
case WMSZ_BOTTOM: return 2;
|
|
|
|
case WMSZ_TOPLEFT: return 1;
|
|
|
|
case WMSZ_TOPRIGHT: return 1;
|
|
|
|
case WMSZ_BOTTOMLEFT: return 3;
|
|
|
|
case WMSZ_BOTTOMRIGHT: return 3;
|
|
|
|
default: return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
static bool key_state(struct vo *vo, int vk)
|
2012-04-14 13:27:34 +02:00
|
|
|
{
|
|
|
|
return GetKeyState(vk) & 0x8000;
|
|
|
|
}
|
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
static int mod_state(struct vo *vo)
|
2012-04-06 23:14:21 +02:00
|
|
|
{
|
|
|
|
int res = 0;
|
2012-04-14 13:39:53 +02:00
|
|
|
if (key_state(vo, VK_CONTROL))
|
2013-02-12 01:34:04 +01:00
|
|
|
res |= MP_KEY_MODIFIER_CTRL;
|
2012-04-14 13:39:53 +02:00
|
|
|
if (key_state(vo, VK_SHIFT))
|
2013-02-12 01:34:04 +01:00
|
|
|
res |= MP_KEY_MODIFIER_SHIFT;
|
2012-04-14 13:39:53 +02:00
|
|
|
if (key_state(vo, VK_MENU))
|
2013-02-12 01:34:04 +01:00
|
|
|
res |= MP_KEY_MODIFIER_ALT;
|
2012-04-06 23:14:21 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
|
|
|
|
LPARAM lParam)
|
|
|
|
{
|
|
|
|
if (message == WM_NCCREATE) {
|
|
|
|
CREATESTRUCT *cs = (void*)lParam;
|
|
|
|
SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)cs->lpCreateParams);
|
|
|
|
}
|
|
|
|
struct vo *vo = (void*)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
|
|
|
|
// message before WM_NCCREATE, pray to Raymond Chen that it's not important
|
|
|
|
if (!vo)
|
|
|
|
return DefWindowProcW(hWnd, message, wParam, lParam);
|
|
|
|
struct vo_w32_state *w32 = vo->w32;
|
|
|
|
|
2003-09-19 16:33:51 +02:00
|
|
|
switch (message) {
|
2008-02-10 20:47:54 +01:00
|
|
|
case WM_ERASEBKGND: // no need to erase background seperately
|
|
|
|
return 1;
|
2007-03-04 11:39:02 +01:00
|
|
|
case WM_PAINT:
|
2012-04-14 13:39:53 +02:00
|
|
|
w32->event_flags |= VO_EVENT_EXPOSE;
|
2007-03-04 11:39:02 +01:00
|
|
|
break;
|
2012-04-14 13:39:53 +02:00
|
|
|
case WM_MOVE: {
|
|
|
|
POINT p = {0};
|
|
|
|
ClientToScreen(w32->window, &p);
|
|
|
|
w32->window_x = p.x;
|
|
|
|
w32->window_y = p.y;
|
2011-10-28 12:39:43 +02:00
|
|
|
mp_msg(MSGT_VO, MSGL_V, "[vo] move window: %d:%d\n",
|
2012-04-14 13:39:53 +02:00
|
|
|
w32->window_x, w32->window_y);
|
2007-03-04 11:39:02 +01:00
|
|
|
break;
|
2012-04-14 13:39:53 +02:00
|
|
|
}
|
|
|
|
case WM_SIZE: {
|
|
|
|
w32->event_flags |= VO_EVENT_RESIZE;
|
|
|
|
RECT r;
|
|
|
|
GetClientRect(w32->window, &r);
|
|
|
|
vo->dwidth = r.right;
|
|
|
|
vo->dheight = r.bottom;
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
mp_msg(MSGT_VO, MSGL_V, "[vo] resize window: %d:%d\n",
|
2012-04-14 13:39:53 +02:00
|
|
|
vo->dwidth, vo->dheight);
|
2007-03-04 11:39:02 +01:00
|
|
|
break;
|
2012-04-14 13:39:53 +02:00
|
|
|
}
|
2011-10-28 15:19:51 +02:00
|
|
|
case WM_SIZING:
|
2013-03-05 17:40:57 +01:00
|
|
|
if (vo->opts->keepaspect && !vo->opts->fs && vo->opts->WinID < 0) {
|
2011-10-28 15:19:51 +02:00
|
|
|
RECT *rc = (RECT*)lParam;
|
|
|
|
// get client area of the windows if it had the rect rc
|
|
|
|
// (subtracting the window borders)
|
2012-04-14 13:39:53 +02:00
|
|
|
RECT r = *rc;
|
|
|
|
subtract_window_borders(w32->window, &r);
|
2011-10-28 15:19:51 +02:00
|
|
|
int c_w = r.right - r.left, c_h = r.bottom - r.top;
|
2012-04-14 13:39:53 +02:00
|
|
|
float aspect = vo->aspdat.asp;
|
2011-10-28 15:19:51 +02:00
|
|
|
int d_w = c_h * aspect - c_w;
|
|
|
|
int d_h = c_w / aspect - c_h;
|
|
|
|
int d_corners[4] = { d_w, d_h, -d_w, -d_h };
|
|
|
|
int corners[4] = { rc->left, rc->top, rc->right, rc->bottom };
|
|
|
|
int corner = get_resize_border(wParam);
|
|
|
|
if (corner >= 0)
|
|
|
|
corners[corner] -= d_corners[corner];
|
|
|
|
*rc = (RECT) { corners[0], corners[1], corners[2], corners[3] };
|
|
|
|
return TRUE;
|
2008-02-02 18:22:07 +01:00
|
|
|
}
|
2011-10-28 15:19:51 +02:00
|
|
|
break;
|
2007-03-04 11:39:02 +01:00
|
|
|
case WM_CLOSE:
|
2013-02-12 01:34:04 +01:00
|
|
|
mplayer_put_key(vo->key_fifo, MP_KEY_CLOSE_WIN);
|
2007-03-04 11:39:02 +01:00
|
|
|
break;
|
2003-09-19 16:33:51 +02:00
|
|
|
case WM_SYSCOMMAND:
|
2007-03-04 11:39:02 +01:00
|
|
|
switch (wParam) {
|
|
|
|
case SC_SCREENSAVE:
|
|
|
|
case SC_MONITORPOWER:
|
|
|
|
mp_msg(MSGT_VO, MSGL_V, "vo: win32: killing screensaver\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2003-09-19 16:33:51 +02:00
|
|
|
case WM_KEYDOWN:
|
2012-04-06 23:14:21 +02:00
|
|
|
case WM_SYSKEYDOWN: {
|
|
|
|
int mpkey = lookup_keymap_table(vk_map, wParam);
|
2008-12-20 12:52:11 +01:00
|
|
|
if (mpkey)
|
2012-04-14 13:39:53 +02:00
|
|
|
mplayer_put_key(vo->key_fifo, mpkey | mod_state(vo));
|
2012-04-07 14:50:55 +02:00
|
|
|
if (wParam == VK_F10)
|
|
|
|
return 0;
|
2007-03-04 11:39:02 +01:00
|
|
|
break;
|
2012-04-06 23:14:21 +02:00
|
|
|
}
|
|
|
|
case WM_CHAR:
|
|
|
|
case WM_SYSCHAR: {
|
2012-04-14 13:39:53 +02:00
|
|
|
int mods = mod_state(vo);
|
2012-04-07 14:47:06 +02:00
|
|
|
int code = wParam;
|
2012-04-14 18:22:12 +02:00
|
|
|
// Windows enables Ctrl+Alt when AltGr (VK_RMENU) is pressed.
|
|
|
|
// E.g. AltGr+9 on a German keyboard would yield Ctrl+Alt+[
|
|
|
|
// Warning: wine handles this differently. Don't test this on wine!
|
|
|
|
if (key_state(vo, VK_RMENU))
|
2013-02-12 01:34:04 +01:00
|
|
|
mods &= ~(MP_KEY_MODIFIER_CTRL | MP_KEY_MODIFIER_ALT);
|
2012-04-06 23:14:21 +02:00
|
|
|
// Apparently Ctrl+A to Ctrl+Z is special cased, and produces
|
|
|
|
// character codes from 1-26. Work it around.
|
2012-04-07 14:47:06 +02:00
|
|
|
// Also, enter/return (including the keypad variant) and CTRL+J both
|
|
|
|
// map to wParam==10. As a workaround, check VK_RETURN to
|
|
|
|
// distinguish these two key combinations.
|
2013-02-12 01:34:04 +01:00
|
|
|
if ((mods & MP_KEY_MODIFIER_CTRL) && code >= 1 && code <= 26
|
2012-04-14 13:39:53 +02:00
|
|
|
&& !key_state(vo, VK_RETURN))
|
2013-02-12 01:34:04 +01:00
|
|
|
code = code - 1 + (mods & MP_KEY_MODIFIER_SHIFT ? 'A' : 'a');
|
2012-04-07 14:47:06 +02:00
|
|
|
if (code >= 32 && code < (1<<21)) {
|
2012-04-14 13:39:53 +02:00
|
|
|
mplayer_put_key(vo->key_fifo, code | mods);
|
2012-04-06 23:14:21 +02:00
|
|
|
// At least with Alt+char, not calling DefWindowProcW stops
|
|
|
|
// Windows from emitting a beep.
|
|
|
|
return 0;
|
|
|
|
}
|
2012-04-07 14:47:06 +02:00
|
|
|
break;
|
2012-04-06 23:14:21 +02:00
|
|
|
}
|
2007-03-04 11:39:02 +01:00
|
|
|
case WM_LBUTTONDOWN:
|
2013-03-05 17:40:57 +01:00
|
|
|
if (!vo->opts->nomouse_input && (vo->opts->fs || (wParam & MK_CONTROL)))
|
|
|
|
{
|
2013-02-12 01:34:04 +01:00
|
|
|
mplayer_put_key(vo->key_fifo, MP_MOUSE_BTN0 | mod_state(vo));
|
2007-03-04 11:39:02 +01:00
|
|
|
break;
|
|
|
|
}
|
2013-03-04 22:41:27 +01:00
|
|
|
if (!vo->opts->fs) {
|
2007-03-04 11:39:02 +01:00
|
|
|
ReleaseCapture();
|
|
|
|
SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_MBUTTONDOWN:
|
2013-03-05 17:40:57 +01:00
|
|
|
if (!vo->opts->nomouse_input)
|
2013-02-12 01:34:04 +01:00
|
|
|
mplayer_put_key(vo->key_fifo, MP_MOUSE_BTN1 | mod_state(vo));
|
2007-03-04 11:39:02 +01:00
|
|
|
break;
|
|
|
|
case WM_RBUTTONDOWN:
|
2013-03-05 17:40:57 +01:00
|
|
|
if (!vo->opts->nomouse_input)
|
2013-02-12 01:34:04 +01:00
|
|
|
mplayer_put_key(vo->key_fifo, MP_MOUSE_BTN2 | mod_state(vo));
|
2007-03-04 11:39:02 +01:00
|
|
|
break;
|
2007-03-04 14:20:51 +01:00
|
|
|
case WM_MOUSEMOVE:
|
2012-04-14 13:39:53 +02:00
|
|
|
vo_mouse_movement(vo, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
|
2007-03-04 14:20:51 +01:00
|
|
|
break;
|
2007-03-04 11:39:02 +01:00
|
|
|
case WM_MOUSEWHEEL:
|
2013-03-05 17:40:57 +01:00
|
|
|
if (!vo->opts->nomouse_input) {
|
2007-03-04 11:39:02 +01:00
|
|
|
int x = GET_WHEEL_DELTA_WPARAM(wParam);
|
|
|
|
if (x > 0)
|
2013-02-12 01:34:04 +01:00
|
|
|
mplayer_put_key(vo->key_fifo, MP_MOUSE_BTN3 | mod_state(vo));
|
2007-03-04 11:39:02 +01:00
|
|
|
else
|
2013-02-12 01:34:04 +01:00
|
|
|
mplayer_put_key(vo->key_fifo, MP_MOUSE_BTN4 | mod_state(vo));
|
2007-03-04 11:39:02 +01:00
|
|
|
}
|
2011-06-10 15:44:55 +02:00
|
|
|
break;
|
|
|
|
case WM_XBUTTONDOWN:
|
2013-03-05 17:40:57 +01:00
|
|
|
if (!vo->opts->nomouse_input) {
|
2011-06-10 15:44:55 +02:00
|
|
|
int x = HIWORD(wParam);
|
|
|
|
if (x == 1)
|
2013-02-12 01:34:04 +01:00
|
|
|
mplayer_put_key(vo->key_fifo, MP_MOUSE_BTN5 | mod_state(vo));
|
2011-06-10 15:44:55 +02:00
|
|
|
else // if (x == 2)
|
2013-02-12 01:34:04 +01:00
|
|
|
mplayer_put_key(vo->key_fifo, MP_MOUSE_BTN6 | mod_state(vo));
|
2011-06-10 15:44:55 +02:00
|
|
|
}
|
|
|
|
break;
|
2003-09-19 16:33:51 +02:00
|
|
|
}
|
2009-07-07 01:26:13 +02:00
|
|
|
|
2012-04-06 23:42:02 +02:00
|
|
|
return DefWindowProcW(hWnd, message, wParam, lParam);
|
2003-09-19 16:33:51 +02:00
|
|
|
}
|
|
|
|
|
2008-11-18 13:23:23 +01:00
|
|
|
/**
|
|
|
|
* \brief Dispatch incoming window events and handle them.
|
|
|
|
*
|
|
|
|
* This function should be placed inside libvo's function "check_events".
|
|
|
|
*
|
|
|
|
* \return int with these flags possibly set, take care to handle in the right order
|
|
|
|
* if it matters in your driver:
|
|
|
|
*
|
|
|
|
* VO_EVENT_RESIZE = The window was resized. If necessary reinit your
|
|
|
|
* driver render context accordingly.
|
|
|
|
* VO_EVENT_EXPOSE = The window was exposed. Call e.g. flip_frame() to redraw
|
|
|
|
* the window if the movie is paused.
|
|
|
|
*/
|
2012-04-14 13:39:53 +02:00
|
|
|
int vo_w32_check_events(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_w32_state *w32 = vo->w32;
|
2003-09-19 16:33:51 +02:00
|
|
|
MSG msg;
|
2012-04-14 13:39:53 +02:00
|
|
|
w32->event_flags = 0;
|
2012-04-06 23:42:02 +02:00
|
|
|
while (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE)) {
|
2007-03-04 11:39:02 +01:00
|
|
|
TranslateMessage(&msg);
|
2012-04-06 23:42:02 +02:00
|
|
|
DispatchMessageW(&msg);
|
2003-09-19 16:33:51 +02:00
|
|
|
}
|
2013-03-04 22:41:27 +01:00
|
|
|
if (vo->opts->WinID >= 0) {
|
2010-05-19 19:53:47 +02:00
|
|
|
BOOL res;
|
2007-03-04 11:30:55 +01:00
|
|
|
RECT r;
|
2011-06-19 12:36:15 +02:00
|
|
|
POINT p;
|
2012-04-14 13:39:53 +02:00
|
|
|
res = GetClientRect(w32->window, &r);
|
|
|
|
if (res && (r.right != vo->dwidth || r.bottom != vo->dheight)) {
|
|
|
|
vo->dwidth = r.right; vo->dheight = r.bottom;
|
|
|
|
w32->event_flags |= VO_EVENT_RESIZE;
|
2008-12-03 11:54:01 +01:00
|
|
|
}
|
2011-06-19 12:36:15 +02:00
|
|
|
p.x = 0; p.y = 0;
|
2012-04-14 13:39:53 +02:00
|
|
|
ClientToScreen(w32->window, &p);
|
|
|
|
if (p.x != w32->window_x || p.y != w32->window_y) {
|
|
|
|
w32->window_x = p.x; w32->window_y = p.y;
|
2011-06-19 12:36:15 +02:00
|
|
|
}
|
2013-03-04 22:41:27 +01:00
|
|
|
res = GetClientRect(WIN_ID_TO_HWND(vo->opts->WinID), &r);
|
2012-04-14 13:39:53 +02:00
|
|
|
if (res && (r.right != vo->dwidth || r.bottom != vo->dheight))
|
|
|
|
MoveWindow(w32->window, 0, 0, r.right, r.bottom, FALSE);
|
2013-03-05 17:40:57 +01:00
|
|
|
if (!IsWindow(WIN_ID_TO_HWND(vo->opts->WinID)))
|
2010-05-19 19:53:47 +02:00
|
|
|
// Window has probably been closed, e.g. due to program crash
|
2013-02-12 01:34:04 +01:00
|
|
|
mplayer_put_key(vo->key_fifo, MP_KEY_CLOSE_WIN);
|
2007-03-04 11:30:55 +01:00
|
|
|
}
|
2009-07-07 01:26:13 +02:00
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
return w32->event_flags;
|
2003-09-19 16:33:51 +02:00
|
|
|
}
|
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
static BOOL CALLBACK mon_enum(HMONITOR hmon, HDC hdc, LPRECT r, LPARAM p)
|
|
|
|
{
|
|
|
|
struct vo *vo = (void*)p;
|
|
|
|
struct vo_w32_state *w32 = vo->w32;
|
2006-04-16 15:38:28 +02:00
|
|
|
// this defaults to the last screen if specified number does not exist
|
2013-03-04 17:40:21 +01:00
|
|
|
vo->xinerama_x = r->left;
|
|
|
|
vo->xinerama_y = r->top;
|
2013-03-04 22:41:27 +01:00
|
|
|
vo->opts->screenwidth = r->right - r->left;
|
|
|
|
vo->opts->screenheight = r->bottom - r->top;
|
2013-02-17 16:35:44 +01:00
|
|
|
if (w32->mon_cnt == w32->mon_id)
|
2006-04-16 15:38:28 +02:00
|
|
|
return FALSE;
|
2012-04-14 13:39:53 +02:00
|
|
|
w32->mon_cnt++;
|
2006-04-16 15:38:28 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-11-18 13:23:23 +01:00
|
|
|
/**
|
|
|
|
* \brief Update screen information.
|
|
|
|
*
|
|
|
|
* This function should be called in libvo's "control" callback
|
|
|
|
* with parameter VOCTRL_UPDATE_SCREENINFO.
|
|
|
|
* Note that this also enables the new API where geometry and aspect
|
|
|
|
* calculations are done in video_out.c:config_video_out
|
|
|
|
*
|
|
|
|
* Global libvo variables changed:
|
|
|
|
* xinerama_x
|
|
|
|
* xinerama_y
|
|
|
|
* vo_screenwidth
|
|
|
|
* vo_screenheight
|
|
|
|
*/
|
2013-05-16 14:07:41 +02:00
|
|
|
static void w32_update_xinerama_info(struct vo *vo)
|
2012-04-14 13:39:53 +02:00
|
|
|
{
|
|
|
|
struct vo_w32_state *w32 = vo->w32;
|
2013-03-04 22:41:27 +01:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
|
|
|
int screen = opts->fs ? opts->fsscreen_id : opts->screen_id;
|
2013-03-04 17:40:21 +01:00
|
|
|
vo->xinerama_x = vo->xinerama_y = 0;
|
2013-03-04 22:41:27 +01:00
|
|
|
if (opts->fs && screen == -2) {
|
2006-04-16 15:38:28 +02:00
|
|
|
int tmp;
|
2013-03-04 17:40:21 +01:00
|
|
|
vo->xinerama_x = GetSystemMetrics(SM_XVIRTUALSCREEN);
|
|
|
|
vo->xinerama_y = GetSystemMetrics(SM_YVIRTUALSCREEN);
|
2006-04-16 15:38:28 +02:00
|
|
|
tmp = GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
2013-03-04 22:41:27 +01:00
|
|
|
if (tmp) vo->opts->screenwidth = tmp;
|
2006-04-16 15:38:28 +02:00
|
|
|
tmp = GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
2013-03-04 22:41:27 +01:00
|
|
|
if (tmp) vo->opts->screenheight = tmp;
|
2013-02-17 16:35:44 +01:00
|
|
|
} else if (screen == -1) {
|
2006-04-16 15:38:28 +02:00
|
|
|
MONITORINFO mi;
|
2012-04-14 13:39:53 +02:00
|
|
|
HMONITOR m = MonitorFromWindow(w32->window, MONITOR_DEFAULTTOPRIMARY);
|
2006-04-16 15:38:28 +02:00
|
|
|
mi.cbSize = sizeof(mi);
|
2012-04-06 23:42:02 +02:00
|
|
|
GetMonitorInfoW(m, &mi);
|
2013-03-04 17:40:21 +01:00
|
|
|
vo->xinerama_x = mi.rcMonitor.left;
|
|
|
|
vo->xinerama_y = mi.rcMonitor.top;
|
2013-03-04 22:41:27 +01:00
|
|
|
vo->opts->screenwidth = mi.rcMonitor.right - mi.rcMonitor.left;
|
|
|
|
vo->opts->screenheight = mi.rcMonitor.bottom - mi.rcMonitor.top;
|
2013-02-17 16:35:44 +01:00
|
|
|
} else if (screen >= 0) {
|
2012-04-14 13:39:53 +02:00
|
|
|
w32->mon_cnt = 0;
|
2013-02-17 16:35:44 +01:00
|
|
|
w32->mon_id = screen;
|
2012-04-14 13:39:53 +02:00
|
|
|
EnumDisplayMonitors(NULL, NULL, mon_enum, (LONG_PTR)vo);
|
2006-04-16 15:38:28 +02:00
|
|
|
}
|
2013-03-04 22:41:27 +01:00
|
|
|
aspect_save_screenres(vo, vo->opts->screenwidth,
|
|
|
|
vo->opts->screenheight);
|
2006-04-16 15:38:28 +02:00
|
|
|
}
|
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
static void updateScreenProperties(struct vo *vo)
|
|
|
|
{
|
2005-02-21 15:44:39 +01:00
|
|
|
DEVMODE dm;
|
|
|
|
dm.dmSize = sizeof dm;
|
|
|
|
dm.dmDriverExtra = 0;
|
|
|
|
dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
|
|
|
if (!EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &dm)) {
|
2012-04-14 13:39:53 +02:00
|
|
|
mp_msg(MSGT_VO, MSGL_ERR,
|
|
|
|
"vo: win32: unable to enumerate display settings!\n");
|
2007-03-04 11:39:02 +01:00
|
|
|
return;
|
2005-02-21 15:44:39 +01:00
|
|
|
}
|
|
|
|
|
2013-03-04 22:41:27 +01:00
|
|
|
vo->opts->screenwidth = dm.dmPelsWidth;
|
|
|
|
vo->opts->screenheight = dm.dmPelsHeight;
|
2012-04-14 13:39:53 +02:00
|
|
|
w32_update_xinerama_info(vo);
|
2005-02-21 15:44:39 +01:00
|
|
|
}
|
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
static DWORD update_style(struct vo *vo, DWORD style)
|
|
|
|
{
|
|
|
|
const DWORD NO_FRAME = WS_POPUP;
|
|
|
|
const DWORD FRAME = WS_OVERLAPPEDWINDOW | WS_SIZEBOX;
|
|
|
|
style &= ~(NO_FRAME | FRAME);
|
2013-03-05 17:40:57 +01:00
|
|
|
style |= (vo->opts->border && !vo->opts->fs) ? FRAME : NO_FRAME;
|
2012-04-14 13:39:53 +02:00
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
2011-12-07 01:36:19 +01:00
|
|
|
// Update the window title, position, size, and border style from vo_* values.
|
2012-04-14 13:39:53 +02:00
|
|
|
static int reinit_window_state(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_w32_state *w32 = vo->w32;
|
2003-11-30 17:36:10 +01:00
|
|
|
HWND layer = HWND_NOTOPMOST;
|
2005-11-17 21:49:46 +01:00
|
|
|
RECT r;
|
2003-09-19 16:33:51 +02:00
|
|
|
|
2013-03-04 22:41:27 +01:00
|
|
|
if (vo->opts->WinID >= 0)
|
2010-11-09 23:11:08 +01:00
|
|
|
return 1;
|
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
wchar_t *title = mp_from_utf8(NULL, vo_get_window_title(vo));
|
|
|
|
SetWindowTextW(w32->window, title);
|
2011-12-07 01:36:19 +01:00
|
|
|
talloc_free(title);
|
|
|
|
|
2013-03-04 22:41:27 +01:00
|
|
|
bool toggle_fs = w32->current_fs != vo->opts->fs;
|
|
|
|
w32->current_fs = vo->opts->fs;
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
DWORD style = update_style(vo, GetWindowLong(w32->window, GWL_STYLE));
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
|
2013-03-04 22:41:27 +01:00
|
|
|
if (vo->opts->fs || vo->opts->ontop)
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
layer = HWND_TOPMOST;
|
|
|
|
|
|
|
|
// xxx not sure if this can trigger any unwanted messages (WM_MOVE/WM_SIZE)
|
2012-04-14 13:39:53 +02:00
|
|
|
updateScreenProperties(vo);
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
|
2013-03-04 22:41:27 +01:00
|
|
|
if (vo->opts->fs) {
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
// Save window position and size when switching to fullscreen.
|
|
|
|
if (toggle_fs) {
|
2012-04-14 13:39:53 +02:00
|
|
|
w32->prev_width = vo->dwidth;
|
|
|
|
w32->prev_height = vo->dheight;
|
|
|
|
w32->prev_x = w32->window_x;
|
|
|
|
w32->prev_y = w32->window_y;
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
mp_msg(MSGT_VO, MSGL_V, "[vo] save window bounds: %d:%d:%d:%d\n",
|
2012-04-14 13:39:53 +02:00
|
|
|
w32->prev_x, w32->prev_y, w32->prev_width, w32->prev_height);
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
}
|
2013-03-04 22:41:27 +01:00
|
|
|
vo->dwidth = vo->opts->screenwidth;
|
|
|
|
vo->dheight = vo->opts->screenheight;
|
2013-03-04 17:40:21 +01:00
|
|
|
w32->window_x = vo->xinerama_x;
|
|
|
|
w32->window_y = vo->xinerama_y;
|
2006-04-12 16:11:26 +02:00
|
|
|
} else {
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
if (toggle_fs) {
|
|
|
|
// Restore window position and size when switching from fullscreen.
|
|
|
|
mp_msg(MSGT_VO, MSGL_V, "[vo] restore window bounds: %d:%d:%d:%d\n",
|
2012-04-14 13:39:53 +02:00
|
|
|
w32->prev_x, w32->prev_y, w32->prev_width, w32->prev_height);
|
|
|
|
vo->dwidth = w32->prev_width;
|
|
|
|
vo->dheight = w32->prev_height;
|
|
|
|
w32->window_x = w32->prev_x;
|
|
|
|
w32->window_y = w32->prev_y;
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
}
|
2006-04-12 16:11:26 +02:00
|
|
|
}
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
r.left = w32->window_x;
|
|
|
|
r.right = r.left + vo->dwidth;
|
|
|
|
r.top = w32->window_y;
|
|
|
|
r.bottom = r.top + vo->dheight;
|
2011-11-18 00:59:48 +01:00
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
SetWindowLong(w32->window, GWL_STYLE, style);
|
|
|
|
add_window_borders(w32->window, &r);
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
|
2013-03-23 20:38:22 +01:00
|
|
|
mp_msg(MSGT_VO, MSGL_V, "[vo] reset window bounds: %d:%d:%d:%d\n",
|
|
|
|
(int) r.left, (int) r.top, (int)(r.right - r.left),
|
|
|
|
(int)(r.bottom - r.top));
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
SetWindowPos(w32->window, layer, r.left, r.top, r.right - r.left,
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
r.bottom - r.top, SWP_FRAMECHANGED);
|
|
|
|
// For some reason, moving SWP_SHOWWINDOW to a second call works better
|
|
|
|
// with wine: returning from fullscreen doesn't cause a bogus resize to
|
|
|
|
// screen size.
|
|
|
|
// It's not needed on Windows XP or wine with a virtual desktop.
|
|
|
|
// It doesn't seem to have any negative effects.
|
2012-04-14 13:39:53 +02:00
|
|
|
SetWindowPos(w32->window, NULL, 0, 0, 0, 0,
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
|
|
|
|
|
2003-09-19 16:33:51 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-11-18 13:23:23 +01:00
|
|
|
/**
|
|
|
|
* \brief Configure and show window on the screen.
|
|
|
|
*
|
|
|
|
* This function should be called in libvo's "config" callback.
|
|
|
|
* It configures a window and shows it on the screen.
|
|
|
|
*
|
|
|
|
* \return 1 - Success, 0 - Failure
|
|
|
|
*/
|
2012-04-14 13:39:53 +02:00
|
|
|
int vo_w32_config(struct vo *vo, uint32_t width, uint32_t height,
|
|
|
|
uint32_t flags)
|
|
|
|
{
|
|
|
|
struct vo_w32_state *w32 = vo->w32;
|
2010-11-10 23:10:30 +01:00
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
|
|
|
int pf;
|
2012-11-10 16:20:03 +01:00
|
|
|
HDC vo_hdc = GetDC(w32->window);
|
2010-11-10 23:10:30 +01:00
|
|
|
|
|
|
|
memset(&pfd, 0, sizeof pfd);
|
|
|
|
pfd.nSize = sizeof pfd;
|
|
|
|
pfd.nVersion = 1;
|
|
|
|
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
2010-11-10 23:48:41 +01:00
|
|
|
if (flags & VOFLAG_STEREO)
|
|
|
|
pfd.dwFlags |= PFD_STEREO;
|
2010-11-10 23:10:30 +01:00
|
|
|
pfd.iPixelType = PFD_TYPE_RGBA;
|
|
|
|
pfd.cColorBits = 24;
|
|
|
|
pfd.iLayerType = PFD_MAIN_PLANE;
|
|
|
|
pf = ChoosePixelFormat(vo_hdc, &pfd);
|
|
|
|
if (!pf) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "vo: win32: unable to select a valid pixel format!\n");
|
2012-11-10 16:20:03 +01:00
|
|
|
ReleaseDC(w32->window, vo_hdc);
|
2010-11-10 23:10:30 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetPixelFormat(vo_hdc, pf, &pfd);
|
2012-11-10 16:20:03 +01:00
|
|
|
ReleaseDC(w32->window, vo_hdc);
|
2010-11-10 23:10:30 +01:00
|
|
|
|
2010-02-04 23:46:45 +01:00
|
|
|
// we already have a fully initialized window, so nothing needs to be done
|
|
|
|
if (flags & VOFLAG_HIDDEN)
|
2010-05-19 19:55:39 +02:00
|
|
|
return 1;
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
bool reset_size = !(w32->o_dwidth == width && w32->o_dheight == height);
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
w32->o_dwidth = width;
|
|
|
|
w32->o_dheight = height;
|
2006-04-12 16:11:26 +02:00
|
|
|
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
// the desired size is ignored in wid mode, it always matches the window size.
|
2013-03-04 22:41:27 +01:00
|
|
|
if (vo->opts->WinID < 0) {
|
2012-04-14 13:39:53 +02:00
|
|
|
if (w32->window_bounds_initialized) {
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
// restore vo_dwidth/vo_dheight, which are reset against our will
|
|
|
|
// in vo_config()
|
|
|
|
RECT r;
|
2012-04-14 13:39:53 +02:00
|
|
|
GetClientRect(w32->window, &r);
|
|
|
|
vo->dwidth = r.right;
|
|
|
|
vo->dheight = r.bottom;
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
} else {
|
|
|
|
// first vo_config call; vo_config() will always set vo_dx/dy so
|
|
|
|
// that the window is centered on the screen, and this is the only
|
|
|
|
// time we actually want to use vo_dy/dy (this is not sane, and
|
2012-11-09 01:06:43 +01:00
|
|
|
// vo.h should provide a function to query the initial
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
// window position instead)
|
2012-04-14 13:39:53 +02:00
|
|
|
w32->window_bounds_initialized = true;
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
reset_size = true;
|
2012-04-14 13:39:53 +02:00
|
|
|
w32->window_x = w32->prev_x = vo->dx;
|
|
|
|
w32->window_y = w32->prev_y = vo->dy;
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
}
|
|
|
|
if (reset_size) {
|
2012-04-14 13:39:53 +02:00
|
|
|
w32->prev_width = vo->dwidth = width;
|
|
|
|
w32->prev_height = vo->dheight = height;
|
win32: fix window creation and size handling
This commit fixes various issues with the way the window position and
size is setup. Most importantly, it fixes some bugs with restoring from
fullscreen state.
Rename create_rendering_context() to reinit_window_state(). This function
doesn't create anything, it just sets the window bounds and styles.
Do not use vo_dx/dy for the window position, as video_out.c overwrites it
with each vo_config() call. Use private variables window_x/y instead.
A big cause for issues was that reinit_window_state() accidentally cleared
the WS_VISIBLE style. I suspect that the API call to temporarily hide the
window was a hack to deal with this. Another bug was that the window style
was changed without calling SetWindowPos with SWP_FRAMECHANGED (as the
MSDN documentation says).
Properly initialize window position and size on vo_config following the
same rules as the x11 backend:
- Never change the window position. The window position should be kept, as
the user might move the window, and resetting the window position e.g.
during ordered chapter playback is not desired.
- Never change the window size, unless the size of the video changes.
These rules don't apply to fullscreen. When switching from fullscreen to
windowed mode, the backend should restore the previous windowed size and
position. When the VO was reconfigured during playback (vo_config() etc.),
the saved window position and size should be changed according to the
rules above, even if the window was in fullscreen mode during
reconfiguring.
Note that these rules might be perceived as awkward by some users: if you
play multiple files with different resolutions, the window won't be
centered when playing the files after the first. This is not a bug.
2011-10-22 02:11:14 +02:00
|
|
|
}
|
2013-03-19 23:36:43 +01:00
|
|
|
} else {
|
|
|
|
RECT r;
|
|
|
|
GetClientRect(w32->window, &r);
|
|
|
|
vo->dwidth = r.right;
|
|
|
|
vo->dheight = r.bottom;
|
2008-12-03 11:38:50 +01:00
|
|
|
}
|
2006-04-12 16:11:26 +02:00
|
|
|
|
2013-03-04 22:41:27 +01:00
|
|
|
vo->opts->fs = flags & VOFLAG_FULLSCREEN;
|
2012-04-14 13:39:53 +02:00
|
|
|
return reinit_window_state(vo);
|
2006-04-12 16:11:26 +02:00
|
|
|
}
|
|
|
|
|
2008-11-18 13:23:23 +01:00
|
|
|
/**
|
|
|
|
* \brief Initialize w32_common framework.
|
|
|
|
*
|
|
|
|
* The first function that should be called from the w32_common framework.
|
|
|
|
* It handles window creation on the screen with proper title and attributes.
|
|
|
|
* It also initializes the framework's internal variables. The function should
|
|
|
|
* be called after your own preinit initialization and you shouldn't do any
|
|
|
|
* window management on your own.
|
|
|
|
*
|
|
|
|
* Global libvo variables changed:
|
|
|
|
* vo_w32_window
|
|
|
|
* vo_screenwidth
|
|
|
|
* vo_screenheight
|
|
|
|
*
|
|
|
|
* \return 1 = Success, 0 = Failure
|
|
|
|
*/
|
2012-04-14 13:39:53 +02:00
|
|
|
int vo_w32_init(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_w32_state *w32 = vo->w32;
|
|
|
|
if (w32 && w32->window)
|
2007-03-04 11:39:02 +01:00
|
|
|
return 1;
|
2003-09-19 16:33:51 +02:00
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
if (!w32)
|
|
|
|
w32 = vo->w32 = talloc_zero(vo, struct vo_w32_state);
|
2009-07-07 01:26:13 +02:00
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
HINSTANCE hInstance = GetModuleHandleW(NULL);
|
|
|
|
|
2012-04-14 16:53:24 +02:00
|
|
|
HICON mplayerIcon = LoadIconW(hInstance, L"IDI_ICON1");
|
2003-09-19 16:33:51 +02:00
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
WNDCLASSEXW wcex = {
|
|
|
|
.cbSize = sizeof wcex,
|
|
|
|
.style = CS_OWNDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW,
|
|
|
|
.lpfnWndProc = WndProc,
|
|
|
|
.hInstance = hInstance,
|
|
|
|
.hIcon = mplayerIcon,
|
|
|
|
.hCursor = LoadCursor(0, IDC_ARROW),
|
|
|
|
.lpszClassName = classname,
|
|
|
|
.hIconSm = mplayerIcon,
|
|
|
|
};
|
2003-09-19 16:33:51 +02:00
|
|
|
|
2012-04-06 23:42:02 +02:00
|
|
|
if (!RegisterClassExW(&wcex)) {
|
2012-04-14 13:39:53 +02:00
|
|
|
mp_msg(MSGT_VO, MSGL_ERR,
|
|
|
|
"vo: win32: unable to register window class!\n");
|
2007-03-04 11:39:02 +01:00
|
|
|
return 0;
|
2003-09-19 16:33:51 +02:00
|
|
|
}
|
|
|
|
|
2013-03-04 22:41:27 +01:00
|
|
|
if (vo->opts->WinID >= 0) {
|
2008-02-09 15:14:35 +01:00
|
|
|
RECT r;
|
2013-03-04 22:41:27 +01:00
|
|
|
GetClientRect(WIN_ID_TO_HWND(vo->opts->WinID), &r);
|
2012-04-14 13:39:53 +02:00
|
|
|
vo->dwidth = r.right; vo->dheight = r.bottom;
|
|
|
|
w32->window = CreateWindowExW(WS_EX_NOPARENTNOTIFY, classname,
|
|
|
|
classname,
|
|
|
|
WS_CHILD | WS_VISIBLE,
|
|
|
|
0, 0, vo->dwidth, vo->dheight,
|
2013-03-04 22:41:27 +01:00
|
|
|
WIN_ID_TO_HWND(vo->opts->WinID),
|
2013-03-04 17:40:21 +01:00
|
|
|
0, hInstance, vo);
|
2012-04-14 13:39:53 +02:00
|
|
|
} else {
|
|
|
|
w32->window = CreateWindowExW(0, classname,
|
|
|
|
classname,
|
|
|
|
update_style(vo, 0),
|
|
|
|
CW_USEDEFAULT, 0, 100, 100,
|
|
|
|
0, 0, hInstance, vo);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!w32->window) {
|
2007-03-04 11:39:02 +01:00
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "vo: win32: unable to create window!\n");
|
|
|
|
return 0;
|
2003-09-19 16:33:51 +02:00
|
|
|
}
|
|
|
|
|
2013-03-04 22:41:27 +01:00
|
|
|
if (vo->opts->WinID >= 0)
|
2012-04-14 13:39:53 +02:00
|
|
|
EnableWindow(w32->window, 0);
|
|
|
|
|
2012-12-19 12:58:52 +01:00
|
|
|
// we don't have proper event handling
|
|
|
|
vo->wakeup_period = 0.02;
|
|
|
|
|
2012-04-14 13:39:53 +02:00
|
|
|
updateScreenProperties(vo);
|
2003-09-19 16:33:51 +02:00
|
|
|
|
2013-03-02 19:16:59 +01:00
|
|
|
mp_msg(MSGT_VO, MSGL_V, "vo: win32: running at %dx%d\n",
|
2013-03-04 22:41:27 +01:00
|
|
|
vo->opts->screenwidth, vo->opts->screenheight);
|
2010-02-04 23:46:01 +01:00
|
|
|
|
2003-09-19 16:33:51 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-11-18 13:23:23 +01:00
|
|
|
/**
|
|
|
|
* \brief Toogle fullscreen / windowed mode.
|
|
|
|
*
|
|
|
|
* Should be called on VOCTRL_FULLSCREEN event. The window is
|
2012-04-14 13:39:53 +02:00
|
|
|
* always resized during this call, so the rendering context
|
2008-11-18 13:23:23 +01:00
|
|
|
* should be reinitialized with the new dimensions.
|
|
|
|
* It is unspecified if vo_check_events will create a resize
|
|
|
|
* event in addition or not.
|
|
|
|
*/
|
|
|
|
|
2013-05-16 14:07:41 +02:00
|
|
|
static void vo_w32_fullscreen(struct vo *vo)
|
2012-04-14 13:39:53 +02:00
|
|
|
{
|
2013-03-04 22:41:27 +01:00
|
|
|
vo->opts->fs = !vo->opts->fs;
|
2012-04-14 13:39:53 +02:00
|
|
|
reinit_window_state(vo);
|
2003-09-19 16:33:51 +02:00
|
|
|
}
|
|
|
|
|
2008-11-18 13:23:23 +01:00
|
|
|
/**
|
|
|
|
* \brief Toogle window border attribute.
|
|
|
|
*
|
|
|
|
* Should be called on VOCTRL_BORDER event.
|
|
|
|
*/
|
2013-05-16 14:07:41 +02:00
|
|
|
static void vo_w32_border(struct vo *vo)
|
2012-04-14 13:39:53 +02:00
|
|
|
{
|
2013-03-05 17:40:57 +01:00
|
|
|
vo->opts->border = !vo->opts->border;
|
2012-04-14 13:39:53 +02:00
|
|
|
reinit_window_state(vo);
|
2005-11-17 21:49:46 +01:00
|
|
|
}
|
|
|
|
|
2008-11-18 13:23:23 +01:00
|
|
|
/**
|
|
|
|
* \brief Toogle window ontop attribute.
|
|
|
|
*
|
|
|
|
* Should be called on VOCTRL_ONTOP event.
|
|
|
|
*/
|
2013-05-16 14:07:41 +02:00
|
|
|
static void vo_w32_ontop(struct vo *vo)
|
2003-11-30 17:36:10 +01:00
|
|
|
{
|
2013-03-04 22:41:27 +01:00
|
|
|
vo->opts->ontop = !vo->opts->ontop;
|
2012-04-14 13:39:53 +02:00
|
|
|
reinit_window_state(vo);
|
2003-11-30 17:36:10 +01:00
|
|
|
}
|
|
|
|
|
2013-05-15 18:17:18 +02:00
|
|
|
int vo_w32_control(struct vo *vo, int *events, int request, void *arg)
|
|
|
|
{
|
|
|
|
switch (request) {
|
|
|
|
case VOCTRL_CHECK_EVENTS:
|
|
|
|
*events |= vo_w32_check_events(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_FULLSCREEN:
|
|
|
|
vo_w32_fullscreen(vo);
|
|
|
|
*events |= VO_EVENT_RESIZE;
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_ONTOP:
|
|
|
|
vo_w32_ontop(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_BORDER:
|
|
|
|
vo_w32_border(vo);
|
|
|
|
*events |= VO_EVENT_RESIZE;
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_UPDATE_SCREENINFO:
|
|
|
|
w32_update_xinerama_info(vo);
|
|
|
|
return VO_TRUE;
|
2013-05-17 00:10:46 +02:00
|
|
|
case VOCTRL_SET_CURSOR_VISIBILITY:
|
|
|
|
if (*(bool *)arg) {
|
|
|
|
while (ShowCursor(1) < 0) { }
|
|
|
|
} else {
|
|
|
|
while (ShowCursor(0) >= 0) { }
|
|
|
|
}
|
2013-05-15 18:17:18 +02:00
|
|
|
}
|
|
|
|
return VO_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2008-11-18 13:23:23 +01:00
|
|
|
/**
|
|
|
|
* \brief Uninitialize w32_common framework.
|
|
|
|
*
|
|
|
|
* Should be called last in video driver's uninit function. First release
|
2008-11-21 20:32:19 +01:00
|
|
|
* anything built on top of the created window e.g. rendering context inside
|
2008-11-18 13:23:23 +01:00
|
|
|
* and call vo_w32_uninit at the end.
|
|
|
|
*/
|
2012-04-14 13:39:53 +02:00
|
|
|
void vo_w32_uninit(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_w32_state *w32 = vo->w32;
|
2003-09-19 16:33:51 +02:00
|
|
|
mp_msg(MSGT_VO, MSGL_V, "vo: win32: uninit\n");
|
2012-04-24 00:41:12 +02:00
|
|
|
if (!w32)
|
|
|
|
return;
|
2013-05-17 00:10:46 +02:00
|
|
|
while (ShowCursor(1) < 0) { }
|
2012-04-14 13:39:53 +02:00
|
|
|
DestroyWindow(w32->window);
|
2012-04-06 23:42:02 +02:00
|
|
|
UnregisterClassW(classname, 0);
|
2012-04-14 13:39:53 +02:00
|
|
|
talloc_free(w32);
|
|
|
|
vo->w32 = NULL;
|
2003-09-19 16:33:51 +02:00
|
|
|
}
|