15namespace platf::window_placement {
20 inline bool names_program(
const std::vector<std::string> &arguments, std::string_view program) {
21 return std::any_of(arguments.begin(), arguments.end(), [program](
const auto &argument) {
22 return std::filesystem::path {argument}.filename() == program;
26 inline bool opens_big_picture(
const std::vector<std::string> &arguments) {
27 const bool steam = names_program(arguments,
"steam") ||
28 (names_program(arguments,
"flatpak") &&
29 std::find(arguments.begin(), arguments.end(),
"com.valvesoftware.Steam") != arguments.end());
30 return steam && std::any_of(arguments.begin(), arguments.end(), [](std::string_view argument) {
31 return argument ==
"steam://open/bigpicture" || argument.starts_with(
"steam://open/bigpicture?") ||
32 argument ==
"-gamepadui" || argument ==
"-bigpicture" || argument ==
"-tenfoot";
36 inline bool launches_gamescope(
const std::vector<std::string> &arguments) {
37 return names_program(arguments,
"gamescope") || names_program(arguments,
"hermes-gamescope-launch");
50 if (names_program(arguments,
"hermes-gamescope-launch")) {
53 return names_program(arguments,
"gamescope") &&
54 (names_program(arguments,
"steam") ||
55 std::find(arguments.begin(), arguments.end(),
"com.valvesoftware.Steam") != arguments.end());
66 return names_program(arguments,
"steam") ||
67 std::find(arguments.begin(), arguments.end(),
"com.valvesoftware.Steam") != arguments.end() ||
68 std::any_of(arguments.begin(), arguments.end(), [](std::string_view argument) {
69 return argument.starts_with(
"steam://");
74 inline std::string kwin_script(
const std::string &output,
const std::vector<std::string> &classes,
const std::vector<std::uint32_t> &gamescope_pids) {
77 if (output.empty() || output.size() > 64 || classes.empty() ||
78 !std::all_of(output.begin(), output.end(), [](
unsigned char c) {
79 return std::isalnum(c) || c ==
'-' || c ==
'_';
83 std::string class_list;
84 for (
const auto &window_class : classes) {
85 if (window_class.empty() || window_class.find_first_not_of(
"abcdefghijklmnopqrstuvwxyz0123456789.-_") != std::string::npos) {
88 class_list += (class_list.empty() ?
"\"" :
", \"") + window_class +
'"';
91 for (
const auto pid : gamescope_pids) {
93 pid_list += (pid_list.empty() ?
"" :
", ") + std::to_string(pid);
97 return "// Hermes: position only the streamed application's windows.\n"
98 "const output = workspace.screens.find(screen => screen.name === \"" + output +
"\");\n"
99 "const classes = [" + class_list +
"];\n"
100 "const gamescopePids = [" + pid_list +
"];\n"
101 "function place(window) {\n"
102 " if (!output || !window.normalWindow || !classes.includes(window.resourceClass) || window.output === output) {\n"
105 " // Other Gamescope instances belong to the local desktop. The shipped\n"
106 " // launcher execs Gamescope, preserving the PID Hermes started. Custom\n"
107 " // launchers that fork it instead are left alone, never matched by class.\n"
108 " if (window.resourceClass === \"gamescope\" && !gamescopePids.includes(window.pid)) {\n"
111 " const wasFullScreen = window.fullScreen;\n"
112 " if (wasFullScreen) {\n"
113 " window.fullScreen = false;\n"
115 " workspace.sendClientToScreen(window, output);\n"
116 " if (wasFullScreen) {\n"
117 " window.fullScreen = true;\n"
120 "// A client can still pick its own output when it goes fullscreen. Steam\n"
121 "// opens Big Picture, is moved here, moves itself back to the primary\n"
122 "// monitor and goes fullscreen there; place it again once it has.\n"
123 "function watch(window) {\n"
125 " if (window.fullScreenChanged) {\n"
126 " window.fullScreenChanged.connect(() => {\n"
127 " if (window.fullScreen) {\n"
133 "workspace.windowList().forEach(watch);\n"
134 "workspace.windowAdded.connect(watch);\n";
bool gamescope_runs_steam(const std::vector< std::string > &arguments)
bool launches_steam(const std::vector< std::string > &arguments)