Explorar o código

Turn the control panel into collapsible quick settings

The whole right top-bar status area is now one button.  It opens a
control popover flush under the bar and the right screen edge.  The
panel starts compact with the battery/clock summary, the brightness
slider and Quick settings pills for Network, Power mode and Date &
Time; clicking a pill expands that section in place.  The popover
resizes itself to the content (SYS_WIN_RESIZE_SELF plus SYS_SCREEN_INFO)
and scrolls when a section is taller than the screen.

- Network expands to the existing status card, device/WiFi lists and
  connection details; it is hidden by default.
- Power mode expands to Balanced/Performance/Power saver rows through
  the new SYS_CPUFREQ.
- Date & Time expands to an inline editor (date/time/NTP fields, Set,
  Now and Sync NTP) instead of spawning settime.  SYS_BACKLIGHT drives
  the brightness slider.
- ngui gains ngui_tile() and ngui_slider().
- The WM gives every window creation a globally unique content_gen, so
  a new window in a just-closed slot cannot reuse a stale front-canvas
  mapping.
- AGENTS.md and docs (graphics, network, userland, cpu, drivers) updated.

make all passes; a headless QEMU run shows the compact panel, the
Network expansion, inline Date & Time editing and the right status area
toggling the panel.
Johannes Zellner hai 1 semana
pai
achega
aca4c5c3c5
Modificáronse 20 ficheiros con 1296 adicións e 187 borrados
  1. 63 36
      AGENTS.md
  2. 1 1
      docs/cpu.html
  3. 5 4
      docs/drivers.html
  4. 38 20
      docs/graphics.html
  5. 1 1
      docs/index.html
  6. 8 5
      docs/network.html
  7. 5 3
      docs/userland.html
  8. 97 0
      ngui.c
  9. 10 0
      ngui.h
  10. 18 0
      power.c
  11. 5 0
      power.h
  12. 5 0
      sys_wm.c
  13. 1 0
      sys_wm.h
  14. 31 0
      syscall.c
  15. 22 0
      syscall.h
  16. 40 0
      ucmd_lib.h
  17. 844 60
      ucmd_netmenu.c
  18. 56 44
      ucmd_wm.c
  19. 45 13
      wm.c
  20. 1 0
      wm.h

+ 63 - 36
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
@@ -896,7 +918,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 +1029,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
@@ -2435,16 +2458,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

+ 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>

+ 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">

+ 8 - 5
docs/network.html

@@ -144,8 +144,11 @@
 			driver untouched if the probe fails.
 		</p>
 		<p>
-			The top-bar network icon opens <span class="file">ucmd_netmenu.c</span>.
-			It asks the kernel for every present driver through
+			The right top-bar status area (network, battery, clock and
+			temperature) is one button that opens
+			<span class="file">ucmd_netmenu.c</span>, the control panel.  The
+			network settings stay collapsed until its Network pill is clicked;
+			the section then asks the kernel for every present driver through
 			<code>SYS_NET_DEVLIST</code> (111), so an RNDIS phone or a USB
 			Ethernet dongle that was not the boot-time winner still appears.
 			Selecting one calls <code>SYS_NET_SELECT</code> (112) and then runs
@@ -185,7 +188,7 @@
 			Data frames are converted between Ethernet and non-QoS 802.11 +
 			LLC/SNAP; EAPOL (ethertype <code>0x888e</code>) never reaches
 			<code>net_pump()</code> and is queued for the supplicant instead.
-			The top-bar menu starts the same supplicant through
+			The top-bar control panel starts the same supplicant through
 			<code>wifi connectfile &lt;path&gt;</code>: it stages the SSID,
 			passphrase and BSSID in a small <code>/share/netmenu.wifi</code>
 			record because a <code>SYS_SPAWN</code> argument is limited to
@@ -197,7 +200,7 @@
 			the network to a most-recently-used list of up to
 			<code>WIFI_CFG_MAX</code> (16) SSID/passphrase records in
 			<code>/data/WIFI.CFG</code> on the persistent <code>NEBOSDATA</code>
-			partition. The network menu marks every scanned SSID that is in the
+			partition. The control panel marks every scanned SSID that is in the
 			list as <em>saved</em>, joins it with the stored passphrase without
 			asking again, and its <em>Saved</em> view lists the records with a
 			<em>Forget</em> button each. The <code>wifi saved</code> command
