Эх сурвалжийг харах

Turn the network menu into a flat popover

Open the top-bar network settings as a chromeless WIN_F_POPOVER canvas
window anchored under the status icon instead of a titled window.  The WM
keeps it topmost, dismisses it on an outside click or Esc, and toggles it
from the icon; it draws no title bar, shadow or rounded outer corners, so
the panel reads as a flat menu.

- wm_abi.h, wm.c: carry the popover flag, use the window origin for
  content-relative pointer/scroll coordinates and clamp the panel fully
  on screen.
- ucmd_lib.h: add u_win_create_popover().
- ucmd_wm.c: skip window chrome for popovers, keep them above every
  window, anchor them under the network icon, fix the damage origin and
  dismiss them on an outside press.
- ngui.c/h: add the popover body/footer component, section headers,
  two-line list rows and signal bars.
- ucmd_netmenu.c: rebuild the menu around those components with a
  connection status card, scrollable Devices/Wi-Fi/Connection sections,
  passphrase, progress and saved-network views and a footer status line.
- AGENTS.md and docs (graphics, network, userland) updated.

make all passes.  A headless QEMU run opened the popover from the status
icon, checked the flat panel and the rich content, and verified outside
click, icon toggle and Esc dismissal.
Johannes Zellner 1 долоо хоног өмнө
parent
commit
484756be4d
12 өөрчлөгдсөн 882 нэмэгдсэн , 335 устгасан
  1. 30 7
      AGENTS.md
  2. 24 5
      docs/graphics.html
  3. 2 2
      docs/network.html
  4. 2 2
      docs/userland.html
  5. 172 0
      ngui.c
  6. 35 0
      ngui.h
  7. 18 2
      ucmd_lib.h
  8. 376 256
      ucmd_netmenu.c
  9. 134 36
      ucmd_wm.c
  10. 81 25
      wm.c
  11. 1 0
      wm.h
  12. 7 0
      wm_abi.h

+ 30 - 7
AGENTS.md

@@ -365,8 +365,16 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   network status icon: a cable for a wired netdev, signal bars for an
   network status icon: a cable for a wired netdev, signal bars for an
   associated WiFi link, a USB mark for RNDIS tethering, and a red X otherwise.
   associated WiFi link, a USB mark for RNDIS tethering, and a red X otherwise.
   The WM polls `SYS_NET_INFO` (and `SYS_WIFI_STATUS` only while WiFi is active)
   The WM polls `SYS_NET_INFO` (and `SYS_WIFI_STATUS` only while WiFi is active)
-  at 1 Hz; clicking the network icon spawns one `/ramfs/bin/netmenu` window and
-  anchors it under the icon once its window exists (`u_wm_set_geom`).
+  at 1 Hz; clicking the network icon opens one `/ramfs/bin/netmenu` popover and
+  anchors it under the icon (`u_wm_set_geom`).  A popover is a chromeless
+  `WIN_F_POPOVER` canvas window (`u_win_create_popover`): the WM skips the
+  title bar/close/resize chrome and treats it as always topmost in painting
+  and hit-testing.  The canvas fills the whole window rectangle: there is no
+  outer shadow, rim or rounded corner, so it reads as a flat menu panel.  The
+  kernel uses the window origin for content-relative pointer and scroll
+  coordinates (a normal window uses the 1 px border plus title bar).  An
+  outside press dismisses the popover and then continues with the normal
+  click handling; a second click on the network icon toggles it.
   The last launcher, `Chat`, spawns `/ramfs/bin/chat`; `WM_BTN_END_X`
   The last launcher, `Chat`, spawns `/ramfs/bin/chat`; `WM_BTN_END_X`
   (`wm_abi.h`) is the launchers' right edge, and the bar notice and the
   (`wm_abi.h`) is the launchers' right edge, and the bar notice and the
   right-aligned status never draw left of it.
   right-aligned status never draw left of it.
@@ -407,7 +415,14 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   live showcase of every control and primitive the toolkit exports.  Buttons
   live showcase of every control and primitive the toolkit exports.  Buttons
   fire on the release edge and keep `active` until `ui->released`: inferring
   fire on the release edge and keep `active` until `ui->released`: inferring
   release from the sampled `ui->buttons` races the WM event queue and drops
   release from the sampled `ui->buttons` races the WM event queue and drops
-  clicks.  Text fields use the proportional font with measured caret,
+  clicks.  The popover component (`ngui_popover_begin`/`footer`, a flat
+  surface with a body and footer, no title bar or close button) is the shell
+  of `netmenu`; `ngui_section` draws captioned section headers with an
+  optional action button, `ngui_list_row` is a two-line hover/selected row
+  with optional signal bars and trailing text, and `ngui_signal_bars` draws
+  the four-bar strength icon.  The WM draws no outer chrome, so a popover
+  fills its whole window.  Text fields use the proportional font with
+  measured caret,
   selection and horizontal scrolling, and support mouse drag-selection,
   selection and horizontal scrolling, and support mouse drag-selection,
   double-click select-all, Ctrl+Left/Right word jumps,
   double-click select-all, Ctrl+Left/Right word jumps,
   Ctrl+Delete/Ctrl+Backspace word deletion and Ctrl+A select-all; typing or
   Ctrl+Delete/Ctrl+Backspace word deletion and Ctrl+A select-all; typing or
@@ -656,9 +671,13 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   the selected driver's probe and leaves the current driver untouched on
   the selected driver's probe and leaves the current driver untouched on
   failure.  The top-bar network icon opens `ucmd_netmenu.c`, which lists every
   failure.  The top-bar network icon opens `ucmd_netmenu.c`, which lists every
   present driver through `SYS_NET_DEVLIST` (111), selects one through
   present driver through `SYS_NET_DEVLIST` (111), selects one through
-  `SYS_NET_SELECT` (112) and runs DHCP; the same window lists scanned WiFi
+  `SYS_NET_SELECT` (112) and runs DHCP; the same popover lists scanned WiFi
   networks, marks the ones in `/data/WIFI.CFG` as saved, joins them with the
   networks, marks the ones in `/data/WIFI.CFG` as saved, joins them with the
   stored passphrase, and has a Saved view that forgets individual networks.
   stored passphrase, and has a Saved view that forgets individual networks.
