Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Be explicit about what display you're querying. The default display i…
Browse files Browse the repository at this point in the history
…s 0.
  • Loading branch information
slouken committed Feb 10, 2011
1 parent b0d89bd commit 0b9dcbb
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 166 deletions.
51 changes: 13 additions & 38 deletions include/SDL_video.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ extern DECLSPEC const char *SDLCALL SDL_GetCurrentVideoDriver(void);
* \brief Returns the number of available video displays. * \brief Returns the number of available video displays.
* *
* \sa SDL_GetDisplayBounds() * \sa SDL_GetDisplayBounds()
* \sa SDL_SelectVideoDisplay()
*/ */
extern DECLSPEC int SDLCALL SDL_GetNumVideoDisplays(void); extern DECLSPEC int SDLCALL SDL_GetNumVideoDisplays(void);


Expand All @@ -248,34 +247,14 @@ extern DECLSPEC int SDLCALL SDL_GetNumVideoDisplays(void);
* *
* \sa SDL_GetNumVideoDisplays() * \sa SDL_GetNumVideoDisplays()
*/ */
extern DECLSPEC int SDLCALL SDL_GetDisplayBounds(int index, SDL_Rect * rect); extern DECLSPEC int SDLCALL SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect);


/** /**
* \brief Set the index of the currently selected display. * \brief Returns the number of available display modes.
*
* \return 0 on success, or -1 if the index is out of range.
*
* \sa SDL_GetNumVideoDisplays()
* \sa SDL_GetCurrentVideoDisplay()
*/
extern DECLSPEC int SDLCALL SDL_SelectVideoDisplay(int index);

/**
* \brief Get the index of the currently selected display.
*
* \return The index of the currently selected display.
*
* \sa SDL_GetNumVideoDisplays()
* \sa SDL_SelectVideoDisplay()
*/
extern DECLSPEC int SDLCALL SDL_GetCurrentVideoDisplay(void);

/**
* \brief Returns the number of available display modes for the current display.
* *
* \sa SDL_GetDisplayMode() * \sa SDL_GetDisplayMode()
*/ */
extern DECLSPEC int SDLCALL SDL_GetNumDisplayModes(void); extern DECLSPEC int SDLCALL SDL_GetNumDisplayModes(int displayIndex);


/** /**
* \brief Fill in information about a specific display mode. * \brief Fill in information about a specific display mode.
Expand All @@ -288,19 +267,18 @@ extern DECLSPEC int SDLCALL SDL_GetNumDisplayModes(void);
* *
* \sa SDL_GetNumDisplayModes() * \sa SDL_GetNumDisplayModes()
*/ */
extern DECLSPEC int SDLCALL SDL_GetDisplayMode(int index, extern DECLSPEC int SDLCALL SDL_GetDisplayMode(int displayIndex, int modeIndex,
SDL_DisplayMode * mode); SDL_DisplayMode * mode);


/** /**
* \brief Fill in information about the desktop display mode for the current * \brief Fill in information about the desktop display mode.
* display.
*/ */
extern DECLSPEC int SDLCALL SDL_GetDesktopDisplayMode(SDL_DisplayMode * mode); extern DECLSPEC int SDLCALL SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * mode);


/** /**
* \brief Fill in information about the current display mode. * \brief Fill in information about the current display mode.
*/ */
extern DECLSPEC int SDLCALL SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode); extern DECLSPEC int SDLCALL SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode * mode);




/** /**
Expand All @@ -323,16 +301,13 @@ extern DECLSPEC int SDLCALL SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode);
* \sa SDL_GetNumDisplayModes() * \sa SDL_GetNumDisplayModes()
* \sa SDL_GetDisplayMode() * \sa SDL_GetDisplayMode()
*/ */
extern DECLSPEC SDL_DisplayMode *SDLCALL SDL_GetClosestDisplayMode(const extern DECLSPEC SDL_DisplayMode * SDLCALL SDL_GetClosestDisplayMode(int displayIndex, const SDL_DisplayMode * mode, SDL_DisplayMode * closest);
SDL_DisplayMode
* mode,
SDL_DisplayMode
* closest);


/** /**
* \brief Set the display mode used when a fullscreen window is visible * \brief Set the display mode used when a fullscreen window is visible.
* on the currently selected display. By default the window's *
* dimensions and the desktop format and refresh rate are used. * By default the window's dimensions and the desktop format and refresh rate
* are used.
* *
* \param mode The mode to use, or NULL for the default mode. * \param mode The mode to use, or NULL for the default mode.
* *
Expand All @@ -347,7 +322,7 @@ extern DECLSPEC int SDLCALL SDL_SetWindowDisplayMode(SDL_Window * window,


/** /**
* \brief Fill in information about the display mode used when a fullscreen * \brief Fill in information about the display mode used when a fullscreen
* window is visible on the currently selected display. * window is visible.
* *
* \sa SDL_SetWindowDisplayMode() * \sa SDL_SetWindowDisplayMode()
* \sa SDL_SetWindowFullscreen() * \sa SDL_SetWindowFullscreen()
Expand Down
32 changes: 13 additions & 19 deletions src/SDL_compat.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@ SDL_VideoDriverName(char *namebuf, int maxlen)
return NULL; return NULL;
} }


static void static int
SelectVideoDisplay() GetVideoDisplay()
{ {
const char *variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_DISPLAY"); const char *variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_DISPLAY");
if ( !variable ) { if ( !variable ) {
variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_HEAD"); variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_HEAD");
} }
if ( variable ) { if ( variable ) {
SDL_SelectVideoDisplay(SDL_atoi(variable)); SDL_atoi(variable);
} else {
return 0;
} }
} }


Expand All @@ -89,10 +91,8 @@ SDL_GetVideoInfo(void)
static SDL_VideoInfo info; static SDL_VideoInfo info;
SDL_DisplayMode mode; SDL_DisplayMode mode;


SelectVideoDisplay();

/* Memory leak, compatibility code, who cares? */ /* Memory leak, compatibility code, who cares? */
if (!info.vfmt && SDL_GetDesktopDisplayMode(&mode) == 0) { if (!info.vfmt && SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode) == 0) {
int bpp; int bpp;
Uint32 Rmask, Gmask, Bmask, Amask; Uint32 Rmask, Gmask, Bmask, Amask;


Expand All @@ -114,17 +114,15 @@ SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags)
return 0; return 0;
} }


