Reset master to testing content
This commit is contained in:
1 parent
0f2587b719
commit
42afa2a56c
1483 files changed
+145308
-938069
No files matched your search
@@ -0,0 +1,31 @@
|
||||
// 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
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// Authors: Storm Dragon, Angus Kola
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package session
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDesktopEnvironment(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name, kind, display, backend, wantBackend string
|
||||
wayland bool
|
||||
}{
|
||||
{"Xorg", "x11", "", "wayland", "x11", false},
|
||||
{"Xorg with inherited Wayland display", "x11", "wayland-0", "", "x11", false},
|
||||
{"Wayland", "wayland", "wayland-0", "", "", true},
|
||||
{"Wayland user backend", "wayland", "wayland-0", "x11", "x11", true},
|
||||
{"normalized session", " Wayland ", "", "wayland,x11", "wayland,x11", true},
|
||||
{"Wayland display fallback", "", "wayland-0", "", "", true},
|
||||
{"unspecified session", "", "", "wayland,x11", "wayland,x11", false},
|
||||
{"explicit other session", "tty", "wayland-0", "", "", false},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Setenv("XDG_SESSION_TYPE", test.kind)
|
||||
t.Setenv("WAYLAND_DISPLAY", test.display)
|
||||
t.Setenv("GDK_BACKEND", test.backend)
|
||||
t.Setenv("CTHULHU_TEST_INHERITED", "preserved")
|
||||
if got := Wayland(); got != test.wayland {
|
||||
t.Fatalf("Wayland = %v, want %v", got, test.wayland)
|
||||
}
|
||||
values := make(map[string]string)
|
||||
for _, entry := range GTKEnvironment() {
|
||||
key, value, _ := strings.Cut(entry, "=")
|
||||
values[key] = value
|
||||
}
|
||||
if values["GDK_BACKEND"] != test.wantBackend || values["CTHULHU_TEST_INHERITED"] != "preserved" {
|
||||
t.Fatalf("GTK backend = %q, inherited value = %q", values["GDK_BACKEND"], values["CTHULHU_TEST_INHERITED"])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user