+  The panel is an ngui popover (a device status card, a scrollable
+  Devices/Wi-Fi/Connection content area with `ngui_section` and
+  `ngui_list_row`, and a footer status line); it opens as a `WIN_F_POPOVER`
+  canvas window anchored under the icon, not as a titled window.
   Hidden SSIDs are omitted, and
   Hidden SSIDs are omitted, and
   BSSIDs that share an SSID/security collapse to the strongest entry (the
   BSSIDs that share an SSID/security collapse to the strongest entry (the
   active BSSID wins while connected).  `wifi.c` (the Intel
   active BSSID wins while connected).  `wifi.c` (the Intel
@@ -2338,9 +2357,13 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
 36. Network menu limits (`ucmd_netmenu.c`): building the device list probes
 36. Network menu limits (`ucmd_netmenu.c`): building the device list probes
     every driver, so opening the menu on a machine with an unconfigured USB
     every driver, so opening the menu on a machine with an unconfigured USB
     NIC can take a moment (USB control transfers) and may initialize a device
     NIC can take a moment (USB control transfers) and may initialize a device
-    that was not the boot-time winner.  The list shows at most six device
-    rows, one menu instance is kept open by the WM, and WiFi scanning is
-    refused while associated (use Disconnect first).  The staged
+    that was not the boot-time winner.  The panel shows at most four device
+    rows plus a "+N more devices" line, one menu instance is kept open by the
+    WM, and WiFi scanning is refused while associated (use Disconnect first).
+    The popover is a 404x520 canvas (with 380x440 and 340x360 fallbacks); the
+    content area scrolls, the connection card can be scrolled away in a long
+    Wi-Fi list, and closing the panel with an outside click kills the netmenu
+    process without cancelling an already started `wifi` helper.  The staged
     `/share/netmenu.wifi` record contains the WPA2 passphrase until the
     `/share/netmenu.wifi` record contains the WPA2 passphrase until the
     `wifi` helper reads and unlinks it; the path is fixed, so two concurrent
     `wifi` helper reads and unlinks it; the path is fixed, so two concurrent
     netmenu instances (e.g. one launched from a terminal) would overwrite
     netmenu instances (e.g. one launched from a terminal) would overwrite

+ 24 - 5
docs/graphics.html

@@ -150,13 +150,27 @@
 			icon, a network status icon shows a
 			icon, a network status icon shows a
 			cable for wired Ethernet, signal bars for a connected WiFi link, a
 			cable for wired Ethernet, signal bars for a connected WiFi link, a
 			USB mark for RNDIS tethering, or a red X when no link is up;
 			USB mark for RNDIS tethering, or a red X when no link is up;
-			clicking it opens the anchored <code>bin/netmenu</code> window.
+			clicking it opens the anchored <code>bin/netmenu</code> popover.
 			Present NICs can be selected (then DHCP runs), and scanned WiFi
 			Present NICs can be selected (then DHCP runs), and scanned WiFi
 			networks can be joined, asking for the WPA2 passphrase first when
 			networks can be joined, asking for the WPA2 passphrase first when
 			the AP requires one. The right-aligned date/time text sits to the
 			the AP requires one. The right-aligned date/time text sits to the
 			icon's left and is also a target: it highlights on hover and opens
 			icon's left and is also a target: it highlights on hover and opens
 			the Date &amp; Time editor (<code>bin/settime</code>) on a click.
 			the Date &amp; Time editor (<code>bin/settime</code>) on a click.
 		</p>
 		</p>
+		<p>
+			A popover is a chromeless canvas window created with
+			<code>u_win_create_popover()</code> (<code>WIN_F_POPOVER</code>).
+			The WM anchors it under the status icon, treats it as always
+			topmost in painting and hit-testing, and draws no chrome at all:
+			the canvas fills the whole window rectangle, with no title bar,
+			shadow, rim or rounded outer corners, so it reads as a flat menu
+			panel. The kernel uses the window origin for content-relative
+			pointer and scroll coordinates. An outside press dismisses the
+			popover and the click then continues normally; a second click on
+			the network icon toggles it. The panel itself is drawn with the
+			ngui popover components: a flat body with section captions and
+			two-line list rows, and a footer status line.
+		</p>
 		<p>
 		<p>
 			The WM is the ring-3 process loaded from
 			The WM is the ring-3 process loaded from
 			<code>/ramfs/bin/wm</code>; there is no kernel WM fallback. The
 			<code>/ramfs/bin/wm</code>; there is no kernel WM fallback. The
@@ -240,9 +254,13 @@
 			counters, so the WM cannot lose one.
 			counters, so the WM cannot lose one.
 		</p>
 		</p>
 		<p>
 		<p>
-			<code>SYS_WIN_CREATE</code> creates a generic canvas window. Input is
-			exposed through <code>SYS_WIN_POINTER</code> (content-relative
-			position, button mask, focus), <code>SYS_WIN_EVENT</code>, which
+			<code>SYS_WIN_CREATE</code> creates a generic canvas window.
+			<code>struct win_create.flags</code> can request
+			<code>WIN_F_POPOVER</code>, a chromeless overlay: the canvas fills
+			the window and the WM supplies only the topmost placement.
+			Input is exposed through <code>SYS_WIN_POINTER</code>
+			(content-relative position, button mask, focus),
+			<code>SYS_WIN_EVENT</code>, which
 			queues press/release edges and a capture window, and
 			queues press/release edges and a capture window, and
 			<code>SYS_WIN_SCROLL</code>, which returns wheel/touchpad scroll
 			<code>SYS_WIN_SCROLL</code>, which returns wheel/touchpad scroll
 			accumulated for the window under the pointer in pixels
 			accumulated for the window under the pointer in pixels
@@ -300,6 +318,7 @@
 		</p>
 		</p>
 		<ul>
 		<ul>
 			<li><strong>Text fields</strong> support drag-selection, double-click select-all, Ctrl+Left/Right word jumps, Ctrl+Delete/Backspace word deletion and Ctrl+A. They use the proportional face with measured caret, selection and horizontal scrolling; a field marked <code>disabled</code> ignores pointer and keyboard input, drops the focus and paints its value dimmed in the same proportional face. A field marked <code>secret</code> is measured and painted from a <code>*</code> mask (caret, selection and click positions follow the mask, Ctrl+Left/Right jump to the ends), and Tab returns <code>NGUI_INPUT_NEXT</code> together with <code>NGUI_INPUT_CANCEL</code> so forms can move the focus. Fields hold up to 511 characters (<code>NGUI_INPUT_MAX</code> 512). The terminal and editor keep the 8×16 cell grid.</li>
 			<li><strong>Text fields</strong> support drag-selection, double-click select-all, Ctrl+Left/Right word jumps, Ctrl+Delete/Backspace word deletion and Ctrl+A. They use the proportional face with measured caret, selection and horizontal scrolling; a field marked <code>disabled</code> ignores pointer and keyboard input, drops the focus and paints its value dimmed in the same proportional face. A field marked <code>secret</code> is measured and painted from a <code>*</code> mask (caret, selection and click positions follow the mask, Ctrl+Left/Right jump to the ends), and Tab returns <code>NGUI_INPUT_NEXT</code> together with <code>NGUI_INPUT_CANCEL</code> so forms can move the focus. Fields hold up to 511 characters (<code>NGUI_INPUT_MAX</code> 512). The terminal and editor keep the 8×16 cell grid.</li>
+			<li><strong>Popover components</strong> give a menu panel its surface: <code>ngui_popover_begin()</code> fills the canvas and returns the body and footer rectangles (no title bar or close button); <code>ngui_section()</code> draws a captioned section header with an optional right-aligned action button; <code>ngui_list_row()</code> is a two-line hover/selected row with optional signal bars and trailing text. The WM draws no outer chrome, so the app paints the whole window.</li>
 			<li><strong>Clip stack</strong> keeps nested panes and popups inside their parents.</li>
 			<li><strong>Clip stack</strong> keeps nested panes and popups inside their parents.</li>
 			<li><strong>Layout cuts</strong> split a rectangle into rows, columns and fixed margins without a constraint solver.</li>
 			<li><strong>Layout cuts</strong> split a rectangle into rows, columns and fixed margins without a constraint solver.</li>
 			<li><strong>No retained widget tree.</strong> Apps redraw from state every frame, which keeps the toolkit small and predictable.</li>
 			<li><strong>No retained widget tree.</strong> Apps redraw from state every frame, which keeps the toolkit small and predictable.</li>
@@ -419,7 +438,7 @@
 			<li><code>cpu.c</code> — SSE2 probing</li>
 			<li><code>cpu.c</code> — SSE2 probing</li>
 			<li><code>wm.c</code>, <code>wm.h</code>, <code>wm_abi.h</code> — kernel window server and shared ABI</li>
 			<li><code>wm.c</code>, <code>wm.h</code>, <code>wm_abi.h</code> — kernel window server and shared ABI</li>
 			<li><code>ucmd_wm.c</code>, <code>uwm_lib.c</code> — ring-3 WM</li>
 			<li><code>ucmd_wm.c</code>, <code>uwm_lib.c</code> — ring-3 WM</li>
-			<li><code>ucmd_netmenu.c</code> — top-bar network menu (NIC selection, DHCP, WiFi scan/passphrase)</li>
+			<li><code>ucmd_netmenu.c</code> — top-bar network popover (NIC selection, DHCP, WiFi scan/passphrase)</li>
 			<li><code>ucmd_settime.c</code>, <code>rtc.c</code>, <code>ntp.c</code> — Date &amp; Time editor, RTC access and SNTP sync</li>
 			<li><code>ucmd_settime.c</code>, <code>rtc.c</code>, <code>ntp.c</code> — Date &amp; Time editor, RTC access and SNTP sync</li>
 			<li><code>gfx.c</code>, <code>gfx.h</code> — RGB565 window canvases</li>
 			<li><code>gfx.c</code>, <code>gfx.h</code> — RGB565 window canvases</li>
 			<li><code>sys_wm.c</code>, <code>sys_wm.h</code> — WM/window ABI</li>
 			<li><code>sys_wm.c</code>, <code>sys_wm.h</code> — WM/window ABI</li>

+ 2 - 2
docs/network.html

@@ -149,7 +149,7 @@
 			<code>SYS_NET_DEVLIST</code> (111), so an RNDIS phone or a USB
 			<code>SYS_NET_DEVLIST</code> (111), so an RNDIS phone or a USB
 			Ethernet dongle that was not the boot-time winner still appears.
 			Ethernet dongle that was not the boot-time winner still appears.
 			Selecting one calls <code>SYS_NET_SELECT</code> (112) and then runs
 			Selecting one calls <code>SYS_NET_SELECT</code> (112) and then runs
-			DHCP. The same window lists scanned WiFi networks; selecting a WPA2
+			DHCP. The same popover lists scanned WiFi networks; selecting a WPA2
 			network asks for the passphrase and starts the existing
 			network asks for the passphrase and starts the existing
 			<code>wifi</code> supplicant, which opens the data port and runs DHCP
 			<code>wifi</code> supplicant, which opens the data port and runs DHCP
 			itself. Mesh/repeater BSSIDs sharing one SSID are collapsed to the
 			itself. Mesh/repeater BSSIDs sharing one SSID are collapsed to the
@@ -505,7 +505,7 @@
 			<li><code>e1000e.c</code>, <code>r8168.c</code>, <code>ne2000.c</code>, <code>asix.c</code>, <code>rndis.c</code></li>
 			<li><code>e1000e.c</code>, <code>r8168.c</code>, <code>ne2000.c</code>, <code>asix.c</code>, <code>rndis.c</code></li>
 			<li><code>wifi.c</code>, <code>wifi_fw.c</code>, <code>iwl_mvm.c</code>, <code>iwl_dvm.c</code>, <code>iwl_trans.c</code>, <code>rtl8821au.c</code> — Intel 7265D/3165 and 6200/6300 WiFi, Realtek RTL8821AU USB WiFi</li>
 			<li><code>wifi.c</code>, <code>wifi_fw.c</code>, <code>iwl_mvm.c</code>, <code>iwl_dvm.c</code>, <code>iwl_trans.c</code>, <code>rtl8821au.c</code> — Intel 7265D/3165 and 6200/6300 WiFi, Realtek RTL8821AU USB WiFi</li>
 			<li><code>wpa.c</code>, <code>wpa_crypto.c</code>, <code>ucmd_wifi.c</code> — WPA2-PSK supplicant and the <code>wifi</code> command (<code>make test-wpa</code>)</li>
 			<li><code>wpa.c</code>, <code>wpa_crypto.c</code>, <code>ucmd_wifi.c</code> — WPA2-PSK supplicant and the <code>wifi</code> command (<code>make test-wpa</code>)</li>
-			<li><code>ucmd_netmenu.c</code>, <code>wifi_cfg.h</code>, <code>wifi_store.c/h</code> — top-bar network menu, staged WiFi connect request and the saved-network list</li>
+			<li><code>ucmd_netmenu.c</code>, <code>wifi_cfg.h</code>, <code>wifi_store.c/h</code> — top-bar network popover, staged WiFi connect request and the saved-network list</li>
 			<li><code>net.c</code>, <code>net.h</code> — ARP cache/ICMP/UDP/IP</li>
 			<li><code>net.c</code>, <code>net.h</code> — ARP cache/ICMP/UDP/IP</li>
 			<li><code>netcore.c</code>, <code>netcore.h</code> — shared receive pump and IRQ helpers</li>
 			<li><code>netcore.c</code>, <code>netcore.h</code> — shared receive pump and IRQ helpers</li>
 			<li><code>dhcp.c</code>, <code>dns.c</code>, <code>ntp.c</code></li>
 			<li><code>dhcp.c</code>, <code>dns.c</code>, <code>ntp.c</code></li>

+ 2 - 2
docs/userland.html

@@ -347,7 +347,7 @@
 			<li><strong>edit</strong> — text editor that draws its own text with the 8x16 font.</li>
 			<li><strong>edit</strong> — text editor that draws its own text with the 8x16 font.</li>
 			<li><strong>clock</strong> / <strong>colors</strong> — small window canvas demos.</li>
 			<li><strong>clock</strong> / <strong>colors</strong> — small window canvas demos.</li>
 			<li><strong>settime</strong> — Date &amp; Time editor opened by clicking the top-bar clock. It reads and writes the CMOS RTC through <code>SYS_RTC_GET</code>/<code>SYS_RTC_SET</code>; the <em>Sync NTP</em> button asks the kernel's SNTP client (<code>SYS_NTP_SYNC</code>, 106) for UTC and writes the result to the RTC. The two-digit RTC year is expanded over 1970–2069 so dead-battery defaults such as 1980/1990 can be corrected.</li>
 			<li><strong>settime</strong> — Date &amp; Time editor opened by clicking the top-bar clock. It reads and writes the CMOS RTC through <code>SYS_RTC_GET</code>/<code>SYS_RTC_SET</code>; the <em>Sync NTP</em> button asks the kernel's SNTP client (<code>SYS_NTP_SYNC</code>, 106) for UTC and writes the result to the RTC. The two-digit RTC year is expanded over 1970–2069 so dead-battery defaults such as 1980/1990 can be corrected.</li>
-			<li><strong>netmenu</strong> — network menu opened by the top-bar status icon. Lists the present NICs from <code>SYS_NET_DEVLIST</code> (Ethernet, USB Ethernet, RNDIS tethering), selects one with <code>SYS_NET_SELECT</code> and runs DHCP. Its WiFi section scans through <code>SYS_WIFI_SCAN</code>/<code>RESULTS</code>, asks for a WPA2 passphrase when the network is not saved and starts the <code>wifi</code> helper through a <code>/share/netmenu.wifi</code> request, because the 64-byte <code>SYS_SPAWN</code> argument cannot hold a long SSID plus passphrase. Networks in <code>/data/WIFI.CFG</code> are marked <em>saved</em> and join with the stored passphrase; a <em>Saved</em> view lists them with a <em>Forget</em> button each. On success the helper moves the SSID/passphrase to the front of the saved list; the next boot's <code>wifi autoconnect</code> helper joins any saved network found. Duplicate BSSIDs for one SSID are collapsed to the strongest entry (or the active one), and hidden networks are omitted.</li>
+			<li><strong>netmenu</strong> — the rich network popover opened by the top-bar status icon. It is a chromeless <code>WIN_F_POPOVER</code> canvas window, anchored by the WM under the icon and dismissed by a click outside or <code>Esc</code>; it has no title bar, shadow or rounded outer corners, and the panel itself is built from the ngui popover/section/list-row components. It shows a connection status card and lists the present NICs from <code>SYS_NET_DEVLIST</code> (Ethernet, USB Ethernet, RNDIS tethering), selects one with <code>SYS_NET_SELECT</code> and runs DHCP. Its WiFi section scans through <code>SYS_WIFI_SCAN</code>/<code>RESULTS</code>, asks for a WPA2 passphrase when the network is not saved and starts the <code>wifi</code> helper through a <code>/share/netmenu.wifi</code> request, because the 64-byte <code>SYS_SPAWN</code> argument cannot hold a long SSID plus passphrase. Networks in <code>/data/WIFI.CFG</code> are marked <em>saved</em> and join with the stored passphrase; a <em>Saved</em> view lists them with a <em>Forget</em> button each. A Connection section shows IP, gateway, DNS and MAC. On success the helper moves the SSID/passphrase to the front of the saved list; the next boot's <code>wifi autoconnect</code> helper joins any saved network found. Duplicate BSSIDs for one SSID are collapsed to the strongest entry (or the active one), and hidden networks are omitted.</li>
 			<li><strong>wm</strong> / <strong>term</strong> — the ring-3 window manager and terminal launcher used by the desktop.</li>
 			<li><strong>wm</strong> / <strong>term</strong> — the ring-3 window manager and terminal launcher used by the desktop.</li>
 		</ul>
 		</ul>
 		<p>
 		<p>
@@ -430,7 +430,7 @@
 			<li><code>browser.c</code>, <code>browser_html.c</code>, <code>svg_raster.c/h</code> (+ <code>svg_test.c</code>), <code>js_browser.c/h</code>, <code>js_mu.c/h</code>, <code>third_party/quickjs/</code>, <code>gallery.c</code></li>
 			<li><code>browser.c</code>, <code>browser_html.c</code>, <code>svg_raster.c/h</code> (+ <code>svg_test.c</code>), <code>js_browser.c/h</code>, <code>js_mu.c/h</code>, <code>third_party/quickjs/</code>, <code>gallery.c</code></li>
 			<li><code>ucmd_chat.c</code>, <code>chat_login.c</code>, <code>ujson.c</code>, <code>uhttp_cookie.c</code> — chat client</li>
 			<li><code>ucmd_chat.c</code>, <code>chat_login.c</code>, <code>ujson.c</code>, <code>uhttp_cookie.c</code> — chat client</li>
 			<li><code>ucmd_wifi.c</code>, <code>wpa.c</code>, <code>wpa_crypto.c</code> — <code>wifi</code> command and the WPA2-PSK supplicant</li>
 			<li><code>ucmd_wifi.c</code>, <code>wpa.c</code>, <code>wpa_crypto.c</code> — <code>wifi</code> command and the WPA2-PSK supplicant</li>
-			<li><code>ucmd_netmenu.c</code>, <code>wifi_cfg.h</code>, <code>wifi_store.c/h</code> — top-bar network menu, staged WiFi connect record and saved-network list</li>
+			<li><code>ucmd_netmenu.c</code>, <code>wifi_cfg.h</code>, <code>wifi_store.c/h</code> — top-bar network popover, staged WiFi connect record and saved-network list</li>
 		</ul>
 		</ul>
 	</section>
 	</section>
 </main>
 </main>

+ 172 - 0
ngui.c

@@ -21,6 +21,8 @@ const struct ngui_theme ngui_theme_dark = {
 	.icon_file   = NGUI_RGB(204, 210, 226),
 	.icon_file   = NGUI_RGB(204, 210, 226),
 	.icon_disk   = NGUI_RGB(112, 174, 232),
 	.icon_disk   = NGUI_RGB(112, 174, 232),
 	.error       = NGUI_RGB(238, 116, 116),
 	.error       = NGUI_RGB(238, 116, 116),
+	.success     = NGUI_RGB(110, 210, 130),
+	.warning     = NGUI_RGB(238, 198, 88),
 };
 };
 
 
 static unsigned int slen(const char *s)
 static unsigned int slen(const char *s)
@@ -1385,6 +1387,176 @@ int ngui_menu_item_utf8(struct ngui *ui, unsigned int id, struct ngui_rect r,
 	return ngui_menu_item_common(ui, id, r, label, shortcut, checked, 1);
 	return ngui_menu_item_common(ui, id, r, label, shortcut, checked, 1);
 }
 }
 
 
