From e8db247635970159523e341ceae03b39a1494df0 Mon Sep 17 00:00:00 2001 From: Skull Date: Thu, 26 Nov 2026 23:53:32 -0600 Subject: [PATCH 1/5] Hover a Slack, Mattermost or Discord rail icon to pick a workspace or server Co-Authored-By: Claude Sonnet 5.5 --- crates/tinyclient/src/gui/layout.rs | 4 + crates/tinyclient/src/gui/rail.rs | 122 +++++++++++++++++++++++++++- 2 files changed, 124 insertions(+), 2 deletions(-) diff --git a/crates/tinyclient/src/gui/layout.rs b/crates/tinyclient/src/gui/layout.rs index 60d5779a..7849f3bb 100644 --- a/crates/tinyclient/src/gui/layout.rs +++ b/crates/tinyclient/src/gui/layout.rs @@ -157,6 +157,8 @@ pub struct State { pub floating: bool, pub resizing: Option, pub menu: Option, + /// The list of servers or workspaces that hangs off a rail icon while the pointer rests on it. + pub flyout: Option, pub right: Option, /// The row of the first-launch card that has the keyboard. pub first_run: usize, @@ -184,6 +186,7 @@ impl Default for State { floating: false, resizing: None, menu: None, + flyout: None, right: None, first_run: 0, details_channels: false, @@ -2554,6 +2557,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)) diff --git a/crates/tinyclient/src/gui/rail.rs b/crates/tinyclient/src/gui/rail.rs index 7000e126..9ebbe39e 100644 --- a/crates/tinyclient/src/gui/rail.rs +++ b/crates/tinyclient/src/gui/rail.rs @@ -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. @@ -25,6 +26,17 @@ fn waiting(attention: u32, unread: bool) -> String { } } +/// 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, + pub button: bool, + pub list: bool, + pub shown: bool, +} + /// One button of the rail. struct Place { mode: Mode, @@ -57,6 +69,7 @@ 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(Network::Slack | Network::Mattermost | Network::Discord)); div() .id(id) .role(gpui::Role::Button) @@ -76,6 +89,10 @@ impl Shell { .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_some(flies.then_some(mode.clone()), |button, mode| { + let Mode::Network(network) = mode else { return button }; + button.on_hover(cx.listener(move |this, over: &bool, window, cx| this.rail_hover(network, *over, 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)) @@ -94,6 +111,107 @@ impl Shell { }) } + /// 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) { + 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 }); + 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(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, grace: Duration, cx: &mut Context) { + cx.spawn(async move |this, cx| { + cx.background_executor().timer(grace).await; + let _ = this.update(cx, |this, cx| { + if this.layout_state.flyout.as_ref().is_some_and(|f| !f.button && !f.list) { + 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) -> Option { + 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(if network == Network::Slack { "Workspaces" } else { "Servers" })); + for (ix, space) in here.iter().enumerate() { + let key = space.key.clone(); + let icon = self.media_path(&space.key, space.icon.as_ref()); + menu = menu.child( + div() + .id(("rail-flyout-row", ix)) + .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.layout_state.flyout = None; + if network == Network::Discord { + this.visit(Mode::Space(key.clone()), window, cx); + } else { + this.sidebar_state.slack = Some(key.clone()); + this.visit(Mode::Network(network), window, cx); + this.show_mode(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)), + ); + } + let menu = menu.id("rail-flyout-list").on_hover(cx.listener(move |this, over: &bool, _, cx| { + if let Some(flyout) = this.layout_state.flyout.as_mut() { + flyout.list = *over; + } + if !*over { + this.rail_flyout_lapse(Duration::from_millis(200), cx); + } + })); + Some(super::components::placed("rail-flyout", super::components::Place::Beside(flyout.at), super::components::Layer::Popover, window, menu)) + } + /// 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) { From 212191a80ebc8bfb38d4b70611f827bd7c1202d0 Mon Sep 17 00:00:00 2001 From: Skull Date: Fri, 27 Nov 2026 00:00:05 -0600 Subject: [PATCH 2/5] Rail icons with a server list show it instead of the tooltip Co-Authored-By: Claude Sonnet 5.5 --- crates/tinyclient/src/gui/rail.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/tinyclient/src/gui/rail.rs b/crates/tinyclient/src/gui/rail.rs index 9ebbe39e..f96b3b9d 100644 --- a/crates/tinyclient/src/gui/rail.rs +++ b/crates/tinyclient/src/gui/rail.rs @@ -69,7 +69,9 @@ 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(Network::Slack | Network::Mattermost | Network::Discord)); + 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 }); div() .id(id) .role(gpui::Role::Button) @@ -88,7 +90,7 @@ 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.on_hover(cx.listener(move |this, over: &bool, window, cx| this.rail_hover(network, *over, window, cx))) @@ -169,7 +171,7 @@ impl Shell { (_, true) => self.workspace_space(network), _ => None, }; - let mut menu = super::components::menu().w(px(260.)).child(super::components::menu_label(if network == Network::Slack { "Workspaces" } else { "Servers" })); + let mut menu = super::components::menu().w(px(260.)).child(super::components::menu_label(format!("{} · {}", network.label(), if network == Network::Slack { "Workspaces" } else { "Servers" }))); for (ix, space) in here.iter().enumerate() { let key = space.key.clone(); let icon = self.media_path(&space.key, space.icon.as_ref()); From 51282adcd98ecc112b1b8b0f9f51ed93e08edb30 Mon Sep 17 00:00:00 2001 From: Skull Date: Fri, 27 Nov 2026 00:02:52 -0600 Subject: [PATCH 3/5] Cap the rail server list at five and link the rest to the full list Co-Authored-By: Claude Sonnet 5.5 --- crates/tinyclient/src/gui/rail.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/crates/tinyclient/src/gui/rail.rs b/crates/tinyclient/src/gui/rail.rs index f96b3b9d..22b99d73 100644 --- a/crates/tinyclient/src/gui/rail.rs +++ b/crates/tinyclient/src/gui/rail.rs @@ -26,6 +26,9 @@ 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)] @@ -172,7 +175,8 @@ impl Shell { _ => 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" }))); - for (ix, space) in here.iter().enumerate() { + let more = here.len().saturating_sub(FLYOUT_SHOWN); + for (ix, space) in here.iter().take(FLYOUT_SHOWN).enumerate() { let key = space.key.clone(); let icon = self.media_path(&space.key, space.icon.as_ref()); menu = menu.child( @@ -203,6 +207,28 @@ impl Shell { .children(super::components::rollup_badge(space.attention, space.unread)), ); } + if more > 0 { + menu = menu.child( + div() + .id("rail-flyout-more") + .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.layout_state.flyout = None; + this.visit(Mode::Network(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").on_hover(cx.listener(move |this, over: &bool, _, cx| { if let Some(flyout) = this.layout_state.flyout.as_mut() { flyout.list = *over; From 3c1ec24d26284f8a45ae343a9f480eb1cef92486 Mon Sep 17 00:00:00 2001 From: Skull Date: Thu, 3 Dec 2026 15:40:48 -0600 Subject: [PATCH 4/5] Open the rail workspace and server switcher --- crates/tinyclient/src/gui/layout.rs | 7 +- crates/tinyclient/src/gui/rail.rs | 104 ++++++-- crates/tinyclient/src/gui/state.rs | 2 +- .../rail-workspace-switcher/drive.linux.sh | 3 + .../rail-workspace-switcher/drive.macos.sh | 3 + .../rail-workspace-switcher/drive.py | 244 ++++++++++++++++++ .../rail-workspace-switcher/drive.windows.ps1 | 3 + .../rail-workspace-switcher/scenario.json | 12 + 8 files changed, 359 insertions(+), 19 deletions(-) create mode 100755 e2e/scenarios/rail-workspace-switcher/drive.linux.sh create mode 100755 e2e/scenarios/rail-workspace-switcher/drive.macos.sh create mode 100644 e2e/scenarios/rail-workspace-switcher/drive.py create mode 100644 e2e/scenarios/rail-workspace-switcher/drive.windows.ps1 create mode 100644 e2e/scenarios/rail-workspace-switcher/scenario.json diff --git a/crates/tinyclient/src/gui/layout.rs b/crates/tinyclient/src/gui/layout.rs index 7849f3bb..10613cc1 100644 --- a/crates/tinyclient/src/gui/layout.rs +++ b/crates/tinyclient/src/gui/layout.rs @@ -159,6 +159,8 @@ pub struct State { pub menu: Option, /// The list of servers or workspaces that hangs off a rail icon while the pointer rests on it. pub flyout: Option, + /// Keyboard focus while the rail's workspace/server menu is open. + pub flyout_focus: gpui::FocusHandle, pub right: Option, /// The row of the first-launch card that has the keyboard. pub first_run: usize, @@ -177,8 +179,8 @@ pub struct State { main_top: Rc>, } -impl Default for State { - fn default() -> Self { +impl State { + pub(super) fn new(flyout_focus: gpui::FocusHandle) -> Self { State { sidebar_width: SIDEBAR_WIDTH, right_width: RIGHT_WIDTH, @@ -187,6 +189,7 @@ impl Default for State { resizing: None, menu: None, flyout: None, + flyout_focus, right: None, first_run: 0, details_channels: false, diff --git a/crates/tinyclient/src/gui/rail.rs b/crates/tinyclient/src/gui/rail.rs index 22b99d73..3e69f644 100644 --- a/crates/tinyclient/src/gui/rail.rs +++ b/crates/tinyclient/src/gui/rail.rs @@ -75,10 +75,12 @@ impl Shell { 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())) @@ -96,7 +98,14 @@ impl Shell { .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.on_hover(cx.listener(move |this, over: &bool, window, cx| this.rail_hover(network, *over, window, cx))) + button + .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)) @@ -116,6 +125,16 @@ 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) { + 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.); + self.layout_state.flyout = Some(Flyout { network, at, button: true, list: false, shown: true }); + window.focus(&self.layout_state.flyout_focus, 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. @@ -141,16 +160,16 @@ impl Shell { if let Some(flyout) = self.layout_state.flyout.as_mut().filter(|f| f.network == network) { flyout.button = false; } - self.rail_flyout_lapse(GRACE, cx); + self.rail_flyout_lapse(network, 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, grace: Duration, cx: &mut Context) { + fn rail_flyout_lapse(&mut self, network: Network, grace: Duration, cx: &mut Context) { cx.spawn(async move |this, cx| { cx.background_executor().timer(grace).await; let _ = this.update(cx, |this, cx| { - if this.layout_state.flyout.as_ref().is_some_and(|f| !f.button && !f.list) { + if this.layout_state.flyout.as_ref().is_some_and(|f| f.network == network && !f.button && !f.list) { this.layout_state.flyout = None; cx.notify(); } @@ -178,10 +197,16 @@ impl Shell { 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.)) @@ -193,13 +218,12 @@ impl Shell { .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.layout_state.flyout = None; - if network == Network::Discord { - this.visit(Mode::Space(key.clone()), window, cx); - } else { - this.sidebar_state.slack = Some(key.clone()); - this.visit(Mode::Network(network), window, cx); - this.show_mode(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()) @@ -211,6 +235,10 @@ impl Shell { 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.)) @@ -221,25 +249,69 @@ impl Shell { .cursor_pointer() .hover(|style| style.bg(theme::hover())) .on_click(cx.listener(move |this, _, window, cx| { - this.layout_state.flyout = None; - this.visit(Mode::Network(network), 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").on_hover(cx.listener(move |this, over: &bool, _, cx| { - if let Some(flyout) = this.layout_state.flyout.as_mut() { + 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), + "escape" => { + this.layout_state.flyout = None; + cx.notify(); + } + _ => return, + } + cx.stop_propagation(); + cx.notify(); + })) + .on_hover(cx.listener(move |this, over: &bool, _, 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(Duration::from_millis(200), cx); + this.rail_flyout_lapse(network, Duration::from_millis(200), cx); } })); Some(super::components::placed("rail-flyout", super::components::Place::Beside(flyout.at), super::components::Layer::Popover, window, menu)) } + fn choose_rail_space(&mut self, network: Network, key: protocol::Key, window: &mut Window, cx: &mut Context) { + self.layout_state.flyout = None; + 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.layout_state.flyout = None; + self.visit(Mode::Network(network), window, cx); + } + /// 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) { diff --git a/crates/tinyclient/src/gui/state.rs b/crates/tinyclient/src/gui/state.rs index c7436862..40a403a4 100644 --- a/crates/tinyclient/src/gui/state.rs +++ b/crates/tinyclient/src/gui/state.rs @@ -344,7 +344,7 @@ 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()), sidebar_state: sidebar::State::new(cx), phone_state: super::phone::State::default(), conversation_state: conversation::State::default(), diff --git a/e2e/scenarios/rail-workspace-switcher/drive.linux.sh b/e2e/scenarios/rail-workspace-switcher/drive.linux.sh new file mode 100755 index 00000000..63dc78a7 --- /dev/null +++ b/e2e/scenarios/rail-workspace-switcher/drive.linux.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -euo pipefail +python3 "$(dirname "$0")/drive.py" linux diff --git a/e2e/scenarios/rail-workspace-switcher/drive.macos.sh b/e2e/scenarios/rail-workspace-switcher/drive.macos.sh new file mode 100755 index 00000000..ff2e3e54 --- /dev/null +++ b/e2e/scenarios/rail-workspace-switcher/drive.macos.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -euo pipefail +python3 "$(dirname "$0")/drive.py" macos diff --git a/e2e/scenarios/rail-workspace-switcher/drive.py b/e2e/scenarios/rail-workspace-switcher/drive.py new file mode 100644 index 00000000..721e1db4 --- /dev/null +++ b/e2e/scenarios/rail-workspace-switcher/drive.py @@ -0,0 +1,244 @@ +#!/usr/bin/env python3 +"""Use the real desktop app to open the Slack rail's workspace quick switcher. + +The live demo seeds two independent Slack workspaces. The driver hovers the Slack rail button, +checks that both workspaces appear, chooses Fernhill Collective, and verifies the new workspace +is open. The base build has no hover list, so the first check fails there. +""" + +import csv +import ctypes +from ctypes import wintypes +import io +import json +import os +from pathlib import Path +import subprocess +import sys +import tempfile +import time + +import pyautogui + +OUT = Path(os.environ["E2E_OUT"]) +T0 = float(os.environ.get("E2E_T0") or time.time()) +PLATFORM = sys.argv[1] + + +def record(name, ok, shot=None): + entry = {"t": round(time.time() - T0, 2), "step": name, "ok": bool(ok)} + if shot: + entry["shot"] = shot + with (OUT / "steps.jsonl").open("a", encoding="utf-8") as log: + log.write(json.dumps(entry) + "\n") + print(("[ok] " if ok else "[FAILED] ") + name, flush=True) + if not ok: + raise RuntimeError(name) + + +def words(shot): + image = pyautogui.screenshot() + image.save(shot) + width, height = pyautogui.size() + scale_x, scale_y = width / image.width, height / image.height + result = [] + proc = subprocess.run( + ["tesseract", str(shot), "stdout", "tsv"], capture_output=True, check=True, + text=True, encoding="utf-8", timeout=20, + ) + for row in csv.DictReader(io.StringIO(proc.stdout), delimiter="\t"): + text = row["text"].casefold().strip(".,·•:;#?!") + if text: + x = (int(row["left"]) + int(row["width"]) / 2) * scale_x + y = (int(row["top"]) + int(row["height"]) / 2) * scale_y + result.append((text, round(x), round(y))) + return result + + +def contains(found, phrase): + text = " ".join(word for word, _, _ in found) + return phrase.casefold() in text + + +def wait_for(phrase, name, timeout=15): + shot = OUT / f"{name}.png" + deadline = time.monotonic() + timeout + found = [] + while time.monotonic() < deadline: + found = words(shot) + if contains(found, phrase): + record(name, True, shot.name) + return found + time.sleep(0.4) + record(name, False, shot.name) + raise RuntimeError(f"expected {phrase!r}") + + +def stop(process): + if process is None or process.poll() is not None: + return + process.terminate() + try: + process.wait(timeout=5) + except subprocess.TimeoutExpired: + process.kill() + process.wait(timeout=5) + + +def window_bounds(pid): + """Return the app window bounds, even when it is not maximized.""" + if PLATFORM == "macos": + helper = os.environ["E2E_HELPER"] + log = OUT / "window-bounds.txt" + with log.open("w", encoding="utf-8") as output: + subprocess.run( + ["open", "-W", "-n", "--stdout", str(log), "--stderr", str(log), + "-a", helper, "--args", "windows", "--pid", str(pid)], + check=True, timeout=30, + ) + lines = log.read_text(encoding="utf-8").splitlines() + info = next((json.loads(line) for line in lines if line.startswith("{")), None) + if info: + return tuple(int(info[key]) for key in ("x", "y", "w", "h")) + raise RuntimeError("could not read the app window position from the lab helper") + if PLATFORM == "windows": + user32 = ctypes.windll.user32 + rect_type = wintypes.RECT + found = [] + + @ctypes.WINFUNCTYPE(ctypes.c_bool, wintypes.HWND, wintypes.LPARAM) + def visit(hwnd, _): + owner = wintypes.DWORD() + user32.GetWindowThreadProcessId(hwnd, ctypes.byref(owner)) + if owner.value == pid and user32.IsWindowVisible(hwnd): + rect = rect_type() + if user32.GetWindowRect(hwnd, ctypes.byref(rect)): + found.append((rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top)) + return True + + user32.EnumWindows(visit, 0) + if found: + return found[0] + raise RuntimeError("could not read the app window position") + + ids = subprocess.run( + ["xdotool", "search", "--onlyvisible", "--pid", str(pid)], + capture_output=True, text=True, check=True, timeout=10, + ).stdout.splitlines() + if not ids: + raise RuntimeError("could not find the app window") + geometry = subprocess.run( + ["xdotool", "getwindowgeometry", "--shell", ids[0]], + capture_output=True, text=True, check=True, timeout=10, + ).stdout + values = {} + for line in geometry.splitlines(): + if "=" in line: + key, value = line.split("=", 1) + if key in {"X", "Y", "WIDTH", "HEIGHT"}: + values[key] = int(value) + if not {"X", "Y", "WIDTH", "HEIGHT"} <= values.keys(): + raise RuntimeError("could not read the app window position") + return values["X"], values["Y"], values["WIDTH"], values["HEIGHT"] + + +def run(data): + app_dir = Path(os.environ["E2E_APP_DIR"]).resolve() + if PLATFORM == "macos": + app_dir /= "Contents" / "MacOS" + suffix = ".exe" if PLATFORM == "windows" else "" + env = dict(os.environ, TINYCLIENT_DIR=str(data)) + daemon = app = None + with (OUT / "app.log").open("wb") as log: + try: + daemon = subprocess.Popen( + [str(app_dir / ("chatd" + suffix)), "--seed-demo=live"], env=env, + stdout=log, stderr=log, + ) + ready = False + deadline = time.monotonic() + 25 + while time.monotonic() < deadline: + if daemon.poll() is not None: + break + try: + ready = subprocess.run( + [str(app_dir / ("tinyclient" + suffix)), "--text"], env=env, + capture_output=True, timeout=5, + ).returncode == 0 + except subprocess.SubprocessError: + ready = False + if ready: + break + time.sleep(0.25) + record("demo service starts", ready) + if not ready: + raise RuntimeError("the demo service did not start") + app = subprocess.Popen([str(app_dir / ("tinyclient" + suffix))], env=env, stdout=log, stderr=log) + (OUT / "app.pid").write_text(str(app.pid), encoding="utf-8") + time.sleep(5) + + # Give the shared rail a stable screen origin before scanning its network buttons. + if PLATFORM == "windows": + pyautogui.hotkey("win", "up") + elif PLATFORM == "macos": + pyautogui.hotkey("ctrl", "command", "f") + else: + pyautogui.hotkey("alt", "f10") + time.sleep(2) + + _, screen_height = pyautogui.size() + left, top, _, window_height = window_bounds(app.pid) + rail_x = left + 36 + rail_top = top + 48 + rail_bottom = min(top + window_height - 80, top + 680, screen_height - 40) + # The shared desktop rail is a 72-point strip at the left edge of the window. Scan + # its account slots until the Slack flyout's two fixture workspaces are visible. + point = None + button_point = None + deadline = time.monotonic() + 20 + while time.monotonic() < deadline and point is None: + for y in range(rail_top, rail_bottom, 20): + pyautogui.moveTo(rail_x, y, duration=0.05) + time.sleep(0.35) + found = words(OUT / "probe.png") + if contains(found, "Harbor Labs") and contains(found, "Fernhill Collective"): + point = next(((x, yy) for text, x, yy in found if text == "Fernhill"), None) + if point: + button_point = (rail_x, y) + break + record("the Slack rail icon opens both workspace choices", point is not None, "probe.png") + if not point: + raise RuntimeError("the Slack workspace flyout did not appear") + + pyautogui.click(*point) + wait_for("volunteers", "selected-workspace") + time.sleep(1) + + # Keyboard path: focus the Slack rail button, open its menu with Down, then select + # Harbor Labs with Down and Enter. This keeps switching usable without a pointer. + pyautogui.click(*button_point) + pyautogui.press("down") + menu_words = wait_for("Workspaces", "keyboard-menu") + harbor_y = next(y for text, _, y in menu_words if text == "harbor") + fernhill_y = next(y for text, _, y in menu_words if text == "fernhill") + pyautogui.press("down", presses=1 if harbor_y < fernhill_y else 2) + pyautogui.press("enter") + wait_for("announcements", "keyboard-selected-workspace") + finally: + stop(app) + stop(daemon) + + +def main(): + OUT.mkdir(parents=True, exist_ok=True) + (OUT / "steps.jsonl").write_text("", encoding="utf-8") + with tempfile.TemporaryDirectory(prefix="rail-workspace-switcher-") as data: + run(Path(data)) + + +if __name__ == "__main__": + try: + main() + except (OSError, RuntimeError, subprocess.SubprocessError, ValueError) as error: + print(error, file=sys.stderr, flush=True) + raise SystemExit(1) diff --git a/e2e/scenarios/rail-workspace-switcher/drive.windows.ps1 b/e2e/scenarios/rail-workspace-switcher/drive.windows.ps1 new file mode 100644 index 00000000..75e56433 --- /dev/null +++ b/e2e/scenarios/rail-workspace-switcher/drive.windows.ps1 @@ -0,0 +1,3 @@ +$ErrorActionPreference = 'Stop' +python "$PSScriptRoot\drive.py" windows +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } diff --git a/e2e/scenarios/rail-workspace-switcher/scenario.json b/e2e/scenarios/rail-workspace-switcher/scenario.json new file mode 100644 index 00000000..6f6c9132 --- /dev/null +++ b/e2e/scenarios/rail-workspace-switcher/scenario.json @@ -0,0 +1,12 @@ +{ + "id": "rail-workspace-switcher", + "title": "Hover a network rail icon to switch workspaces or servers", + "platforms": ["windows", "macos", "linux"], + "not_applicable": { + "android": "Phone layouts have no hover input; the rail quick switcher is desktop-only.", + "ios": "Phone layouts have no hover input; the rail quick switcher is desktop-only." + }, + "needs": [], + "release": false, + "max_still_seconds": 60 +} From 28c6840270df25434bd94d9f9dd79897b2dd562b Mon Sep 17 00:00:00 2001 From: Skull Date: Thu, 3 Dec 2026 17:14:16 -0600 Subject: [PATCH 5/5] fix: close rail switcher when focus leaves --- crates/tinyclient/src/gui/layout.rs | 5 ++- crates/tinyclient/src/gui/rail.rs | 49 ++++++++++++++++++++--------- crates/tinyclient/src/gui/state.rs | 8 ++++- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/crates/tinyclient/src/gui/layout.rs b/crates/tinyclient/src/gui/layout.rs index 10613cc1..37b9af43 100644 --- a/crates/tinyclient/src/gui/layout.rs +++ b/crates/tinyclient/src/gui/layout.rs @@ -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; @@ -161,6 +162,7 @@ pub struct State { pub flyout: Option, /// Keyboard focus while the rail's workspace/server menu is open. pub flyout_focus: gpui::FocusHandle, + pub rail_focus: HashMap, pub right: Option, /// The row of the first-launch card that has the keyboard. pub first_run: usize, @@ -180,7 +182,7 @@ pub struct State { } impl State { - pub(super) fn new(flyout_focus: gpui::FocusHandle) -> Self { + pub(super) fn new(flyout_focus: gpui::FocusHandle, rail_focus: HashMap) -> Self { State { sidebar_width: SIDEBAR_WIDTH, right_width: RIGHT_WIDTH, @@ -190,6 +192,7 @@ impl State { menu: None, flyout: None, flyout_focus, + rail_focus, right: None, first_run: 0, details_channels: false, diff --git a/crates/tinyclient/src/gui/rail.rs b/crates/tinyclient/src/gui/rail.rs index 3e69f644..716c6aa2 100644 --- a/crates/tinyclient/src/gui/rail.rs +++ b/crates/tinyclient/src/gui/rail.rs @@ -38,6 +38,8 @@ pub struct Flyout { pub button: bool, pub list: bool, pub shown: bool, + pub keyboard: bool, + pub opener: Option, } /// One button of the rail. @@ -99,6 +101,7 @@ impl Shell { .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" { @@ -130,8 +133,10 @@ impl Shell { fn rail_keyboard_open(&mut self, network: Network, window: &mut Window, cx: &mut Context) { 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.); - self.layout_state.flyout = Some(Flyout { network, at, button: true, list: false, shown: true }); + 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(); } @@ -145,7 +150,7 @@ impl Shell { 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 }); + 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| { @@ -160,19 +165,25 @@ impl Shell { if let Some(flyout) = self.layout_state.flyout.as_mut().filter(|f| f.network == network) { flyout.button = false; } - self.rail_flyout_lapse(network, GRACE, cx); + 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, grace: Duration, cx: &mut Context) { + fn rail_flyout_lapse(&mut self, network: Network, window: gpui::AnyWindowHandle, grace: Duration, cx: &mut Context) { cx.spawn(async move |this, cx| { cx.background_executor().timer(grace).await; - let _ = this.update(cx, |this, cx| { - if this.layout_state.flyout.as_ref().is_some_and(|f| f.network == network && !f.button && !f.list) { - this.layout_state.flyout = None; - cx.notify(); - } + 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(); @@ -273,7 +284,10 @@ impl Shell { "down" => window.focus_next(cx), "up" => window.focus_prev(cx), "escape" => { - this.layout_state.flyout = None; + 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, @@ -281,19 +295,26 @@ impl Shell { cx.stop_propagation(); cx.notify(); })) - .on_hover(cx.listener(move |this, over: &bool, _, cx| { + .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, Duration::from_millis(200), cx); + 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) { + 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.layout_state.flyout = None; + self.close_rail_flyout(window, cx); if network == Network::Discord { self.visit(Mode::Space(key), window, cx); } else { @@ -308,7 +329,7 @@ impl Shell { } fn show_all_rail_spaces(&mut self, network: Network, window: &mut Window, cx: &mut Context) { - self.layout_state.flyout = None; + self.close_rail_flyout(window, cx); self.visit(Mode::Network(network), window, cx); } diff --git a/crates/tinyclient/src/gui/state.rs b/crates/tinyclient/src/gui/state.rs index 40a403a4..a1e32d0d 100644 --- a/crates/tinyclient/src/gui/state.rs +++ b/crates/tinyclient/src/gui/state.rs @@ -344,7 +344,13 @@ impl Shell { call_dock: Some(call::dock), search: Some(Self::open_message_search), }, - layout_state: layout::State::new(cx.focus_handle()), + 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(),