WIN32: Add experimental SDL2 support.

Based on changes by aquadran.
This commit is contained in:
Johannes Schickel 2015-02-16 02:13:11 +01:00
parent 3f22c12c56
commit 3745ddbefd
7 changed files with 44 additions and 11 deletions

View file

@ -28,6 +28,8 @@
#include "icons/scummvm.xpm" #include "icons/scummvm.xpm"
#include <SDL_syswm.h>
SdlWindow::SdlWindow() SdlWindow::SdlWindow()
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
: _window(nullptr), _inputGrabState(false), _windowCaption("ScummVM"), _windowIcon(nullptr) : _window(nullptr), _inputGrabState(false), _windowCaption("ScummVM"), _windowIcon(nullptr)
@ -171,6 +173,15 @@ void SdlWindow::iconifyWindow() {
#endif #endif
} }
bool SdlWindow::getSDLWMInformation(SDL_SysWMinfo *info) const {
SDL_VERSION(&info->version);
#if SDL_VERSION_ATLEAST(2, 0, 0)
return SDL_GetWindowWMInfo(_window, info);
#else
return SDL_GetWMInfo(info);
#endif
}
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_Surface *copySDLSurface(SDL_Surface *src) { SDL_Surface *copySDLSurface(SDL_Surface *src) {
const bool locked = SDL_MUSTLOCK(src) == SDL_TRUE; const bool locked = SDL_MUSTLOCK(src) == SDL_TRUE;

View file

@ -27,6 +27,8 @@
#include "common/str.h" #include "common/str.h"
struct SDL_SysWMinfo;
class SdlWindow { class SdlWindow {
public: public:
SdlWindow(); SdlWindow();
@ -65,6 +67,14 @@ public:
*/ */
void iconifyWindow(); void iconifyWindow();
/**
* Query platform specific SDL window manager information.
*
* Since this is an SDL internal structure clients are responsible
* for accessing it in a version safe manner.
*/
bool getSDLWMInformation(SDL_SysWMinfo *info) const;
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
public: public:
/** /**

View file

@ -40,7 +40,9 @@
#include "base/main.h" #include "base/main.h"
int __stdcall WinMain(HINSTANCE /*hInst*/, HINSTANCE /*hPrevInst*/, LPSTR /*lpCmdLine*/, int /*iShowCmd*/) { int __stdcall WinMain(HINSTANCE /*hInst*/, HINSTANCE /*hPrevInst*/, LPSTR /*lpCmdLine*/, int /*iShowCmd*/) {
#if !SDL_VERSION_ATLEAST(2, 0, 0)
SDL_SetModuleHandle(GetModuleHandle(NULL)); SDL_SetModuleHandle(GetModuleHandle(NULL));
#endif
return main(__argc, __argv); return main(__argc, __argv);
} }

View file

@ -37,11 +37,14 @@ void SdlWindow_Win32::setupIcon() {
HMODULE handle = GetModuleHandle(NULL); HMODULE handle = GetModuleHandle(NULL);
HICON ico = LoadIcon(handle, MAKEINTRESOURCE(1001 /* IDI_ICON */)); HICON ico = LoadIcon(handle, MAKEINTRESOURCE(1001 /* IDI_ICON */));
if (ico) { if (ico) {
SDL_SysWMinfo wminfo; SDL_SysWMinfo wminfo;
SDL_VERSION(&wminfo.version); if (getSDLWMInformation(&wminfo)) {
if (SDL_GetWMInfo(&wminfo)) {
// Replace the handle to the icon associated with the window class by our custom icon // Replace the handle to the icon associated with the window class by our custom icon
#if SDL_VERSION_ATLEAST(2, 0, 0)
SetClassLongPtr(wminfo.info.win.window, GCLP_HICON, (ULONG_PTR)ico);
#else
SetClassLongPtr(wminfo.window, GCLP_HICON, (ULONG_PTR)ico); SetClassLongPtr(wminfo.window, GCLP_HICON, (ULONG_PTR)ico);
#endif
// Since there wasn't any default icon, we can't use the return value from SetClassLong // Since there wasn't any default icon, we can't use the return value from SetClassLong
// to check for errors (it would be 0 in both cases: error or no previous value for the // to check for errors (it would be 0 in both cases: error or no previous value for the

View file

@ -54,7 +54,7 @@ void OSystem_Win32::init() {
#if defined(USE_TASKBAR) #if defined(USE_TASKBAR)
// Initialize taskbar manager // Initialize taskbar manager
_taskbarManager = new Win32TaskbarManager(); _taskbarManager = new Win32TaskbarManager(_window);
#endif #endif
// Invoke parent implementation of this method // Invoke parent implementation of this method

View file

@ -62,7 +62,7 @@
// System.Title property key, values taken from http://msdn.microsoft.com/en-us/library/bb787584.aspx // System.Title property key, values taken from http://msdn.microsoft.com/en-us/library/bb787584.aspx
const PROPERTYKEY PKEY_Title = { /* fmtid = */ { 0xF29F85E0, 0x4FF9, 0x1068, { 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9 } }, /* propID = */ 2 }; const PROPERTYKEY PKEY_Title = { /* fmtid = */ { 0xF29F85E0, 0x4FF9, 0x1068, { 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9 } }, /* propID = */ 2 };
Win32TaskbarManager::Win32TaskbarManager() : _taskbar(NULL), _count(0), _icon(NULL) { Win32TaskbarManager::Win32TaskbarManager(SdlWindow *window) : _window(window), _taskbar(NULL), _count(0), _icon(NULL) {
// Do nothing if not running on Windows 7 or later // Do nothing if not running on Windows 7 or later
if (!isWin7OrLater()) if (!isWin7OrLater())
return; return;
@ -408,12 +408,15 @@ LPWSTR Win32TaskbarManager::ansiToUnicode(const char *s) {
HWND Win32TaskbarManager::getHwnd() { HWND Win32TaskbarManager::getHwnd() {
SDL_SysWMinfo wmi; SDL_SysWMinfo wmi;
SDL_VERSION(&wmi.version); if (_window->getSDLWMInformation(&wmi)) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
if(!SDL_GetWMInfo(&wmi)) return wmi.info.win.window;
#else
return wmi.window;
#endif
} else {
return NULL; return NULL;
}
return wmi.window;
} }
#endif #endif

View file

@ -25,6 +25,8 @@
#if defined(WIN32) && defined(USE_TASKBAR) #if defined(WIN32) && defined(USE_TASKBAR)
#include "backends/platform/sdl/sdl-window.h"
#include "common/str.h" #include "common/str.h"
#include "common/taskbar.h" #include "common/taskbar.h"
@ -32,7 +34,7 @@ struct ITaskbarList3;
class Win32TaskbarManager : public Common::TaskbarManager { class Win32TaskbarManager : public Common::TaskbarManager {
public: public:
Win32TaskbarManager(); Win32TaskbarManager(SdlWindow *window);
virtual ~Win32TaskbarManager(); virtual ~Win32TaskbarManager();
virtual void setOverlayIcon(const Common::String &name, const Common::String &description); virtual void setOverlayIcon(const Common::String &name, const Common::String &description);
@ -44,6 +46,8 @@ public:
virtual void clearError(); virtual void clearError();
private: private:
SdlWindow *_window;
ITaskbarList3 *_taskbar; ITaskbarList3 *_taskbar;
// Count handling // Count handling