@@ -505,7 +508,7 @@
 			<li><code>e1000e.c</code>, <code>r8168.c</code>, <code>ne2000.c</code>, <code>asix.c</code>, <code>rndis.c</code></li>
 			<li><code>wifi.c</code>, <code>wifi_fw.c</code>, <code>iwl_mvm.c</code>, <code>iwl_dvm.c</code>, <code>iwl_trans.c</code>, <code>rtl8821au.c</code> — Intel 7265D/3165 and 6200/6300 WiFi, Realtek RTL8821AU USB WiFi</li>
 			<li><code>wpa.c</code>, <code>wpa_crypto.c</code>, <code>ucmd_wifi.c</code> — WPA2-PSK supplicant and the <code>wifi</code> command (<code>make test-wpa</code>)</li>
-			<li><code>ucmd_netmenu.c</code>, <code>wifi_cfg.h</code>, <code>wifi_store.c/h</code> — top-bar network popover, staged WiFi connect request and the saved-network list</li>
+			<li><code>ucmd_netmenu.c</code>, <code>wifi_cfg.h</code>, <code>wifi_store.c/h</code> — top-bar control panel, staged WiFi connect request and the saved-network list</li>
 			<li><code>net.c</code>, <code>net.h</code> — ARP cache/ICMP/UDP/IP</li>
 			<li><code>netcore.c</code>, <code>netcore.h</code> — shared receive pump and IRQ helpers</li>
 			<li><code>dhcp.c</code>, <code>dns.c</code>, <code>ntp.c</code></li>

+ 5 - 3
docs/userland.html

@@ -228,6 +228,8 @@
 					<tr><td>TCP server</td><td>93–97, 99–101</td><td>listen, accept, server recv/send/close, peer, speed, MAC set</td></tr>
 					<tr><td>WiFi</td><td>110</td><td><code>SYS_WIFI(op, a2, a3)</code>: up, status, scan/results, connect/disconnect, EAPOL RX/TX, set key, authorize, set/get PTK for the rekey helper (<span class="file">wifi.c</span>)</td></tr>
 					<tr><td>NIC menu</td><td>111–112</td><td><code>SYS_NET_DEVLIST</code> (present drivers with kind/active/link) and <code>SYS_NET_SELECT</code> (make a named netdev active)</td></tr>
+					<tr><td>Hardware settings</td><td>113–114</td><td><code>SYS_BACKLIGHT(op, value)</code> get/set/step the panel PWM, <code>SYS_CPUFREQ(mode)</code> get/set the P-state mode (control panel sliders/tiles)</td></tr>
+					<tr><td>Popover layout</td><td>115–116</td><td><code>SYS_WIN_RESIZE_SELF(w, h)</code> resizes the caller's canvas, <code>SYS_SCREEN_INFO(out)</code> returns the framebuffer dimensions (the control panel collapses/grows)</td></tr>
 				</tbody>
 			</table>
 		</div>
@@ -346,8 +348,8 @@
 			<li><strong>view</strong> — fit/1:1/zoom/pan image viewer, animated GIF playback.</li>
 			<li><strong>edit</strong> — text editor that draws its own text with the 8x16 font.</li>
 			<li><strong>clock</strong> / <strong>colors</strong> — small window canvas demos.</li>
-			<li><strong>settime</strong> — Date &amp; Time editor opened by clicking the top-bar clock. It reads and writes the CMOS RTC through <code>SYS_RTC_GET</code>/<code>SYS_RTC_SET</code>; the <em>Sync NTP</em> button asks the kernel's SNTP client (<code>SYS_NTP_SYNC</code>, 106) for UTC and writes the result to the RTC. The two-digit RTC year is expanded over 1970–2069 so dead-battery defaults such as 1980/1990 can be corrected.</li>
-			<li><strong>netmenu</strong> — the rich network popover opened by the top-bar status icon. It is a chromeless <code>WIN_F_POPOVER</code> canvas window, anchored by the WM under the icon and dismissed by a click outside or <code>Esc</code>; it has no title bar, shadow or rounded outer corners, and the panel itself is built from the ngui popover/section/list-row components. It shows a connection status card and lists the present NICs from <code>SYS_NET_DEVLIST</code> (Ethernet, USB Ethernet, RNDIS tethering), selects one with <code>SYS_NET_SELECT</code> and runs DHCP. Its WiFi section scans through <code>SYS_WIFI_SCAN</code>/<code>RESULTS</code>, asks for a WPA2 passphrase when the network is not saved and starts the <code>wifi</code> helper through a <code>/share/netmenu.wifi</code> request, because the 64-byte <code>SYS_SPAWN</code> argument cannot hold a long SSID plus passphrase. Networks in <code>/data/WIFI.CFG</code> are marked <em>saved</em> and join with the stored passphrase; a <em>Saved</em> view lists them with a <em>Forget</em> button each. A Connection section shows IP, gateway, DNS and MAC. On success the helper moves the SSID/passphrase to the front of the saved list; the next boot's <code>wifi autoconnect</code> helper joins any saved network found. Duplicate BSSIDs for one SSID are collapsed to the strongest entry (or the active one), and hidden networks are omitted.</li>
+			<li><strong>settime</strong> — the standalone Date &amp; Time editor (the control panel has an inline editor on its Date &amp; Time tile). It reads and writes the CMOS RTC through <code>SYS_RTC_GET</code>/<code>SYS_RTC_SET</code>; the <em>Sync NTP</em> button asks the kernel's SNTP client (<code>SYS_NTP_SYNC</code>, 106) for UTC and writes the result to the RTC. The two-digit RTC year is expanded over 1970–2069 so dead-battery defaults such as 1980/1990 can be corrected.</li>
+			<li><strong>netmenu</strong> — the top-bar control panel, opened by clicking anywhere in the right top-bar status area (temperature, date/time, network and AC/battery items). It is a chromeless <code>WIN_F_POPOVER</code> canvas window, anchored flush under the bar at the right screen edge, dismissed by a click outside or <code>Esc</code>, and has no title bar, shadow or rounded outer corners. It opens collapsed: the battery/AC and clock summary, a brightness slider when the panel PWM is present, and Quick settings pills for Network, the P-state power mode (<code>SYS_CPUFREQ</code>) and Date &amp; Time. Clicking a pill expands that section in place and grows the window with <code>SYS_WIN_RESIZE_SELF</code>; the network section has the connection status card and NIC/WiFi lists, the power section has the three modes, and the date section has an inline editor (Set/Now/Sync NTP) instead of opening <code>settime</code>. It lists the present NICs from <code>SYS_NET_DEVLIST</code> (Ethernet, USB Ethernet, RNDIS tethering), selects one with <code>SYS_NET_SELECT</code> and runs DHCP. Its WiFi section scans through <code>SYS_WIFI_SCAN</code>/<code>RESULTS</code>, asks for a WPA2 passphrase when the network is not saved and starts the <code>wifi</code> helper through a <code>/share/netmenu.wifi</code> request, because the 64-byte <code>SYS_SPAWN</code> argument cannot hold a long SSID plus passphrase. Networks in <code>/data/WIFI.CFG</code> are marked <em>saved</em> and join with the stored passphrase; a <em>Saved</em> view lists them with a <em>Forget</em> button each. A Connection section shows IP, gateway, DNS and MAC. On success the helper moves the SSID/passphrase to the front of the saved list; the next boot's <code>wifi autoconnect</code> helper joins any saved network found. Duplicate BSSIDs for one SSID are collapsed to the strongest entry (or the active one), and hidden networks are omitted.</li>
 			<li><strong>wm</strong> / <strong>term</strong> — the ring-3 window manager and terminal launcher used by the desktop.</li>
 		</ul>
 		<p>
@@ -431,7 +433,7 @@
 			<li><code>browser.c</code>, <code>browser_html.c</code>, <code>svg_raster.c/h</code> (+ <code>svg_test.c</code>), <code>js_browser.c/h</code>, <code>js_prelude.js</code> + <code>js_prelude.S</code>, <code>js_mu.c/h</code>, <code>third_party/quickjs/</code>, <code>gallery.c</code></li>
 			<li><code>ucmd_chat.c</code>, <code>chat_login.c</code>, <code>ujson.c</code>, <code>uhttp_cookie.c</code> — chat client</li>
 			<li><code>ucmd_wifi.c</code>, <code>wpa.c</code>, <code>wpa_crypto.c</code> — <code>wifi</code> command and the WPA2-PSK supplicant</li>
-			<li><code>ucmd_netmenu.c</code>, <code>wifi_cfg.h</code>, <code>wifi_store.c/h</code> — top-bar network popover, staged WiFi connect record and saved-network list</li>
+			<li><code>ucmd_netmenu.c</code>, <code>wifi_cfg.h</code>, <code>wifi_store.c/h</code> — top-bar control panel, staged WiFi connect record and saved-network list</li>
 		</ul>
 	</section>
 </main>

+ 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 */

+ 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)
 {

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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()) {

+ 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);

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio