19namespace platf::gamescope {
36 inline std::string_view drm_selector_flag(drm_selector_e selector) {
38 case drm_selector_e::prefer_drm:
39 return "--prefer-drm";
40 case drm_selector_e::drm_device:
41 return "--drm-device";
42 case drm_selector_e::none:
53 const auto is_option_char = [](
char ch) {
54 return std::isalnum(
static_cast<unsigned char>(ch)) != 0 || ch ==
'-' || ch ==
'_';
56 for (
auto pos = help.find(option); pos != std::string_view::npos; pos = help.find(option, pos + 1)) {
57 const auto end = pos + option.size();
58 const bool starts_alone = pos == 0 || !is_option_char(help[pos - 1]);
59 const bool ends_alone = end == help.size() || !is_option_char(help[end]);
60 if (starts_alone && ends_alone) {
90 if (value ==
"--prefer-drm" || value ==
"prefer-drm") {
93 if (value ==
"--drm-device" || value ==
"drm-device") {
96 if (value ==
"none") {
108 constexpr std::string_view prefix {
"/dev/dri/card"};
109 if (!path.starts_with(prefix) || path.size() == prefix.size()) {
112 for (
const char ch : path.substr(prefix.size())) {
113 if (std::isdigit(
static_cast<unsigned char>(ch)) == 0) {
136 const auto begin = command.find_first_not_of(
" \t");
137 if (begin == std::string_view::npos) {
140 auto program = command.substr(begin, command.find_first_of(
" \t", begin) - begin);
141 if (
const auto slash = program.rfind(
'/'); slash != std::string_view::npos) {
142 program.remove_prefix(slash + 1);
144 return program ==
"steam" || program ==
"hermes-gamescope-launch" || program ==
"apollo-gamescope-launch";
148 constexpr std::string_view
default_args {
"--expose-wayland --force-windows-fullscreen"};
153 inline std::optional<std::string> session_option_override(std::span<const std::string> arguments) {
154 constexpr std::string_view reserved[] {
165 for (
const auto &argument : arguments) {
166 const std::string_view option = std::string_view {argument}.substr(0, argument.find(
'='));
167 if (option ==
"--") {
170 if (option.starts_with(
"--")) {
172 for (
const auto name : reserved) {
173 if (name.starts_with(option)) {
177 }
else if (argument.starts_with(
'-')) {
180 for (
const char flag : std::string_view {argument}.substr(1)) {
181 if (std::string_view {
"WHwhrO"}.find(flag) != std::string_view::npos) {
184 if (std::string_view {
"mSFsoRTC"}.find(flag) != std::string_view::npos) {
201 bool steam_mode =
false;
226 auto command = std::format(
227 "{} --backend=drm -W {} -H {} -w {} -h {} -r {}",
228 launch.binary.empty() ? std::string {
"gamescope"} : launch.binary,
236 command += std::format(
" {} {}", drm_selector_flag(launch.selector), launch.scanout_card);
238 command += launch.steam_mode ?
" -e --xwayland-count 2" :
" --xwayland-count 1";
240 command += launch.args.empty() ? std::string {
default_args} : launch.args;
241 if (!launch.connector.empty()) {
242 command +=
" -O " + launch.connector;
244 command +=
" -- " + launch.command;
constexpr std::string_view default_args
The optional flags an application session gets when its app sets none.
@ drm_device
–drm-device, the shorter downstream patch reported in Hermes#57.
@ none
No option: the build scans out on the device it renders with.
@ prefer_drm
–prefer-drm, ValveSoftware/gamescope#2220; also read from GAMESCOPE_PREFER_DRM.
bool steam_mode_for(std::string_view mode, std::string_view command)
std::optional< drm_selector_e > drm_selector_from_help(std::string_view help)
bool is_primary_card_path(std::string_view path)
std::string launch_command(const launch_t &launch)
bool help_lists_option(std::string_view help, std::string_view option)
std::optional< drm_selector_e > drm_selector_from_override(std::string_view value)
Functions for handling command line arguments.
std::string connector
The session card's connector, e.g. Virtual-2.
std::string binary
The executable; an absolute path for Hermes' own build.
std::string command
What runs inside Gamescope, after –.
std::string scanout_card
The session card's primary node.