Просмотр исходного кода

wm: add a Windows-like start menu

The NebOS banner is now the start button.  It opens a WM-drawn overlay that lists every self-contained GUI app (Terminal, Files, Web, Gallery, Chat, Clock, Text editor, Colors, Mines, Cards, Disks, Tasks, Settings, Date & Time) with hover highlighting and adaptive row heights.

The final Power row opens a submenu that reboots or powers off through SYS_SPAWN_KCMD.  The old top-bar launcher buttons are gone; WM_BTN_* is replaced by WM_BAR_LEFT_END, and the docs and AGENTS.md map are updated.
Johannes Zellner 2 дней назад
Родитель
Сommit
4e792643e5
6 измененных файлов с 494 добавлено и 199 удалено
  1. 31 16
      AGENTS.md
  2. 1 1
      docs/filesystems.html
  3. 21 5
      docs/graphics.html
  4. 3 3
      docs/userland.html
  5. 4 49
      include/wm_abi.h
  6. 434 125
      user/apps/wm/ucmd_wm.c

+ 31 - 16
AGENTS.md

@@ -503,9 +503,23 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   window behind it.  While dragged or resized the WM owns the pointer
   (`SYS_WM_MOUSE_CAPTURE`), so canvas clients see no held button and cannot
   start a scrollbar drag.  The kernel hit-test uses the same order.
+  The NebOS banner in the top-left corner is the start button.  Clicking it
+  opens the WM's Windows-like start menu, a flat overlay panel drawn by the
+  WM (not a window, so it does not consume a `WM_MAX_WINDOWS` slot).  It
+  lists every self-contained GUI app in the pack -- Terminal, Files, Web,
+  Gallery, Chat, Clock, Text editor, Colors, Mines, Cards, Disks, Tasks,
+  Settings and Date & Time -- with a coloured letter tile and a hover
+  highlight, shrinks its row height to fit short panels, and closes on an
+  outside press.  The last row, Power, opens a submenu with Reboot and Power
+  off; both spawn the privileged kernel command through `SYS_SPAWN_KCMD`
+  with no tty.  The menu
+  floats above every window and is redrawn with the bar tooltip and OSD
+  overlays.  The bar notice and the right-aligned status never draw left of
+  `WM_BAR_LEFT_END` (`wm_abi.h`).
   The right-aligned date/time text is itself a click target: `draw_bar()`
   records its rectangle, the pointer highlights it, and a click opens the
-  control panel (the `Clock` launcher still opens the analog clock).
+  control panel (whose Date & Time section has the editor; the start menu's
+  Clock entry opens the analog clock).
   The rightmost bar item is the AC/battery status icon: the Adwaita
   `ac-adapter` symbol while the adapter is online and the `battery` outline
   with our own level fill inside on battery.  Hovering it paints
@@ -536,12 +550,11 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   the origin directly).  An outside press dismisses the
   popover and then continues with the normal click handling; a second click
   on a status target toggles it.
-  `Chat` spawns `/ramfs/bin/chat`, `Tasks` spawns `/ramfs/bin/process` (the
-  task manager) and the last launcher, `Disks`, spawns `/ramfs/bin/disks`
-  (the storage manager); `WM_BTN_END_X` (`wm_abi.h`) is the launchers' right
-  edge, and the bar notice and the right-aligned status never draw left of
-  it.  When the full date/time would cross that edge, the clock falls back to
-  `MM-DD HH:MM` and is hidden if even that does not fit.
+  The start menu entries spawn the same pack binaries (`Chat` ->
+  `/ramfs/bin/chat`, `Tasks` -> `/ramfs/bin/process`, `Disks` ->
+  `/ramfs/bin/disks`, ...).  When the full date/time would cross
+  `WM_BAR_LEFT_END`, the clock falls back to `MM-DD HH:MM` and is hidden if
+  even that does not fit.
   `terminal.c` keeps the privileged kernel command
   registry for the ring-3 terminal (`SYS_SPAWN_KCMD` / `term_kcmd_spawn`),
   but the kernel terminal entry/shell and the cell-window ABI are gone.
@@ -701,10 +714,11 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   sees the right century.  `SYS_RTC_GET`/`SYS_RTC_SET` (104/105)
   expose the full `struct sys_datetime`; `SYS_RTC_HMS`/`SYS_RTC_DATETIME`
   (56/69) stay the small read-only views.  The WM top-bar date/time is a
-  click target that spawns `/ramfs/bin/settime`, whose "Sync NTP" button
-  fetches UTC through `SYS_NTP_SYNC` and writes it with `SYS_RTC_SET`; the
-  `date` command prints the classic `date` line and a small `+FORMAT`
-  subset.
+  click target that opens the control panel's inline Date & Time editor; the
+  start menu's Date & Time entry spawns `/ramfs/bin/settime`, whose "Sync
+  NTP" button fetches UTC through `SYS_NTP_SYNC` and writes it with
+  `SYS_RTC_SET`; the `date` command prints the classic `date` line and a
+  small `+FORMAT` subset.
 - **Fonts**: `ufont.c/h`, `ufont_ttf.c`, `ufont_draw.c`, `ufont_file.c` — a
   fixed-point (26.6, no FPU) TrueType parser and antialiased rasterizer for
   ring-3 text.  The byte/Latin-1 path remains the default; cmap format 4 and
@@ -801,7 +815,7 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `kernel-dev`); use `net-install` for that.  `target=auto` picks the only
   non-USB NebOS disk.
 - **Storage manager / mount policies**: `ucmd_disks.c` (`disks`, the
-  top-bar `Disks` launcher and the `Disks` button in the `files` toolbar) is the ngui view of storage; the
+  start menu's `Disks` entry and the `Disks` button in the `files` toolbar) is the ngui view of storage; the
   `storage` command stays the text view.  It lists the present block
   devices (empty IDE/eMMC slots are hidden), reads sector 0 and each
   partition's first sector with `SYS_BLK_READ` (119, one 512-byte sector,
@@ -1155,7 +1169,8 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `CURSOR_DEFAULT`; a WM restart clears the override.  The ring-3 WM
   overrides with resize arrows on the resize band and while
   resizing, the move cross during a title-bar drag
-  (once it moved), and a hand over launchers and the status area.  ngui
+  (once it moved), and a hand over the start button, the start menu and the
+  status area.  ngui
   resets `ui->cursor` to the arrow for every redrawn frame (begin returned
   1), `ngui_text_input` asks for the I-beam (not-allowed when disabled),
   apps use `ngui_cursor_rect()`/`ngui_set_cursor()`, and `ngui_end_ex()`
