Compare commits

...

5 Commits

@ -265,10 +265,9 @@ bool GlWndProc(CDriverGL *driver, XEvent &e)
case ConfigureNotify: case ConfigureNotify:
if (driver->_CurrentMode.Windowed && driver->_WndActive) if (driver->_WndActive)
{ {
// first time setting decoration sizes if (driver->_CurrentMode.Windowed)
if ((driver->_DecorationWidth == -1) || (driver->_DecorationWidth == 0))
{ {
Atom type_return = 0; Atom type_return = 0;
int format_return = 0; int format_return = 0;
@ -294,12 +293,19 @@ bool GlWndProc(CDriverGL *driver, XEvent &e)
// don't allow negative decoration sizes // don't allow negative decoration sizes
if (driver->_DecorationWidth < 0) driver->_DecorationWidth = 0; if (driver->_DecorationWidth < 0) driver->_DecorationWidth = 0;
if (driver->_DecorationHeight < 0) driver->_DecorationHeight = 0; if (driver->_DecorationHeight < 0) driver->_DecorationHeight = 0;
driver->_WindowX = e.xconfigure.x - driver->_DecorationWidth;
driver->_WindowY = e.xconfigure.y - driver->_DecorationHeight;
}
else
{
// fullscreen
driver->_WindowX = e.xconfigure.x;
driver->_WindowY = e.xconfigure.y;
} }
driver->_CurrentMode.Width = e.xconfigure.width; driver->_CurrentMode.Width = e.xconfigure.width;
driver->_CurrentMode.Height = e.xconfigure.height; driver->_CurrentMode.Height = e.xconfigure.height;
driver->_WindowX = e.xconfigure.x - driver->_DecorationWidth;
driver->_WindowY = e.xconfigure.y - driver->_DecorationHeight;
} }
break; break;
@ -641,6 +647,11 @@ void CDriverGL::setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps)
} }
// -------------------------------------------------- // --------------------------------------------------
#if defined(NL_OS_UNIX) && !defined(NL_OS_MAC)
static Bool WaitForNotify( Display *dpy, XEvent *event, XPointer arg ) {
return (event->type == MapNotify) && (event->xmap.window == reinterpret_cast<Window>(arg));
}
#endif
bool CDriverGL::setDisplay(nlWindow wnd, const GfxMode &mode, bool show, bool resizeable) bool CDriverGL::setDisplay(nlWindow wnd, const GfxMode &mode, bool show, bool resizeable)
{ {
H_AUTO_OGL(CDriverGL_setDisplay) H_AUTO_OGL(CDriverGL_setDisplay)
@ -1145,14 +1156,17 @@ bool CDriverGL::setDisplay(nlWindow wnd, const GfxMode &mode, bool show, bool re
} }
glXMakeCurrent (_dpy, _win, _ctx); glXMakeCurrent (_dpy, _win, _ctx);
// XMapRaised (_dpy, _win);
// XMapWindow(_dpy, _win);
_EventEmitter.init (_dpy, _win, this); _EventEmitter.init (_dpy, _win, this);
// XEvent event; // KDE/GNOME has issues selecting correct fullscreen monitor if window is not visible before setMode()
// XIfEvent(dpy, &event, WaitForNotify, (char *)this); if (!mode.Windowed)
{
XMapRaised(_dpy, _win);
XEvent event;
nlctassert(sizeof(XPointer) >= sizeof(_win));
XPeekIfEvent(_dpy, &event, WaitForNotify, reinterpret_cast<XPointer>(_win));
}
#endif // NL_OS_UNIX #endif // NL_OS_UNIX
@ -2484,13 +2498,19 @@ bool CDriverGL::getCurrentScreenMode(GfxMode &mode)
Window child; Window child;
// get window position so we can compare monitors (or mouse position if window not visible yet) // get window position so we can compare monitors (or mouse position if window not visible yet)
XWindowAttributes xwa; bool useMouseForPosition = true;
XGetWindowAttributes(_dpy, _win, &xwa); if (_win != EmptyWindow)
if (xwa.map_state != IsUnmapped)
{ {
XTranslateCoordinates(_dpy, _win, xwa.root, xwa.x, xwa.y, &x, &y, &child); XWindowAttributes xwa;
XGetWindowAttributes(_dpy, _win, &xwa);
if (xwa.map_state != IsUnmapped)
{
XTranslateCoordinates(_dpy, _win, xwa.root, xwa.x, xwa.y, &x, &y, &child);
useMouseForPosition = false;
}
} }
else
if (useMouseForPosition)
{ {
sint rx, ry, wx, wy; sint rx, ry, wx, wy;
uint mask; uint mask;
@ -2763,15 +2783,7 @@ void CDriverGL::setWindowPos(sint32 x, sint32 y)
#elif defined (NL_OS_UNIX) #elif defined (NL_OS_UNIX)
if (_CurrentMode.Windowed) if (_CurrentMode.Windowed)
{
// first time requesting decoration sizes
if (_WindowX && _WindowY && !_DecorationWidth && !_DecorationHeight && _WndActive)
{
_DecorationWidth = -1;
_DecorationHeight = -1;
}
XMoveWindow(_dpy, _win, x, y); XMoveWindow(_dpy, _win, x, y);
}
#endif // NL_OS_WINDOWS #endif // NL_OS_WINDOWS
} }
@ -2799,7 +2811,17 @@ void CDriverGL::showWindow(bool show)
if (show) if (show)
{ {
XMapRaised(_dpy, _win); // if window is mapped, then MapNotify event will not trigger and XPeekIfEvent deadlocks
XWindowAttributes attr;
XGetWindowAttributes(_dpy, _win, &attr);
if (attr.map_state == IsUnmapped)
{
XMapRaised(_dpy, _win);
// sync to MapNotify event or setWindowSize() in GNOME might resize window to wrong size
XEvent event;
nlctassert(sizeof(XPointer) >= sizeof(_win));
XPeekIfEvent(_dpy, &event, WaitForNotify, reinterpret_cast<XPointer>(_win));
}
// fix window position if windows manager want to impose them // fix window position if windows manager want to impose them
setWindowPos(_WindowX, _WindowY); setWindowPos(_WindowX, _WindowY);

@ -1235,27 +1235,9 @@ void prelogInit()
Driver->setWindowIcon(bitmaps); Driver->setWindowIcon(bitmaps);
#endif #endif
sint32 posX = 0, posY = 0; // use position saved in config
if (ClientCfg.Windowed) if (ClientCfg.Windowed)
{ Driver->setWindowPos(ClientCfg.PositionX, ClientCfg.PositionY);
// use position saved in config
posX = ClientCfg.PositionX;
posY = ClientCfg.PositionY;
}
else
{
// position is not saved in config so center the window
UDriver::CMode tmp;
if (Driver->getCurrentScreenMode(tmp))
{
posX = (tmp.Width - Driver->getWindowWidth())/2;
posY = (tmp.Height - Driver->getWindowHeight())/2;
}
}
// Set the window position
Driver->setWindowPos(posX, posY);
// Show the window // Show the window
Driver->showWindow(); Driver->showWindow();

Loading…
Cancel
Save