Skip to content

Commit

Permalink
xrandr: observe orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
FernetMenta committed Oct 28, 2013
1 parent 8895d22 commit 017900d
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 17 deletions.
89 changes: 72 additions & 17 deletions xbmc/windowing/X11/WinSystemX11.cpp
Expand Up @@ -85,11 +85,11 @@ bool CWinSystemX11::DestroyWindowSystem()
{
XOutput out;
XMode mode;
out.name = g_settings.m_ResInfo[RES_DESKTOP].strOutput;
mode.w = g_settings.m_ResInfo[RES_DESKTOP].iWidth;
mode.h = g_settings.m_ResInfo[RES_DESKTOP].iHeight;
mode.hz = g_settings.m_ResInfo[RES_DESKTOP].fRefreshRate;
mode.id = g_settings.m_ResInfo[RES_DESKTOP].strId;
out.name = CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP).strOutput;
mode.w = CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP).iWidth;
mode.h = CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP).iHeight;
mode.hz = CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP).fRefreshRate;
mode.id = CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP).strId;
g_xrandr.SetMode(out, mode);
}
#endif
Expand Down Expand Up @@ -173,25 +173,34 @@ bool CWinSystemX11::ResizeWindow(int newWidth, int newHeight, int newLeft, int n

void CWinSystemX11::RefreshWindow()
{
g_xrandr.Query(true);
if (!g_xrandr.Query(true))
{
CLog::Log(LOGERROR, "WinSystemX11::RefreshWindow - failed to query xrandr");
return;
}
XOutput out = g_xrandr.GetCurrentOutput();
XMode mode = g_xrandr.GetCurrentMode(out.name);

RotateResolutions();

// only overwrite desktop resolution, if we are not in fullscreen mode
if (!g_graphicsContext.IsFullScreenVideo())
{
CLog::Log(LOGDEBUG, "CWinSystemX11::RefreshWindow - store desktop resolution, width: %d, height: %d, hz: %2.2f", mode.w, mode.h, mode.hz);
UpdateDesktopResolution(g_settings.m_ResInfo[RES_DESKTOP], 0, mode.w, mode.h, mode.hz);
g_settings.m_ResInfo[RES_DESKTOP].strId = mode.id;
g_settings.m_ResInfo[RES_DESKTOP].strOutput = out.name;
if (!out.isRotated)
UpdateDesktopResolution(CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP), 0, mode.w, mode.h, mode.hz);
else
UpdateDesktopResolution(CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP), 0, mode.h, mode.w, mode.hz);
CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP).strId = mode.id;
CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP).strOutput = out.name;
}

RESOLUTION_INFO res;
unsigned int i;
bool found(false);
for (i = RES_DESKTOP; i < g_settings.m_ResInfo.size(); ++i)
for (i = RES_DESKTOP; i < CDisplaySettings::Get().ResolutionInfoSize(); ++i)
{
if (g_settings.m_ResInfo[i].strId == mode.id)
if (CDisplaySettings::Get().GetResolutionInfo(i).strId == mode.id)
{
found = true;
break;
Expand Down Expand Up @@ -227,16 +236,24 @@ bool CWinSystemX11::SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, bool bl
}
else
{
out.name = g_settings.m_ResInfo[RES_DESKTOP].strOutput;
mode.w = g_settings.m_ResInfo[RES_DESKTOP].iWidth;
mode.h = g_settings.m_ResInfo[RES_DESKTOP].iHeight;
mode.hz = g_settings.m_ResInfo[RES_DESKTOP].fRefreshRate;
mode.id = g_settings.m_ResInfo[RES_DESKTOP].strId;
out.name = CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP).strOutput;
mode.w = CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP).iWidth;
mode.h = CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP).iHeight;
mode.hz = CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP).fRefreshRate;
mode.id = CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP).strId;
}

XOutput currout = g_xrandr.GetCurrentOutput();
XMode currmode = g_xrandr.GetCurrentMode(currout.name);

// flip h/w when rotated
if (m_bIsRotated)
{
int w = mode.w;
mode.w = mode.h;
mode.h = w;
}

