Пример #1
0
int set_x11videomode(const x11videomode_t * xvidmode, x11screen_t * x11screen)
{
    int err ;
    XRRScreenConfiguration * screen_config = 0 ;

    if (!isextxrandr_x11display(display_x11screen(x11screen))) {
        err = ENOSYS ;
        goto ONERR;
    }

    Display * sys_display = display_x11screen(x11screen)->sys_display ;
    screen_config = XRRGetScreenInfo(sys_display, RootWindow(sys_display, number_x11screen(x11screen))) ;
    if (!screen_config) {
        err = ENOSYS ;
        goto ONERR;
    }

    Rotation current_rotation ;
    uint16_t current_size = XRRConfigCurrentConfiguration(screen_config, &current_rotation) ;

    int            sizes_count ;
    XRRScreenSize  * sizes = XRRConfigSizes(screen_config, &sizes_count) ;
    if (  !sizes
            || (current_size >= sizes_count)) {
        err = EOVERFLOW ;
        goto ONERR;
    }

    if (  xvidmode->modeid > sizes_count
            || xvidmode->width_in_pixel  != (uint32_t) sizes[xvidmode->modeid].width
            || xvidmode->height_in_pixel != (uint32_t) sizes[xvidmode->modeid].height) {
        err = EINVAL ;
        goto ONERR;
    }

    if (XRRSetScreenConfig( sys_display, screen_config,
                            RootWindow(sys_display, number_x11screen(x11screen)),
                            xvidmode->modeid, current_rotation, CurrentTime)) {
        err = EOPNOTSUPP ;
        goto ONERR;
    }

    XRRFreeScreenConfigInfo(screen_config) ;

    return 0 ;
ONERR:
    if (screen_config) {
        XRRFreeScreenConfigInfo(screen_config) ;
    }
    TRACEEXIT_ERRLOG(err);
    return err ;
}
Пример #2
0
void RandRScreen::loadSettings()
{
    if(d->config)
        XRRFreeScreenConfigInfo(d->config);

    d->config = XRRGetScreenInfo(qt_xdisplay(), RootWindow(qt_xdisplay(), m_screen));
    Q_ASSERT(d->config);

    Rotation rotation;
    m_currentSize = m_proposedSize = XRRConfigCurrentConfiguration(d->config, &rotation);
    m_currentRotation = m_proposedRotation = rotation;

    m_pixelSizes.clear();
    m_mmSizes.clear();
    int numSizes;
    XRRScreenSize *sizes = XRRSizes(qt_xdisplay(), m_screen, &numSizes);
    for(int i = 0; i < numSizes; i++)
    {
        m_pixelSizes.append(QSize(sizes[i].width, sizes[i].height));
        m_mmSizes.append(QSize(sizes[i].mwidth, sizes[i].mheight));
    }

    m_rotations = XRRRotations(qt_xdisplay(), m_screen, &rotation);

    m_currentRefreshRate = m_proposedRefreshRate = refreshRateHzToIndex(m_currentSize, XRRConfigCurrentRate(d->config));
}
Пример #3
0
/*
 * @brief sets the current primary output's refresh rate
 * @param root window which's primary output will be queried
 * @param size_index referencing the size to be set
 * @param rate the refresh rate to be set
 * @return EINA_TRUE on success else EINA_FALSE
 */
EAPI Eina_Bool
ecore_x_randr_screen_primary_output_refresh_rate_set(
   Ecore_X_Window root,
   int            size_index,
   Ecore_X_Randr_Refresh_Rate
   rate)
{
#ifdef ECORE_XRANDR
   RANDR_CHECK_1_1_RET(EINA_FALSE);
   Eina_Bool ret = EINA_FALSE;
   XRRScreenConfiguration *sc = NULL;

   if (!(sc = XRRGetScreenInfo(_ecore_x_disp, root)))
      return ret;

   if (!XRRSetScreenConfigAndRate(_ecore_x_disp, sc,
                                  root, size_index,
                                  RR_Rotate_0, rate, CurrentTime))
      ret = EINA_TRUE;

   XRRFreeScreenConfigInfo(sc);
   return ret;
#else /* ifdef ECORE_XRANDR */
   return EINA_FALSE;
#endif /* ifdef ECORE_XRANDR */
} /* ecore_x_randr_screen_primary_output_refresh_rate_set */
Пример #4
0
/*
 * @brief sets a given screen's primary output's orientation
 * @param root window which's screen's primary output will be queried
 * @param orientation orientation which should be set for the root window's screen primary output
 * @return EINA_TRUE if the primary output's orientation could be successfully altered
 */
EAPI Eina_Bool
ecore_x_randr_screen_primary_output_orientation_set(
   Ecore_X_Window root,
   Ecore_X_Randr_Orientation
   orientation)
{
#ifdef ECORE_XRANDR
   XRRScreenConfiguration *xrr_screen_cfg = NULL;
   int sizeid;
   Rotation crot;
   Eina_Bool ret = EINA_FALSE;
   if (!(xrr_screen_cfg = XRRGetScreenInfo(_ecore_x_disp, root)))
      return EINA_FALSE;

   sizeid = XRRConfigCurrentConfiguration(xrr_screen_cfg, &crot);
   if (!XRRSetScreenConfig(_ecore_x_disp, xrr_screen_cfg, root, sizeid,
                           orientation, CurrentTime))
      ret = EINA_TRUE;

   if (xrr_screen_cfg)
      XRRFreeScreenConfigInfo(xrr_screen_cfg);

   return ret;
#else /* ifdef ECORE_XRANDR */
   return EINA_FALSE;
#endif /* ifdef ECORE_XRANDR */
} /* ecore_x_randr_screen_primary_output_orientation_set */
Пример #5
0
/*!
 * \brief Ends RandR support
 * \warning !!! DO NOT CALL THIS METHOD !!!
 *
 * This method is designed to be called from iContext::destroy() or
 * from the destructor of this class. Calling this method will end
 * the RandR support.
 */
