JNIEXPORT jint JNICALL
Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModeRate
(JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused)))
{
#ifdef HAVE_XRANDR

	GdkDisplay *display;
	XRRScreenConfiguration *config;
	int rate;
	
	display = (GdkDisplay *) NSA_GET_DISPLAY_PTR(env, gdkGraphicsEnv);
	
	gdk_threads_enter();
	
	config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW());

	rate = (int) XRRConfigCurrentRate (config);

    XRRFreeScreenConfigInfo (config);

	gdk_threads_leave();
	
	return rate;
#else
    JCL_ThrowException(env,
                       "java/lang/InternalError",
                       "Method should not have been invoked.");
    
    return -1;
#endif    
}
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;
}
示例#3
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;
    }
}
示例#4
0
文件: randr.cpp 项目: Fat-Zer/tdelibs
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;
	}
}
示例#5
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!");
    }
}
示例#6
0
int getScreenSize(int& width, int& height)
{
    int num_sizes;
    Rotation original_rotation;

    Window root = RootWindow(s_display, 0);
    XRRScreenSize *xrrs = XRRSizes(s_display, 0, &num_sizes);

    XRRScreenConfiguration *conf = XRRGetScreenInfo(s_display, root);
    short original_rate          = XRRConfigCurrentRate(conf);
    SizeID original_size_id      = XRRConfigCurrentConfiguration(conf, &original_rotation);

    //xrrs[2] is correct, so I have to figure out how to determine this programmatically.
    width  = xrrs[original_size_id].width;
    height = xrrs[original_size_id].height;
 }
示例#7
0
    /**
     * Returns the currently active mode as specified in the Xrandr config.
     * Also determines the display's current rotation angle.
     */
    DisplayMode currentMode() const
    {
        DisplayMode mode;
        de::zap(mode);

        if(!_conf) return mode;

        SizeID currentSize = XRRConfigCurrentConfiguration(_conf, &displayRotation);

        // Update the current mode.
        mode.width = _sizes[currentSize].width;
        mode.height = _sizes[currentSize].height;
        mode.depth = displayDepth;
        mode.refreshRate = XRRConfigCurrentRate(_conf);
        return mode;
    }
