GUI: prevent window from being too big

issue #942
This commit is contained in:
tildearrow 2023-04-30 16:07:46 -05:00
parent 4cb9970fa1
commit 672c440d4e
2 changed files with 20 additions and 6 deletions

View File

@ -3249,18 +3249,18 @@ void FurnaceGUI::pointMotion(int x, int y, int xrel, int yrel) {
// how many pixels should be visible at least at x/y dir
#define OOB_PIXELS_SAFETY 25
bool FurnaceGUI::detectOutOfBoundsWindow() {
bool FurnaceGUI::detectOutOfBoundsWindow(SDL_Rect& failing) {
int count=SDL_GetNumVideoDisplays();
if (count<1) {
logW("bounds check: error %s",SDL_GetError());
logW("bounds check: error: %s",SDL_GetError());
return false;
}
SDL_Rect rect;
for (int i=0; i<count; i++) {
if (SDL_GetDisplayUsableBounds(i,&rect)!=0) {
logW("bounds check: error %s",SDL_GetError());
return false;
logW("bounds check: error in display %d: %s",i,SDL_GetError());
continue;
}
bool xbound=((rect.x+OOB_PIXELS_SAFETY)<=(scrX+scrW)) && ((rect.x+rect.w-OOB_PIXELS_SAFETY)>=scrX);
@ -3268,6 +3268,7 @@ bool FurnaceGUI::detectOutOfBoundsWindow() {
logD("bounds check: display %d is at %dx%dx%dx%d: %s%s",i,rect.x+OOB_PIXELS_SAFETY,rect.y+OOB_PIXELS_SAFETY,rect.x+rect.w-OOB_PIXELS_SAFETY,rect.y+rect.h-OOB_PIXELS_SAFETY,xbound?"x":"",ybound?"y":"");
if (xbound && ybound) {
failing=rect;
return true;
}
}
@ -6007,10 +6008,23 @@ bool FurnaceGUI::init() {
#ifndef IS_MOBILE
// if window would spawn out of bounds, force it to be get default position
if (!detectOutOfBoundsWindow()) {
SDL_Rect bounds;
if (!detectOutOfBoundsWindow(bounds)) {
scrMax=false;
scrX=scrConfX=SDL_WINDOWPOS_CENTERED;
scrY=scrConfY=SDL_WINDOWPOS_CENTERED;
// make sure our window isn't big
if (bounds.w<scrW) {
logD("resizing width because it does not fit");
scrW=bounds.w-OOB_PIXELS_SAFETY*2;
if (scrW<200) scrW=200;
}
if (bounds.h<scrH) {
logD("resizing height because it does not fit");
scrH=bounds.h-OOB_PIXELS_SAFETY*2;
if (scrH<100) scrH=100;
}
}
#endif

View File

@ -2159,7 +2159,7 @@ class FurnaceGUI {
void runBackupThread();
void pushPartBlend();
void popPartBlend();
bool detectOutOfBoundsWindow();
bool detectOutOfBoundsWindow(SDL_Rect& failing);
int processEvent(SDL_Event* ev);
bool loop();
bool finish();