+void ngui_popover_begin(struct ngui *ui, struct ngui_popover *p)
+{
+	struct ngui_rect all = { 0, 0, ui->w, ui->h };
+
+	ngui_fill_rect(ui, all, ui->theme.bg);
+	p->body = rect_make(12, 12, ui->w - 24, ui->h - 12 - 28);
+	p->footer = rect_make(12, ui->h - 26, ui->w - 24, 16);
+}
+
+void ngui_popover_footer(struct ngui *ui, const struct ngui_popover *p,
+			 const char *text, unsigned short color)
+{
+	if (!p || !text || !text[0])
+		return;
+	ngui_push_clip(ui, p->footer);
+	ngui_text_px(ui, p->footer.x, p->footer.y, text, slen(text),
+		     color, 11, 0, 0, 0);
+	ngui_pop_clip(ui);
+}
+
+int ngui_section(struct ngui *ui, struct ngui_rect r, const char *caption,
+		 unsigned int action_id, const char *action)
+{
+	struct ngui_rect br;
+	int fired = 0;
+	int y = r.y + (r.h - 18) / 2;
+
+	if (y < r.y)
+		y = r.y;
+	ngui_text_px(ui, r.x, y, caption, slen(caption), ui->theme.text_dim,
+		     11, 1, 0, 0);
+	ngui_fill_rect(ui, rect_make(r.x, r.y + r.h - 1, r.w, 1),
+		       ui->theme.button);
+	if (action_id && action && action[0]) {
+		int tw = (int)ngui_text_width_ui(ui, action);
+		int bw = tw + 24;
+
+		if (bw < 58)
+			bw = 58;
+		br = rect_make(r.x + r.w - bw, r.y + (r.h - 22) / 2, bw, 22);
+		if (ngui_button(ui, action_id, br, action))
+			fired = 1;
+	}
+	return fired;
+}
+
+/* Shared by the byte and UTF-8 variants: one hover/selection row with an
+ * optional signal icon and right-aligned text. */
+static int ngui_list_row_common(struct ngui *ui, unsigned int id,
+				struct ngui_rect r,
+				const struct ngui_row *row, int utf8)
+{
+	int hot = ui->inside && ngui_rect_contains(&r, ui->mouse_x, ui->mouse_y);
+	int press_hot = ui->pressed &&
+		ngui_rect_contains(&r, ui->press_x, ui->press_y);
+	int release_hot = ui->released &&
+		ngui_rect_contains(&r, ui->release_x, ui->release_y);
+	int fired = 0;
+	int left = r.x + 10, right = r.x + r.w - 10;
+	int title_h, sub_h, block_h, ty;
+	unsigned short bg = 0, fg, sub_fg, trail_fg;
+
+	if (press_hot)
+		ui->active = id;
+	if (ui->pressed && ui->released && press_hot && release_hot)
+		fired = 1;
+	if (ui->released && ui->active == id) {
+		if (release_hot)
+			fired = 1;
+		ui->active = 0;
+	}
+
+	if (row->selected)
+		bg = ui->theme.selection;
+	else if (hot || ui->active == id)
+		bg = ui->theme.panel_alt;
+	if (bg)
+		ngui_fill_round_rect(ui, r, 6, 6, 6, 6, bg);
+	fg = ui->theme.text;
+	sub_fg = row->selected ? ui->theme.text : ui->theme.text_dim;
+	trail_fg = row->selected ? ui->theme.text : ui->theme.text_dim;
+
+	if (row->selected) {
+		int cy = r.y + r.h / 2;
+
+		ngui_line(ui, left, cy, left + 3, cy + 4, fg);
+		ngui_line(ui, left + 3, cy + 4, left + 11, cy - 5, fg);
+		left += 17;
+	}
+
+	if (row->trailing && row->trailing[0]) {
+		int tw = (int)ngui_text_width_ui(ui, row->trailing);
+
+		right -= tw + 8;
+		if (utf8)
+			ngui_text_utf8(ui, right + 8,
+				       r.y + (r.h - 16) / 2, row->trailing,
+				       trail_fg);
+		else
+			ngui_text(ui, right + 8, r.y + (r.h - 16) / 2,
+				  row->trailing, trail_fg);
+	}
+	if (row->bars >= 0) {
+		struct ngui_rect br;
+
+		right -= 26;
+		br.x = right + 6;
+		br.y = r.y + (r.h - 14) / 2;
+		br.w = 18;
+		br.h = 14;
+		ngui_signal_bars(ui, br, row->bars,
+				 row->selected ? ui->theme.text :
+						 ui->theme.accent);
+	}
+	if (right <= left)
+		return fired;
+
+	title_h = ngui_text_line_height(ui, ui->font_px, 0);
+	sub_h = ngui_text_line_height(ui, 11, 0);
+	block_h = row->subtitle && row->subtitle[0] ? title_h + sub_h - 2 :
+						      title_h;
+	ty = r.y + (r.h - block_h) / 2;
+	if (ty < r.y)
+		ty = r.y;
+
+	ngui_push_clip(ui, rect_make(left, r.y, right - left, r.h));
+	if (utf8)
+		ngui_text_utf8(ui, left, ty, row->title, fg);
+	else
+		ngui_text(ui, left, ty, row->title, fg);
+	if (row->subtitle && row->subtitle[0])
+		ngui_text_px(ui, left, ty + title_h - 2, row->subtitle,
+			     slen(row->subtitle), sub_fg, 11, 0, 0, 0);
+	ngui_pop_clip(ui);
+
+	if (hot)
+		ui->hot = id;
+	return fired;
+}
+
+int ngui_list_row(struct ngui *ui, unsigned int id, struct ngui_rect r,
+		  const struct ngui_row *row)
+{
+	return ngui_list_row_common(ui, id, r, row, 0);
+}
+
+int ngui_list_row_utf8(struct ngui *ui, unsigned int id, struct ngui_rect r,
+		       const struct ngui_row *row)
+{
+	return ngui_list_row_common(ui, id, r, row, 1);
+}
+
+void ngui_signal_bars(struct ngui *ui, struct ngui_rect r, int bars,
+		      unsigned short color)
+{
+	int i;
+	int base = r.y + r.h - 1;
+
+	for (i = 0; i < 4; i++) {
+		int h = 3 + i * 3;
+		struct ngui_rect br;
+
+		br.x = r.x + i * 5;
+		br.y = base - h;
+		br.w = 3;
+		br.h = h;
+		ngui_fill_rect(ui, br, i < bars ? color : ui->theme.button);
+	}
+}
+
 int ngui_icon_button(struct ngui *ui, unsigned int id, struct ngui_rect r,
 int ngui_icon_button(struct ngui *ui, unsigned int id, struct ngui_rect r,
 		     enum ngui_icon icon){
 		     enum ngui_icon icon){
 	int hot = ui->inside && ngui_rect_contains(&r, ui->mouse_x, ui->mouse_y);
 	int hot = ui->inside && ngui_rect_contains(&r, ui->mouse_x, ui->mouse_y);

+ 35 - 0
ngui.h

@@ -61,6 +61,8 @@ struct ngui_theme {
 	unsigned short icon_file;
 	unsigned short icon_file;
 	unsigned short icon_disk;
 	unsigned short icon_disk;
 	unsigned short error;
 	unsigned short error;
+	unsigned short success;
+	unsigned short warning;
 };
 };
 
 
 extern const struct ngui_theme ngui_theme_dark;
 extern const struct ngui_theme ngui_theme_dark;
@@ -98,6 +100,24 @@ struct ngui_scroll {
 	int drag_dy;
 	int drag_dy;
 };
 };
 
 
+/* A flat menu panel: the surface, a body rectangle for the caller's widgets
+ * and a one-line footer for status text.  There is no title bar or close
+ * button; the app is dismissed by clicking outside it or pressing Esc.  Use
+ * on one chromeless canvas window created with u_win_create_popover(). */
+struct ngui_popover {
+	struct ngui_rect body;
+	struct ngui_rect footer;
+};
+
+/* A two-line list row with optional signal bars and right-aligned text. */
+struct ngui_row {
+	const char *title;
+	const char *subtitle;
+	const char *trailing;
+	int bars;                     /* -1 none, 0..4 signal strength bars */
+	int selected;
+};
+
 struct ngui {
 struct ngui {
 	unsigned short *px;
 	unsigned short *px;
 	int w, h;
 	int w, h;
@@ -246,6 +266,21 @@ int ngui_menu_item_utf8(struct ngui *ui, unsigned int id, struct ngui_rect r,
 			const char *label, const char *shortcut, int checked);
 			const char *label, const char *shortcut, int checked);
 int ngui_icon_button(struct ngui *ui, unsigned int id, struct ngui_rect r,
 int ngui_icon_button(struct ngui *ui, unsigned int id, struct ngui_rect r,
 		     enum ngui_icon icon);
 		     enum ngui_icon icon);
+
+/* Menu panel component (see struct ngui_popover). */
+void ngui_popover_begin(struct ngui *ui, struct ngui_popover *p);
+void ngui_popover_footer(struct ngui *ui, const struct ngui_popover *p,
+			 const char *text, unsigned short color);
+/* Section caption with an optional right-aligned action button; returns 1
+ * when the action fired. */
+int  ngui_section(struct ngui *ui, struct ngui_rect r, const char *caption,
+		  unsigned int action_id, const char *action);
+int  ngui_list_row(struct ngui *ui, unsigned int id, struct ngui_rect r,
+		   const struct ngui_row *row);
+int  ngui_list_row_utf8(struct ngui *ui, unsigned int id, struct ngui_rect r,
+			const struct ngui_row *row);
+void ngui_signal_bars(struct ngui *ui, struct ngui_rect r, int bars,
+		      unsigned short color);
 int ngui_text_input(struct ngui *ui, unsigned int id, struct ngui_rect r,
 int ngui_text_input(struct ngui *ui, unsigned int id, struct ngui_rect r,
 		    struct ngui_input *in);
 		    struct ngui_input *in);
 void ngui_input_set(struct ngui_input *in, const char *s);
 void ngui_input_set(struct ngui_input *in, const char *s);

+ 18 - 2
ucmd_lib.h

@@ -269,14 +269,16 @@ static inline int u_wm_sync(void)
 
 
 /* Generic canvas window (gfx commands own a window instead of replacing a
 /* Generic canvas window (gfx commands own a window instead of replacing a
  * terminal's content). */
  * terminal's content). */
-static inline int u_win_create(unsigned int w, unsigned int h, const char *title,
-			       struct win_info *out)
+static inline int u_win_create_flags(unsigned int w, unsigned int h,
+				     const char *title, unsigned int flags,
+				     struct win_info *out)
 {
 {
 	struct win_create in;
 	struct win_create in;
 	unsigned int i = 0;
 	unsigned int i = 0;
 
 
 	in.w = w;
 	in.w = w;
 	in.h = h;
 	in.h = h;
+	in.flags = flags;
 	while (title && title[i] && i < sizeof(in.title) - 1) {
 	while (title && title[i] && i < sizeof(in.title) - 1) {
 		in.title[i] = title[i];
 		in.title[i] = title[i];
 		i++;
 		i++;
@@ -285,6 +287,20 @@ static inline int u_win_create(unsigned int w, unsigned int h, const char *title
 	return u_syscall2(SYS_WIN_CREATE, (int)&in, (int)out);
 	return u_syscall2(SYS_WIN_CREATE, (int)&in, (int)out);
 }
 }
 
 
+static inline int u_win_create(unsigned int w, unsigned int h, const char *title,
+			       struct win_info *out)
+{
+	return u_win_create_flags(w, h, title, 0, out);
+}
+
+/* A chromeless panel anchored by the WM under the top-bar status icons. */
+static inline int u_win_create_popover(unsigned int w, unsigned int h,
+				       const char *title,
+				       struct win_info *out)
+{
+	return u_win_create_flags(w, h, title, WIN_F_POPOVER, out);
+}
+
 static inline int u_win_present(void)
 static inline int u_win_present(void)
 {
 {
 	return u_syscall1(SYS_WIN_PRESENT, 0);
 	return u_syscall1(SYS_WIN_PRESENT, 0);

+ 376 - 256
ucmd_netmenu.c

@@ -19,7 +19,9 @@
 
 
 #define MAX_DEVS 8
 #define MAX_DEVS 8
 #define MAX_BSS  32
 #define MAX_BSS  32
-#define ROW_H    24
+#define DEV_ROW_H  32
+#define WIFI_ROW_H 38
+#define SAVED_ROW_H 34
 #define LOG_MAX  2048
 #define LOG_MAX  2048
 
 
 #define ID_REFRESH       1
 #define ID_REFRESH       1
@@ -34,6 +36,8 @@
 #define ID_DEV_BASE      100
 #define ID_DEV_BASE      100
 #define ID_BSS_BASE      200
 #define ID_BSS_BASE      200
 #define ID_SAVED_BASE    300
 #define ID_SAVED_BASE    300
+#define ID_INFO_BASE     400
+#define ID_SAVED_ROW_BASE 500
 
 
 #define ACT_REFRESH    (1u << 0)
 #define ACT_REFRESH    (1u << 0)
 #define ACT_SCAN       (1u << 1)
 #define ACT_SCAN       (1u << 1)
@@ -46,8 +50,9 @@
 enum { VIEW_MAIN, VIEW_PASS, VIEW_CONNECT, VIEW_SAVED };
 enum { VIEW_MAIN, VIEW_PASS, VIEW_CONNECT, VIEW_SAVED };
 
 
 static struct ngui ui;
 static struct ngui ui;
+static struct ngui_popover pop;
 static struct ngui_input pass_in;
 static struct ngui_input pass_in;
-static struct ngui_scroll wifi_scroll;
+static struct ngui_scroll main_scroll;
 static struct ngui_scroll saved_scroll;
 static struct ngui_scroll saved_scroll;
 
 
 static struct sys_netdev devs[MAX_DEVS];
 static struct sys_netdev devs[MAX_DEVS];
@@ -146,6 +151,25 @@ static char *put_ip(char *p, const unsigned char ip[4])
 	return p;
 	return p;
 }
 }
 
 
+static char *put_mac(char *p, const unsigned char mac[6])
+{
+	static const char hex[] = "0123456789abcdef";
+	int i;
+
+	for (i = 0; i < 6; i++) {
+		*p++ = hex[mac[i] >> 4];
+		*p++ = hex[mac[i] & 15];
+		if (i != 5)
+			*p++ = ':';
+	}
+	return p;
+}
+
+static int ip_any(const unsigned char ip[4])
+{
+	return ip[0] || ip[1] || ip[2] || ip[3];
+}
+
 static void ssid_name(const struct sys_wifi_bss *b, char out[33])
 static void ssid_name(const struct sys_wifi_bss *b, char out[33])
 {
 {
 	unsigned int i, n = b->ssid_len;
 	unsigned int i, n = b->ssid_len;
@@ -370,7 +394,7 @@ static void start_scan(void)
 	scanning = 1;
 	scanning = 1;
 	scan_start = u_ticks_ms();
 	scan_start = u_ticks_ms();
 	nbss = 0;
 	nbss = 0;
-	wifi_scroll.offset = 0;
+	main_scroll.offset = 0;
 	ngui_invalidate(&ui);
 	ngui_invalidate(&ui);
 }
 }
 
 
@@ -686,305 +710,387 @@ static void handle_actions(void)
 	}
 	}
 }
 }
 
 