示例#8
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);
}
示例#9
0
static void
get_resolution(Enna_Buffer *b)
{
    XRRScreenConfiguration *sc;
    Window root;
    Display *dpy;
    short rate;
    int screen;
    int minWidth, maxWidth, minHeight, maxHeight;

    dpy = XOpenDisplay(":0.0");
    if (!dpy)
        return;

    screen = DefaultScreen(dpy);
    if (screen >= ScreenCount(dpy))
        return;

    root = RootWindow(dpy, screen);
    if (root < 0)
        return;

    sc = XRRGetScreenInfo(dpy, root);
    if (!sc)
        return;

    rate = XRRConfigCurrentRate(sc);
    XRRGetScreenSizeRange(dpy, root,
                          &minWidth, &minHeight, &maxWidth, &maxHeight);

    enna_buffer_append(b, "<hilight>");
    enna_buffer_append(b, _("Screen resolution:"));
    enna_buffer_appendf(b, "</hilight> %dx%d ",
                   DisplayWidth(dpy, screen), DisplayHeight(dpy, screen));
    enna_buffer_append(b, _("at"));
    enna_buffer_appendf(b, " %d Hz (", rate);
    enna_buffer_append(b, _("min:"));
    enna_buffer_appendf(b, " %dx%d, ", minWidth, minHeight);
    enna_buffer_append(b, _("max:"));
    enna_buffer_appendf(b, " %dx%d)<br>", maxWidth, maxHeight);
    XCloseDisplay(dpy);
}
示例#10
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);
        }
    }
}
示例#11
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
}
XRandRToggler::XRandRToggler() :
    config(XRRGetScreenInfo(QX11Info::display(), QX11Info::appRootWindow())),
    originalResIndex(0),
    fullResIndex(0),
    rotation(0),
    fullRateIndex(0),
    originalRate(0),
    isFull(false)
{
    fullResIndex = originalResIndex = XRRConfigCurrentConfiguration(config, &rotation);
    originalRate = XRRConfigCurrentRate(config);

    int nSizes;
    XRRScreenSize *randrSizes = XRRConfigSizes(config, &nSizes);

    for (int i = 0; i < nSizes; ++i) {
        ResInfo info;
        info.w = randrSizes[i].width;
        info.h = randrSizes[i].height;

        int nHz;
        short *rates = XRRConfigRates(config, i, &nHz);

        for (int j = 0; j < nHz; ++j)
            info.rates.push_back(rates[j] * 10);

        infoVector.push_back(info);
    }

    {
        unsigned i = 0;

        while (i < infoVector[fullResIndex].rates.size() && infoVector[fullResIndex].rates[i] != originalRate * 10)
            ++i;

        if (i == infoVector[fullResIndex].rates.size())
            infoVector[fullResIndex].rates.push_back(originalRate * 10);

        fullRateIndex = i;
    }
}
示例#13
0
/*
 Gets current desktop resolution and frequency
*/
static void
libgadget_sidebar_get_size (int *width, int *height, int *width_desktop)
{
	int num_sizes;
	Rotation original_rotation;

	Display *dpy = XOpenDisplay (NULL);
	Window root = RootWindow (dpy, 0);
	XRRScreenSize *xrrs = XRRSizes (dpy, 0, &num_sizes);

	XRRScreenConfiguration *conf = XRRGetScreenInfo (dpy, root);
	short original_rate = XRRConfigCurrentRate (conf);
	SizeID original_size_id = XRRConfigCurrentConfiguration (conf, &original_rotation);

	/* Save data */
	*width = (xrrs[original_size_id].width * PERCENTUAL_WIDTH_SIZE) / 100;
	*width_desktop = xrrs[original_size_id].width;
	*height = xrrs[original_size_id].height - 25;
	
	XCloseDisplay (dpy);
}
示例#14
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 */
示例#15
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();
}
示例#16
0
DisplayModeDescriptor LinuxDisplay::GetDisplayMode() const
{
    DisplayModeDescriptor modeDesc;
    
    auto dpy = GetNative();
    if (auto scr = ScreenOfDisplay(dpy, screen_))
    {
        auto rootWnd = RootWindow(dpy, screen_);
        
        /* Get screen resolution from X11 screen */
        modeDesc.resolution.width   = static_cast<std::uint32_t>(scr->width);
        modeDesc.resolution.height  = static_cast<std::uint32_t>(scr->height);
        
        /* Get refresh reate from X11 extension Xrandr */
        if (auto scrCfg = XRRGetScreenInfo(dpy, rootWnd))
        {
            modeDesc.refreshRate = static_cast<std::uint32_t>(XRRConfigCurrentRate(scrCfg));
            XRRFreeScreenConfigInfo(scrCfg);
        }
    }
    
    return modeDesc;
}
X11EGLSupport::X11EGLSupport()
{
    mNativeDisplay = getNativeDisplay();
    mGLDisplay = getGLDisplay();

    int dummy;

    if (XQueryExtension((Display*)mNativeDisplay, "RANDR", &dummy, &dummy, &dummy))
    {
        XRRScreenConfiguration *screenConfig;

        mRandr = true;
        screenConfig = XRRGetScreenInfo((Display*)mNativeDisplay, DefaultRootWindow((Display*)mNativeDisplay));

        if (screenConfig)
        {
            XRRScreenSize *screenSizes;
            int nSizes = 0;
            Rotation currentRotation;
            int currentSizeID = XRRConfigCurrentConfiguration(screenConfig, &currentRotation);

            screenSizes = XRRConfigSizes(screenConfig, &nSizes);
            mCurrentMode.first.first = screenSizes[currentSizeID].width;
            mCurrentMode.first.second = screenSizes[currentSizeID].height;
            mCurrentMode.second = XRRConfigCurrentRate(screenConfig);
            mOriginalMode = mCurrentMode;

            for (int sizeID = 0; sizeID < nSizes; sizeID++)
            {
                short *rates;
                int nRates = 0;

                rates = XRRConfigRates(screenConfig, sizeID, &nRates);
                for (int rate = 0; rate < nRates; rate++)
                {
                    VideoMode mode;

                    mode.first.first = screenSizes[sizeID].width;
                    mode.first.second = screenSizes[sizeID].height;
                    mode.second = rates[rate];

                    mVideoModes.push_back(mode);
                }
            }
            XRRFreeScreenConfigInfo(screenConfig);
        }
    }
    else
    {
        mCurrentMode.first.first = DisplayWidth((Display*)mNativeDisplay, DefaultScreen(mNativeDisplay));
        mCurrentMode.first.second = DisplayHeight((Display*)mNativeDisplay, DefaultScreen(mNativeDisplay));
        mCurrentMode.second = 0;
        mOriginalMode = mCurrentMode;
        mVideoModes.push_back(mCurrentMode);
    }

    EGLConfig *glConfigs;
    int config, nConfigs = 0;

    glConfigs = chooseGLConfig(NULL, &nConfigs);

    for (config = 0; config < nConfigs; config++)
    {
        int caveat, samples;

        getGLConfigAttrib(glConfigs[config], EGL_CONFIG_CAVEAT, &caveat);

        if (caveat != EGL_SLOW_CONFIG)
        {
            getGLConfigAttrib(glConfigs[config], EGL_SAMPLES, &samples);
            mSampleLevels.push_back(StringConverter::toString(samples));
        }
    }

    free(glConfigs);

    removeDuplicates(mSampleLevels);
}
void XRandRToggler::emitRate() {
    emit rateChange(XRRConfigCurrentRate(config) * 10);
}
示例#19
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));
}
示例#20
0
/*
 * Remembers the current visual settings, so that
 * we can change them and restore later...
 */