void iRandR::endRandR() {
   if ( !vIsRandRSupported_B )
      return;

   XCloseDisplay( vDisplay_X11 );

   if ( GlobConf.win.restoreOldScreenRes && vWasScreenChanged_B )
      restore( vDefaultConfig_RandR );


   for ( auto &elem : vDefaultConfig_RandR.gamma )
      XRRFreeGamma( elem );

   vDefaultConfig_RandR.gamma.clear();
   vDefaultConfig_RandR.CRTCInfo.clear();


   for ( auto &elem : vLatestConfig_RandR.gamma )
      XRRFreeGamma( elem );


   vLatestConfig_RandR.gamma.clear();


   XRRFreeScreenConfigInfo( vConfig_XRR );
   XRRFreeScreenResources( vResources_XRR );

   vCRTC_V_RandR.clear();
   vOutput_V_RandR.clear();
   vMode_V_RandR.clear();

   vIsRandRSupported_B = false;
}
CD_APPLET_ON_CLICK_END


//\___________ Define here the entries you want to add to the menu when the user right-clicks on your icon or on its subdock or your desklet. The icon and the container that were clicked are available through the macros CD_APPLET_CLICKED_ICON and CD_APPLET_CLICKED_CONTAINER. CD_APPLET_CLICKED_ICON may be NULL if the user clicked in the container but out of icons. The menu where you can add your entries is available throught the macro CD_APPLET_MY_MENU; you can add sub-menu to it if you want.
#ifdef HAVE_X11
#ifdef HAVE_XRANDR
static void _on_select_resolution (GtkMenuItem *menu_item, gpointer data)  /// TODO: put that in the core...
{
	CD_APPLET_ENTER;
	int 				    iNumRes = GPOINTER_TO_INT (data);
	Display                 *dpy;
	Window                  root;
	XRRScreenConfiguration  *conf;
	short                   *rates;
	int                     num_rates;
	dpy = gdk_x11_get_default_xdisplay ();
	root = RootWindow(dpy, 0);
	
	conf = XRRGetScreenInfo(dpy, root);
	CD_APPLET_LEAVE_IF_FAIL (conf != NULL);
	//g_return_if_fail (conf != NULL);
	
	rates = XRRRates(dpy, 0, iNumRes, &num_rates);
	CD_APPLET_LEAVE_IF_FAIL (num_rates > 0);
	//g_return_if_fail (num_rates > 0);
	cd_debug ("available rates : from %d to %d Hz", rates[0], rates[num_rates-1]);
	
	XRRSetScreenConfigAndRate(dpy, conf, root, iNumRes, RR_Rotate_0, rates[num_rates-1], CurrentTime);
	XRRFreeScreenConfigInfo (conf);
	
	// restore original conf :  XRRSetScreenConfigAndRate(dpy, conf, root, original_size_id, original_rotation, original_rate, CurrentTime);
	CD_APPLET_LEAVE();
}
Пример #7
0
const DisplayResVector& DisplayResX::GetVideoModes(void) const
{
    if (m_video_modes.size())
        return m_video_modes;

    Display *display = NULL;
    XRRScreenConfiguration *cfg = GetScreenConfig(display);
    if (!cfg)
        return m_video_modes;

    int num_sizes, num_rates;
    XRRScreenSize *sizes = NULL;
    X11S(sizes = XRRConfigSizes(cfg, &num_sizes));
    for (int i = 0; i < num_sizes; ++i)
    {
        short *rates = NULL;
        X11S(rates = XRRRates(display, DefaultScreen(display), i, &num_rates));
        DisplayResScreen scr(sizes[i].width, sizes[i].height,
                             sizes[i].mwidth, sizes[i].mheight,
                             rates, num_rates);
        m_video_modes.push_back(scr);
    }
    m_video_modes_unsorted = m_video_modes;
    sort(m_video_modes.begin(), m_video_modes.end());

    X11L;
    XRRFreeScreenConfigInfo(cfg);
    XCloseDisplay(display);
    X11U;

    return m_video_modes;
}
Пример #8
0
bool DisplayResX::SwitchToVideoMode(int width, int height, short desired_rate)
{
    short rate;
    DisplayResScreen desired_screen(width, height, 0, 0, -1.0, desired_rate);
    int idx = DisplayResScreen::FindBestMatch(m_video_modes_unsorted,
                                              desired_screen, rate);
    if (idx >= 0)
    {
        Display *display = NULL;
        XRRScreenConfiguration *cfg = GetScreenConfig(display);
        if (!cfg)
            return false;

        X11L;
        Rotation rot;
        XRRConfigCurrentConfiguration(cfg, &rot);
        
        Window root = DefaultRootWindow(display);
        Status status = XRRSetScreenConfigAndRate(display, cfg, root, idx,
                                                  rot, rate, CurrentTime);
        
        XRRFreeScreenConfigInfo(cfg);
        XCloseDisplay(display);
        X11U;

        if (RRSetConfigSuccess != status)
            cerr<<"DisplaResX: XRRSetScreenConfigAndRate() call failed."<<endl;
        return RRSetConfigSuccess == status;
    }
    cerr<<"DisplaResX: Desired Resolution and FrameRate not found."<<endl;
    return false;
}
Пример #9
0
////////////////////////////////////////////////////////////
/// Cleanup graphical resources attached to the window
////////////////////////////////////////////////////////////
void WindowImplX11::CleanUp()
{
    // Restore the previous video mode (in case we were running in fullscreen)
    if (ourFullscreenWindow == this)
    {
        // Get current screen info
        XRRScreenConfiguration* Config = XRRGetScreenInfo(ourDisplay, RootWindow(ourDisplay, ourScreen));
        if (Config) 
        {
            // Get the current rotation
            Rotation CurrentRotation;
            XRRConfigCurrentConfiguration(Config, &CurrentRotation);

            // Reset the video mode
            XRRSetScreenConfig(ourDisplay, Config, RootWindow(ourDisplay, ourScreen), myOldVideoMode, CurrentRotation, CurrentTime);

            // Free the configuration instance
            XRRFreeScreenConfigInfo(Config);
        } 

        // Reset the fullscreen window
        ourFullscreenWindow = NULL;
    }

    // Unhide the mouse cursor (in case it was hidden)
    ShowMouseCursor(true);

    // Destroy the OpenGL context
    if (myGLContext)
    {
        glXDestroyContext(ourDisplay, myGLContext);
        myGLContext = NULL;
    }
}
JNIEXPORT jint JNICALL
Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModeIndex
(JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused)))
{
#ifdef HAVE_XRANDR	

	GdkDisplay *display;
	XRRScreenConfiguration *config;
	SizeID index;
	Rotation rotation;
	
	display = (GdkDisplay *) NSA_GET_DISPLAY_PTR(env, gdkGraphicsEnv);
	
	gdk_threads_enter();
	
	config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW());

	index = XRRConfigCurrentConfiguration (config, &rotation);

    XRRFreeScreenConfigInfo (config);

	gdk_threads_leave();
	
	return (int) index;

