Exemplo n.º 1
0
bool RandRScreen::applyProposed()
{
    // kdDebug() << k_funcinfo << " size " << (SizeID)proposedSize() << ", rotation " << proposedRotation() << ", refresh " <<
    // refreshRateIndexToHz(proposedSize(), proposedRefreshRate()) << endl;

    Status status;

    if(proposedRefreshRate() < 0)
        status = XRRSetScreenConfig(qt_xdisplay(), d->config, DefaultRootWindow(qt_xdisplay()), (SizeID)proposedSize(), (Rotation)proposedRotation(),
                                    CurrentTime);
    else
    {
        if(refreshRateIndexToHz(proposedSize(), proposedRefreshRate()) <= 0)
        {
            m_proposedRefreshRate = 0;
        }
        status = XRRSetScreenConfigAndRate(qt_xdisplay(), d->config, DefaultRootWindow(qt_xdisplay()), (SizeID)proposedSize(),
                                           (Rotation)proposedRotation(), refreshRateIndexToHz(proposedSize(), proposedRefreshRate()), CurrentTime);
    }

    // kdDebug() << "New size: " << WidthOfScreen(ScreenOfDisplay(QPaintDevice::x11AppDisplay(), screen)) << ", " <<
    // HeightOfScreen(ScreenOfDisplay(QPaintDevice::x11AppDisplay(), screen)) << endl;

    if(status == RRSetConfigSuccess)
    {
        m_currentSize = m_proposedSize;
        m_currentRotation = m_proposedRotation;
        m_currentRefreshRate = m_proposedRefreshRate;
        return true;
    }

    return 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();
}
Exemplo n.º 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 */
Exemplo n.º 4
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;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
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));
        }
    }
}
Exemplo n.º 7
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;
}
Exemplo n.º 8
0
void XRandRToggler::setFullMode(const bool enable) {
    SizeID currentID = XRRConfigCurrentConfiguration(config, &rotation);
    int currentRate = XRRConfigCurrentRate(config);

    SizeID newID;
    int newRate;

    if (enable) {
        newID = fullResIndex;
        newRate = infoVector[fullResIndex].rates[fullRateIndex] / 10;

        if (!isFull) {
            originalResIndex = currentID;
            originalRate = currentRate;
        }
    } else {
        newID = originalResIndex;
        newRate = originalRate;
    }

    if (newID != currentID || newRate != currentRate) {
        XRRSetScreenConfigAndRate(QX11Info::display(), config, QX11Info::appRootWindow(), newID, rotation, newRate, CurrentTime);

        if (newRate != currentRate)
            emit rateChange(newRate * 10);
    }

    isFull = enable;
}
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");
        }
    }
}
Exemplo n.º 10
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);
}
Exemplo n.º 11
0
void RotationDaemon::rotate(int angle)
{
    // XXX: technically this is leaked
    static XRRScreenConfiguration *config = XRRGetScreenInfo(QX11Info::display(), DefaultRootWindow(QX11Info::display()));

    ushort rotation;
    ushort size;
    size = XRRConfigCurrentConfiguration(config, &rotation);

    short rate;
    rate = XRRConfigCurrentRate(config);

    unsigned long timestamp, current_time;
    timestamp = XRRTimes(QX11Info::display(), XDefaultScreen(QX11Info::display()), &current_time);

    qDebug() << "RotationDaemon::rotate(" << angle << ")";
    XRRSetScreenConfigAndRate(QX11Info::display(), config, DefaultRootWindow(QX11Info::display()), size, angle, rate, timestamp);
}
Exemplo n.º 12
0
KDE_EXPORT bool RandRScreen::applyProposed()
{
	//kdDebug() << k_funcinfo << " size " << (SizeID)proposedSize() << ", rotation " << proposedRotation() << ", refresh " << refreshRateIndexToHz(proposedSize(), proposedRefreshRate()) << endl;

	Status status;

	if (!d->config) {
		d->config = XRRGetScreenInfo(tqt_xdisplay(), RootWindow(tqt_xdisplay(), m_screen));
		Q_ASSERT(d->config);
	}

	if (d->config) {
		if (proposedRefreshRate() < 0)
			status = XRRSetScreenConfig(tqt_xdisplay(), d->config, DefaultRootWindow(tqt_xdisplay()), (SizeID)proposedSize(), (Rotation)proposedRotation(), CurrentTime);
		else {
			if( refreshRateIndexToHz(proposedSize(), proposedRefreshRate()) <= 0 ) {
				m_proposedRefreshRate = 0;
			}
			status = XRRSetScreenConfigAndRate(tqt_xdisplay(), d->config, DefaultRootWindow(tqt_xdisplay()), (SizeID)proposedSize(), (Rotation)proposedRotation(), refreshRateIndexToHz(proposedSize(), proposedRefreshRate()), CurrentTime);
		}
	}
	else {
		// Great, now we have to set the information manually.  Ughh.
		// FIXME--this does not work!
		ScreenInfo *screeninfo = internal_read_screen_info(tqt_xdisplay());
		screeninfo->cur_width = (*m_pixelSizes.at(proposedSize())).width();
		screeninfo->cur_height = (*m_pixelSizes.at(proposedSize())).height();
		internal_main_low_apply(screeninfo);

		status = RRSetConfigSuccess;
	}

	//kdDebug() << "New size: " << WidthOfScreen(ScreenOfDisplay(TQPaintDevice::x11AppDisplay(), screen)) << ", " << HeightOfScreen(ScreenOfDisplay(TQPaintDevice::x11AppDisplay(), screen)) << endl;

	if (status == RRSetConfigSuccess) {
		m_currentSize = m_proposedSize;
		m_currentRotation = m_proposedRotation;
		m_currentRefreshRate = m_proposedRefreshRate;
		return true;
	}

	return false;
}
Exemplo n.º 13
0
void SetScreenSize(int width, int height, XVisualInfo *visual) {
    XRRScreenSize *sizes;
    int snum, rnum, i;
    short *rates;

    cg_screen_conf = XRRGetScreenInfo(cg_display, cg_window);
    cg_orig_size   = XRRConfigCurrentConfiguration(cg_screen_conf, &cg_rotation);
    cg_orig_rate   = XRRConfigCurrentRate(cg_screen_conf);

    /* Get the available resolutions */
    sizes = XRRSizes(cg_display, visual->screen, &snum);
    for(i = 0; i < snum; i++) {
        if((sizes[i].width == width) && (sizes[i].height == height)) {
            rates = XRRRates(cg_display, visual->screen, i, &rnum);
            XRRSetScreenConfigAndRate(cg_display, cg_screen_conf,
                                      DefaultRootWindow(cg_display), i,
                                      cg_rotation, rates[0], CurrentTime);
        }
    }
}
Exemplo n.º 14
0
    bool apply(const DisplayMode* mode)
    {
        if(!_conf) return false;

        int sizeIdx = find(mode);
        assert(sizeIdx >= 0);

        //qDebug() << "calling XRRSetScreenConfig" << _confTime;
        Status result = XRRSetScreenConfigAndRate(QX11Info::display(), _conf, QX11Info::appRootWindow(),
                                                  sizeIdx, displayRotation, rateFromMode(mode), _confTime);
        //qDebug() << "result" << result;
        if(result == BadValue)
        {
            qDebug() << "Failed to apply screen config and rate with Xrandr";
            return false;
        }

        // Update the current mode.
        de::currentMode = *mode;
        return true;
    }
