3

I would like to determine the maximum possible windowed size on the current display during initialization to determine if settings are valid. The only way I could figure out to do this is to create a temporary maximized window and call SDL_GetWindowSize(). This works as expected on macOS, but fails on Linux.

Here is my code:

int max_width, max_height;
SDL_Window* test_window = SDL_CreateWindow( "test_window",
    SDL_WINDOWPOS_CENTERED_DISPLAY( current_display_id ),
    SDL_WINDOWPOS_CENTERED_DISPLAY( current_display_id ),
    20, 10, // No display is this small
    SDL_WINDOW_RESIZABLE | SDL_WINDOW_MAXIMIZED
);

SDL_GetWindowSize( test_window, &max_width, &max_height );

On macOS max_width and max_height are properly set to the maximum windowed size. On Linux however, they are set to 20 and 10.

Could anyone tell me why this doesn't work on Linux? Is there a better way to accomplish the same thing?

Edit: Maybe I wasn't clear enough about what I mean by maximum windowed size. Most operating systems have some kind of taskbar/dock that limits the usable area of the display, so "maximum windowed size" is not equal to the display size obtained with SDL_GetDesktopDisplayMode()

user654379
  • 31
  • 2
  • Possible duplicate of [How to get screen size in SDL](https://stackoverflow.com/questions/33393528/how-to-get-screen-size-in-sdl) – Rietty Feb 26 '19 at 19:09
  • Please see this question, it should work across all systems. – Rietty Feb 26 '19 at 19:10
  • Unfortunately the size of the display is not quite the same as what I'm calling the maximum windowed size. There can be taskbars/docks/whatever that reduce the available size for windows. – user654379 Feb 26 '19 at 19:18
  • 1
    Can I ask why you need this (it sounds like an XY problem right now)? Your application interface should adapt to be usable with any reasonable window size (for some definition of \`reasonable'). – G.M. Feb 26 '19 at 19:41
  • The application in question is a curses game that requires a minimum resolution of 80x24 characters (640x384 with the standard font size). I am attempting to add a "scaling factor" option to the SDL curses port which scales the entire game by 2x or 4x using `SDL_RenderSetLogicalSize()`, mostly for use on high dpi systems where the ui can be hard to read. This scaling naturally increases the minimum dimensions of the game, and I need to check if it is possible to create the window at the desired scaling factor, falling back to 1x if the display does not have enough available space. – user654379 Feb 26 '19 at 20:29
  • Does `SDL_GetWindowMaximumSize` work? – HolyBlackCat Feb 27 '19 at 09:16
  • That seems to always return 0 unless a maximum size is set with `SDL_SetWindowMaximumSize` – user654379 Mar 01 '19 at 13:13

0 Answers0