//////////////////////////////////////////////////////////// /// 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; } }
void Viewer::OnResize(const CVD::ImageRef &size) { m_pWnd->set_size(size); int x_pos, y_pos; #ifdef WIN32 x_pos = (GetSystemMetrics(SM_CXSCREEN) - size.x) / 2; y_pos = (GetSystemMetrics(SM_CYSCREEN) - size.y) / 2; #elif defined(__linux__) int num_sizes; Display *dpy = XOpenDisplay(NULL); Window root = RootWindow(dpy, 0); XRRScreenSize *xrrs = XRRSizes(dpy, 0, &num_sizes); XRRScreenConfiguration *conf = XRRGetScreenInfo(dpy, root); Rotation original_rotation; SizeID original_size_id = XRRConfigCurrentConfiguration(conf, &original_rotation); x_pos = (xrrs[original_size_id].width - size.x) / 2; y_pos = (xrrs[original_size_id].height - size.y) / 2; XCloseDisplay(dpy); #else // TODO(mingyu): OSX support #endif m_pWnd->set_position(CVD::ImageRef(x_pos, y_pos)); glViewport(0, 0, size.x, size.y); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, size.x, size.y, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }
void Viewer::Initialize(const int w, const int h) { if (!m_pWnd) { #ifndef WIN32 // TODO(mingyu): Why no need to glutInit on Windows? int argc = 0; char** argv; glutInit(&argc, argv); #endif m_pWnd = new CVD::GLWindow(CVD::ImageRef(w, h)); int x_pos, y_pos; #ifdef WIN32 x_pos = (GetSystemMetrics(SM_CXSCREEN) - w) / 2; y_pos = (GetSystemMetrics(SM_CYSCREEN) - h) / 2; #elif defined(__linux__) int num_sizes; Display *dpy = XOpenDisplay(NULL); Window root = RootWindow(dpy, 0); XRRScreenSize *xrrs = XRRSizes(dpy, 0, &num_sizes); XRRScreenConfiguration *conf = XRRGetScreenInfo(dpy, root); Rotation original_rotation; SizeID original_size_id = XRRConfigCurrentConfiguration(conf, &original_rotation); x_pos = (xrrs[original_size_id].width - w) / 2; y_pos = (xrrs[original_size_id].height - h) / 2; XCloseDisplay(dpy); #else // TODO(mingyu): OSX support #endif m_pWnd->set_position(CVD::ImageRef(x_pos, y_pos)); glewInit(); } OnResize(CVD::ImageRef(w, h)); m_handler.Initialize(this, &Viewer::OnKeyDown, &Viewer::OnKeyUp, &Viewer::OnMouseMove, &Viewer::OnMouseDown, &Viewer::OnMouseUp, &Viewer::OnMouseDraging, &Viewer::OnMouseDoubleClicked, &Viewer::OnResize); }
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, ¤t_rotation); XRRSetScreenConfigAndRate(display, screenConfig, rootWnd, size, current_rotation, mode.refreshRate, CurrentTime); XRRFreeScreenConfigInfo(screenConfig); Trace(String("Video mode changed to:") + VideoMode::ToString(mode)); } } }
/* ** VID_GetDisplaySize */ qboolean VID_GetDisplaySize( int *width, int *height ) { XRRScreenConfiguration *xrrConfig; XRRScreenSize *xrrSizes; Display *dpy; Window root; Rotation rotation; SizeID size_id; int num_sizes; dpy = XOpenDisplay( NULL ); if( dpy ) { root = DefaultRootWindow( dpy ); xrrConfig = XRRGetScreenInfo( dpy, root ); xrrSizes = XRRConfigSizes( xrrConfig, &num_sizes ); size_id = XRRConfigCurrentConfiguration( xrrConfig, &rotation ); *width = xrrSizes[size_id].width; *height = xrrSizes[size_id].height; XCloseDisplay( dpy ); return qtrue; } return qfalse; }
/* * @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 */
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)); }
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 }
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; }
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; }
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; }
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; } }
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, ¤tRotation); // 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; }
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, ¤tRotation); 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"); } } }
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, ¤t_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 ; }
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!"); } }
//////////////////////////////////////////////////////////// /// 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; } }
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; }
/** * 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; }
/* * @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 */
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()), ¤t_time); qDebug() << "RotationDaemon::rotate(" << angle << ")"; XRRSetScreenConfigAndRate(QX11Info::display(), config, DefaultRootWindow(QX11Info::display()), size, angle, rate, timestamp); }
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, ¤t_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 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); } } }
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; } }
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 }
const QRect XRandRToggler::fullScreenRect(const QWidget */*wdgt*/) const { int w, h; { int nSizes = 0; XRRScreenSize *randrSizes = XRRConfigSizes(config, &nSizes); Rotation rot = rotation; SizeID currentID = XRRConfigCurrentConfiguration(config, &rot); if (currentID < nSizes) { w = randrSizes[currentID].width; h = randrSizes[currentID].height; } else { w = infoVector[fullResIndex].w; h = infoVector[fullResIndex].h; } } return QRect(0, 0, w, h); }
/* 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); }
/* * 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(); }
void CommandInterpreter::queryResolution() { int numberSizes; Rotation originalRotation; XRRScreenSize *xrrs = XRRSizes(display, 0, &numberSizes); XRRScreenConfiguration *configuration = XRRGetScreenInfo(display, RootWindow(display, 0)); SizeID originalSize = XRRConfigCurrentConfiguration(configuration, &originalRotation); displayXResolution = xrrs[originalSize].width; displayYResolution = xrrs[originalSize].height; xOrigin = displayXResolution / 2; yOrigin = displayYResolution / 2; upBound = 70; downBound = displayYResolution - 70; printf("Server Dimensions: %i x %i.\n", displayXResolution, displayYResolution); printf("Origin of Screen %i: (%i, %i).\n", DefaultScreen(display), xOrigin, yOrigin); }