Skip to content
Open
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
14 changes: 12 additions & 2 deletions crates/tinyclient/src/gui/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use gpui::{
Rgba, SharedString, Window, WindowControlArea,
};
use protocol::{CallState, Conversation, Key, Link, Network, Notify, Presence};
use std::collections::HashMap;
use std::rc::Rc;
use std::time::Duration;

Expand Down Expand Up @@ -157,6 +158,11 @@ pub struct State {
pub floating: bool,
pub resizing: Option<Edge>,
pub menu: Option<Menu>,
/// The list of servers or workspaces that hangs off a rail icon while the pointer rests on it.
pub flyout: Option<super::rail::Flyout>,
/// Keyboard focus while the rail's workspace/server menu is open.
pub flyout_focus: gpui::FocusHandle,
pub rail_focus: HashMap<Network, gpui::FocusHandle>,
pub right: Option<RightPane>,
/// The row of the first-launch card that has the keyboard.
pub first_run: usize,
Expand All @@ -175,15 +181,18 @@ pub struct State {
main_top: Rc<std::cell::Cell<f32>>,
}

impl Default for State {
fn default() -> Self {
impl State {
pub(super) fn new(flyout_focus: gpui::FocusHandle, rail_focus: HashMap<Network, gpui::FocusHandle>) -> Self {
State {
sidebar_width: SIDEBAR_WIDTH,
right_width: RIGHT_WIDTH,
sidebar_hidden: false,
floating: false,
resizing: None,
menu: None,
flyout: None,
flyout_focus,
rail_focus,
right: None,
first_run: 0,
details_channels: false,
Expand Down Expand Up @@ -2554,6 +2563,7 @@ impl Render for Shell {
// With no sidebar dock in view (collapsed, hidden, or narrow Tiny page), float incoming calls here.
.children(self.call_incoming_overlay(snapshot, cx))
.children(self.menu_layer(snapshot, actual_sidebar_width, overview, top_offset, window, cx).map(super::components::focus_scope))
.children(self.rail_flyout_layer(window, cx))
.children(self.meeting_layer(window, cx))
.children(self.story_viewer_layer(window, cx))
.children(self.toast_layer(width, cx))
Expand Down
245 changes: 242 additions & 3 deletions crates/tinyclient/src/gui/rail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ use super::phone::tokens;
use super::people::presence;
use super::sidebar::Mode;
use super::state::{Shell, Snapshot};
use super::theme;
use super::theme::{self, Type};
use gpui::{
div, prelude::*, px, AnyElement, Context, Div, ElementId, MouseButton, SharedString, Stateful,
div, prelude::*, px, AnyElement, Bounds, Context, Div, ElementId, MouseButton, Pixels, SharedString, Stateful,
Window,
};
use std::time::Duration;
use protocol::{Link, Network};

/// What a rail button's tooltip says after its name.
Expand All @@ -25,6 +26,22 @@ fn waiting(attention: u32, unread: bool) -> String {
}
}

/// Servers a rail list shows before it says how many more there are.
const FLYOUT_SHOWN: usize = 5;

/// A list of servers hanging off a rail icon. `button` and `list`: the pointer is on the icon, on
/// the list. `shown`: the beat before it appears has passed.
#[derive(Clone, Debug)]
pub struct Flyout {
pub network: Network,
pub at: Bounds<Pixels>,
pub button: bool,
pub list: bool,
pub shown: bool,
pub keyboard: bool,
pub opener: Option<gpui::FocusHandle>,
}

/// One button of the rail.
struct Place {
mode: Mode,
Expand Down Expand Up @@ -57,10 +74,15 @@ impl Shell {
let phone = super::phone::active();
const KEYS: [&str; 9] = ["⌘1", "⌘2", "⌘3", "⌘4", "⌘5", "⌘6", "⌘7", "⌘8", "⌘9"];
let label = format!("{name}{}", waiting(attention, unread));
let flies = !phone
&& matches!(mode, Mode::Network(net @ (Network::Slack | Network::Mattermost | Network::Discord))
if self.spaces.iter().filter(|s| s.key.network == net).count() >= if net == Network::Discord { 1 } else { 2 });
let flyout_open = matches!(mode, Mode::Network(network) if self.layout_state.flyout.as_ref().is_some_and(|flyout| flyout.network == network));
div()
.id(id)
.role(gpui::Role::Button)
.aria_label(label.clone())
.aria_expanded(flyout_open)
.when(lit, |row| row.aria_description("Current place"))
.tab_index(0)
.focus_visible(|style| style.shadow(theme::focus_ring_inset()))
Expand All @@ -75,7 +97,19 @@ impl Shell {
.when(lit, |button| button.bg(theme::selected()))
.when(!lit && !phone, |button| button.hover(|style| style.bg(theme::hover())))
.when(phone, |button| button.active(|style| style.bg(theme::pressed())))
.tooltip(tip(label, KEYS.get(place).copied()))
.when(!flies, |button| button.tooltip(tip(label, KEYS.get(place).copied())))
.when_some(flies.then_some(mode.clone()), |button, mode| {
let Mode::Network(network) = mode else { return button };
button
.track_focus(self.layout_state.rail_focus.get(&network).expect("eligible network has a rail focus handle"))
.on_hover(cx.listener(move |this, over: &bool, window, cx| this.rail_hover(network, *over, window, cx)))
.on_key_down(cx.listener(move |this, event: &gpui::KeyDownEvent, window, cx| {
if event.keystroke.key == "down" {
cx.stop_propagation();
this.rail_keyboard_open(network, window, cx);
}
}))
})
.on_click(cx.listener(move |this, _, window, cx| this.visit(mode.clone(), window, cx)))
.child(div().when(faint, |content| content.opacity(0.4)).child(content))
.children(rail_badge(attention, unread, mention, counted))
Expand All @@ -94,6 +128,211 @@ impl Shell {
})
}

/// Open the flyout from the keyboard when its rail button is focused. Centering the anchor in
/// the rail keeps it visible even when the focused button is in a scrolled server list.
fn rail_keyboard_open(&mut self, network: Network, window: &mut Window, cx: &mut Context<Self>) {
let y = f32::from(window.viewport_size().height) / 2. - 22.;
let at = super::components::place::anchor(0., y.max(0.), super::layout::RAIL_WIDTH, 44.);
let opener = self.layout_state.rail_focus.get(&network).cloned();
self.layout_state.flyout = Some(Flyout { network, at, button: false, list: false, shown: true, keyboard: true, opener });
window.focus(&self.layout_state.flyout_focus, cx);
self.rail_flyout_lapse(network, window.window_handle(), Duration::from_millis(200), cx);
cx.notify();
}

/// The pointer came to rest on a network's rail icon, or left it: after a beat the list of
/// that network's servers or workspaces hangs off the icon, and goes when the pointer has
/// left both.
fn rail_hover(&mut self, network: Network, over: bool, window: &mut Window, cx: &mut Context<Self>) {
const WAIT: Duration = Duration::from_millis(250);
const GRACE: Duration = Duration::from_millis(200);
if over {
let y = f32::from(window.mouse_position().y) - 22.;
let at = super::components::place::anchor(0., y.max(0.), super::layout::RAIL_WIDTH, 44.);
let shown = self.layout_state.flyout.as_ref().is_some_and(|f| f.shown);
self.layout_state.flyout = Some(Flyout { network, at, button: true, list: false, shown, keyboard: false, opener: None });
cx.spawn(async move |this, cx| {
cx.background_executor().timer(if shown { Duration::ZERO } else { WAIT }).await;
let _ = this.update(cx, |this, cx| {
if let Some(flyout) = this.layout_state.flyout.as_mut().filter(|f| f.network == network && f.button) {
flyout.shown = true;
cx.notify();
}
});
})
.detach();
} else {
if let Some(flyout) = self.layout_state.flyout.as_mut().filter(|f| f.network == network) {
flyout.button = false;
}
self.rail_flyout_lapse(network, window.window_handle(), GRACE, cx);
}
}

/// After a grace, drop the flyout if the pointer is on neither the icon nor the list.
fn rail_flyout_lapse(&mut self, network: Network, window: gpui::AnyWindowHandle, grace: Duration, cx: &mut Context<Self>) {
cx.spawn(async move |this, cx| {
cx.background_executor().timer(grace).await;
let _ = cx.update_window(window, |_, window, cx| {
let _ = this.update(cx, |this, cx| {
if let Some(flyout) = this.layout_state.flyout.as_ref().filter(|f| f.network == network && !f.button && !f.list) {
if flyout.keyboard && this.layout_state.flyout_focus.contains_focused(window, cx) {
this.rail_flyout_lapse(network, window.window_handle(), Duration::from_millis(200), cx);
return;
}
this.layout_state.flyout = None;
cx.notify();
}
});
});
})
.detach();
}

/// The list that hangs off a rail icon: the network's servers (Discord, Mattermost) or
/// workspaces (Slack), the current one marked. Picking one goes there.
pub(super) fn rail_flyout_layer(&self, window: &mut Window, cx: &mut Context<Self>) -> Option<AnyElement> {
let flyout = self.layout_state.flyout.as_ref().filter(|f| f.shown)?;
let network = flyout.network;
let here: Vec<&protocol::Space> = self.spaces.iter().filter(|s| s.key.network == network).collect();
let single = network != Network::Discord;
if here.len() < if single { 2 } else { 1 } {
return None;
}
let current = match (&self.sidebar_state.mode, single) {
(Mode::Space(key), _) => Some(key.clone()),
(_, true) => self.workspace_space(network),
_ => None,
};
let mut menu = super::components::menu().w(px(260.)).child(super::components::menu_label(format!("{} · {}", network.label(), if network == Network::Slack { "Workspaces" } else { "Servers" })));
let more = here.len().saturating_sub(FLYOUT_SHOWN);
for (ix, space) in here.iter().take(FLYOUT_SHOWN).enumerate() {
let key = space.key.clone();
let click_key = key.clone();
let keyboard_key = key.clone();
let icon = self.media_path(&space.key, space.icon.as_ref());
menu = menu.child(
div()
.id(("rail-flyout-row", ix))
.role(gpui::Role::MenuItem)
.aria_label(space.name.clone())
.tab_index(0)
.focus_visible(|style| style.shadow(theme::focus_ring_inset()))
.h(px(28.))
.px(px(8.))
.mx(px(4.))
.rounded(px(theme::R_CONTROL))
.flex()
.items_center()
.gap(px(8.))
.cursor_pointer()
.when(current.as_ref() == Some(&space.key), |row| row.bg(theme::selected()))
.hover(|style| style.bg(theme::hover()))
.on_click(cx.listener(move |this, _, window, cx| {
this.choose_rail_space(network, click_key.clone(), window, cx);
}))
.on_key_down(cx.listener(move |this, event: &gpui::KeyDownEvent, window, cx| {
if matches!(event.keystroke.key.as_str(), "enter" | "space") {
cx.stop_propagation();
this.choose_rail_space(network, keyboard_key.clone(), window, cx);
}
}))
.child(Avatar::new(&space.key, &space.name, 20.).shape(Shape::Place).image_at(icon).build())
.child(div().flex_1().min_w_0().truncate().type_ui().text_color(theme::text()).child(space.name.clone()))
.children(super::components::rollup_badge(space.attention, space.unread)),
);
}
if more > 0 {
menu = menu.child(
div()
.id("rail-flyout-more")
.role(gpui::Role::MenuItem)
.aria_label(format!("Show all {}", network.label()))
.tab_index(0)
.focus_visible(|style| style.shadow(theme::focus_ring_inset()))
.h(px(28.))
.px(px(8.))
.mx(px(4.))
.rounded(px(theme::R_CONTROL))
.flex()
.items_center()
.gap(px(8.))
.cursor_pointer()
.hover(|style| style.bg(theme::hover()))
.on_click(cx.listener(move |this, _, window, cx| {
this.show_all_rail_spaces(network, window, cx);
}))
.on_key_down(cx.listener(move |this, event: &gpui::KeyDownEvent, window, cx| {
if matches!(event.keystroke.key.as_str(), "enter" | "space") {
cx.stop_propagation();
this.show_all_rail_spaces(network, window, cx);
}
}))
.child(div().size(px(20.)).flex_none().flex().items_center().justify_center().child(glyph("icons/ellipsis.svg", 14., theme::text_faint())))
.child(div().flex_1().min_w_0().type_ui().text_color(theme::text_soft()).child(format!("{more} more")))
.child(glyph("icons/chevron-right.svg", 12., theme::text_faint())),
);
}
let menu = menu
.id("rail-flyout-list")
.role(gpui::Role::Menu)
.aria_label(format!("{} {}", network.label(), if network == Network::Slack { "workspaces" } else { "servers" }))
.tab_index(0)
.track_focus(&self.layout_state.flyout_focus)
.on_key_down(cx.listener(|this, event: &gpui::KeyDownEvent, window, cx| {
match event.keystroke.key.as_str() {
"down" => window.focus_next(cx),
"up" => window.focus_prev(cx),
Comment on lines +284 to +285

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major: Up and Down leave the flyout at the ends.
window.focus_next and focus_prev walk every tab stop of the window and wrap at both ends (TabStopMap, pinned by gpui's test_tab_handles). The flyout is painted last.
Up right after opening, while the list itself has the focus, lands on the last stop before the flyout. Down on the last row wraps to the first stop of the window. Either way the focus is outside, and the lapse closes the flyout without returning focus to the opener.
The other menus wrap through their rows (menu_step, overlay.rs:75).
Smallest fix: keep an index as they do, or hold a handle per row and, after the step, move to the last or first row when the focus is no longer on one.
Not seen running: this follows from the focus code and that test.

"escape" => {
let opener = this.layout_state.flyout.take().and_then(|flyout| flyout.opener);
if let Some(opener) = opener.as_ref() {
window.focus(opener, cx);
}
cx.notify();
}
_ => return,
}
cx.stop_propagation();
cx.notify();
}))
.on_hover(cx.listener(move |this, over: &bool, window, cx| {
if let Some(flyout) = this.layout_state.flyout.as_mut().filter(|flyout| flyout.network == network) {
flyout.list = *over;
}
if !*over {
this.rail_flyout_lapse(network, window.window_handle(), Duration::from_millis(200), cx);
}
}));
Some(super::components::placed("rail-flyout", super::components::Place::Beside(flyout.at), super::components::Layer::Popover, window, menu))
}

fn close_rail_flyout(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let opener = self.layout_state.flyout.take().and_then(|flyout| flyout.keyboard.then_some(flyout.opener).flatten());
if let Some(opener) = opener.as_ref() {
window.focus(opener, cx);
}
}

fn choose_rail_space(&mut self, network: Network, key: protocol::Key, window: &mut Window, cx: &mut Context<Self>) {
self.close_rail_flyout(window, cx);
if network == Network::Discord {
self.visit(Mode::Space(key), window, cx);
} else {
match network {
Network::Slack => self.sidebar_state.slack = Some(key),
Network::Mattermost => self.sidebar_state.mattermost = Some(key),
_ => return,
}
self.visit(Mode::Network(network), window, cx);
self.show_mode(cx);
}
}

fn show_all_rail_spaces(&mut self, network: Network, window: &mut Window, cx: &mut Context<Self>) {
self.close_rail_flyout(window, cx);
self.visit(Mode::Network(network), window, cx);
}
Comment on lines +331 to +334

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major: "N more" leads to the full list only on Discord.
show_all_rail_spaces goes to Mode::Network(network). For Discord that is the server list. For Slack and Mattermost it is the channel list of the workspace already open. The full list there is the header menu behind sidebar_state.slack_menu and mattermost_menu (sidebar.rs:2772, sidebar.rs:3003), which this never sets.
Already in that network, go returns early (sidebar.rs:727-741), so the row closes the flyout and does nothing else. The demo has two Slack workspaces, so the scenario never draws this row.
Smallest fix: after visit, set that network's menu flag and call cx.notify(). It has to come after visit, because set_mode clears both flags.


/// A rail click: the place opens in the sidebar. In a window too narrow to keep the
/// sidebar in the row, it floats over the conversation.
pub(super) fn visit(&mut self, mode: Mode, window: &mut Window, cx: &mut Context<Self>) {
Expand Down
8 changes: 7 additions & 1 deletion crates/tinyclient/src/gui/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,13 @@ impl Shell {
call_dock: Some(call::dock),
search: Some(Self::open_message_search),
},
layout_state: layout::State::default(),
layout_state: layout::State::new(
cx.focus_handle().tab_index(0).tab_stop(true),
[Network::Slack, Network::Mattermost, Network::Discord]
.into_iter()
.map(|network| (network, cx.focus_handle().tab_index(0).tab_stop(true)))
.collect(),
),
sidebar_state: sidebar::State::new(cx),
phone_state: super::phone::State::default(),
conversation_state: conversation::State::default(),
Expand Down
3 changes: 3 additions & 0 deletions e2e/scenarios/rail-workspace-switcher/drive.linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
set -euo pipefail
python3 "$(dirname "$0")/drive.py" linux
3 changes: 3 additions & 0 deletions e2e/scenarios/rail-workspace-switcher/drive.macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
set -euo pipefail
python3 "$(dirname "$0")/drive.py" macos
Loading
Loading