-static void draw_bars(int x, int y, int bars, unsigned short color)
-{
-	int i;
-
-	for (i = 0; i < 4; i++) {
-		int h = 3 + i * 3;
-		struct ngui_rect r;
-
-		r.x = x + i * 5;
-		r.y = y + 12 - h;
-		r.w = 3;
-		r.h = h;
-		ngui_fill_rect(&ui, r, i < bars ? color : ui.theme.border);
-	}
-}
-
 static void draw_status(void)
 static void draw_status(void)
 {
 {
 	if (status[0] && status_until &&
 	if (status[0] && status_until &&
 	    (int)(u_ticks_ms() - status_until) < 0)
 	    (int)(u_ticks_ms() - status_until) < 0)
-		ngui_text_utf8(&ui, 10, ui.h - 22, status,
-			  status_error ? ui.theme.error : ui.theme.accent);
+		ngui_popover_footer(&ui, &pop, status,
+			status_error ? ui.theme.error : ui.theme.success);
+}
+
+/* The active connection at the top of the panel: a status dot, the link
+ * state and the device address (plus the SSID and RSSI on Wi-Fi). */
+static void draw_status_card(struct ngui_rect r)
+{
+	struct ngui_rect line_r = { r.x + 34, r.y + 34, r.w - 44, 16 };
+	struct ngui_rect dot = { r.x + 14, r.y + 25, 10, 10 };
+	char line[160], *p;
+	unsigned short dot_color;
+	int i, have_ip = 0;
+
+	for (i = 0; i < 4; i++)
+		if (net.ip[i])
+			have_ip = 1;
+	if (!net_present)
+		dot_color = ui.theme.error;
+	else if (!have_ip ||
+		 (seq(net.name, "wifi") && wst.state < SYS_WIFI_ST_LINK))
+		dot_color = ui.theme.warning;
+	else
+		dot_color = ui.theme.success;
+
+	ngui_fill_round_rect(&ui, r, 8, 8, 8, 8, ui.theme.panel);
+	ngui_frame_round(&ui, r, 8, 8, 8, 8, 1, ui.theme.panel_alt);
+	ngui_fill_round_rect(&ui, dot, 5, 5, 5, 5, dot_color);
+
+	p = line;
+	if (!net_present)
+		p = sput(p, "Offline");
+	else if (seq(net.name, "wifi"))
+		p = sput(p, wst.state >= SYS_WIFI_ST_LINK ?
+			 "Wi-Fi connected" : "Wi-Fi");
+	else if (seq(net.name, "rndis"))
+		p = sput(p, "USB tethering");
+	else
+		p = sput(p, "Wired network");
+	*p = '\0';
+	ngui_text_px(&ui, r.x + 34, r.y + 10, line, slen(line),
+		     ui.theme.text, 16, 1, 0, 0);
+
+	p = line;
+	if (net_present) {
+		p = sput(p, net.name);
+		p = sput(p, " \xC2\xB7 ");
+		if (have_ip)
+			p = put_ip(p, net.ip);
+		else
+			p = sput(p, "no IP");
+		if (seq(net.name, "wifi") && wst.state >= SYS_WIFI_ST_ASSOC) {
+			p = sput(p, " \xC2\xB7 ");
+			for (i = 0; i < wst.ssid_len && i < 32; i++)
+				*p++ = (char)wst.ssid[i];
+			p = sput(p, "  ");
+			p = put_signed(p, wst.rssi);
+			p = sput(p, " dBm");
+		}
+	} else {
+		p = sput(p, "No network device active");
+	}
+	*p = '\0';
+	ngui_text_ellipsis_utf8(&ui, line_r, line_r.x, line_r.y, line,
+				ui.theme.text_dim);
 }
 }
 
 
