fix: hide cursor natively, keep OSD on top, pin codec extension contract (#3)

This commit is contained in:
2026-11-03 22:49:36 +01:00
parent 3d6d146007
commit 296569232e
4 changed files with 271 additions and 37 deletions
+81 -23
View File
@@ -117,21 +117,27 @@ 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
// stackReassert decides the OSD overlay's stacking correction on its
// refresh: above the tracked video window while video is live, and raised
// to the top while video is absent — the fallback canvas raises itself to
// the top when video ends and would otherwise bury the overlay's text under
// the fullscreen presentation indefinitely. Only the OSD overlay ever
// re-asserts; the canvas and video windows are never moved by this.
func stackReassert(role LayerRole, videoActive bool, topVideo xproto.Window, videoWindows map[xproto.Window]struct{}) (sibling xproto.Window, mode uint32, ok bool) {
if role != RoleAbove {
return 0, 0, false
}
if !videoActive {
// No sibling: raise the overlay to the top of the stack.
return 0, xproto.StackModeAbove, true
}
if topVideo == 0 {
return 0, 0, false
}
if _, tracked := videoWindows[topVideo]; !tracked {
return 0, false
return 0, 0, false
}
return topVideo, true
return topVideo, xproto.StackModeAbove, true
}
// raisesOnVideoEnd reports whether a layer raises itself when video ends:
@@ -180,6 +186,43 @@ func osdFallbackFontMetrics() (ascent, descent, cell int16) {
return 11, 3, 6
}
// createWindowValues builds the CreateWindow value mask and values; the
// order must follow the mask bit order (back pixel, event mask, cursor) so
// the server reads each value correctly. The blank cursor hides the pointer
// over the layer from its first frame, independently of video, wfb-ng or
// any cursor-hiding helper process.
func createWindowValues(backPixel uint32, eventMask uint32, cursor xproto.Cursor) (uint32, []uint32) {
values := []uint32{backPixel, eventMask, uint32(cursor)}
return xproto.CwBackPixel | xproto.CwEventMask | xproto.CwCursor, values
}
// newBlankCursor builds the invisible cursor from zeroed 1x1 source and
// mask pixmaps: an all-zero mask displays nothing regardless of the source
// contents, so the pointer disappears over the layer without any shell
// polling or helper process. The pixmaps and graphics context are freed
// immediately; the cursor itself lives until the session closes.
func newBlankCursor(conn *xgb.Conn, screen *xproto.ScreenInfo) xproto.Cursor {
pixmap, _ := xproto.NewPixmapId(conn)
xproto.CreatePixmap(conn, screen.RootDepth, pixmap,
xproto.Drawable(screen.Root), 1, 1)
mask, _ := xproto.NewPixmapId(conn)
xproto.CreatePixmap(conn, screen.RootDepth, mask,
xproto.Drawable(screen.Root), 1, 1)
gc, _ := xproto.NewGcontextId(conn)
xproto.CreateGC(conn, gc, xproto.Drawable(pixmap), 0, nil)
unit := []xproto.Rectangle{{Width: 1, Height: 1}}
xproto.PolyFillRectangle(conn, xproto.Drawable(pixmap), gc, unit)
xproto.PolyFillRectangle(conn, xproto.Drawable(mask), gc, unit)
xproto.FreeGC(conn, gc)
cursor, _ := xproto.NewCursorId(conn)
// Zeroed colors and hotspot: with the all-zero mask nothing is ever
// displayed, so the fore/back colors never reach the screen.
xproto.CreateCursor(conn, cursor, pixmap, mask, 0, 0, 0, 0, 0, 0, 0, 0)
xproto.FreePixmap(conn, pixmap)
xproto.FreePixmap(conn, mask)
return cursor
}
// osdTextRect is the output region covering one drawn text: its glyph cell
// around the baseline, widened by the shape padding.
func osdTextRect(x, y, units int, cell, ascent, descent int16) xproto.Rectangle {
@@ -302,11 +345,15 @@ func (o X11Opener) Open(ctx context.Context) (Session, error) {
if o.Role == RoleAbove {
eventMask = osdEventMask
}
values := uint32(xproto.CwBackPixel | xproto.CwEventMask)
// The blank cursor hides the pointer over this layer from its first
// frame and stays on the layer across no-video/video transitions; the
// server reclaims it when the session's connection closes.
cursor := newBlankCursor(conn, screen)
valueMask, values := createWindowValues(screen.BlackPixel, eventMask, cursor)
xproto.CreateWindow(conn, screen.RootDepth, window, screen.Root,
0, 0, screen.WidthInPixels, screen.HeightInPixels, 0,
xproto.WindowClassInputOutput, screen.RootVisual, values,
[]uint32{screen.BlackPixel, eventMask})
xproto.WindowClassInputOutput, screen.RootVisual, valueMask,
values)
// Tag the window as a Ground Station layer and announce its EWMH role
// before mapping, so no observer or window manager ever sees an
// untagged frame of our own layers.
@@ -442,6 +489,7 @@ func (o X11Opener) Open(ctx context.Context) (Session, error) {
markerAtom: markerAtom,
role: o.Role,
unicodeFont: unicodeFont,
cursor: cursor,
fontAscent: ascent,
fontDescent: descent,
fontCell: cell,
@@ -711,6 +759,9 @@ type x11Session struct {
markerAtom xproto.Atom
role LayerRole
unicodeFont bool
// cursor is the blank cursor applied to the layer window at creation;
// it is freed when the session closes.
cursor xproto.Cursor
// 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
@@ -849,17 +900,22 @@ 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.
// reassertStacking re-claims the overlay's stacking place on the OSD's
// slower refresh cadence: above the live video window, or on top of the
// stack while video is absent so the fallback canvas can never bury it. A
// no-op for the canvas layer.
func (s *x11Session) reassertStacking() {
if s.video == nil || !s.video.Active() {
return
}
target, ok := stackReassertTarget(s.role, s.video.Active(), s.topVideo, s.videoWindows)
videoActive := s.video != nil && s.video.Active()
sibling, mode, ok := stackReassert(s.role, videoActive, s.topVideo, s.videoWindows)
if !ok {
return
}
stackWindowRelative(s.conn, s.window, target, xproto.StackModeAbove)
if sibling != 0 {
stackWindowRelative(s.conn, s.window, sibling, mode)
return
}
xproto.ConfigureWindow(s.conn, s.window,
xproto.ConfigWindowStackMode, []uint32{mode})
}
// applyVideoChange folds one root structure event into the shared video
@@ -983,7 +1039,9 @@ func foldToASCII(message string) string {
}
func (s *x11Session) Close() error {
// Closing the connection makes the X server destroy the kiosk window.
// Free the blank cursor explicitly; closing the connection then makes
// the X server reclaim everything else, including the kiosk window.
xproto.FreeCursor(s.conn, s.cursor)
s.conn.Close()
return nil
}