Parcourir la source

wm: add a Tasks launcher for the process monitor

Add WM_BTN_PROCESS_* after Disks, draw the Tasks button, include it in the launcher hit test and spawn /ramfs/bin/process from the click path.

The launcher row now ends further right, so the clock falls back to "MM-DD HH:MM" when the full date/time would cross WM_BTN_END_X, and is hidden if even that does not fit.  This keeps the right status area clear on 1024-wide screens.

Verified in QEMU at 1920x1080 and 1280x1024: the Tasks button launches the process monitor, and the clock/status layout remains clean.
Johannes Zellner il y a 2 jours
Parent
commit
379fb20fd2
5 fichiers modifiés avec 50 ajouts et 24 suppressions
  1. 9 6
      AGENTS.md
  2. 1 1
      docs/graphics.html
  3. 1 1
      docs/userland.html
  4. 5 1
      include/wm_abi.h
  5. 34 15
      user/apps/wm/ucmd_wm.c

+ 9 - 6
AGENTS.md

@@ -521,10 +521,12 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   the origin directly).  An outside press dismisses the
   the origin directly).  An outside press dismisses the
   popover and then continues with the normal click handling; a second click
   popover and then continues with the normal click handling; a second click
   on a status target toggles it.
   on a status target toggles it.
-  `Chat` spawns `/ramfs/bin/chat` and the last launcher, `Disks`, spawns
-  `/ramfs/bin/disks` (the storage manager); `WM_BTN_END_X`
-  (`wm_abi.h`) is the launchers' right edge, and the bar notice and the
-  right-aligned status never draw left of it.
+  `Chat` spawns `/ramfs/bin/chat`, `Tasks` spawns `/ramfs/bin/process` (the
+  task manager) and the last launcher, `Disks`, spawns `/ramfs/bin/disks`
+  (the storage manager); `WM_BTN_END_X` (`wm_abi.h`) is the launchers' right
+  edge, and the bar notice and the right-aligned status never draw left of
+  it.  When the full date/time would cross that edge, the clock falls back to
+  `MM-DD HH:MM` and is hidden if even that does not fit.
   `terminal.c` keeps the privileged kernel command
   `terminal.c` keeps the privileged kernel command
   registry for the ring-3 terminal (`SYS_SPAWN_KCMD` / `term_kcmd_spawn`),
   registry for the ring-3 terminal (`SYS_SPAWN_KCMD` / `term_kcmd_spawn`),
   but the kernel terminal entry/shell and the cell-window ABI are gone.
   but the kernel terminal entry/shell and the cell-window ABI are gone.
@@ -1467,8 +1469,9 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `bin/gallery` launcher, which prefers `/share/GALLERY` (development upload
   `bin/gallery` launcher, which prefers `/share/GALLERY` (development upload
   via `make gallery-dev`), then the pack copy, then the `GALLERY` disk
   via `make gallery-dev`), then the pack copy, then the `GALLERY` disk
   fallback on `root.img`/FAT mounts.
   fallback on `root.img`/FAT mounts.