-static void draw_wifi_list(struct ngui_rect area)
+static void draw_wifi_list(struct ngui_rect area, int *y)
 {
 {
-	char label[40], shortcut[20];
+	struct ngui_row row;
+	char ssid[33], sub[72], *p;
 	int i;
 	int i;
 
 
 	if (!wifi_present) {
 	if (!wifi_present) {
-		ngui_text(&ui, area.x + 2, area.y + 4,
-			  "No WiFi card detected", ui.theme.text_dim);
+		ngui_text_px(&ui, area.x + 12, *y + 10,
+			     "No Wi-Fi card detected", 22,
+			     ui.theme.text_dim, 11, 0, 0, 0);
+		*y += WIFI_ROW_H;
 		return;
 		return;
 	}
 	}
 	if (scanning) {
 	if (scanning) {
-		ngui_text(&ui, area.x + 2, area.y + 4,
-			  "Scanning...", ui.theme.text_dim);
+		ngui_text_px(&ui, area.x + 12, *y + 10,
+			     "Scanning for networks...", 24,
+			     ui.theme.accent, 11, 0, 0, 0);
+		*y += WIFI_ROW_H;
 		return;
 		return;
 	}
 	}
 	if (nbss == 0) {
 	if (nbss == 0) {
-		ngui_text(&ui, area.x + 2, area.y + 4,
-			  wst.state >= SYS_WIFI_ST_ASSOC ?
-			  "Connected - Disconnect to scan for other networks" :
-			  "Press Scan to list WiFi networks",
-			  ui.theme.text_dim);
+		const char *msg = wst.state >= SYS_WIFI_ST_ASSOC ?
+			"Connected - disconnect to scan for other networks" :
+			"Press Scan to list Wi-Fi networks";
+
+		ngui_text_px(&ui, area.x + 12, *y + 10, msg, slen(msg),
+			     ui.theme.text_dim, 11, 0, 0, 0);
+		*y += WIFI_ROW_H;
 		return;
 		return;
 	}
 	}
 
 
-	wifi_scroll.content_h = nbss * ROW_H;
-	ngui_scroll_begin(&ui, area, &wifi_scroll);
-	ngui_scroll_wheel(&ui, area, &wifi_scroll);
-	ngui_scroll_keys(&ui, &wifi_scroll);
 	for (i = 0; i < nbss; i++) {
 	for (i = 0; i < nbss; i++) {
-		struct ngui_rect rr;
 		struct sys_wifi_bss *b = &bss[i];
 		struct sys_wifi_bss *b = &bss[i];
-		char ssid[33];
-		int sw, bx, clicked;
-		unsigned short signal;
-
-		rr.x = area.x;
-		rr.y = area.y - wifi_scroll.offset + i * ROW_H;
-		rr.w = area.w - 16;
-		rr.h = ROW_H - 2;
-		if (rr.y + rr.h <= area.y || rr.y >= area.y + area.h)
-			continue;
+		struct ngui_rect r = { area.x, *y, area.w - 18, WIFI_ROW_H };
+
+		if (r.y + r.h > area.y && r.y < area.y + area.h) {
+			ssid_name(b, ssid);
+			p = sub;
+			p = sput(p, security_name(b->security));
+			if (bss_saved(b) >= 0)
+				p = sput(p, " \xC2\xB7 saved");
+			if (bss_is_active(b))
+				p = sput(p, " \xC2\xB7 connected");
+			*p = '\0';
 
 
-		ssid_name(b, ssid);
-		sput(label, ssid);
-		sput(shortcut, security_name(b->security));
-		if (bss_saved(b) >= 0)
-			sput(shortcut + slen(shortcut), " saved");
-		clicked = ngui_menu_item_utf8(&ui, ID_BSS_BASE + i, rr, label,
-					 shortcut, bss_is_active(b));
-
-		sw = (int)ngui_text_width_ui(&ui, shortcut);
-		bx = rr.x + rr.w - 8 - sw - 30;
-		if (b->security == SYS_WIFI_SEC_OTHER)
-			signal = ui.theme.error;
-		else
-			signal = rssi_bars(b->rssi) >= 3 ? ui.theme.accent :
-				 ui.theme.text_dim;
-		draw_bars(bx, rr.y + 3, rssi_bars(b->rssi), signal);
-		if (clicked) {
-			action_bss = i;
+			row.title = ssid;
+			row.subtitle = sub;
+			row.trailing = 0;
+			row.bars = b->security == SYS_WIFI_SEC_OTHER ? -1 :
+				   rssi_bars(b->rssi);
+			row.selected = bss_is_active(b);
+			if (ngui_list_row_utf8(&ui, ID_BSS_BASE + i, r,
+					       &row))
+				action_bss = i;
 		}
 		}
+		*y += WIFI_ROW_H;
 	}
 	}
-	ngui_scroll_end(&ui, area, &wifi_scroll);
 }
 }
 
 
 static void draw_main(void)
 static void draw_main(void)
 {
 {
-	struct ngui_rect body = { 10, 8, ui.w - 20, ui.h - 34 };
-	struct ngui_rect r, rb;
-	char line[128], *p;
-	int i, shown;
+	struct ngui_rect body = pop.body;
+	struct ngui_rect card, area, r;
+	struct ngui_row row;
+	char line[48], *p;
+	int i, y, content_h, shown, more;
 
 
-	/* Active connection summary. */
-	r = ngui_cut_top(&body, 20);
-	p = line;
-	if (!net_present) {
-		p = sput(p, "No active network device");
-	} else {
-		p = sput(p, "Active: ");
-		p = sput(p, net.name);
-		p = sput(p, " (");
-		p = sput(p, net.chip);
-		p = sput(p, ")");
-		if (seq(net.name, "wifi") && wst.state >= SYS_WIFI_ST_ASSOC) {
-			p = sput(p, "  ");
-			for (i = 0; i < wst.ssid_len && i < 32; i++)
-				*p++ = (char)wst.ssid[i];
-			p = sput(p, " ");
-			p = put_signed(p, wst.rssi);
-			p = sput(p, " dBm");
-		}
-	}
-	*p = '\0';
-	ngui_text_ellipsis_utf8(&ui, r, r.x, r.y, line, ui.theme.text);
+	card = ngui_cut_top(&body, 64);
+	draw_status_card(card);
+	body.y += 8;
+	body.h -= 8;
 
 
-	r = ngui_cut_top(&body, 20);
-	p = line;
-	if (net_present) {
-		p = sput(p, "IP ");
-		if (net.ip[0] || net.ip[1] || net.ip[2] || net.ip[3])
-			p = put_ip(p, net.ip);
-		else
-			p = sput(p, "not configured");
-		if (seq(net.name, "wifi"))
-			p = sput(p, wst.state >= SYS_WIFI_ST_LINK ?
-				 "  link up" : "  link down");
-	} else if (wifi_present) {
-		p = sput(p, "WiFi card present - scan to join a network");
-	} else {
-		p = sput(p, "Plug in Ethernet or USB tethering, then Refresh");
-	}
-	*p = '\0';
-	ngui_text_ellipsis_utf8(&ui, r, r.x, r.y, line, ui.theme.text_dim);
-	body.y += 4;
-	body.h -= 4;
-
-	/* Devices. */
-	r = ngui_cut_top(&body, 26);
-	ngui_text(&ui, r.x, r.y + 3, "Network devices", ui.theme.text_dim);
-	rb = r;
-	rb.x = r.x + r.w - 78;
-	rb.w = 78;
-	rb.h = 22;
-	if (ngui_button(&ui, ID_REFRESH, rb, "Refresh"))
+	shown = 0;
+	for (i = 0; i < ndev; i++)
+		if (devs[i].kind != SYS_NETDEV_WIFI)
+			shown++;
+	more = shown > 4 ? shown - 4 : 0;
+	if (shown > 4)
+		shown = 4;
+
+	content_h = 26 + (shown ? shown * DEV_ROW_H : DEV_ROW_H) +
+		    (more ? 18 : 0) + 10 + 26;
+	if (!wifi_present || scanning || nbss == 0)
+		content_h += WIFI_ROW_H;
+	else
+		content_h += nbss * WIFI_ROW_H;
+	if (net_present)
+		content_h += 10 + 26 + 4 * 26;
+	if (nsaved)
+		content_h += SAVED_ROW_H + 8;
+
+	main_scroll.content_h = content_h;
+	area = body;
+	ngui_scroll_begin(&ui, area, &main_scroll);
+	ngui_scroll_wheel(&ui, area, &main_scroll);
+	ngui_scroll_keys(&ui, &main_scroll);
+
+	y = area.y - main_scroll.offset;
+	r = (struct ngui_rect){ area.x, y, area.w - 18, 26 };
+	if (ngui_section(&ui, r, "Devices", ID_REFRESH, "Refresh"))
 		actions |= ACT_REFRESH;
 		actions |= ACT_REFRESH;
+	y += 26;
 
 
-	shown = 0;
-	for (i = 0; i < ndev && shown < 6; i++) {
-		if (devs[i].kind == SYS_NETDEV_WIFI)
-			continue;
+	{
+		int n = 0;
+
+		for (i = 0; i < ndev && n < shown; i++) {
+			if (devs[i].kind == SYS_NETDEV_WIFI)
+				continue;
+			r = (struct ngui_rect){ area.x, y, area.w - 18,
+						DEV_ROW_H };
+			if (r.y + r.h > area.y && r.y < area.y + area.h) {
+				row.title = devs[i].name;
+				row.subtitle = devs[i].chip;
+				row.trailing = devs[i].active ? "Connected" :
+					       (devs[i].link ? "link" : 0);
+				row.bars = -1;
+				row.selected = devs[i].active;
+				if (ngui_list_row(&ui, ID_DEV_BASE + i, r,
+						  &row))
+					action_dev = i;
+			}
+			y += DEV_ROW_H;
+			n++;
+		}
+	}
+	if (!shown) {
+		const char *msg = wifi_present ?
+			"No wired or USB device" :
+			"No device found - plug one in and Refresh";
+
+		ngui_text_px(&ui, area.x + 12, y + 8, msg, slen(msg),
+			     ui.theme.text_dim, 11, 0, 0, 0);
+		y += DEV_ROW_H;
+	} else if (more) {
 		p = line;
 		p = line;
-		p = sput(p, devs[i].name);
-		p = sput(p, "  ");
-		p = sput(p, devs[i].chip);
+		p = sput(p, "+");
+		p = put_dec(p, (unsigned int)more);
+		p = sput(p, " more devices");
 		*p = '\0';
 		*p = '\0';
-		r = ngui_cut_top(&body, ROW_H);
-		if (ngui_menu_item(&ui, ID_DEV_BASE + i, r, line,
-				   devs[i].active ? "active" :
-				   (devs[i].link ? "link" : ""),
-				   devs[i].active))
-			action_dev = i;
-		shown++;
+		ngui_text_px(&ui, area.x + 12, y + 2, line, slen(line),
+			     ui.theme.text_dim, 11, 0, 0, 0);
+		y += 18;
 	}
 	}
-	if (!shown) {
-		r = ngui_cut_top(&body, ROW_H);
-		ngui_text(&ui, r.x + 2, r.y + 3,
-			  wifi_present ?
-			  "No wired or USB device - use the WiFi list" :
-			  "None found - Refresh after plugging a device in",
-			  ui.theme.text_dim);
+
+	y += 10;
+	r = (struct ngui_rect){ area.x, y, area.w - 18, 26 };
+	if (wifi_present && wst.state >= SYS_WIFI_ST_ASSOC) {
+		if (ngui_section(&ui, r, "Wi-Fi", ID_DISCONNECT,
+				 "Disconnect"))
+			actions |= ACT_DISCONNECT;
+	} else if (wifi_present && !scanning) {
+		if (ngui_section(&ui, r, "Wi-Fi", ID_SCAN, "Scan"))
+			actions |= ACT_SCAN;
+	} else {
+		ngui_section(&ui, r, "Wi-Fi", 0, 0);
 	}
 	}
-	body.y += 6;
-	body.h -= 6;
-
-	/* WiFi networks. */
-	r = ngui_cut_top(&body, 26);
-	ngui_text(&ui, r.x, r.y + 3, "WiFi networks", ui.theme.text_dim);
-	rb = r;
-	rb.x = r.x + r.w - 96;
-	rb.w = 96;
-	rb.h = 22;
-	if (nsaved > 0) {
-		struct ngui_rect sb = rb;
-
-		sb.x = rb.x - 68;
-		sb.w = 64;
-		if (ngui_button(&ui, ID_SAVED, sb, "Saved"))
-			actions |= ACT_SAVED;
+	y += 26;
+
+	draw_wifi_list(area, &y);
+
+	if (net_present) {
+		static const char *labels[4] = {
+			"IP address", "Gateway", "DNS", "MAC address"
+		};
+		char value[40];
+		int di;
+
+		y += 10;
+		r = (struct ngui_rect){ area.x, y, area.w - 18, 26 };
+		ngui_section(&ui, r, "Connection", 0, 0);
+		y += 26;
+		for (di = 0; di < 4; di++) {
+			char *vp = value;
+
+			if (di == 0)
+				vp = ip_any(net.ip) ? put_ip(vp, net.ip) :
+				     sput(vp, "not configured");
+			else if (di == 1)
+				vp = ip_any(net.gw) ? put_ip(vp, net.gw) :
+				     sput(vp, "-");
+			else if (di == 2)
+				vp = ip_any(net.dns) ? put_ip(vp, net.dns) :
+				     sput(vp, "-");
+			else
+				vp = put_mac(vp, net.mac);
+			*vp = '\0';
+
+			r = (struct ngui_rect){ area.x, y, area.w - 18, 26 };
+			if (r.y + r.h > area.y && r.y < area.y + area.h) {
+				row.title = labels[di];
+				row.subtitle = 0;
+				row.trailing = value;
+				row.bars = -1;
+				row.selected = 0;
+				ngui_list_row(&ui, ID_INFO_BASE + di, r, &row);
+			}
+			y += 26;
+		}
 	}
 	}
-	if (wifi_present) {
-		if (wst.state >= SYS_WIFI_ST_ASSOC) {
-			if (ngui_button(&ui, ID_DISCONNECT, rb, "Disconnect"))
-				actions |= ACT_DISCONNECT;
-		} else if (scanning) {
-			ngui_text(&ui, rb.x + 10, rb.y + 3, "Scanning...",
-				  ui.theme.text_dim);
-		} else {
-			if (ngui_button(&ui, ID_SCAN, rb, "Scan"))
-				actions |= ACT_SCAN;
+
+	if (nsaved) {
+		char nbuf[12], *np = nbuf;
+
+		y += 8;
+		r = (struct ngui_rect){ area.x, y, area.w - 18, SAVED_ROW_H };
+		if (r.y + r.h > area.y && r.y < area.y + area.h) {
+			np = put_dec(np, (unsigned int)nsaved);
+			*np = '\0';
+			row.title = "Saved networks";
+			row.subtitle = "Join again without the passphrase";
+			row.trailing = nbuf;
+			row.bars = -1;
+			row.selected = 0;
+			if (ngui_list_row(&ui, ID_SAVED, r, &row))
+				actions |= ACT_SAVED;
 		}
 		}
 	}
 	}
-	draw_wifi_list(body);
+	ngui_scroll_end(&ui, area, &main_scroll);
 }
 }
 
 
 static void draw_pass(void)
 static void draw_pass(void)
 {
 {
-	struct ngui_rect body = { 10, 10, ui.w - 20, ui.h - 40 };
+	struct ngui_rect body = pop.body;
 	struct ngui_rect r, b1, b2;
 	struct ngui_rect r, b1, b2;
 	char line[80], *p;
 	char line[80], *p;
 	int ev;
 	int ev;
 
 
 	r = ngui_cut_top(&body, 24);
 	r = ngui_cut_top(&body, 24);
-	p = sput(line, "Join WiFi network \"");
+	p = sput(line, "Join \"");
 	p = sput(p, sel_ssid);
 	p = sput(p, sel_ssid);
 	p = sput(p, "\"");
 	p = sput(p, "\"");
 	*p = '\0';
 	*p = '\0';
 	ngui_text_ellipsis_utf8(&ui, r, r.x, r.y, line, ui.theme.text);
 	ngui_text_ellipsis_utf8(&ui, r, r.x, r.y, line, ui.theme.text);
 
 
 	r = ngui_cut_top(&body, 22);
 	r = ngui_cut_top(&body, 22);
-	ngui_text(&ui, r.x, r.y, "WPA2-PSK passphrase", ui.theme.text_dim);
+	ngui_text_px(&ui, r.x, r.y, "WPA2-PSK passphrase", 19,
+		     ui.theme.text_dim, 11, 1, 0, 0);
 
 
-	r = ngui_cut_top(&body, 30);
+	r = ngui_cut_top(&body, 34);
 	ev = ngui_text_input(&ui, ID_PASS, r, &pass_in);
 	ev = ngui_text_input(&ui, ID_PASS, r, &pass_in);
 	if (ev & NGUI_INPUT_SUBMIT)
 	if (ev & NGUI_INPUT_SUBMIT)
 		actions |= ACT_CONNECT;
 		actions |= ACT_CONNECT;
 	if (ev & NGUI_INPUT_CANCEL)
 	if (ev & NGUI_INPUT_CANCEL)
 		actions |= ACT_BACK;
 		actions |= ACT_BACK;
-	body.y += 6;
-	body.h -= 6;
+	body.y += 8;
+	body.h -= 8;
+
+	r = ngui_cut_top(&body, 20);
+	ngui_text_px(&ui, r.x, r.y,
+		     "8-63 characters, or 64 hex digits for a raw PSK.",
+		     48, ui.theme.text_dim, 11, 0, 0, 0);
+	body.y += 12;
+	body.h -= 12;
 
 
 	r = ngui_cut_top(&body, 30);
 	r = ngui_cut_top(&body, 30);
 	b1 = r;
 	b1 = r;
-	b1.w = 100;
+	b1.w = 110;
 	b2 = r;
 	b2 = r;
-	b2.x = r.x + 110;
-	b2.w = 100;
+	b2.x = r.x + 120;
+	b2.w = 110;
 	if (ngui_button(&ui, ID_PASS_OK, b1, "Connect"))
 	if (ngui_button(&ui, ID_PASS_OK, b1, "Connect"))
 		actions |= ACT_CONNECT;
 		actions |= ACT_CONNECT;
 	if (ngui_button(&ui, ID_PASS_CANCEL, b2, "Cancel"))
 	if (ngui_button(&ui, ID_PASS_CANCEL, b2, "Cancel"))
 		actions |= ACT_BACK;
 		actions |= ACT_BACK;
-
-	r = ngui_cut_top(&body, 22);
-	ngui_text(&ui, r.x, r.y,
-		  "8-63 characters, or 64 hex digits for a raw PSK.",
-		  ui.theme.text_dim);
-	draw_status();
 }
 }
 
 
 static void draw_connect(void)
 static void draw_connect(void)
 {
 {
-	struct ngui_rect body = { 10, 10, ui.w - 20, ui.h - 40 };
-	struct ngui_rect r, b;
+	struct ngui_rect body = pop.body;
+	struct ngui_rect log, b, r;
 	char line[96], *p;
 	char line[96], *p;
 	unsigned int start = 0, lines = 0, i;
 	unsigned int start = 0, lines = 0, i;
-	int y, line_y;
+	int y, line_y = 0;
 
 
-	r = ngui_cut_top(&body, 24);
-	p = line;
-	if (connect_pid > 0) {
-		p = sput(p, "Connecting to \"");
-		p = sput(p, sel_ssid);
-		p = sput(p, "\"...");
-	} else {
-		p = sput(p, "WiFi connection \"");
-		p = sput(p, sel_ssid);
-		p = sput(p, "\"");
-	}
+	r = ngui_cut_top(&body, 22);
+	p = sput(line, connect_pid > 0 ? "Connecting to \"" :
+		 "Connection to \"");
+	p = sput(p, sel_ssid);
+	p = sput(p, "\"");
 	*p = '\0';
 	*p = '\0';
 	ngui_text_ellipsis_utf8(&ui, r, r.x, r.y, line, ui.theme.text);
 	ngui_text_ellipsis_utf8(&ui, r, r.x, r.y, line, ui.theme.text);
 
 
-	r = ngui_cut_top(&body, 22);
-	if (status[0])
-		ngui_text_utf8(&ui, r.x, r.y, status,
-			  status_error ? ui.theme.error : ui.theme.accent);
-	body.y += 4;
-	body.h -= 4;
+	/* The supplicant trail in a recessed card; the connection state is in
+	 * the popover footer. */
+	log = body;
+	log.h -= 38;
+	ngui_fill_round_rect(&ui, log, 6, 6, 6, 6, ui.theme.panel);
+	ngui_push_clip(&ui, (struct ngui_rect){ log.x + 8, log.y + 8,
+						log.w - 16, log.h - 16 });
 
 
-	/* Last ~12 lines of the helper's terminal output. */
 	for (i = conn_log_len; i > 0; i--) {
 	for (i = conn_log_len; i > 0; i--) {
 		if (conn_log[i - 1] == '\n' && ++lines > 12) {
 		if (conn_log[i - 1] == '\n' && ++lines > 12) {
 			start = i;
 			start = i;
 			break;
 			break;
 		}
 		}
 	}
 	}
-	y = body.y;
-	line_y = 0;
-	for (i = start; i < conn_log_len && y + 16 <= body.y + body.h - 34; i++) {
+	y = log.y + 10;
+	for (i = start; i < conn_log_len && y + 14 <= log.y + log.h - 8; i++) {
 		char c = conn_log[i];
 		char c = conn_log[i];
 
 
 		if (c == '\r')
 		if (c == '\r')
 			continue;
 			continue;
 		if (c == '\n') {
 		if (c == '\n') {
 			line[line_y] = '\0';
 			line[line_y] = '\0';
-			ngui_text_utf8(&ui, body.x, y, line, ui.theme.text_dim);
-			y += 16;
+			if (line_y)
+				ngui_text_px(&ui, log.x + 10, y, line,
+					     (unsigned int)line_y,
+					     ui.theme.text_dim, 11, 0, 0, 1);
+			y += 14;
 			line_y = 0;
 			line_y = 0;
 			continue;
 			continue;
 		}
 		}
@@ -993,14 +1099,15 @@ static void draw_connect(void)
 	}
 	}
 	if (line_y) {
 	if (line_y) {
 		line[line_y] = '\0';
 		line[line_y] = '\0';
-		ngui_text_utf8(&ui, body.x, y, line, ui.theme.text_dim);
+		ngui_text_px(&ui, log.x + 10, y, line, (unsigned int)line_y,
+			     ui.theme.text_dim, 11, 0, 0, 1);
 	}
 	}
+	ngui_pop_clip(&ui);
 
 
-	/* Cancel at the bottom. */
 	b.x = body.x;
 	b.x = body.x;
 	b.y = body.y + body.h - 28;
 	b.y = body.y + body.h - 28;
-	b.w = 100;
-	b.h = 24;
+	b.w = 110;
+	b.h = 26;
 	if (ngui_button(&ui, ID_CONN_CANCEL, b,
 	if (ngui_button(&ui, ID_CONN_CANCEL, b,
 			connect_pid > 0 ? "Cancel" : "Back"))
 			connect_pid > 0 ? "Cancel" : "Back"))
 		actions |= ACT_BACK;
 		actions |= ACT_BACK;
@@ -1008,67 +1115,71 @@ static void draw_connect(void)
 
 
 static void draw_saved(void)
 static void draw_saved(void)
 {
 {
-	struct ngui_rect body = { 10, 10, ui.w - 20, ui.h - 40 };
-	struct ngui_rect r, b, row, bt;
-	char line[96], *p;
+	struct ngui_rect body = pop.body;
+	struct ngui_rect back, row, bt, list, r;
+	struct ngui_row desc;
+	char ssid[33];
 	int i;
 	int i;
 
 
-	r = ngui_cut_top(&body, 24);
-	ngui_text(&ui, r.x, r.y, "Saved WiFi networks", ui.theme.text);
-	body.y += 4;
-	body.h -= 4;
-	body.h -= 34;                 /* room for the Back button */
+	r = ngui_cut_top(&body, 22);
+	ngui_text_px(&ui, r.x, r.y, "Saved Wi-Fi networks", 20,
+		     ui.theme.text, 16, 1, 0, 0);
 
 
 	if (!nsaved) {
 	if (!nsaved) {
-		ngui_text(&ui, body.x + 2, body.y + 4,
-			  "No saved networks", ui.theme.text_dim);
+		ngui_text_px(&ui, body.x + 2, body.y + 4,
+			     "No saved networks", 17,
+			     ui.theme.text_dim, 11, 0, 0, 0);
 	} else {
 	} else {
-		saved_scroll.content_h = nsaved * 28;
-		ngui_scroll_begin(&ui, body, &saved_scroll);
-		ngui_scroll_wheel(&ui, body, &saved_scroll);
+		list = body;
+		list.h -= 38;
+		saved_scroll.content_h = nsaved * 40;
+		ngui_scroll_begin(&ui, list, &saved_scroll);
+		ngui_scroll_wheel(&ui, list, &saved_scroll);
 		ngui_scroll_keys(&ui, &saved_scroll);
 		ngui_scroll_keys(&ui, &saved_scroll);
 		for (i = 0; i < nsaved; i++) {
 		for (i = 0; i < nsaved; i++) {
-			char ssid[33];
-
-			row.x = body.x;
-			row.y = body.y - saved_scroll.offset + i * 28;
-			row.w = body.w - 16;
-			row.h = 26;
-			if (row.y + row.h <= body.y ||
-			    row.y >= body.y + body.h)
+			row.x = list.x;
+			row.y = list.y - saved_scroll.offset + i * 40;
+			row.w = list.w - 16;
+			row.h = 38;
+			if (row.y + row.h <= list.y ||
+			    row.y >= list.y + list.h)
 				continue;
 				continue;
 			cfg_ssid_name(&saved[i], ssid);
 			cfg_ssid_name(&saved[i], ssid);
 			bt = row;
 			bt = row;
 			bt.x = row.x + row.w - 64;
 			bt.x = row.x + row.w - 64;
 			bt.w = 60;
 			bt.w = 60;
-			bt.h = 22;
-			row.w -= 70;
-			p = sput(line, ssid);
-			p = sput(p, saved[i].pass_len ? "   WPA2" : "   open");
-			*p = '\0';
-			ngui_text_ellipsis_utf8(&ui, row, row.x, row.y + 3,
-						line, ui.theme.text);
+			bt.h = 28;
+			bt.y = row.y + 5;
+			row.w -= 76;
+
+			desc.title = ssid;
+			desc.subtitle = saved[i].pass_len ? "WPA2-PSK" : "Open";
+			desc.trailing = 0;
+			desc.bars = -1;
+			desc.selected = 0;
+			ngui_list_row_utf8(&ui, ID_SAVED_ROW_BASE + i, row,
+					   &desc);
+
 			if (ngui_button(&ui, ID_SAVED_BASE + i, bt,
 			if (ngui_button(&ui, ID_SAVED_BASE + i, bt,
 					"Forget")) {
 					"Forget")) {
 				action_saved = i;
 				action_saved = i;
 				actions |= ACT_FORGET;
 				actions |= ACT_FORGET;
 			}
 			}
 		}
 		}
-		ngui_scroll_end(&ui, body, &saved_scroll);
+		ngui_scroll_end(&ui, list, &saved_scroll);
 	}
 	}
 
 
-	b.x = body.x;
-	b.y = body.y + body.h + 6;
-	b.w = 100;
-	b.h = 24;
-	if (ngui_button(&ui, ID_SAVED_BACK, b, "Back"))
+	back.x = body.x;
+	back.y = body.y + body.h - 28;
+	back.w = 100;
+	back.h = 26;
+	if (ngui_button(&ui, ID_SAVED_BACK, back, "Back"))
 		actions |= ACT_BACK;
 		actions |= ACT_BACK;
 }
 }
 
 
 static void draw(void)
 static void draw(void)
 {
 {
-	ngui_fill_rect(&ui, (struct ngui_rect){ 0, 0, ui.w, ui.h },
-		       ui.theme.bg);
+	ngui_popover_begin(&ui, &pop);
 	if (view == VIEW_PASS)
 	if (view == VIEW_PASS)
 		draw_pass();
 		draw_pass();
 	else if (view == VIEW_CONNECT)
 	else if (view == VIEW_CONNECT)
@@ -1077,8 +1188,7 @@ static void draw(void)
 		draw_saved();
 		draw_saved();
 	else
 	else
 		draw_main();
 		draw_main();
-	if (view != VIEW_PASS && view != VIEW_CONNECT)
-		draw_status();
+	draw_status();
 }
 }
 
 
 static void paint_frame(void)
 static void paint_frame(void)
@@ -1099,9 +1209,9 @@ void _start(const char *arg)
 	unsigned int last_status = 0;
 	unsigned int last_status = 0;
 
 
 	(void)arg;
 	(void)arg;
-	if (u_win_create(460, 500, "Network", &wi) != 0 &&
-	    u_win_create(400, 420, "Network", &wi) != 0 &&
-	    u_win_create(340, 360, "Network", &wi) != 0) {
+	if (u_win_create_popover(404, 520, "Network", &wi) != 0 &&
+	    u_win_create_popover(380, 440, "Network", &wi) != 0 &&
+	    u_win_create_popover(340, 360, "Network", &wi) != 0) {
 		u_exit(1);
 		u_exit(1);
 	}
 	}
 	ngui_init(&ui, (unsigned short *)wi.fb, (int)wi.width, (int)wi.height);
 	ngui_init(&ui, (unsigned short *)wi.fb, (int)wi.width, (int)wi.height);
@@ -1109,6 +1219,7 @@ void _start(const char *arg)
 	pass_in.secret = 1;
 	pass_in.secret = 1;
 	pass_in.placeholder = "WPA2 passphrase";
 	pass_in.placeholder = "WPA2 passphrase";
 	view = VIEW_MAIN;
 	view = VIEW_MAIN;
+	main_scroll.offset = 0;
 
 
 	load_devices();
 	load_devices();
 	load_status();
 	load_status();
@@ -1120,6 +1231,7 @@ void _start(const char *arg)
 	}
 	}
 
 
 	for (;;) {
 	for (;;) {
+		static int first_frame = 1;
 		unsigned int now = u_ticks_ms();
 		unsigned int now = u_ticks_ms();
 
 
 		drain_tty();
 		drain_tty();
@@ -1139,6 +1251,14 @@ void _start(const char *arg)
 		if (ngui_begin(&ui)) {
 		if (ngui_begin(&ui)) {
 			draw();
 			draw();
 			ngui_end(&ui);
 			ngui_end(&ui);
+			if (first_frame) {
+				/* The first present can race the WM's initial
+				 * mapping of the popover canvas; paint a second
+				 * frame once so the panel never shows a black
+				 * tail. */
+				first_frame = 0;
+				ngui_invalidate(&ui);
+			}
 			handle_actions();
 			handle_actions();
 		}
 		}
 
 

+ 134 - 36
ucmd_wm.c

@@ -102,7 +102,6 @@ static int bar_net_kind;
 static int bar_net_bars;
 static int bar_net_bars;
 static unsigned int bar_net_color = 0xFF5050u;
 static unsigned int bar_net_color = 0xFF5050u;
 static int netmenu_pid;
 static int netmenu_pid;
-static int netmenu_placed;
 
 
 static void bar_notice(const char *msg)
 static void bar_notice(const char *msg)
 {
 {
@@ -574,6 +573,29 @@ static void draw_bar(void)
 	}
 	}
 }
 }
 
 
