Skip to content

Commit ad14d22

Browse files
committed
SDL: avoid saving dimensions of fullscreen window
1 parent 51618b2 commit ad14d22

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

src/platform/sdl/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,12 @@ int main(int argc, char* argv[]) {
405405
Runtime *runtime = new Runtime(window);
406406
runtime->construct(font.c_str(), fontBold.c_str());
407407
fontScale = runtime->runShell(runFile, fontScale, debug ? g_debugPort : 0);
408+
rect = runtime->getWindowRect();
408409
delete runtime;
409410
} else {
410411
fprintf(stderr, "Failed to locate display font\n");
411412
}
412-
saveSettings(window, fontScale, debug);
413+
saveSettings(rect, fontScale, debug);
413414
SDL_DestroyWindow(window);
414415
} else {
415416
fprintf(stderr, "Could not create window: %s\n", SDL_GetError());

src/platform/sdl/runtime.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ void Runtime::exportRun(const char *file) {
296296
}
297297

298298
bool Runtime::toggleFullscreen() {
299+
if (!_fullscreen) {
300+
setWindowRect(_windowRect);
301+
}
299302
_fullscreen = !_fullscreen;
300303
SDL_SetWindowFullscreen(_window, _fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
301304
return _fullscreen;
@@ -815,6 +818,21 @@ void Runtime::optionsBox(StringList *items) {
815818
_output->redraw();
816819
}
817820

821+
SDL_Rect Runtime::getWindowRect() {
822+
SDL_Rect result;
823+
if (_fullscreen) {
824+
result = _windowRect;
825+
} else {
826+
setWindowRect(result);
827+
}
828+
return result;
829+
}
830+
831+
void Runtime::setWindowRect(SDL_Rect &rc) {
832+
SDL_GetWindowPosition(_window, &rc.x, &rc.y);
833+
SDL_GetWindowSize(_window, &rc.w, &rc.h);
834+
}
835+
818836
void Runtime::setClipboardText(const char *text) {
819837
SDL_SetClipboardText(text);
820838
}

src/platform/sdl/runtime.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ struct Runtime : public System {
5454
void onResize(int w, int h);
5555
void setClipboardText(const char *text);
5656
char *getClipboardText();
57+
void setWindowRect(SDL_Rect &rect);
58+
SDL_Rect getWindowRect();
5759

5860
private:
5961
int _menuX, _menuY;
6062
bool _fullscreen;
63+
SDL_Rect _windowRect;
6164
Graphics *_graphics;
6265
Stack<MAEvent *> *_eventQueue;
6366
SDL_Window *_window;

src/platform/sdl/settings.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,10 @@ void restoreSettings(SDL_Rect &rect, int &fontScale, bool debug, bool restoreDir
217217
//
218218
// save the window position
219219
//
220-
void saveSettings(SDL_Window *window, int fontScale, bool debug) {
220+
void saveSettings(SDL_Rect &rect, int fontScale, bool debug) {
221221
FILE *fp = openConfig(false, debug ? k_debug : k_window);
222222
if (fp) {
223-
int x, y, w, h;
224-
SDL_GetWindowPosition(window, &x, &y);
225-
SDL_GetWindowSize(window, &w, &h);
226-
fprintf(fp, "%d,%d,%d,%d,%d,%d,%d,%d\n", x, y, w, h,
223+
fprintf(fp, "%d,%d,%d,%d,%d,%d,%d,%d\n", rect.x, rect.y, rect.w, rect.h,
227224
fontScale, opt_mute_audio, opt_ide, g_themeId);
228225
// print user theme colours on the second line
229226
for (int i = 0; i < THEME_COLOURS; i++) {

src/platform/sdl/settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <SDL.h>
1313

1414
void restoreSettings(SDL_Rect &rect, int &fontScale, bool debug, bool restoreDir);
15-
void saveSettings(SDL_Window *window, int fontScale, bool debug);
15+
void saveSettings(SDL_Rect &rect, int fontScale, bool debug);
1616
String saveGist(const char *buffer, const char *fileName, const char *description);
1717
void setRecentFile(const char *path);
1818
bool getRecentFile(strlib::String &path, unsigned position);

0 commit comments

Comments
 (0)