Exemplo n.º 15
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);
    }
}
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeSetDisplayMode
(JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused)), jint index __attribute__((unused)), jshort rate __attribute__((unused)))
{
#ifdef HAVE_XRANDR
	GdkDisplay *display;
	XRRScreenConfiguration *config;
	Rotation rotation;
	
	display = (GdkDisplay *) NSA_GET_DISPLAY_PTR(env, gdkGraphicsEnv);
	
	gdk_threads_enter();
	
	config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW());

	/* The rotation is not exposed to the Java API. So we retrieve its current
	 * value and set it to the same when switching resolution.
	 */
	XRRConfigCurrentConfiguration (config, &rotation);
	
	XRRSetScreenConfigAndRate (GDK_DISPLAY_XDISPLAY(display),
                        		   config,
                               GDK_ROOT_WINDOW(),
                               index,
                               rotation,
                               rate,
                               CurrentTime);
	
	XRRFreeScreenConfigInfo(config);
	
	gdk_threads_leave();

#else
    JCL_ThrowException(env,
                       "java/lang/InternalError",
                       "Method should not have been invoked.");
#endif	
}
Exemplo n.º 17
0
void _glfwSetVideoModeMODE(int mode, int rate)
{
    if (_glfwLibrary.X11.RandR.available)
    {
#if defined(_GLFW_HAS_XRANDR)
        XRRScreenConfiguration* sc;
        Window root;

        root = _glfwLibrary.X11.root;
        sc   = XRRGetScreenInfo(_glfwLibrary.X11.display, root);

        // Remember old size and flag that we have changed the mode
        if (!_glfwLibrary.X11.FS.modeChanged)
        {
            _glfwLibrary.X11.FS.oldSizeID = XRRConfigCurrentConfiguration(sc, &_glfwLibrary.X11.FS.oldRotation);
            _glfwLibrary.X11.FS.oldWidth  = DisplayWidth(_glfwLibrary.X11.display,
                                                         _glfwLibrary.X11.screen);
            _glfwLibrary.X11.FS.oldHeight = DisplayHeight(_glfwLibrary.X11.display,
                                                          _glfwLibrary.X11.screen);

            _glfwLibrary.X11.FS.modeChanged = GL_TRUE;
        }

        if (rate > 0)
        {
            // Set desired configuration
            XRRSetScreenConfigAndRate(_glfwLibrary.X11.display,
                                      sc,
                                      root,
                                      mode,
                                      RR_Rotate_0,
                                      (short) rate,
                                      CurrentTime);
        }
        else
        {
            // Set desired configuration
            XRRSetScreenConfig(_glfwLibrary.X11.display,
                               sc,
                               root,
                               mode,
                               RR_Rotate_0,
                               CurrentTime);
        }

        XRRFreeScreenConfigInfo(sc);
#endif /*_GLFW_HAS_XRANDR*/
    }
    else if (_glfwLibrary.X11.VidMode.available)
    {
#if defined(_GLFW_HAS_XF86VIDMODE)
        XF86VidModeModeInfo **modelist;
        int modecount;

        // Get a list of all available display modes
        XF86VidModeGetAllModeLines(_glfwLibrary.X11.display,
                                   _glfwLibrary.X11.screen,
                                   &modecount, &modelist);

        // Unlock mode switch if necessary
        if (_glfwLibrary.X11.FS.modeChanged)
        {
            XF86VidModeLockModeSwitch(_glfwLibrary.X11.display,
                                      _glfwLibrary.X11.screen,
                                      0);
        }

        // Change the video mode to the desired mode
        XF86VidModeSwitchToMode(_glfwLibrary.X11.display,
                                _glfwLibrary.X11.screen,
                                modelist[mode]);

        // Set viewport to upper left corner (where our window will be)
        XF86VidModeSetViewPort(_glfwLibrary.X11.display,
                               _glfwLibrary.X11.screen,
                               0, 0);

        // Lock mode switch
        XF86VidModeLockModeSwitch(_glfwLibrary.X11.display,
                                  _glfwLibrary.X11.screen,
                                  1);

        // Remember old mode and flag that we have changed the mode
        if (!_glfwLibrary.X11.FS.modeChanged)
        {
            _glfwLibrary.X11.FS.oldMode = *modelist[0];
            _glfwLibrary.X11.FS.modeChanged = GL_TRUE;
        }

        XFree(modelist);
#endif /*_GLFW_HAS_XF86VIDMODE*/
    }
}
Exemplo n.º 18
0
static int xrandr_resize(int xsz, int ysz, int rate, int just_checking)
{
#ifdef HAVE_X11_EXTENSIONS_XRANDR_H
    int event_base, error_base, ver_major, ver_minor, use_rate;
    XRRScreenConfiguration *xrr_config = 0;
    Status result = -1;

    /* must check at runtime for the availability of the extension */
    if(!XRRQueryExtension(fgDisplay.Display, &event_base, &error_base)) {
        return -1;
    }

    XRRQueryVersion(fgDisplay.Display, &ver_major, &ver_minor);

    /* we only heed the rate if we CAN actually use it (Xrandr >= 1.1) and
     * the user actually cares about it (rate > 0)
     */
    use_rate = ( rate > 0 ) && ( ( ver_major >= 1 ) ||
		                         ( ( ver_major == 1 ) && ( ver_minor >= 1 ) ) );

    /* this loop is only so that the whole thing will be repeated if someone
     * else changes video mode between our query of the current information and
     * the attempt to change it.
     */
    do {
        XRRScreenSize *ssizes;
        short *rates;
        Rotation rot;
        int i, ssizes_count, rates_count, curr, res_idx = -1;
        Time timestamp, cfg_timestamp;

        if(xrr_config) {
            XRRFreeScreenConfigInfo(xrr_config);
        }

        if(!(xrr_config = XRRGetScreenInfo(fgDisplay.Display, fgDisplay.RootWindow))) {
            fgWarning("XRRGetScreenInfo failed");
            break;
        }
        ssizes = XRRConfigSizes(xrr_config, &ssizes_count);
        curr = XRRConfigCurrentConfiguration(xrr_config, &rot);
        timestamp = XRRConfigTimes(xrr_config, &cfg_timestamp);

        /* if either of xsz or ysz are unspecified, use the current values */
        if(xsz <= 0)
            xsz = fgState.GameModeSize.X = ssizes[curr].width;
        if(ysz <= 0)
            ysz = fgState.GameModeSize.Y = ssizes[curr].height;


        if(xsz == ssizes[curr].width && ysz == ssizes[curr].height) {
            /* no need to switch, we're already in the requested resolution */
            res_idx = curr;
        } else {
            for(i=0; i<ssizes_count; i++) {
                if(ssizes[i].width == xsz && ssizes[i].height == ysz) {
                    res_idx = i;
                    break;  /* found it */
                }
            }
        }
        if(res_idx == -1)
            break;  /* no matching resolution */

#if ( RANDR_MAJOR >= 1 ) || ( ( RANDR_MAJOR == 1 ) && ( RANDR_MINOR >= 1 ) )
        if(use_rate) {
            rate = fgState.GameModeRefresh;

            /* for the selected resolution, let's find out if there is
             * a matching refresh rate available.
             */
            rates = XRRConfigRates(xrr_config, res_idx, &rates_count);

            for(i=0; i<rates_count; i++) {
                if(rates[i] == rate) {
                    break;
                }
            }
            if(i == rates_count) {
                break; /* no matching rate */
            }
        }
#endif

        if(just_checking) {
            result = 0;
            break;
        }

#if ( RANDR_MAJOR >= 1 ) || ( ( RANDR_MAJOR == 1 ) && ( RANDR_MINOR >= 1 ) )
        if(use_rate)
            result = XRRSetScreenConfigAndRate(fgDisplay.Display, xrr_config,
                    fgDisplay.RootWindow, res_idx, rot, rate, timestamp);
        else
#endif
            result = XRRSetScreenConfig(fgDisplay.Display, xrr_config,
                    fgDisplay.RootWindow, res_idx, rot, timestamp);

    } while(result == RRSetConfigInvalidTime);

    if(xrr_config) {
        XRRFreeScreenConfigInfo(xrr_config);
    }

    if(result == 0) {
        return 0;
    }

#endif  /* HAVE_X11_EXTENSIONS_XRANDR_H */
    return -1;
}
Exemplo n.º 19
0
/*
 * r_desktop_set_resolution:
 * @width:
 * @height:
 * @rate:
 *
 */
