Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ keyboard.

The control bar hides 2 s after the pointer last moved or a key was pressed while a video
plays, in a window and in full screen. It stays while the video is paused or has ended,
for music, and while the keyboard focus is in it. The mouse pointer hides with the bar and
for music, while the keyboard focus is in it, and while the pointer rests on it. The mouse pointer hides with the bar and
comes back with it: on any pointer motion, and on a key, a click or a pause. It hides only
where the desktop offers cursor-shape-v1, without which its shape couldn't be set again.
A video stops on its last frame with a
Expand Down
2 changes: 1 addition & 1 deletion design/tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@
{
"name": "controls-hide",
"value": "2s",
"usage": "While a video plays, how long the control bar stays after the pointer last moved or a key was pressed. Paused, ended, loading, failed, music, or a keyboard focus inside the bar: it stays. The mouse pointer hides and comes back with it."
"usage": "While a video plays, how long the control bar stays after the pointer last moved or a key was pressed. Paused, ended, loading, failed, music, a keyboard focus inside the bar, or the pointer resting on the bar: it stays. The mouse pointer hides and comes back with it."
},
{
"name": "seek-step",
Expand Down
10 changes: 8 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ impl App {

pub fn resize(&mut self, w: u32, h: u32, scale: f64) {
let changed = (w, h) != self.win || (scale - self.scale).abs() > 1e-9;
// The pointer is kept in buffer pixels: the same place at the new scale.
if self.scale > 0.0 && (scale - self.scale).abs() > 1e-9 {
let k = scale / self.scale;
self.pointer = (self.pointer.0 * k, self.pointer.1 * k);
}
self.win = (w.max(1), h.max(1));
self.scale = scale;
self.frame.resize(self.win.0 as usize * self.win.1 as usize, 0);
Expand All @@ -256,6 +261,8 @@ impl App {
}
if changed {
self.overlay_all();
// The bar moved; the pointer may be on it now, or no longer.
self.refresh_hover();
}
let size = self.media.as_ref().map(|m| m.kind).map(|k| self.media_box(k));
if let (Some(m), Some(b)) = (&mut self.media, size) {
Expand Down Expand Up @@ -305,12 +312,11 @@ impl App {
} else {
Media::failed(path, kind, "this desktop can't show video from another process (it lacks linux-dmabuf or viewporter)".into())
});
self.controls = Controls { focus, ..Controls::default() };
self.track += 1;
self.seek_said_at = None;
let opening = format!("Opening {}", self.name());
self.say(opening);
self.poke_controls(Instant::now());
self.reset_controls(focus, Instant::now());
self.after_media_news(None);
self.all();
self.a11y_dirty = true;
Expand Down
219 changes: 187 additions & 32 deletions src/app/player_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ pub struct Controls {
pub hover: Option<Control>,
/// A slider held down with the pointer.
pub drag: Option<Control>,
/// The pointer rests over the bar. While it's there the bar stays.
pub on_bar: bool,
pub shown: bool,
pub hide_at: Option<Instant>,
}

/// Whether the bar may hide by itself: only while a video plays, with no keyboard focus or
/// drag in it (Mike, 2026-12-02: paused, ended, music and a focus in the bar keep it).
pub fn may_hide(kind: Kind, phase: &Phase, focus: Option<Control>, drag: Option<Control>) -> bool {
kind == Kind::Video && *phase == Phase::Playing && focus.is_none() && drag.is_none()
/// drag in it (Mike, 2026-12-02: paused, ended, music and a focus in the bar keep it) and the
/// pointer not resting on it (Mike, 2026-12-04, ALI-2664).
pub fn may_hide(kind: Kind, phase: &Phase, c: &Controls) -> bool {
kind == Kind::Video && *phase == Phase::Playing && c.focus.is_none() && c.drag.is_none() && !c.on_bar
}

/// Whether the pointer is hidden: with the bar, once the bar hid by itself over a playing
Expand All @@ -51,20 +54,30 @@ impl App {

/// Something happened: show the bar, and hide it `controls-hide` later if it may.
pub(super) fn poke_controls(&mut self, now: Instant) {
let Some(m) = &self.media else { return };
let may = may_hide(m.kind, &m.phase(), self.controls.focus, self.controls.drag);
if self.media.is_none() {
return;
}
if !self.controls.shown {
self.controls.shown = true;
// A key can show it under a pointer that hasn't moved since the bar hid.
self.controls.on_bar = self.bar_under_pointer();
self.overlay_all();
}
let may = self.media.as_ref().is_some_and(|m| may_hide(m.kind, &m.phase(), &self.controls));
self.controls.hide_at = may.then(|| now + motion::CONTROLS_HIDE);
}

/// Whether the pointer is in the window and over the bar's place, shown or not.
fn bar_under_pointer(&mut self) -> bool {
let (x, y) = (self.pointer.0 as i32, self.pointer.1 as i32);
self.pointer_in && self.bar_layout().is_some_and(|l| l.bar.contains(x, y))
}

/// The bar's time to hide came: hides it if it still may.
pub(super) fn expire_controls(&mut self, now: Instant) {
if self.controls.hide_at.is_some_and(|t| now >= t) {
self.controls.hide_at = None;
let may = self.media.as_ref().is_some_and(|m| may_hide(m.kind, &m.phase(), self.controls.focus, self.controls.drag));
let may = self.media.as_ref().is_some_and(|m| may_hide(m.kind, &m.phase(), &self.controls));
if may && self.controls.shown {
self.controls.shown = false;
self.controls.hover = None;
Expand Down Expand Up @@ -343,15 +356,36 @@ impl App {
self.a11y_dirty = true;
}

/// Highlights the control under the pointer, if the bar is shown, without counting as
/// motion: for when the bar came or went while the pointer stayed put.
/// Highlights the control under the pointer and notes whether it rests on the bar, if the
/// bar is shown, without counting as motion: for when the bar came, went or moved while the
/// pointer stayed put. Coming onto or off the bar stops or restarts the time to hide.
pub(super) fn refresh_hover(&mut self) {
let (x, y) = (self.pointer.0 as i32, self.pointer.1 as i32);
let hover = if self.controls.shown { self.bar_layout().and_then(|l| l.hit(x, y)) } else { None };
// Outside the window, the last place it was isn't where it is.
let l = self.bar_layout().filter(|_| self.pointer_in);
let hover = if self.controls.shown { l.and_then(|l| l.hit(x, y)) } else { None };
if hover != self.controls.hover {
self.controls.hover = hover;
self.overlay_bar();
}
// The bar can move from under a still pointer, or come under it: a resize, new media.
let on_bar = self.controls.shown && self.bar_under_pointer();
self.set_on_bar(on_bar, Instant::now());
}

/// Whether the pointer rests on the bar. Coming onto it stops the time to hide; coming off
/// it starts it again.
pub(super) fn set_on_bar(&mut self, on_bar: bool, now: Instant) {
if std::mem::replace(&mut self.controls.on_bar, on_bar) != on_bar && self.controls.shown {
self.poke_controls(now);
}
}

/// New media opened: a fresh bar, keeping the keyboard focus, and the pointer's place on it.
pub(super) fn reset_controls(&mut self, focus: Option<Control>, now: Instant) {
self.controls = Controls { focus, ..Controls::default() };
self.poke_controls(now);
self.refresh_hover();
}

/// The pointer, over a video or song. True if it was the player's.
Expand All @@ -363,23 +397,11 @@ impl App {
let (x, y) = (self.pointer.0 as i32, self.pointer.1 as i32);
match *ev {
Input::Move { .. } => {
let was_shown = self.controls.shown;
self.poke_controls(now);
let l = self.bar_layout();
if let (Some(c), Some(l)) = (self.controls.drag, l) {
self.slide(c, l, x);
}
let hover = if was_shown { l.and_then(|l| l.hit(x, y)) } else { None };
if hover != self.controls.hover {
self.controls.hover = hover;
self.overlay_bar();
}
self.pointer_motion(now);
true
}
Input::Leave => {
if self.controls.hover.take().is_some() {
self.overlay_bar();
}
self.pointer_left(now);
false
}
Input::Button { button: BTN_LEFT, pressed } => {
Expand Down Expand Up @@ -417,6 +439,32 @@ impl App {
}
}

/// The pointer moved to `self.pointer`, over a video or song.
fn pointer_motion(&mut self, now: Instant) {
let (x, y) = (self.pointer.0 as i32, self.pointer.1 as i32);
let was_shown = self.controls.shown;
// Before the poke, so a pointer on the bar keeps it from timing out.
self.controls.on_bar = self.bar_under_pointer();
self.poke_controls(now);
let l = self.bar_layout();
if let (Some(c), Some(l)) = (self.controls.drag, l) {
self.slide(c, l, x);
}
let hover = if was_shown { l.and_then(|l| l.hit(x, y)) } else { None };
if hover != self.controls.hover {
self.controls.hover = hover;
self.overlay_bar();
}
}

/// The pointer left the window.
fn pointer_left(&mut self, now: Instant) {
if self.controls.hover.take().is_some() {
self.overlay_bar();
}
self.set_on_bar(false, now);
}

/// The pointer at `x` on a slider sets its value.
fn slide(&mut self, c: Control, l: Layout, x: i32) {
let Some(r) = l.rect(c) else { return };
Expand Down Expand Up @@ -754,15 +802,17 @@ mod tests {
use super::*;

#[test]
fn the_bar_hides_only_while_a_video_plays_with_no_focus_in_it() {
assert!(may_hide(Kind::Video, &Phase::Playing, None, None));
assert!(!may_hide(Kind::Video, &Phase::Paused, None, None));
assert!(!may_hide(Kind::Video, &Phase::Ended, None, None));
assert!(!may_hide(Kind::Video, &Phase::Opening, None, None));
assert!(!may_hide(Kind::Video, &Phase::Failed("x".into()), None, None));
assert!(!may_hide(Kind::Music, &Phase::Playing, None, None));
assert!(!may_hide(Kind::Video, &Phase::Playing, Some(Control::Play), None));
assert!(!may_hide(Kind::Video, &Phase::Playing, None, Some(Control::Position)));
fn the_bar_hides_only_while_a_video_plays_with_no_focus_or_pointer_in_it() {
let free = Controls::default();
assert!(may_hide(Kind::Video, &Phase::Playing, &free));
assert!(!may_hide(Kind::Video, &Phase::Paused, &free));
assert!(!may_hide(Kind::Video, &Phase::Ended, &free));
assert!(!may_hide(Kind::Video, &Phase::Opening, &free));
assert!(!may_hide(Kind::Video, &Phase::Failed("x".into()), &free));
assert!(!may_hide(Kind::Music, &Phase::Playing, &free));
assert!(!may_hide(Kind::Video, &Phase::Playing, &Controls { focus: Some(Control::Play), ..Controls::default() }));
assert!(!may_hide(Kind::Video, &Phase::Playing, &Controls { drag: Some(Control::Position), ..Controls::default() }));
assert!(!may_hide(Kind::Video, &Phase::Playing, &Controls { on_bar: true, ..Controls::default() }));
}

#[test]
Expand Down Expand Up @@ -810,6 +860,111 @@ mod tests {
assert!(a.pointer_moved(&at(50.5, 40.0)), "back over the window counts, even at the same place");
}

#[test]
fn the_bar_stays_while_the_pointer_rests_on_it_and_times_out_once_it_leaves() {
let t = Instant::now();
let mut a = playing("clip.mp4", false, false);
a.scale = 2.0;
let bar = a.bar_layout().expect("a bar").bar;
// In surface pixels, as the compositor sends them: the bar's middle, and the video above.
let cx = (bar.x + bar.w / 2) as f64 / 2.0;
let on = || Input::Move { x: cx, y: (bar.y + bar.h / 2) as f64 / 2.0 };
// Just above the bar's top edge.
let off = || Input::Move { x: cx, y: (bar.y - 1) as f64 / 2.0 };
let feed = |a: &mut App, ev: Input, now: Instant| {
assert!(a.pointer_moved(&ev), "{ev:?} is motion");
match ev {
Input::Leave => a.pointer_left(now),
_ => a.pointer_motion(now),
}
};
feed(&mut a, on(), t);
assert!(a.controls.shown && a.controls.on_bar, "on the bar");
a.expire_controls(t + motion::CONTROLS_HIDE * 10);
assert!(a.controls.shown && !a.pointer_hidden(), "resting on the bar keeps it and the pointer");
// Hyprland repeating the place doesn't change that.
assert!(!a.pointer_moved(&on()));
a.refresh_hover();
a.expire_controls(t + motion::CONTROLS_HIDE * 11);
assert!(a.controls.shown && a.controls.on_bar, "still on the bar");
let t2 = t + motion::CONTROLS_HIDE * 12;
feed(&mut a, off(), t2);
assert!(!a.controls.on_bar && a.controls.hide_at.is_some(), "back over the video, the time to hide starts again");
a.expire_controls(t2 + motion::CONTROLS_HIDE);
assert!(!a.controls.shown && a.pointer_hidden(), "and then both hide");
// Leaving the window from the bar starts the time to hide too.
let t3 = t2 + motion::CONTROLS_HIDE * 2;
feed(&mut a, on(), t3);
a.expire_controls(t3 + motion::CONTROLS_HIDE);
assert!(a.controls.shown, "kept while on the bar");
let t4 = t3 + motion::CONTROLS_HIDE * 2;
feed(&mut a, Input::Leave, t4);
assert!(!a.controls.on_bar && a.controls.hide_at.is_some(), "leaving starts the time to hide");
a.expire_controls(t4 + motion::CONTROLS_HIDE);
assert!(!a.controls.shown, "so the bar still hides once the pointer has gone");
}

#[test]
fn the_bar_stays_under_a_resting_pointer_when_new_media_opens_or_the_window_resizes() {
let t = Instant::now();
let mut a = playing("clip.mp4", false, false);
let bar = a.bar_layout().expect("a bar").bar;
let on_bar = Input::Move { x: (bar.x + bar.w / 2) as f64, y: (bar.y + bar.h / 2) as f64 };
assert!(a.pointer_moved(&on_bar));
a.pointer_motion(t);
assert!(a.controls.on_bar);
// As sync_media does for the next video, opened with Next or a key.
a.reset_controls(None, t);
assert!(a.controls.on_bar && a.controls.hide_at.is_none(), "the pointer is still on the new bar");
a.expire_controls(t + motion::CONTROLS_HIDE * 2);
assert!(a.controls.shown, "so it stays");
// Taller: the bar moves down from under the still pointer.
a.resize(400, 600, 1.0);
assert!(!a.controls.on_bar && a.controls.hide_at.is_some(), "off the bar after the resize");
a.expire_controls(Instant::now() + motion::CONTROLS_HIDE);
assert!(!a.controls.shown && a.pointer_hidden(), "so it hides");
// Back: the bar comes under the pointer again; shown on motion, it then stays.
a.resize(400, 300, 1.0);
a.pointer_motion(Instant::now());
assert!(a.controls.on_bar && a.controls.hide_at.is_none());
// Gone from the window: its last place doesn't count.
assert!(a.pointer_moved(&Input::Leave));
a.pointer_left(Instant::now());
a.refresh_hover();
assert!(!a.controls.on_bar, "not on the bar from outside the window");
}

#[test]
fn a_key_showing_the_bar_under_a_still_pointer_keeps_it() {
let t = Instant::now();
let mut a = playing("clip.mp4", false, false);
// Rest on the video, 10 px above the bar, and let both hide.
let bar = a.bar_layout().expect("a bar").bar;
assert!(a.pointer_moved(&Input::Move { x: (bar.x + bar.w / 2) as f64, y: (bar.y - 10) as f64 }));
a.pointer_motion(t);
a.expire_controls(t + motion::CONTROLS_HIDE);
assert!(!a.controls.shown && a.pointer_hidden());
// Shorter: the hidden bar's place comes under the still pointer.
a.resize(400, 280, 1.0);
assert!(!a.controls.shown && !a.controls.on_bar, "still hidden, so not on it");
// A key shows it, as Space or an arrow does.
a.poke_controls(t + motion::CONTROLS_HIDE * 2);
assert!(a.controls.shown && a.controls.on_bar && a.controls.hide_at.is_none(), "shown under the pointer, it stays");
}

#[test]
fn a_new_scale_keeps_the_pointer_where_it_is() {
let t = Instant::now();
let mut a = playing("clip.mp4", false, false);
let bar = a.bar_layout().expect("a bar").bar;
assert!(a.pointer_moved(&Input::Move { x: (bar.x + bar.w - 4) as f64, y: (bar.y + bar.h - 2) as f64 }));
a.pointer_motion(t);
assert!(a.controls.on_bar);
// To a monitor at scale 2: the same surface, twice the buffer pixels.
a.resize(800, 600, 2.0);
assert!(a.controls.on_bar && a.controls.hide_at.is_none(), "still on the bar at the new scale");
}

#[test]
fn the_pointer_hides_with_the_bar_while_a_video_plays_and_motion_brings_it_back() {
let t = Instant::now();
Expand Down
2 changes: 1 addition & 1 deletion src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ pub mod motion {
/// After the theme folder changes, how long the viewer waits before reading it, so a theme swap is read once it's whole (src/main.rs).
pub const THEME_SETTLE: Duration = Duration::from_millis(15);

/// While a video plays, how long the control bar stays after the pointer last moved or a key was pressed. Paused, ended, loading, failed, music, or a keyboard focus inside the bar: it stays. The mouse pointer hides and comes back with it.
/// While a video plays, how long the control bar stays after the pointer last moved or a key was pressed. Paused, ended, loading, failed, music, a keyboard focus inside the bar, or the pointer resting on the bar: it stays. The mouse pointer hides and comes back with it.
pub const CONTROLS_HIDE: Duration = Duration::from_millis(2000);

/// How far Left and Right (or a click on the seek bar's keyboard focus) move in a video.
Expand Down
Loading