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)); }
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 ExtInitRR(int available) { Rotation rot; if (!available) return; /* Listen for RandR events */ XRRSelectInput(disp, WinGetXwin(VROOT), RRScreenChangeNotifyMask); XRRRotations(disp, Dpy.screen, &rot); Mode.screen.rotation = rot; #if 0 /* Debug */ if (EDebug(EDBUG_TYPE_VERBOSE)) { XRRScreenResources *psr; XRRCrtcInfo *pci; XRROutputInfo *poi; int i; psr = XRRGetScreenResources(disp, WinGetXwin(VROOT)); if (!psr) return; Eprintf("CRTC ID X,Y WxH mode rot nout\n"); for (i = 0; i < psr->ncrtc; i++) { pci = XRRGetCrtcInfo(disp, psr, psr->crtcs[i]); if (!pci) break; Eprintf("%3d %#04lx %4d,%4d %4ux%4u %#04lx %4d %5d\n", i, psr->crtcs[i], pci->x, pci->y, pci->width, pci->height, pci->mode, pci->rotation, pci->noutput); XRRFreeCrtcInfo(pci); } Eprintf("OUTP ID Name WxH crtc ncrtc nclon nmode\n"); for (i = 0; i < psr->noutput; i++) { poi = XRRGetOutputInfo(disp, psr, psr->outputs[i]); if (!poi) break; Eprintf("%3d %#04lx %-8s %4lux%4lu %#04lx %4d %5d %5d\n", i, psr->outputs[i], poi->name, poi->mm_width, poi->mm_height, poi->crtc, poi->ncrtc, poi->nclone, poi->nmode); XRRFreeOutputInfo(poi); } XRRFreeScreenResources(psr); } #endif }
/* * @param root window which's primary output will be queried * @return the current orientation of the root window's screen primary output */ EAPI Ecore_X_Randr_Orientation ecore_x_randr_screen_primary_output_orientation_get(Ecore_X_Window root) { #ifdef ECORE_XRANDR Rotation crot = Ecore_X_Randr_None; XRRRotations(_ecore_x_disp, XRRRootToScreen(_ecore_x_disp, root), &crot); return crot; #else /* ifdef ECORE_XRANDR */ return Ecore_X_Randr_None; #endif /* ifdef ECORE_XRANDR */ } /* ecore_x_randr_screen_primary_output_orientation_get */
/* * @param root window which's primary output will be queried */ EAPI Ecore_X_Randr_Orientation ecore_x_randr_screen_primary_output_orientations_get(Ecore_X_Window root) { #ifdef ECORE_XRANDR Rotation rot = Ecore_X_Randr_None, crot; LOGFN(__FILE__, __LINE__, __FUNCTION__); rot = XRRRotations(_ecore_x_disp, XRRRootToScreen(_ecore_x_disp, root), &crot); return rot; #else /* ifdef ECORE_XRANDR */ return Ecore_X_Randr_None; #endif /* ifdef ECORE_XRANDR */ } /* ecore_x_randr_screen_primary_output_orientations_get */
void initialize_xrandr(void) { if (xrandr_present && dpy) { #if LIBVNCSERVER_HAVE_LIBXRANDR Rotation rot; X_LOCK; xrandr_width = XDisplayWidth(dpy, scr); xrandr_height = XDisplayHeight(dpy, scr); XRRRotations(dpy, scr, &rot); xrandr_rotation = (int) rot; if (xrandr || xrandr_maybe) { XRRSelectInput(dpy, rootwin, RRScreenChangeNotifyMask); } else { XRRSelectInput(dpy, rootwin, 0); } X_UNLOCK; #endif } else if (xrandr) { rfbLog("-xrandr mode specified, but no RANDR support on\n"); rfbLog(" display or in client library. Disabling -xrandr " "mode.\n"); xrandr = 0; } }
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 }
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 }
void GuiCalibratorX11::redraw() { if (calibrator->get_geometry() == NULL) { int width; int height; #ifdef HAVE_X11_XRANDR // check that screensize did not change 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; width = rot ? randrsize->height : randrsize->width; height = rot ? randrsize->width : randrsize->height; } else { width = DisplayWidth(display, screen_num); height = DisplayHeight(display, screen_num); } #else width = DisplayWidth(display, screen_num); height = DisplayHeight(display, screen_num); #endif if (display_width != width || display_height != height) { set_display_size(width, height); } } // 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); }