Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
virtual_display.h File Reference

Virtual display declarations for Linux. More...

#include <atomic>
#include <chrono>
#include <condition_variable>
#include <cstdint>
#include <filesystem>
#include <functional>
#include <map>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
#include <sys/types.h>
#include "src/uuid.h"
#include "hermes_kms_color.h"
#include "monitor_restore.h"
Include dependency graph for virtual_display.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  VDISPLAY::EvdiVirtualDisplayStatus
struct  VDISPLAY::HermesKmsStatus
struct  VDISPLAY::EvdiStatus
struct  VDISPLAY::HermesKmsMetrics
 Output-lifetime counters read from the Hermes-KMS GET_METRICS ioctl. More...
struct  VDISPLAY::FeatureReport
struct  VDISPLAY::SessionFacts
 What was observed about the session, before any verdict is drawn. More...
struct  VDISPLAY::kscreen_point_t
 A point in KScreen's logical coordinate space. More...
struct  VDISPLAY::kscreen_hdr_state_t
struct  VDISPLAY::hdr_launch_mode_t
class  VDISPLAY::EvdiBuffer
struct  VDISPLAY::HermesKmsFrame
struct  VDISPLAY::HermesKmsUpdate
struct  VDISPLAY::HermesKmsCursor

Enumerations

enum class  VDISPLAY::DRIVER_STATUS {
  UNKNOWN = 1 , OK = 0 , FAILED = -1 , VERSION_INCOMPATIBLE = -2 ,
  WATCHDOG_FAILED = -3 , NOT_SUPPORTED = -4
}
 Status of the virtual display driver. More...
enum class  VDISPLAY::EVDI_DIAGNOSTIC {
  READY , INITIAL_DEVICE_CONFIGURATION_REQUIRED , LIBRARY_MISSING , MODULE_NOT_INSTALLED ,
  MODULE_NOT_LOADED , DKMS_BUILD_FAILED
}
 Actionable EVDI state exposed to the Web UI. More...
enum class  VDISPLAY::HERMES_KMS_DIAGNOSTIC {
  READY , MODULE_NOT_LOADED , MODULE_NOT_INSTALLED , DKMS_BUILD_FAILED ,
  UAPI_TOO_OLD , MISSING_CAPABILITIES , DEVICE_NODE_MISSING , NO_ACCESS
}
 Actionable Hermes-KMS state exposed to the Web UI. More...
enum class  VDISPLAY::virtual_display_layout_e { extend , detached , mirror , primary }
 Where the host compositor places a newly created virtual output. More...
enum class  VDISPLAY::compositor_e {
  unknown , kwin , mutter , hyprland ,
  wlroots , cosmic
}
 The Wayland compositor driving this session. More...
enum class  VDISPLAY::feature_e {
  virtual_display , client_requested_mode , exclusive_mode , multiple_displays ,
  isolated_sessions , zero_copy_capture
}
 A thing Hermes does that a session either supports or does not. More...
enum class  VDISPLAY::readiness_e { ready , degraded , unavailable , unknown }
 How well a session supports one feature. More...
enum class  VDISPLAY::kscreen_mode_state_e { unknown_output , not_advertised , advertised , current }
 What kscreen-doctor -j says about a mode on one output. More...

Functions

HermesKmsMetrics VDISPLAY::getHermesKmsMetrics ()
 Read the Hermes-KMS device metrics, if a metrics-capable device is present. It opens a short-lived render fd and binds the active generic session capability before reading protected counters.
DRIVER_STATUS VDISPLAY::openVDisplayDevice ()
 Initialize the virtual display driver.
bool VDISPLAY::needsInitialDeviceConfiguration ()
 Whether EVDI needs a device pre-created at module load time.
EVDI_DIAGNOSTIC VDISPLAY::getEvdiDiagnostic ()
EvdiStatus VDISPLAY::getEvdiStatus ()
HERMES_KMS_DIAGNOSTIC VDISPLAY::getHermesKmsDiagnostic ()
HermesKmsStatus VDISPLAY::getHermesKmsStatus ()
void VDISPLAY::closeVDisplayDevice ()
 Close the virtual display driver.
bool VDISPLAY::startPingThread (std::function< void()> failCb)
 Start a ping thread to keep the virtual display alive.
bool VDISPLAY::setRenderAdapterByName (const std::string &adapterName)
 Set the render adapter by name.
std::string VDISPLAY::createVirtualDisplay (const char *s_client_uid, const char *s_client_name, uint32_t width, uint32_t height, uint32_t fps, const uuid_util::uuid_t &guid, std::optional< uid_t > session_owner_uid=std::nullopt, virtual_display_layout_e layout=virtual_display_layout_e::extend, bool isolated_session=false)
 Create a virtual display.
bool VDISPLAY::removeVirtualDisplay (const uuid_util::uuid_t &guid)
 Remove a virtual display.
int VDISPLAY::changeDisplaySettings (const char *deviceName, int width, int height, int refresh_rate, int deadline_ms=4000)
 Change the display settings of a virtual display.
int VDISPLAY::changeDisplaySettings2 (const char *deviceName, int width, int height, int refresh_rate, bool bApplyIsolated=false)
 Change the display settings with isolated display option.
std::string VDISPLAY::getEvdiConnectorName (const std::string &displayName)
std::string VDISPLAY::getHermesKmsConnectorName (const std::string &displayName)
std::string VDISPLAY::compositorName (compositor_e compositor)
std::string VDISPLAY::featureName (feature_e feature)
std::string VDISPLAY::readinessName (readiness_e readiness)
std::vector< FeatureReport > VDISPLAY::assessSession (const SessionFacts &facts)
 Turn observations into a per-feature verdict with remediation.
SessionFacts VDISPLAY::probeSessionFacts ()
void VDISPLAY::logSessionAssessment ()
 Probe, assess and log what this session can and cannot do.
bool VDISPLAY::hermesKmsSeatIsolationActive ()
 Whether Hermes-KMS session cards carry a private DRM seat.
std::optional< bool > VDISPLAY::displayConnectorLit (const std::filesystem::path &drm_class="/sys/class/drm", const std::string &ignored_connector={})
 Whether any DRM connector is lighting a monitor right now.
bool VDISPLAY::windowSystemAttached ()
 Whether Hermes runs inside a graphical session (Wayland or X11).
std::optional< std::string > VDISPLAY::boundedCommandOutput (const std::string &command, std::chrono::milliseconds timeout, bool *timed_out=nullptr)
 Run a shell command and collect its standard output, waiting no longer than timeout for it.
bool VDISPLAY::displayServerReachable (const std::string &wayland_display, const std::string &x_display, const std::string &runtime_dir)
 Whether a display server is listening where these variables point.
std::optional< bool > VDISPLAY::graphicalSessionPresent ()
 Whether this user has a session of their own, as logind sees it - graphical or not, so a "yes" does not mean a desktop is up.
bool VDISPLAY::inLoginSession ()
 Whether Hermes itself runs inside a login session - started from a terminal or over SSH - rather than as a service of the user manager.
std::optional< std::vector< std::string > > VDISPLAY::userManagerEnvironment ()
 The environment the systemd user manager hands to the units it starts, as "NAME=value" strings.
bool VDISPLAY::waitForConnectorEnabled (const std::string &connector, std::chrono::milliseconds timeout, const std::filesystem::path &drm_class="/sys/class/drm")
 Wait until some compositor has bound connector to a CRTC.
bool VDISPLAY::removalStrandsGreeter (bool greeter_on_seat, bool output_lit, std::optional< bool > another_connector_lit)
 Whether removing a virtual display would leave the login greeter with nothing to draw on.
std::string VDISPLAY::parkedConnector ()
 The connector of the output being kept for the login greeter, or empty. It is lit, but it is not a monitor the host has.
compositor_e VDISPLAY::compositorFromDesktopNames (const std::string &desktop_names)
 Classify a compositor from an XDG_CURRENT_DESKTOP-style value.
