Files
dolphin/Source/Core/DolphinWX/GLInterface/X11_Util.cpp
Jasper St. Pierre 5cb5a6ecd2 Don't sleep in the event thread
The person who wrote this seemed to misunderstand how XPending and
XNextEvent actually work. XNextEvent will wait in poll if there's
no event yet, meaning that we don't need to sleep after we process
all the events; the kernel will sleep for us.

This changes indentation, so view with -w or a similar feature to
understand what's actually changed here.
2014-09-04 17:24:51 -07:00

72 lines
1.5 KiB
C++

// Copyright 2014 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#include "Common/Thread.h"
#include "Core/Host.h"
#include "DolphinWX/GLInterface/X11_Util.h"
#include "VideoBackends/OGL/GLInterfaceBase.h"
#include "VideoCommon/VideoConfig.h"
void cX11Window::Initialize(Display *_dpy)
{
dpy = _dpy;
}
Window cX11Window::CreateXWindow(Window parent, XVisualInfo *vi)
{
XSetWindowAttributes attr;
colormap = XCreateColormap(dpy, parent, vi->visual, AllocNone);
// Setup window attributes
attr.colormap = colormap;
XWindowAttributes attribs;
if (!XGetWindowAttributes(dpy, parent, &attribs))
{
ERROR_LOG(VIDEO, "Window attribute retrieval failed");
return 0;
}
// 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;
}
void cX11Window::DestroyXWindow(void)
{
XUnmapWindow(dpy, win);
win = 0;
if (xEventThread.joinable())
xEventThread.join();
XFreeColormap(dpy, colormap);
}
void cX11Window::XEventThread()
{
while (win)
{
XEvent event;
XNextEvent(dpy, &event);
switch (event.type)
{
case ConfigureNotify:
XResizeWindow(dpy, win, event.xconfigure.width, event.xconfigure.height);
GLInterface->SetBackBufferDimensions(event.xconfigure.width, event.xconfigure.height);
break;
default:
break;
}
}
}