Files
itgmania212121/src/DisplaySpec.cpp
T
Drew Barbarello 557be7cf1b 5 1 new backport x11 fs rework (#1485)
* Use XRandR 1.2 to set fullscreen resolution for single output

Squash of roothorick's PR #497
(also includes Kyzentun's CMake changes from PR #716)

* Cherry-pick json c++1x stuff (b9e3d7174e)

* Cherry-pick c++11 support from 5bba5c0038 and 9f8b045309

* rework Linux (X11) fullscreen, improve display-related Graphics Options

Implement option to select between monitors for exclusive fullscreen mode
on X11 (using XRandR 1.2), or use a fullscreen borderless window.

Reimplement resolution/refresh rate/display mode-related option rows
using Lua, update choices dynamically so only known-good groupings of
resolution/refresh rate/aspect ratio can be selected.

Minimally update Windows/MacOS LowLevelWindow implementations to support
changes made for Linux side. Fullscreen Borderless Window/multi monitor
support from X11 not implemented for those in this commit.

* allow forcibly disabling xinerama use on Linux

When libXinerama is available, SM tries to use it to find the proper
monitor indexes to use to set _NET_WM_FULLSCREEN_MONITORS (on borderless
fullscreen). xfwm4 seems to assume that monitors are numbered in increasing
order from left to right (rather than using the Xinerama-assigned numbers),
so _NET_WM_FULLSCREEN_MONITORS misbehaves on Xfce.

This commit bypasses use of libXinerama, and instead forces SM to induce fullscreen
on the desired monitor in the backup, hacky way: remove all window hints, move window
to desired monitor, then add _NET_WM_STATE_FULLSCREEN hint. This works on
mutter and Xfce.

* Remove multiple warnings on redundant define.

This used to be hard-coded due to pthread related items, but now it's dynamically determined.

* fix _fallback menu behavior for unrecognized aspect ratios

* Fix error recreating existing FS texture

* Bump deployment target to 10.7 to use libc++ on XCode 8

* Add explicit casts to please clang

* Update changelog
2017-06-18 08:55:16 -07:00

150 lines
3.2 KiB
C++

#include "global.h"
#include "DisplaySpec.h"
#include "LuaBinding.h"
#include "RageLog.h"
class LunaDisplayMode: public Luna<DisplayMode>
{
public:
DEFINE_METHOD( GetWidth, width );
DEFINE_METHOD( GetHeight, height );
DEFINE_METHOD( GetRefreshRate, refreshRate );
LunaDisplayMode()
{
ADD_METHOD( GetWidth );
ADD_METHOD( GetHeight );
ADD_METHOD( GetRefreshRate );
}
};
LUA_REGISTER_CLASS( DisplayMode )
class LunaDisplaySpec: public Luna<DisplaySpec>
{
public:
DEFINE_METHOD( GetId, id() );
DEFINE_METHOD( GetName, name() );
DEFINE_METHOD( IsVirtual, isVirtual() );
static int GetSupportedModes( T* p, lua_State *L)
{
std::vector<DisplayMode*> v;
for (auto const &m: p->supportedModes())
{
v.push_back( const_cast<DisplayMode*>(&m));
}
LuaHelpers::CreateTableFromArray( v, L );
return 1;
}
static int GetCurrentMode( T *p, lua_State *L )
{
if (p->currentMode() != NULL) {
DisplayMode *m = const_cast<DisplayMode *>( p->currentMode() );
m->PushSelf( L );
} else {
lua_pushnil( L );
}
return 1;
}
LunaDisplaySpec()
{
ADD_METHOD( GetId );
ADD_METHOD( GetName );
ADD_METHOD( GetSupportedModes );
ADD_METHOD( IsVirtual );
ADD_METHOD( GetCurrentMode );
}
};
LUA_REGISTER_CLASS( DisplaySpec )
namespace
{
const char *DISPLAYSPECS = "DisplaySpecs";
DisplaySpecs *check_DisplaySpecs(lua_State *L)
{
void *ud = luaL_checkudata( L, 1, DISPLAYSPECS );
luaL_argcheck( L, ud != NULL, 1, "`DisplaySpecs` expected" );
return static_cast<DisplaySpecs *>(ud);
}
int DisplaySpecs_gc(lua_State *L)
{
DisplaySpecs *specs = static_cast<DisplaySpecs *> (lua_touserdata( L, 1 ));
if (specs)
{
specs->~DisplaySpecs();
}
return 0;
}
int DisplaySpecs_len(lua_State *L)
{
DisplaySpecs *specs = check_DisplaySpecs( L );
if (specs)
{
lua_pushinteger( L, specs->size() );
} else
{
lua_pushinteger( L, 0 );
}
return 1;
}
int DisplaySpecs_tostring(lua_State *L)
{
DisplaySpecs *specs = check_DisplaySpecs( L );
lua_pushfstring( L, "DisplaySpecs: %p", specs );
return 1;
}
int DisplaySpecs_get(lua_State *L)
{
DisplaySpecs *specs = check_DisplaySpecs( L );
if (specs)
{
int index = luaL_checkint( L, 2 );
luaL_argcheck( L, 1 <= index && static_cast<unsigned int> (index) <= specs->size(), 2,
"index out of range" );
DisplaySpecs::iterator it = specs->begin();
std::advance( it, index - 1 );
DisplaySpec *s = const_cast<DisplaySpec *>(&(*it));
s->PushSelf( L );
}
else
{
lua_pushnil( L );
}
return 1;
}
const luaL_Reg DisplaySpecs_meta[] =
{
{"__gc", DisplaySpecs_gc},
{"__index", DisplaySpecs_get},
{"__len", DisplaySpecs_len},
{"__tostring", DisplaySpecs_tostring},
{NULL, NULL}
};
void register_DisplaySpecs(lua_State *L)
{
luaL_newmetatable( L, DISPLAYSPECS );
luaL_openlib( L, 0, DisplaySpecs_meta, 0 );
lua_pop( L, 1 );
}
}
REGISTER_WITH_LUA_FUNCTION(register_DisplaySpecs);
DisplaySpecs *pushDisplaySpecs(lua_State *L, const DisplaySpecs &specs)
{
void *vpSpecs = lua_newuserdata( L, sizeof( DisplaySpecs ));
DisplaySpecs *pspecs = new( vpSpecs ) DisplaySpecs( specs );
luaL_getmetatable( L, DISPLAYSPECS );
lua_setmetatable( L, -2 );
return pspecs;
}