32 lines
961 B
Go
32 lines
961 B
Go
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
// Package session keeps desktop session policy independent of native backends.
|
|
package session
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
// Wayland respects an explicit session type; WAYLAND_DISPLAY is a fallback for
|
|
// launchers that do not set XDG_SESSION_TYPE.
|
|
func Wayland() bool {
|
|
kind := strings.ToLower(strings.TrimSpace(os.Getenv("XDG_SESSION_TYPE")))
|
|
if kind != "" {
|
|
return kind == "wayland"
|
|
}
|
|
return strings.TrimSpace(os.Getenv("WAYLAND_DISPLAY")) != ""
|
|
}
|
|
|
|
// GTKEnvironment preserves Xorg focus correlation in explicit X11 sessions.
|
|
// Elsewhere GTK inherits the user's backend choice and selects its own default.
|
|
func GTKEnvironment() []string {
|
|
environment := os.Environ()
|
|
if strings.EqualFold(strings.TrimSpace(os.Getenv("XDG_SESSION_TYPE")), "x11") {
|
|
environment = append(environment, "GDK_BACKEND=x11")
|
|
}
|
|
return environment
|
|
}
|