2015-01-15 18:37:43 +01:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2017-01-22 13:40:32 +01:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2016-12-02 23:36:23 -05:00
|
|
|
*
|
2015-01-15 18:37:43 +01:00
|
|
|
* RetroArch 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 Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch 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 RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-03-04 04:51:57 +01:00
|
|
|
#include <retro_miscellaneous.h>
|
2016-06-03 19:45:58 +02:00
|
|
|
#include <string/stdstring.h>
|
2016-03-04 04:51:57 +01:00
|
|
|
|
2016-09-08 08:15:40 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
|
|
|
|
2016-09-11 14:54:34 +02:00
|
|
|
#include "win32_common.h"
|
2016-03-04 05:01:49 +01:00
|
|
|
#include "../../frontend/frontend_driver.h"
|
2016-09-05 18:43:06 +02:00
|
|
|
#include "../../configuration.h"
|
2015-11-23 12:14:53 +01:00
|
|
|
#include "../../verbosity.h"
|
2016-06-03 09:14:53 +10:00
|
|
|
#include "../../driver.h"
|
2016-09-17 15:07:45 +02:00
|
|
|
#include "../../paths.h"
|
2017-05-11 09:11:46 +02:00
|
|
|
#include "../../retroarch.h"
|
2016-06-03 09:14:53 +10:00
|
|
|
#include "../../tasks/tasks_internal.h"
|
2016-06-03 16:00:08 +10:00
|
|
|
#include "../../core_info.h"
|
2015-01-15 18:37:43 +01:00
|
|
|
|
2015-09-05 14:40:01 +02:00
|
|
|
#if !defined(_XBOX)
|
2015-04-09 05:16:02 +02:00
|
|
|
|
2015-11-11 18:29:06 +01:00
|
|
|
#define IDI_ICON 1
|
|
|
|
|
2015-04-09 05:16:02 +02:00
|
|
|
#ifndef _WIN32_WINNT
|
2016-06-03 08:21:56 +02:00
|
|
|
#define _WIN32_WINNT 0x0500 /*_WIN32_WINNT_WIN2K */
|
2015-04-09 05:16:02 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <commdlg.h>
|
2015-01-15 18:37:43 +01:00
|
|
|
#include "../../retroarch.h"
|
2015-11-11 19:48:24 +01:00
|
|
|
#include "../video_thread_wrapper.h"
|
2016-09-15 20:54:05 +02:00
|
|
|
#include <shellapi.h>
|
2017-01-12 15:03:27 -05:00
|
|
|
|
|
|
|
#ifdef HAVE_MENU
|
|
|
|
#include "../../menu/menu_driver.h"
|
|
|
|
#endif
|
|
|
|
|
2015-11-19 08:20:16 +01:00
|
|
|
#ifndef _MSC_VER
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-11-29 12:53:38 -05:00
|
|
|
#include <encodings/utf.h>
|
|
|
|
|
2015-11-19 08:20:16 +01:00
|
|
|
LRESULT win32_menu_loop(HWND owner, WPARAM wparam);
|
|
|
|
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-13 14:31:36 -05:00
|
|
|
#ifdef HAVE_D3D9
|
2016-11-06 11:52:03 +01:00
|
|
|
extern "C" bool dinput_handle_message(void *dinput, UINT message,
|
|
|
|
WPARAM wParam, LPARAM lParam);
|
2017-01-04 02:07:19 -05:00
|
|
|
extern void *dinput_gdi;
|
2015-11-11 18:29:06 +01:00
|
|
|
extern void *dinput_wgl;
|
2015-11-11 19:48:24 +01:00
|
|
|
extern void *dinput;
|
2017-01-13 14:31:36 -05:00
|
|
|
#endif
|
2015-11-11 18:26:10 +01:00
|
|
|
|
2016-11-06 11:52:03 +01:00
|
|
|
unsigned g_resize_width = 0;
|
|
|
|
unsigned g_resize_height = 0;
|
|
|
|
static bool g_resized = false;
|
|
|
|
bool g_restore_desktop = false;
|
|
|
|
static bool doubleclick_on_titlebar = false;
|
|
|
|
bool g_inited = false;
|
|
|
|
static bool g_quit = false;
|
|
|
|
static unsigned g_pos_x = CW_USEDEFAULT;
|
|
|
|
static unsigned g_pos_y = CW_USEDEFAULT;
|
|
|
|
static void *curD3D = NULL;
|
|
|
|
|
|
|
|
ui_window_win32_t main_window;
|
|
|
|
|
2015-10-10 08:13:58 +02:00
|
|
|
/* Power Request APIs */
|
|
|
|
|
2006-01-17 04:36:32 +01:00
|
|
|
#if !defined(_XBOX) && (_MSC_VER == 1310)
|
2016-12-02 23:36:23 -05:00
|
|
|
typedef struct _REASON_CONTEXT
|
2006-01-17 04:36:32 +01:00
|
|
|
{
|
|
|
|
ULONG Version;
|
|
|
|
DWORD Flags;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
HMODULE LocalizedReasonModule;
|
|
|
|
ULONG LocalizedreasonId;
|
|
|
|
ULONG ReasonStringCount;
|
|
|
|
LPWSTR *ReasonStrings;
|
|
|
|
} Detailed;
|
|
|
|
LPWSTR SimpleReasonString;
|
|
|
|
} Reason;
|
|
|
|
} REASON_CONTEXT, *PREASON_CONTEXT;
|
|
|
|
|
|
|
|
typedef enum _POWER_REQUEST_TYPE
|
|
|
|
{
|
|
|
|
PowerRequestDisplayRequired,
|
|
|
|
PowerRequestSystemRequired,
|
|
|
|
PowerRequestAwayModeRequired,
|
|
|
|
PowerRequestExecutionRequired
|
|
|
|
} POWER_REQUEST_TYPE, *PPOWER_REQUEST_TYPE;
|
|
|
|
|
|
|
|
#define POWER_REQUEST_CONTEXT_VERSION 0
|
|
|
|
#define POWER_REQUEST_CONTEXT_SIMPLE_STRING 1
|
|
|
|
#define POWER_REQUEST_CONTEXT_DETAILED_STRING 2
|
|
|
|
#endif
|
|
|
|
|
2017-01-14 04:06:56 -05:00
|
|
|
#ifdef _WIN32_WINNT_WIN7
|
2016-01-18 18:05:49 +01:00
|
|
|
typedef REASON_CONTEXT POWER_REQUEST_CONTEXT, *PPOWER_REQUEST_CONTEXT, *LPPOWER_REQUEST_CONTEXT;
|
2017-01-14 04:06:56 -05:00
|
|
|
#endif
|
2015-11-11 17:36:52 +01:00
|
|
|
|
|
|
|
#ifndef MAX_MONITORS
|
|
|
|
#define MAX_MONITORS 9
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static HMONITOR win32_monitor_last;
|
|
|
|
static HMONITOR win32_monitor_all[MAX_MONITORS];
|
2016-12-04 03:45:46 +01:00
|
|
|
static unsigned win32_monitor_count = 0;
|
2015-11-11 17:36:52 +01:00
|
|
|
|
2016-07-16 17:56:07 +02:00
|
|
|
extern "C"
|
|
|
|
{
|
2017-01-16 20:40:43 -05:00
|
|
|
bool doubleclick_on_titlebar_pressed(void)
|
|
|
|
{
|
|
|
|
return doubleclick_on_titlebar;
|
|
|
|
}
|
2016-07-16 17:56:07 +02:00
|
|
|
|
2016-11-06 11:52:03 +01:00
|
|
|
void unset_doubleclick_on_titlebar(void)
|
|
|
|
{
|
|
|
|
doubleclick_on_titlebar = false;
|
|
|
|
}
|
2016-07-16 17:56:07 +02:00
|
|
|
};
|
|
|
|
|
2016-12-02 23:36:23 -05:00
|
|
|
INT_PTR CALLBACK PickCoreProc(HWND hDlg, UINT message,
|
2016-06-03 16:00:08 +10:00
|
|
|
WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2016-06-03 08:23:43 +02:00
|
|
|
size_t list_size;
|
|
|
|
core_info_list_t *core_info_list = NULL;
|
|
|
|
const core_info_t *core_info = NULL;
|
|
|
|
|
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
HWND hwndList;
|
|
|
|
unsigned i;
|
|
|
|
/* Add items to list. */
|
|
|
|
|
|
|
|
core_info_get_list(&core_info_list);
|
|
|
|
core_info_list_get_supported_cores(core_info_list,
|
2016-10-03 15:43:03 +02:00
|
|
|
path_get(RARCH_PATH_CONTENT), &core_info, &list_size);
|
2016-06-03 08:23:43 +02:00
|
|
|
|
2016-12-02 23:36:23 -05:00
|
|
|
hwndList = GetDlgItem(hDlg, ID_CORELISTBOX);
|
2016-06-03 08:23:43 +02:00
|
|
|
|
|
|
|
for (i = 0; i < list_size; i++)
|
2016-06-03 16:00:08 +10:00
|
|
|
{
|
2016-06-03 08:23:43 +02:00
|
|
|
const core_info_t *info = (const core_info_t*)&core_info[i];
|
2016-12-02 23:36:23 -05:00
|
|
|
SendMessage(hwndList, LB_ADDSTRING, 0,
|
|
|
|
(LPARAM)info->display_name);
|
2016-06-03 16:00:08 +10:00
|
|
|
}
|
2016-12-02 23:36:23 -05:00
|
|
|
SetFocus(hwndList);
|
|
|
|
return TRUE;
|
2016-06-03 08:23:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case IDOK:
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hDlg, LOWORD(wParam));
|
2016-11-06 11:52:03 +01:00
|
|
|
break;
|
2016-06-03 08:23:43 +02:00
|
|
|
case ID_CORELISTBOX:
|
2016-12-02 23:36:23 -05:00
|
|
|
switch (HIWORD(wParam))
|
|
|
|
{
|
2016-11-06 11:52:03 +01:00
|
|
|
case LBN_SELCHANGE:
|
|
|
|
{
|
|
|
|
int lbItem;
|
|
|
|
const core_info_t *info = NULL;
|
2016-12-02 23:36:23 -05:00
|
|
|
HWND hwndList = GetDlgItem(hDlg, ID_CORELISTBOX);
|
|
|
|
lbItem = (int)SendMessage(hwndList, LB_GETCURSEL, 0, 0);
|
2016-11-06 11:52:03 +01:00
|
|
|
core_info_get_list(&core_info_list);
|
|
|
|
core_info_list_get_supported_cores(core_info_list,
|
|
|
|
path_get(RARCH_PATH_CONTENT), &core_info, &list_size);
|
|
|
|
info = (const core_info_t*)&core_info[lbItem];
|
2017-05-15 05:06:23 +02:00
|
|
|
rarch_ctl(RARCH_CTL_SET_LIBRETRO_PATH,info->path);
|
2016-12-02 23:36:23 -05:00
|
|
|
}
|
2016-11-06 11:52:03 +01:00
|
|
|
break;
|
2016-06-03 08:23:43 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
2016-06-03 16:00:08 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-11 17:36:52 +01:00
|
|
|
static BOOL CALLBACK win32_monitor_enum_proc(HMONITOR hMonitor,
|
|
|
|
HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
|
|
|
|
{
|
|
|
|
win32_monitor_all[win32_monitor_count++] = hMonitor;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-04 05:54:33 +02:00
|
|
|
void win32_monitor_from_window(void)
|
2015-11-11 17:36:52 +01:00
|
|
|
{
|
2015-11-17 10:49:36 +01:00
|
|
|
#ifndef _XBOX
|
2016-06-04 05:58:03 +02:00
|
|
|
win32_monitor_last = MonitorFromWindow(main_window.hwnd, MONITOR_DEFAULTTONEAREST);
|
2016-06-06 08:01:26 +02:00
|
|
|
const ui_window_t *window = ui_companion_driver_get_window_ptr();
|
|
|
|
|
|
|
|
if (window)
|
|
|
|
window->destroy(&main_window);
|
2015-11-17 10:49:36 +01:00
|
|
|
#endif
|
2015-11-11 17:36:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void win32_monitor_get_info(void)
|
|
|
|
{
|
2016-12-03 00:14:33 -05:00
|
|
|
MONITORINFOEX current_mon;
|
2015-11-11 17:36:52 +01:00
|
|
|
|
|
|
|
memset(¤t_mon, 0, sizeof(current_mon));
|
2016-12-03 00:14:33 -05:00
|
|
|
current_mon.cbSize = sizeof(MONITORINFOEX);
|
2015-11-11 17:36:52 +01:00
|
|
|
|
2016-12-03 00:14:33 -05:00
|
|
|
GetMonitorInfo(win32_monitor_last, (MONITORINFOEX*)¤t_mon);
|
|
|
|
ChangeDisplaySettingsEx(current_mon.szDevice, NULL, NULL, 0, NULL);
|
2015-11-11 17:36:52 +01:00
|
|
|
}
|
|
|
|
|
2015-11-11 17:47:56 +01:00
|
|
|
void win32_monitor_info(void *data, void *hm_data, unsigned *mon_id)
|
2015-11-11 17:36:52 +01:00
|
|
|
{
|
2015-11-11 17:47:56 +01:00
|
|
|
unsigned i, fs_monitor;
|
2015-11-11 17:36:52 +01:00
|
|
|
settings_t *settings = config_get_ptr();
|
2016-12-03 00:14:33 -05:00
|
|
|
MONITORINFOEX *mon = (MONITORINFOEX*)data;
|
2015-11-11 17:36:52 +01:00
|
|
|
HMONITOR *hm_to_use = (HMONITOR*)hm_data;
|
|
|
|
|
|
|
|
if (!win32_monitor_last)
|
2016-11-06 11:52:03 +01:00
|
|
|
win32_monitor_last = MonitorFromWindow(GetDesktopWindow(),
|
|
|
|
MONITOR_DEFAULTTONEAREST);
|
2015-11-11 17:36:52 +01:00
|
|
|
|
|
|
|
*hm_to_use = win32_monitor_last;
|
2017-04-28 21:03:04 +02:00
|
|
|
fs_monitor = settings->uints.video_monitor_index;
|
2015-11-11 17:36:52 +01:00
|
|
|
|
|
|
|
if (fs_monitor && fs_monitor <= win32_monitor_count
|
|
|
|
&& win32_monitor_all[fs_monitor - 1])
|
2015-11-11 17:47:56 +01:00
|
|
|
{
|
2015-11-11 17:36:52 +01:00
|
|
|
*hm_to_use = win32_monitor_all[fs_monitor - 1];
|
2015-11-11 17:47:56 +01:00
|
|
|
*mon_id = fs_monitor - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < win32_monitor_count; i++)
|
|
|
|
{
|
|
|
|
if (win32_monitor_all[i] != *hm_to_use)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
*mon_id = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-11-11 17:36:52 +01:00
|
|
|
|
|
|
|
memset(mon, 0, sizeof(*mon));
|
2016-12-03 00:14:33 -05:00
|
|
|
mon->cbSize = sizeof(MONITORINFOEX);
|
|
|
|
GetMonitorInfo(*hm_to_use, (MONITORINFOEX*)mon);
|
2015-11-11 17:36:52 +01:00
|
|
|
}
|
2015-11-19 07:53:00 +01:00
|
|
|
|
2016-06-04 03:20:55 +02:00
|
|
|
/* Get the count of the files dropped */
|
|
|
|
static int win32_drag_query_file(HWND hwnd, WPARAM wparam)
|
|
|
|
{
|
2016-12-17 14:40:06 +01:00
|
|
|
char szFilename[1024];
|
|
|
|
|
|
|
|
szFilename[0] = '\0';
|
2016-06-04 03:20:55 +02:00
|
|
|
|
2016-12-03 00:14:33 -05:00
|
|
|
if (DragQueryFile((HDROP)wparam, 0xFFFFFFFF, NULL, 0))
|
2016-06-04 03:20:55 +02:00
|
|
|
{
|
|
|
|
/*poll list of current cores */
|
|
|
|
size_t list_size;
|
|
|
|
content_ctx_info_t content_info = {0};
|
|
|
|
core_info_list_t *core_info_list = NULL;
|
|
|
|
const core_info_t *core_info = NULL;
|
2016-12-02 23:36:23 -05:00
|
|
|
|
2016-12-03 00:14:33 -05:00
|
|
|
DragQueryFile((HDROP)wparam, 0, szFilename, sizeof(szFilename));
|
2016-12-02 23:36:23 -05:00
|
|
|
|
2016-06-04 03:20:55 +02:00
|
|
|
core_info_get_list(&core_info_list);
|
2016-07-16 23:00:35 +02:00
|
|
|
|
2017-01-16 20:40:43 -05:00
|
|
|
if (!core_info_list)
|
|
|
|
return 0;
|
2016-07-16 23:00:35 +02:00
|
|
|
|
2016-06-04 03:20:55 +02:00
|
|
|
core_info_list_get_supported_cores(core_info_list,
|
|
|
|
(const char*)szFilename, &core_info, &list_size);
|
|
|
|
|
2016-09-07 09:44:07 +10:00
|
|
|
if (!list_size)
|
|
|
|
return 0;
|
|
|
|
|
2016-10-01 09:49:15 +02:00
|
|
|
path_set(RARCH_PATH_CONTENT, szFilename);
|
2016-06-04 03:20:55 +02:00
|
|
|
|
2016-10-01 09:49:15 +02:00
|
|
|
if (!path_is_empty(RARCH_PATH_CONTENT))
|
2016-06-04 03:20:55 +02:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
core_info_t *current_core = NULL;
|
|
|
|
core_info_get_current_core(¤t_core);
|
|
|
|
|
|
|
|
/*we already have path for libretro core */
|
|
|
|
for (i = 0; i < list_size; i++)
|
|
|
|
{
|
|
|
|
const core_info_t *info = (const core_info_t*)&core_info[i];
|
|
|
|
|
2016-07-16 23:13:24 +02:00
|
|
|
if(!string_is_equal(info->systemname, current_core->systemname))
|
2016-06-04 03:20:55 +02:00
|
|
|
break;
|
|
|
|
|
2016-09-29 08:23:41 +02:00
|
|
|
if(string_is_equal(path_get(RARCH_PATH_CORE), info->path))
|
2016-06-04 03:20:55 +02:00
|
|
|
{
|
|
|
|
/* Our previous core supports the current rom */
|
|
|
|
content_ctx_info_t content_info = {0};
|
2017-02-21 17:32:22 +01:00
|
|
|
task_push_load_content_with_current_core_from_companion_ui(
|
2017-02-21 17:29:30 +01:00
|
|
|
NULL,
|
2016-06-04 03:20:55 +02:00
|
|
|
&content_info,
|
|
|
|
CORE_TYPE_PLAIN,
|
|
|
|
NULL, NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Poll for cores for current rom since none exist. */
|
|
|
|
if(list_size ==1)
|
|
|
|
{
|
|
|
|
/*pick core that only exists and is bound to work. Ish. */
|
|
|
|
const core_info_t *info = (const core_info_t*)&core_info[0];
|
2016-07-16 23:16:30 +02:00
|
|
|
|
|
|
|
if (info)
|
2017-02-21 18:58:03 +01:00
|
|
|
task_push_load_content_with_new_core_from_companion_ui(
|
2016-07-16 23:16:30 +02:00
|
|
|
info->path, NULL,
|
|
|
|
&content_info,
|
|
|
|
NULL, NULL);
|
2016-06-04 03:20:55 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Pick one core that could be compatible, ew */
|
2016-12-03 00:14:33 -05:00
|
|
|
if(DialogBoxParam(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_PICKCORE),
|
2016-12-02 23:36:23 -05:00
|
|
|
hwnd,PickCoreProc,(LPARAM)NULL)==IDOK)
|
2016-06-04 03:20:55 +02:00
|
|
|
{
|
2017-02-21 17:32:22 +01:00
|
|
|
task_push_load_content_with_current_core_from_companion_ui(
|
2017-02-21 17:29:30 +01:00
|
|
|
NULL,
|
2016-06-04 03:20:55 +02:00
|
|
|
&content_info,
|
|
|
|
CORE_TYPE_PLAIN,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-20 19:46:27 +02:00
|
|
|
static LRESULT win32_handle_keyboard_event(HWND hwnd, UINT message,
|
|
|
|
WPARAM wparam, LPARAM lparam)
|
|
|
|
{
|
|
|
|
unsigned scancode = (lparam >> 16) & 0xff;
|
|
|
|
unsigned keycode = input_keymaps_translate_keysym_to_rk(scancode);
|
|
|
|
uint16_t mod = 0;
|
|
|
|
bool keydown = true;
|
|
|
|
|
|
|
|
if (GetKeyState(VK_SHIFT) & 0x80)
|
|
|
|
mod |= RETROKMOD_SHIFT;
|
|
|
|
if (GetKeyState(VK_CONTROL) & 0x80)
|
|
|
|
mod |= RETROKMOD_CTRL;
|
|
|
|
if (GetKeyState(VK_MENU) & 0x80)
|
|
|
|
mod |= RETROKMOD_ALT;
|
|
|
|
if (GetKeyState(VK_CAPITAL) & 0x81)
|
|
|
|
mod |= RETROKMOD_CAPSLOCK;
|
|
|
|
if (GetKeyState(VK_SCROLL) & 0x81)
|
|
|
|
mod |= RETROKMOD_SCROLLOCK;
|
|
|
|
if ((GetKeyState(VK_LWIN) | GetKeyState(VK_RWIN)) & 0x80)
|
|
|
|
mod |= RETROKMOD_META;
|
|
|
|
|
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
/* Seems to be hard to synchronize
|
|
|
|
* WM_CHAR and WM_KEYDOWN properly.
|
|
|
|
*/
|
|
|
|
case WM_CHAR:
|
|
|
|
input_keyboard_event(keydown, RETROK_UNKNOWN, wparam, mod,
|
|
|
|
RETRO_DEVICE_KEYBOARD);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_KEYUP:
|
|
|
|
case WM_SYSKEYUP:
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
/* Key released? */
|
|
|
|
if (message == WM_KEYUP || message == WM_SYSKEYUP)
|
|
|
|
keydown = false;
|
|
|
|
|
|
|
|
/* DirectInput uses scancodes directly. */
|
|
|
|
input_keyboard_event(keydown, keycode, 0, mod,
|
|
|
|
RETRO_DEVICE_KEYBOARD);
|
|
|
|
|
|
|
|
if (message == WM_SYSKEYDOWN)
|
|
|
|
{
|
|
|
|
switch (wparam)
|
|
|
|
{
|
|
|
|
case VK_F10:
|
|
|
|
case VK_MENU:
|
|
|
|
case VK_RSHIFT:
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DefWindowProc(hwnd, message, wparam, lparam);
|
|
|
|
}
|
|
|
|
|
2015-11-30 06:27:00 +01:00
|
|
|
static LRESULT CALLBACK WndProcCommon(bool *quit, HWND hwnd, UINT message,
|
2015-11-19 07:53:00 +01:00
|
|
|
WPARAM wparam, LPARAM lparam)
|
|
|
|
{
|
2015-11-28 22:01:02 +01:00
|
|
|
|
2016-07-16 17:44:21 +02:00
|
|
|
if (message == WM_NCLBUTTONDBLCLK)
|
|
|
|
doubleclick_on_titlebar = true;
|
|
|
|
|
2015-11-19 07:53:00 +01:00
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
case WM_SYSCOMMAND:
|
|
|
|
/* Prevent screensavers, etc, while running. */
|
|
|
|
switch (wparam)
|
|
|
|
{
|
|
|
|
case SC_SCREENSAVE:
|
|
|
|
case SC_MONITORPOWER:
|
2015-11-30 06:27:00 +01:00
|
|
|
*quit = true;
|
2016-06-04 05:09:58 +02:00
|
|
|
break;
|
2015-11-19 07:53:00 +01:00
|
|
|
}
|
|
|
|
break;
|
2016-06-03 09:14:53 +10:00
|
|
|
case WM_DROPFILES:
|
2016-07-16 22:39:21 +02:00
|
|
|
{
|
|
|
|
int ret = win32_drag_query_file(hwnd, wparam);
|
|
|
|
DragFinish((HDROP)wparam);
|
|
|
|
if (ret != 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2015-11-19 07:53:00 +01:00
|
|
|
case WM_CHAR:
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
case WM_KEYUP:
|
|
|
|
case WM_SYSKEYUP:
|
|
|
|
case WM_SYSKEYDOWN:
|
2015-11-30 06:27:00 +01:00
|
|
|
*quit = true;
|
2015-11-19 07:53:00 +01:00
|
|
|
return win32_handle_keyboard_event(hwnd, message, wparam, lparam);
|
|
|
|
|
|
|
|
case WM_CLOSE:
|
|
|
|
case WM_DESTROY:
|
|
|
|
case WM_QUIT:
|
2016-06-04 05:09:58 +02:00
|
|
|
{
|
|
|
|
WINDOWPLACEMENT placement;
|
2016-06-04 05:44:06 +02:00
|
|
|
GetWindowPlacement(main_window.hwnd, &placement);
|
2016-06-04 05:09:58 +02:00
|
|
|
g_pos_x = placement.rcNormalPosition.left;
|
|
|
|
g_pos_y = placement.rcNormalPosition.top;
|
|
|
|
g_quit = true;
|
|
|
|
*quit = true;
|
|
|
|
}
|
|
|
|
break;
|
2015-11-19 07:53:00 +01:00
|
|
|
case WM_SIZE:
|
|
|
|
/* Do not send resize message if we minimize. */
|
|
|
|
if (wparam != SIZE_MAXHIDE && wparam != SIZE_MINIMIZED)
|
|
|
|
{
|
|
|
|
g_resize_width = LOWORD(lparam);
|
|
|
|
g_resize_height = HIWORD(lparam);
|
|
|
|
g_resized = true;
|
|
|
|
}
|
2015-11-30 06:27:00 +01:00
|
|
|
*quit = true;
|
2016-06-04 05:09:58 +02:00
|
|
|
break;
|
2017-01-16 20:40:43 -05:00
|
|
|
case WM_COMMAND:
|
2016-07-24 11:12:26 +02:00
|
|
|
{
|
|
|
|
settings_t *settings = config_get_ptr();
|
2017-04-28 00:53:06 +02:00
|
|
|
if (settings->bools.ui_menubar_enable)
|
2016-07-24 11:12:26 +02:00
|
|
|
win32_menu_loop(main_window.hwnd, wparam);
|
|
|
|
}
|
2015-11-28 22:00:22 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-16 23:49:44 +02:00
|
|
|
extern void ui_window_win32_set_droppable(void *data, bool droppable);
|
|
|
|
|
2017-01-13 14:31:36 -05:00
|
|
|
#ifdef HAVE_D3D9
|
2015-11-28 22:00:22 +01:00
|
|
|
LRESULT CALLBACK WndProcD3D(HWND hwnd, UINT message,
|
|
|
|
WPARAM wparam, LPARAM lparam)
|
|
|
|
{
|
2015-11-30 06:27:00 +01:00
|
|
|
LRESULT ret;
|
|
|
|
bool quit = false;
|
2015-11-28 22:00:22 +01:00
|
|
|
|
2016-07-16 17:44:21 +02:00
|
|
|
if (message == WM_NCLBUTTONDBLCLK)
|
|
|
|
doubleclick_on_titlebar = true;
|
|
|
|
|
2015-11-28 22:00:22 +01:00
|
|
|
switch (message)
|
|
|
|
{
|
2016-06-03 09:14:53 +10:00
|
|
|
case WM_DROPFILES:
|
2015-11-28 22:00:22 +01:00
|
|
|
case WM_SYSCOMMAND:
|
|
|
|
case WM_CHAR:
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
case WM_KEYUP:
|
|
|
|
case WM_SYSKEYUP:
|
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
case WM_CLOSE:
|
|
|
|
case WM_DESTROY:
|
|
|
|
case WM_QUIT:
|
|
|
|
case WM_COMMAND:
|
2015-11-30 06:27:00 +01:00
|
|
|
ret = WndProcCommon(&quit, hwnd, message, wparam, lparam);
|
|
|
|
if (quit)
|
|
|
|
return ret;
|
|
|
|
break;
|
2015-11-28 22:00:22 +01:00
|
|
|
case WM_CREATE:
|
2015-11-19 07:53:00 +01:00
|
|
|
{
|
2016-06-06 08:01:26 +02:00
|
|
|
ui_window_win32_t win32_window;
|
2015-11-28 22:00:22 +01:00
|
|
|
LPCREATESTRUCT p_cs = (LPCREATESTRUCT)lparam;
|
|
|
|
curD3D = p_cs->lpCreateParams;
|
2016-01-07 07:18:52 +01:00
|
|
|
g_inited = true;
|
2016-12-02 23:36:23 -05:00
|
|
|
|
2016-06-06 08:01:26 +02:00
|
|
|
win32_window.hwnd = hwnd;
|
2016-06-04 08:50:43 +02:00
|
|
|
|
2016-07-16 23:49:44 +02:00
|
|
|
ui_window_win32_set_droppable(&win32_window, true);
|
2015-11-19 07:53:00 +01:00
|
|
|
}
|
2015-11-28 22:00:22 +01:00
|
|
|
return 0;
|
2015-11-19 07:53:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-29 13:27:45 +02:00
|
|
|
if (dinput && dinput_handle_message(dinput, message, wparam, lparam))
|
2015-11-28 21:50:28 +01:00
|
|
|
return 0;
|
|
|
|
return DefWindowProc(hwnd, message, wparam, lparam);
|
|
|
|
}
|
2017-01-13 14:31:36 -05:00
|
|
|
#endif
|
2015-11-28 21:50:28 +01:00
|
|
|
|
2017-01-13 14:31:36 -05:00
|
|
|
#if defined(HAVE_OPENGL) || defined(HAVE_VULKAN)
|
2015-11-28 21:50:28 +01:00
|
|
|
LRESULT CALLBACK WndProcGL(HWND hwnd, UINT message,
|
|
|
|
WPARAM wparam, LPARAM lparam)
|
|
|
|
{
|
2015-11-30 06:27:00 +01:00
|
|
|
LRESULT ret;
|
|
|
|
bool quit = false;
|
2015-11-28 21:50:28 +01:00
|
|
|
|
2016-07-16 17:44:21 +02:00
|
|
|
if (message == WM_NCLBUTTONDBLCLK)
|
|
|
|
doubleclick_on_titlebar = true;
|
|
|
|
|
2015-11-28 21:50:28 +01:00
|
|
|
switch (message)
|
|
|
|
{
|
2016-06-03 09:14:53 +10:00
|
|
|
case WM_DROPFILES:
|
2015-11-28 21:50:28 +01:00
|
|
|
case WM_SYSCOMMAND:
|
|
|
|
case WM_CHAR:
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
case WM_KEYUP:
|
|
|
|
case WM_SYSKEYUP:
|
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
case WM_CLOSE:
|
|
|
|
case WM_DESTROY:
|
|
|
|
case WM_QUIT:
|
|
|
|
case WM_SIZE:
|
2015-11-28 22:00:22 +01:00
|
|
|
case WM_COMMAND:
|
2015-11-30 06:27:00 +01:00
|
|
|
ret = WndProcCommon(&quit, hwnd, message, wparam, lparam);
|
|
|
|
if (quit)
|
|
|
|
return ret;
|
|
|
|
break;
|
2015-11-28 22:00:22 +01:00
|
|
|
case WM_CREATE:
|
2016-06-04 08:50:43 +02:00
|
|
|
{
|
2016-06-06 08:01:26 +02:00
|
|
|
ui_window_win32_t win32_window;
|
|
|
|
win32_window.hwnd = hwnd;
|
2016-06-04 08:50:43 +02:00
|
|
|
|
|
|
|
create_graphics_context(hwnd, &g_quit);
|
2016-06-06 08:01:26 +02:00
|
|
|
|
2016-07-16 23:49:44 +02:00
|
|
|
ui_window_win32_set_droppable(&win32_window, true);
|
2016-06-04 08:50:43 +02:00
|
|
|
}
|
2015-11-28 21:50:28 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-13 14:31:36 -05:00
|
|
|
#ifdef HAVE_D3D9
|
2016-03-29 13:27:45 +02:00
|
|
|
if (dinput_wgl && dinput_handle_message(dinput_wgl, message, wparam, lparam))
|
2015-11-19 07:53:00 +01:00
|
|
|
return 0;
|
2017-01-13 14:31:36 -05:00
|
|
|
#endif
|
2016-12-03 00:14:33 -05:00
|
|
|
return DefWindowProc(hwnd, message, wparam, lparam);
|
2015-11-19 07:53:00 +01:00
|
|
|
}
|
2017-01-13 14:31:36 -05:00
|
|
|
#endif
|
2015-11-11 18:26:10 +01:00
|
|
|
|
2017-01-04 22:57:00 -05:00
|
|
|
LRESULT CALLBACK WndProcGDI(HWND hwnd, UINT message,
|
|
|
|
WPARAM wparam, LPARAM lparam)
|
|
|
|
{
|
|
|
|
LRESULT ret;
|
|
|
|
bool quit = false;
|
|
|
|
|
|
|
|
if (message == WM_NCLBUTTONDBLCLK)
|
|
|
|
doubleclick_on_titlebar = true;
|
|
|
|
|
|
|
|
switch (message)
|
|
|
|
{
|
2017-01-11 00:44:34 -05:00
|
|
|
case WM_PAINT:
|
|
|
|
{
|
|
|
|
PAINTSTRUCT ps;
|
2017-01-08 15:27:51 -05:00
|
|
|
HDC hdc = BeginPaint(hwnd, &ps);
|
|
|
|
|
2017-01-12 15:03:27 -05:00
|
|
|
#ifdef HAVE_MENU
|
2017-01-23 00:37:39 +01:00
|
|
|
if (menu_driver_is_alive() && !gdi_has_menu_frame())
|
2017-01-16 20:40:43 -05:00
|
|
|
{
|
|
|
|
RECT rect;
|
|
|
|
GetClientRect(hwnd, &rect);
|
|
|
|
|
|
|
|
TRIVERTEX vertex[2];
|
|
|
|
vertex[0].x = rect.left;
|
|
|
|
vertex[0].y = rect.top;
|
|
|
|
vertex[0].Red = 1 << 8;
|
|
|
|
vertex[0].Green = 81 << 8;
|
|
|
|
vertex[0].Blue = 127 << 8;
|
|
|
|
vertex[0].Alpha = 0;
|
|
|
|
|
|
|
|
vertex[1].x = rect.right;
|
|
|
|
vertex[1].y = rect.bottom;
|
|
|
|
vertex[1].Red = 0;
|
|
|
|
vertex[1].Green = 1 << 8;
|
|
|
|
vertex[1].Blue = 33 << 8;
|
|
|
|
vertex[1].Alpha = 0;
|
|
|
|
|
|
|
|
GRADIENT_RECT gRect;
|
|
|
|
gRect.LowerRight = 0;
|
|
|
|
gRect.UpperLeft = 1;
|
|
|
|
|
|
|
|
GradientFill(hdc, vertex, 2, &gRect, 1, GRADIENT_FILL_RECT_V);
|
|
|
|
}
|
2017-01-12 15:03:27 -05:00
|
|
|
#endif
|
2017-01-08 15:27:51 -05:00
|
|
|
|
2017-01-11 00:44:34 -05:00
|
|
|
EndPaint(hwnd, &ps);
|
|
|
|
break;
|
|
|
|
}
|
2017-01-04 22:57:00 -05:00
|
|
|
case WM_DROPFILES:
|
|
|
|
case WM_SYSCOMMAND:
|
|
|
|
case WM_CHAR:
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
case WM_KEYUP:
|
|
|
|
case WM_SYSKEYUP:
|
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
case WM_CLOSE:
|
|
|
|
case WM_DESTROY:
|
|
|
|
case WM_QUIT:
|
|
|
|
case WM_SIZE:
|
|
|
|
case WM_COMMAND:
|
|
|
|
ret = WndProcCommon(&quit, hwnd, message, wparam, lparam);
|
|
|
|
if (quit)
|
|
|
|
return ret;
|
|
|
|
break;
|
|
|
|
case WM_CREATE:
|
|
|
|
{
|
|
|
|
ui_window_win32_t win32_window;
|
|
|
|
win32_window.hwnd = hwnd;
|
|
|
|
|
2017-01-04 23:13:08 -05:00
|
|
|
create_gdi_context(hwnd, &g_quit);
|
2017-01-04 22:57:00 -05:00
|
|
|
|
|
|
|
ui_window_win32_set_droppable(&win32_window, true);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-13 14:31:36 -05:00
|
|
|
#ifdef HAVE_D3D9
|
2017-01-04 22:57:00 -05:00
|
|
|
if (dinput_gdi && dinput_handle_message(dinput_gdi, message, wparam, lparam))
|
|
|
|
return 0;
|
2017-01-13 14:31:36 -05:00
|
|
|
#endif
|
2017-01-04 22:57:00 -05:00
|
|
|
return DefWindowProc(hwnd, message, wparam, lparam);
|
|
|
|
}
|
|
|
|
|
2015-11-12 02:51:40 +01:00
|
|
|
bool win32_window_create(void *data, unsigned style,
|
|
|
|
RECT *mon_rect, unsigned width,
|
|
|
|
unsigned height, bool fullscreen)
|
|
|
|
{
|
|
|
|
#ifndef _XBOX
|
2016-12-03 00:14:33 -05:00
|
|
|
main_window.hwnd = CreateWindowEx(0, "RetroArch", "RetroArch",
|
2015-11-12 02:51:40 +01:00
|
|
|
style,
|
2015-11-12 02:53:01 +01:00
|
|
|
fullscreen ? mon_rect->left : g_pos_x,
|
|
|
|
fullscreen ? mon_rect->top : g_pos_y,
|
|
|
|
width, height,
|
2015-11-12 02:51:40 +01:00
|
|
|
NULL, NULL, NULL, data);
|
2016-06-04 05:44:06 +02:00
|
|
|
if (!main_window.hwnd)
|
2015-11-12 02:51:40 +01:00
|
|
|
return false;
|
|
|
|
|
2015-11-29 01:12:49 +01:00
|
|
|
video_driver_display_type_set(RARCH_DISPLAY_WIN32);
|
|
|
|
video_driver_display_set(0);
|
2016-06-04 05:44:06 +02:00
|
|
|
video_driver_window_set((uintptr_t)main_window.hwnd);
|
2015-11-12 02:51:40 +01:00
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
2015-11-19 07:53:00 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-09 05:19:29 +02:00
|
|
|
bool win32_get_metrics(void *data,
|
2017-01-16 20:40:43 -05:00
|
|
|
enum display_metric_types type, float *value)
|
2015-04-09 05:19:29 +02:00
|
|
|
{
|
|
|
|
#ifdef _XBOX
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
HDC monitor = GetDC(NULL);
|
|
|
|
int pixels_x = GetDeviceCaps(monitor, HORZRES);
|
|
|
|
int pixels_y = GetDeviceCaps(monitor, VERTRES);
|
|
|
|
int physical_width = GetDeviceCaps(monitor, HORZSIZE);
|
|
|
|
int physical_height = GetDeviceCaps(monitor, VERTSIZE);
|
|
|
|
|
|
|
|
ReleaseDC(NULL, monitor);
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case DISPLAY_METRIC_MM_WIDTH:
|
|
|
|
*value = physical_width;
|
|
|
|
break;
|
|
|
|
case DISPLAY_METRIC_MM_HEIGHT:
|
|
|
|
*value = physical_height;
|
|
|
|
break;
|
|
|
|
case DISPLAY_METRIC_DPI:
|
|
|
|
/* 25.4 mm in an inch. */
|
|
|
|
*value = 254 * pixels_x / physical_width / 10;
|
|
|
|
break;
|
|
|
|
case DISPLAY_METRIC_NONE:
|
|
|
|
default:
|
|
|
|
*value = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
2015-04-10 09:30:18 +02:00
|
|
|
|
2015-11-12 01:22:28 +01:00
|
|
|
void win32_monitor_init(void)
|
|
|
|
{
|
|
|
|
#ifndef _XBOX
|
|
|
|
win32_monitor_count = 0;
|
|
|
|
EnumDisplayMonitors(NULL, NULL, win32_monitor_enum_proc, 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
g_quit = false;
|
|
|
|
}
|
|
|
|
|
2016-11-06 18:35:00 +01:00
|
|
|
static bool win32_monitor_set_fullscreen(unsigned width, unsigned height,
|
2016-11-06 11:52:03 +01:00
|
|
|
unsigned refresh, char *dev_name)
|
2015-11-12 03:01:50 +01:00
|
|
|
{
|
|
|
|
#ifndef _XBOX
|
|
|
|
DEVMODE devmode;
|
|
|
|
|
|
|
|
memset(&devmode, 0, sizeof(devmode));
|
2016-11-06 18:35:00 +01:00
|
|
|
devmode.dmSize = sizeof(DEVMODE);
|
|
|
|
devmode.dmPelsWidth = width;
|
|
|
|
devmode.dmPelsHeight = height;
|
2015-11-12 03:01:50 +01:00
|
|
|
devmode.dmDisplayFrequency = refresh;
|
2016-11-06 18:35:00 +01:00
|
|
|
devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
|
2015-11-12 03:01:50 +01:00
|
|
|
|
2016-11-06 18:35:00 +01:00
|
|
|
RARCH_LOG("Setting fullscreen to %ux%u @ %uHz on device %s.\n",
|
2016-11-06 11:52:03 +01:00
|
|
|
width, height, refresh, dev_name);
|
2016-11-29 02:04:13 -05:00
|
|
|
|
2016-12-03 00:14:33 -05:00
|
|
|
return ChangeDisplaySettingsEx(dev_name, &devmode,
|
2016-12-02 23:36:23 -05:00
|
|
|
NULL, CDS_FULLSCREEN, NULL) == DISP_CHANGE_SUCCESSFUL;
|
2015-11-12 03:01:50 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-04-10 09:30:18 +02:00
|
|
|
void win32_show_cursor(bool state)
|
|
|
|
{
|
2015-04-11 07:10:35 +02:00
|
|
|
#ifndef _XBOX
|
2015-04-10 09:30:18 +02:00
|
|
|
if (state)
|
|
|
|
while (ShowCursor(TRUE) < 0);
|
|
|
|
else
|
|
|
|
while (ShowCursor(FALSE) >= 0);
|
|
|
|
#endif
|
|
|
|
}
|
2015-04-10 09:36:03 +02:00
|
|
|
|
2016-11-06 11:52:03 +01:00
|
|
|
void win32_check_window(bool *quit, bool *resize,
|
|
|
|
unsigned *width, unsigned *height)
|
2015-04-10 09:36:03 +02:00
|
|
|
{
|
|
|
|
#ifndef _XBOX
|
2016-12-02 23:36:23 -05:00
|
|
|
const ui_application_t *application =
|
2016-11-06 11:52:03 +01:00
|
|
|
ui_companion_driver_get_application_ptr();
|
2016-06-07 17:28:51 +02:00
|
|
|
if (application)
|
|
|
|
application->process_events();
|
2015-04-10 09:36:03 +02:00
|
|
|
#endif
|
2015-11-11 19:41:32 +01:00
|
|
|
*quit = g_quit;
|
|
|
|
|
|
|
|
if (g_resized)
|
|
|
|
{
|
|
|
|
*resize = true;
|
|
|
|
*width = g_resize_width;
|
|
|
|
*height = g_resize_height;
|
|
|
|
g_resized = false;
|
|
|
|
}
|
2015-04-10 09:36:03 +02:00
|
|
|
}
|
2015-10-10 08:13:58 +02:00
|
|
|
|
|
|
|
bool win32_suppress_screensaver(void *data, bool enable)
|
|
|
|
{
|
|
|
|
#ifdef _XBOX
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
|
|
|
|
if(enable)
|
|
|
|
{
|
2016-03-04 04:51:57 +01:00
|
|
|
int major, minor;
|
|
|
|
char tmp[PATH_MAX_LENGTH];
|
2016-03-04 05:01:49 +01:00
|
|
|
const frontend_ctx_driver_t *frontend = frontend_get_ptr();
|
|
|
|
|
|
|
|
if (!frontend)
|
|
|
|
return false;
|
2016-03-04 04:51:57 +01:00
|
|
|
|
|
|
|
frontend->get_os(tmp, sizeof(tmp), &major, &minor);
|
|
|
|
|
2016-07-16 16:51:09 +02:00
|
|
|
if (major*100+minor >= 601)
|
2015-10-10 08:13:58 +02:00
|
|
|
{
|
2017-01-14 04:06:56 -05:00
|
|
|
#ifdef _WIN32_WINNT_WIN7
|
2015-10-10 08:13:58 +02:00
|
|
|
/* Windows 7, 8, 10 codepath */
|
2016-03-04 04:51:57 +01:00
|
|
|
typedef HANDLE (WINAPI * PowerCreateRequestPtr)(REASON_CONTEXT *context);
|
|
|
|
typedef BOOL (WINAPI * PowerSetRequestPtr)(HANDLE PowerRequest,
|
|
|
|
POWER_REQUEST_TYPE RequestType);
|
2016-12-03 00:14:33 -05:00
|
|
|
HMODULE kernel32 = GetModuleHandle("kernel32.dll");
|
2016-03-04 04:51:57 +01:00
|
|
|
PowerCreateRequestPtr powerCreateRequest =
|
|
|
|
(PowerCreateRequestPtr)GetProcAddress(kernel32, "PowerCreateRequest");
|
|
|
|
PowerSetRequestPtr powerSetRequest =
|
|
|
|
(PowerSetRequestPtr)GetProcAddress(kernel32, "PowerSetRequest");
|
|
|
|
|
|
|
|
if(powerCreateRequest && powerSetRequest)
|
|
|
|
{
|
|
|
|
POWER_REQUEST_CONTEXT RequestContext;
|
|
|
|
HANDLE Request;
|
2015-10-10 08:13:58 +02:00
|
|
|
|
2016-03-04 04:51:57 +01:00
|
|
|
RequestContext.Version = POWER_REQUEST_CONTEXT_VERSION;
|
|
|
|
RequestContext.Flags = POWER_REQUEST_CONTEXT_SIMPLE_STRING;
|
|
|
|
RequestContext.Reason.SimpleReasonString = (LPWSTR)L"RetroArch running";
|
2015-10-10 08:13:58 +02:00
|
|
|
|
2016-03-04 04:51:57 +01:00
|
|
|
Request = powerCreateRequest(&RequestContext);
|
2015-10-10 08:13:58 +02:00
|
|
|
|
2016-03-04 04:51:57 +01:00
|
|
|
powerSetRequest( Request, PowerRequestDisplayRequired);
|
|
|
|
return true;
|
|
|
|
}
|
2017-01-14 04:06:56 -05:00
|
|
|
#endif
|
2015-10-10 08:13:58 +02:00
|
|
|
}
|
2016-03-04 04:51:57 +01:00
|
|
|
else
|
2015-10-10 08:13:58 +02:00
|
|
|
{
|
|
|
|
/* XP / Vista codepath */
|
|
|
|
SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
2015-11-12 05:16:06 +01:00
|
|
|
|
2016-11-29 02:04:13 -05:00
|
|
|
/* FIXME: It should not be necessary to add the W after MONITORINFOEX, but linking fails without it. */
|
2016-12-03 00:14:33 -05:00
|
|
|
void win32_set_style(MONITORINFOEX *current_mon, HMONITOR *hm_to_use,
|
2017-01-16 20:40:43 -05:00
|
|
|
unsigned *width, unsigned *height, bool fullscreen, bool windowed_full,
|
|
|
|
RECT *rect, RECT *mon_rect, DWORD *style)
|
2016-01-09 05:24:27 +01:00
|
|
|
{
|
|
|
|
#ifndef _XBOX
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
|
2016-12-02 23:36:23 -05:00
|
|
|
/* Windows only reports the refresh rates for modelines as
|
2017-04-28 15:59:42 +02:00
|
|
|
* an integer, so video_refresh_rate needs to be rounded. Also, account
|
|
|
|
* for black frame insertion using video_refresh_rate set to half
|
2016-01-09 05:24:27 +01:00
|
|
|
* of the display refresh rate, as well as higher vsync swap intervals. */
|
2017-04-28 14:28:40 +02:00
|
|
|
float refresh_mod = settings->bools.video_black_frame_insertion ? 2.0f : 1.0f;
|
2017-04-28 15:59:42 +02:00
|
|
|
unsigned refresh = roundf(settings->floats.video_refresh_rate
|
2017-04-28 21:03:04 +02:00
|
|
|
* refresh_mod * settings->uints.video_swap_interval);
|
2016-01-09 05:24:27 +01:00
|
|
|
|
|
|
|
if (fullscreen)
|
|
|
|
{
|
|
|
|
if (windowed_full)
|
|
|
|
{
|
|
|
|
*style = WS_EX_TOPMOST | WS_POPUP;
|
|
|
|
g_resize_width = *width = mon_rect->right - mon_rect->left;
|
|
|
|
g_resize_height = *height = mon_rect->bottom - mon_rect->top;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*style = WS_POPUP | WS_VISIBLE;
|
|
|
|
|
|
|
|
if (!win32_monitor_set_fullscreen(*width, *height,
|
2016-12-03 00:14:33 -05:00
|
|
|
refresh, current_mon->szDevice))
|
2017-01-16 20:40:43 -05:00
|
|
|
{}
|
2016-12-02 21:11:55 -05:00
|
|
|
|
2016-01-09 05:24:27 +01:00
|
|
|
/* Display settings might have changed, get new coordinates. */
|
2016-12-03 00:14:33 -05:00
|
|
|
GetMonitorInfo(*hm_to_use, (MONITORINFOEX*)current_mon);
|
2016-01-09 05:24:27 +01:00
|
|
|
*mon_rect = current_mon->rcMonitor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*style = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
|
|
|
|
rect->right = *width;
|
|
|
|
rect->bottom = *height;
|
|
|
|
AdjustWindowRect(rect, *style, FALSE);
|
|
|
|
g_resize_width = *width = rect->right - rect->left;
|
|
|
|
g_resize_height = *height = rect->bottom - rect->top;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-01-09 04:59:12 +01:00
|
|
|
void win32_set_window(unsigned *width, unsigned *height,
|
2016-01-09 05:00:56 +01:00
|
|
|
bool fullscreen, bool windowed_full, void *rect_data)
|
2016-01-09 04:59:12 +01:00
|
|
|
{
|
2016-01-09 05:04:47 +01:00
|
|
|
#ifndef _XBOX
|
2016-01-09 05:00:56 +01:00
|
|
|
RECT *rect = (RECT*)rect_data;
|
2016-01-09 04:59:12 +01:00
|
|
|
|
|
|
|
if (!fullscreen || windowed_full)
|
|
|
|
{
|
2017-04-25 15:31:32 +02:00
|
|
|
settings_t *settings = config_get_ptr();
|
2016-06-06 08:01:26 +02:00
|
|
|
const ui_window_t *window = ui_companion_driver_get_window_ptr();
|
|
|
|
|
2017-04-28 00:53:06 +02:00
|
|
|
if (!fullscreen && settings->bools.ui_menubar_enable)
|
2016-01-09 04:59:12 +01:00
|
|
|
{
|
|
|
|
RECT rc_temp = {0, 0, (LONG)*height, 0x7FFF};
|
2016-11-06 11:52:03 +01:00
|
|
|
SetMenu(main_window.hwnd,
|
2016-12-03 00:14:33 -05:00
|
|
|
LoadMenu(GetModuleHandle(NULL),MAKEINTRESOURCE(IDR_MENU)));
|
|
|
|
SendMessage(main_window.hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)&rc_temp);
|
2016-01-09 05:00:56 +01:00
|
|
|
g_resize_height = *height += rc_temp.top + rect->top;
|
2016-06-04 05:44:06 +02:00
|
|
|
SetWindowPos(main_window.hwnd, NULL, 0, 0, *width, *height, SWP_NOMOVE);
|
2016-01-09 04:59:12 +01:00
|
|
|
}
|
|
|
|
|
2016-06-04 05:44:06 +02:00
|
|
|
ShowWindow(main_window.hwnd, SW_RESTORE);
|
|
|
|
UpdateWindow(main_window.hwnd);
|
|
|
|
SetForegroundWindow(main_window.hwnd);
|
2016-06-06 08:01:26 +02:00
|
|
|
|
|
|
|
if (window)
|
|
|
|
window->set_focused(&main_window);
|
2016-01-09 04:59:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
win32_show_cursor(!fullscreen);
|
2016-01-09 05:04:47 +01:00
|
|
|
#endif
|
2016-01-09 04:59:12 +01:00
|
|
|
}
|
|
|
|
|
2015-11-12 05:16:06 +01:00
|
|
|
bool win32_set_video_mode(void *data,
|
|
|
|
unsigned width, unsigned height,
|
|
|
|
bool fullscreen)
|
|
|
|
{
|
|
|
|
#ifndef _XBOX
|
|
|
|
DWORD style;
|
|
|
|
MSG msg;
|
|
|
|
RECT mon_rect;
|
|
|
|
unsigned mon_id;
|
2016-12-03 00:14:33 -05:00
|
|
|
MONITORINFOEX current_mon;
|
2015-11-12 05:16:06 +01:00
|
|
|
bool windowed_full;
|
2015-12-05 12:50:56 +01:00
|
|
|
RECT rect = {0};
|
|
|
|
HMONITOR hm_to_use = NULL;
|
|
|
|
settings_t *settings = config_get_ptr();
|
2017-01-04 22:57:00 -05:00
|
|
|
int res = 0;
|
2015-11-12 05:16:06 +01:00
|
|
|
|
|
|
|
win32_monitor_info(¤t_mon, &hm_to_use, &mon_id);
|
|
|
|
|
|
|
|
mon_rect = current_mon.rcMonitor;
|
|
|
|
g_resize_width = width;
|
|
|
|
g_resize_height = height;
|
|
|
|
|
2017-04-28 00:53:06 +02:00
|
|
|
windowed_full = settings->bools.video_windowed_fullscreen;
|
2015-11-12 05:16:06 +01:00
|
|
|
|
2016-11-06 11:52:03 +01:00
|
|
|
win32_set_style(¤t_mon, &hm_to_use, &width, &height,
|
|
|
|
fullscreen, windowed_full, &rect, &mon_rect, &style);
|
2015-11-12 05:16:06 +01:00
|
|
|
|
2016-01-08 05:13:10 +01:00
|
|
|
if (!win32_window_create(data, style, &mon_rect, width, height, fullscreen))
|
2015-11-12 05:19:00 +01:00
|
|
|
return false;
|
2016-12-02 23:36:23 -05:00
|
|
|
|
2016-01-09 05:00:56 +01:00
|
|
|
win32_set_window(&width, &height, fullscreen, windowed_full, &rect);
|
2015-11-12 05:16:06 +01:00
|
|
|
|
2017-01-04 22:57:00 -05:00
|
|
|
/* Wait until context is created (or failed to do so ...).
|
|
|
|
* Please don't remove the (res = ) as GetMessage can return -1. */
|
|
|
|
while (!g_inited && !g_quit && (res = GetMessage(&msg, main_window.hwnd, 0, 0)) != 0)
|
2015-11-12 05:16:06 +01:00
|
|
|
{
|
2017-01-04 22:57:00 -05:00
|
|
|
if (res == -1)
|
|
|
|
{
|
|
|
|
RARCH_ERR("GetMessage error code %d\n", GetLastError());
|
2017-01-05 17:21:13 -05:00
|
|
|
break;
|
2017-01-04 22:57:00 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
2015-11-12 05:16:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (g_quit)
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-11-17 08:58:49 +01:00
|
|
|
|
|
|
|
#ifdef _XBOX
|
|
|
|
static HANDLE GetFocus(void)
|
|
|
|
{
|
2016-06-04 05:44:06 +02:00
|
|
|
return main_window.hwnd;
|
2015-11-17 08:58:49 +01:00
|
|
|
}
|
2015-11-17 10:49:36 +01:00
|
|
|
|
2016-06-04 17:18:20 +02:00
|
|
|
static HWND GetForegroundWindow(void)
|
|
|
|
{
|
|
|
|
return main_window.hwnd;
|
|
|
|
}
|
|
|
|
|
2015-11-17 10:49:36 +01:00
|
|
|
BOOL IsIconic(HWND hwnd)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-11-17 08:58:49 +01:00
|
|
|
#endif
|
|
|
|
|
2015-11-17 09:02:02 +01:00
|
|
|
bool win32_has_focus(void)
|
2015-11-17 08:58:49 +01:00
|
|
|
{
|
2016-06-06 08:01:26 +02:00
|
|
|
#ifndef _XBOX
|
|
|
|
const ui_window_t *window = ui_companion_driver_get_window_ptr();
|
|
|
|
#endif
|
2015-11-17 08:58:49 +01:00
|
|
|
if (!g_inited)
|
|
|
|
return false;
|
|
|
|
|
2016-06-04 17:30:06 +02:00
|
|
|
#ifdef _XBOX
|
2016-06-04 17:17:10 +02:00
|
|
|
return GetForegroundWindow() == main_window.hwnd;
|
2016-06-04 17:30:06 +02:00
|
|
|
#else
|
2016-06-06 08:01:26 +02:00
|
|
|
if (window)
|
|
|
|
return window->focused(&main_window);
|
|
|
|
return false;
|
2016-06-04 17:30:06 +02:00
|
|
|
#endif
|
2015-11-17 08:58:49 +01:00
|
|
|
}
|
2015-11-17 09:41:18 +01:00
|
|
|
|
|
|
|
HWND win32_get_window(void)
|
|
|
|
{
|
2016-06-04 05:45:39 +02:00
|
|
|
return main_window.hwnd;
|
2015-11-17 09:41:18 +01:00
|
|
|
}
|
2015-11-17 09:44:26 +01:00
|
|
|
|
2015-11-17 10:16:16 +01:00
|
|
|
void win32_window_reset(void)
|
|
|
|
{
|
|
|
|
g_quit = false;
|
|
|
|
g_restore_desktop = false;
|
|
|
|
}
|
|
|
|
|
2015-11-17 09:44:26 +01:00
|
|
|
void win32_destroy_window(void)
|
|
|
|
{
|
|
|
|
#ifndef _XBOX
|
2016-12-03 00:14:33 -05:00
|
|
|
UnregisterClass("RetroArch", GetModuleHandle(NULL));
|
2015-11-17 09:44:26 +01:00
|
|
|
#endif
|
2016-06-04 05:44:06 +02:00
|
|
|
main_window.hwnd = NULL;
|
2015-11-17 09:44:26 +01:00
|
|
|
}
|