Просмотр исходного кода

wm: enlarge the resize band and corner grab squares

The edge band now reaches 4 px outside the window (was 3), and each
corner gets a 12 px grab square inside both edges in addition to the
4 px outside.  Corners win over the thin edge bands, so a press up to
12 px down or along an edge near a corner resizes both axes; beyond
that the edge band or a title-bar drag takes over.

The kernel's band test uses four unsigned range checks and an AND/OR
reduction so it stays inlined.  The first explicit version grew the
kernel text by 432 bytes and pushed .bss across a page boundary,
breaking the 0x90000 link assertion.

Tested in QEMU with QMP input: a press 3 px outside the right edge
starts a resize and 4 px outside does not; a press 6 px in and 8 px
below the top-left corner resizes the left/top edges, while 20 px
below the top starts a title-bar drag with the size unchanged.
Johannes Zellner 15 часов назад
Родитель
Сommit
17dc2c3c81
5 измененных файлов с 45 добавлено и 10 удалено
  1. 6 4
      AGENTS.md
  2. 5 3
      docs/graphics.html
  3. 4 1
      include/wm_abi.h
  4. 15 1
      kernel/wm.c
  5. 15 1
      user/apps/wm/ucmd_wm.c

+ 6 - 4
AGENTS.md

@@ -548,8 +548,9 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   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 and a resize band (`WM_RESIZE_IN` 1 px inside,
-  `WM_RESIZE_OUT` 3 px outside every outer edge) is the edge/corner resize
-  grab area.  The focused title bar uses
+  `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.
+  The focused title bar uses
   the toolkit highlight `ngui_theme_dark.selection`.  The boot
   the toolkit highlight `ngui_theme_dark.selection`.  The boot
   console stays visible until the WM attaches (`wm_server_attach` disables
   console stays visible until the WM attaches (`wm_server_attach` disables
   it), so a missing `/ramfs/bin/wm` leaves the kernel boot log on screen and
   it), so a missing `/ramfs/bin/wm` leaves the kernel boot log on screen and
@@ -576,8 +577,9 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   dragging, screen edges and the facing edges of windows that overlap on the
   dragging, screen edges and the facing edges of windows that overlap on the
   other axis resist the window: it stays flush until the pointer overshoots
   other axis resist the window: it stays flush until the pointer overshoots
   by `WM_RESIST` (24 px) (`resist_geom()` in `ucmd_wm.c`).  A press in the
   by `WM_RESIST` (24 px) (`resist_geom()` in `ucmd_wm.c`).  A press in the
-  resize band (1 px inside, 3 px outside) along any edge or corner starts a
-  resize: the grabbed edges follow the pointer while the opposite edges stay
+  resize band (1 px inside, 4 px outside, with 12 px corner squares) along
+  any edge or corner starts a resize: the grabbed edges follow the pointer
+  while the opposite edges stay
   put, clamped to the work area.  The topmost window's band wins over a
   put, clamped to the work area.  The topmost window's band wins over a
   window behind it.  While dragged or resized the WM owns the pointer
   window behind it.  While dragged or resized the WM owns the pointer
   (`SYS_WM_MOUSE_CAPTURE`), so canvas clients see no held button and cannot
   (`SYS_WM_MOUSE_CAPTURE`), so canvas clients see no held button and cannot

+ 5 - 3
docs/graphics.html

@@ -155,7 +155,8 @@
 			draggable
 			draggable
 			terminal and canvas windows with a title bar and close button.
 			terminal and canvas windows with a title bar and close button.
 			A normal window has no visible frame; an invisible resize band
 			A normal window has no visible frame; an invisible resize band
-			(1 px inside, 3 px outside its outer edge) is the resize grab
+			(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
 			area, and the active title bar uses the toolkit's highlight
 			colour. The desktop starts as a flat colour; <code>view</code>'s
 			colour. 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
@@ -430,8 +431,9 @@
 			which makes side-by-side placement exact. Windows can be dragged past the left, right and
 			which makes side-by-side placement exact. Windows can be dragged past the left, right and
 			bottom edges; <code>WM_DRAG_VISIBLE</code> (48 px) of the title bar
 			bottom edges; <code>WM_DRAG_VISIBLE</code> (48 px) of the title bar
 			always stays on-screen for recovery, and the top bar is never
 			always stays on-screen for recovery, and the top bar is never
-			overlapped. An invisible resize band (1 px inside, 3 px outside)
-			runs along every edge and corner: the grabbed edges follow the
+			overlapped. An invisible resize band (1 px inside, 4 px outside)
+			runs along every edge, with 12 px corner squares: the grabbed
+			edges follow the
 			pointer while the opposite edges stay put, clamped to the work
 			pointer while the opposite edges stay put, clamped to the work
 			area. While a drag or resize is active the WM owns the pointer,
 			area. While a drag or resize is active the WM owns the pointer,
 			so the window content does not see the held button.
 			so the window content does not see the held button.

+ 4 - 1
include/wm_abi.h

@@ -20,7 +20,10 @@
  * outer edge and WM_RESIZE_OUT px outside it.  Presses in the inside part
  * outer edge and WM_RESIZE_OUT px outside it.  Presses in the inside part
  * are not routed to the window content; the whole band starts a resize. */
  * are not routed to the window content; the whole band starts a resize. */
 #define WM_RESIZE_IN  1
 #define WM_RESIZE_IN  1
-#define WM_RESIZE_OUT 3
+#define WM_RESIZE_OUT 4
+/* Corner grab squares reach this far inside the window along both edges, so
+ * the diagonal resize is easier to hit than the thin edge band. */
+#define WM_CORNER_IN  12
 
 
 /* Keep at least this much of the title bar on-screen when a window is dragged
 /* Keep at least this much of the title bar on-screen when a window is dragged
  * past an edge, so it can always be grabbed and brought back. */
  * past an edge, so it can always be grabbed and brought back. */

+ 15 - 1
kernel/wm.c

@@ -1420,15 +1420,29 @@ static int wm_window_at(int px, int py)
 }
 }
 
 
 /* Resize band of a normal window: WM_RESIZE_IN px inside and WM_RESIZE_OUT
 /* Resize band of a normal window: WM_RESIZE_IN px inside and WM_RESIZE_OUT
- * px outside every edge.  Mirrors the ring-3 WM's resize_edges_at(). */
+ * px outside every edge, with WM_CORNER_IN px corner squares.  Mirrors the
+ * ring-3 WM's resize_edges_at(). */
 static int wm_in_resize_band(const struct window *w, int mx, int my)
 static int wm_in_resize_band(const struct window *w, int mx, int my)
 {
 {
 	int l = w->x, t = w->y;
 	int l = w->x, t = w->y;
 	int r = l + (int)w->pw, b = t + (int)w->ph;
 	int r = l + (int)w->pw, b = t + (int)w->ph;
+	unsigned int xl, xr, yt, yb;
 	int near_x, near_y;
 	int near_x, near_y;
 
 
 	if (w->popover || my < WM_BAR_H)
 	if (w->popover || my < WM_BAR_H)
 		return 0;
 		return 0;
+	/* Corner squares as unsigned range tests: [edge-OUT, edge+CORNER_IN)
+	 * on one axis, intersected across the two axes. */
+	xl = (unsigned int)(mx - (l - WM_RESIZE_OUT)) <
+	     WM_RESIZE_OUT + WM_CORNER_IN;
+	xr = (unsigned int)(mx - (r - WM_CORNER_IN)) <
+	     WM_RESIZE_OUT + WM_CORNER_IN;
+	yt = (unsigned int)(my - (t - WM_RESIZE_OUT)) <
+	     WM_RESIZE_OUT + WM_CORNER_IN;
+	yb = (unsigned int)(my - (b - WM_CORNER_IN)) <
+	     WM_RESIZE_OUT + WM_CORNER_IN;
+	if ((xl | xr) & (yt | yb))
+		return 1;
 	near_x = mx >= l - WM_RESIZE_OUT && mx < r + WM_RESIZE_OUT;
 	near_x = mx >= l - WM_RESIZE_OUT && mx < r + WM_RESIZE_OUT;
 	near_y = my >= t - WM_RESIZE_OUT && my < b + WM_RESIZE_OUT;
 	near_y = my >= t - WM_RESIZE_OUT && my < b + WM_RESIZE_OUT;
 	return (near_y && mx >= l - WM_RESIZE_OUT && mx < l + WM_RESIZE_IN) ||
 	return (near_y && mx >= l - WM_RESIZE_OUT && mx < l + WM_RESIZE_IN) ||

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

@@ -1176,7 +1176,8 @@ static void draw_rect(int x, int y, unsigned int w, unsigned int h)
 
 
 /* Invisible resize border: edge bits for a point in the band around the
 /* Invisible resize border: edge bits for a point in the band around the
  * window's outer edge (WM_RESIZE_IN px inside and WM_RESIZE_OUT px outside).
  * window's outer edge (WM_RESIZE_IN px inside and WM_RESIZE_OUT px outside).
- * Popovers have no chrome and never resize. */
+ * The corner squares reach WM_CORNER_IN px along both edges.  Popovers have
+ * no chrome and never resize. */
 #define WM_EDGE_LEFT   1
 #define WM_EDGE_LEFT   1
 #define WM_EDGE_RIGHT  2
 #define WM_EDGE_RIGHT  2
 #define WM_EDGE_TOP    4
 #define WM_EDGE_TOP    4
@@ -1191,6 +1192,19 @@ static int resize_edges_at(const struct uwin *u, int mx, int my)
 
 
 	if (w->popover)
 	if (w->popover)
 		return 0;
 		return 0;
+	/* Corners win over the thin edge bands so the diagonal grab is easy. */
+	if (mx >= l - WM_RESIZE_OUT && mx < l + WM_CORNER_IN &&
+	    my >= t - WM_RESIZE_OUT && my < t + WM_CORNER_IN)
+		return WM_EDGE_LEFT | WM_EDGE_TOP;
+	if (mx >= r - WM_CORNER_IN && mx < r + WM_RESIZE_OUT &&
+	    my >= t - WM_RESIZE_OUT && my < t + WM_CORNER_IN)
+		return WM_EDGE_RIGHT | WM_EDGE_TOP;
+	if (mx >= l - WM_RESIZE_OUT && mx < l + WM_CORNER_IN &&
+	    my >= b - WM_CORNER_IN && my < b + WM_RESIZE_OUT)
+		return WM_EDGE_LEFT | WM_EDGE_BOTTOM;
+	if (mx >= r - WM_CORNER_IN && mx < r + WM_RESIZE_OUT &&
+	    my >= b - WM_CORNER_IN && my < b + WM_RESIZE_OUT)
+		return WM_EDGE_RIGHT | WM_EDGE_BOTTOM;
 	near_x = mx >= l - WM_RESIZE_OUT && mx < r + WM_RESIZE_OUT;
 	near_x = mx >= l - WM_RESIZE_OUT && mx < r + WM_RESIZE_OUT;
 	near_y = my >= t - WM_RESIZE_OUT && my < b + WM_RESIZE_OUT;
 	near_y = my >= t - WM_RESIZE_OUT && my < b + WM_RESIZE_OUT;
 	if (near_y && mx >= l - WM_RESIZE_OUT && mx < l + WM_RESIZE_IN)
 	if (near_y && mx >= l - WM_RESIZE_OUT && mx < l + WM_RESIZE_IN)