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

@ -883,7 +883,7 @@ void FurnaceGUI::stopPreviewNote(SDL_Scancode scancode, bool autoNote) {
void FurnaceGUI::noteInput(int num, int key, int vol) {
DivPattern* pat=e->curPat[cursor.xCoarse].getPattern(e->curOrders->ord[cursor.xCoarse][curOrder],true);
prepareUndo(GUI_UNDO_PATTERN_EDIT);
if (key==100) { // note off
@ -2174,7 +2174,7 @@ void FurnaceGUI::editOptions(bool topMenu) {
snprintf(id,63,"%.2x##LatchFX",data);
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[fxColors[data]]);
}
if (ImGui::Selectable(id,latchTarget==3,ImGuiSelectableFlags_DontClosePopups)) {
latchTarget=3;
latchNibble=false;
@ -2247,7 +2247,7 @@ void FurnaceGUI::editOptions(bool topMenu) {
doTranspose(transposeAmount,opMaskTransposeValue);
ImGui::CloseCurrentPopup();
}
ImGui::Separator();
if (ImGui::MenuItem("interpolate",BIND_FOR(GUI_ACTION_PAT_INTERPOLATE))) doInterpolate();
if (ImGui::BeginMenu("change instrument...")) {
@ -2374,7 +2374,7 @@ void FurnaceGUI::toggleMobileUI(bool enable, bool force) {
if (mobileUI!=enable || force) {
if (!mobileUI && enable) {
ImGui::SaveIniSettingsToDisk(finalLayoutPath);
}
}
mobileUI=enable;
if (mobileUI) {
ImGui::GetIO().IniFilename=NULL;
@ -2382,7 +2382,7 @@ void FurnaceGUI::toggleMobileUI(bool enable, bool force) {
ImGui::GetIO().IniFilename=finalLayoutPath;
ImGui::LoadIniSettingsFromDisk(finalLayoutPath);
}
}
}
}
int _processEvent(void* instance, SDL_Event* event) {
@ -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) {
@ -2785,7 +2839,7 @@ bool FurnaceGUI::loop() {
if (ImGui::GetIO().MouseDown[0] || ImGui::GetIO().MouseDown[1] || ImGui::GetIO().MouseDown[2] || ImGui::GetIO().MouseDown[3] || ImGui::GetIO().MouseDown[4]) {
WAKE_UP;
}
while (true) {
midiLock.lock();
if (midiQueue.empty()) {
@ -2941,7 +2995,7 @@ bool FurnaceGUI::loop() {
eventTimeEnd=SDL_GetPerformanceCounter();
layoutTimeBegin=SDL_GetPerformanceCounter();
ImGui_ImplSDLRenderer_NewFrame();
ImGui_ImplSDL2_NewFrame(sdlWin);
ImGui::NewFrame();
@ -3205,7 +3259,7 @@ bool FurnaceGUI::loop() {
if (ImGui::MenuItem("log viewer",BIND_FOR(GUI_ACTION_WINDOW_LOG),logOpen)) logOpen=!logOpen;
if (ImGui::MenuItem("statistics",BIND_FOR(GUI_ACTION_WINDOW_STATS),statsOpen)) statsOpen=!statsOpen;
if (spoilerOpen) if (ImGui::MenuItem("spoiler",NULL,spoilerOpen)) spoilerOpen=!spoilerOpen;
ImGui::EndMenu();
}
if (ImGui::BeginMenu("help")) {
@ -4346,7 +4400,7 @@ bool FurnaceGUI::loop() {
}
logD("saving backup...");
SafeWriter* w=e->saveFur(true);
if (w!=NULL) {
FILE* outFile=ps_fopen(backupPath.c_str(),"wb");
if (outFile!=NULL) {
@ -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);