Sfoglia il codice sorgente

wm: pad the title and use a hover-bright close icon

Johannes Zellner 18 ore fa
parent
commit
1e391e1572
5 ha cambiato i file con 139 aggiunte e 28 eliminazioni
  1. 8 3
      AGENTS.md
  2. 10 6
      docs/graphics.html
  3. 99 14
      user/apps/wm/ucmd_wm.c
  4. 18 5
      user/lib/uwm/uwm_lib.c
  5. 4 0
      user/lib/uwm/uwm_lib.h

+ 8 - 3
AGENTS.md

@@ -547,7 +547,12 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   newest window and keeps the keyboard focus on startup, and composites the
   newest window and keeps the keyboard focus on startup, and composites the
   canvases into the shadow.  A normal
   canvases into the shadow.  A normal
   window has no visible frame: its `WM_TITLE_H` title bar starts at the
   window has no visible frame: its `WM_TITLE_H` title bar starts at the
-  window origin and a resize band (`WM_RESIZE_IN` 1 px inside,
+  window origin, the title text is inset `WM_TITLE_PAD` (8 px) from the left
+  edge, and the close control is the Adwaita `window-close` icon in the top
+  right (3 px from the edge, no red button fill); it is dimmed while idle,
+  turns white while the pointer is over it and shows the hand cursor.  A
+  hover change repaints only the two affected button rectangles.  A resize
+  band (`WM_RESIZE_IN` 1 px inside,
   `WM_RESIZE_OUT` 4 px outside every outer edge) is the edge/corner resize
   `WM_RESIZE_OUT` 4 px outside every outer edge) is the edge/corner resize
   grab area; corner squares reach `WM_CORNER_IN` (12 px) along both edges.
   grab area; corner squares reach `WM_CORNER_IN` (12 px) along both edges.
   The focused title bar uses
   The focused title bar uses
@@ -1352,8 +1357,8 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `CURSOR_DEFAULT`; a WM restart clears the override.  The ring-3 WM
   `CURSOR_DEFAULT`; a WM restart clears the override.  The ring-3 WM
   overrides with resize arrows on the resize band and while
   overrides with resize arrows on the resize band and while
   resizing, the move cross during a title-bar drag
   resizing, the move cross during a title-bar drag
-  (once it moved), and a hand over the start button, the start menu and the
-  status cluster.  ngui
+  (once it moved), and a hand over the start button, the start menu, the
+  status cluster, the dock and a window's close icon.  ngui
   resets `ui->cursor` to the arrow for every redrawn frame (begin returned
   resets `ui->cursor` to the arrow for every redrawn frame (begin returned
   1), `ngui_text_input` asks for the I-beam (not-allowed when disabled),
   1), `ngui_text_input` asks for the I-beam (not-allowed when disabled),
   apps use `ngui_cursor_rect()`/`ngui_set_cursor()`, and `ngui_end_ex()`
   apps use `ngui_cursor_rect()`/`ngui_set_cursor()`, and `ngui_end_ex()`

+ 10 - 6
docs/graphics.html

@@ -153,12 +153,16 @@
 			<code>ac-adapter</code> symbol on AC, and the <code>battery</code>
 			<code>ac-adapter</code> symbol on AC, and the <code>battery</code>
 			outline with our own level fill inside on battery), plus
 			outline with our own level fill inside on battery), plus
 			draggable
 			draggable
-			terminal and canvas windows with a title bar and close button.
-			A normal window has no visible frame; an invisible resize band
-			(1 px inside, 4 px outside its outer edge, with 12 px corner
-			squares) is the resize grab
-			area, and the active title bar uses the toolkit's highlight
-			colour. The desktop starts as a flat colour; <code>view</code>'s
+			terminal and canvas windows with a title bar and a close
+			icon. A normal window has no visible frame; an invisible
+			resize band (1 px inside, 4 px outside its outer edge, with
+			12 px corner squares) is the resize grab area, and the active
+			title bar uses the toolkit's highlight colour. The title is
+			inset 8 px from the left; the close control is the Adwaita
+			<code>window-close</code> symbol at the right edge with no red
+			button fill, dimmed while idle and brightened on hover, and it
+			shows the hand cursor. The desktop starts as a flat colour;
+			<code>view</code>'s
 			<em>Background</em> button stores a pre-scaled RGB565 file
 			<em>Background</em> button stores a pre-scaled RGB565 file
 			(<code>/data/WALLPAPR.BIN</code> on an installed board, else
 			(<code>/data/WALLPAPR.BIN</code> on an installed board, else
 			<code>/share/wallpaper</code>) and signals the WM through
 			<code>/share/wallpaper</code>) and signals the WM through

