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

Commit

Permalink
Implemented SDL_GetDisplayName() for X11, which requires the XRandR e…
Browse files Browse the repository at this point in the history
…xtension.

It turns out there's all kinds of good information in the EDID data for a monitor...
  • Loading branch information
slouken committed Jan 1, 2013
1 parent 0c26b5e commit 1281e99
Show file tree
Hide file tree
Showing 5 changed files with 993 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/test/SDL_test_common.c
Expand Up @@ -674,7 +674,7 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
n = SDL_GetNumVideoDisplays();
fprintf(stderr, "Number of displays: %d\n", n);
for (i = 0; i < n; ++i) {
fprintf(stderr, "Display %d:\n", i);
fprintf(stderr, "Display %d: %s\n", i, SDL_GetDisplayName(i));

SDL_zero(bounds);
SDL_GetDisplayBounds(i, &bounds);
Expand Down
59 changes: 58 additions & 1 deletion src/video/x11/SDL_x11modes.c
Expand Up @@ -24,6 +24,7 @@

#include "SDL_hints.h"
#include "SDL_x11video.h"
#include "edid.h"

/*#define X11MODES_DEBUG*/

Expand All @@ -34,8 +35,10 @@
* I can find. For example, on Unity 3D if you show a fullscreen window while
* the resolution is changing (within ~250 ms) your window will retain the
* fullscreen state hint but be decorated and windowed.
*
* However, many people swear by it, so let them swear at it. :)
*/
#define XRANDR_DISABLED_BY_DEFAULT
/*#define XRANDR_DISABLED_BY_DEFAULT*/


static int
Expand Down Expand Up @@ -427,6 +430,7 @@ X11_InitModes(_THIS)
SDL_DisplayMode mode;
SDL_DisplayModeData *modedata;
XPixmapFormatValues *pixmapFormats;
char display_name[128];
int i, n;

#if SDL_VIDEO_DRIVER_X11_XINERAMA
Expand All @@ -449,6 +453,7 @@ X11_InitModes(_THIS)
if (!displaydata) {
continue;
}
display_name[0] = '\0';

mode.format = X11_GetPixelFormatFromVisualInfo(data->display, &vinfo);
if (SDL_ISPIXELFORMAT_INDEXED(mode.format)) {
Expand Down Expand Up @@ -527,6 +532,12 @@ X11_InitModes(_THIS)
XRROutputInfo *output_info;
XRRCrtcInfo *crtc;
int output;
Atom EDID = XInternAtom(data->display, "EDID", False);
Atom *props;
int nprop;
unsigned long width_mm;
unsigned long height_mm;
int inches = 0;

for (output = 0; output < res->noutput; output++) {
output_info = XRRGetOutputInfo(data->display, res, res->outputs[output]);
Expand All @@ -551,6 +562,49 @@ X11_InitModes(_THIS)
displaydata->xrandr_output = res->outputs[output];
SetXRandRModeInfo(data->display, res, output_info, crtc->mode, &mode);

/* Get the name of this display */
width_mm = output_info->mm_width;
height_mm = output_info->mm_height;
inches = (int)((sqrt(width_mm * width_mm +
height_mm * height_mm) / 25.4f) + 0.5f);
SDL_strlcpy(display_name, output_info->name, sizeof(display_name));

/* See if we can get the EDID data for the real monitor name */
props = XRRListOutputProperties(data->display, res->outputs[output], &nprop);
for (i = 0; i < nprop; ++i) {
unsigned char *prop;
int actual_format;
unsigned long nitems, bytes_after;
Atom actual_type;

if (props[i] == EDID) {
XRRGetOutputProperty(data->display, res->outputs[output], props[i],
0, 100, False, False,
AnyPropertyType,
&actual_type, &actual_format,
&nitems, &bytes_after, &prop);

MonitorInfo *info = decode_edid(prop);
if (info) {
#ifdef X11MODES_DEBUG
printf("Found EDID data for %s\n", output_info->name);
dump_monitor_info(info);
#endif
SDL_strlcpy(display_name, info->dsc_product_name, sizeof(display_name));
free(info);
}
break;
}
}

if (*display_name && inches) {
size_t len = SDL_strlen(display_name);
SDL_snprintf(&display_name[len], sizeof(display_name)-len, " %d\"", inches);
}
#ifdef X11MODES_DEBUG
printf("Display name: %s\n", display_name);
#endif

XRRFreeOutputInfo(output_info);
XRRFreeCrtcInfo(crtc);
break;
Expand Down Expand Up @@ -583,6 +637,9 @@ X11_InitModes(_THIS)
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */

SDL_zero(display);
if (*display_name) {
display.name = display_name;
}
display.desktop_mode = mode;
display.current_mode = mode;
display.driverdata = displaydata;
Expand Down
3 changes: 3 additions & 0 deletions src/video/x11/SDL_x11sym.h
Expand Up @@ -265,6 +265,9 @@ SDL_X11_SYM(void,XRRFreeOutputInfo,(XRROutputInfo *outputInfo),(outputInfo),)
SDL_X11_SYM(XRRCrtcInfo *,XRRGetCrtcInfo,(Display *dpy, XRRScreenResources *resources, RRCrtc crtc),(dpy,resources,crtc),return)
SDL_X11_SYM(void,XRRFreeCrtcInfo,(XRRCrtcInfo *crtcInfo),(crtcInfo),)
SDL_X11_SYM(Status,XRRSetCrtcConfig,(Display *dpy, XRRScreenResources *resources, RRCrtc crtc, Time timestamp, int x, int y, RRMode mode, Rotation rotation, RROutput *outputs, int noutputs),(dpy,resources,crtc,timestamp,x,y,mode,rotation,outputs,noutputs),return)
SDL_X11_SYM(Atom*,XRRListOutputProperties,(Display *dpy, RROutput output, int *nprop),(dpy,output,nprop),return)
SDL_X11_SYM(XRRPropertyInfo*,XRRQueryOutputProperty,(Display *dpy,RROutput output, Atom property),(dpy,output,property),return)
SDL_X11_SYM(int,XRRGetOutputProperty,(Display *dpy,RROutput output, Atom property, long offset, long length, Bool _delete, Bool pending, Atom req_type, Atom *actual_type, int *actual_format, unsigned long *nitems, unsigned long *bytes_after, unsigned char **prop),(dpy,output,property,offset,length, _delete, pending, req_type, actual_type, actual_format, nitems, bytes_after, prop),return)
#endif

/* MIT-SCREEN-SAVER support */
Expand Down

0 comments on commit 1281e99

Please sign in to comment.