A new style desktop shell for Windows 11: menu bar, Dock, Finder, Spotlight, Control Center and Liquid Glass, in native C++.
Rust
//! verde.cpp: menu do botão verde (macOS Sequoia): parar o ponteiro sobre o botão verde de uma janela abre um menu para
//! encaixar a janela (metades, quartos, centralizar, preencher). Quem percebe o ponteiro parado é a WacOSWindow.dll
//! (janelas com a nossa barra) ou o próprio app nosso; eles mandam "ShellMenuVerde" com a janela e o ponto da tela. Os
//! encaixes respeitam a área livre (sem passar da barra de menus nem do Dock). No Tahoe é o menu de tiling do macOS 26
//! (painel de vidro com os ícones, guia macOS26-Theme-Reference, seção 46).
#![allow(dead_code)]
use comum::ctxmenu::{self, Item as MItem};
use comum::windows::core::*;
use comum::windows::Win32::Foundation::*;
use comum::windows::Win32::Graphics::Direct2D::*;
use comum::windows::Win32::Graphics::DirectWrite::*;
use comum::windows::Win32::Graphics::Dwm::*;
use comum::windows::Win32::Graphics::Gdi::*;
use comum::windows::Win32::System::Threading::GetCurrentProcessId;
use comum::windows::Win32::UI::Controls::WM_MOUSELEAVE;
use comum::windows::Win32::UI::Input::KeyboardAndMouse::*;
use comum::windows::Win32::UI::WindowsAndMessaging::*;
use comum::*;
use crate::{apps, backdrop, liquid, log, shell, ui};
static OWNER: Global<HWND> = Global::new(HWND(std::ptr::null_mut()));
unsafe extern "system" fn owner_proc(h: HWND, m: u32, w: WPARAM, l: LPARAM) -> LRESULT {
if let Some(r) = ctxmenu::forward_owner_msg(m, w, l) {
return r;
}
DefWindowProcW(h, m, w, l)
}
fn win_rect(h: HWND) -> RECT {
let mut r = RECT::default();
unsafe {
let _ = GetWindowRect(h, &mut r);
}
r
}
/// o retângulo visível (sem a borda invisível de redimensionar; com a nossa barra, a região da janela)
fn visible(h: HWND) -> (RECT, RECT) {
let wr = win_rect(h);
let mut vis = wr;
unsafe {
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 mut bx = RECT::default();
if !GetPropW(h, w!("MacJanela")).is_invalid() && GetWindowRgnBox(h, &mut bx) != GDI_REGION_TYPE(0) && bx.right > bx.left {
vis = RECT { left: wr.left + bx.left, top: wr.top + bx.top, right: wr.left + bx.right, bottom: wr.top + bx.bottom };
}
}
(vis, wr)
}
fn place(h: HWND, want: RECT) {
unsafe {
if IsZoomed(h).as_bool() {
let _ = ShowWindow(h, SW_RESTORE);
}
let (vis, wr) = visible(h);
// a borda invisível volta em volta do retângulo pedido
let r = RECT { left: want.left - (vis.left - wr.left), top: want.top - (vis.top - wr.top), right: want.right + (wr.right - vis.right), bottom: want.bottom + (wr.bottom - vis.bottom) };
let _ = SetWindowPos(h, None, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_NOZORDER | SWP_NOACTIVATE);
let _ = SetForegroundWindow(h);
}
}
// ================= Tahoe: o menu de tiling do macOS 26 (seção 46, medido)
// Janela de vidro de 264 × 218, 13 de margem: "Mover e Redimensionar" → 4 ícones de 54 × 44 → separador → "Preencher e
// Organizar" → 4 ícones → separador → "Tela Cheia ›". Com ⌥ as paletas trocam. Aparece sem animação e some na hora.
mod tiling {
use super::*;
pub const W: f32 = 264.0;
pub const H: f32 = 218.0;
const M: f32 = 13.0;
const CELL_W: f32 = 54.0;
const CELL_H: f32 = 44.0;
const R: f32 = 12.0;
const Y_H1: f32 = 6.0;
const Y_P1: f32 = 32.0;
const Y_S1: f32 = 80.0;
const Y_H2: f32 = 91.0;
const Y_P2: f32 = 117.0;
const Y_S2: f32 = 165.0;
pub const Y_FS: f32 = 182.0;
pub const T_ALT: usize = 1;
#[derive(Default)]
pub struct T {
pub wnd: HWND,
pub back: HWND,
pub target: HWND,
pub glass: bool,
pub alt: bool,
pub sub: bool,
/// 0..3 paleta 1, 4..7 paleta 2, 8 Tela Cheia
pub hover: i32,
pub s: ui::GpuSurface,
}
static TS: Global<Option<T>> = Global::new(None);
pub fn t() -> &'static mut T {
TS.get().get_or_insert_with(|| T { hover: -1, ..Default::default() })
}
/// área ocupada de cada ícone: retângulos em frações da tela (x0, y0, x1, y1)
pub struct Ico {
pub name: &'static str,
pub id: i32,
pub r: &'static [[f32; 4]],
}
const MOVE: [Ico; 4] = [
Ico { name: "Esquerda", id: 10, r: &[[0.0, 0.0, 0.5, 1.0]] },
Ico { name: "Direita", id: 11, r: &[[0.5, 0.0, 1.0, 1.0]] },
Ico { name: "Superior", id: 12, r: &[[0.0, 0.0, 1.0, 0.5]] },
Ico { name: "Inferior", id: 13, r: &[[0.0, 0.5, 1.0, 1.0]] },
];
const MOVE_ALT: [Ico; 4] = [
Ico { name: "Superior Esquerda", id: 20, r: &[[0.0, 0.0, 0.5, 0.5]] },
Ico { name: "Superior Direita", id: 21, r: &[[0.5, 0.0, 1.0, 0.5]] },
Ico { name: "Inferior Esquerda", id: 22, r: &[[0.0, 0.5, 0.5, 1.0]] },
Ico { name: "Inferior Direita", id: 23, r: &[[0.5, 0.5, 1.0, 1.0]] },
];
const QUARTOS: &[[f32; 4]] = &[[0.0, 0.0, 0.5, 0.5], [0.5, 0.0, 1.0, 0.5], [0.0, 0.5, 0.5, 1.0], [0.5, 0.5, 1.0, 1.0]];
const FILL: [Ico; 4] = [
Ico { name: "Preencher", id: 1, r: &[[0.0, 0.0, 1.0, 1.0]] },
Ico { name: "Esquerda e Direita", id: 30, r: &[[0.0, 0.0, 0.5, 1.0], [0.5, 0.0, 1.0, 1.0]] },
Ico { name: "Esquerda e Quartos", id: 31, r: &[[0.0, 0.0, 0.5, 1.0], [0.5, 0.0, 1.0, 0.5], [0.5, 0.5, 1.0, 1.0]] },
Ico { name: "Quartos", id: 32, r: QUARTOS },
];
const FILL_ALT: [Ico; 4] = [
Ico { name: "Centralizar", id: 2, r: &[[0.2, 0.15, 0.8, 0.85]] },
Ico { name: "Direita e Esquerda", id: 33, r: &[[0.5, 0.0, 1.0, 1.0], [0.0, 0.0, 0.5, 1.0]] },
Ico { name: "Direita e Quartos", id: 34, r: &[[0.5, 0.0, 1.0, 1.0], [0.0, 0.0, 0.5, 0.5], [0.0, 0.5, 0.5, 1.0]] },
Ico { name: "Quartos", id: 32, r: QUARTOS },
];
pub fn ico_at(k: i32) -> &'static Ico {
let alt = t().alt;
if k < 4 {
&(if alt { &MOVE_ALT } else { &MOVE })[k as usize]
} else {
&(if alt { &FILL_ALT } else { &FILL })[(k - 4) as usize]
}
}
fn cell_rect(k: i32) -> RectF {
let gap = (W - 2.0 * M - 4.0 * CELL_W) / 3.0;
let y = if k < 4 { Y_P1 } else { Y_P2 };
let x = M + (k % 4) as f32 * (CELL_W + gap);
rf(x, y, x + CELL_W, y + CELL_H)
}
fn fs_rect() -> RectF {
rf(5.0, Y_FS, W - 5.0, Y_FS + 24.0)
}
pub fn paint() {
let st = t();
if st.wnd.0.is_null() || !unsafe { IsWindowVisible(st.wnd).as_bool() } {
return;
}
let sc = ui::scale(st.wnd);
let (wpx, hpx) = ((W * sc).round() as i32, (H * sc).round() as i32);
let Some(dc) = ui::gpu_begin(&mut st.s, wpx, hpx, sc) else { return };
let dark = ui::dark();
let text = if dark { col(1.0, 1.0, 1.0, 0.92) } else { col(0.0, 0.0, 0.0, 0.88) };
let text2 = if dark { col(1.0, 1.0, 1.0, 0.55) } else { col(0.0, 0.0, 0.0, 0.50) };
let accent = col(0.0, 0.39, 0.88, 1.0); // selectedContentBackground
let rt: ID2D1RenderTarget = dc.cast().unwrap();
unsafe {
let Ok(br) = rt.CreateSolidColorBrush(&text, None) else {
ui::gpu_end(&mut st.s);
return;
};
let all = rf(0.0, 0.0, W, H);
if !st.glass {
br.SetColor(&if dark { col(0.17, 0.17, 0.18, 0.95) } else { col(0.96, 0.96, 0.965, 0.95) });
rt.FillRoundedRectangle(&rr(all, R, R), &br);
}
liquid::rim0(&rt, all, R, dark);
let tf = ui::format(13.0, DWRITE_FONT_WEIGHT_NORMAL, false, DWRITE_TEXT_ALIGNMENT_LEADING);
let th = ui::format(13.0, DWRITE_FONT_WEIGHT_SEMI_BOLD, false, DWRITE_TEXT_ALIGNMENT_LEADING);
for f in [&tf, &th] {
let _ = f.SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
let _ = f.SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
}
let txt = |s: &str, f: &IDWriteTextFormat, r: RectF, c: Cor| {
br.SetColor(&c);
let w16: Vec<u16> = s.encode_utf16().collect();
rt.DrawText(&w16, f, &r, &br, D2D1_DRAW_TEXT_OPTIONS_CLIP, DWRITE_MEASURING_MODE_NATURAL);
};
// cabeçalhos: com o ponteiro num ícone, o nome dele aparece no lugar do título da seção (como no Mac)
let h1 = if (0..4).contains(&st.hover) { tr(ico_at(st.hover).name) } else { tr("Mover e Redimensionar") };
let h2 = if (4..8).contains(&st.hover) { tr(ico_at(st.hover).name) } else { tr("Preencher e Organizar") };
txt(&h1, &th, rf(M + 1.0, Y_H1, W - M, Y_H1 + 24.0), text2);
txt(&h2, &th, rf(M + 1.0, Y_H2, W - M, Y_H2 + 24.0), text2);
for k in 0..8 {
let c = cell_rect(k);
let hot = st.hover == k;
if hot {
br.SetColor(&if dark { col(1.0, 1.0, 1.0, 0.12) } else { col(0.0, 0.0, 0.0, 0.07) });
rt.FillRoundedRectangle(&rr(c, 9.0, 9.0), &br);
}
// a tela: retângulo arredondado de 34 × 24 no meio da célula, com a área ocupada cheia
let (cx, cy, sw, sh) = ((c.left + c.right) / 2.0, (c.top + c.bottom) / 2.0, 34.0, 24.0);
let sr = rf(cx - sw / 2.0, cy - sh / 2.0, cx + sw / 2.0, cy + sh / 2.0);
for (i, q) in ico_at(k).r.iter().enumerate() {
let a = rf(sr.left + 2.5 + (sw - 5.0) * q[0] + 0.75, sr.top + 2.5 + (sh - 5.0) * q[1] + 0.75, sr.left + 2.5 + (sw - 5.0) * q[2] - 0.75, sr.top + 2.5 + (sh - 5.0) * q[3] - 0.75);
br.SetColor(&if hot {
accent
} else if i == 0 {
text
} else {
text2
});
rt.FillRoundedRectangle(&rr(a, 2.0, 2.0), &br);
}
br.SetColor(&if hot { accent } else { text2 });
rt.DrawRoundedRectangle(&rr(sr, 5.0, 5.0), &br, 1.2, None);
}
for y in [Y_S1, Y_S2] {
br.SetColor(&if dark { col(1.0, 1.0, 1.0, 0.10) } else { col(0.0, 0.0, 0.0, 0.10) });
rt.FillRectangle(&rf(M, y + 5.0, W - M, y + 5.0 + 1.0 / sc), &br);
}
let fs = fs_rect();
let fhot = st.hover == 8 || st.sub;
if fhot {
br.SetColor(&accent);
rt.FillRoundedRectangle(&rr(fs, 8.0, 8.0), &br);
}
txt(&tr("Tela Cheia"), &tf, rf(M + 1.0, fs.top, W - M, fs.bottom), if fhot { col(1.0, 1.0, 1.0, 1.0) } else { text });
// seta ›
let (x, y) = (W - M - 6.0, (fs.top + fs.bottom) / 2.0);
br.SetColor(&if fhot { col(1.0, 1.0, 1.0, 1.0) } else { text });
rt.DrawLine(pt(x - 2.0, y - 4.0), pt(x + 2.0, y), &br, 1.5, None);
rt.DrawLine(pt(x + 2.0, y), pt(x - 2.0, y + 4.0), &br, 1.5, None);
}
ui::gpu_end(&mut st.s);
if st.glass {
// é um menu: vidro fosco que não segue o controle de transparência (vidro dos menus, seção 52)
if liquid::on() {
let tint = if dark { col(0.17, 0.165, 0.165, 0.90) } else { col(0.95, 0.945, 0.94, 0.86) };
backdrop::set_pieces(st.back, wpx as f32, hpx as f32, &[backdrop::Piece { r: rf(0.0, 0.0, wpx as f32, hpx as f32), radius: R * sc, ..Default::default() }], tint, 24.0);
} else {
let tint = if dark { col(0.165, 0.165, 0.172, 0.85) } else { col(0.96, 0.96, 0.965, 0.77) };
backdrop::set(st.back, wpx as f32, hpx as f32, R * sc, tint);
}
backdrop::fade(st.back, 1.0, 1.0, 0.0, 0.0);
}
}
pub fn hide() {
let st = t();
if st.wnd.0.is_null() {
return;
}
unsafe {
let _ = KillTimer(st.wnd, T_ALT);
let _ = ShowWindow(st.wnd, SW_HIDE);
let _ = ShowWindow(st.back, SW_HIDE);
}
st.hover = -1;
st.sub = false;
}
fn hit_at(x: f32, y: f32) -> i32 {
let dentro = |c: RectF| x >= c.left && x < c.right && y >= c.top && y < c.bottom;
(0..8).find(|k| dentro(cell_rect(*k))).unwrap_or(if dentro(fs_rect()) { 8 } else { -1 })
}
unsafe extern "system" fn proc_(h: HWND, m: u32, w: WPARAM, l: LPARAM) -> LRESULT {
let st = t();
match m {
WM_PAINT => {
let mut ps = PAINTSTRUCT::default();
BeginPaint(h, &mut ps);
let _ = EndPaint(h, &ps);
paint();
return LRESULT(0);
}
WM_TIMER => {
if w.0 == T_ALT {
// ⌥ apertado troca as paletas (como no Mac)
let alt = GetAsyncKeyState(VK_MENU.0 as i32) < 0;
if alt != st.alt {
st.alt = alt;
paint();
}
}
return LRESULT(0);
}
WM_MOUSEMOVE => {
let sc = ui::scale(h);
let mut tme = TRACKMOUSEEVENT { cbSize: std::mem::size_of::<TRACKMOUSEEVENT>() as u32, dwFlags: TME_LEAVE, hwndTrack: h, dwHoverTime: 0 };
let _ = TrackMouseEvent(&mut tme);
let hv = hit_at(get_x_lparam(l) as f32 / sc, get_y_lparam(l) as f32 / sc);
if hv != st.hover {
st.hover = hv;
paint();
if hv == 8 {
full_screen_sub();
}
}
return LRESULT(0);
}
WM_MOUSELEAVE => {
if st.hover != -1 && !st.sub {
st.hover = -1;
paint();
}
return LRESULT(0);
}
WM_LBUTTONUP => {
let sc = ui::scale(h);
let k = hit_at(get_x_lparam(l) as f32 / sc, get_y_lparam(l) as f32 / sc);
if k == 8 {
full_screen_sub();
} else if k >= 0 {
let id = ico_at(k).id;
let tg = st.target;
hide();
executar(tg, id);
}
return LRESULT(0);
}
WM_KEYDOWN => {
if w.0 == VK_ESCAPE.0 as usize {
hide();
}
return LRESULT(0);
}
WM_SYSKEYDOWN | WM_SYSKEYUP => {
let alt = m == WM_SYSKEYDOWN;
if w.0 == VK_MENU.0 as usize && alt != st.alt {
st.alt = alt;
paint();
}
return LRESULT(0);
}
WM_ACTIVATE => {
if loword(w.0) == WA_INACTIVE && !st.sub {
hide();
}
return LRESULT(0);
}
_ => {}
}
DefWindowProcW(h, m, w, l)
}
unsafe extern "system" fn back_proc(h: HWND, m: u32, w: WPARAM, l: LPARAM) -> LRESULT {
if m == WM_MOUSEACTIVATE {
return LRESULT(MA_NOACTIVATE as isize);
}
DefWindowProcW(h, m, w, l)
}
fn make() -> bool {
let st = t();
if !st.wnd.0.is_null() {
return true;
}
unsafe {
let inst = shell::inst();
let wc = WNDCLASSW { lpfnWndProc: Some(proc_), hInstance: inst, lpszClassName: w!("ShellMenuVerdeTahoe"), hCursor: LoadCursorW(None, IDC_ARROW).unwrap_or_default(), ..Default::default() };
RegisterClassW(&wc);
let bc = WNDCLASSW { lpfnWndProc: Some(back_proc), hInstance: inst, lpszClassName: w!("ShellMenuVerdeFundo"), ..Default::default() };
RegisterClassW(&bc);
st.wnd = CreateWindowExW(WS_EX_TOPMOST | WS_EX_TOOLWINDOW | WS_EX_NOREDIRECTIONBITMAP, w!("ShellMenuVerdeTahoe"), w!(""), WS_POPUP, 0, 0, 10, 10, None, None, inst, None).unwrap_or_default();
st.back = CreateWindowExW(WS_EX_TOPMOST | WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE | WS_EX_TRANSPARENT | WS_EX_NOREDIRECTIONBITMAP, w!("ShellMenuVerdeFundo"), w!(""), WS_POPUP, 0, 0, 10, 10, None, None, inst, None).unwrap_or_default();
if st.wnd.0.is_null() || st.back.0.is_null() {
return false;
}
st.glass = backdrop::attach(st.back);
let (c1, none) = (1u32, 0xFFFF_FFFEu32);
for x in [st.wnd, st.back] {
let _ = DwmSetWindowAttribute(x, DWMWINDOWATTRIBUTE(33), &c1 as *const _ as *const _, 4);
let _ = DwmSetWindowAttribute(x, DWMWINDOWATTRIBUTE(34), &none as *const _ as *const _, 4);
}
st.s.hwnd = st.wnd;
apps::ours().push(st.wnd);
apps::ours().push(st.back);
}
true
}
pub fn show(target: HWND, p: POINT) {
if !make() {
return;
}
let st = t();
st.target = target;
st.hover = -1;
st.sub = false;
unsafe {
st.alt = GetAsyncKeyState(VK_MENU.0 as i32) < 0;
let sc = ui::scale(st.wnd);
let (wpx, hpx) = ((W * sc).round() as i32, (H * sc).round() as i32);
let mut mi = MONITORINFO { cbSize: std::mem::size_of::<MONITORINFO>() as u32, ..Default::default() };
let _ = GetMonitorInfoW(MonitorFromPoint(p, MONITOR_DEFAULTTONEAREST), &mut mi);
// ~15 abaixo do topo do botão verde e ~33 à esquerda dele (o ponto é o ponteiro, no meio do botão de 14)
let wk = mi.rcWork;
let x = (p.x - (40.0 * sc).round() as i32).clamp(wk.left + 4, (wk.right - wpx - 4).max(wk.left + 4));
let y = (p.y + (8.0 * sc).round() as i32).clamp(wk.top + 4, (wk.bottom - hpx - 4).max(wk.top + 4));
let _ = SetWindowPos(st.back, HWND_TOPMOST, x, y, wpx, hpx, SWP_NOACTIVATE | SWP_SHOWWINDOW);
let _ = SetWindowPos(st.wnd, HWND_TOPMOST, x, y, wpx, hpx, SWP_SHOWWINDOW);
let _ = SetForegroundWindow(st.wnd);
SetTimer(st.wnd, T_ALT, 50, None);
}
paint();
}
pub fn full_screen_sub() {
let st = t();
if st.sub || st.wnd.0.is_null() {
return;
}
st.sub = true;
paint();
let sc = ui::scale(st.wnd);
let wr = win_rect(st.wnd);
let p = POINT { x: wr.right - (6.0 * sc).round() as i32, y: wr.top + ((Y_FS - 5.0) * sc).round() as i32 };
let id = ctxmenu::show_items(st.wnd, p, &[MItem::new(tr("Tela Inteira"), 40), MItem::new(tr("Esquerda da Tela"), 41), MItem::new(tr("Direita da Tela"), 42)]);
let st = t();
st.sub = false;
let tg = st.target;
hide();
if id != 0 {
executar(tg, id);
}
}
}
/// as outras janelas na ordem da tela (de cima para baixo), para "Organizar" (Esquerda e Direita, Quartos...)
fn outras(target: HWND, n: usize) -> Vec<HWND> {
let mut v = Vec::new();
unsafe {
let mut h = GetTopWindow(None).unwrap_or_default();
while !h.0.is_null() && v.len() < n {
let ok = (|| {
if h == target || !IsWindowVisible(h).as_bool() || IsIconic(h).as_bool() || !GetWindow(h, GW_OWNER).unwrap_or_default().0.is_null() {
return false;
}
let ex = GetWindowLongW(h, GWL_EXSTYLE) as u32;
if ex & (WS_EX_TOOLWINDOW.0 | WS_EX_NOACTIVATE.0) != 0 {
return false;
}
if GetWindowLongW(h, GWL_STYLE) as u32 & WS_CAPTION.0 == 0 || GetWindowTextLengthW(h) == 0 {
return false;
}
let mut pid = 0u32;
GetWindowThreadProcessId(h, Some(&mut pid));
if pid == GetCurrentProcessId() {
return false;
}
let mut cl = 0i32;
let _ = DwmGetWindowAttribute(h, DWMWA_CLOAKED, &mut cl as *mut _ as *mut _, 4);
cl == 0
})();
if ok {
v.push(h);
}
h = GetWindow(h, GW_HWNDNEXT).unwrap_or_default();
}
}
v
}
/// o ponteiro parou no botão verde de `target` (no ponto `p` da tela)
pub fn show(target: HWND, p: POINT) {
if !unsafe { IsWindow(target).as_bool() } {
return;
}
if liquid::on() {
tiling::show(target, p);
return;
}
unsafe {
if OWNER.get().0.is_null() {
let inst = shell::inst();
let wc = WNDCLASSW { lpfnWndProc: Some(owner_proc), hInstance: inst, lpszClassName: w!("ShellMenuVerde"), ..Default::default() };
RegisterClassW(&wc);
*OWNER.get() = CreateWindowExW(WS_EX_TOOLWINDOW, w!("ShellMenuVerde"), w!(""), WS_POPUP, 0, 0, 0, 0, None, None, inst, None).unwrap_or_default();
apps::ours().push(*OWNER.get());
}
let m = vec![
MItem::new(tr("Preencher"), 1),
MItem::new(tr("Centralizar"), 2),
MItem::sep(),
MItem::new(tr("Esquerda"), 10),
MItem::new(tr("Direita"), 11),
MItem::new(tr("Parte de Cima"), 12),
MItem::new(tr("Parte de Baixo"), 13),
MItem::sep(),
MItem::new(tr("Superior Esquerdo"), 20),
MItem::new(tr("Superior Direito"), 21),
MItem::new(tr("Inferior Esquerdo"), 22),
MItem::new(tr("Inferior Direito"), 23),
];
ctxmenu::plain_next();
let _ = SetForegroundWindow(*OWNER.get());
let id = ctxmenu::show_items(*OWNER.get(), p, &m);
if id != 0 {
executar(target, id);
}
}
}
fn executar(target: HWND, id: i32) {
if id == 0 || !unsafe { IsWindow(target).as_bool() } {
return;
}
let mut mi = MONITORINFO { cbSize: std::mem::size_of::<MONITORINFO>() as u32, ..Default::default() };
unsafe {
let _ = GetMonitorInfoW(MonitorFromWindow(target, MONITOR_DEFAULTTONEAREST), &mut mi);
}
let a = mi.rcWork;
let (cx, cy) = ((a.left + a.right) / 2, (a.top + a.bottom) / 2);
let rc = |l: i32, t: i32, r: i32, b: i32| RECT { left: l, top: t, right: r, bottom: b };
log!("menu verde: opção {id}");
unsafe {
match id {
1 => {
if !GetPropW(target, w!("MacJanela")).is_invalid() {
// a nossa barra: o "ampliar" animado da DLL
if GetPropW(target, w!("MacJanelaAmpliada")).is_invalid() {
let _ = PostMessageW(target, reg_msg("MacJanelaAmpliar"), WPARAM(0), LPARAM(0));
}
let _ = SetForegroundWindow(target);
} else {
place(target, a);
}
}
2 => {
let (v, _) = visible(target);
let (w, hh) = ((v.right - v.left).min(a.right - a.left), (v.bottom - v.top).min(a.bottom - a.top));
place(target, rc(cx - w / 2, cy - hh / 2, cx - w / 2 + w, cy - hh / 2 + hh));
}
10 => place(target, rc(a.left, a.top, cx, a.bottom)),
11 => place(target, rc(cx, a.top, a.right, a.bottom)),
12 => place(target, rc(a.left, a.top, a.right, cy)),
13 => place(target, rc(a.left, cy, a.right, a.bottom)),
20 => place(target, rc(a.left, a.top, cx, cy)),
21 => place(target, rc(cx, a.top, a.right, cy)),
22 => place(target, rc(a.left, cy, cx, a.bottom)),
23 => place(target, rc(cx, cy, a.right, a.bottom)),
// Tahoe: Organizar (a janela e as próximas da tela) e Tela Cheia
30 | 33 => {
let o = outras(target, 1);
let left = id == 30;
place(target, if left { rc(a.left, a.top, cx, a.bottom) } else { rc(cx, a.top, a.right, a.bottom) });
if let Some(x) = o.first() {
place(*x, if left { rc(cx, a.top, a.right, a.bottom) } else { rc(a.left, a.top, cx, a.bottom) });
}
let _ = SetForegroundWindow(target);
}
31 | 34 => {
let o = outras(target, 2);
let left = id == 31;
place(target, if left { rc(a.left, a.top, cx, a.bottom) } else { rc(cx, a.top, a.right, a.bottom) });
let (x0, x1) = if left { (cx, a.right) } else { (a.left, cx) };
if let Some(x) = o.first() {
place(*x, rc(x0, a.top, x1, cy));
}
if let Some(x) = o.get(1) {
place(*x, rc(x0, cy, x1, a.bottom));
}
let _ = SetForegroundWindow(target);
}
32 => {
let o = outras(target, 3);
place(target, rc(a.left, a.top, cx, cy));
let q = [rc(cx, a.top, a.right, cy), rc(a.left, cy, cx, a.bottom), rc(cx, cy, a.right, a.bottom)];
for (i, x) in o.iter().enumerate() {
place(*x, q[i]);
}
let _ = SetForegroundWindow(target);
}
40 => {
// Tela Inteira
let _ = ShowWindow(target, SW_MAXIMIZE);
let _ = SetForegroundWindow(target);
}
41 => place(target, rc(mi.rcMonitor.left, a.top, cx, a.bottom)), // Esquerda da Tela
42 => place(target, rc(cx, a.top, mi.rcMonitor.right, a.bottom)), // Direita da Tela
_ => {}
}
}
}