dolphin/Source/Core/DolphinWX/GLInterface/X11_Util.cpp
Jasper St. Pierre 0dd7f6f5ea MainNoGUI: Supply a window in Host_GetRenderHandle
Our existing code was relying on the GLX backend to create the GLX
window properly, and for the rest of the code to patch that up, sort
of. If we rely on Host_GetRenderHandle() returning a valid window, we
can do a lot better about this.

Create a simple window inside MainNoGUI to make this happen.
2014-08-19 10:05:57 -04:00

65 lines
1.8 KiB
C++

// Copyright 2014 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#include "Core/Host.h"
#include "DolphinWX/GLInterface/GLInterface.h"
#include "VideoCommon/VideoConfig.h"
void cX11Window::CreateXWindow(void)
{
Atom wmProtocols[1];
// Setup window attributes
GLWin.attr.colormap = XCreateColormap(GLWin.dpy,
GLWin.parent, GLWin.vi->visual, AllocNone);
GLWin.attr.event_mask = StructureNotifyMask;
GLWin.attr.background_pixel = BlackPixel(GLWin.dpy, GLWin.screen);
GLWin.attr.border_pixel = 0;
// Create the window
GLWin.win = XCreateWindow(GLWin.dpy, GLWin.parent,
0, 0, 1, 1, 0,
GLWin.vi->depth, InputOutput, GLWin.vi->visual,
CWBorderPixel | CWBackPixel | CWColormap | CWEventMask, &GLWin.attr);
wmProtocols[0] = XInternAtom(GLWin.dpy, "WM_DELETE_WINDOW", True);
XSetWMProtocols(GLWin.dpy, GLWin.win, wmProtocols, 1);
XMapRaised(GLWin.dpy, GLWin.win);
XSync(GLWin.dpy, True);
GLWin.xEventThread = std::thread(&cX11Window::XEventThread, this);
}
void cX11Window::DestroyXWindow(void)
{
XUnmapWindow(GLWin.dpy, GLWin.win);
GLWin.win = 0;
if (GLWin.xEventThread.joinable())
GLWin.xEventThread.join();
XFreeColormap(GLWin.dpy, GLWin.attr.colormap);
}
void cX11Window::XEventThread()
{
while (GLWin.win)
{
XEvent event;
for (int num_events = XPending(GLWin.dpy); num_events > 0; num_events--)
{
XNextEvent(GLWin.dpy, &event);
switch (event.type) {
case ConfigureNotify:
GLInterface->SetBackBufferDimensions(event.xconfigure.width, event.xconfigure.height);
break;
case ClientMessage:
if ((unsigned long) event.xclient.data.l[0] ==
XInternAtom(GLWin.dpy, "WM_DELETE_WINDOW", False))
Host_Message(WM_USER_STOP);
break;
default:
break;
}
}
Common::SleepCurrentThread(20);
}
}