@@ -1503,7 +1518,7 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   pauses the follow), colours `vfs:`/`blk:`/`[boot]` lines, and closes with
   Esc or the title-bar X.
 - **Process monitor**: `ucmd_process.c` — the graphical task manager (`process`
-  or the top bar's `Tasks` button), the ngui counterpart of `top`.  It
+  or the start menu's `Tasks` entry), the ngui counterpart of `top`.  It
   samples once per second and keeps 60 s
   histories of CPU busy (summed `SYS_SCHEDINFO` idle ticks over all CPUs),
   physical memory in use (`SYS_MEMINFO`) and NIC throughput (the 32-bit frame
@@ -1978,8 +1993,8 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   loads FAT ELFs through `kmalloc` now (the old 16 KB `fat_load_buf` is gone)
   and wraps the load in `sys_fs_enter/exit`,
   since the floppy needs IRQ 6.
-- **Chat client**: `ucmd_chat.c` (`chat [config-path]`, top-bar `Chat`
-  button) is a native Cloudron Chat client on ngui: channel/DM sidebar with
+- **Chat client**: `ucmd_chat.c` (`chat [config-path]`, start menu `Chat`
+  entry) is a native Cloudron Chat client on ngui: channel/DM sidebar with
   unread badges, presence dots and previews; a timeline with circular
   profile-picture avatars (initials until the picture loads, or when there is
   none), author grouping, UTC times, day headers, reply snippets, inline

+ 1 - 1
docs/filesystems.html

@@ -325,7 +325,7 @@
 		<h2>Storage manager &amp; mount policies</h2>
 		<p>
 			<code>disks</code> (<span class="file">ucmd_disks.c</span>, also the
-			top-bar <em>Disks</em> launcher and the <em>Disks</em> button in
+			start menu's <em>Disks</em> entry and the <em>Disks</em> button in
 			<code>files</code>) is the ngui front end to
 			storage; <code>storage</code> stays the text view. It lists every
 			present block device (<code>SYS_BLKDEV</code>), reads sector 0 and

+ 21 - 5
docs/graphics.html

@@ -146,7 +146,7 @@
 		<h2>Window manager</h2>
 		<p>
 			The WM is a process that owns the desktop and a fixed array of eight
-			windows. It draws a system bar with the banner, launcher buttons,
+			windows. It draws a system bar with the NebOS start button, the
 			clock, the temperature, and, on ThinkPads and Chromebooks, an
 			AC/battery status icon at the far right (the Adwaita
 			<code>ac-adapter</code> symbol on AC, and the <code>battery</code>
@@ -178,6 +178,22 @@
 			joined, asking for the WPA2 passphrase first when the AP requires
 			one.
 		</p>
+		<p>
+			The NebOS banner in the top-left is the start button. Clicking it
+			opens a Windows-like start menu drawn by the WM as a flat overlay,
+			not a window, so it floats above every canvas without consuming a
+			window slot. Every self-contained GUI application in the pack
+			gets a row with a coloured letter tile — Terminal, Files, Web,
+			Gallery, Chat, Clock, Text editor, Colors, Mines, Cards, Disks,
+			Tasks, Settings and Date &amp; Time — the pointer highlights the
+			hovered row, and an outside press dismisses the panel. Row height
+			shrinks to keep the whole list inside the work area on short
+			panels. The last row,
+			Power, opens a submenu with Reboot and Power off; both run the
+			privileged kernel command through <code>SYS_SPAWN_KCMD</code>. The
+			bar notice and the right-aligned status never draw left of
+			<code>WM_BAR_LEFT_END</code>.
+		</p>
 		<p>
 			A popover is a chromeless canvas window created with
 			<code>u_win_create_popover()</code> (<code>WIN_F_POPOVER</code>).
@@ -415,7 +431,7 @@
 			</div>
 			<div class="card">
 				<h3>process</h3>
-				<p>Graphical task manager (the top-bar <em>Tasks</em> button or <code>process</code>, the ngui counterpart of <code>top</code>): 60 s CPU, physical-memory and NIC-throughput graphs fed by one sample per second, and a sortable process table (PID, state, CPU%, memory, CPU time, name). A selected row shows its details and <em>End task</em> terminates it after a second confirming click; kernel threads and the monitor itself are protected. Headers sort, PgUp/PgDn and the wheel scroll, Esc closes.</p>
+				<p>Graphical task manager (the start menu's <em>Tasks</em> entry or <code>process</code>, the ngui counterpart of <code>top</code>): 60 s CPU, physical-memory and NIC-throughput graphs fed by one sample per second, and a sortable process table (PID, state, CPU%, memory, CPU time, name). A selected row shows its details and <em>End task</em> terminates it after a second confirming click; kernel threads and the monitor itself are protected. Headers sort, PgUp/PgDn and the wheel scroll, Esc closes.</p>
 			</div>
 			<div class="card">
 				<h3>gallery</h3>
@@ -423,11 +439,11 @@
 			</div>
 			<div class="card">
 				<h3>chat</h3>
-				<p>Cloudron Chat client: native OIDC login, channel/DM sidebar with unread badges and presence dots, a wrapped timeline with avatars, day headers, reply snippets and link-preview cards (site, title, description and an optional thumbnail; clicking one opens the link in the browser), a composer and browse/new-DM pickers. Media downloads use a warm <code>curl __serve</code> helper; message images are also decoded there (480&times;320 bounds), while avatars decode at 32&times;32 on the chat thread, so the window keeps drawing. Saved sessions resume from <code>/data</code>. The top-bar <em>Chat</em> button launches it.</p>
+				<p>Cloudron Chat client: native OIDC login, channel/DM sidebar with unread badges and presence dots, a wrapped timeline with avatars, day headers, reply snippets and link-preview cards (site, title, description and an optional thumbnail; clicking one opens the link in the browser), a composer and browse/new-DM pickers. Media downloads use a warm <code>curl __serve</code> helper; message images are also decoded there (480&times;320 bounds), while avatars decode at 32&times;32 on the chat thread, so the window keeps drawing. Saved sessions resume from <code>/data</code>. The start menu's <em>Chat</em> entry launches it.</p>
 			</div>
 			<div class="card">
 				<h3>disks</h3>
-				<p>Storage manager: devices, MBR partitions and mounts, per-volume mount name, read-only and automount, and Format / Install NebOS dialogs that show the kernel command's output. The top-bar <em>Disks</em> button and the <em>Disks</em> button in <code>files</code> launch it.</p>
+				<p>Storage manager: devices, MBR partitions and mounts, per-volume mount name, read-only and automount, and Format / Install NebOS dialogs that show the kernel command's output. The start menu's <em>Disks</em> entry and the <em>Disks</em> button in <code>files</code> launch it.</p>
 			</div>
 			<div class="card">
 				<h3>solitaire</h3>
@@ -512,7 +528,7 @@
 		</p>
 		<ul>
 			<li><strong>Loading.</strong> <span class="file">cursor.c</span> copies the bundle out of the ramfs into its own pages after <code>ramfs_init()</code> and after every <code>ramfs_replace()</code> (the old pack is freed), then tells <span class="file">mouse.c</span> to re-fetch its image.</li>
-			<li><strong>Selection.</strong> On every <code>SYS_WM_POLL</code> the window server resolves the shape: the WM's override (<code>SYS_WM_SET_CURSOR</code>: resize arrows on the resize band and while resizing, the move cross during a title-bar drag, a hand over launchers and the status area), else the cursor of the window holding the pointer capture, else the content cursor (<code>SYS_WIN_SET_CURSOR</code>) of the window under the pointer, else the arrow.</li>
+			<li><strong>Selection.</strong> On every <code>SYS_WM_POLL</code> the window server resolves the shape: the WM's override (<code>SYS_WM_SET_CURSOR</code>: resize arrows on the resize band and while resizing, the move cross during a title-bar drag, a hand over the start button, the start menu and the status area), else the cursor of the window holding the pointer capture, else the content cursor (<code>SYS_WIN_SET_CURSOR</code>) of the window under the pointer, else the arrow.</li>
 			<li><strong>Clients.</strong> ngui resets the cursor to the arrow for each redrawn frame, a hovered text field asks for the I-beam, <code>ngui_cursor_rect()</code>/<code>ngui_set_cursor()</code> serve apps, and <code>ngui_end_ex()</code> sends it when it changed.  The terminal uses the I-beam; the browser maps the inherited CSS <code>cursor</code> property and, for <code>auto</code>, a hand over links, an I-beam over text fields and the progress arrow while a page loads.  The gallery's Cursors section shows every shape.</li>
 			<li><strong>Drawing.</strong> <code>cur_x</code>/<code>cur_y</code> stay the hotspot; the image's top-left is the hotspot minus the image's hotspot and may be off-screen.  The software cursor saves up to 32&times;32 pixels under it and blends the premultiplied pixels over them.  Intel Ironlake and Radeon copy the ARGB image into their 64&times;64 planes (Intel uses CURPOS sign bits for negative positions and follows the matching primary plane's gamma enable, because the display palette is after the plane blender and a cursor-only gamma pass brightens its antialiased edges on a VBE mode whose primary bypasses the palette; Radeon uses <code>HORZ_VERT_OFF</code> plus a shifted <code>CUR_OFFSET</code>); Cirrus reduces it to its two colours and clamps the position at 0.  Animated frames advance from <code>mouse_poll_update()</code>.</li>
 		</ul>

+ 3 - 3
docs/userland.html

@@ -351,10 +351,10 @@
 		<ul>
 			<li><strong>files</strong> — browser for the VFS; opens text in <code>edit</code>, images in <code>view</code>, HTML in <code>browser</code>. First user of ngui.</li>
 			<li><strong>bootscan</strong> — live tail of the boot storage-scan kernel thread's output (the WM opens it before the terminal, flush right under the top bar). The kernel captures the thread's COM1 trail (mounts, probes, boot traces) into a ring exposed by <code>SYS_BOOTLOG</code>; the window follows the tail while the scan runs, keeps the scrollback afterwards, pauses the follow when scrolled up, and closes with Esc. Also startable from the shell.</li>
-			<li><strong>process</strong> — graphical task manager (top-bar <em>Tasks</em> button or <code>process</code>), the ngui counterpart of <code>top</code>. It samples once per second into 60 s histories of CPU busy (<code>SYS_SCHEDINFO</code> idle ticks summed over all CPUs), physical memory in use (<code>SYS_MEMINFO</code>) and NIC throughput (<code>SYS_NET_INFO.rx_bytes</code>/<code>tx_bytes</code> from the netdev frame counters), then draws the three graphs with ngui rectangles and lines. The table lists PID, state, CPU%, memory, total CPU time and name; clicking a header sorts by PID, state, CPU, memory, time or name, and PgUp/PgDn or the wheel scrolls. Selecting a row shows its details; <em>End task</em> asks for a second click and then calls <code>SYS_KILL</code>, while kernel threads (<code>kernel_thread</code> in the process snapshot) and the monitor itself are protected. Esc closes it.</li>
-			<li><strong>disks</strong> — storage manager (top-bar <em>Disks</em> button, or the <em>Disks</em> button in <code>files</code>): devices, MBR partitions and mounts; per-volume mount name, read-only and automount saved to <code>/data/MOUNTS.CFG</code>; Format and Install NebOS dialogs that run <code>format -y</code>/<code>install -y</code> on a private tty and show the log. See <a href="filesystems.html#disks">Filesystems → Storage manager</a>.</li>
+			<li><strong>process</strong> — graphical task manager (start menu <em>Tasks</em> entry or <code>process</code>), the ngui counterpart of <code>top</code>. It samples once per second into 60 s histories of CPU busy (<code>SYS_SCHEDINFO</code> idle ticks summed over all CPUs), physical memory in use (<code>SYS_MEMINFO</code>) and NIC throughput (<code>SYS_NET_INFO.rx_bytes</code>/<code>tx_bytes</code> from the netdev frame counters), then draws the three graphs with ngui rectangles and lines. The table lists PID, state, CPU%, memory, total CPU time and name; clicking a header sorts by PID, state, CPU, memory, time or name, and PgUp/PgDn or the wheel scrolls. Selecting a row shows its details; <em>End task</em> asks for a second click and then calls <code>SYS_KILL</code>, while kernel threads (<code>kernel_thread</code> in the process snapshot) and the monitor itself are protected. Esc closes it.</li>
+			<li><strong>disks</strong> — storage manager (start menu <em>Disks</em> entry, or the <em>Disks</em> button in <code>files</code>): devices, MBR partitions and mounts; per-volume mount name, read-only and automount saved to <code>/data/MOUNTS.CFG</code>; Format and Install NebOS dialogs that run <code>format -y</code>/<code>install -y</code> on a private tty and show the log. See <a href="filesystems.html#disks">Filesystems → Storage manager</a>.</li>
 			<li><strong>gallery</strong> — live widget and primitive showcase; the real app ships in the pack.</li>
-			<li><strong>chat</strong> — native Cloudron Chat client (top-bar <em>Chat</em> button, or <code>chat [config-path]</code>): username/password/TOTP login through the Cloudron OIDC API or a pasted session cookie, channels and DMs with unread badges and presence, history with older paging, inline image attachments, link-preview cards (click one to open it in the browser) and profile-picture avatars, sending, REST polling, read markers, browse/join and new DM.  The session cookie (never the password) is saved in <code>/data/CHAT.CFG</code> when the persistent volume is mounted, or in the RAM-only <code>/share/chat.cfg</code> otherwise.  Keys: Enter sends, PgUp/PgDn scroll, Home at the top pages in older history, Ctrl+B browse, Ctrl+N new DM, Ctrl+R refresh, and with the composer unfocused (Esc) Up/Down switch conversations.  See <a href="network.html#chat">Network → Chat client</a>.</li>
+			<li><strong>chat</strong> — native Cloudron Chat client (start menu <em>Chat</em> entry, or <code>chat [config-path]</code>): username/password/TOTP login through the Cloudron OIDC API or a pasted session cookie, channels and DMs with unread badges and presence, history with older paging, inline image attachments, link-preview cards (click one to open it in the browser) and profile-picture avatars, sending, REST polling, read markers, browse/join and new DM.  The session cookie (never the password) is saved in <code>/data/CHAT.CFG</code> when the persistent volume is mounted, or in the RAM-only <code>/share/chat.cfg</code> otherwise.  Keys: Enter sends, PgUp/PgDn scroll, Home at the top pages in older history, Ctrl+B browse, Ctrl+N new DM, Ctrl+R refresh, and with the composer unfocused (Esc) Up/Down switch conversations.  See <a href="network.html#chat">Network → Chat client</a>.</li>
 			<li><strong>solitaire</strong> — Klondike with drag-and-drop, scoring and a win animation.</li>
 			<li><strong>mines</strong> — second ngui canvas app; shares the toolkit and event model.</li>
 			<li><strong>view</strong> — fit/1:1/zoom/pan image viewer, animated GIF playback.</li>

+ 4 - 49
include/wm_abi.h

@@ -8,55 +8,10 @@
 
 /* Shared chrome layout (the WM draws it, the kernel only stores geometry). */
 #define WM_BAR_H   30
-#define WM_BTN_X   132
-#define WM_BTN_Y   5
-#define WM_BTN_W   56
-#define WM_BTN_H   20
-/* The other top-bar buttons follow the terminal button. */
-#define WM_BTN_GAP     6
-#define WM_BTN_CLOCK_X (WM_BTN_X + WM_BTN_W + WM_BTN_GAP)
-#define WM_BTN_CLOCK_Y WM_BTN_Y
-#define WM_BTN_CLOCK_W 64
-#define WM_BTN_CLOCK_H WM_BTN_H
-#define WM_BTN_COLORS_X (WM_BTN_CLOCK_X + WM_BTN_CLOCK_W + WM_BTN_GAP)
-#define WM_BTN_COLORS_Y WM_BTN_Y
-#define WM_BTN_COLORS_W 72
-#define WM_BTN_COLORS_H WM_BTN_H
-#define WM_BTN_FILES_X (WM_BTN_COLORS_X + WM_BTN_COLORS_W + WM_BTN_GAP)
-#define WM_BTN_FILES_Y WM_BTN_Y
-#define WM_BTN_FILES_W 64
-#define WM_BTN_FILES_H WM_BTN_H
-#define WM_BTN_MINES_X (WM_BTN_FILES_X + WM_BTN_FILES_W + WM_BTN_GAP)
-#define WM_BTN_MINES_Y WM_BTN_Y
-#define WM_BTN_MINES_W 56
-#define WM_BTN_MINES_H WM_BTN_H
-#define WM_BTN_WEB_X (WM_BTN_MINES_X + WM_BTN_MINES_W + WM_BTN_GAP)
-#define WM_BTN_WEB_Y WM_BTN_Y
-#define WM_BTN_WEB_W 56
-#define WM_BTN_WEB_H WM_BTN_H
-#define WM_BTN_CARDS_X (WM_BTN_WEB_X + WM_BTN_WEB_W + WM_BTN_GAP)
-#define WM_BTN_CARDS_Y WM_BTN_Y
-#define WM_BTN_CARDS_W 56
-#define WM_BTN_CARDS_H WM_BTN_H
-#define WM_BTN_GALLERY_X (WM_BTN_CARDS_X + WM_BTN_CARDS_W + WM_BTN_GAP)
-#define WM_BTN_GALLERY_Y WM_BTN_Y
-#define WM_BTN_GALLERY_W 72
-#define WM_BTN_GALLERY_H WM_BTN_H
-#define WM_BTN_CHAT_X (WM_BTN_GALLERY_X + WM_BTN_GALLERY_W + WM_BTN_GAP)
-#define WM_BTN_CHAT_Y WM_BTN_Y
-#define WM_BTN_CHAT_W 56
-#define WM_BTN_CHAT_H WM_BTN_H
-#define WM_BTN_DISKS_X (WM_BTN_CHAT_X + WM_BTN_CHAT_W + WM_BTN_GAP)
-#define WM_BTN_DISKS_Y WM_BTN_Y
-#define WM_BTN_DISKS_W 64
-#define WM_BTN_DISKS_H WM_BTN_H
-#define WM_BTN_PROCESS_X (WM_BTN_DISKS_X + WM_BTN_DISKS_W + WM_BTN_GAP)
-#define WM_BTN_PROCESS_Y WM_BTN_Y
-#define WM_BTN_PROCESS_W 56
-#define WM_BTN_PROCESS_H WM_BTN_H
-/* Right edge of the launcher buttons: the notice text and the right-aligned
- * status (clock, sensors, power) never draw left of it. */
-#define WM_BTN_END_X (WM_BTN_PROCESS_X + WM_BTN_PROCESS_W)
+/* The WM's start button is the NebOS banner at the top left; it opens the
+ * start menu.  The bar notice and the right-aligned status area (clock,
+ * sensors, network, power) never draw left of this edge. */
+#define WM_BAR_LEFT_END 160
 #define WM_TITLE_H 22
 #define WM_CLOSE_W 16
 /* No visible frame: the title bar and content start at the window origin. */

+ 434 - 125
user/apps/wm/ucmd_wm.c

@@ -113,6 +113,82 @@ static unsigned int bar_clock_w;
 static int bar_clock_hot;
 static unsigned int stat_frames, stat_ms, stat_px, stat_max, stat_last;
 
+/* ---- Start menu --------------------------------------------------------
+ * The NebOS banner in the top-left corner is the start button.  It opens a
+ * Windows-like panel drawn by the WM itself (not a window, so it never
+ * consumes a WM_MAX_WINDOWS slot and floats above every canvas).  The panel
+ * lists every GUI app in the pack and ends with a Power row whose submenu
+ * reboots or powers off the machine through the privileged kernel command
+ * registry (SYS_SPAWN_KCMD). */
+#define SM_W        236
+#define SM_ROW_H    30
+#define SM_MIN_ROW  18
+#define SM_HDR_H    44
+#define SM_SEP_H    7
+#define SM_SUB_W    152
+#define SM_TILE     18
+
+#define SM_HIT_NONE     (-1)
+#define SM_HIT_START    (-2)
+#define SM_HIT_POWER    (-3)
+#define SM_HIT_REBOOT   (-4)
+#define SM_HIT_POWEROFF (-5)
+
+#define SM_ACT_SPAWN    0
+#define SM_ACT_TERM     1
+#define SM_ACT_SETTINGS 2
+
+struct sm_app {
+	const char *label;
+	const char *path;
+	const char *arg;
+	unsigned int tile;
+	char letter;
+	unsigned char action;
+};
+
+/* Every self-contained GUI application in the pack.  Terminal and Settings
+ * are WM actions (a new terminal canvas and the control panel); edit gets a
+ * scratch file so it can start without a file argument. */
+static const struct sm_app sm_apps[] = {
+	{ "Terminal",    "",                    "",                     0x3C8CD2u, 'T', SM_ACT_TERM },
+	{ "Files",       "/ramfs/bin/files",    "",                     0xE0A030u, 'F', SM_ACT_SPAWN },
+	{ "Web",         "/ramfs/bin/browser",  "",                     0x4CA0E0u, 'W', SM_ACT_SPAWN },
+	{ "Gallery",     "/ramfs/bin/gallery",  "",                     0xC864B4u, 'G', SM_ACT_SPAWN },
+	{ "Chat",        "/ramfs/bin/chat",     "",                     0x55A055u, 'C', SM_ACT_SPAWN },
+	{ "Clock",       "/ramfs/bin/clock",    "",                     0x8C8C9Cu, 'C', SM_ACT_SPAWN },
+	{ "Text editor", "/ramfs/bin/edit",     "/share/UNTITLED.TXT",  0xD27850u, 'E', SM_ACT_SPAWN },
+	{ "Colors",      "/ramfs/bin/colors",   "",                     0xC85A5Au, 'P', SM_ACT_SPAWN },
+	{ "Mines",       "/ramfs/bin/mines",    "",                     0x8C6CD2u, 'M', SM_ACT_SPAWN },
+	{ "Cards",       "/ramfs/bin/solitaire","",                     0x3CA08Cu, 'S', SM_ACT_SPAWN },
+	{ "Disks",       "/ramfs/bin/disks",    "",                     0x5A8CC8u, 'D', SM_ACT_SPAWN },
+	{ "Tasks",       "/ramfs/bin/process",  "",                     0xE0B040u, 'P', SM_ACT_SPAWN },
+	{ "Settings",    "",                    "",                     0x7A7A9Au, 'S', SM_ACT_SETTINGS },
+	{ "Date & Time", "/ramfs/bin/settime",  "",                     0x5AA0A0u, 'D', SM_ACT_SPAWN },
+};
+#define SM_NAPP ((int)(sizeof(sm_apps) / sizeof(sm_apps[0])))
+
+struct sm_layout {
+	int x, y, w, h;
+	int row_h;
+	int list_y;
+	int power_y;
+	int sub_x, sub_y, sub_w, sub_h;
+};
+
+static int sm_open;
+static int sm_power_open;
+static int sm_start_hot;
+static int sm_hot;              /* hovered app index, -1 = none */
+static int sm_power_hot;        /* 0 none, 1 Power, 2 Reboot, 3 Power off */
+
+static void sm_layout_get(struct sm_layout *l);
+static void sm_draw(void);
+static void sm_add_present(struct wm_present_info *p);
+static int sm_update_hover(unsigned int mx, unsigned int my);
+static void sm_close(void);
+static void sm_launch(int idx);
+
 /* Network status icon (right side of the bar). */
 #define BAR_NET_W 24
 #define BAR_NET_Y 7
@@ -208,14 +284,39 @@ static void fill_clip(int x, int y, unsigned int w, unsigned int h,
 			   (unsigned int)(y1 - y0), rgb);
 }
 
-static void bar_button(unsigned int x, unsigned int y, unsigned int w,
-		       unsigned int h, const char *label)
+/* The NebOS banner doubles as the start button.  Its width follows the
+ * proportional font, so the hit area and the highlight use the same
+ * geometry. */
+static void bar_start_geom(int *x, int *y, int *w, int *h)
+{
+	*x = 2;
+	*y = 2;
+	*h = WM_BAR_H - 6;
+	*w = (int)usurf_text_width(&screen, OS_NAME " v" OS_VERSION) + 20;
+}
+
+static int bar_start_hit(unsigned int mx, unsigned int my)
+{
+	int x, y, w, h;
+
+	bar_start_geom(&x, &y, &w, &h);
+	return (int)mx >= x && (int)mx < x + w &&
+	       (int)my >= y && (int)my < y + h;
+}
+
+static void bar_start_button(void)
 {
-	int tw = (int)usurf_text_width(&screen, label);
+	int x, y, w, h;
 
-	usurf_fill(&screen, x, y, w, h, 0x963CD2u);
-	usurf_text(&screen, (int)x + ((int)w - tw) / 2, (int)(y + 3),
-		   label, COL_WHITE, 0, 0, fbw, WM_BAR_H);
+	bar_start_geom(&x, &y, &w, &h);
+	if (sm_open || sm_start_hot) {
+		usurf_fill(&screen, x, y, w, h,
+			   sm_open ? 0x365CA6u : 0x3A3A55u);
+		usurf_fill(&screen, x + 2, y + h - 2, w - 4, 2,
+			   sm_open ? 0x55FF55u : 0x70709Au);
+	}
+	usurf_text(&screen, x + 10, y + 4, OS_NAME " v" OS_VERSION,
+		   sm_open ? COL_WHITE : COL_BANNER, 0, 0, fbw, WM_BAR_H);
 }
 
 static int name_is(const char *a, const char *b)
@@ -439,32 +540,10 @@ static void draw_bar(void)
 	unsigned int n, i, x, y;
 
 	usurf_fill(&screen, 0, 0, fbw, WM_BAR_H, COL_BG);
-	usurf_text(&screen, 4, 5, OS_NAME " v" OS_VERSION, COL_BANNER,
-		   0, 0, fbw, WM_BAR_H);
-	bar_button(WM_BTN_X, WM_BTN_Y, WM_BTN_W, WM_BTN_H, "New");
-	bar_button(WM_BTN_CLOCK_X, WM_BTN_CLOCK_Y, WM_BTN_CLOCK_W,
-		   WM_BTN_CLOCK_H, "Clock");
-	bar_button(WM_BTN_COLORS_X, WM_BTN_COLORS_Y, WM_BTN_COLORS_W,
-		   WM_BTN_COLORS_H, "Colors");
-	bar_button(WM_BTN_FILES_X, WM_BTN_FILES_Y, WM_BTN_FILES_W,
-		   WM_BTN_FILES_H, "Files");
-	bar_button(WM_BTN_MINES_X, WM_BTN_MINES_Y, WM_BTN_MINES_W,
-		   WM_BTN_MINES_H, "Mines");
-	bar_button(WM_BTN_WEB_X, WM_BTN_WEB_Y, WM_BTN_WEB_W,
-		   WM_BTN_WEB_H, "Web");
-	bar_button(WM_BTN_CARDS_X, WM_BTN_CARDS_Y, WM_BTN_CARDS_W,
-		   WM_BTN_CARDS_H, "Cards");
-	bar_button(WM_BTN_GALLERY_X, WM_BTN_GALLERY_Y, WM_BTN_GALLERY_W,
-		   WM_BTN_GALLERY_H, "Gallery");
-	bar_button(WM_BTN_CHAT_X, WM_BTN_CHAT_Y, WM_BTN_CHAT_W,
-		   WM_BTN_CHAT_H, "Chat");
-	bar_button(WM_BTN_DISKS_X, WM_BTN_DISKS_Y, WM_BTN_DISKS_W,
-		   WM_BTN_DISKS_H, "Disks");
-	bar_button(WM_BTN_PROCESS_X, WM_BTN_PROCESS_Y, WM_BTN_PROCESS_W,
-		   WM_BTN_PROCESS_H, "Tasks");
+	bar_start_button();
 	if (bar_msg_until &&
 	    (int)(u_ticks_ms() - bar_msg_until) < 0)
-		usurf_text(&screen, (int)(WM_BTN_END_X + 8),
+		usurf_text(&screen, (int)(WM_BAR_LEFT_END + 8),
 			   5, bar_msg, 0xFFD250u, 0, 0, fbw, WM_BAR_H);
 
 	/* Rainbow separator (same y as the kernel's old bar). */
@@ -501,7 +580,7 @@ static void draw_bar(void)
 	} else {
 		unsigned int clock_chars = 0;
 		int right = (int)fbw - 4;
-		int min_x = (int)WM_BTN_END_X + 4;
+		int min_x = (int)WM_BAR_LEFT_END + 4;
 
 		bar_clock_x = -1;
 		bar_clock_w = 0;
@@ -1107,6 +1186,10 @@ static void wm_overlays(struct wm_present_info *p)
 		osd_draw();
 		add_rect(p, osd_x, osd_y, osd_w, osd_h);
 	}
+	if (sm_open) {
+		sm_draw();
+		sm_add_present(p);
+	}
 }
 
 /* A focused window is topmost, so the shadow contains exactly its pixels in
@@ -1358,11 +1441,228 @@ static int bar_pwr_hit(unsigned int mx, unsigned int my)
 }
 
 /* The whole right status area is one button: the clock, temperature, network
- * and power items plus the gaps between them.  The launcher buttons end at
- * WM_BTN_END_X, so this never overlaps them. */
+ * and power items plus the gaps between them.  The start button ends well
+ * before WM_BAR_LEFT_END, so this never overlaps it. */
 static int bar_status_hit(unsigned int mx, unsigned int my)
 {
-	return my < WM_BAR_H && (int)mx >= WM_BTN_END_X + 4;
+	return my < WM_BAR_H && (int)mx >= WM_BAR_LEFT_END + 4;
+}
+
+static void sm_layout_get(struct sm_layout *l)
+{
+	int avail = (int)fbh - WM_BAR_H - 8;
+	int row = SM_ROW_H;
+	int total = SM_HDR_H + SM_NAPP * row + SM_SEP_H + row;
+
+	/* Shrink the rows to the work area, so a 540-600 px panel still fits
+	 * the whole list.  The low bound is the smallest legible row. */
+	while (row > SM_MIN_ROW && total > avail) {
+		row--;
+		total = SM_HDR_H + SM_NAPP * row + SM_SEP_H + row;
+	}
+	l->x = 4;
+	l->y = WM_BAR_H + 2;
+	l->w = SM_W;
+	l->h = total;
+	l->row_h = row;
+	l->list_y = l->y + SM_HDR_H;
+	l->power_y = l->list_y + SM_NAPP * row + SM_SEP_H;
+
+	l->sub_w = SM_SUB_W;
+	l->sub_h = 2 * row + 4;
+	l->sub_x = l->x + l->w + 2;
+	if (l->sub_x + l->sub_w > (int)fbw - 2) {
+		if (l->x - l->sub_w - 2 >= 0)
+			l->sub_x = l->x - l->sub_w - 2;
+		else
+			l->sub_x = (int)fbw - 2 - l->sub_w;
+	}
+	/* The power row is the last menu row: open the submenu upwards and
+	 * align its bottom with that row. */
+	l->sub_y = l->power_y + row - l->sub_h;
+	if (l->sub_y < WM_BAR_H + 2)
+		l->sub_y = WM_BAR_H + 2;
+	if (l->sub_y + l->sub_h > (int)fbh - 2)
+		l->sub_y = (int)fbh - 2 - l->sub_h;
+	if (l->sub_y < 0)
+		l->sub_y = 0;
+}
+
+static void sm_frame(int x, int y, int w, int h)
+{
+	usurf_fill(&screen, x, y, (unsigned int)w, (unsigned int)h, 0x161622u);
+	usurf_fill(&screen, x, y, (unsigned int)w, 1, 0x5A5A7Au);
+	usurf_fill(&screen, x, y + h - 1, (unsigned int)w, 1, 0x5A5A7Au);
+	usurf_fill(&screen, x, y, 1, (unsigned int)h, 0x5A5A7Au);
+	usurf_fill(&screen, x + w - 1, y, 1, (unsigned int)h, 0x5A5A7Au);
+}
+
+static void sm_tile(int x, int y, int size, unsigned int rgb, char letter)
+{
+	char s[2];
+	int tw, tx, ty;
+
+	if (size < 12)
+		size = 12;
+	s[0] = letter;
+	s[1] = '\0';
+	usurf_fill(&screen, x, y, (unsigned int)size, (unsigned int)size, rgb);
+	tw = (int)usurf_text_width(&screen, s);
+	tx = x + (size - tw) / 2;
+	ty = y + (size - 16) / 2;
+	usurf_text(&screen, tx, ty, s, COL_WHITE,
+		   x, y, (unsigned int)size, (unsigned int)size);
+}
+
+static void sm_draw_app(int i, const struct sm_layout *l)
+{
+	const struct sm_app *a = &sm_apps[i];
+	int ry = l->list_y + i * l->row_h;
+	int ty = ry + (l->row_h - 16) / 2;
+	int tile = l->row_h - 4;
+
+	if (tile > SM_TILE)
+		tile = SM_TILE;
+	if (sm_hot == i)
+		usurf_fill(&screen, l->x + 4, ry + 1, l->w - 8,
+			   (unsigned int)(l->row_h - 2), 0x365CA6u);
+	sm_tile(l->x + 10, ry + (l->row_h - tile) / 2, tile,
+		a->tile, a->letter);
+	usurf_text(&screen, l->x + 36, ty, a->label,
+		   sm_hot == i ? COL_WHITE : 0xE8E8F6u,
+		   l->x, l->y, l->w, l->h);
+}
+
+static void sm_draw(void)
+{
+	struct sm_layout l;
+	unsigned int ver_w;
+	int i, ty;
+
+	if (!sm_open)
+		return;
+	sm_layout_get(&l);
+	sm_frame(l.x, l.y, l.w, l.h);
+
+	ver_w = usurf_text_width(&screen, "v" OS_VERSION);
+	usurf_text(&screen, l.x + 12, l.y + 6, OS_NAME, COL_WHITE,
+		   l.x, l.y, (unsigned int)l.w, (unsigned int)l.h);
+	usurf_text(&screen, l.x + l.w - 12 - (int)ver_w, l.y + 6,
+		   "v" OS_VERSION, 0x9A9AAEu,
+		   l.x, l.y, (unsigned int)l.w, (unsigned int)l.h);
+	usurf_text(&screen, l.x + 12, l.y + 25, "All apps", 0x9A9AAEu,
+		   l.x, l.y, (unsigned int)l.w, (unsigned int)l.h);
+	usurf_fill(&screen, l.x + 8, l.list_y - 1, l.w - 16, 1, 0x3A3A55u);
+
+	for (i = 0; i < SM_NAPP; i++)
+		sm_draw_app(i, &l);
+
+	/* Power row and the separator above it. */
+	usurf_fill(&screen, l.x + 8, l.power_y - 4, l.w - 16, 1, 0x3A3A55u);
+	if (sm_power_hot == 1 || sm_power_open)
+		usurf_fill(&screen, l.x + 4, l.power_y + 1, l.w - 8,
+			   (unsigned int)(l.row_h - 2), 0x365CA6u);
+	ty = l.power_y + (l.row_h - 16) / 2;
+	usurf_text(&screen, l.x + 12, ty, "Power",
+		   sm_power_hot == 1 || sm_power_open ? COL_WHITE : 0xE8E8F6u,
+		   l.x, l.y, (unsigned int)l.w, (unsigned int)l.h);
+	{
+		const char *arrow = sm_power_open ? "v" : ">";
+		int aw = (int)usurf_text_width(&screen, arrow);
+
+		usurf_text(&screen, l.x + l.w - 12 - aw, ty, arrow,
+			   0x9A9AAEu, l.x, l.y, (unsigned int)l.w,
+			   (unsigned int)l.h);
+	}
+
+	if (!sm_power_open)
+		return;
+	sm_frame(l.sub_x, l.sub_y, l.sub_w, l.sub_h);
+	for (i = 0; i < 2; i++) {
+		int sy = l.sub_y + 2 + i * l.row_h;
+		int sty = sy + (l.row_h - 16) / 2;
+
+		if (sm_power_hot == i + 2)
+			usurf_fill(&screen, l.sub_x + 3, sy + 1, l.sub_w - 6,
+				   (unsigned int)(l.row_h - 2), 0x365CA6u);
+		usurf_text(&screen, l.sub_x + 12, sty,
+			   i == 0 ? "Reboot" : "Power off",
+			   i == 1 ? (sm_power_hot == 3 ? COL_WHITE : 0xFF9090u)
+				  : (sm_power_hot == 2 ? COL_WHITE
+						       : 0xE8E8F6u),
+			   l.sub_x, l.sub_y, (unsigned int)l.sub_w,
+			   (unsigned int)l.sub_h);
+	}
+}
+
+static int sm_hit(unsigned int mx, unsigned int my)
+{
+	struct sm_layout l;
+	int x = (int)mx, y = (int)my;
+
+	if (bar_start_hit(mx, my))
+		return SM_HIT_START;
+	if (!sm_open)
+		return SM_HIT_NONE;
+	sm_layout_get(&l);
+	if (sm_power_open &&
+	    x >= l.sub_x && x < l.sub_x + l.sub_w &&
+	    y >= l.sub_y + 2 && y < l.sub_y + 2 + 2 * l.row_h)
+		return (y - (l.sub_y + 2)) / l.row_h == 0 ?
+		       SM_HIT_REBOOT : SM_HIT_POWEROFF;
+	if (x < l.x || x >= l.x + l.w)
+		return SM_HIT_NONE;
+	if (y >= l.list_y && y < l.list_y + SM_NAPP * l.row_h)
+		return (y - l.list_y) / l.row_h;
+	if (y >= l.power_y && y < l.power_y + l.row_h)
+		return SM_HIT_POWER;
+	return SM_HIT_NONE;
+}
+
+static int sm_update_hover(unsigned int mx, unsigned int my)
+{
+	int hot = -1, pwr = 0, hit;
+
+	if (sm_open) {
+		hit = sm_hit(mx, my);
+		if (hit >= 0)
+			hot = hit;
+		else if (hit == SM_HIT_POWER)
+			pwr = 1;
+		else if (hit == SM_HIT_REBOOT)
+			pwr = 2;
+		else if (hit == SM_HIT_POWEROFF)
+			pwr = 3;
+	}
+	if (hot == sm_hot && pwr == sm_power_hot)
+		return 0;
+	sm_hot = hot;
+	sm_power_hot = pwr;
+	return 1;
+}
+
+static void sm_add_present(struct wm_present_info *p)
+{
+	struct sm_layout l;
+
+	if (!sm_open)
+		return;
+	sm_layout_get(&l);
+	add_rect(p, l.x, l.y, (unsigned int)l.w, (unsigned int)l.h);
+	if (sm_power_open)
+		add_rect(p, l.sub_x, l.sub_y, (unsigned int)l.sub_w,
+			 (unsigned int)l.sub_h);
+}
+
+static void sm_close(void)
+{
+	if (!sm_open && !sm_power_open)
+		return;
+	sm_open = 0;
+	sm_power_open = 0;
+	sm_hot = -1;
+	sm_power_hot = 0;
+	full_redraw = 1;
 }
 
 static void do_update(struct wm_status *st)
@@ -1377,6 +1677,7 @@ static void do_update(struct wm_status *st)
 		(st->kexec_busy && st->kexec_progress != bar_kexec_progress);
 	unsigned int msg_now = u_ticks_ms();
 	int osd_hide = 0, osd_repaint = 0;
+	int sm_dirty;
 
 	/* The kernel bumps backlight_seq on every brightness key/command.
 	 * Pop the OSD on a change and keep it up for OSD_MS after the last
@@ -1403,6 +1704,8 @@ static void do_update(struct wm_status *st)
 	if (osd_hide && osd_visible)
 		osd_repaint = 1;
 
+	sm_dirty = sm_update_hover(st->mouse.x, st->mouse.y);
+
 	/* The boot-scan window is created before the terminal so the terminal
 	 * stays the newest (last) window and keeps the keyboard focus.  Wait
 	 * for the scan window to exist before starting the terminal; a failed
@@ -1466,6 +1769,14 @@ static void do_update(struct wm_status *st)
 	if (kexec_changed)
 		bar_dirty = 1;
 
+	{
+		int hot = bar_start_hit(st->mouse.x, st->mouse.y);
+
+		if (hot != sm_start_hot) {
+			sm_start_hot = hot;
+			bar_dirty = 1;
+		}
+	}
 	{
 		int hot = bar_clock_hit(st->mouse.x, st->mouse.y);
 
@@ -1636,6 +1947,7 @@ static void do_update(struct wm_status *st)
 			if (osd_show)
 				osd_draw();
 			osd_visible = osd_show;
+			sm_draw();
 			present.count = 0;
 			add_rect(&present, 0, 0, fbw, fbh);
 			present.immediate = 0;
@@ -1691,12 +2003,16 @@ static void do_update(struct wm_status *st)
 		add_rect(&present, bar_pwr_tip_on_x, bar_pwr_tip_on_y,
 			 bar_pwr_tip_on_w, bar_pwr_tip_on_h);
 	}
+	if (sm_dirty && sm_open)
+		need = 1;
 
 	if (!need) {
 		/* Drag movement is handled below; a stationary mouse can be
 		 * left to the kernel's cursor overlay. */
 		return;
 	}
+	if (sm_open)
+		sm_add_present(&present);
 	if (u_wm_begin() != 0)
 		return;
 
@@ -1717,6 +2033,7 @@ static void do_update(struct wm_status *st)
 		add_rect(&present, osd_x, osd_y, osd_w, osd_h);
 	}
 	osd_visible = osd_show;
+	sm_draw();
 
 	for (i = 0; i < WM_MAX_WINDOWS; i++) {
 		struct uwin *u = &wins[i];
@@ -1730,25 +2047,18 @@ static void do_update(struct wm_status *st)
 	u_wm_present(&present);
 }
 
-static int spawn_app(const char *path)
-{
-	int pid = u_spawn(path, "", 0, "/");
-
-	if (pid > 0)
-		full_redraw = 1;
-	return pid;
-}
-
-static void spawn_app_checked(const char *path)
+static void spawn_app_arg_checked(const char *path, const char *arg)
 {
 	if (!free_window_slot()) {
 		bar_notice("window limit");
 		full_redraw = 1;
 		return;
 	}
-	if (spawn_app(path) < 0) {
+	if (u_spawn(path, arg, 0, "/") < 0) {
 		bar_notice("spawn failed");
 		full_redraw = 1;
+	} else {
+		full_redraw = 1;
 	}
 }
 
@@ -1788,6 +2098,35 @@ static void open_control_panel(void)
 	}
 }
 
