Skip to content

Commit

Permalink
Add --force-panel-type and --force-external-orientation arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
honjow committed Apr 10, 2024
1 parent 9583874 commit 95983d1
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 5 deletions.
74 changes: 74 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"files.associations": {
"*.tpl": "nunjucks",
"*.install": "shellscript",
"*.dsl": "asl",
"*.migration": "shellscript",
"__bit_reference": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__split_buffer": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__verbose_abort": "cpp",
"array": "cpp",
"atomic": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"exception": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"mutex": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"queue": "cpp",
"ratio": "cpp",
"set": "cpp",
"span": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"thread": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"variant": "cpp",
"vector": "cpp",
"algorithm": "cpp"
}
}
67 changes: 62 additions & 5 deletions src/drm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ namespace gamescope
GamescopeKnownDisplays GetKnownDisplayType() const { return m_Mutable.eKnownDisplay; }
const displaycolorimetry_t& GetDisplayColorimetry() const { return m_Mutable.DisplayColorimetry; }

// GamescopePanelType

std::span<const uint8_t> GetRawEDID() const override { return std::span<const uint8_t>{ m_Mutable.EdidData.begin(), m_Mutable.EdidData.end() }; }

bool SupportsHDR10() const
Expand All @@ -281,14 +283,30 @@ namespace gamescope

GamescopeScreenType GetScreenType() const override
{
if ( m_pConnector->connector_type == DRM_MODE_CONNECTOR_eDP ||
m_pConnector->connector_type == DRM_MODE_CONNECTOR_LVDS ||
m_pConnector->connector_type == DRM_MODE_CONNECTOR_DSI )
return GAMESCOPE_SCREEN_TYPE_INTERNAL;
switch ( m_ChosenPanelType )
{
case GAMESCOPE_PANEL_TYPE_INTERNAL:
return GAMESCOPE_SCREEN_TYPE_INTERNAL;
case GAMESCOPE_PANEL_TYPE_EXTERNAL:
return GAMESCOPE_SCREEN_TYPE_EXTERNAL;
case GAMESCOPE_PANEL_TYPE_AUTO:
if ( m_pConnector->connector_type == DRM_MODE_CONNECTOR_eDP ||
m_pConnector->connector_type == DRM_MODE_CONNECTOR_LVDS ||
m_pConnector->connector_type == DRM_MODE_CONNECTOR_DSI )
return GAMESCOPE_SCREEN_TYPE_INTERNAL;
break;
}

return GAMESCOPE_SCREEN_TYPE_EXTERNAL;
}

bool GetDisplayTypeInternal()
{
return m_pConnector->connector_type == DRM_MODE_CONNECTOR_eDP ||
m_pConnector->connector_type == DRM_MODE_CONNECTOR_LVDS ||
m_pConnector->connector_type == DRM_MODE_CONNECTOR_DSI;
}

GamescopePanelOrientation GetCurrentOrientation() const override
{
return m_ChosenOrientation;
Expand Down Expand Up @@ -345,6 +363,8 @@ namespace gamescope

void UpdateEffectiveOrientation( const drmModeModeInfo *pMode );

void SetPanelType( GamescopePanelType ePanelType );

private:
void ParseEDID();

Expand Down Expand Up @@ -372,6 +392,8 @@ namespace gamescope

GamescopePanelOrientation m_ChosenOrientation = GAMESCOPE_PANEL_ORIENTATION_AUTO;

GamescopePanelType m_ChosenPanelType = GAMESCOPE_PANEL_TYPE_AUTO;

ConnectorProperties m_Props;
};

Expand Down Expand Up @@ -500,6 +522,9 @@ bool g_bSupportsSyncObjs = false;
extern gamescope::GamescopeModeGeneration g_eGamescopeModeGeneration;
extern GamescopePanelOrientation g_DesiredInternalOrientation;

extern GamescopePanelType g_eGamescopePanelType;
extern GamescopePanelExternalOrientation g_eGamescopePanelExternalOrientation;

extern bool g_bForceDisableColorMgmt;

