feat: publish adaptive-link OSD contract and keep overlay above video (#3)

This commit is contained in:
2026-10-18 08:02:18 +02:00
parent f0d5052ccb
commit 79ea5d62b7
14 changed files with 616 additions and 81 deletions
+51 -6
View File
@@ -99,6 +99,23 @@ func stackModeForVideoAppear(role LayerRole) uint32 {
return xproto.StackModeBelow
}
// stackReassertTarget reports which video window the OSD overlay must sit
// above after an external restack, and whether one exists. Only the OSD
// overlay re-asserts its place: window managers promote fullscreened video
// to the top of their stacking order after the video-appear restack, which
// would bury the overlay — and its text — for the rest of the flight. The
// fallback canvas keeps its event-driven lifecycle, and the video window is
// never moved.
func stackReassertTarget(role LayerRole, videoActive bool, topVideo xproto.Window, videoWindows map[xproto.Window]struct{}) (xproto.Window, bool) {
if role != RoleAbove || !videoActive || topVideo == 0 {
return 0, false
}
if _, tracked := videoWindows[topVideo]; !tracked {
return 0, false
}
return topVideo, true
}
// raisesOnVideoEnd reports whether a layer raises itself when video ends:
// only the below canvas needs that to make the fallback visible again; the
// OSD overlay is already above everything.
@@ -321,9 +338,11 @@ func (o X11Opener) Open(ctx context.Context) (Session, error) {
presence := o.presence()
typeAtom := internWindowTypeAtom(conn)
videoWindows := scanVideoWindows(conn, screen.Root, window, typeAtom, markerAtom)
var topVideo xproto.Window
if len(videoWindows) > 0 {
presence.SetActive(true)
stackWindowRelative(conn, window, videoWindows[len(videoWindows)-1],
topVideo = videoWindows[len(videoWindows)-1]
stackWindowRelative(conn, window, topVideo,
stackModeForVideoAppear(o.Role))
} else {
presence.SetActive(false)
@@ -380,6 +399,7 @@ func (o X11Opener) Open(ctx context.Context) (Session, error) {
refresh: o.RefreshInterval,
video: presence,
videoWindows: videoWindowSet(videoWindows),
topVideo: topVideo,
typeAtom: typeAtom,
markerAtom: markerAtom,
role: o.Role,
@@ -645,10 +665,14 @@ type x11Session struct {
refresh time.Duration
video *VideoPresence
videoWindows map[xproto.Window]struct{}
typeAtom xproto.Atom
markerAtom xproto.Atom
role LayerRole
unicodeFont bool
// topVideo is the video window the OSD overlay must sit above; it is
// re-asserted on the overlay's refresh because window managers may
// promote fullscreened video back on top after the appear restack.
topVideo xproto.Window
typeAtom xproto.Atom
markerAtom xproto.Atom
role LayerRole
unicodeFont bool
// fontAscent, fontDescent and fontCell describe the drawn font so the
// OSD overlay can punch its output shape around each text's glyph cell.
fontAscent int16
@@ -767,6 +791,10 @@ func (s *x11Session) WaitEvent(ctx context.Context) (bool, error) {
// event-driven.
if s.refresh > 0 && time.Since(lastRefresh) >= s.refresh {
lastRefresh = time.Now()
// The redraw is also where the overlay re-claims its place
// above fullscreen video: window managers may have promoted
// the video window back on top since the appear restack.
s.reassertStacking()
return true, nil
}
// Round trip keeps the connection liveness visible even without
@@ -783,6 +811,19 @@ func (s *x11Session) WaitEvent(ctx context.Context) (bool, error) {
}
}
// reassertStacking re-claims the overlay's place above the presented video
// window; a no-op for the canvas and whenever video is absent.
func (s *x11Session) reassertStacking() {
if s.video == nil || !s.video.Active() {
return
}
target, ok := stackReassertTarget(s.role, s.video.Active(), s.topVideo, s.videoWindows)
if !ok {
return
}
stackWindowRelative(s.conn, s.window, target, xproto.StackModeAbove)
}
// applyVideoChange folds one root structure event into the shared video
// presence and restacks this layer so video keeps rendering priority: the
// canvas parks below video and the OSD overlay rises above it. It reports
@@ -803,13 +844,17 @@ func (s *x11Session) applyVideoChange(event xgb.Event) bool {
return false
}
// The first presented video output takes priority: park on our side
// of it.
// of it, and remember it as the restack target for later re-claims.
s.topVideo = w
stackWindowRelative(s.conn, s.window, w, stackModeForVideoAppear(s.role))
return s.video.SetActive(true)
case videoDisappeared:
if !removeVideoWindow(s.videoWindows, w) {
return false
}
if s.topVideo == w {
s.topVideo = 0
}
// Only the below canvas raises itself so the fallback returns
// visibly even if some other window was stacked above it; the OSD
// overlay is already above video.