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 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(); }
QSize native_res_for_monitior() { Display* dpy = QX11Info::display(); int major_version_return; int minor_version_return; XRRQueryVersion(dpy, &major_version_return, &minor_version_return); int event_base_return; int error_base_return; if (!XRRQueryExtension(dpy, &event_base_return, &error_base_return)) { return QSize(); } qDebug() << "XRandR extension supported"; int nscreen_sizes = 0; XRRScreenSize * screen_sizes; screen_sizes = XRRSizes(dpy, QX11Info::appScreen(), &nscreen_sizes); for ( int i = 0 ; i < nscreen_sizes; i++ ) { XRRScreenSize ss = screen_sizes[i]; QSize qss(ss.width, ss.height); return qss; } return QSize(); }
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)); }
/* * @brief gets a screen's primary output's possible sizes * @param root window which's primary output will be queried * @param num number of sizes reported as supported by the screen's primary output * @return an array of sizes reported as supported by the screen's primary output or - if query failed - NULL */ EAPI Ecore_X_Randr_Screen_Size_MM * ecore_x_randr_screen_primary_output_sizes_get(Ecore_X_Window root, int *num) { #ifdef ECORE_XRANDR Ecore_X_Randr_Screen_Size_MM *ret = NULL; XRRScreenSize *sizes; int i, n; /* we don't have to free sizes, because they're hold in a cache inside X*/ sizes = XRRSizes(_ecore_x_disp, XRRRootToScreen(_ecore_x_disp, root), &n); if ((!sizes) || (n <= 0)) return NULL; ret = calloc(n, sizeof(Ecore_X_Randr_Screen_Size_MM)); if (!ret) return NULL; if (num) *num = n; for (i = 0; i < n; i++) { ret[i].width = sizes[i].width; ret[i].height = sizes[i].height; ret[i].width_mm = sizes[i].mwidth; ret[i].height_mm = sizes[i].mheight; } return ret; #else /* ifdef ECORE_XRANDR */ return NULL; #endif /* ifdef ECORE_XRANDR */ } /* ecore_x_randr_screen_primary_output_sizes_get */
std::vector<DisplayModeDescriptor> LinuxDisplay::QuerySupportedDisplayModes() const { std::vector<DisplayModeDescriptor> displayModeDescs; DisplayModeDescriptor modeDesc; /* Get all screen sizes from X11 extension Xrandr */ int numSizes = 0; auto scrSizes = XRRSizes(GetNative(), screen_, &numSizes); for (int i = 0; i < numSizes; ++i) { /* Initialize resolution */ modeDesc.resolution.width = static_cast<std::uint32_t>(scrSizes[i].width); modeDesc.resolution.height = static_cast<std::uint32_t>(scrSizes[i].height); /* Add one display mode for each rate */ int numRates = 0; auto rates = XRRRates(GetNative(), screen_, i, &numRates); for (int j = 0; j < numRates; ++j) { modeDesc.refreshRate = static_cast<std::uint32_t>(rates[j]); displayModeDescs.push_back(modeDesc); } } /* Sort final display mode list and remove duplciate entries */ FinalizeDisplayModes(displayModeDescs); return displayModeDescs; }
void GuiCalibratorX11::redraw() { #ifdef HAVE_X11_XRANDR // check that screensize did not change int nsizes; XRRScreenSize* randrsize = XRRSizes(display, screen_num, &nsizes); if (nsizes != 0 && (display_width != randrsize->width || display_height != randrsize->height)) { set_display_size(randrsize->width, randrsize->height); } #endif // Print the text int text_height = font_info->ascent + font_info->descent; int text_width = -1; for (int i = 0; i != help_lines; i++) { text_width = std::max(text_width, XTextWidth(font_info, help_text[i].c_str(), help_text[i].length())); } int x = (display_width - text_width) / 2; int y = (display_height - text_height) / 2 - 60; XSetForeground(display, gc, pixel[BLACK]); XSetLineAttributes(display, gc, 2, LineSolid, CapRound, JoinRound); XDrawRectangle(display, win, gc, x - 10, y - (help_lines*text_height) - 10, text_width + 20, (help_lines*text_height) + 20); // Print help lines y -= 3; for (int i = help_lines-1; i != -1; i--) { int w = XTextWidth(font_info, help_text[i].c_str(), help_text[i].length()); XDrawString(display, win, gc, x + (text_width-w)/2, y, help_text[i].c_str(), help_text[i].length()); y -= text_height; } // Draw the points for (int i = 0; i <= calibrator->get_numclicks(); i++) { // set color: already clicked or not if (i < calibrator->get_numclicks()) XSetForeground(display, gc, pixel[WHITE]); else XSetForeground(display, gc, pixel[RED]); XSetLineAttributes(display, gc, 1, LineSolid, CapRound, JoinRound); XDrawLine(display, win, gc, X[i] - cross_lines, Y[i], X[i] + cross_lines, Y[i]); XDrawLine(display, win, gc, X[i], Y[i] - cross_lines, X[i], Y[i] + cross_lines); XDrawArc(display, win, gc, X[i] - cross_circle, Y[i] - cross_circle, (2 * cross_circle), (2 * cross_circle), 0, 360 * 64); } // Draw the clock background XSetForeground(display, gc, pixel[DIMGRAY]); XSetLineAttributes(display, gc, 0, LineSolid, CapRound, JoinRound); XFillArc(display, win, gc, (display_width-clock_radius)/2, (display_height - clock_radius)/2, clock_radius, clock_radius, 0, 360 * 64); }
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; }
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!"); } }
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; }
bool C4AbstractApp::GetIndexedDisplayMode(int32_t iIndex, int32_t *piXRes, int32_t *piYRes, int32_t *piBitDepth, int32_t *piRefreshRate, uint32_t iMonitor) { #ifdef GDK_WINDOWING_X11 Display * const dpy = gdk_x11_display_get_xdisplay(gdk_display_get_default()); int n; XRRScreenSize * sizes = XRRSizes(dpy, XDefaultScreen(dpy), &n); if (iIndex < n && iIndex >= 0) { *piXRes = sizes[iIndex].width; *piYRes = sizes[iIndex].height; *piBitDepth = 32; return true; } return false; #endif }
/* * @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 CDisplaySettingsList::GetAllDisplaySettings( void ) { int numsizes; XRRScreenSize *xrrs; Display *dpy; int index = 0; dpy = XOpenDisplay(NULL); xrrs = XRRSizes(dpy, 0, &numsizes); clear(); for (int wn = 0; wn < numsizes; wn++) { CDisplaySettings settings; short *pfreq; int numfreq; pfreq = XRRRates(dpy, 0, wn, &numfreq ); for (int freq = 0; freq < numfreq; freq++) { settings.m_index = index++; settings.m_pelswidth = xrrs[freq].width; settings.m_pelsheight = xrrs[freq].height; settings.m_displayvertfreq = pfreq[freq]; settings.m_bitsperpel = -1; // The horizontal freq must be width * height * vertfreq settings.m_displayhorizfreq = settings.m_pelsheight * settings.m_displayvertfreq; if ( settings.m_bitsperpel > 0) { settings.m_displayhorizfreq *= settings.m_bitsperpel; }; settings.m_displaybandwidth = settings.m_displayhorizfreq * settings.m_pelswidth; push_back(settings); } } }
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); } } }
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 }
/* 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); }
/* * @brief sets a given screen's primary output size, but disables all other outputs at the same time * @param root window which's primary output will be queried * @param size_index within the list of sizes reported as supported by the root window's screen primary output * @return EINA_TRUE on success, EINA_FALSE on failure due to e.g. invalid times */ EAPI Eina_Bool ecore_x_randr_screen_primary_output_size_set(Ecore_X_Window root, int size_index) { #ifdef ECORE_XRANDR XRRScreenConfiguration *sc = NULL; XRRScreenSize *sizes; Eina_Bool ret = EINA_FALSE; int nsizes = 0; if (size_index >= 0 && _ecore_x_randr_root_validate(root)) { sizes = XRRSizes(_ecore_x_disp, XRRRootToScreen(_ecore_x_disp, root), &nsizes); if (size_index < nsizes) { sc = XRRGetScreenInfo(_ecore_x_disp, root); if (!XRRSetScreenConfig(_ecore_x_disp, sc, root, size_index, ECORE_X_RANDR_ORIENTATION_ROT_0, CurrentTime)) { ret = EINA_TRUE; } if (sc) XRRFreeScreenConfigInfo(sc); } } return ret; #else /* ifdef ECORE_XRANDR */ return EINA_FALSE; #endif /* ifdef ECORE_XRANDR */ } /* ecore_x_randr_screen_primary_output_size_set */
GuiCalibratorX11::GuiCalibratorX11(Calibrator* calibrator0) : calibrator(calibrator0), time_elapsed(0) { display = XOpenDisplay(NULL); if (display == NULL) { throw std::runtime_error("Unable to connect to X server"); } screen_num = DefaultScreen(display); // Load font and get font information structure font_info = XLoadQueryFont(display, "9x15"); if (font_info == NULL) { // fall back to native font font_info = XLoadQueryFont(display, "fixed"); if (font_info == NULL) { XCloseDisplay(display); throw std::runtime_error("Unable to open neither '9x15' nor 'fixed' font"); } } #ifdef HAVE_X11_XRANDR // get screensize from xrandr int nsizes; XRRScreenSize* randrsize = XRRSizes(display, screen_num, &nsizes); if (nsizes != 0) { Rotation current = 0; XRRRotations(display, screen_num, ¤t); bool rot = current & RR_Rotate_90 || current & RR_Rotate_270; int width = rot ? randrsize->height : randrsize->width; int height = rot ? randrsize->width : randrsize->height; set_display_size(width, height); } else { set_display_size(DisplayWidth(display, screen_num), DisplayHeight(display, screen_num)); } # else set_display_size(DisplayWidth(display, screen_num), DisplayHeight(display, screen_num)); #endif // parse geometry string const char* geo = calibrator->get_geometry(); if (geo != NULL) { int gw,gh; int res = sscanf(geo,"%dx%d",&gw,&gh); if (res != 2) { fprintf(stderr,"Warning: error parsing geometry string - using defaults.\n"); } else { set_display_size( gw, gh ); } } // Register events on the window XSetWindowAttributes attributes; attributes.override_redirect = True; attributes.event_mask = ExposureMask | KeyPressMask | ButtonPressMask; win = XCreateWindow(display, RootWindow(display, screen_num), 0, 0, display_width, display_height, 0, CopyFromParent, InputOutput, CopyFromParent, CWOverrideRedirect | CWEventMask, &attributes); XMapWindow(display, win); // Listen to events XGrabKeyboard(display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime); XGrabPointer(display, win, False, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); Colormap colormap = DefaultColormap(display, screen_num); XColor color; for (int i = 0; i != NUM_COLORS; i++) { XParseColor(display, colormap, colors[i], &color); XAllocColor(display, colormap, &color); pixel[i] = color.pixel; } XSetWindowBackground(display, win, pixel[GRAY]); XClearWindow(display, win); gc = XCreateGC(display, win, 0, NULL); XSetFont(display, gc, font_info->fid); // Setup timer for animation #ifdef HAVE_TIMERFD struct itimerspec timer; unsigned int period = time_step * 1000; // microseconds unsigned int sec = period/1000000; unsigned int ns = (period - (sec * 1000000)) * 1000; timer.it_value.tv_sec = sec; timer.it_value.tv_nsec = ns; timer.it_interval = timer.it_value; timer_fd = timerfd_create(CLOCK_MONOTONIC, 0); timerfd_settime(timer_fd, 0, &timer, NULL); #else signal(SIGALRM, sigalarm_handler); struct itimerval timer; timer.it_value.tv_sec = time_step/1000; timer.it_value.tv_usec = (time_step % 1000) * 1000; timer.it_interval = timer.it_value; setitimer(ITIMER_REAL, &timer, NULL); #endif }
GuiCalibratorX11::GuiCalibratorX11(Calibrator* calibrator0) : calibrator(calibrator0), time_elapsed(0) { display = XOpenDisplay(NULL); if (display == NULL) { throw std::runtime_error("Unable to connect to X server"); } screen_num = DefaultScreen(display); // Load font and get font information structure font_info = XLoadQueryFont(display, "9x15"); if (font_info == NULL) { // fall back to native font font_info = XLoadQueryFont(display, "fixed"); if (font_info == NULL) { XCloseDisplay(display); throw std::runtime_error("Unable to open neither '9x15' nor 'fixed' font"); } } #ifdef HAVE_X11_XRANDR // get screensize from xrandr int nsizes; XRRScreenSize* randrsize = XRRSizes(display, screen_num, &nsizes); if (nsizes != 0) { set_display_size(randrsize->width, randrsize->height); } else { set_display_size(DisplayWidth(display, screen_num), DisplayHeight(display, screen_num)); } # else set_display_size(DisplayWidth(display, screen_num), DisplayHeight(display, screen_num)); #endif // Register events on the window XSetWindowAttributes attributes; attributes.override_redirect = True; attributes.event_mask = ExposureMask | KeyPressMask | ButtonPressMask; win = XCreateWindow(display, RootWindow(display, screen_num), 0, 0, display_width, display_height, 0, CopyFromParent, InputOutput, CopyFromParent, CWOverrideRedirect | CWEventMask, &attributes); XMapWindow(display, win); // Listen to events XGrabKeyboard(display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime); calib_input = calibrator->register_events(); if (!calib_input) { XGrabPointer(display, win, False, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); } Colormap colormap = DefaultColormap(display, screen_num); XColor color; for (int i = 0; i != nr_colors; i++) { XParseColor(display, colormap, colors[i], &color); XAllocColor(display, colormap, &color); pixel[i] = color.pixel; } XSetWindowBackground(display, win, pixel[GRAY]); XClearWindow(display, win); gc = XCreateGC(display, win, 0, NULL); XSetFont(display, gc, font_info->fid); // Setup timer for animation signal(SIGALRM, sigalarm_handler); struct itimerval timer; timer.it_value.tv_sec = time_step/1000; timer.it_value.tv_usec = (time_step % 1000) * 1000; timer.it_interval = timer.it_value; setitimer(ITIMER_REAL, &timer, NULL); }
bool iRandR::reload( bool _overwriteLatest, bool _overwriteDefaults ) { if ( !vIsRandRSupported_B ) return false; SizeID lTemoID_suI; int lTempSizes_I; Rotation lTempRotate_XRR; // Exists only for XRRConfigCurrentConfiguration(...); to make it happy vConfig_XRR = XRRGetScreenInfo( vDisplay_X11, vRootWindow_X11 ); vResources_XRR = XRRGetScreenResources( vDisplay_X11, vRootWindow_X11 ); lTemoID_suI = XRRConfigCurrentConfiguration( vConfig_XRR, &lTempRotate_XRR ); XRRScreenSize *lTempSizes_XRR = XRRSizes( vDisplay_X11, 0, &lTempSizes_I ); if ( lTemoID_suI < lTempSizes_I ) { vScreenWidth_uI = static_cast<unsigned>( lTempSizes_XRR[lTemoID_suI].width ); vScreenHeight_uI = static_cast<unsigned>( lTempSizes_XRR[lTemoID_suI].height ); } if ( _overwriteLatest ) { vLatestConfig_RandR.primary = XRRGetOutputPrimary( vDisplay_X11, vRootWindow_X11 ); for ( auto &elem : vLatestConfig_RandR.gamma ) XRRFreeGamma( elem ); vLatestConfig_RandR.gamma.clear(); for ( int i = 0; i < vResources_XRR->ncrtc; ++i ) { vLatestConfig_RandR.gamma.push_back( XRRGetCrtcGamma( vDisplay_X11, vResources_XRR->crtcs[i] ) ); } } if ( _overwriteDefaults ) { vDefaultConfig_RandR.primary = XRRGetOutputPrimary( vDisplay_X11, vRootWindow_X11 ); for ( auto &elem : vDefaultConfig_RandR.gamma ) XRRFreeGamma( elem ); vDefaultConfig_RandR.gamma.clear(); for ( int i = 0; i < vResources_XRR->ncrtc; ++i ) { vDefaultConfig_RandR.gamma.push_back( XRRGetCrtcGamma( vDisplay_X11, vResources_XRR->crtcs[i] ) ); } } // Clear old data vCRTC_V_RandR.clear(); vOutput_V_RandR.clear(); vMode_V_RandR.clear(); vLatestConfig_RandR.CRTCInfo.clear(); // CRTC for ( int i = 0; i < vResources_XRR->ncrtc; ++i ) { internal::_crtc lTempCRTC_RandR; XRRCrtcInfo *lTempCRTCInfo_XRR = XRRGetCrtcInfo( vDisplay_X11, vResources_XRR, vResources_XRR->crtcs[i] ); lTempCRTC_RandR.id = vResources_XRR->crtcs[i]; lTempCRTC_RandR.timestamp = lTempCRTCInfo_XRR->timestamp; lTempCRTC_RandR.posX = lTempCRTCInfo_XRR->x; lTempCRTC_RandR.posY = lTempCRTCInfo_XRR->y; lTempCRTC_RandR.width = lTempCRTCInfo_XRR->width; lTempCRTC_RandR.height = lTempCRTCInfo_XRR->height; lTempCRTC_RandR.mode = lTempCRTCInfo_XRR->mode; lTempCRTC_RandR.rotation = lTempCRTCInfo_XRR->rotation; lTempCRTC_RandR.rotations = lTempCRTCInfo_XRR->rotations; for ( int j = 0; j < lTempCRTCInfo_XRR->noutput; ++j ) { lTempCRTC_RandR.outputs.push_back( lTempCRTCInfo_XRR->outputs[j] ); } for ( int j = 0; j < lTempCRTCInfo_XRR->npossible; ++j ) { lTempCRTC_RandR.possibleOutputs.push_back( lTempCRTCInfo_XRR->possible[j] ); } vCRTC_V_RandR.push_back( lTempCRTC_RandR ); XRRFreeCrtcInfo( lTempCRTCInfo_XRR ); } // Output for ( int i = 0; i < vResources_XRR->noutput; ++i ) { internal::_output lTempOutput_RandR; XRROutputInfo *lTempOutputInfo_XRR = XRRGetOutputInfo( vDisplay_X11, vResources_XRR, vResources_XRR->outputs[i] ); lTempOutput_RandR.id = vResources_XRR->outputs[i]; lTempOutput_RandR.timestamp = lTempOutputInfo_XRR->timestamp; lTempOutput_RandR.crtc = lTempOutputInfo_XRR->crtc; lTempOutput_RandR.name = lTempOutputInfo_XRR->name; lTempOutput_RandR.mm_width = lTempOutputInfo_XRR->mm_width; lTempOutput_RandR.mm_height = lTempOutputInfo_XRR->mm_height; lTempOutput_RandR.connection = lTempOutputInfo_XRR->connection; lTempOutput_RandR.subpixel_order = lTempOutputInfo_XRR->subpixel_order; lTempOutput_RandR.npreferred = lTempOutputInfo_XRR->npreferred; for ( int j = 0; j < lTempOutputInfo_XRR->ncrtc; ++j ) { lTempOutput_RandR.crtcs.push_back( lTempOutputInfo_XRR->crtcs[j] ); } for ( int j = 0; j < lTempOutputInfo_XRR->nclone; ++j ) { lTempOutput_RandR.clones.push_back( lTempOutputInfo_XRR->clones[j] ); } for ( int j = 0; j < lTempOutputInfo_XRR->nmode; ++j ) { lTempOutput_RandR.modes.push_back( lTempOutputInfo_XRR->modes[j] ); } vOutput_V_RandR.push_back( lTempOutput_RandR ); XRRFreeOutputInfo( lTempOutputInfo_XRR ); } // Modes for ( int i = 0; i < vResources_XRR->nmode; ++i ) { internal::_mode lTempMode_RandR; XRRModeInfo lTempModeInfo_XRR = vResources_XRR->modes[i]; lTempMode_RandR.id = lTempModeInfo_XRR.id; lTempMode_RandR.width = lTempModeInfo_XRR.width; lTempMode_RandR.height = lTempModeInfo_XRR.height; lTempMode_RandR.dotClock = lTempModeInfo_XRR.dotClock; lTempMode_RandR.hSyncStart = lTempModeInfo_XRR.hSyncStart; lTempMode_RandR.hSyncEnd = lTempModeInfo_XRR.hSyncEnd; lTempMode_RandR.hTotal = lTempModeInfo_XRR.hTotal; lTempMode_RandR.hSkew = lTempModeInfo_XRR.hSkew; lTempMode_RandR.vSyncStart = lTempModeInfo_XRR.vSyncStart; lTempMode_RandR.vSyncEnd = lTempModeInfo_XRR.vSyncEnd; lTempMode_RandR.vTotal = lTempModeInfo_XRR.vTotal; lTempMode_RandR.name = lTempModeInfo_XRR.name; lTempMode_RandR.modeFlags = lTempModeInfo_XRR.modeFlags; /* v refresh frequency in Hz */ unsigned int lVTotalTemp = lTempMode_RandR.vTotal; if ( lTempMode_RandR.modeFlags & RR_DoubleScan ) lVTotalTemp *= 2; if ( lTempMode_RandR.modeFlags & RR_Interlace ) lVTotalTemp /= 2; if ( lTempMode_RandR.hTotal && lVTotalTemp ) lTempMode_RandR.refresh = ( static_cast<double>( lTempMode_RandR.dotClock ) / ( static_cast<double>( lTempMode_RandR.hTotal ) * static_cast<double>( lVTotalTemp ) ) ); else lTempMode_RandR.refresh = 0; /* h sync frequency in Hz */ if ( lTempMode_RandR.hTotal ) lTempMode_RandR.syncFreq = lTempMode_RandR.dotClock / lTempMode_RandR.hTotal; else lTempMode_RandR.syncFreq = 0; vMode_V_RandR.push_back( lTempMode_RandR ); } vLatestConfig_RandR.CRTCInfo = vCRTC_V_RandR; if ( _overwriteLatest ) vDefaultConfig_RandR.CRTCInfo = vCRTC_V_RandR; vMode_V_RandR.sort(); return true; }
void GuiCalibratorX11::detect_screen_geometry(int *width, int *height, int *x, int *y) { #ifdef HAVE_X11_XRANDR int ox = 0, oy = 0, gw = 0, gh = 0; if (calibrator->get_x_output()) { XRRScreenResources *resources = XRRGetScreenResources(display, RootWindow(display, screen_num)); // Get the XID of the CRTC the selected output is connected to. RRCrtc crtc = get_crtc_id(display, resources, calibrator->get_x_output()); if (crtc != (RRCrtc) -1) { XRRCrtcInfo *crtc_info = XRRGetCrtcInfo(display, resources, crtc); if (crtc_info->mode != None && crtc_info->noutput > 0) { ox = crtc_info->x; oy = crtc_info->y; gw = crtc_info->width; gh = crtc_info->height; } else printf("Warning: output \"%s\" resulted in an invalid CRTC.\n", calibrator->get_x_output()); XRRFreeCrtcInfo(crtc_info); } XRRFreeScreenResources(resources); } if (gw == 0 || gh == 0) { int nsizes = 0; XRRScreenSize *randrsize = XRRSizes(display, screen_num, &nsizes); if (nsizes != 0) { Rotation current_rotation = 0; XRRScreenConfiguration *sc = XRRGetScreenInfo(display, RootWindow(display, screen_num)); int current_size = XRRConfigCurrentConfiguration(sc, ¤t_rotation); if (current_size < nsizes) { XRRRotations(display, screen_num, ¤t_rotation); randrsize += current_size; bool rot = current_rotation & RR_Rotate_90 || current_rotation & RR_Rotate_270; gw = rot ? randrsize->height : randrsize->width; gh = rot ? randrsize->width : randrsize->height; } } } // Get screensize from xrandr if (gw > 0 && gh > 0) { *width = gw; *height = gh; } else { *width = DisplayWidth(display, screen_num); *height = DisplayHeight(display, screen_num); } if (x && y) { *x = ox; *y = oy; } # else *width = DisplayWidth(display, screen_num); *height = DisplayHeight(display, screen_num); if (x && y) { *x = 0; *y = 0; } #endif }
/* * 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); }