Quellcode durchsuchen

wm: add Win/Super app runner

Johannes Zellner vor 1 Stunde
Ursprung
Commit
b06af42d39
6 geänderte Dateien mit 692 neuen und 62 gelöschten Zeilen
  1. 14 1
      AGENTS.md
  2. 26 7
      include/wm_abi.h
  3. 13 0
      kernel/io.c
  4. 1 0
      kernel/io.h
  5. 46 14
      kernel/wm.c
  6. 592 40
      user/apps/wm/ucmd_wm.c

+ 14 - 1
AGENTS.md

@@ -610,13 +610,26 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `IO_KEY_ALT_TAB`/`IO_KEY_ALT_SHIFT_TAB` (with typematic repeat);
   `wm_pump_keyboard()` consumes the chord so the focused client never sees a
   Tab and queues `WM_CHORD_NEXT`/`WM_CHORD_PREV` in `struct wm_status`'s
-  eight-entry chord ring, because the WM itself is not a window with a key
+  16-entry input ring, because the WM itself is not a window with a key
   queue.  The WM keeps the MRU list from the `focused` flags it already
   refreshes (`sw_track_focus()`), draws a centred icon strip with the
   selected app's name while `alt_down` is set, and focuses the selection
   with `SYS_WM_FOCUS` when Alt is released (a quick tap switches without a
   visible overlay).  Popovers are filtered out of the list; Shift+Alt+Tab
   walks backwards.
