Esempio n. 1
0
void ui_get_screen_res(int *x0, int *y0, int *width, int *height, int monitor)
{
	int i, n, x, y, di;
	unsigned int du;
	Window dw;
	XRRScreenResources *sr;
	XRRCrtcInfo *ci = NULL;

	if (getenv("JGMENU_SCREEN_INFO"))
		print_screen_info();
	sr = XRRGetScreenResources(ui->dpy, DefaultRootWindow(ui->dpy));
	BUG_ON(!sr);
	n = sr->ncrtc;

	/*
	 * Global variable config.monitor let's the user specify a monitor.
	 * If not set, we use the current pointer position
	 */
	if (monitor) {
		if (monitor > n)
			die("cannot connect to monitor '%d'", monitor);
		ci = XRRGetCrtcInfo(ui->dpy, sr, sr->crtcs[monitor - 1]);
		if (!ci->noutput)
			die("cannot connect to monitor '%d'", monitor);
		info("using user specified monitor '%d'", monitor);
		goto monitor_selected;
	}

	XQueryPointer(ui->dpy, ui->root, &dw, &dw, &x, &y, &di, &di, &du);
	for (i = 0; i < n; i++) {
		if (ci)
			XRRFreeCrtcInfo(ci);
		ci = XRRGetCrtcInfo(ui->dpy, sr, sr->crtcs[i]);
		BUG_ON(!ci);
		if (!ci->noutput)
			continue;
		if (intersect(x, y, 1, 1, ci)) {
			info("using monitor '%d'", i + 1);
			break;
		}
	}

monitor_selected:
	if (!ci)
		die("connection could be established to monitor");
	*x0 = ci->x;
	*y0 = ci->y;
	*width = ci->width;
	*height = ci->height;
	XRRFreeCrtcInfo(ci);
	XRRFreeScreenResources(sr);
}
Esempio n. 2
0
Monitor::~Monitor() {
    if (GetCurrentVideoMode() != mOriginalVideoMode)
        SetVideoMode(mOriginalVideoMode);
#if defined(FastOSLinux)
    XRRFreeCrtcInfo((XRRCrtcInfo*)mXRRCrtcInfo);
#endif
}
Esempio n. 3
0
int main() {
    Display *disp;
    XRRScreenResources *screen;
    XRROutputInfo *info;
    XRRCrtcInfo *crtc_info;
    int iscres;
    int icrtc;

    disp = XOpenDisplay(0);
    screen = XRRGetScreenResources (disp, DefaultRootWindow(disp));
    for (iscres = screen->noutput; iscres > 0; ) {
        --iscres;

        info = XRRGetOutputInfo (disp, screen, screen->outputs[iscres]);
        if (info->connection == RR_Connected) {
            for (icrtc = info->ncrtc; icrtc > 0;) {
                --icrtc;

                crtc_info = XRRGetCrtcInfo (disp, screen, screen->crtcs[icrtc]);
                fprintf(stderr, "==> %dx%d+%dx%d\n", crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height);

                XRRFreeCrtcInfo(crtc_info);
            }
        }
        XRRFreeOutputInfo (info);
    }
    XRRFreeScreenResources(screen);

    return 0;
}
Esempio n. 4
0
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
{
    if (_glfw.x11.randr.available)
    {
        XRRScreenResources* sr;
        XRRCrtcInfo* ci;

        sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root);
        ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);

        mode->width = ci->width;
        mode->height = ci->height;

        mode->refreshRate = calculateRefreshRate(getModeInfo(sr, ci->mode));

        XRRFreeCrtcInfo(ci);
        XRRFreeScreenResources(sr);
    }
    else
    {
        mode->width = DisplayWidth(_glfw.x11.display, _glfw.x11.screen);
        mode->height = DisplayHeight(_glfw.x11.display, _glfw.x11.screen);
        mode->refreshRate = 0;
    }

    _glfwSplitBPP(DefaultDepth(_glfw.x11.display, _glfw.x11.screen),
                  &mode->redBits, &mode->greenBits, &mode->blueBits);
}
Esempio n. 5
0
static int
map_output_xrandr(Display *dpy, int deviceid, const char *output_name)
{
    int rc = EXIT_FAILURE;
    XRRScreenResources *res;
    XRROutputInfo *output_info;

    res = XRRGetScreenResources(dpy, DefaultRootWindow(dpy));
    output_info = find_output_xrandr(dpy, output_name);

    /* crtc holds our screen info, need to compare to actual screen size */
    if (output_info)
    {
        XRRCrtcInfo *crtc_info;
        Matrix m;
        matrix_set_unity(&m);
        crtc_info = XRRGetCrtcInfo (dpy, res, output_info->crtc);
        set_transformation_matrix(dpy, &m, crtc_info->x, crtc_info->y,
                                  crtc_info->width, crtc_info->height);
        rc = apply_matrix(dpy, deviceid, &m);
        XRRFreeCrtcInfo(crtc_info);
        XRRFreeOutputInfo(output_info);
    } else
        printf("Unable to find output '%s'. "
                "Output may not be connected.\n", output_name);

    XRRFreeScreenResources(res);

    return rc;
}
Esempio n. 6
0
static display init(XRRScreenResources* sr, RROutput output)
{
	display result;

	XRROutputInfo* oi = XRRGetOutputInfo(g_display, sr, output);
	if (oi->connection == RR_Connected)
	{
		result.scale = 1;
		result.name = oi->name;
		result.color_depth = XDefaultDepth(g_display, g_screen);
		result.color_depth_per_component = result.color_depth >= 24? 8 : 0;

		result.crtc = oi->crtc;
		result.output = output;

		XRRCrtcInfo* ci = XRRGetCrtcInfo(g_display, sr, oi->crtc);
		result.rect.left = ci->x;
		result.rect.top = ci->y;
		result.rect.width = ci->width;
		result.rect.height = ci->height;
		if (ci->rotation == RR_Rotate_90 || ci->rotation == RR_Rotate_270)
		{
			std::swap(result.rect.width, result.rect.height);
		}
		XRRFreeCrtcInfo(ci);

		result.work_rect = result.rect;
	}
	XRRFreeOutputInfo(oi);
	return result;
}
Esempio n. 7
0
// Restore the saved (original) video mode for the specified monitor
//
void _glfwRestoreVideoMode(_GLFWmonitor* monitor)
{
    if (_glfw.x11.randr.available)
    {
        XRRScreenResources* sr;
        XRRCrtcInfo* ci;

        if (monitor->x11.oldMode == None)
            return;

        sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root);
        ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);

        XRRSetCrtcConfig(_glfw.x11.display,
                         sr, monitor->x11.crtc,
                         CurrentTime,
                         ci->x, ci->y,
                         monitor->x11.oldMode,
                         ci->rotation,
                         ci->outputs,
                         ci->noutput);

        XRRFreeCrtcInfo(ci);
        XRRFreeScreenResources(sr);

        monitor->x11.oldMode = None;
    }
}
Esempio n. 8
0
std::vector<display::mode> display::modes() const
{
	std::vector<display::mode> result;
	if (randr.is_available)
	{
		XRRScreenResources* sr = XRRGetScreenResources(g_display, g_root);
		XRRCrtcInfo* ci = XRRGetCrtcInfo(g_display, sr, crtc);
		XRROutputInfo* oi = XRRGetOutputInfo(g_display, sr, output);

		for (int i = 0; i < oi->nmode; ++i)
		{
			XRRModeInfo const* mi = mode_info(sr, oi->modes[i]);
			if (mi && !(mi->modeFlags & RR_Interlace))
			{
				result.emplace_back(make_mode(mi, ci));
			}
		}

		XRRFreeOutputInfo(oi);
		XRRFreeCrtcInfo(ci);
		XRRFreeScreenResources(sr);

		std::sort(result.begin(), result.end());
		result.erase(std::unique(result.begin(), result.end()), result.end());
	}
	else
	{
		result.emplace_back(current_mode());
	}
	return result;
}
Esempio n. 9
0
static inline void _gfx_x11_leave_fullscreen(

		GFX_X11_Monitor* monitor)
{
	Window root =
		XRootWindowOfScreen(monitor->screen);
	XRRScreenResources* res =
		XRRGetScreenResources(_gfx_x11.display, root);
	XRRCrtcInfo* crtc =
		XRRGetCrtcInfo(_gfx_x11.display, res, monitor->crtc);

	/* Set mode */
	XRRSetCrtcConfig(
		_gfx_x11.display,
		res,
		monitor->crtc,
		crtc->timestamp,
		crtc->x,
		crtc->y,
		monitor->mode,
		crtc->rotation,
		crtc->outputs,
		crtc->noutput
	);

	XRRFreeCrtcInfo(crtc);
	XRRFreeScreenResources(res);
}
Esempio n. 10
0
void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
{
    if (_glfw.x11.randr.available)
    {
        XRRScreenResources* sr;
        XRRCrtcInfo* ci;

        sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root);
        ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);

        if (xpos)
            *xpos = ci->x;
        if (ypos)
            *ypos = ci->y;

        XRRFreeCrtcInfo(ci);
        XRRFreeScreenResources(sr);
    }
    else
    {
        if (xpos)
            *xpos = 0;
        if (ypos)
            *ypos = 0;
    }
}
Esempio n. 11
0
/*
 * Class:     jogamp_newt_driver_x11_RandR13
 * Method:    freeMonitorInfoHandle0
 * Signature: (J)V
 */
JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_RandR13_freeMonitorInfoHandle0
  (JNIEnv *env, jclass clazz, jlong monitorInfo)
{
    XRRCrtcInfo *xrrCrtcInfo = (XRRCrtcInfo *) (intptr_t) monitorInfo;
    if( NULL != xrrCrtcInfo ) {
        XRRFreeCrtcInfo( xrrCrtcInfo );
    }
}
Esempio n. 12
0
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
{
    GLFWvidmode* result;

    *found = 0;

    // Build array of available resolutions

    if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
    {
        int i, j;
        XRRScreenResources* sr;
        XRRCrtcInfo* ci;
        XRROutputInfo* oi;

        sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root);
        ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);
        oi = XRRGetOutputInfo(_glfw.x11.display, sr, monitor->x11.output);

        result = calloc(oi->nmode, sizeof(GLFWvidmode));

        for (i = 0;  i < oi->nmode;  i++)
        {
            const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]);
            if (!modeIsGood(mi))
                continue;

            const GLFWvidmode mode = vidmodeFromModeInfo(mi, ci);

            for (j = 0;  j < *found;  j++)
            {
                if (_glfwCompareVideoModes(result + j, &mode) == 0)
                    break;
            }

            if (j < *found)
            {
                // This is a duplicate, so skip it
                continue;
            }

            result[*found] = mode;
            (*found)++;
        }

        XRRFreeOutputInfo(oi);
        XRRFreeCrtcInfo(ci);
        XRRFreeScreenResources(sr);
    }
    else
    {
        *found = 1;
        result = calloc(1, sizeof(GLFWvidmode));
        _glfwPlatformGetVideoMode(monitor, result);
    }

    return result;
}
Esempio n. 13
0
MonitorManager *monitor_mgr_create()
{
    Display *display = XOpenDisplay(NULL);
    if (!display)
    {
        fprintf(stderr, "Cannot open display.\n");
        return NULL;
    }

    MonitorManager *mgr = malloc(sizeof(MonitorManager*));
    mgr->monitor_count = 0;
    mgr->monitors = NULL;

    Window root = DefaultRootWindow(display);
    RROutput primary_output = XRRGetOutputPrimary(display, root);

    XRRScreenResources *screen = XRRGetScreenResources(display, root);
    assert(screen);

    for (int i = 0; i < screen->noutput; i++)
    {
        XRROutputInfo *output_info = XRRGetOutputInfo(
            display, screen, screen->outputs[i]);
        assert(output_info);

        if (output_info->connection == RR_Connected)
        {
            XRRCrtcInfo *crtc_info = XRRGetCrtcInfo(
                display, screen, output_info->crtc);
            assert(crtc_info);

            int primary = 0;
            for (int j = 0; j < crtc_info->noutput; j++)
                if (crtc_info->outputs[j] == primary_output)
                    primary = 1;

            Monitor *monitor = monitor_create(
                primary,
                crtc_info->x,
                crtc_info->y,
                crtc_info->width,
                crtc_info->height);
            assert(monitor);

            monitor_mgr_add(mgr, monitor);

            XRRFreeCrtcInfo(crtc_info);
        }

        XRRFreeOutputInfo(output_info);
    }

    XRRFreeScreenResources(screen);
    XCloseDisplay(display);
    return mgr;
}
Esempio n. 14
0
// Set the current video mode for the specified monitor
//
void _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired)
{
    if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
    {
        XRRScreenResources* sr;
        XRRCrtcInfo* ci;
        XRROutputInfo* oi;
        GLFWvidmode current;
        const GLFWvidmode* best;
        RRMode native = None;
        int i;

        best = _glfwChooseVideoMode(monitor, desired);
        _glfwPlatformGetVideoMode(monitor, &current);
        if (_glfwCompareVideoModes(&current, best) == 0)
            return;

        sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root);
        ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);
        oi = XRRGetOutputInfo(_glfw.x11.display, sr, monitor->x11.output);

        for (i = 0;  i < oi->nmode;  i++)
        {
            const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]);
            if (!modeIsGood(mi))
                continue;

            const GLFWvidmode mode = vidmodeFromModeInfo(mi, ci);
            if (_glfwCompareVideoModes(best, &mode) == 0)
            {
                native = mi->id;
                break;
            }
        }

        if (native)
        {
            if (monitor->x11.oldMode == None)
                monitor->x11.oldMode = ci->mode;

            XRRSetCrtcConfig(_glfw.x11.display,
                             sr, monitor->x11.crtc,
                             CurrentTime,
                             ci->x, ci->y,
                             native,
                             ci->rotation,
                             ci->outputs,
                             ci->noutput);
        }

        XRRFreeOutputInfo(oi);
        XRRFreeCrtcInfo(ci);
        XRRFreeScreenResources(sr);
    }
}
Esempio n. 15
0
File: events.c Progetto: Limsik/e17
static void
ExtInitRR(int available)
{
   Rotation            rot;

   if (!available)
      return;

   /* Listen for RandR events */
   XRRSelectInput(disp, WinGetXwin(VROOT), RRScreenChangeNotifyMask);
   XRRRotations(disp, Dpy.screen, &rot);
   Mode.screen.rotation = rot;

#if 0				/* Debug */
   if (EDebug(EDBUG_TYPE_VERBOSE))
     {
	XRRScreenResources *psr;
	XRRCrtcInfo        *pci;
	XRROutputInfo      *poi;
	int                 i;

	psr = XRRGetScreenResources(disp, WinGetXwin(VROOT));
	if (!psr)
	   return;

	Eprintf("CRTC  ID      X,Y         WxH     mode   rot   nout\n");
	for (i = 0; i < psr->ncrtc; i++)
	  {
	     pci = XRRGetCrtcInfo(disp, psr, psr->crtcs[i]);
	     if (!pci)
		break;
	     Eprintf("%3d  %#04lx  %4d,%4d   %4ux%4u  %#04lx %4d %5d\n",
		     i, psr->crtcs[i],
		     pci->x, pci->y, pci->width, pci->height,
		     pci->mode, pci->rotation, pci->noutput);
	     XRRFreeCrtcInfo(pci);
	  }

	Eprintf("OUTP  ID  Name            WxH     crtc  ncrtc nclon nmode\n");
	for (i = 0; i < psr->noutput; i++)
	  {
	     poi = XRRGetOutputInfo(disp, psr, psr->outputs[i]);
	     if (!poi)
		break;
	     Eprintf("%3d  %#04lx %-8s     %4lux%4lu  %#04lx %4d %5d %5d\n",
		     i, psr->outputs[i],
		     poi->name, poi->mm_width, poi->mm_height,
		     poi->crtc, poi->ncrtc, poi->nclone, poi->nmode);
	     XRRFreeOutputInfo(poi);
	  }

	XRRFreeScreenResources(psr);
     }
#endif
}
Esempio n. 16
0
XRRConfiguration::~XRRConfiguration()
{
	if (bValid && bIsFullscreen)
		ToggleDisplayMode(False);
	if (screenResources)
		XRRFreeScreenResources(screenResources);
	if (outputInfo)
		XRRFreeOutputInfo(outputInfo);
	if (crtcInfo)
		XRRFreeCrtcInfo(crtcInfo);
}
Esempio n. 17
0
static void _gfx_x11_enter_fullscreen(

		GFX_X11_Monitor*  monitor,
		Window            handle,
		RRMode            mode)
{
	Window root =
		XRootWindowOfScreen(monitor->screen);
	XRRScreenResources* res =
		XRRGetScreenResources(_gfx_x11.display, root);
	XRRCrtcInfo* crtc =
		XRRGetCrtcInfo(_gfx_x11.display, res, monitor->crtc);

	/* Above state */
	XEvent event;
	memset(&event, 0, sizeof(XEvent));

	event.type                 = ClientMessage;
	event.xclient.window       = handle;
	event.xclient.message_type = _gfx_x11.NET_WM_STATE;
	event.xclient.format       = 32;
	event.xclient.data.l[0]    = 1;
	event.xclient.data.l[1]    = _gfx_x11.NET_WM_STATE_ABOVE;

	/* Send event, set mode and move window */
	XSendEvent(
		_gfx_x11.display,
		root,
		False,
		SubstructureRedirectMask | SubstructureNotifyMask,
		&event);

	XRRSetCrtcConfig(
		_gfx_x11.display,
		res,
		monitor->crtc,
		crtc->timestamp,
		crtc->x,
		crtc->y,
		mode,
		crtc->rotation,
		crtc->outputs,
		crtc->noutput);

	XMoveWindow(
		_gfx_x11.display,
		handle,
		crtc->x,
		crtc->y);

	XRRFreeCrtcInfo(crtc);
	XRRFreeScreenResources(res);
}
Esempio n. 18
0
// Set the current video mode for the specified monitor
//
void _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired)
{
    if (_glfw.x11.randr.available)
    {
        int i;
        XRRScreenResources* sr;
        XRRCrtcInfo* ci;
        RRMode bestMode = 0;
        unsigned int leastSizeDiff = UINT_MAX, leastRateDiff = UINT_MAX;

        sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root);
        ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);

        for (i = 0;  i < sr->nmode;  i++)
        {
            XRRModeInfo* mi = sr->modes + i;

            if (mi->modeFlags & RR_Interlace)
                continue;

            const unsigned int sizeDiff = (mi->width - desired->width) *
                                          (mi->width - desired->width) +
                                          (mi->height - desired->height) *
                                          (mi->height - desired->height);

            const unsigned int rateDiff = abs(calculateRefreshRate(mi) - desired->refreshRate);

            if ((sizeDiff < leastSizeDiff) ||
                (sizeDiff == leastSizeDiff && rateDiff < leastRateDiff))
            {
                bestMode = mi->id;
                leastSizeDiff = sizeDiff;
                leastRateDiff = rateDiff;
            }
        }

        monitor->x11.oldMode = ci->mode;

        XRRSetCrtcConfig(_glfw.x11.display,
                         sr, monitor->x11.crtc,
                         CurrentTime,
                         ci->x, ci->y,
                         bestMode,
                         ci->rotation,
                         ci->outputs,
                         ci->noutput);

        XRRFreeCrtcInfo(ci);
        XRRFreeScreenResources(sr);
    }
}
Esempio n. 19
0
int _screen_info(const char *name, int num, Rect *r) {
	XRRScreenResources *res = XRRGetScreenResources(dpy, root);
	if (!res) return 0;
	int i, n = res->noutput;
	XRROutputInfo *info;
	XRRCrtcInfo *crtc;
	r->w = r->h = 0;
	for (i = 0; i < n; ++i) {
		/* skip if output lacks info or crtc */
		if (!(info=XRRGetOutputInfo(dpy, res, res->outputs[i]))) continue;
		if (!info->crtc || !(crtc=XRRGetCrtcInfo(dpy,res,info->crtc))) {
			XRRFreeOutputInfo(info);
			continue;
		}
		/* skip if name is provided and doesn't match */
		if (name && strncmp(name, info->name, strlen(name))) {
			XRRFreeCrtcInfo(crtc);
			XRRFreeOutputInfo(info);
			continue;
		}
		/* and skip if number is provided and doesn't match */
		if (num && num - 1 != i) {
			XRRFreeCrtcInfo(crtc);
			XRRFreeOutputInfo(info);
			continue;
		}
		/* match found, return size */
		r->x = crtc->x;
		r->y = crtc->y;
		r->w = crtc->width;
		r->h = crtc->height;
		XRRFreeCrtcInfo(crtc);
		XRRFreeOutputInfo(info);
		if (r->w && r->h) break;
	}
	XRRFreeScreenResources(res);
	return n;
}
Esempio n. 20
0
static int
SwitchRes(char inout, int x __UNUSED__, int y __UNUSED__, int w, int h,
	  int *dw, int *dh)
{
   XRRScreenResources *xsr;
   XRRCrtcInfo        *xci;
   RRCrtc              crtc;
   RRMode              ss_mode_new;
   int                 ok = 0;

   Dprintf("%s: inout=%d\n", __func__, inout);

   xsr = XRRGetScreenResourcesCurrent(disp, WinGetXwin(VROOT));
   if (!xsr)
      goto done;
   crtc = xsr->crtcs[0];	/* FIXME - Which crtc? */

   if (inout)
     {
	/* Save current setup */
	xci = XRRGetCrtcInfo(disp, xsr, crtc);
	if (!xci)
	   goto done;
	ss_mode = xci->mode;
	ss_rot = xci->rotation;
	XRRFreeCrtcInfo(xci);

	/* Select zoomed setup */
	ss_mode_new = FindMode(xsr, w, h, dw, dh);

	/* Set zoomed setup */
	SetPanning(xsr, crtc, 1);

	ok = SetMode(xsr, crtc, ss_mode_new, ss_rot);
     }
   else
     {
	/* Revert to original setup */
	ok = SetMode(xsr, crtc, ss_mode, ss_rot);

	SetPanning(xsr, crtc, 0);
     }

 done:
   if (xsr)
      XRRFreeScreenResources(xsr);

   Dprintf("%s: ok=%d\n", __func__, ok);
   return ok;
}
Esempio n. 21
0
JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_RandR13_dumpInfo0
  (JNIEnv *env, jclass clazz, jlong display, jint screen_idx, jlong screenResources)
{
    Display * dpy = (Display *) (intptr_t) display;
    Window root = RootWindow(dpy, (int)screen_idx);
    XRRScreenResources *resources = (XRRScreenResources *) (intptr_t) screenResources;
    int pos[] = { 0, 0 } ;
    int i, j, minWidth, minHeight, maxWidth, maxHeight;

    int vs_width = DisplayWidth(dpy, screen_idx);
    int vs_height = DisplayHeight(dpy, screen_idx);
    int vs_width_mm = DisplayWidthMM(dpy, screen_idx);
    int vs_height_mm = DisplayHeightMM(dpy, screen_idx);
    fprintf(stderr, "ScreenVirtualSize: %dx%d %dx%d mm\n", vs_width, vs_height, vs_width_mm, vs_height_mm);

    XRRGetScreenSizeRange (dpy, root, &minWidth, &minHeight, &maxWidth, &maxHeight);
    fprintf(stderr, "XRRGetScreenSizeRange: %dx%d .. %dx%d\n", minWidth, minHeight, maxWidth, maxHeight);

    if( NULL == resources ) {
        fprintf(stderr, "XRRScreenResources NULL\n");
        return;
    }
    fprintf(stderr, "XRRScreenResources %p: Crtc count %d\n", resources, resources->ncrtc);
    for(i=0; i<resources->ncrtc; i++) {
        RRCrtc crtc = resources->crtcs[i];
        XRRCrtcInfo *xrrCrtcInfo = XRRGetCrtcInfo (dpy, resources, crtc);
        fprintf(stderr, "Crtc[%d] %#lx: %d/%d %dx%d, rot 0x%X, mode.id %#lx\n", 
            i, crtc, xrrCrtcInfo->x, xrrCrtcInfo->y, xrrCrtcInfo->width, xrrCrtcInfo->height, xrrCrtcInfo->rotations, xrrCrtcInfo->mode);
        for(j=0; j<xrrCrtcInfo->noutput; j++) {
            fprintf(stderr, "    Crtc[%d].Output[%d].id %#lx\n", i, j, xrrCrtcInfo->outputs[j]);
            dumpOutput("        ", dpy, screen_idx, resources, j, xrrCrtcInfo->outputs[j]);
        }
        XRRFreeCrtcInfo(xrrCrtcInfo);
    }

    dumpOutputs("XRRScreenResources.outputs", dpy, (int)screen_idx, resources, resources->noutput, resources->outputs);

    fprintf(stderr, "XRRScreenResources %p: Mode count %d\n", resources, resources->nmode);
    for(i=0; i<resources->nmode; i++) {
        XRRModeInfo *mode = &resources->modes[i];

        unsigned int dots = mode->hTotal * mode->vTotal;
        float refresh = getVRefresh(mode);
        fprintf(stderr, "Mode[%d, id %#lx]: %ux%u@%f, name %s\n", i, mode->id, mode->width, mode->height, refresh, SAFE_STRING(mode->name));
    }
}
Esempio n. 22
0
std::vector<display> display::enumerate()
{
	std::vector<display> result;

	if (randr.is_available)
	{
		RROutput const primary = XRRGetOutputPrimary(g_display, g_root);

		XRRScreenResources* sr = XRRGetScreenResources(g_display, g_root);
		for (int i = 0; i < sr->ncrtc; ++i)
		{
			XRRCrtcInfo* info = XRRGetCrtcInfo(g_display, sr, sr->crtcs[i]);

			if (info->noutput)
			{
				RROutput* output = std::find_if(info->outputs, info->outputs + info->noutput,
					[primary](RROutput output) { return output == primary; });
				if (output == info->outputs + info->noutput)
				{
					output = info->outputs;
				}

				display disp = init(sr, *output);
				if (!disp.name.empty())
				{
					result.emplace_back(disp);
				}
			}
			XRRFreeCrtcInfo(info);
		}
		XRRFreeScreenResources(sr);

		std::vector<display>::iterator it = std::find_if(result.begin(), result.end(),
			[primary](display const& disp) { return disp.output == primary; });
		if (it != result.begin() && it != result.end())
		{
			std::iter_swap(it, result.begin());
		}
	}
	else
	{
		result.push_back(primary());
	}

	return result;
}
Esempio n. 23
0
static gboolean
force_timestamp_update (MateRRScreen *screen)
{
    MateRRCrtc *crtc;
    XRRCrtcInfo *current_info;
    Status status;
    gboolean timestamp_updated;

    timestamp_updated = FALSE;

    crtc = screen->info->crtcs[0];

    if (crtc == NULL)
	goto out;

    current_info = XRRGetCrtcInfo (screen->xdisplay,
				   screen->info->resources,
				   crtc->id);

    if (current_info == NULL)
	goto out;

    gdk_error_trap_push ();
    status = XRRSetCrtcConfig (screen->xdisplay,
			       screen->info->resources,
			       crtc->id,
			       current_info->timestamp,
			       current_info->x,
			       current_info->y,
			       current_info->mode,
			       current_info->rotation,
			       current_info->outputs,
			       current_info->noutput);

    XRRFreeCrtcInfo (current_info);

    gdk_flush ();
    if (gdk_error_trap_pop ())
	goto out;

    if (status == RRSetConfigSuccess)
	timestamp_updated = TRUE;
out:
    return timestamp_updated;
}
Esempio n. 24
0
display::mode display::current_mode() const
{
	if (randr.is_available)
	{
		XRRScreenResources* sr = XRRGetScreenResources(g_display, g_root);
		XRRCrtcInfo* ci =  XRRGetCrtcInfo(g_display, sr, crtc);

		XRRModeInfo const* mi = mode_info(sr, ci->mode);
		display::mode const result = make_mode(mi, ci);

		XRRFreeCrtcInfo(ci);
		XRRFreeScreenResources(sr);

		return result;
	}
	else
	{
		return display::mode(DisplayWidth(g_display, g_screen), DisplayHeight(g_display, g_screen),
			DefaultDepth(g_display, g_screen), 0);
	}
}
Esempio n. 25
0
static void destroyCrtcChain(crtc_t *root_crtc, RRCrtc customCrtc) {
    crtc_t * iter_crtc = root_crtc;
    while(NULL!=iter_crtc) {
        if( NULL != iter_crtc->crtc_info ) {
            if( iter_crtc->crtc_id != customCrtc || 0 == customCrtc ) {
                XRRFreeCrtcInfo(iter_crtc->crtc_info);
            }
            iter_crtc->crtc_info = NULL;
        }
        if( NULL != iter_crtc->panning_info ) {
            XRRFreePanning(iter_crtc->panning_info);
            iter_crtc->panning_info = NULL;
        }
        {
            crtc_t * last = iter_crtc;
            iter_crtc = iter_crtc->next;
            last->next = NULL;
            free(last);
        }
    }
}
Esempio n. 26
0
static void print_screen_info(void)
{
	int i;
	XRRScreenResources *sr;
	XRRCrtcInfo *ci = NULL;
	static int info_has_been_shown;

	if (info_has_been_shown)
		return;
	info_has_been_shown = 1;

	sr = XRRGetScreenResources(ui->dpy, DefaultRootWindow(ui->dpy));
	info("%d xrandr crt controller(s) found", sr->ncrtc);
	for (i = 0; i < sr->ncrtc; i++) {
		ci = XRRGetCrtcInfo(ui->dpy, sr, sr->crtcs[i]);
		if (!ci->noutput)
			continue;
		printf("    - monitor-%d: x0=%d; y0=%d; w=%d; h=%d\n",
		       i + 1, ci->x, ci->y, ci->width, ci->height);
		XRRFreeCrtcInfo(ci);
	}
	XRRFreeScreenResources(sr);
}
Esempio n. 27
0
static Rotation
xfce_randr_get_safe_rotations (XfceRandr *randr,
                               Display   *xdisplay,
                               guint      num_output)
{
    XRRCrtcInfo *crtc_info;
    Rotation     rot;
    gint         n;

    g_return_val_if_fail (num_output < randr->noutput, RR_Rotate_0);
    g_return_val_if_fail (randr->priv->output_info[num_output]->ncrtc > 0, RR_Rotate_0);

    rot = XFCE_RANDR_ROTATIONS_MASK | XFCE_RANDR_REFLECTIONS_MASK;
    for (n = 0; n < randr->priv->output_info[num_output]->ncrtc; ++n)
    {
        crtc_info = XRRGetCrtcInfo (xdisplay, randr->priv->resources,
                                    randr->priv->output_info[num_output]->crtcs[n]);
        rot &= crtc_info->rotations;
        XRRFreeCrtcInfo (crtc_info);
    }

    return rot;
}
Esempio n. 28
0
Rect2 *
apc_application_get_monitor_rects( Handle self, int * nrects)
{
#ifdef HAVE_X11_EXTENSIONS_XRANDR_H
	XRRScreenResources * sr;
	Rect2 * ret = nil;

	if ( !guts. randr_extension) {
		*nrects = 0;
		return nil;
	}

	XCHECKPOINT;
	sr = XRRGetScreenResources(DISP,guts.root);
	if ( sr ) {
		int i;
		ret = malloc(sizeof(Rect2) * sr->ncrtc);
		*nrects = sr->ncrtc;
		for ( i = 0; i < sr->ncrtc; i++) {
			XRRCrtcInfo * ci = XRRGetCrtcInfo (DISP, sr, sr->crtcs[i]);
			ret[i].x      = ci->x;
			ret[i].y      = guts.displaySize.y - ci->height - ci->y;
			ret[i].width  = ci->width;
			ret[i].height = ci->height;
			XRRFreeCrtcInfo(ci);
		}
		XRRFreeScreenResources(sr);
		XCHECKPOINT;
	} else {
		*nrects = 0;
	}
	return ret;
#else   
	*nrects = 0;
	return nil;
#endif
}
JNIEXPORT void JNICALL Java_org_lwjgl_system_linux_Xrandr_nXRRFreeCrtcInfo(JNIEnv *__env, jclass clazz, jlong crtcInfoAddress) {
	XRRCrtcInfo *crtcInfo = (XRRCrtcInfo *)(intptr_t)crtcInfoAddress;
	UNUSED_PARAMS(__env, clazz)
	XRRFreeCrtcInfo(crtcInfo);
}
Esempio n. 30
0
void XRRConfiguration::Update()
{
	if (SConfig::GetInstance().strFullscreenResolution == "Auto")
		return;

	if (!bValid)
		return;

	if (outputInfo)
	{
		XRRFreeOutputInfo(outputInfo);
		outputInfo = nullptr;
	}
	if (crtcInfo)
	{
		XRRFreeCrtcInfo(crtcInfo);
		crtcInfo = nullptr;
	}
	fullMode = 0;

	// Get the resolution setings for fullscreen mode
	unsigned int fullWidth, fullHeight;
	char *output_name = nullptr;
	char auxFlag = '\0';
	if (SConfig::GetInstance().strFullscreenResolution.find(':') ==
			std::string::npos)
	{
		fullWidth = fb_width;
		fullHeight = fb_height;
	}
	else
	{
		sscanf(SConfig::GetInstance().strFullscreenResolution.c_str(),
				"%m[^:]: %ux%u%c", &output_name, &fullWidth, &fullHeight, &auxFlag);
	}
	bool want_interlaced = ('i' == auxFlag);

	for (int i = 0; i < screenResources->noutput; i++)
	{
		XRROutputInfo *output_info = XRRGetOutputInfo(dpy, screenResources, screenResources->outputs[i]);
		if (output_info && output_info->crtc && output_info->connection == RR_Connected)
		{
			XRRCrtcInfo *crtc_info = XRRGetCrtcInfo(dpy, screenResources, output_info->crtc);
			if (crtc_info)
			{
				if (!output_name || !strcmp(output_name, output_info->name))
				{
					// Use the first output for the default setting.
					if (!output_name)
					{
						output_name = strdup(output_info->name);
						SConfig::GetInstance().strFullscreenResolution =
							StringFromFormat("%s: %ux%u", output_info->name, fullWidth, fullHeight);
					}
					outputInfo = output_info;
					crtcInfo = crtc_info;
					for (int j = 0; j < output_info->nmode && fullMode == 0; j++)
					{
						for (int k = 0; k < screenResources->nmode && fullMode == 0; k++)
						{
							if (output_info->modes[j] == screenResources->modes[k].id)
							{
								if (fullWidth == screenResources->modes[k].width &&
										fullHeight == screenResources->modes[k].height &&
										want_interlaced == !!(screenResources->modes[k].modeFlags & RR_Interlace))
								{
									fullMode = screenResources->modes[k].id;
									if (crtcInfo->x + (int)screenResources->modes[k].width > fs_fb_width)
										fs_fb_width = crtcInfo->x + screenResources->modes[k].width;
									if (crtcInfo->y + (int)screenResources->modes[k].height > fs_fb_height)
										fs_fb_height = crtcInfo->y + screenResources->modes[k].height;
								}
							}
						}
					}
				}
				else
				{
					if (crtc_info->x + (int)crtc_info->width > fs_fb_width)
						fs_fb_width = crtc_info->x + crtc_info->width;
					if (crtc_info->y + (int)crtc_info->height > fs_fb_height)
						fs_fb_height = crtc_info->y + crtc_info->height;
				}
			}
			if (crtc_info && crtcInfo != crtc_info)
				XRRFreeCrtcInfo(crtc_info);
		}
		if (output_info && outputInfo != output_info)
			XRRFreeOutputInfo(output_info);
	}
	fs_fb_width_mm = fs_fb_width * DisplayHeightMM(dpy, screen) / DisplayHeight(dpy, screen);
	fs_fb_height_mm = fs_fb_height * DisplayHeightMM(dpy, screen) / DisplayHeight(dpy, screen);

	if (output_name)
		free(output_name);

	if (outputInfo && crtcInfo && fullMode)
	{
		INFO_LOG(VIDEO, "Fullscreen Resolution %dx%d", fullWidth, fullHeight);
	}
	else
	{
		ERROR_LOG(VIDEO, "Failed to obtain fullscreen size.\n"
				"Using current desktop resolution for fullscreen.");
	}
}