compositor_e VDISPLAY::sessionCompositor ()
 Classify the compositor of the running session.
bool VDISPLAY::buildMutterLayoutWithoutConnector (const std::string &current_state, const std::string &virtual_connector, std::string &serial, std::string &argument)
 Build the Mutter ApplyMonitorsConfig payload that drops a connector.
bool VDISPLAY::buildMutterLayoutWithMode (const std::string &current_state, const std::string &connector, uint32_t width, uint32_t height, uint32_t refresh_mhz, std::string &serial, std::string &argument)
 Build the Mutter ApplyMonitorsConfig payload that drives a connector at a requested geometry.
bool VDISPLAY::buildMutterExclusiveLayout (const std::string &current_state, const std::string &connector, std::string &serial, std::string &argument)
 Build the ApplyMonitorsConfig payload that hands the desktop to connector alone, which is how a monitor is turned off on GNOME: Mutter disables every connected monitor absent from the config.
bool VDISPLAY::buildMutterMirrorLayout (const std::string &current_state, const std::string &connector, std::string &serial, std::string &argument)
 Build the payload that clones the primary output onto connector.
bool VDISPLAY::buildMutterRestoreLayout (const std::string &current_state, std::string &serial, std::string &argument)
 Build the payload that reproduces the layout in current_state.
uint64_t VDISPLAY::displayLayoutGeneration ()
 A counter bumped whenever the desktop layout changes underneath a running session.
std::string VDISPLAY::mutterInputDeviceOutputValue (const std::string &current_state, const std::string &connector)
 The GNOME output value that binds an input device to connector.
void VDISPLAY::mutterInputDeviceSettingsTargets (std::string &touch, std::string &pen)
 The relocatable-schema targets whose output key binds Hermes' own touch and pen devices, as <schema>:<path>.
std::string VDISPLAY::systemdUserBusAddress (uint32_t uid)
 The standard systemd user-bus address for uid.
bool VDISPLAY::unlockHostSessionIfLocked ()
 Unlock the active graphical login session for the Hermes user when locked.
bool VDISPLAY::isHermesKWinInputDevice (const std::string &name, uint32_t vendor, uint32_t product)
 Whether a device KWin reports is one of Hermes' touch or pen devices.
std::string VDISPLAY::buildKWinInputBindingReadCommand (const std::string &device_name)
 The kreadconfig6 command that prints the output UUID a KWin input device is bound to. It prints nothing when there is none.
std::string VDISPLAY::buildKWinInputBindingRestoreCommand (const std::string &device_name, const std::string &previous_uuid)
 The kwriteconfig6 command that puts a KWin input device's binding back to previous_uuid, deleting the key when it is empty.
bool VDISPLAY::mutterDisplayGeometry (const std::string &current_state, const std::string &connector, int &offset_x, int &offset_y, int &environment_width, int &environment_height)
 Where a connector sits on a GNOME desktop, for absolute input.
kscreen_point_t VDISPLAY::kscreenVirtualOutputPosition (const std::string &virtual_output, const std::vector< kscreen_output_t > &before, const std::vector< kscreen_output_t > &current, virtual_display_layout_e layout)
 Decide where the virtual output goes, in KScreen's logical space.
bool VDISPLAY::kscreenDisplayGeometry (const std::vector< kscreen_output_t > &outputs, const std::string &output_name, int &offset_x, int &offset_y, int &environment_width, int &environment_height)
 Resolve one KScreen output inside the live desktop envelope.
std::string VDISPLAY::buildKScreenLayoutCommand (const std::string &virtual_output, const std::map< std::string, int > &enabled_before, int target_x, int target_y, int mode_width, int mode_height, int mode_refresh_hz, const std::map< std::string, kscreen_point_t > &positions_before={}, virtual_display_layout_e layout=virtual_display_layout_e::extend)
 Build the kscreen-doctor invocation that enables a virtual output, places it, and drives it at a requested mode.
kscreen_mode_state_e VDISPLAY::kscreenModeState (const std::string &json_text, const std::string &output, int width, int height, int refresh_hz)
 Find a mode on one output in a kscreen-doctor -j reply.
std::optional< kscreen_hdr_state_t > VDISPLAY::kscreenHdrState (const std::string &json_text, const std::string &output)
std::optional< std::string > VDISPLAY::kscreenLayoutFailure (std::string_view output)
 What went wrong with a kscreen-doctor layout command, read from its output.
hdr_launch_mode_t VDISPLAY::virtualDisplayHdrMode (bool requested, const kscreen_hdr_state_t &state, bool driver_reports_frame_color)
bool VDISPLAY::configureVirtualDisplayHdr (const std::string &displayName, bool hdr)
bool VDISPLAY::activateVirtualDisplayOutput (const std::string &displayName)
std::string VDISPLAY::primaryPhysicalOutputName ()
 The desktop's primary physical output ("DP-2"), or empty.
void VDISPLAY::beginPhysicalOutputSession ()
void VDISPLAY::endPhysicalOutputSession ()
void VDISPLAY::notePhysicalCaptureOutput (const std::string &connector_name)
bool VDISPLAY::wakeSleepingMonitor ()
 Wake a monitor the compositor has put to sleep.
void VDISPLAY::placeWindowsOnVirtualDisplay (const std::string &displayName, const std::vector< std::string > &windowClasses, const std::vector< std::uint32_t > &gamescopePids)
bool VDISPLAY::enableExclusiveVirtualDisplay (const std::string &displayName)
void VDISPLAY::restoreExclusiveVirtualDisplay ()
std::string VDISPLAY::getPrimaryDisplay ()
 Get the primary display name.
bool VDISPLAY::setPrimaryDisplay (const char *primaryDeviceName)
 Set the primary display by name.
bool VDISPLAY::getDisplayHDRByName (const char *displayName)
 Get the HDR status of a display by name.
bool VDISPLAY::setDisplayHDRByName (const char *displayName, bool enableAdvancedColor)
 Set the HDR status of a display by name.
std::vector< std::string > VDISPLAY::matchDisplay (const std::string &sMatch)
 Match displays by a given pattern.
bool VDISPLAY::isEvdiDisplay (const std::string &displayName)
 Check if a display name is an EVDI virtual display.
bool VDISPLAY::isHermesKmsDisplay (const std::string &displayName)
std::string VDISPLAY::getHyprlandOutputName (const std::string &displayName)
 The Hyprland output name backing a virtual display, or empty.
int VDISPLAY::getEvdiCardIndex (const std::string &displayName)
 Get the DRM card index for an EVDI display.
int VDISPLAY::getHermesKmsCardIndex (const std::string &displayName)
bool VDISPLAY::isHermesKmsDriverPresent ()
std::vector< std::string > VDISPLAY::listHermesKmsDisplayNames ()
std::string VDISPLAY::getHermesKmsDevicePath (const std::string &displayName)
std::string VDISPLAY::getHermesKmsSeatName (const std::string &displayName)
std::shared_ptr< EvdiBuffer > VDISPLAY::getEvdiBuffer (const std::string &display_name)
int VDISPLAY::hermesKmsOpenCapture (const std::string &display_name)
bool VDISPLAY::getHermesKmsDisplayGeometry (const std::string &display_name, int &offset_x, int &offset_y, int &environment_width, int &environment_height)
bool VDISPLAY::hermesKmsCaptureSize (int render_fd, int &width, int &height, uint32_t timeout_ms)
bool VDISPLAY::hermesKmsCaptureColor (int render_fd, hermes_kms::color_t &color, uint32_t &fourcc)
bool VDISPLAY::hermesKmsReportsFrameColor (int render_fd)
bool VDISPLAY::hermesKmsAcquireFrame (int render_fd, uint64_t after_sequence, uint32_t timeout_ms, HermesKmsFrame &out, bool capture_color)
bool VDISPLAY::hermesKmsWaitUpdate (int render_fd, uint64_t after_frame_sequence, uint64_t after_cursor_sequence, uint32_t timeout_ms, HermesKmsUpdate &out)
bool VDISPLAY::hermesKmsAcquireCursor (int render_fd, bool request_buffer, HermesKmsCursor &out)