#else

    JCL_ThrowException(env,
                       "java/lang/InternalError",
                       "Method should not have been invoked.");
   
    return -1;
   
#endif	
}
Пример #11
0
bool DisplayResX::SwitchToVideoMode(int width, int height, double desired_rate)
{
    double rate;
    DisplayResScreen desired_screen(width, height, 0, 0, -1.0, desired_rate);
    int idx = DisplayResScreen::FindBestMatch(m_videoModesUnsorted,
              desired_screen, rate);

    if (idx >= 0)
    {
        short finalrate;
        MythXDisplay *display = NULL;
        XRRScreenConfiguration *cfg = GetScreenConfig(display);

        if (!cfg)
            return false;

        Rotation rot;

        XRRConfigCurrentConfiguration(cfg, &rot);

        // Search real xrandr rate for desired_rate
        finalrate = (short) rate;

        for (uint i = 0; i < m_videoModes.size(); i++)
        {
            if ((m_videoModes[i].Width() == width) &&
                    (m_videoModes[i].Height() == height))
            {
                if (m_videoModes[i].Custom())
                {
                    finalrate = m_videoModes[i].realRates[rate];
                    LOG(VB_PLAYBACK, LOG_INFO,
                        QString("Dynamic TwinView rate found, set %1Hz as "
                                "XRandR %2") .arg(rate) .arg(finalrate));
                }

                break;
            }
        }

        Window root = display->GetRoot();

        Status status = XRRSetScreenConfigAndRate(display->GetDisplay(), cfg,
                        root, idx, rot, finalrate,
                        CurrentTime);

        XRRFreeScreenConfigInfo(cfg);
        delete display;

        if (RRSetConfigSuccess != status)
            LOG(VB_GENERAL, LOG_ERR,
                "XRRSetScreenConfigAndRate() call failed.");

        return RRSetConfigSuccess == status;
    }

    LOG(VB_GENERAL, LOG_ERR, "Desired Resolution and FrameRate not found.");

    return false;
}
Пример #12
0
void _glfwPlatformRefreshWindowParams(_GLFWwindow* window)
{
    // Retrieve refresh rate if possible
    if (_glfwLibrary.X11.RandR.available)
    {
#if defined(_GLFW_HAS_XRANDR)
	XRRScreenConfiguration* sc;

	sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root);
	window->refreshRate = XRRConfigCurrentRate(sc);
	XRRFreeScreenConfigInfo(sc);
#endif /*_GLFW_HAS_XRANDR*/
    }
    else if (_glfwLibrary.X11.VidMode.available)
    {
#if defined(_GLFW_HAS_XF86VIDMODE)
	XF86VidModeModeLine modeline;
	int dotclock;
	float pixels_per_second, pixels_per_frame;

	// Use the XF86VidMode extension to get current video mode
	XF86VidModeGetModeLine(_glfwLibrary.X11.display,
			       _glfwLibrary.X11.screen,
			       &dotclock, &modeline);
	pixels_per_second = 1000.0f * (float) dotclock;
	pixels_per_frame  = (float) modeline.htotal * modeline.vtotal;
	window->refreshRate = (int) (pixels_per_second / pixels_per_frame + 0.5);
#endif /*_GLFW_HAS_XF86VIDMODE*/
    }
    else
    {
	// Zero means unknown according to the GLFW spec
	window->refreshRate = 0;
    }
}
Пример #13
0
void RenderContextImplGLX::SetVideoModeImpl(const VideoMode& mode) {
    if (xrandrSupported) {
        Window rootWnd = RootWindow(display, screenIndex);
        XRRScreenConfiguration *screenConfig = XRRGetScreenInfo(display,
                                               rootWnd);

        if (screenConfig) {

            int size = -1;
            int nsizes = 0;
            XRRScreenSize* screenSize = XRRConfigSizes(screenConfig, &nsizes);
            for (int i = 0; i < nsizes; ++i) {
                if (mode.width == uint16(screenSize[i].width)
                        && mode.height == uint16(screenSize[i].height)) {
                    size = i;
                    break;
                }
            }
            if (size < 0)
                // invalid mode
                return;
            Rotation current_rotation;
            XRRConfigCurrentConfiguration(screenConfig, &current_rotation);
            XRRSetScreenConfigAndRate(display, screenConfig, rootWnd, size,
                                      current_rotation, mode.refreshRate, CurrentTime);
            XRRFreeScreenConfigInfo(screenConfig);
            Trace(String("Video mode changed to:") + VideoMode::ToString(mode));
        }
    }
}
Пример #14
0
bool QxtScreenPrivate::set(const QSize& reso, int rate, int depth)
{
    bool result = false;
    Q_UNUSED(reso);
    Q_UNUSED(rate);
    Q_UNUSED(depth);
#ifdef HAVE_XRANDR
    Display* display = XOpenDisplay(NULL);
    Window root = RootWindow(display, screen);
    XRRScreenConfiguration* config = XRRGetScreenInfo(display, root);

    int sizeIndex = 0;
    if (reso.isValid())
        sizeIndex = availResos.indexOf(reso);
    else
        sizeIndex = availResos.indexOf(currReso);
    Q_ASSERT(sizeIndex != -1);

    if (rate == -1)
        result = XRRSetScreenConfig(display, config, root, sizeIndex, RR_Rotate_0, CurrentTime);
    else
        result = XRRSetScreenConfigAndRate(display, config, root, sizeIndex, RR_Rotate_0, rate, CurrentTime);

    XRRFreeScreenConfigInfo(config);
    XCloseDisplay(display);
#endif // HAVE_XRANDR
    return result;
}
Пример #15
0
KDE_EXPORT void RandRScreen::loadSettings()
{
	if (d->config) {
		XRRFreeScreenConfigInfo(d->config);
	}

	d->config = XRRGetScreenInfo(tqt_xdisplay(), RootWindow(tqt_xdisplay(), m_screen));

	Rotation rotation;
	if (d->config) {
		m_currentSize = m_proposedSize = XRRConfigCurrentConfiguration(d->config, &rotation);
		m_currentRotation = m_proposedRotation = rotation;
	}
	else {
		m_currentSize = m_proposedSize = 0;
		m_currentRotation = m_proposedRotation = 0;
	}

	m_pixelSizes.clear();
	m_mmSizes.clear();

	if (d->config) {
		int numSizes;
		XRRScreenSize* sizes = XRRSizes(tqt_xdisplay(), m_screen, &numSizes);
		for (int i = 0; i < numSizes; i++) {
			m_pixelSizes.append(TQSize(sizes[i].width, sizes[i].height));
			m_mmSizes.append(TQSize(sizes[i].mwidth, sizes[i].mheight));
		}

		m_rotations = XRRRotations(tqt_xdisplay(), m_screen, &rotation);
	}
	else {
		// Great, now we have to go after the information manually.  Ughh.
		ScreenInfo *screeninfo = internal_read_screen_info(tqt_xdisplay());
		XRROutputInfo *output_info = screeninfo->outputs[m_screen]->info;
		CrtcInfo *current_crtc = screeninfo->outputs[m_screen]->cur_crtc;
		int numSizes = output_info->nmode;
		for (int i = 0; i < numSizes; i++) {
			XRRModeInfo *xrrmode;
			xrrmode = internal_find_mode_by_xid (screeninfo, output_info->modes[i]);
			TQSize newSize = TQSize(xrrmode->width, xrrmode->height);
			if (!m_pixelSizes.contains(newSize)) {
				m_pixelSizes.append(newSize);
				m_mmSizes.append(TQSize(output_info->mm_width, output_info->mm_height));
			}
		}
		if (current_crtc) {
			m_rotations = current_crtc->rotations;
			m_currentRotation = m_proposedRotation = current_crtc->cur_rotation;
		}
	}

	if (d->config) {
		m_currentRefreshRate = m_proposedRefreshRate = refreshRateHzToIndex(m_currentSize, XRRConfigCurrentRate(d->config));
	}
	else {
		m_currentRefreshRate = m_proposedRefreshRate = 0;
	}
}
Пример #16
0
static void
gst_vaapi_display_x11_get_size_mm(
    GstVaapiDisplay *display,
    guint           *pwidth,
    guint           *pheight
)
{
    GstVaapiDisplayX11Private * const priv =
        GST_VAAPI_DISPLAY_X11(display)->priv;
    guint width_mm, height_mm;

    if (!priv->x11_display)
        return;

    width_mm  = DisplayWidthMM(priv->x11_display, priv->x11_screen);
    height_mm = DisplayHeightMM(priv->x11_display, priv->x11_screen);

#ifdef HAVE_XRANDR
    /* XXX: fix up physical size if the display is rotated */
    if (priv->use_xrandr) {
        XRRScreenConfiguration *xrr_config = NULL;
        XRRScreenSize *xrr_sizes;
        Window win;
        int num_xrr_sizes, size_id, screen;
        Rotation rotation;

        do {
            win    = DefaultRootWindow(priv->x11_display);
            screen = XRRRootToScreen(priv->x11_display, win);

            xrr_config = XRRGetScreenInfo(priv->x11_display, win);
            if (!xrr_config)
                break;

            size_id = XRRConfigCurrentConfiguration(xrr_config, &rotation);
            if (rotation == RR_Rotate_0 || rotation == RR_Rotate_180)
                break;

            xrr_sizes = XRRSizes(priv->x11_display, screen, &num_xrr_sizes);
            if (!xrr_sizes || size_id >= num_xrr_sizes)
                break;

            width_mm  = xrr_sizes[size_id].mheight;
            height_mm = xrr_sizes[size_id].mwidth;
        } while (0);
        if (xrr_config)
            XRRFreeScreenConfigInfo(xrr_config);
    }
#endif

    if (pwidth)
        *pwidth = width_mm;

    if (pheight)
        *pheight = height_mm;
}
VideoMode VideoModeImpl::getDesktopMode()
{
    VideoMode desktopMode;

    // Open a connection with the X server
    Display* display = OpenDisplay();
    if (display)
    {
        // Retrieve the default screen number
        int screen = DefaultScreen(display);

        // Check if the XRandR extension is present
        int version;
        if (XQueryExtension(display, "RANDR", &version, &version, &version))
        {
            // Get the current configuration
            XRRScreenConfiguration* config = XRRGetScreenInfo(display, RootWindow(display, screen));
            if (config)
            {
                // Get the current video mode
                Rotation currentRotation;
                int currentMode = XRRConfigCurrentConfiguration(config, &currentRotation);

                // Get the available screen sizes
                int nbSizes;
                XRRScreenSize* sizes = XRRConfigSizes(config, &nbSizes);
                if (sizes && (nbSizes > 0))
                    desktopMode = VideoMode(sizes[currentMode].width, sizes[currentMode].height, DefaultDepth(display, screen));

                // Free the configuration instance
                XRRFreeScreenConfigInfo(config);
            }
            else
            {
                // Failed to get the screen configuration
                err() << "Failed to retrieve the screen configuration while trying to get the desktop video modes" << std::endl;
            }
        }
        else
        {
            // XRandr extension is not supported : we cannot get the video modes
            err() << "Failed to use the XRandR extension while trying to get the desktop video modes" << std::endl;
        }

        // Close the connection with the X server
        CloseDisplay(display);
    }
    else
    {
        // We couldn't connect to the X server
        err() << "Failed to connect to the X server while trying to get the desktop video modes" << std::endl;
    }

    return desktopMode;
}
Пример #18
0
int initcurrent_x11videomode(/*out*/x11videomode_t * current_xvidmode, x11screen_t * x11screen)
{
    int err ;
    XRRScreenConfiguration * screen_config = 0 ;

    if (!isextxrandr_x11display(display_x11screen(x11screen))) {
        err = ENOSYS ;
        goto ONERR;
    }

    Display * sys_display = display_x11screen(x11screen)->sys_display ;
    screen_config = XRRGetScreenInfo(sys_display, RootWindow(sys_display, number_x11screen(x11screen))) ;
    if (!screen_config) {
        err = ENOSYS ;
        goto ONERR;
    }

    Rotation current_rotation ;
    uint16_t current_size = XRRConfigCurrentConfiguration(screen_config, &current_rotation) ;

    int           sizes_count ;
    XRRScreenSize * sizes = XRRConfigSizes(screen_config, &sizes_count) ;
    if (  !sizes
            || (current_size >= sizes_count)) {
        err = EOVERFLOW ;
        goto ONERR;
    }

    current_xvidmode->modeid          = current_size ;
    current_xvidmode->width_in_pixel  = (uint32_t) sizes[current_size].width ;
    current_xvidmode->height_in_pixel = (uint32_t) sizes[current_size].height ;

    XRRFreeScreenConfigInfo(screen_config) ;

    return 0 ;
ONERR:
    if (screen_config) {
        XRRFreeScreenConfigInfo(screen_config) ;
    }
    TRACEEXIT_ERRLOG(err);
    return err ;
}
void X11EGLSupport::switchMode(uint& width, uint& height, short& frequency)
{
    if (!mRandr)
        return;

    int size = 0;
    int newSize = -1;

    VideoModes::iterator mode;
    VideoModes::iterator end = mVideoModes.end();
    VideoMode *newMode = 0;

    for(mode = mVideoModes.begin(); mode != end; size++)
    {
        if (mode->first.first >= static_cast<int>(width) &&
                mode->first.second >= static_cast<int>(height))
        {
            if (!newMode ||
                    mode->first.first < newMode->first.first ||
                    mode->first.second < newMode->first.second)
            {
                newSize = size;
                newMode = &(*mode);
            }
        }

        VideoMode* lastMode = &(*mode);

        while (++mode != end && mode->first == lastMode->first)
        {
            if (lastMode == newMode && mode->second == frequency)
            {
                newMode = &(*mode);
            }
        }
    }

    if (newMode && *newMode != mCurrentMode)
    {
        XRRScreenConfiguration *screenConfig =
            XRRGetScreenInfo((Display*)mNativeDisplay, DefaultRootWindow((Display*)mNativeDisplay));
        if (screenConfig)
        {
            Rotation currentRotation;

            XRRConfigCurrentConfiguration (screenConfig, &currentRotation);
            XRRSetScreenConfigAndRate((Display*)mNativeDisplay, screenConfig, DefaultRootWindow((Display*)mNativeDisplay),
                                      newSize, currentRotation, newMode->second, CurrentTime);
            XRRFreeScreenConfigInfo(screenConfig);
            mCurrentMode = *newMode;
            LogManager::getSingleton().logMessage("Entered video mode " + StringConverter::toString(mCurrentMode.first.first) + "x" + StringConverter::toString(mCurrentMode.first.second) + " @ " + StringConverter::toString(mCurrentMode.second) + "MHz");
        }
    }
}
Пример #20
0
void RenderContextImplGLX::EnumVideoModes(VideoModeList& videoModes) {
    // check for xrandr support
    videoModes.clear();
    bool fallback = false;
    if ((xrandrSupported = IsXRandrSupported())) {
        XRRScreenSize* screenSize;
        int nsizes = 0;

        Trace("XRANDR is enabled");
        screenSize = XRRSizes(display, screenIndex, &nsizes);
        if (!nsizes)
            fallback = true;
        videoModes.reserve((size_t) nsizes);
        for (int i = 0; i < nsizes; ++i) {
            VideoMode vmode;
            vmode.width = uint16(screenSize[i].width);
            vmode.height = uint16(screenSize[i].height);

            int nrates;
            short* rates = XRRRates(display, screenIndex, i, &nrates);
            for (int j = 0; j < nrates; ++j) {
                vmode.refreshRate = uint16(rates[j]);
                videoModes.push_back(vmode);
            }
        }
        Window root = RootWindow(display, screenIndex);
        Rotation rotation;
        XRRScreenConfiguration *conf = XRRGetScreenInfo(display, root);
        int currsize = XRRConfigCurrentConfiguration(conf, &rotation);
        VideoMode current = VideoMode(screenSize[currsize].width,
                                      screenSize[currsize].height, XRRConfigCurrentRate(conf));
        std::sort(videoModes.begin(), videoModes.end());
        auto it = std::find(videoModes.begin(), videoModes.end(), current);
        if (it != videoModes.end())
            baseContext->SetOriginalVideoMode((uint32)(it - videoModes.begin()));
        else {
            videoModes.push_back(current);
            baseContext->SetOriginalVideoMode((uint32)videoModes.size() - 1);
        }
        XRRFreeScreenConfigInfo(conf);
    } /* check vid modes*/
    if (fallback || !videoModes.size()) {
        VideoMode vmode;
        vmode.width = DisplayWidth(display, screenIndex);
        vmode.height = DisplayHeight(display, screenIndex);
        vmode.refreshRate = 0;
        videoModes.push_back(vmode);
        baseContext->SetOriginalVideoMode((uint32)videoModes.size() - 1);
        Error("Viewmode set in fallback mode!");
    }
}
Пример #21
0
int free_x11videomodeiterator(x11videomode_iterator_t * xvidit)
{
    XRRScreenConfiguration * screen_config = xvidit->config ;

    xvidit->nextindex = 0 ;
    xvidit->nrmodes   = 0 ;
    xvidit->config    = 0 ;

    if (screen_config) {
        XRRFreeScreenConfigInfo(screen_config) ;
    }

    return 0 ;
}
Пример #22
0
////////////////////////////////////////////////////////////
/// Switch to fullscreen mode
////////////////////////////////////////////////////////////
void WindowImplX11::SwitchToFullscreen(const VideoMode& Mode)
{
    // Check if the XRandR extension is present
    int Version;
    if (XQueryExtension(ourDisplay, "RANDR", &Version, &Version, &Version))
    {
        // Get the current configuration
        XRRScreenConfiguration* Config = XRRGetScreenInfo(ourDisplay, RootWindow(ourDisplay, ourScreen));
        if (Config)
        {
            // Get the current rotation
            Rotation CurrentRotation;
            myOldVideoMode = XRRConfigCurrentConfiguration(Config, &CurrentRotation);

            // Get the available screen sizes
            int NbSizes;
            XRRScreenSize* Sizes = XRRConfigSizes(Config, &NbSizes);
            if (Sizes && (NbSizes > 0))
            {
                // Search a matching size
                for (int i = 0; i < NbSizes; ++i)
                {
                    if ((Sizes[i].width == static_cast<int>(Mode.Width)) && (Sizes[i].height == static_cast<int>(Mode.Height)))
                    {
                        // Switch to fullscreen mode
                        XRRSetScreenConfig(ourDisplay, Config, RootWindow(ourDisplay, ourScreen), i, CurrentRotation, CurrentTime);

                        // Set "this" as the current fullscreen window
                        ourFullscreenWindow = this;
                        break;
                    }
                }
            }

            // Free the configuration instance
            XRRFreeScreenConfigInfo(Config);
        }
        else
        {
            // Failed to get the screen configuration
            std::cerr << "Failed to get the current screen configuration for fullscreen mode, switching to windiw mode" << std::endl;
        }
    }
    else
    {
        // XRandr extension is not supported : we cannot use fullscreen mode
        std::cerr << "Fullscreen is not supported, switching to window mode" << std::endl;
    }
}
Пример #23
0
void RestoreScene() {
    /* Restore screen resolution */
    if(cg_screen_mode == CG_FULLSCREEN) {
        XRRSetScreenConfigAndRate(cg_display, cg_screen_conf,
                                  DefaultRootWindow(cg_display), cg_orig_size,
                                  cg_rotation, cg_orig_rate, CurrentTime);
        XRRFreeScreenConfigInfo(cg_screen_conf);
    }

    /* Free resources */
    glXMakeCurrent(cg_display, 0, 0);
    glXDestroyContext(cg_display, cg_context);
    XDestroyWindow(cg_display, cg_window);
    XCloseDisplay(cg_display);
}
Пример #24
0
/*
 * @brief get the current set size of a given screen's primary output
 * @param root window which's primary output will be queried
 * @param w the current size's width
 * @param h the current size's height
 * @param w_mm the current size's width in mm
 * @param h_mm the current size's height in mm
 * @param size_index of current set size to be used with ecore_x_randr_primary_output_size_set()
 */
