/*
* This file is part of mpv.
*
* mpv 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.
*
* mpv 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 mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#include <initguid.h>
#include <stdio.h>
#include <limits.h>
#include <pthread.h>
#include <assert.h>
#include <windows.h>
#include <windowsx.h>
#include <ole2.h>
#include <shobjidl.h>
#include <avrt.h>
#include "options/options.h"
#include "input/keycodes.h"
#include "input/input.h"
#include "input/event.h"
#include "stream/stream.h"
#include "common/msg.h"
#include "common/common.h"
#include "vo.h"
#include "win_state.h"
#include "w32_common.h"
#include "win32/displayconfig.h"
#include "osdep/io.h"
#include "osdep/threads.h"
#include "osdep/w32_keyboard.h"
#include "osdep/atomics.h"
#include "misc/dispatch.h"
#include "misc/rendezvous.h"
#include "mpv_talloc.h"
static const wchar_t classname[] = L"mpv";
static __thread struct vo_w32_state *w32_thread_context;
struct vo_w32_state {
struct mp_log *log;
struct vo *vo;
struct mp_vo_opts *opts;
struct input_ctx *input_ctx;
pthread_t thread;
bool terminate;
struct mp_dispatch_queue *dispatch; // used to run stuff on the GUI thread
HWND window;
HWND parent; // 0 normally, set in embedding mode
HMONITOR monitor; // Handle of the current screen
struct mp_rect screenrc; // Size and virtual position of the current screen
char *color_profile; // Path of the current screen's color profile
// last non-fullscreen extends (updated only on fullscreen or on initialization)
int prev_width;
int prev_height;
int prev_x;
int prev_y;
// Has the window seen a WM_DESTROY? If so, don't call DestroyWindow again.
bool destroyed;
// whether the window position and size were intialized
bool window_bounds_initialized;
bool current_fs;
// currently known window state
int window_x;
int window_y;
int dw;
int dh;
// video size
uint32_t o_dwidth;
uint32_t o_dheight;
bool disable_screensaver;
bool cursor_visible;
int event_flags;
BOOL tracking;
TRACKMOUSEEVENT trackEvent;
int mouse_x;
int mouse_y;
// Should SetCursor be called when handling VOCTRL_SET_CURSOR_VISIBILITY?
bool can_set_cursor;
// UTF-16 decoding state for WM_CHAR and VK_PACKET
int high_surrogate;
ITaskbarList2 *taskbar_list;
ITaskbarList3 *taskbar_list3;
UINT tbtnCreatedMsg;
bool tbtnCreated;
// updates on move/resize/displaychange
double display_fps;
HANDLE avrt_handle;
};
typedef struct tagDropTarget {
IDropTarget iface;
atomic_int refCnt;
DWORD lastEffect;
IDataObject* dataObj;
struct vo_w32_state *w32;
} DropTarget;
static FORMATETC fmtetc_file = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
static FORMATETC fmtetc_url = { 0, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
static void DropTarget_Destroy(DropTarget* This)
{
if (This->dataObj != NULL) {
This->dataObj->lpVtbl->Release(This->dataObj);
This->dataObj->lpVtbl = NULL;
}
talloc_free(This);
}
static HRESULT STDMETHODCALLTYPE DropTarget_QueryInterface(IDropTarget* This,
REFIID riid,
void** ppvObject)
{
if (!IsEqualGUID(riid, &IID_IUnknown) ||
!IsEqualGUID(riid, &IID_IDataObject)) {
*ppvObject = NULL;
return E_NOINTERFACE;
}
*ppvObject = This;
This->lpVtbl->AddRef(This);
return S_OK;
}
static ULONG STDMETHODCALLTYPE DropTarget_AddRef(IDropTarget* This)
{
DropTarget* t = (DropTarget*)This;
return atomic_fetch_add(&t->refCnt, 1) + 1;
}
static ULONG STDMETHODCALLTYPE DropTarget_Release(IDropTarget* This)
{
DropTarget* t = (DropTarget*)This;
ULONG cRef = atomic_fetch_add(&t->refCnt, -1) - 1;
if (cRef == 0) {
DropTarget_Destroy(t);
}
return cRef;
}
static HRESULT STDMETHODCALLTYPE DropTarget_DragEnter(IDropTarget* This,
IDataObject* pDataObj,
DWORD grfKeyState,
POINTL pt,
DWORD* pdwEffect)
{
DropTarget* t = (DropTarget*)This;
pDataObj->lpVtbl->AddRef(pDataObj);
if (pDataObj->lpVtbl->QueryGetData(pDataObj, &fmtetc_file) != S_OK &&
pDataObj->lpVtbl->QueryGetData(pDataObj, &fmtetc_url) != S_OK) {
*pdwEffect = DROPEFFECT_NONE;
}
if (t->dataObj != NULL) {
t->dataObj->lpVtbl->Release(t->dataObj);
}
t->dataObj = pDataObj;
t->lastEffect = *pdwEffect;
return S_OK;
}
static HRESULT STDMETHODCALLTYPE DropTarget_DragOver(IDropTarget* This,
DWORD grfKeyState,
POINTL pt,
DWORD* pdwEffect)
{
DropTarget* t = (DropTarget*)This;
*pdwEffect = t->lastEffect;
return S_OK;
}
static HRESULT STDMETHODCALLTYPE DropTarget_DragLeave(IDropTarget* This)
{
DropTarget* t = (DropTarget*)This;
if (t->dataObj != NULL) {
t->dataObj->lpVtbl->Release(t->dataObj);
t->dataObj = NULL;
}
return S_OK;
}
static HRESULT STDMETHODCALLTYPE DropTarget_Drop(IDropTarget* This,
IDataObject* pDataObj,
DWORD grfKeyState, POINTL p
|