Variables

constexpr uint16_t VDISPLAY::VIRTUAL_INPUT_SETTINGS_VENDOR_ID = 0xBEEF
 The ids GNOME's per-device settings path is built from.
constexpr uint16_t VDISPLAY::VIRTUAL_INPUT_SETTINGS_PRODUCT_ID = 0xDEAD
constexpr const char * VDISPLAY::VIRTUAL_TOUCH_DEVICE_NAME = "Touch passthrough"
 The names Hermes gives its per-client touch and pen devices.
constexpr const char * VDISPLAY::VIRTUAL_PEN_DEVICE_NAME = "Pen passthrough"

Detailed Description

Virtual display declarations for Linux.

Definition in file virtual_display.h.

Enumeration Type Documentation

◆ compositor_e

enum class VDISPLAY::compositor_e
strong

The Wayland compositor driving this session.

Hermes' virtual-display strategy differs per compositor in kind, not in detail: KWin is configured through kscreen-doctor, Mutter only through org.gnome.Mutter.DisplayConfig, and Hyprland accepts the output through wlr-output-management and then cannot composite onto it. Treating "wayland" as a single case hides those differences until someone reports a black stream, so the session is classified once and dispatched on.

The wlroots family is named rather than left unknown because "unknown" is the answer for a session Hermes cannot advise at all, while sway, wayfire, river and labwc are a case it can advise: they take the plain wlr-output-management path with no per-compositor workaround. Reporting them as unknown means the diagnostics cannot tell a user their session is expected to work from one where nobody knows.

Enumerator
unknown 

X11, no session, or a compositor Hermes cannot name.

kwin 

KDE Plasma.

mutter 

GNOME.

hyprland 

Hyprland - aquamarine, not wlroots, and it does not behave like it.

wlroots 

sway, wayfire, river, labwc: the plain wlr-output-management path.

cosmic 

COSMIC: wlr-output-management, but no wlr-screencopy for capture.

Definition at line 342 of file virtual_display.h.

◆ DRIVER_STATUS

enum class VDISPLAY::DRIVER_STATUS
strong

Status of the virtual display driver.

Enumerator
UNKNOWN 

Driver status unknown.

OK 

Driver is operational.

FAILED 

Driver failed to initialize.

VERSION_INCOMPATIBLE 

Driver version incompatible.

WATCHDOG_FAILED 

Driver watchdog failed.

NOT_SUPPORTED 

Virtual display not supported on this system.

Definition at line 34 of file virtual_display.h.

◆ EVDI_DIAGNOSTIC

enum class VDISPLAY::EVDI_DIAGNOSTIC
strong

Actionable EVDI state exposed to the Web UI.

The generic driver status only tells callers that virtual displays are unavailable. This enum identifies the host-side condition a user can fix.

Definition at line 49 of file virtual_display.h.

◆ feature_e

enum class VDISPLAY::feature_e
strong

A thing Hermes does that a session either supports or does not.

These are the promises a user reads on the box, and each one rests on a different mechanism: driving a mode is wlr-output-management or kscreen-doctor, blanking the physical monitor is the same protocols used differently, and isolating a session does not involve the session compositor at all. Reporting "virtual displays: unsupported" for a session that can do four of the five is what makes the failures unactionable.

Enumerator
virtual_display 

Create a virtual display and have it composited onto.

client_requested_mode 

Drive it at the geometry the client asked for.

exclusive_mode 

Blank the physical monitors for the duration of a session.

multiple_displays 

More than one virtual display in the same session.

isolated_sessions 

One seat and one compositor per client.

zero_copy_capture 

Capture over DMA-BUF rather than through a CPU copy.

Definition at line 364 of file virtual_display.h.

◆ HERMES_KMS_DIAGNOSTIC

Actionable Hermes-KMS state exposed to the Web UI.

Mirrors EVDI_DIAGNOSTIC for the hermes_kms backend. open_device already distinguishes these failure modes internally; this surfaces the reason so the UI can offer the matching install/repair guidance instead of a generic "unavailable".

Enumerator
NO_ACCESS 

The driver's desktop render node exists but this user may not open it.

Definition at line 78 of file virtual_display.h.

◆ kscreen_mode_state_e

enum class VDISPLAY::kscreen_mode_state_e
strong

What kscreen-doctor -j says about a mode on one output.

Enumerator
unknown_output 

KWin does not report that output at all.

not_advertised 

The output exists but offers no such mode.

advertised 

The mode exists and is not the one being driven.

current 

KWin already drives the output at that mode.

Definition at line 965 of file virtual_display.h.

◆ readiness_e

enum class VDISPLAY::readiness_e
strong

How well a session supports one feature.

degraded and unknown are deliberately distinct from unavailable: "works, but not the way you asked" and "could not be determined" are different messages to a user, and collapsing either into "unsupported" is how a fixable configuration ends up read as a missing capability.

Enumerator
ready 

Verified available in this session.

degraded 

Usable, but not as asked for - the detail says how.

unavailable 

Cannot work here; remediation says what would change that.

unknown 

Could not be probed - never assume this means broken.

Definition at line 381 of file virtual_display.h.

◆ virtual_display_layout_e

Where the host compositor places a newly created virtual output.

The KScreen path either appends the output beside the physical monitors (extend) or overlaps the primary output (mirror). Mirror reproduces the pre-0.5.0 behaviour, where KWin adopted the hotplugged connector at the primary's position and cloned the desktop onto it - which is also what makes windows the compositor places on the physical monitor (such as a nested Gamescope) visible in the captured stream.

Enumerator
extend 

Side-by-side, reasserting the pre-session physical layout.

detached 

Side-by-side while preserving physical-output state where possible.

mirror 

Overlapped with the primary output, so the desktop is cloned.

primary 

Side-by-side like extend, with the virtual output as the primary one.

Definition at line 245 of file virtual_display.h.

Function Documentation

◆ activateVirtualDisplayOutput()

bool VDISPLAY::activateVirtualDisplayOutput ( const std::string & displayName)

Activate a virtual output using the current session's display protocol.

Definition at line 8228 of file virtual_display.cpp.

◆ assessSession()

std::vector< FeatureReport > VDISPLAY::assessSession ( const SessionFacts & facts)

Turn observations into a per-feature verdict with remediation.

Pure: it reads facts and nothing else, so it is the whole of Hermes' advice and can be tested for every session shape without one existing.

Definition at line 2071 of file virtual_display.cpp.

◆ beginPhysicalOutputSession()

void VDISPLAY::beginPhysicalOutputSession ( )

Touch and pen binding for sessions that stream an existing monitor rather than a virtual display. begin/end bracket the session; the KMS capture reports the connector it streams (e.g. "DP-2"), and on KWin the touch and pen devices are bound to that output until the session ends.

Definition at line 7985 of file virtual_display.cpp.

◆ boundedCommandOutput()

std::optional< std::string > VDISPLAY::boundedCommandOutput ( const std::string & command,
std::chrono::milliseconds timeout,
bool * timed_out = nullptr )

Run a shell command and collect its standard output, waiting no longer than timeout for it.

For the desktop's own tools, which Hermes calls while holding locks a session cannot start without: one that never answers must cost a feature, not the host.

Parameters
timed_outSet to whether the command was stopped for running over.
Returns
The output when the command exited with status 0; std::nullopt when it failed, could not be started, or ran over - in which case it and everything it started have been killed.

Definition at line 2741 of file virtual_display.cpp.

◆ buildKScreenLayoutCommand()

