Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API to discover current desktop resolution... #8

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Closed

API to discover current desktop resolution... #8

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 2.0.0
Reported for operating system, platform: All, All

Comments on the original bug report:

On 2006-01-22 04:55:55 +0000, Ryan C. Gordon wrote:

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.

On 2006-01-27 11:23:20 +0000, Ryan C. Gordon wrote:

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.

On 2006-01-30 02:13:01 +0000, Sam Lantinga wrote:

(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.

On 2006-01-30 02:25:25 +0000, Sam Lantinga wrote:

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.

On 2006-01-30 02:27:20 +0000, Sam Lantinga wrote:

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

On 2006-01-30 02:30:00 +0000, Sam Lantinga wrote:

Created attachment 54
dm-cvs-20050124144500.diff.txt

Here's Jon's patch to add this function to the API

On 2006-01-30 02:31:43 +0000, Sam Lantinga wrote:

Ryan, is there value to adding an API function in addition to simply adding the information to the VideoInfo structure in 1.3?

On 2006-01-30 10:28:21 +0000, Ryan C. Gordon wrote:

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.

On 2006-01-31 09:09:42 +0000, Sam Lantinga wrote:

(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?

On 2006-01-31 10:37:43 +0000, Ryan C. Gordon wrote:

Yeah, I think that's a good 1.3 candidate.

--ryan.

On 2006-03-15 12:46:10 +0000, Sam Lantinga wrote:

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.

On 2009-02-16 20:42:20 +0000, Sam Lantinga wrote:

SDL_GetDesktopDisplayMode() is in for SDL 1.3

slouken added a commit that referenced this issue Feb 9, 2023
…pened

This was the callstack:
    frame #3: 0x00000001004e1930 libSDL3.1.0.0.dylib`IOS_AddJoystickDevice(controller=0x0000600003b0c000, accelerometer=SDL_FALSE) at SDL_mfijoystick.m:528:14
    frame #4: 0x00000001004e1a54 libSDL3.1.0.0.dylib`__IOS_JoystickInit_block_invoke(.block_descriptor=0x0000000100547760, note=@"GCControllerDidConnectNotification") at SDL_mfijoystick.m:673:45
    frame #5: 0x000000018601e578 CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 128
    frame #6: 0x00000001860bc074 CoreFoundation`___CFXRegistrationPost_block_invoke + 88
    frame #7: 0x00000001860bbfbc CoreFoundation`_CFXRegistrationPost + 440
    frame #8: 0x0000000185fefbac CoreFoundation`_CFXNotificationPost + 708
    frame #9: 0x0000000186edc72c Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 88
    frame #10: 0x000000019b054a18 GameController`__60-[_GCControllerManagerAppClient _onqueue_publishController:]_block_invoke + 156
    frame #11: 0x0000000185dc19dc libdispatch.dylib`_dispatch_call_block_and_release + 32
    frame #12: 0x0000000185dc3504 libdispatch.dylib`_dispatch_client_callout + 20
    frame #13: 0x0000000185dd1d1c libdispatch.dylib`_dispatch_main_queue_drain + 928
    frame #14: 0x0000000185dd196c libdispatch.dylib`_dispatch_main_queue_callback_4CF + 44
    frame #15: 0x000000018606ad6c CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
    frame #16: 0x00000001860287ec CoreFoundation`__CFRunLoopRun + 2036
    frame #17: 0x00000001860278a4 CoreFoundation`CFRunLoopRunSpecific + 612
    frame #18: 0x00000001003b1194 libSDL3.1.0.0.dylib`process_pending_events at hid.c:509:9
    frame #19: 0x00000001003aebe8 libSDL3.1.0.0.dylib`PLATFORM_hid_open_path(path="USB_054c_05c4_0x11a104290", bExclusive=0) at hid.c:823:2
    frame #20: 0x00000001003b051c libSDL3.1.0.0.dylib`SDL_hid_open_path_REAL(path="USB_054c_05c4_0x11a104290", bExclusive=0) at SDL_hidapi.c:1419:19
    frame #21: 0x00000001004dabdc libSDL3.1.0.0.dylib`HIDAPI_SetupDeviceDriver(device=0x0000600003518000, removed=0x000000016fdfee3c) at SDL_hidapijoystick.c:399:19
    frame #22: 0x00000001004da890 libSDL3.1.0.0.dylib`HIDAPI_AddDevice(info=0x000060000212c2d0, num_children=0, children=0x0000000000000000) at SDL_hidapijoystick.c:843:5
    frame #23: 0x00000001004d9148 libSDL3.1.0.0.dylib`HIDAPI_UpdateDeviceList at SDL_hidapijoystick.c:1000:21
    frame #24: 0x00000001004d9940 libSDL3.1.0.0.dylib`HIDAPI_JoystickDetect at SDL_hidapijoystick.c:1205:13
    frame #25: 0x00000001003bc6d8 libSDL3.1.0.0.dylib`SDL_UpdateJoysticks_REAL at SDL_joystick.c:1703:9
    frame #26: 0x00000001003a13a8 libSDL3.1.0.0.dylib`SDL_PumpEventsInternal(push_sentinel=SDL_FALSE) at SDL_events.c:855:9
    frame #27: 0x00000001003a1340 libSDL3.1.0.0.dylib`SDL_PumpEvents_REAL at SDL_events.c:879:5
    frame #28: 0x000000010038b380 libSDL3.1.0.0.dylib`SDL_PumpEvents at SDL_dynapi_procs.h:572:1
    frame #29: 0x0000000100004524 testgamepad`loop + 40
    frame #30: 0x00000001000063d8 testgamepad`main + 2140
slouken added a commit that referenced this issue Feb 9, 2023
…pened

This was the callstack:
    frame #3: 0x00000001004e1930 libSDL3.1.0.0.dylib`IOS_AddJoystickDevice(controller=0x0000600003b0c000, accelerometer=SDL_FALSE) at SDL_mfijoystick.m:528:14
    frame #4: 0x00000001004e1a54 libSDL3.1.0.0.dylib`__IOS_JoystickInit_block_invoke(.block_descriptor=0x0000000100547760, note=@"GCControllerDidConnectNotification") at SDL_mfijoystick.m:673:45
    frame #5: 0x000000018601e578 CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 128
    frame #6: 0x00000001860bc074 CoreFoundation`___CFXRegistrationPost_block_invoke + 88
    frame #7: 0x00000001860bbfbc CoreFoundation`_CFXRegistrationPost + 440
    frame #8: 0x0000000185fefbac CoreFoundation`_CFXNotificationPost + 708
    frame #9: 0x0000000186edc72c Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 88
    frame #10: 0x000000019b054a18 GameController`__60-[_GCControllerManagerAppClient _onqueue_publishController:]_block_invoke + 156
    frame #11: 0x0000000185dc19dc libdispatch.dylib`_dispatch_call_block_and_release + 32
    frame #12: 0x0000000185dc3504 libdispatch.dylib`_dispatch_client_callout + 20
    frame #13: 0x0000000185dd1d1c libdispatch.dylib`_dispatch_main_queue_drain + 928
    frame #14: 0x0000000185dd196c libdispatch.dylib`_dispatch_main_queue_callback_4CF + 44
    frame #15: 0x000000018606ad6c CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
    frame #16: 0x00000001860287ec CoreFoundation`__CFRunLoopRun + 2036
    frame #17: 0x00000001860278a4 CoreFoundation`CFRunLoopRunSpecific + 612
    frame #18: 0x00000001003b1194 libSDL3.1.0.0.dylib`process_pending_events at hid.c:509:9
    frame #19: 0x00000001003aebe8 libSDL3.1.0.0.dylib`PLATFORM_hid_open_path(path="USB_054c_05c4_0x11a104290", bExclusive=0) at hid.c:823:2
    frame #20: 0x00000001003b051c libSDL3.1.0.0.dylib`SDL_hid_open_path_REAL(path="USB_054c_05c4_0x11a104290", bExclusive=0) at SDL_hidapi.c:1419:19
    frame #21: 0x00000001004dabdc libSDL3.1.0.0.dylib`HIDAPI_SetupDeviceDriver(device=0x0000600003518000, removed=0x000000016fdfee3c) at SDL_hidapijoystick.c:399:19
    frame #22: 0x00000001004da890 libSDL3.1.0.0.dylib`HIDAPI_AddDevice(info=0x000060000212c2d0, num_children=0, children=0x0000000000000000) at SDL_hidapijoystick.c:843:5
    frame #23: 0x00000001004d9148 libSDL3.1.0.0.dylib`HIDAPI_UpdateDeviceList at SDL_hidapijoystick.c:1000:21
    frame #24: 0x00000001004d9940 libSDL3.1.0.0.dylib`HIDAPI_JoystickDetect at SDL_hidapijoystick.c:1205:13
    frame #25: 0x00000001003bc6d8 libSDL3.1.0.0.dylib`SDL_UpdateJoysticks_REAL at SDL_joystick.c:1703:9
    frame #26: 0x00000001003a13a8 libSDL3.1.0.0.dylib`SDL_PumpEventsInternal(push_sentinel=SDL_FALSE) at SDL_events.c:855:9
    frame #27: 0x00000001003a1340 libSDL3.1.0.0.dylib`SDL_PumpEvents_REAL at SDL_events.c:879:5
    frame #28: 0x000000010038b380 libSDL3.1.0.0.dylib`SDL_PumpEvents at SDL_dynapi_procs.h:572:1
    frame #29: 0x0000000100004524 testgamepad`loop + 40
    frame #30: 0x00000001000063d8 testgamepad`main + 2140

(cherry picked from commit a9650d4)
1bsyl pushed a commit to 1bsyl/SDL that referenced this issue Feb 9, 2023
…pened

This was the callstack:
    frame libsdl-org#3: 0x00000001004e1930 libSDL3.1.0.0.dylib`IOS_AddJoystickDevice(controller=0x0000600003b0c000, accelerometer=SDL_FALSE) at SDL_mfijoystick.m:528:14
    frame libsdl-org#4: 0x00000001004e1a54 libSDL3.1.0.0.dylib`__IOS_JoystickInit_block_invoke(.block_descriptor=0x0000000100547760, note=@"GCControllerDidConnectNotification") at SDL_mfijoystick.m:673:45
    frame libsdl-org#5: 0x000000018601e578 CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 128
    frame libsdl-org#6: 0x00000001860bc074 CoreFoundation`___CFXRegistrationPost_block_invoke + 88
    frame libsdl-org#7: 0x00000001860bbfbc CoreFoundation`_CFXRegistrationPost + 440
    frame libsdl-org#8: 0x0000000185fefbac CoreFoundation`_CFXNotificationPost + 708
    frame libsdl-org#9: 0x0000000186edc72c Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 88
    frame libsdl-org#10: 0x000000019b054a18 GameController`__60-[_GCControllerManagerAppClient _onqueue_publishController:]_block_invoke + 156
    frame libsdl-org#11: 0x0000000185dc19dc libdispatch.dylib`_dispatch_call_block_and_release + 32
    frame libsdl-org#12: 0x0000000185dc3504 libdispatch.dylib`_dispatch_client_callout + 20
    frame libsdl-org#13: 0x0000000185dd1d1c libdispatch.dylib`_dispatch_main_queue_drain + 928
    frame libsdl-org#14: 0x0000000185dd196c libdispatch.dylib`_dispatch_main_queue_callback_4CF + 44
    frame libsdl-org#15: 0x000000018606ad6c CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
    frame libsdl-org#16: 0x00000001860287ec CoreFoundation`__CFRunLoopRun + 2036
    frame libsdl-org#17: 0x00000001860278a4 CoreFoundation`CFRunLoopRunSpecific + 612
    frame libsdl-org#18: 0x00000001003b1194 libSDL3.1.0.0.dylib`process_pending_events at hid.c:509:9
    frame libsdl-org#19: 0x00000001003aebe8 libSDL3.1.0.0.dylib`PLATFORM_hid_open_path(path="USB_054c_05c4_0x11a104290", bExclusive=0) at hid.c:823:2
    frame libsdl-org#20: 0x00000001003b051c libSDL3.1.0.0.dylib`SDL_hid_open_path_REAL(path="USB_054c_05c4_0x11a104290", bExclusive=0) at SDL_hidapi.c:1419:19
    frame libsdl-org#21: 0x00000001004dabdc libSDL3.1.0.0.dylib`HIDAPI_SetupDeviceDriver(device=0x0000600003518000, removed=0x000000016fdfee3c) at SDL_hidapijoystick.c:399:19
    frame libsdl-org#22: 0x00000001004da890 libSDL3.1.0.0.dylib`HIDAPI_AddDevice(info=0x000060000212c2d0, num_children=0, children=0x0000000000000000) at SDL_hidapijoystick.c:843:5
    frame libsdl-org#23: 0x00000001004d9148 libSDL3.1.0.0.dylib`HIDAPI_UpdateDeviceList at SDL_hidapijoystick.c:1000:21
    frame libsdl-org#24: 0x00000001004d9940 libSDL3.1.0.0.dylib`HIDAPI_JoystickDetect at SDL_hidapijoystick.c:1205:13
    frame libsdl-org#25: 0x00000001003bc6d8 libSDL3.1.0.0.dylib`SDL_UpdateJoysticks_REAL at SDL_joystick.c:1703:9
    frame libsdl-org#26: 0x00000001003a13a8 libSDL3.1.0.0.dylib`SDL_PumpEventsInternal(push_sentinel=SDL_FALSE) at SDL_events.c:855:9
    frame libsdl-org#27: 0x00000001003a1340 libSDL3.1.0.0.dylib`SDL_PumpEvents_REAL at SDL_events.c:879:5
    frame libsdl-org#28: 0x000000010038b380 libSDL3.1.0.0.dylib`SDL_PumpEvents at SDL_dynapi_procs.h:572:1
    frame libsdl-org#29: 0x0000000100004524 testgamepad`loop + 40
    frame libsdl-org#30: 0x00000001000063d8 testgamepad`main + 2140
madebr pushed a commit to madebr/SDL that referenced this issue Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant