4 Комити d57c67b1e4 ... abbc1fbd1b

Аутор SHA1 Порука Датум
  Johannes Zellner abbc1fbd1b Answer ARP/ICMP while receiving a netkexec upload пре 1 недеља
  Johannes Zellner aca4c5c3c5 Turn the control panel into collapsible quick settings пре 1 недеља
  Johannes Zellner 0e15afe99c Keep browser sessions across login POSTs and route #fragments in place пре 1 недеља
  Johannes Zellner a6d2afec15 Persist browser cookies and localStorage in /data пре 1 недеља
32 измењених фајлова са 2064 додато и 256 уклоњено
  1. 98 41
      AGENTS.md
  2. 378 11
      browser.c
  3. 1 1
      docs/cpu.html
  4. 6 3
      docs/development.html
  5. 5 4
      docs/drivers.html
  6. 38 20
      docs/graphics.html
  7. 1 1
      docs/index.html
  8. 13 7
      docs/network.html
  9. 4 2
      docs/userland.html
  10. 98 6
      js_browser.c
  11. 7 0
      js_browser.h
  12. 40 8
      net.c
  13. 7 1
      net.h
  14. 57 28
      netkexec.c
  15. 41 1
      netkexec_send.c
  16. 97 0
      ngui.c
  17. 10 0
      ngui.h
  18. 18 0
      power.c
  19. 5 0
      power.h
  20. 5 0
      sys_wm.c
  21. 1 0
      sys_wm.h
  22. 31 0
      syscall.c
  23. 22 0
      syscall.h
  24. 71 2
      ucmd_curl.c
  25. 40 0
      ucmd_lib.h
  26. 844 60
      ucmd_netmenu.c
  27. 56 44
      ucmd_wm.c
  28. 6 2
      uhttp_cookie.c
  29. 4 1
      uhttp_cookie.h
  30. 14 0
      uhttp_cookie_test.c
  31. 45 13
      wm.c
  32. 1 0
      wm.h

+ 98 - 41
AGENTS.md

@@ -366,24 +366,33 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   grows a window to the full work area (snapping when dragged into the screen
   corner).  The kernel hit-test uses the same order.
   The right-aligned date/time text is itself a click target: `draw_bar()`
-  records its rectangle, the pointer highlights it, and a click spawns
-  `/ramfs/bin/settime` (the `Clock` launcher still opens the analog clock).
+  records its rectangle, the pointer highlights it, and a click opens the
+  control panel (the `Clock` launcher still opens the analog clock).
   The rightmost bar item is the AC/battery status icon: a plug while the
   adapter is online and a level-filled battery on battery.  Hovering it paints
-  a percentage tooltip below the bar, above every window.  To its left is the
-  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.
-  The WM polls `SYS_NET_INFO` (and `SYS_WIFI_STATUS` only while WiFi is active)
-  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.
+  a percentage tooltip below the bar, above every window; clicking it opens
+  the control panel.  To its left is the 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.  The WM polls `SYS_NET_INFO` (and
+  `SYS_WIFI_STATUS` only while WiFi is active) at 1 Hz.  The whole right
+  status area is one click target: the temperature, clock, network and
+  AC/battery items and the gaps between them toggle one
+  `/ramfs/bin/netmenu` control popover, anchored flush against the bottom of
+  the top bar and the right screen edge (`u_wm_set_geom`).  It opens
+  collapsed: the battery/clock summary and
+  the Quick settings pills are visible, while the network, power-mode and
+  date/time settings are hidden until their pill is clicked.  A pill toggles
+  its section in place; the panel resizes itself to the content height (up to
+  the screen) and scrolls when a section is taller.  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 a status target toggles it.
   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
   right-aligned status never draw left of it.
@@ -408,9 +417,16 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `SYS_WIN_SCROLL`, `SYS_WIN_KEY_WAIT` and the generic `SYS_KEY_POLL` handle
   input.  `SYS_WIN_SCROLL` returns scroll accumulated for the canvas window
   under the pointer, in pixels (`+dy` = later content), so every client sees
-  one unit independent of whether it came from the touchpad or a wheel.  The WM
+  one unit independent of whether it came from the touchpad or a wheel.
+  `SYS_WIN_RESIZE_SELF` (115) lets a canvas window grow or shrink itself and
+  `SYS_SCREEN_INFO` (116) returns the framebuffer dimensions; the panel uses
+  them to collapse to the pills or grow over an expanded section.  The kernel
+  refuses a self-resize while the WM owns a frame, and the caller retries.  The WM
   composites the front canvas; presented frames carry monotonic seq
-  counters, so the WM can never lose one.  Closing a window kills its owner;
+  counters, so the WM can never lose one.  `content_gen` comes from a global
+  counter and is unique per window creation, so a close followed by a new
+  window in the same slot forces a remap instead of reusing a stale front
+  canvas mapping.  Closing a window kills its owner;
   the reaper frees the canvas.  `clock`, `colors`, `settime`,
   `term`, `files` and the other apps are canvas clients.  The old
   `SYS_GFX_BEGIN/PRESENT/END` terminal-takeover service and the kernel
@@ -496,7 +512,8 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   The 10% steps clamp at 5..100% and the level is not persisted across a cold
   boot.  `io.c` maps F6/F7 (the ChromeOS EC action row) and `E0 14`/`E0 15`
   (standard brightness scancodes) to `backlight_step()` and consumes them.
-  The `backlight [0-100|up|down|probe]` kernel command is the other interface.
+  The `backlight [0-100|up|down|probe]` kernel command and `SYS_BACKLIGHT`
+  (op 0 get, 1 set, 2 step) are the other interfaces.
   `struct wm_status` carries the level and a change counter
   (`backlight_seq()`); the ring-3 WM shows a centered 3 s bubble with a
   sun icon, the percentage and a bar after each change, and redraws it on
@@ -678,15 +695,20 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `netdev [name]` is a kernel command that shows the active driver or
   switches it (`netdev rndis`, `netdev asix`, `netdev e1000e`, ...); it calls
   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
-  present driver through `SYS_NET_DEVLIST` (111), selects one through
-  `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
-  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.
+  failure.  The top-bar status area opens `ucmd_netmenu.c`, the control
+  panel.  It lists every present driver through `SYS_NET_DEVLIST` (111),
+  selects one
+  through `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 stored passphrase, and has a Saved view that forgets individual networks.
+  The panel is an ngui popover: a battery/AC and clock summary, a brightness
+  slider (when a panel PWM exists), and a Quick settings grid of
+  `ngui_tile`s for Network, the P-state power mode (`SYS_CPUFREQ`) and
+  Date & Time.  Clicking a tile expands that section in place: the network
+  devices/Wi-Fi/connection area (built with `ngui_section` and
+  `ngui_list_row`), three power-mode rows, or an inline date/time editor
+  (fields, Set, Now, Sync NTP — no separate `settime` window).  It opens as a
+  `WIN_F_POPOVER` canvas window, not as a titled window.
   Hidden SSIDs are omitted, and
   BSSIDs that share an SSID/security collapse to the strongest entry (the
   active BSSID wins while connected).  `wifi.c` (the Intel
@@ -770,7 +792,7 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `netdev_shutdown()` always calls `wifi_shutdown()` before a kexec (the RX
   ring would keep writing into reused pages).  The ring-3 side is
   `ucmd_wifi.c` (`wifi`, `wifi up|scan|connect <ssid> [pass]|disconnect`,
-  `wifi connectfile <path>` for the network menu's staged SSID/pass/BSSID
+  `wifi connectfile <path>` for the control panel's staged SSID/pass/BSSID
   record, `wifi saved` to list the saved networks, `wifi autoconnect` for the
   boot helper and `wifi forget [ssid]`),
   `wpa.c/h` (4-way + group handshake, key descriptor v2) and
@@ -854,7 +876,12 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   (`make net-dev BOARD_IP=…`): the WM loop auto-detects the header, the board
   acks every datagram with the next expected offset, verifies the checksum and
   jumps. While idle the same loop answers ARP/ICMP for our IP, so the board is
-  reachable (and MAC-resolvable) without running any command.
+  reachable (and MAC-resolvable) without running any command.  The receive
+  loop keeps answering ARP/ICMP for the receiving NIC as well, because a
+  multi-megabyte upload outlives the host's neighbour entry: unanswered
+  probes make the host drop datagrams while `sendto()` still succeeds.  The
+  host tool stops after 10 s without the offset advancing and reports an
+  `ACK_BADSUM` as a failure instead of as completion.
   `kexec_jump()` calls `smp_stop_aps()` first: every AP gets an INIT and is
   parked in the wait-for-SIPI state before the trampoline overwrites the kernel
   they were executing.  It runs with interrupts off, resets `sched_lock` (an AP
@@ -896,7 +923,7 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   USB errors, a disconnected port or a re-enumeration set `fatal`, and
   `wifi.c` reloads on the next use.  Tested by QEMU `usb-host` passthrough
   on xHCI (C-cut chip, firmware 42.4): 2.4 + 5 GHz scan, WPA2-PSK connect
-  and DHCP through the network menu.
+  and DHCP through the control panel.
 - **Mouse**: `mouse.c/h` — cursor move/draw shared by the PS/2 path
   (IntelliMouse including the 4th-byte wheel, Cirrus/Radeon hardware
   cursor) and the USB backend.  Scroll from every backend accumulates in
@@ -1007,7 +1034,8 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   the platform, effective MHz (`APERF`/`MPERF`), current/requested pstate,
   and on Nehalem the C3/C6 and package residency; the Airmont line adds the
   FSB, nominal MHz, turbo pstate/VID, VID range and the live `PERF_CTL`.
-  `cpufreq [auto|min|max|off|<pstate>]` overrides the governor on both.
+  `cpufreq [auto|min|max|off|<pstate>]` overrides the governor on both;
+  `SYS_CPUFREQ` exposes the same mode set/get to the control panel.
 - **CPU temperature**: `thermal.c/h` — Intel DTS through `IA32_THERM_STATUS`
   (MSR `0x19C`).  Each CPU samples itself once a second from its scheduler
   tick (`struct cpu.temp_c`), and `SYS_CPU_TEMP` (`sys_info.c`) exposes the
@@ -1368,9 +1396,34 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `js_host_http` submits `X <method> <len> <ctype> <url>` to a helper and
   returns the status and body whatever the HTTP status (2 MB response, 16 KB
   request body).  Web Storage is stored in `/share/bls<origin-hash>`
-  (local, per boot) and `/share/bss<pid>-<origin-hash>` (session, per
-  window), outside the page heap that navigation resets.  `console.*` print
-  Error stacks.  `location.assign`/`replace`/`reload` navigate.  The
+  (local) and `/share/bss<pid>-<origin-hash>` (session, per window),
+  outside the page heap that navigation resets.  The helpers share one
+  jar, `/share/bcookies`: `h.jar` is attached before every request
+  (`uhttp_init()` after a POST clears it, which made the request after the
+  OIDC login POST go out cookie-less: "authorization request has
+  expired"), and a helper saves by re-reading the file and replaying only
+  its own request's cookie additions/changes/deletions (`jar_save()` in
+  `ucmd_curl.c`), so parallel helpers cannot clobber each other.  When `/data` is mounted
+  the browser also persists the helpers' cookie jar (`/share/bcookies` ->
+  `/data/BCOOKIES.BIN`) and localStorage (every origin in one
+  `/data/BSTORE.DAT`: `NBLS1\n` then `<origin>\n<len>\n<json>\n` records,
+  192 KB cap) across reboots: `persist_restore()` seeds `/share` from disk
+  at start (a store missing from `/share` is looked up on disk on first
+  use, and a cleared store is kept as `{}` so it cannot reappear), and
+  `persist_tick()` in the main loop writes back what changed at most every
+  3 s (`PERSIST_MS`).  The helpers only touch `/share`.  Both files are
+  plaintext bearer credentials, like `CHAT.CFG`; sessionStorage stays in
+  RAM.  Without `/data` the disk accesses just fail.  `console.*` print
+  Error stacks.  `location.assign`/`replace`/`reload` navigate, except that a
+  change of only the `#fragment` stays on the page: `location.hash` is a
+  live accessor, `href`/`hash`/`assign`/`replace` and clicks on `#...` links
+  update `page_url`, the address bar and history (`host.set_hash`), and a
+  `hashchange` event fires on `window` from the next tick; back/forward
+  between fragments of the same page do the same (hash-routed apps such as
+  the Cloudron dashboard would otherwise reload on every menu click).
+  Clicks on plain elements with listeners (`div role="button"`) reach the
+  innermost laid-out box under the pointer.  `<select>` exposes `options`
+  and `multiple`, and an `<option>` without `value` reports its text.  The
   Cloudron dashboard (`my.<domain>`: a Vite/Vue 3 app, 12 modules / 3.5 MB)
   boots, builds its PKCE request, and its OIDC login form renders, submits
   through `fetch()` with the interaction cookie and shows the server's
@@ -1431,7 +1484,7 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   exists, otherwise `/share/chat.cfg` (or the given path), and are
   re-saved when the server rolls the cookie.  A session left in the old
   `/share/chat.cfg` is copied to `/data` once.  `uhttp_cookie.c/h` is the jar
-  (24 host-only cookies, Path prefix match, Secure, Max-Age/1970-Expires
+  (48 host-only cookies, least-recently-set eviction, Path prefix match, Secure, Max-Age/1970-Expires
   deletion); uhttp stores every `Set-Cookie` (redirects too), sends matching
   cookies on each hop, splits requests/bodies into 1024-byte TLS records or
   MSS-sized TCP sends, takes `accept`/`extra_headers`, follows up to 8
@@ -2410,16 +2463,20 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     firmware layers, `_end` is ~0x85ca0 with the RTL8821AU driver (~41 KB
     below the `0x90000` wall).
 
-36. Network menu limits (`ucmd_netmenu.c`): building the device list probes
+36. Control panel limits (`ucmd_netmenu.c`): building the device list probes
     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
     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
+    The panel opens at a compact height (the summary plus the Quick settings
+    pills) and calls `SYS_WIN_RESIZE_SELF` to grow over an expanded section;
+    it is clamped to the screen and the section scrolls when it is taller.
+    The brightness card and the Power mode pill are hidden when the machine
+    has no panel PWM / P-state control.  The inline Date & Time editor writes
+    the RTC and can block for a 5 s NTP sync.  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
     `wifi` helper reads and unlinks it; the path is fixed, so two concurrent
     netmenu instances (e.g. one launched from a terminal) would overwrite

+ 378 - 11
browser.c

@@ -20,6 +20,7 @@
 #include "browser_html.h"
 #include "js_browser.h"
 #include "uhttp.h"
+#include "uhttp_cookie.h"
 #include "img.h"
 #include "inflate.h"
 #include "ufont.h"
@@ -250,6 +251,8 @@ static unsigned int form_dirty;
 
 static int form_descendant(unsigned int node, unsigned int form);
 static int form_submit_form(unsigned int node, int fire_event);
+static int link_fragment_nav(unsigned int node);
+static void history_push(const char *url);
 static void form_reset_event(unsigned int form);
 
 static unsigned int s_len(const char *s);
@@ -613,6 +616,45 @@ static void js_host_navigate(const char *url)
 	cancel_fetch = 1;
 }
 
+/* Same-document fragment change (location.hash, an <a href="#/x"> click,
+ * back/forward between fragments): the page URL, address bar and history
+ * follow, nothing is reloaded.  `push` adds a history entry. */
+static int page_set_fragment(const char *url, int push)
+{
+	if (!url || !url[0] || s_len(url) >= sizeof(page_url))
+		return -1;
+	s_copy(page_url, url, sizeof(page_url));
+	s_copy(url_in.text, page_url, NGUI_INPUT_MAX);
+	url_in.len = s_len(url_in.text);
+	url_in.cursor = url_in.len;
+	url_in.scroll = 0;
+	if (push)
+		history_push(page_url);
+	ngui_invalidate(&ui);
+	return 0;
+}
+
+static int js_host_set_hash(const char *url)
+{
+	return page_set_fragment(url, 1);
+}
+
+/* 1 when `url` is this page with a different #fragment (and JavaScript runs
+ * the page, so a hash router can react). */
+static int same_doc_fragment(const char *url)
+{
+	unsigned int a = 0, b = 0;
+
+	if (!js_browser_active() || !url)
+		return 0;
+	while (url[a] && url[a] != '#')
+		a++;
+	while (page_url[b] && page_url[b] != '#')
+		b++;
+	return url[a] == '#' && a == b && !strncmp(url, page_url, a) &&
+	       !s_eq(url, page_url);
+}
+
 static void js_host_changed(void)
 {
 	/* Class/style/attribute mutations change computed styles, not just the
@@ -1137,6 +1179,8 @@ static int js_host_click(unsigned int node)
 	 * default action, like a real click (delegated list handlers). */
 	if (!js_browser_event(node, "click", 1, 1))
 		return 1;
+	if (link_fragment_nav(node))
+		return 1;
 	href = br_href(&doc, node);
 	if (resolve_link(page_url, href, url, sizeof(url)) != 0)
 		return 0;
@@ -1283,19 +1327,41 @@ static char *js_host_load_script(const char *url, unsigned int *len)
 /* Web Storage lives in /share, outside the page heap that every navigation
  * resets: localStorage per origin for the boot, sessionStorage per origin
  * and browser window. */
-static void js_storage_path(int kind, char *out, unsigned int cap)
+#define JS_ORIGIN_MAX 160
+
+/* scheme://host[:port] of the page (a local page's whole path). */
+static void js_page_origin(char *origin, unsigned int cap)
 {
-	char origin[160];
-	unsigned int n = 0, i = 0, slashes = 0;
+	unsigned int i = 0, slashes = 0;
 
-	while (page_url[i] && i + 1 < sizeof(origin)) {
+	while (page_url[i] && i + 1 < cap) {
 		if (page_url[i] == '/' && ++slashes == 3)
 			break;
 		origin[i] = page_url[i];
 		i++;
 	}
 	origin[i] = '\0';
-	s_append(out, &n, kind ? "/share/bss" : "/share/bls", cap);
+}
+
+static void js_origin_path(const char *origin, char *out, unsigned int cap)
+{
+	unsigned int n = 0;
+
+	s_append(out, &n, "/share/bls", cap);
+	s_append_dec(out, &n, script_cache_hash(origin), cap);
+}
+
+static void js_storage_path(int kind, char *out, unsigned int cap)
+{
+	char origin[JS_ORIGIN_MAX];
+	unsigned int n = 0;
+
+	js_page_origin(origin, sizeof(origin));
+	if (!kind) {
+		js_origin_path(origin, out, cap);
+		return;
+	}
+	s_append(out, &n, "/share/bss", cap);
 	if (kind) {
 		s_append_dec(out, &n, (unsigned int)u_getpid(), cap);
 		s_append(out, &n, "-", cap);
@@ -1303,27 +1369,285 @@ static void js_storage_path(int kind, char *out, unsigned int cap)
 	s_append_dec(out, &n, script_cache_hash(origin), cap);
 }
 
+static void persist_mark_origin(const char *origin);
+static int persist_store_lookup(const char *origin, char *out, int cap);
+
 static int js_host_storage(int kind, const char *set, char *out, int cap)
 {
-	char path[48];
+	char path[48], origin[JS_ORIGIN_MAX];
 	int rv;
 
 	js_storage_path(kind, path, sizeof(path));
 	if (set) {
-		if (!set[0] || !strcmp(set, "{}")) {
-			u_syscall1(SYS_UNLINK, (int)path);
-			return 0;
+		if (kind) {
+			if (!set[0] || !strcmp(set, "{}")) {
+				u_syscall1(SYS_UNLINK, (int)path);
+				return 0;
+			}
+		} else {
+			/* localStorage keeps an explicit "{}" rather than no
+			 * file: a missing /share file means "not loaded from
+			 * /data yet", and a cleared store must not come back
+			 * from the disk copy before it is flushed. */
+			if (!set[0])
+				set = "{}";
+			js_page_origin(origin, sizeof(origin));
+			persist_mark_origin(origin);
 		}
 		return u_syscall3(SYS_WRITE_FILE, (int)path, (int)set,
 				  (int)strlen(set)) < 0 ? -1 : 0;
 	}
 	rv = u_syscall3(SYS_READ_FILE, (int)path, (int)out, cap - 1);
+	if (rv < 0 && !kind) {
+		/* First use this boot: the persistent copy on /data. */
+		js_page_origin(origin, sizeof(origin));
+		rv = persist_store_lookup(origin, out, cap);
+		if (rv >= 0)
+			u_syscall3(SYS_WRITE_FILE, (int)path, (int)out, rv);
+	}
 	if (rv < 0)
 		return -1;
 	out[rv] = '\0';
 	return rv;
 }
 
+/* ---- persistence on /data ----
+ *
+ * /share is the working copy (RAM, shared by every helper and window); the
+ * installed disk's /data volume keeps the cookie jar and localStorage
+ * across reboots when it is mounted.  The browser owns the disk copies: at
+ * start it restores the jar into /share, and its main loop writes back
+ * whatever changed at most every PERSIST_MS, so a burst of cookie or
+ * setItem updates costs one FAT write.  The helpers only touch /share (they
+ * are killed on focus loss, so they cannot be trusted to flush).  Without a
+ * /data mount every disk access simply fails.  Both files are plaintext
+ * bearer credentials, like /data/CHAT.CFG.  sessionStorage stays in RAM. */
+#define PERSIST_MS        3000u
+#define SHARE_COOKIES     "/share/bcookies"
+#define DATA_COOKIES      "/data/BCOOKIES.BIN"
+#define DATA_STORE        "/data/BSTORE.DAT"
+#define DATA_STORE_MAGIC  "NBLS1\n"
+#define DATA_STORE_MAX    (192u * 1024u)
+#define PERSIST_DIRTY_MAX 8
+
+static unsigned int persist_due;
+static unsigned int cookie_sum_saved;
+static int cookie_sum_valid;
+static char persist_dirty[PERSIST_DIRTY_MAX][JS_ORIGIN_MAX];
+static int persist_ndirty;
+
+static unsigned int persist_sum(const unsigned char *p, unsigned int n)
+{
+	unsigned int h = 2166136261u, i;
+
+	for (i = 0; i < n; i++)
+		h = (h ^ p[i]) * 16777619u;
+	return h;
+}
+
+/* Called once at startup, before any helper runs. */
+static void persist_restore(void)
+{
+	unsigned char *jar = (unsigned char *)malloc(sizeof(struct uhttp_jar));
+	int n;
+
+	if (!jar)
+		return;
+	n = u_syscall3(SYS_READ_FILE, (int)SHARE_COOKIES, (int)jar,
+		       (int)sizeof(struct uhttp_jar));
+	if (n != (int)sizeof(struct uhttp_jar)) {
+		n = u_syscall3(SYS_READ_FILE, (int)DATA_COOKIES, (int)jar,
+			       (int)sizeof(struct uhttp_jar));
+		if (n == (int)sizeof(struct uhttp_jar)) {
+			u_syscall3(SYS_WRITE_FILE, (int)SHARE_COOKIES,
+				   (int)jar, n);
+			cookie_sum_saved = persist_sum(jar, (unsigned int)n);
+			cookie_sum_valid = 1;
+		}
+	}
+	free(jar);
+	persist_due = u_ticks_ms() + PERSIST_MS;
+}
+
+static void persist_mark_origin(const char *origin)
+{
+	int i;
+
+	for (i = 0; i < persist_ndirty; i++)
+		if (s_eq(persist_dirty[i], origin))
+			return;
+	if (persist_ndirty < PERSIST_DIRTY_MAX)
+		s_copy(persist_dirty[persist_ndirty++], origin, JS_ORIGIN_MAX);
+}
+
+/* BSTORE.DAT: "NBLS1\n", then per origin "<origin>\n<length>\n<json>\n".
+ * Walk it; returns 1 with the record's fields, 0 at the end. */
+static int store_next(const char *buf, unsigned int len, unsigned int *pos,
+		      unsigned int *o_off, unsigned int *o_len,
+		      unsigned int *d_off, unsigned int *d_len,
+		      unsigned int *rec_end)
+{
+	unsigned int p = *pos, v = 0;
+
+	if (p >= len)
+		return 0;
+	*o_off = p;
+	while (p < len && buf[p] != '\n')
+		p++;
+	if (p >= len)
+		return 0;
+	*o_len = p - *o_off;
+	p++;
+	while (p < len && buf[p] >= '0' && buf[p] <= '9')
+		v = v * 10 + (unsigned int)(buf[p++] - '0');
+	if (p >= len || buf[p] != '\n')
+		return 0;
+	p++;
+	if (v > len - p)
+		return 0;
+	*d_off = p;
+	*d_len = v;
+	p += v;
+	if (p < len && buf[p] == '\n')
+		p++;
+	*rec_end = p;
+	*pos = p;
+	return 1;
+}
+
+static int store_load(char **out)
+{
+	char *buf = (char *)malloc(DATA_STORE_MAX + 1);
+	int n;
+
+	*out = buf;
+	if (!buf)
+		return -1;
+	n = u_syscall3(SYS_READ_FILE, (int)DATA_STORE, (int)buf,
+		       (int)DATA_STORE_MAX);
+	if (n < (int)s_len(DATA_STORE_MAGIC) ||
+	    !starts_with(buf, DATA_STORE_MAGIC))
+		return 0;
+	return n;
+}
+
+static int persist_store_lookup(const char *origin, char *out, int cap)
+{
+	char *buf;
+	unsigned int pos = s_len(DATA_STORE_MAGIC), oo, ol, d, dl, e;
+	unsigned int olen = s_len(origin);
+	int n = store_load(&buf), rv = -1;
+
+	while (n > 0 && store_next(buf, (unsigned int)n, &pos, &oo, &ol, &d,
+				   &dl, &e)) {
+		if (ol == olen && !memcmp(buf + oo, origin, olen)) {
+			if ((int)dl < cap) {
+				memcpy(out, buf + d, dl);
+				out[dl] = '\0';
+				rv = (int)dl;
+			}
+			break;
+		}
+	}
+	free(buf);
+	return rv;
+}
+
+/* Rewrite BSTORE.DAT with the dirty origins' current /share copies. */
+static void persist_store_flush(void)
+{
+	char *old, *nb, path[48];
+	unsigned int pos = s_len(DATA_STORE_MAGIC), oo, ol, d, dl, e, nn = 0;
+	int n = store_load(&old), i, w;
+
+	nb = (char *)malloc(DATA_STORE_MAX + 1);
+	if (n < 0 || !nb) {
+		free(old);
+		free(nb);
+		return;
+	}
+	s_append(nb, &nn, DATA_STORE_MAGIC, DATA_STORE_MAX);
+	/* Untouched origins first, in their old order. */
+	while (n > 0 && store_next(old, (unsigned int)n, &pos, &oo, &ol, &d,
+				   &dl, &e)) {
+		int dirty = 0;
+
+		for (i = 0; i < persist_ndirty; i++)
+			if (s_len(persist_dirty[i]) == ol &&
+			    !memcmp(persist_dirty[i], old + oo, ol))
+				dirty = 1;
+		if (dirty || nn + (e - oo) > DATA_STORE_MAX)
+			continue;
+		memcpy(nb + nn, old + oo, e - oo);
+		nn += e - oo;
+	}
+	/* Then the changed ones (an emptied store is dropped). */
+	for (i = 0; i < persist_ndirty; i++) {
+		char num[12];
+		unsigned int k = 0;
+
+		js_origin_path(persist_dirty[i], path, sizeof(path));
+		w = u_syscall3(SYS_READ_FILE, (int)path, (int)old,
+			       (int)DATA_STORE_MAX);
+		if (w <= 2)     /* missing or "{}" */
+			continue;
+		s_append_dec(num, &k, (unsigned int)w, sizeof(num));
+		if (nn + s_len(persist_dirty[i]) + k + (unsigned int)w + 3 >
+		    DATA_STORE_MAX) {
+			set_status("Saved site data is full; a site's "
+				   "localStorage was not saved", 1, 6000);
+			continue;
+		}
+		s_append(nb, &nn, persist_dirty[i], DATA_STORE_MAX);
+		nb[nn++] = '\n';
+		s_append(nb, &nn, num, DATA_STORE_MAX);
+		nb[nn++] = '\n';
+		memcpy(nb + nn, old, (unsigned int)w);
+		nn += (unsigned int)w;
+		nb[nn++] = '\n';
+	}
+	u_syscall3(SYS_WRITE_FILE, (int)DATA_STORE, (int)nb, (int)nn);
+	persist_ndirty = 0;
+	free(old);
+	free(nb);
+}
+
+static void persist_cookies_flush(void)
+{
+	unsigned char *jar = (unsigned char *)malloc(sizeof(struct uhttp_jar));
+	unsigned int sum;
+	int n;
+
+	if (!jar)
+		return;
+	n = u_syscall3(SYS_READ_FILE, (int)SHARE_COOKIES, (int)jar,
+		       (int)sizeof(struct uhttp_jar));
+	if (n == (int)sizeof(struct uhttp_jar)) {
+		sum = persist_sum(jar, (unsigned int)n);
+		if (!cookie_sum_valid || sum != cookie_sum_saved) {
+			if (u_syscall3(SYS_WRITE_FILE, (int)DATA_COOKIES,
+				       (int)jar, n) >= 0) {
+				cookie_sum_saved = sum;
+				cookie_sum_valid = 1;
+			}
+		}
+	}
+	free(jar);
+}
+
+/* Main-loop hook: write back to /data at most every PERSIST_MS. */
+static void persist_tick(void)
+{
+	unsigned int now = u_ticks_ms();
+
+	if ((int)(now - persist_due) < 0)
+		return;
+	persist_due = now + PERSIST_MS;
+	persist_cookies_flush();
+	if (persist_ndirty)
+		persist_store_flush();
+}
+
 /* <link rel="modulepreload">: download the page's module graph on all
  * helpers at once into the boot script cache, before any script runs.  The
  * engine's module loader is sequential (one blocking fetch per import), so
@@ -1472,6 +1796,7 @@ static void run_page_scripts(void)
 	host.http = js_host_http;
 	host.load_script = js_host_load_script;
 	host.storage = js_host_storage;
+	host.set_hash = js_host_set_hash;
 	host.page_url = page_url;
 	host.width = ui.w;
 	host.height = ui.h;
@@ -9968,6 +10293,34 @@ static void form_key(int k)
 	ngui_invalidate(&ui);
 }
 
+/* A link to "#..." (or to this page plus a fragment) on a scripted page is
+ * a same-document navigation: update the URL and fire hashchange.  Returns
+ * 1 when handled. */
+static int link_fragment_nav(unsigned int node)
+{
+	const char *href = br_href(&doc, node);
+	char url[BR_URL_MAX];
+	unsigned int n = 0;
+
+	if (!href || !href[0] || !js_browser_active())
+		return 0;
+	if (href[0] == '#') {
+		while (page_url[n] && page_url[n] != '#' && n + 1 < sizeof(url)) {
+			url[n] = page_url[n];
+			n++;
+		}
+		url[n] = '\0';
+		s_append(url, &n, href, sizeof(url));
+	} else if (resolve_link(page_url, href, url, sizeof(url)) != 0) {
+		return 0;
+	}
+	if (!same_doc_fragment(url))
+		return href[0] == '#';
+	page_set_fragment(url, 1);
+	js_browser_hashchange();
+	return 1;
+}
+
 /* The innermost laid-out box under a screen point: the smallest valid box
  * that contains it (the last one wins a tie, i.e. the later/deeper node).
  * Used to deliver clicks to elements that are neither links nor controls
@@ -10025,6 +10378,8 @@ static void handle_page_click(unsigned int *action)
 	form_blur();
 	if (!js_browser_event((unsigned int)node, "click", 1, 1))
 		return;
+	if (link_fragment_nav((unsigned int)node))
+		return;
 	if (resolve_link(page_url, br_href(&doc, (unsigned int)node), url,
 			 sizeof(url)) != 0)
 		return;
@@ -10053,6 +10408,7 @@ void _start(const char *arg)
 	origin_cache_load();
 	css_cache_init();
 	script_cache_init();
+	persist_restore();
 	page_scroll.offset = 0;
 	page_scroll.content_h = 0;
 
@@ -10093,6 +10449,7 @@ void _start(const char *arg)
 			preload_active = 1;
 		}
 		js_browser_tick();
+		persist_tick();
 		if (pending_action)
 			continue;
 		now = u_ticks_ms();
@@ -10128,13 +10485,23 @@ void _start(const char *arg)
 		if (action & ACT_BACK) {
 			if (hist_pos > 0) {
 				hist_pos--;
-				navigate(history[hist_pos], 0);
+				if (same_doc_fragment(history[hist_pos])) {
+					page_set_fragment(history[hist_pos], 0);
+					js_browser_hashchange();
+				} else {
+					navigate(history[hist_pos], 0);
+				}
 			}
 		}
 		if (action & ACT_FORWARD) {
 			if (hist_pos + 1 < hist_len) {
 				hist_pos++;
-				navigate(history[hist_pos], 0);
+				if (same_doc_fragment(history[hist_pos])) {
+					page_set_fragment(history[hist_pos], 0);
+					js_browser_hashchange();
+				} else {
+					navigate(history[hist_pos], 0);
+				}
 			}
 		}
 		if (action & ACT_RELOAD) {

+ 1 - 1
docs/cpu.html

@@ -348,7 +348,7 @@
 		<ul>
 			<li><strong>Nehalem/Westmere P-states.</strong> <code>power_init</code> enables SpeedStep, raises the package C-state limit to C6 when unlocked, reads min/max ratios from <code>PLATFORM_INFO</code> and starts at the maximum non-turbo ratio. The target ratio goes in bits 15:8 of <code>IA32_PERF_CTL</code> with the low byte zero.</li>
 			<li><strong>Airmont/Braswell P-states.</strong> Family 6 model <code>0x4C</code> reads the Atom ratio/VID MSRs (<code>0x66A..0x66D</code>), <code>MSR_FSB_FREQ</code> and the FSB table. The N3060 reports pstates 6..20, BCLK 80 MHz (1600 MHz nominal), turbo pstate 31 (2480 MHz) and VID 0x2D..0x3C. <code>power_init</code> enters at max non-turbo and the governor drops to pstate 6 (480 MHz); <code>IA32_PERF_CTL</code> carries the pstate in 15:8 and the Linux-interpolated VID in 7:0. Turbo is detected but not requested. The probe deliberately avoids package/power-SKU MSRs; an unsupported <code>rdmsr</code> before the IDT triple-faults.</li>
-			<li><strong>Governor.</strong> A 100 ms window picks min/max/linear target pstates; short busy streaks jump to max immediately. Each CPU writes its own <code>IA32_PERF_CTL</code>; <code>cpufreq [auto|min|max|off|&lt;pstate&gt;]</code> overrides it.</li>
+			<li><strong>Governor.</strong> A 100 ms window picks min/max/linear target pstates; short busy streaks jump to max immediately. Each CPU writes its own <code>IA32_PERF_CTL</code>; <code>cpufreq [auto|min|max|off|&lt;pstate&gt;]</code> overrides it, and <code>SYS_CPUFREQ</code> exposes the same auto/min/max/off mode to the control panel's Power mode tile.</li>
 			<li><strong>Telemetry.</strong> <code>power</code> prints effective MHz from APERF/MPERF, the current/requested pstate and, on Airmont, the FSB, nominal MHz, turbo pstate/VID, VID range and live <code>PERF_CTL</code>; <code>sensors</code> prints DTS, board sensors and both EC types; <code>powerinfo</code> prints the AC adapter and battery state, and the WM top bar shows the temperature plus a far-right AC plug or level-filled battery icon (percentage tooltip below it on hover) on ThinkPads and Chromebooks.</li>
 			<li><strong>Thermal.</strong> Each CPU samples its DTS once a second from its scheduler tick; the hottest core is exposed to ring 3. TjMax comes from <code>IA32_TEMPERATURE_TARGET</code> on Nehalem/Westmere, the coretemp 90 °C table on Airmont, and the Bonnell table on older Atoms.</li>
 			<li><strong>Limits.</strong> Package C-states/S0ix remain firmware-managed; Airmont reports no C3/C6 residency and does not request the turbo pstate. The explicit <code>idle c6</code> override is the Nehalem <code>0x20</code> hint; use <code>idle auto</code> for the Airmont C6N (<code>0x58</code>) path.</li>

+ 6 - 3
docs/development.html

@@ -253,9 +253,12 @@ make net-install NETINSTALL_TARGET=sata0
 make net-cmds                   # replace /ramfs only</code></pre>
 		<p>
 			The board must be idle at a shell prompt. The WM loop answers
-			ARP/ICMP, detects the <code>KXN2</code>/<code>KXNP</code> header and
-			pauses the auto-detect while a packet-level command owns the NIC or a
-			transfer is in progress. Datagrams are at most 1400 bytes.
+			ARP/ICMP while idle, detects the <code>KXN2</code>/<code>KXNP</code>
+			header and pauses the auto-detect while a packet-level command owns
+			the NIC or a transfer is in progress.  During the transfer the
+			receive loop keeps answering ARP/ICMP itself, so the host's
+			neighbour entry cannot expire mid-upload. Datagrams are at most
+			1400 bytes.
 		</p>
 		<p>
 			The board address comes from DHCP when a server is present; use

+ 5 - 4
docs/drivers.html

@@ -87,7 +87,7 @@
 					<tr><td>Network</td><td><span class="file">e1000e.c</span> <span class="file">r8168.c</span> <span class="file">ne2000.c</span> <span class="file">asix.c</span> <span class="file">rndis.c</span></td><td>PCI or USB</td><td>Polled, one active receiver</td></tr>
 					<tr><td>WiFi</td><td><span class="file">iwl_trans.c</span> <span class="file">iwl_mvm.c</span> <span class="file">iwl_dvm.c</span> <span class="file">wifi.c</span></td><td>PCIe, Intel 7265D/3165 (<code>8086:095a/095b/3165/3166</code>) and 6200/6300 (<code>8086:4239/422c</code>, <code>4238/422b</code>)</td><td>Polled RX ring; firmware from <code>/ramfs/firmware</code>, loaded on first use</td></tr>
 					<tr><td>USB WiFi</td><td><span class="file">rtl8821au.c</span> <span class="file">wifi.c</span></td><td>USB 2.0 high speed, Realtek RTL8821AU/8811AU (TP-Link Archer T2U Nano <code>2357:011f</code> and the other Linux <code>rtw88_8821au</code> IDs)</td><td>Vendor control requests for registers, one bulk-IN/one bulk-OUT endpoint; firmware + register tables from <code>/ramfs/firmware</code></td></tr>
-					<tr><td>Panel backlight</td><td><span class="file">backlight.c</span></td><td>Intel Braswell/Cherryview graphics MMIO, PCI <code>00:02.0</code> (<code>8086:22b0/22b1</code>)</td><td>Polled register writes; F6/F7 and <code>E0 14</code>/<code>E0 15</code> step 10%</td></tr>
+					<tr><td>Panel backlight</td><td><span class="file">backlight.c</span></td><td>Intel Braswell/Cherryview graphics MMIO, PCI <code>00:02.0</code> (<code>8086:22b0/22b1</code>)</td><td>Polled register writes; F6/F7 and <code>E0 14</code>/<code>E0 15</code> step 10%; <code>SYS_BACKLIGHT</code> drives the control-panel slider</td></tr>
 					<tr><td>PS/2</td><td><span class="file">mouse.c</span>, <span class="file">io.c</span></td><td>i8042</td><td>IRQ 1 keyboard, IRQ 12 mouse; polling fallback</td></tr>
 					<tr><td>Touchpad</td><td><span class="file">i2c.c</span>, <span class="file">touchpad.c</span>, <span class="file">touchpad_gesture.c</span></td><td>LPSS DesignWare I2C, slave <code>0x15</code></td><td>Polled input register every 25 ms; software tap and two-finger scroll gestures; no GPIO interrupt driver</td></tr>
 					<tr><td>Serial</td><td><span class="file">serial.c</span></td><td>16550 UART, COM1</td><td>IRQ 4 ring buffer + polled transmitter</td></tr>
@@ -628,9 +628,10 @@
 			<code>SYS_RTC_GET</code>/<code>SYS_RTC_SET</code> (104/105) expose
 			the full <code>struct sys_datetime</code>; the older
 			<code>SYS_RTC_HMS</code>/<code>SYS_RTC_DATETIME</code> calls remain
-			the small read-only views. The WM’s top-bar date/time is a click
-			target that opens <code>bin/settime</code>; its <em>Sync NTP</em>
-			button fetches UTC through <code>SYS_NTP_SYNC</code> (106), backed
+			the small read-only views. The WM’s top-bar date/time opens the
+			control panel, whose Date &amp; Time tile reveals an inline
+			editor; its <em>Sync NTP</em> button fetches UTC through
+			<code>SYS_NTP_SYNC</code> (106), backed
 			by the SNTP client in <span class="file">ntp.c</span>, and writes
 			it with <code>SYS_RTC_SET</code>. The <code>date</code> command
 			prints the same clock in the classic Linux format.

+ 38 - 20
docs/graphics.html

@@ -149,27 +149,39 @@
 			same pointer path. To the left of the rightmost AC/battery status
 			icon, a network status icon shows 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;
-			clicking it opens the anchored <code>bin/netmenu</code> popover.
-			Present NICs can be selected (then DHCP runs), and scanned WiFi
-			networks can be joined, asking for the WPA2 passphrase first when
-			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
-			the Date &amp; Time editor (<code>bin/settime</code>) on a click.
+			USB mark for RNDIS tethering, or a red X when no link is up.
+			The whole right status area — temperature, date/time, network
+			and AC/battery items plus the gaps between them — is one button:
+			it opens the anchored <code>bin/netmenu</code> control panel (a
+			second click closes it).
+			It opens collapsed: the battery/clock summary and Quick settings
+			pills are visible, while the network, power-mode and date/time
+			settings stay hidden until their pill is clicked.  Present NICs
+			can then be selected (DHCP runs), and scanned WiFi networks can be
+			joined, asking for the WPA2 passphrase first when the AP requires
+			one.
 		</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 WM anchors it flush under the top bar at the right screen
+			edge, 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.
+			any status target toggles it. The panel itself is drawn with the
+			ngui components: a battery/AC and clock summary, a brightness
+			slider when the panel PWM is present, and Quick settings tiles for
+			Network, the CPU power mode (<code>SYS_CPUFREQ</code>) and Date
+			&amp; Time.  Clicking a tile expands that section in place — the
+			network devices/Wi-Fi/connection lists, the three power modes, or
+			an inline date/time editor with Set, Now and Sync NTP (no separate
+			window).  <code>SYS_WIN_RESIZE_SELF</code> grows or shrinks the
+			popover to the section, clamped to <code>SYS_SCREEN_INFO</code>'s
+			framebuffer; the section scrolls when it is taller than the screen.
 		</p>
 		<p>
 			The WM is the ring-3 process loaded from
@@ -251,14 +263,20 @@
 			region. Present copies that region from the back buffer into the
 			composited front canvas with interrupts off, so a half-drawn frame
 			can never reach the screen. Frames carry monotonic sequence
-			counters, so the WM cannot lose one.
+			counters, so the WM cannot lose one. <code>content_gen</code> comes
+			from a global counter and is unique per window creation, so a new
+			window that reuses a just-closed slot forces the WM to remap its
+			front canvas instead of reusing a stale mapping.
 		</p>
 		<p>
 			<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>
+			<code>SYS_WIN_RESIZE_SELF</code> (115) resizes the caller's canvas
+			and <code>SYS_SCREEN_INFO</code> (116) reports the framebuffer
+			size, so a popover can collapse or grow.  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
@@ -322,12 +340,12 @@
 			clipped RGB565 primitives, buttons, menu items, text fields, nine
 			procedural icons, a theme palette, layout cut helpers and scrolling
 			panes. It is linked into <code>files</code>, <code>mines</code>,
-			<code>solitaire</code>, <code>chat</code> and the real
-			<code>gallery.elf</code>.
+			<code>solitaire</code>, <code>chat</code>, the control panel and
+			the real <code>gallery.elf</code>.
 		</p>
 		<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>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>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; <code>ngui_tile()</code> is a rounded quick-settings tile and <code>ngui_slider()</code> a draggable horizontal slider. 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>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>
@@ -383,7 +401,7 @@
 			</div>
 			<div class="card">
 				<h3>clock / colors / settime</h3>
-				<p>Small canvas demos: an analog clock, a colour test window, and the Date &amp; Time editor. Clicking the top-bar date/time opens <code>settime</code>, which reads and writes the CMOS RTC and can fetch UTC from an SNTP server.</p>
+				<p>Small canvas demos: an analog clock, a colour test window, and the standalone Date &amp; Time editor (<code>settime</code>). The control panel's Date &amp; Time tile reveals its own inline editor, which reads and writes the CMOS RTC and can fetch UTC from an SNTP server.</p>
 			</div>
 			<div class="card">
 				<h3>browser</h3>
@@ -432,7 +450,7 @@
 		<ul>
 			<li><strong>Registers.</strong> <code>BLC_PWM_CTL2</code> at GPU BAR0 + <code>0x1E1250</code> (pipe A; pipe B is <code>+0x100</code>): bit 31 enables, bit 28 is polarity. <code>BLC_PWM_CTL</code> at <code>0x1E1254</code>: period in bits 31:16, duty in bits 15:0. The Cherryview PWM clock is 19.2 MHz with a fixed /16 increment, so 200 Hz is a period of 6000.</li>
 			<li><strong>Probe.</strong> <span class="file">backlight.c</span> matches Intel <code>8086:22b0</code>/<code>22b1</code>, maps the graphics MMIO BAR, reads both pipes, follows the one the firmware enabled and falls back to controller 0. It logs the chosen pipe, period, duty and raw registers to COM1.</li>
-			<li><strong>Use.</strong> The <code>backlight</code> command prints the percentage and PWM state; <code>backlight up|down</code> steps by 10%, <code>backlight 0-100</code> sets a level (clamped to 5..100), and <code>backlight probe</code> dumps both pipes' registers. F6/F7 (the ChromeOS EC action-row brightness keys) and the standard <code>E0 14</code>/<code>E0 15</code> brightness scancodes adjust it; the keys are consumed in <span class="file">io.c</span> and never reach a window.</li>
+			<li><strong>Use.</strong> The <code>backlight</code> command prints the percentage and PWM state; <code>backlight up|down</code> steps by 10%, <code>backlight 0-100</code> sets a level (clamped to 5..100), and <code>backlight probe</code> dumps both pipes' registers. <code>SYS_BACKLIGHT</code> gives ring 3 the same get/set/step, which drives the control panel's brightness slider. F6/F7 (the ChromeOS EC action-row brightness keys) and the standard <code>E0 14</code>/<code>E0 15</code> brightness scancodes adjust it; the keys are consumed in <span class="file">io.c</span> and never reach a window.</li>
 			<li><strong>Overlay.</strong> <code>SYS_WM_POLL</code> also reports the backlight percentage and a change counter. After each change the ring-3 WM (<span class="file">ucmd_wm.c</span>) draws a centered <em>Brightness</em> bubble with a sun icon, the percentage and a level bar, keeps it up for 3 s, and composits it above the windows on every pass while it is visible.</li>
 			<li><strong>Limits.</strong> Only the Cherryview/Braswell native PWM (<code>8086:22b0</code>/<code>22b1</code>) is driven. The level is not persisted; a cold boot returns to the firmware's duty.</li>
 		</ul>
@@ -447,7 +465,7 @@
 			<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>ucmd_wm.c</code>, <code>uwm_lib.c</code> — ring-3 WM</li>
-			<li><code>ucmd_netmenu.c</code> — top-bar network popover (NIC selection, DHCP, WiFi scan/passphrase)</li>
+			<li><code>ucmd_netmenu.c</code> — top-bar control panel (network/WiFi, brightness, power mode, Date &amp; Time)</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>sys_wm.c</code>, <code>sys_wm.h</code> — WM/window ABI</li>

+ 1 - 1
docs/index.html

@@ -217,7 +217,7 @@
 			</a>
 			<a class="card" href="network.html">
 				<h3>Networking</h3>
-				<p>NIC registry, ARP/ICMP/UDP, DHCP, DNS, NTP, TCP client and listener, TLS 1.3, USB tethering, WiFi, the top-bar network menu, netconsole and netkexec.</p>
+				<p>NIC registry, ARP/ICMP/UDP, DHCP, DNS, NTP, TCP client and listener, TLS 1.3, USB tethering, WiFi, the top-bar control panel, netconsole and netkexec.</p>
 				<span class="card-tag">network.html</span>
 			</a>
 			<a class="card" href="drivers.html#wifi">

Разлика између датотеке није приказан због своје велике величине
+ 13 - 7
docs/network.html


Разлика између датотеке није приказан због своје велике величине
+ 4 - 2
docs/userland.html


+ 98 - 6
js_browser.c

@@ -72,6 +72,12 @@ static int node_delete(js_State *state, void *p, const char *name);
 static void push_element_url(js_State *state, unsigned int node,
 			     const char *name);
 static void rellist_supports(js_State *state);
+static void push_query_array(js_State *state, unsigned int root,
+			     const char *selector);
+static void node_push_text(js_State *state, unsigned int node);
+static void url_resolve(const char *base, const char *rel,
+			char *out, unsigned int cap);
+static int hash_pending;
 
 /* One wrapper per DOM node: the same element must have the same object
  * identity on every access, or library caches (jQuery expando data, Sizzle)
@@ -571,7 +577,8 @@ static int dispatch_object(js_State *state, unsigned int target,
 	}
 	if (target != JS_TARGET_WINDOW)
 		path[np++] = JS_TARGET_DOCUMENT;
-	if (np < (int)(sizeof(path) / sizeof(path[0])))
+	if (target != JS_TARGET_WINDOW &&
+	    np < (int)(sizeof(path) / sizeof(path[0])))
 		path[np++] = JS_TARGET_WINDOW;
 
 	/* Capture from the outermost ancestor down to the parent. */
@@ -1926,6 +1933,22 @@ static int node_has(js_State *state, void *p, const char *name)
 	}
 	if (!strcmp(name, "href")) { push_attr(state, node, "href", 0); return 1; }
 	if (!strcmp(name, "src")) { push_attr(state, node, "src", 0); return 1; }
+	if (n->type == BR_NODE_ELEM && n->tag == BR_TAG_SELECT) {
+		if (!strcmp(name, "options")) {
+			push_query_array(state, node, "option");
+			return 1;
+		}
+		if (!strcmp(name, "multiple")) {
+			js_pushboolean(state, node_attr(node, "multiple") != 0);
+			return 1;
+		}
+	}
+	/* An <option> without a value attribute has its text as value. */
+	if (n->type == BR_NODE_ELEM && n->tag == BR_TAG_OPTION &&
+	    !strcmp(name, "value") && !node_attr(node, "value")) {
+		node_push_text(state, node);
+		return 1;
+	}
 	if (!strcmp(name, "value")) {
 		char buf[128];
 
@@ -2369,22 +2392,78 @@ static void location_get(js_State *state)
 	js_pushstring(state, current_url ? current_url : "");
 }
 
-static void location_set(js_State *state)
+/* Length of a URL without its #fragment. */
+static unsigned int url_doc_len(const char *u)
+{
+	unsigned int n = 0;
+
+	while (u[n] && u[n] != '#')
+		n++;
+	return n;
+}
+
+/* Navigate, or, when only the #fragment changes, stay on the page: the
+ * host updates the URL (location.href follows it) and a hashchange event is
+ * queued.  Hash-routed apps (the Cloudron dashboard) navigate this way; a
+ * reload would restart the whole app. */
+static void location_go(const char *url)
 {
-	const char *url = js_tostring(state, 1);
+	char abs[1024];
+	unsigned int n;
 
+	if (!current_url || !url) {
+		if (host.navigate && url)
+			host.navigate(url);
+		return;
+	}
+	url_resolve(current_url, url, abs, sizeof(abs));
+	n = url_doc_len(abs);
+	if (host.set_hash && abs[n] == '#' && n == url_doc_len(current_url) &&
+	    !strncmp(abs, current_url, n)) {
+		if (strcmp(abs, current_url) && host.set_hash(abs) == 0)
+			hash_pending = 1;
+		return;
+	}
 	if (host.navigate)
 		host.navigate(url);
 }
 
+static void location_set(js_State *state)
+{
+	location_go(js_tostring(state, 1));
+}
+
 /* assign()/replace(): navigate (the history entry is not replaced yet). */
 static void location_assign(js_State *state)
 {
-	if (host.navigate)
-		host.navigate(js_tostring(state, 1));
+	location_go(js_tostring(state, 1));
 	js_pushundefined(state);
 }
 
+static void location_hash_get(js_State *state)
+{
+	const char *h = current_url ? strchr(current_url, '#') : 0;
+
+	js_pushstring(state, h && h[1] ? h : "");
+}
+
+static void location_hash_set(js_State *state)
+{
+	const char *v = js_tostring(state, 1);
+	char url[1024];
+	unsigned int n;
+
+	if (!current_url)
+		return;
+	n = url_doc_len(current_url);
+	if (n + 2 >= sizeof(url))
+		return;
+	memcpy(url, current_url, n);
+	url[n] = '#';
+	snprintf(url + n + 1, sizeof(url) - n - 1, "%s", v[0] == '#' ? v + 1 : v);
+	location_go(url);
+}
+
 static void location_reload(js_State *state)
 {
 	if (host.navigate && current_url)
@@ -2493,10 +2572,12 @@ static void push_location(js_State *state)
 		       p.path ? (int)p.path_len : 0);
 	js_setproperty(state, -2, "pathname");
 	LOC_FIELD(search);
-	LOC_FIELD(hash);
 	LOC_FIELD(origin);
 #undef LOC_FIELD
 
+	js_newcfunction(state, location_hash_get, "get hash", 0);
+	js_newcfunction(state, location_hash_set, "set hash", 1);
+	js_defaccessor(state, -3, "hash", 0);
 	js_newcfunction(state, location_reload, "reload", 0);
 	js_setproperty(state, -2, "reload");
 	js_newcfunction(state, location_assign, "assign", 1);
@@ -3196,6 +3277,11 @@ static void report_top(js_State *state)
 	js_pop(state, 1);
 }
 
+void js_browser_hashchange(void)
+{
+	hash_pending = 1;
+}
+
 void js_browser_tick(void)
 {
 	unsigned int now;
@@ -3203,6 +3289,12 @@ void js_browser_tick(void)
 
 	if (!J)
 		return;
+	if (hash_pending) {
+		hash_pending = 0;
+		js_browser_event(JS_TARGET_WINDOW, "hashchange", 0, 0);
+		if (!J)
+			return;
+	}
 	now = u_ticks_ms();
 	for (i = 0; i < JS_TIMERS; i++) {
 		if (!timers[i].used ||

+ 7 - 0
js_browser.h

@@ -53,6 +53,9 @@ struct js_browser_host {
 	 * With `set` the text is stored (returns 0); otherwise it is read into
 	 * out (returns its length, or -1). */
 	int (*storage)(int kind, const char *set, char *out, int cap);
+	/* Same-document #fragment change: update the page URL in place
+	 * (history, address bar) without loading; 0 on success. */
+	int (*set_hash)(const char *url);
 	const char *page_url;   /* location.href for every script on the page */
 	unsigned int width;     /* viewport size for window.inner* */
 	unsigned int height;
@@ -69,6 +72,10 @@ int js_browser_run(const char *source, const char *url);
  * host.load_script. */
 int js_browser_run_module(const char *source, const char *url);
 
+/* Queue a hashchange event on window (the host changed the fragment, e.g.
+ * a click on <a href="#/apps">); it fires from the next tick. */
+void js_browser_hashchange(void);
+
 /* Run due setTimeout/setInterval callbacks; call once per UI loop. */
 void js_browser_tick(void);
 

+ 40 - 8
net.c

@@ -670,10 +670,33 @@ void net_decode_frame(const unsigned char *f, unsigned int len)
 
 /* ---- reply generation ---- */
 
-int net_build_reply(const unsigned char *frame, unsigned int len,
-		    unsigned char *out, unsigned int maxout)
+/* Source address for a reply received on `nd`: the configured IP, or the
+ * driver's link-local default when the peer targets that.  The ASIX
+ * management link keeps 192.168.50.2 while the active e1000e may hold a
+ * DHCP address on another subnet. */
+static int reply_src_ip(const struct netdev *nd, const unsigned char *dst,
+			unsigned char src[4])
 {
-	unsigned char mac[6];
+	unsigned int i;
+
+	if (ip_eq(dst, my_ip)) {
+		for (i = 0; i < 4; i++)
+			src[i] = my_ip[i];
+		return 1;
+	}
+	if (nd && nd->default_ip && ip_eq(dst, nd->default_ip)) {
+		for (i = 0; i < 4; i++)
+			src[i] = nd->default_ip[i];
+		return 1;
+	}
+	return 0;
+}
+
+int net_build_reply_dev(const struct netdev *nd,
+			const unsigned char *frame, unsigned int len,
+			unsigned char *out, unsigned int maxout)
+{
+	unsigned char mac[6], src_ip[4];
 	unsigned short et;
 	unsigned int i;
 
@@ -681,7 +704,10 @@ int net_build_reply(const unsigned char *frame, unsigned int len,
 		return 0;
 	et = ((unsigned short)frame[12] << 8) | frame[13];
 
-	netdev_get_mac(mac);
+	if (nd && nd->get_mac)
+		nd->get_mac(mac);
+	else
+		netdev_get_mac(mac);
 
 	/* ARP request for our IP -> ARP reply. */	if (et == ET_ARP && len >= 14 + 28) {
 		const unsigned char *a = frame + 14;
@@ -695,7 +721,7 @@ int net_build_reply(const unsigned char *frame, unsigned int len,
 			return 0;
 		if (a[4] != 6 || a[5] != 4)
 			return 0;
-		if (!ip_eq(a + 24, my_ip))                       /* target != us */
+		if (!reply_src_ip(nd, a + 24, src_ip))           /* target != us */
 			return 0;
 
 		for (i = 0; i < 6; i++)
@@ -713,7 +739,7 @@ int net_build_reply(const unsigned char *frame, unsigned int len,
 			for (i = 0; i < 6; i++)
 				r[8 + i] = mac[i];        /* sha */
 			for (i = 0; i < 4; i++)
-				r[14 + i] = my_ip[i];     /* spa */
+				r[14 + i] = src_ip[i];    /* spa */
 			for (i = 0; i < 6; i++)
 				r[18 + i] = a[8 + i];     /* tha = requester MAC */
 			for (i = 0; i < 4; i++)
@@ -737,7 +763,7 @@ int net_build_reply(const unsigned char *frame, unsigned int len,
 			return 0;
 		if (ip[9] != IPPROTO_ICMP)
 			return 0;
-		if (!ip_eq(ip + 16, my_ip))
+		if (!reply_src_ip(nd, ip + 16, src_ip))
 			return 0;
 
 		ip_len = ((unsigned short)ip[2] << 8) | ip[3];
@@ -773,7 +799,7 @@ int net_build_reply(const unsigned char *frame, unsigned int len,
 		rip[9] = IPPROTO_ICMP;
 		rip[10] = 0; rip[11] = 0;             /* checksum (computed below) */
 		for (i = 0; i < 4; i++)
-			rip[12 + i] = my_ip[i];         /* src = us */
+			rip[12 + i] = src_ip[i];        /* src = us */
 		for (i = 0; i < 4; i++)
 			rip[16 + i] = ip[12 + i];       /* dst = requester */
 
@@ -801,3 +827,9 @@ int net_build_reply(const unsigned char *frame, unsigned int len,
 
 	return 0;
 }
+
+int net_build_reply(const unsigned char *frame, unsigned int len,
+		    unsigned char *out, unsigned int maxout)
+{
+	return net_build_reply_dev(netdev_active(), frame, len, out, maxout);
+}

+ 7 - 1
net.h

@@ -107,8 +107,14 @@ int net_udp_parse_any(const unsigned char *frame, unsigned int len,
 void net_decode_frame(const unsigned char *frame, unsigned int len);
 
 /* Build a reply to an ARP request or ICMP echo request addressed to us.
-   Returns reply length (> 0) or 0 if the frame needs no reply. */
+   Returns reply length (> 0) or 0 if the frame needs no reply.  The _dev
+   variant uses the given NIC's MAC and accepts its link-local default
+   address (a reply received on the management link must not carry the active
+   NIC's address); net_build_reply() uses the active NIC. */
 int net_build_reply(const unsigned char *frame, unsigned int len,
 		    unsigned char *out, unsigned int maxout);
+int net_build_reply_dev(const struct netdev *nd,
+			const unsigned char *frame, unsigned int len,
+			unsigned char *out, unsigned int maxout);
 
 #endif

+ 57 - 28
netkexec.c

@@ -23,7 +23,10 @@
  * program_netkexec_main() then runs stop-and-wait: every datagram is acked
  * with the next expected offset, so a lost or duplicated datagram costs one
  * retransmit.  Datagrams addressed to the broadcast IP are accepted too, so
- * the host can push without knowing whether the board is up yet.
+ * the host can push without knowing whether the board is up yet.  While the
+ * receive owns the NIC it keeps answering ARP/ICMP, otherwise the host's
+ * neighbour entry expires in the middle of a long upload and the host drops
+ * every datagram while sendto() still succeeds.
  */
 
 #include "install.h"
@@ -163,11 +166,15 @@ static int netkexec_poll_nd(const struct netdev *nd, int capture)
 		 * ICMP echo requests for our IP (so the board can be pinged,
 		 * and a host can resolve its MAC, without running a
 		 * command).  Until an address is configured there is nothing
-		 * to answer for. */
-		if (net_is_configured()) {
-			int rlen = net_build_reply(rxbuf, (unsigned int)len,
-						   replybuf,
-						   sizeof(replybuf));
+		 * to answer for.  Use the receiving NIC's MAC: this also
+		 * runs for the active NIC when the management link is a
+		 * different device.  A driver's link-local default address
+		 * (ASIX) is answerable even when the active NIC has none. */
+		if (net_is_configured() || nd->default_ip) {
+			int rlen = net_build_reply_dev(nd, rxbuf,
+						       (unsigned int)len,
+						       replybuf,
+						       sizeof(replybuf));
 			if (rlen > 0)
 				nd->tx(replybuf, (unsigned int)rlen);
 		}
@@ -268,9 +275,9 @@ int netkexec_capture_frame(const unsigned char *frame, unsigned int len)
 	return 1;
 }
 
-static void send_ack(unsigned int next_offset, unsigned int status)
+static void send_ack(const struct netdev *nd, unsigned int next_offset,
+		     unsigned int status)
 {
-	const struct netdev *nd = netdev_mgmt();
 	unsigned char src[4];
 
 	if (!nd)
@@ -295,24 +302,26 @@ static int netkexec_recv(unsigned int stage_base)
 		return -1;
 	kexec_total = x_size;
 	kexec_progress = 0;
-	send_ack(0, ACK_CONTINUE);          /* header ok, send from offset 0 */
+	send_ack(nd, 0, ACK_CONTINUE);      /* header ok, send from offset 0 */
 
 	while (offset < x_size) {
 		const unsigned char *payload;
-		unsigned int plen, port, doff, dlen;
+		unsigned int plen, doff, dlen;
+		unsigned char p_mac[6], p_ip[4];
+		unsigned int p_port;
 		int len, i;
 
 		/* A host that trickles one datagram at a time can keep the
-		 * per-packet deadline alive forever, holding the NIC (and the
-		 * background ARP/ICMP responder) hostage.  Cap the whole
-		 * transfer as well. */
+		 * per-packet deadline alive forever, holding the NIC (and
+		 * the auto-detect loop) hostage.  Cap the whole transfer as
+		 * well. */
 		if ((int)(get_ticks_ms() - hard_deadline) > 0)
 			return -1;
 
 		if ((int)(get_ticks_ms() - deadline) > 0) {
 			if (++retries > 10)
 				return -1;      /* host gave up */
-			send_ack(offset, ACK_CONTINUE);
+			send_ack(nd, offset, ACK_CONTINUE);
 			deadline = get_ticks_ms() + 1000;
 			continue;
 		}
@@ -325,28 +334,48 @@ static int netkexec_recv(unsigned int stage_base)
 			process_sleep_ms(1);
 			continue;
 		}
+
+		/* We own the NIC for the whole transfer, so the idle loop's
+		 * ARP/ICMP responder cannot run.  Keep answering here: a
+		 * multi-megabyte upload lasts long enough for the host's
+		 * neighbour entry to go STALE, and once its probes go
+		 * unanswered the host drops every datagram while sendto()
+		 * still returns success (the transfer would stall at a
+		 * random offset until the host gives up). */
 		if (!parse_udp(rxbuf, (unsigned int)len, &payload, &plen,
-			       peer_mac, peer_ip, &port)) {
-			process_sleep_ms(1);
-			continue;
-		}
-		if (plen < 12 || rd32(payload) != X_MAGIC_DATA) {
+			       p_mac, p_ip, &p_port) ||
+		    plen < 12 || rd32(payload) != X_MAGIC_DATA) {
+			net_arp_input(rxbuf, (unsigned int)len);
+			if (net_is_configured() || nd->default_ip) {
+				int rlen = net_build_reply_dev(nd, rxbuf,
+							       (unsigned int)len,
+							       replybuf,
+							       sizeof(replybuf));
+				if (rlen > 0)
+					nd->tx(replybuf, (unsigned int)rlen);
+			}
+			/* Yield after a frame that was not ours (ARP/ICMP or
+			 * a stray datagram), so a broadcast storm cannot keep
+			 * the BKL for the whole transfer. */
 			process_sleep_ms(1);
 			continue;
 		}
 
 		doff = rd32(payload + 4);
 		dlen = rd32(payload + 8);
-		if (dlen > NETKEXEC_DATA_MAX || plen < 12 + dlen) {
-			process_sleep_ms(1);
+		if (dlen > NETKEXEC_DATA_MAX || plen < 12 + dlen)
 			continue;
-		}
 
 		if (doff == offset) {
 			for (i = 0; i < (int)dlen; i++) {
 				stage[offset + i] = payload[12 + i];
 				sum += payload[12 + i];
 			}
+			for (i = 0; i < 6; i++)
+				peer_mac[i] = p_mac[i];
+			for (i = 0; i < 4; i++)
+				peer_ip[i] = p_ip[i];
+			peer_port = p_port;
 			offset += dlen;
 			kexec_progress = offset;
 			retries = 0;
@@ -355,14 +384,14 @@ static int netkexec_recv(unsigned int stage_base)
 				io_putchar('.');
 		}
 		if (offset < x_size)
-			send_ack(offset, ACK_CONTINUE);  /* also acks duplicates */
+			send_ack(nd, offset, ACK_CONTINUE); /* acks duplicates */
 	}
 
 	if (sum != x_csum) {
-		send_ack(offset, ACK_BADSUM);
+		send_ack(nd, offset, ACK_BADSUM);
 		return -1;
 	}
-	send_ack(x_size, ACK_DONE);
+	send_ack(nd, x_size, ACK_DONE);
 	return 0;
 }
 
@@ -454,7 +483,7 @@ void program_netkexec_main(void)
 		if (x_pack_size < ROOTFS_HDR_SIZE ||
 		    rh->pack_bytes > x_pack_size - ROOTFS_HDR_SIZE) {
 			io_putstr("netinstall: bad rootfs image\n");
-			send_ack(x_size, ACK_INSTALL_FAIL);
+			send_ack(netdev_mgmt(), x_size, ACK_INSTALL_FAIL);
 			kexec_stage_free();
 			netdev_release();
 			kexec_busy = 0;
@@ -465,13 +494,13 @@ void program_netkexec_main(void)
 				      rh, x_pack_size);
 		if (r != 0) {
 			io_putstr("netinstall: failed; disk not updated\n");
-			send_ack(x_size, ACK_INSTALL_FAIL);
+			send_ack(netdev_mgmt(), x_size, ACK_INSTALL_FAIL);
 			kexec_stage_free();
 			netdev_release();
 			kexec_busy = 0;
 			return;
 		}
-		send_ack(x_size, ACK_INSTALLED);
+		send_ack(netdev_mgmt(), x_size, ACK_INSTALLED);
 		io_putstr("netinstall: persisted to ");
 		io_putstr(x_install_target);
 		io_putstr(" -> jumping\n");

+ 41 - 1
netkexec_send.c

@@ -26,7 +26,9 @@
 #define MAGIC_INST 0x3249584Bu   /* "KXI2" (persist kernel + rootfs) */
 #define MAGIC_DATA 0x444E584Bu   /* "KXND" */
 #define MAGIC_ACK  0x414E584Bu   /* "KXNA" */
+#define ACK_CONTINUE      0
 #define ACK_DONE          1
+#define ACK_BADSUM        2
 #define ACK_INSTALLED     3
 #define ACK_INSTALL_FAIL  4
 
@@ -51,6 +53,18 @@ static int send_packet(int fd, const struct sockaddr_in *dst,
 		      sizeof(*dst)) == (ssize_t)len ? 0 : -1;
 }
 
+/* Milliseconds for the no-progress guard: a stalled transfer must time out
+ * even while the board keeps sending stale ACKs that do not advance the
+ * offset. */
+static unsigned long long now_ms(void)
+{
+	struct timeval tv;
+
+	gettimeofday(&tv, NULL);
+	return (unsigned long long)tv.tv_sec * 1000ULL +
+	       (unsigned long long)tv.tv_usec / 1000ULL;
+}
+
 /* Wait for an ACK ("KXNA" next_offset status).  Returns next_offset, or -1
  * on timeout. */
 static long wait_ack(int fd, unsigned int timeout_ms, uint32_t *status)
@@ -110,6 +124,7 @@ int main(int argc, char **argv)
 	unsigned char *kdata, *pdata = 0, *data, *pkt;
 	long ksize, psize = 0, size;
 	unsigned int offset = 0, sum = 0;
+	unsigned long long progress_ms = 0;
 	int fd, i, fails = 0;
 	int payload = 0, install = 0, installed = 0, install_failed = 0;
 	const char *install_target = 0;
@@ -252,11 +267,24 @@ int main(int argc, char **argv)
 	}
 
 	/* Stop-and-wait data transfer (kernel bytes, then rootfs bytes). */
+	progress_ms = now_ms();
 	while (offset < (unsigned int)size) {
 		unsigned int chunk = (unsigned int)size - offset;
 		uint32_t status = 0;
 		long ack;
 
+		/* An ACK that does not advance the offset (the board keeps
+		 * repeating its last offset while it receives nothing) is
+		 * not progress.  Bound the time without it so a lost ARP
+		 * entry or a dead link reports a readable error instead of
+		 * retransmitting for as long as the ACKs keep coming. */
+		if (now_ms() - progress_ms > 10000ULL) {
+			fprintf(stderr,
+				"\nnetkexec: no forward progress at offset %u/%ld (board unreachable?)\n",
+				offset, size);
+			return 1;
+		}
+
 		if (chunk > DATA_MAX)
 			chunk = DATA_MAX;
 		wr32(pkt, MAGIC_DATA);
@@ -277,6 +305,12 @@ int main(int argc, char **argv)
 			continue;                  /* retransmit */
 		}
 		fails = 0;
+		if (status == ACK_BADSUM) {
+			fprintf(stderr,
+				"\nnetkexec: board rejected the checksum at offset %u\n",
+				offset);
+			return 1;
+		}
 		if ((unsigned int)ack == (unsigned int)size &&
 		    status == ACK_INSTALLED) {
 			offset = (unsigned int)ack;
@@ -292,8 +326,14 @@ int main(int argc, char **argv)
 			offset = (unsigned int)ack;
 			break;
 		}
-		if (ack > (long)offset && (unsigned int)ack <= (unsigned int)size)
+		/* Only a CONTINUE ACK that advances the offset is progress;
+		 * a duplicate or a repeated offset means retransmit the same
+		 * datagram, not that the transfer is healthy. */
+		if (status == ACK_CONTINUE && (unsigned int)ack > offset &&
+		    (unsigned int)ack <= (unsigned int)size) {
 			offset = (unsigned int)ack;
+			progress_ms = now_ms();
+		}
 		printf("\rnetkexec: %3u%% (%u/%ld bytes)", offset * 100 / (unsigned)size,
 		       offset, size);
 		fflush(stdout);

+ 97 - 0
ngui.c

@@ -1561,6 +1561,103 @@ void ngui_signal_bars(struct ngui *ui, struct ngui_rect r, int bars,
 	}
 }
 
+int ngui_tile(struct ngui *ui, unsigned int id, struct ngui_rect r,
+	      const char *title, const char *subtitle, int on)
+{
+	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;
+	unsigned short bg, fg, sub_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 (on)
+		bg = ui->theme.selection;
+	else if (hot || ui->active == id)
+		bg = ui->theme.button_hot;
+	else
+		bg = ui->theme.panel_alt;
+	ngui_fill_round_rect(ui, r, 10, 10, 10, 10, bg);
+	fg = ui->theme.text;
+	sub_fg = on ? ui->theme.text : ui->theme.text_dim;
+
+	ngui_push_clip(ui, r);
+	ngui_text_px(ui, r.x + 14, r.y + 8, title, slen(title), fg,
+		     14, 1, 0, 0);
+	if (subtitle && subtitle[0])
+		ngui_text_utf8(ui, r.x + 14, r.y + 27, subtitle, sub_fg);
+	ngui_pop_clip(ui);
+	if (hot)
+		ui->hot = id;
+	return fired;
+}
+
+int ngui_slider(struct ngui *ui, unsigned int id, struct ngui_slider *s,
+		struct ngui_rect r, int *value, int min, int max)
+{
+	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 changed = 0;
+	int track_y = r.y + r.h / 2 - 2;
+	int knob_x, fill_w;
+
+	if (!s || !value || max <= min)
+		return 0;
+	if (*value < min)
+		*value = min;
+	if (*value > max)
+		*value = max;
+
+	if (press_hot) {
+		s->dragging = 1;
+		ui->active = id;
+	}
+	if (s->dragging && (ui->buttons & 1)) {
+		int rel = ui->mouse_x - r.x;
+		int v;
+
+		if (rel < 0)
+			rel = 0;
+		if (rel >= r.w)
+			rel = r.w - 1;
+		v = min + rel * (max - min) / (r.w > 1 ? r.w - 1 : 1);
+		if (v != *value) {
+			*value = v;
+			changed = 1;
+		}
+	}
+	if (ui->released) {
+		s->dragging = 0;
+		if (ui->active == id)
+			ui->active = 0;
+	}
+	if (hot)
+		ui->hot = id;
+
+	ngui_fill_rect(ui, rect_make(r.x, track_y, r.w, 4),
+		       ui->theme.button);
+	fill_w = (*value - min) * r.w / (max - min);
+	if (fill_w > 0)
+		ngui_fill_rect(ui, rect_make(r.x, track_y, fill_w, 4),
+			       ui->theme.accent);
+	knob_x = r.x + (*value - min) * (r.w - 1) / (max - min);
+	ngui_fill_round_rect(ui,
+		rect_make(knob_x - 7, r.y + r.h / 2 - 7, 14, 14),
+		7, 7, 7, 7, ui->theme.text);
+	return changed;
+}
+
 int ngui_icon_button(struct ngui *ui, unsigned int id, struct ngui_rect r,
 		     enum ngui_icon icon){
 	int hot = ui->inside && ngui_rect_contains(&r, ui->mouse_x, ui->mouse_y);

+ 10 - 0
ngui.h

@@ -100,6 +100,10 @@ struct ngui_scroll {
 	int drag_dy;
 };
 
+struct ngui_slider {
+	int dragging;
+};
+
 /* 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
@@ -281,6 +285,12 @@ 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);
+/* A two-line quick-settings tile (rounded, active when `on`). */
+int  ngui_tile(struct ngui *ui, unsigned int id, struct ngui_rect r,
+	       const char *title, const char *subtitle, int on);
+/* Horizontal slider; writes *value and returns 1 when it changed. */
+int  ngui_slider(struct ngui *ui, unsigned int id, struct ngui_slider *s,
+		 struct ngui_rect r, int *value, int min, int max);
 int ngui_text_input(struct ngui *ui, unsigned int id, struct ngui_rect r,
 		    struct ngui_input *in);
 void ngui_input_set(struct ngui_input *in, const char *s);

+ 18 - 0
power.c

@@ -742,6 +742,24 @@ const char *power_cpufreq_name(void)
 	}
 }
 
+int power_cpufreq_mode(void)
+{
+	if (!supported || !pstate_writes)
+		return -1;
+	return cpufreq_mode;
+}
+
+int power_cpufreq_set_mode(int mode)
+{
+	if (!supported || !pstate_writes)
+		return -1;
+	if (mode != POWER_CPUFREQ_AUTO && mode != POWER_CPUFREQ_MIN &&
+	    mode != POWER_CPUFREQ_MAX && mode != POWER_CPUFREQ_OFF)
+		return -1;
+	cpufreq_mode = mode;
+	return cpufreq_mode;
+}
+
 static void put_dec(unsigned int v)
 {
 	char buf[12];

+ 5 - 0
power.h

@@ -28,4 +28,9 @@ void power_print(void);
 int power_cpufreq_command(const char *arg);
 const char *power_cpufreq_name(void);
 
+/* Ring-3 policy control (SYS_CPUFREQ): -1 when P-state writes are
+ * unavailable, otherwise POWER_CPUFREQ_AUTO/MIN/MAX/OFF. */
+int power_cpufreq_mode(void);
+int power_cpufreq_set_mode(int mode);
+
 #endif

+ 5 - 0
sys_wm.c

@@ -280,3 +280,8 @@ int sys_win_key_wait(unsigned int timeout_ms)
 {
 	return wm_server_key_wait(timeout_ms);
 }
+
+int sys_win_resize_self(unsigned int w, unsigned int h)
+{
+	return wm_server_win_resize_self(w, h);
+}

+ 1 - 0
sys_wm.h

@@ -28,6 +28,7 @@ int sys_win_event(struct win_event *out);
 int sys_win_scroll(struct win_scroll *out);
 int sys_wm_resize(unsigned int index, const struct wm_size *in);
 int sys_win_key_wait(unsigned int timeout_ms);
+int sys_win_resize_self(unsigned int w, unsigned int h);
 
 /* Set once the first application window (the boot terminal) has presented
  * a frame; kernel_main waits for it before the USB bring-up. */

+ 31 - 0
syscall.c

@@ -1,8 +1,10 @@
 /* Syscall dispatcher: services int 0x80 requests from ring-3. */
 
 #include "syscall.h"
+#include "backlight.h"
 #include "io.h"
 #include "paging.h"
+#include "power.h"
 #include "process.h"
 #include "rtc.h"
 #include "serial.h"
@@ -15,6 +17,7 @@
 #include "timer.h"
 #include "tty.h"
 #include "vfs.h"
+#include "vga.h"
 #include "wifi.h"
 
 static int copy_user_string(char *dst, unsigned int max, const char *src)
@@ -327,8 +330,36 @@ static int syscall_dispatch_locked(int num, int a1, int a2, int a3)
 			return -1;
 		return sys_powerinfo((struct sys_powerinfo *)a1,
 				     (unsigned int)a2);
+	case SYS_BACKLIGHT:
+		if (a1 == SYS_BACKLIGHT_GET)
+			return backlight_percent();
+		if (a1 == SYS_BACKLIGHT_SET) {
+			backlight_set_percent(a2);
+			return backlight_percent();
+		}
+		if (a1 == SYS_BACKLIGHT_STEP) {
+			backlight_step(a2);
+			return backlight_percent();
+		}
+		return -1;
+	case SYS_CPUFREQ:
+		if (a1 == SYS_CPUFREQ_GET)
+			return power_cpufreq_mode();
+		return power_cpufreq_set_mode(a1);
 	case SYS_WIN_KEY_WAIT:
 		return sys_win_key_wait((unsigned int)a1);
+	case SYS_WIN_RESIZE_SELF:
+		return sys_win_resize_self((unsigned int)a1, (unsigned int)a2);
+	case SYS_SCREEN_INFO: {
+		struct sys_screen *out = (struct sys_screen *)a1;
+
+		if (!paging_user_range_ok(current_proc()->cr3, (unsigned int)a1,
+					  sizeof(*out), 1))
+			return -1;
+		out->width = vga_fb_width();
+		out->height = vga_fb_height();
+		return 0;
+	}
 	case SYS_SCHEDINFO:
 		if (!paging_user_range_ok(current_proc()->cr3, (unsigned int)a1,
 					  sizeof(struct sys_schedinfo), 1))

+ 22 - 0
syscall.h

@@ -115,6 +115,22 @@
 #define SYS_WIN_POINTER    86  /* (struct win_pointer *out) -> 0/-1 */
 #define SYS_WIN_EVENT      87  /* (struct win_event *out) -> 1 event, 0 none */
 #define SYS_WIN_SCROLL     109 /* (struct win_scroll *out) -> 1 delta, 0 none, -1 */
+#define SYS_WIN_RESIZE_SELF 115 /* (int w, int h) -> 0/-1; resize the caller's canvas */
+#define SYS_SCREEN_INFO   116 /* (struct sys_screen *out) -> 0/-1 */
+#define SYS_BACKLIGHT     113 /* (int op, int value) -> percent / -1.
+				  op 0 = get, 1 = set (5..100), 2 = step */
+#define SYS_BACKLIGHT_GET  0
+#define SYS_BACKLIGHT_SET  1
+#define SYS_BACKLIGHT_STEP 2
+#define SYS_CPUFREQ       114 /* (int mode) -> mode / -1.
+				  -1 = get; AUTO/MIN/MAX/OFF set the
+				  race-to-idle P-state governor. */
+#define SYS_CPUFREQ_GET  (-1)
+#define SYS_CPUFREQ_AUTO  0
+#define SYS_CPUFREQ_MIN   1
+#define SYS_CPUFREQ_MAX   2
+#define SYS_CPUFREQ_FIXED 3
+#define SYS_CPUFREQ_OFF   4
 
 /* Per-process anonymous heap (see sys_mem.c).  One growable arena at
  * USER_HEAP_BASE (0x60000000), at most USER_HEAP_MAX (64 MB), freed when the
@@ -245,6 +261,12 @@ struct sys_netdev {
 	unsigned int link;
 };
 
+/* Framebuffer dimensions for popover sizing (see SYS_SCREEN_INFO). */
+struct sys_screen {
+	unsigned int width;
+	unsigned int height;
+};
+
 /* Error codes returned by the file syscalls. */
 #define SYS_EIO     (-1)     /* disk I/O error */
 #define SYS_ENODEV  (-2)     /* no such device / unusable path prefix */

+ 71 - 2
ucmd_curl.c

@@ -157,10 +157,74 @@ static void jar_load(void)
 		uhttp_jar_init(&fetch_jar);
 }
 
+/* The jar as loaded before this request, and a scratch copy of the file. */
+static struct uhttp_jar jar_before, jar_file;
+
+static const struct uhttp_cookie *jar_lookup(const struct uhttp_jar *jar,
+					     const struct uhttp_cookie *c)
+{
+	int i;
+
+	for (i = 0; i < UHTTP_COOKIE_MAX; i++) {
+		const struct uhttp_cookie *o = &jar->c[i];
+
+		if (o->used && !strcmp(o->host, c->host) &&
+		    !strcmp(o->path, c->path) && !strcmp(o->name, c->name))
+			return o;
+	}
+	return 0;
+}
+
+/* Replay one cookie into jar_file as a Set-Cookie line (or delete it). */
+static void jar_replay(const struct uhttp_cookie *c, int del)
+{
+	static char line[UHTTP_COOKIE_NAME_MAX + UHTTP_COOKIE_VALUE_MAX +
+			 UHTTP_COOKIE_PATH_MAX + 32];
+	unsigned int n = 0;
+
+	app_str(line, &n, c->name, sizeof(line));
+	app_ch(line, &n, '=', sizeof(line));
+	if (!del)
+		app_str(line, &n, c->value, sizeof(line));
+	app_str(line, &n, "; Path=", sizeof(line));
+	app_str(line, &n, c->path, sizeof(line));
+	if (c->secure)
+		app_str(line, &n, "; Secure", sizeof(line));
+	if (del)
+		app_str(line, &n, "; Max-Age=0", sizeof(line));
+	(void)uhttp_jar_set(&jar_file, c->host, c->path, line);
+}
+
+/* Save this request's cookie changes.  Other helpers may have saved while
+ * the request ran, so the file is re-read and only what this request added,
+ * changed or deleted is applied on top (writing our whole copy back would
+ * drop their cookies). */
 static void jar_save(void)
 {
-	u_syscall3(SYS_WRITE_FILE, (int)FETCH_JAR_PATH, (int)&fetch_jar,
-		   (int)sizeof(fetch_jar));
+	int i, n;
+
+	n = u_syscall3(SYS_READ_FILE, (int)FETCH_JAR_PATH, (int)&jar_file,
+		       (int)sizeof(jar_file));
+	if (n != (int)sizeof(jar_file))
+		uhttp_jar_init(&jar_file);
+	for (i = 0; i < UHTTP_COOKIE_MAX; i++) {
+		const struct uhttp_cookie *c = &fetch_jar.c[i];
+		const struct uhttp_cookie *o;
+
+		if (!c->used)
+			continue;
+		o = jar_lookup(&jar_before, c);
+		if (!o || strcmp(o->value, c->value) || o->secure != c->secure)
+			jar_replay(c, 0);
+	}
+	for (i = 0; i < UHTTP_COOKIE_MAX; i++) {
+		const struct uhttp_cookie *o = &jar_before.c[i];
+
+		if (o->used && !jar_lookup(&fetch_jar, o))
+			jar_replay(o, 1);
+	}
+	u_syscall3(SYS_WRITE_FILE, (int)FETCH_JAR_PATH, (int)&jar_file,
+		   (int)sizeof(jar_file));
 }
 
 struct fetch_times {
@@ -468,7 +532,12 @@ static void fetch_serve(const char *arg)
 		}
 
 		jar_load();
+		memcpy(&jar_before, &fetch_jar, sizeof(jar_before));
 		jar_changes = fetch_jar.changes;
+		/* Every request: uhttp_init() after a POST clears h.jar, and a
+		 * jar-less request after the OIDC login POST drops the
+		 * interaction cookie ("authorization request has expired"). */
+		h.jar = &fetch_jar;
 		helper_fetch(&h, url, cap, method[0] ? method : 0, ctype,
 			     post_len ? (char *)post : 0, post_len,
 			     buf, &body_len, &body_trunc, &err, &times);

+ 40 - 0
ucmd_lib.h

@@ -334,6 +334,24 @@ static inline int u_win_ack_resize(void)
 	return u_syscall0(SYS_WIN_ACK_RESIZE);
 }
 
+/* Ask the kernel to grow/shrink this canvas window (a popover expanding a
+ * section); ngui_begin() acknowledges the new canvas on the next frame. */
+static inline int u_win_resize_self(unsigned int w, unsigned int h)
+{
+	return u_syscall2(SYS_WIN_RESIZE_SELF, (int)w, (int)h);
+}
+
+static inline int u_screen_size(unsigned int *w, unsigned int *h)
+{
+	struct sys_screen s;
+
+	if (u_syscall1(SYS_SCREEN_INFO, (int)&s) != 0)
+		return -1;
+	*w = s.width;
+	*h = s.height;
+	return 0;
+}
+
 static inline int u_win_pointer(struct win_pointer *out)
 {
 	return u_syscall1(SYS_WIN_POINTER, (int)out);
@@ -446,6 +464,28 @@ static inline int u_power_info(struct sys_powerinfo *out, unsigned int flags)
 	return u_syscall2(SYS_POWER_INFO, (int)out, (int)flags);
 }
 
+/* Panel brightness in percent (-1 when the machine has no PWM backlight). */
+static inline int u_backlight_get(void)
+{
+	return u_syscall2(SYS_BACKLIGHT, SYS_BACKLIGHT_GET, 0);
+}
+
+static inline int u_backlight_set(int percent)
+{
+	return u_syscall2(SYS_BACKLIGHT, SYS_BACKLIGHT_SET, percent);
+}
+
+/* CPU power mode: -1 when the CPU has no P-state control. */
+static inline int u_cpufreq_get(void)
+{
+	return u_syscall1(SYS_CPUFREQ, SYS_CPUFREQ_GET);
+}
+
+static inline int u_cpufreq_set(int mode)
+{
+	return u_syscall1(SYS_CPUFREQ, mode);
+}
+
 /* Path metadata (size, directory flag, read-only mount). */
 static inline int u_stat(const char *path, struct sys_stat *out)
 {

Разлика између датотеке није приказан због своје велике величине
+ 844 - 60
ucmd_netmenu.c


+ 56 - 44
ucmd_wm.c

@@ -118,7 +118,7 @@ static int bar_net_hot;
 static int bar_net_kind;
 static int bar_net_bars;
 static unsigned int bar_net_color = 0xFF5050u;
-static int netmenu_pid;
+static int control_pid;
 
 static void bar_notice(const char *msg)
 {
@@ -1272,8 +1272,9 @@ static int bar_net_hit(unsigned int mx, unsigned int my)
 	       (int)mx < bar_net_x + (int)bar_net_w + 3;
 }
 
-/* The AC/battery icon has no click action, but hovering it reveals the
- * percentage tooltip below it; the tooltip area keeps the hover alive. */
+/* The AC/battery icon opens the control panel on a click; hovering it also
+ * reveals the percentage tooltip below it.  The tooltip area keeps the hover
+ * alive but is not a click target. */
 static int bar_pwr_hit(unsigned int mx, unsigned int my)
 {
 	if (my >= WM_BAR_H)
@@ -1287,6 +1288,14 @@ static int bar_pwr_hit(unsigned int mx, unsigned int my)
 	       (int)mx < bar_pwr_x + BAR_PWR_W + 3;
 }
 
+/* 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. */
+static int bar_status_hit(unsigned int mx, unsigned int my)
+{
+	return my < WM_BAR_H && (int)mx >= WM_BTN_END_X + 4;
+}
+
 static void do_update(struct wm_status *st)
 {
 	struct wm_present_info present;
@@ -1395,27 +1404,33 @@ static void do_update(struct wm_status *st)
 			wins[i].mapped = 0;
 			continue;
 		}
-		if (!wins[i].info.used ||
-		    info.content_gen != wins[i].info.content_gen)
-			full_redraw = 1;
-		wins[i].info = info;
-		if (!wins[i].mapped ||
-		    wins[i].map.generation != info.content_gen) {
-			struct wm_map_info map;
-
-			if (u_wm_map(i, &map) == 0) {
-				wins[i].map = map;
-				wins[i].mapped = 1;
-			} else {
-				wins[i].mapped = 0;
+		{
+			int pid_changed = wins[i].info.used &&
+					  info.pid != wins[i].info.pid;
+
+			if (!wins[i].info.used ||
+			    info.content_gen != wins[i].info.content_gen ||
+			    pid_changed)
+				full_redraw = 1;
+			wins[i].info = info;
+			if (!wins[i].mapped || pid_changed ||
+			    wins[i].map.generation != info.content_gen) {
+				struct wm_map_info map;
+
+				if (u_wm_map(i, &map) == 0) {
+					wins[i].map = map;
+					wins[i].mapped = 1;
+				} else {
+					wins[i].mapped = 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. */
+	/* Popovers are WM-anchored overlays, flush against the bottom of the
+	 * bar and the right screen edge.  The WM owns the geometry, so the app
+	 * does not need a placement ABI. */
 	{
-		int netmenu_found = 0;
+		int control_found = 0;
 
 		for (i = 0; i < WM_MAX_WINDOWS; i++) {
 			struct wm_window_info ni;
@@ -1423,12 +1438,11 @@ static void do_update(struct wm_status *st)
 
 			if (!wins[i].info.used || !wins[i].info.popover)
 				continue;
-			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 (control_pid > 0 &&
+			    wins[i].info.pid == (unsigned int)control_pid)
+				control_found = 1;
+			nx = (int)fbw - (int)wins[i].info.w;
+			ny = WM_BAR_H;
 			if (nx != wins[i].info.x || ny != wins[i].info.y) {
 				if (u_wm_set_geom(i, nx, ny) == 0 &&
 				    u_wm_info(i, &ni) == 1) {
@@ -1437,9 +1451,9 @@ static void do_update(struct wm_status *st)
 				}
 			}
 		}
-		if (!netmenu_found && netmenu_pid > 0 &&
-		    !u_alive((unsigned int)netmenu_pid))
-			netmenu_pid = 0;
+		if (!control_found && control_pid > 0 &&
+		    !u_alive((unsigned int)control_pid))
+			control_pid = 0;
 	}
 	/* 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. */
@@ -1635,17 +1649,17 @@ static void spawn_app_checked(const char *path)
 	}
 }
 
-/* The network icon opens one menu at a time; a second click closes it. */
-static void open_netmenu(void)
+/* Any status target opens one control panel; a second click closes it. */
+static void open_control_panel(void)
 {
 	unsigned int i;
 
-	if (netmenu_pid > 0 && u_alive((unsigned int)netmenu_pid)) {
+	if (control_pid > 0 && u_alive((unsigned int)control_pid)) {
 		for (i = 0; i < WM_MAX_WINDOWS; i++)
 			if (wins[i].info.used &&
-			    wins[i].info.pid == (unsigned int)netmenu_pid) {
+			    wins[i].info.pid == (unsigned int)control_pid) {
 				if (u_wm_close(i) == 0) {
-					netmenu_pid = 0;
+					control_pid = 0;
 					full_redraw = 1;
 				} else {
 					u_wm_focus(i);
@@ -1661,9 +1675,9 @@ static void open_netmenu(void)
 		full_redraw = 1;
 		return;
 	}
-	netmenu_pid = u_spawn("/ramfs/bin/netmenu", "", 0, "/");
-	if (netmenu_pid < 0) {
-		netmenu_pid = 0;
+	control_pid = u_spawn("/ramfs/bin/netmenu", "", 0, "/");
+	if (control_pid < 0) {
+		control_pid = 0;
 		bar_notice("spawn failed");
 		full_redraw = 1;
 	} else {
@@ -1699,8 +1713,8 @@ static void dismiss_popover_outside(unsigned int mx, unsigned int my)
 	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 (wins[i].info.pid == (unsigned int)control_pid)
+			control_pid = 0;
 		if (u_wm_close(i) == 0) {
 			wins[i].info.used = 0;
 			wins[i].mapped = 0;
@@ -1721,13 +1735,11 @@ static void handle_mouse(struct wm_status *st)
 		int prev_title_id = last_title_id;
 		unsigned int now = u_ticks_ms();
 
-		if (!bar_net_hit(mx, my))
+		if (!bar_status_hit(mx, my))
 			dismiss_popover_outside(mx, my);
 		last_title_id = -1;
-		if (bar_net_hit(mx, my)) {
-			open_netmenu();
-		} else if (bar_clock_hit(mx, my)) {
-			spawn_app_checked("/ramfs/bin/settime");
+		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()) {

+ 6 - 2
uhttp_cookie.c

@@ -177,6 +177,7 @@ static int store(struct uhttp_jar *jar, const char *host, const char *path,
 			return 0;
 		copy_n(c->value, sizeof(c->value), value, c_len(value));
 		c->secure = secure ? 1 : 0;
+		c->touch = ++jar->seq;
 		jar->changes++;
 		return 1;
 	}
@@ -184,11 +185,13 @@ static int store(struct uhttp_jar *jar, const char *host, const char *path,
 		if (!jar->c[i].used)
 			break;
 	if (i == UHTTP_COOKIE_MAX) {
-		/* Full: evict the oldest cookie. */
+		/* Full: evict the cookie set or updated longest ago, so a
+		 * session cookie the server keeps refreshing outlives a burst
+		 * of one-shot cookies. */
 		int j, old = 0;
 
 		for (j = 1; j < UHTTP_COOKIE_MAX; j++)
-			if (jar->c[j].seq < jar->c[old].seq)
+			if (jar->c[j].touch < jar->c[old].touch)
 				old = j;
 		i = old;
 	}
@@ -203,6 +206,7 @@ static int store(struct uhttp_jar *jar, const char *host, const char *path,
 	c->secure = secure ? 1 : 0;
 	c->used = 1;
 	c->seq = ++jar->seq;
+	c->touch = c->seq;
 	jar->changes++;
 	return 1;
 }

+ 4 - 1
uhttp_cookie.h

@@ -12,7 +12,9 @@
 #ifndef UHTTP_COOKIE_H
 #define UHTTP_COOKIE_H
 
-#define UHTTP_COOKIE_MAX        24
+/* Every OIDC login attempt adds four path-scoped interaction cookies that
+ * live for an hour, and the browser shares one jar across all sites. */
+#define UHTTP_COOKIE_MAX        48
 #define UHTTP_COOKIE_HOST_MAX   128
 #define UHTTP_COOKIE_PATH_MAX   160
 #define UHTTP_COOKIE_NAME_MAX   64
@@ -26,6 +28,7 @@ struct uhttp_cookie {
 	unsigned char used;
 	unsigned char secure;
 	unsigned int seq;               /* insertion order, for sending */
+	unsigned int touch;             /* last set/update, for eviction */
 };
 
 struct uhttp_jar {

+ 14 - 0
uhttp_cookie_test.c

@@ -135,6 +135,20 @@ static void test_import_and_limits(void)
 	CHECK(strstr(hdr("h", "/", 0), "n0=") == NULL);
 	CHECK(strstr(hdr("h", "/", 0), "n1=") == NULL);
 	CHECK(strstr(hdr("h", "/", 0), "n2=v2") != NULL);
+
+	/* Updating a cookie makes it recently used: it survives eviction. */
+	uhttp_jar_init(&jar);
+	CHECK(uhttp_jar_set(&jar, "h", "/", "session=a") == 1);
+	for (i = 0; i < UHTTP_COOKIE_MAX - 1; i++) {
+		char c[32];
+
+		snprintf(c, sizeof(c), "x%d=v", i);
+		CHECK(uhttp_jar_set(&jar, "h", "/", c) == 1);
+	}
+	CHECK(uhttp_jar_set(&jar, "h", "/", "session=b") == 1);
+	CHECK(uhttp_jar_set(&jar, "h", "/", "late=1") == 1);
+	CHECK(strstr(hdr("h", "/", 0), "session=b") != NULL);
+	CHECK(strstr(hdr("h", "/", 0), "x0=") == NULL);
 	uhttp_jar_clear(&jar);
 	CHECK(uhttp_jar_count(&jar, "h") == 0);
 }

+ 45 - 13
wm.c

@@ -20,6 +20,14 @@
 
 static struct window windows[MAX_WINDOWS];
 static int wm_full_redraw;
+static unsigned int wm_content_seq;
+
+static unsigned int wm_next_content_gen(void)
+{
+	if (++wm_content_seq == 0)
+		wm_content_seq++;
+	return wm_content_seq;
+}
 
 /* Content pointer routing for canvas windows.  wm_server_poll() is
  * called by the ring-3 WM every loop, so it is the cheapest place to turn the
@@ -269,8 +277,8 @@ int wm_server_win_create(const struct win_create *in, struct win_info *out)
 	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;
+		w->x = (int)vga_fb_width() - (int)w->pw;
+		w->y = WM_BAR_H;
 	} else {
 		w->x = 24 + (int)i * 32;
 		w->y = WM_BAR_H + 12 + (int)i * 28;
@@ -282,7 +290,7 @@ int wm_server_win_create(const struct win_create *in, struct win_info *out)
 	}
 	wm_clamp_window(w, w->x, w->y);
 	w->focused = 0;
-	w->content_gen = 1;
+	w->content_gen = wm_next_content_gen();
 	w->mapped_kind = WM_KIND_NONE;
 	w->mapped_gen = 0;
 	w->mapped_pages = 0;
@@ -372,16 +380,19 @@ int wm_server_win_present(const struct wm_win_present *in)
 int wm_server_win_close(void)
 {
 	int idx = wm_window_for_pid(current_proc()->pid);
+	int was_focused;
 
 	if (idx < 0 || !wm_server_can_reap())
 		return -1;
+	was_focused = windows[idx].focused;
 	wm_server_unmap_index((unsigned int)idx);
 	wm_free_canvas_window((unsigned int)idx);
 	windows[idx].used = 0;
 	windows[idx].pid = 0;
 	windows[idx].focused = 0;
 	windows[idx].content_gen++;
-	wm_focus_top();
+	if (was_focused)
+		wm_focus_top();
 	wm_request_redraw();
 	return 0;
 }
@@ -508,14 +519,14 @@ int wm_server_win_scroll(struct win_scroll *out)
 	return (out->dx || out->dy) ? 1 : 0;
 }
 
-int wm_server_resize(unsigned int index, unsigned int cw, unsigned int ch)
+static int wm_resize_window(unsigned int index, unsigned int cw, unsigned int ch)
 {
 	struct window *w;
 	struct gfx_canvas nf;
 	unsigned short *nb;
 	unsigned int i, pages, pad, top;
 
-	if (!wm_server_is_wm() || index >= MAX_WINDOWS || !windows[index].used)
+	if (index >= MAX_WINDOWS || !windows[index].used)
 		return -1;
 	w = &windows[index];
 	if (!w->canvas_window || !process_is_alive(w->pid))
@@ -555,13 +566,32 @@ int wm_server_resize(unsigned int index, unsigned int cw, unsigned int ch)
 	w->resize_pending = 1;
 	w->pw = cw + pad * 2;
 	w->ph = ch + top + pad;
-	w->content_gen++;
+	w->content_gen = wm_next_content_gen();
 	/* The owner is probably parked in SYS_WIN_KEY_WAIT; wake it so it
 	 * acknowledges the resize (and reflows its content) immediately. */
 	wait_wake_one(&w->key_wq);
 	return 0;
 }
 
+int wm_server_resize(unsigned int index, unsigned int cw, unsigned int ch)
+{
+	if (!wm_server_is_wm())
+		return -1;
+	return wm_resize_window(index, cw, ch);
+}
+
+/* A canvas app resizes its own popover when it expands or collapses a
+ * section.  Refuse while the WM owns a frame: it may still be reading the
+ * old front canvas.  The app retries on its next loop. */
+int wm_server_win_resize_self(unsigned int cw, unsigned int ch)
+{
+	int idx = wm_window_for_pid(current_proc()->pid);
+
+	if (idx < 0 || wm_frame_active)
+		return -1;
+	return wm_resize_window((unsigned int)idx, cw, ch);
+}
+
 int wm_server_key_poll(void)
 {
 	int idx = wm_window_for_pid(current_proc()->pid);
@@ -1201,6 +1231,7 @@ static void wm_focus_top(void)
 static void wm_close_window(unsigned int idx)
 {
 	struct window *w = &windows[idx];
+	int was_focused = w->focused;
 
 	if (wm_ptr_capture == (int)idx)
 		wm_ptr_capture = -1;
@@ -1222,7 +1253,8 @@ static void wm_close_window(unsigned int idx)
 	w->mapped_gen = 0;
 	w->mapped_pages = 0;
 	w->mapped_src = 0;
-	wm_focus_top();
+	if (was_focused)
+		wm_focus_top();
 	wm_request_redraw();
 }
 
@@ -1265,11 +1297,11 @@ static void wm_clamp_window(struct window *w, int nx, int ny)
 
 	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;
+		 * flush under the bar and against the right edge. */
+		minx = 0;
+		maxx = fbw - (int)w->pw;
+		miny = WM_BAR_H;
+		maxy = fbh - (int)w->ph;
 		if (minx > maxx)
 			minx = maxx = 0;
 		if (miny > maxy)

+ 1 - 0
wm.h

@@ -86,6 +86,7 @@ int  wm_server_key_wait(unsigned int timeout_ms);
 int  wm_server_win_pointer(struct win_pointer *out);
 int  wm_server_win_event(struct win_event *out);
 int  wm_server_win_scroll(struct win_scroll *out);
+int  wm_server_win_resize_self(unsigned int cw, unsigned int ch);
 void wm_server_boot_ready(void);
 struct window *wm_focused_window(void);
 int  wm_is_focused(const struct window *w);

Неке датотеке нису приказане због велике количине промена