Fullscreen fills the screen with the player, not the app
Browse files at this commit- feat
- fullscreen fills the screen with the player, not the app
6 changed files +191 -104
- crates/app/src/main.rs +10 -0
- crates/app/src/player/actions.rs +14 -4
- crates/app/src/render.rs +148 -97
- crates/app/src/tests/cards.rs +11 -0
- crates/app/src/tests/mod.rs +1 -0
- crates/app/src/ui/toolbar.rs +7 -3
crates/app/src/main.rsmodified+10 -0
| @@ -30,6 +30,7 @@ pub(crate) use interact::*; | ||
| 30 | 30 | pub(crate) use layout::*; |
| 31 | 31 | pub(crate) use library_meta::*; |
| 32 | 32 | pub(crate) use menus::*; |
| 33 | +pub(crate) use render::escape_leaves_player_fullscreen; | |
| 33 | 34 | pub(crate) use notices::*; |
| 34 | 35 | pub(crate) use oracle::*; |
| 35 | 36 | pub(crate) use subs::*; |
| @@ -93,6 +94,14 @@ struct Player { | ||
| 93 | 94 | /// ([`Player::open_preview`] pauses it so the two sounds never overlap): |
| 94 | 95 | /// what [`Player::close_preview`] resumes, and only then. |
| 95 | 96 | preview_playing: bool, |
| 97 | + /// The picture alone, filling the window -- what `Fullscreen` gives every | |
| 98 | + /// consumer video player, and not what gpui's own `toggle_fullscreen` | |
| 99 | + /// gives on its own (the OS window, chrome and all). Kept apart from | |
| 100 | + /// `window.is_fullscreen()` because the two can fall out of step: a | |
| 101 | + /// compositor keybind changes the window's without this flag hearing | |
| 102 | + /// about it, so [`Player::act`] reconciles them rather than trusting | |
| 103 | + /// either alone. | |
| 104 | + player_fullscreen: bool, | |
| 96 | 105 | /// Timeline seconds -> frame index, so the clock can be compared to what |
| 97 | 106 | /// the decoder hands over. |
| 98 | 107 | fps: f64, |
| @@ -722,6 +731,7 @@ fn main() { | ||
| 722 | 731 | pending_settings: (None, None, None), |
| 723 | 732 | preview_session: None, |
| 724 | 733 | preview_playing: false, |
| 734 | + player_fullscreen: false, | |
| 725 | 735 | // Full and unmuted, which is what the session it was just |
| 726 | 736 | // handed is already set to: nothing to push at startup. |
| 727 | 737 | volume: Volume::default(), |
crates/app/src/player/actions.rsmodified+14 -4
| @@ -98,10 +98,20 @@ impl Player { | ||
| 98 | 98 | // At the window's corner, since a stroke names no place -- and |
| 99 | 99 | // [`menu_at`] keeps it on screen from there. |
| 100 | 100 | ActionId::Theme => self.open_picker(Pick::Theme, Point::default(), cx), |
| 101 | - // The platform's own toggle (gpui::Window::toggle_fullscreen); the | |
| 102 | - // window reports its own new state back through `is_fullscreen`, | |
| 103 | - // there is no local bool to keep in step with it. | |
| 104 | - ActionId::Fullscreen => window.toggle_fullscreen(), | |
| 101 | + // Not the window's own toggle alone -- every consumer video | |
| 102 | + // player fullscreens the *picture*, chrome and all, not just the | |
| 103 | + // OS frame around it -- so this flips both: `player_fullscreen` | |
| 104 | + // is what [`crate::render`] reads to draw the picture only, and | |
| 105 | + // the platform's own toggle is what actually grows the window to | |
| 106 | + // the monitor. The two are asked to agree rather than one being | |
| 107 | + // derived from the other, because a compositor keybind can move | |
| 108 | + // `window.is_fullscreen()` without this action ever firing. | |
| 109 | + ActionId::Fullscreen => { | |
| 110 | + self.player_fullscreen = !self.player_fullscreen; | |
| 111 | + if window.is_fullscreen() != self.player_fullscreen { | |
| 112 | + window.toggle_fullscreen(); | |
| 113 | + } | |
| 114 | + } | |
| 105 | 115 | // Nothing to cancel while nothing is exporting; the export guard in |
| 106 | 116 | // the key handler is what answers this one while there is. |
| 107 | 117 | ActionId::CancelExport => {} |
crates/app/src/render.rsmodified+148 -97
| @@ -3,6 +3,92 @@ | ||
| 3 | 3 | |
| 4 | 4 | use crate::*; |
| 5 | 5 | |
| 6 | +/// Whether a stroke leaves player fullscreen. Bare escape does, the same | |
| 7 | +/// stroke every card and menu in this window answers to -- and it is | |
| 8 | +/// answered *first*: the picture-only layout is the chrome itself missing, | |
| 9 | +/// not a card drawn over it, so it goes before a menu close or a preview | |
| 10 | +/// close gets a look at the same key. See the call site in [`Player::render`] | |
| 11 | +/// for the deliberate order this buys with a preview open underneath. | |
| 12 | +pub(crate) fn escape_leaves_player_fullscreen(key: &str, ctrl: bool, player_fullscreen: bool) -> bool { | |
| 13 | + key == ESCAPE && !ctrl && player_fullscreen | |
| 14 | +} | |
| 15 | + | |
| 16 | +impl Player { | |
| 17 | + /// The picture region alone: the image, the subtitle cue plate, the | |
| 18 | + /// preview badge and the three transient bars over its bottom edge. | |
| 19 | + /// Its own method so player fullscreen ([`Player::act`]) can stand it up | |
| 20 | + /// as the window's only child without a second copy of what it draws. | |
| 21 | + fn picture_area( | |
| 22 | + &mut self, | |
| 23 | + position: f64, | |
| 24 | + window: &mut Window, | |
| 25 | + cx: &mut Context<Self>, | |
| 26 | + ) -> impl IntoElement { | |
| 27 | + div() | |
| 28 | + .flex_1() | |
| 29 | + .min_h(px(0.)) | |
| 30 | + .overflow_hidden() | |
| 31 | + // The bed the cue plate is placed against: it hangs off the | |
| 32 | + // bottom of the picture region, which is the one box that is the | |
| 33 | + // picture and nothing else. | |
| 34 | + .relative() | |
| 35 | + .flex() | |
| 36 | + .justify_center() | |
| 37 | + .items_center() | |
| 38 | + .bg(rgb(BG_CANVAS())) | |
| 39 | + .children( | |
| 40 | + self.image | |
| 41 | + .clone() | |
| 42 | + .map(|i| { | |
| 43 | + img(i) | |
| 44 | + .size_full() | |
| 45 | + .object_fit(gpui::ObjectFit::Contain) | |
| 46 | + .into_any_element() | |
| 47 | + }) | |
| 48 | + // With no file open the letterbox is the whole region, | |
| 49 | + // and a black rectangle says only that something is | |
| 50 | + // broken -- so it says what it wants instead. The window | |
| 51 | + // is already the drop target. | |
| 52 | + .or_else(|| { | |
| 53 | + (self.active_session().is_none()) | |
| 54 | + .then(|| empty_hint().into_any_element()) | |
| 55 | + }), | |
| 56 | + ) | |
| 57 | + // After the picture, so the plate is drawn over it rather than | |
| 58 | + // under. | |
| 59 | + .children(self.subtitle_overlay(position, window)) | |
| 60 | + .children(self.preview_badge(cx)) | |
| 61 | + // The three transient lines hang off the bottom of the picture | |
| 62 | + // rather than taking a row of the column: a notice that arrives | |
| 63 | + // must not push the transport, the toolbar and the timeline down | |
| 64 | + // by its own height -- which is a control moving with state, on | |
| 65 | + // every control below it at once. | |
| 66 | + .child( | |
| 67 | + div() | |
| 68 | + .absolute() | |
| 69 | + .bottom_0() | |
| 70 | + .left_0() | |
| 71 | + .right_0() | |
| 72 | + .flex() | |
| 73 | + .flex_col() | |
| 74 | + .gap(px(2.)) | |
| 75 | + .children(self.import_bar(cx)) | |
| 76 | + .children(self.seek_bar()) | |
| 77 | + .children(self.notice_bar(cx)) | |
| 78 | + // How tall the lot came out, for the cue plate above to | |
| 79 | + // step over ([`sub_bottom`]) -- the bars are over the | |
| 80 | + // picture, and a message drawn across the line being | |
| 81 | + // read loses both of them. Zero with no bar up, since | |
| 82 | + // this box is then empty. | |
| 83 | + .child(height_probe(self.notice_h.clone())), | |
| 84 | + ) | |
| 85 | + // The preview's scrub bar, drawn LAST: the notice box above shares | |
| 86 | + // its bottom edge, and a bar under the "PREVIEWING ..." plate was | |
| 87 | + // invisible for exactly the moment it matters. | |
| 88 | + .children(self.preview_scrub_bar(cx)) | |
| 89 | + } | |
| 90 | +} | |
| 91 | + | |
| 6 | 92 | impl Render for Player { |
| 7 | 93 | fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { |
| 8 | 94 | // A file that has just been opened sits on its first frame with the |
| @@ -37,6 +123,16 @@ impl Render for Player { | ||
| 37 | 123 | window.set_window_title(&title); |
| 38 | 124 | self.titled = title; |
| 39 | 125 | } |
| 126 | + // A compositor keybind (the window manager's own fullscreen, not | |
| 127 | + // ours) can drop `window.is_fullscreen()` without ever going through | |
| 128 | + // [`Player::act`] -- the picture-only layout below must not survive | |
| 129 | + // that on its own, or the chrome never comes back. Only the *leaving* | |
| 130 | + // direction is reconciled here: the platform going fullscreen behind | |
| 131 | + // our back is not this editor asking for the picture-only layout, so | |
| 132 | + // it is left alone rather than guessed at. | |
| 133 | + if self.player_fullscreen && !window.is_fullscreen() { | |
| 134 | + self.player_fullscreen = false; | |
| 135 | + } | |
| 40 | 136 | // No shadow flag: the session is the only truth about play state, and |
| 41 | 137 | // [`Player::transport`] is the one place it is read. |
| 42 | 138 | let state = self.transport(); |
| @@ -477,6 +573,21 @@ impl Render for Player { | ||
| 477 | 573 | // the keys before anything under it does: ↑↓ walk it, enter |
| 478 | 574 | // takes the row, and escape falls through to the close below -- |
| 479 | 575 | // the same three strokes every list in this editor answers. |
| 576 | + // The picture-only layout is the outermost thing on screen -- | |
| 577 | + // it is the chrome itself that is missing, not a card drawn | |
| 578 | + // over it -- so its own escape is answered before any menu or | |
| 579 | + // preview below gets a look at the stroke. Deliberate order: | |
| 580 | + // with a preview open *and* the player fullscreen, the first | |
| 581 | + // Escape only leaves fullscreen (the preview keeps playing, | |
| 582 | + // now behind the chrome again), and it takes a second Escape | |
| 583 | + // to stop the preview -- one stroke, one effect, same as | |
| 584 | + // every other card in this chain. | |
| 585 | + if escape_leaves_player_fullscreen(key, ctrl, this.player_fullscreen) { | |
| 586 | + this.player_fullscreen = false; | |
| 587 | + window.toggle_fullscreen(); | |
| 588 | + cx.notify(); | |
| 589 | + return; | |
| 590 | + } | |
| 480 | 591 | if let Some(mut picker) = this.picker { |
| 481 | 592 | let rows = this.choices(picker.of); |
| 482 | 593 | if !rows.is_empty() && matches!(key, "up" | "down" | "enter") { |
| @@ -598,113 +709,53 @@ impl Render for Player { | ||
| 598 | 709 | // it. Nothing here moves when the state changes -- the regions are |
| 599 | 710 | // fixed and the panels keep their room whether or not anything is |
| 600 | 711 | // open in them. |
| 601 | - .child(self.topbar(window, cx)) | |
| 602 | - .child( | |
| 603 | - div() | |
| 604 | - .flex_1() | |
| 605 | - .min_h(px(0.)) | |
| 606 | - .flex() | |
| 607 | - .child(self.library( | |
| 608 | - self.split_px(Split::Library, window.viewport_size()), | |
| 609 | - cx, | |
| 610 | - )) | |
| 611 | - // The seams, one per pair of regions: what a hand drags to | |
| 612 | - // give a panel more room and its neighbour less | |
| 613 | - // ([`divider`]). | |
| 614 | - .child(divider(Split::Library, cx)) | |
| 712 | + // Player fullscreen: the picture and nothing else -- what | |
| 713 | + // `Fullscreen` gives every consumer video player. The four-region | |
| 714 | + // layout is skipped rather than hidden under it (a hidden library | |
| 715 | + // and inspector would still lay out and take the split's own | |
| 716 | + // room), and the picture div itself is untouched either way -- | |
| 717 | + // [`Player::picture_area`] is the same call in both arms. | |
| 718 | + .when(self.player_fullscreen, |d| { | |
| 719 | + d.child(self.picture_area(position, window, cx)) | |
| 720 | + }) | |
| 721 | + .when(!self.player_fullscreen, |d| { | |
| 722 | + d.child(self.topbar(window, cx)) | |
| 615 | 723 | .child( |
| 616 | 724 | div() |
| 617 | 725 | .flex_1() |
| 618 | - .min_w(px(0.)) | |
| 726 | + .min_h(px(0.)) | |
| 619 | 727 | .flex() |
| 620 | - .flex_col() | |
| 728 | + .child(self.library( | |
| 729 | + self.split_px(Split::Library, window.viewport_size()), | |
| 730 | + cx, | |
| 731 | + )) | |
| 732 | + // The seams, one per pair of regions: what a hand | |
| 733 | + // drags to give a panel more room and its | |
| 734 | + // neighbour less ([`divider`]). | |
| 735 | + .child(divider(Split::Library, cx)) | |
| 621 | 736 | .child( |
| 622 | 737 | div() |
| 623 | 738 | .flex_1() |
| 624 | - .min_h(px(0.)) | |
| 625 | - .overflow_hidden() | |
| 626 | - // The bed the cue plate is placed against: | |
| 627 | - // it hangs off the bottom of the picture | |
| 628 | - // region, which is the one box that is the | |
| 629 | - // picture and nothing else. | |
| 630 | - .relative() | |
| 739 | + .min_w(px(0.)) | |
| 631 | 740 | .flex() |
| 632 | - .justify_center() | |
| 633 | - .items_center() | |
| 634 | - .bg(rgb(BG_CANVAS())) | |
| 635 | - .children( | |
| 636 | - self.image | |
| 637 | - .clone() | |
| 638 | - .map(|i| { | |
| 639 | - img(i) | |
| 640 | - .size_full() | |
| 641 | - .object_fit(gpui::ObjectFit::Contain) | |
| 642 | - .into_any_element() | |
| 643 | - }) | |
| 644 | - // With no file open the letterbox | |
| 645 | - // is the whole region, and a black | |
| 646 | - // rectangle says only that | |
| 647 | - // something is broken -- so it says | |
| 648 | - // what it wants instead. The window | |
| 649 | - // is already the drop target. | |
| 650 | - .or_else(|| { | |
| 651 | - (self.active_session().is_none()) | |
| 652 | - .then(|| empty_hint().into_any_element()) | |
| 653 | - }), | |
| 654 | - ) | |
| 655 | - // After the picture, so the plate is drawn | |
| 656 | - // over it rather than under. | |
| 657 | - .children(self.subtitle_overlay(position, window)) | |
| 658 | - .children(self.preview_badge(cx)) | |
| 659 | - // The preview's own scrub bar, low over | |
| 660 | - // the picture the badge is drawn over the | |
| 661 | - // top of: drawn after both, so it sits | |
| 662 | - // above the subtitle plate and never | |
| 663 | - // under the badge's banner. | |
| 664 | - .children(self.preview_scrub_bar(cx)) | |
| 665 | - // The three transient lines hang off the | |
| 666 | - // bottom of the picture rather than taking | |
| 667 | - // a row of the column: a notice that | |
| 668 | - // arrives must not push the transport, the | |
| 669 | - // toolbar and the timeline down by its own | |
| 670 | - // height -- which is a control moving with | |
| 671 | - // state, on every control below it at once. | |
| 672 | - .child( | |
| 673 | - div() | |
| 674 | - .absolute() | |
| 675 | - .bottom_0() | |
| 676 | - .left_0() | |
| 677 | - .right_0() | |
| 678 | - .flex() | |
| 679 | - .flex_col() | |
| 680 | - .gap(px(2.)) | |
| 681 | - .children(self.import_bar(cx)) | |
| 682 | - .children(self.seek_bar()) | |
| 683 | - .children(self.notice_bar(cx)) | |
| 684 | - // How tall the lot came out, for the | |
| 685 | - // cue plate above to step over | |
| 686 | - // ([`sub_bottom`]) -- the bars are | |
| 687 | - // over the picture, and a message | |
| 688 | - // drawn across the line being read | |
| 689 | - // loses both of them. Zero with no | |
| 690 | - // bar up, since this box is then | |
| 691 | - // empty. | |
| 692 | - .child(height_probe(self.notice_h.clone())), | |
| 693 | - ), | |
| 741 | + .flex_col() | |
| 742 | + .child(self.picture_area(position, window, cx)) | |
| 743 | + .child(self.transport_bar(state, window.viewport_size(), cx)), | |
| 694 | 744 | ) |
| 695 | - .child(self.transport_bar(state, window.viewport_size(), cx)), | |
| 745 | + .child(divider(Split::Inspector, cx)) | |
| 746 | + // The settings cards live in here rather than over | |
| 747 | + // the timeline: adjusting a clip must not hide the | |
| 748 | + // clip. | |
| 749 | + .child(self.inspector(window.viewport_size(), cx)), | |
| 696 | 750 | ) |
| 697 | - .child(divider(Split::Inspector, cx)) | |
| 698 | - // The settings cards live in here rather than over the | |
| 699 | - // timeline: adjusting a clip must not hide the clip. | |
| 700 | - .child(self.inspector(window.viewport_size(), cx)), | |
| 701 | - ) | |
| 702 | - // Above the toolbar rather than under it: the toolbar is a fixed | |
| 703 | - // strip belonging to the timeline, so the pair moves as one and the | |
| 704 | - // edge the hand is pulling is the edge under the pointer. | |
| 705 | - .child(divider(Split::Timeline, cx)) | |
| 706 | - .child(self.toolbar(cx)) | |
| 707 | - .child(self.timeline(position, state, window.viewport_size(), cx)) | |
| 751 | + // Above the toolbar rather than under it: the toolbar is | |
| 752 | + // a fixed strip belonging to the timeline, so the pair | |
| 753 | + // moves as one and the edge the hand is pulling is the | |
| 754 | + // edge under the pointer. | |
| 755 | + .child(divider(Split::Timeline, cx)) | |
| 756 | + .child(self.toolbar(cx)) | |
| 757 | + .child(self.timeline(position, state, window.viewport_size(), cx)) | |
| 758 | + }) | |
| 708 | 759 | // Over the region they were opened on, and under the modal cards: |
| 709 | 760 | // they are only ever up while none of those is (`modal`). |
| 710 | 761 | .children(self.context_card(window.viewport_size(), cx)) |
crates/app/src/tests/cards.rsmodified+11 -0
| @@ -3,6 +3,17 @@ | ||
| 3 | 3 | |
| 4 | 4 | use super::*; |
| 5 | 5 | |
| 6 | +#[test] | |
| 7 | +fn a_bare_escape_leaves_player_fullscreen_before_anything_under_it() { | |
| 8 | + // Fires while the picture-only layout is up, on the same bare escape | |
| 9 | + // every menu and preview close on -- and only that key: a chord, or an | |
| 10 | + // escape while not fullscreen, means nothing to it. | |
| 11 | + assert!(escape_leaves_player_fullscreen("escape", false, true)); | |
| 12 | + assert!(!escape_leaves_player_fullscreen("escape", false, false)); | |
| 13 | + assert!(!escape_leaves_player_fullscreen("escape", true, true)); | |
| 14 | + assert!(!escape_leaves_player_fullscreen("q", false, true)); | |
| 15 | +} | |
| 16 | + | |
| 6 | 17 | #[test] |
| 7 | 18 | fn only_a_chord_gets_out_of_an_export() { |
| 8 | 19 | use keymap::ActionId; |
crates/app/src/tests/mod.rsmodified+1 -0
| @@ -25,6 +25,7 @@ use super::{ | ||
| 25 | 25 | bitrate_detail, bitrate_refusal, can_add, cancels_export, clipboard_after_remove, color_snap, commit_mbps, |
| 26 | 26 | containers, |
| 27 | 27 | enable, envelope, eq_card_w, eq_freq, eq_freq_label, eq_spectrum, eq_x, eq_y, |
| 28 | + escape_leaves_player_fullscreen, | |
| 28 | 29 | estimated_bytes, export_path, export_settings, format_key, |
| 29 | 30 | format_line, format_refusal, fps_choices, fps_label, frac_along, frac_down, frame_at, |
| 30 | 31 | frame_rate_ladder, histogram, |
crates/app/src/ui/toolbar.rsmodified+7 -3
| @@ -49,9 +49,13 @@ impl Player { | ||
| 49 | 49 | /// write a file on the right. Export is the one accented button in the |
| 50 | 50 | /// window -- the primary action of an editor, where every consumer editor |
| 51 | 51 | /// puts it -- and it keeps its rect while it is a Cancel. |
| 52 | - pub(crate) fn topbar(&self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { | |
| 52 | + pub(crate) fn topbar(&self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { | |
| 53 | 53 | let exporting = self.exporting().is_some(); |
| 54 | - let fullscreen = window.is_fullscreen(); | |
| 54 | + // This button's own row is part of the chrome player fullscreen | |
| 55 | + // hides, so once it reads true the button is already off screen -- | |
| 56 | + // F11 or Escape is what a person actually leaves by, which is why the | |
| 57 | + // hint below names both. | |
| 58 | + let fullscreen = self.player_fullscreen; | |
| 55 | 59 | div() |
| 56 | 60 | .flex_none() |
| 57 | 61 | .h(px(TOPBAR_H)) |
| @@ -89,7 +93,7 @@ impl Player { | ||
| 89 | 93 | true => "Exit fullscreen", |
| 90 | 94 | false => "Fullscreen", |
| 91 | 95 | }, |
| 92 | - "fills the screen with the window, or gives it back", | |
| 96 | + "fills the screen with the picture; F11 or Escape gives it back", | |
| 93 | 97 | ActionId::Fullscreen, |
| 94 | 98 | cx.listener(|this, _: &ClickEvent, window, cx| { |
| 95 | 99 | this.act(ActionId::Fullscreen, window, cx) |