+  **Win/Super** opens the app runner.  `io.c` reports only the press as
+  `IO_KEY_META` (the keyboard's typematic make codes cannot toggle it again),
+  and `wm_pump_keyboard()` toggles a kernel grab (`wm_status.runner_active`)
+  that routes every following key into the same input ring as
+  `WM_CHORD_KEY | key` instead of to the focused client.  Enter and Esc also
+  release the grab in the kernel, so a crashed or wedged WM cannot leave the
+  keyboard captured.  The WM mirrors the flag, draws a centred query field and
+  a ranked list from `sm_apps` (case-insensitive matches on label, command
+  basename and window title, with inline label completion), and launches the
+  selection through the normal `sm_launch()` path on Enter.  Up/Down/
+  PageUp/PageDown select, Tab completes the label, Left/Right/Home/End edit
+  the query, the panel is modal for the pointer, and a second Win toggles it
+  closed.  It is a WM-drawn overlay, not a window.
   The desktop background is `wm_prefs.bg_rgb` (default `#202030`), unless a
   wallpaper image is installed.  The image viewer and the Settings app's
   *Appearance* page pre-render an image to a screen-aspect RGB565

+ 26 - 7
include/wm_abi.h

@@ -98,10 +98,24 @@ struct wm_mouse_info {
 	unsigned int buttons;      /* bit0 left, bit1 right, bit2 middle */
 };
 
-/* Alt+Tab chord events queued in struct wm_status. */
-#define WM_CHORD_QUEUE 8
+/* WM input events queued in struct wm_status.  Alt+Tab/Shift+Alt+Tab are
+ * small event codes; a runner key is WM_CHORD_KEY | <key code>. */
+#define WM_CHORD_QUEUE 16
 #define WM_CHORD_NEXT 1   /* Alt+Tab: next window in MRU order */
 #define WM_CHORD_PREV 2   /* Shift+Alt+Tab: previous window */
+#define WM_CHORD_KEY  0x80000000u
+
+/* Raw key codes forwarded to the app runner.  The values match the kernel's
+ * IO_KEY_* codes (static assertions in kernel/wm.c keep them in sync). */
+#define WM_RUNNER_KEY_LEFT      0x100
+#define WM_RUNNER_KEY_RIGHT     0x101
+#define WM_RUNNER_KEY_UP        0x102
+#define WM_RUNNER_KEY_DOWN      0x103
+#define WM_RUNNER_KEY_PAGE_UP   0x104
+#define WM_RUNNER_KEY_PAGE_DOWN 0x105
+#define WM_RUNNER_KEY_HOME      0x106
+#define WM_RUNNER_KEY_END       0x107
+#define WM_RUNNER_KEY_DELETE    0x108
 
 struct wm_status {
 	struct wm_mouse_info mouse;
@@ -125,14 +139,19 @@ struct wm_status {
 	 * (SYS_WM_OPEN_SETTINGS); the sequence makes every request visible. */
 	unsigned int settings_req_seq;
 	unsigned int settings_req_section;
-	/* Alt+Tab chords for the WM.  The WM has no window key queue of its
-	 * own, so the kernel consumes the chord and publishes the events
-	 * here.  chord_head is a monotonic write counter: the event at
-	 * position n lives in chord_keys[n % WM_CHORD_QUEUE].  alt_down lets
-	 * the WM commit the selection when Alt is released. */
+	/* WM input events (Alt+Tab chords and app-runner keys).  The WM has no
+	 * window key queue of its own, so the kernel consumes them and
+	 * publishes the events here.  chord_head is a monotonic write
+	 * counter: the event at position n lives in
+	 * chord_keys[n % WM_CHORD_QUEUE].  alt_down lets the WM commit the
+	 * Alt+Tab selection when Alt is released. */
 	unsigned int alt_down;
 	unsigned int chord_head;
 	unsigned int chord_keys[WM_CHORD_QUEUE];
+	/* 1 while the kernel is grabbing keys for the WM's app runner.  The
+	 * Win/Super key toggles it; the WM mirrors this flag and draws the
+	 * centered input panel.  Enter/Esc also release the grab. */
+	unsigned int runner_active;
 };
 
 /* Wallpaper file: one header followed by tightly packed RGB565 pixels,

+ 13 - 0
kernel/io.c

@@ -52,6 +52,7 @@ static const unsigned char scancode_to_ascii[256] __attribute__((section(".rodat
 static int shift_pressed;
 static int ctrl_pressed;
 static int alt_pressed;
+static int meta_down;
 static int kbd_extended;  /* 1 after 0xE0, next byte is extended scancode */
 
 /* Software typematic repeat.  PS/2 keyboards repeat in hardware; the USB HID
@@ -306,6 +307,7 @@ void io_drain_keyboard(void)
 	kbd_head = kbd_tail = 0;
 	kbd_extended = 0;
 	alt_pressed = 0;
+	meta_down = 0;
 	repeat_active = 0;
 }
 
@@ -357,6 +359,8 @@ static int kbd_process_byte_inner(unsigned char sc)
 				ctrl_pressed = 0;
 			if (sc == 0xB8)   /* right Alt release */
 				alt_pressed = 0;
+			if (sc == 0xDB || sc == 0xDC)  /* Win/Super release */
+				meta_down = 0;
 			return 0;  /* key release */
 		}
 		if (sc == 0x1D) {         /* right Ctrl */
@@ -367,6 +371,15 @@ static int kbd_process_byte_inner(unsigned char sc)
 			alt_pressed = 1;
 			return 0;
 		}
+		if (sc == 0x5B || sc == 0x5C) {
+			/* Left/right Win/Super.  Only the press matters (it
+			 * toggles the app runner), and the keyboard's own
+			 * typematic make codes must not toggle it again. */
+			if (meta_down)
+				return 0;
+			meta_down = 1;
+			return IO_KEY_META;
+		}
 		if (sc == 0x14 || sc == 0x15) {
 			/* Standard AT brightness down/up (E0 14 / E0 15);
 			 * ChromeOS EC action-key boards send these. */

+ 1 - 0
kernel/io.h

@@ -38,6 +38,7 @@ void io_drain_keyboard(void);
 #define IO_KEY_CTRL_BACKSPACE 0x10C
 #define IO_KEY_ALT_TAB       0x10D  /* Alt+Tab (Shift+Alt+Tab is separate) */
 #define IO_KEY_ALT_SHIFT_TAB 0x10E
+#define IO_KEY_META          0x10F  /* Win/Super key press (no repeat) */
 int io_poll_key(void);
 /* 1 while either Alt key is held.  The WM uses it to end an Alt+Tab
    switcher session when Alt is released. */

+ 46 - 14
kernel/wm.c

@@ -63,11 +63,30 @@ static unsigned int wm_settings_req_seq;
 static unsigned int wm_settings_req_section;
 static unsigned int wm_last_seen;
 
-/* Alt+Tab chords are routed to the WM through struct wm_status: the WM is
- * not a window, so it has no key queue of its own.  This ring decouples the
- * 2 ms keyboard pump from the WM's 10 ms poll. */
+/* Alt+Tab chords and app-runner keys are routed to the WM through struct
+ * wm_status: the WM is not a window, so it has no key queue of its own.
+ * This ring decouples the 2 ms keyboard pump from the WM's 10 ms poll. */
 static unsigned int wm_chord_head;
 static unsigned int wm_chord_keys[WM_CHORD_QUEUE];
+/* 1 while the Win/Super runner has grabbed the keyboard.  The WM mirrors
+ * this through wm_status.runner_active. */
+static int wm_runner_active;
+
+_Static_assert(IO_KEY_LEFT == WM_RUNNER_KEY_LEFT, "runner key ABI");
+_Static_assert(IO_KEY_RIGHT == WM_RUNNER_KEY_RIGHT, "runner key ABI");
+_Static_assert(IO_KEY_UP == WM_RUNNER_KEY_UP, "runner key ABI");
+_Static_assert(IO_KEY_DOWN == WM_RUNNER_KEY_DOWN, "runner key ABI");
+_Static_assert(IO_KEY_PAGE_UP == WM_RUNNER_KEY_PAGE_UP, "runner key ABI");
+_Static_assert(IO_KEY_PAGE_DOWN == WM_RUNNER_KEY_PAGE_DOWN, "runner key ABI");
+_Static_assert(IO_KEY_HOME == WM_RUNNER_KEY_HOME, "runner key ABI");
+_Static_assert(IO_KEY_END == WM_RUNNER_KEY_END, "runner key ABI");
+_Static_assert(IO_KEY_DELETE == WM_RUNNER_KEY_DELETE, "runner key ABI");
+
+static void wm_chord_push(unsigned int event)
+{
+	wm_chord_keys[wm_chord_head % WM_CHORD_QUEUE] = event;
+	wm_chord_head++;
+}
 
 static inline unsigned int irq_save_disable(void)
 {
@@ -1197,6 +1216,7 @@ int wm_server_poll(struct wm_status *out)
 	out->chord_head = wm_chord_head;
 	for (i = 0; i < WM_CHORD_QUEUE; i++)
 		out->chord_keys[i] = wm_chord_keys[i];
+	out->runner_active = wm_runner_active ? 1 : 0;
 	wm_full_redraw = 0;
 	return 0;
 }
@@ -1327,6 +1347,7 @@ static void wm_server_wm_died(void)
 	wm_ptr_capture = -1;
 	wm_cursor_override = CURSOR_NO_OVERRIDE;
 	wm_pointer_owned = 0;
+	wm_runner_active = 0;
 	mouse_set_shape(CURSOR_DEFAULT);
 	for (i = 0; i < MAX_WINDOWS; i++) {
 		windows[i].mapped_kind = WM_KIND_NONE;
@@ -1390,6 +1411,7 @@ void wm_server_init(void)
 	wm_attached = 0;
 	wm_frame_active = 0;
 	wm_first_frame = 0;
+	wm_runner_active = 0;
 	/* The ring-3 WM spawns the first terminal once wm_server_boot_ready()
 	 * says the storage scan is done. */
 }
@@ -1626,7 +1648,7 @@ void wm_pump_keyboard(void)
 
 	if (io_keyboard_raw())
 		return;   /* an inline command is polling for keys itself */
-	if (!fw)
+	if (!fw && !wm_runner_active)
 		return;
 
 	for (n = 0; n < 8; n++) {
@@ -1640,22 +1662,32 @@ void wm_pump_keyboard(void)
 		}
 		if (!k)
 			break;
+		/* Win/Super toggles the WM's app runner.  Only claim it while
+		 * a WM is attached; otherwise it is not ours to consume. */
+		if (k == IO_KEY_META) {
+			if (wm_attached)
+				wm_runner_active = !wm_runner_active;
+			continue;
+		}
+		/* While the runner owns the keyboard, keys go to its input
+		 * ring instead of the focused window.  Enter and Esc also
+		 * release the grab so a lost WM cannot leave it stuck. */
+		if (wm_runner_active) {
+			wm_chord_push(WM_CHORD_KEY | (unsigned int)k);
+			if (k == 0x1B || k == '\n')
+				wm_runner_active = 0;
+			continue;
+		}
 		/* Alt+Tab and Shift+Alt+Tab are global window-switcher chords:
 		 * they must not reach the focused window (or a popover).  A
 		 * typematic repeat after Alt was released is ignored. */
 		if (k == IO_KEY_ALT_TAB || k == IO_KEY_ALT_SHIFT_TAB) {
-			if (io_alt_down()) {
-				unsigned int slot = wm_chord_head %
-						    WM_CHORD_QUEUE;
-
-				wm_chord_keys[slot] =
-					k == IO_KEY_ALT_TAB ? WM_CHORD_NEXT :
-							      WM_CHORD_PREV;
-				wm_chord_head++;
-			}
+			if (io_alt_down())
+				wm_chord_push(k == IO_KEY_ALT_TAB ?
+					      WM_CHORD_NEXT : WM_CHORD_PREV);
 			continue;
 		}
-		if (fw->canvas_window) {
+		if (fw && fw->canvas_window) {
 			unsigned int next = (fw->key_head + 1) % 16;
 
 			if (next != fw->key_tail) {

+ 592 - 40
user/apps/wm/ucmd_wm.c

@@ -187,6 +187,37 @@ static unsigned int sw_mru_count;
 static int sw_last_focus = -1;
 static unsigned int sw_chord_seen;
 static int sw_chord_seen_valid;
+/* Win/Super app runner: a centered query field with ranked app suggestions.
+ * The kernel toggles the keyboard grab; this side mirrors
+ * wm_status.runner_active, consumes the raw keys from the same chord ring
+ * (WM_CHORD_KEY | key), and launches the selected app through sm_launch().
+ * Enter/Esc are also released by the kernel, so a crashed WM cannot leave
+ * the keyboard grabbed. */
+#define RUN_QUERY_MAX 48
+#define RUN_ROWS_MAX  7
+#define RUN_ROW_H     28
+#define RUN_FIELD_H   34
+#define RUN_HINT_H    18
+#define RUN_PAD       14
+#define RUN_W         560
+#define RUN_ICON      20
+#define RUN_MAX_APPS  32
+static int run_open;
+static char run_query[RUN_QUERY_MAX];
+static unsigned int run_len, run_caret;
+static int run_sel, run_top;
+static int run_matches[RUN_MAX_APPS];
+static int run_scores[RUN_MAX_APPS];
+static int run_nmatch;
+static int run_visible;
+static int run_x, run_y;
+static unsigned int run_w, run_h;
+/* The panel height depends on the match count, so a query edit can move and
+ * resize it.  Remember the painted rectangle and damage both the old and new
+ * one, otherwise the old panel stays on screen. */
+static int run_prev_x, run_prev_y;
+static unsigned int run_prev_w, run_prev_h;
+static int run_prev_valid;
 static char bar_msg[24];
 static unsigned int bar_msg_until;
 static int bar_msg_dirty;
@@ -298,6 +329,11 @@ static void sw_geom(void);
 static void sw_draw(void);
 static void sw_add_present(struct wm_present_info *p);
 
+/* Win/Super app runner overlay (defined with the switcher state). */
+static void run_geom(void);
+static void run_draw(void);
+static void run_add_present(struct wm_present_info *p);
+
 /* Bottom dock (defined with the start-menu/launch helpers further down). */
 static void dock_update(unsigned int mx, unsigned int my);
 static void dock_draw(void);
@@ -1579,6 +1615,10 @@ static void wm_overlays(struct wm_present_info *p)
 		sw_draw();
 		sw_add_present(p);
 	}
+	if (run_open) {
+		run_draw();
+		run_add_present(p);
+	}
 }
 
 /* True when a screen rectangle contains pixels from an overlay rather than
@@ -1601,6 +1641,10 @@ static int shadow_overlay_covers(int x, int y, int w, int h)
 	    x < sw_x + (int)sw_w && x + w > sw_x &&
 	    y < sw_y + (int)sw_h && y + h > sw_y)
 		return 1;
+	if (run_visible &&
+	    x < run_x + (int)run_w && x + w > run_x &&
+	    y < run_y + (int)run_h && y + h > run_y)
+		return 1;
 	return 0;
 }
 
@@ -2007,6 +2051,8 @@ static void sw_build(void)
  * as entry 0, so the selection moves to the previously used window. */
 static void sw_step(int dir)
 {
+	if (run_open)
+		return;
 	if (!sw_active) {
 		sw_build();
 		if (sw_count < 2)
@@ -2048,9 +2094,460 @@ static void sw_commit(void)
 	full_redraw = 1;
 }
 
-/* Consume queued chords and end the session when Alt is released.  Returns 1
- * when an active session needs its panel repainted. */
-static int sw_process(struct wm_status *st)
+/* ---- Win/Super app runner -------------------------------------------- */
+
+static char run_lower(char c)
+{
+	return c >= 'A' && c <= 'Z' ? (char)(c - 'A' + 'a') : c;
+}
+
+/* Case-insensitive prefix/substring tests for the app-name and command
+ * matches.  The query length is known, so these avoid needing a lowered
+ * copy of every string. */
+static int run_prefix(const char *s, const char *q, unsigned int n)
+{
+	unsigned int i;
+
+	for (i = 0; i < n; i++) {
+		if (!s[i] || run_lower(s[i]) != run_lower(q[i]))
+			return 0;
+	}
+	return 1;
+}
+
+static int run_contains(const char *s, const char *q, unsigned int n)
+{
+	unsigned int i;
+
+	if (!n)
+		return 1;
+	for (; *s; s++) {
+		for (i = 0; i < n; i++)
+			if (!s[i] || run_lower(s[i]) != run_lower(q[i]))
+				break;
+		if (i == n)
+			return 1;
+	}
+	return 0;
+}
+
+static const char *run_basename(const char *path)
+{
+	const char *base = path;
+
+	while (*path) {
+		if (*path == '/')
+			base = path + 1;
+		path++;
+	}
+	return base;
+}
+
+/* Lower is a better match: app label, command name, window title, then the
+ * same three as substrings. */
+static int run_score(const struct sm_app *a, const char *q, unsigned int n)
+{
+	const char *cmd = run_basename(a->path);
+
+	if (!n)
+		return 0;
+	if (run_prefix(a->label, q, n))
+		return 0;
+	if (a->path[0] && run_prefix(cmd, q, n))
+		return 1;
+	if (a->win_title && run_prefix(a->win_title, q, n))
+		return 2;
+	if (run_contains(a->label, q, n))
+		return 3;
+	if (a->path[0] && run_contains(cmd, q, n))
+		return 4;
+	if (a->win_title && run_contains(a->win_title, q, n))
+		return 5;
+	return -1;
+}
+
+/* Rank the apps into run_matches.  Insertion sort keeps equal scores in
+ * start-menu order, and the list is small enough to rebuild per keystroke. */
+static void run_recompute(void)
+{
+	int i, n = 0;
+
+	for (i = 0; i < SM_NAPP && i < RUN_MAX_APPS; i++) {
+		int score = run_score(&sm_apps[i], run_query, run_len);
+		int pos;
+
+		if (score < 0)
+			continue;
+		pos = n;
+		while (pos > 0 && score < run_scores[pos - 1]) {
+			run_matches[pos] = run_matches[pos - 1];
+			run_scores[pos] = run_scores[pos - 1];
+			pos--;
+		}
+		run_matches[pos] = i;
+		run_scores[pos] = score;
+		n++;
+	}
+	run_nmatch = n;
+	run_sel = 0;
+	run_top = 0;
+}
+
+static int run_rows_max(void)
+{
+	int avail = (int)fbh - WM_BAR_H - 40;
+	int rows = (avail - 2 * RUN_PAD - RUN_FIELD_H - 8 - RUN_HINT_H) /
+		   RUN_ROW_H;
+
+	if (rows > RUN_ROWS_MAX)
+		rows = RUN_ROWS_MAX;
+	if (rows < 1)
+		rows = 1;
+	return rows;
+}
+
+static void run_geom(void)
+{
+	int rows = run_nmatch < run_rows_max() ? run_nmatch : run_rows_max();
+
+	if (rows < 1)
+		rows = 1;
+	run_w = RUN_W;
+	if ((int)run_w > (int)fbw - 48)
+		run_w = fbw - 48;
+	run_h = 2 * RUN_PAD + RUN_FIELD_H + 8 +
+		(unsigned int)rows * RUN_ROW_H + RUN_HINT_H;
+	run_x = ((int)fbw - (int)run_w) / 2;
+	run_y = WM_BAR_H + ((int)fbh - WM_BAR_H - (int)run_h) / 2;
+	if (run_x < 8)
+		run_x = 8;
+	if (run_x + (int)run_w > (int)fbw - 8)
+		run_x = (int)fbw - 8 - (int)run_w;
+	if (run_y < WM_BAR_H + 8)
+		run_y = WM_BAR_H + 8;
+	if (run_y + (int)run_h > (int)fbh - 8)
+		run_y = (int)fbh - 8 - (int)run_h;
+}
+
+static void run_sel_visible(void)
+{
+	int rows = run_rows_max();
+	int max_top = run_nmatch - rows;
+
+	if (run_sel < run_top)
+		run_top = run_sel;
+	if (run_sel >= run_top + rows)
+		run_top = run_sel - rows + 1;
+	if (run_top < 0)
+		run_top = 0;
+	if (max_top < 0)
+		max_top = 0;
+	if (run_top > max_top)
+		run_top = max_top;
+}
+
+static void run_move(int delta)
+{
+	if (!run_nmatch)
+		return;
+	run_sel += delta;
+	if (run_sel < 0)
+		run_sel = 0;
+	if (run_sel >= run_nmatch)
+		run_sel = run_nmatch - 1;
+	run_sel_visible();
+}
+
+/* The selected label's suffix after the typed prefix, for the inline ghost
+ * completion.  NULL when the query is empty or the match came from another
+ * field. */
+static const char *run_completion(void)
+{
+	const struct sm_app *a;
+	unsigned int i;
+
+	if (!run_nmatch || !run_len || run_sel < 0 || run_sel >= run_nmatch)
+		return (void *)0;
+	a = &sm_apps[run_matches[run_sel]];
+	for (i = 0; i < run_len; i++)
+		if (!a->label[i] ||
+		    run_lower(a->label[i]) != run_lower(run_query[i]))
+			return (void *)0;
+	return a->label;
+}
+
+static void run_complete(void)
+{
+	const char *completion = run_completion();
+	unsigned int i;
+
+	if (!completion)
+		return;
+	for (i = 0; completion[i] && i + 1 < RUN_QUERY_MAX; i++)
+		run_query[i] = completion[i];
+	run_query[i] = '\0';
+	run_len = run_caret = i;
+	run_recompute();
+}
+
+static void run_insert(char c)
+{
+	unsigned int i;
+
+	if (run_len + 1 >= RUN_QUERY_MAX)
+		return;
+	for (i = run_len; i > run_caret; i--)
+		run_query[i] = run_query[i - 1];
+	run_query[run_caret] = c;
+	run_len++;
+	run_caret++;
+	run_query[run_len] = '\0';
+	run_recompute();
+}
+
+static void run_erase_before(void)
+{
+	unsigned int i;
+
+	if (!run_caret)
+		return;
+	for (i = run_caret - 1; i + 1 <= run_len; i++)
+		run_query[i] = run_query[i + 1];
+	run_len--;
+	run_caret--;
+	run_query[run_len] = '\0';
+	run_recompute();
+}
+
+static void run_erase_at(void)
+{
+	unsigned int i;
+
+	if (run_caret >= run_len)
+		return;
+	for (i = run_caret; i + 1 <= run_len; i++)
+		run_query[i] = run_query[i + 1];
+	run_len--;
+	run_query[run_len] = '\0';
+	run_recompute();
+}
+
+static void run_open_ui(void)
+{
+	run_open = 1;
+	run_prev_valid = 0;
+	run_query[0] = '\0';
+	run_len = 0;
+	run_caret = 0;
+	run_sel = 0;
+	run_top = 0;
+	run_recompute();
+	sw_active = 0;
+	sw_count = 0;
+	sm_close();
+	full_redraw = 1;
+}
+
+static void run_close_ui(void)
+{
+	if (!run_open)
+		return;
+	run_open = 0;
+	run_nmatch = 0;
+	run_len = 0;
+	run_caret = 0;
+	run_query[0] = '\0';
+	run_prev_valid = 0;
+	full_redraw = 1;
+}
+
+static void run_launch(void)
+{
+	int idx;
+
+	if (run_sel < 0 || run_sel >= run_nmatch) {
+		run_close_ui();
+		return;
+	}
+	idx = run_matches[run_sel];
+	run_close_ui();
+	if (idx >= 0 && idx < SM_NAPP)
+		sm_launch(idx);
+}
+
+static void run_key(unsigned int key)
+{
+	if (!run_open)
+		return;
+	if (key == 0x1B) {
+		run_close_ui();
+		return;
+	}
+	if (key == '\n' || key == '\r') {
+		run_launch();
+		return;
+	}
+	if (key == '\t') {
+		run_complete();
+		return;
+	}
+	if (key == WM_RUNNER_KEY_UP) {
+		run_move(-1);
+		return;
+	}
+	if (key == WM_RUNNER_KEY_DOWN) {
+		run_move(1);
+		return;
+	}
+	if (key == WM_RUNNER_KEY_PAGE_UP) {
+		run_move(-run_rows_max());
+		return;
+	}
+	if (key == WM_RUNNER_KEY_PAGE_DOWN) {
+		run_move(run_rows_max());
+		return;
+	}
+	if (key == WM_RUNNER_KEY_LEFT) {
+		if (run_caret)
+			run_caret--;
+		return;
+	}
+	if (key == WM_RUNNER_KEY_RIGHT) {
+		if (run_caret < run_len)
+			run_caret++;
+		return;
+	}
+	if (key == WM_RUNNER_KEY_HOME) {
+		run_caret = 0;
+		return;
+	}
+	if (key == WM_RUNNER_KEY_END) {
+		run_caret = run_len;
+		return;
+	}
+	if (key == 0x08) {
+		run_erase_before();
+		return;
+	}
+	if (key == WM_RUNNER_KEY_DELETE) {
+		run_erase_at();
+		return;
+	}
+	if (key >= 32 && key < 127) {
+		run_insert((char)key);
+		return;
+	}
+}
+
+static void run_draw(void)
+{
+	const struct sm_app *a;
+	const char *completion;
+	char saved;
+	unsigned int i, qw;
+	int fx, fy, fw, ry, rows, shown, hint_y;
+
+	if (!run_open)
+		return;
+	run_geom();
+	usurf_fill_round_alpha(&screen, run_x, run_y, (int)run_w, (int)run_h,
+			       10, 0x141824u, 242);
+
+	fx = run_x + RUN_PAD;
+	fy = run_y + RUN_PAD;
+	fw = (int)run_w - 2 * RUN_PAD;
+	sm_fill_round(fx, fy, fw, RUN_FIELD_H, 7, 0x0B0D14u);
+
+	/* The query text, a dim placeholder, and the caret at the edit point.
+	 * Temporarily terminating at the caret gives the measured prefix. */
+	if (run_len)
+		usurf_text(&screen, fx + 10, fy + (RUN_FIELD_H - 16) / 2,
+			   run_query, SM_TEXT, fx, fy, (unsigned int)fw,
+			   RUN_FIELD_H);
+	else
+		usurf_text(&screen, fx + 10, fy + (RUN_FIELD_H - 16) / 2,
+			   "Search apps", SM_TEXT_DIM, fx, fy,
+			   (unsigned int)fw, RUN_FIELD_H);
+	saved = run_query[run_caret];
+	run_query[run_caret] = '\0';
+	qw = usurf_text_width(&screen, run_query);
+	run_query[run_caret] = saved;
+	usurf_fill(&screen, fx + 10 + (int)qw, fy + 9, 1, 16, 0xE8EAF6u);
+
+	completion = run_completion();
+	if (completion && run_caret == run_len)
+		usurf_text(&screen, fx + 10 + (int)qw + 1,
+			   fy + (RUN_FIELD_H - 16) / 2,
+			   completion + run_len, SM_TEXT_DIM, fx, fy,
+			   (unsigned int)fw, RUN_FIELD_H);
+
+	rows = run_rows_max();
+	ry = fy + RUN_FIELD_H + 8;
+	shown = run_nmatch - run_top;
+	if (shown > rows)
+		shown = rows;
+	if (!run_nmatch) {
+		usurf_text(&screen, fx + 10, ry + 5, "No matching apps",
+			   SM_TEXT_DIM, fx, ry, (unsigned int)fw,
+			   RUN_ROW_H);
+		shown = 0;
+	}
+	for (i = 0; i < (unsigned int)shown; i++) {
+		int mi = run_top + (int)i;
+		int row_y = ry + (int)i * RUN_ROW_H;
+		const char *cmd;
+		int tx = fx + 34;
+		int tw;
+
+		a = &sm_apps[run_matches[mi]];
+		if (mi == run_sel)
+			sm_fill_round(fx, row_y, fw, RUN_ROW_H - 2, 6,
+				      0x365CA6);
+		if (!usurf_app_icon(&screen, fx + 6,
+				    row_y + (RUN_ROW_H - RUN_ICON) / 2,
+				    RUN_ICON, (enum app_icon)a->icon))
+			sm_tile(fx + 6, row_y + (RUN_ROW_H - RUN_ICON) / 2,
+				RUN_ICON, a->tile, a->letter);
+		usurf_text(&screen, tx, row_y + (RUN_ROW_H - 16) / 2,
+			   a->label, mi == run_sel ? COL_WHITE : SM_TEXT,
+			   fx, row_y, (unsigned int)fw, RUN_ROW_H);
+		cmd = run_basename(a->path);
+		if (a->path[0] && cmd[0]) {
+			tw = (int)usurf_text_width(&screen, cmd);
+			if (tx + tw + 10 < fx + fw)
+				usurf_text(&screen, fx + fw - 10 - tw,
+					   row_y + (RUN_ROW_H - 16) / 2,
+					   cmd, SM_TEXT_DIM, fx, row_y,
+					   (unsigned int)fw, RUN_ROW_H);
+		}
+	}
+
+	hint_y = run_y + (int)run_h - RUN_PAD - RUN_HINT_H + 2;
+	usurf_text(&screen, fx + 2, hint_y,
+		   "Tab complete  Up/Down select  Enter run  Esc close",
+		   SM_TEXT_DIM, run_x, run_y, run_w, run_h);
+
+	run_prev_x = run_x;
+	run_prev_y = run_y;
+	run_prev_w = run_w;
+	run_prev_h = run_h;
+	run_prev_valid = 1;
+}
+
+static void run_add_present(struct wm_present_info *p)
+{
+	if (!run_open)
+		return;
+	run_geom();
+	add_rect(p, run_x, run_y, run_w, run_h);
+}
+
+/* Consume the kernel's WM input ring: Alt+Tab chords, runner keys, and the
+ * runner grab transition.  Returns a bitmask of overlays that need a
+ * repaint (WM_INPUT_SW / WM_INPUT_RUN). */
+#define WM_INPUT_SW  1
+#define WM_INPUT_RUN 2
+static int wm_input_process(struct wm_status *st)
 {
 	int changed = 0;
 	unsigned int n;
@@ -2059,48 +2556,64 @@ static int sw_process(struct wm_status *st)
 		sw_chord_seen = st->chord_head;
 		sw_chord_seen_valid = 1;
 	}
+	/* The Win key already toggled the kernel grab, so open the runner
+	 * before applying keys typed in the same interval. */
+	if (st->runner_active && !run_open) {
+		run_open_ui();
+		changed |= WM_INPUT_RUN;
+	}
 	while (sw_chord_seen != st->chord_head) {
-		unsigned int key =
+		unsigned int event =
 			st->chord_keys[sw_chord_seen % WM_CHORD_QUEUE];
 
 		sw_chord_seen++;
-		if (key == WM_CHORD_NEXT)
+		if (event & WM_CHORD_KEY) {
+			if (run_open)
+				run_key(event & 0xFFFFu);
+			changed |= WM_INPUT_RUN;
+		} else if (event == WM_CHORD_NEXT) {
 			sw_step(1);
-		else if (key == WM_CHORD_PREV)
+			changed |= WM_INPUT_SW;
+		} else if (event == WM_CHORD_PREV) {
 			sw_step(-1);
-		changed = 1;
+			changed |= WM_INPUT_SW;
+		}
 	}
-	if (!sw_active)
-		return 0;
-	if (!st->alt_down) {
-		sw_commit();
-		return 0;
+	/* A runner launch or Esc/Enter already ended the local session; the
+	 * kernel has released the grab for Enter/Esc and for a second Win. */
+	if (!st->runner_active && run_open) {
+		run_close_ui();
+		changed |= WM_INPUT_RUN;
 	}
-	/* A window may have closed while the session is open. */
-	{
-		unsigned int keep = sw_sel < sw_count ? sw_slots[sw_sel] :
-				    WM_MAX_WINDOWS;
-		unsigned int i, sel = 0;
-
-		n = 0;
-		for (i = 0; i < sw_count; i++)
-			if (sw_slot_usable(sw_slots[i])) {
-				if (sw_slots[i] == keep)
-					sel = n;
-				sw_slots[n++] = sw_slots[i];
+	if (sw_active) {
+		if (!st->alt_down) {
+			sw_commit();
+			changed |= WM_INPUT_SW;
+		} else {
+			/* A window may have closed while the session is open. */
+			unsigned int keep = sw_sel < sw_count ?
+					    sw_slots[sw_sel] : WM_MAX_WINDOWS;
+			unsigned int i, sel = 0;
+
+			n = 0;
+			for (i = 0; i < sw_count; i++)
+				if (sw_slot_usable(sw_slots[i])) {
+					if (sw_slots[i] == keep)
+						sel = n;
+					sw_slots[n++] = sw_slots[i];
+				}
+			if (n != sw_count) {
+				sw_count = n;
+				sw_sel = sel;
+				changed |= WM_INPUT_SW;
+			}
+			if (sw_count < 2) {
+				sw_active = 0;
+				sw_count = 0;
+				full_redraw = 1;
 			}
-		if (n != sw_count) {
-			sw_count = n;
-			sw_sel = sel;
-			changed = 1;
 		}
 	}
-	if (sw_count < 2) {
-		sw_active = 0;
-		sw_count = 0;
-		full_redraw = 1;
-		return 0;
-	}
 	return changed;
 }
 
@@ -2414,7 +2927,7 @@ static void do_update(struct wm_status *st)
 	int osd_hide = 0, osd_repaint = 0;
 	int sm_dirty;
 	int dock_redraw = 0, dock_overlap = 0;
-	int sw_repaint = 0;
+	int input_repaint = 0;
 	unsigned int dj;
 
 	/* The kernel bumps backlight_seq on every brightness key/command.
@@ -2566,7 +3079,7 @@ static void do_update(struct wm_status *st)
 	/* Alt+Tab runs after the info refresh: focus transitions are visible
 	 * in wins[] and a window that closed mid-session is filtered out. */
 	sw_track_focus();
-	sw_repaint = sw_process(st);
+	input_repaint = wm_input_process(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. */
@@ -2698,6 +3211,8 @@ static void do_update(struct wm_status *st)
 			sm_draw();
 			sw_draw();
 			sw_visible = sw_active;
+			run_draw();
+			run_visible = run_open;
 			present.count = 0;
 			add_rect(&present, 0, 0, fbw, fbh);
 			present.immediate = 0;
@@ -2726,11 +3241,19 @@ static void do_update(struct wm_status *st)
 		add_rect(&present, osd_x, osd_y, osd_w, osd_h);
 		need = 1;
 	}
-	if (sw_repaint && sw_active) {
+	if ((input_repaint & WM_INPUT_SW) && sw_active) {
 		sw_geom();
 		add_rect(&present, sw_x, sw_y, sw_w, sw_h);
 		need = 1;
 	}
+	if ((input_repaint & WM_INPUT_RUN) && run_open) {
+		run_geom();
+		if (run_prev_valid)
+			add_rect(&present, run_prev_x, run_prev_y,
+				 run_prev_w, run_prev_h);
+		add_rect(&present, run_x, run_y, run_w, run_h);
+		need = 1;
+	}
 	if (osd_show)
 		need = 1;
 	if (bar_dirty) {
@@ -2774,9 +3297,9 @@ static void do_update(struct wm_status *st)
 			break;
 		}
 	}
-	/* A window damage rectangle under the switcher panel would overwrite
+	/* A window damage rectangle under an overlay panel would overwrite
 	 * its pixels; repaint the panel after the window draw. */
-	if (sw_active && !sw_repaint) {
+	if (sw_active && !(input_repaint & WM_INPUT_SW)) {
 		sw_geom();
 		for (dj = 0; dj < present.count; dj++) {
 			int rx = present.rect[dj].x;
@@ -2786,13 +3309,30 @@ static void do_update(struct wm_status *st)
 			    rx + (int)present.rect[dj].w > sw_x &&
 			    ry < sw_y + (int)sw_h &&
 			    ry + (int)present.rect[dj].h > sw_y) {
-				sw_repaint = 1;
+				input_repaint |= WM_INPUT_SW;
 				add_rect(&present, sw_x, sw_y, sw_w, sw_h);
 				need = 1;
 				break;
 			}
 		}
 	}
+	if (run_open && !(input_repaint & WM_INPUT_RUN)) {
+		run_geom();
+		for (dj = 0; dj < present.count; dj++) {
+			int rx = present.rect[dj].x;
+			int ry = present.rect[dj].y;
+
+			if (rx < run_x + (int)run_w &&
+			    rx + (int)present.rect[dj].w > run_x &&
+			    ry < run_y + (int)run_h &&
+			    ry + (int)present.rect[dj].h > run_y) {
+				input_repaint |= WM_INPUT_RUN;
+				add_rect(&present, run_x, run_y, run_w, run_h);
+				need = 1;
+				break;
+			}
+		}
+	}
 	if (dock_dirty || dock_overlap) {
 		dock_damage(&present);
 		dock_redraw = 1;
@@ -2830,6 +3370,11 @@ static void do_update(struct wm_status *st)
 	sw_visible = sw_active;
 	if (sw_active)
 		sw_add_present(&present);
+	if (run_open)
+		run_draw();
+	run_visible = run_open;
+	if (run_open)
+		run_add_present(&present);
 
 	for (i = 0; i < WM_MAX_WINDOWS; i++) {
 		struct uwin *u = &wins[i];
@@ -3603,6 +4148,13 @@ static void handle_mouse(struct wm_status *st)
 	int down = (buttons & 1) != 0;
 	int was = (prev_buttons & 1) != 0;
 
+	/* The app runner is modal: clicks cannot reach the start menu, the
+	 * dock or a window below the overlay.  Dismiss it with Win/Esc. */
+	if (run_open) {
+		prev_buttons = buttons;
+		return;
+	}
+
 	if (down && !was) {
 		int prev_title_id = last_title_id;
 		unsigned int now = u_ticks_ms();