linuxdesktop

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Linuxdesktop

LICENSE codecov CodSpeed Go Reference FOSSA Status FOSSA Status

A Go library for detecting the Linux desktop environment, login session, display servers, compositor, GPUs, graphics stack, and desktop portal capabilities.

Detection returns partial results alongside probe errors, so an unavailable service does not prevent you from using information collected by other probes. This repository provides a library; it does not install a command-line program.

Installation

Use Go 1.27.2 or newer, as required by go.mod. Inside your application's Go module, add the dependency:

go get github.com/gostafa/linuxdesktop

Import github.com/gostafa/linuxdesktop in your application. Commit go.mod and go.sum to keep dependency versions reproducible.

Runtime Requirements

Run detection on Linux, preferably as the logged-in desktop user. Results depend on the process's environment and access to display sockets, D-Bus, /proc, and /sys. A graphical session is not required for operating-system information. Headless machines, containers, and SSH sessions may expose fewer details.

The default graphics probe inspects the installed stack without initializing an OpenGL context. The optional WithOpenGL() probe loads native graphics libraries and attempts to query the driver; it needs suitable installed libraries and driver access. Installing the Go module does not install graphics drivers or desktop services.

On other operating systems, detection returns a non-nil, headless environment and an error matching ErrNotLinux. This allows cross-platform applications to import the package and handle the unsupported platform explicitly.

Quick Start

Save this as main.go in your application:

package main

import (
	"context"
	"encoding/json"
	"errors"
	"log"
	"os"
	"time"

	"github.com/gostafa/linuxdesktop"
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
	defer cancel()

	env, err := linuxdesktop.DetectContext(ctx)
	if errors.Is(err, linuxdesktop.ErrNotLinux) {
		log.Print("desktop detection requires Linux")
		return
	}
	if err != nil {
		// Successful probes still provide useful data.
		log.Printf("desktop detection returned partial results: %v", err)
	}

	encoder := json.NewEncoder(os.Stdout)
	encoder.SetIndent("", "  ")
	if err := encoder.Encode(env); err != nil {
		log.Fatal(err)
	}
}

Run it from your desktop session:

go run .

For the default detection without a caller-supplied context, use env, err := linuxdesktop.Detect().

Configuration

Pass options to DetectContext. Select multiple sections with bitwise OR:

env, err := linuxdesktop.DetectContext(
	ctx,
	linuxdesktop.WithSections(
		linuxdesktop.SectionOS | linuxdesktop.SectionDisplay,
	),
	linuxdesktop.WithTimeout(2*time.Second),
	linuxdesktop.WithProbeTimeout(500*time.Millisecond),
)

Here, ctx is your application's context. Handle err and use env as in the quick-start example.

Option Purpose Default
WithSections(sections) Select which result sections to populate SectionAll
WithTimeout(duration) Bound the whole detection run 2 seconds
WithProbeTimeout(duration) Bound each individual probe 500 milliseconds
WithConnectionRetry(policy) Configure D-Bus connection initialization 3 attempts; 25 ms initial and 100 ms maximum interval
WithOpenGL() Enable native graphics queries for driver details Disabled
WithProcessScan() Enable the /proc fallback for compositor identification Disabled

Available sections are SectionOS, SectionSession, SectionDisplay, SectionDesktop, SectionCompositor, SectionGraphics, and SectionPortal. Unselected sections remain unpopulated. Passing WithSections(0) selects all sections. Options apply in order, so a later option can override an earlier one.

D-Bus connections are shared by probes within each detection run and closed when the run finishes. Transient transport failures are retried with exponential delays (multiplier 2 and ±20% jitter), within the run and probe timeout budgets. Missing sockets, invalid addresses, and authentication or permission failures fail immediately. Each probe's context bounds its own wait without cancelling another probe's shared initialization. The final connection outcome is cached for that run.

For custom retry settings:

env, err := linuxdesktop.DetectContext(ctx,
	linuxdesktop.WithConnectionRetry(linuxdesktop.RetryPolicy{
		MaxAttempts:     3,
		InitialInterval: 25 * time.Millisecond,
		MaxInterval:     100 * time.Millisecond,
	}),
)

MaxAttempts includes the first attempt; set it to 1 to disable retries. Attempts must be positive, the initial interval must be positive, and the maximum interval must be at least the initial interval. Invalid settings return a non-nil empty environment and an error matching ErrInvalidRetryPolicy before Linux probes run.

To request live graphics details, include SectionGraphics and add WithOpenGL(). This initializes the graphics stack and can cost more than the default filesystem probe. A compositor identified by the process-scan fallback is reported with ConfidenceLow.

