2009-02-08 03:27:30 +00: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 13:20:51 +00:00
|
|
|
#include <stdio.h>
|
2003-09-19 14:33:51 +00: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 00:11:14 +00:00
|
|
|
#include <assert.h>
|
2003-09-19 14:33:51 +00:00
|
|
|
#include <windows.h>
|
2007-03-04 13:20:51 +00:00
|
|
|
#include <windowsx.h>
|
2003-09-19 14:33:51 +00:00
|
|
|
|
2013-08-06 20:41:30 +00:00
|
|
|
#include "mpvcore/options.h"
|
|
|
|
#include "mpvcore/input/keycodes.h"
|
|
|
|
#include "mpvcore/input/input.h"
|
|
|
|
#include "mpvcore/mp_msg.h"
|
|
|
|
#include "mpvcore/mp_common.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "vo.h"
|
2003-09-19 14:33:51 +00:00
|
|
|
#include "aspect.h"
|
|
|
|
#include "w32_common.h"
|
2013-08-06 20:41:30 +00:00
|
|
|
#include "mpvcore/input/input.h"
|
2011-12-07 00:36:19 +00:00
|
|
|
#include "osdep/io.h"
|
|
|
|
#include "talloc.h"
|
2003-09-19 14:33:51 +00:00
|
|
|
|
2013-03-23 19:38:22 +00:00
|
|
|
#define WIN_ID_TO_HWND(x) ((HWND)(intptr_t)(x))
|
2012-02-27 18:15:13 +00:00
|
|
|
|
2012-10-11 00:04:08 +00:00
|
|
|
static const wchar_t classname[] = L"mpv";
|
2003-09-19 14:33:51 +00:00
|
|
|
|
2010-04-23 10:22:44 +00:00
|
|
|
static const struct mp_keymap vk_map[] = {
|
2008-12-20 11:52:11 +00:00
|
|
|
// special keys
|
2013-02-12 00:34:04 +00: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 11:52:11 +00:00
|
|
|
|
|
|
|
// cursor keys
|
2013-02-12 00:34:04 +00:00
|
|
|
{VK_LEFT, MP_KEY_LEFT}, {VK_UP, MP_KEY_UP}, {VK_RIGHT, MP_KEY_RIGHT}, {VK_DOWN, MP_KEY_DOWN},
|
2008-12-20 11:52:11 +00:00
|
|
|
|
|
|
|
// navigation block
|
2013-02-12 00:34:04 +00: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 11:52:11 +00:00
|
|
|
|
2008-12-30 17:00:11 +00:00
|
|
|
// F-keys
|
2013-02-12 00:34:04 +00: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 17:00:11 +00:00
|
|
|
// numpad
|
2013-02-12 00:34:04 +00: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 17:00:11 +00:00
|
|
|
|
2008-12-20 11:52:11 +00:00
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
2012-04-14 11:39:53 +00:00
|
|
|
static void add_window_borders(HWND hwnd, RECT *rc)
|
2011-10-28 13:19:51 +00:00
|
|
|
{
|
2012-04-14 11:39:53 +00:00
|
|
|
AdjustWindowRect(rc, GetWindowLong(hwnd, GWL_STYLE), 0);
|
2011-10-28 13:19:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// basically a reverse AdjustWindowRect (win32 doesn't appear to have this)
|
2012-04-14 11:39:53 +00:00
|
|
|
static void subtract_window_borders(HWND hwnd, RECT *rc)
|
2011-10-28 13:19:51 +00:00
|
|
|
{
|
|
|
|
RECT b = { 0, 0, 0, 0 };
|
2012-04-14 11:39:53 +00:00
|
|
|
add_window_borders(hwnd, &b);
|
2011-10-28 13:19:51 +00: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 11:39:53 +00:00
|
|
|
static bool key_state(struct vo *vo, int vk)
|
2012-04-14 11:27:34 +00:00
|
|
|
{
|
|
|
|
return GetKeyState(vk) & 0x8000;
|
|
|
|
}
|
|
|
|
|
2012-04-14 11:39:53 +00:00
|
|
|
static int mod_state(struct vo *vo)
|
2012-04-06 21:14:21 +00:00
|
|
|
{
|
|
|
|
int res = 0;
|
2012-04-14 11:39:53 +00:00
|
|
|
if (key_state(vo, VK_CONTROL))
|
2013-02-12 00:34:04 +00:00
|
|
|
res |= MP_KEY_MODIFIER_CTRL;
|
2012-04-14 11:39:53 +00:00
|
|
|
if (key_state(vo, VK_SHIFT))
|
2013-02-12 00:34:04 +00:00
|
|
|
res |= MP_KEY_MODIFIER_SHIFT;
|
2012-04-14 11:39:53 +00:00
|
|
|
if (key_state(vo, VK_MENU))
|
2013-02-12 00:34:04 +00:00
|
|
|
res |= MP_KEY_MODIFIER_ALT;
|
2012-04-06 21:14:21 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-04-14 11:39:53 +00: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;
|
2013-06-20 21:39:53 +00:00
|
|
|
int mouse_button = 0;
|
2012-04-14 11:39:53 +00:00
|
|
|
|
2003-09-19 14:33:51 +00:00
|
|
|
switch (message) {
|
2008-02-10 19:47:54 +00:00
|
|
|
case WM_ERASEBKGND: // no need to erase background seperately
|
|
|
|
return 1;
|
2007-03-04 10:39:02 +00:00
|
|
|
case WM_PAINT:
|
2012-04-14 11:39:53 +00:00
|
|
|
w32->event_flags |= VO_EVENT_EXPOSE;
|
2007-03-04 10:39:02 +00:00
|
|
|
break;
|
2012-04-14 11:39:53 +00:00
|
|
|
case WM_MOVE: {
|
|
|
|
POINT p = {0};
|
|
|
|
ClientToScreen(w32->window, &p);
|
|
|
|
w32->window_x = p.x;
|
|
|
|
w32->window_y = p.y;
|
2013-09-11 19:32:36 +00:00
|
|
|
MP_VERBOSE(vo, "move window: %d:%d\n",
|
2012-04-14 11:39:53 +00:00
|
|
|
w32->window_x, w32->window_y);
|
2007-03-04 10:39:02 +00:00
|
|
|
break;
|
2012-04-14 11:39:53 +00:00
|
|
|
}
|
|
|
|
case WM_SIZE: {
|
|
|
|
w32->event_flags |= VO_EVENT_RESIZE;
|
|
|
|
RECT r;
|
|
|
|
GetClientRect(w32->window, &r);
|
|
|
|
vo->dwidth = r.right;
|
|
|
|
vo->dheight = r.bottom;
|
2013-09-11 19:32:36 +00:00
|
|
|
MP_VERBOSE(vo, "resize window: %d:%d\n",
|
2012-04-14 11:39:53 +00:00
|
|
|
vo->dwidth, vo->dheight);
|
2007-03-04 10:39:02 +00:00
|
|
|
break;
|
2012-04-14 11:39:53 +00:00
|
|
|
}
|
2011-10-28 13:19:51 +00:00
|
|
|
case WM_SIZING:
|
2013-07-18 12:05:39 +00:00
|
|
|
if (vo->opts->keepaspect && !vo->opts->fullscreen &&
|
|
|
|
vo->opts->WinID < 0)
|
|
|
|
{
|
2011-10-28 13:19:51 +00:00
|
|
|
RECT *rc = (RECT*)lParam;
|
|
|
|
// get client area of the windows if it had the rect rc
|
|
|
|
// (subtracting the window borders)
|
2012-04-14 11:39:53 +00:00
|
|
|
RECT r = *rc;
|
|
|
|
subtract_window_borders(w32->window, &r);
|
2011-10-28 13:19:51 +00:00
|
|
|
int c_w = r.right - r.left, c_h = r.bottom - r.top;
|
2013-07-15 21:55:19 +00:00
|
|
|
float aspect = w32->o_dwidth / (float) MPMAX(w32->o_dheight, 1);
|
2011-10-28 13:19:51 +00: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 17:22:07 +00:00
|
|
|
}
|
2011-10-28 13:19:51 +00:00
|
|
|
break;
|
2007-03-04 10:39:02 +00:00
|
|
|
case WM_CLOSE:
|
2013-07-02 12:04:36 +00:00
|
|
|
mp_input_put_key(vo->input_ctx, MP_KEY_CLOSE_WIN);
|
2007-03-04 10:39:02 +00:00
|
|
|
break;
|
2003-09-19 14:33:51 +00:00
|
|
|
case WM_SYSCOMMAND:
|
2007-03-04 10:39:02 +00:00
|
|
|
switch (wParam) {
|
2013-06-13 22:36:43 +00:00
|
|
|
case SC_SCREENSAVE:
|
|
|
|
case SC_MONITORPOWER:
|
|
|
|
if (w32->disable_screensaver) {
|
2013-09-11 19:32:36 +00:00
|
|
|
MP_VERBOSE(vo, "win32: killing screensaver\n");
|
2007-03-04 10:39:02 +00:00
|
|
|
return 0;
|
2013-06-13 22:36:43 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-03-04 10:39:02 +00:00
|
|
|
}
|
|
|
|
break;
|
2003-09-19 14:33:51 +00:00
|
|
|
case WM_KEYDOWN:
|
2012-04-06 21:14:21 +00:00
|
|
|
case WM_SYSKEYDOWN: {
|
|
|
|
int mpkey = lookup_keymap_table(vk_map, wParam);
|
2008-12-20 11:52:11 +00:00
|
|
|
if (mpkey)
|
2013-07-02 12:04:36 +00:00
|
|
|
mp_input_put_key(vo->input_ctx, mpkey | mod_state(vo));
|
2012-04-07 12:50:55 +00:00
|
|
|
if (wParam == VK_F10)
|
|
|
|
return 0;
|
2007-03-04 10:39:02 +00:00
|
|
|
break;
|
2012-04-06 21:14:21 +00:00
|
|
|
}
|
|
|
|
case WM_CHAR:
|
|
|
|
case WM_SYSCHAR: {
|
2012-04-14 11:39:53 +00:00
|
|
|
int mods = mod_state(vo);
|
2012-04-07 12:47:06 +00:00
|
|
|
int code = wParam;
|
2012-04-14 16:22:12 +00: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 00:34:04 +00:00
|
|
|
mods &= ~(MP_KEY_MODIFIER_CTRL | MP_KEY_MODIFIER_ALT);
|
2012-04-06 21:14:21 +00:00
|
|
|
// Apparently Ctrl+A to Ctrl+Z is special cased, and produces
|
|
|
|
// character codes from 1-26. Work it around.
|
2012-04-07 12:47:06 +00: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 00:34:04 +00:00
|
|
|
if ((mods & MP_KEY_MODIFIER_CTRL) && code >= 1 && code <= 26
|
2012-04-14 11:39:53 +00:00
|
|
|
&& !key_state(vo, VK_RETURN))
|
2013-02-12 00:34:04 +00:00
|
|
|
code = code - 1 + (mods & MP_KEY_MODIFIER_SHIFT ? 'A' : 'a');
|
2012-04-07 12:47:06 +00:00
|
|
|
if (code >= 32 && code < (1<<21)) {
|
2013-07-02 12:04:36 +00:00
|
|
|
mp_input_put_key(vo->input_ctx, code | mods);
|
2012-04-06 21:14:21 +00:00
|
|
|
// At least with Alt+char, not calling DefWindowProcW stops
|
|
|
|
// Windows from emitting a beep.
|
|
|
|
return 0;
|
|
|
|
}
|
2012-04-07 12:47:06 +00:00
|
|
|
break;
|
2012-04-06 21:14:21 +00:00
|
|
|
}
|
2013-07-14 12:57:39 +00:00
|
|
|
case WM_SETCURSOR:
|
|
|
|
if (LOWORD(lParam) == HTCLIENT && !w32->cursor_visible) {
|
|
|
|
SetCursor(NULL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2013-07-25 17:19:12 +00:00
|
|
|
case WM_MOUSELEAVE:
|
2013-07-25 17:47:49 +00:00
|
|
|
w32->tracking = FALSE;
|
2013-07-25 17:19:12 +00:00
|
|
|
mp_input_put_key(vo->input_ctx, MP_KEY_MOUSE_LEAVE);
|
|
|
|
break;
|
2013-08-31 19:21:05 +00:00
|
|
|
case WM_MOUSEMOVE: {
|
2013-07-25 17:47:49 +00:00
|
|
|
if (!w32->tracking)
|
2013-08-31 19:21:05 +00:00
|
|
|
w32->tracking = TrackMouseEvent(&w32->trackEvent);
|
|
|
|
// Windows can send spurious mouse events, which would make the mpv
|
|
|
|
// core unhide the mouse cursor on completely unrelated events. See:
|
|
|
|
// https://blogs.msdn.com/b/oldnewthing/archive/2003/10/01/55108.aspx
|
|
|
|
int x = GET_X_LPARAM(lParam);
|
|
|
|
int y = GET_Y_LPARAM(lParam);
|
|
|
|
if (x != w32->mouse_x || y != w32->mouse_y) {
|
|
|
|
w32->mouse_x = x;
|
|
|
|
w32->mouse_y = y;
|
|
|
|
vo_mouse_movement(vo, x, y);
|
|
|
|
}
|
2013-06-20 21:39:53 +00:00
|
|
|
break;
|
2013-08-31 19:21:05 +00:00
|
|
|
}
|
2007-03-04 10:39:02 +00:00
|
|
|
case WM_LBUTTONDOWN:
|
2013-06-20 21:39:53 +00:00
|
|
|
mouse_button = MP_MOUSE_BTN0 | MP_KEY_STATE_DOWN;
|
|
|
|
break;
|
|
|
|
case WM_LBUTTONUP:
|
2013-07-01 21:54:59 +00:00
|
|
|
mouse_button = MP_MOUSE_BTN0 | MP_KEY_STATE_UP;
|
2007-03-04 10:39:02 +00:00
|
|
|
break;
|
|
|
|
case WM_MBUTTONDOWN:
|
2013-06-20 21:39:53 +00:00
|
|
|
mouse_button = MP_MOUSE_BTN1 | MP_KEY_STATE_DOWN;
|
|
|
|
break;
|
|
|
|
case WM_MBUTTONUP:
|
2013-07-01 21:54:59 +00:00
|
|
|
mouse_button = MP_MOUSE_BTN1 | MP_KEY_STATE_UP;
|
2007-03-04 10:39:02 +00:00
|
|
|
break;
|
|
|
|
case WM_RBUTTONDOWN:
|
2013-06-20 21:39:53 +00:00
|
|
|
mouse_button = MP_MOUSE_BTN2 | MP_KEY_STATE_DOWN;
|
2007-03-04 10:39:02 +00:00
|
|
|
break;
|
2013-06-20 21:39:53 +00:00
|
|
|
case WM_RBUTTONUP:
|
2013-07-01 21:54:59 +00:00
|
|
|
mouse_button = MP_MOUSE_BTN2 | MP_KEY_STATE_UP;
|
2007-03-04 13:20:51 +00:00
|
|
|
break;
|
2013-06-20 21:39:53 +00:00
|
|
|
case WM_MOUSEWHEEL: {
|
|
|
|
int x = GET_WHEEL_DELTA_WPARAM(wParam);
|
|
|
|
mouse_button = x > 0 ? MP_MOUSE_BTN3 : MP_MOUSE_BTN4;
|
2011-06-10 13:44:55 +00:00
|
|
|
break;
|
2013-06-20 21:39:53 +00:00
|
|
|
}
|
2011-06-10 13:44:55 +00:00
|
|
|
case WM_XBUTTONDOWN:
|
2013-06-20 21:39:53 +00:00
|
|
|
mouse_button = HIWORD(wParam) == 1 ? MP_MOUSE_BTN5 : MP_MOUSE_BTN6;
|
|
|
|
mouse_button |= MP_KEY_STATE_DOWN;
|
2011-06-10 13:44:55 +00:00
|
|
|
break;
|
2013-06-20 21:39:53 +00:00
|
|
|
case WM_XBUTTONUP:
|
|
|
|
mouse_button = HIWORD(wParam) == 1 ? MP_MOUSE_BTN5 : MP_MOUSE_BTN6;
|
2013-07-01 21:54:59 +00:00
|
|
|
mouse_button |= MP_KEY_STATE_UP;
|
2013-06-20 21:39:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-09-08 00:12:36 +00:00
|
|
|
if (mouse_button && vo->opts->enable_mouse_movements) {
|
2013-06-20 21:39:53 +00:00
|
|
|
int x = GET_X_LPARAM(lParam);
|
|
|
|
int y = GET_Y_LPARAM(lParam);
|
|
|
|
mouse_button |= mod_state(vo);
|
|
|
|
if (mouse_button == (MP_MOUSE_BTN0 | MP_KEY_STATE_DOWN) &&
|
2013-07-18 12:05:39 +00:00
|
|
|
!vo->opts->fullscreen && !mp_input_test_dragging(vo->input_ctx, x, y))
|
2013-06-20 21:39:53 +00:00
|
|
|
{
|
|
|
|
// Window dragging hack
|
|
|
|
ReleaseCapture();
|
|
|
|
SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-07-02 12:04:36 +00:00
|
|
|
mp_input_put_key(vo->input_ctx, mouse_button);
|
2003-09-19 14:33:51 +00:00
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2012-04-06 21:42:02 +00:00
|
|
|
return DefWindowProcW(hWnd, message, wParam, lParam);
|
2003-09-19 14:33:51 +00:00
|
|
|
}
|
|
|
|
|
2008-11-18 12:23:23 +00: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 11:39:53 +00:00
|
|
|
int vo_w32_check_events(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_w32_state *w32 = vo->w32;
|
2003-09-19 14:33:51 +00:00
|
|
|
MSG msg;
|
2012-04-14 11:39:53 +00:00
|
|
|
w32->event_flags = 0;
|
2012-04-06 21:42:02 +00:00
|
|
|
while (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE)) {
|
2007-03-04 10:39:02 +00:00
|
|
|
TranslateMessage(&msg);
|
2012-04-06 21:42:02 +00:00
|
|
|
DispatchMessageW(&msg);
|
2003-09-19 14:33:51 +00:00
|
|
|
}
|
2013-03-04 21:41:27 +00:00
|
|
|
if (vo->opts->WinID >= 0) {
|
2010-05-19 17:53:47 +00:00
|
|
|
BOOL res;
|
2007-03-04 10:30:55 +00:00
|
|
|
RECT r;
|
2011-06-19 10:36:15 +00:00
|
|
|
POINT p;
|
2012-04-14 11:39:53 +00: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 10:54:01 +00:00
|
|
|
}
|
2011-06-19 10:36:15 +00:00
|
|
|
p.x = 0; p.y = 0;
|
2012-04-14 11:39:53 +00: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 10:36:15 +00:00
|
|
|
}
|
2013-03-04 21:41:27 +00:00
|
|
|
res = GetClientRect(WIN_ID_TO_HWND(vo->opts->WinID), &r);
|
2012-04-14 11:39:53 +00:00
|
|
|
if (res && (r.right != vo->dwidth || r.bottom != vo->dheight))
|
|
|
|
MoveWindow(w32->window, 0, 0, r.right, r.bottom, FALSE);
|
2013-03-05 16:40:57 +00:00
|
|
|
if (!IsWindow(WIN_ID_TO_HWND(vo->opts->WinID)))
|
2010-05-19 17:53:47 +00:00
|
|
|
// Window has probably been closed, e.g. due to program crash
|
2013-07-02 12:04:36 +00:00
|
|
|
mp_input_put_key(vo->input_ctx, MP_KEY_CLOSE_WIN);
|
2007-03-04 10:30:55 +00:00
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2012-04-14 11:39:53 +00:00
|
|
|
return w32->event_flags;
|
2003-09-19 14:33:51 +00:00
|
|
|
}
|
|
|
|
|
2012-04-14 11:39:53 +00: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 13:38:28 +00:00
|
|
|
// this defaults to the last screen if specified number does not exist
|
2013-03-04 16:40:21 +00:00
|
|
|
vo->xinerama_x = r->left;
|
|
|
|
vo->xinerama_y = r->top;
|
2013-03-04 21:41:27 +00:00
|
|
|
vo->opts->screenwidth = r->right - r->left;
|
|
|
|
vo->opts->screenheight = r->bottom - r->top;
|
2013-02-17 15:35:44 +00:00
|
|
|
if (w32->mon_cnt == w32->mon_id)
|
2006-04-16 13:38:28 +00:00
|
|
|
return FALSE;
|
2012-04-14 11:39:53 +00:00
|
|
|
w32->mon_cnt++;
|
2006-04-16 13:38:28 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-11-18 12:23:23 +00: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 12:07:41 +00:00
|
|
|
static void w32_update_xinerama_info(struct vo *vo)
|
2012-04-14 11:39:53 +00:00
|
|
|
{
|
|
|
|
struct vo_w32_state *w32 = vo->w32;
|
2013-03-04 21:41:27 +00:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
2013-07-18 12:05:39 +00:00
|
|
|
int screen = opts->fullscreen ? opts->fsscreen_id : opts->screen_id;
|
2013-03-04 16:40:21 +00:00
|
|
|
vo->xinerama_x = vo->xinerama_y = 0;
|
2013-07-18 12:05:39 +00:00
|
|
|
if (opts->fullscreen && screen == -2) {
|
2006-04-16 13:38:28 +00:00
|
|
|
int tmp;
|
2013-03-04 16:40:21 +00:00
|
|
|
vo->xinerama_x = GetSystemMetrics(SM_XVIRTUALSCREEN);
|
|
|
|
vo->xinerama_y = GetSystemMetrics(SM_YVIRTUALSCREEN);
|
2006-04-16 13:38:28 +00:00
|
|
|
tmp = GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
2013-03-04 21:41:27 +00:00
|
|
|
if (tmp) vo->opts->screenwidth = tmp;
|
2006-04-16 13:38:28 +00:00
|
|
|
tmp = GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
2013-03-04 21:41:27 +00:00
|
|
|
if (tmp) vo->opts->screenheight = tmp;
|
2013-02-17 15:35:44 +00:00
|
|
|
} else if (screen == -1) {
|
2006-04-16 13:38:28 +00:00
|
|
|
MONITORINFO mi;
|
2012-04-14 11:39:53 +00:00
|
|
|
HMONITOR m = MonitorFromWindow(w32->window, MONITOR_DEFAULTTOPRIMARY);
|
2006-04-16 13:38:28 +00:00
|
|
|
mi.cbSize = sizeof(mi);
|
2012-04-06 21:42:02 +00:00
|
|
|
GetMonitorInfoW(m, &mi);
|
2013-03-04 16:40:21 +00:00
|
|
|
vo->xinerama_x = mi.rcMonitor.left;
|
|
|
|
vo->xinerama_y = mi.rcMonitor.top;
|
2013-03-04 21:41:27 +00:00
|
|
|
vo->opts->screenwidth = mi.rcMonitor.right - mi.rcMonitor.left;
|
|
|
|
vo->opts->screenheight = mi.rcMonitor.bottom - mi.rcMonitor.top;
|
2013-02-17 15:35:44 +00:00
|
|
|
} else if (screen >= 0) {
|
2012-04-14 11:39:53 +00:00
|
|
|
w32->mon_cnt = 0;
|
2013-02-17 15:35:44 +00:00
|
|
|
w32->mon_id = screen;
|
2012-04-14 11:39:53 +00:00
|
|
|
EnumDisplayMonitors(NULL, NULL, mon_enum, (LONG_PTR)vo);
|
2006-04-16 13:38:28 +00:00
|
|
|
}
|
2013-03-04 21:41:27 +00:00
|
|
|
aspect_save_screenres(vo, vo->opts->screenwidth,
|
|
|
|
vo->opts->screenheight);
|
2006-04-16 13:38:28 +00:00
|
|
|
}
|
|
|
|
|
2012-04-14 11:39:53 +00:00
|
|
|
static void updateScreenProperties(struct vo *vo)
|
|
|
|
{
|
2005-02-21 14:44:39 +00: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)) {
|
2013-09-11 19:32:36 +00:00
|
|
|
MP_ERR(vo, "win32: unable to enumerate display settings!\n");
|
2007-03-04 10:39:02 +00:00
|
|
|
return;
|
2005-02-21 14:44:39 +00:00
|
|
|
}
|
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
vo->opts->screenwidth = dm.dmPelsWidth;
|
|
|
|
vo->opts->screenheight = dm.dmPelsHeight;
|
2012-04-14 11:39:53 +00:00
|
|
|
w32_update_xinerama_info(vo);
|
2005-02-21 14:44:39 +00:00
|
|
|
}
|
|
|
|
|
2012-04-14 11:39:53 +00: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-07-18 12:05:39 +00:00
|
|
|
style |= (vo->opts->border && !vo->opts->fullscreen) ? FRAME : NO_FRAME;
|
2012-04-14 11:39:53 +00:00
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
2011-12-07 00:36:19 +00:00
|
|
|
// Update the window title, position, size, and border style from vo_* values.
|
2012-04-14 11:39:53 +00:00
|
|
|
static int reinit_window_state(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_w32_state *w32 = vo->w32;
|
2003-11-30 16:36:10 +00:00
|
|
|
HWND layer = HWND_NOTOPMOST;
|
2005-11-17 20:49:46 +00:00
|
|
|
RECT r;
|
2003-09-19 14:33:51 +00:00
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
if (vo->opts->WinID >= 0)
|
2010-11-09 22:11:08 +00:00
|
|
|
return 1;
|
|
|
|
|
2013-07-18 12:05:39 +00:00
|
|
|
bool toggle_fs = w32->current_fs != vo->opts->fullscreen;
|
|
|
|
w32->current_fs = vo->opts->fullscreen;
|
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 00:11:14 +00:00
|
|
|
|
2012-04-14 11:39:53 +00: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 00:11:14 +00:00
|
|
|
|
2013-07-18 12:05:39 +00:00
|
|
|
if (vo->opts->fullscreen || 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 00:11:14 +00:00
|
|
|
layer = HWND_TOPMOST;
|
|
|
|
|
|
|
|
// xxx not sure if this can trigger any unwanted messages (WM_MOVE/WM_SIZE)
|
2012-04-14 11:39:53 +00: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 00:11:14 +00:00
|
|
|
|
2013-07-18 12:05:39 +00:00
|
|
|
if (vo->opts->fullscreen) {
|
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 00:11:14 +00:00
|
|
|
// Save window position and size when switching to fullscreen.
|
|
|
|
if (toggle_fs) {
|
2012-04-14 11:39:53 +00:00
|
|
|
w32->prev_width = vo->dwidth;
|
|
|
|
w32->prev_height = vo->dheight;
|
|
|
|
w32->prev_x = w32->window_x;
|
|
|
|
w32->prev_y = w32->window_y;
|
2013-09-11 19:32:36 +00:00
|
|
|
MP_VERBOSE(vo, "save window bounds: %d:%d:%d:%d\n",
|
2012-04-14 11:39:53 +00: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 00:11:14 +00:00
|
|
|
}
|
2013-03-04 21:41:27 +00:00
|
|
|
vo->dwidth = vo->opts->screenwidth;
|
|
|
|
vo->dheight = vo->opts->screenheight;
|
2013-03-04 16:40:21 +00:00
|
|
|
w32->window_x = vo->xinerama_x;
|
|
|
|
w32->window_y = vo->xinerama_y;
|
2006-04-12 14:11:26 +00: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 00:11:14 +00:00
|
|
|
if (toggle_fs) {
|
|
|
|
// Restore window position and size when switching from fullscreen.
|
2013-09-11 19:32:36 +00:00
|
|
|
MP_VERBOSE(vo, "restore window bounds: %d:%d:%d:%d\n",
|
2012-04-14 11:39:53 +00: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 00:11:14 +00:00
|
|
|
}
|
2006-04-12 14:11:26 +00: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 00:11:14 +00:00
|
|
|
|
2012-04-14 11:39:53 +00: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-17 23:59:48 +00:00
|
|
|
|
2012-04-14 11:39:53 +00: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 00:11:14 +00:00
|
|
|
|
2013-09-11 19:32:36 +00:00
|
|
|
MP_VERBOSE(vo, "reset window bounds: %d:%d:%d:%d\n",
|
2013-03-23 19:38:22 +00:00
|
|
|
(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 00:11:14 +00:00
|
|
|
|
2012-04-14 11:39:53 +00: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 00:11:14 +00: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 11:39:53 +00: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 00:11:14 +00:00
|
|
|
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
|
|
|
|
|
2003-09-19 14:33:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-11-18 12:23:23 +00: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 11:39:53 +00: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 22:10:30 +00:00
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
|
|
|
int pf;
|
2012-11-10 15:20:03 +00:00
|
|
|
HDC vo_hdc = GetDC(w32->window);
|
2010-11-10 22:10:30 +00: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 22:48:41 +00:00
|
|
|
if (flags & VOFLAG_STEREO)
|
|
|
|
pfd.dwFlags |= PFD_STEREO;
|
2010-11-10 22:10:30 +00:00
|
|
|
pfd.iPixelType = PFD_TYPE_RGBA;
|
|
|
|
pfd.cColorBits = 24;
|
|
|
|
pfd.iLayerType = PFD_MAIN_PLANE;
|
|
|
|
pf = ChoosePixelFormat(vo_hdc, &pfd);
|
|
|
|
if (!pf) {
|
2013-09-11 19:32:36 +00:00
|
|
|
MP_ERR(vo, "win32: unable to select a valid pixel format!\n");
|
2012-11-10 15:20:03 +00:00
|
|
|
ReleaseDC(w32->window, vo_hdc);
|
2010-11-10 22:10:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetPixelFormat(vo_hdc, pf, &pfd);
|
2012-11-10 15:20:03 +00:00
|
|
|
ReleaseDC(w32->window, vo_hdc);
|
2010-11-10 22:10:30 +00:00
|
|
|
|
2010-02-04 22:46:45 +00:00
|
|
|
// we already have a fully initialized window, so nothing needs to be done
|
|
|
|
if (flags & VOFLAG_HIDDEN)
|
2010-05-19 17:55:39 +00: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 00:11:14 +00:00
|
|
|
|
2012-04-14 11:39:53 +00: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 00:11:14 +00:00
|
|
|
|
2012-04-14 11:39:53 +00:00
|
|
|
w32->o_dwidth = width;
|
|
|
|
w32->o_dheight = height;
|
2006-04-12 14:11:26 +00: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 00:11:14 +00:00
|
|
|
// the desired size is ignored in wid mode, it always matches the window size.
|
2013-03-04 21:41:27 +00:00
|
|
|
if (vo->opts->WinID < 0) {
|
2012-04-14 11:39:53 +00: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 00:11:14 +00:00
|
|
|
// restore vo_dwidth/vo_dheight, which are reset against our will
|
|
|
|
// in vo_config()
|
|
|
|
RECT r;
|
2012-04-14 11:39:53 +00: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 00:11:14 +00: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 00:06:43 +00: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 00:11:14 +00:00
|
|
|
// window position instead)
|
2012-04-14 11:39:53 +00: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 00:11:14 +00:00
|
|
|
reset_size = true;
|
2012-04-14 11:39:53 +00: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 00:11:14 +00:00
|
|
|
}
|
|
|
|
if (reset_size) {
|
2012-04-14 11:39:53 +00: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 00:11:14 +00:00
|
|
|
}
|
2013-03-19 22:36:43 +00:00
|
|
|
} else {
|
|
|
|
RECT r;
|
|
|
|
GetClientRect(w32->window, &r);
|
|
|
|
vo->dwidth = r.right;
|
|
|
|
vo->dheight = r.bottom;
|
2008-12-03 10:38:50 +00:00
|
|
|
}
|
2006-04-12 14:11:26 +00:00
|
|
|
|
2012-04-14 11:39:53 +00:00
|
|
|
return reinit_window_state(vo);
|
2006-04-12 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
2008-11-18 12:23:23 +00: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 11:39:53 +00:00
|
|
|
int vo_w32_init(struct vo *vo)
|
|
|
|
{
|
2013-06-15 16:57:38 +00:00
|
|
|
assert(!vo->w32);
|
2003-09-19 14:33:51 +00:00
|
|
|
|
2013-06-15 16:57:38 +00:00
|
|
|
struct vo_w32_state *w32 = talloc_zero(vo, struct vo_w32_state);
|
|
|
|
vo->w32 = w32;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2012-04-14 11:39:53 +00:00
|
|
|
HINSTANCE hInstance = GetModuleHandleW(NULL);
|
|
|
|
|
2012-04-14 14:53:24 +00:00
|
|
|
HICON mplayerIcon = LoadIconW(hInstance, L"IDI_ICON1");
|
2003-09-19 14:33:51 +00:00
|
|
|
|
2012-04-14 11:39:53 +00:00
|
|
|
WNDCLASSEXW wcex = {
|
|
|
|
.cbSize = sizeof wcex,
|
|
|
|
.style = CS_OWNDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW,
|
|
|
|
.lpfnWndProc = WndProc,
|
|
|
|
.hInstance = hInstance,
|
|
|
|
.hIcon = mplayerIcon,
|
2013-07-14 12:57:39 +00:00
|
|
|
.hCursor = LoadCursor(NULL, IDC_ARROW),
|
2012-04-14 11:39:53 +00:00
|
|
|
.lpszClassName = classname,
|
|
|
|
.hIconSm = mplayerIcon,
|
|
|
|
};
|
2003-09-19 14:33:51 +00:00
|
|
|
|
2012-04-06 21:42:02 +00:00
|
|
|
if (!RegisterClassExW(&wcex)) {
|
2013-09-11 19:32:36 +00:00
|
|
|
MP_ERR(vo, "win32: unable to register window class!\n");
|
2007-03-04 10:39:02 +00:00
|
|
|
return 0;
|
2003-09-19 14:33:51 +00:00
|
|
|
}
|
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
if (vo->opts->WinID >= 0) {
|
2008-02-09 14:14:35 +00:00
|
|
|
RECT r;
|
2013-03-04 21:41:27 +00:00
|
|
|
GetClientRect(WIN_ID_TO_HWND(vo->opts->WinID), &r);
|
2012-04-14 11:39:53 +00: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 21:41:27 +00:00
|
|
|
WIN_ID_TO_HWND(vo->opts->WinID),
|
2013-03-04 16:40:21 +00:00
|
|
|
0, hInstance, vo);
|
2012-04-14 11:39:53 +00:00
|
|
|
} else {
|
|
|
|
w32->window = CreateWindowExW(0, classname,
|
|
|
|
classname,
|
|
|
|
update_style(vo, 0),
|
|
|
|
CW_USEDEFAULT, 0, 100, 100,
|
|
|
|
0, 0, hInstance, vo);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!w32->window) {
|
2013-09-11 19:32:36 +00:00
|
|
|
MP_ERR(vo, "win32: unable to create window!\n");
|
2007-03-04 10:39:02 +00:00
|
|
|
return 0;
|
2003-09-19 14:33:51 +00:00
|
|
|
}
|
|
|
|
|
2013-07-25 17:47:49 +00:00
|
|
|
w32->tracking = FALSE;
|
|
|
|
w32->trackEvent = (TRACKMOUSEEVENT){
|
|
|
|
.cbSize = sizeof(TRACKMOUSEEVENT),
|
|
|
|
.dwFlags = TME_LEAVE,
|
|
|
|
.hwndTrack = w32->window,
|
|
|
|
};
|
2013-07-25 17:19:12 +00:00
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
if (vo->opts->WinID >= 0)
|
2012-04-14 11:39:53 +00:00
|
|
|
EnableWindow(w32->window, 0);
|
2013-07-14 12:57:39 +00:00
|
|
|
w32->cursor_visible = true;
|
2012-04-14 11:39:53 +00:00
|
|
|
|
2012-12-19 11:58:52 +00:00
|
|
|
// we don't have proper event handling
|
|
|
|
vo->wakeup_period = 0.02;
|
|
|
|
|
2012-04-14 11:39:53 +00:00
|
|
|
updateScreenProperties(vo);
|
2003-09-19 14:33:51 +00:00
|
|
|
|
2013-09-11 19:32:36 +00:00
|
|
|
MP_VERBOSE(vo, "win32: running at %dx%d\n",
|
2013-03-04 21:41:27 +00:00
|
|
|
vo->opts->screenwidth, vo->opts->screenheight);
|
2010-02-04 22:46:01 +00:00
|
|
|
|
2003-09-19 14:33:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-11-18 12:23:23 +00:00
|
|
|
/**
|
|
|
|
* \brief Toogle fullscreen / windowed mode.
|
|
|
|
*
|
|
|
|
* Should be called on VOCTRL_FULLSCREEN event. The window is
|
2012-04-14 11:39:53 +00:00
|
|
|
* always resized during this call, so the rendering context
|
2008-11-18 12:23:23 +00: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 12:07:41 +00:00
|
|
|
static void vo_w32_fullscreen(struct vo *vo)
|
2012-04-14 11:39:53 +00:00
|
|
|
{
|
2013-07-18 12:05:39 +00:00
|
|
|
if (vo->opts->fullscreen != vo->w32->current_fs)
|
|
|
|
reinit_window_state(vo);
|
2003-09-19 14:33:51 +00:00
|
|
|
}
|
|
|
|
|
2008-11-18 12:23:23 +00:00
|
|
|
/**
|
|
|
|
* \brief Toogle window border attribute.
|
|
|
|
*
|
|
|
|
* Should be called on VOCTRL_BORDER event.
|
|
|
|
*/
|
2013-05-16 12:07:41 +00:00
|
|
|
static void vo_w32_border(struct vo *vo)
|
2012-04-14 11:39:53 +00:00
|
|
|
{
|
2013-03-05 16:40:57 +00:00
|
|
|
vo->opts->border = !vo->opts->border;
|
2012-04-14 11:39:53 +00:00
|
|
|
reinit_window_state(vo);
|
2005-11-17 20:49:46 +00:00
|
|
|
}
|
|
|
|
|
2008-11-18 12:23:23 +00:00
|
|
|
/**
|
|
|
|
* \brief Toogle window ontop attribute.
|
|
|
|
*
|
|
|
|
* Should be called on VOCTRL_ONTOP event.
|
|
|
|
*/
|
2013-05-16 12:07:41 +00:00
|
|
|
static void vo_w32_ontop(struct vo *vo)
|
2003-11-30 16:36:10 +00:00
|
|
|
{
|
2013-03-04 21:41:27 +00:00
|
|
|
vo->opts->ontop = !vo->opts->ontop;
|
2012-04-14 11:39:53 +00:00
|
|
|
reinit_window_state(vo);
|
2003-11-30 16:36:10 +00:00
|
|
|
}
|
|
|
|
|
2013-07-14 12:57:39 +00:00
|
|
|
static bool vo_w32_is_cursor_in_client(struct vo *vo)
|
|
|
|
{
|
|
|
|
DWORD pos = GetMessagePos();
|
|
|
|
return SendMessage(vo->w32->window, WM_NCHITTEST, 0, pos) == HTCLIENT;
|
|
|
|
}
|
|
|
|
|
2013-05-15 16:17:18 +00:00
|
|
|
int vo_w32_control(struct vo *vo, int *events, int request, void *arg)
|
|
|
|
{
|
2013-06-13 22:36:43 +00:00
|
|
|
struct vo_w32_state *w32 = vo->w32;
|
2013-05-15 16:17:18 +00:00
|
|
|
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-16 22:10:46 +00:00
|
|
|
case VOCTRL_SET_CURSOR_VISIBILITY:
|
2013-07-14 12:57:39 +00:00
|
|
|
w32->cursor_visible = *(bool *)arg;
|
|
|
|
|
|
|
|
if (vo_w32_is_cursor_in_client(vo)) {
|
|
|
|
if (w32->cursor_visible)
|
|
|
|
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
|
|
|
else
|
|
|
|
SetCursor(NULL);
|
2013-05-16 22:10:46 +00:00
|
|
|
}
|
2013-06-15 16:54:01 +00:00
|
|
|
return VO_TRUE;
|
2013-06-13 22:36:43 +00:00
|
|
|
case VOCTRL_KILL_SCREENSAVER:
|
|
|
|
w32->disable_screensaver = true;
|
2013-06-27 02:27:34 +00:00
|
|
|
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED);
|
2013-06-15 16:54:01 +00:00
|
|
|
return VO_TRUE;
|
2013-06-13 22:36:43 +00:00
|
|
|
case VOCTRL_RESTORE_SCREENSAVER:
|
|
|
|
w32->disable_screensaver = false;
|
2013-06-27 02:27:34 +00:00
|
|
|
SetThreadExecutionState(ES_CONTINUOUS);
|
2013-06-15 16:54:01 +00:00
|
|
|
return VO_TRUE;
|
2013-06-15 17:04:20 +00:00
|
|
|
case VOCTRL_UPDATE_WINDOW_TITLE: {
|
|
|
|
wchar_t *title = mp_from_utf8(NULL, (char *)arg);
|
|
|
|
SetWindowTextW(w32->window, title);
|
|
|
|
talloc_free(title);
|
|
|
|
return VO_TRUE;
|
|
|
|
}
|
2013-05-15 16:17:18 +00:00
|
|
|
}
|
|
|
|
return VO_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2008-11-18 12:23:23 +00:00
|
|
|
/**
|
|
|
|
* \brief Uninitialize w32_common framework.
|
|
|
|
*
|
|
|
|
* Should be called last in video driver's uninit function. First release
|
2008-11-21 19:32:19 +00:00
|
|
|
* anything built on top of the created window e.g. rendering context inside
|
2008-11-18 12:23:23 +00:00
|
|
|
* and call vo_w32_uninit at the end.
|
|
|
|
*/
|
2012-04-14 11:39:53 +00:00
|
|
|
void vo_w32_uninit(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_w32_state *w32 = vo->w32;
|
2013-09-11 19:32:36 +00:00
|
|
|
MP_VERBOSE(vo, "win32: uninit\n");
|
2012-04-23 22:41:12 +00:00
|
|
|
if (!w32)
|
|
|
|
return;
|
2013-06-27 02:27:34 +00:00
|
|
|
SetThreadExecutionState(ES_CONTINUOUS);
|
2012-04-14 11:39:53 +00:00
|
|
|
DestroyWindow(w32->window);
|
2012-04-06 21:42:02 +00:00
|
|
|
UnregisterClassW(classname, 0);
|
2012-04-14 11:39:53 +00:00
|
|
|
talloc_free(w32);
|
|
|
|
vo->w32 = NULL;
|
2003-09-19 14:33:51 +00:00
|
|
|
}
|