|
|
@@ -162,6 +162,31 @@ static unsigned int osd_seen_seq;
|
|
|
static int osd_seen_valid;
|
|
|
static int osd_x, osd_y;
|
|
|
static unsigned int osd_w, osd_h;
|
|
|
+/* Alt+Tab switcher: the kernel consumes the chord (so the focused window
|
|
|
+ * never sees the Tab) and queues WM_CHORD_NEXT/PREV events plus the Alt
|
|
|
+ * held state in wm_status. The WM keeps the MRU order and the selection,
|
|
|
+ * draws the icon strip, and focuses the selected window when Alt is
|
|
|
+ * released. sw_visible tracks pixels on screen so a window drag under it
|
|
|
+ * takes the full repaint path. */
|
|
|
+#define SW_ICON_MAX 48
|
|
|
+#define SW_CELL_W 68
|
|
|
+#define SW_PAD 16
|
|
|
+#define SW_LABEL_H 24
|
|
|
+static int sw_active;
|
|
|
+static unsigned int sw_sel;
|
|
|
+static unsigned int sw_count;
|
|
|
+static unsigned int sw_slots[WM_MAX_WINDOWS];
|
|
|
+static int sw_visible;
|
|
|
+static int sw_x, sw_y;
|
|
|
+static unsigned int sw_w, sw_h;
|
|
|
+/* Most-recently-focused order, maintained from the window focus flags (the
|
|
|
+ * WM is the only process that moves focus, but the kernel can pick a new
|
|
|
+ * focused window when one closes). Popovers are filtered out of the list. */
|
|
|
+static unsigned int sw_mru[WM_MAX_WINDOWS];
|
|
|
+static unsigned int sw_mru_count;
|
|
|
+static int sw_last_focus = -1;
|
|
|
+static unsigned int sw_chord_seen;
|
|
|
+static int sw_chord_seen_valid;
|
|
|
static char bar_msg[24];
|
|
|
static unsigned int bar_msg_until;
|
|
|
static int bar_msg_dirty;
|
|
|
@@ -266,6 +291,12 @@ static void sm_add_present(struct wm_present_info *p);
|
|
|
static int sm_update_hover(unsigned int mx, unsigned int my);
|
|
|
static void sm_close(void);
|
|
|
static void sm_launch(int idx);
|
|
|
+static void sm_tile(int x, int y, int size, unsigned int rgb, char letter);
|
|
|
+
|
|
|
+/* Alt+Tab switcher overlay (defined next to the app-icon helpers). */
|
|
|
+static void sw_geom(void);
|
|
|
+static void sw_draw(void);
|
|
|
+static void sw_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);
|
|
|
@@ -1544,6 +1575,10 @@ static void wm_overlays(struct wm_present_info *p)
|
|
|
sm_draw();
|
|
|
sm_add_present(p);
|
|
|
}
|
|
|
+ if (sw_active) {
|
|
|
+ sw_draw();
|
|
|
+ sw_add_present(p);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/* True when a screen rectangle contains pixels from an overlay rather than
|
|
|
@@ -1562,6 +1597,10 @@ static int shadow_overlay_covers(int x, int y, int w, int h)
|
|
|
x < osd_x + (int)osd_w && x + w > osd_x &&
|
|
|
y < osd_y + (int)osd_h && y + h > osd_y)
|
|
|
return 1;
|
|
|
+ if (sw_visible &&
|
|
|
+ x < sw_x + (int)sw_w && x + w > sw_x &&
|
|
|
+ y < sw_y + (int)sw_h && y + h > sw_y)
|
|
|
+ return 1;
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -1870,6 +1909,310 @@ static void sm_tile(int x, int y, int size, unsigned int rgb, char letter)
|
|
|
x, y, (unsigned int)size, (unsigned int)size);
|
|
|
}
|
|
|
|
|
|
+/* ---- Alt+Tab switcher -------------------------------------------------
|
|
|
+ * The kernel consumes the chord and reports it plus the Alt held state in
|
|
|
+ * wm_status; the WM keeps the MRU order and the selection, draws a
|
|
|
+ * horizontal icon strip with the selected app's name below it, and focuses
|
|
|
+ * the selection when Alt is released. The overlay itself is display
|
|
|
+ * only. */
|
|
|
+static unsigned int sw_cell;
|
|
|
+static unsigned int sw_icon;
|
|
|
+
|
|
|
+static int sw_slot_usable(unsigned int idx)
|
|
|
+{
|
|
|
+ return idx < WM_MAX_WINDOWS && wins[idx].info.used &&
|
|
|
+ !wins[idx].info.popover;
|
|
|
+}
|
|
|
+
|
|
|
+static void sw_mru_remove(unsigned int idx)
|
|
|
+{
|
|
|
+ unsigned int i, j;
|
|
|
+
|
|
|
+ for (i = 0; i < sw_mru_count; i++) {
|
|
|
+ if (sw_mru[i] != idx)
|
|
|
+ continue;
|
|
|
+ for (j = i; j + 1 < sw_mru_count; j++)
|
|
|
+ sw_mru[j] = sw_mru[j + 1];
|
|
|
+ sw_mru_count--;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static void sw_mru_touch(unsigned int idx)
|
|
|
+{
|
|
|
+ unsigned int i;
|
|
|
+
|
|
|
+ sw_mru_remove(idx);
|
|
|
+ for (i = sw_mru_count < WM_MAX_WINDOWS ? sw_mru_count :
|
|
|
+ WM_MAX_WINDOWS - 1; i > 0; i--)
|
|
|
+ sw_mru[i] = sw_mru[i - 1];
|
|
|
+ sw_mru[0] = idx;
|
|
|
+ if (sw_mru_count < WM_MAX_WINDOWS)
|
|
|
+ sw_mru_count++;
|
|
|
+}
|
|
|
+
|
|
|
+/* Track focus transitions from the window info the WM refreshes every
|
|
|
+ * frame. The focused normal window goes to the front of the MRU; closed
|
|
|
+ * entries are dropped. */
|
|
|
+static void sw_track_focus(void)
|
|
|
+{
|
|
|
+ int f = -1;
|
|
|
+ unsigned int i;
|
|
|
+
|
|
|
+ for (i = 0; i < WM_MAX_WINDOWS; i++)
|
|
|
+ if (wins[i].info.used && wins[i].info.focused &&
|
|
|
+ !wins[i].info.popover) {
|
|
|
+ f = (int)i;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (f != sw_last_focus) {
|
|
|
+ sw_last_focus = f;
|
|
|
+ if (f >= 0)
|
|
|
+ sw_mru_touch((unsigned int)f);
|
|
|
+ }
|
|
|
+ for (i = 0; i < sw_mru_count; ) {
|
|
|
+ if (sw_slot_usable(sw_mru[i]))
|
|
|
+ i++;
|
|
|
+ else
|
|
|
+ sw_mru_remove(sw_mru[i]);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/* Build the switcher list in MRU order, then append any normal window the
|
|
|
+ * MRU does not know yet. */
|
|
|
+static void sw_build(void)
|
|
|
+{
|
|
|
+ unsigned int i, j, n = 0;
|
|
|
+
|
|
|
+ for (i = 0; i < sw_mru_count && n < WM_MAX_WINDOWS; i++)
|
|
|
+ if (sw_slot_usable(sw_mru[i]))
|
|
|
+ sw_slots[n++] = sw_mru[i];
|
|
|
+ for (i = 0; i < WM_MAX_WINDOWS && n < WM_MAX_WINDOWS; i++) {
|
|
|
+ int seen = 0;
|
|
|
+
|
|
|
+ if (!sw_slot_usable(i))
|
|
|
+ continue;
|
|
|
+ for (j = 0; j < n; j++)
|
|
|
+ if (sw_slots[j] == i) {
|
|
|
+ seen = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (!seen)
|
|
|
+ sw_slots[n++] = i;
|
|
|
+ }
|
|
|
+ sw_count = n;
|
|
|
+}
|
|
|
+
|
|
|
+/* One chord step. The first step opens the session with the focused window
|
|
|
+ * as entry 0, so the selection moves to the previously used window. */
|
|
|
+static void sw_step(int dir)
|
|
|
+{
|
|
|
+ if (!sw_active) {
|
|
|
+ sw_build();
|
|
|
+ if (sw_count < 2)
|
|
|
+ return;
|
|
|
+ sw_active = 1;
|
|
|
+ sw_sel = 0;
|
|
|
+ sm_close();
|
|
|
+ full_redraw = 1;
|
|
|
+ } else {
|
|
|
+ sw_build();
|
|
|
+ if (sw_count < 2) {
|
|
|
+ sw_active = 0;
|
|
|
+ sw_count = 0;
|
|
|
+ full_redraw = 1;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (dir > 0)
|
|
|
+ sw_sel = (sw_sel + 1) % sw_count;
|
|
|
+ else
|
|
|
+ sw_sel = (sw_sel + sw_count - 1) % sw_count;
|
|
|
+}
|
|
|
+
|
|
|
+/* Alt released: focus the selection. A missing/closed entry is ignored. */
|
|
|
+static void sw_commit(void)
|
|
|
+{
|
|
|
+ unsigned int idx;
|
|
|
+
|
|
|
+ if (!sw_active)
|
|
|
+ return;
|
|
|
+ sw_active = 0;
|
|
|
+ if (sw_sel < sw_count) {
|
|
|
+ idx = sw_slots[sw_sel];
|
|
|
+ if (sw_slot_usable(idx))
|
|
|
+ u_wm_focus(idx);
|
|
|
+ }
|
|
|
+ sw_count = 0;
|
|
|
+ sw_sel = 0;
|
|
|
+ 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)
|
|
|
+{
|
|
|
+ int changed = 0;
|
|
|
+ unsigned int n;
|
|
|
+
|
|
|
+ if (!sw_chord_seen_valid) {
|
|
|
+ sw_chord_seen = st->chord_head;
|
|
|
+ sw_chord_seen_valid = 1;
|
|
|
+ }
|
|
|
+ while (sw_chord_seen != st->chord_head) {
|
|
|
+ unsigned int key =
|
|
|
+ st->chord_keys[sw_chord_seen % WM_CHORD_QUEUE];
|
|
|
+
|
|
|
+ sw_chord_seen++;
|
|
|
+ if (key == WM_CHORD_NEXT)
|
|
|
+ sw_step(1);
|
|
|
+ else if (key == WM_CHORD_PREV)
|
|
|
+ sw_step(-1);
|
|
|
+ changed = 1;
|
|
|
+ }
|
|
|
+ if (!sw_active)
|
|
|
+ return 0;
|
|
|
+ if (!st->alt_down) {
|
|
|
+ sw_commit();
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ /* 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 = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (sw_count < 2) {
|
|
|
+ sw_active = 0;
|
|
|
+ sw_count = 0;
|
|
|
+ full_redraw = 1;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return changed;
|
|
|
+}
|
|
|
+
|
|
|
+static const struct sm_app *sw_app_for_title(const char *title)
|
|
|
+{
|
|
|
+ int i;
|
|
|
+
|
|
|
+ for (i = 0; i < SM_NAPP; i++) {
|
|
|
+ const char *t = sm_apps[i].win_title;
|
|
|
+ const char *a = title;
|
|
|
+
|
|
|
+ if (!t)
|
|
|
+ continue;
|
|
|
+ while (*a && *a == *t) {
|
|
|
+ a++;
|
|
|
+ t++;
|
|
|
+ }
|
|
|
+ if (*a == *t)
|
|
|
+ return &sm_apps[i];
|
|
|
+ }
|
|
|
+ return (void *)0;
|
|
|
+}
|
|
|
+
|
|
|
+static void sw_geom(void)
|
|
|
+{
|
|
|
+ unsigned int n = sw_count;
|
|
|
+
|
|
|
+ if (!n)
|
|
|
+ n = 1;
|
|
|
+ sw_cell = SW_CELL_W;
|
|
|
+ if ((int)(n * sw_cell + 2 * SW_PAD) > (int)fbw - 16 &&
|
|
|
+ (int)fbw > (int)(2 * SW_PAD + 16 + n * 34))
|
|
|
+ sw_cell = (fbw - 16 - 2 * SW_PAD) / n;
|
|
|
+ sw_icon = sw_cell > 20 ? sw_cell - 20 : 16;
|
|
|
+ if (sw_icon > SW_ICON_MAX)
|
|
|
+ sw_icon = SW_ICON_MAX;
|
|
|
+ sw_w = n * sw_cell + 2 * SW_PAD;
|
|
|
+ sw_h = SW_PAD + sw_icon + 10 + SW_LABEL_H + SW_PAD;
|
|
|
+ sw_x = ((int)fbw - (int)sw_w) / 2;
|
|
|
+ if (sw_x < 8)
|
|
|
+ sw_x = 8;
|
|
|
+ sw_y = WM_BAR_H + ((int)fbh - WM_BAR_H - (int)sw_h) / 2;
|
|
|
+ if (sw_y < WM_BAR_H + 8)
|
|
|
+ sw_y = WM_BAR_H + 8;
|
|
|
+ if (sw_y + (int)sw_h > (int)fbh - 8)
|
|
|
+ sw_y = (int)fbh - 8 - (int)sw_h;
|
|
|
+}
|
|
|
+
|
|
|
+static void sw_draw(void)
|
|
|
+{
|
|
|
+ const char *label;
|
|
|
+ unsigned int i;
|
|
|
+ int ty, tx, tw;
|
|
|
+
|
|
|
+ if (!sw_active || !sw_count)
|
|
|
+ return;
|
|
|
+ sw_geom();
|
|
|
+ usurf_fill_round_alpha(&screen, sw_x, sw_y, (int)sw_w, (int)sw_h, 10,
|
|
|
+ 0x141824u, 242);
|
|
|
+
|
|
|
+ for (i = 0; i < sw_count; i++) {
|
|
|
+ const struct wm_window_info *w = &wins[sw_slots[i]].info;
|
|
|
+ const struct sm_app *a = sw_app_for_title(w->title);
|
|
|
+ int cell_x = sw_x + SW_PAD + (int)i * (int)sw_cell;
|
|
|
+ int ix = cell_x + ((int)sw_cell - (int)sw_icon) / 2;
|
|
|
+ int iy = sw_y + SW_PAD;
|
|
|
+
|
|
|
+ if (i == sw_sel)
|
|
|
+ usurf_fill_round_alpha(&screen, cell_x + 3, iy - 5,
|
|
|
+ (int)sw_cell - 6,
|
|
|
+ (int)sw_icon + 10, 8,
|
|
|
+ 0x3C69B4u, 230);
|
|
|
+ if (a) {
|
|
|
+ if (!usurf_app_icon(&screen, ix, iy, (int)sw_icon,
|
|
|
+ (enum app_icon)a->icon))
|
|
|
+ sm_tile(ix, iy, (int)sw_icon, a->tile,
|
|
|
+ a->letter);
|
|
|
+ } else {
|
|
|
+ char letter = '?';
|
|
|
+
|
|
|
+ if (w->title[0]) {
|
|
|
+ letter = w->title[0];
|
|
|
+ if (letter >= 'a' && letter <= 'z')
|
|
|
+ letter = (char)(letter - 'a' + 'A');
|
|
|
+ }
|
|
|
+ sm_tile(ix, iy, (int)sw_icon, 0x4A4F62u, letter);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ const struct wm_window_info *w =
|
|
|
+ &wins[sw_slots[sw_sel]].info;
|
|
|
+ const struct sm_app *a = sw_app_for_title(w->title);
|
|
|
+
|
|
|
+ label = a ? a->label : w->title;
|
|
|
+ }
|
|
|
+ ty = sw_y + SW_PAD + (int)sw_icon + 10 +
|
|
|
+ (SW_LABEL_H - 16) / 2;
|
|
|
+ tw = (int)usurf_text_width(&screen, label);
|
|
|
+ tx = sw_x + ((int)sw_w - tw) / 2;
|
|
|
+ usurf_text(&screen, tx, ty, label, SM_TEXT,
|
|
|
+ sw_x, sw_y, sw_w, sw_h);
|
|
|
+}
|
|
|
+
|
|
|
+static void sw_add_present(struct wm_present_info *p)
|
|
|
+{
|
|
|
+ if (!sw_active || !sw_count)
|
|
|
+ return;
|
|
|
+ sw_geom();
|
|
|
+ add_rect(p, sw_x, sw_y, sw_w, sw_h);
|
|
|
+}
|
|
|
+
|
|
|
static void sm_draw_app(int i, const struct sm_layout *l)
|
|
|
{
|
|
|
const struct sm_app *a = &sm_apps[i];
|
|
|
@@ -2071,6 +2414,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;
|
|
|
unsigned int dj;
|
|
|
|
|
|
/* The kernel bumps backlight_seq on every brightness key/command.
|
|
|
@@ -2219,6 +2563,10 @@ 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);
|
|
|
/* 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. */
|
|
|
@@ -2348,6 +2696,8 @@ static void do_update(struct wm_status *st)
|
|
|
osd_draw();
|
|
|
osd_visible = osd_show;
|
|
|
sm_draw();
|
|
|
+ sw_draw();
|
|
|
+ sw_visible = sw_active;
|
|
|
present.count = 0;
|
|
|
add_rect(&present, 0, 0, fbw, fbh);
|
|
|
present.immediate = 0;
|
|
|
@@ -2376,6 +2726,11 @@ 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) {
|
|
|
+ sw_geom();
|
|
|
+ add_rect(&present, sw_x, sw_y, sw_w, sw_h);
|
|
|
+ need = 1;
|
|
|
+ }
|
|
|
if (osd_show)
|
|
|
need = 1;
|
|
|
if (bar_dirty) {
|
|
|
@@ -2419,6 +2774,25 @@ static void do_update(struct wm_status *st)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ /* A window damage rectangle under the switcher panel would overwrite
|
|
|
+ * its pixels; repaint the panel after the window draw. */
|
|
|
+ if (sw_active && !sw_repaint) {
|
|
|
+ sw_geom();
|
|
|
+ for (dj = 0; dj < present.count; dj++) {
|
|
|
+ int rx = present.rect[dj].x;
|
|
|
+ int ry = present.rect[dj].y;
|
|
|
+
|
|
|
+ if (rx < sw_x + (int)sw_w &&
|
|
|
+ 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;
|
|
|
+ add_rect(&present, sw_x, sw_y, sw_w, sw_h);
|
|
|
+ need = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
if (dock_dirty || dock_overlap) {
|
|
|
dock_damage(&present);
|
|
|
dock_redraw = 1;
|
|
|
@@ -2451,6 +2825,11 @@ static void do_update(struct wm_status *st)
|
|
|
}
|
|
|
osd_visible = osd_show;
|
|
|
sm_draw();
|
|
|
+ if (sw_active)
|
|
|
+ sw_draw();
|
|
|
+ sw_visible = sw_active;
|
|
|
+ if (sw_active)
|
|
|
+ sw_add_present(&present);
|
|
|
|
|
|
for (i = 0; i < WM_MAX_WINDOWS; i++) {
|
|
|
struct uwin *u = &wins[i];
|