We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 66 - API to discover current desktop resolution...
Summary: API to discover current desktop resolution...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.0
Hardware: All All
: P2 API change
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-22 04:55 UTC by Ryan C. Gordon
Modified: 2009-02-16 20:42 UTC (History)
0 users

See Also:


Attachments
dm-cvs-20050124144500.diff.txt (6.95 KB, patch)
2006-01-30 02:30 UTC, Sam Lantinga
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan C. Gordon 2006-01-22 04:55:55 UTC
It would be nice if the application can determine what the current desktop resolution is, which can be useful as a default, or at least a known-good quantity.

My current proposal looks something like this:

    int SDL_GetCurrentResolution(SDL_Rect *physical, SDL_Rect *virtual);

On success, (physical) will be the physical resolution of the display at the time of the call, and (virtual) will be filled with the "virtual" resolution (i.e. - an X11 desktop bigger than the physical display that scrolls as the mouse moves around it, etc). Either parameter may be NULL, in which case that parameter won't receive a value.

returns -1 on error (unsupported, hardware error, etc)...use SDL_GetError() for reason for failure. Returns 0 on success.

Issues:
- What to do with multimonitor support?
- Is virtual resolution really useful?
- Should this report the resolution at that moment? Should it change with a successful call to SDL_SetVideoMode(..., SDL_FULLSCREEN)?
- What drivers can actually support this?

--ryan.
Comment 1 Ryan C. Gordon 2006-01-27 11:23:20 UTC
Setting Sam as "QA Contact" on all bugs (even resolved ones) so he'll definitely be in the loop to any further discussion here about SDL.

--ryan.

Comment 2 Sam Lantinga 2006-01-30 02:13:01 UTC
(In reply to comment #0)
> My current proposal looks something like this:
>     int SDL_GetCurrentResolution(SDL_Rect *physical, SDL_Rect *virtual);

How about SDL_GetDesktopResolution(...)?

> Issues:
> - What to do with multimonitor support?

Punt until we have multimonitor support in SDL.  We'd need to be able to enumerate the attached monitors and specify which one is used in the API calls to list video modes, set video modes, and this one.

> - Is virtual resolution really useful?

*shrug*

> - Should this report the resolution at that moment? Should it change with a
> successful call to SDL_SetVideoMode(..., SDL_FULLSCREEN)?

No, it should just report the current desktop resolution, before going to fullscreen.  If you're in windowed mode, and the user changes desktop resolution, it should return the new desktop resolution.

> - What drivers can actually support this?

Windows can, X11 can, I presume most other systems with a desktop can do this.


Comment 3 Sam Lantinga 2006-01-30 02:25:25 UTC
Date: Tue, 22 Mar 2005 02:50:26 +0000 (UTC)
From: Marco Tarini <tarini@isti.cnr.it>
Subject: [SDL] detecting current screen resolution (again!)

Let me also suggest the simplest way (from the point of view of the
library-user, not the SDL-dev) to have that: make SDL_SetVideoMode(sx,sx,bpp,flags), when
- flags includes SDL_FULLSCREEN and
- (sx,sy,bpp)==(0,0,0)
set the fullscreen mode at the _current_ screen bpp, size x, and y.

Also, VideoInfo would return screen res as well. BTW isn't it peculiar that it currently doesn't? I wonder if it is that nobody though that it would be useful, or if there is problem I can't see implementing it in some system.
Comment 4 Sam Lantinga 2006-01-30 02:27:20 UTC
Date: Tue, 22 Mar 2005 18:20:37 +0000
From: Jon Colverson <sdl@vcxz.co.uk>
Subject: Re: [SDL] detecting current screen resolution (again!)

I wrote a patch to add a function to get the current desktop resolution.
Unfortunately, it's only implemented for X11 and Windows. There was a
thread about it on this list which starts here:

http://www.devolution.com/pipermail/sdl/2005-January/thread.html#67010
and continues in February:
http://www.devolution.com/pipermail/sdl/2005-February/thread.html#67335

To summarise the thread:

It was widely agreed that this would be useful functionality. Some
people didn't like my API (int SDL_GetDesktopMode(int *width, int
*height)), and it doesn't allow for complete binary compatibility
(programs that use the new function can't run with earlier SDL 1.2
libs). Stephane Marchesin suggested adding the information to the
SDL_VideoInfo structure. This can't be done without breaking binary
compatibility, so will have to wait for SDL 1.3 (I don't know if there's
a schedule for that yet). Simon Roby suggested the same API as you did
above. I was not wild about it, because it makes it harder/more
error-prone to specify a fallback default resolution, which is        
particularly important when the functionality isn't implemented for all
the SDL platforms/video drivers.

Sam Lantinga (lead developer of SDL) chimed in that he likes the idea of
using 0,0 in SDL_SetVideoMode to specify the desktop resolution, which
can be done now, in SDL 1.2. He also likes the idea of adding the 
desktop resolution to SDL_VideoInfo at a later date.             

So, it seems like it would be sensible for me to rewrite my patch to use
the 0,0 API, make sure it's documented well to minimise problems, and
accept a little ugliness in our application code which can be removed
when SDL 1.3 is available. I'll get to work on it, since Ryan just made 
a call for patches, and that would seem like a good chance of getting my
code commited and in the next release.

--
Jon
Comment 5 Sam Lantinga 2006-01-30 02:30:00 UTC
Created attachment 54 [details]
dm-cvs-20050124144500.diff.txt

Here's Jon's patch to add this function to the API
Comment 6 Sam Lantinga 2006-01-30 02:31:43 UTC
Ryan, is there value to adding an API function in addition to simply adding the information to the VideoInfo structure in 1.3?
Comment 7 Ryan C. Gordon 2006-01-30 10:28:21 UTC
Adding to the structure is better, so long as it doesn't break binaries that expect it to be a certain size, which was what I was aiming to avoid...in this case, it's probably safe if you add it to the end of the struct.

--ryan.

Comment 8 Sam Lantinga 2006-01-31 09:09:42 UTC
(In reply to comment #7)
> Adding to the structure is better, so long as it doesn't break binaries that
> expect it to be a certain size, which was what I was aiming to avoid...in this
> case, it's probably safe if you add it to the end of the struct.

That seems reasonable.  I'm tempted to add it to 1.3, since I can easily see that information followed up with requests to get/set the window position programmatically - one of the items on the 1.3 TODO list.  What do you think?

Comment 9 Ryan C. Gordon 2006-01-31 10:37:43 UTC
Yeah, I think that's a good 1.3 candidate.

--ryan.

Comment 10 Sam Lantinga 2006-03-15 12:46:10 UTC
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.

SDL_SetVideoMode() now accepts 0 for width or height and will use the current video mode (or the desktop mode if no mode has been set.)

We can add something like SDL_GetDesktopResolution() for 1.3, so I'll leave this bug open, and move it to a 1.3 API request.
Comment 11 Sam Lantinga 2009-02-16 20:42:20 UTC
SDL_GetDesktopDisplayMode() is in for SDL 1.3