Documentation
¶
Overview ¶
Package linuxdesktop detects the Linux desktop environment, display servers, and graphics stack. Detection returns partial results alongside probe errors; callers can use the available data even when a probe fails. On other operating systems it returns a headless environment and ErrNotLinux.
DetectContext applies options to the default configuration in order. Use the With functions or supply a custom option, for example:
func(c *linuxdesktop.Config) { c.Sections = linuxdesktop.SectionOS }
Public result and configuration types belong to this package. Probe engines and their models are implementation details kept under internal/.
Unknown is the shared constant for unidentified session, display, desktop, compositor, confidence, and detection method values. It replaces the former type-specific unknown constants. Display protocols use the session constants with an explicit conversion, such as DisplayProtocol(SessionTypeWayland) or DisplayProtocol(SessionTypeX11).
Index ¶
- Constants
- Variables
- func IsHeadless() bool
- func IsWayland() bool
- func IsX11() bool
- type CompositorInfo
- type CompositorInfoData
- type CompositorKind
- type Config
- type ConfigData
- type DesktopEnvironment
- type DesktopInfo
- type DesktopInfoData
- type DetectionConfidence
- type DetectionMethod
- type DisplayInfo
- type DisplayInfoData
- type DisplayProtocol
- type Environment
- type EnvironmentData
- type GPUInfo
- type GraphicsInfo
- type GraphicsInfoData
- type OSInfo
- type OpenGLInfo
- type Option
- type PortalInfo
- type RetryPolicy
- type Section
- type SessionInfo
- type SessionInfoData
- type SessionType
- type VulkanInfo
- type WaylandGlobal
- type WaylandInfo
- type WaylandInfoData
- type X11Info
Constants ¶
const ( // SectionOS selects operating system information. Combine the section flags // with bitwise OR to select multiple parts of an Environment. SectionOS Section = 1 << iota // SectionSession selects login session information. SectionSession // SectionDisplay selects display server information. SectionDisplay // SectionDesktop selects desktop environment information. SectionDesktop // SectionCompositor selects compositor identification. SectionCompositor // SectionGraphics selects GPU and graphics stack information. SectionGraphics // SectionPortal selects desktop portal information. SectionPortal // SectionAll selects every section and is the default. SectionAll Section = SectionOS | SectionSession | SectionDisplay | SectionDesktop | SectionCompositor | SectionGraphics | SectionPortal // Unknown indicates an unidentified session, display, desktop, compositor, // confidence, or detection method. It is assignable to each identity type. Unknown = "unknown" // SessionTypeWayland and the other session constants mirror logind's TYPE= // and $XDG_SESSION_TYPE. SessionTypeWayland SessionType = "wayland" SessionTypeX11 SessionType = "x11" SessionTypeTTY SessionType = "tty" SessionTypeMir SessionType = "mir" // DesktopGNOME and the other desktop constants identify recognized environments. DesktopGNOME DesktopEnvironment = "gnome" DesktopKDE DesktopEnvironment = "kde" DesktopXFCE DesktopEnvironment = "xfce" DesktopCinnamon DesktopEnvironment = "cinnamon" DesktopMATE DesktopEnvironment = "mate" DesktopLXQt DesktopEnvironment = "lxqt" DesktopLXDE DesktopEnvironment = "lxde" DesktopBudgie DesktopEnvironment = "budgie" DesktopCOSMIC DesktopEnvironment = "cosmic" DesktopPantheon DesktopEnvironment = "pantheon" // CompositorMutter and the other compositor constants identify recognized // compositors or window managers. For Unknown, CompositorInfo.Name preserves // the unrecognized raw name. CompositorMutter CompositorKind = "mutter" CompositorKWin CompositorKind = "kwin" CompositorSway CompositorKind = "sway" CompositorHyprland CompositorKind = "hyprland" CompositorWayfire CompositorKind = "wayfire" CompositorRiver CompositorKind = "river" CompositorWeston CompositorKind = "weston" CompositorLabwc CompositorKind = "labwc" CompositorXfwm CompositorKind = "xfwm4" CompositorMarco CompositorKind = "marco" CompositorOpenbox CompositorKind = "openbox" CompositorI3 CompositorKind = "i3" CompositorAwesome CompositorKind = "awesome" // ConfidenceLow and the other confidence constants grade detection evidence. ConfidenceLow DetectionConfidence = "low" ConfidenceMedium DetectionConfidence = "medium" ConfidenceHigh DetectionConfidence = "high" // DetectedEnvironment and the other detection methods are roughly ordered // from cheapest to most invasive. DetectedEnvironment DetectionMethod = "environment" DetectedLogind DetectionMethod = "logind" DetectedDBus DetectionMethod = "dbus" DetectedX11EWMH DetectionMethod = "x11_ewmh" DetectedWayland DetectionMethod = "wayland_protocol" DetectedSocket DetectionMethod = "socket" DetectedProcess DetectionMethod = "process" // ExtensionXWayland is the X11 extension an Xwayland server advertises and a // native X.Org server does not. Its presence in X11Info.Extensions is the only // unambiguous way to tell the two apart. ExtensionXWayland = "XWAYLAND" // DefaultTimeout bounds a whole detection run and // DefaultProbeTimeout bounds each probe within it, so one unresponsive server // cannot consume the entire budget. DefaultTimeout = 2 * time.Second // DefaultProbeTimeout bounds each individual detection probe. DefaultProbeTimeout = 500 * time.Millisecond )
Detection flags and identities describe the selected sections and recognized desktop components.
Variables ¶
var ( // ErrNotLinux is joined into the error from Detect when the program is not // running on Linux. The returned Environment is still valid: it is zero-valued // and marked headless, so a cross-platform caller can import this package // unconditionally and branch on the result rather than on the build tag. ErrNotLinux = errors.New("linuxdesktop: not running on Linux") // ErrInvalidRetryPolicy reports invalid D-Bus connection retry settings. ErrInvalidRetryPolicy = errors.New("linuxdesktop: invalid connection retry policy") )
Functions ¶
func IsHeadless ¶
func IsHeadless() bool
IsHeadless reports whether there is no display server to draw on.
Types ¶
type CompositorInfo ¶
type CompositorInfo = CompositorInfoData[CompositorKind, DetectionConfidence, DetectionMethod]
CompositorInfo identifies the compositor or window manager, and says how certain that identification is.
func Compositor ¶
func Compositor() (CompositorInfo, error)
Compositor reports the compositor or window manager, together with the method that identified it and how far that method can be trusted.
type CompositorInfoData ¶
type CompositorInfoData[KindType, ConfidenceType, MethodType any] struct { // Kind identifies the compositor or window manager. Kind KindType `json:"kind"` // Confidence expresses the certainty of the identification. Confidence ConfidenceType `json:"confidence"` // DetectedBy identifies the source of detection evidence. DetectedBy MethodType `json:"detected_by"` // Name is the human-readable compositor name. Name string `json:"name"` // Version is the reported compositor version, when available. Version string `json:"version,omitempty"` // Wayland reports whether the compositor supports Wayland. Wayland bool `json:"wayland"` // X11 reports whether the window manager supports X11. X11 bool `json:"x11"` }
CompositorInfoData is the shared CompositorInfoData layout, parameterized by its component types.
type CompositorKind ¶
type CompositorKind string
CompositorKind is a recognized window manager or Wayland compositor.
type Config ¶
type Config = ConfigData[Section]
Config controls a detection run. DetectContext initializes the defaults before applying options in order; callers can supply custom Option functions.
type ConfigData ¶
type ConfigData[SectionsType any] struct { Sections SectionsType ConnectionRetry RetryPolicy Timeout time.Duration ProbeTimeout time.Duration NativeGL bool ProcessScan bool }
ConfigData is the shared ConfigData layout, parameterized by its component types.
type DesktopEnvironment ¶
type DesktopEnvironment string
DesktopEnvironment is a recognized desktop environment.
type DesktopInfo ¶
type DesktopInfo = DesktopInfoData[DesktopEnvironment]
DesktopInfo identifies the desktop environment.
type DesktopInfoData ¶
type DesktopInfoData[DesktopType any] struct { // Environment recognized desktop environment. Environment DesktopType `json:"environment"` // Name human-readable name reported by the source. Name string `json:"name"` // Version version reported by the source, when available. Version string `json:"version,omitempty"` // CurrentDesktop unmodified XDG_CURRENT_DESKTOP value. CurrentDesktop string `json:"current_desktop"` // SessionDesktop unmodified XDG_SESSION_DESKTOP value. SessionDesktop string `json:"session_desktop"` // DesktopSession unmodified DESKTOP_SESSION value. DesktopSession string `json:"desktop_session"` // CurrentDesktops ordered desktop tokens from XDG_CURRENT_DESKTOP. CurrentDesktops []string `json:"current_desktops"` }
DesktopInfoData is the shared DesktopInfoData layout, parameterized by its component types.
type DetectionConfidence ¶
type DetectionConfidence string
DetectionConfidence grades how much a detection result can be trusted.
type DetectionMethod ¶
type DetectionMethod string
DetectionMethod records which signal produced a detection result.
type DisplayInfo ¶
type DisplayInfo = DisplayInfoData[X11Info, WaylandInfo, DisplayProtocol]
DisplayInfo describes which display servers are reachable.
type DisplayInfoData ¶
type DisplayInfoData[XServerType, WaylandServerType, ProtocolType any] struct { // X11 details of a reachable X server; nil when unavailable. X11 *XServerType `json:"x11,omitempty"` // Wayland details of a reachable Wayland compositor; nil when unavailable. Wayland *WaylandServerType `json:"wayland,omitempty"` // Protocol preferred display protocol for a client. Protocol ProtocolType `json:"protocol"` // WaylandDisplay wayland socket name from WAYLAND_DISPLAY. WaylandDisplay string `json:"wayland_display"` // X11Display x display address from DISPLAY. X11Display string `json:"x11_display"` // X11Available whether the X server probe reached a server. X11Available bool `json:"x11_available"` // WaylandAvailable whether the Wayland probe reached a compositor. WaylandAvailable bool `json:"wayland_available"` // XWayland whether the X server runs inside a Wayland session. XWayland bool `json:"xwayland"` }
DisplayInfoData is the shared DisplayInfoData layout, parameterized by its component types.
type DisplayProtocol ¶
type DisplayProtocol string
DisplayProtocol is the windowing protocol the process should speak.
type Environment ¶
type Environment = EnvironmentData[ OSInfo, SessionInfo, DisplayInfo, DesktopInfo, CompositorInfo, GraphicsInfo, PortalInfo, ]
Environment is the complete picture of the desktop the process is running in.
func Detect ¶
func Detect() (*Environment, error)
Detect reports the complete desktop environment using the default options.
The returned *Environment is never nil. The error reports probes that did not succeed and is safe to ignore; see the package documentation.
func DetectContext ¶
func DetectContext( ctx context.Context, opts ...Option, ) (*Environment, error)
DetectContext reports the desktop environment, honoring ctx and opts.
type EnvironmentData ¶
type EnvironmentData[ OSType, SessionType, DisplayType, DesktopType, CompositorType, GraphicsType, PortalType any, ] struct { // OS operating system and kernel identity. OS OSType `json:"os"` // Session seat and login session details. Session SessionType `json:"session"` // Display reachable display servers and selected protocol. Display DisplayType `json:"display"` // Desktop desktop environment identity. Desktop DesktopType `json:"desktop"` // Compositor window manager or compositor identity and detection evidence. Compositor CompositorType `json:"compositor"` // Graphics gPU hardware and client graphics implementations. Graphics GraphicsType `json:"graphics"` // Portal availability and interfaces of the desktop portal. Portal PortalType `json:"portal"` // Headless whether neither display protocol is reachable. Headless bool `json:"headless"` }
EnvironmentData is the shared EnvironmentData layout, parameterized by its component types.
type GPUInfo ¶
type GPUInfo struct {
// ID identifier reported by the underlying system.
ID string `json:"id"`
// Vendor vendor name reported by the driver or server.
Vendor string `json:"vendor"`
// Model marketing name from the driver or PCI device database.
Model string `json:"model"`
// VendorID pCI vendor identifier as reported by sysfs.
VendorID string `json:"vendor_id"`
// DeviceID pCI device identifier as reported by sysfs.
DeviceID string `json:"device_id"`
// PCIAddress pCI slot address, when the GPU is on a PCI bus.
PCIAddress string `json:"pci_address"`
// Driver kernel driver bound to the device.
Driver string `json:"driver"`
// DRMDevice path to the DRM card device.
DRMDevice string `json:"drm_device"`
// RenderDevice path to the corresponding DRM render node.
RenderDevice string `json:"render_device"`
// Integrated whether the device is classified as integrated.
Integrated bool `json:"integrated"`
// Discrete whether the device is classified as discrete.
Discrete bool `json:"discrete"`
}
GPUInfo is one DRM device and its PCI identity.
type GraphicsInfo ¶
type GraphicsInfo = GraphicsInfoData[OpenGLInfo, VulkanInfo, GPUInfo]
GraphicsInfo describes the GPUs and the client-side graphics stack.
type GraphicsInfoData ¶
type GraphicsInfoData[OpenGLType, VulkanType, GPUType any] struct { // OpenGL openGL implementation reported by drivers or manifests. OpenGL OpenGLType `json:"opengl"` // Vulkan vulkan loader and driver availability. Vulkan VulkanType `json:"vulkan"` // PrimaryGPU identifier of the firmware-posted GPU, or the first detected GPU. PrimaryGPU string `json:"primary_gpu,omitempty"` // GPUs detected DRM devices with their PCI identity. GPUs []GPUType `json:"gpus"` }
GraphicsInfoData is the shared GraphicsInfoData layout, parameterized by its component types.
type OSInfo ¶
type OSInfo struct {
// Name human-readable name reported by the source.
Name string `json:"name"`
// PrettyName human-readable distribution name from os-release.
PrettyName string `json:"pretty_name"`
// ID identifier reported by the underlying system.
ID string `json:"id"`
// IDLike related distribution identifiers from os-release.
IDLike string `json:"id_like"`
// Version version reported by the source, when available.
Version string `json:"version"`
// VersionID machine-readable distribution version.
VersionID string `json:"version_id"`
// Kernel kernel name.
Kernel string `json:"kernel"`
// KernelRelease kernel release string.
KernelRelease string `json:"kernel_release"`
// Architecture architecture in uname-style spelling.
Architecture string `json:"architecture"`
// Hostname host name reported by the operating system.
Hostname string `json:"hostname"`
}
OSInfo describes the operating system and kernel.
type OpenGLInfo ¶
type OpenGLInfo struct {
// Vendor vendor name reported by the driver or server.
Vendor string `json:"vendor,omitempty"`
// Renderer openGL renderer string from the live driver.
Renderer string `json:"renderer,omitempty"`
// Version version reported by the source, when available.
Version string `json:"version,omitempty"`
// Available whether the implementation or service was detected.
Available bool `json:"available"`
}
OpenGLInfo describes the OpenGL implementation.
type Option ¶
type Option func(*Config)
Option configures a detection run by modifying its public configuration.
func WithConnectionRetry ¶
func WithConnectionRetry(policy RetryPolicy) Option
WithConnectionRetry sets the D-Bus initialization policy. The default is three attempts with delays starting at 25ms and capped at 100ms before jitter. MaxAttempts of one disables retries. Invalid policies return ErrInvalidRetryPolicy.
func WithOpenGL ¶
func WithOpenGL() Option
WithOpenGL asks the graphics drivers directly instead of reading their manifests, which yields a true vendor, renderer and version at the cost of initializing the GPU stack — tens of milliseconds, not microseconds.
func WithProbeTimeout ¶
WithProbeTimeout bounds each individual probe, so one unresponsive server cannot consume the whole budget. The default is DefaultProbeTimeout.
func WithProcessScan ¶
func WithProcessScan() Option
WithProcessScan enables the /proc fallback for compositor detection. It only affects the outcome when every stronger signal has failed, and a compositor found this way is reported with ConfidenceLow.
func WithSections ¶
WithSections selects which parts of the Environment to populate. Probes for unselected sections never run.
func WithTimeout ¶
WithTimeout bounds the whole detection run. The default is DefaultTimeout.
type PortalInfo ¶
type PortalInfo struct {
// Backend preferred or matching portal implementation.
Backend string `json:"backend,omitempty"`
// Available whether the implementation or service was detected.
Available bool `json:"available"`
// DesktopPortal whether any desktop portal interface is exported.
DesktopPortal bool `json:"desktop_portal"`
// ScreenCast whether the ScreenCast interface is exported.
ScreenCast bool `json:"screencast"`
// Screenshot whether the Screenshot interface is exported.
Screenshot bool `json:"screenshot"`
// FileChooser whether the FileChooser interface is exported.
FileChooser bool `json:"file_chooser"`
// OpenURI whether the OpenURI interface is exported.
OpenURI bool `json:"open_uri"`
// RemoteDesktop whether the RemoteDesktop interface is exported.
RemoteDesktop bool `json:"remote_desktop"`
// Inhibit whether the Inhibit interface is exported.
Inhibit bool `json:"inhibit"`
// Notification whether the Notification interface is exported.
Notification bool `json:"notification"`
}
PortalInfo describes xdg-desktop-portal and which of its interfaces the running backend actually exports.
type RetryPolicy ¶
type RetryPolicy struct {
// MaxAttempts counts the first attempt; one disables retries.
MaxAttempts uint
// InitialInterval is the initial delay between failed attempts.
InitialInterval time.Duration
// MaxInterval caps the nominal delay before jitter.
MaxInterval time.Duration
}
RetryPolicy configures D-Bus connection attempts and exponential retry delays. Delays have a multiplier of two and jitter of plus or minus twenty percent.
type Section ¶
type Section uint16
Section selects which parts of an Environment to populate. Sections are a bitmask so a caller can pay only for what it reads.
type SessionInfo ¶
type SessionInfo = SessionInfoData[SessionType]
SessionInfo describes the logind seat session.
type SessionInfoData ¶
type SessionInfoData[SessionType any] struct { // ID identifier reported by the underlying system. ID string `json:"id"` // Seat logind seat identifier, such as seat0. Seat string `json:"seat"` // Type windowing protocol associated with the session. Type SessionType `json:"type"` // Desktop desktop identifier reported by logind or the environment. Desktop string `json:"desktop"` // Name human-readable name reported by the source. Name string `json:"name"` // User user associated with the login session. User string `json:"user"` // XDGSessionType unmodified XDG_SESSION_TYPE value. XDGSessionType string `json:"xdg_session_type"` // XDGSessionDesktop unmodified XDG_SESSION_DESKTOP value. XDGSessionDesktop string `json:"xdg_session_desktop"` // VTNumber virtual terminal number; zero when unavailable. VTNumber int `json:"vt_number"` // Remote whether the session is remote, including SSH sessions. Remote bool `json:"remote"` // Active whether the session is currently active. Active bool `json:"active"` }
SessionInfoData is the shared SessionInfoData layout, parameterized by its component types.
type SessionType ¶
type SessionType string
SessionType is the kind of seat session the process is attached to.
type VulkanInfo ¶
type VulkanInfo struct {
// Version version reported by the source, when available.
Version string `json:"version,omitempty"`
// Available whether the implementation or service was detected.
Available bool `json:"available"`
}
VulkanInfo describes the Vulkan loader and its ICDs.
type WaylandGlobal ¶
type WaylandGlobal struct {
// Interface fully qualified Wayland interface name.
Interface string `json:"interface"`
// Name numeric object name assigned by the Wayland registry.
Name uint32 `json:"name"`
// Version version reported by the source, when available.
Version uint32 `json:"version"`
}
WaylandGlobal is one entry from the compositor's global registry.
type WaylandInfo ¶
type WaylandInfo = WaylandInfoData[WaylandGlobal]
WaylandInfo is the result of a real connection to a Wayland compositor.
type WaylandInfoData ¶
type WaylandInfoData[GlobalType any] struct { // Display wayland socket name used for the connection. Display string `json:"display"` // Globals global interfaces advertised by the Wayland registry. Globals []GlobalType `json:"globals,omitempty"` // SocketFD inherited WAYLAND_SOCKET descriptor, when present. SocketFD int `json:"socket_fd,omitempty"` }
WaylandInfoData is the shared WaylandInfoData layout, parameterized by its component types.
type X11Info ¶
type X11Info struct {
// Display x display address used for the connection.
Display string `json:"display"`
// Vendor vendor name reported by the driver or server.
Vendor string `json:"vendor"`
// WindowManager window manager name from EWMH properties.
WindowManager string `json:"window_manager"`
// Extensions extension names advertised by the X server.
Extensions []string `json:"extensions,omitempty"`
// Screen default X screen index.
Screen int `json:"screen"`
// ProtocolMajor major version of the X protocol.
ProtocolMajor int `json:"protocol_major"`
// ProtocolMinor minor version of the X protocol.
ProtocolMinor int `json:"protocol_minor"`
}
X11Info is the result of a real connection to an X server.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
adapter/dbusconn
Package dbusconn opens and caches private D-Bus connections for detection probes.
|
Package dbusconn opens and caches private D-Bus connections for detection probes. |
|
adapter/desktop
Package desktop identifies the desktop environment and queries its version.
|
Package desktop identifies the desktop environment and queries its version. |
|
adapter/drm
Package drm enumerates GPU devices through DRM and sysfs.
|
Package drm enumerates GPU devices through DRM and sysfs. |
|
adapter/env
Package env snapshots environment variables used by detection probes.
|
Package env snapshots environment variables used by detection probes. |
|
adapter/gl
Package gl detects graphics implementations from manifests and optional native queries.
|
Package gl detects graphics implementations from manifests and optional native queries. |
|
adapter/gl/native
Package native queries installed graphics drivers through native libraries.
|
Package native queries installed graphics drivers through native libraries. |
|
adapter/logind
Package logind reads login session information from systemd mirrors and D-Bus.
|
Package logind reads login session information from systemd mirrors and D-Bus. |
|
adapter/osinfo
Package osinfo reads operating system and kernel identity.
|
Package osinfo reads operating system and kernel identity. |
|
adapter/portal
Package portal detects desktop portal backends and their interfaces.
|
Package portal detects desktop portal backends and their interfaces. |
|
adapter/procscan
Package procscan scans user processes for compositor evidence.
|
Package procscan scans user processes for compositor evidence. |
|
adapter/wayland
Package wayland queries Wayland compositor registries.
|
Package wayland queries Wayland compositor registries. |
|
adapter/x11
Package x11 queries X server metadata and window manager properties.
|
Package x11 queries X server metadata and window manager properties. |
|
core
Package core coordinates detection probes and merges their results.
|
Package core coordinates detection probes and merges their results. |
|
domain
Package domain defines internal detection models and enumerations.
|
Package domain defines internal detection models and enumerations. |
|
port
Package port defines the interfaces implemented by detection adapters.
|
Package port defines the interfaces implemented by detection adapters. |
|
probe
Package probe supplies defaults without coupling callers to concrete models.
|
Package probe supplies defaults without coupling callers to concrete models. |
|
rules
Package rules classifies desktop and compositor evidence.
|
Package rules classifies desktop and compositor evidence. |
|
schema
Package schema shares result layouts without choosing domain or public enum types.
|
Package schema shares result layouts without choosing domain or public enum types. |
|
sysfs
Package sysfs reads system metadata with bounded reusable buffers.
|
Package sysfs reads system metadata with bounded reusable buffers. |