The player goes fullscreen from the toolbar or F11
Browse files at this commit1ac24b82f1b5ca1229d7b772500d491761fe0d61Parent: 31449fc- feat
- the player goes fullscreen from the toolbar or F11
7 changed files +57 -15
- crates/app/src/keymap.rs +15 -2
- crates/app/src/oracle.rs +3 -1
- crates/app/src/player/actions.rs +5 -1
- crates/app/src/render.rs +3 -3
- crates/app/src/tests/editing.rs +7 -3
- crates/app/src/ui/overlays.rs +4 -4
- crates/app/src/ui/toolbar.rs +20 -1
crates/app/src/keymap.rsmodified+15 -2
| @@ -134,6 +134,9 @@ actions! { | |||
| 134 | /// toolbar's Theme button. It was a build feature once, which made it a | 134 | /// toolbar's Theme button. It was a build feature once, which made it a |
| 135 | /// choice only whoever compiled the binary could make. | 135 | /// choice only whoever compiled the binary could make. |
| 136 | Theme, | 136 | Theme, |
| 137 | + /// The whole window, borderless over the screen: a player's own control, | ||
| 138 | + /// on the platform's own toggle ([`gpui::Window::toggle_fullscreen`]). | ||
| 139 | + Fullscreen, | ||
| 137 | CancelExport, | 140 | CancelExport, |
| 138 | /// Opens the actions card -- the list every other action is on. A door of | 141 | /// Opens the actions card -- the list every other action is on. A door of |
| 139 | /// its own, because a card reachable only by a button in the panel is one a | 142 | /// its own, because a card reachable only by a button in the panel is one a |
| @@ -197,6 +200,7 @@ impl ActionId { | |||
| 197 | ActionId::ToggleProxies => "Proxies on / off for the picture", | 200 | ActionId::ToggleProxies => "Proxies on / off for the picture", |
| 198 | ActionId::ToggleAutoProxies => "Make proxies on import: on / off", | 201 | ActionId::ToggleAutoProxies => "Make proxies on import: on / off", |
| 199 | ActionId::Theme => "Theme: the window's colours…", | 202 | ActionId::Theme => "Theme: the window's colours…", |
| 203 | + ActionId::Fullscreen => "Fullscreen on / off", | ||
| 200 | ActionId::CancelExport => "Cancel export", | 204 | ActionId::CancelExport => "Cancel export", |
| 201 | ActionId::ShowActions => "All actions and their keys…", | 205 | ActionId::ShowActions => "All actions and their keys…", |
| 202 | } | 206 | } |
| @@ -255,6 +259,7 @@ impl ActionId { | |||
| 255 | ActionId::ToggleProxies => "toggle-proxies", | 259 | ActionId::ToggleProxies => "toggle-proxies", |
| 256 | ActionId::ToggleAutoProxies => "toggle-auto-proxies", | 260 | ActionId::ToggleAutoProxies => "toggle-auto-proxies", |
| 257 | ActionId::Theme => "theme", | 261 | ActionId::Theme => "theme", |
| 262 | + ActionId::Fullscreen => "fullscreen", | ||
| 258 | ActionId::CancelExport => "cancel-export", | 263 | ActionId::CancelExport => "cancel-export", |
| 259 | ActionId::ShowActions => "show-actions", | 264 | ActionId::ShowActions => "show-actions", |
| 260 | } | 265 | } |
| @@ -317,7 +322,10 @@ impl ActionId { | |||
| 317 | | ActionId::ToggleAutoProxies | 322 | | ActionId::ToggleAutoProxies |
| 318 | // ...and what the whole window is painted in: it edits nothing at | 323 | // ...and what the whole window is painted in: it edits nothing at |
| 319 | // all, it is what one is looking *with*. | 324 | // all, it is what one is looking *with*. |
| 320 | - | ActionId::Theme => Category::View, | 325 | + | ActionId::Theme |
| 326 | + // ...and whether that window fills the screen: a way of looking, | ||
| 327 | + // same as the zoom and the theme beside it. | ||
| 328 | + | ActionId::Fullscreen => Category::View, | ||
| 321 | ActionId::Cut | 329 | ActionId::Cut |
| 322 | | ActionId::Regroup | 330 | | ActionId::Regroup |
| 323 | | ActionId::Detach | 331 | | ActionId::Detach |
| @@ -884,6 +892,10 @@ impl Keymap { | |||
| 884 | // it is a preference set once, not a stroke wanted under a hand | 892 | // it is a preference set once, not a stroke wanted under a hand |
| 885 | // that is editing. | 893 | // that is editing. |
| 886 | b(ActionId::Theme, "h", true), | 894 | b(ActionId::Theme, "h", true), |
| 895 | + // Every other player's key for it, and free here: nothing in | ||
| 896 | + // this table answers to "f11" (gpui lowercases the keysym | ||
| 897 | + // name it gets from xkb, same as "f1" below). | ||
| 898 | + b(ActionId::Fullscreen, "f11", false), | ||
| 887 | // A chord, and the only escape in this table: bare `esc` is the | 899 | // A chord, and the only escape in this table: bare `esc` is the |
| 888 | // stroke a hand throws at anything on screen, and throwing it | 900 | // stroke a hand throws at anything on screen, and throwing it |
| 889 | // at a running export used to delete an hour of encoding. The | 901 | // at a running export used to delete an hour of encoding. The |
| @@ -1158,7 +1170,8 @@ mod tests { | |||
| 1158 | #[test] | 1170 | #[test] |
| 1159 | fn every_default_stroke_reaches_its_action() { | 1171 | fn every_default_stroke_reaches_its_action() { |
| 1160 | let k = Keymap::defaults(); | 1172 | let k = Keymap::defaults(); |
| 1161 | - assert_eq!(k.entries().len(), 53); | 1173 | + assert_eq!(k.entries().len(), 54); |
| 1174 | + assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen)); | ||
| 1162 | assert_eq!(k.lookup("p", true), Some(ActionId::ToggleProxies)); | 1175 | assert_eq!(k.lookup("p", true), Some(ActionId::ToggleProxies)); |
| 1163 | assert_eq!(k.lookup("o", true), Some(ActionId::ToggleAutoProxies)); | 1176 | assert_eq!(k.lookup("o", true), Some(ActionId::ToggleAutoProxies)); |
| 1164 | assert_eq!(k.lookup("f1", false), Some(ActionId::ShowActions)); | 1177 | assert_eq!(k.lookup("f1", false), Some(ActionId::ShowActions)); |
crates/app/src/oracle.rsmodified+3 -1
| @@ -98,7 +98,9 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { | |||
| 98 | // The window's own colours: there is always a window, and repainting it | 98 | // The window's own colours: there is always a window, and repainting it |
| 99 | // touches no timeline -- so this one is live even while an export is | 99 | // touches no timeline -- so this one is live even while an export is |
| 100 | // reading one, which is the only state that dims the list above. | 100 | // reading one, which is the only state that dims the list above. |
| 101 | - if action == ActionId::Theme { | 101 | + // ...and whether that window fills the screen: also always there, also |
| 102 | + // touching no timeline, live through an export the same way. | ||
| 103 | + if action == ActionId::Theme || action == ActionId::Fullscreen { | ||
| 102 | return Enable::Yes; | 104 | return Enable::Yes; |
| 103 | } | 105 | } |
| 104 | if action == ActionId::ShowActions { | 106 | if action == ActionId::ShowActions { |
crates/app/src/player/actions.rsmodified+5 -1
| @@ -7,7 +7,7 @@ impl Player { | |||
| 7 | /// What an action does, wherever it was asked for -- a stroke, or the clip | 7 | /// What an action does, wherever it was asked for -- a stroke, or the clip |
| 8 | /// menu item that names the same action. One table, so the two can never | 8 | /// menu item that names the same action. One table, so the two can never |
| 9 | /// come to mean different things. | 9 | /// come to mean different things. |
| 10 | - pub(crate) fn act(&mut self, action: ActionId, cx: &mut Context<Self>) { | 10 | + pub(crate) fn act(&mut self, action: ActionId, window: &mut Window, cx: &mut Context<Self>) { |
| 11 | // Two doors, one oracle. This used to be the asymmetry the whole | 11 | // Two doors, one oracle. This used to be the asymmetry the whole |
| 12 | // toolbar was built on: the buttons dimmed themselves off | 12 | // toolbar was built on: the buttons dimmed themselves off |
| 13 | // [`enable`] while the keyboard walked straight past it, so with no | 13 | // [`enable`] while the keyboard walked straight past it, so with no |
| @@ -97,6 +97,10 @@ impl Player { | |||
| 97 | // At the window's corner, since a stroke names no place -- and | 97 | // At the window's corner, since a stroke names no place -- and |
| 98 | // [`menu_at`] keeps it on screen from there. | 98 | // [`menu_at`] keeps it on screen from there. |
| 99 | ActionId::Theme => self.open_picker(Pick::Theme, Point::default(), cx), | 99 | ActionId::Theme => self.open_picker(Pick::Theme, Point::default(), cx), |
| 100 | + // The platform's own toggle (gpui::Window::toggle_fullscreen); the | ||
| 101 | + // window reports its own new state back through `is_fullscreen`, | ||
| 102 | + // there is no local bool to keep in step with it. | ||
| 103 | + ActionId::Fullscreen => window.toggle_fullscreen(), | ||
| 100 | // Nothing to cancel while nothing is exporting; the export guard in | 104 | // Nothing to cancel while nothing is exporting; the export guard in |
| 101 | // the key handler is what answers this one while there is. | 105 | // the key handler is what answers this one while there is. |
| 102 | ActionId::CancelExport => {} | 106 | ActionId::CancelExport => {} |
crates/app/src/render.rsmodified+3 -3
| @@ -95,7 +95,7 @@ impl Render for Player { | |||
| 95 | 95 | ||
| 96 | div() | 96 | div() |
| 97 | .track_focus(&self.focus) | 97 | .track_focus(&self.focus) |
| 98 | - .on_key_down(cx.listener(|this, event: &KeyDownEvent, _, cx| { | 98 | + .on_key_down(cx.listener(|this, event: &KeyDownEvent, window, cx| { |
| 99 | let key = event.keystroke.key.as_str(); | 99 | let key = event.keystroke.key.as_str(); |
| 100 | let ctrl = event.keystroke.modifiers.control; | 100 | let ctrl = event.keystroke.modifiers.control; |
| 101 | // `is_held` is the auto-repeat, and a value is the one thing | 101 | // `is_held` is the auto-repeat, and a value is the one thing |
| @@ -462,7 +462,7 @@ impl Render for Player { | |||
| 462 | } | 462 | } |
| 463 | } | 463 | } |
| 464 | if let Some(action) = action { | 464 | if let Some(action) = action { |
| 465 | - this.act(action, cx); | 465 | + this.act(action, window, cx); |
| 466 | } | 466 | } |
| 467 | })) | 467 | })) |
| 468 | // The whole window is the drop target: gpui turns an external file | 468 | // The whole window is the drop target: gpui turns an external file |
| @@ -548,7 +548,7 @@ impl Render for Player { | |||
| 548 | // it. Nothing here moves when the state changes -- the regions are | 548 | // it. Nothing here moves when the state changes -- the regions are |
| 549 | // fixed and the panels keep their room whether or not anything is | 549 | // fixed and the panels keep their room whether or not anything is |
| 550 | // open in them. | 550 | // open in them. |
| 551 | - .child(self.topbar(cx)) | 551 | + .child(self.topbar(window, cx)) |
| 552 | .child( | 552 | .child( |
| 553 | div() | 553 | div() |
| 554 | .flex_1() | 554 | .flex_1() |
crates/app/src/tests/editing.rsmodified+7 -3
| @@ -884,9 +884,13 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() { | |||
| 884 | for action in ActionId::ALL { | 884 | for action in ActionId::ALL { |
| 885 | // Nothing may touch the edit list while an export is reading it -- | 885 | // Nothing may touch the edit list while an export is reading it -- |
| 886 | // and the palette does not: it repaints this window and writes one | 886 | // and the palette does not: it repaints this window and writes one |
| 887 | - // word to the user's own config file, which is why it is the one | 887 | + // word to the user's own config file, which is why it is one of the |
| 888 | - // action besides the cancel that stays live here. | 888 | + // actions besides the cancel that stay live here. Fullscreen is the |
| 889 | - let allowed = action == ActionId::CancelExport || action == ActionId::Theme; | 889 | + // same kind of thing: the platform's own window toggle, touching no |
| 890 | + // edit list either. | ||
| 891 | + let allowed = action == ActionId::CancelExport | ||
| 892 | + || action == ActionId::Theme | ||
| 893 | + || action == ActionId::Fullscreen; | ||
| 890 | assert_eq!( | 894 | assert_eq!( |
| 891 | whole(action, busy).yes(), | 895 | whole(action, busy).yes(), |
| 892 | allowed, | 896 | allowed, |
crates/app/src/ui/overlays.rsmodified+4 -4
| @@ -304,14 +304,14 @@ impl Player { | |||
| 304 | .when(!refusal.yes(), |d| d.opacity(0.4).cursor_not_allowed()) | 304 | .when(!refusal.yes(), |d| d.opacity(0.4).cursor_not_allowed()) |
| 305 | .when(refusal.yes(), |d| { | 305 | .when(refusal.yes(), |d| { |
| 306 | d.cursor_pointer().hover(|s| s.bg(rgb(BG_HOVER()))).on_click( | 306 | d.cursor_pointer().hover(|s| s.bg(rgb(BG_HOVER()))).on_click( |
| 307 | - cx.listener(move |this, _: &ClickEvent, _, cx| { | 307 | + cx.listener(move |this, _: &ClickEvent, window, cx| { |
| 308 | // The card goes first: several of | 308 | // The card goes first: several of |
| 309 | // these open a card of their own, | 309 | // these open a card of their own, |
| 310 | // and every edit moves the indices | 310 | // and every edit moves the indices |
| 311 | // the menus are holding. | 311 | // the menus are holding. |
| 312 | this.keys_open = false; | 312 | this.keys_open = false; |
| 313 | this.rebinding = None; | 313 | this.rebinding = None; |
| 314 | - this.act(action, cx); | 314 | + this.act(action, window, cx); |
| 315 | cx.notify(); | 315 | cx.notify(); |
| 316 | }), | 316 | }), |
| 317 | ) | 317 | ) |
| @@ -578,7 +578,7 @@ impl Player { | |||
| 578 | .when(enabled, |d| { | 578 | .when(enabled, |d| { |
| 579 | d.cursor_pointer() | 579 | d.cursor_pointer() |
| 580 | .hover(|s| s.bg(rgb(BG_HOVER()))) | 580 | .hover(|s| s.bg(rgb(BG_HOVER()))) |
| 581 | - .on_click(cx.listener(move |this, event: &ClickEvent, _, cx| { | 581 | + .on_click(cx.listener(move |this, event: &ClickEvent, window, cx| { |
| 582 | // Closed first: the action moves the very | 582 | // Closed first: the action moves the very |
| 583 | // indices this menu is holding. | 583 | // indices this menu is holding. |
| 584 | this.context_menu = None; | 584 | this.context_menu = None; |
| @@ -594,7 +594,7 @@ impl Player { | |||
| 594 | cx, | 594 | cx, |
| 595 | ); | 595 | ); |
| 596 | } else { | 596 | } else { |
| 597 | - this.act(action, cx); | 597 | + this.act(action, window, cx); |
| 598 | } | 598 | } |
| 599 | })) | 599 | })) |
| 600 | }) | 600 | }) |
crates/app/src/ui/toolbar.rsmodified+20 -1
| @@ -49,8 +49,9 @@ impl Player { | |||
| 49 | /// write a file on the right. Export is the one accented button in the | 49 | /// write a file on the right. Export is the one accented button in the |
| 50 | /// window -- the primary action of an editor, where every consumer editor | 50 | /// window -- the primary action of an editor, where every consumer editor |
| 51 | /// puts it -- and it keeps its rect while it is a Cancel. | 51 | /// puts it -- and it keeps its rect while it is a Cancel. |
| 52 | - pub(crate) fn topbar(&self, cx: &mut Context<Self>) -> impl IntoElement { | 52 | + pub(crate) fn topbar(&self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { |
| 53 | let exporting = self.exporting().is_some(); | 53 | let exporting = self.exporting().is_some(); |
| 54 | + let fullscreen = window.is_fullscreen(); | ||
| 54 | div() | 55 | div() |
| 55 | .flex_none() | 56 | .flex_none() |
| 56 | .h(px(TOPBAR_H)) | 57 | .h(px(TOPBAR_H)) |
| @@ -76,6 +77,24 @@ impl Player { | |||
| 76 | .truncate() | 77 | .truncate() |
| 77 | .child(self.name.clone()), | 78 | .child(self.name.clone()), |
| 78 | ) | 79 | ) |
| 80 | + // The window's own control, in the fixed rect the mute button uses | ||
| 81 | + // for the same reason (toolbar.rs:194-203): fullscreen swaps the | ||
| 82 | + // word and the colour, never the box. | ||
| 83 | + .child(self.action_control( | ||
| 84 | + "fullscreen", | ||
| 85 | + 0., | ||
| 86 | + BG_RAISED(), | ||
| 87 | + None, | ||
| 88 | + match fullscreen { | ||
| 89 | + true => "Exit fullscreen", | ||
| 90 | + false => "Fullscreen", | ||
| 91 | + }, | ||
| 92 | + "fills the screen with the window, or gives it back", | ||
| 93 | + ActionId::Fullscreen, | ||
| 94 | + cx.listener(|this, _: &ClickEvent, window, cx| { | ||
| 95 | + this.act(ActionId::Fullscreen, window, cx) | ||
| 96 | + }), | ||
| 97 | + )) | ||
| 79 | .child(self.action_control( | 98 | .child(self.action_control( |
| 80 | "save", | 99 | "save", |
| 81 | 0., | 100 | 0., |