Search code examples
csdlsdl-2

Size a window relative to the size of the screen the window is in (in case of multiple displays) in SDL2


I'm writing some code which wraps parts of SDL2. I want to handle a case where a window is moved to another display after it's created, scaling up the window appropriately.

I'm using C.

The part I can't figure out is how to, given an SDL_Window object, find out which display that window is in, on a multi-display setup. If I can find that out, it's trivial to find the size of that display and set the window size appropriately.

// Width and height of display that myWindow is in (myWindow some previously created SDL_Window)
int disp_x_size_px;
int disp_y_size_px;

/* Need code to get values for disp_x_size_px and disp_y_size_px.
    With these values I can set the window size correctly. */

Solution

  • From genpfault's comment, the answer is to use SDL_GetWindowDisplayIndex() to get the display a window is on. Then of course SDL_GetDisplayBounds() can be used to get the display size and SDL_SetWindowPosition() to set the window position appropriately.

    Note: I'm putting this in an answer so this question can have an accepted answer: it has been answered acceptably, after all.