-- **Process monitor**: `ucmd_process.c` — the graphical task manager (`process`,
-  the ngui counterpart of `top`).  It samples once per second and keeps 60 s
+- **Process monitor**: `ucmd_process.c` — the graphical task manager (`process`
+  or the top bar's `Tasks` button), the ngui counterpart of `top`.  It
+  samples once per second and keeps 60 s
   histories of CPU busy (summed `SYS_SCHEDINFO` idle ticks over all CPUs),
   histories of CPU busy (summed `SYS_SCHEDINFO` idle ticks over all CPUs),
   physical memory in use (`SYS_MEMINFO`) and NIC throughput (the 32-bit frame
   physical memory in use (`SYS_MEMINFO`) and NIC throughput (the 32-bit frame
   byte counters in `SYS_NET_INFO`).  Three cards draw the graphs with ngui
   byte counters in `SYS_NET_INFO`).  Three cards draw the graphs with ngui

+ 1 - 1
docs/graphics.html

@@ -415,7 +415,7 @@
 			</div>
 			</div>
 			<div class="card">
 			<div class="card">
 				<h3>process</h3>
 				<h3>process</h3>
-				<p>Graphical task manager (<code>process</code>, the ngui counterpart of <code>top</code>): 60 s CPU, physical-memory and NIC-throughput graphs fed by one sample per second, and a sortable process table (PID, state, CPU%, memory, CPU time, name). A selected row shows its details and <em>End task</em> terminates it after a second confirming click; kernel threads and the monitor itself are protected. Headers sort, PgUp/PgDn and the wheel scroll, Esc closes.</p>
+				<p>Graphical task manager (the top-bar <em>Tasks</em> button or <code>process</code>, the ngui counterpart of <code>top</code>): 60 s CPU, physical-memory and NIC-throughput graphs fed by one sample per second, and a sortable process table (PID, state, CPU%, memory, CPU time, name). A selected row shows its details and <em>End task</em> terminates it after a second confirming click; kernel threads and the monitor itself are protected. Headers sort, PgUp/PgDn and the wheel scroll, Esc closes.</p>
 			</div>
 			</div>
 			<div class="card">
 			<div class="card">
 				<h3>gallery</h3>
 				<h3>gallery</h3>

+ 1 - 1
docs/userland.html

@@ -347,7 +347,7 @@
 		<h2>GUI applications</h2>
 		<h2>GUI applications</h2>
 		<ul>
 		<ul>
 			<li><strong>files</strong> — browser for the VFS; opens text in <code>edit</code>, images in <code>view</code>, HTML in <code>browser</code>. First user of ngui.</li>
 			<li><strong>files</strong> — browser for the VFS; opens text in <code>edit</code>, images in <code>view</code>, HTML in <code>browser</code>. First user of ngui.</li>
-			<li><strong>process</strong> — graphical task manager, the ngui counterpart of <code>top</code>. It samples once per second into 60 s histories of CPU busy (<code>SYS_SCHEDINFO</code> idle ticks summed over all CPUs), physical memory in use (<code>SYS_MEMINFO</code>) and NIC throughput (<code>SYS_NET_INFO.rx_bytes</code>/<code>tx_bytes</code> from the netdev frame counters), then draws the three graphs with ngui rectangles and lines. The table lists PID, state, CPU%, memory, total CPU time and name; clicking a header sorts by PID, state, CPU, memory, time or name, and PgUp/PgDn or the wheel scrolls. Selecting a row shows its details; <em>End task</em> asks for a second click and then calls <code>SYS_KILL</code>, while kernel threads (<code>kernel_thread</code> in the process snapshot) and the monitor itself are protected. Esc closes it.</li>
+			<li><strong>process</strong> — graphical task manager (top-bar <em>Tasks</em> button or <code>process</code>), the ngui counterpart of <code>top</code>. It samples once per second into 60 s histories of CPU busy (<code>SYS_SCHEDINFO</code> idle ticks summed over all CPUs), physical memory in use (<code>SYS_MEMINFO</code>) and NIC throughput (<code>SYS_NET_INFO.rx_bytes</code>/<code>tx_bytes</code> from the netdev frame counters), then draws the three graphs with ngui rectangles and lines. The table lists PID, state, CPU%, memory, total CPU time and name; clicking a header sorts by PID, state, CPU, memory, time or name, and PgUp/PgDn or the wheel scrolls. Selecting a row shows its details; <em>End task</em> asks for a second click and then calls <code>SYS_KILL</code>, while kernel threads (<code>kernel_thread</code> in the process snapshot) and the monitor itself are protected. Esc closes it.</li>
 			<li><strong>disks</strong> — storage manager (top-bar <em>Disks</em> button, or the <em>Disks</em> button in <code>files</code>): devices, MBR partitions and mounts; per-volume mount name, read-only and automount saved to <code>/data/MOUNTS.CFG</code>; Format and Install NebOS dialogs that run <code>format -y</code>/<code>install -y</code> on a private tty and show the log. See <a href="filesystems.html#disks">Filesystems → Storage manager</a>.</li>
 			<li><strong>disks</strong> — storage manager (top-bar <em>Disks</em> button, or the <em>Disks</em> button in <code>files</code>): devices, MBR partitions and mounts; per-volume mount name, read-only and automount saved to <code>/data/MOUNTS.CFG</code>; Format and Install NebOS dialogs that run <code>format -y</code>/<code>install -y</code> on a private tty and show the log. See <a href="filesystems.html#disks">Filesystems → Storage manager</a>.</li>
 			<li><strong>gallery</strong> — live widget and primitive showcase; the real app ships in the pack.</li>
 			<li><strong>gallery</strong> — live widget and primitive showcase; the real app ships in the pack.</li>
 			<li><strong>chat</strong> — native Cloudron Chat client (top-bar <em>Chat</em> button, or <code>chat [config-path]</code>): username/password/TOTP login through the Cloudron OIDC API or a pasted session cookie, channels and DMs with unread badges and presence, history with older paging, inline image attachments, link-preview cards (click one to open it in the browser) and profile-picture avatars, sending, REST polling, read markers, browse/join and new DM.  The session cookie (never the password) is saved in <code>/data/CHAT.CFG</code> when the persistent volume is mounted, or in the RAM-only <code>/share/chat.cfg</code> otherwise.  Keys: Enter sends, PgUp/PgDn scroll, Home at the top pages in older history, Ctrl+B browse, Ctrl+N new DM, Ctrl+R refresh, and with the composer unfocused (Esc) Up/Down switch conversations.  See <a href="network.html#chat">Network → Chat client</a>.</li>
 			<li><strong>chat</strong> — native Cloudron Chat client (top-bar <em>Chat</em> button, or <code>chat [config-path]</code>): username/password/TOTP login through the Cloudron OIDC API or a pasted session cookie, channels and DMs with unread badges and presence, history with older paging, inline image attachments, link-preview cards (click one to open it in the browser) and profile-picture avatars, sending, REST polling, read markers, browse/join and new DM.  The session cookie (never the password) is saved in <code>/data/CHAT.CFG</code> when the persistent volume is mounted, or in the RAM-only <code>/share/chat.cfg</code> otherwise.  Keys: Enter sends, PgUp/PgDn scroll, Home at the top pages in older history, Ctrl+B browse, Ctrl+N new DM, Ctrl+R refresh, and with the composer unfocused (Esc) Up/Down switch conversations.  See <a href="network.html#chat">Network → Chat client</a>.</li>

+ 5 - 1
include/wm_abi.h

@@ -50,9 +50,13 @@
 #define WM_BTN_DISKS_Y WM_BTN_Y
 #define WM_BTN_DISKS_Y WM_BTN_Y
 #define WM_BTN_DISKS_W 64
 #define WM_BTN_DISKS_W 64
 #define WM_BTN_DISKS_H WM_BTN_H
 #define WM_BTN_DISKS_H WM_BTN_H
+#define WM_BTN_PROCESS_X (WM_BTN_DISKS_X + WM_BTN_DISKS_W + WM_BTN_GAP)
+#define WM_BTN_PROCESS_Y WM_BTN_Y
+#define WM_BTN_PROCESS_W 56
+#define WM_BTN_PROCESS_H WM_BTN_H
 /* Right edge of the launcher buttons: the notice text and the right-aligned
 /* Right edge of the launcher buttons: the notice text and the right-aligned
  * status (clock, sensors, power) never draw left of it. */
  * status (clock, sensors, power) never draw left of it. */
-#define WM_BTN_END_X (WM_BTN_DISKS_X + WM_BTN_DISKS_W)
+#define WM_BTN_END_X (WM_BTN_PROCESS_X + WM_BTN_PROCESS_W)
 #define WM_TITLE_H 22
 #define WM_TITLE_H 22
 #define WM_CLOSE_W 16
 #define WM_CLOSE_W 16
 /* No visible frame: the title bar and content start at the window origin. */
 /* No visible frame: the title bar and content start at the window origin. */

+ 34 - 15
user/apps/wm/ucmd_wm.c

@@ -437,6 +437,8 @@ static void draw_bar(void)
 		   WM_BTN_CHAT_H, "Chat");
 		   WM_BTN_CHAT_H, "Chat");
 	bar_button(WM_BTN_DISKS_X, WM_BTN_DISKS_Y, WM_BTN_DISKS_W,
 	bar_button(WM_BTN_DISKS_X, WM_BTN_DISKS_Y, WM_BTN_DISKS_W,
 		   WM_BTN_DISKS_H, "Disks");
 		   WM_BTN_DISKS_H, "Disks");
