Place windows at map time so stream restarts never flash
Diagnosis: individual tiles flickered when their stream died and mpv relaunched (confirmed via status: a PID dropping to 0 and coming back). The restarted window mapped at the video's native size wherever sway dropped it, and the corrective loop only snapped it into its cell on the next tick — up to 2s later on the relaxed cadence. Fix, at the source instead of racing the map: - Pre-install a per-slot for_window rule (matched on each mpv's unique window title, anchored so slot-1 never matches slot-10) so sway positions and sizes the window synchronously the moment it maps. - Pass --geometry=WxH per tile so mpv opens at the tile size rather than resizing itself to the video's native size on load. The placeLoop remains as a corrective backstop for mid-life drift. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -185,3 +185,17 @@ func (c *Client) Place(ctx context.Context, pid int, r Rect) error {
|
||||
func (c *Client) PrepareForMPV(ctx context.Context) error {
|
||||
return c.run(ctx, `for_window [app_id="mpv"] floating enable, border none`)
|
||||
}
|
||||
|
||||
// PlaceOnMap installs a for_window rule that positions any window with the
|
||||
// given title at rect the moment it maps. This is what keeps a restarting
|
||||
// stream from flashing at the wrong place/size: sway applies the geometry
|
||||
// synchronously at map time, before the daemon's corrective loop ever sees
|
||||
// the window. Re-installing a rule for the same title replaces it. The title
|
||||
// is anchored (^...$) so slot-1 never matches slot-10.
|
||||
func (c *Client) PlaceOnMap(ctx context.Context, title string, r Rect) error {
|
||||
cmd := fmt.Sprintf(
|
||||
`for_window [title="^%s$"] floating enable, border none, move absolute position %d %d, resize set %d %d`,
|
||||
title, r.X, r.Y, r.W, r.H,
|
||||
)
|
||||
return c.run(ctx, cmd)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user