+ 99 - 14
user/apps/wm/ucmd_wm.c

@@ -12,10 +12,19 @@
  * the inactive one stays neutral.  Windows have no visible frame. */
  * the inactive one stays neutral.  Windows have no visible frame. */
 #define COL_TITLE_ON  0x365CA6u
 #define COL_TITLE_ON  0x365CA6u
 #define COL_TITLE_OFF 0x646464u
 #define COL_TITLE_OFF 0x646464u
-#define COL_CLOSE     0xC64040u
+/* The close control is a bare window-close icon in the title bar: dimmed
+ * while idle, bright white while the pointer is over it. */
+#define COL_CLOSE_ICON 0xD3DAE6u
+#define COL_CLOSE_HOT  0xFFFFFFu
 #define COL_WHITE     0xFFFFFFu
 #define COL_WHITE     0xFFFFFFu
 #define COL_BANNER    0x55FF55u
 #define COL_BANNER    0x55FF55u
 
 
+/* Title-bar text inset from the window's left edge, and the close icon's
+ * inset from its right edge.  The Adwaita symbolic icon mask is 16x16. */
+#define WM_TITLE_PAD      8
+#define WM_CLOSE_INSET    3
+#define WM_CLOSE_ICON_PX  16
+
 struct uwin {
 struct uwin {
 	struct wm_window_info info;
 	struct wm_window_info info;
 	struct wm_map_info map;
 	struct wm_map_info map;
@@ -89,6 +98,11 @@ static unsigned int resize_mx, resize_my, resize_ow, resize_oh;
 static unsigned int resize_last_ms;
 static unsigned int resize_last_ms;
 static unsigned int last_title_ms;
 static unsigned int last_title_ms;
 static int last_title_id = -1, last_title_x, last_title_y;
 static int last_title_id = -1, last_title_x, last_title_y;
+/* Window whose close icon is under the pointer (-1 for none); a change
+ * repaints only that button instead of the whole desktop. */
+static int close_hot = -1;
+static int close_hot_old = -1;
+static int close_dirty;
 static unsigned int prev_buttons;
 static unsigned int prev_buttons;
 static int full_redraw = 1;
 static int full_redraw = 1;
 static int boot_term_spawned;
 static int boot_term_spawned;
@@ -816,7 +830,7 @@ static void draw_window_clip(unsigned int idx, int cx, int cy,
 	struct wm_window_info *w = &u->info;
 	struct wm_window_info *w = &u->info;
 	int x = w->x, y = w->y;
 	int x = w->x, y = w->y;
 	unsigned int pw = w->w;
 	unsigned int pw = w->w;
-	int bx = x + (int)pw - WM_BORDER_W - WM_CLOSE_W;
+	int bx = x + (int)pw - WM_BORDER_W - WM_CLOSE_W - WM_CLOSE_INSET;
 	int cony = y + WM_BORDER_W + WM_TITLE_H;
 	int cony = y + WM_BORDER_W + WM_TITLE_H;
 	int content_x = x + WM_BORDER_W;
 	int content_x = x + WM_BORDER_W;
 	unsigned int content_w = w->content_w;
 	unsigned int content_w = w->content_w;
@@ -827,14 +841,31 @@ static void draw_window_clip(unsigned int idx, int cx, int cy,
 		return;
 		return;
 	}
 	}
 
 
-	/* Title bar and close button; windows have no visible frame. */
+	/* Title bar and close icon; windows have no visible frame.  The title
+	 * text is clipped where the icon starts, so a long title never runs
+	 * under the button. */
 	fill_clip(x, y, pw, WM_TITLE_H,
 	fill_clip(x, y, pw, WM_TITLE_H,
 		  w->focused ? COL_TITLE_ON : COL_TITLE_OFF, cx, cy, cw, ch);
 		  w->focused ? COL_TITLE_ON : COL_TITLE_OFF, cx, cy, cw, ch);
-	usurf_text(&screen, x + 3, y + 2, w->title, COL_WHITE,
-		   cx, cy, cw, ch);
-	fill_clip(bx, y, WM_CLOSE_W, WM_TITLE_H, COL_CLOSE, cx, cy, cw, ch);
-	usurf_text(&screen, bx + 4, y + 2, "x", COL_WHITE,
-		   cx, cy, cw, ch);
+	{
+		int tx0 = x + WM_TITLE_PAD, ty0 = y;
+		int tx1 = bx - 4, ty1 = y + WM_TITLE_H;
+
+		if (tx0 < cx) tx0 = cx;
+		if (ty0 < cy) ty0 = cy;
+		if (tx1 > cx + (int)cw) tx1 = cx + (int)cw;
+		if (ty1 > cy + (int)ch) ty1 = cy + (int)ch;
+		if (tx1 > tx0 && ty1 > ty0)
+			usurf_text(&screen, x + WM_TITLE_PAD, y + 2,
+				   w->title, COL_WHITE, tx0, ty0,
+				   (unsigned int)(tx1 - tx0),
+				   (unsigned int)(ty1 - ty0));
+	}
+	(void)usurf_icon_clip(&screen, bx,
+			      y + (WM_TITLE_H - WM_CLOSE_ICON_PX) / 2,
+			      UWM_ICON_CLOSE,
+			      close_hot == (int)idx ? COL_CLOSE_HOT :
+						     COL_CLOSE_ICON,
+			      cx, cy, cw, ch);
 
 
 	/* Content: every window presents an RGB565 canvas (the terminal
 	/* Content: every window presents an RGB565 canvas (the terminal
 	 * renders its cells into one; gfx commands own theirs).  A mapped
 	 * renders its cells into one; gfx commands own theirs).  A mapped
@@ -1270,13 +1301,28 @@ static int resize_cursor(int edges)
 /* Close button hit area (the top-right WM_CLOSE_W columns of the title bar). */
 /* Close button hit area (the top-right WM_CLOSE_W columns of the title bar). */
 static int close_hit(const struct wm_window_info *w, int mx, int my)
 static int close_hit(const struct wm_window_info *w, int mx, int my)
 {
 {
+	int bx;
+
 	if (w->popover)
 	if (w->popover)
 		return 0;
 		return 0;
-	return mx >= w->x + (int)w->w - WM_CLOSE_W &&
-	       mx < w->x + (int)w->w &&
+	bx = w->x + (int)w->w - WM_BORDER_W - WM_CLOSE_W - WM_CLOSE_INSET;
+	return mx >= bx && mx < bx + WM_CLOSE_W &&
 	       my >= w->y && my < w->y + WM_TITLE_H;
 	       my >= w->y && my < w->y + WM_TITLE_H;
 }
 }
 
 
+/* Window whose close icon is under the pointer, or -1.  The topmost window
+ * decides, like a press does, so an icon covered by a popover or another
+ * window does not react. */
+static int close_window_at(int mx, int my)
+{
+	int edges = 0;
+	int idx = resize_hit(mx, my, &edges);
+
+	if (idx < 0 || !close_hit(&wins[idx].info, mx, my))
+		return -1;
+	return idx;
+}
+
 static void clamp_geom(struct uwin *u, int *x, int *y)
 static void clamp_geom(struct uwin *u, int *x, int *y)
 {
 {
 	/* Match wm_clamp_window(): allow the window to hang off the left,
 	/* Match wm_clamp_window(): allow the window to hang off the left,
@@ -1330,6 +1376,20 @@ static void add_rect(struct wm_present_info *p, int x, int y,
 	}
 	}
 }
 }
 
 
+/* Damage rectangle covering one window's close button, for a hover change. */
+static void close_add_damage(struct wm_present_info *p, int idx)
+{
+	struct wm_window_info *w;
+
+	if (idx < 0 || idx >= WM_MAX_WINDOWS)
+		return;
+	w = &wins[idx].info;
+	if (!w->used || w->popover)
+		return;
+	add_rect(p, w->x + (int)w->w - WM_BORDER_W - WM_CLOSE_W -
+		 WM_CLOSE_INSET, w->y, WM_CLOSE_W, WM_TITLE_H);
+}
+
 /* Center the brightness bubble in the work area, clamped on small screens. */
 /* Center the brightness bubble in the work area, clamped on small screens. */
 static void osd_geom(void)
 static void osd_geom(void)
 {
 {
@@ -2103,6 +2163,23 @@ static void do_update(struct wm_status *st)
 			}
 			}
 		}
 		}
 	}
 	}