EAPI void
ecore_x_randr_screen_primary_output_current_size_get(Ecore_X_Window root,
                                                     int           *w,
                                                     int           *h,
                                                     int           *w_mm,
                                                     int           *h_mm,
                                                     int           *size_index)
{
#ifdef ECORE_XRANDR
   XRRScreenSize *sizes;
   XRRScreenConfiguration *sc = NULL;
   int index;
   Rotation orientation;
   int n;

   if (!(sc = XRRGetScreenInfo(_ecore_x_disp, root)))
     {
        ERR("Couldn't get screen information for %d", root);
        return;
     }

   index = XRRConfigCurrentConfiguration(sc, &orientation);

   sizes =
      XRRSizes(_ecore_x_disp, XRRRootToScreen(_ecore_x_disp,
                                                    root), &n);
   if ((index < n) && (index >= 0))
     {
        if (w)
           *w = sizes[index].width;

        if (h)
           *h = sizes[index].height;

        if (w_mm)
           *w_mm = sizes[index].mwidth;

        if (h_mm)
           *h_mm = sizes[index].mheight;

        if (size_index)
           *size_index = index;
     }

   XRRFreeScreenConfigInfo(sc);
#endif /* ifdef ECORE_XRANDR */
} /* ecore_x_randr_screen_primary_output_current_size_get */
Пример #25
0
void _glfwRestoreVideoMode(void)
{
    if (_glfwLibrary.X11.FS.modeChanged)
    {
        if (_glfwLibrary.X11.RandR.available)
        {
#if defined(_GLFW_HAS_XRANDR)
            XRRScreenConfiguration* sc;

            if (_glfwLibrary.X11.RandR.available)
            {
                sc = XRRGetScreenInfo(_glfwLibrary.X11.display,
                                      _glfwLibrary.X11.root);

                XRRSetScreenConfig(_glfwLibrary.X11.display,
                                   sc,
                                   _glfwLibrary.X11.root,
                                   _glfwLibrary.X11.FS.oldSizeID,
                                   _glfwLibrary.X11.FS.oldRotation,
                                   CurrentTime);

                XRRFreeScreenConfigInfo(sc);
            }
#endif /*_GLFW_HAS_XRANDR*/
        }
        else if (_glfwLibrary.X11.VidMode.available)
        {
#if defined(_GLFW_HAS_XF86VIDMODE)
            // Unlock mode switch
            XF86VidModeLockModeSwitch(_glfwLibrary.X11.display,
                                      _glfwLibrary.X11.screen,
                                      0);

            // Change the video mode back to the old mode
            XF86VidModeSwitchToMode(_glfwLibrary.X11.display,
                                    _glfwLibrary.X11.screen,
                                    &_glfwLibrary.X11.FS.oldMode);
#endif /*_GLFW_HAS_XF86VIDMODE*/
        }

        _glfwLibrary.X11.FS.modeChanged = GL_FALSE;
    }
}
Пример #26
0
void QxtScreenPrivate::init_sys()
{
#ifdef HAVE_XRANDR
    Display* display = XOpenDisplay(NULL);
    Window root = RootWindow(display, screen);
    XRRScreenConfiguration* config = XRRGetScreenInfo(display, root);

    // available resolutions & rates
    if (availResos.isEmpty() || availRates.isEmpty())
    {
        availResos.clear();
        availRates.clear();

        int sizeCount = 0;
        XRRScreenSize* sizes = XRRSizes(display, 0, &sizeCount);
        for (int i = 0; i < sizeCount; ++i)
        {
            QSize reso(sizes[i].width, sizes[i].height);
            if (!availResos.contains(reso))
                availResos += reso;

            int rateCount = 0;
            short* rates = XRRConfigRates(config, i, &rateCount);
            for (int j = 0; j < rateCount; ++j)
                availRates.insertMulti(reso, rates[j]);
        }
    }

    // current resolution & rate
    if (!currReso.isValid() || currRate < 0)
    {
        Rotation rotation;
        SizeID sizeId = XRRConfigCurrentConfiguration(config, &rotation);
        currReso = availResos.at(sizeId);
        currRate = XRRConfigCurrentRate(config);
    }

    XRRFreeScreenConfigInfo(config);
    XCloseDisplay(display);
#endif // HAVE_XRANDR
}
Пример #27
0
/*
 * r_desktop_destroy:
 *
 */