std::string VDISPLAY::buildKScreenLayoutCommand ( const std::string & virtual_output,
const std::map< std::string, int > & enabled_before,
int target_x,
int target_y,
int mode_width,
int mode_height,
int mode_refresh_hz,
const std::map< std::string, kscreen_point_t > & positions_before = {},
virtual_display_layout_e layout = virtual_display_layout_e::extend )

Build the kscreen-doctor invocation that enables a virtual output, places it, and drives it at a requested mode.

KWin adopts a hotplugged connector at whichever mode it prefers rather than the one the streaming client negotiated: Hermes-KMS marks the client's exact CVT mode preferred but still exposes the standard mode ladder, and KWin has been seen taking 1920x1080 from that ladder for an 854x480 session. Because the capture path reports the real scanout, the client then receives a full-resolution stream of a display it asked to be small, so the mode has to be pushed rather than assumed.

Every output in enabled_before is re-enabled at its own priority and the virtual output takes the next one, keeping the local displays lit. Passing a non-positive component in mode_width, mode_height or mode_refresh_hz omits the mode, which is also how the caller retries a layout that KWin rejected for the mode alone.

An output named in positions_before is also placed back where it was before the hotplug. Enabling one without saying where it goes leaves KWin free to keep the position from the setup it replayed for the new output combination, which is how a monitor came back on top of the virtual output rather than beside it.

Exposed so the invocation can be checked without a running KDE session.

Returns
the complete command line.

Definition at line 2453 of file virtual_display.cpp.

◆ buildKWinInputBindingReadCommand()

std::string VDISPLAY::buildKWinInputBindingReadCommand ( const std::string & device_name)

The kreadconfig6 command that prints the output UUID a KWin input device is bound to. It prints nothing when there is none.

Returns
the command, or an empty string for a device name that cannot be put on a command line safely.

Definition at line 7790 of file virtual_display.cpp.

◆ buildKWinInputBindingRestoreCommand()

std::string VDISPLAY::buildKWinInputBindingRestoreCommand ( const std::string & device_name,
const std::string & previous_uuid )

The kwriteconfig6 command that puts a KWin input device's binding back to previous_uuid, deleting the key when it is empty.

The command notifies KWin, which otherwise keeps serving the value it has cached to every device it adds.

Returns
the command, or an empty string when previous_uuid is not spelled like a UUID or the device name is unsafe: a value read back from the file never reaches a command line unchecked.

Definition at line 7794 of file virtual_display.cpp.

◆ buildMutterExclusiveLayout()

bool VDISPLAY::buildMutterExclusiveLayout ( const std::string & current_state,
const std::string & connector,
std::string & serial,
std::string & argument )

Build the ApplyMonitorsConfig payload that hands the desktop to connector alone, which is how a monitor is turned off on GNOME: Mutter disables every connected monitor absent from the config.

Exposed so an all-or-nothing payload can be checked without a GNOME session.

Returns
true when a config was built; false when the reply is unusable, the connector is not being driven, or it already has the desktop to itself (nothing to apply).

Definition at line 7721 of file virtual_display.cpp.

◆ buildMutterLayoutWithMode()

bool VDISPLAY::buildMutterLayoutWithMode ( const std::string & current_state,
const std::string & connector,
uint32_t width,
uint32_t height,
uint32_t refresh_mhz,
std::string & serial,
std::string & argument )

Build the Mutter ApplyMonitorsConfig payload that drives a connector at a requested geometry.

Mutter adopts a hotplugged virtual connector on its own, but at whichever mode it prefers. If that is not the mode the streaming client asked for, the compositor scans out one resolution while Hermes captures another and the client receives a black image. This selects the advertised mode that matches width x height with the closest refresh rate (refresh_mhz is in mHz, as Hermes carries it internally; Mutter reports Hz), keeping every other logical monitor as Mutter has it, and appending a logical monitor at the current right edge when Mutter adopted the connector without placing it (Mutter rejects layouts with gaps between logical monitors).

Exposed so the payload can be validated without a running GNOME session.

Returns
true when a config was built; false when the reply is unusable, the connector is absent or does not advertise the geometry, or Mutter already drives it at that mode (nothing to apply).

Definition at line 7701 of file virtual_display.cpp.

◆ buildMutterLayoutWithoutConnector()

bool VDISPLAY::buildMutterLayoutWithoutConnector ( const std::string & current_state,
const std::string & virtual_connector,
std::string & serial,
std::string & argument )

Build the Mutter ApplyMonitorsConfig payload that drops a connector.

Pure text transformation over an org.gnome.Mutter.DisplayConfig GetCurrentState reply: it keeps every logical monitor except virtual_connector, moving the primary flag to the first survivor when the dropped monitor held it. Exposed so the payload - which is submitted to a compositor as an all-or-nothing config - can be validated without GNOME.

Parameters
current_stateThe GetCurrentState reply, as printed by gdbus call.
virtual_connectorThe connector to remove, e.g. "Virtual-1".
serialReceives the config serial the payload must be applied with.
argumentReceives the a(iiduba(ssa{sv})) argument.
Returns
true when a repair config was built; false when the connector is absent from the layout, the reply is unusable, or dropping it would leave Mutter with no monitor.

Definition at line 7685 of file virtual_display.cpp.

◆ buildMutterMirrorLayout()

bool VDISPLAY::buildMutterMirrorLayout ( const std::string & current_state,
const std::string & connector,
std::string & serial,
std::string & argument )

Build the payload that clones the primary output onto connector.

Mutter refuses overlapping logical monitors, so cloning means one logical monitor holding both connectors - and it refuses that unless their modes have identical dimensions. The payload therefore exists only at a resolution the virtual output advertises.

Returns
true when a config was built; false when the reply is unusable, no shared mode size exists, or the outputs are already mirrored.

Definition at line 7737 of file virtual_display.cpp.

◆ buildMutterRestoreLayout()

bool VDISPLAY::buildMutterRestoreLayout ( const std::string & current_state,
std::string & serial,
std::string & argument )

Build the payload that reproduces the layout in current_state.

This is what a session captures before changing the layout, and submits again when it ends.

Definition at line 7753 of file virtual_display.cpp.

◆ changeDisplaySettings()

int VDISPLAY::changeDisplaySettings ( const char * deviceName,
int width,
int height,
int refresh_rate,
int deadline_ms = 4000 )

Change the display settings of a virtual display.

Parameters
deviceNameThe name of the virtual display.
widthThe new width.
heightThe new height.
refresh_rateThe new refresh rate (in mHz).
deadline_msHow long the compositor-side mode apply may poll before giving up. A hot path answering a waiting client - /resume - passes a shorter budget than a launch does.
Returns
0 on success, -1 on failure, and 1 when the driver accepted the mode but the compositor kept the previously active one. That last case is not fatal: capture reads the real scanout geometry, so the stream follows the display rather than the request.

Definition at line 7549 of file virtual_display.cpp.

◆ changeDisplaySettings2()

int VDISPLAY::changeDisplaySettings2 ( const char * deviceName,
int width,
int height,
int refresh_rate,
bool bApplyIsolated = false )

Change the display settings with isolated display option.

Parameters
deviceNameThe name of the virtual display.
widthThe new width.
heightThe new height.
refresh_rateThe new refresh rate (in mHz).
bApplyIsolatedWhether to apply isolated display settings.
Returns
0 on success, non-zero on failure.

Definition at line 7640 of file virtual_display.cpp.

◆ closeVDisplayDevice()

void VDISPLAY::closeVDisplayDevice ( )

Close the virtual display driver.

Definition at line 6922 of file virtual_display.cpp.

◆ compositorFromDesktopNames()

compositor_e VDISPLAY::compositorFromDesktopNames ( const std::string & desktop_names)

Classify a compositor from an XDG_CURRENT_DESKTOP-style value.