void
r_desktop_set_resolution(
    guint       width,
    guint       height,
    guint       rate
    )
{
    gint sizes_count;
    XRRScreenSize* sizes;
    gint rates_count;
    gshort* rates;
    gint i, d1, d2;
    gint best_size = -1;
    gshort best_rate = -1;
    XRRScreenConfiguration *sc;

    if(width == self.current_width && height == self.current_height)
    {
        return;
    }

#ifdef DEBUG
    g_debug("Old Video Mode: %dx%d %dHz", self.current_width, self.current_height, self.current_rate);
#endif

    if(width == self.default_width && height == self.default_height)
    {
        best_size = self.size;
        best_rate = self.rate;
        self.current_width = self.default_width;
        self.current_height = self.default_height;
        self.current_rate = self.rate;
    }
    else
    {
        sizes = XRRSizes(game->display, DefaultScreen(game->display), &sizes_count);
        d1  = (width - sizes[0].width) * (width - sizes[0].width)
            + (height - sizes[0].height) * (height - sizes[0].height);
        best_size = 0;
        for(i = 1; i < sizes_count; i++)
        {
            d2  = (width - sizes[i].width) * (width - sizes[i].width)
                + (height - sizes[i].height) * (height - sizes[i].height);
            if(d1 > d2)
            {
                d1 = d2;
                best_size = i;
            }
        }
        
        rates = XRRRates(game->display, DefaultScreen(game->display), best_size, &rates_count);
        best_rate = rates[0];
        for(i = 1; i < rates_count; i++)
        {
            if(rates[i] > best_rate)
            {
                best_rate = rates[i];
            }
        }
    
        self.current_width = sizes[best_size].width;
        self.current_height = sizes[best_size].height;
        self.current_rate = best_rate;
    }
    
#ifdef DEBUG
    g_debug("New Video Mode: %dx%d %dHz", self.current_width, self.current_height, self.current_rate);
#endif

    sc = XRRGetScreenInfo(game->display, DefaultRootWindow(game->display));
    XRRSetScreenConfigAndRate(
        game->display,
        sc,
        DefaultRootWindow(game->display),
        best_size,
        self.rotation,
        best_rate,
        CurrentTime
        );
    XRRFreeScreenConfigInfo(sc);
    XSync(game->display, True);
}