Files
chandra/compositor/host/overview.mbt
T
Claude 30f5e88639
CI / test (push) Successful in 1m35s
Overview (Exposé): every window side by side when the launcher opens, or alone on Super+W
Opening the launcher (Super tap or its panel button) now also shows every window of the
workspace scaled down beside it, over the dimmed wallpaper, like GNOME's Activities overview:
a natural layout (rows, one scale, aspect ratios kept, never enlarged), minimized windows
dimmed, windows gliding in and out over 220 ms. Hover lights a window and shows a close
button; click brings it forward and closes the overview and launcher; middle-click closes the
window; Escape or a click on empty space closes it. Typing in the launcher's search fades the
windows whose title and app id don't match.

- compositor/host/overview.mbt: layout, area beside the launcher, hit testing, easing,
  input and draw ops; previews reuse the Alt+Tab thumbnails (10 fps refresh, nothing redrawn
  once settled).
- New shortcut "overview" (Super+W) in the shortcut table, rebindable in Settings > Shortcuts.
- chandra-ctl / control socket: "shortcut ID" runs any shortcut by id.
- Both renderers keep only one large scaled copy per image (a gliding preview is drawn at a
  new size every frame) and draw images up to 4096 px.
- Tests: layout packing and aspect ratio, balance, hit testing, animation, Super tap + click,
  Super+W + Escape/empty click, search filter, middle click, inspector, control command;
  screenshots of 1/4/9 windows in dark and light.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hgo3PfGPY8wwv21ZZS
2026-11-26 00:24:16 +00:00

744 lines
25 KiB
MoonBit