void fgPlatformRememberState( void )
{
    int event_base, error_base;

    /*
     * Remember the current pointer location before going fullscreen
     * for restoring it later:
     */
    Window junk_window;
    unsigned int junk_mask;

    XQueryPointer(fgDisplay.pDisplay.Display, fgDisplay.pDisplay.RootWindow,
            &junk_window, &junk_window,
            &fgDisplay.pDisplay.DisplayPointerX, &fgDisplay.pDisplay.DisplayPointerY,
            &fgDisplay.pDisplay.DisplayPointerX, &fgDisplay.pDisplay.DisplayPointerY, &junk_mask);

#   ifdef HAVE_X11_EXTENSIONS_XRANDR_H
    if(XRRQueryExtension(fgDisplay.pDisplay.Display, &event_base, &error_base)) {
        XRRScreenConfiguration *xrr_config;
        XRRScreenSize *ssizes;
        Rotation rot;
        int ssize_count, curr;

        if((xrr_config = XRRGetScreenInfo(fgDisplay.pDisplay.Display, fgDisplay.pDisplay.RootWindow))) {
            ssizes = XRRConfigSizes(xrr_config, &ssize_count);
            curr = XRRConfigCurrentConfiguration(xrr_config, &rot);

            fgDisplay.pDisplay.prev_xsz = ssizes[curr].width;
            fgDisplay.pDisplay.prev_ysz = ssizes[curr].height;
            fgDisplay.pDisplay.prev_refresh = -1;

#       if ( RANDR_MAJOR > 1 ) || ( ( RANDR_MAJOR == 1 ) && ( RANDR_MINOR >= 1 ) )
            if(fgState.GameModeRefresh != -1) {
                fgDisplay.pDisplay.prev_refresh = XRRConfigCurrentRate(xrr_config);
            }
#       endif

            fgDisplay.pDisplay.prev_size_valid = 1;

            XRRFreeScreenConfigInfo(xrr_config);
        }
    }
#   endif

    /*
     * This highly depends on the XFree86 extensions,
     * not approved as X Consortium standards
     */
#   ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
    if(!XF86VidModeQueryExtension(fgDisplay.pDisplay.Display, &event_base, &error_base)) {
        return;
    }

    /*
     * Remember the current ViewPort location of the screen to be able to
     * restore the ViewPort on LeaveGameMode():
     */
    if( !XF86VidModeGetViewPort(
             fgDisplay.pDisplay.Display,
             fgDisplay.pDisplay.Screen,
             &fgDisplay.pDisplay.DisplayViewPortX,
             &fgDisplay.pDisplay.DisplayViewPortY ) )
        fgWarning( "XF86VidModeGetViewPort failed" );


    /* Query the current display settings: */
    fgDisplay.pDisplay.DisplayModeValid =
      XF86VidModeGetModeLine(
        fgDisplay.pDisplay.Display,
        fgDisplay.pDisplay.Screen,
        &fgDisplay.pDisplay.DisplayModeClock,
        &fgDisplay.pDisplay.DisplayMode
    );

    if( !fgDisplay.pDisplay.DisplayModeValid )
        fgWarning( "XF86VidModeGetModeLine failed" );
#   endif

}
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 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(rate <= 0) {
            fgState.GameModeRefresh = XRRConfigCurrentRate(xrr_config);
        }

        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;
}
示例#22
0
	//-------------------------------------------------------------------------------------------------//
	GLXGLSupport::GLXGLSupport() : mGLDisplay(0), mXDisplay(0)
	{
		// A connection that might be shared with the application for GL rendering:
		mGLDisplay = getGLDisplay();
		
		// A connection that is NOT shared to enable independent event processing:
		mXDisplay  = getXDisplay();
		
		int dummy;
		
		if (XQueryExtension(mXDisplay, "RANDR", &dummy, &dummy, &dummy))
		{
			XRRScreenConfiguration *screenConfig;
			
			screenConfig = XRRGetScreenInfo(mXDisplay, DefaultRootWindow(mXDisplay));
			
			if (screenConfig) 
			{
				XRRScreenSize *screenSizes;
				int nSizes = 0;
				Rotation currentRotation;
				int currentSizeID = XRRConfigCurrentConfiguration(screenConfig, &currentRotation);
				
				screenSizes = XRRConfigSizes(screenConfig, &nSizes);
				
				mCurrentMode.first.first = screenSizes[currentSizeID].width;
				mCurrentMode.first.second = screenSizes[currentSizeID].height;
				mCurrentMode.second = XRRConfigCurrentRate(screenConfig);
				
				mOriginalMode = mCurrentMode;
				
				for(int sizeID = 0; sizeID < nSizes; sizeID++) 
				{
					short *rates;
					int nRates = 0;
					
					rates = XRRConfigRates(screenConfig, sizeID, &nRates);
					
					for (int rate = 0; rate < nRates; rate++)
					{
						VideoMode mode;
						
						mode.first.first = screenSizes[sizeID].width;
						mode.first.second = screenSizes[sizeID].height;
						mode.second = rates[rate];
						
						mVideoModes.push_back(mode);
					}
				}
				XRRFreeScreenConfigInfo(screenConfig);
			}
		}
		else
		{
			mCurrentMode.first.first = DisplayWidth(mXDisplay, DefaultScreen(mXDisplay));
			mCurrentMode.first.second = DisplayHeight(mXDisplay, DefaultScreen(mXDisplay));
			mCurrentMode.second = 0;
			
			mOriginalMode = mCurrentMode;
			
			mVideoModes.push_back(mCurrentMode);
		}
		
		GLXFBConfig *fbConfigs;
		int config, nConfigs = 0;
		
		fbConfigs = chooseFBConfig(NULL, &nConfigs);
		
		for (config = 0; config < nConfigs; config++)
		{
			int caveat, samples;
			
			getFBConfigAttrib (fbConfigs[config], GLX_CONFIG_CAVEAT, &caveat);
			
			if (caveat != GLX_SLOW_CONFIG)
			{
				getFBConfigAttrib (fbConfigs[config], GLX_SAMPLES, &samples);
				mSampleLevels.push_back(StringConverter::toString(samples));
			}
		}
		
		XFree (fbConfigs);
		
		remove_duplicates(mSampleLevels);
	}