// only call xrandr if mode changes
if (currout.name != out.name || currmode.w != mode.w || currmode.h != mode.h ||
currmode.hz != mode.hz || currmode.id != mode.id)
Expand Down Expand Up @@ -269,7 +286,11 @@ void CWinSystemX11::UpdateResolutions()
{
XOutput out = g_xrandr.GetCurrentOutput();
XMode mode = g_xrandr.GetCurrentMode(out.name);
UpdateDesktopResolution(CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP), 0, mode.w, mode.h, mode.hz);
m_bIsRotated = out.isRotated;
if (!m_bIsRotated)
UpdateDesktopResolution(CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP), 0, mode.w, mode.h, mode.hz);
else
UpdateDesktopResolution(CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP), 0, mode.h, mode.w, mode.hz);
CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP).strId = mode.id;
CDisplaySettings::Get().GetResolutionInfo(RES_DESKTOP).strOutput = out.name;
}
Expand Down Expand Up @@ -308,6 +329,16 @@ void CWinSystemX11::UpdateResolutions()
res.iHeight = mode.h;
res.iScreenWidth = mode.w;
res.iScreenHeight = mode.h;
if (!m_bIsRotated)
{
res.iWidth = mode.w;
res.iHeight = mode.h;
}
else
{
res.iWidth = mode.h;
res.iHeight = mode.w;
}
if (mode.h>0 && mode.w>0 && out.hmm>0 && out.wmm>0)
res.fPixelRatio = ((float)out.wmm/(float)mode.w) / (((float)out.hmm/(float)mode.h));
else
Expand Down Expand Up @@ -335,6 +366,30 @@ void CWinSystemX11::UpdateResolutions()

}

void CWinSystemX11::RotateResolutions()
{
#if defined(HAS_XRANDR)
XOutput out = g_xrandr.GetCurrentOutput();
if (out.isRotated == m_bIsRotated)
return;

for (unsigned int i = 0; i < CDisplaySettings::Get().ResolutionInfoSize(); ++i)
{
int width = CDisplaySettings::Get().GetResolutionInfo(i).iWidth;
CDisplaySettings::Get().GetResolutionInfo(i).iWidth = CDisplaySettings::Get().GetResolutionInfo(i).iHeight;
CDisplaySettings::Get().GetResolutionInfo(i).iHeight = width;
}
// update desktop resolution
// int h = g_settings.m_ResInfo[RES_DESKTOP].iHeight;
// int w = g_settings.m_ResInfo[RES_DESKTOP].iWidth;
// float hz = g_settings.m_ResInfo[RES_DESKTOP].fRefreshRate;
// UpdateDesktopResolution(g_settings.m_ResInfo[RES_DESKTOP], 0, w, h, hz);

m_bIsRotated = out.isRotated;

#endif
}

bool CWinSystemX11::IsSuitableVisual(XVisualInfo *vInfo)
{
int value;
Expand Down
2 changes: 2 additions & 0 deletions xbmc/windowing/X11/WinSystemX11.h
Expand Up @@ -75,12 +75,14 @@ class CWinSystemX11 : public CWinSystemBase, public ISettingCallback
void CheckDisplayEvents();
void OnLostDevice();
bool SetWindow(int width, int height, bool fullscreen);
void RotateResolutions();

Window m_glWindow;
GLXContext m_glContext;
Display* m_dpy;
Cursor m_invisibleCursor;
Pixmap m_icon;
bool m_bIsRotated;
bool m_bWasFullScreenBeforeMinimize;
bool m_minimized;
bool m_bIgnoreNextFocusMessage;
Expand Down
7 changes: 7 additions & 0 deletions xbmc/windowing/X11/XRandR.cpp
Expand Up @@ -98,6 +98,13 @@ bool CXRandR::Query(bool force)
xoutput.y = (output->Attribute("y") != NULL ? atoi(output->Attribute("y")) : 0);
xoutput.wmm = (output->Attribute("wmm") != NULL ? atoi(output->Attribute("wmm")) : 0);
xoutput.hmm = (output->Attribute("hmm") != NULL ? atoi(output->Attribute("hmm")) : 0);
if (output->Attribute("rotation") != NULL
&& (strcasecmp(output->Attribute("rotation"), "left") == 0 || strcasecmp(output->Attribute("rotation"), "right") == 0))
{
xoutput.isRotated = true;
}
else
xoutput.isRotated = false;

if (!xoutput.isConnected)
continue;
Expand Down
1 change: 1 addition & 0 deletions xbmc/windowing/X11/XRandR.h
Expand Up @@ -86,6 +86,7 @@ class XOutput
int wmm;
int hmm;
std::vector<XMode> modes;
bool isRotated;
};

class CXRandR
Expand Down

0 comments on commit 017900d

Please sign in to comment.