pharo-graphics / Bloc

Low-level UI infrastructure & framework for Pharo
MIT License
83 stars 40 forks source link

Multiple monitors: Position a space on a specific monitor #554

Open tinchodias opened 4 months ago

tinchodias commented 4 months ago

I looked at how it would be to support multiple monitors with SDL2 host. I did this "research" from a question of @labordep in #507

This is a tutorial about this: https://lazyfoo.net/tutorials/SDL/37_multiple_displays/index.php

Apparently it's as simple as knowing the number of monitors with: https://wiki.libsdl.org/SDL2/SDL_GetNumVideoDisplays , and then you ask for each monitors bound (a rectangle): https://wiki.libsdl.org/SDL2/SDL_GetDisplayBounds and finally, you set the window position at e.g. (monitorBounds at: 2) origin + aSpace positionInMonitor

tinchodias commented 4 months ago

Possible implementation:

Let's think on scenarios.

  1. Simple case: open a space in 50@100 of the last of the monitors (I guess 1 is the default, and that's the OS main monitor)

    s := BlSpace new.
    s position: 50@100.
    s videoDisplayIndex: s numberOfVideoDisplays. 
    s show
  2. Move that space to 50@100 position but in first (main) display: s videoDisplayIndex: 1

In the case the default Bloc host is Morphic, not SDL, then 2. has no effect.

labordep commented 4 months ago

Hi! Cool! This is important to determine on what screen to display, for example on starting an application I can display a first window on screen 1 and a second window on screen 2. Each windows can be in fullscreen or not. But before that it is necessary to known the hardware configuration, what is the way to known:

This question also concern window placement and moving after starting the application.

tinchodias commented 4 months ago

Okay, for extra info, I see:

https://wiki.libsdl.org/SDL2/SDL_GetDisplayName, to get a String

https://wiki.libsdl.org/SDL2/SDL_GetDisplayDPI, to get: int displayIndex the index of the display from which DPI information should be queried.
float * ddpi a pointer filled in with the diagonal DPI of the display; may be NULL.
float * hdpi a pointer filled in with the horizontal DPI of the display; may be NULL.
float * vdpi a pointer filled in with the vertical DPI of the display; may be NULL.

https://wiki.libsdl.org/SDL2/SDL_GetNumDisplayModes and https://wiki.libsdl.org/SDL2/SDL_GetDisplayMode, to get a list of:

    Uint32 format;              /**< pixel format */
    int w;                      /**< width, in screen coordinates */
    int h;                      /**< height, in screen coordinates */
    int refresh_rate;           /**< refresh rate (or zero for unspecified) */
    void *driverdata;           /**< driver-specific data, initialize to 0 */

https://wiki.libsdl.org/SDL2/SDL_DisplayOrientation, to get one of:

    SDL_ORIENTATION_UNKNOWN,            /**< The display orientation can't be determined */
    SDL_ORIENTATION_LANDSCAPE,          /**< The display is in landscape mode, with the right side up, relative to portrait mode */
    SDL_ORIENTATION_LANDSCAPE_FLIPPED,  /**< The display is in landscape mode, with the left side up, relative to portrait mode */
    SDL_ORIENTATION_PORTRAIT,           /**< The display is in portrait mode */
    SDL_ORIENTATION_PORTRAIT_FLIPPED    /**< The display is in portrait mode, upside down */
labordep commented 4 months ago

Wow awesome!