Skip to content

armgit / WacOS

Public Imported from GitHub
0

A new style desktop shell for Windows 11: menu bar, Dock, Finder, Spotlight, Control Center and Liquid Glass, in native C++.

Rust
25.4 KB
Raw Blame
// macjanela.cpp, parte 2: recorte arredondado, ampliar animado, encaixe e prévia, tamanho grande demais, cliques no
// grupo movido da barra própria e arrastar a janela.

pub fn apply_region(i: &mut Info) {
    let h = i.owner;
    unsafe {
        // barra própria (Chromium/Electron): nunca recorta (a região não corta o conteúdo da GPU e desligava o quadro do
        // DWM). Os cantos são os do DWM (modo leve).
        if i.custom {
            if i.rgn.cx != 0 {
                i.rgn = SIZE::default();
                let _ = SetWindowRgn(h, None, true);
                let on = DWMNCRP_USEWINDOWSTYLE;
                let _ = DwmSetWindowAttribute(h, DWMWA_NCRENDERING_POLICY, &on as *const _ as *const _, 4);
            }
            return;
        }
        if zoomed(h) || iconic(h) || fullscreen(h) {
            // maximizada de verdade ou tela cheia: sem cantos
            if i.rgn.cx != 0 {
                i.rgn = SIZE::default();
                let _ = SetWindowRgn(h, None, true);
                let on = DWMNCRP_USEWINDOWSTYLE;
                let _ = DwmSetWindowAttribute(h, DWMWA_NCRENDERING_POLICY, &on as *const _ as *const _, 4);
                let round = 2u32;
                let _ = DwmSetWindowAttribute(h, DWMWINDOWATTRIBUTE(33), &round as *const _ as *const _, 4);
                apply_colors(i); // borda fina de volta
            }
            if fullscreen(h) {
                // tela cheia (vídeo, jogo): nem o arredondamento nem a borda colorida ficam por cima (issue #101). Quem
                // ia do maximizado para a tela cheia (F11) herdava os dois do estado maximizado, porque o recorte já
                // tinha saído e o bloco de cima não rodava de novo.
                let square = 1u32; // DWMWCP_DONOTROUND
                let _ = DwmSetWindowAttribute(h, DWMWINDOWATTRIBUTE(33), &square as *const _ as *const _, 4);
                apply_colors(i); // com fullscreen() verdadeiro, ele grava a borda DWMWA_COLOR_NONE
            }
            return;
        }
        let wr = win_rect(h);
        let sz = SIZE { cx: wr.right - wr.left, cy: wr.bottom - wr.top };
        if sz.cx == i.rgn.cx && sz.cy == i.rgn.cy {
            return;
        }
        let (l, t, rr_, b) = insets(i);
        let r = corner_radius(h); // por dentro do arco: a borda suavizada (update_corners) cobre o que sobra
        i.rgn = sz;
        // a borda fina e o arredondamento do Windows seriam desenhados no tamanho antigo, em volta do recorte
        let none = 0xFFFF_FFFEu32; // DWMWA_COLOR_NONE
        let _ = DwmSetWindowAttribute(h, DWMWINDOWATTRIBUTE(34), &none as *const _ as *const _, 4);
        let square = 1u32; // DWMWCP_DONOTROUND
        let _ = DwmSetWindowAttribute(h, DWMWINDOWATTRIBUTE(33), &square as *const _ as *const _, 4);
        // sem o quadro do DWM: senão ele ainda desenhava a sombra/fundo do retângulo inteiro da janela
        let off = DWMNCRP_DISABLED;
        let _ = DwmSetWindowAttribute(h, DWMWA_NCRENDERING_POLICY, &off as *const _ as *const _, 4);
        let _ = SetWindowRgn(h, round_rgn(l, t, sz.cx - rr_, sz.cy - b, r), true);
    }
    paint_nc(i);
}
pub fn zoom_rect(i: &mut Info) -> RECT {
    let h = i.owner;
    let mut mi = MONITORINFO { cbSize: std::mem::size_of::<MONITORINFO>() as u32, ..Default::default() };
    unsafe {
        let _ = GetMonitorInfoW(MonitorFromWindow(h, MONITOR_DEFAULTTONEAREST), &mut mi);
    }
    // bordas invisíveis de redimensionar: ficam para fora da área, como numa janela maximizada
    let (l, t, rr_, b) = insets(i);
    let wa = mi.rcWork;
    RECT { left: wa.left - l, top: wa.top - t, right: wa.right + rr_, bottom: wa.bottom + b }
}
/// encaixe (sem o botão de maximizar o Windows não encaixa sozinho): mouse na borda esquerda/direita = metade da tela;
/// num canto = um quarto; no topo = ampliar. 0: nada, 1: encaixar em t, 2: ampliar
pub fn snap_target(i: &Info) -> (i32, RECT) {
    let h = i.owner;
    if i.style as u32 & WS_THICKFRAME.0 == 0 {
        return (0, RECT::default());
    }
    unsafe {
        let mut c = POINT::default();
        let _ = GetCursorPos(&mut c);
        let mut mi = MONITORINFO { cbSize: std::mem::size_of::<MONITORINFO>() as u32, ..Default::default() };
        if !GetMonitorInfoW(MonitorFromPoint(c, MONITOR_DEFAULTTONEAREST), &mut mi).as_bool() {
            return (0, RECT::default());
        }
        let (m, wa) = (mi.rcMonitor, mi.rcWork);
        let (e, q) = ((4.0 * scale(h)) as i32, (60.0 * scale(h)) as i32);
        // topo: a janela para na barra de menus, então o gesto vale já com o mouse dentro da barra
        let (l, r, t) = (c.x <= m.left + e, c.x >= m.right - 1 - e, c.y <= (m.top + e).max(wa.top));
        let (mx, my) = ((wa.left + wa.right) / 2, (wa.top + wa.bottom) / 2);
        if l || r {
            let mut rr_ = if l { RECT { left: wa.left, top: wa.top, right: mx, bottom: wa.bottom } } else { RECT { left: mx, top: wa.top, right: wa.right, bottom: wa.bottom } };
            if c.y <= wa.top + q {
                rr_.bottom = my;
            } else if c.y >= wa.bottom - q {
                rr_.top = my;
            }
            return (1, rr_);
        }
        if t && i.style as u32 & WS_MAXIMIZEBOX.0 != 0 {
            return (2, wa);
        }
    }
    (0, RECT::default())
}
pub fn hide_preview(i: &mut Info) {
    if !i.preview.0.is_null() {
        unsafe {
            let _ = ShowWindow(i.preview, SW_HIDE);
        }
    }
    i.preview_for = RECT::default();
}
fn registra_canto() {
    unsafe {
        let mut wc = WNDCLASSW::default();
        if GetClassInfoW(g_mod(), w!("MacJanelaCanto"), &mut wc).is_err() {
            RegisterClassW(&WNDCLASSW { lpfnWndProc: Some(corner_proc), hInstance: g_mod(), lpszClassName: w!("MacJanelaCanto"), ..Default::default() });
        }
    }
}
/// prévia do Mac: retângulo arredondado translúcido, com borda clara, atrás da janela arrastada
pub fn show_preview(i: &mut Info, mut t: RECT) {
    let sc = scale(i.owner);
    let g = (6.0 * sc) as i32;
    t = RECT { left: t.left + g, top: t.top + g, right: t.right - g, bottom: t.bottom - g };
    if t == i.preview_for && visible(i.preview) {
        return;
    }
    i.preview_for = t;
    unsafe {
        if i.preview.0.is_null() {
            registra_canto();
            i.preview = CreateWindowExW(WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE, w!("MacJanelaCanto"), w!(""), WS_POPUP, 0, 0, 1, 1, None, None, g_mod(), None).unwrap_or_default();
            if i.preview.0.is_null() {
                return;
            }
        }
        let (ww, hh) = (t.right - t.left, t.bottom - t.top);
        if ww <= 0 || hh <= 0 {
            return;
        }
        let mem = CreateCompatibleDC(None);
        let bi = BITMAPINFO { bmiHeader: BITMAPINFOHEADER { biSize: std::mem::size_of::<BITMAPINFOHEADER>() as u32, biWidth: ww, biHeight: -hh, biPlanes: 1, biBitCount: 32, ..Default::default() }, ..Default::default() };
        let mut bits: *mut core::ffi::c_void = std::ptr::null_mut();
        let Ok(bmp) = CreateDIBSection(None, &bi, DIB_RGB_COLORS, &mut bits, None, 0) else {
            let _ = DeleteDC(mem);
            return;
        };
        let px = std::slice::from_raw_parts_mut(bits as *mut u32, (ww * hh) as usize);
        let (r, hw, hh2) = (12.0 * sc, ww as f32 / 2.0, hh as f32 / 2.0);
        let perfil = perfil_para(r, hw, hh2);
        let cov = |d: f32| (0.5 - d).clamp(0.0, 1.0);
        const FILL_A: f32 = 0.22;
        const LINE_A: f32 = 0.55;
        for y in 0..hh {
            for x in 0..ww {
                let (d, _, _) = sq_sdf(x as f32 + 0.5 - hw, y as f32 + 0.5 - hh2, hw, hh2, perfil.as_ref()); // o mesmo canto das janelas
                let inside = cov(d);
                let ln = inside - cov(d + 1.0);
                let a = (inside - ln) * FILL_A + ln * LINE_A; // branco pré-multiplicado
                let v = (a * 255.0).round() as u32;
                px[(y * ww + x) as usize] = v << 24 | v << 16 | v << 8 | v;
            }
        }
        let old = SelectObject(mem, bmp);
        let (pos, zero, size) = (POINT { x: t.left, y: t.top }, POINT { x: 0, y: 0 }, SIZE { cx: ww, cy: hh });
        let bf = BLENDFUNCTION { BlendOp: 0, BlendFlags: 0, SourceConstantAlpha: 255, AlphaFormat: 1 };
        let _ = UpdateLayeredWindow(i.preview, None, Some(&pos), Some(&size), mem, Some(&zero), COLORREF(0), Some(&bf), ULW_ALPHA);
        SelectObject(mem, old);
        let _ = DeleteObject(bmp);
        let _ = DeleteDC(mem);
        let _ = SetWindowPos(i.preview, i.owner, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW); // logo atrás
    }
}
/// janela cobrindo o monitor inteiro com barra de título (o Ableton guarda esse tamanho como "normal"): vai para o
/// tamanho normal, 3/4 da tela no meio. Ampliar fica com o botão verde.
pub fn fix_oversize(i: &mut Info) {
    let h = i.owner;
    if i.custom || i.zoomed || i.moving || zoomed(h) || iconic(h) {
        return;
    }
    let st = i.style as u32;
    if st & WS_THICKFRAME.0 == 0 || st & WS_MAXIMIZEBOX.0 == 0 {
        return;
    }
    let wr = win_rect(h);
    let (l, t, r, b) = insets(i);
    let mut mi = MONITORINFO { cbSize: std::mem::size_of::<MONITORINFO>() as u32, ..Default::default() };
    unsafe {
        if !GetMonitorInfoW(MonitorFromWindow(h, MONITOR_DEFAULTTONEAREST), &mut mi).as_bool() {
            return;
        }
    }
    // quase toda a área de trabalho (95%) e, além disso, maior que ela ou recém-aberta (10 s)
    let wa = mi.rcWork;
    let (vw, vh) = ((wr.right - r) - (wr.left + l), (wr.bottom - b) - (wr.top + t));
    let (aw, ah) = (wa.right - wa.left, wa.bottom - wa.top);
    let nearly = vw >= aw * 95 / 100 && vh >= ah * 95 / 100;
    let bigger = vw > aw || vh > ah;
    if !nearly || !(bigger || tick().wrapping_sub(i.attached_at) < 10000) {
        return;
    }
    let (w_, hh) = (aw * 3 / 4, ah * 3 / 4);
    let (x, y) = (wa.left + (aw - w_) / 2, wa.top + (ah - hh) / 2);
    i.before = RECT { left: x - l, top: y - t, right: x + w_ + r, bottom: y + hh + b };
    unsafe {
        let _ = SetWindowPos(h, None, i.before.left, i.before.top, i.before.right - i.before.left, i.before.bottom - i.before.top, SWP_NOZORDER | SWP_NOACTIVATE);
    }
}
// ---- "Ampliar" animado (como o zoom do Mac), com foto: o Shell mostra a foto de agora parada por cima; a janela de
// verdade muda de tamanho escondida (cloak, só vale para janelas do próprio processo, por isso aqui na DLL) e se
// redesenha; ~100 ms depois o Shell tira a foto já no layout novo e anima só ela; no fim ele avisa ("MacJanelaMostrar")
pub const ZOOM_TIMER: usize = 0x4D4A;
pub fn info_subclass(h: HWND) -> Option<&'static mut Info> {
    let mut r = 0usize;
    unsafe {
        if GetWindowSubclass(h, Some(owner_proc), SUBCLASS_ID, Some(&mut r)).as_bool() && r != 0 {
            return Some(&mut *(r as *mut Info));
        }
    }
    None
}
/// a janela aparece de novo (fim da animação, ou segurança)
pub fn zoom_show(h: HWND) {
    unsafe {
        let _ = KillTimer(h, ZOOM_TIMER);
        let mut i = info_subclass(h);
        // a barra (pintada por nós) pode não ter sido pintada enquanto a janela estava escondida: pinta antes e depois
        if let Some(i) = i.as_mut() {
            apply_colors(i);
            paint_nc(i);
        }
        let _ = RedrawWindow(h, None, None, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW);
        // a faixa (por cima dos botões do Windows do app) volta ANTES de a janela aparecer, já no tamanho novo, e
        // espera um quadro da tela; antes ela voltava depois e os botões do Windows piscavam (PR #263)
        if let Some(i) = i.as_mut() {
            if i.transit && i.custom && i.filho {
                i.transit = false;
                place_overlay(i);
                let _ = DwmFlush();
                i.transit = true;
            }
        }
        let off: i32 = 0;
        let _ = DwmSetWindowAttribute(h, DWMWA_CLOAK, &off as *const _ as *const _, 4);
        if let Some(i) = i.as_mut() {
            paint_nc(i);
        }
        let _ = RedrawWindow(h, None, None, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW);
        if let Some(i) = i {
            i.color_freeze_until = tick().wrapping_add(600);
            // avisa o Shell: a janela já está na tela, a foto pode sumir
            if let Some(s) = find_window("ShellMensagens") {
                let _ = PostMessageW(s, reg_msg("ShellAmpliarPronto"), WPARAM(h.0 as usize), LPARAM(0));
            }
            if i.transit {
                i.transit = false;
                place_overlay(i);
                update_shadow(i);
            }
        } else if let Some(s) = find_window("ShellMensagens") {
            let _ = PostMessageW(s, reg_msg("ShellAmpliarPronto"), WPARAM(h.0 as usize), LPARAM(0));
        }
    }
}
/// o Shell não avisou: não fica escondida
unsafe extern "system" fn zoom_safety(h: HWND, _: u32, _: usize, _: u32) {
    // pânico aqui não pode derrubar o programa onde a DLL está (vira o valor neutro)
    crate::guarda((), || {
        zoom_show(h);
    })
}
unsafe extern "system" fn zoom_photo(w_: HWND, _: u32, id: usize, _: u32) {
    // pânico aqui não pode derrubar o programa onde a DLL está (vira o valor neutro)
    crate::guarda((), || {
        let _ = KillTimer(w_, id);
        if let Some(s) = find_window("ShellMensagens") {
            let _ = PostMessageW(s, reg_msg("ShellAmpliarFoto"), WPARAM(w_.0 as usize), LPARAM(0));
        }
    })
}
/// janela do Qt (OBS Studio, DaVinci): a prévia desenhada pela placa de vídeo não se redesenha escondida; o Shell usa o
/// caminho dos apps que não desenham escondidos (flags 4)
pub fn qt_window(h: HWND) -> bool {
    let c = class_name(h);
    c.starts_with("Qt") && c.contains("QWindow")
}
pub fn move_animated(i: &mut Info, z: RECT) {
    let h = i.owner;
    let (l, t, rr_, b) = insets(i);
    let wr = win_rect(h);
    let mut from = RECT { left: wr.left + l, top: wr.top + t, right: wr.right - rr_, bottom: wr.bottom - b };
    unsafe {
        let mut bx = RECT::default();
        if GetWindowRgnBox(h, &mut bx) != GDI_REGION_TYPE(0) && bx.right > bx.left {
            from = RECT { left: wr.left + bx.left, top: wr.top + bx.top, right: wr.left + bx.right, bottom: wr.top + bx.bottom };
        }
        let to = RECT { left: z.left + (from.left - wr.left), top: z.top + (from.top - wr.top), right: z.right - (wr.right - from.right), bottom: z.bottom - (wr.bottom - from.bottom) };
        // a cor da barra vai junto: a foto às vezes sai com a barra sem pintar (preta)
        #[repr(C)]
        struct Msg {
            hwnd: u64,
            from: RECT,
            to: RECT,
            flags: i32,
            cap: u32,
        }
        let flags = (if i.custom {
            0
        } else if i.tool {
            3
        } else {
            1
        }) | if qt_window(h) { 4 } else { 0 };
        let cap = if i.cap == CLR_INVALID {
            if i.dark {
                rgb(0x2D, 0x2D, 0x2F)
            } else {
                rgb(0xE9, 0xE9, 0xEA)
            }
        } else {
            i.cap
        };
        let msg = Msg { hwnd: h.0 as usize as u64, from, to, flags, cap };
        let cd = COPYDATASTRUCT { dwData: 0x414D504C, cbData: std::mem::size_of::<Msg>() as u32, lpData: &msg as *const _ as *mut _ }; // 'AMPL'
        let mut ok = 0usize;
        let anim = match find_window("ShellMensagens") {
            Some(sh) if visible(h) && !iconic(h) && !i.transit => SendMessageTimeoutW(sh, WM_COPYDATA, WPARAM(h.0 as usize), LPARAM(&cd as *const _ as isize), SMTO_ABORTIFHUNG, 400, Some(&mut ok)).0 != 0 && ok != 0,
            _ => false,
        };
        if anim {
            // a foto já está na tela, por cima: esconde a janela e o que vai em volta dela
            i.transit = true;
            let on: i32 = 1;
            let _ = DwmSetWindowAttribute(h, DWMWA_CLOAK, &on as *const _ as *const _, 4);
            for x in [i.overlay, i.minis, i.shadow.wnd] {
                if !x.0.is_null() {
                    let _ = ShowWindow(x, SW_HIDE);
                }
            }
            hide_corners(i);
            SetTimer(h, ZOOM_TIMER, 1500, Some(zoom_safety));
        }
        let _ = SetWindowPos(h, None, z.left, z.top, z.right - z.left, z.bottom - z.top, SWP_NOZORDER | SWP_NOACTIVATE);
        if anim {
            // o app redesenha no tamanho novo (escondido): o Shell tira a foto já com o layout novo
            let _ = UpdateWindow(h);
            SetTimer(h, ZOOM_TIMER + 1, 50, Some(zoom_photo));
        }
    }
}
pub fn toggle_zoom(i: &mut Info) {
    let h = i.owner;
    unsafe {
        if i.zoomed {
            i.zoomed = false;
            let _ = RemovePropW(h, w!("MacJanelaAmpliada"));
            let mut b = i.before;
            // nunca com o topo atrás da barra de menus (uma posição antiga já gravada assim continuava voltando para lá)
            let mut mi = MONITORINFO { cbSize: std::mem::size_of::<MONITORINFO>() as u32, ..Default::default() };
            if GetMonitorInfoW(MonitorFromRect(&b, MONITOR_DEFAULTTONEAREST), &mut mi).as_bool() && b.top < mi.rcWork.top && b.bottom - b.top <= mi.rcWork.bottom - mi.rcWork.top + 64 {
                let dy = mi.rcWork.top - b.top;
                b.top += dy;
                b.bottom += dy;
                i.before = b;
            }
            move_animated(i, b);
            return;
        }
        // barra própria (Chrome, Electron): as bordas invisíveis lidas AGORA, ainda maximizada. Logo depois do SW_RESTORE
        // o DWM ainda devolve a moldura da janela maximizada e a borda de cima saía com a altura da barra de menus: a
        // janela ampliada ia para y=0, atrás da barra, e o Windows gravava isso como a posição normal (Claude, teste ao
        // vivo de 27/11/2026). Em cima, sem a barra do Windows, a borda é 0.
        let bordas_antes = if zoomed(h) && i.custom { Some(insets(i)) } else { None };
        if zoomed(h) {
            // maximizada pelo Windows/pelo app: vira "ampliada" (o tamanho normal guardado é o de antes)
            let mut wp = WINDOWPLACEMENT { length: std::mem::size_of::<WINDOWPLACEMENT>() as u32, ..Default::default() };
            let _ = GetWindowPlacement(h, &mut wp);
            i.before = wp.rcNormalPosition;
            let mut mi = MONITORINFO { cbSize: std::mem::size_of::<MONITORINFO>() as u32, ..Default::default() };
            if get_ex(h) as u32 & WS_EX_TOOLWINDOW.0 == 0 && GetMonitorInfoW(MonitorFromWindow(h, MONITOR_DEFAULTTONEAREST), &mut mi).as_bool() {
                let (dx, dy) = (mi.rcWork.left - mi.rcMonitor.left, mi.rcWork.top - mi.rcMonitor.top);
                i.before = RECT { left: i.before.left + dx, top: i.before.top + dy, right: i.before.right + dx, bottom: i.before.bottom + dy };
            }
            let _ = ShowWindow(h, SW_RESTORE);
        } else {
            i.before = win_rect(h);
        }
        let mut z = zoom_rect(i);
        if let Some((l, _, r, b)) = bordas_antes {
            let mut mi = MONITORINFO { cbSize: std::mem::size_of::<MONITORINFO>() as u32, ..Default::default() };
            if GetMonitorInfoW(MonitorFromWindow(h, MONITOR_DEFAULTTONEAREST), &mut mi).as_bool() {
                let wa = mi.rcWork;
                z = RECT { left: wa.left - l, top: wa.top, right: wa.right + r, bottom: wa.bottom + b };
            }
        }
        i.zoomed = true;
        let _ = SetPropW(h, w!("MacJanelaAmpliada"), HANDLE(1 as *mut _)); // o Shell sabe que Win+↓ deve desfazer
        move_animated(i, z);
    }
}
/// o ponto da faixa (px) está no grupo movido (1), no ˅ levado para a direita (2) ou no grupo da direita (3)? devolve o
/// tipo e o ponto de verdade (tela)
pub fn alvo_movido(i: &mut Info, p: POINT) -> (i32, POINT) {
    let r = bar_rect(i);
    let f = frame_rect(i.owner);
    let s = POINT { x: r.left + p.x, y: r.top + p.y }; // tela
    if i.chunk_w != 0 {
        let x0 = f.left + i.chunk_dst;
        if s.x >= x0 && s.x < x0 + i.chunk_w && s.y >= f.top + i.chunk_top && s.y < f.top + i.chunk_top + i.chunk_h {
            return (1, POINT { x: s.x - i.chunk_dst + i.chunk_src, y: s.y });
        }
    }
    if i.gr_w != 0 {
        // o grupo levado para a borda direita
        let m = (10.0 * scale(i.owner)).round() as i32;
        let x0 = r.right - m - i.gr_w;
        if s.x >= x0 && s.x < r.right - m && s.y >= f.top + i.gr_top && s.y < f.top + i.gr_top + i.gr_h {
            return (3, POINT { x: f.left + i.gr_src + (s.x - x0), y: s.y });
        }
    }
    if i.seta_w != 0 {
        let m = (8.0 * scale(i.owner)).round() as i32;
        let x0 = r.right - m - i.seta_w;
        if s.x >= x0 && s.x < r.right - m && s.y >= f.top + i.seta_y && s.y < f.top + i.seta_y + i.seta_h {
            return (2, POINT { x: f.left + i.seta_x + (s.x - x0), y: s.y });
        }
    }
    (0, POINT::default())
}
/// o menu que o Chrome abre embaixo do ˅ nasce onde o botão de verdade está: por até 1,6 s depois do clique, a janela
/// dele é levada para baixo do ˅ da direita, alinhada pela direita, como no Chrome do Mac
pub fn levar_menu_da_seta(i: &mut Info) -> bool {
    let r = bar_rect(i);
    let sc = scale(i.owner);
    struct F {
        owner: HWND,
        ov: HWND,
        achou: HWND,
        faixa: RECT,
        sc: f32,
    }
    unsafe extern "system" fn cb(w_: HWND, l: LPARAM) -> BOOL {
        // pânico aqui não pode derrubar o programa onde a DLL está (vira o valor neutro)
        crate::guarda(FALSE, || {
            let f = &mut *(l.0 as *mut F);
            if w_ == f.owner || w_ == f.ov || !IsWindowVisible(w_).as_bool() {
                return TRUE;
            }
            let mut p = 0u32;
            GetWindowThreadProcessId(w_, Some(&mut p));
            if p != GetCurrentProcessId() || get_style(w_) as u32 & WS_POPUP.0 == 0 {
                return TRUE;
            }
            if class_name(w_).starts_with("MacJanela") {
                return TRUE;
            }
            let q = win_rect(w_);
            let (ww, hh) = (q.right - q.left, q.bottom - q.top);
            if ww < (180.0 * f.sc) as i32 || ww > (560.0 * f.sc) as i32 || hh < (60.0 * f.sc) as i32 {
                return TRUE;
            }
            if q.top < f.faixa.top || q.top > f.faixa.bottom + (24.0 * f.sc) as i32 {
                return TRUE;
            }
            f.achou = w_;
            FALSE
        })
    }
    let mut f = F { owner: i.owner, ov: i.overlay, achou: HWND::default(), faixa: r, sc };
    unsafe {
        let _ = EnumWindows(Some(cb), LPARAM(&mut f as *mut _ as isize));
        if f.achou.0.is_null() {
            return false;
        }
        let q = win_rect(f.achou);
        let x = r.right - (8.0 * sc).round() as i32 - (q.right - q.left);
        if (q.left - x).abs() > 2 {
            let _ = SetWindowPos(f.achou, None, x, q.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
        }
    }
    true
}
/// o mouse saiu do grupo movido (ou do ˅): o app tinha recebido o mouse repassado e o botão ficava aceso; o Chromium
/// ignora o WM_MOUSELEAVE que não pediu, então vai também um movimento para um ponto vazio da barra
pub fn sai_do_grupo(i: &Info) {
    let f = frame_rect(i.owner);
    let sc = scale(i.owner);
    let mut a = POINT { x: f.left + if i.chunk_w != 0 { i.chunk_src + i.chunk_w + (10.0 * sc) as i32 } else { (patch_l(i) * sc) as i32 + 4 }, y: f.top + (4.0 * sc) as i32 };
    unsafe {
        let _ = ScreenToClient(i.owner, &mut a);
        let _ = PostMessageW(i.owner, WM_MOUSEMOVE, WPARAM(0), makelparam(a.x, a.y));
        let _ = PostMessageW(i.owner, WM_MOUSELEAVE_, WPARAM(0), LPARAM(0));
    }
}
pub const WM_MOUSELEAVE_: u32 = 0x02A3;
pub fn repassa_grupo(i: &mut Info, p: POINT, msg: u32) -> bool {
    let (k, real) = alvo_movido(i, p);
    if k == 0 {
        return false;
    }
    let mut a = real;
    unsafe {
        let _ = ScreenToClient(i.owner, &mut a);
        let lp = makelparam(a.x, a.y);
        if msg == WM_LBUTTONDOWN {
            let _ = PostMessageW(i.owner, WM_MOUSEMOVE, WPARAM(0), lp);
        }
        let _ = PostMessageW(i.owner, msg, WPARAM(if msg == WM_LBUTTONDOWN { 1 } else { 0 }), lp); // MK_LBUTTON
    }
    true
}
/// arrasta a janela h que começou no ponto pt (tela), sem passar pelo teste de clique do app: maximizada, sai do
/// maximizado no lugar proporcional ao ponteiro e segue o arraste; senão, o arraste do Windows (SC_MOVE)
pub fn arrasta_janela(h: HWND, pt_: POINT) {
    unsafe {
        let mut c = POINT::default();
        let _ = GetCursorPos(&mut c);
        if zoomed(h) {
            let mut fb = RECT::default();
            if DwmGetWindowAttribute(h, DWMWA_EXTENDED_FRAME_BOUNDS, &mut fb as *mut _ as *mut _, std::mem::size_of::<RECT>() as u32).is_err() {
                fb = win_rect(h);
            }
            let fx = (pt_.x - fb.left) as f32 / (fb.right - fb.left).max(1) as f32; // onde o ponteiro estava na largura
            let dy = pt_.y - fb.top; // e abaixo do topo
            let _ = SetPropW(h, w!("MacJanelaLeve"), HANDLE(1 as *mut _)); // sem a animação de ampliar no meio do arrasto
            let _ = ShowWindow(h, SW_RESTORE);
            let _ = GetCursorPos(&mut c);
            let wr = win_rect(h);
            let mut vis = RECT::default();
            if DwmGetWindowAttribute(h, DWMWA_EXTENDED_FRAME_BOUNDS, &mut vis as *mut _ as *mut _, std::mem::size_of::<RECT>() as u32).is_err() {
                vis = wr;
            }
            let x = c.x - (fx * (vis.right - vis.left) as f32).round() as i32 - (vis.left - wr.left);
            let y = c.y - dy - (vis.top - wr.top);
            let _ = SetWindowPos(h, None, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
        }
        SendMessageW(h, WM_SYSCOMMAND, WPARAM((SC_MOVE | HTCAPTION as u32) as usize), makelparam(c.x, c.y)); // o arrasto continua
    }
}