internal/system: relocate from system
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m18s
Test / Hakurei (push) Successful in 3m17s
Test / Sandbox (race detector) (push) Successful in 4m7s
Test / Hpkg (push) Successful in 4m13s
Test / Hakurei (race detector) (push) Successful in 5m3s
Test / Flake checks (push) Successful in 1m40s

These packages are highly specific to hakurei and are difficult to use safely from other pieces of code.

Their exported symbols are made available until v0.4.0 where they will be removed for #24.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2025-11-13 01:15:19 +09:00
parent 15a66a2b31
commit 4e7aab07d5
54 changed files with 243 additions and 30 deletions

38
internal/system/xhost.go Normal file
View File

@@ -0,0 +1,38 @@
package system
import (
"hakurei.app/hst"
"hakurei.app/internal/system/xcb"
)
// ChangeHosts inserts the target user into X11 hosts and deletes it once its [Enablement] is no longer satisfied.
func (sys *I) ChangeHosts(username string) *I {
sys.ops = append(sys.ops, xhostOp(username))
return sys
}
// xhostOp implements [I.ChangeHosts].
type xhostOp string
func (x xhostOp) Type() hst.Enablement { return hst.EX11 }
func (x xhostOp) apply(sys *I) error {
sys.msg.Verbosef("inserting entry %s to X11", x)
return newOpError("xhost",
sys.xcbChangeHosts(xcb.HostModeInsert, xcb.FamilyServerInterpreted, "localuser\x00"+string(x)), false)
}
func (x xhostOp) revert(sys *I, ec *Criteria) error {
if ec.hasType(x.Type()) {
sys.msg.Verbosef("deleting entry %s from X11", x)
return newOpError("xhost",
sys.xcbChangeHosts(xcb.HostModeDelete, xcb.FamilyServerInterpreted, "localuser\x00"+string(x)), true)
} else {
sys.msg.Verbosef("skipping entry %s in X11", x)
return nil
}
}
func (x xhostOp) Is(o Op) bool { target, ok := o.(xhostOp); return ok && x == target }
func (x xhostOp) Path() string { return "/tmp/.X11-unix" }
func (x xhostOp) String() string { return string("SI:localuser:" + x) }