+	/* Close-icon hover: only the topmost window under a free pointer
+	 * reacts; an open menu, the dock and the top bar own the pointer when
+	 * they are under it.  A change repaints just the two button rects. */
+	{
+		int hot = -1;
+
+		if (resize_id < 0 && drag_id < 0 && !sm_open &&
+		    !dock_pointer_inside(st->mouse.x, st->mouse.y) &&
+		    st->mouse.y >= WM_BAR_H)
+			hot = close_window_at((int)st->mouse.x,
+					      (int)st->mouse.y);
+		if (hot != close_hot) {
+			close_hot_old = close_hot;
+			close_hot = hot;
+			close_dirty = 1;
+		}
+	}
 	/* Popovers are WM-anchored overlays, flush against the bottom of the
 	/* 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
 	 * bar and the right screen edge.  The WM owns the geometry, so the app
 	 * does not need a placement ABI. */
 	 * does not need a placement ABI. */
@@ -2232,6 +2309,13 @@ static void do_update(struct wm_status *st)
 	/* Partial cell/canvas updates and the bar clock. */
 	/* Partial cell/canvas updates and the bar clock. */
 	present.count = 0;
 	present.count = 0;
 	present.immediate = 0;
 	present.immediate = 0;
+	if (close_dirty) {
+		close_dirty = 0;
+		close_add_damage(&present, close_hot);
+		close_add_damage(&present, close_hot_old);
+		close_hot_old = -1;
+		need = 1;
+	}
 	if (osd_repaint) {
 	if (osd_repaint) {
 		add_rect(&present, osd_x, osd_y, osd_w, osd_h);
 		add_rect(&present, osd_x, osd_y, osd_w, osd_h);
 		need = 1;
 		need = 1;
@@ -2962,8 +3046,8 @@ static void begin_resize(unsigned int idx, int edges, unsigned int mx,
 /* The WM's cursor override (SYS_WM_SET_CURSOR): resize arrows on the
 /* The WM's cursor override (SYS_WM_SET_CURSOR): resize arrows on the
  * invisible resize border and while resizing, the move cross while a
  * invisible resize border and while resizing, the move cross while a
  * title-bar drag is under way, a hand over the start button, the open start
  * title-bar drag is under way, a hand over the start button, the open start
- * menu and the status area.  Everywhere else the kernel picks the window's
- * own content cursor (or the arrow). */
+ * menu, the status area, the dock or a window's close icon.  Everywhere else
+ * the kernel picks the window's own content cursor (or the arrow). */
 static void update_cursor(unsigned int mx, unsigned int my)
 static void update_cursor(unsigned int mx, unsigned int my)
 {
 {
 	static int current = CURSOR_NO_OVERRIDE;
 	static int current = CURSOR_NO_OVERRIDE;
@@ -2991,8 +3075,9 @@ static void update_cursor(unsigned int mx, unsigned int my)
 		int edges = 0;
 		int edges = 0;
 		int idx = resize_hit((int)mx, (int)my, &edges);
 		int idx = resize_hit((int)mx, (int)my, &edges);
 
 
-		if (idx >= 0 && edges &&
-		    !close_hit(&wins[idx].info, (int)mx, (int)my))
+		if (idx >= 0 && close_hit(&wins[idx].info, (int)mx, (int)my))
+			want = CURSOR_POINTER;
+		else if (idx >= 0 && edges)
 			want = resize_cursor(edges);
 			want = resize_cursor(edges);
 	}
 	}
 	if (want != current && u_wm_set_cursor(want) == 0)
 	if (want != current && u_wm_set_cursor(want) == 0)

+ 18 - 5
user/lib/uwm/uwm_lib.c

@@ -82,14 +82,17 @@ static const unsigned char *icon_mask(unsigned int icon)
 		icon * UWM_ICON_BYTES;
 		icon * UWM_ICON_BYTES;
 }
 }
 
 
-/* Tint a coverage mask with `rgb` and blend it over the canvas. */
-int usurf_icon(struct usurf *s, int x, int y, enum uwm_icon icon,
-	       unsigned int rgb)
+/* Tint a coverage mask with `rgb` and blend it over the canvas, clipped to
+ * the rectangle (cx,cy,cw,ch). */
+int usurf_icon_clip(struct usurf *s, int x, int y, enum uwm_icon icon,
+		    unsigned int rgb, int cx, int cy,
+		    unsigned int cw, unsigned int ch)
 {
 {
 	const unsigned char *m = icon_mask((unsigned int)icon);
 	const unsigned char *m = icon_mask((unsigned int)icon);
 	unsigned int sr = (rgb >> 16) & 0xFF;
 	unsigned int sr = (rgb >> 16) & 0xFF;
 	unsigned int sg = (rgb >> 8) & 0xFF;
 	unsigned int sg = (rgb >> 8) & 0xFF;
 	unsigned int sb = rgb & 0xFF;
 	unsigned int sb = rgb & 0xFF;
+	int x1 = cx + (int)cw, y1 = cy + (int)ch;
 	int i, j;
 	int i, j;
 
 
 	if (!s || !s->px || !m)
 	if (!s || !s->px || !m)
@@ -98,14 +101,15 @@ int usurf_icon(struct usurf *s, int x, int y, enum uwm_icon icon,
 		int py = y + j;
 		int py = y + j;
 		unsigned char *row;
 		unsigned char *row;
 
 
-		if (py < 0 || py >= (int)s->h)
+		if (py < cy || py >= y1 || py < 0 || py >= (int)s->h)
 			continue;
 			continue;
 		row = s->px + (unsigned long)py * s->pitch;
 		row = s->px + (unsigned long)py * s->pitch;
 		for (i = 0; i < UWM_ICON_PX; i++) {
 		for (i = 0; i < UWM_ICON_PX; i++) {
 			int px = x + i, a = m[j * UWM_ICON_PX + i];
 			int px = x + i, a = m[j * UWM_ICON_PX + i];
 			unsigned int dr, dg, db;
 			unsigned int dr, dg, db;
 
 
-			if (!a || px < 0 || px >= (int)s->w)
+			if (!a || px < cx || px >= x1 ||
+			    px < 0 || px >= (int)s->w)
 				continue;
 				continue;
 			usurf_pixels++;
 			usurf_pixels++;
 			if (s->bpp == 16) {
 			if (s->bpp == 16) {
@@ -142,6 +146,15 @@ int usurf_icon(struct usurf *s, int x, int y, enum uwm_icon icon,
 	return 1;
 	return 1;
 }
 }
 
 
+/* The same without clipping, i.e. clipped to the whole canvas. */
+int usurf_icon(struct usurf *s, int x, int y, enum uwm_icon icon,
+	       unsigned int rgb)
+{
+	if (!s)
+		return 0;
+	return usurf_icon_clip(s, x, y, icon, rgb, 0, 0, s->w, s->h);
+}
+
 /* ---- Full-colour app icons -------------------------------------------- */
 /* ---- Full-colour app icons -------------------------------------------- */
 #define UWM_APP_BYTES (APP_ICON_PX * APP_ICON_PX * 3u)
 #define UWM_APP_BYTES (APP_ICON_PX * APP_ICON_PX * 3u)
 
 

+ 4 - 0
user/lib/uwm/uwm_lib.h

@@ -61,6 +61,10 @@ void usurf_canvas(struct usurf *s, const struct uwm_canvas *c,
  * surface.  Returns 0 when the bundle (or that id) is not available. */
  * surface.  Returns 0 when the bundle (or that id) is not available. */
 int usurf_icon(struct usurf *s, int x, int y, enum uwm_icon icon,
 int usurf_icon(struct usurf *s, int x, int y, enum uwm_icon icon,
 	       unsigned int rgb);
 	       unsigned int rgb);
+/* Icon blit clipped to (cx,cy,cw,ch), in screen coordinates. */
+int usurf_icon_clip(struct usurf *s, int x, int y, enum uwm_icon icon,
+		    unsigned int rgb, int cx, int cy,
+		    unsigned int cw, unsigned int ch);
 
 
 /* Draw one full-colour app icon from /ramfs/icons/apps96.icn, scaled to
 /* Draw one full-colour app icon from /ramfs/icons/apps96.icn, scaled to
  * size x size and centred at (x, y).  Returns 0 when the bundle (or that
  * size x size and centred at (x, y).  Returns 0 when the bundle (or that