+/* A popover is a flat, chromeless panel: the canvas fills the window. */
+static void draw_popover_clip(unsigned int idx, int cx, int cy,
+			      unsigned int cw, unsigned int ch)
+{
+	struct uwin *u = &wins[idx];
+	struct wm_window_info *w = &u->info;
+	unsigned int cwid = w->content_w, chei = w->content_h;
+
+	if (u->mapped && u->map.kind == WM_KIND_GFX) {
+		struct uwm_canvas c;
+
+		c.px = (const unsigned short *)u->map.va;
+		c.w = u->map.w;
+		c.h = u->map.h;
+		if (c.w == cwid && c.h == chei) {
+			usurf_canvas(&screen, &c, w->x, w->y,
+				     cx, cy, cw, ch);
+			return;
+		}
+	}
+	fill_clip(w->x, w->y, cwid, chei, 0x181C28u, cx, cy, cw, ch);
+}
+
 static void draw_window_clip(unsigned int idx, int cx, int cy,
 static void draw_window_clip(unsigned int idx, int cx, int cy,
 			     unsigned int cw, unsigned int ch)
 			     unsigned int cw, unsigned int ch)
 {
 {
@@ -587,6 +609,11 @@ static void draw_window_clip(unsigned int idx, int cx, int cy,
 	unsigned int content_w = w->content_w;
 	unsigned int content_w = w->content_w;
 	unsigned int content_h = w->content_h;
 	unsigned int content_h = w->content_h;
 
 
+	if (w->popover) {
+		draw_popover_clip(idx, cx, cy, cw, ch);
+		return;
+	}
+
 	/* Border, title bar, close button. */
 	/* Border, title bar, close button. */
 	fill_clip(x, y, pw, ph, COL_BORDER, cx, cy, cw, ch);
 	fill_clip(x, y, pw, ph, COL_BORDER, cx, cy, cw, ch);
 	fill_clip(x + 1, y + 1, pw - 2, WM_TITLE_H,
 	fill_clip(x + 1, y + 1, pw - 2, WM_TITLE_H,
@@ -633,17 +660,23 @@ static void draw_window_clip(unsigned int idx, int cx, int cy,
 	}
 	}
 }
 }
 
 
-/* Front-to-back window order: the focused window is on top, the others
- * follow in descending slot order.  Painting and hit-testing share it. */
+/* Front-to-back window order: popovers float above everything, then the
+ * focused window, then the others in descending slot order.  Painting and
+ * hit-testing share it. */
 static unsigned int build_order(int *order)
 static unsigned int build_order(int *order)
 {
 {
 	unsigned int i, n = 0;
 	unsigned int i, n = 0;
 
 
 	for (i = 0; i < WM_MAX_WINDOWS; i++)
 	for (i = 0; i < WM_MAX_WINDOWS; i++)
-		if (wins[i].info.used && wins[i].info.focused)
+		if (wins[i].info.used && wins[i].info.popover)
+			order[n++] = (int)i;
+	for (i = 0; i < WM_MAX_WINDOWS; i++)
+		if (wins[i].info.used && wins[i].info.focused &&
+		    !wins[i].info.popover)
 			order[n++] = (int)i;
 			order[n++] = (int)i;
 	for (i = WM_MAX_WINDOWS; i-- > 0;)
 	for (i = WM_MAX_WINDOWS; i-- > 0;)
-		if (wins[i].info.used && !wins[i].info.focused)
+		if (wins[i].info.used && !wins[i].info.focused &&
+		    !wins[i].info.popover)
 			order[n++] = (int)i;
 			order[n++] = (int)i;
 	return n;
 	return n;
 }
 }
@@ -712,6 +745,7 @@ static void draw_rect_naive(int x, int y, unsigned int w, unsigned int h)
 	usurf_fill(&screen, x, y, w, h, COL_BG);
 	usurf_fill(&screen, x, y, w, h, COL_BG);
 	for (i = 0; i < WM_MAX_WINDOWS; i++)
 	for (i = 0; i < WM_MAX_WINDOWS; i++)
 		if (wins[i].info.used && !wins[i].info.focused &&
 		if (wins[i].info.used && !wins[i].info.focused &&
+		    !wins[i].info.popover &&
 		    x < wins[i].info.x + (int)wins[i].info.w &&
 		    x < wins[i].info.x + (int)wins[i].info.w &&
 		    x + (int)w > wins[i].info.x &&
 		    x + (int)w > wins[i].info.x &&
 		    y < wins[i].info.y + (int)wins[i].info.h &&
 		    y < wins[i].info.y + (int)wins[i].info.h &&
@@ -719,6 +753,14 @@ static void draw_rect_naive(int x, int y, unsigned int w, unsigned int h)
 			draw_window_clip(i, x, y, w, h);
 			draw_window_clip(i, x, y, w, h);
 	for (i = 0; i < WM_MAX_WINDOWS; i++)
 	for (i = 0; i < WM_MAX_WINDOWS; i++)
 		if (wins[i].info.used && wins[i].info.focused &&
 		if (wins[i].info.used && wins[i].info.focused &&
+		    !wins[i].info.popover &&
+		    x < wins[i].info.x + (int)wins[i].info.w &&
+		    x + (int)w > wins[i].info.x &&
+		    y < wins[i].info.y + (int)wins[i].info.h &&
+		    y + (int)h > wins[i].info.y)
+			draw_window_clip(i, x, y, w, h);
+	for (i = 0; i < WM_MAX_WINDOWS; i++)
+		if (wins[i].info.used && wins[i].info.popover &&
 		    x < wins[i].info.x + (int)wins[i].info.w &&
 		    x < wins[i].info.x + (int)wins[i].info.w &&
 		    x + (int)w > wins[i].info.x &&
 		    x + (int)w > wins[i].info.x &&
 		    y < wins[i].info.y + (int)wins[i].info.h &&
 		    y < wins[i].info.y + (int)wins[i].info.h &&
@@ -807,6 +849,18 @@ static int window_at(int mx, int my)
 	for (i = 0; i < n; i++) {
 	for (i = 0; i < n; i++) {
 		struct wm_window_info *w = &wins[order[i]].info;
 		struct wm_window_info *w = &wins[order[i]].info;
 
 
+		if (!w->popover)
+			continue;
+		if (mx >= w->x && my >= w->y &&
+		    mx < w->x + (int)w->w &&
+		    my < w->y + (int)w->h)
+			return order[i];
+	}
+	for (i = 0; i < n; i++) {
+		struct wm_window_info *w = &wins[order[i]].info;
+
+		if (w->popover)
+			continue;
 		if (mx >= w->x && my >= w->y &&
 		if (mx >= w->x && my >= w->y &&
 		    mx < w->x + (int)w->w &&
 		    mx < w->x + (int)w->w &&
 		    my < w->y + (int)w->h)
 		    my < w->y + (int)w->h)
@@ -1244,43 +1298,35 @@ static void do_update(struct wm_status *st)
 			}
 			}
 		}
 		}
 	}
 	}
-	/* Anchor the network menu under its bar icon once it has created its
-	 * window.  The WM owns the geometry syscall, so the app itself does
-	 * not need a special placement ABI. */
-	if (netmenu_pid > 0) {
-		int found = 0;
+	/* Popovers are WM-anchored overlays, right-aligned to the network
+	 * status icon and just below the bar.  The WM owns the geometry, so
+	 * the app does not need a placement ABI. */
+	{
+		int netmenu_found = 0;
 
 
 		for (i = 0; i < WM_MAX_WINDOWS; i++) {
 		for (i = 0; i < WM_MAX_WINDOWS; i++) {
 			struct wm_window_info ni;
 			struct wm_window_info ni;
+			int nx, ny;
 
 
-			if (!wins[i].info.used ||
-			    wins[i].info.pid != (unsigned int)netmenu_pid)
+			if (!wins[i].info.used || !wins[i].info.popover)
 				continue;
 				continue;
-			found = 1;
-			if (!netmenu_placed) {
-				int nx = (bar_net_x >= 0 ?
-					  bar_net_x + (int)bar_net_w :
-					  (int)fbw) - (int)wins[i].info.w;
-				int ny = WM_BAR_H + 2;
-
-				if (nx < 4)
-					nx = 4;
-				if (nx + (int)wins[i].info.w > (int)fbw - 4)
-					nx = (int)fbw - 4 -
-					     (int)wins[i].info.w;
+			if (netmenu_pid > 0 &&
+			    wins[i].info.pid == (unsigned int)netmenu_pid)
+				netmenu_found = 1;
+			nx = (bar_net_x >= 0 ? bar_net_x + (int)bar_net_w :
+			      (int)fbw - 4) - (int)wins[i].info.w;
+			ny = WM_BAR_H + 4;
+			if (nx != wins[i].info.x || ny != wins[i].info.y) {
 				if (u_wm_set_geom(i, nx, ny) == 0 &&
 				if (u_wm_set_geom(i, nx, ny) == 0 &&
 				    u_wm_info(i, &ni) == 1) {
 				    u_wm_info(i, &ni) == 1) {
 					wins[i].info = ni;
 					wins[i].info = ni;
 					full_redraw = 1;
 					full_redraw = 1;
 				}
 				}
-				netmenu_placed = 1;
 			}
 			}
-			break;
 		}
 		}
-		if (!found && !u_alive((unsigned int)netmenu_pid)) {
+		if (!netmenu_found && netmenu_pid > 0 &&
+		    !u_alive((unsigned int)netmenu_pid))
 			netmenu_pid = 0;
 			netmenu_pid = 0;
-			netmenu_placed = 0;
-		}
 	}
 	}
 	/* The RTC is slow (CMOS polling) and the temperature/battery state only
 	/* The RTC is slow (CMOS polling) and the temperature/battery state only
 	 * changes once a second; query them at 1 Hz instead of every 10 ms. */
 	 * changes once a second; query them at 1 Hz instead of every 10 ms. */
@@ -1397,8 +1443,9 @@ static void do_update(struct wm_status *st)
 			continue;
 			continue;
 		if (!w->dmg_w || !w->dmg_h)
 		if (!w->dmg_w || !w->dmg_h)
 			continue;
 			continue;
-		rx = w->x + 1 + (int)w->dmg_x;
-		ry = w->y + 1 + WM_TITLE_H + (int)w->dmg_y;
+		rx = w->x + (w->popover ? 0 : 1) + (int)w->dmg_x;
+		ry = w->y + (w->popover ? 0 : 1 + WM_TITLE_H) +
+		     (int)w->dmg_y;
 		rw = w->dmg_w;
 		rw = w->dmg_w;
 		rh = w->dmg_h;
 		rh = w->dmg_h;
 		add_rect(&present, rx, ry, rw, rh);
 		add_rect(&present, rx, ry, rw, rh);
@@ -1475,7 +1522,7 @@ static void spawn_app_checked(const char *path)
 	}
 	}
 }
 }
 
 