示例#23
0
/*
 * Remembers the current visual settings, so that
 * we can change them and restore later...
 */
static void fghRememberState( void )
{
#if TARGET_HOST_POSIX_X11
    int event_base, error_base;

    /*
     * Remember the current pointer location before going fullscreen
     * for restoring it later:
     */
    Window junk_window;
    unsigned int junk_mask;

    XQueryPointer(fgDisplay.Display, fgDisplay.RootWindow,
            &junk_window, &junk_window,
            &fgDisplay.DisplayPointerX, &fgDisplay.DisplayPointerY,
            &fgDisplay.DisplayPointerX, &fgDisplay.DisplayPointerY, &junk_mask);

#   ifdef HAVE_X11_EXTENSIONS_XRANDR_H
    if(XRRQueryExtension(fgDisplay.Display, &event_base, &error_base)) {
        XRRScreenConfiguration *xrr_config;
        XRRScreenSize *ssizes;
        Rotation rot;
        int ssize_count, curr;

        if((xrr_config = XRRGetScreenInfo(fgDisplay.Display, fgDisplay.RootWindow))) {
            ssizes = XRRConfigSizes(xrr_config, &ssize_count);
            curr = XRRConfigCurrentConfiguration(xrr_config, &rot);

            fgDisplay.prev_xsz = ssizes[curr].width;
            fgDisplay.prev_ysz = ssizes[curr].height;
            fgDisplay.prev_refresh = -1;

#       if ( RANDR_MAJOR >= 1 ) || ( ( RANDR_MAJOR == 1 ) && ( RANDR_MINOR >= 1 ) )
            if(fgState.GameModeRefresh != -1) {
                fgDisplay.prev_refresh = XRRConfigCurrentRate(xrr_config);
            }
#       endif

            fgDisplay.prev_size_valid = 1;

            XRRFreeScreenConfigInfo(xrr_config);
        }
    }
#   endif

    /*
     * This highly depends on the XFree86 extensions,
     * not approved as X Consortium standards
     */
#   ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
    if(!XF86VidModeQueryExtension(fgDisplay.Display, &event_base, &error_base)) {
        return;
    }

    /*
     * Remember the current ViewPort location of the screen to be able to
     * restore the ViewPort on LeaveGameMode():
     */
    if( !XF86VidModeGetViewPort(
             fgDisplay.Display,
             fgDisplay.Screen,
             &fgDisplay.DisplayViewPortX,
             &fgDisplay.DisplayViewPortY ) )
        fgWarning( "XF86VidModeGetViewPort failed" );


    /* Query the current display settings: */
    fgDisplay.DisplayModeValid =
      XF86VidModeGetModeLine(
        fgDisplay.Display,
        fgDisplay.Screen,
        &fgDisplay.DisplayModeClock,
        &fgDisplay.DisplayMode
    );

    if( !fgDisplay.DisplayModeValid )
        fgWarning( "XF86VidModeGetModeLine failed" );
#   endif

#elif TARGET_HOST_MS_WINDOWS

/*    DEVMODE devMode; */

    /* Grab the current desktop settings... */

/* hack to get around my stupid cross-gcc headers */
#define FREEGLUT_ENUM_CURRENT_SETTINGS -1

    EnumDisplaySettings( fgDisplay.DisplayName, FREEGLUT_ENUM_CURRENT_SETTINGS,
                         &fgDisplay.DisplayMode );

    /* Make sure we will be restoring all settings needed */
    fgDisplay.DisplayMode.dmFields |=
        DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;

#endif
}
示例#24
0
unsigned ScreenProperties::suggestFrameRate()
{
// use XRandR only in X11
#ifndef Q_WS_X11
    return 25;
#else
    int eventBase, errorBase;

    if ( !XRRQueryExtension(QX11Info::display(), &eventBase, &errorBase))
    {
        // No information, make a lucky guess on based on that ;)
        return 25;
    }

    // ask X11 for the refresh rate of the current screen
    XRRScreenConfiguration* config = 0;

    int screenRate;

    config     = XRRGetScreenInfo(QX11Info::display(), RootWindow(QX11Info::display(), activeScreen));
    screenRate = XRRConfigCurrentRate(config);

    XRRFreeScreenConfigInfo(config);

    //qDebug("monitor refresh rate %d Hz", screenRate);

    // Find the frame rate, that matches the monitor's refresh rate best.
    // We will choose between 25, 28 and 30 Hz, to get smooth animations.
    // The following frame rate will be chosen according to the monitor's
    // refresh rate:
    //
    // Frame rate:   Monitor refresh rate
    // 25 Hz         (50), 75, 100 Hz (PAL compliant setups)
    // 28 Hz         85 Hz, 110 Hz    (seems to work ok)
    // 30 Hz         60, 90, 120 Hz   (NTSC compliant setups)
    //
    // However, this will only work, if the kernel can schedule the
    // screensaver at the right time (a 2.6.x kernel should work fine,
    // because of the high HZ value).
    int candidateRate[3] = { 30, 25, 28 };

    int bestRate         = candidateRate[0];
    int smallestError    = 1000, i = 0;

    do
    {
        int r     = candidateRate[i];
        int error = qMin(screenRate % r, (screenRate + r) % r);

        if (error < smallestError)
        {
            smallestError = error;
            bestRate      = r;
        }
    }
    while (++i < 3);

    //qDebug("using %d Hz as framerate for effects", bestRate);
    return bestRate;

#endif // Q_WS_X11
}