void
r_desktop_destroy()
{
    XRRScreenConfiguration *sc;
    
    if(self.current_width != self.default_width || self.current_height != self.default_height)
    {
        sc = XRRGetScreenInfo(game->display, DefaultRootWindow(game->display));
        XRRSetScreenConfigAndRate(
            game->display,
            sc,
            DefaultRootWindow(game->display),
            self.size,
            self.rotation,
            self.rate,
            CurrentTime
            );
        XRRFreeScreenConfigInfo(sc);
        XSync(game->display, True);
    }
}
Пример #28
0
/*
 * @param root window which's primary output will be queried
 * @return currently used refresh rate or - if request failed or RandRR is not available - 0.0
 */
EAPI Ecore_X_Randr_Refresh_Rate
ecore_x_randr_screen_primary_output_current_refresh_rate_get(
   Ecore_X_Window root)
{
#ifdef ECORE_XRANDR
   Ecore_X_Randr_Refresh_Rate ret = 0.0;
   XRRScreenConfiguration *sc = NULL;

   if (!_ecore_x_randr_root_validate(root) ||
       !(sc = XRRGetScreenInfo(_ecore_x_disp, root)))
      return ret;

   ret = XRRConfigCurrentRate(sc);
   if (sc)
      XRRFreeScreenConfigInfo(sc);

   return ret;
#else /* ifdef ECORE_XRANDR */
   return 0.0;
#endif /* ifdef ECORE_XRANDR */
} /* ecore_x_randr_screen_primary_output_current_refresh_rate_get */
Пример #29
0
/*
 * r_desktop_init:
 *
 */
