mirror of https://github.com/xemu-project/xemu.git
ui: Save screen size on resize
Co-authored-by: 7oxicshadow <7oxicshadow@googlemail.com>
This commit is contained in:
parent
d58f4e7051
commit
cd5d3df626
|
@ -2804,7 +2804,7 @@ void qemu_init(int argc, char **argv, char **envp)
|
|||
break;
|
||||
}
|
||||
}
|
||||
xemu_settings_load();
|
||||
|
||||
int first_boot = xemu_settings_did_fail_to_load();
|
||||
int fake_argc = 32 + argc;
|
||||
char **fake_argv = malloc(sizeof(char*)*fake_argc);
|
||||
|
|
|
@ -55,6 +55,8 @@ struct xemu_settings {
|
|||
int scale;
|
||||
int ui_scale;
|
||||
int render_scale;
|
||||
int window_width;
|
||||
int window_height;
|
||||
|
||||
// [input]
|
||||
char *controller_1_guid;
|
||||
|
@ -119,9 +121,11 @@ struct config_offset_table {
|
|||
|
||||
[XEMU_SETTINGS_AUDIO_USE_DSP] = { CONFIG_TYPE_BOOL, "audio", "use_dsp", offsetof(struct xemu_settings, use_dsp), { .default_bool = 0 } },
|
||||
|
||||
[XEMU_SETTINGS_DISPLAY_SCALE] = { CONFIG_TYPE_ENUM, "display", "scale", offsetof(struct xemu_settings, scale), { .default_int = DISPLAY_SCALE_SCALE }, display_scale_map },
|
||||
[XEMU_SETTINGS_DISPLAY_UI_SCALE] = { CONFIG_TYPE_INT, "display", "ui_scale", offsetof(struct xemu_settings, ui_scale), { .default_int = 1 } },
|
||||
[XEMU_SETTINGS_DISPLAY_RENDER_SCALE] = { CONFIG_TYPE_INT, "display", "render_scale", offsetof(struct xemu_settings, render_scale), { .default_int = 1 } },
|
||||
[XEMU_SETTINGS_DISPLAY_SCALE] = { CONFIG_TYPE_ENUM, "display", "scale", offsetof(struct xemu_settings, scale), { .default_int = DISPLAY_SCALE_SCALE }, display_scale_map },
|
||||
[XEMU_SETTINGS_DISPLAY_UI_SCALE] = { CONFIG_TYPE_INT, "display", "ui_scale", offsetof(struct xemu_settings, ui_scale), { .default_int = 1 } },
|
||||
[XEMU_SETTINGS_DISPLAY_RENDER_SCALE] = { CONFIG_TYPE_INT, "display", "render_scale", offsetof(struct xemu_settings, render_scale), { .default_int = 1 } },
|
||||
[XEMU_SETTINGS_DISPLAY_WINDOW_WIDTH] = { CONFIG_TYPE_INT, "display", "window_width", offsetof(struct xemu_settings, window_width), { .default_int = 1280 } },
|
||||
[XEMU_SETTINGS_DISPLAY_WINDOW_HEIGHT] = { CONFIG_TYPE_INT, "display", "window_height", offsetof(struct xemu_settings, window_height), { .default_int = 960 } },
|
||||
|
||||
[XEMU_SETTINGS_INPUT_CONTROLLER_1_GUID] = { CONFIG_TYPE_STRING, "input", "controller_1_guid", offsetof(struct xemu_settings, controller_1_guid), { .default_str = "" } },
|
||||
[XEMU_SETTINGS_INPUT_CONTROLLER_2_GUID] = { CONFIG_TYPE_STRING, "input", "controller_2_guid", offsetof(struct xemu_settings, controller_2_guid), { .default_str = "" } },
|
||||
|
@ -392,7 +396,7 @@ void xemu_settings_load(void)
|
|||
}
|
||||
}
|
||||
|
||||
int xemu_settings_save(void)
|
||||
void xemu_settings_save(void)
|
||||
{
|
||||
FILE *fd = qemu_fopen(xemu_settings_get_path(), "wb");
|
||||
assert(fd != NULL);
|
||||
|
@ -434,5 +438,4 @@ int xemu_settings_save(void)
|
|||
}
|
||||
|
||||
fclose(fd);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,8 @@ enum xemu_settings_keys {
|
|||
XEMU_SETTINGS_DISPLAY_SCALE,
|
||||
XEMU_SETTINGS_DISPLAY_UI_SCALE,
|
||||
XEMU_SETTINGS_DISPLAY_RENDER_SCALE,
|
||||
XEMU_SETTINGS_DISPLAY_WINDOW_WIDTH,
|
||||
XEMU_SETTINGS_DISPLAY_WINDOW_HEIGHT,
|
||||
XEMU_SETTINGS_INPUT_CONTROLLER_1_GUID,
|
||||
XEMU_SETTINGS_INPUT_CONTROLLER_2_GUID,
|
||||
XEMU_SETTINGS_INPUT_CONTROLLER_3_GUID,
|
||||
|
@ -91,7 +93,7 @@ const char *xemu_settings_get_default_eeprom_path(void);
|
|||
void xemu_settings_load(void);
|
||||
|
||||
// Save config file to disk
|
||||
int xemu_settings_save(void);
|
||||
void xemu_settings_save(void);
|
||||
|
||||
// Config item setters/getters
|
||||
int xemu_settings_set_string(enum xemu_settings_keys key, const char *str);
|
||||
|
|
24
ui/xemu.c
24
ui/xemu.c
|
@ -591,6 +591,11 @@ static void handle_windowevent(SDL_Event *ev)
|
|||
info.width = ev->window.data1;
|
||||
info.height = ev->window.data2;
|
||||
dpy_set_ui_info(scon->dcl.con, &info);
|
||||
|
||||
if (!gui_fullscreen) {
|
||||
xemu_settings_set_int(XEMU_SETTINGS_DISPLAY_WINDOW_WIDTH, ev->window.data1);
|
||||
xemu_settings_set_int(XEMU_SETTINGS_DISPLAY_WINDOW_HEIGHT, ev->window.data2);
|
||||
}
|
||||
}
|
||||
sdl2_redraw(scon);
|
||||
break;
|
||||
|
@ -843,7 +848,7 @@ static void sdl2_display_very_early_init(DisplayOptions *o)
|
|||
|
||||
// Create main window
|
||||
m_window = SDL_CreateWindow(
|
||||
title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 960,
|
||||
title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480,
|
||||
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||
if (m_window == NULL) {
|
||||
fprintf(stderr, "Failed to create main window\n");
|
||||
|
@ -852,6 +857,20 @@ static void sdl2_display_very_early_init(DisplayOptions *o)
|
|||
}
|
||||
g_free(title);
|
||||
|
||||
SDL_DisplayMode disp_mode;
|
||||
SDL_GetCurrentDisplayMode(SDL_GetWindowDisplayIndex(m_window), &disp_mode);
|
||||
|
||||
int win_w, win_h;
|
||||
xemu_settings_get_int(XEMU_SETTINGS_DISPLAY_WINDOW_WIDTH, &win_w);
|
||||
xemu_settings_get_int(XEMU_SETTINGS_DISPLAY_WINDOW_HEIGHT, &win_h);
|
||||
|
||||
if (win_w > 0 && win_h > 0) {
|
||||
if (disp_mode.w >= win_w && disp_mode.h >= win_h) {
|
||||
SDL_SetWindowSize(m_window, win_w, win_h);
|
||||
SDL_SetWindowPosition(m_window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
}
|
||||
}
|
||||
|
||||
m_context = SDL_GL_CreateContext(m_window);
|
||||
|
||||
if (m_context != NULL && epoxy_gl_version() < 40) {
|
||||
|
@ -1503,6 +1522,9 @@ int main(int argc, char **argv)
|
|||
gArgc = argc;
|
||||
gArgv = argv;
|
||||
|
||||
xemu_settings_load();
|
||||
atexit(xemu_settings_save);
|
||||
|
||||
sdl2_display_very_early_init(NULL);
|
||||
|
||||
qemu_sem_init(&display_init_sem, 0);
|
||||
|
|
Loading…
Reference in New Issue