The variable holds a colon-separated list whose case is not guaranteed ("KDE", "Hyprland", "ubuntu:GNOME"), so it is matched token by token: a substring test would classify a desktop merely mentioning another one. A token is accepted when it equals the compositor's desktop name or is a variant of it ("GNOME-Classic").

Exposed so the classification can be tested without a session.

Definition at line 1903 of file virtual_display.cpp.

◆ compositorName()

std::string VDISPLAY::compositorName ( compositor_e compositor)

Human-readable name for a compositor class, for logs and diagnostics.

Definition at line 1976 of file virtual_display.cpp.

◆ configureVirtualDisplayHdr()

bool VDISPLAY::configureVirtualDisplayHdr ( const std::string & displayName,
bool hdr )

Match only the owned KDE virtual output to the connecting client's HDR request.

Definition at line 8390 of file virtual_display.cpp.

◆ createVirtualDisplay()

std::string VDISPLAY::createVirtualDisplay ( const char * s_client_uid,
const char * s_client_name,
uint32_t width,
uint32_t height,
uint32_t fps,
const uuid_util::uuid_t & guid,
std::optional< uid_t > session_owner_uid = std::nullopt,
virtual_display_layout_e layout = virtual_display_layout_e::extend,
bool isolated_session = false )

Create a virtual display.