+	bar_button(WM_BTN_PROCESS_X, WM_BTN_PROCESS_Y, WM_BTN_PROCESS_W,
+		   WM_BTN_PROCESS_H, "Tasks");
 	if (bar_msg_until &&
 	if (bar_msg_until &&
 	    (int)(u_ticks_ms() - bar_msg_until) < 0)
 	    (int)(u_ticks_ms() - bar_msg_until) < 0)
 		usurf_text(&screen, (int)(WM_BTN_END_X + 8),
 		usurf_text(&screen, (int)(WM_BTN_END_X + 8),
@@ -540,21 +542,34 @@ static void draw_bar(void)
 			}
 			}
 		}
 		}
 		if (u_rtc_datetime(dt, sizeof(dt)) == 0) {
 		if (u_rtc_datetime(dt, sizeof(dt)) == 0) {
+			char cdt[12];
+			const char *txt = dt;
 			int tw = (int)usurf_text_width(&screen, dt);
 			int tw = (int)usurf_text_width(&screen, dt);
 			int tx = right - tw;
 			int tx = right - tw;
-
-			n = 0;
-			while (dt[n] && n < sizeof(dt) - 1)
-				n++;
-			bar_clock_x = tx;
-			bar_clock_w = (unsigned int)tw;
-			if (bar_clock_hot)
-				usurf_fill(&screen, tx - 5, 2,
-					   (unsigned int)tw + 10,
-					   WM_BAR_H - 7, 0x3A3A55u);
-			usurf_text(&screen, tx, 5, dt, COL_BANNER, 0, 0,
-				   fbw, WM_BAR_H);
-			clock_chars = (unsigned int)tw;
+			unsigned int i;
+
+			if (tx < min_x) {
+				/* Compact form "MM-DD HH:MM" from
+				 * "YYYY-MM-DD HH:MM:SS" when the launcher row is
+				 * too wide for the full date. */
+				for (i = 0; i < 11 && dt[5 + i]; i++)
+					cdt[i] = dt[5 + i];
+				cdt[i] = '\0';
+				txt = cdt;
+				tw = (int)usurf_text_width(&screen, cdt);
+				tx = right - tw;
+			}
+			if (tx >= min_x) {
+				bar_clock_x = tx;
+				bar_clock_w = (unsigned int)tw;
+				if (bar_clock_hot)
+					usurf_fill(&screen, tx - 5, 2,
+						   (unsigned int)tw + 10,
+						   WM_BAR_H - 7, 0x3A3A55u);
+				usurf_text(&screen, tx, 5, txt, COL_BANNER, 0, 0,
+					   fbw, WM_BAR_H);
+				clock_chars = (unsigned int)tw;
+			}
 		}
 		}
 		if (clock_chars)
 		if (clock_chars)
 			right -= (int)clock_chars + 8;
 			right -= (int)clock_chars + 8;