SelectVideoDisplay();

if (!(flags & SDL_FULLSCREEN)) { if (!(flags & SDL_FULLSCREEN)) {
SDL_DisplayMode mode; SDL_DisplayMode mode;
SDL_GetDesktopDisplayMode(&mode); SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode);
return SDL_BITSPERPIXEL(mode.format); return SDL_BITSPERPIXEL(mode.format);
} }


for (i = 0; i < SDL_GetNumDisplayModes(); ++i) { for (i = 0; i < SDL_GetNumDisplayModes(GetVideoDisplay()); ++i) {
SDL_DisplayMode mode; SDL_DisplayMode mode;
SDL_GetDisplayMode(i, &mode); SDL_GetDisplayMode(GetVideoDisplay(), i, &mode);
if (!mode.w || !mode.h || (width == mode.w && height == mode.h)) { if (!mode.w || !mode.h || (width == mode.w && height == mode.h)) {
if (!mode.format) { if (!mode.format) {
return bpp; return bpp;
Expand All @@ -147,8 +145,6 @@ SDL_ListModes(const SDL_PixelFormat * format, Uint32 flags)
return NULL; return NULL;
} }


SelectVideoDisplay();

if (!(flags & SDL_FULLSCREEN)) { if (!(flags & SDL_FULLSCREEN)) {
return (SDL_Rect **) (-1); return (SDL_Rect **) (-1);
} }
Expand All @@ -160,11 +156,11 @@ SDL_ListModes(const SDL_PixelFormat * format, Uint32 flags)
/* Memory leak, but this is a compatibility function, who cares? */ /* Memory leak, but this is a compatibility function, who cares? */
nmodes = 0; nmodes = 0;
modes = NULL; modes = NULL;
for (i = 0; i < SDL_GetNumDisplayModes(); ++i) { for (i = 0; i < SDL_GetNumDisplayModes(GetVideoDisplay()); ++i) {
SDL_DisplayMode mode; SDL_DisplayMode mode;
int bpp; int bpp;


SDL_GetDisplayMode(i, &mode); SDL_GetDisplayMode(GetVideoDisplay(), i, &mode);
if (!mode.w || !mode.h) { if (!mode.w || !mode.h) {
return (SDL_Rect **) (-1); return (SDL_Rect **) (-1);
} }
Expand Down Expand Up @@ -342,7 +338,7 @@ GetEnvironmentWindowPosition(int w, int h, int *x, int *y)
} }
if (center) { if (center) {
SDL_DisplayMode mode; SDL_DisplayMode mode;
SDL_GetDesktopDisplayMode(&mode); SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode);
*x = (mode.w - w) / 2; *x = (mode.w - w) / 2;
*y = (mode.h - h) / 2; *y = (mode.h - h) / 2;
} }
Expand Down Expand Up @@ -453,9 +449,7 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
} }
} }


SelectVideoDisplay(); SDL_GetDesktopDisplayMode(GetVideoDisplay(), &desktop_mode);

SDL_GetDesktopDisplayMode(&desktop_mode);


if (width == 0) { if (width == 0) {
width = desktop_mode.w; width = desktop_mode.w;
Expand Down
8 changes: 0 additions & 8 deletions src/video/SDL_sysvideo.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -322,18 +322,10 @@ extern VideoBootStrap Android_bootstrap;
extern VideoBootStrap DUMMY_bootstrap; extern VideoBootStrap DUMMY_bootstrap;
#endif #endif


#define SDL_CurrentDisplay (&_this->displays[_this->current_display])

extern SDL_VideoDevice *SDL_GetVideoDevice(void); extern SDL_VideoDevice *SDL_GetVideoDevice(void);
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode); extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display); extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode); extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
extern int SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display);
extern int SDL_GetDisplayModeForDisplay(SDL_VideoDisplay * display, int index, SDL_DisplayMode * mode);
extern int SDL_GetDesktopDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode);
extern int SDL_GetCurrentDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode);
extern SDL_DisplayMode * SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode, SDL_DisplayMode * closest);
extern int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode);


extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags); extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);


Expand Down
Loading

0 comments on commit 0b9dcbb

Please sign in to comment.