11#ifndef BOOST_PROCESS_VERSION
12 #define BOOST_PROCESS_VERSION 1
19#include <unordered_map>
23#include <boost/process/v1/child.hpp>
24#include <boost/process/v1/group.hpp>
25#include <boost/process/v1/environment.hpp>
26#include <boost/process/v1/search_path.hpp>
27#include <boost/property_tree/ptree.hpp>
28#include <nlohmann/json.hpp>
38#define VIRTUAL_DISPLAY_UUID "8902CB19-674A-403D-A587-41B092E900BA"
39#define FALLBACK_DESKTOP_UUID "EAAC6159-089A-46A9-9E24-6436885F6610"
40#define REMOTE_INPUT_UUID "8CB5C136-DA67-4F99-B4A1-F9CD35005CF4"
41#define TERMINATE_APP_UUID "E16CBE1B-295D-4632-9A76-EC4180C857D3"
42#define DETACHED_DESKTOP_UUID "5B1C7E0A-3D52-4F8E-9A61-2E7D0C4B9F13"
43#define DETACHED_STEAM_UUID "A4E2F6C8-1B37-4D95-8C0E-7F3A9D2B6E51"
46 using file_t = util::safe_ptr_v2<FILE, int, fclose>;
50 typedef config::prep_cmd_t cmd_t;
77 std::vector<cmd_t> prep_cmds;
78 std::vector<cmd_t> state_cmds;
98 std::string working_dir;
100 std::string image_path;
106 bool virtual_display;
113 bool virtual_display_primary;
114 bool use_app_identity;
115 bool per_client_app_identity;
116 bool allow_client_commands;
117 bool terminate_on_pause;
118 bool unlock_host_session;
125 std::string isolation_method;
127 bool host_session {
false};
130 std::chrono::seconds first_frame_timeout {0};
134 std::string virtual_display_layout;
138 std::string gamescope_steam_mode;
141 std::string gamescope_args;
145 std::string isolate_devices;
146 std::string isolate_sound;
149 std::string stop_desktop_steam;
151 std::chrono::seconds exit_timeout;
163 const rtsp_stream::launch_session_t &launch_session,
232 bool isolated_sessions_enabled,
233 bool virtual_display_requested,
234 std::string_view global_method =
"gamescope"
242 KITTY_DEFAULT_CONSTR_MOVE_THROW(proc_t)
244 std::string display_name;
245 std::string initial_display;
246 std::string mode_changed_display;
247 bool initial_hdr =
false;
248 bool virtual_display =
false;
249 bool allow_client_commands =
false;
252 boost::process::v1::environment &&env,
253 std::vector<ctx_t> &&apps
255 _env(std::move(env)),
256 _apps(std::move(apps)) {
259 void launch_input_only();
261 int execute(
const ctx_t& _app, std::shared_ptr<rtsp_stream::launch_session_t> launch_session);
274 std::shared_ptr<rtsp_stream::launch_session_t> launch_session,
275 bool apply_scale =
true,
276 const ctx_t *session_app =
nullptr,
277 std::optional<uid_t> session_owner_uid = std::nullopt,
278 bool isolated_session =
false
287 std::shared_ptr<rtsp_stream::launch_session_t> launch_session
316 uint32_t launch_session_id {};
317 std::string client_uuid;
318 std::string client_name;
320 std::string app_name;
322 std::string compositor;
326 uint32_t account_uid {};
330 int64_t uptime_seconds {};
338 std::string running_app_uuid_for_client(
const std::string &client_uuid);
344 boost::process::v1::environment
get_session_env(uint32_t launch_session_id);
366 std::shared_ptr<rtsp_stream::launch_session_t> launch_session
376 const std::vector<ctx_t> &get_apps()
const;
377 std::vector<ctx_t> &get_apps();
378 std::string get_app_image(
int app_id);
379 std::string get_last_run_app_name();
380 std::string get_running_app_uuid();
381 boost::process::v1::environment get_env();
384 void terminate(
bool immediate =
false,
bool needs_refresh =
true);
388 std::string _app_name;
390 boost::process::v1::environment _env;
392 std::shared_ptr<rtsp_stream::launch_session_t> _launch_session;
393 std::shared_ptr<config::input_t> _saved_input_config;
395 std::vector<ctx_t> _apps;
397 std::chrono::steady_clock::time_point _app_launch_time;
402 std::vector<std::pair<std::string, std::optional<std::string>>> _frame_limit_restore;
404 bool _reopen_desktop_steam {};
405 bool _desktop_steam_flatpak {};
407 boost::process::v1::child _process;
408 boost::process::v1::group _process_group;
410 std::vector<std::string> _detached_units;
413 std::vector<cmd_t>::const_iterator _app_prep_it;
414 std::vector<cmd_t>::const_iterator _app_prep_begin;
417 boost::filesystem::path
418 find_working_directory(
const std::string &cmd,
const boost::process::v1::environment &env);
424 std::tuple<std::string, std::string>
calculate_app_id(
const std::string &app_name, std::string app_image_path,
int index);
426 std::string validate_app_image_path(std::string app_image_path);
427 void refresh(
const std::string &file_name,
bool needs_terminate =
true);
428 void migrate_apps(nlohmann::json* fileTree_p, nlohmann::json* inputTree_p);
438 std::optional<proc::proc_t>
parse(
const std::string &file_name,
bool fallback_on_failure =
true);
444 std::unique_ptr<platf::deinit_t>
init();
458 void terminate_process_group(boost::process::v1::child &proc, boost::process::v1::group &group, std::chrono::seconds exit_timeout);
462 extern int input_only_app_id;
463 extern std::string input_only_app_id_str;
464 extern int terminate_app_id;
465 extern std::string terminate_app_id_str;
468#ifdef BOOST_PROCESS_VERSION
469 #undef BOOST_PROCESS_VERSION
int execute_isolated(const ctx_t &app, std::shared_ptr< rtsp_stream::launch_session_t > launch_session)
int running_for_client(const std::string &client_uuid)
void terminate_isolated_client(const std::string &client_uuid)
std::string isolated_audio_sink(uint32_t launch_session_id)
The sink an isolated session plays into, or empty for one that shares the host's.
bool isolated_client_present(const std::string &client_uuid)
std::string isolated_audio_server(uint32_t launch_session_id)
std::string isolated_mic_source(uint32_t launch_session_id)
bool isolated_session_has_account(uint32_t launch_session_id)
Whether an isolated session runs under a helper account of its own, whose audio server the host's can...
void terminate_isolated(uint32_t launch_session_id)
void disconnect_isolated(uint32_t launch_session_id)
int prepare_session_virtual_display(std::shared_ptr< rtsp_stream::launch_session_t > launch_session, bool apply_scale=true, const ctx_t *session_app=nullptr, std::optional< uid_t > session_owner_uid=std::nullopt, bool isolated_session=false)
boost::process::v1::environment get_session_env(uint32_t launch_session_id)
bool prepare_isolated_resume(std::shared_ptr< rtsp_stream::launch_session_t > launch_session)
std::vector< isolated_session_t > list_isolated()
void terminate_all_isolated()
Declarations for common platform specific utilities.
Declarations for the configuration of Sunshine.
session_route_e resolve_session_route(const ctx_t &app, bool isolated_sessions_enabled, bool virtual_display_requested, std::string_view global_method)
void migrate_apps(nlohmann::json *fileTree_p, nlohmann::json *inputTree_p)
Migrate the applications stored in the file tree by merging in a new app.
std::string_view describe(virtual_display_source_e source)
bool launch_requests_virtual_display(const ctx_t &app, const rtsp_stream::launch_session_t &launch_session, bool headless_mode)
void migration_v7(nlohmann::json &fileTree)
void terminate_process_group(boost::process::v1::child &proc, boost::process::v1::group &group, std::chrono::seconds exit_timeout)
Terminates all child processes in a process group.
std::unique_ptr< platf::deinit_t > init()
Initialize proc functions.
virtual_display_decision_t decide_virtual_display(const ctx_t &app, const rtsp_stream::launch_session_t &launch_session, bool headless_mode)
std::tuple< std::string, std::string > calculate_app_id(const std::string &app_name, std::string app_image_path, int index)
Calculate a stable id based on name and image data.
std::optional< proc::proc_t > parse(const std::string &file_name, bool fallback_on_failure)
Load the applications from apps.json.
void initVDisplayDriver()
Initialize the virtual display driver. This should be called early in startup to enable virtual displ...
scale_factor_decision_t decide_scale_factor(const ctx_t &app, const rtsp_stream::launch_session_t &launch_session, int host_default)
@ host_default
Neither did; the host's default_scale_factor.
@ app
The client sent none; the app's own scale.
@ app_forced
The app forces its setting on every client.
@ default_rule
No explicit choice: client request, per-client or app setting.
Declarations for RTSP streaming.
bool limit_fps
Cap the application's frame rate at the stream's (DXVK, VKD3D-Proton, MangoHud).
bool force_virtual_display
bool stop_detached
Stop the app's detached commands, and all they started, when the app ends.
std::vector< std::string > detached
One live isolated session, as the host needs to see it.
std::string unit
The systemd unit, where the session has one.
std::string profile
"desktop" or "application".
bool running
False for one whose compositor has died but was not reaped.
std::string account_user
Empty where the session runs as the Hermes user.
std::string audio_sink
Empty where the session shares the host's audio.
Declarations for utility functions.
Virtual display declarations for Linux.
DRIVER_STATUS
Status of the virtual display driver.