testwm.c: show all modes of all displays in the on-screen list (#7323)
* testwm.c: show all modes of all displays in the on-screen list To allow testing https://github.com/libsdl-org/SDL/pull/7317
This commit is contained in:
parent
beb6a2afdc
commit
1f46986d33
1 changed files with 48 additions and 45 deletions
|
@ -40,7 +40,7 @@ static const char *cursorNames[] = {
|
||||||
int system_cursor = -1;
|
int system_cursor = -1;
|
||||||
SDL_Cursor *cursor = NULL;
|
SDL_Cursor *cursor = NULL;
|
||||||
SDL_bool relative_mode = SDL_FALSE;
|
SDL_bool relative_mode = SDL_FALSE;
|
||||||
int highlighted_mode = -1;
|
const SDL_DisplayMode *highlighted_mode = NULL;
|
||||||
|
|
||||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||||
static void
|
static void
|
||||||
|
@ -57,13 +57,13 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
|
||||||
const SDL_DisplayMode **modes;
|
const SDL_DisplayMode **modes;
|
||||||
char text[1024];
|
char text[1024];
|
||||||
const int lineHeight = 10;
|
const int lineHeight = 10;
|
||||||
const SDL_DisplayID displayID = SDL_GetDisplayForWindow(window);
|
int i, j;
|
||||||
int i;
|
|
||||||
int column_chars = 0;
|
int column_chars = 0;
|
||||||
int text_length;
|
int text_length;
|
||||||
float x, y;
|
float x, y;
|
||||||
float table_top;
|
float table_top;
|
||||||
SDL_FPoint mouse_pos = { -1.0f, -1.0f };
|
SDL_FPoint mouse_pos = { -1.0f, -1.0f };
|
||||||
|
SDL_DisplayID *display_ids;
|
||||||
|
|
||||||
/* Get mouse position */
|
/* Get mouse position */
|
||||||
if (SDL_GetMouseFocus() == window) {
|
if (SDL_GetMouseFocus() == window) {
|
||||||
|
@ -96,16 +96,22 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
|
||||||
|
|
||||||
/* Clear the cached mode under the mouse */
|
/* Clear the cached mode under the mouse */
|
||||||
if (window == SDL_GetMouseFocus()) {
|
if (window == SDL_GetMouseFocus()) {
|
||||||
highlighted_mode = -1;
|
highlighted_mode = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
modes = SDL_GetFullscreenDisplayModes(displayID, NULL);
|
display_ids = SDL_GetDisplays(NULL);
|
||||||
for (i = 0; modes[i]; ++i) {
|
|
||||||
SDL_FRect cell_rect;
|
|
||||||
const SDL_DisplayMode *mode = modes[i];
|
|
||||||
|
|
||||||
(void)SDL_snprintf(text, sizeof text, "%d: %dx%d@%gHz",
|
if (display_ids) {
|
||||||
i, mode->pixel_w, mode->pixel_h, mode->refresh_rate);
|
for (i = 0; display_ids[i]; ++i) {
|
||||||
|
const SDL_DisplayID display_id = display_ids[i];
|
||||||
|
modes = SDL_GetFullscreenDisplayModes(display_id, NULL);
|
||||||
|
for (j = 0; modes[j]; ++j) {
|
||||||
|
SDL_FRect cell_rect;
|
||||||
|
const SDL_DisplayMode *mode = modes[j];
|
||||||
|
|
||||||
|
(void)SDL_snprintf(text, sizeof text, "%s mode %d: %dx%d@%gHz",
|
||||||
|
SDL_GetDisplayName(display_id),
|
||||||
|
j, mode->pixel_w, mode->pixel_h, mode->refresh_rate);
|
||||||
|
|
||||||
/* Update column width */
|
/* Update column width */
|
||||||
text_length = (int)SDL_strlen(text);
|
text_length = (int)SDL_strlen(text);
|
||||||
|
@ -122,7 +128,7 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
|
||||||
|
|
||||||
/* Update cached mode under the mouse */
|
/* Update cached mode under the mouse */
|
||||||
if (window == SDL_GetMouseFocus()) {
|
if (window == SDL_GetMouseFocus()) {
|
||||||
highlighted_mode = i;
|
highlighted_mode = mode;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
|
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
|
||||||
|
@ -140,6 +146,9 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
|
||||||
}
|
}
|
||||||
SDL_free((void *)modes);
|
SDL_free((void *)modes);
|
||||||
}
|
}
|
||||||
|
SDL_free(display_ids);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
@ -206,15 +215,9 @@ void loop()
|
||||||
}
|
}
|
||||||
if (event.type == SDL_EVENT_MOUSE_BUTTON_UP) {
|
if (event.type == SDL_EVENT_MOUSE_BUTTON_UP) {
|
||||||
SDL_Window *window = SDL_GetMouseFocus();
|
SDL_Window *window = SDL_GetMouseFocus();
|
||||||
if (highlighted_mode != -1 && window != NULL) {
|
if (highlighted_mode != NULL && window != NULL) {
|
||||||
SDL_DisplayID displayID = SDL_GetDisplayForWindow(window);
|
SDL_memcpy(&state->fullscreen_mode, highlighted_mode, sizeof(state->fullscreen_mode));
|
||||||
int num_modes;
|
SDL_SetWindowFullscreenMode(window, highlighted_mode);
|
||||||
const SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(displayID, &num_modes);
|
|
||||||
if (highlighted_mode < num_modes) {
|
|
||||||
SDL_memcpy(&state->fullscreen_mode, modes[highlighted_mode], sizeof(state->fullscreen_mode));
|
|
||||||
SDL_SetWindowFullscreenMode(window, modes[highlighted_mode]);
|
|
||||||
}
|
|
||||||
SDL_free((void *)modes);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue