Be explicit about what display you're querying. The default display is 0.

This commit is contained in:
Sam Lantinga 2011-02-10 12:14:37 -08:00
parent e0f869b698
commit e9689c29d5
9 changed files with 90 additions and 166 deletions

View file

@ -71,15 +71,17 @@ SDL_VideoDriverName(char *namebuf, int maxlen)
return NULL;
}
static void
SelectVideoDisplay()
static int
GetVideoDisplay()
{
const char *variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_DISPLAY");
if ( !variable ) {
variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_HEAD");
}
if ( variable ) {
SDL_SelectVideoDisplay(SDL_atoi(variable));
SDL_atoi(variable);
} else {
return 0;
}
}
@ -89,10 +91,8 @@ SDL_GetVideoInfo(void)
static SDL_VideoInfo info;
SDL_DisplayMode mode;
SelectVideoDisplay();
/* Memory leak, compatibility code, who cares? */
if (!info.vfmt && SDL_GetDesktopDisplayMode(&mode) == 0) {
if (!info.vfmt && SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode) == 0) {
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
@ -114,17 +114,15 @@ SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags)
return 0;
}
SelectVideoDisplay();
if (!(flags & SDL_FULLSCREEN)) {
SDL_DisplayMode mode;
SDL_GetDesktopDisplayMode(&mode);
SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode);
return SDL_BITSPERPIXEL(mode.format);
}
for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
for (i = 0; i < SDL_GetNumDisplayModes(GetVideoDisplay()); ++i) {
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.format) {
return bpp;
@ -147,8 +145,6 @@ SDL_ListModes(const SDL_PixelFormat * format, Uint32 flags)
return NULL;
}
SelectVideoDisplay();
if (!(flags & SDL_FULLSCREEN)) {
return (SDL_Rect **) (-1);
}
@ -160,11 +156,11 @@ SDL_ListModes(const SDL_PixelFormat * format, Uint32 flags)
/* Memory leak, but this is a compatibility function, who cares? */
nmodes = 0;
modes = NULL;
for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
for (i = 0; i < SDL_GetNumDisplayModes(GetVideoDisplay()); ++i) {
SDL_DisplayMode mode;
int bpp;
SDL_GetDisplayMode(i, &mode);
SDL_GetDisplayMode(GetVideoDisplay(), i, &mode);
if (!mode.w || !mode.h) {
return (SDL_Rect **) (-1);
}
@ -342,7 +338,7 @@ GetEnvironmentWindowPosition(int w, int h, int *x, int *y)
}
if (center) {
SDL_DisplayMode mode;
SDL_GetDesktopDisplayMode(&mode);
SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode);
*x = (mode.w - w) / 2;
*y = (mode.h - h) / 2;
}
@ -453,9 +449,7 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
}
}
SelectVideoDisplay();
SDL_GetDesktopDisplayMode(&desktop_mode);
SDL_GetDesktopDisplayMode(GetVideoDisplay(), &desktop_mode);
if (width == 0) {
width = desktop_mode.w;

View file

@ -322,18 +322,10 @@ extern VideoBootStrap Android_bootstrap;
extern VideoBootStrap DUMMY_bootstrap;
#endif
#define SDL_CurrentDisplay (&_this->displays[_this->current_display])
extern SDL_VideoDevice *SDL_GetVideoDevice(void);
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
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);

View file

@ -96,6 +96,17 @@ static SDL_VideoDevice *_this = NULL;
return retval; \
}
#define CHECK_DISPLAY_INDEX(displayIndex, retval) \
if (!_this) { \
SDL_UninitializedVideo(); \
return retval; \
} \
if (displayIndex < 0 || displayIndex >= _this->num_displays) { \
SDL_SetError("displayIndex must be in the range 0 - %d", \
_this->num_displays - 1); \
return retval; \
}
/* Various local functions */
static void SDL_UpdateWindowGrab(SDL_Window * window);
@ -581,19 +592,12 @@ SDL_GetNumVideoDisplays(void)
}
int
SDL_GetDisplayBounds(int index, SDL_Rect * rect)
SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect)
{
if (!_this) {
SDL_UninitializedVideo();
return -1;
}
if (index < 0 || index >= _this->num_displays) {
SDL_SetError("index must be in the range 0 - %d",
_this->num_displays - 1);
return -1;
}
CHECK_DISPLAY_INDEX(displayIndex, -1);
if (rect) {
SDL_VideoDisplay *display = &_this->displays[index];
SDL_VideoDisplay *display = &_this->displays[displayIndex];
if (_this->GetDisplayBounds) {
if (_this->GetDisplayBounds(_this, display, rect) < 0) {
@ -601,11 +605,11 @@ SDL_GetDisplayBounds(int index, SDL_Rect * rect)
}
} else {
/* Assume that the displays are left to right */
if (index == 0) {
if (displayIndex == 0) {
rect->x = 0;
rect->y = 0;
} else {
SDL_GetDisplayBounds(index-1, rect);
SDL_GetDisplayBounds(displayIndex-1, rect);
rect->x += rect->w;
}
rect->w = display->desktop_mode.w;
@ -615,32 +619,6 @@ SDL_GetDisplayBounds(int index, SDL_Rect * rect)
return 0;
}
int
SDL_SelectVideoDisplay(int index)
{
if (!_this) {
SDL_UninitializedVideo();
return (-1);
}
if (index < 0 || index >= _this->num_displays) {
SDL_SetError("index must be in the range 0 - %d",
_this->num_displays - 1);
return -1;
}
_this->current_display = index;
return 0;
}
int
SDL_GetCurrentVideoDisplay(void)
{
if (!_this) {
SDL_UninitializedVideo();
return (-1);
}
return _this->current_display;
}
SDL_bool
SDL_AddDisplayMode(SDL_VideoDisplay * display, const SDL_DisplayMode * mode)
{
@ -677,7 +655,7 @@ SDL_AddDisplayMode(SDL_VideoDisplay * display, const SDL_DisplayMode * mode)
return SDL_TRUE;
}
int
static int
SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display)
{
if (!display->num_display_modes && _this->GetDisplayModes) {
@ -689,17 +667,21 @@ SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display)
}
int
SDL_GetNumDisplayModes()
SDL_GetNumDisplayModes(int displayIndex)
{
if (_this) {
return SDL_GetNumDisplayModesForDisplay(SDL_CurrentDisplay);
}
return 0;
CHECK_DISPLAY_INDEX(displayIndex, -1);
return SDL_GetNumDisplayModesForDisplay(&_this->displays[displayIndex]);
}
int
SDL_GetDisplayModeForDisplay(SDL_VideoDisplay * display, int index, SDL_DisplayMode * mode)
SDL_GetDisplayMode(int displayIndex, int index, SDL_DisplayMode * mode)
{
SDL_VideoDisplay *display;
CHECK_DISPLAY_INDEX(displayIndex, -1);
display = &_this->displays[displayIndex];
if (index < 0 || index >= SDL_GetNumDisplayModesForDisplay(display)) {
SDL_SetError("index must be in the range of 0 - %d",
SDL_GetNumDisplayModesForDisplay(display) - 1);
@ -712,14 +694,13 @@ SDL_GetDisplayModeForDisplay(SDL_VideoDisplay * display, int index, SDL_DisplayM
}
int
SDL_GetDisplayMode(int index, SDL_DisplayMode * mode)
SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * mode)
{
return SDL_GetDisplayModeForDisplay(SDL_CurrentDisplay, index, mode);
}
SDL_VideoDisplay *display;
int
SDL_GetDesktopDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{
CHECK_DISPLAY_INDEX(displayIndex, -1);
display = &_this->displays[displayIndex];
if (mode) {
*mode = display->desktop_mode;
}
@ -727,35 +708,20 @@ SDL_GetDesktopDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode
}
int
SDL_GetDesktopDisplayMode(SDL_DisplayMode * mode)
SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode * mode)
{
if (!_this) {
SDL_UninitializedVideo();
return -1;
}
return SDL_GetDesktopDisplayModeForDisplay(SDL_CurrentDisplay, mode);
}
SDL_VideoDisplay *display;
int
SDL_GetCurrentDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{
CHECK_DISPLAY_INDEX(displayIndex, -1);
display = &_this->displays[displayIndex];
if (mode) {
*mode = display->current_mode;
}
return 0;
}
int
SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode)
{
if (!_this) {
SDL_UninitializedVideo();
return -1;
}
return SDL_GetCurrentDisplayModeForDisplay(SDL_CurrentDisplay, mode);
}
SDL_DisplayMode *
static SDL_DisplayMode *
SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display,
const SDL_DisplayMode * mode,
SDL_DisplayMode * closest)
@ -863,14 +829,16 @@ SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display,
}
SDL_DisplayMode *
SDL_GetClosestDisplayMode(const SDL_DisplayMode * mode,
SDL_GetClosestDisplayMode(int displayIndex,
const SDL_DisplayMode * mode,
SDL_DisplayMode * closest)
{
if (!_this) {
SDL_UninitializedVideo();
return NULL;
}
return SDL_GetClosestDisplayModeForDisplay(SDL_CurrentDisplay, mode, closest);
SDL_VideoDisplay *display;
CHECK_DISPLAY_INDEX(displayIndex, NULL);
display = &_this->displays[displayIndex];
return SDL_GetClosestDisplayModeForDisplay(display, mode, closest);
}
int
@ -907,7 +875,7 @@ SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode *
}
/* See if there's anything left to do */
SDL_GetCurrentDisplayModeForDisplay(display, &current_mode);
current_mode = display->current_mode;
if (SDL_memcmp(&display_mode, &current_mode, sizeof(display_mode)) == 0) {
return 0;
}
@ -1054,7 +1022,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
}
SDL_GL_LoadLibrary(NULL);
}
display = SDL_CurrentDisplay;
display = &_this->displays[0]; /* FIXME */
window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
window->magic = &_this->window_magic;
window->id = _this->next_object_id++;
@ -1102,7 +1070,7 @@ SDL_CreateWindowFrom(const void *data)
SDL_UninitializedVideo();
return NULL;
}
display = SDL_CurrentDisplay;
display = &_this->displays[0]; /* FIXME */
window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
window->magic = &_this->window_magic;
window->id = _this->next_object_id++;
@ -1676,7 +1644,7 @@ SDL_GetFocusWindow(void)
if (!_this) {
return NULL;
}
display = SDL_CurrentDisplay;
display = &_this->displays[0]; /* FIXME */
for (window = display->windows; window; window = window->next) {
if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
return window;

View file

@ -220,7 +220,7 @@ static void
X11_GL_InitExtensions(_THIS)
{
Display *display = ((SDL_VideoData *) _this->driverdata)->display;
int screen = ((SDL_DisplayData *) SDL_CurrentDisplay->driverdata)->screen;
int screen = DefaultScreen(display);
XVisualInfo *vinfo;
XSetWindowAttributes xattr;
Window w;