Implemented window size saving/loading for Linux.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
pull/35/head
sigonasr2 9 months ago
parent 5d7b342c51
commit 92f488986e
  1. 1
      Adventures in Lestoria/SaveFile.cpp
  2. 34
      Adventures in Lestoria/olcPixelGameEngine.h

@ -156,6 +156,7 @@ const void SaveFile::SaveGame(){
#pragma endregion
#pragma region Save System Settings
//HACK ALERT! It's possible that on X11 the actual reported window position is offset later when we set it. We will set it now to see if it moves or adjusts, and use that new position instead as the position we save.
saveSystemFile["Window Pos"].SetInt(game->GetActualWindowPos().x,0);
saveSystemFile["Window Pos"].SetInt(game->GetActualWindowPos().y,1);
saveSystemFile["Window Size"].SetInt(game->GetWindowSize().x,0);

@ -6575,10 +6575,12 @@ namespace olc
private:
X11::Display* olc_Display = nullptr;
X11::Window olc_WindowRoot;
X11::Window olc_WindowParent;
X11::Window olc_Window;
X11::XVisualInfo* olc_VisualInfo;
X11::Colormap olc_ColourMap;
X11::XSetWindowAttributes olc_SetWindowAttribs;
vi2d desiredPos{30,30};
public:
virtual olc::rcode ApplicationStartUp() override
@ -6718,9 +6720,21 @@ namespace olc
}
virtual void SetWindowPos(vi2d pos)override{
using namespace X11;
if(!ptrPGE->IsFullscreen()){
Window rootW,parentW;
Window*childWindows;
unsigned int children;
XQueryTree(olc_Display,olc_Window,&rootW,&olc_WindowParent,&childWindows,&children);
if(childWindows!=nullptr)XFree(childWindows);
XWindowAttributes gwa;
XGetWindowAttributes(olc_Display, olc_Window, &gwa);
XWindowAttributes cwa;
XGetWindowAttributes(olc_Display, olc_WindowParent, &cwa);
int diffX=gwa.x-cwa.x; //The border is some defined size, and the window manager may be accounting for that when deciding window positions. If we take the difference of window between the two and subtract, we probably end up with a window at the right spot!
int diffY=gwa.y-cwa.y;
XMapWindow(olc_Display, olc_Window);
XMoveWindow(olc_Display, olc_Window, pos.x, pos.y);
XMoveWindow(olc_Display, olc_Window, pos.x-diffX, pos.y-diffY);
}
}
virtual void SetWindowSize(vi2d size)override{
@ -6782,17 +6796,31 @@ namespace olc
XNextEvent(olc_Display, &xev);
if (xev.type == Expose)
{
Window rootW,parentW;
Window*childWindows;
unsigned int children;
XQueryTree(olc_Display,olc_Window,&rootW,&olc_WindowParent,&childWindows,&children);
if(childWindows!=nullptr)XFree(childWindows);
XWindowAttributes cwa;
XGetWindowAttributes(olc_Display, olc_WindowParent, &cwa);
XWindowAttributes gwa;
XGetWindowAttributes(olc_Display, olc_Window, &gwa);
ptrPGE->olc_UpdateWindowPos(gwa.x, gwa.y);
ptrPGE->olc_UpdateActualWindowPos(gwa.x, gwa.y);
ptrPGE->olc_UpdateActualWindowPos(cwa.x, cwa.y);
ptrPGE->olc_UpdateWindowSize(gwa.width, gwa.height);
}
else if (xev.type == ConfigureNotify)
{
Window rootW,parentW;
Window*childWindows;
unsigned int children;
XQueryTree(olc_Display,olc_Window,&rootW,&olc_WindowParent,&childWindows,&children);
if(childWindows!=nullptr)XFree(childWindows);
XWindowAttributes gwa;
XGetWindowAttributes(olc_Display, olc_WindowParent, &gwa);
XConfigureEvent xce = xev.xconfigure;
ptrPGE->olc_UpdateWindowPos(xce.x, xce.y);
ptrPGE->olc_UpdateActualWindowPos(xce.x, xce.y);
ptrPGE->olc_UpdateActualWindowPos(gwa.x, gwa.y);
ptrPGE->olc_UpdateWindowSize(xce.width, xce.height);
}
else if (xev.type == KeyPress)

Loading…
Cancel
Save