Merge pull request #644 from NatsumiFox/master

GUI: Remember window x/y position and maximized state.
This commit is contained in:
tildearrow 2022-09-08 01:35:29 -05:00 committed by GitHub
commit 43100fbbee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 111 additions and 29 deletions

View file

@ -2588,6 +2588,35 @@ void FurnaceGUI::processPoint(SDL_Event& ev) {
}
}
// how many pixels should be visible at least at x/y dir
#define OOB_PIXELS_SAFETY 25
bool FurnaceGUI::detectOutOfBoundsWindow() {
int count = SDL_GetNumVideoDisplays();
if(count < 1) {
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;
}
bool xbound = (rect.x + OOB_PIXELS_SAFETY) <= (scrX + scrW) && (rect.x + rect.w - OOB_PIXELS_SAFETY) >= scrX;
bool ybound = (rect.y + OOB_PIXELS_SAFETY) <= (scrY + scrH) && (rect.y + rect.h - OOB_PIXELS_SAFETY) >= scrY;
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) {
return true;
}
}
return false;
}
bool FurnaceGUI::loop() {
bool doThreadedInput=!settings.noThreadedInput;
if (doThreadedInput) {
@ -2607,6 +2636,7 @@ bool FurnaceGUI::loop() {
if (settings.powerSave) SDL_WaitEventTimeout(NULL,500);
}
eventTimeBegin=SDL_GetPerformanceCounter();
bool updateWindow = false;
while (SDL_PollEvent(&ev)) {
WAKE_UP;
ImGui_ImplSDL2_ProcessEvent(&ev);
@ -2713,6 +2743,20 @@ bool FurnaceGUI::loop() {
scrW=ev.window.data1/dpiScale;
scrH=ev.window.data2/dpiScale;
#endif
updateWindow=true;
break;
case SDL_WINDOWEVENT_MOVED:
scrX=ev.window.data1;
scrY=ev.window.data2;
updateWindow=true;
break;
case SDL_WINDOWEVENT_MAXIMIZED:
scrMax=true;
updateWindow=true;
break;
case SDL_WINDOWEVENT_RESTORED:
scrMax=false;
updateWindow=true;
break;
}
break;
@ -2768,6 +2812,16 @@ bool FurnaceGUI::loop() {
}
}
// update config x/y/w/h values based on scrMax state
if(updateWindow) {
if(!scrMax) {
scrConfX=scrX;
scrConfY=scrY;
scrConfW=scrW;
scrConfH=scrH;
}
}
wantCaptureKeyboard=ImGui::GetIO().WantTextInput;
if (wantCaptureKeyboard!=oldWantCaptureKeyboard) {
@ -4519,8 +4573,11 @@ bool FurnaceGUI::init() {
SDL_Surface* icon=SDL_CreateRGBSurfaceFrom(furIcon,256,256,32,256*4,0xff,0xff00,0xff0000,0xff000000);
#endif
scrW=e->getConfInt("lastWindowWidth",1280);
scrH=e->getConfInt("lastWindowHeight",800);
scrW=scrConfW=e->getConfInt("lastWindowWidth",1280);
scrH=scrConfH=e->getConfInt("lastWindowHeight",800);
scrX=scrConfX=e->getConfInt("lastWindowX",SDL_WINDOWPOS_CENTERED);
scrY=scrConfY=e->getConfInt("lastWindowY",SDL_WINDOWPOS_CENTERED);
scrMax=e->getConfBool("lastWindowMax",false);
#ifndef __APPLE__
SDL_Rect displaySize;
@ -4536,7 +4593,14 @@ bool FurnaceGUI::init() {
SDL_Init(SDL_INIT_VIDEO);
sdlWin=SDL_CreateWindow("Furnace",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,scrW*dpiScale,scrH*dpiScale,SDL_WINDOW_RESIZABLE|SDL_WINDOW_ALLOW_HIGHDPI|(fullScreen?SDL_WINDOW_FULLSCREEN_DESKTOP:0));
// if window would spawn out of bounds, force it to be get default position
if(!detectOutOfBoundsWindow()) {
scrMax = false;
scrX=scrConfX=SDL_WINDOWPOS_CENTERED;
scrY=scrConfY=SDL_WINDOWPOS_CENTERED;
}
sdlWin=SDL_CreateWindow("Furnace",scrX,scrY,scrW*dpiScale,scrH*dpiScale,SDL_WINDOW_RESIZABLE|SDL_WINDOW_ALLOW_HIGHDPI|(scrMax?SDL_WINDOW_MAXIMIZED:0)|(fullScreen?SDL_WINDOW_FULLSCREEN_DESKTOP:0));
if (sdlWin==NULL) {
logE("could not open window! %s",SDL_GetError());
return false;
@ -4702,8 +4766,11 @@ bool FurnaceGUI::finish() {
e->setConf("spoilerOpen",spoilerOpen);
// commit last window size
e->setConf("lastWindowWidth",scrW);
e->setConf("lastWindowHeight",scrH);
e->setConf("lastWindowWidth",scrConfW);
e->setConf("lastWindowHeight",scrConfH);
e->setConf("lastWindowX",settings.saveWindowPos?scrConfX:(int)SDL_WINDOWPOS_CENTERED);
e->setConf("lastWindowY",settings.saveWindowPos?scrConfY:(int)SDL_WINDOWPOS_CENTERED);
e->setConf("lastWindowMax",scrMax);
e->setConf("tempoView",tempoView);
e->setConf("waveHex",waveHex);

View file

@ -1010,7 +1010,9 @@ class FurnaceGUI {
FurnaceGUIFileDialog* fileDialog;
int scrW, scrH;
int scrW, scrH, scrConfW, scrConfH;
int scrX, scrY, scrConfX, scrConfY;
bool scrMax;
double dpiScale;
@ -1144,6 +1146,7 @@ class FurnaceGUI {
int dragMovesSelection;
int unsignedDetune;
int noThreadedInput;
int saveWindowPos;
int clampSamples;
int saveUnusedPatterns;
int channelColors;
@ -1731,6 +1734,7 @@ class FurnaceGUI {
void runBackupThread();
void pushPartBlend();
void popPartBlend();
bool detectOutOfBoundsWindow();
int processEvent(SDL_Event* ev);
bool loop();
bool finish();

View file

@ -514,6 +514,14 @@ void FurnaceGUI::drawSettings() {
ImGui::SetTooltip("threaded input processes key presses for note preview on a separate thread (on supported platforms), which reduces latency.\nhowever, crashes have been reported when threaded input is on. enable this option if that is the case.");
}
bool saveWindowPosB=settings.saveWindowPos;
if (ImGui::Checkbox("Remember window location",&saveWindowPosB)) {
settings.saveWindowPos=saveWindowPosB;
}
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("remembers where window was last located on start-up. When disabled, window will start in a defaul location.");
}
bool blankInsB=settings.blankIns;
if (ImGui::Checkbox("New instruments are blank",&blankInsB)) {
settings.blankIns=blankInsB;
@ -2251,6 +2259,7 @@ void FurnaceGUI::syncSettings() {
settings.dragMovesSelection=e->getConfInt("dragMovesSelection",2);
settings.unsignedDetune=e->getConfInt("unsignedDetune",0);
settings.noThreadedInput=e->getConfInt("noThreadedInput",0);
settings.saveWindowPos=e->getConfInt("saveWindowPos",1);
settings.initialSysName=e->getConfString("initialSysName","");
settings.clampSamples=e->getConfInt("clampSamples",0);
settings.noteOffLabel=e->getConfString("noteOffLabel","OFF");
@ -2354,6 +2363,7 @@ void FurnaceGUI::syncSettings() {
clampSetting(settings.dragMovesSelection,0,2);
clampSetting(settings.unsignedDetune,0,1);
clampSetting(settings.noThreadedInput,0,1);
clampSetting(settings.saveWindowPos,0,1);
clampSetting(settings.clampSamples,0,1);
clampSetting(settings.saveUnusedPatterns,0,1);
clampSetting(settings.channelColors,0,2);
@ -2502,6 +2512,7 @@ void FurnaceGUI::commitSettings() {
e->setConf("dragMovesSelection",settings.dragMovesSelection);
e->setConf("unsignedDetune",settings.unsignedDetune);
e->setConf("noThreadedInput",settings.noThreadedInput);
e->setConf("saveWindowPos",settings.saveWindowPos);
e->setConf("clampSamples",settings.clampSamples);
e->setConf("noteOffLabel",settings.noteOffLabel);
e->setConf("noteRelLabel",settings.noteRelLabel);