void
r_desktop_init()
{
    gint event_base;
    gint error_base;
    gint version_major;
    gint version_minor;
    gint sizes_count;
    XRRScreenSize* sizes;
    XRRScreenConfiguration *sc;
    
    if(!XRRQueryExtension(
        game->display,
        &event_base,
        &error_base
        )
    || !XRRQueryVersion(
        game->display,
        &version_major,
        &version_minor
        ))
    {
        g_error("XRandr not supported");
    }
    
    sc = XRRGetScreenInfo(game->display, DefaultRootWindow(game->display));
    self.size = XRRConfigCurrentConfiguration(sc, &self.rotation);
    self.rate = XRRConfigCurrentRate(sc);
    XRRFreeScreenConfigInfo(sc);

    sizes = XRRSizes(game->display, DefaultScreen(game->display), &sizes_count);
    self.default_width = sizes[self.size].width;
    self.default_height = sizes[self.size].height;
    self.default_rate = self.rate;
    self.current_width = self.default_width;
    self.current_height = self.default_height;
    self.current_rate = self.default_rate;

    _desktop_print_info();
}
Пример #30
0
/**
 * This method first resets the current resolution using RandR to wake up
 * the graphics driver, then sets the resolution requested if it is among
 * those offered by the driver.
 */
static void setSize(Display *pDisplay, uint32_t cx, uint32_t cy)
{
    XRRScreenConfiguration *pConfig;
    XRRScreenSize *pSizes;
    int cSizes;
    pConfig = XRRGetScreenInfo(pDisplay, DefaultRootWindow(pDisplay));
    /* Reset the current mode */
    LogRelFlowFunc(("Setting size %ux%u\n", cx, cy));
    if (pConfig)
    {
        pSizes = XRRConfigSizes(pConfig, &cSizes);
        unsigned uDist = UINT32_MAX;
        int iMode = -1;
        for (int i = 0; i < cSizes; ++i)
        {
#define VBCL_SQUARE(x) (x) * (x)
            unsigned uThisDist =   VBCL_SQUARE(pSizes[i].width - cx)
                                 + VBCL_SQUARE(pSizes[i].height - cy);
            LogRelFlowFunc(("Found size %dx%d, distance %u\n", pSizes[i].width,
                         pSizes[i].height, uThisDist));
#undef VBCL_SQUARE
            if (uThisDist < uDist)
            {
                uDist = uThisDist;
                iMode = i;
            }
        }
        if (iMode >= 0)
        {
            Time config_timestamp = 0;
            XRRConfigTimes(pConfig, &config_timestamp);
            LogRelFlowFunc(("Setting new size %d\n", iMode));
            XRRSetScreenConfig(pDisplay, pConfig,
                               DefaultRootWindow(pDisplay), iMode,
                               RR_Rotate_0, config_timestamp);
        }
        XRRFreeScreenConfigInfo(pConfig);
    }
}