diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 4051f12..7578afe 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -30,6 +30,7 @@ pub(crate) use interact::*; pub(crate) use layout::*; pub(crate) use library_meta::*; pub(crate) use menus::*; +pub(crate) use render::escape_leaves_player_fullscreen; pub(crate) use notices::*; pub(crate) use oracle::*; pub(crate) use subs::*; @@ -93,6 +94,14 @@ struct Player { /// ([`Player::open_preview`] pauses it so the two sounds never overlap): /// what [`Player::close_preview`] resumes, and only then. preview_playing: bool, + /// The picture alone, filling the window -- what `Fullscreen` gives every + /// consumer video player, and not what gpui's own `toggle_fullscreen` + /// gives on its own (the OS window, chrome and all). Kept apart from + /// `window.is_fullscreen()` because the two can fall out of step: a + /// compositor keybind changes the window's without this flag hearing + /// about it, so [`Player::act`] reconciles them rather than trusting + /// either alone. + player_fullscreen: bool, /// Timeline seconds -> frame index, so the clock can be compared to what /// the decoder hands over. fps: f64, @@ -722,6 +731,7 @@ fn main() { pending_settings: (None, None, None), preview_session: None, preview_playing: false, + player_fullscreen: false, // Full and unmuted, which is what the session it was just // handed is already set to: nothing to push at startup. volume: Volume::default(), diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index 5f8bdc6..2e65e76 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -98,10 +98,20 @@ impl Player { // At the window's corner, since a stroke names no place -- and // [`menu_at`] keeps it on screen from there. ActionId::Theme => self.open_picker(Pick::Theme, Point::default(), cx), - // The platform's own toggle (gpui::Window::toggle_fullscreen); the - // window reports its own new state back through `is_fullscreen`, - // there is no local bool to keep in step with it. - ActionId::Fullscreen => window.toggle_fullscreen(), + // Not the window's own toggle alone -- every consumer video + // player fullscreens the *picture*, chrome and all, not just the + // OS frame around it -- so this flips both: `player_fullscreen` + // is what [`crate::render`] reads to draw the picture only, and + // the platform's own toggle is what actually grows the window to + // the monitor. The two are asked to agree rather than one being + // derived from the other, because a compositor keybind can move + // `window.is_fullscreen()` without this action ever firing. + ActionId::Fullscreen => { + self.player_fullscreen = !self.player_fullscreen; + if window.is_fullscreen() != self.player_fullscreen { + window.toggle_fullscreen(); + } + } // Nothing to cancel while nothing is exporting; the export guard in // the key handler is what answers this one while there is. ActionId::CancelExport => {} diff --git a/crates/app/src/render.rs b/crates/app/src/render.rs index a2e0105..b466311 100644 --- a/crates/app/src/render.rs +++ b/crates/app/src/render.rs @@ -3,6 +3,92 @@ use crate::*; +/// Whether a stroke leaves player fullscreen. Bare escape does, the same +/// stroke every card and menu in this window answers to -- and it is +/// answered *first*: the picture-only layout is the chrome itself missing, +/// not a card drawn over it, so it goes before a menu close or a preview +/// close gets a look at the same key. See the call site in [`Player::render`] +/// for the deliberate order this buys with a preview open underneath. +pub(crate) fn escape_leaves_player_fullscreen(key: &str, ctrl: bool, player_fullscreen: bool) -> bool { + key == ESCAPE && !ctrl && player_fullscreen +} + +impl Player { + /// The picture region alone: the image, the subtitle cue plate, the + /// preview badge and the three transient bars over its bottom edge. + /// Its own method so player fullscreen ([`Player::act`]) can stand it up + /// as the window's only child without a second copy of what it draws. + fn picture_area( + &mut self, + position: f64, + window: &mut Window, + cx: &mut Context, + ) -> impl IntoElement { + div() + .flex_1() + .min_h(px(0.)) + .overflow_hidden() + // The bed the cue plate is placed against: it hangs off the + // bottom of the picture region, which is the one box that is the + // picture and nothing else. + .relative() + .flex() + .justify_center() + .items_center() + .bg(rgb(BG_CANVAS())) + .children( + self.image + .clone() + .map(|i| { + img(i) + .size_full() + .object_fit(gpui::ObjectFit::Contain) + .into_any_element() + }) + // With no file open the letterbox is the whole region, + // and a black rectangle says only that something is + // broken -- so it says what it wants instead. The window + // is already the drop target. + .or_else(|| { + (self.active_session().is_none()) + .then(|| empty_hint().into_any_element()) + }), + ) + // After the picture, so the plate is drawn over it rather than + // under. + .children(self.subtitle_overlay(position, window)) + .children(self.preview_badge(cx)) + // The three transient lines hang off the bottom of the picture + // rather than taking a row of the column: a notice that arrives + // must not push the transport, the toolbar and the timeline down + // by its own height -- which is a control moving with state, on + // every control below it at once. + .child( + div() + .absolute() + .bottom_0() + .left_0() + .right_0() + .flex() + .flex_col() + .gap(px(2.)) + .children(self.import_bar(cx)) + .children(self.seek_bar()) + .children(self.notice_bar(cx)) + // How tall the lot came out, for the cue plate above to + // step over ([`sub_bottom`]) -- the bars are over the + // picture, and a message drawn across the line being + // read loses both of them. Zero with no bar up, since + // this box is then empty. + .child(height_probe(self.notice_h.clone())), + ) + // The preview's scrub bar, drawn LAST: the notice box above shares + // its bottom edge, and a bar under the "PREVIEWING ..." plate was + // invisible for exactly the moment it matters. + .children(self.preview_scrub_bar(cx)) + } +} + impl Render for Player { fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { // A file that has just been opened sits on its first frame with the @@ -37,6 +123,16 @@ impl Render for Player { window.set_window_title(&title); self.titled = title; } + // A compositor keybind (the window manager's own fullscreen, not + // ours) can drop `window.is_fullscreen()` without ever going through + // [`Player::act`] -- the picture-only layout below must not survive + // that on its own, or the chrome never comes back. Only the *leaving* + // direction is reconciled here: the platform going fullscreen behind + // our back is not this editor asking for the picture-only layout, so + // it is left alone rather than guessed at. + if self.player_fullscreen && !window.is_fullscreen() { + self.player_fullscreen = false; + } // No shadow flag: the session is the only truth about play state, and // [`Player::transport`] is the one place it is read. let state = self.transport(); @@ -477,6 +573,21 @@ impl Render for Player { // the keys before anything under it does: ↑↓ walk it, enter // takes the row, and escape falls through to the close below -- // the same three strokes every list in this editor answers. + // The picture-only layout is the outermost thing on screen -- + // it is the chrome itself that is missing, not a card drawn + // over it -- so its own escape is answered before any menu or + // preview below gets a look at the stroke. Deliberate order: + // with a preview open *and* the player fullscreen, the first + // Escape only leaves fullscreen (the preview keeps playing, + // now behind the chrome again), and it takes a second Escape + // to stop the preview -- one stroke, one effect, same as + // every other card in this chain. + if escape_leaves_player_fullscreen(key, ctrl, this.player_fullscreen) { + this.player_fullscreen = false; + window.toggle_fullscreen(); + cx.notify(); + return; + } if let Some(mut picker) = this.picker { let rows = this.choices(picker.of); if !rows.is_empty() && matches!(key, "up" | "down" | "enter") { @@ -598,113 +709,53 @@ impl Render for Player { // it. Nothing here moves when the state changes -- the regions are // fixed and the panels keep their room whether or not anything is // open in them. - .child(self.topbar(window, cx)) - .child( - div() - .flex_1() - .min_h(px(0.)) - .flex() - .child(self.library( - self.split_px(Split::Library, window.viewport_size()), - cx, - )) - // The seams, one per pair of regions: what a hand drags to - // give a panel more room and its neighbour less - // ([`divider`]). - .child(divider(Split::Library, cx)) + // Player fullscreen: the picture and nothing else -- what + // `Fullscreen` gives every consumer video player. The four-region + // layout is skipped rather than hidden under it (a hidden library + // and inspector would still lay out and take the split's own + // room), and the picture div itself is untouched either way -- + // [`Player::picture_area`] is the same call in both arms. + .when(self.player_fullscreen, |d| { + d.child(self.picture_area(position, window, cx)) + }) + .when(!self.player_fullscreen, |d| { + d.child(self.topbar(window, cx)) .child( div() .flex_1() - .min_w(px(0.)) + .min_h(px(0.)) .flex() - .flex_col() + .child(self.library( + self.split_px(Split::Library, window.viewport_size()), + cx, + )) + // The seams, one per pair of regions: what a hand + // drags to give a panel more room and its + // neighbour less ([`divider`]). + .child(divider(Split::Library, cx)) .child( div() .flex_1() - .min_h(px(0.)) - .overflow_hidden() - // The bed the cue plate is placed against: - // it hangs off the bottom of the picture - // region, which is the one box that is the - // picture and nothing else. - .relative() + .min_w(px(0.)) .flex() - .justify_center() - .items_center() - .bg(rgb(BG_CANVAS())) - .children( - self.image - .clone() - .map(|i| { - img(i) - .size_full() - .object_fit(gpui::ObjectFit::Contain) - .into_any_element() - }) - // With no file open the letterbox - // is the whole region, and a black - // rectangle says only that - // something is broken -- so it says - // what it wants instead. The window - // is already the drop target. - .or_else(|| { - (self.active_session().is_none()) - .then(|| empty_hint().into_any_element()) - }), - ) - // After the picture, so the plate is drawn - // over it rather than under. - .children(self.subtitle_overlay(position, window)) - .children(self.preview_badge(cx)) - // The preview's own scrub bar, low over - // the picture the badge is drawn over the - // top of: drawn after both, so it sits - // above the subtitle plate and never - // under the badge's banner. - .children(self.preview_scrub_bar(cx)) - // The three transient lines hang off the - // bottom of the picture rather than taking - // a row of the column: a notice that - // arrives must not push the transport, the - // toolbar and the timeline down by its own - // height -- which is a control moving with - // state, on every control below it at once. - .child( - div() - .absolute() - .bottom_0() - .left_0() - .right_0() - .flex() - .flex_col() - .gap(px(2.)) - .children(self.import_bar(cx)) - .children(self.seek_bar()) - .children(self.notice_bar(cx)) - // How tall the lot came out, for the - // cue plate above to step over - // ([`sub_bottom`]) -- the bars are - // over the picture, and a message - // drawn across the line being read - // loses both of them. Zero with no - // bar up, since this box is then - // empty. - .child(height_probe(self.notice_h.clone())), - ), + .flex_col() + .child(self.picture_area(position, window, cx)) + .child(self.transport_bar(state, window.viewport_size(), cx)), ) - .child(self.transport_bar(state, window.viewport_size(), cx)), + .child(divider(Split::Inspector, cx)) + // The settings cards live in here rather than over + // the timeline: adjusting a clip must not hide the + // clip. + .child(self.inspector(window.viewport_size(), cx)), ) - .child(divider(Split::Inspector, cx)) - // The settings cards live in here rather than over the - // timeline: adjusting a clip must not hide the clip. - .child(self.inspector(window.viewport_size(), cx)), - ) - // Above the toolbar rather than under it: the toolbar is a fixed - // strip belonging to the timeline, so the pair moves as one and the - // edge the hand is pulling is the edge under the pointer. - .child(divider(Split::Timeline, cx)) - .child(self.toolbar(cx)) - .child(self.timeline(position, state, window.viewport_size(), cx)) + // Above the toolbar rather than under it: the toolbar is + // a fixed strip belonging to the timeline, so the pair + // moves as one and the edge the hand is pulling is the + // edge under the pointer. + .child(divider(Split::Timeline, cx)) + .child(self.toolbar(cx)) + .child(self.timeline(position, state, window.viewport_size(), cx)) + }) // Over the region they were opened on, and under the modal cards: // they are only ever up while none of those is (`modal`). .children(self.context_card(window.viewport_size(), cx)) diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index 43eb649..12ba0df 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -3,6 +3,17 @@ use super::*; +#[test] +fn a_bare_escape_leaves_player_fullscreen_before_anything_under_it() { + // Fires while the picture-only layout is up, on the same bare escape + // every menu and preview close on -- and only that key: a chord, or an + // escape while not fullscreen, means nothing to it. + assert!(escape_leaves_player_fullscreen("escape", false, true)); + assert!(!escape_leaves_player_fullscreen("escape", false, false)); + assert!(!escape_leaves_player_fullscreen("escape", true, true)); + assert!(!escape_leaves_player_fullscreen("q", false, true)); +} + #[test] fn only_a_chord_gets_out_of_an_export() { use keymap::ActionId; diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index 73f7363..72eabe4 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -25,6 +25,7 @@ use super::{ bitrate_detail, bitrate_refusal, can_add, cancels_export, clipboard_after_remove, color_snap, commit_mbps, containers, enable, envelope, eq_card_w, eq_freq, eq_freq_label, eq_spectrum, eq_x, eq_y, + escape_leaves_player_fullscreen, estimated_bytes, export_path, export_settings, format_key, format_line, format_refusal, fps_choices, fps_label, frac_along, frac_down, frame_at, frame_rate_ladder, histogram, diff --git a/crates/app/src/ui/toolbar.rs b/crates/app/src/ui/toolbar.rs index 9e5ade7..ca45f5e 100644 --- a/crates/app/src/ui/toolbar.rs +++ b/crates/app/src/ui/toolbar.rs @@ -49,9 +49,13 @@ impl Player { /// write a file on the right. Export is the one accented button in the /// window -- the primary action of an editor, where every consumer editor /// puts it -- and it keeps its rect while it is a Cancel. - pub(crate) fn topbar(&self, window: &mut Window, cx: &mut Context) -> impl IntoElement { + pub(crate) fn topbar(&self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { let exporting = self.exporting().is_some(); - let fullscreen = window.is_fullscreen(); + // This button's own row is part of the chrome player fullscreen + // hides, so once it reads true the button is already off screen -- + // F11 or Escape is what a person actually leaves by, which is why the + // hint below names both. + let fullscreen = self.player_fullscreen; div() .flex_none() .h(px(TOPBAR_H)) @@ -89,7 +93,7 @@ impl Player { true => "Exit fullscreen", false => "Fullscreen", }, - "fills the screen with the window, or gives it back", + "fills the screen with the picture; F11 or Escape gives it back", ActionId::Fullscreen, cx.listener(|this, _: &ClickEvent, window, cx| { this.act(ActionId::Fullscreen, window, cx)