Exemplo n.º 1
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;
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
0
/* Caller must free return value */
static XRROutputInfo*
find_output_xrandr(Display *dpy, const char *output_name)
{
    XRRScreenResources *res;
    XRROutputInfo *output_info = NULL;
    int i;
    int found = 0;

    res = XRRGetScreenResources(dpy, DefaultRootWindow(dpy));

    for (i = 0; i < res->noutput && !found; i++)
    {
        output_info = XRRGetOutputInfo(dpy, res, res->outputs[i]);

        if (output_info->crtc && output_info->connection == RR_Connected &&
            strcmp(output_info->name, output_name) == 0)
        {
            found = 1;
            break;
        }

        XRRFreeOutputInfo(output_info);
    }

    XRRFreeScreenResources(res);

    if (!found)
        output_info = NULL;

    return output_info;
}
Exemplo n.º 4
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);
}
Exemplo 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;
}
Exemplo n.º 6
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;
}
Exemplo n.º 7
0
void
xfce_randr_reload (XfceRandr *randr)
{
    Display   *xdisplay;
    GdkWindow *root_window;

    xfce_randr_cleanup (randr);

    /* get the x display */
    xdisplay = gdk_x11_display_get_xdisplay (randr->priv->display);

    /* get the root window */
    root_window = gdk_get_default_root_window ();

    /* get the screen resource */
#ifdef HAS_RANDR_ONE_POINT_THREE
    /* xfce_randr_reload() is only called after a xrandr notification, which
       means that X is aware of the new hardware already. So, if possible,
       do not reprobe the hardware again. */
    if (randr->priv->has_1_3)
        randr->priv->resources = XRRGetScreenResourcesCurrent (xdisplay, GDK_WINDOW_XID (root_window));
    else
#endif
    randr->priv->resources = XRRGetScreenResources (xdisplay, GDK_WINDOW_XID (root_window));

    /* repopulate */
    xfce_randr_populate (randr, xdisplay, root_window);
}
Exemplo n.º 8
0
int get_monitor_dims(int *ret_left_x, int *ret_right_x,
	int *ret_top_y, int *ret_bottom_y, int i) {

	Display *display;
	if (!(display = XOpenDisplay(0))) { return ERR_COULDNT_OPEN_X_DISPLAY; }

	XRRScreenResources *screen_res =
		XRRGetScreenResources(display, DefaultRootWindow(display));

	*ret_left_x = INT_MAX;
	*ret_right_x = INT_MIN;
	*ret_top_y = INT_MAX;
	*ret_bottom_y = INT_MIN;
	int nmonitors = 0;
	XRRGetMonitors(display, DefaultRootWindow(display), 1, &nmonitors);

	/* If the user requests a screen outside of the number of monitors, exit */
	if (i >= nmonitors) {
		return ERR_MONITOR_DNE;
	}

	XRRCrtcInfo *screen_info =
		XRRGetCrtcInfo(display, screen_res, screen_res->crtcs[i]);

	*ret_left_x = screen_info->x;
	*ret_right_x = screen_info->x + screen_info->width;
	*ret_top_y = screen_info->y;
	*ret_bottom_y = screen_info->y + screen_info->height;

	return 0;
}
Exemplo n.º 9
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;
    }
}
Exemplo 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;
    }
}
Exemplo n.º 11
0
void eventNotifier::do_RRNotify (XEvent *eventp)
{
    XRRNotifyEvent *e = (XRRNotifyEvent *) eventp;
    XRRScreenResources *screen_resources;

    XRRUpdateConfiguration (eventp);
    screen_resources = XRRGetScreenResources (m_pDpy, m_screen);
    prologue (eventp, "RRNotify");
    switch (e->subtype) {
      case RRNotify_OutputChange:
        qDebug() << "OutputChange";
//          do_RRNotify_OutputChange (eventp, screen_resources); break;
      break;

      case RRNotify_CrtcChange:
        qDebug() << "CrtcChange";
//         do_RRNotify_CrtcChange (eventp, screen_resources); break;
      break;

      case RRNotify_OutputProperty:
        qDebug() << "OutputProperty";
//          do_RRNotify_OutputProperty (eventp, screen_resources); break;
      break;

      default:
          printf ("    subtype %d\n", e->subtype);
    }
    XRRFreeScreenResources (screen_resources);
}
Exemplo 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;
        XRROutputInfo* oi;

        sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root);
        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);

            for (j = 0;  j < *found;  j++)
            {
                if (result[j].width == mode.width &&
                    result[j].height == mode.height &&
                    result[j].refreshRate == mode.refreshRate)
                {
                    break;
                }
            }

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

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

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

    return result;
}
Exemplo n.º 13
0
int get_monitor_dims_of_focused_screen(int use_anchors, int *ret_left_x, int *ret_right_x,
	int *ret_top_y, int *ret_bottom_y) {

	Display *dpy;
	if (!(dpy = XOpenDisplay(0))) { return ERR_COULDNT_OPEN_X_DISPLAY; }

	/* Get currently focused window */
	Window win = -1;
	int focus_status;
	XGetInputFocus(dpy, &win, &focus_status);
	if (win == PointerRoot || win == None) { return ERR_WIN_NOT_FOUND; }

	XRRScreenResources *screen_res =
		XRRGetScreenResources(dpy, DefaultRootWindow(dpy));
	XWindowAttributes win_attr;
	XGetWindowAttributes(dpy, win, &win_attr);

	int det_x = 0;
	int det_y = 0;
	int nmonitors = 0;
	XRRGetMonitors(dpy, win, 1, &nmonitors);

	for (int i = 0; i < nmonitors; i++) {
		XRRCrtcInfo *screen_info =
			XRRGetCrtcInfo(dpy, screen_res, screen_res->crtcs[i]);

		/* option flag for using the "anchor" (top left corner)  of a window
		 * to determine what screen it belongs to */
		if (use_anchors == 1) {
			det_x = win_attr.x;
			det_y = win_attr.y;
		/* Use the center of the window to determine what screen it's on */
		} else {
			det_x = win_attr.x + ((win_attr.width)/2);
			det_y = win_attr.y + ((win_attr.height)/2);
		}

		/* If the window is on the ith screen in the x */
		if (det_x >= screen_info->x &&
			det_x < (screen_info->x + screen_info->width)) {
			/* If the window is on the ith screen in the y */
			if (det_y >= screen_info->y &&
				det_y < (screen_info->y + screen_info->height)) {

				*ret_left_x = screen_info->x;
				*ret_right_x = screen_info->x + screen_info->width;
				*ret_top_y = screen_info->y;
				*ret_bottom_y = screen_info->y + screen_info->height;
				return 0;
			}
		}
	}

	/* If the function has not returned yet, then it could not find a screen
	 * on which 'win' resides.
	 */
	return ERR_SCREEN_OF_WIN_NOT_FOUND;
}
Exemplo n.º 14
0
void
UpdateHardwareGamma(void)
{
	float gamma = (vid_gamma->value);
	int i;

	Display* dpy = NULL;
	SDL_SysWMinfo info;

#if SDL_VERSION_ATLEAST(2, 0, 0)
	SDL_VERSION(&info.version);
	if(!SDL_GetWindowWMInfo(window, &info))
#else
	if(SDL_GetWMInfo(&info) != 1)
#endif
	{
		VID_Printf(PRINT_ALL, "Couldn't get Window info from SDL\n");
		return;
	}

	dpy = info.info.x11.display;

	XRRScreenResources* res = XRRGetScreenResources(dpy, info.info.x11.window);
	if(res == NULL)
	{
		VID_Printf(PRINT_ALL, "Unable to get xrandr screen resources.\n");
		return;
	}

	for(i=0; i < res->ncrtc; ++i)
	{
		int len = XRRGetCrtcGammaSize(dpy, res->crtcs[i]);
		size_t rampSize = len*sizeof(Uint16);
		Uint16* ramp = malloc(rampSize); // TODO: check for NULL
		if(ramp == NULL)
		{
			VID_Printf(PRINT_ALL, "Couldn't allocate &zd byte of memory for gamma ramp - OOM?!\n", rampSize);
			return;
		}

		CalculateGammaRamp(gamma, ramp, len);

		XRRCrtcGamma* gamma = XRRAllocGamma(len);

		memcpy(gamma->red, ramp, rampSize);
		memcpy(gamma->green, ramp, rampSize);
		memcpy(gamma->blue, ramp, rampSize);

		free(ramp);

		XRRSetCrtcGamma(dpy, res->crtcs[i], gamma);

		XRRFreeGamma(gamma);
	}

	XRRFreeScreenResources(res);
}
Exemplo n.º 15
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;
}
Exemplo n.º 16
0
static void
randrd(void)
{
	XRRScreenResources		*resources;
	XRROutputInfo			*info;
	XRROutputChangeNotifyEvent	*rrocevt;
	XRRNotifyEvent			*rrevt;
	char				*new_edidhash;
	Window				 root;
	XEvent	 			 evt;

	exec_script(script, "init", "", current_edidhash);

	XRRSelectInput(dpy, DefaultRootWindow(dpy), RROutputChangeNotifyMask);
	while (!quit) {
		root = RootWindow(dpy, DefaultScreen(dpy));
		resources = XRRGetScreenResources(dpy, root);

		while (XPending(dpy)) {
			XNextEvent(dpy, &evt);

			if (evt.type != rr_event_base + RRNotify)
				continue;

			rrevt = (XRRNotifyEvent *)&evt;
			if (rrevt->subtype != RRNotify_OutputChange)
				continue;

			new_edidhash = getedidhash1(resources);
			if (new_edidhash == NULL)
				continue;

			if (!strcmp(current_edidhash, new_edidhash)) {
				free(new_edidhash);
				continue;
			}

			free(current_edidhash);
			current_edidhash = new_edidhash;

			rrocevt = (XRROutputChangeNotifyEvent *)&evt;
			info = XRRGetOutputInfo(rrocevt->display, resources,
					rrocevt->output);

			syslog(LOG_INFO, "%s %s", info->name,
					connstates[info->connection]);
			exec_script(script, connstates[info->connection],
					info->name, new_edidhash);

			XRRFreeOutputInfo(info);
		}

		XRRFreeScreenResources(resources);
		sleep(interval);
	}
}
Exemplo n.º 17
0
static void RestoreGamma()
{
	int i=0;
	SDL_SysWMinfo info;
	Display* dpy = NULL;

	if(gammaRamps == NULL)
			return;

#if SDL_VERSION_ATLEAST(2, 0, 0)
	SDL_VERSION(&info.version);
	if(!SDL_GetWindowWMInfo(window, &info))
#else
	if(SDL_GetWMInfo(&info) != 1)
#endif
	{
		VID_Printf(PRINT_ALL, "Couldn't get Window info from SDL\n");
		return;
	}

	dpy = info.info.x11.display;

	XRRScreenResources* res = XRRGetScreenResources(dpy, info.info.x11.window);
	if(res == NULL)
	{
		VID_Printf(PRINT_ALL, "Unable to get xrandr screen resources.\n");
		return;
	}

	for(i=0; i < noGammaRamps; ++i)
	{
		// in case a display was unplugged or something, noGammaRamps may be > res->ncrtc
		if(i < res->ncrtc)
		{
			int len = XRRGetCrtcGammaSize(dpy, res->crtcs[i]);
			if(len != gammaRamps[i]->size) {
				VID_Printf(PRINT_ALL, "WTF, gamma ramp size for display %d has changed from %d to %d!\n",
							   i, gammaRamps[i]->size, len);

				continue;
			}

			XRRSetCrtcGamma(dpy, res->crtcs[i], gammaRamps[i]);
		}

		// the ramp needs to be free()d either way
		XRRFreeGamma(gammaRamps[i]);
		gammaRamps[i] = NULL;

	}
	XRRFreeScreenResources(res);
	free(gammaRamps);
	gammaRamps = NULL;

	VID_Printf(PRINT_ALL, "Restored original Gamma\n");
}
Exemplo n.º 18
0
static inline XRRScreenResources *_XRRGetScreenResourcesCurrent(Display *dpy, Window window)
{
	XRRScreenResources *res;

	res = XRRGetScreenResourcesCurrent(dpy, window);
	if (res == NULL)
		res = XRRGetScreenResources(dpy, window);

	return res;
}
Exemplo n.º 19
0
Arquivo: events.c Projeto: 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
}
Exemplo n.º 20
0
static void *settings_thread_proc(void *arg) {
	Display *settings_disp = XOpenDisplay(XDisplayName(NULL));;
	if (settings_disp != NULL) {
		logger(LOG_LEVEL_DEBUG,	"%s [%u]: %s\n",
				__FUNCTION__, __LINE__, "XOpenDisplay success.");

		pthread_cleanup_push(settings_cleanup_proc, settings_disp);

		int event_base = 0;
		int error_base = 0;
		if (XRRQueryExtension(settings_disp, &event_base, &error_base)) {
			Window root = XDefaultRootWindow(settings_disp);
			unsigned long event_mask = RRScreenChangeNotifyMask;
			XRRSelectInput(settings_disp, root, event_mask);

			XEvent ev;

			while(settings_disp != NULL) {
				XNextEvent(settings_disp, &ev);

				if (ev.type == event_base + RRScreenChangeNotifyMask) {
					logger(LOG_LEVEL_DEBUG,	"%s [%u]: Received XRRScreenChangeNotifyEvent.\n",
							__FUNCTION__, __LINE__);

					pthread_mutex_lock(&xrandr_mutex);
					if (xrandr_resources != NULL) {
						XRRFreeScreenResources(xrandr_resources);
					}

					xrandr_resources = XRRGetScreenResources(settings_disp, root);
					if (xrandr_resources == NULL) {
						logger(LOG_LEVEL_WARN,	"%s [%u]: XRandR could not get screen resources!\n",
								__FUNCTION__, __LINE__);
					}
					pthread_mutex_unlock(&xrandr_mutex);
				}
				else {
					logger(LOG_LEVEL_WARN,	"%s [%u]: XRandR is not currently available!\n",
							__FUNCTION__, __LINE__);
				}
			}
		}

		// Execute the thread cleanup handler.
		pthread_cleanup_pop(1);

	}
	else {
		logger(LOG_LEVEL_ERROR,	"%s [%u]: XOpenDisplay failure!\n",
				__FUNCTION__, __LINE__);
	}

	return NULL;
}
Exemplo n.º 21
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);
}
Exemplo n.º 22
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);
}
Exemplo n.º 23
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);
    }
}
Exemplo n.º 24
0
XfceRandr *
xfce_randr_new (GdkDisplay  *display,
                GError     **error)
{
    XfceRandr *randr;
    Display   *xdisplay;
    GdkWindow *root_window;
    gint       major, minor;

    g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
    g_return_val_if_fail (error == NULL || *error == NULL, NULL);

    /* get the x display */
    xdisplay = gdk_x11_display_get_xdisplay (display);

    /* check if the randr extension is available */
    if (XRRQueryVersion (xdisplay, &major, &minor) == FALSE)
    {
        g_set_error (error, 0, 0, _("Unable to query the version of the RandR extension being used"));
        return NULL;
    }

    /* we need atleast randr 1.2, 2.0 will probably break the api */
    if (major < 1 || (major == 1 && minor < 2))
    {
        /* 1.2 is required */
        g_set_error (error, 0, 0, _("This system is using RandR %d.%d. For the display settings to work "
                                    "version 1.2 is required at least"), major, minor);
        return NULL;
    }

    /* allocate the structure */
    randr = g_slice_new0 (XfceRandr);
    randr->priv = g_slice_new0 (XfceRandrPrivate);

    randr->priv->has_1_3 = (major > 1 || (major == 1 && minor >= 3));

    /* set display */
    randr->priv->display = display;

    /* get the root window */
    root_window = gdk_get_default_root_window ();

    /* get the screen resource */
    randr->priv->resources = XRRGetScreenResources (xdisplay, GDK_WINDOW_XID (root_window));

    xfce_randr_populate (randr, xdisplay, root_window);

    return randr;
}
Exemplo n.º 25
0
VAStatus psb_xrandr_init(VADriverContextP ctx)
{
    int major, minor;
    int screen;

    psb_xrandr_info = (psb_xrandr_info_p)calloc(1, sizeof(psb_xrandr_info_s));

    if (!psb_xrandr_info) {
        drv_debug_msg(VIDEO_DEBUG_ERROR, "output of memory\n");
        return VA_STATUS_ERROR_UNKNOWN;
    }
    memset(psb_xrandr_info, 0, sizeof(psb_xrandr_info_s));
    psb_xrandr_info->mipi0_rotation = RR_Rotate_0;
    psb_xrandr_info->mipi1_rotation = RR_Rotate_0;
    psb_xrandr_info->hdmi_rotation = RR_Rotate_0;

    psb_xrandr_info->hdmi_extvideo_prop = (psb_extvideo_prop_p)calloc(1, sizeof(psb_extvideo_prop_s));
    if (!psb_xrandr_info->hdmi_extvideo_prop) {
        drv_debug_msg(VIDEO_DEBUG_ERROR, "output of memory\n");
        return VA_STATUS_ERROR_ALLOCATION_FAILED;
    }
    memset(psb_xrandr_info->hdmi_extvideo_prop, 0, sizeof(psb_extvideo_prop_s));

    psb_xrandr_info->dpy = (Display *)ctx->native_dpy;
    screen = DefaultScreen(psb_xrandr_info->dpy);

    if (screen >= ScreenCount(psb_xrandr_info->dpy)) {
        drv_debug_msg(VIDEO_DEBUG_ERROR, "Xrandr: Invalid screen number %d (display has %d)\n",
                           screen, ScreenCount(psb_xrandr_info->dpy));
        return VA_STATUS_ERROR_UNKNOWN;
    }

    psb_xrandr_info->root = RootWindow(psb_xrandr_info->dpy, screen);

    if (!XRRQueryVersion(psb_xrandr_info->dpy, &major, &minor)) {
        drv_debug_msg(VIDEO_DEBUG_ERROR, "Xrandr: RandR extension missing\n");
        return VA_STATUS_ERROR_UNKNOWN;
    }

    psb_xrandr_info->res = XRRGetScreenResources(psb_xrandr_info->dpy, psb_xrandr_info->root);
    if (!psb_xrandr_info->res)
        drv_debug_msg(VIDEO_DEBUG_ERROR, "Xrandr: failed to get screen resources\n");

    pthread_mutex_init(&psb_xrandr_info->psb_extvideo_mutex, NULL);

    psb_xrandr_refresh(ctx);

    return VA_STATUS_SUCCESS;
}
Exemplo n.º 26
0
static char *
getedidhash(void)
{
	XRRScreenResources		*resources;
	char				*edidhash;
	Window				 root;

	root = RootWindow(dpy, DefaultScreen(dpy));
	resources = XRRGetScreenResources(dpy, root);

	edidhash = getedidhash1(resources);

	XRRFreeScreenResources(resources);
	return (edidhash);
}
Exemplo n.º 27
0
void
get_xrandr_config(Display *dpy, Window root, char *name,
    int *x, int *y, int *width, int *height)
{
	XRRScreenResources *res;
	XRROutputInfo *output_info;
	XRRCrtcInfo *crtc_info;
	int o, found = 0;

	res = XRRGetScreenResources(dpy, root);

	for (o = 0; o < res->noutput; o++) {
		output_info = XRRGetOutputInfo (dpy, res, res->outputs[o]);
		if (!output_info) {
			fprintf(stderr,
			    "could not get output 0x%lx information\n",
			    res->outputs[o]);
			exit(2);
		}
		if (output_info->crtc != 0) {
			crtc_info = XRRGetCrtcInfo(dpy, res,
			    output_info->crtc);
			if (!crtc_info) {
				fprintf(stderr,
				    "%s: could not get crtc 0x%lx "
				    "information\n", __progname,
				    output_info->crtc);
				exit(2);
			}
			printf("%s: %dx%d+%d+%d\n",
			    output_info->name,
			    crtc_info->width, crtc_info->height,
			    crtc_info->x, crtc_info->y);
			if (!strcmp(output_info->name, name)) {
				*x = crtc_info->x;
				*y = crtc_info->y;
				*width = crtc_info->width;
				*height = crtc_info->height;
				found = 1;
			}
		}
	}
	if (!found) {
		fprintf(stderr, "%s: output %s not found\n", __progname, name);
		exit(2);
	}
}
Exemplo n.º 28
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;
}
/* for HDMI rotation */
void e_illume_util_hdmi_rotation (Ecore_X_Window root, int angle)
{
   Ecore_X_Display *dpy;
   RROutput output;
   char hdmi_commands[HDMI_BUF_SIZE];
   char buf[5];
   int buf_len;
   int i;
   char* x_control[] = {"illume2", "rotation", buf, NULL };

   if (access(HDMI_DEV_NODE, F_OK) == 0)
     {
        if (!_atom_hdmi)
           _atom_hdmi = ecore_x_atom_get ("X_RR_PROPERTY_REMOTE_CONTROLLER");

        if(!_atom_hdmi)
          {
             fprintf (stderr, "[ILLUME2] Critical Error!!! Cannot create X_RR_PROPERTY_REMOTE_CONTROLLER Atom...\n");
             return;
          }

        dpy = ecore_x_display_get();

        memset (hdmi_commands, 0, sizeof(hdmi_commands));
        memset (buf, 0, sizeof(buf));

        output = 0;
        XRRScreenResources* res = XRRGetScreenResources (dpy, root);
        if (res && (res->noutput != 0))
          {
             for (i=0; i<res->noutput; i++)
               {
                  output = res->outputs[i];
               }

             snprintf (buf, sizeof(buf)-1, "%d", angle);
             buf_len = _e_illume_util_marshalize_string (hdmi_commands, 3, x_control);

             XRRChangeOutputProperty(dpy, output, _atom_hdmi, XA_CARDINAL, 8, PropModeReplace, (unsigned char *)hdmi_commands, buf_len);
          }
        else
          {
             printf("[ILLUME2]Error.. Cannot get screen resource.\n");
          }
     }
}
Exemplo n.º 30
0
/** Returns an int of 0 if it succeeds in finding the screen number of a
 * given Window or an int representing the error it ran into.
 * win the Window we are trying to find the screen of.
 * *dpy pointer to the Display we will be searching on.
 * *return_screen_num pointer to an int where the function will fill in the
 *     screen number that 'win' belongs to, if it can be found.
 * This function will return 0 if it was able to find the screen 'win' belongs
 * to. If it cannot, then it will return the correct
 * error code for window-not-found.
 */
