1
0
Fork 0
forked from fte/fteqw

Try to fix xrandr monitor selection - should now properly default to the primary monitor, as well as actually use it...

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5523 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2019-08-20 11:45:43 +00:00
parent 267d9a1753
commit 06be934fa2

View file

@ -665,40 +665,43 @@ static struct
XRRScreenResources *res; //all the resources on the system (including modes etc) XRRScreenResources *res; //all the resources on the system (including modes etc)
XRROutputInfo **outputs; //list of info for all outputs XRROutputInfo **outputs; //list of info for all outputs
XRROutputInfo *output; //the output device that we're using XRROutputInfo *output; //the output device that we're using
RRCrtc crtc; //the output device's screen that we're focusing on (modes and gamma) RRCrtc crtc; //the output device's screen that we're focusing on (modes and gamma)
XRRCrtcInfo *crtcinfo; //the info to restore XRRCrtcInfo *crtcinfo; //the info to restore
XRRModeInfo *crtcmode; //the mode we want to use XRRModeInfo *crtcmode; //the mode we want to use
XRRCrtcGamma *origgamma; XRRCrtcGamma *origgamma;
// Status (*pGetScreenSizeRange) (Display *dpy, Window window, int *minwidth, int *minheight, int *maxwidth, int *maxheight); // Status (*pGetScreenSizeRange) (Display *dpy, Window window, int *minwidth, int *minheight, int *maxwidth, int *maxheight);
// void (*pSetScreenSize) (Display *dpy, Window window, int width, int height, int mmwidth, int mmheight); // void (*pSetScreenSize) (Display *dpy, Window window, int width, int height, int mmwidth, int mmheight);
XRRScreenResources *(*pGetScreenResources) (Display *dpy, Window window); XRRScreenResources *(*pGetScreenResources) (Display *dpy, Window window);
void *(*pFreeScreenResources)(XRRScreenResources *); void *(*pFreeScreenResources)(XRRScreenResources *);
XRROutputInfo *(*pGetOutputInfo) (Display *dpy, XRRScreenResources *resources, RROutput output); XRROutputInfo *(*pGetOutputInfo) (Display *dpy, XRRScreenResources *resources, RROutput output);
void *(*pFreeOutputInfo) (XRROutputInfo *outputinfo); void *(*pFreeOutputInfo) (XRROutputInfo *outputinfo);
XRRCrtcInfo *(*pGetCrtcInfo) (Display *dpy, XRRScreenResources *resources, RRCrtc crtc); XRRCrtcInfo *(*pGetCrtcInfo) (Display *dpy, XRRScreenResources *resources, RRCrtc crtc);
void *(*pFreeCrtcInfo) (XRRCrtcInfo *crtcinfo); void *(*pFreeCrtcInfo) (XRRCrtcInfo *crtcinfo);
Status (*pSetCrtcConfig) (Display *dpy, XRRScreenResources *resources, RRCrtc crtc, Time timestamp, int x, int y, RRMode mode, Rotation rotation, RROutput *output, int noutputs); Status (*pSetCrtcConfig) (Display *dpy, XRRScreenResources *resources, RRCrtc crtc, Time timestamp, int x, int y, RRMode mode, Rotation rotation, RROutput *output, int noutputs);
XRRCrtcGamma * (*pGetCrtcGamma) (Display *dpy, RRCrtc crtc); XRRCrtcGamma * (*pGetCrtcGamma) (Display *dpy, RRCrtc crtc);
void (*pFreeGamma) (XRRCrtcGamma *gamma); void (*pFreeGamma) (XRRCrtcGamma *gamma);
void (*pSetCrtcGamma) (Display *dpy, RRCrtc crtc, XRRCrtcGamma *gamma); void (*pSetCrtcGamma) (Display *dpy, RRCrtc crtc, XRRCrtcGamma *gamma);
//v1.3 has non-0 primary monitors.
RROutput (*pGetOutputPrimary) (Display *dpy, Window window);
} xrandr; } xrandr;
static qboolean XRandR_Init(void) static qboolean XRandR_Init(void)
{ {
static dllfunction_t xrandr_functable[] = static dllfunction_t xrandr_functable[] =
{ {
{(void**)&xrandr.pQueryExtension, "XRRQueryExtension"}, {(void**)&xrandr.pQueryExtension, "XRRQueryExtension"},
{(void**)&xrandr.pQueryVersion, "XRRQueryVersion"}, {(void**)&xrandr.pQueryVersion, "XRRQueryVersion"},
//1.0 //1.0
{(void**)&xrandr.pGetScreenInfo, "XRRGetScreenInfo"}, {(void**)&xrandr.pGetScreenInfo, "XRRGetScreenInfo"},
{(void**)&xrandr.pConfigTimes, "XRRConfigTimes"}, {(void**)&xrandr.pConfigTimes, "XRRConfigTimes"},
{(void**)&xrandr.pConfigSizes, "XRRConfigSizes"}, {(void**)&xrandr.pConfigSizes, "XRRConfigSizes"},
{(void**)&xrandr.pConfigRates, "XRRConfigRates"}, {(void**)&xrandr.pConfigRates, "XRRConfigRates"},
{(void**)&xrandr.pConfigCurrentConfiguration, "XRRConfigCurrentConfiguration"}, {(void**)&xrandr.pConfigCurrentConfiguration, "XRRConfigCurrentConfiguration"},
{(void**)&xrandr.pConfigCurrentRate, "XRRConfigCurrentRate"}, {(void**)&xrandr.pConfigCurrentRate, "XRRConfigCurrentRate"},
//1.1 //1.1
{(void**)&xrandr.pSetScreenConfigAndRate, "XRRSetScreenConfigAndRate"}, {(void**)&xrandr.pSetScreenConfigAndRate, "XRRSetScreenConfigAndRate"},
{NULL, NULL} {NULL, NULL}
}; };
@ -744,6 +747,8 @@ static qboolean XRandR_Init(void)
) )
xrandr.canmodechange12 = true; xrandr.canmodechange12 = true;
} }
if (xrandr.vmajor > 1 || (xrandr.vmajor == 1 && xrandr.vminor >= 3))
xrandr.pGetOutputPrimary = Sys_GetAddressForName(xrandr.lib, "XRRGetOutputPrimary");
//FIXME: query monitor sizes and calculate dpi for vid.dpy_[x|y] //FIXME: query monitor sizes and calculate dpi for vid.dpy_[x|y]
return true; return true;
@ -880,7 +885,7 @@ static void XRandR_Shutdown(void)
} }
static qboolean XRandR_FindOutput(const char *name) static qboolean XRandR_FindOutput(const char *name)
{ {
XRROutputInfo *primary = NULL; RROutput p;
int i; int i;
if (!xrandr.canmodechange12) if (!xrandr.canmodechange12)
return false; return false;
@ -894,6 +899,12 @@ static qboolean XRandR_FindOutput(const char *name)
for (i = 0; i < xrandr.res->noutput; i++) for (i = 0; i < xrandr.res->noutput; i++)
xrandr.outputs[i] = xrandr.pGetOutputInfo(vid_dpy, xrandr.res, xrandr.res->outputs[i]); xrandr.outputs[i] = xrandr.pGetOutputInfo(vid_dpy, xrandr.res, xrandr.res->outputs[i]);
} }
if (xrandr.pGetOutputPrimary)
p = xrandr.pGetOutputPrimary(vid_dpy, DefaultRootWindow(vid_dpy));
else if (xrandr.res->noutput)
p = xrandr.res->outputs[0];
else
p = 0;
xrandr.output = NULL; xrandr.output = NULL;
xrandr.crtc = None; xrandr.crtc = None;
if (xrandr.origgamma) if (xrandr.origgamma)
@ -909,19 +920,17 @@ static qboolean XRandR_FindOutput(const char *name)
{ {
if (xrandr.outputs[i]->connection != RR_Connected || !xrandr.outputs[i]->ncrtc) if (xrandr.outputs[i]->connection != RR_Connected || !xrandr.outputs[i]->ncrtc)
continue; //not usable... continue; //not usable...
if (!primary || (xrandr.outputs[i]->npreferred && !primary->npreferred)) if (!xrandr.output && xrandr.res->outputs[i] == p)
primary = xrandr.outputs[i]; xrandr.output = xrandr.outputs[i];
if (*name && !strncmp(xrandr.outputs[i]->name, name, xrandr.outputs[i]->nameLen)) if (*name && !strncmp(xrandr.outputs[i]->name, name, xrandr.outputs[i]->nameLen))
{ //this is the one they asked for { //this is the one they asked for
xrandr.output = xrandr.outputs[i]; xrandr.output = xrandr.outputs[i];
break; break;
} }
} }
if (!xrandr.output)
xrandr.output = primary;
if (xrandr.output) if (xrandr.output)
{ {
xrandr.crtc = xrandr.output->crtcs[0]; xrandr.crtc = xrandr.output->crtc;
xrandr.crtcinfo = xrandr.pGetCrtcInfo(vid_dpy, xrandr.res, xrandr.crtc); xrandr.crtcinfo = xrandr.pGetCrtcInfo(vid_dpy, xrandr.res, xrandr.crtc);
if (xrandr.crtcinfo) if (xrandr.crtcinfo)
{ {
@ -943,7 +952,7 @@ static qboolean XRandr_PickScreen(const char *devicename, int *x, int *y, int *w
*y = c->y; *y = c->y;
*width = c->width; *width = c->width;
*height = c->height; *height = c->height;
Con_Printf("Found monitor %s %ix%i +%i,%i\n", xrandr.output->name, c->width, c->height, c->x, c->y); Con_Printf("Found monitor %s %ix%i %i,%i\n", xrandr.output->name, c->width, c->height, c->x, c->y);
return true; return true;
} }
return false; return false;