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;
|
|
|
|
attr.background_pixel = BlackPixel(dpy, 0);
|
|
|
|
attr.border_pixel = 0;
|
2012-12-26 18:12:26 +00:00
|
|
|
|
|
|
|
// Create the window
|
2014-08-09 13:49:45 +00:00
|
|
|
win = XCreateWindow(dpy, parent,
|
|
|
|
0, 0, 1, 1, 0,
|
|
|
|
vi->depth, InputOutput, vi->visual,
|
|
|
|
CWBorderPixel | CWBackPixel | CWColormap, &attr);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|