Use x11 functions in irr_driver only if x11 device was created

This commit is contained in:
Deve 2017-05-14 00:05:36 +02:00
parent da802d836d
commit 1966d3f072
3 changed files with 57 additions and 44 deletions

View File

@ -20,6 +20,7 @@ namespace irr
/** This device works on Windows Mobile, Pocket PC and Microsoft SmartPhone devices */
EIDT_WINCE,
//! A device native to Linux
EIDT_WAYLAND,
//! A device native to Unix style operating systems.

View File

@ -454,7 +454,7 @@ bool ContextManagerEGL::makeCurrent()
bool success = eglMakeCurrent(m_egl_display, m_egl_surface, m_egl_surface,
m_egl_context);
return success;
return success;
}

View File

@ -312,22 +312,26 @@ void IrrDriver::updateConfigIfRelevant()
Log::warn("irr_driver", "Could not retrieve window location\n");
}
#elif defined(__linux__) && !defined(ANDROID)
const video::SExposedVideoData& videoData =
m_device->getVideoDriver()->getExposedVideoData();
Display* display = (Display*)videoData.OpenGLLinux.X11Display;
XWindowAttributes xwa;
XGetWindowAttributes(display, get_toplevel_parent(display,
videoData.OpenGLLinux.X11Window), &xwa);
int wx = xwa.x;
int wy = xwa.y;
Log::verbose("irr_driver",
"Retrieved window location for config : %i %i\n", wx, wy);
if (UserConfigParams::m_window_x != wx || UserConfigParams::m_window_y != wy)
if (m_device->getType() == EIDT_X11)
{
UserConfigParams::m_window_x = wx;
UserConfigParams::m_window_y = wy;
const video::SExposedVideoData& videoData =
m_device->getVideoDriver()->getExposedVideoData();
Display* display = (Display*)videoData.OpenGLLinux.X11Display;
XWindowAttributes xwa;
XGetWindowAttributes(display, get_toplevel_parent(display,
videoData.OpenGLLinux.X11Window), &xwa);
int wx = xwa.x;
int wy = xwa.y;
Log::verbose("irr_driver",
"Retrieved window location for config : %i %i\n", wx, wy);
if (UserConfigParams::m_window_x != wx ||
UserConfigParams::m_window_y != wy)
{
UserConfigParams::m_window_x = wx;
UserConfigParams::m_window_y = wy;
}
}
#endif
}
@ -418,6 +422,7 @@ void IrrDriver::initDevice()
UserConfigParams::m_width,
UserConfigParams::m_height);
res = modes->getVideoModeResolution(res, res);
UserConfigParams::m_width = res.Width;
UserConfigParams::m_height = res.Height;
}
@ -711,17 +716,20 @@ void IrrDriver::initDevice()
// Only change video driver settings if we are showing graphics
if (!ProfileWorld::isNoGraphics())
{
#if 0//defined(__linux__) && !defined(ANDROID) && !defined(SERVER_ONLY)
// Set class hints on Linux, used by Window Managers.
const video::SExposedVideoData& videoData = m_video_driver
->getExposedVideoData();
XClassHint* classhint = XAllocClassHint();
classhint->res_name = (char*)"SuperTuxKart";
classhint->res_class = (char*)"SuperTuxKart";
XSetClassHint((Display*)videoData.OpenGLLinux.X11Display,
videoData.OpenGLLinux.X11Window,
classhint);
XFree(classhint);
#if defined(__linux__) && !defined(ANDROID) && !defined(SERVER_ONLY)
if (m_device->getType() == EIDT_X11)
{
// Set class hints on Linux, used by Window Managers.
const video::SExposedVideoData& videoData = m_video_driver
->getExposedVideoData();
XClassHint* classhint = XAllocClassHint();
classhint->res_name = (char*)"SuperTuxKart";
classhint->res_class = (char*)"SuperTuxKart";
XSetClassHint((Display*)videoData.OpenGLLinux.X11Display,
videoData.OpenGLLinux.X11Window,
classhint);
XFree(classhint);
}
#endif
m_device->setWindowCaption(L"SuperTuxKart");
m_device->getVideoDriver()
@ -892,25 +900,29 @@ bool IrrDriver::moveWindow(int x, int y)
return false;
}
#elif defined(__linux__) && !defined(ANDROID)
const video::SExposedVideoData& videoData = m_video_driver->getExposedVideoData();
Display* display = (Display*)videoData.OpenGLLinux.X11Display;
int screen = DefaultScreen(display);
int screen_w = DisplayWidth(display, screen);
int screen_h = DisplayHeight(display, screen);
if (x + UserConfigParams::m_width > screen_w)
if (m_device->getType() == EIDT_X11)
{
x = screen_w - UserConfigParams::m_width;
const video::SExposedVideoData& videoData =
m_video_driver->getExposedVideoData();
Display* display = (Display*)videoData.OpenGLLinux.X11Display;
int screen = DefaultScreen(display);
int screen_w = DisplayWidth(display, screen);
int screen_h = DisplayHeight(display, screen);
if (x + UserConfigParams::m_width > screen_w)
{
x = screen_w - UserConfigParams::m_width;
}
if (y + UserConfigParams::m_height > screen_h)
{
y = screen_h - UserConfigParams::m_height;
}
// TODO: Actually handle possible failure
XMoveWindow(display, videoData.OpenGLLinux.X11Window, x, y);
}
if (y + UserConfigParams::m_height > screen_h)
{
y = screen_h - UserConfigParams::m_height;
}
// TODO: Actually handle possible failure
XMoveWindow(display, videoData.OpenGLLinux.X11Window, x, y);
#endif
#endif
return true;