@@ -1762,12 +1777,12 @@ static int bar_launcher_hit(unsigned int mx, unsigned int my)
 	static const int x0[] = {
 	static const int x0[] = {
 		WM_BTN_X, WM_BTN_CLOCK_X, WM_BTN_COLORS_X, WM_BTN_FILES_X,
 		WM_BTN_X, WM_BTN_CLOCK_X, WM_BTN_COLORS_X, WM_BTN_FILES_X,
 		WM_BTN_MINES_X, WM_BTN_WEB_X, WM_BTN_CARDS_X, WM_BTN_GALLERY_X,
 		WM_BTN_MINES_X, WM_BTN_WEB_X, WM_BTN_CARDS_X, WM_BTN_GALLERY_X,
-		WM_BTN_CHAT_X, WM_BTN_DISKS_X
+		WM_BTN_CHAT_X, WM_BTN_DISKS_X, WM_BTN_PROCESS_X
 	};
 	};
 	static const int w[] = {
 	static const int w[] = {
 		WM_BTN_W, WM_BTN_CLOCK_W, WM_BTN_COLORS_W, WM_BTN_FILES_W,
 		WM_BTN_W, WM_BTN_CLOCK_W, WM_BTN_COLORS_W, WM_BTN_FILES_W,
 		WM_BTN_MINES_W, WM_BTN_WEB_W, WM_BTN_CARDS_W, WM_BTN_GALLERY_W,
 		WM_BTN_MINES_W, WM_BTN_WEB_W, WM_BTN_CARDS_W, WM_BTN_GALLERY_W,
-		WM_BTN_CHAT_W, WM_BTN_DISKS_W
+		WM_BTN_CHAT_W, WM_BTN_DISKS_W, WM_BTN_PROCESS_W
 	};
 	};
 	unsigned int i;
 	unsigned int i;
 
 
@@ -1954,6 +1969,10 @@ static void handle_mouse(struct wm_status *st)
 			   mx < WM_BTN_DISKS_X + WM_BTN_DISKS_W &&
 			   mx < WM_BTN_DISKS_X + WM_BTN_DISKS_W &&
 			   my < WM_BTN_DISKS_Y + WM_BTN_DISKS_H) {
 			   my < WM_BTN_DISKS_Y + WM_BTN_DISKS_H) {
 			spawn_app_checked("/ramfs/bin/disks");
 			spawn_app_checked("/ramfs/bin/disks");
+		} else if (mx >= WM_BTN_PROCESS_X && my >= WM_BTN_PROCESS_Y &&
+			   mx < WM_BTN_PROCESS_X + WM_BTN_PROCESS_W &&
+			   my < WM_BTN_PROCESS_Y + WM_BTN_PROCESS_H) {
+			spawn_app_checked("/ramfs/bin/process");
 		} else {
 		} else {
 			int edges = 0;
 			int edges = 0;
 			int idx = resize_hit((int)mx, (int)my, &edges);
 			int idx = resize_hit((int)mx, (int)my, &edges);