static LogScope drm_log("drm");
Expand Down Expand Up @@ -1923,7 +1948,29 @@ namespace gamescope

void CDRMConnector::UpdateEffectiveOrientation( const drmModeModeInfo *pMode )
{
if ( this->GetScreenType() == GAMESCOPE_SCREEN_TYPE_INTERNAL && g_DesiredInternalOrientation != GAMESCOPE_PANEL_ORIENTATION_AUTO )
if ( this->GetScreenType() == GAMESCOPE_SCREEN_TYPE_EXTERNAL &&
g_eGamescopePanelExternalOrientation != GAMESCOPE_PANEL_EXTERNAL_ORIENTATION_AUTO &&
this->GetDisplayTypeInternal() )
{
switch ( g_eGamescopePanelExternalOrientation )
{
case GAMESCOPE_PANEL_EXTERNAL_ORIENTATION_0:
m_ChosenOrientation = GAMESCOPE_PANEL_ORIENTATION_0;
return;
case GAMESCOPE_PANEL_EXTERNAL_ORIENTATION_90:
m_ChosenOrientation = GAMESCOPE_PANEL_ORIENTATION_90;
return;
case GAMESCOPE_PANEL_EXTERNAL_ORIENTATION_180:
m_ChosenOrientation = GAMESCOPE_PANEL_ORIENTATION_180;
return;
case GAMESCOPE_PANEL_EXTERNAL_ORIENTATION_270:
m_ChosenOrientation = GAMESCOPE_PANEL_ORIENTATION_270;
return;
default:
break;
}
}
else if ( this->GetScreenType() == GAMESCOPE_SCREEN_TYPE_INTERNAL && g_DesiredInternalOrientation != GAMESCOPE_PANEL_ORIENTATION_AUTO )
{
m_ChosenOrientation = g_DesiredInternalOrientation;
}
Expand Down Expand Up @@ -1964,6 +2011,14 @@ namespace gamescope
}
}

// void CDRMConnector::SetPanelType( GamescopePanelType ePanelType )
// {
// if ( ePanelType == m_ChosenPanelType )
// return;

// m_ChosenPanelType = ePanelType;
// }

void CDRMConnector::ParseEDID()
{
if ( !GetProperties().EDID )
Expand Down Expand Up @@ -2017,6 +2072,8 @@ namespace gamescope

drm_log.infof("Connector %s -> %s - %s", m_Mutable.szName, m_Mutable.szMakePNP, m_Mutable.szModel );

m_ChosenPanelType = g_eGamescopePanelType;

const bool bSteamDeckDisplay =
( m_Mutable.szMakePNP == "WLC"sv && m_Mutable.szModel == "ANX7530 U"sv ) ||
( m_Mutable.szMakePNP == "ANX"sv && m_Mutable.szModel == "ANX7530 U"sv ) ||
Expand Down
16 changes: 16 additions & 0 deletions src/gamescope_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ enum GamescopePanelOrientation
GAMESCOPE_PANEL_ORIENTATION_AUTO,
};

enum GamescopePanelExternalOrientation
{
GAMESCOPE_PANEL_EXTERNAL_ORIENTATION_0, /* NORMAL */
GAMESCOPE_PANEL_EXTERNAL_ORIENTATION_270, /* RIGHT */
GAMESCOPE_PANEL_EXTERNAL_ORIENTATION_90, /* LEFT */
GAMESCOPE_PANEL_EXTERNAL_ORIENTATION_180, /* UPSIDE DOWN */
GAMESCOPE_PANEL_EXTERNAL_ORIENTATION_AUTO,
};

enum GamescopePanelType
{
GAMESCOPE_PANEL_TYPE_INTERNAL,
GAMESCOPE_PANEL_TYPE_EXTERNAL,
GAMESCOPE_PANEL_TYPE_AUTO,
};

// Disable partial composition for now until we get
// composite priorities working in libliftoff + also
// use the proper libliftoff composite plane system.
Expand Down
38 changes: 38 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ const struct option *gamescope_options = (struct option[]){
{ "disable-xres", no_argument, nullptr, 'x' },
{ "fade-out-duration", required_argument, nullptr, 0 },
{ "force-orientation", required_argument, nullptr, 0 },
{ "force-external-orientation", required_argument, nullptr, 0 },
{ "force-panel-type", required_argument, nullptr, 0 },
{ "force-windows-fullscreen", no_argument, nullptr, 0 },

{ "disable-color-management", no_argument, nullptr, 0 },
Expand Down Expand Up @@ -173,6 +175,8 @@ const char usage[] =
" --xwayland-count create N xwayland servers\n"
" --prefer-vk-device prefer Vulkan device for compositing (ex: 1002:7300)\n"
" --force-orientation rotate the internal display (left, right, normal, upsidedown)\n"
" --force-external-orientation rotate the external display (left, right, normal, upsidedown)\n"
" --force-panel-type force gamescope to treat the display as either internal or external\n"
" --force-windows-fullscreen force windows inside of gamescope to be the size of the nested display (fullscreen)\n"
" --cursor-scale-height if specified, sets a base output height to linearly scale the cursor against.\n"
" --hdr-enabled enable HDR output (needs Gamescope WSI layer enabled for support from clients)\n"
Expand Down Expand Up @@ -343,6 +347,19 @@ static gamescope::GamescopeModeGeneration parse_gamescope_mode_generation( const
}
}

GamescopePanelType g_eGamescopePanelType = GAMESCOPE_PANEL_TYPE_AUTO;
static GamescopePanelType force_panel_type(const char *str)
{
if (strcmp(str, "internal") == 0) {
return GAMESCOPE_PANEL_TYPE_INTERNAL;
} else if (strcmp(str, "external") == 0) {
return GAMESCOPE_PANEL_TYPE_EXTERNAL;
} else {
fprintf( stderr, "gamescope: invalid value for --force-panel-type\n" );
exit(1);
}
}

GamescopePanelOrientation g_DesiredInternalOrientation = GAMESCOPE_PANEL_ORIENTATION_AUTO;
static GamescopePanelOrientation force_orientation(const char *str)
{
Expand Down Expand Up @@ -400,6 +417,23 @@ struct sigaction handle_signal_action = {};
extern std::mutex g_ChildPidMutex;
extern std::vector<pid_t> g_ChildPids;

GamescopePanelExternalOrientation g_eGamescopePanelExternalOrientation = GAMESCOPE_PANEL_EXTERNAL_ORIENTATION_AUTO;
static GamescopePanelExternalOrientation force_external_orientation(const char *str)
{
if (strcmp(str, "normal") == 0) {
return GAMESCOPE_PANEL_EXTERNAL_ORIENTATION_0;
} else if (strcmp(str, "right") == 0) {
return GAMESCOPE_PANEL_EXTERNAL_ORIENTATION_270;
} else if (strcmp(str, "left") == 0) {
return GAMESCOPE_PANEL_EXTERNAL_ORIENTATION_90;
} else if (strcmp(str, "upsidedown") == 0) {
return GAMESCOPE_PANEL_EXTERNAL_ORIENTATION_180;
} else {
fprintf( stderr, "gamescope: invalid value for --force-external-orientation\n" );
exit(1);
}
}

static void handle_signal( int sig )
{
switch ( sig ) {
Expand Down Expand Up @@ -657,6 +691,10 @@ int main(int argc, char **argv)
initialize_custom_modes( optarg );
} else if (strcmp(opt_name, "force-orientation") == 0) {
g_DesiredInternalOrientation = force_orientation( optarg );
} else if (strcmp(opt_name, "force-external-orientation") == 0) {
g_eGamescopePanelExternalOrientation = force_external_orientation( optarg );
} else if (strcmp(opt_name, "force-panel-type") == 0) {
g_eGamescopePanelType = force_panel_type( optarg );
} else if (strcmp(opt_name, "sharpness") == 0 ||
strcmp(opt_name, "fsr-sharpness") == 0) {
g_upscaleFilterSharpness = atoi( optarg );
Expand Down

0 comments on commit 95983d1

Please sign in to comment.