summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinWX/MainNoGUI.cpp
diff options
context:
space:
mode:
authorJasper St. Pierre <jstpierre@mecheye.net>2014-08-06 00:34:31 -0400
committerJasper St. Pierre <jstpierre@mecheye.net>2014-08-19 10:05:57 -0400
commit09eb30ea3bc37554bc6894b597b326731158bb86 (patch)
tree91a3e4f248ec465bbf64d9be9ff337a0599c003a /Source/Core/DolphinWX/MainNoGUI.cpp
parente3a9ba30e379730a60aa569f653165d51e72b7c1 (diff)
MainNoGUI: Remove old OS X backend that doesn't work, rearchitect
Diffstat (limited to 'Source/Core/DolphinWX/MainNoGUI.cpp')
-rw-r--r--Source/Core/DolphinWX/MainNoGUI.cpp216
1 files changed, 113 insertions, 103 deletions
diff --git a/Source/Core/DolphinWX/MainNoGUI.cpp b/Source/Core/DolphinWX/MainNoGUI.cpp
index 8c091a0391..2b966876e2 100644
--- a/Source/Core/DolphinWX/MainNoGUI.cpp
+++ b/Source/Core/DolphinWX/MainNoGUI.cpp
@@ -18,24 +18,26 @@
#include "Core/Core.h"
#include "Core/CoreParameter.h"
#include "Core/Host.h"
+#include "Core/State.h"
#include "Core/HW/Wiimote.h"
#include "Core/PowerPC/PowerPC.h"
#include "VideoCommon/VideoBackendBase.h"
-#if HAVE_X11
-#include <X11/keysym.h>
-#include "Core/State.h"
-#include "DolphinWX/X11Utils.h"
-#endif
-
-#ifdef __APPLE__
-#import <Cocoa/Cocoa.h>
-#endif
-
static bool rendererHasFocus = true;
static bool running = true;
+class Platform
+{
+public:
+ virtual void Init() = 0;
+ virtual void MainLoop() = 0;
+ virtual void Shutdown() = 0;
+ virtual ~Platform() {};
+};
+
+static Platform* platform;
+
void Host_NotifyMapLoaded() {}
void Host_RefreshDSPDebuggerWindow() {}
@@ -121,54 +123,67 @@ void Host_SetWiiMoteConnectionState(int _State) {}
void Host_ShowVideoConfig(void*, const std::string&, const std::string&) {}
#if HAVE_X11
-static void X11_MainLoop()
-{
- bool fullscreen = SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen;
- while (!Core::IsRunning())
- updateMainFrameEvent.Wait();
-
- Display *dpy = XOpenDisplay(0);
- Window win = (Window)Core::GetWindowHandle();
- XSelectInput(dpy, win, KeyPressMask | FocusChangeMask);
-
- if (SConfig::GetInstance().m_LocalCoreStartupParameter.bDisableScreenSaver)
- X11Utils::InhibitScreensaver(dpy, win, true);
+#include <X11/keysym.h>
+#include "DolphinWX/X11Utils.h"
+class PlatformX11 : public Platform
+{
+ Display *dpy;
+ Cursor blankCursor = None;
#if defined(HAVE_XRANDR) && HAVE_XRANDR
- X11Utils::XRRConfiguration *XRRConfig = new X11Utils::XRRConfiguration(dpy, win);
+ X11Utils::XRRConfiguration *XRRConfig;
#endif
- Cursor blankCursor = None;
- if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
+ void Init() override
{
- // make a blank cursor
- Pixmap Blank;
- XColor DummyColor;
- char ZeroData[1] = {0};
- Blank = XCreateBitmapFromData (dpy, win, ZeroData, 1, 1);
- blankCursor = XCreatePixmapCursor(dpy, Blank, Blank, &DummyColor, &DummyColor, 0, 0);
- XFreePixmap (dpy, Blank);
- XDefineCursor(dpy, win, blankCursor);
+ XInitThreads();
+ dpy = XOpenDisplay(NULL);
}
- if (fullscreen)
+ void MainLoop() override
{
- X11Utils::EWMH_Fullscreen(dpy, _NET_WM_STATE_TOGGLE);
+ Window win = (Window)Core::GetWindowHandle();
+ XSelectInput(dpy, win, KeyPressMask | FocusChangeMask);
+
+ if (SConfig::GetInstance().m_LocalCoreStartupParameter.bDisableScreenSaver)
+ X11Utils::InhibitScreensaver(dpy, win, true);
+
#if defined(HAVE_XRANDR) && HAVE_XRANDR
- XRRConfig->ToggleDisplayMode(True);
+ XRRConfig = new X11Utils::XRRConfiguration(dpy, win);
#endif
- }
- // The actual loop
- while (running)
- {
- XEvent event;
- KeySym key;
- for (int num_events = XPending(dpy); num_events > 0; num_events--)
+ if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
{
- XNextEvent(dpy, &event);
- switch (event.type)
+ // make a blank cursor
+ Pixmap Blank;
+ XColor DummyColor;
+ char ZeroData[1] = {0};
+ Blank = XCreateBitmapFromData (dpy, win, ZeroData, 1, 1);
+ blankCursor = XCreatePixmapCursor(dpy, Blank, Blank, &DummyColor, &DummyColor, 0, 0);
+ XFreePixmap (dpy, Blank);
+ XDefineCursor(dpy, win, blankCursor);
+ }
+
+ bool fullscreen = SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen;
+
+ if (fullscreen)
+ {
+ X11Utils::EWMH_Fullscreen(dpy, _NET_WM_STATE_TOGGLE);
+#if defined(HAVE_XRANDR) && HAVE_XRANDR
+ XRRConfig->ToggleDisplayMode(True);
+#endif
+ }
+
+ // The actual loop
+ while (running)
+ {
+ XEvent event;
+ KeySym key;
+ for (int num_events = XPending(dpy); num_events > 0; num_events--)
{
+ XNextEvent(dpy, &event);
+ switch (event.type)
+ {
case KeyPress:
key = XLookupKeysym((XKeyEvent*)&event, 0);
if (key == XK_Escape)
@@ -217,7 +232,7 @@ static void X11_MainLoop()
case FocusIn:
rendererHasFocus = true;
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor &&
- Core::GetState() != Core::CORE_PAUSE)
+ Core::GetState() != Core::CORE_PAUSE)
XDefineCursor(dpy, win, blankCursor);
break;
case FocusOut:
@@ -225,44 +240,47 @@ static void X11_MainLoop()
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
XUndefineCursor(dpy, win);
break;
+ }
}
+ if (!fullscreen)
+ {
+ Window winDummy;
+ unsigned int borderDummy, depthDummy;
+ XGetGeometry(dpy, win, &winDummy,
+ &SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowXPos,
+ &SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowYPos,
+ (unsigned int *)&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth,
+ (unsigned int *)&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight,
+ &borderDummy, &depthDummy);
+ }
+ usleep(100000);
}
- if (!fullscreen)
- {
- Window winDummy;
- unsigned int borderDummy, depthDummy;
- XGetGeometry(dpy, win, &winDummy,
- &SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowXPos,
- &SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowYPos,
- (unsigned int *)&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth,
- (unsigned int *)&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight,
- &borderDummy, &depthDummy);
- }
- usleep(100000);
}
+ void Shutdown() override
+ {
#if defined(HAVE_XRANDR) && HAVE_XRANDR
- delete XRRConfig;
+ delete XRRConfig;
#endif
- if (SConfig::GetInstance().m_LocalCoreStartupParameter.bDisableScreenSaver)
- X11Utils::InhibitScreensaver(dpy, win, false);
- if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
- XFreeCursor(dpy, blankCursor);
- XCloseDisplay(dpy);
- Core::Stop();
-}
+ if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
+ XFreeCursor(dpy, blankCursor);
+
+ XCloseDisplay(dpy);
+ }
+};
#endif
-int main(int argc, char* argv[])
+static Platform* GetPlatform()
{
-#ifdef __APPLE__
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSEvent *event = [[NSEvent alloc] init];
- [NSApplication sharedApplication];
- [NSApp activateIgnoringOtherApps: YES];
- [NSApp finishLaunching];
+#if HAVE_X11
+ return new PlatformX11();
#endif
+ return nullptr;
+}
+
+int main(int argc, char* argv[])
+{
int ch, help = 0;
struct option longopts[] = {
{ "exec", no_argument, nullptr, 'e' },
@@ -298,6 +316,13 @@ int main(int argc, char* argv[])
return 1;
}
+ platform = GetPlatform();
+ if (!platform)
+ {
+ fprintf(stderr, "No platform found\n");
+ return 1;
+ }
+
LogManager::Init();
SConfig::Init();
VideoBackend::PopulateList();
@@ -305,45 +330,30 @@ int main(int argc, char* argv[])
m_LocalCoreStartupParameter.m_strVideoBackend);
WiimoteReal::LoadSettings();
- // No use running the loop when booting fails
- if (BootManager::BootCore(argv[optind]))
- {
-#if HAVE_X11
- XInitThreads();
- X11_MainLoop();
-#endif
-#ifdef __APPLE__
- while (running)
- {
- event = [NSApp nextEventMatchingMask: NSAnyEventMask
- untilDate: [NSDate distantFuture]
- inMode: NSDefaultRunLoopMode dequeue: YES];
+ platform->Init();
- if ([event type] == NSKeyDown &&
- [event modifierFlags] & NSCommandKeyMask &&
- [[event characters] UTF8String][0] == 'q')
- {
- Core::Stop();
- break;
- }
+ if (!BootManager::BootCore(argv[optind]))
+ {
+ fprintf(stderr, "Could not boot %s\n", argv[optind]);
+ return 1;
+ }
- if ([event type] != NSKeyDown)
- [NSApp sendEvent: event];
- }
+ while (!Core::IsRunning())
+ updateMainFrameEvent.Wait();
- [event release];
- [pool release];
-#else
- while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN)
- updateMainFrameEvent.Wait();
-#endif
- }
+ platform->MainLoop();
+ Core::Stop();
+ while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN)
+ updateMainFrameEvent.Wait();
+ platform->Shutdown();
Core::Shutdown();
WiimoteReal::Shutdown();
VideoBackend::ClearList();
SConfig::Shutdown();
LogManager::Shutdown();
+ delete platform;
+
return 0;
}