A new style desktop shell for Windows 11: menu bar, Dock, Finder, Spotlight, Control Center and Liquid Glass, in native C++.
Rust
//! Os globais do main.cpp (g_*), juntos num estado só da janela (uma thread, como no C++).
#![allow(dead_code)]
use std::collections::{HashMap, HashSet};
use comum::campo::TextField;
use comum::windows::Win32::Foundation::*;
use comum::windows::Win32::Graphics::Direct2D::*;
use comum::windows::Win32::Graphics::DirectWrite::*;
use comum::*;
use crate::base::*;
use crate::rodape::PathSeg;
use crate::thumbs;
use crate::vistas::UndoOp;
/// medidas que mudam com o tema e com a janela (Lay:: no C++)
#[derive(Clone, Copy)]
pub struct Lay {
pub sidebar_w: f32,
pub toolbar_h: f32,
pub tool_cy: f32,
pub status_h: f32,
pub footer_h: f32,
pub side_row_h: f32,
pub side_hdr_h: f32,
pub side_top: f32,
pub header_h: f32,
}
impl Default for Lay {
fn default() -> Self {
Lay { sidebar_w: 142.0, toolbar_h: 53.0, tool_cy: 26.3, status_h: 26.0, footer_h: 26.0, side_row_h: 28.7, side_hdr_h: 23.5, side_top: 47.0, header_h: 28.0 }
}
}
/// coluna à esquerda da ativa (visão em colunas)
#[derive(Clone, Default)]
pub struct Column {
pub folder: String,
pub open: String,
pub items: Vec<Entry>,
pub scroll: f32,
}
#[derive(Clone, Default)]
pub struct TabState {
pub folder: String,
pub tag_view: i32,
pub back: Vec<String>,
pub fwd: Vec<String>,
pub view: View,
pub scroll: f32,
pub col_trail: Vec<Column>,
pub sel: Vec<String>,
}
#[derive(Clone, Copy, PartialEq, Default)]
pub enum Drag {
#[default]
None,
Pending,
Band,
}
/// modo escolher (janela de Abrir/Salvar)
#[derive(Clone, Default)]
pub struct Picker {
pub on: bool,
/// 0 abrir, 1 salvar, 2 pasta
pub mode: i32,
pub multi: bool,
pub overwrite: bool,
pub types: Vec<(String, String)>,
pub type_: i32,
pub ok: String,
pub ext: String,
pub result: String,
pub owner: HWND,
}
#[derive(Clone)]
pub struct Fonts {
pub glyph: IDWriteTextFormat,
pub side: IDWriteTextFormat,
pub side_hdr: IDWriteTextFormat,
pub title: IDWriteTextFormat,
pub status: IDWriteTextFormat,
pub search: IDWriteTextFormat,
pub label: IDWriteTextFormat,
pub row: IDWriteTextFormat,
pub row_r: IDWriteTextFormat,
pub header: IDWriteTextFormat,
pub header_l: IDWriteTextFormat,
pub header_r: IDWriteTextFormat,
pub group: IDWriteTextFormat,
pub preview_name: IDWriteTextFormat,
pub preview_info: IDWriteTextFormat,
pub path: IDWriteTextFormat,
pub rename: IDWriteTextFormat,
pub leo_header: IDWriteTextFormat,
pub leo_ql_title: IDWriteTextFormat,
pub leo_ql_info: IDWriteTextFormat,
pub gg_ql_title: IDWriteTextFormat,
pub cf_name: IDWriteTextFormat,
pub cf_kind: IDWriteTextFormat,
pub mono: IDWriteTextFormat,
pub ql_title: IDWriteTextFormat,
pub ql_button: IDWriteTextFormat,
pub ql_glyph: IDWriteTextFormat,
pub ql_time: IDWriteTextFormat,
pub ql_artist: IDWriteTextFormat,
pub go_field: IDWriteTextFormat,
pub go_row: IDWriteTextFormat,
pub go_row_b: IDWriteTextFormat,
pub go_head: IDWriteTextFormat,
}
/// controle do painel de Opções de Visualização (recalculado a cada desenho)
#[derive(Clone, Copy)]
pub struct OptCtl {
pub r: RectF,
pub id: i32,
}
/// favorito da barra lateral (favoritos.txt)
#[derive(Clone)]
pub struct Fav {
pub label: String,
pub path: String,
pub glyph: u16,
}
pub struct S {
pub hwnd: HWND,
pub rt: Option<ID2D1HwndRenderTarget>,
pub scale: f32,
pub dark: bool,
pub win_active: bool,
pub hover_lights: bool,
pub press_light: i32,
pub tahoe: bool,
pub tahoe_lay: bool,
pub icon: f32,
pub label_size: f32,
pub row_text_size: f32,
pub side: Vec<SideEntry>,
pub side_scroll: f32,
pub searching: bool,
pub search: TextField,
pub search_focus: bool,
pub search_busy: bool,
pub search_scope: i32,
pub search_home: String,
pub tag_view: i32,
pub folder: String,
pub flash: String,
pub flash_at: u32,
pub kind_cache: HashMap<String, String>,
pub group_by: GroupBy,
pub group_main: GroupBy,
pub group_dl: i32,
pub in_downloads: bool,
pub sort_col: SortCol,
pub sort_asc: bool,
pub items: Vec<Entry>,
pub all: Vec<Entry>,
pub rows: Vec<ListRow>,
pub row_of_item: Vec<i32>,
pub rows_dirty: bool,
pub list_large: bool,
pub col_size: bool,
pub col_kind: bool,
pub col_date: bool,
pub col_created: bool,
pub col_icons: bool,
pub col_preview: bool,
pub col_trail: Vec<Column>,
pub child_path: String,
pub child_items: Vec<Entry>,
pub gallery_x: f32,
pub scroll: f32,
pub scroll_target: f32,
pub scroll_anim: bool,
pub scroll_t: std::time::Instant,
pub scroll_shown_at: u32,
pub scroll_drag: bool,
pub scroll_drag_off: f32,
pub scroll_hover: bool,
pub view: View,
pub default_view: View,
pub tabs: Vec<TabState>,
pub cur_tab: usize,
pub hover_tab: i32,
pub lay: Lay,
/// modo foto: tamanho do cliente em DIPs
pub foto: Option<(f32, f32)>,
pub focus: i32,
pub anchor: i32,
pub rename: TextField,
pub rename_idx: i32,
pub caret_on: bool,
pub ui_family: String,
pub icon_family: String,
pub body_weight: DWRITE_FONT_WEIGHT,
pub images: HashMap<String, ID2D1Bitmap>,
pub img_born: HashMap<String, f64>,
pub requested: HashSet<String>,
pub kinds: HashMap<String, thumbs::Kind>,
pub gen: u32,
pub back: Vec<String>,
pub fwd: Vec<String>,
pub emblems: Vec<(String, u16)>,
pub show_hidden: bool,
pub recent_folder: String,
pub notify_id: u32,
pub select_after_reload: String,
pub rename_after_reload: bool,
pub nav_ms: i32,
pub undo: Vec<UndoOp>,
pub pick: Picker,
pub pick_name: TextField,
pub pick_name_focus: bool,
pub pick_view: i32,
pub pick_win: RECT,
pub saved_win: RECT,
pub exit_code: i32,
pub cover_flow: bool,
pub cf_hits: Vec<(i32, RectF)>,
pub hover_side: i32,
pub hover_tool: i32,
pub press_tool: i32,
pub hover_title: bool,
pub drop_hi: i32,
pub drop_side_row: i32,
/// trecho da barra de caminho que receberá o soltar (issue #152)
pub drop_seg: i32,
pub side_insert: i32,
pub side_dragging: bool,
pub side_press: i32,
pub side_press_pt: Ponto,
pub side_resize: bool,
pub side_width_set: bool,
pub side_cloud: bool,
pub side_drives: bool,
pub side_tags: bool,
pub favs: Vec<Fav>,
pub favs_loaded: bool,
pub drag: Drag,
pub drag_start_px: POINT,
pub own_drag: bool,
pub band_start: Ponto,
pub band_end: Ponto,
pub band_base: Vec<bool>,
pub band_mods: u32,
pub press_item: i32,
pub press_was_selected: bool,
pub press_was_only: bool,
pub slow_rename_idx: i32,
pub slider_drag: bool,
pub show_thumbs: bool,
pub rel_dates: bool,
pub thumb_fading: bool,
pub pack_bmps: HashMap<String, Option<ID2D1Bitmap>>,
pub fmt_cache: HashMap<String, IDWriteTextFormat>,
pub path_bar: bool,
/// issue #302: Enter abre o item, F2 renomeia (como no Explorador); padrão: Enter renomeia, como no Mac
pub enter_abre: bool,
/// Alt segurado revela a barra de caminho por um instante (Option no Mac, issue #152)
pub alt_path: bool,
pub path_bar_user: bool,
pub path_segs: Vec<PathSeg>,
pub view_opts: bool,
pub opt_ctls: Vec<OptCtl>,
pub opt_slider_drag: bool,
pub trash_press: bool,
pub typed: String,
pub typed_at: u32,
// Ir para a Pasta
pub go_open: bool,
pub go: TextField,
pub go_sugg: Vec<String>,
pub go_sel: i32,
// Quick Look
pub ql: bool,
pub ql_closing: bool,
pub ql_opened_at: u32,
pub ql_closed_at: u32,
pub ql_from: RectF,
pub ql_ext_path: String,
pub ql_text_path: String,
pub ql_lines: Vec<String>,
pub ql_text_scroll: f32,
pub ql_text_max: f32,
pub ql_text_shown: bool,
pub ql_media_path: String,
pub ql_media_title: String,
pub ql_media_artist: String,
pub ql_mouse_at: u32,
pub ql_seek_drag: bool,
pub ql_zoom: f32,
pub ql_pan: (f32, f32),
pub ql_pan0: (f32, f32),
pub ql_pan_from: Ponto,
pub ql_panning: bool,
pub ql_zoom_path: String,
pub ql_zoom_fill: bool,
pub ql_zoom_wh: (u32, u32),
pub ql_body: RectF,
// janela
pub frente_ate: u32,
pub frente_input: bool,
pub f: Fonts,
}
static ST: Global<Option<S>> = Global::new(None);
pub fn s() -> &'static mut S {
ST.get().as_mut().expect("estado do Finder")
}
pub fn s_pronto() -> bool {
ST.get().is_some()
}
pub fn init(f: Fonts, ui_family: String, icon_family: String, body_weight: DWRITE_FONT_WEIGHT) {
let z = rf(0.0, 0.0, 0.0, 0.0);
*ST.get() = Some(S {
hwnd: HWND::default(),
rt: None,
scale: 1.0,
dark: false,
win_active: true,
hover_lights: false,
press_light: -1,
tahoe: false,
tahoe_lay: false,
icon: 64.0,
label_size: 12.0,
row_text_size: 13.0,
side: Vec::new(),
side_scroll: 0.0,
searching: false,
search: TextField::default(),
search_focus: false,
search_busy: false,
search_scope: 0,
search_home: String::new(),
tag_view: -1,
folder: String::new(),
flash: String::new(),
flash_at: 0,
kind_cache: HashMap::new(),
group_by: GroupBy::None,
group_main: GroupBy::None,
group_dl: -1,
in_downloads: false,
sort_col: SortCol::Name,
sort_asc: true,
items: Vec::new(),
all: Vec::new(),
rows: Vec::new(),
row_of_item: Vec::new(),
rows_dirty: true,
list_large: true,
col_size: true,
col_kind: true,
col_date: true,
col_created: false,
col_icons: true,
col_preview: true,
col_trail: Vec::new(),
child_path: String::new(),
child_items: Vec::new(),
gallery_x: 0.0,
scroll: 0.0,
scroll_target: 0.0,
scroll_anim: false,
scroll_t: std::time::Instant::now(),
scroll_shown_at: 0,
scroll_drag: false,
scroll_drag_off: 0.0,
scroll_hover: false,
view: View::Icons,
default_view: View::Icons,
tabs: vec![TabState { tag_view: -1, ..Default::default() }],
cur_tab: 0,
hover_tab: -1,
lay: Lay::default(),
foto: None,
focus: -1,
anchor: -1,
rename: TextField::default(),
rename_idx: -1,
caret_on: true,
ui_family,
icon_family,
body_weight,
images: HashMap::new(),
img_born: HashMap::new(),
requested: HashSet::new(),
kinds: HashMap::new(),
gen: 1,
back: Vec::new(),
fwd: Vec::new(),
emblems: Vec::new(),
show_hidden: false,
recent_folder: String::new(),
notify_id: 0,
select_after_reload: String::new(),
rename_after_reload: false,
nav_ms: 0,
undo: Vec::new(),
pick: Picker { overwrite: true, ..Default::default() },
pick_name: TextField::default(),
pick_name_focus: false,
pick_view: -1,
pick_win: RECT::default(),
saved_win: RECT::default(),
exit_code: 0,
cover_flow: false,
cf_hits: Vec::new(),
hover_side: -1,
hover_tool: -1,
press_tool: -1,
hover_title: false,
drop_hi: -1,
drop_side_row: -1,
drop_seg: -1,
side_insert: -1,
side_dragging: false,
side_press: -1,
side_press_pt: pt(0.0, 0.0),
side_resize: false,
side_width_set: false,
side_cloud: true,
side_drives: true,
side_tags: true,
favs: Vec::new(),
favs_loaded: false,
drag: Drag::None,
drag_start_px: POINT::default(),
own_drag: false,
band_start: pt(0.0, 0.0),
band_end: pt(0.0, 0.0),
band_base: Vec::new(),
band_mods: 0,
press_item: -1,
press_was_selected: false,
press_was_only: false,
slow_rename_idx: -1,
slider_drag: false,
show_thumbs: true,
rel_dates: true,
thumb_fading: false,
pack_bmps: HashMap::new(),
fmt_cache: HashMap::new(),
path_bar: false,
enter_abre: false,
alt_path: false,
path_bar_user: false,
path_segs: Vec::new(),
view_opts: false,
opt_ctls: Vec::new(),
opt_slider_drag: false,
trash_press: false,
typed: String::new(),
typed_at: 0,
go_open: false,
go: TextField::default(),
go_sugg: Vec::new(),
go_sel: -1,
ql: false,
ql_closing: false,
ql_opened_at: 0,
ql_closed_at: 0,
ql_from: z,
ql_ext_path: String::new(),
ql_text_path: String::new(),
ql_lines: Vec::new(),
ql_text_scroll: 0.0,
ql_text_max: 0.0,
ql_text_shown: false,
ql_media_path: String::new(),
ql_media_title: String::new(),
ql_media_artist: String::new(),
ql_mouse_at: 0,
ql_seek_drag: false,
ql_zoom: 1.0,
ql_pan: (0.0, 0.0),
ql_pan0: (0.0, 0.0),
ql_pan_from: pt(0.0, 0.0),
ql_panning: false,
ql_zoom_path: String::new(),
ql_zoom_fill: false,
ql_zoom_wh: (0, 0),
ql_body: z,
frente_ate: 0,
frente_input: false,
f,
});
}