From 67948dfe28adf4d2a91649f5a37e9ca23f75f07c Mon Sep 17 00:00:00 2001 From: Deve Date: Thu, 31 Jul 2014 23:12:40 +0200 Subject: [PATCH] xrandr: add support for rotated screens --- .../source/Irrlicht/CIrrDeviceLinux.cpp | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp index 16275eb6f..39cc7556f 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp @@ -49,6 +49,9 @@ #endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ +#define XRANDR_ROTATION_LEFT (1 << 1) +#define XRANDR_ROTATION_RIGHT (1 << 3) + namespace irr { namespace video @@ -346,8 +349,20 @@ bool CIrrDeviceLinux::switchToFullscreen(bool reset) for (int i = 0; i < res->nmode; i++) { const XRRModeInfo* mode = &res->modes[i]; + unsigned int w, h; + + if (crtc->rotation & (XRANDR_ROTATION_LEFT|XRANDR_ROTATION_RIGHT)) + { + w = mode->height; + h = mode->width; + } + else + { + w = mode->width; + h = mode->height; + } - if (bestMode == -1 && mode->width == Width && mode->height == Height) + if (bestMode == -1 && w == Width && h == Height) { for (int j = 0; j < output->nmode; j++) { @@ -359,7 +374,7 @@ bool CIrrDeviceLinux::switchToFullscreen(bool reset) } } } - else if (bestMode != -1 && mode->width == Width && mode->height == Height) + else if (bestMode != -1 && w == Width && h == Height) { refresh_rate_new = (mode->dotClock * 1000.0) / (mode->hTotal * mode->vTotal); @@ -1628,13 +1643,25 @@ video::IVideoModeList* CIrrDeviceLinux::getVideoModeList() for (int i = 0; i < res->nmode; i++) { const XRRModeInfo* mode = &res->modes[i]; + unsigned int w, h; + + if (crtc->rotation & (XRANDR_ROTATION_LEFT|XRANDR_ROTATION_RIGHT)) + { + w = mode->height; + h = mode->width; + } + else + { + w = mode->width; + h = mode->height; + } for (int j = 0; j < output->nmode; j++) - { + { if (mode->id == output->modes[j]) { VideoModeList.addMode(core::dimension2d( - mode->width, mode->height), defaultDepth); + w, h), defaultDepth); break; } } @@ -1643,7 +1670,7 @@ video::IVideoModeList* CIrrDeviceLinux::getVideoModeList() { old_mode = crtc->mode; VideoModeList.setDesktop(defaultDepth, - core::dimension2d(mode->width, mode->height)); + core::dimension2d(w, h)); } }