dolphin/Source/Core/DolphinWX/GLInterface/X11_Util.cpp

72 lines
1.5 KiB
C++
Raw Normal View History

// Copyright 2014 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
2012-12-26 18:12:26 +00:00
#include "Common/Thread.h"
#include "Core/Host.h"
#include "DolphinWX/GLInterface/X11_Util.h"
#include "VideoBackends/OGL/GLInterfaceBase.h"
#include "VideoCommon/VideoConfig.h"
2012-12-26 18:12:26 +00:00
void cX11Window::Initialize(Display *_dpy)
2012-12-26 18:12:26 +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
attr.colormap = colormap;
2012-12-26 18:12:26 +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
win = XCreateWindow(dpy, parent,
0, 0, attribs.width, attribs.height, 0,
vi->depth, InputOutput, vi->visual,
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)
{
XUnmapWindow(dpy, win);
2014-08-25 05:33:51 +00:00
win = 0;
if (xEventThread.joinable())
xEventThread.join();
XFreeColormap(dpy, colormap);
2012-12-26 18:12:26 +00:00
}
void cX11Window::XEventThread()
{
while (win)
2012-12-26 18:12:26 +00:00
{
XEvent event;
XNextEvent(dpy, &event);
switch (event.type)
2012-12-26 18:12:26 +00:00
{
case ConfigureNotify:
XResizeWindow(dpy, win, event.xconfigure.width, event.xconfigure.height);
GLInterface->SetBackBufferDimensions(event.xconfigure.width, event.xconfigure.height);
break;
default:
break;
2012-12-26 18:12:26 +00:00
}
}
}