///| Window overview (Exposé), like GNOME's Activities overview and Plasma's Present Windows.
///
/// Opening the launcher (a Super tap, or its panel button) also shows every window of the
/// active workspace side by side, scaled down with their aspect ratios kept, beside the launcher's
/// popup over the dimmed wallpaper; minimized windows are there too, dimmed. The "overview"
/// shortcut (Super+W by default) shows it alone. The windows glide from where they are into their
/// places (and back when it closes), in `overview_ms`.
///
/// Not while the Interface Explorer is inspecting.
///
/// Hovering a window lights it up and shows a close button on its corner. Clicking a window
/// brings it to the front (restoring it if minimized) and closes the overview and the launcher;
/// a middle click or the close button closes that window; Escape or a click on empty space closes
/// the overview (and the launcher). Typing in the launcher's search also filters the windows:
/// those whose title or app id don't match fade out.
///
/// The previews are the Alt+Tab switcher's (switcher.mbt: `switcher_thumb`), made only while
/// the overview is up and remade at most every `THUMB_REFRESH_MS` for windows that keep drawing.
/// Nothing is redrawn for the overview once it settles unless a window draws or the pointer
/// moves onto another window.
///| How long the overview takes to open or close, in ms.
pub let overview_ms : UInt64 = 220
///| Space kept free around the windows, and between them.
let overview_margin : Int = 32
///|
let overview_gap : Int = 24
///| Height of the title below each window.
let overview_label_h : Int = 30
///| Size of the close button shown on the hovered window's corner.
let overview_close_size : Int = 26
///| The overview while it is on screen (`ChandraCompositor.overview`).
pub(all) struct Overview {
/// Opened with the launcher (closes with it) or alone, by its shortcut.
mut with_launcher : Bool
/// Opening (true) or closing (false), and since when (monotonic ms).
mut opening : Bool
mut t0 : UInt64
/// The window under the pointer (0 for none) and whether the pointer is on its close button.
mut hover : UInt64
mut hover_close : Bool
/// The launcher's search text, as typed (it filters the windows).
mut query : String
}
///| How far along a transition of `ms` that started at `t0` is at `now`, 0.0 .. 1.0.
pub fn overview_progress(t0 : UInt64, now : UInt64, ms : UInt64) -> Double {
if now <= t0 || ms == 0UL {
return if now < t0 { 0.0 } else if ms == 0UL { 1.0 } else { 0.0 }
}
let p = (now - t0).to_double() / ms.to_double()
if p > 1.0 {
1.0
} else {
p
}
}
///| How open the overview looks at progress `p` (0 = windows where they are, 1 = in their
/// places): opening eases out (fast, then settling), closing eases in and out.
pub fn overview_openness(opening : Bool, p : Double) -> Double {
if opening {
let q = 1.0 - p
1.0 - q * q * q
} else {
let e = if p < 0.5 {
4.0 * p * p * p
} else {
let q = -2.0 * p + 2.0
1.0 - q * q * q / 2.0
}
1.0 - e
}
}
///| `a` moved `t` of the way to `b`.
pub fn lerp_rect(a : @scene.Rect, b : @scene.Rect, t : Double) -> @scene.Rect {
let f = fn(x : Int, y : Int) { x + ((y - x).to_double() * t).round().to_int() }
@scene.Rect::new(f(a.x, b.x), f(a.y, b.y), f(a.w, b.w), f(a.h, b.h))
}
///| Places for windows of sizes `sizes` (in that order) inside `area`: rows of windows, each
/// scaled by the same factor with its aspect ratio kept, rows and windows `gap` apart (rows
/// `row_gap`), centred. The number of rows that lets the windows be largest wins; windows are
/// never shown larger than they are.
pub fn overview_layout(
sizes : Array[(Int, Int)],
area : @scene.Rect,
gap : Int,
row_gap : Int,
) -> Array[@scene.Rect] {
let n = sizes.length()
if n == 0 || area.w <= 0 || area.h <= 0 {
return []
}
let ws = sizes.map(s => if s.0 < 1 { 1 } else { s.0 })
let hs = sizes.map(s => if s.1 < 1 { 1 } else { s.1 })
let mut best_rows : Array[Array[Int]] = []
let mut best_scale = -1.0
for nrows = 1; nrows <= n; nrows = nrows + 1 {
let rows = overview_rows(ws, nrows)
let s = overview_scale(rows, ws, hs, area, gap, row_gap)
// More rows only when it makes the windows noticeably larger.
if s > best_scale * 1.05 || best_scale < 0.0 {
best_scale = s
best_rows = rows
}
}
let s = if best_scale > 1.0 { 1.0 } else if best_scale <= 0.0 { 0.01 } else { best_scale }
let out = Array::make(n, @scene.Rect::new(0, 0, 0, 0))
let row_hs = best_rows.map(r => r.fold(init=0, (m, i) => if hs[i] > m { hs[i] } else { m }))
let total_h = row_hs.fold(init=0, (a, h) => a + scaled(h, s)) + row_gap * (best_rows.length() - 1)
let mut y = area.y + (area.h - total_h) / 2
for ri, row in best_rows {
let rh = scaled(row_hs[ri], s)
let rw = row.fold(init=0, (a, i) => a + scaled(ws[i], s)) + gap * (row.length() - 1)
let mut x = area.x + (area.w - rw) / 2
for i in row {
let w = scaled(ws[i], s)
let h = scaled(hs[i], s)
out[i] = @scene.Rect::new(x, y + (rh - h) / 2, w, h)
x = x + w + gap
}
y = y + rh + row_gap
}
out
}
///|
fn scaled(v : Int, s : Double) -> Int {
let r = (v.to_double() * s).to_int()
if r < 1 {
1
} else {
r
}
}
///| Windows (indexes, in order) split into `nrows` rows of about equal total width.
fn overview_rows(ws : Array[Int], nrows : Int) -> Array[Array[Int]] {
let total = ws.fold(init=0, (a, w) => a + w)
let target = total.to_double() / nrows.to_double()
let rows : Array[Array[Int]] = []
let mut cur : Array[Int] = []
let mut cur_w = 0
for i, w in ws {
let left = ws.length() - i // windows still to place, this one included
let rows_left = nrows - rows.length() - 1 // rows after the current one
// Start a new row when this window takes the row further past the target than it is
// short of it, as long as rows remain, and always when every remaining row needs a window.
let over = (cur_w + w).to_double() - target
let under = target - cur_w.to_double()
if cur.length() > 0 && rows_left > 0 && (over > under || left <= rows_left) {
rows.push(cur)
cur = []
cur_w = 0
}
cur.push(i)
cur_w = cur_w + w
}
if cur.length() > 0 {
rows.push(cur)
}
rows
}
///| The largest factor rows `rows` can be scaled by to fit in `area`.
fn overview_scale(
rows : Array[Array[Int]],
ws : Array[Int],
hs : Array[Int],
area : @scene.Rect,
gap : Int,
row_gap : Int,
) -> Double {
let mut s = 1000.0
let mut sum_h = 0
for row in rows {
let w = row.fold(init=0, (a, i) => a + ws[i])
let room = area.w - gap * (row.length() - 1)
let sw = room.to_double() / w.to_double()
if sw < s {
s = sw
}
sum_h = sum_h + row.fold(init=0, (m, i) => if hs[i] > m { hs[i] } else { m })
}
let room_h = area.h - row_gap * (rows.length() - 1)
let sh = room_h.to_double() / sum_h.to_double()
if sh < s {
s = sh
}
s
}
///| The largest part of `area` that `hole` leaves free: what is left of it, right of it, above
/// or below it (all of `area` when they don't overlap).
pub fn overview_area_beside(area : @scene.Rect, hole : @scene.Rect?) -> @scene.Rect {
let h = match hole {
Some(h) => h
None => return area
}
let ax1 = area.x + area.w
let ay1 = area.y + area.h
let hx1 = h.x + h.w
let hy1 = h.y + h.h
if h.w <= 0 || h.h <= 0 || hx1 <= area.x || h.x >= ax1 || hy1 <= area.y || h.y >= ay1 {
return area
}
let parts = [
@scene.Rect::new(area.x, area.y, h.x - area.x, area.h), // left
@scene.Rect::new(hx1, area.y, ax1 - hx1, area.h), // right
@scene.Rect::new(area.x, area.y, area.w, h.y - area.y), // above
@scene.Rect::new(area.x, hy1, area.w, ay1 - hy1), // below
]
let mut best = @scene.Rect::new(area.x, area.y, 0, 0)
for p in parts {
if p.w > 0 && p.h > 0 && p.w * p.h > best.w * best.h {
best = p
}
}
best
}
///| The index of the rect in `rects` containing (x, y), or -1 (the last one wins on overlap).
pub fn overview_hit(rects : Array[@scene.Rect], x : Int, y : Int) -> Int {
let mut i = rects.length() - 1
while i >= 0 {
let r = rects[i]
if x >= r.x && x < r.x + r.w && y >= r.y && y < r.y + r.h {
return i
}
i = i - 1
}
-1
}
///| The close button on a window shown at `r`: a square on its top-right corner.
pub fn overview_close_rect(r : @scene.Rect) -> @scene.Rect {
let s = overview_close_size
@scene.Rect::new(r.x + r.w - s * 2 / 3, r.y - s / 3, s, s)
}
///| True when the window's title or app id contains `query` (any case); everything matches an
/// empty query.
pub fn overview_matches(title : String, app_id : String, query : String) -> Bool {
let q = query.trim().to_string().to_lower()
q.length() == 0 || title.to_lower().contains(q) || app_id.to_lower().contains(q)
}
///| True while the overview is on screen (opening, open or closing).
pub fn ChandraCompositor::overview_shown(self : ChandraCompositor) -> Bool {
self.overview is Some(_)
}
///| True while the overview is open or opening (not on its way out).
pub fn ChandraCompositor::overview_open(self : ChandraCompositor) -> Bool {
match self.overview {
Some(o) => o.opening
None => false
}
}
///| True while the overview's windows are moving (the main loop keeps its frame pace).
fn ChandraCompositor::overview_animating(self : ChandraCompositor) -> Bool {
match self.overview {
Some(o) => overview_progress(o.t0, @sys.monotonic_ms(), overview_ms) < 1.0
None => false
}
}
///| Open the overview; `with_launcher` when the launcher opened it (it then closes with it).
pub fn ChandraCompositor::open_overview(self : ChandraCompositor, with_launcher : Bool) -> Unit {
match self.overview {
Some(o) => {
o.with_launcher = o.with_launcher || with_launcher
if !o.opening {
o.opening = true
o.t0 = turn_around(o.t0)
}
}
None => {
// Client menus would float over nothing: close them.
let mut i = self.popups.length() - 1
while i >= 0 {
self.server.popup_done(self.popups[i].id)
i = i - 1
}
self.leave_pointer()
self.overview = Some({
with_launcher,
opening: true,
t0: @sys.monotonic_ms(),
hover: 0UL,
hover_close: false,
query: "",
})
self.overview_hover_at(self.ptr_x.to_int(), self.ptr_y.to_int())
}
}
self.damage.mark_full()
}
///| A transition that started at `t0` turns around now: the new one starts as far along as the
/// old one still had to go.
fn turn_around(t0 : UInt64) -> UInt64 {
let now = @sys.monotonic_ms()
let p = overview_progress(t0, now, overview_ms)
let left = ((1.0 - p) * overview_ms.to_double()).to_uint64()
if now > left {
now - left
} else {
1UL
}
}
///| Close the overview (the windows glide back), and the launcher with it.
pub fn ChandraCompositor::close_overview(self : ChandraCompositor) -> Unit {
match self.overview {
Some(o) =>
if o.opening {
o.opening = false
o.t0 = turn_around(o.t0)
o.hover = 0UL
o.hover_close = false
self.damage.mark_full()
}
None => ()
}
if self.shell.launcher_open() {
self.shell.close_launcher()
}
}
///| The overview shortcut: open it alone, or close it.
pub fn ChandraCompositor::toggle_overview(self : ChandraCompositor) -> Unit {
if self.overview_open() {
self.close_overview()
} else {
self.open_overview(false)
}
}
///| Keep the overview in step with the launcher (opening it opens the overview; closing it, by
/// any means, closes the overview it opened) and drop it once it has finished closing.
fn ChandraCompositor::overview_sync(self : ChandraCompositor) -> Unit {
let launcher = self.shell.launcher_open()
if self.shell.inspecting() {
// The Interface Explorer looks at the launcher as it is; no overview over it.
if self.overview is Some(_) {
self.overview = None
self.damage.mark_full()
}
self.launcher_was_open = launcher
return
}
if launcher && !self.launcher_was_open {
self.open_overview(true)
} else if !launcher && self.launcher_was_open {
match self.overview {
Some(o) if o.with_launcher && o.opening => self.close_overview()
_ => ()
}
}
self.launcher_was_open = launcher
if self.switcher_on && self.overview is Some(_) {
self.overview = None // Alt+Tab takes over
self.damage.mark_full()
}
match self.overview {
Some(o) =>
if !o.opening && overview_progress(o.t0, @sys.monotonic_ms(), overview_ms) >= 1.0 {
self.overview = None
self.damage.mark_full()
}
None => ()
}
}
///| The windows the overview shows: those of the active workspace, visible ones in stacking order
/// (bottom to top), then minimized ones.
fn ChandraCompositor::overview_windows(self : ChandraCompositor) -> Array[UInt64] {
let out : Array[UInt64] = []
for id in self.wm.stacking_order() {
if self.windows.contains(id) {
out.push(id)
}
}
for id in self.switcher_candidates() {
if !out.contains(id) {
out.push(id)
}
}
out
}
///| Where the overview puts the windows: inside the work area, beside the launcher's popup.
fn ChandraCompositor::overview_area(self : ChandraCompositor) -> @scene.Rect {
let wa = self.work_area
let m = overview_margin
let area = @scene.Rect::new(wa.x + m, wa.y + m, wa.w - m * 2, wa.h - m * 2 - overview_label_h)
let hole = match self.shell.launcher_rect() {
Some(r) => Some(@scene.Rect::new(r.x - m, r.y - m, r.w + m * 2, r.h + m * 2))
None => None
}
let beside = overview_area_beside(area, hole)
// Too small a space beside the launcher: use the whole area (the launcher stays on top).
if beside.w < 160 || beside.h < 120 {
area
} else {
beside
}
}
///| One window in the overview: where it is on the desktop (`home`) and where the overview
/// puts it (`slot`).
struct OverviewItem {
id : UInt64
home : @scene.Rect
slot : @scene.Rect
minimized : Bool
}
///| The overview's windows and their places. Windows are laid out in the order they stand on
/// the desktop (top to bottom, left to right), so each lands near where it was.
fn ChandraCompositor::overview_items(self : ChandraCompositor) -> Array[OverviewItem] {
let ids = self.overview_windows()
let homes : Array[(UInt64, @scene.Rect, Bool)] = []
for id in ids {
match self.windows.get(id) {
Some(win) => {
let m = match self.wm.windows.get(id) {
Some(r) => r.minimized
None => false
}
homes.push((id, win.geometry, m))
}
None => ()
}
}
// Reading order of the window centres (minimized ones last).
let order = Array::makei(homes.length(), i => i)
order.sort_by((a, b) => {
let (_, ra, ma) = homes[a]
let (_, rb, mb) = homes[b]
if ma != mb {
return if ma { 1 } else { -1 }
}
let band = 160
let ya = (ra.y + ra.h / 2) / band
let yb = (rb.y + rb.h / 2) / band
if ya != yb {
ya - yb
} else {
ra.x + ra.w / 2 - (rb.x + rb.w / 2)
}
})
let sizes = overview_balance(order.map(i => (homes[i].1.w, homes[i].1.h)))
let slots = overview_layout(sizes, self.overview_area(), overview_gap, overview_gap + overview_label_h)
let by_index : Map[Int, @scene.Rect] = {}
for k, i in order {
by_index.set(i, slots[k])
}
// Minimized windows come out of (and go back to) the bottom middle of the screen.
let dock = @scene.Rect::new(self.output_w / 2 - 40, self.output_h - 40, 80, 40)
let items : Array[OverviewItem] = []
for i, h in homes {
let (id, r, m) = h
let slot = by_index.get(i).unwrap_or(r)
items.push({ id, home: if m { dock } else { r }, slot, minimized: m })
}
items
}
///| Where each window is shown in the overview once it has settled (for tests and tools).
pub fn ChandraCompositor::overview_places(self : ChandraCompositor) -> Array[(UInt64, @scene.Rect)] {
if self.overview is None {
return []
}
self.overview_items().map(it => (it.id, it.slot))
}
///| The window under the pointer in the overview (0 for none), and the search text it filters by.
pub fn ChandraCompositor::overview_hover(self : ChandraCompositor) -> (UInt64, String) {
match self.overview {
Some(o) => (o.hover, o.query)
None => (0UL, "")
}
}
///| Sizes to lay windows out by: windows less than half as tall as the tallest are counted as
/// half its height (aspect ratio kept), so a small dialog next to a maximized window isn't lost.
pub fn overview_balance(sizes : Array[(Int, Int)]) -> Array[(Int, Int)] {
let max_h = sizes.fold(init=0, (m, s) => if s.1 > m { s.1 } else { m })
sizes.map(s => {
let (w, h) = s
if h > 0 && h * 2 < max_h {
(w * max_h / (h * 2), max_h / 2)
} else {
(w, h)
}
})
}
///| The window shown at (x, y) in the open overview (0 for none) and whether (x, y) is on its
/// close button.
fn ChandraCompositor::overview_target(self : ChandraCompositor, x : Int, y : Int) -> (UInt64, Bool) {
let o = match self.overview {
Some(o) if o.opening => o
_ => return (0UL, false)
}
if self.shell.hit(x, y) {
return (0UL, false)
}
let items = self.overview_items()
// The hovered window's close button sticks out of its corner.
for it in items {
if it.id == o.hover && inside_rect(overview_close_rect(it.slot), x, y) {
return (it.id, true)
}
}
let i = overview_hit(items.map(it => it.slot), x, y)
if i < 0 {
(0UL, false)
} else {
(items[i].id, false)
}
}
///| `w`x`h` scaled (up or down) to fit `box_w`x`box_h` with its aspect ratio kept.
pub fn fit_within(w : Int, h : Int, box_w : Int, box_h : Int) -> (Int, Int) {
if w <= 0 || h <= 0 || box_w <= 0 || box_h <= 0 {
return (0, 0)
}
if w * box_h >= h * box_w {
let fh = h * box_w / w
(box_w, if fh < 1 { 1 } else { fh })
} else {
let fw = w * box_h / h
(if fw < 1 { 1 } else { fw }, box_h)
}
}
///|
fn inside_rect(r : @scene.Rect, x : Int, y : Int) -> Bool {
x >= r.x && x < r.x + r.w && y >= r.y && y < r.y + r.h
}
///| Track the window under the pointer.
fn ChandraCompositor::overview_hover_at(self : ChandraCompositor, x : Int, y : Int) -> Unit {
let (id, close) = self.overview_target(x, y)
match self.overview {
Some(o) =>
if o.hover != id || o.hover_close != close {
o.hover = id
o.hover_close = close
self.damage.mark_full()
}
None => ()
}
}
///| Pointer motion while the overview is up: hover its windows (the shell still sees motion over
/// the panel and the launcher). True when the overview took it (windows don't see it).
fn ChandraCompositor::overview_motion(self : ChandraCompositor, x : Int, y : Int) -> Bool {
self.overview_sync()
if self.overview is None {
return false
}
ignore(self.shell.pointer_move(x, y))
self.leave_pointer()
self.overview_hover_at(x, y)
true
}
///| A button while the overview is up. Presses over the panel or the launcher go to the shell;
/// elsewhere: left on a window picks it, middle on it (or left on its close button) closes it,
/// anything on empty space closes the overview. True when the event was used here.
fn ChandraCompositor::overview_button(self : ChandraCompositor, button : UInt, pressed : Bool, x : Int, y : Int) -> Bool {
self.overview_sync()
if self.overview is None {
return false
}
// Releases, and presses on the panel or the launcher, take the usual way (the launcher's
// right-click menu, the panel's buttons); what they open or close is picked up next frame.
if !pressed || self.shell.hit(x, y) {
return false
}
if !self.overview_open() {
return true // on its way out
}
let (id, close) = self.overview_target(x, y)
if id == 0UL {
self.close_overview()
} else if button == 274U || (button == 272U && close) {
self.window_command(id, @shell.WindowCommand::Close)
} else if button == 272U {
self.activate_task(id)
self.close_overview()
}
self.overview_sync()
true
}
///| A key while the overview is up. With the launcher, keys go on to its search (the search
/// text is followed here to filter the windows); alone, Escape closes it, Enter picks the window
/// under the pointer, and no key reaches a client. True when the key was used here.
fn ChandraCompositor::overview_key(self : ChandraCompositor, code : UInt, pressed : Bool) -> Bool {
self.overview_sync()
let o = match self.overview {
Some(o) => o
None => return false
}
if o.with_launcher && self.shell.launcher_open() {
if pressed {
let name = key_name(code, (self.mods & 1U) != 0U)
if name == "Backspace" {
if o.query.length() > 0 {
o.query = o.query[:o.query.length() - 1].to_string()
}
} else if name == "Escape" || name == "Enter" {
o.query = ""
} else if name.length() == 1 {
o.query = o.query + name
}
self.damage.mark_full()
}
return false // the launcher gets it
}
if pressed && o.opening {
if code == key_esc {
self.close_overview()
} else if code == 28U && o.hover != 0UL {
self.activate_task(o.hover)
self.close_overview()
}
}
true
}
///| The overview's draw ops (under the panel and the launcher): the wallpaper dimmed, then each
/// window's preview gliding between its place on the desktop and its place in the overview,
/// with its icon and title, the hovered one lit with a close button.
fn ChandraCompositor::overview_ops(self : ChandraCompositor) -> Array[@scene.DrawOp] {
let ops : Array[@scene.DrawOp] = []
let o = match self.overview {
Some(o) => o
None => return ops
}
let p = self.theme.palette
let fs = self.theme.font_size
let now = @sys.monotonic_ms()
let t = overview_openness(o.opening, overview_progress(o.t0, now, overview_ms))
let settled = t >= 1.0
ops.push(
@scene.DrawOp::FillRect(
@scene.Rect::new(0, 0, self.output_w, self.output_h),
@scene.Rgba::new(0, 0, 0, (t * 140.0).to_int()),
0,
),
)
for it in self.overview_items() {
let win = match self.windows.get(it.id) {
Some(w) => w
None => continue
}
let title = if win.title.length() > 0 { win.title } else { win.app_id }
let matches = overview_matches(win.title, win.app_id, o.query)
let r = lerp_rect(it.home, it.slot, t)
if r.w <= 0 || r.h <= 0 {
continue
}
// Previews are made at most 960 px a side (both hosts' limit is 1024) and stretched past it.
let (thumb, tw, th) = self.switcher_thumb(
it.id,
if it.slot.w > 960 { 960 } else { it.slot.w },
if it.slot.h > 960 { 960 } else { it.slot.h },
)
let hovered = settled && o.hover == it.id && matches
if hovered {
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(r.x - 5, r.y - 5, r.w + 10, r.h + 10), p.accent, self.theme.radius + 4))
}
if thumb != 0U {
// The preview is made at the slot's size; while gliding it is stretched to `r`.
let ir = if settled {
let (fw, fh) = fit_within(tw, th, r.w, r.h)
@scene.Rect::new(r.x + (r.w - fw) / 2, r.y + (r.h - fh) / 2, fw, fh)
} else {
r
}
ops.push(@scene.DrawOp::Image(ir, thumb))
} else {
ops.push(@scene.DrawOp::FillRect(r, p.surface, self.theme.radius))
}
ops.push(@scene.DrawOp::StrokeRect(r, p.border, 1, 0))
if it.minimized {
ops.push(@scene.DrawOp::FillRect(r, @scene.Rgba::new(0, 0, 0, 120), 0))
}
if !matches {
// Filtered out by the search: faded.
ops.push(@scene.DrawOp::FillRect(r, @scene.Rgba::new(0, 0, 0, 170), 0))
}
if !settled {
continue
}
// The app icon on the bottom edge, the title below.
let icon = self.shell.window_icon(win.app_id)
let isz = if r.h / 3 < 40 { r.h / 3 } else { 40 }
if icon != 0U && isz >= 12 && matches {
ops.push(@scene.DrawOp::Image(@scene.Rect::new(r.x + (r.w - isz) / 2, r.y + r.h - isz * 3 / 4, isz, isz), icon))
}
if it.minimized && matches {
ops.push(@scene.DrawOp::Text(r.x + r.w / 2, r.y + r.h / 2, "minimized", fs - 1, @scene.Rgba::new(255, 255, 255, 230), @scene.TextAlign::Center, true))
}
let cw = (fs * 11 + 19) / 20
let max_chars = (if r.w + 40 > 120 { r.w + 40 } else { 120 }) / cw
let shown = if title.length() > max_chars && max_chars > 1 { title[:max_chars - 1].to_string() + "…" } else { title }
let lw = shown.length() * cw + 20
let ly = r.y + r.h + 12 + (overview_label_h - 12) / 2
let lrect = @scene.Rect::new(r.x + (r.w - lw) / 2, ly - 11, lw, 22)
if matches {
ops.push(@scene.DrawOp::FillRect(lrect, if hovered { p.accent } else { p.surface_popup }, 11))
ops.push(@scene.DrawOp::Text(r.x + r.w / 2, ly, shown, fs, if hovered { p.accent_foreground } else { p.foreground }, @scene.TextAlign::Center, hovered))
}
if hovered {
let c = overview_close_rect(r)
let lit = o.hover_close
ops.push(@scene.DrawOp::Circle(c.x + c.w / 2, c.y + c.h / 2, c.w / 2, if lit { @scene.Rgba::new(220, 60, 60, 255) } else { p.surface_popup }, true))
ops.push(@scene.DrawOp::Circle(c.x + c.w / 2, c.y + c.h / 2, c.w / 2, p.border, false))
let cx = c.x + c.w / 2
let cy = c.y + c.h / 2
let d = c.w / 5
let fg = if lit { @scene.Rgba::new(255, 255, 255, 255) } else { p.foreground }
ops.push(@scene.DrawOp::Line(cx - d, cy - d, cx + d, cy + d, fg, 2))
ops.push(@scene.DrawOp::Line(cx - d, cy + d, cx + d, cy - d, fg, 2))
}
}
ops
}