Skip to content
Merged
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
6 changes: 5 additions & 1 deletion docs/specifications/ephemeral_window.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ by `EphemeralWindowWidget`.
only raises an existing window, or a failed launch — stays readable here
instead of becoming a blank card.
- **Opened** — once a meta window is attributed, `EphemeralWindowWidget` renders
it (`WindowWidget`) maximized.
it (`WindowWidget`) maximized and hands it the keyboard: focus moves to the
window's surface node, so keys the client handles (`Enter`, `Space`, `Escape`,
`Tab`, directions) fall through to it instead of being consumed by the
overview's search pane. While the surface has not been matched yet, the
placeholder holds the keyboard for the same reason.
- **Closed** — closing the native window removes the window. Closing while no
native window is owned (the waiting case above) removes the window directly
and cancels its pending launch (`systemctl --user stop` on the tracked
Expand Down
7 changes: 6 additions & 1 deletion docs/specifications/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ focused context's ancestry**. The `ActivateIntent` handler is therefore
registered only by the search pane (`SearchEngine`) and the result lists, so
`Enter` acts there but is ignored — and forwarded to the focused client —
everywhere else, and never steals `Enter` from a focused client surface or an
unrelated text field. `DismissIntent` is registered by the overview, so
unrelated text field. A client surface that owns the keyboard (`SurfaceFocus`)
shadows activation, dismissal and traversal keys with an action that does not
consume them, so they fall through to the client; the overview hands the
keyboard to an ephemeral window's surface when it is displayed, so `Enter`
reaches the application rather than the search pane that launched it.
`DismissIntent` is registered by the overview, so
`Escape` hides it, but a dialog or menu opened above it consumes the key first.
`Super+Tab` is registered above both overview panes, so it keeps acting no
matter which part of the overview holds focus.
Expand Down
14 changes: 12 additions & 2 deletions docs/specifications/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ displayed content and `Overview.selectedContent` resolves it (falling back to
the Helm when stale). Opening the overview keeps the current selection and
`show(windowId)` opens it to a specific window (used when bringing a window into
view). Each tab shows its icon and a label — `Helm`, the window's application
name, or the file name. The content cross-fades when the selection changes, and
only the selected button is tinted — unselected buttons use a low surface.
name, or the file name. Selecting a window's tab displays it and hands it the
keyboard. The content cross-fades when the selection changes, and only the
selected button is tinted — unselected buttons use a low surface.

Selecting a file in the Files mode opens or reuses a **preview tab** and
displays it:
Expand Down Expand Up @@ -72,6 +73,15 @@ between the panes and the same direction keys then walk the Helm's controls,
switches and notification list. Focus drives the semantic focus, so the
selection is what assistive technology follows.

A displayed ephemeral window owns the keyboard: launching an application hands
focus to its surface as soon as it is mapped (the launch placeholder holds it
until then), and clicking the window or selecting its panel tab hands it back.
The surface's `SurfaceFocus` lets `Enter`, `Space`, `Escape`, `Tab` and the
direction keys fall through to the client, so they act in the application
instead of the overview — without the hand-off the search pane keeps the Flutter
focus and `Enter` would launch another instance. Use the `Super` chords to move
the keyboard back to the search pane to keep launching.

The navigation applies to all three modes: `Super+W`/`Super+S` move through the
mode's results and `Enter` activates them — a file opens with its handler, an
application is launched as an ephemeral window, and a settings row is activated.
Expand Down
27 changes: 23 additions & 4 deletions src/shell/lib/overview/widget/overview_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@ class OverviewContentPane extends HookConsumerWidget {
overviewStateProvider(screenId).select((state) => state.selectedContent),
);

final node = useFocusNode();
final node = useFocusNode(debugLabel: 'OverviewWindowFocus');

// Selecting a window's tab hands it the keyboard. `selectContent` is a
// no-op when that window is already the displayed content (the common
// re-click): nothing remounts, so the window widget's own focus hand-off
// never runs and the keyboard would stay where it was (e.g. the search
// field), where `Enter` would launch another instance.
void selectContent(OverviewContent content) {
ref
.read(overviewStateProvider(screenId).notifier)
.selectContent(content.contentId);
if (content is WindowOverviewContent) {
node.requestFocus();
}
}

// Directional navigation inside the content pane (the Helm's controls, a
// preview, an embedded window) uses the framework's directional focus:
Expand All @@ -45,7 +59,7 @@ class OverviewContentPane extends HookConsumerWidget {
padding: const EdgeInsets.all(16),
child: Column(
children: [
const _OverviewContentPanel(),
_OverviewContentPanel(onSelect: selectContent),
const SizedBox(height: 16),
Expanded(
child: AnimatedSwitcher(
Expand All @@ -72,7 +86,12 @@ class OverviewContentPane extends HookConsumerWidget {
}

class _OverviewContentPanel extends HookConsumerWidget {
const _OverviewContentPanel();
const _OverviewContentPanel({required this.onSelect});

/// Selects a content; the pane uses it to also hand a selected window the
/// keyboard.
final ValueChanged<OverviewContent> onSelect;

@override
Widget build(BuildContext context, WidgetRef ref) {
final screenId = CurrentScreenId.of(context);
Expand Down Expand Up @@ -106,7 +125,7 @@ class _OverviewContentPanel extends HookConsumerWidget {
OverviewContentTab(
content: content,
isSelected: content.contentId == selectedContentId,
onSelect: () => notifier.selectContent(content.contentId),
onSelect: () => onSelect(content),
onClose: () => notifier.closeContent(content.contentId),
),
],
Expand Down
92 changes: 61 additions & 31 deletions src/shell/lib/window/widget/ephemeral_window.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:material_ui/material_ui.dart';
import 'package:shell/application/widget/logs_viewer.dart';
Expand Down Expand Up @@ -27,38 +28,67 @@ class EphemeralWindowWidget extends HookConsumerWidget {

final metaWindowId = window.metaWindowId;
final fileChooser = ref.watch(fileChooserForWindowProvider(windowId));
if (metaWindowId != null) {
return Stack(
fit: StackFit.expand,
children: [
WindowWidget(
metaWindowId: metaWindowId,
focusNode: focusNode,
dialogMetaWindowList: ref
.watch(dialogSetForWindowProvider(window.windowId))
.map((element) {
return ref
.read(dialogWindowStateProvider(element))
.metaWindowId;
})
.toList(),
),
// The trusted file chooser renders inside the window container,
// attached to the window that asked for it (like a native dialog).
if (fileChooser != null) FileChooserModal(request: fileChooser),
],
);
}

// No native window yet: an ephemeral launch may never produce one (a
// single-instance app that only raises its existing window, a launch that
// fails). Show the execution logs in a dark terminal container so the tile
// is never a blank, unclosable card while it waits for its surface.
return _EphemeralLaunchView(
pid: window.pid,
onClose: () => ref
.read(ephemeralWindowStateProvider(windowId).notifier)
.closeWindow(),
// While the launch has no surface, the window owns a placeholder focus
// target; once the surface exists, the keyboard goes to the surface node.
// Handing the keyboard over is what makes the reported bug go away: the
// surface wraps itself in `SurfaceFocus`, which lets `Enter`/`Space`/
// `Escape` and the direction keys fall through to the client, while the
// placeholder has no actions at all, so those keys are not consumed by the
// overview's search pane either. Without the hand-off the search pane keeps
// the Flutter focus and its `ActivateIntent` fires, launching another
// instance instead of reaching the focused client.
final waitingFocusNode = useFocusNode(debugLabel: 'EphemeralWindowWaiting');
final activeFocusNode = metaWindowId == null ? waitingFocusNode : focusNode;
useEffect(() {
activeFocusNode.requestFocus();
return null;
}, [metaWindowId]);

final content = metaWindowId != null
? Stack(
fit: StackFit.expand,
children: [
WindowWidget(
metaWindowId: metaWindowId,
focusNode: focusNode,
dialogMetaWindowList: ref
.watch(dialogSetForWindowProvider(window.windowId))
.map((element) {
return ref
.read(dialogWindowStateProvider(element))
.metaWindowId;
})
.toList(),
),
// The trusted file chooser renders inside the window container,
// attached to the window that asked for it (native-dialog like).
if (fileChooser != null) FileChooserModal(request: fileChooser),
],
)
: Focus(
// No native window yet: an ephemeral launch may never produce one
// (a single-instance app that only raises its existing window, a
// launch that fails). Show the execution logs in a dark terminal
// container so the tile is never a blank, unclosable card while it
// waits for its surface.
focusNode: waitingFocusNode,
child: _EphemeralLaunchView(
pid: window.pid,
onClose: () => ref
.read(ephemeralWindowStateProvider(windowId).notifier)
.closeWindow(),
),
);

// Clicking into the window hands it the keyboard as well. The compositor
// already activates the client on pointer down
// (`ActivateSurfaceOnPointerDown`); this keeps the Flutter focus in step,
// so a click after the launch is what `Enter`/`Space` follow.
return Listener(
behavior: HitTestBehavior.translucent,
onPointerDown: (_) => activeFocusNode.requestFocus(),
child: content,
);
}
}
Expand Down
Loading
Loading