void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) { if (_glfw.x11.randr.available) { XRRScreenResources* sr; XRRCrtcInfo* ci; sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root); ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); if (xpos) *xpos = ci->x; if (ypos) *ypos = ci->y; XRRFreeCrtcInfo(ci); XRRFreeScreenResources(sr); } else { if (xpos) *xpos = 0; if (ypos) *ypos = 0; } }
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) { if (_glfw.x11.randr.available) { XRRScreenResources* sr; XRRCrtcInfo* ci; sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root); ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); mode->width = ci->width; mode->height = ci->height; mode->refreshRate = calculateRefreshRate(getModeInfo(sr, ci->mode)); XRRFreeCrtcInfo(ci); XRRFreeScreenResources(sr); } else { mode->width = DisplayWidth(_glfw.x11.display, _glfw.x11.screen); mode->height = DisplayHeight(_glfw.x11.display, _glfw.x11.screen); mode->refreshRate = 0; } _glfwSplitBPP(DefaultDepth(_glfw.x11.display, _glfw.x11.screen), &mode->redBits, &mode->greenBits, &mode->blueBits); }
static int map_output_xrandr(Display *dpy, int deviceid, const char *output_name) { int rc = EXIT_FAILURE; XRRScreenResources *res; XRROutputInfo *output_info; res = XRRGetScreenResources(dpy, DefaultRootWindow(dpy)); output_info = find_output_xrandr(dpy, output_name); /* crtc holds our screen info, need to compare to actual screen size */ if (output_info) { XRRCrtcInfo *crtc_info; Matrix m; matrix_set_unity(&m); crtc_info = XRRGetCrtcInfo (dpy, res, output_info->crtc); set_transformation_matrix(dpy, &m, crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height); rc = apply_matrix(dpy, deviceid, &m); XRRFreeCrtcInfo(crtc_info); XRRFreeOutputInfo(output_info); } else printf("Unable to find output '%s'. " "Output may not be connected.\n", output_name); XRRFreeScreenResources(res); return rc; }
// Restore the saved (original) video mode for the specified monitor // void _glfwRestoreVideoMode(_GLFWmonitor* monitor) { if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) { XRRScreenResources* sr; XRRCrtcInfo* ci; if (monitor->x11.oldMode == None) return; sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root); ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); XRRSetCrtcConfig(_glfw.x11.display, sr, monitor->x11.crtc, CurrentTime, ci->x, ci->y, monitor->x11.oldMode, ci->rotation, ci->outputs, ci->noutput); XRRFreeCrtcInfo(ci); XRRFreeScreenResources(sr); monitor->x11.oldMode = None; } }
int main() { Display *disp; XRRScreenResources *screen; XRROutputInfo *info; XRRCrtcInfo *crtc_info; int iscres; int icrtc; disp = XOpenDisplay(0); screen = XRRGetScreenResources (disp, DefaultRootWindow(disp)); for (iscres = screen->noutput; iscres > 0; ) { --iscres; info = XRRGetOutputInfo (disp, screen, screen->outputs[iscres]); if (info->connection == RR_Connected) { for (icrtc = info->ncrtc; icrtc > 0;) { --icrtc; crtc_info = XRRGetCrtcInfo (disp, screen, screen->crtcs[icrtc]); fprintf(stderr, "==> %dx%d+%dx%d\n", crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height); XRRFreeCrtcInfo(crtc_info); } } XRRFreeOutputInfo (info); } XRRFreeScreenResources(screen); return 0; }
static void xfce_randr_cleanup (XfceRandr *randr) { guint n; /* free the output/mode info cache */ for (n = 0; n < randr->noutput; ++n) { if (G_LIKELY (randr->priv->output_info[n])) XRRFreeOutputInfo (randr->priv->output_info[n]); if (G_LIKELY (randr->priv->modes[n])) g_free (randr->priv->modes[n]); if (G_LIKELY (randr->friendly_name[n])) g_free (randr->friendly_name[n]); } /* free the screen resources */ XRRFreeScreenResources (randr->priv->resources); /* free the settings */ g_free (randr->friendly_name); g_free (randr->mode); g_free (randr->priv->modes); g_free (randr->rotation); g_free (randr->rotations); g_free (randr->status); g_free (randr->position); g_free (randr->mirrored); g_free (randr->priv->output_info); }
/* Caller must free return value */ static XRROutputInfo* find_output_xrandr(Display *dpy, const char *output_name) { XRRScreenResources *res; XRROutputInfo *output_info = NULL; int i; int found = 0; res = XRRGetScreenResources(dpy, DefaultRootWindow(dpy)); for (i = 0; i < res->noutput && !found; i++) { output_info = XRRGetOutputInfo(dpy, res, res->outputs[i]); if (output_info->crtc && output_info->connection == RR_Connected && strcmp(output_info->name, output_name) == 0) { found = 1; break; } XRRFreeOutputInfo(output_info); } XRRFreeScreenResources(res); if (!found) output_info = NULL; return output_info; }
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) { GLFWvidmode* result; *found = 0; // Build array of available resolutions if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) { int i, j; XRRScreenResources* sr; XRROutputInfo* oi; sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root); oi = XRRGetOutputInfo(_glfw.x11.display, sr, monitor->x11.output); result = calloc(oi->nmode, sizeof(GLFWvidmode)); for (i = 0; i < oi->nmode; i++) { const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]); if (!modeIsGood(mi)) continue; const GLFWvidmode mode = vidmodeFromModeInfo(mi); for (j = 0; j < *found; j++) { if (result[j].width == mode.width && result[j].height == mode.height && result[j].refreshRate == mode.refreshRate) { break; } } if (j < *found) { // This is a duplicate, so skip it continue; } result[*found] = mode; (*found)++; } XRRFreeOutputInfo(oi); XRRFreeScreenResources(sr); } else { *found = 1; result = calloc(1, sizeof(GLFWvidmode)); _glfwPlatformGetVideoMode(monitor, result); } return result; }
/* * Class: jogamp_newt_driver_x11_RandR13 * Method: freeScreenResources0 * Signature: (J)V */ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_RandR13_freeScreenResources0 (JNIEnv *env, jclass clazz, jlong screenResources) { XRRScreenResources *resources = (XRRScreenResources *) (intptr_t) screenResources; if( NULL != resources ) { XRRFreeScreenResources( resources ); } }
void UpdateHardwareGamma(void) { float gamma = (vid_gamma->value); int i; Display* dpy = NULL; SDL_SysWMinfo info; #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_VERSION(&info.version); if(!SDL_GetWindowWMInfo(window, &info)) #else if(SDL_GetWMInfo(&info) != 1) #endif { VID_Printf(PRINT_ALL, "Couldn't get Window info from SDL\n"); return; } dpy = info.info.x11.display; XRRScreenResources* res = XRRGetScreenResources(dpy, info.info.x11.window); if(res == NULL) { VID_Printf(PRINT_ALL, "Unable to get xrandr screen resources.\n"); return; } for(i=0; i < res->ncrtc; ++i) { int len = XRRGetCrtcGammaSize(dpy, res->crtcs[i]); size_t rampSize = len*sizeof(Uint16); Uint16* ramp = malloc(rampSize); // TODO: check for NULL if(ramp == NULL) { VID_Printf(PRINT_ALL, "Couldn't allocate &zd byte of memory for gamma ramp - OOM?!\n", rampSize); return; } CalculateGammaRamp(gamma, ramp, len); XRRCrtcGamma* gamma = XRRAllocGamma(len); memcpy(gamma->red, ramp, rampSize); memcpy(gamma->green, ramp, rampSize); memcpy(gamma->blue, ramp, rampSize); free(ramp); XRRSetCrtcGamma(dpy, res->crtcs[i], gamma); XRRFreeGamma(gamma); } XRRFreeScreenResources(res); }
static void randrd(void) { XRRScreenResources *resources; XRROutputInfo *info; XRROutputChangeNotifyEvent *rrocevt; XRRNotifyEvent *rrevt; char *new_edidhash; Window root; XEvent evt; exec_script(script, "init", "", current_edidhash); XRRSelectInput(dpy, DefaultRootWindow(dpy), RROutputChangeNotifyMask); while (!quit) { root = RootWindow(dpy, DefaultScreen(dpy)); resources = XRRGetScreenResources(dpy, root); while (XPending(dpy)) { XNextEvent(dpy, &evt); if (evt.type != rr_event_base + RRNotify) continue; rrevt = (XRRNotifyEvent *)&evt; if (rrevt->subtype != RRNotify_OutputChange) continue; new_edidhash = getedidhash1(resources); if (new_edidhash == NULL) continue; if (!strcmp(current_edidhash, new_edidhash)) { free(new_edidhash); continue; } free(current_edidhash); current_edidhash = new_edidhash; rrocevt = (XRROutputChangeNotifyEvent *)&evt; info = XRRGetOutputInfo(rrocevt->display, resources, rrocevt->output); syslog(LOG_INFO, "%s %s", info->name, connstates[info->connection]); exec_script(script, connstates[info->connection], info->name, new_edidhash); XRRFreeOutputInfo(info); } XRRFreeScreenResources(resources); sleep(interval); } }
MonitorManager *monitor_mgr_create() { Display *display = XOpenDisplay(NULL); if (!display) { fprintf(stderr, "Cannot open display.\n"); return NULL; } MonitorManager *mgr = malloc(sizeof(MonitorManager*)); mgr->monitor_count = 0; mgr->monitors = NULL; Window root = DefaultRootWindow(display); RROutput primary_output = XRRGetOutputPrimary(display, root); XRRScreenResources *screen = XRRGetScreenResources(display, root); assert(screen); for (int i = 0; i < screen->noutput; i++) { XRROutputInfo *output_info = XRRGetOutputInfo( display, screen, screen->outputs[i]); assert(output_info); if (output_info->connection == RR_Connected) { XRRCrtcInfo *crtc_info = XRRGetCrtcInfo( display, screen, output_info->crtc); assert(crtc_info); int primary = 0; for (int j = 0; j < crtc_info->noutput; j++) if (crtc_info->outputs[j] == primary_output) primary = 1; Monitor *monitor = monitor_create( primary, crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height); assert(monitor); monitor_mgr_add(mgr, monitor); XRRFreeCrtcInfo(crtc_info); } XRRFreeOutputInfo(output_info); } XRRFreeScreenResources(screen); XCloseDisplay(display); return mgr; }
static void RestoreGamma() { int i=0; SDL_SysWMinfo info; Display* dpy = NULL; if(gammaRamps == NULL) return; #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_VERSION(&info.version); if(!SDL_GetWindowWMInfo(window, &info)) #else if(SDL_GetWMInfo(&info) != 1) #endif { VID_Printf(PRINT_ALL, "Couldn't get Window info from SDL\n"); return; } dpy = info.info.x11.display; XRRScreenResources* res = XRRGetScreenResources(dpy, info.info.x11.window); if(res == NULL) { VID_Printf(PRINT_ALL, "Unable to get xrandr screen resources.\n"); return; } for(i=0; i < noGammaRamps; ++i) { // in case a display was unplugged or something, noGammaRamps may be > res->ncrtc if(i < res->ncrtc) { int len = XRRGetCrtcGammaSize(dpy, res->crtcs[i]); if(len != gammaRamps[i]->size) { VID_Printf(PRINT_ALL, "WTF, gamma ramp size for display %d has changed from %d to %d!\n", i, gammaRamps[i]->size, len); continue; } XRRSetCrtcGamma(dpy, res->crtcs[i], gammaRamps[i]); } // the ramp needs to be free()d either way XRRFreeGamma(gammaRamps[i]); gammaRamps[i] = NULL; } XRRFreeScreenResources(res); free(gammaRamps); gammaRamps = NULL; VID_Printf(PRINT_ALL, "Restored original Gamma\n"); }
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 }
// Set the current video mode for the specified monitor // void _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired) { if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) { XRRScreenResources* sr; XRRCrtcInfo* ci; XRROutputInfo* oi; GLFWvidmode current; const GLFWvidmode* best; RRMode native = None; int i; best = _glfwChooseVideoMode(monitor, desired); _glfwPlatformGetVideoMode(monitor, ¤t); if (_glfwCompareVideoModes(¤t, best) == 0) return; sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root); ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); oi = XRRGetOutputInfo(_glfw.x11.display, sr, monitor->x11.output); for (i = 0; i < oi->nmode; i++) { const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]); if (!modeIsGood(mi)) continue; const GLFWvidmode mode = vidmodeFromModeInfo(mi, ci); if (_glfwCompareVideoModes(best, &mode) == 0) { native = mi->id; break; } } if (native) { if (monitor->x11.oldMode == None) monitor->x11.oldMode = ci->mode; XRRSetCrtcConfig(_glfw.x11.display, sr, monitor->x11.crtc, CurrentTime, ci->x, ci->y, native, ci->rotation, ci->outputs, ci->noutput); } XRRFreeOutputInfo(oi); XRRFreeCrtcInfo(ci); XRRFreeScreenResources(sr); } }
XRRConfiguration::~XRRConfiguration() { if (bValid && bIsFullscreen) ToggleDisplayMode(False); if (screenResources) XRRFreeScreenResources(screenResources); if (outputInfo) XRRFreeOutputInfo(outputInfo); if (crtcInfo) XRRFreeCrtcInfo(crtcInfo); }
static void *settings_thread_proc(void *arg) { Display *settings_disp = XOpenDisplay(XDisplayName(NULL));; if (settings_disp != NULL) { logger(LOG_LEVEL_DEBUG, "%s [%u]: %s\n", __FUNCTION__, __LINE__, "XOpenDisplay success."); pthread_cleanup_push(settings_cleanup_proc, settings_disp); int event_base = 0; int error_base = 0; if (XRRQueryExtension(settings_disp, &event_base, &error_base)) { Window root = XDefaultRootWindow(settings_disp); unsigned long event_mask = RRScreenChangeNotifyMask; XRRSelectInput(settings_disp, root, event_mask); XEvent ev; while(settings_disp != NULL) { XNextEvent(settings_disp, &ev); if (ev.type == event_base + RRScreenChangeNotifyMask) { logger(LOG_LEVEL_DEBUG, "%s [%u]: Received XRRScreenChangeNotifyEvent.\n", __FUNCTION__, __LINE__); pthread_mutex_lock(&xrandr_mutex); if (xrandr_resources != NULL) { XRRFreeScreenResources(xrandr_resources); } xrandr_resources = XRRGetScreenResources(settings_disp, root); if (xrandr_resources == NULL) { logger(LOG_LEVEL_WARN, "%s [%u]: XRandR could not get screen resources!\n", __FUNCTION__, __LINE__); } pthread_mutex_unlock(&xrandr_mutex); } else { logger(LOG_LEVEL_WARN, "%s [%u]: XRandR is not currently available!\n", __FUNCTION__, __LINE__); } } } // Execute the thread cleanup handler. pthread_cleanup_pop(1); } else { logger(LOG_LEVEL_ERROR, "%s [%u]: XOpenDisplay failure!\n", __FUNCTION__, __LINE__); } return NULL; }
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count) { GLFWvidmode* result; *count = 0; if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) { int i, j; XRRScreenResources* sr; XRRCrtcInfo* ci; XRROutputInfo* oi; sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root); ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); oi = XRRGetOutputInfo(_glfw.x11.display, sr, monitor->x11.output); result = calloc(oi->nmode, sizeof(GLFWvidmode)); for (i = 0; i < oi->nmode; i++) { const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]); if (!modeIsGood(mi)) continue; const GLFWvidmode mode = vidmodeFromModeInfo(mi, ci); for (j = 0; j < *count; j++) { if (_glfwCompareVideoModes(result + j, &mode) == 0) break; } // Skip duplicate modes if (j < *count) continue; (*count)++; result[*count - 1] = mode; } XRRFreeOutputInfo(oi); XRRFreeCrtcInfo(ci); XRRFreeScreenResources(sr); } else { *count = 1; result = calloc(1, sizeof(GLFWvidmode)); _glfwPlatformGetVideoMode(monitor, result); } return result; }
static void _gfx_x11_enter_fullscreen( GFX_X11_Monitor* monitor, Window handle, RRMode mode) { Window root = XRootWindowOfScreen(monitor->screen); XRRScreenResources* res = XRRGetScreenResources(_gfx_x11.display, root); XRRCrtcInfo* crtc = XRRGetCrtcInfo(_gfx_x11.display, res, monitor->crtc); /* Above state */ XEvent event; memset(&event, 0, sizeof(XEvent)); event.type = ClientMessage; event.xclient.window = handle; event.xclient.message_type = _gfx_x11.NET_WM_STATE; event.xclient.format = 32; event.xclient.data.l[0] = 1; event.xclient.data.l[1] = _gfx_x11.NET_WM_STATE_ABOVE; /* Send event, set mode and move window */ XSendEvent( _gfx_x11.display, root, False, SubstructureRedirectMask | SubstructureNotifyMask, &event); XRRSetCrtcConfig( _gfx_x11.display, res, monitor->crtc, crtc->timestamp, crtc->x, crtc->y, mode, crtc->rotation, crtc->outputs, crtc->noutput); XMoveWindow( _gfx_x11.display, handle, crtc->x, crtc->y); XRRFreeCrtcInfo(crtc); XRRFreeScreenResources(res); }
void ui_get_screen_res(int *x0, int *y0, int *width, int *height, int monitor) { int i, n, x, y, di; unsigned int du; Window dw; XRRScreenResources *sr; XRRCrtcInfo *ci = NULL; if (getenv("JGMENU_SCREEN_INFO")) print_screen_info(); sr = XRRGetScreenResources(ui->dpy, DefaultRootWindow(ui->dpy)); BUG_ON(!sr); n = sr->ncrtc; /* * Global variable config.monitor let's the user specify a monitor. * If not set, we use the current pointer position */ if (monitor) { if (monitor > n) die("cannot connect to monitor '%d'", monitor); ci = XRRGetCrtcInfo(ui->dpy, sr, sr->crtcs[monitor - 1]); if (!ci->noutput) die("cannot connect to monitor '%d'", monitor); info("using user specified monitor '%d'", monitor); goto monitor_selected; } XQueryPointer(ui->dpy, ui->root, &dw, &dw, &x, &y, &di, &di, &du); for (i = 0; i < n; i++) { if (ci) XRRFreeCrtcInfo(ci); ci = XRRGetCrtcInfo(ui->dpy, sr, sr->crtcs[i]); BUG_ON(!ci); if (!ci->noutput) continue; if (intersect(x, y, 1, 1, ci)) { info("using monitor '%d'", i + 1); break; } } monitor_selected: if (!ci) die("connection could be established to monitor"); *x0 = ci->x; *y0 = ci->y; *width = ci->width; *height = ci->height; XRRFreeCrtcInfo(ci); XRRFreeScreenResources(sr); }
// Set the current video mode for the specified monitor // void _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired) { if (_glfw.x11.randr.available) { int i; XRRScreenResources* sr; XRRCrtcInfo* ci; RRMode bestMode = 0; unsigned int leastSizeDiff = UINT_MAX, leastRateDiff = UINT_MAX; sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root); ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); for (i = 0; i < sr->nmode; i++) { XRRModeInfo* mi = sr->modes + i; if (mi->modeFlags & RR_Interlace) continue; const unsigned int sizeDiff = (mi->width - desired->width) * (mi->width - desired->width) + (mi->height - desired->height) * (mi->height - desired->height); const unsigned int rateDiff = abs(calculateRefreshRate(mi) - desired->refreshRate); if ((sizeDiff < leastSizeDiff) || (sizeDiff == leastSizeDiff && rateDiff < leastRateDiff)) { bestMode = mi->id; leastSizeDiff = sizeDiff; leastRateDiff = rateDiff; } } monitor->x11.oldMode = ci->mode; XRRSetCrtcConfig(_glfw.x11.display, sr, monitor->x11.crtc, CurrentTime, ci->x, ci->y, bestMode, ci->rotation, ci->outputs, ci->noutput); XRRFreeCrtcInfo(ci); XRRFreeScreenResources(sr); } }
static int SwitchRes(char inout, int x __UNUSED__, int y __UNUSED__, int w, int h, int *dw, int *dh) { XRRScreenResources *xsr; XRRCrtcInfo *xci; RRCrtc crtc; RRMode ss_mode_new; int ok = 0; Dprintf("%s: inout=%d\n", __func__, inout); xsr = XRRGetScreenResourcesCurrent(disp, WinGetXwin(VROOT)); if (!xsr) goto done; crtc = xsr->crtcs[0]; /* FIXME - Which crtc? */ if (inout) { /* Save current setup */ xci = XRRGetCrtcInfo(disp, xsr, crtc); if (!xci) goto done; ss_mode = xci->mode; ss_rot = xci->rotation; XRRFreeCrtcInfo(xci); /* Select zoomed setup */ ss_mode_new = FindMode(xsr, w, h, dw, dh); /* Set zoomed setup */ SetPanning(xsr, crtc, 1); ok = SetMode(xsr, crtc, ss_mode_new, ss_rot); } else { /* Revert to original setup */ ok = SetMode(xsr, crtc, ss_mode, ss_rot); SetPanning(xsr, crtc, 0); } done: if (xsr) XRRFreeScreenResources(xsr); Dprintf("%s: ok=%d\n", __func__, ok); return ok; }
static void settings_cleanup_proc(void *arg) { if (pthread_mutex_trylock(&xrandr_mutex) == 0) { if (xrandr_resources != NULL) { XRRFreeScreenResources(xrandr_resources); xrandr_resources = NULL; } if (arg != NULL) { XCloseDisplay((Display *) arg); arg = NULL; } pthread_mutex_unlock(&xrandr_mutex); } }
static char * getedidhash(void) { XRRScreenResources *resources; char *edidhash; Window root; root = RootWindow(dpy, DefaultScreen(dpy)); resources = XRRGetScreenResources(dpy, root); edidhash = getedidhash1(resources); XRRFreeScreenResources(resources); return (edidhash); }
void screen_info_free (ScreenInfo *info) { GnomeRROutput **output; GnomeRRCrtc **crtc; GnomeRRMode **mode; g_return_if_fail (info != NULL); #ifdef HAVE_RANDR if (info->resources) { XRRFreeScreenResources (info->resources); info->resources = NULL; } #endif if (info->outputs) { for (output = info->outputs; *output; ++output) output_free (*output); g_free (info->outputs); } if (info->crtcs) { for (crtc = info->crtcs; *crtc; ++crtc) crtc_free (*crtc); g_free (info->crtcs); } if (info->modes) { for (mode = info->modes; *mode; ++mode) mode_free (*mode); g_free (info->modes); } if (info->clone_modes) { /* The modes themselves were freed above */ g_free (info->clone_modes); } g_free (info); }
std::vector<display> display::enumerate() { std::vector<display> result; if (randr.is_available) { RROutput const primary = XRRGetOutputPrimary(g_display, g_root); XRRScreenResources* sr = XRRGetScreenResources(g_display, g_root); for (int i = 0; i < sr->ncrtc; ++i) { XRRCrtcInfo* info = XRRGetCrtcInfo(g_display, sr, sr->crtcs[i]); if (info->noutput) { RROutput* output = std::find_if(info->outputs, info->outputs + info->noutput, [primary](RROutput output) { return output == primary; }); if (output == info->outputs + info->noutput) { output = info->outputs; } display disp = init(sr, *output); if (!disp.name.empty()) { result.emplace_back(disp); } } XRRFreeCrtcInfo(info); } XRRFreeScreenResources(sr); std::vector<display>::iterator it = std::find_if(result.begin(), result.end(), [primary](display const& disp) { return disp.output == primary; }); if (it != result.begin() && it != result.end()) { std::iter_swap(it, result.begin()); } } else { result.push_back(primary()); } return result; }
display::mode display::current_mode() const { if (randr.is_available) { XRRScreenResources* sr = XRRGetScreenResources(g_display, g_root); XRRCrtcInfo* ci = XRRGetCrtcInfo(g_display, sr, crtc); XRRModeInfo const* mi = mode_info(sr, ci->mode); display::mode const result = make_mode(mi, ci); XRRFreeCrtcInfo(ci); XRRFreeScreenResources(sr); return result; } else { return display::mode(DisplayWidth(g_display, g_screen), DisplayHeight(g_display, g_screen), DefaultDepth(g_display, g_screen), 0); } }
display display::from_window(window const* w) { Window root = w? *w : g_root; display result; if (randr.is_available) { XRRScreenResources* sr = XRRGetScreenResources(g_display, root); RROutput primary = XRRGetOutputPrimary(g_display, g_root); result = init(sr, primary); XRRFreeScreenResources(sr); } else { result.scale = 1; result.color_depth = XDefaultDepth(g_display, g_screen); result.color_depth_per_component = result.color_depth >= 24? 8 : 0; result.rect = result.work_rect = rectangle<int>(0, 0, DisplayWidthMM(g_display, g_screen), DisplayHeightMM(g_display, g_screen)); } return result; }
// Detect gamma ramp support // void _glfwInitGammaRamp(void) { // RandR gamma support is only available with version 1.2 and above if (_glfw.x11.randr.available && (_glfw.x11.randr.versionMajor > 1 || (_glfw.x11.randr.versionMajor == 1 && _glfw.x11.randr.versionMinor >= 2))) { // FIXME: Assumes that all monitors have the same size gamma tables // This is reasonable as I suspect the that if they did differ, it // would imply that setting the gamma size to an arbitary size is // possible as well. XRRScreenResources *rr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root); if (XRRGetCrtcGammaSize(_glfw.x11.display, rr->crtcs[0]) == 0) { // This is probably older Nvidia RandR with broken gamma support // Flag it as useless and try Xf86VidMode below, if available _glfw.x11.randr.gammaBroken = GL_TRUE; } XRRFreeScreenResources(rr); } }
int _screen_info(const char *name, int num, Rect *r) { XRRScreenResources *res = XRRGetScreenResources(dpy, root); if (!res) return 0; int i, n = res->noutput; XRROutputInfo *info; XRRCrtcInfo *crtc; r->w = r->h = 0; for (i = 0; i < n; ++i) { /* skip if output lacks info or crtc */ if (!(info=XRRGetOutputInfo(dpy, res, res->outputs[i]))) continue; if (!info->crtc || !(crtc=XRRGetCrtcInfo(dpy,res,info->crtc))) { XRRFreeOutputInfo(info); continue; } /* skip if name is provided and doesn't match */ if (name && strncmp(name, info->name, strlen(name))) { XRRFreeCrtcInfo(crtc); XRRFreeOutputInfo(info); continue; } /* and skip if number is provided and doesn't match */ if (num && num - 1 != i) { XRRFreeCrtcInfo(crtc); XRRFreeOutputInfo(info); continue; } /* match found, return size */ r->x = crtc->x; r->y = crtc->y; r->w = crtc->width; r->h = crtc->height; XRRFreeCrtcInfo(crtc); XRRFreeOutputInfo(info); if (r->w && r->h) break; } XRRFreeScreenResources(res); return n; }