Skip to content

Detect device form factor #12584

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Semphriss
Copy link
Contributor

Description

This adds a new function SDL_GetDeviceFormFactor(), which guesses what kind of device the current device may be.

It can report the following devices:

  • Desktop
  • Laptop
  • Phone
  • Tablet
  • Console
  • Handheld console
  • Smartwatch
  • TV
  • VR
  • Car

I've added support to the best of my abilities, but I couldn't cover 100% of cases either because I'm not familiar enough with the platform (QNX can be in phones, cars, and other embedded systems) or because the system itself doesn't provide that information (generic Unix).

I'm also aware that private platforms may want to provide their own value, but I couldn't find a compiler macro that detects if SDL is currently being compiled for a private platform. I would need help to find out how that can be done.

Existing Issue(s)

None

@Semphriss Semphriss force-pushed the form-factor branch 3 times, most recently from 4255201 to bd739df Compare March 23, 2025 18:18
@TheMode
Copy link
Contributor

TheMode commented Mar 31, 2025

SDL_GetDeviceFormFactorName giving a human readable name would be nice to have

@Semphriss
Copy link
Contributor Author

Semphriss commented May 21, 2025

@TheMode I'm not sure how translation would be supported, but I can give it a try. I'll see if there's another similar function in SDL to use as a template.

Edit: I've given it a quick look, and it seems that most functions promising a "human readable" string either returns a string generated by something outside SDL (like a camera device name) or the literal stringification of an enum (like SDL_GetPixelFormatName). I'm not sure what the use case is for the latter, other than error/debug messages, but I suppose I can make something similar to that.

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

Successfully merging this pull request may close these issues.

None yet

4 participants