2014-02-17 10:18:15 +00:00
|
|
|
// Copyright 2014 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2012-12-26 18:12:26 +00:00
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
#include "Common/Thread.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/Host.h"
|
2014-08-09 13:49:45 +00:00
|
|
|
#include "DolphinWX/GLInterface/X11_Util.h"
|
|
|
|
#include "VideoBackends/OGL/GLInterfaceBase.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/VideoConfig.h"
|
2012-12-26 18:12:26 +00:00
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
void cX11Window::Initialize(Display *_dpy)
|
2012-12-26 18:12:26 +00:00
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
dpy = _dpy;
|
|
|
|
}
|
|
|
|
|
|
|
|
Window cX11Window::CreateXWindow(Window parent, XVisualInfo *vi)
|
|
|
|
{
|
|
|
|
XSetWindowAttributes attr;
|
|
|
|
|
|
|
|
colormap = XCreateColormap(dpy, parent, vi->visual, AllocNone);
|
|
|
|
|
2012-12-26 18:12:26 +00:00
|
|
|
// Setup window attributes
|
2014-08-09 13:49:45 +00:00
|
|
|
attr.colormap = colormap;
|
2012-12-26 18:12:26 +00:00
|
|
|
|
2014-08-21 19:39:03 +00:00
|
|
|
XWindowAttributes attribs;
|
|
|
|
if (!XGetWindowAttributes(dpy, parent, &attribs))
|
|
|
|
{
|
|
|
|
ERROR_LOG(VIDEO, "Window attribute retrieval failed");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-26 18:12:26 +00:00
|
|
|
// Create the window
|
2014-08-09 13:49:45 +00:00
|
|
|
win = XCreateWindow(dpy, parent,
|
2014-08-21 19:39:03 +00:00
|
|
|
0, 0, attribs.width, attribs.height, 0,
|
2014-08-09 13:49:45 +00:00
|
|
|
vi->depth, InputOutput, vi->visual,
|
2014-08-09 14:54:42 +00:00
|
|
|
CWColormap, &attr);
|
2014-08-09 13:49:45 +00:00
|
|
|
XSelectInput(dpy, parent, StructureNotifyMask);
|
|
|
|
XMapWindow(dpy, win);
|
|
|
|
XSync(dpy, True);
|
|
|
|
|
|
|
|
xEventThread = std::thread(&cX11Window::XEventThread, this);
|
|
|
|
|
|
|
|
return win;
|
2012-12-26 18:12:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cX11Window::DestroyXWindow(void)
|
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
XUnmapWindow(dpy, win);
|
2014-08-25 05:33:51 +00:00
|
|
|
win = 0;
|
2014-08-09 13:49:45 +00:00
|
|
|
if (xEventThread.joinable())
|
|
|
|
xEventThread.join();
|
|
|
|
XFreeColormap(dpy, colormap);
|
2012-12-26 18:12:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cX11Window::XEventThread()
|
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
while (win)
|
2012-12-26 18:12:26 +00:00
|
|
|
{
|
|
|
|
XEvent event;
|
2014-08-09 13:49:45 +00:00
|
|
|
for (int num_events = XPending(dpy); num_events > 0; num_events--)
|
2012-12-26 18:12:26 +00:00
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
XNextEvent(dpy, &event);
|
2014-03-10 11:30:55 +00:00
|
|
|
switch (event.type) {
|
2012-12-26 18:12:26 +00:00
|
|
|
case ConfigureNotify:
|
2014-08-09 13:49:45 +00:00
|
|
|
XResizeWindow(dpy, win, event.xconfigure.width, event.xconfigure.height);
|
2013-07-21 05:02:10 +00:00
|
|
|
GLInterface->SetBackBufferDimensions(event.xconfigure.width, event.xconfigure.height);
|
2012-12-26 18:12:26 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Common::SleepCurrentThread(20);
|
|
|
|
}
|
|
|
|
}
|