int get_screen_number_of_win(Window win, Display *dpy, int use_anchors, \
	int *return_screen_num) {

	XRRScreenResources *screen_res =
		XRRGetScreenResources(dpy, DefaultRootWindow(dpy));
	XWindowAttributes win_attr;
	XGetWindowAttributes(dpy, win, &win_attr);

	int det_x = 0;
	int det_y = 0;
	int nmonitors = 0;
	XRRGetMonitors(dpy, win, 1, &nmonitors);

	for (int i = 0; i < nmonitors; i++) {
		XRRCrtcInfo *screen_info =
			XRRGetCrtcInfo(dpy, screen_res, screen_res->crtcs[i]);

		/* option flag for using the "anchor" (top left corner)  of a window
		 * to determine what screen it belongs to */
		if (use_anchors == 1) {
			det_x = win_attr.x;
			det_y = win_attr.y;
		/* Use the center of the window to determine what screen it's on */
		} else {
			det_x = win_attr.x + ((win_attr.width)/2);
			det_y = win_attr.y + ((win_attr.height)/2);
		}

		/* If the window is on the ith screen in the x */
		if (det_x >= screen_info->x &&
			det_x < (screen_info->x + screen_info->width)) {
			/* If the window is on the ith screen in the y */
			if (det_y >= screen_info->y &&
				det_y < (screen_info->y + screen_info->height)) {
				*return_screen_num = i;
				return 0;
			}
		}
	}

	/* If the function has not returned yet, then it could not find a screen
	 * on which 'win' resides.
	 */
	return ERR_SCREEN_OF_WIN_NOT_FOUND;
}