2024-09-08 02:24:01 +09:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
|
2024-09-16 20:32:07 +09:00
|
|
|
"git.ophivana.moe/cat/fortify/acl"
|
2024-09-17 13:48:42 +09:00
|
|
|
"git.ophivana.moe/cat/fortify/internal"
|
2024-09-12 21:07:05 +09:00
|
|
|
"git.ophivana.moe/cat/fortify/internal/verbose"
|
2024-09-08 02:24:01 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// https://manpages.debian.org/experimental/libwayland-doc/wl_display_connect.3.en.html
|
|
|
|
waylandDisplay = "WAYLAND_DISPLAY"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (a *App) ShareWayland() {
|
2024-09-17 13:48:42 +09:00
|
|
|
a.setEnablement(internal.EnableWayland)
|
2024-09-08 02:24:01 +09:00
|
|
|
|
|
|
|
// ensure Wayland socket ACL (e.g. `/run/user/%d/wayland-%d`)
|
|
|
|
if w, ok := os.LookupEnv(waylandDisplay); !ok {
|
2024-09-17 13:48:42 +09:00
|
|
|
internal.Fatal("Wayland: WAYLAND_DISPLAY not set")
|
2024-09-08 02:24:01 +09:00
|
|
|
} else {
|
|
|
|
// add environment variable for new process
|
2024-09-16 20:31:15 +09:00
|
|
|
wp := path.Join(a.runtimePath, w)
|
2024-09-08 02:24:01 +09:00
|
|
|
a.AppendEnv(waylandDisplay, wp)
|
|
|
|
if err := acl.UpdatePerm(wp, a.UID(), acl.Read, acl.Write, acl.Execute); err != nil {
|
2024-09-17 13:48:42 +09:00
|
|
|
internal.Fatal(fmt.Sprintf("Error preparing Wayland '%s':", w), err)
|
2024-09-08 02:24:01 +09:00
|
|
|
} else {
|
2024-09-17 13:48:42 +09:00
|
|
|
a.exit.RegisterRevertPath(wp)
|
2024-09-08 02:24:01 +09:00
|
|
|
}
|
2024-09-12 21:07:05 +09:00
|
|
|
verbose.Printf("Wayland socket '%s' configured\n", w)
|
2024-09-08 02:24:01 +09:00
|
|
|
}
|
|
|
|
}
|