Skip to content

Commit

Permalink
Add --force-panel-type and --force-external-orientation arguments (#2)
Browse files Browse the repository at this point in the history
* Add --force-panel-type and --force-external-orientation arguments.

* Rotate only the internal display when faked as "external"

* Try to prevent the external display from being rotated when --force-panel-type external is used.

* Fixed docking issue when --force-panel-type external is used and you dock/undock the handheld.
  • Loading branch information
ruineka authored and Samsagax committed Apr 10, 2024
1 parent 868fd68 commit 0687da2
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 7 deletions.
54 changes: 47 additions & 7 deletions src/drm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ uint32_t g_nDRMFormat = DRM_FORMAT_INVALID;
uint32_t g_nDRMFormatOverlay = DRM_FORMAT_INVALID; // for partial composition, we may have more limited formats than base planes + alpha.
bool g_bRotated = false;
bool g_rotate_ctl_enable = false;
bool g_bDisplayTypeInternal = false;
bool g_bUseLayers = true;
bool g_bDebugLayers = false;
const char *g_sOutputName = nullptr;
Expand All @@ -68,6 +69,8 @@ enum drm_mode_generation g_drmModeGeneration = DRM_MODE_GENERATE_CVT;
enum g_panel_orientation g_drmModeOrientation = PANEL_ORIENTATION_AUTO;
enum g_rotate_ctl g_drmRotateCTL;
std::atomic<uint64_t> g_drmEffectiveOrientation[DRM_SCREEN_TYPE_COUNT]{ {DRM_MODE_ROTATE_0}, {DRM_MODE_ROTATE_0} };
enum g_panel_external_orientation g_drmModeExternalOrientation = PANEL_EXTERNAL_ORIENTATION_AUTO;
enum g_panel_type g_drmPanelType = PANEL_TYPE_AUTO;

bool g_bForceDisableColorMgmt = false;

Expand Down Expand Up @@ -1972,8 +1975,29 @@ static uint64_t determine_drm_orientation(struct drm_t *drm, struct connector *c
static void update_drm_effective_orientation(struct drm_t *drm, struct connector *conn, const drmModeModeInfo *mode)
{
drm_screen_type screenType = drm_get_connector_type(conn->connector);

if (screenType == DRM_SCREEN_TYPE_INTERNAL)
if ( screenType == DRM_SCREEN_TYPE_EXTERNAL && g_bDisplayTypeInternal == true )
{
switch ( g_drmModeExternalOrientation )
{
case PANEL_EXTERNAL_ORIENTATION_0:
g_drmEffectiveOrientation[screenType] = DRM_MODE_ROTATE_0;
break;
case PANEL_EXTERNAL_ORIENTATION_90:
g_drmEffectiveOrientation[screenType] = DRM_MODE_ROTATE_90;
break;
case PANEL_EXTERNAL_ORIENTATION_180:
g_drmEffectiveOrientation[screenType] = DRM_MODE_ROTATE_180;
break;
case PANEL_EXTERNAL_ORIENTATION_270:
g_drmEffectiveOrientation[screenType] = DRM_MODE_ROTATE_270;
break;
case PANEL_EXTERNAL_ORIENTATION_AUTO:
g_drmEffectiveOrientation[screenType] = determine_drm_orientation(drm, conn, mode);
break;
}
return;
}
else if ( screenType == DRM_SCREEN_TYPE_INTERNAL )
{
switch ( g_drmModeOrientation )
{
Expand Down Expand Up @@ -2924,11 +2948,27 @@ bool drm_get_vrr_in_use(struct drm_t *drm)

drm_screen_type drm_get_connector_type(drmModeConnector *connector)
{
if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
connector->connector_type == DRM_MODE_CONNECTOR_LVDS ||
connector->connector_type == DRM_MODE_CONNECTOR_DSI)
return DRM_SCREEN_TYPE_INTERNAL;

// Set to the default state of false to make sure the external display isn't rotated when a system is docked
g_bDisplayTypeInternal = false;
switch ( g_drmPanelType )
{
case PANEL_TYPE_INTERNAL:
return DRM_SCREEN_TYPE_INTERNAL;
break;
case PANEL_TYPE_EXTERNAL:
if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
connector->connector_type == DRM_MODE_CONNECTOR_LVDS ||
connector->connector_type == DRM_MODE_CONNECTOR_DSI)
g_bDisplayTypeInternal = true;
return DRM_SCREEN_TYPE_EXTERNAL;
break;
case PANEL_TYPE_AUTO:
if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
connector->connector_type == DRM_MODE_CONNECTOR_LVDS ||
connector->connector_type == DRM_MODE_CONNECTOR_DSI)
return DRM_SCREEN_TYPE_INTERNAL;
break;
}
return DRM_SCREEN_TYPE_EXTERNAL;
}

Expand Down
15 changes: 15 additions & 0 deletions src/drm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,26 @@ enum g_rotate_ctl{
UPSIDEDOWN,
RIGHT_UP,
};
enum g_panel_external_orientation {
PANEL_EXTERNAL_ORIENTATION_0, /* NORMAL */
PANEL_EXTERNAL_ORIENTATION_270, /* RIGHT */
PANEL_EXTERNAL_ORIENTATION_90, /* LEFT */
PANEL_EXTERNAL_ORIENTATION_180, /* UPSIDE DOWN */
PANEL_EXTERNAL_ORIENTATION_AUTO,
};

enum g_panel_type {
PANEL_TYPE_INTERNAL,
PANEL_TYPE_EXTERNAL,
PANEL_TYPE_AUTO,
};

extern enum drm_mode_generation g_drmModeGeneration;
extern enum g_panel_orientation g_drmModeOrientation;
extern enum g_rotate_ctl g_drmRotateCTL;
extern bool g_rotate_ctl_enable;
extern enum g_panel_external_orientation g_drmModeExternalOrientation;
extern enum g_panel_type g_drmPanelType;

extern std::atomic<uint64_t> g_drmEffectiveOrientation[DRM_SCREEN_TYPE_COUNT]; // DRM_MODE_ROTATE_*

Expand Down
36 changes: 36 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,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 @@ -167,6 +169,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 @@ -353,6 +357,18 @@ static enum drm_mode_generation parse_drm_mode_generation(const char *str)
}
}

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

static enum g_panel_orientation force_orientation(const char *str)
{
if (strcmp(str, "normal") == 0) {
Expand Down Expand Up @@ -408,6 +424,22 @@ static enum GamescopeUpscaleFilter parse_upscaler_filter(const char *str)
struct sigaction handle_signal_action = {};
extern pid_t child_pid;

static enum g_panel_external_orientation force_external_orientation(const char *str)
{
if (strcmp(str, "normal") == 0) {
return PANEL_EXTERNAL_ORIENTATION_0;
} else if (strcmp(str, "right") == 0) {
return PANEL_EXTERNAL_ORIENTATION_270;
} else if (strcmp(str, "left") == 0) {
return PANEL_EXTERNAL_ORIENTATION_90;
} else if (strcmp(str, "upsidedown") == 0) {
return 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 @@ -614,6 +646,10 @@ int main(int argc, char **argv)
g_drmModeGeneration = parse_drm_mode_generation( optarg );
} else if (strcmp(opt_name, "force-orientation") == 0) {
g_drmModeOrientation = force_orientation( optarg );
} else if (strcmp(opt_name, "force-external-orientation") == 0) {
g_drmModeExternalOrientation = force_external_orientation( optarg );
} else if (strcmp(opt_name, "force-panel-type") == 0) {
g_drmPanelType = 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 0687da2

Please sign in to comment.