+/* Launch one start-menu entry.  The terminal and the control panel are WM
+ * actions; every other entry spawns its ELF from the pack. */
+static void sm_launch(int idx)
+{
+	const struct sm_app *a;
+
+	if (idx < 0 || idx >= SM_NAPP) {
+		sm_close();
+		return;
+	}
+	a = &sm_apps[idx];
+	sm_close();
+	if (a->action == SM_ACT_TERM) {
+		if (!free_window_slot()) {
+			bar_notice("window limit");
+			full_redraw = 1;
+		} else if (u_wm_create_term() < 0) {
+			bar_notice("cannot start term");
+			full_redraw = 1;
+		} else {
+			full_redraw = 1;
+		}
+	} else if (a->action == SM_ACT_SETTINGS) {
+		open_control_panel();
+	} else {
+		spawn_app_arg_checked(a->path, a->arg);
+	}
+}
+
 /* Index of a popover containing the point, or -1. */
 static int popover_under(unsigned int mx, unsigned int my)
 {
@@ -1827,30 +2166,6 @@ static void dismiss_popover_outside(unsigned int mx, unsigned int my)
 	}
 }
 
-/* Top-bar launcher under (mx, my)?  Same rectangles as the click chain in
- * handle_mouse(); every launcher shares WM_BTN_Y/WM_BTN_H. */
-static int bar_launcher_hit(unsigned int mx, unsigned int my)
-{
-	static const int x0[] = {
-		WM_BTN_X, WM_BTN_CLOCK_X, WM_BTN_COLORS_X, WM_BTN_FILES_X,
-		WM_BTN_MINES_X, WM_BTN_WEB_X, WM_BTN_CARDS_X, WM_BTN_GALLERY_X,
-		WM_BTN_CHAT_X, WM_BTN_DISKS_X, WM_BTN_PROCESS_X
-	};
-	static const int w[] = {
-		WM_BTN_W, WM_BTN_CLOCK_W, WM_BTN_COLORS_W, WM_BTN_FILES_W,
-		WM_BTN_MINES_W, WM_BTN_WEB_W, WM_BTN_CARDS_W, WM_BTN_GALLERY_W,
-		WM_BTN_CHAT_W, WM_BTN_DISKS_W, WM_BTN_PROCESS_W
-	};
-	unsigned int i;
-
-	if ((int)my < WM_BTN_Y || (int)my >= WM_BTN_Y + WM_BTN_H)
-		return 0;
-	for (i = 0; i < sizeof(x0) / sizeof(x0[0]); i++)
-		if ((int)mx >= x0[i] && (int)mx < x0[i] + w[i])
-			return 1;
-	return 0;
-}
-
 /* Apply one edge-drag step.  The grabbed edges follow the pointer while the
  * opposite edges stay put; the work area clamps the active edges. */
 static void resize_window_drag(struct uwin *u, unsigned int idx,
@@ -1935,9 +2250,9 @@ static void begin_resize(unsigned int idx, int edges, unsigned int mx,
 
 /* The WM's cursor override (SYS_WM_SET_CURSOR): resize arrows on the
  * invisible resize border and while resizing, the move cross while a
- * title-bar drag is under way, a hand over the launchers and the status
- * area.  Everywhere else the kernel picks the window's own content cursor
- * (or the arrow). */
+ * title-bar drag is under way, a hand over the start button, the open start
+ * menu and the status area.  Everywhere else the kernel picks the window's
+ * own content cursor (or the arrow). */
 static void update_cursor(unsigned int mx, unsigned int my)
 {
 	static int current = CURSOR_NO_OVERRIDE;
@@ -1948,8 +2263,13 @@ static void update_cursor(unsigned int mx, unsigned int my)
 	} else if (drag_id >= 0) {
 		if (drag_moved)
 			want = CURSOR_MOVE;
+	} else if (sm_open) {
+		/* The menu is modal: a hand over its items, the arrow
+		 * elsewhere, never a window's content cursor underneath. */
+		want = sm_hit(mx, my) == SM_HIT_NONE ?
+		       CURSOR_DEFAULT : CURSOR_POINTER;
 	} else if (my < WM_BAR_H) {
-		if (bar_launcher_hit(mx, my) || bar_status_hit(mx, my))
+		if (bar_start_hit(mx, my) || bar_status_hit(mx, my))
 			want = CURSOR_POINTER;
 	} else {
 		int edges = 0;
@@ -1973,63 +2293,51 @@ static void handle_mouse(struct wm_status *st)
 	if (down && !was) {
 		int prev_title_id = last_title_id;
 		unsigned int now = u_ticks_ms();
-
+		int hit;
+
+		/* The start menu is modal: a press on an entry launches it,
+		 * a press on Power opens its submenu, and any other press
+		 * dismisses the menu without reaching the window below. */
+		if (sm_open) {
+			hit = sm_hit(mx, my);
+			last_title_id = -1;
+			if (hit == SM_HIT_START) {
+				sm_close();
+			} else if (hit == SM_HIT_POWER) {
+				sm_power_open = !sm_power_open;
+				full_redraw = 1;
+			} else if (hit == SM_HIT_REBOOT) {
+				sm_close();
+				if (u_spawn_kcmd("reboot", "", 0) < 0)
+					bar_notice("reboot failed");
+			} else if (hit == SM_HIT_POWEROFF) {
+				sm_close();
+				if (u_spawn_kcmd("poweroff", "", 0) < 0)
+					bar_notice("poweroff failed");
+			} else if (hit >= 0) {
+				sm_launch(hit);
+			} else {
+				sm_close();
+			}
+			goto mouse_done;
+		}
+		if (bar_start_hit(mx, my)) {
+			/* Opening the menu also closes an open control
+			 * panel, so only one floating panel is visible. */
+			dismiss_popover_outside(mx, my);
+			last_title_id = -1;
+			sm_open = 1;
+			sm_power_open = 0;
+			sm_hot = -1;
+			sm_power_hot = 0;
+			full_redraw = 1;
+			goto mouse_done;
+		}
 		if (!bar_status_hit(mx, my))
 			dismiss_popover_outside(mx, my);
 		last_title_id = -1;
 		if (bar_status_hit(mx, my)) {
 			open_control_panel();
-		} else if (mx >= WM_BTN_X && my >= WM_BTN_Y &&
-		    mx < WM_BTN_X + WM_BTN_W && my < WM_BTN_Y + WM_BTN_H) {
-			if (!free_window_slot()) {
-				bar_notice("window limit");
-				full_redraw = 1;
-			} else if (u_wm_create_term() < 0) {
-				bar_notice("cannot start term");
-				full_redraw = 1;
-			} else {
-				full_redraw = 1;
-			}
-		} else if (mx >= WM_BTN_CLOCK_X && my >= WM_BTN_CLOCK_Y &&
-			   mx < WM_BTN_CLOCK_X + WM_BTN_CLOCK_W &&
-			   my < WM_BTN_CLOCK_Y + WM_BTN_CLOCK_H) {
-			spawn_app_checked("/ramfs/bin/clock");
-		} else if (mx >= WM_BTN_COLORS_X && my >= WM_BTN_COLORS_Y &&
-			   mx < WM_BTN_COLORS_X + WM_BTN_COLORS_W &&
-			   my < WM_BTN_COLORS_Y + WM_BTN_COLORS_H) {
-			spawn_app_checked("/ramfs/bin/colors");
-		} else if (mx >= WM_BTN_FILES_X && my >= WM_BTN_FILES_Y &&
-			   mx < WM_BTN_FILES_X + WM_BTN_FILES_W &&
-			   my < WM_BTN_FILES_Y + WM_BTN_FILES_H) {
-			spawn_app_checked("/ramfs/bin/files");
-		} else if (mx >= WM_BTN_MINES_X && my >= WM_BTN_MINES_Y &&
-			   mx < WM_BTN_MINES_X + WM_BTN_MINES_W &&
-			   my < WM_BTN_MINES_Y + WM_BTN_MINES_H) {
-			spawn_app_checked("/ramfs/bin/mines");
-		} else if (mx >= WM_BTN_WEB_X && my >= WM_BTN_WEB_Y &&
-			   mx < WM_BTN_WEB_X + WM_BTN_WEB_W &&
-			   my < WM_BTN_WEB_Y + WM_BTN_WEB_H) {
-			spawn_app_checked("/ramfs/bin/browser");
-		} else if (mx >= WM_BTN_CARDS_X && my >= WM_BTN_CARDS_Y &&
-			   mx < WM_BTN_CARDS_X + WM_BTN_CARDS_W &&
-			   my < WM_BTN_CARDS_Y + WM_BTN_CARDS_H) {
-			spawn_app_checked("/ramfs/bin/solitaire");
-		} else if (mx >= WM_BTN_GALLERY_X && my >= WM_BTN_GALLERY_Y &&
-			   mx < WM_BTN_GALLERY_X + WM_BTN_GALLERY_W &&
-			   my < WM_BTN_GALLERY_Y + WM_BTN_GALLERY_H) {
-			spawn_app_checked("/ramfs/bin/gallery");
-		} else if (mx >= WM_BTN_CHAT_X && my >= WM_BTN_CHAT_Y &&
-			   mx < WM_BTN_CHAT_X + WM_BTN_CHAT_W &&
-			   my < WM_BTN_CHAT_Y + WM_BTN_CHAT_H) {
-			spawn_app_checked("/ramfs/bin/chat");
-		} else if (mx >= WM_BTN_DISKS_X && my >= WM_BTN_DISKS_Y &&
-			   mx < WM_BTN_DISKS_X + WM_BTN_DISKS_W &&
-			   my < WM_BTN_DISKS_Y + WM_BTN_DISKS_H) {
-			spawn_app_checked("/ramfs/bin/disks");
-		} else if (mx >= WM_BTN_PROCESS_X && my >= WM_BTN_PROCESS_Y &&
-			   mx < WM_BTN_PROCESS_X + WM_BTN_PROCESS_W &&
-			   my < WM_BTN_PROCESS_Y + WM_BTN_PROCESS_H) {
-			spawn_app_checked("/ramfs/bin/process");
 		} else {
 			int edges = 0;
 			int idx = resize_hit((int)mx, (int)my, &edges);
@@ -2177,6 +2485,7 @@ static void handle_mouse(struct wm_status *st)
 		resize_id = -1;
 		u_wm_mouse_capture(0);
 	}
+mouse_done:
 	prev_buttons = buttons;
 	update_cursor(mx, my);
 }