Parameters
s_client_uidThe unique identifier of the client.
s_client_nameThe name of the client.
widthThe width of the virtual display.
heightThe height of the virtual display.
fpsThe refresh rate of the virtual display (in mHz).
guidThe GUID for the virtual display.
session_owner_uidWhen set, a Hermes-KMS card the broker creates for this display belongs to this uid (an isolated session's account) rather than to Hermes itself.
layoutWhere the compositor should place the output. Honoured by the KScreen (KWin) and Mutter (GNOME) activation paths; other backends keep their own behaviour. The two compositors clone differently: KWin overlaps the virtual output with the primary, while Mutter refuses overlapping monitors and clones by putting both connectors in one logical monitor - which it only accepts when they advertise the same mode size, so mirroring there runs the stream at the physical monitor's resolution.
Returns
The name of the created virtual display, or empty string on failure.

Definition at line 7061 of file virtual_display.cpp.

◆ displayConnectorLit()

std::optional< bool > VDISPLAY::displayConnectorLit ( const std::filesystem::path & drm_class = "/sys/class/drm",
const std::string & ignored_connector = {} )

Whether any DRM connector is lighting a monitor right now.

A connector counts once something is attached to it and the compositor has bound it to a CRTC - the kernel's own status and enabled attributes, so the answer does not depend on which compositor is running or whether there is one. A monitor that is unplugged, switched off far enough to drop the link, or disabled in the display settings does not count.

Parameters
drm_classThe sysfs DRM class directory; tests point it at a fake tree.
ignored_connectorA connector ("Virtual-1") to leave out of the answer, for asking whether anything else is lit.
Returns
std::nullopt when sysfs cannot answer: the directory is unreadable or lists no card, or nothing is lit and some card exposes no connector at all - a GPU driven without kernel modesetting, such as NVIDIA with modeset=0 under X11, lights monitors sysfs never sees.

Definition at line 2318 of file virtual_display.cpp.

◆ displayLayoutGeneration()

uint64_t VDISPLAY::displayLayoutGeneration ( )

A counter bumped whenever the desktop layout changes underneath a running session.

The offsets a capture resolves at start-up are a snapshot: the compositor can move outputs, change their modes or replace a temporary configuration at any time, and the geometry absolute input is measured against then goes quietly wrong. A capture records this value when it starts and reinitialises when it no longer matches, which re-resolves the geometry through the path that already exists for a resolution change.

Only the GNOME backend moves it today, and only when built with sd-bus; everywhere else it is constant and the comparison costs nothing.

Definition at line 7798 of file virtual_display.cpp.

◆ displayServerReachable()

bool VDISPLAY::displayServerReachable ( const std::string & wayland_display,
const std::string & x_display,
const std::string & runtime_dir )

Whether a display server is listening where these variables point.

Asked of the socket itself, so it holds for any compositor and any way a session was started. A Wayland name is tried first, then a local X display; an X display on another host counts as reachable untested.

Parameters
wayland_displayWAYLAND_DISPLAY: a socket name under runtime_dir, or a path.
x_displayDISPLAY.
runtime_dirXDG_RUNTIME_DIR.

Definition at line 107 of file virtual_display.cpp.

◆ enableExclusiveVirtualDisplay()

bool VDISPLAY::enableExclusiveVirtualDisplay ( const std::string & displayName)

Enable/restore exclusive layout for an EVDI virtual display.

Definition at line 8453 of file virtual_display.cpp.

◆ endPhysicalOutputSession()

void VDISPLAY::endPhysicalOutputSession ( )

Definition at line 7992 of file virtual_display.cpp.

◆ featureName()

std::string VDISPLAY::featureName ( feature_e feature)

Human-readable names, for logs, diagnostics and the Web UI.

Definition at line 1994 of file virtual_display.cpp.

◆ getDisplayHDRByName()

bool VDISPLAY::getDisplayHDRByName ( const char * displayName)

Get the HDR status of a display by name.

Parameters
displayNameThe name of the display.
Returns
true if HDR is enabled, false otherwise.

Definition at line 8602 of file virtual_display.cpp.

◆ getEvdiBuffer()

std::shared_ptr< EvdiBuffer > VDISPLAY::getEvdiBuffer ( const std::string & display_name)

Return the active CPU capture buffer for an EVDI virtual display.

Definition at line 8829 of file virtual_display.cpp.

◆ getEvdiCardIndex()

int VDISPLAY::getEvdiCardIndex ( const std::string & displayName)

Get the DRM card index for an EVDI display.

Returns
Card index, or -1 if not found.
Parameters
displayNameThe name of the EVDI display.
Returns
The card index, or -1 if not found or not an EVDI display.

Definition at line 8662 of file virtual_display.cpp.

◆ getEvdiConnectorName()

std::string VDISPLAY::getEvdiConnectorName ( const std::string & displayName)

Return the compositor-facing connector name for an EVDI display.

Definition at line 7671 of file virtual_display.cpp.

◆ getEvdiDiagnostic()

EVDI_DIAGNOSTIC VDISPLAY::getEvdiDiagnostic ( )

Return the most specific available EVDI diagnostic for the current host.

Definition at line 6101 of file virtual_display.cpp.

◆ getEvdiStatus()

EvdiStatus VDISPLAY::getEvdiStatus ( )

Return runtime, DKMS, and frame-update details for the Audio/Video UI.

Definition at line 6175 of file virtual_display.cpp.

◆ getHermesKmsCardIndex()

int VDISPLAY::getHermesKmsCardIndex ( const std::string & displayName)

Get the DRM card index for a Hermes-KMS display.

Definition at line 8672 of file virtual_display.cpp.

◆ getHermesKmsConnectorName()

std::string VDISPLAY::getHermesKmsConnectorName ( const std::string & displayName)

Return the compositor-facing connector name for a Hermes-KMS display.

Definition at line 7675 of file virtual_display.cpp.

◆ getHermesKmsDevicePath()

std::string VDISPLAY::getHermesKmsDevicePath ( const std::string & displayName)

Get the primary DRM node path assigned to a Hermes-KMS display.

Definition at line 8702 of file virtual_display.cpp.

◆ getHermesKmsDiagnostic()

HERMES_KMS_DIAGNOSTIC VDISPLAY::getHermesKmsDiagnostic ( )

Return the most specific available Hermes-KMS diagnostic for the current host.

Definition at line 6248 of file virtual_display.cpp.

◆ getHermesKmsDisplayGeometry()

bool VDISPLAY::getHermesKmsDisplayGeometry ( const std::string & display_name,
int & offset_x,
int & offset_y,
int & environment_width,
int & environment_height )

Resolve the compositor position of a Hermes-KMS output for absolute input. Returns false when the desktop integration cannot expose a geometry.

Definition at line 8913 of file virtual_display.cpp.

◆ getHermesKmsMetrics()

HermesKmsMetrics VDISPLAY::getHermesKmsMetrics ( )

Read the Hermes-KMS device metrics, if a metrics-capable device is present. It opens a short-lived render fd and binds the active generic session capability before reading protected counters.

Returns
Metrics with available=true on success; a default (available=false) value when no metrics-capable Hermes-KMS device is found.

Definition at line 8730 of file virtual_display.cpp.

◆ getHermesKmsSeatName()

std::string VDISPLAY::getHermesKmsSeatName ( const std::string & displayName)

Get the stable udev/libseat name assigned to an independent DRM card.

Definition at line 8709 of file virtual_display.cpp.

◆ getHermesKmsStatus()

HermesKmsStatus VDISPLAY::getHermesKmsStatus ( )

Return module, DKMS, and device details for the Audio/Video UI.

Definition at line 6283 of file virtual_display.cpp.

◆ getHyprlandOutputName()

std::string VDISPLAY::getHyprlandOutputName ( const std::string & displayName)

The Hyprland output name backing a virtual display, or empty.

Non-empty only for a display Hyprland created as a headless output, which is also the test for "this display works on this session": a Hermes-KMS or EVDI display in a Hyprland session cannot be composited onto.

Definition at line 7853 of file virtual_display.cpp.

◆ getPrimaryDisplay()

std::string VDISPLAY::getPrimaryDisplay ( )

Get the primary display name.

Returns
The name of the primary display.

Definition at line 8565 of file virtual_display.cpp.

◆ graphicalSessionPresent()

std::optional< bool > VDISPLAY::graphicalSessionPresent ( )

Whether this user has a session of their own, as logind sees it - graphical or not, so a "yes" does not mean a desktop is up.

Returns
std::nullopt when logind could not be asked.

Definition at line 135 of file virtual_display.cpp.

◆ hermesKmsAcquireCursor()

bool VDISPLAY::hermesKmsAcquireCursor ( int render_fd,
bool request_buffer,
HermesKmsCursor & out )

Acquire current cursor metadata and, when requested, its DMA-BUF.

Definition at line 9113 of file virtual_display.cpp.

◆ hermesKmsAcquireFrame()

bool VDISPLAY::hermesKmsAcquireFrame ( int render_fd,
uint64_t after_sequence,
uint32_t timeout_ms,
HermesKmsFrame & out,
bool capture_color )

Definition at line 8998 of file virtual_display.cpp.

◆ hermesKmsCaptureColor()

bool VDISPLAY::hermesKmsCaptureColor ( int render_fd,
hermes_kms::color_t & color,
uint32_t & fourcc )

Acquire the current scanout frame as DMA-BUFs. Blocks up to timeout_ms for a frame newer than after_sequence (pass 0 to take whatever is current). On success out owns the returned fds; the caller must call out.close() when done.

Returns
true on success.

Definition at line 8974 of file virtual_display.cpp.

◆ hermesKmsCaptureSize()

bool VDISPLAY::hermesKmsCaptureSize ( int render_fd,
int & width,
int & height,
uint32_t timeout_ms = 0 )

Query a live scanout with an available framebuffer, optionally waiting up to timeout_ms for the compositor. Never substitute the requested mode for an unready scanout. A zero timeout performs a single query. On failure dimensions are cleared and errno distinguishes EAGAIN (not ready), ETIMEDOUT, and driver errors such as EACCES (unauthorized capture).

Definition at line 8947 of file virtual_display.cpp.

◆ hermesKmsOpenCapture()

int VDISPLAY::hermesKmsOpenCapture ( const std::string & display_name)

Open the render node of the Hermes-KMS card behind display_name.

Returns
a render-node fd >= 0 on success, or -1 on failure.

Definition at line 8865 of file virtual_display.cpp.

◆ hermesKmsReportsFrameColor()

bool VDISPLAY::hermesKmsReportsFrameColor ( int render_fd)

Whether the driver behind a capture descriptor reports frame colour (UAPI 14).

Definition at line 8968 of file virtual_display.cpp.

◆ hermesKmsSeatIsolationActive()

bool VDISPLAY::hermesKmsSeatIsolationActive ( )

Whether Hermes-KMS session cards carry a private DRM seat.

Isolation has two halves and they are installed separately: Hermes' own udev rules place a session's input devices on a private seat, while the driver's 72-hermes-kms-session-seats.rules does the same for its DRM cards. With only the first installed a session still starts, still gets its own input, and shares the host compositor's screen - and every check Hermes performs today passes. This is the missing check: a card with no ID_SEAT is on seat0, where the host compositor claims it.

Definition at line 2300 of file virtual_display.cpp.

◆ hermesKmsWaitUpdate()

bool VDISPLAY::hermesKmsWaitUpdate ( int render_fd,
uint64_t after_frame_sequence,
uint64_t after_cursor_sequence,
uint32_t timeout_ms,
HermesKmsUpdate & out )

Wait until the primary frame or cursor stream advances.

Definition at line 9080 of file virtual_display.cpp.

◆ inLoginSession()

bool VDISPLAY::inLoginSession ( )

Whether Hermes itself runs inside a login session - started from a terminal or over SSH - rather than as a service of the user manager.

Definition at line 163 of file virtual_display.cpp.

◆ isEvdiDisplay()

bool VDISPLAY::isEvdiDisplay ( const std::string & displayName)

Check if a display name is an EVDI virtual display.

Check if a display is an EVDI virtual display.

Parameters
displayNameThe name of the display to check.
Returns
true if the display is an EVDI virtual display, false otherwise.

Definition at line 8634 of file virtual_display.cpp.

◆ isHermesKmsDisplay()

bool VDISPLAY::isHermesKmsDisplay ( const std::string & displayName)

Check if a display is a Hermes-KMS virtual display.

Definition at line 8648 of file virtual_display.cpp.

◆ isHermesKmsDriverPresent()

bool VDISPLAY::isHermesKmsDriverPresent ( )

Check whether a usable Hermes-KMS DRM device exists on this host.

Definition at line 8682 of file virtual_display.cpp.

◆ isHermesKWinInputDevice()

bool VDISPLAY::isHermesKWinInputDevice ( const std::string & name,
uint32_t vendor,
uint32_t product )

Whether a device KWin reports is one of Hermes' touch or pen devices.

Name, vendor and product together, so that neither a real touchscreen nor another program's device that happens to share a name is ever rebound.

Definition at line 7786 of file virtual_display.cpp.

◆ kscreenDisplayGeometry()

bool VDISPLAY::kscreenDisplayGeometry ( const std::vector< kscreen_output_t > & outputs,
const std::string & output_name,
int & offset_x,
int & offset_y,
int & environment_width,
int & environment_height )

Resolve one KScreen output inside the live desktop envelope.

Only connected, enabled outputs form the desktop. KScreen retains an output's old position when its neighbours are disabled, so the envelope has to start at the first live pixel rather than unconditionally at 0,0. Otherwise an exclusive session whose sole output remains at x=3440 is reported as 3440 pixels into a 6000-pixel desktop, and absolute input is shifted when KWin maps it over that sole output.

Exposed so layouts captured from kscreen-doctor can be checked without a running KDE session.

Returns
true when output_name names an enabled output with a usable geometry; false leaves the output arguments untouched.

Definition at line 2593 of file virtual_display.cpp.

◆ kscreenHdrState()

std::optional< kscreen_hdr_state_t > VDISPLAY::kscreenHdrState ( const std::string & json_text,
const std::string & output )

Definition at line 2718 of file virtual_display.cpp.

◆ kscreenLayoutFailure()

std::optional< std::string > VDISPLAY::kscreenLayoutFailure ( std::string_view output)

What went wrong with a kscreen-doctor layout command, read from its output.

kscreen-doctor exits 0 whatever happened: on an error it calls qApp->exit() with a code, then applies the configuration anyway and calls qApp->exit(0) (libkscreen src/doctor/doctor.cpp). Only its output tells. It stops reading the command at the first option it cannot use (an output or mode it cannot find, an invalid value) and applies the options before it, so the layout may be only partly applied; and KWin may refuse the whole configuration ("applying config failed!" and KWin's reason).

Parameters
outputWhat kscreen-doctor printed, stdout and stderr together.
Returns
The first line reporting a failure, or nothing when there was none.

Definition at line 2642 of file virtual_display.cpp.

◆ kscreenModeState()

kscreen_mode_state_e VDISPLAY::kscreenModeState ( const std::string & json_text,
const std::string & output,
int width,
int height,
int refresh_hz )

Find a mode on one output in a kscreen-doctor -j reply.

Pushing a mode blind gives the same generic failure whether KWin refused a valid request, the connector never advertised the geometry, or it was already being driven at it. Reading the reply first separates those, and the last case removes a needless kscreen-doctor call per session.

Refresh rates are compared rounded to whole Hz, which is how kscreen-doctor itself matches a WxH@R argument against the mode list: a connector advertising 89.991 Hz is driven by asking for 90.

Exposed so the reply can be interpreted without a running KDE session.

Definition at line 2677 of file virtual_display.cpp.

◆ kscreenVirtualOutputPosition()

kscreen_point_t VDISPLAY::kscreenVirtualOutputPosition ( const std::string & virtual_output,
const std::vector< kscreen_output_t > & before,
const std::vector< kscreen_output_t > & current,
virtual_display_layout_e layout )

Decide where the virtual output goes, in KScreen's logical space.

The layout to place against is the one the session is about to restore - before, sampled before the connector was hotplugged - and not the one KWin happens to be showing in current. KWin keeps a saved setup per output combination and replays it when a connector appears: a combination last used by an exclusive session comes back with the physical monitor disabled and the virtual connector at the origin. Placing against that transient state put the virtual output at 0,0 too, and re-enabling the monitor in the same transaction left both there, so the client received the physical desktop cropped to the mode it had asked for.

current is still consulted for presence: an output that has since been unplugged reserves no space. When it is empty - kscreen-doctor gave no answer - every output in before is taken as present, and when before itself yields no anchor the same rule is applied to current so a session that started without a usable snapshot still lands beside the desktop.

Exposed so the placement can be checked without a running KDE session.

Returns
the position for virtual_output.

Definition at line 2530 of file virtual_display.cpp.

◆ listHermesKmsDisplayNames()

std::vector< std::string > VDISPLAY::listHermesKmsDisplayNames ( )

List the display names of all registered Hermes-KMS virtual displays.

Definition at line 8691 of file virtual_display.cpp.

◆ logSessionAssessment()

void VDISPLAY::logSessionAssessment ( )

Probe, assess and log what this session can and cannot do.

Written for the user who only ever sees the log: a working feature is one line, and one that is not carries both the reason and the fix.

Definition at line 6154 of file virtual_display.cpp.

◆ matchDisplay()

std::vector< std::string > VDISPLAY::matchDisplay ( const std::string & sMatch)

Match displays by a given pattern.

Parameters
sMatchThe pattern to match.
Returns
A vector of matching display names.

Definition at line 8613 of file virtual_display.cpp.

◆ mutterDisplayGeometry()

bool VDISPLAY::mutterDisplayGeometry ( const std::string & current_state,
const std::string & connector,
int & offset_x,
int & offset_y,
int & environment_width,
int & environment_height )

Where a connector sits on a GNOME desktop, for absolute input.

Mutter feeds an absolute pointing device the extents of the whole stage, so a client's coordinates only land on the streamed output once they carry that output's offset within the desktop envelope. Both are read from the logical monitor layout - the space the stage is measured in - which means scale and rotation, not the mode size.

The values come back in the connector's own pixel space rather than in logical pixels, so a consumer holding coordinates in the captured mode's pixels can use them unchanged; at scale 1 the two are the same thing.

Exposed so the arithmetic can be checked against a captured GetCurrentState reply, without a running GNOME session.

Parameters
current_stateThe GetCurrentState reply, as printed by gdbus call.
connectorThe connector to locate, e.g. "Virtual-1".
Returns
true when the connector is in the layout and the envelope could be measured; false leaves the outputs untouched.

Definition at line 7802 of file virtual_display.cpp.

◆ mutterInputDeviceOutputValue()

std::string VDISPLAY::mutterInputDeviceOutputValue ( const std::string & current_state,
const std::string & connector )

The GNOME output value that binds an input device to connector.

GNOME binds a touchscreen or tablet to one monitor, matching a list of at least three strings against the monitor's EDID vendor, product and serial. The connector is appended as a fourth element, which Mutter uses to disambiguate two monitors sharing an EDID.

Returns
the value to write, or an empty string when the monitor is unknown, carries no identity at all, or spells one that cannot be put on a command line safely.

Definition at line 7770 of file virtual_display.cpp.

◆ mutterInputDeviceSettingsTargets()

void VDISPLAY::mutterInputDeviceSettingsTargets ( std::string & touch,
std::string & pen )

The relocatable-schema targets whose output key binds Hermes' own touch and pen devices, as <schema>:<path>.

Mutter derives the path from the device's vendor and product ids, so these only reach Hermes' devices while they match the ids libvirtualhid is given.

Definition at line 7781 of file virtual_display.cpp.

◆ needsInitialDeviceConfiguration()

bool VDISPLAY::needsInitialDeviceConfiguration ( )

Whether EVDI needs a device pre-created at module load time.

This occurs when the loaded module has no devices and the current Apollo process cannot write to EVDI's root-only sysfs add endpoint.

Definition at line 5935 of file virtual_display.cpp.

◆ notePhysicalCaptureOutput()

void VDISPLAY::notePhysicalCaptureOutput ( const std::string & connector_name)

Definition at line 7966 of file virtual_display.cpp.

◆ openVDisplayDevice()

DRIVER_STATUS VDISPLAY::openVDisplayDevice ( )

Initialize the virtual display driver.

Returns
DRIVER_STATUS indicating the result of initialization.

Definition at line 6820 of file virtual_display.cpp.

◆ parkedConnector()

std::string VDISPLAY::parkedConnector ( )

The connector of the output being kept for the login greeter, or empty. It is lit, but it is not a monitor the host has.

Definition at line 2406 of file virtual_display.cpp.

◆ placeWindowsOnVirtualDisplay()

void VDISPLAY::placeWindowsOnVirtualDisplay ( const std::string & displayName,
const std::vector< std::string > & windowClasses,
const std::vector< std::uint32_t > & gamescopePids = {} )

Put windows of these classes on the session's virtual output, now and as they appear, until the display is removed. KWin only; elsewhere nothing happens. For an application that reuses a window already open on a physical monitor, such as Steam switching to Big Picture. Gamescope windows must also match a launched PID; other local instances are left alone.

Definition at line 7931 of file virtual_display.cpp.

◆ primaryPhysicalOutputName()

std::string VDISPLAY::primaryPhysicalOutputName ( )

The desktop's primary physical output ("DP-2"), or empty.

KWin on Wayland only: the connected, enabled output KScreen gives priority 1, unless it is a virtual output. Empty when there is no such output or it can't be determined.

Definition at line 7972 of file virtual_display.cpp.

◆ probeSessionFacts()

SessionFacts VDISPLAY::probeSessionFacts ( )

Observe the running session. Safe to call while a stream is running.

Definition at line 6125 of file virtual_display.cpp.

◆ readinessName()

std::string VDISPLAY::readinessName ( readiness_e readiness)

Definition at line 2012 of file virtual_display.cpp.

◆ removalStrandsGreeter()

bool VDISPLAY::removalStrandsGreeter ( bool greeter_on_seat,
bool output_lit,
std::optional< bool > another_connector_lit )

Whether removing a virtual display would leave the login greeter with nothing to draw on.

SDDM's greeter exits when its last output goes away and is not started again, so a display removed before login takes the login prompt with it. When this says yes the display's Hermes-KMS output is kept connected instead, for the next session to reuse.

Parameters
greeter_on_seatA display manager's greeter is the session in front.
output_litThe output being removed is one a compositor drives.
another_connector_litdisplayConnectorLit() with that output left out.

Definition at line 2399 of file virtual_display.cpp.

◆ removeVirtualDisplay()

bool VDISPLAY::removeVirtualDisplay ( const uuid_util::uuid_t & guid)

Remove a virtual display.

Parameters
guidThe GUID of the virtual display to remove.
Returns
true if the virtual display was removed successfully, false otherwise.

Definition at line 7533 of file virtual_display.cpp.

◆ restoreExclusiveVirtualDisplay()

void VDISPLAY::restoreExclusiveVirtualDisplay ( )

Definition at line 8523 of file virtual_display.cpp.

◆ sessionCompositor()

compositor_e VDISPLAY::sessionCompositor ( )

Classify the compositor of the running session.

Reads XDG_CURRENT_DESKTOP, falls back to XDG_SESSION_DESKTOP, and finally to the sockets a compositor exports whether or not a session file named it: HYPRLAND_INSTANCE_SIGNATURE, SWAYSOCK and WAYFIRE_SOCKET. A session started from a TTY or a bare exec sway frequently leaves both desktop variables empty, which is the case that used to reach the generic path unnamed.

Definition at line 1946 of file virtual_display.cpp.

◆ setDisplayHDRByName()

bool VDISPLAY::setDisplayHDRByName ( const char * displayName,
bool enableAdvancedColor )

Set the HDR status of a display by name.

Parameters
displayNameThe name of the display.
enableAdvancedColorWhether to enable HDR.
Returns
true if the HDR status was set successfully, false otherwise.

Definition at line 8608 of file virtual_display.cpp.

◆ setPrimaryDisplay()

bool VDISPLAY::setPrimaryDisplay ( const char * primaryDeviceName)

Set the primary display by name.

Parameters
primaryDeviceNameThe name of the display to set as primary.
Returns
true if the primary display was set successfully, false otherwise.

Definition at line 8597 of file virtual_display.cpp.

◆ setRenderAdapterByName()

bool VDISPLAY::setRenderAdapterByName ( const std::string & adapterName)

Set the render adapter by name.

Parameters
adapterNameThe name of the adapter to use for rendering.
Returns
true if the adapter was set successfully, false otherwise.

Definition at line 7048 of file virtual_display.cpp.

◆ startPingThread()

bool VDISPLAY::startPingThread ( std::function< void()> failCb)

Start a ping thread to keep the virtual display alive.

Parameters
failCbCallback to invoke if the watchdog fails.
Returns
true if the ping thread was started successfully, false otherwise.

Definition at line 6968 of file virtual_display.cpp.

◆ systemdUserBusAddress()

std::string VDISPLAY::systemdUserBusAddress ( uint32_t uid)

The standard systemd user-bus address for uid.

Kept independent of the process environment because libsystemd suppresses environment-based bus discovery when Hermes' file capability sets AT_SECURE.

Definition at line 80 of file virtual_display.cpp.

◆ unlockHostSessionIfLocked()

bool VDISPLAY::unlockHostSessionIfLocked ( )

Unlock the active graphical login session for the Hermes user when locked.

Uses systemd-logind directly over D-Bus. The graphical session is selected with sd-login rather than from Hermes' own PID because Hermes normally runs as a systemd user service outside the desktop session's process tree.

Returns
true when the session was already unlocked or an unlock request was accepted; false when no graphical session could be identified or logind could not be reached.

Definition at line 211 of file virtual_display.cpp.

◆ userManagerEnvironment()

std::optional< std::vector< std::string > > VDISPLAY::userManagerEnvironment ( )

The environment the systemd user manager hands to the units it starts, as "NAME=value" strings.

A desktop publishes its display variables there at login, so this is what a Hermes started before that login would have been given had it started after it. std::nullopt when the manager could not be asked.

Definition at line 174 of file virtual_display.cpp.

◆ virtualDisplayHdrMode()

hdr_launch_mode_t VDISPLAY::virtualDisplayHdrMode ( bool requested,
const kscreen_hdr_state_t & state,
bool driver_reports_frame_color )

Stream HDR only when the output offers it and the driver reports each frame's colour, which is how capture tells PQ pixels from SDR ones. Otherwise an HDR request streams SDR, as it did before HDR capture existed, rather than refusing the session.

Definition at line 8377 of file virtual_display.cpp.

◆ waitForConnectorEnabled()

bool VDISPLAY::waitForConnectorEnabled ( const std::string & connector,
std::chrono::milliseconds timeout,
const std::filesystem::path & drm_class = "/sys/class/drm" )

Wait until some compositor has bound connector to a CRTC.

Parameters
connectorDRM connector name as the driver reports it ("Virtual-1").
drm_classThe sysfs DRM class directory; tests point it at a fake tree.
Returns
true once its enabled attribute reads "enabled", false on timeout.

Definition at line 2411 of file virtual_display.cpp.

◆ wakeSleepingMonitor()

bool VDISPLAY::wakeSleepingMonitor ( )

Wake a monitor the compositor has put to sleep.

KWin on Wayland only. Screens in power saving read as unlit, the same as no monitor at all. A DisplayPort monitor in deep sleep is woken with one read on its AUX channel and waited for, at most 8 seconds, until the compositor has lit it. Otherwise, if KScreen still lists a connected, enabled physical output, the screens are turned back on and the primary one is waited for, at most 3 seconds, until it shows a frame.

Returns
True once that output is scanning out; false if there was nothing to wake or it did not come back.

Definition at line 8192 of file virtual_display.cpp.

◆ windowSystemAttached()

bool VDISPLAY::windowSystemAttached ( )

Whether Hermes runs inside a graphical session (Wayland or X11).

False when it was started before anyone logged in - by a lingering user manager at boot - or under a session that publishes no display variables, such as gamescope-session.

Definition at line 2366 of file virtual_display.cpp.

Variable Documentation

◆ VIRTUAL_INPUT_SETTINGS_PRODUCT_ID

uint16_t VDISPLAY::VIRTUAL_INPUT_SETTINGS_PRODUCT_ID = 0xDEAD
constexpr

Definition at line 741 of file virtual_display.h.

◆ VIRTUAL_INPUT_SETTINGS_VENDOR_ID

uint16_t VDISPLAY::VIRTUAL_INPUT_SETTINGS_VENDOR_ID = 0xBEEF
constexpr

The ids GNOME's per-device settings path is built from.

GNOME binds a touchscreen or tablet to a monitor through a key whose path it derives from the device's vendor and product. These must be the ids libvirtualhid gives Hermes' virtual devices, or the binding addresses a device that does not exist - which fails silently, since nothing errors and touch input simply goes on being placed by guesswork. platf::VIRTUAL_INPUT_VENDOR_ID is checked against these at compile time.

Definition at line 740 of file virtual_display.h.

◆ VIRTUAL_PEN_DEVICE_NAME

const char* VDISPLAY::VIRTUAL_PEN_DEVICE_NAME = "Pen passthrough"
constexpr

Definition at line 800 of file virtual_display.h.

◆ VIRTUAL_TOUCH_DEVICE_NAME

const char* VDISPLAY::VIRTUAL_TOUCH_DEVICE_NAME = "Touch passthrough"
constexpr

The names Hermes gives its per-client touch and pen devices.

KWin keeps a device's settings, the output it is bound to among them, in a kcminputrc group named after the device's vendor, product and name. The display code has to address that group, so these are named here and libvirtualhid is given the same constants.

Definition at line 799 of file virtual_display.h.