-/* The network icon opens one menu at a time; a second click focuses it. */
+/* The network icon opens one menu at a time; a second click closes it. */
 static void open_netmenu(void)
 static void open_netmenu(void)
 {
 {
 	unsigned int i;
 	unsigned int i;
@@ -1484,10 +1531,17 @@ static void open_netmenu(void)
 		for (i = 0; i < WM_MAX_WINDOWS; i++)
 		for (i = 0; i < WM_MAX_WINDOWS; i++)
 			if (wins[i].info.used &&
 			if (wins[i].info.used &&
 			    wins[i].info.pid == (unsigned int)netmenu_pid) {
 			    wins[i].info.pid == (unsigned int)netmenu_pid) {
-				u_wm_focus(i);
-				full_redraw = 1;
+				if (u_wm_close(i) == 0) {
+					netmenu_pid = 0;
+					full_redraw = 1;
+				} else {
+					u_wm_focus(i);
+					full_redraw = 1;
+				}
 				return;
 				return;
 			}
 			}
+		/* The process is alive but has not created its window yet. */
+		return;
 	}
 	}
 	if (!free_window_slot()) {
 	if (!free_window_slot()) {
 		bar_notice("window limit");
 		bar_notice("window limit");
@@ -1495,7 +1549,6 @@ static void open_netmenu(void)
 		return;
 		return;
 	}
 	}
 	netmenu_pid = u_spawn("/ramfs/bin/netmenu", "", 0, "/");
 	netmenu_pid = u_spawn("/ramfs/bin/netmenu", "", 0, "/");
-	netmenu_placed = 0;
 	if (netmenu_pid < 0) {
 	if (netmenu_pid < 0) {
 		netmenu_pid = 0;
 		netmenu_pid = 0;
 		bar_notice("spawn failed");
 		bar_notice("spawn failed");
@@ -1505,6 +1558,45 @@ static void open_netmenu(void)
 	}
 	}
 }
 }
 
 