Successful EGL and Vulkan library handles, static function bindings, and the initialized default EGL display are retained for the process lifetime. The display may be shared with the host application, so detection never terminates it. Graphics values and probe-owned EGL contexts are queried fresh on each native probe; failed loads or initialization can be retried on a later call. EGL queries are serialized and restore the thread's previous EGL state. An OpenGL version is reported only when the driver provides a GL version string. Display transport operations respond to context cancellation; a native driver call already in progress cannot be interrupted by the Go context.

Results and Convenience Helpers

Environment contains the following fields:

Field Information
OS Distribution, kernel, architecture, and hostname
Session Login session, seat, session type, and remote/active status
Display Display protocol, X11/Wayland availability, and server details
Desktop Desktop identity, version, and original desktop environment values
Compositor Compositor identity, confidence, and detection method
Graphics GPU devices and OpenGL/Vulkan information
Portal Desktop portal availability and exported interfaces
Headless Whether detection found no available display server

For a single section, use OS(), Session(), Display(), Desktop(), Compositor(), Graphics(), or Portal(). Each returns its section's result and an error. Use DetectContext when you need cancellation or custom options.

IsWayland(), IsX11(), and IsHeadless() provide inexpensive availability checks. They do not connect to display servers; use Display() or the display section of DetectContext to check actual connections. Both X11 and Wayland can be available in the same session.

Best Practices

  • Keep partial results. Log or handle probe errors while retaining successful data. Use errors.Is(err, linuxdesktop.ErrNotLinux) for platform checks because errors may be wrapped or joined.
  • Request only what you use. Select relevant sections and use positive timeout values appropriate to your application's responsiveness requirements.
  • Detect outside hot paths. Cache a snapshot when appropriate and refresh it when the session changes. Display connections and optional driver queries have a cost.
  • Treat unknown values as normal. Identity fields may contain linuxdesktop.Unknown; other unavailable details may be empty or zero-valued. Check env.Display.X11 and env.Display.Wayland for nil before reading them.
  • Use confidence and capability fields. Consider Compositor.Confidence and Compositor.DetectedBy when interpreting identification. Check the specific portal interface you need instead of assuming it exists from the desktop name.
  • Run in the intended user's session. Running through sudo or in an isolated container can change environment variables and service access. Preserve the real session environment rather than inventing display or D-Bus addresses.
  • Share diagnostics carefully. Results can include a hostname, user/session identifiers, and GPU details. Remove information you do not need before sending diagnostic output elsewhere.

Development

Clone the repository and download its Go dependencies:

git clone https://github.com/gostafa/linuxdesktop.git
cd linuxdesktop
go mod download

Dependencies are pinned in go.mod. The X11 adapter uses upstream XGB with project-owned transport cancellation and authentication selection.

Run the tests and static checks:

go test ./...
go vet ./...

Tests involving real system facilities may skip when the platform or required services are unavailable. Validate Linux desktop behavior in an actual Linux session when changing probes.

The repository also includes Task automation. If Task is installed, run task --list-all to discover commands, or task taskotter:go:test to run Go tests. See taskotter for the included tooling tasks.

Keep the public API in the root package; probe implementations live under internal/. Format changed Go files with gofmt, add relevant tests for behavior changes, and keep this README consistent with public options and defaults.

License

FOSSA Status

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

View Source
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

View Source
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.

func IsWayland

func IsWayland() bool

IsWayland reports whether a Wayland compositor socket is present. It stats a path and nothing more, so it is safe on any hot path; Display connects and is therefore the authority.

func IsX11

func IsX11() bool

IsX11 reports whether an X server appears to be reachable. Like IsWayland it only stats; a display on a remote host is assumed reachable.

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.

func Desktop

func Desktop() (DesktopInfo, error)

Desktop reports 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.

func Display

func Display() (DisplayInfo, error)

Display reports which display servers are reachable, connecting to each one that is.

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.

func Graphics

func Graphics() (GraphicsInfo, error)

Graphics reports the GPUs and the client-side graphics stack. It uses the filesystem-only stack probe; for a live renderer string call DetectContext with WithOpenGL.

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.

func OS

func OS() (OSInfo, error)

OS reports the distribution and kernel identity.

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

func WithProbeTimeout(d time.Duration) Option

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

func WithSections(s Section) Option

WithSections selects which parts of the Environment to populate. Probes for unselected sections never run.

func WithTimeout

func WithTimeout(d time.Duration) Option

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.

func Portal

func Portal() (PortalInfo, error)

Portal reports whether xdg-desktop-portal is running and what it offers.

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.

func Session

func Session() (SessionInfo, error)

Session reports 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL