bool DisplayManagerWin::setDisplayMode(int display, int mode) { DEVMODEW modeInfo; if (!isValidDisplayMode(display, mode)) return false; if (getModeInfo(display, mode, modeInfo)) { modeInfo.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS; LONG rc = ChangeDisplaySettingsExW((LPCWSTR)m_displayAdapters[display].utf16(), &modeInfo, NULL, CDS_FULLSCREEN, NULL); if (rc != DISP_CHANGE_SUCCESSFUL) { QLOG_ERROR() << "Failed to changed DisplayMode, error" << rc; return false; } else { return true; } } return false; }
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); }
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; }
bool DisplayManagerWin::initialize() { DISPLAY_DEVICEW displayInfo; int displayId = 0; while (getDisplayInfo(displayId, displayInfo)) { if (displayInfo.StateFlags & (DISPLAY_DEVICE_ACTIVE | DISPLAY_DEVICE_ATTACHED)) { DEVMODEW modeInfo; int modeId = 0; // add the display DMDisplayPtr display = DMDisplayPtr(new DMDisplay); display->id = displayId; display->name = QString::fromWCharArray(displayInfo.DeviceString); displays[display->id] = DMDisplayPtr(display); m_displayAdapters[display->id] = QString::fromWCharArray(displayInfo.DeviceName); while (getModeInfo(displayId, modeId, modeInfo)) { // add the videomode to the display DMVideoModePtr videoMode = DMVideoModePtr(new DMVideoMode); videoMode->id = modeId; display->videoModes[videoMode->id] = videoMode; // setup mode information videoMode->height = modeInfo.dmPelsHeight; videoMode->width = modeInfo.dmPelsWidth; videoMode->refreshRate = modeInfo.dmDisplayFrequency; videoMode->bitsPerPixel = modeInfo.dmBitsPerPel; videoMode->interlaced = (modeInfo.dmDisplayFlags & DM_INTERLACED) ? true : false; // Windows just returns interger refresh rate so // let's fudge it if (videoMode->refreshRate == 59 || videoMode->refreshRate == 29 || videoMode->refreshRate == 23) videoMode->refreshRate = (float)(videoMode->refreshRate + 1) / 1.001f; modeId++; } } displayId++; } if (displays.size() == 0) { QLOG_DEBUG() << "No display found."; return false; } else return DisplayManager::initialize(); }
// 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); } }
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; }
bool DisplayManagerWin::initialize() { DISPLAY_DEVICEW displayInfo; int displayId = 0; m_displayAdapters.clear(); displays.clear(); while (getDisplayInfo(displayId, displayInfo)) { if (displayInfo.StateFlags & (DISPLAY_DEVICE_ACTIVE | DISPLAY_DEVICE_ATTACHED)) { DEVMODEW modeInfo; int modeId = 0; // add the display DMDisplayPtr display = DMDisplayPtr(new DMDisplay); display->id = displayId; display->name = QString::fromWCharArray(displayInfo.DeviceString); displays[display->id] = DMDisplayPtr(display); m_displayAdapters[display->id] = QString::fromWCharArray(displayInfo.DeviceName); while (getModeInfo(displayId, modeId, modeInfo)) { // add the videomode to the display DMVideoModePtr videoMode = DMVideoModePtr(new DMVideoMode); *videoMode = convertDevMode(modeInfo); videoMode->id = modeId; display->videoModes[videoMode->id] = videoMode; modeId++; } } displayId++; } if (displays.size() == 0) { QLOG_DEBUG() << "No display found."; return false; } else return DisplayManager::initialize(); }
int DisplayManagerWin::getDisplayFromPoint(int x, int y) { for (int displayId = 0; displayId < displays.size(); displayId++) { int currentMode = getCurrentDisplayMode(displayId); if (currentMode > 0) { DEVMODEW modeInfo; if (getModeInfo(displayId, currentMode, modeInfo)) { QRect displayRect(modeInfo.dmPosition.x, modeInfo.dmPosition.y, modeInfo.dmPelsWidth, modeInfo.dmPelsHeight); if (displayRect.contains(x, y)) return displayId; } } } return -1; }
int DisplayManagerWin::getDisplayFromPoint(int x, int y) { foreach (int displayId, displays.keys()) { int currentMode = getCurrentDisplayMode(displayId); if (currentMode >= 0) { DEVMODEW modeInfo; if (getModeInfo(displayId, currentMode, modeInfo)) { QRect displayRect(modeInfo.dmPosition.x, modeInfo.dmPosition.y, modeInfo.dmPelsWidth, modeInfo.dmPelsHeight); QLOG_DEBUG() << "Looking at display" << displayId << "mode" << currentMode << "at" << displayRect; if (displayRect.contains(x, y)) return displayId; } } } return -1; }
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) { GLFWvidmode* result; int depth, r, g, b; depth = DefaultDepth(_glfw.x11.display, _glfw.x11.screen); _glfwSplitBPP(depth, &r, &g, &b); *found = 0; // Build array of available resolutions if (_glfw.x11.randr.available) { 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++) { GLFWvidmode mode; const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]); mode.width = mi->width; mode.height = mi->height; mode.refreshRate = calculateRefreshRate(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; } mode.redBits = r; mode.greenBits = g; mode.blueBits = b; result[*found] = mode; (*found)++; } XRRFreeOutputInfo(oi); XRRFreeScreenResources(sr); } else { *found = 1; result = calloc(1, sizeof(GLFWvidmode)); result[0].width = DisplayWidth(_glfw.x11.display, _glfw.x11.screen); result[0].height = DisplayHeight(_glfw.x11.display, _glfw.x11.screen); result[0].redBits = r; result[0].greenBits = g; result[0].blueBits = b; result[0].refreshRate = 0; } return result; }
void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor, int* xpos, int* ypos, int* width, int* height) { int areaX = 0, areaY = 0, areaWidth = 0, areaHeight = 0; if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) { XRRScreenResources* sr; XRRCrtcInfo* ci; sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root); ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); areaX = ci->x; areaY = ci->y; const XRRModeInfo* mi = getModeInfo(sr, ci->mode); if (ci->rotation == RR_Rotate_90 || ci->rotation == RR_Rotate_270) { areaWidth = mi->height; areaHeight = mi->width; } else { areaWidth = mi->width; areaHeight = mi->height; } XRRFreeCrtcInfo(ci); XRRFreeScreenResources(sr); } else { areaWidth = DisplayWidth(_glfw.x11.display, _glfw.x11.screen); areaHeight = DisplayHeight(_glfw.x11.display, _glfw.x11.screen); } if (_glfw.x11.NET_WORKAREA && _glfw.x11.NET_CURRENT_DESKTOP) { Atom* extents = NULL; Atom* desktop = NULL; const unsigned long extentCount = _glfwGetWindowPropertyX11(_glfw.x11.root, _glfw.x11.NET_WORKAREA, XA_CARDINAL, (unsigned char**) &extents); if (_glfwGetWindowPropertyX11(_glfw.x11.root, _glfw.x11.NET_CURRENT_DESKTOP, XA_CARDINAL, (unsigned char**) &desktop) > 0) { if (extentCount >= 4 && *desktop < extentCount / 4) { const int globalX = extents[*desktop * 4 + 0]; const int globalY = extents[*desktop * 4 + 1]; const int globalWidth = extents[*desktop * 4 + 2]; const int globalHeight = extents[*desktop * 4 + 3]; if (areaX < globalX) { areaWidth -= globalX - areaX; areaX = globalX; } if (areaY < globalY) { areaHeight -= globalY - areaY; areaY = globalY; } if (areaX + areaWidth > globalX + globalWidth) areaWidth = globalX - areaX + globalWidth; if (areaY + areaHeight > globalY + globalHeight) areaHeight = globalY - areaY + globalHeight; } } if (extents) XFree(extents); if (desktop) XFree(desktop); } if (xpos) *xpos = areaX; if (ypos) *ypos = areaY; if (width) *width = areaWidth; if (height) *height = areaHeight; }