The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
desktop(linux): draw the title bar on GNOME, menus and all
bubu-dudu56f9ecb0e247
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dartindex 5f92e10f7..1abd99efe 100644--- a/desktop/lib/screens/swarm_screen.dart+++ b/desktop/lib/screens/swarm_screen.dart@@ -42,6 +42,8 @@ import '../shortcuts/keymap_native.dart';import '../shortcuts/keymap_settings.dart';import '../state/app_state.dart';import '../state/notification_inbox.dart';+import '../widgets/linux_menu_bar.dart'+ show LinuxTitleBar, linuxTitleBarActions;import '../widgets/notification_inbox.dart';import '../widgets/workspace_notifications_button.dart';import '../state/harness_sessions.dart';@@ -234,6 +236,15 @@ class _SwarmScreenState extends State<SwarmScreen> {/// the strip stays and only the menu state and actions cross the bus.late final bool _menuHost =_native || (RuntimePlatform.isLinux && !kUnderTest);++ /// On Linux the in-window menu bar is the title bar, and search,+ /// notifications and Store sit at its right end instead of the tab strip's+ /// ([linuxTitleBarActions]).+ late final bool _titleBarActions =+ !_native &&+ RuntimePlatform.isLinux &&+ !kUnderTest &&+ LinuxTitleBar.current == LinuxTitleBar.flutter;late final SwarmProjectStore _projects =widget.projectStore ??SwarmProjectStore(storage: kUnderTest ? null : HarnessFileStore.shared);@@ -546,6 +557,9 @@ class _SwarmScreenState extends State<SwarmScreen> {@overridevoid initState() {super.initState();+ if (_titleBarActions) {+ linuxTitleBarActions.attach(this, _buildTitleBarActions);+ }app.deviceNavigationAllowed = _allowDeviceNavigation;app.deviceFormCommand = _deviceFormCommand;_pullRequest = WorkspacePullRequest(app)..addListener(_statusPrefsChanged);@@ -736,6 +750,7 @@ class _SwarmScreenState extends State<SwarmScreen> {@overridevoid dispose() {+ linuxTitleBarActions.detach(this);_closeDaemonHint();app.foreground.removeListener(_daemonEnvironmentChanged);if (app.deviceNavigationAllowed == _allowDeviceNavigation) {@@ -6256,7 +6271,39 @@ class _SwarmScreenState extends State<SwarmScreen> {);@override- Widget build(BuildContext context) => _buildWorkspace(context);+ Widget build(BuildContext context) {+ // The title bar draws this screen's controls from outside its subtree, so+ // it redraws after each of this screen's builds — after, because asking+ // for a build during one is what setState-during-build forbids.+ if (_titleBarActions) {+ WidgetsBinding.instance.addPostFrameCallback((_) {+ if (mounted) linuxTitleBarActions.refresh();+ });+ }+ return _buildWorkspace(context);+ }++ /// Search, notifications and Store, for the right end of the Linux title+ /// bar — the same three the tab strip draws on every other host.+ Widget _buildTitleBarActions(BuildContext context) {+ final theme = terminalThemeFor(+ grid.AppTheme.palette.value,+ terminalThemeStore.value,+ );+ return Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ _searchButton(theme),+ _notificationsButton(theme),+ WorkspaceStoreButton(+ key: const ValueKey('swarm-store-button'),+ width: WorkspaceStoreButton.widthOf(context),+ tooltip: 'Harness Store ${_keymap.hint('app.store') ?? ''}',+ onPressed: _shortcutsEnabled ? _openStore : null,+ ),+ ],+ );+ }Widget _buildWorkspace(BuildContext context) => ListenableBuilder(listenable: Listenable.merge([app, _projects, _learning]),@@ -6902,14 +6949,16 @@ class _SwarmScreenState extends State<SwarmScreen> {WorkspaceStoreButton.widthOf(context),math.max(0.0, constraints.maxWidth - cell.width * 22),);+ // Store, search and notifications — none of it here when the title bar+ // holds them.+ final actionsWidth = _titleBarActions ? 0.0 : storeWidth + cell.width * 8;final leadingWidth = chrome?.leadingWidth(context) ?? 0.0;final tabBudget = math.max(0.0,constraints.maxWidth -cell.width * 6 -- storeWidth -+ actionsWidth -(_slotShown ? 44 : 0) -- cell.width * 8 -leadingWidth,);_tabWidths = [@@ -7068,14 +7117,16 @@ class _SwarmScreenState extends State<SwarmScreen> {tooltip: 'New Tab ${_keymap.hint('swarm.new') ?? ''}',),const Spacer(),- _searchButton(theme),- _notificationsButton(theme),- WorkspaceStoreButton(- key: const ValueKey('swarm-store-button'),- width: storeWidth,- tooltip: 'Harness Store ${_keymap.hint('app.store') ?? ''}',- onPressed: _shortcutsEnabled ? _openStore : null,- ),+ if (!_titleBarActions) ...[+ _searchButton(theme),+ _notificationsButton(theme),+ WorkspaceStoreButton(+ key: const ValueKey('swarm-store-button'),+ width: storeWidth,+ tooltip: 'Harness Store ${_keymap.hint('app.store') ?? ''}',+ onPressed: _shortcutsEnabled ? _openStore : null,+ ),+ ],if (kIsWeb && _slotShown) _daemonTabButton(),SizedBox(width: cell.width),],diff --git a/desktop/lib/widgets/linux_menu_bar.dart b/desktop/lib/widgets/linux_menu_bar.dartindex 9656e889e..8e74efdf0 100644--- a/desktop/lib/widgets/linux_menu_bar.dart+++ b/desktop/lib/widgets/linux_menu_bar.dart@@ -38,6 +38,54 @@ typedef AppMenuActionHandler = Future<void> Function(String action);/// tests at large keep the bar off by default: it is window chrome — on macOS/// it costs the layout nothing at all — and pane-geometry assertions should/// not depend on whether the Linux build is drawing it.+/// Who draws the Linux window's title bar — decided by the runner+/// (`my_application.cc`) and handed over as `HARNESS_LINUX_TITLE_BAR`.+enum LinuxTitleBar {+ /// GNOME: no GTK caption; this bar is the title bar, window buttons and all.+ flutter,++ /// A tiling compositor: no title bar anywhere, nor buttons to draw.+ none,++ /// A window manager's own caption sits above this bar.+ native;++ static LinuxTitleBar get current =>+ switch (RuntimePlatform.environment['HARNESS_LINUX_TITLE_BAR']) {+ 'flutter' => flutter,+ 'none' => none,+ _ => native,+ };+}++/// The workspace's own controls for the right end of the Linux title bar —+/// search, notifications, Store — which the workspace draws in its tab strip+/// everywhere else. The workspace installs a builder while it is on screen and+/// [refresh]es after each of its builds, so the bar redraws with it.+class LinuxTitleBarActions extends ChangeNotifier {+ Object? _owner;+ WidgetBuilder? _builder;++ WidgetBuilder? get builder => _builder;++ void attach(Object owner, WidgetBuilder builder) {+ _owner = owner;+ _builder = builder;+ notifyListeners();+ }++ void detach(Object owner) {+ if (!identical(_owner, owner)) return;+ _owner = null;+ _builder = null;+ notifyListeners();+ }++ void refresh() => notifyListeners();+}++final linuxTitleBarActions = LinuxTitleBarActions();+class LinuxMenuBar extends StatefulWidget {const LinuxMenuBar({super.key,@@ -89,7 +137,7 @@ class _LinuxMenuBarState extends State<LinuxMenuBar> {/// and a margin for the screen edge; past that a menu really does scroll.MenuStyle get _panelStyle {final height = MediaQuery.sizeOf(context).height;- return grid.AppMenu.style(maxHeight: height - 30 - 24);+ return grid.AppMenu.style(maxHeight: height - 36 - 24);}@override@@ -98,36 +146,76 @@ class _LinuxMenuBarState extends State<LinuxMenuBar> {final visible = widget.visible ?? (RuntimePlatform.isLinux && !kUnderTest);if (!visible) return const SizedBox.shrink();grid.AppTheme.watch(context);- // The strip spans the window with the menus at its left end, where a menu- // bar sits; the shell's Column would otherwise centre a strip only as- // wide as its menus.+ // The full set of menus outgrows a narrow window; a menubar that scrolls+ // beats one that clips its last menus into nothing.+ final menus = ScrollConfiguration(+ behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),+ child: SingleChildScrollView(+ scrollDirection: Axis.horizontal,+ padding: const EdgeInsets.symmetric(horizontal: 6),+ child: Row(+ children: [+ _menu('Harness', _buildHarnessMenu()),+ _menu('File', _buildFileMenu()),+ _menu('Edit', _buildEditMenu()),+ _menu('View', _buildViewMenu(), onOpen: _readFullScreen),+ _menu('History', _buildHistoryMenu()),+ _menu('Window', _buildWindowMenu()),+ _menu('Help', _buildHelpMenu()),+ ],+ ),+ ),+ );+ final decoration = BoxDecoration(+ color: grid.AppPalette.panelBg,+ border: Border(bottom: BorderSide(color: grid.AppGlass.hair)),+ );+ // Under a window manager's caption, or a tiling compositor's none, the+ // bar is a strip of menus across the window, left-aligned where a menu bar+ // sits; the shell's Column would otherwise centre one only as wide as its+ // menus.+ if (LinuxTitleBar.current != LinuxTitleBar.flutter) {+ return Container(+ width: double.infinity,+ height: 30,+ alignment: Alignment.centerLeft,+ decoration: decoration,+ child: menus,+ );+ }+ // Where nothing else draws a caption (GNOME), the bar IS the title bar,+ // one row: the menus; the space after them, which drags the window as a+ // caption would; the workspace's search, notifications and Store; and the+ // window's own buttons.return Container(width: double.infinity,- height: 30,- alignment: Alignment.centerLeft,- decoration: BoxDecoration(- color: grid.AppPalette.panelBg,- border: Border(bottom: BorderSide(color: grid.AppGlass.hair)),- ),- // The full set of menus outgrows a narrow window; a menubar that- // scrolls beats one that clips its last menus into nothing.- child: ScrollConfiguration(- behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),- child: SingleChildScrollView(- scrollDirection: Axis.horizontal,- padding: const EdgeInsets.symmetric(horizontal: 6),- child: Row(- children: [- _menu('Harness', _buildHarnessMenu()),- _menu('File', _buildFileMenu()),- _menu('Edit', _buildEditMenu()),- _menu('View', _buildViewMenu(), onOpen: _readFullScreen),- _menu('History', _buildHistoryMenu()),- _menu('Window', _buildWindowMenu()),- _menu('Help', _buildHelpMenu()),- ],+ height: 36,+ decoration: decoration,+ child: Row(+ children: [+ // The menus sit over the drag area rather than beside it, so the+ // area takes whatever they leave and the controls after it reach the+ // right edge; a loose Flexible would keep its unused share instead.+ // Nothing is drawn inside the area itself, so its double-click to+ // maximize holds up no control (the 300ms wait at WindowDragArea).+ Expanded(+ child: Stack(+ children: [+ const Positioned.fill(+ child: DragToMoveArea(child: SizedBox.expand()),+ ),+ Align(alignment: Alignment.centerLeft, child: menus),+ ],+ ),),- ),+ ListenableBuilder(+ listenable: linuxTitleBarActions,+ builder: (context, _) =>+ linuxTitleBarActions.builder?.call(context) ??+ const SizedBox.shrink(),+ ),+ const _WindowButtons(),+ ],),);}@@ -772,3 +860,104 @@ class _MenuLabelRow extends StatelessWidget {);}}++/// Minimize, maximize and close, for a window no manager draws a caption on+/// ([LinuxTitleBar.flutter]). GNOME's own order and shapes: the close button+/// last, a square that becomes two when the window already fills the screen.+class _WindowButtons extends StatefulWidget {+ const _WindowButtons();++ @override+ State<_WindowButtons> createState() => _WindowButtonsState();+}++class _WindowButtonsState extends State<_WindowButtons> with WindowListener {+ bool _maximized = false;++ @override+ void initState() {+ super.initState();+ windowManager.addListener(this);+ windowManager.isMaximized().then((value) {+ if (mounted) setState(() => _maximized = value);+ });+ }++ @override+ void dispose() {+ windowManager.removeListener(this);+ super.dispose();+ }++ @override+ void onWindowMaximize() => setState(() => _maximized = true);++ @override+ void onWindowUnmaximize() => setState(() => _maximized = false);++ @override+ Widget build(BuildContext context) => Padding(+ padding: const EdgeInsets.only(left: 6, right: 8),+ child: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ _WindowButton(+ key: const ValueKey('linux-window-minimize'),+ tooltip: 'Minimize',+ icon: LucideIcons.minus,+ onPressed: windowManager.minimize,+ ),+ _WindowButton(+ key: const ValueKey('linux-window-maximize'),+ tooltip: _maximized ? 'Restore' : 'Maximize',+ icon: _maximized ? LucideIcons.copy : LucideIcons.square,+ onPressed: () => _maximized+ ? windowManager.unmaximize()+ : windowManager.maximize(),+ ),+ _WindowButton(+ key: const ValueKey('linux-window-close'),+ tooltip: 'Close',+ icon: LucideIcons.x,+ // Through window_manager, as Quit does, so the exit lifecycle runs.+ onPressed: windowManager.close,+ ),+ ],+ ),+ );+}++class _WindowButton extends StatelessWidget {+ const _WindowButton({+ super.key,+ required this.tooltip,+ required this.icon,+ required this.onPressed,+ });++ final String tooltip;+ final IconData icon;+ final VoidCallback onPressed;++ @override+ Widget build(BuildContext context) => Padding(+ padding: const EdgeInsets.only(left: 6),+ child: Tooltip(+ message: tooltip,+ child: Material(+ color: grid.AppSurface.recess,+ shape: const CircleBorder(),+ clipBehavior: Clip.antiAlias,+ child: InkWell(+ onTap: onPressed,+ hoverColor: grid.AppSurface.recessHover,+ child: SizedBox(+ width: 24,+ height: 24,+ child: Icon(icon, size: 14, color: grid.AppPalette.textPrimary),+ ),+ ),+ ),+ ),+ );+}diff --git a/desktop/linux/runner/my_application.cc b/desktop/linux/runner/my_application.ccindex 0f60eb8f7..51270632c 100644--- a/desktop/linux/runner/my_application.cc+++ b/desktop/linux/runner/my_application.cc@@ -173,37 +173,34 @@ static void my_application_activate(GApplication* application) {icon_path = g_build_filename(exe_dir, "harness.png", nullptr);}- // Use a header bar when running in GNOME as this is the common style used- // by applications and is the setup most users will be using (e.g. Ubuntu- // desktop) — there it is the only way to drag, minimize or close a GTK- // window.- // If running on X and not using GNOME then just use a traditional title bar- // in case the window manager does more exotic layout, e.g. tiling.- // Under a tiling compositor draw no title bar at all; on Wayland GTK would- // otherwise fall back to a client-side one of its own.- gboolean use_header_bar = TRUE;+ // Who draws the window's title bar, told to Dart through the environment+ // (HARNESS_LINUX_TITLE_BAR, read by linux_menu_bar.dart):+ // - "flutter": GNOME, the common case (e.g. Ubuntu desktop). The app draws+ // one row itself — its menus, search, notifications, Store and the+ // window buttons — where a GTK header bar would have taken a row of its+ // own above them. GTK keeps drawing the shadow and the resize edges+ // (client-side decorations) round a titlebar widget that is never shown.+ // - "none": a tiling compositor. Windows there carry no title bar; on+ // Wayland GTK would otherwise fall back to a client-side one of its own.+ // - "native": X without GNOME, where the window manager may lay windows out+ // in exotic ways, so it keeps its own traditional title bar.+ const gchar* title_bar = "flutter";if (is_tiling_session()) {- use_header_bar = FALSE;+ title_bar = "none";gtk_window_set_decorated(window, FALSE);- }+ } else {#ifdef GDK_WINDOWING_X11- GdkScreen* screen = gtk_window_get_screen(window);- if (GDK_IS_X11_SCREEN(screen)) {- const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);- if (g_strcmp0(wm_name, "GNOME Shell") != 0) {- use_header_bar = FALSE;+ GdkScreen* screen = gtk_window_get_screen(window);+ if (GDK_IS_X11_SCREEN(screen)) {+ const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);+ if (g_strcmp0(wm_name, "GNOME Shell") != 0) title_bar = "native";}- }#endif- if (use_header_bar) {- // The stock title, name only, as GNOME's own apps caption their windows;- // the icon already sits in the dock and the task switcher.- GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());- gtk_widget_show(GTK_WIDGET(header_bar));- gtk_header_bar_set_title(header_bar, "Harness");- gtk_header_bar_set_show_close_button(header_bar, TRUE);- gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));}+ if (g_strcmp0(title_bar, "flutter") == 0) {+ gtk_window_set_titlebar(window, gtk_fixed_new());+ }+ g_setenv("HARNESS_LINUX_TITLE_BAR", title_bar, TRUE);// Keep the native window metadata correct even when a custom header is// drawn. Window managers use it for non-GNOME captions and accessibility.gtk_window_set_title(window, "Harness");