+/* Index of a popover containing the point, or -1. */
+static int popover_under(unsigned int mx, unsigned int my)
+{
+	unsigned int i;
+
+	for (i = 0; i < WM_MAX_WINDOWS; i++) {
+		struct wm_window_info *w = &wins[i].info;
+
+		if (w->used && w->popover &&
+		    mx >= (unsigned int)w->x && my >= (unsigned int)w->y &&
+		    mx < (unsigned int)(w->x + (int)w->w) &&
+		    my < (unsigned int)(w->y + (int)w->h))
+			return (int)i;
+	}
+	return -1;
+}
+
+/* A press anywhere outside an open popover dismisses it; the click then
+ * continues normally so the target under the pointer still reacts. */
+static void dismiss_popover_outside(unsigned int mx, unsigned int my)
+{
+	unsigned int i;
+
+	if (popover_under(mx, my) >= 0)
+		return;
+	for (i = 0; i < WM_MAX_WINDOWS; i++) {
+		if (!wins[i].info.used || !wins[i].info.popover)
+			continue;
+		if (wins[i].info.pid == (unsigned int)netmenu_pid)
+			netmenu_pid = 0;
+		if (u_wm_close(i) == 0) {
+			wins[i].info.used = 0;
+			wins[i].mapped = 0;
+			full_redraw = 1;
+		}
+		break;
+	}
+}
+
 static void handle_mouse(struct wm_status *st)
 static void handle_mouse(struct wm_status *st)
 {
 {
 	unsigned int buttons = st->mouse.buttons;
 	unsigned int buttons = st->mouse.buttons;
@@ -1516,6 +1608,8 @@ static void handle_mouse(struct wm_status *st)
 		int prev_title_id = last_title_id;
 		int prev_title_id = last_title_id;
 		unsigned int now = u_ticks_ms();
 		unsigned int now = u_ticks_ms();
 
 
+		if (!bar_net_hit(mx, my))
+			dismiss_popover_outside(mx, my);
 		last_title_id = -1;
 		last_title_id = -1;
 		if (bar_net_hit(mx, my)) {
 		if (bar_net_hit(mx, my)) {
 			open_netmenu();
 			open_netmenu();
@@ -1575,7 +1669,11 @@ static void handle_mouse(struct wm_status *st)
 				int ry = u->info.y + 1;
 				int ry = u->info.y + 1;
 
 
 				u_wm_focus((unsigned int)idx);
 				u_wm_focus((unsigned int)idx);
-				if (pmx >= rx &&
+				if (u->info.popover) {
+					/* A popover has no title bar, close
+					 * button or resize grip; the app owns
+					 * its content. */
+				} else if (pmx >= rx &&
 				    pmx < u->info.x + (int)u->info.w &&
 				    pmx < u->info.x + (int)u->info.w &&
 				    pmy >= ry && pmy < ry + WM_TITLE_H) {
 				    pmy >= ry && pmy < ry + WM_TITLE_H) {
 					u_wm_close((unsigned int)idx);
 					u_wm_close((unsigned int)idx);

+ 81 - 25
wm.c

@@ -64,6 +64,18 @@ static void wm_clamp_window(struct window *w, int nx, int ny);
 static void wm_server_unmap_index(unsigned int idx);
 static void wm_server_unmap_index(unsigned int idx);
 static int wm_window_at(int px, int py);
 static int wm_window_at(int px, int py);
 
 
+/* Content origin: a normal window has a 1 px border and title bar, a popover
+ * is a flat chromeless panel whose canvas fills the window. */
+static int win_content_x(const struct window *w)
+{
+	return w->x + (w->popover ? 0 : 1);
+}
+
+static int win_content_y(const struct window *w)
+{
+	return w->y + (w->popover ? 0 : 1 + WM_TITLE_H);
+}
+
 void wm_request_redraw(void)
 void wm_request_redraw(void)
 {
 {
 	wm_full_redraw = 1;
 	wm_full_redraw = 1;
@@ -183,6 +195,9 @@ int wm_server_win_create(const struct win_create *in, struct win_info *out)
 	unsigned short *back;
 	unsigned short *back;
 	unsigned int i, j, pages, cw, ch, base;
 	unsigned int i, j, pages, cw, ch, base;
 	unsigned int flags;
 	unsigned int flags;
+	int popover = (in && (in->flags & WIN_F_POPOVER)) ? 1 : 0;
+	unsigned int pad = popover ? 0 : 1;
+	unsigned int top = popover ? 0 : WM_TITLE_H + 1;
 
 
 	if (!in || !out)
 	if (!in || !out)
 		return -1;
 		return -1;
@@ -195,7 +210,8 @@ int wm_server_win_create(const struct win_create *in, struct win_info *out)
 		return -1;
 		return -1;
 	if (cw * ch * 2 > WM_CONTENT_SLOT || cw * ch * 2 > USER_WIN_RANGE)
 	if (cw * ch * 2 > WM_CONTENT_SLOT || cw * ch * 2 > USER_WIN_RANGE)
 		return -1;
 		return -1;
-	if (cw + 2 > vga_fb_width() || ch + WM_TITLE_H + 2 > vga_fb_height())
+	if (cw + pad * 2 > vga_fb_width() ||
+	    ch + top + pad > vga_fb_height())
 		return -1;
 		return -1;
 	for (i = 0; i < MAX_WINDOWS; i++)
 	for (i = 0; i < MAX_WINDOWS; i++)
 		if (!windows[i].used)
 		if (!windows[i].used)
@@ -236,6 +252,7 @@ int wm_server_win_create(const struct win_create *in, struct win_info *out)
 	irq_restore(flags);
 	irq_restore(flags);
 
 
 	w->used = 1;
 	w->used = 1;
+	w->popover = popover;
 	w->canvas_window = 1;
 	w->canvas_window = 1;
 	w->pid = current_proc()->pid;
 	w->pid = current_proc()->pid;
 	w->owner_cr3 = base;
 	w->owner_cr3 = base;
@@ -249,15 +266,20 @@ int wm_server_win_create(const struct win_create *in, struct win_info *out)
 	w->scroll_x = w->scroll_y = 0;
 	w->scroll_x = w->scroll_y = 0;
 	w->canvas_dmg_x = w->canvas_dmg_y = 0;
 	w->canvas_dmg_x = w->canvas_dmg_y = 0;
 	w->canvas_dmg_w = w->canvas_dmg_h = 0;
 	w->canvas_dmg_w = w->canvas_dmg_h = 0;
-	w->pw = cw + 2;
-	w->ph = ch + WM_TITLE_H + 2;
-	w->x = 24 + (int)i * 32;
-	w->y = WM_BAR_H + 12 + (int)i * 28;
-	if (w->x + (int)w->pw > (int)vga_fb_width())
-		w->x = ((int)vga_fb_width() > (int)w->pw) ?
-		       (int)vga_fb_width() - (int)w->pw : 0;
-	if (w->y + (int)w->ph > (int)vga_fb_height())
-		w->y = WM_BAR_H + 4;
+	w->pw = cw + pad * 2;
+	w->ph = ch + top + pad;
+	if (popover) {
+		w->x = (int)vga_fb_width() - (int)w->pw - 8;
+		w->y = WM_BAR_H + 2;
+	} else {
+		w->x = 24 + (int)i * 32;
+		w->y = WM_BAR_H + 12 + (int)i * 28;
+		if (w->x + (int)w->pw > (int)vga_fb_width())
+			w->x = ((int)vga_fb_width() > (int)w->pw) ?
+			       (int)vga_fb_width() - (int)w->pw : 0;
+		if (w->y + (int)w->ph > (int)vga_fb_height())
+			w->y = WM_BAR_H + 4;
+	}
 	wm_clamp_window(w, w->x, w->y);
 	wm_clamp_window(w, w->x, w->y);
 	w->focused = 0;
 	w->focused = 0;
 	w->content_gen = 1;
 	w->content_gen = 1;
@@ -444,8 +466,8 @@ int wm_server_win_pointer(struct win_pointer *out)
 	w = &windows[idx];
 	w = &windows[idx];
 	mx = mouse_get_x();
 	mx = mouse_get_x();
 	my = mouse_get_y();
 	my = mouse_get_y();
-	cx = (int)mx - (int)w->x - 1;
-	cy = (int)my - (int)w->y - 1 - WM_TITLE_H;
+	cx = (int)mx - win_content_x(w);
+	cy = (int)my - win_content_y(w);
 	out->x = cx;
 	out->x = cx;
 	out->y = cy;
 	out->y = cy;
 	out->buttons = mouse_buttons_state();
 	out->buttons = mouse_buttons_state();
@@ -491,18 +513,20 @@ int wm_server_resize(unsigned int index, unsigned int cw, unsigned int ch)
 	struct window *w;
 	struct window *w;
 	struct gfx_canvas nf;
 	struct gfx_canvas nf;
 	unsigned short *nb;
 	unsigned short *nb;
-	unsigned int i, pages;
+	unsigned int i, pages, pad, top;
 
 
 	if (!wm_server_is_wm() || index >= MAX_WINDOWS || !windows[index].used)
 	if (!wm_server_is_wm() || index >= MAX_WINDOWS || !windows[index].used)
 		return -1;
 		return -1;
 	w = &windows[index];
 	w = &windows[index];
 	if (!w->canvas_window || !process_is_alive(w->pid))
 	if (!w->canvas_window || !process_is_alive(w->pid))
 		return -1;
 		return -1;
+	pad = w->popover ? 0 : 1;
+	top = w->popover ? 0 : WM_TITLE_H + 1;
 	if (cw < 160 || ch < 80 || cw > WM_WIN_MAX_W || ch > WM_WIN_MAX_H)
 	if (cw < 160 || ch < 80 || cw > WM_WIN_MAX_W || ch > WM_WIN_MAX_H)
 		return -1;
 		return -1;
 	if (cw * ch * 2 > WM_CONTENT_SLOT || cw * ch * 2 > USER_WIN_RANGE)
 	if (cw * ch * 2 > WM_CONTENT_SLOT || cw * ch * 2 > USER_WIN_RANGE)
 		return -1;
 		return -1;
-	if (cw + 2 > vga_fb_width() || ch + WM_TITLE_H + 2 > vga_fb_height())
+	if (cw + pad * 2 > vga_fb_width() || ch + top + pad > vga_fb_height())
 		return -1;
 		return -1;
 	if (gfx_alloc(&nf, cw, ch) != 0)
 	if (gfx_alloc(&nf, cw, ch) != 0)
 		return -1;
 		return -1;
@@ -529,8 +553,8 @@ int wm_server_resize(unsigned int index, unsigned int cw, unsigned int ch)
 	w->pending_back = nb;
 	w->pending_back = nb;
 	w->pending_pages = pages;
 	w->pending_pages = pages;
 	w->resize_pending = 1;
 	w->resize_pending = 1;
-	w->pw = cw + 2;
-	w->ph = ch + WM_TITLE_H + 2;
+	w->pw = cw + pad * 2;
+	w->ph = ch + top + pad;
 	w->content_gen++;
 	w->content_gen++;
 	/* The owner is probably parked in SYS_WIN_KEY_WAIT; wake it so it
 	/* The owner is probably parked in SYS_WIN_KEY_WAIT; wake it so it
 	 * acknowledges the resize (and reflows its content) immediately. */
 	 * acknowledges the resize (and reflows its content) immediately. */
@@ -660,6 +684,7 @@ int wm_server_info(unsigned int index, struct wm_window_info *out)
 	out->used = 1;
 	out->used = 1;
 	out->focused = w->focused ? 1 : 0;
 	out->focused = w->focused ? 1 : 0;
 	out->pid = w->pid;
 	out->pid = w->pid;
+	out->popover = w->popover ? 1 : 0;
 	out->x = (int)w->x;
 	out->x = (int)w->x;
 	out->y = (int)w->y;
 	out->y = (int)w->y;
 	out->w = w->pw;
 	out->w = w->pw;
@@ -854,13 +879,14 @@ static void wm_route_pointer(unsigned int mx, unsigned int my,
 
 
 		if (idx >= 0) {
 		if (idx >= 0) {
 			struct window *w = &windows[idx];
 			struct window *w = &windows[idx];
-			int cx = (int)mx - w->x - 1;
-			int cy = (int)my - w->y - 1 - WM_TITLE_H;
+			int cx = (int)mx - win_content_x(w);
+			int cy = (int)my - win_content_y(w);
 
 
 			if (w->canvas_window && cx >= 0 && cy >= 0 &&
 			if (w->canvas_window && cx >= 0 && cy >= 0 &&
 			    cx < (int)w->canvas.w && cy < (int)w->canvas.h &&
 			    cx < (int)w->canvas.w && cy < (int)w->canvas.h &&
-			    !((int)mx >= w->x + (int)w->pw - 16 &&
-			      (int)my >= w->y + (int)w->ph - 16)) {
+			    (w->popover ||
+			     !((int)mx >= w->x + (int)w->pw - 16 &&
+			       (int)my >= w->y + (int)w->ph - 16))) {
 				wm_queue_ptr_event(w, WIN_EV_POINTER_DOWN,
 				wm_queue_ptr_event(w, WIN_EV_POINTER_DOWN,
 						   cx, cy, buttons);
 						   cx, cy, buttons);
 				wm_ptr_capture = idx;
 				wm_ptr_capture = idx;
@@ -871,8 +897,8 @@ static void wm_route_pointer(unsigned int mx, unsigned int my,
 		struct window *w = &windows[wm_ptr_capture];
 		struct window *w = &windows[wm_ptr_capture];
 
 
 		if (w->used && w->canvas_window) {
 		if (w->used && w->canvas_window) {
-			int cx = (int)mx - (int)w->x - 1;
-			int cy = (int)my - (int)w->y - 1 - WM_TITLE_H;
+			int cx = (int)mx - win_content_x(w);
+			int cy = (int)my - win_content_y(w);
 
 
 			wm_queue_ptr_event(w, WIN_EV_POINTER_UP,
 			wm_queue_ptr_event(w, WIN_EV_POINTER_UP,
 					   cx, cy, buttons);
 					   cx, cy, buttons);
@@ -897,8 +923,8 @@ static void wm_route_scroll(unsigned int mx, unsigned int my)
 	w = &windows[idx];
 	w = &windows[idx];
 	if (!w->canvas_window)
 	if (!w->canvas_window)
 		return;
 		return;
-	cx = (int)mx - w->x - 1;
-	cy = (int)my - w->y - 1 - WM_TITLE_H;
+	cx = (int)mx - win_content_x(w);
+	cy = (int)my - win_content_y(w);
 	if (cx < 0 || cy < 0 || cx >= (int)w->canvas.w ||
 	if (cx < 0 || cy < 0 || cx >= (int)w->canvas.w ||
 	    cy >= (int)w->canvas.h)
 	    cy >= (int)w->canvas.h)
 		return;
 		return;
@@ -1200,10 +1226,16 @@ static void wm_close_window(unsigned int idx)
 	wm_request_redraw();
 	wm_request_redraw();
 }
 }
 
 
-/* Topmost window containing (px,py), or -1. */
+/* Topmost window containing (px,py), or -1.  A popover overrides the normal
+ * focus/slot order: it is an overlay panel and always receives the click. */
 static int wm_window_at(int px, int py)
 static int wm_window_at(int px, int py)
 {
 {
 	unsigned int i;
 	unsigned int i;
+	for (i = 0; i < MAX_WINDOWS; i++)
+		if (windows[i].used && windows[i].popover &&
+		    wm_point_in_rect(px, py, windows[i].x, windows[i].y,
+				     windows[i].pw, windows[i].ph))
+			return (int)i;
 	for (i = 0; i < MAX_WINDOWS; i++)
 	for (i = 0; i < MAX_WINDOWS; i++)
 		if (windows[i].used && windows[i].focused &&
 		if (windows[i].used && windows[i].focused &&
 		    wm_point_in_rect(px, py, windows[i].x, windows[i].y,
 		    wm_point_in_rect(px, py, windows[i].x, windows[i].y,
@@ -1231,6 +1263,30 @@ static void wm_clamp_window(struct window *w, int nx, int ny)
 	int miny = WM_BAR_H;
 	int miny = WM_BAR_H;
 	int maxy = fbh - WM_TITLE_H;
 	int maxy = fbh - WM_TITLE_H;
 
 
+	if (w->popover) {
+		/* A popover is an overlay panel: keep all of it on screen,
+		 * below the bar. */
+		minx = 4;
+		maxx = fbw - (int)w->pw - 4;
+		miny = WM_BAR_H + 2;
+		maxy = fbh - (int)w->ph - 4;
+		if (minx > maxx)
+			minx = maxx = 0;
+		if (miny > maxy)
+			miny = maxy = WM_BAR_H + 2;
+		if (nx < minx)
+			nx = minx;
+		else if (nx > maxx)
+			nx = maxx;
+		if (ny < miny)
+			ny = miny;
+		else if (ny > maxy)
+			ny = maxy;
+		w->x = nx;
+		w->y = ny;
+		return;
+	}
+
 	if (minx > maxx)
 	if (minx > maxx)
 		minx = maxx = 0;
 		minx = maxx = 0;
 	if (miny > maxy)
 	if (miny > maxy)

+ 1 - 0
wm.h

@@ -16,6 +16,7 @@
 
 
 struct window {
 struct window {
 	int used;
 	int used;
+	int popover;             /* WIN_F_POPOVER: no chrome, anchored by the WM */
 	int x, y;                /* title bar top-left; may be negative */
 	int x, y;                /* title bar top-left; may be negative */
 	unsigned int pw, ph;     /* pixel size */
 	unsigned int pw, ph;     /* pixel size */
 	char title[16];
 	char title[16];

+ 7 - 0
wm_abi.h

@@ -67,6 +67,11 @@
 #define WM_KIND_NONE 0
 #define WM_KIND_NONE 0
 #define WM_KIND_GFX  1
 #define WM_KIND_GFX  1
 
 
+/* Canvas-window flags (struct win_create.flags).  A popover is chromeless,
+ * always on top and anchored by the WM under the top-bar network icon; its
+ * canvas fills the whole window rectangle. */
+#define WIN_F_POPOVER   0x1u
+
 struct wm_screen_info {
 struct wm_screen_info {
 	unsigned int width;
 	unsigned int width;
 	unsigned int height;
 	unsigned int height;
@@ -100,6 +105,7 @@ struct wm_window_info {
 	unsigned int used;
 	unsigned int used;
 	unsigned int focused;
 	unsigned int focused;
 	unsigned int pid;
 	unsigned int pid;
+	unsigned int popover;      /* WIN_F_POPOVER: no title bar, drawn on top */
 	int x, y;
 	int x, y;
 	unsigned int w, h;         /* outer window rectangle */
 	unsigned int w, h;         /* outer window rectangle */
 	unsigned int content_w, content_h;
 	unsigned int content_w, content_h;
@@ -147,6 +153,7 @@ struct wm_size {
 /* Generic canvas-window client API (gfx commands own their own window). */
 /* Generic canvas-window client API (gfx commands own their own window). */
 struct win_create {
 struct win_create {
 	unsigned int w, h;
 	unsigned int w, h;
+	unsigned int flags;        /* WIN_F_* */
 	char title[16];
 	char title[16];
 };
 };