Skip to content

Windows shell replacement in Rust: taskbar, file manager, NTFS search, task manager, disk cleaner. One installer exe.

Rust

Release v0.3.0

Lemxycf64d35e8633
diff --git a/Cargo.lock b/Cargo.lock
index 29d74f6..3d7c458 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -154,7 +154,7 @@ dependencies = [
[[package]]
name = "plugin-launcher"
-version = "0.2.1"
+version = "0.3.0"
dependencies = [
"embed-resource",
"windows-sys",
@@ -223,6 +223,7 @@ dependencies = [
"windows",
"windows-core",
"windows-sys",
+ "winrust-common",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index e8305d4..afd16e9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "plugin-launcher"
-version = "0.2.1"
+version = "0.3.0"
edition = "2024"
[[bin]]
diff --git a/README.md b/README.md
index dc382f0..73825cc 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ English | [Русский](README.ru.md)
**Update:** download the new `WinRust.exe` from the releases page, run it as administrator and press **Update WinRust**. Installed plugins are updated, missing ones installed; your settings and the saved original Windows values stay.
-The installer is in English. The **Русский** button in its corner (or "Language" in the bar's right-click menu) switches every WinRust program to Russian.
+The installer is in English. The **Русский** button in its corner (or "WinRust apps in Русский" in the bar's right-click menu) switches every WinRust program to Russian.
## Remove
@@ -41,6 +41,19 @@ The installer is in English. The **Русский** button in its corner (or "La
Every change is reversible: uninstall puts back the values that were there before.
+## Styles
+
+The gear at the left end of the bar opens **Style**. The choice applies at once to the bar, the file manager (rust-explorer) and the search window (Alt+Space):
+
+| Style | Look |
+|---|---|
+| **Normal** | Windows 11 blue, the bar at the bottom |
+| **Terminal** | Green on black, Consolas, square corners |
+| **Floating dock** | A pill-shaped bar in the middle; maximized windows get the whole screen, the dock slides away over them and comes back at the bottom edge |
+| **Tiling** | A thin bar at the top, amber accent, square corners; "Tile the windows" puts the open windows side by side |
+
+The choice is stored in `%ProgramData%\WinRust\style.txt`.
+
## Benchmark
One-off measurements on one machine (Windows 11 IoT Enterprise 10.0.26300, RTX 4060 Laptop, NTFS). Treat them as orders of magnitude, not lab numbers.
@@ -83,7 +96,7 @@ src/ the installer (plugin-launcher.exe)
main.rs the plugin table PLUGINS: name, texts, install/uninstall pair, icon
install/ what each plugin changes and how it is undone (one file per plugin)
cli.rs, ui.rs the command line and the window; both call the same install functions
-common/ winrust-common: language switch (t!/tf!) and the NTFS MFT reader, shared by the programs
+common/ winrust-common: language switch (t!/tf!), UI styles and palettes, reg.exe output parser, NTFS MFT reader
plugins/ sources of every plugin, each its own crate
ReShell/ reshell (desktop hotkeys, topbar safety net), ships with topbar
payload.txt the exes embedded into the installer, and where the build puts them
diff --git a/README.ru.md b/README.ru.md
index 462b1da..1296ef6 100644
--- a/README.ru.md
+++ b/README.ru.md
@@ -18,7 +18,7 @@
**Обновление:** скачайте новый `WinRust.exe` со страницы релизов, запустите от имени администратора и нажмите **Update WinRust** («Обновить WinRust» в русском режиме). Установленные плагины обновятся, недостающие поставятся; ваши настройки и сохранённые исходные значения Windows остаются.
-Установщик открывается на английском. Кнопка **Русский** в его углу (или «Язык» в меню панели по правому клику) переключает на русский все программы WinRust.
+Установщик открывается на английском. Кнопка **Русский** в его углу (или «Программы WinRust на English» в меню панели по правому клику) переключает язык всех программ WinRust.
## Удаление
@@ -41,6 +41,19 @@
Все изменения обратимы: удаление возвращает те значения, что были до установки.
+## Стили
+
+Шестерёнка в левом краю панели открывает меню **Стиль**. Выбор сразу применяется к панели, файловому менеджеру (rust-explorer) и окну поиска (Alt+Space):
+
+| Стиль | Как выглядит |
+|---|---|
+| **Обычный** | Синий, как в Windows 11, панель внизу |
+| **Терминал** | Зелёный на чёрном, шрифт Consolas, прямые углы |
+| **Плавающий док** | Панель-пилюля по центру; развёрнутые окна занимают весь экран, док уезжает из-под них и возвращается у нижнего края |
+| **Тайлинг** | Тонкая панель сверху, янтарный акцент, прямые углы; «Разложить окна плиткой» ставит открытые окна рядом |
+
+Выбор хранится в `%ProgramData%\WinRust\style.txt`.
+
## Бенчмарк
Одноразовые замеры на одной машине (Windows 11 IoT Enterprise 10.0.26300, RTX 4060 Laptop, NTFS). Это порядок величин, а не лабораторные цифры.
@@ -83,7 +96,7 @@ src/ установщик (plugin-launcher.exe)
main.rs таблица плагинов PLUGINS: имя, тексты, пара install/uninstall, значок
install/ что каждый плагин меняет в системе и как это откатывается (файл на плагин)
cli.rs, ui.rs командная строка и окно; оба вызывают одни и те же функции установки
-common/ winrust-common: переключатель языка (t!/tf!) и чтение MFT, общие для программ
+common/ winrust-common: переключатель языка (t!/tf!), стили и палитры, разбор вывода reg.exe, чтение MFT
plugins/ исходники всех плагинов, каждый отдельный crate
ReShell/ reshell (хоткеи рабочих столов, страховка topbar), ставится вместе с topbar
payload.txt какие exe вшиваются в установщик и где их кладёт сборка
diff --git a/ROADMAP.md b/ROADMAP.md
index 4adc143..efb4f1e 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -15,6 +15,7 @@ Each item says how far it was checked: **tests** (unit tests), **built** (compil
- Command line: `list | install <plugin> --yes | update <plugin> | uninstall <plugin> | rollback --yes`, exit codes 0/1/2; the window and the command line call the same functions. Only the read-only commands were run. *ran (partly)*
- `update` and `scripts\update-plugin.ps1`: reinstall from `payload\` on disk without rebuilding the installer. *ran*
- English by default, Русский/English switch in the installer and in the bar menu; the choice is stored in `%ProgramData%\WinRust\lang.txt`. *tests*
+- Review fixes (v0.3.0): rs-du keeps its quarantine list next to its exe (admin-only), `payload\` two levels up only from `target\release`, rtaskmgr and rust-explorer save and restore another program's Task Manager / folder settings, rust-search brings Windows Search back before removing its files, DiagTrack is left to debloat, one `reg query` parser with a test. *tests, built*
- Code layout: one cargo workspace; the installer split into `install/` (one file per plugin), `cli.rs`, `ui.rs`; shared `winrust-common` crate (language switch, MFT reader); one `payload.txt` list for the build and the scripts; CI on GitHub Actions. *tests*
### Plugins
@@ -23,6 +24,8 @@ Each item says how far it was checked: **tests** (unit tests), **built** (compil
- **topbar**: Windows 11-style bottom bar instead of the taskbar; `topbar.exe --restore` brings the taskbar back. Installs with it: reshell hotkeys, rs-du, the PowerShell profile block (`src/install/profile.ps1`, Windows PowerShell 5.1 and pwsh 7). *ran; the profile block only on a temporary profile*
- **reshell safety net**: if topbar is not running while the taskbar is hidden, twice in a row (~10 s), it runs `topbar.exe --restore`. *tests; killing topbar was not tried*
- **reshell hotkeys**: Win+D (show desktop) and Win+I (Settings) work without Explorer, like Win+E (v0.2.1). *ran*
+- **Styles** (v0.3.0): a gear at the left end of the bar switches Normal / Terminal / Floating dock / Tiling; the bar, rust-explorer and the search window repaint at once (a broadcast message, `%ProgramData%\WinRust\style.txt`). The dock reserves no screen space and slides away from maximized windows; Tiling puts the bar at the top and can tile the windows. *ran*
+- **topbar look** (v0.3.0): the network icon is drawn (Wi-Fi arcs by signal, a cross when offline, "!" when there is no internet, per Windows' connectivity hint); new Wi-Fi panel (status, connected card with its own Disconnect button, saved/open networks, rows fade in); text-only menus with key hints; input language picker (left click on ENG/RUS); the tray flyout fades in and its chevron turns. *ran*
- **rust-explorer**: file manager (tabs, icons, IFileOperation copy/paste/delete, shell context menu, drag and drop), draws the desktop, turns off Explorer as the shell with `rs-shell --overlay` (90 s after sign-in at the latest: Windows 26300 no longer writes the autostart markers it used to wait for, v0.2.1), trims services. *tests, ran*
- **rs-du**: disk cleaner (MFT analysis, caches, `target`/`node_modules`, recycle bin, 30-day quarantine), started from the bar menu. *tests*
- **wiztree**: disk-usage treemap from the MFT. *tests (layout only); not run on a live disk*
diff --git a/ROADMAP.ru.md b/ROADMAP.ru.md
index 9e70971..c645b03 100644
--- a/ROADMAP.ru.md
+++ b/ROADMAP.ru.md
@@ -7,6 +7,7 @@
## Сделано
### Установщик
+- Исправления после ревью (v0.3.0): rs-du хранит список карантина рядом со своим exe (писать туда может только администратор), `payload\` двумя уровнями выше берётся только из `target\release`, rtaskmgr и rust-explorer сохраняют и возвращают чужие настройки диспетчера задач и папок, rust-search сначала возвращает поиск Windows и только потом удаляет свои файлы, DiagTrack оставлен debloat, один разбор вывода `reg query` с тестом. *тесты, собрано*
- Один `plugin-launcher.exe`, в который вшиты все плагины (распаковка в Program Files, не в %TEMP%), статический CRT, тёмное окно на Win32/GDI. *запускалось*
- «Install WinRust» ставит недостающее по порядку (topbar раньше rust-explorer), когда всё стоит, обновляет; «Удалить всё» удаляет в обратном порядке. *собрано*
- Сбой установки откатывает свои изменения (кроме обновления рабочей копии); исходные значения (WSearch, строка поиска, настройки Проводника, службы) сохраняются в `HKLM\SOFTWARE\plugin-launcher\<плагин>` и возвращаются при удалении; несмертельные ошибки пишутся в `%ProgramData%\plugin-launcher\install.log`. *собрано*
@@ -23,6 +24,8 @@
- **topbar**: нижняя панель в стиле Windows 11 вместо панели задач; `topbar.exe --restore` возвращает панель задач. Вместе с ним ставятся хоткеи reshell, rs-du, блок профиля PowerShell (`src/install/profile.ps1`, Windows PowerShell 5.1 и pwsh 7). *запускалось; блок профиля только на временном профиле*
- **Страховка reshell**: если topbar не запущен, а панель задач скрыта, два раза подряд (~10 с), запускает `topbar.exe --restore`. *тесты; сценарий «убить topbar» не проверялся*
- **Хоткеи reshell**: Win+D (показать рабочий стол) и Win+I (Параметры) работают без Проводника, как Win+E (v0.2.1). *запускалось*
+- **Стили** (v0.3.0): шестерёнка в левом краю панели переключает Обычный / Терминал / Плавающий док / Тайлинг; панель, rust-explorer и окно поиска перекрашиваются сразу (широковещательное сообщение, `%ProgramData%\WinRust\style.txt`). Док не занимает места на экране и уезжает из-под развёрнутых окон; Тайлинг ставит панель наверх и умеет раскладывать окна плиткой. *запускалось*
+- **Вид topbar** (v0.3.0): значок сети рисуется сам (дуги Wi‑Fi по сигналу, крестик без сети, «!» без интернета, по данным Windows о подключении); новая панель Wi‑Fi (статус, карточка подключённой сети с отдельной кнопкой «Отключиться», сохранённые и открытые сети, строки появляются по очереди); меню только из текста с подсказками клавиш; выбор языка ввода (левый клик по ENG/RUS); трей проявляется с анимацией, стрелка поворачивается. *запускалось*
- **rust-explorer**: файловый менеджер (вкладки, иконки, копирование/вставка/удаление через IFileOperation, контекстное меню, перетаскивание), рисует рабочий стол, отключает Проводник как оболочку через `rs-shell --overlay` (не позже 90 с после входа: Windows 26300 больше не пишет отметки автозагрузки, которых он ждал, v0.2.1), урезает службы. *тесты, запускалось*
- **rs-du**: чистильщик диска (анализ MFT, кеши, `target`/`node_modules`, корзина, карантин на 30 дней), запускается из меню панели. *тесты*
- **wiztree**: карта занятого места по MFT. *тесты (только раскладка); на живом диске не запускался*
diff --git a/common/src/lib.rs b/common/src/lib.rs
index fde001f..0f31223 100644
--- a/common/src/lib.rs
+++ b/common/src/lib.rs
@@ -11,6 +11,7 @@ use std::{
pub mod desktop;
pub mod mft;
pub mod reg;
+pub mod style;
static LANG: AtomicU8 = AtomicU8::new(0); // 0 = not read yet, 1 = English, 2 = Russian
diff --git a/common/src/style.rs b/common/src/style.rs
new file mode 100644
index 0000000..4c27882
--- /dev/null
+++ b/common/src/style.rs
@@ -0,0 +1,143 @@
+//! The UI style shared by the WinRust programs: %ProgramData%\WinRust\style.txt holds its name (the topbar gear menu writes it).
+//! Programs re-read it at most once a second and repaint at once on the broadcast `set_style` sends (`msg()`).
+use std::{
+ path::PathBuf,
+ sync::atomic::{AtomicU8, AtomicU32, AtomicU64, Ordering::Relaxed},
+};
+use windows_sys::Win32::UI::WindowsAndMessaging::{HWND_BROADCAST, PostMessageW, RegisterWindowMessageW};
+
+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
+pub enum Style {
+ Normal,
+ Terminal, // monospace, green on black, square corners
+ Dock, // the bar is a floating pill in the middle
+ Tiling, // a thin status strip at the top, square corners, windows side by side
+}
+
+pub const ALL: [Style; 4] = [Style::Normal, Style::Terminal, Style::Dock, Style::Tiling];
+
+impl Style {
+ pub fn name(self) -> &'static str {
+ match self {
+ Style::Normal => "normal",
+ Style::Terminal => "terminal",
+ Style::Dock => "dock",
+ Style::Tiling => "tiling",
+ }
+ }
+ /// Unknown or empty text (no file yet, a hand edit) is the normal style.
+ pub fn parse(s: &str) -> Style {
+ ALL.into_iter().find(|v| v.name().eq_ignore_ascii_case(s.trim())).unwrap_or(Style::Normal)
+ }
+ /// Square corners everywhere.
+ pub fn square(self) -> bool {
+ matches!(self, Style::Terminal | Style::Tiling)
+ }
+ pub fn mono(self) -> bool {
+ matches!(self, Style::Terminal | Style::Tiling)
+ }
+}
+
+static CUR: AtomicU8 = AtomicU8::new(u8::MAX); // index into ALL; MAX = not read yet
+static READ_AT: AtomicU64 = AtomicU64::new(0); // when the file was last read, ms since the epoch
+
+fn file() -> Option<PathBuf> {
+ std::env::var_os("ProgramData").map(|p| PathBuf::from(p).join("WinRust").join("style.txt"))
+}
+
+fn now_ms() -> u64 {
+ std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map_or(0, |d| d.as_millis() as u64)
+}
+
+fn store(s: Style) {
+ CUR.store(ALL.iter().position(|&v| v == s).unwrap_or(0) as u8, Relaxed);
+ READ_AT.store(now_ms(), Relaxed);
+}
+
+/// Reads the file again now (on the "style changed" broadcast).
+pub fn reload() {
+ store(Style::parse(&file().and_then(|f| std::fs::read_to_string(f).ok()).unwrap_or_default()));
+}
+
+/// The current style. The file is read again at most once a second, so a program that missed the broadcast still follows.
+pub fn style() -> Style {
+ if CUR.load(Relaxed) == u8::MAX || now_ms().saturating_sub(READ_AT.load(Relaxed)) > 1000 {
+ reload();
+ }
+ ALL[CUR.load(Relaxed) as usize % ALL.len()]
+}
+
+/// Switches this process, writes the choice and tells the other WinRust windows to repaint in it.
+pub fn set_style(s: Style) {
+ store(s);
+ if let Some(f) = file() {
+ let _ = std::fs::create_dir_all(f.parent().unwrap());
+ let _ = std::fs::write(f, s.name());
+ }
+ unsafe { PostMessageW(HWND_BROADCAST, msg(), 0, 0) };
+}
+
+/// The broadcast message a window gets when the style changed: call `reload()` and repaint.
+pub fn msg() -> u32 {
+ static M: AtomicU32 = AtomicU32::new(0);
+ match M.load(Relaxed) {
+ 0 => {
+ let n: Vec<u16> = "WinRustStyleChanged\0".encode_utf16().collect();
+ let m = unsafe { RegisterWindowMessageW(n.as_ptr()) };
+ M.store(m, Relaxed);
+ m
+ }
+ m => m,
+ }
+}
+
+/// Colours of one style, as COLORREF (0x00BBGGRR) like GDI wants them.
+pub struct Pal {
+ pub bg: u32,
+ pub line: u32,
+ pub hover: u32,
+ pub active: u32,
+ pub accent: u32,
+ pub text: u32,
+ pub dim: u32,
+}
+
+pub const fn rgb(r: u8, g: u8, b: u8) -> u32 {
+ r as u32 | (g as u32) << 8 | (b as u32) << 16
+}
+
+/// In the order of `ALL`.
+pub const PALS: [Pal; 4] = [
+ // normal: Windows 11 blue
+ Pal { bg: rgb(24, 30, 44), line: rgb(44, 52, 72), hover: rgb(40, 48, 68), active: rgb(52, 61, 84), accent: rgb(76, 194, 255), text: rgb(255, 255, 255), dim: rgb(150, 158, 175) },
+ // terminal: green on black
+ Pal { bg: rgb(10, 15, 10), line: rgb(40, 72, 40), hover: rgb(20, 40, 20), active: rgb(28, 56, 28), accent: rgb(91, 215, 91), text: rgb(207, 232, 207), dim: rgb(100, 145, 100) },
+ // dock: graphite with violet
+ Pal { bg: rgb(27, 29, 34), line: rgb(50, 53, 62), hover: rgb(42, 45, 53), active: rgb(52, 55, 66), accent: rgb(167, 139, 250), text: rgb(255, 255, 255), dim: rgb(154, 160, 170) },
+ // tiling: dark with amber
+ Pal { bg: rgb(17, 19, 23), line: rgb(40, 44, 52), hover: rgb(30, 34, 41), active: rgb(38, 43, 52), accent: rgb(229, 192, 123), text: rgb(215, 218, 224), dim: rgb(110, 117, 130) },
+];
+
+pub fn pal() -> &'static Pal {
+ &PALS[ALL.iter().position(|&s| s == style()).unwrap_or(0)]
+}
+
+/// The UI font of the current style.
+pub fn ui_face() -> &'static str {
+ if style().mono() { "Consolas" } else { "Segoe UI" }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn names_round_trip_and_junk_is_normal() {
+ for s in ALL {
+ assert_eq!(Style::parse(s.name()), s);
+ }
+ assert_eq!(Style::parse(" Tiling\r\n"), Style::Tiling);
+ assert_eq!(Style::parse(""), Style::Normal);
+ assert_eq!(Style::parse("neon"), Style::Normal);
+ }
+}
diff --git a/plugins/rust-explorer/Cargo.toml b/plugins/rust-explorer/Cargo.toml
index bd852c6..6d9f2a6 100644
--- a/plugins/rust-explorer/Cargo.toml
+++ b/plugins/rust-explorer/Cargo.toml
@@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2024"
[dependencies]
+winrust-common = { path = "../../common" }
windows = { version = "0.62.2", features = ["Win32_Foundation", "Win32_Graphics_Gdi", "Win32_System_Com_StructuredStorage", "Win32_System_DataExchange", "Win32_System_Memory", "Win32_System_Ole", "Win32_System_SystemServices", "Win32_UI_Shell", "Win32_UI_Shell_Common", "Win32_UI_WindowsAndMessaging", "Win32_System_Com"] }
windows-core = "0.62"
windows-sys = { version = "0.61.2", features = ["Win32_Foundation", "Win32_Graphics_Gdi", "Win32_Storage_FileSystem", "Win32_System_LibraryLoader", "Win32_System_Registry", "Win32_System_Time", "Win32_System_SystemInformation", "Win32_Graphics_Dwm", "Win32_Graphics_GdiPlus", "Win32_UI_Controls", "Win32_UI_Input_KeyboardAndMouse", "Win32_UI_Shell", "Win32_UI_WindowsAndMessaging"] }
diff --git a/plugins/rust-explorer/src/main.rs b/plugins/rust-explorer/src/main.rs
index 2e21c3e..87adb1a 100644
--- a/plugins/rust-explorer/src/main.rs
+++ b/plugins/rust-explorer/src/main.rs
@@ -921,6 +921,12 @@ unsafe extern "system" fn edit_proc(h: HWND, m: u32, wp: WPARAM, lp: LPARAM) ->
unsafe extern "system" fn proc(h: HWND, m: u32, wp: WPARAM, lp: LPARAM) -> LRESULT {
unsafe {
+ if m == winrust_common::style::msg() {
+ // the topbar switched the WinRust style: take it now (the desktop's list keeps its see-through colours)
+ winrust_common::style::reload();
+ if desk() { InvalidateRect(h, ptr::null(), 1); } else { ui::restyle(h); }
+ return 0;
+ }
match m {
WM_CREATE => {
let inst = GetModuleHandleW(ptr::null());
@@ -932,7 +938,7 @@ unsafe extern "system" fn proc(h: HWND, m: u32, wp: WPARAM, lp: LPARAM) -> LRESU
tab = CreateWindowExW(0, w("RxChrome").as_ptr(), ptr::null(), WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN, 0, 0, 0, 0, h, 0 as _, inst, ptr::null());
ui::nav_init(CreateWindowExW(0, w("RxNav").as_ptr(), ptr::null(), WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, h, 0 as _, inst, ptr::null()));
edit = CreateWindowExW(0, w("EDIT").as_ptr(), ptr::null(), WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL as u32, 0, 0, 0, 0, tab, 0 as _, inst, ptr::null());
- put(edit, WM_SETFONT, ui::font(14, 400, "Segoe UI") as usize, 1);
+ put(edit, WM_SETFONT, ui::font(14, 400, ui::ui_face()) as usize, 1);
EDIT_OLD.store(SetWindowLongPtrW(edit, GWLP_WNDPROC, edit_proc as *const () as isize), std::sync::atomic::Ordering::Relaxed);
}
let view = if desk() { LVS_ICON } else { LVS_REPORT };
@@ -954,7 +960,7 @@ unsafe extern "system" fn proc(h: HWND, m: u32, wp: WPARAM, lp: LPARAM) -> LRESU
let (cw, ch) = (GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
WALL.set((wall::load(cw, ch), cw, ch));
// grey (not ClearType) smoothing: on a live wallpaper the labels sit on a colour key, where ClearType leaves coloured fringes
- put(list, WM_SETFONT, windows_sys::Win32::Graphics::Gdi::CreateFontW(-ui::sc(13), 0, 0, 0, 400, 0, 0, 0, 1, 0, 0, 4, 0, w("Segoe UI").as_ptr()) as usize, 1);
+ put(list, WM_SETFONT, windows_sys::Win32::Graphics::Gdi::CreateFontW(-ui::sc(13), 0, 0, 0, 400, 0, 0, 0, 1, 0, 0, 4, 0, w(ui::ui_face()).as_ptr()) as usize, 1);
// like explorer's desktop: wallpaper apps look for a SHELLDLL_DefView under Progman
CreateWindowExW(0, w("SHELLDLL_DefView").as_ptr(), ptr::null(), WS_CHILD, 0, 0, 0, 0, h, 0 as _, inst, ptr::null());
SetTimer(h, 7, 2000, None); // live wallpaper on / off (desk::check_live)
@@ -1197,7 +1203,7 @@ fn main() {
let cls = w("RustExplorer");
let desktop = env::args().nth(1).as_deref() == Some("--desktop");
// desktop without a wallpaper file shows black, not window white
- let bg = if desktop { GetStockObject(BLACK_BRUSH) as _ } else { windows_sys::Win32::Graphics::Gdi::CreateSolidBrush(ui::BG) };
+ let bg = if desktop { GetStockObject(BLACK_BRUSH) as _ } else { windows_sys::Win32::Graphics::Gdi::CreateSolidBrush(ui::pal().bg) };
RegisterClassW(&WNDCLASSW { lpfnWndProc: Some(ui::proc), hInstance: inst, lpszClassName: w("RxChrome").as_ptr(), hCursor: LoadCursorW(0 as _, IDC_ARROW), ..std::mem::zeroed() });
RegisterClassW(&WNDCLASSW { lpfnWndProc: Some(ui::nav_proc), hInstance: inst, lpszClassName: w("RxNav").as_ptr(), hCursor: LoadCursorW(0 as _, IDC_ARROW), ..std::mem::zeroed() });
RegisterClassW(&WNDCLASSW { lpfnWndProc: Some(proc), hInstance: inst, lpszClassName: cls.as_ptr(), hCursor: LoadCursorW(0 as _, IDC_ARROW), hbrBackground: bg, ..std::mem::zeroed() });
diff --git a/plugins/rust-explorer/src/ui.rs b/plugins/rust-explorer/src/ui.rs
index 4cc18bd..5f6a284 100644
--- a/plugins/rust-explorer/src/ui.rs
+++ b/plugins/rust-explorer/src/ui.rs
@@ -7,16 +7,11 @@ use std::{cell::Cell, collections::HashMap, path::Path};
use windows_sys::Win32::{Graphics::{Dwm::DwmSetWindowAttribute, Gdi::*}, System::{LibraryLoader::{GetProcAddress, LoadLibraryW}, SystemInformation::GetTickCount64}, UI::Input::KeyboardAndMouse::{GetFocus, TRACKMOUSEEVENT, TME_LEAVE, TrackMouseEvent}};
pub const fn rgb(r: u8, g: u8, b: u8) -> u32 { r as u32 | (g as u32) << 8 | (b as u32) << 16 }
-pub const BG: u32 = rgb(24, 30, 44);
-pub const LISTBG: u32 = rgb(19, 24, 36);
-pub const PILL: u32 = rgb(16, 20, 30);
-pub const LINE: u32 = rgb(44, 52, 72);
-pub const HOVER: u32 = rgb(40, 48, 68);
-pub const ACTIVE: u32 = rgb(52, 61, 84);
-pub const ACCENT: u32 = rgb(76, 194, 255);
-pub const TEXT: u32 = rgb(255, 255, 255);
-pub const DIM: u32 = rgb(150, 158, 175);
-pub const OFF: u32 = rgb(80, 88, 105);
+// The colours come from the WinRust style the topbar gear picks (normal, terminal, dock, tiling): the same palette as the bar.
+pub use winrust_common::style::{pal, ui_face};
+pub fn listbg() -> u32 { mix(pal().bg, 0, 0.22) }
+pub fn pill() -> u32 { mix(pal().bg, 0, 0.35) }
+pub fn off() -> u32 { mix(pal().dim, pal().bg, 0.45) }
pub const CHROME_H: i32 = 88;
pub const STATUS_H: i32 = 26;
@@ -128,10 +123,10 @@ pub fn dark_title(h: HWND) {
unsafe {
let set = |attr: u32, v: i32| { DwmSetWindowAttribute(h, attr, &v as *const _ as _, 4); };
set(20, 1); // immersive dark mode
- set(33, 2); // round corners
- set(35, BG as i32); // caption
- set(36, TEXT as i32); // caption text
- set(34, LINE as i32); // border
+ set(33, if winrust_common::style::style().square() { 1 } else { 2 }); // round corners, square in the terminal and tiling styles
+ set(35, pal().bg as i32); // caption
+ set(36, pal().text as i32); // caption text
+ set(34, pal().line as i32); // border
}
}
@@ -145,14 +140,37 @@ pub fn dark_mode() {
}
}
+/// The WinRust style changed (the topbar's broadcast): the lists take the new colours and font, everything repaints.
+pub unsafe fn restyle(h: HWND) {
+ unsafe extern "system" fn each(c: HWND, _: LPARAM) -> i32 {
+ let mut cls = [0u16; 32];
+ let n = GetClassNameW(c, cls.as_mut_ptr(), 32).max(0) as usize;
+ if String::from_utf16_lossy(&cls[..n]) == "SysListView32" {
+ style_list(c);
+ }
+ 1
+ }
+ EnumChildWindows(h, Some(each), 0);
+ // the list rows' cached fonts and the title bar follow too
+ let (a, b) = FONTS.replace((0, 0));
+ for f in [a, b].into_iter().filter(|&f| f != 0) {
+ DeleteObject(f as HGDIOBJ);
+ }
+ dark_title(h);
+ // the window class was registered with the old background brush (shows while a pane resizes)
+ let old = SetClassLongPtrW(h, GCLP_HBRBACKGROUND, CreateSolidBrush(pal().bg) as isize);
+ DeleteObject(old as HGDIOBJ);
+ RedrawWindow(h, ptr::null(), ptr::null_mut(), RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN | RDW_FRAME);
+}
+
/// Dark list: themed scrollbars and header, own colours and font, taller rows.
pub fn style_list(list: HWND) {
unsafe {
SetWindowTheme(list, w("DarkMode_Explorer").as_ptr(), ptr::null());
let hdr = SendMessageW(list, LVM_GETHEADER, 0, 0) as HWND;
SetWindowTheme(hdr, w("DarkMode_ItemsView").as_ptr(), ptr::null());
- for (m, c) in [(LVM_SETBKCOLOR, LISTBG), (LVM_SETTEXTBKCOLOR, LISTBG), (LVM_SETTEXTCOLOR, TEXT)] { SendMessageW(list, m, 0, c as isize); }
- SendMessageW(list, WM_SETFONT, font(14, 400, "Segoe UI") as usize, 1);
+ for (m, c) in [(LVM_SETBKCOLOR, listbg()), (LVM_SETTEXTBKCOLOR, listbg()), (LVM_SETTEXTCOLOR, pal().text)] { SendMessageW(list, m, 0, c as isize); }
+ SendMessageW(list, WM_SETFONT, font(14, 400, ui_face()) as usize, 1);
row_height(list, true);
SetWindowSubclass(list, Some(list_sub), 1, 0); // paints the column header (the theme alone leaves it dim)
}
@@ -203,14 +221,14 @@ pub unsafe fn list_draw(lp: LPARAM) -> LRESULT {
CDDS_POSTPAINT => {
if SendMessageW(list, LVM_GETITEMCOUNT, 0, 0) == 0 {
// an empty folder says so instead of showing a blank list
- let (f_big, f_txt) = (font(40, 400, "Segoe MDL2 Assets") as HFONT, font(14, 400, "Segoe UI") as HFONT);
+ let (f_big, f_txt) = (font(40, 400, "Segoe MDL2 Assets") as HFONT, font(14, 400, ui_face()) as HFONT);
SetBkMode(dc, TRANSPARENT as i32);
let mid = cr.bottom / 3;
let of = SelectObject(dc, f_big);
- text(dc, "\u{E8B7}", rc(0, mid - sc(40), cr.right, mid + sc(10)), mix(LISTBG, DIM, 0.5), DT_CENTER);
+ text(dc, "\u{E8B7}", rc(0, mid - sc(40), cr.right, mid + sc(10)), mix(listbg(), pal().dim, 0.5), DT_CENTER);
SelectObject(dc, f_txt);
let msg = if SEARCHING.with_borrow(|s| s.is_some()) { "Nothing found" } else { "This folder is empty" };
- text(dc, msg, rc(0, mid + sc(14), cr.right, mid + sc(40)), DIM, DT_CENTER);
+ text(dc, msg, rc(0, mid + sc(14), cr.right, mid + sc(40)), pal().dim, DT_CENTER);
SelectObject(dc, of);
DeleteObject(f_big);
DeleteObject(f_txt);
@@ -230,7 +248,7 @@ pub unsafe fn list_draw(lp: LPARAM) -> LRESULT {
let mut r = RECT { left: LVIR_BOUNDS as i32, ..std::mem::zeroed() };
SendMessageW(list, LVM_GETITEMRECT, i, &mut r as *mut _ as isize);
let row_r = rc(0, r.top, cr.right, r.bottom);
- let b = CreateSolidBrush(LISTBG);
+ let b = CreateSolidBrush(listbg());
FillRect(dc, &row_r, b);
DeleteObject(b);
let sel = SendMessageW(list, LVM_GETITEMSTATE, i, LVIS_SELECTED as isize) as u32 & LVIS_SELECTED != 0;
@@ -238,13 +256,13 @@ pub unsafe fn list_draw(lp: LPARAM) -> LRESULT {
let focus = GetFocus() == list;
let pill = rc(sc(6), r.top + sc(2), cr.right - sc(6), r.bottom - sc(2));
let bg = match (sel, focus) {
- (true, true) => mix(LISTBG, ACCENT, if hot { 0.26 } else { 0.20 }),
- (true, false) => mix(LISTBG, TEXT, 0.10),
- _ if hot => mix(LISTBG, TEXT, 0.055),
- _ => LISTBG,
+ (true, true) => mix(listbg(), pal().accent, if hot { 0.26 } else { 0.20 }),
+ (true, false) => mix(listbg(), pal().text, 0.10),
+ _ if hot => mix(listbg(), pal().text, 0.055),
+ _ => listbg(),
};
- if bg != LISTBG { fill(dc, pill, bg, sc(10)); }
- if sel { fill(dc, rc(pill.left, pill.top + sc(8), pill.left + sc(3), pill.bottom - sc(8)), if focus { ACCENT } else { DIM }, sc(3)); }
+ if bg != listbg() { fill(dc, pill, bg, sc(10)); }
+ if sel { fill(dc, rc(pill.left, pill.top + sc(8), pill.left + sc(3), pill.bottom - sc(8)), if focus { pal().accent } else { pal().dim }, sc(3)); }
// columns from the header widths (left of the row = minus the horizontal scroll)
let cw: Vec<i32> = (0..4).map(|k| SendMessageW(list, LVM_GETCOLUMNWIDTH, k, 0) as i32).collect();
let x: Vec<i32> = (0..4).map(|k| r.left + cw[..k].iter().sum::<i32>()).collect();
@@ -252,16 +270,16 @@ pub unsafe fn list_draw(lp: LPARAM) -> LRESULT {
let (mut iw, mut ih) = (0, 0);
ImageList_GetIconSize(himl as _, &mut iw, &mut ih);
if icon >= 0 { ImageList_Draw(himl as _, icon, dc, x[0] + sc(16), (r.top + r.bottom - ih) / 2, ILD_TRANSPARENT); }
- if FONTS.get().0 == 0 { FONTS.set((font(14, 400, "Segoe UI"), font(13, 400, "Segoe UI"))); }
+ if FONTS.get().0 == 0 { FONTS.set((font(14, 400, ui_face()), font(13, 400, ui_face()))); }
let (f_name, f_det) = FONTS.get();
SetBkMode(dc, TRANSPARENT as i32);
let of = SelectObject(dc, f_name as HFONT);
let p = Path::new(&name);
let hit_of_search = p.is_absolute(); // search hits are absolute paths: show the name, and where it lies in the type column
let shown = if hit_of_search { p.file_name().map_or(name.clone(), |n| n.to_string_lossy().into_owned()) } else { name.clone() };
- text(dc, &shown, rc(x[0] + sc(16) + iw + sc(12), r.top, x[1] - sc(8), r.bottom), TEXT, DT_LEFT);
+ text(dc, &shown, rc(x[0] + sc(16) + iw + sc(12), r.top, x[1] - sc(8), r.bottom), pal().text, DT_LEFT);
SelectObject(dc, f_det as HFONT);
- let dim = if sel { mix(DIM, TEXT, 0.45) } else { DIM };
+ let dim = if sel { mix(pal().dim, pal().text, 0.45) } else { pal().dim };
text(dc, &friendly_date(time), rc(x[1] + sc(10), r.top, x[2] - sc(8), r.bottom), dim, DT_LEFT);
let kind = if hit_of_search { p.parent().map_or(String::new(), |d| d.to_string_lossy().into_owned()) } else { type_text(&name, is_dir) };
text(dc, &kind, rc(x[2] + sc(10), r.top, x[3] - sc(8), r.bottom), dim, DT_LEFT | DT_PATH_ELLIPSIS);
@@ -318,17 +336,17 @@ unsafe extern "system" fn list_sub(h: HWND, m: u32, wp: WPARAM, lp: LPARAM, _id:
if nm.hdr.hwndFrom == hdr && nm.hdr.code == NM_CUSTOMDRAW {
return match nm.dwDrawStage {
CDDS_PREPAINT => {
- let b = CreateSolidBrush(BG); // the bar behind the columns too
+ let b = CreateSolidBrush(pal().bg); // the bar behind the columns too
FillRect(nm.hdc, &nm.rc, b);
DeleteObject(b);
CDRF_NOTIFYITEMDRAW as isize
}
CDDS_ITEMPREPAINT => {
let (dc, r, i) = (nm.hdc, nm.rc, nm.dwItemSpec);
- let b = CreateSolidBrush(BG);
+ let b = CreateSolidBrush(pal().bg);
FillRect(dc, &r, b);
DeleteObject(b);
- fill(dc, rc(r.right - 1, r.top + sc(8), r.right, r.bottom - sc(8)), LINE, 0);
+ fill(dc, rc(r.right - 1, r.top + sc(8), r.right, r.bottom - sc(8)), pal().line, 0);
let mut buf = [0u16; 128];
let mut it: HDITEMW = std::mem::zeroed();
it.mask = HDI_TEXT;
@@ -337,11 +355,11 @@ unsafe extern "system" fn list_sub(h: HWND, m: u32, wp: WPARAM, lp: LPARAM, _id:
SendMessageW(hdr, HDM_GETITEMW, i, &mut it as *mut _ as isize);
let sorted = SORT_COL.load(Relaxed) == i;
let arrow = if !sorted { "" } else if SORT_ASC.load(Relaxed) { " \u{2191}" } else { " \u{2193}" };
- let f = font(13, if sorted { 600 } else { 400 }, "Segoe UI") as HFONT;
+ let f = font(13, if sorted { 600 } else { 400 }, ui_face()) as HFONT;
let of = SelectObject(dc, f);
SetBkMode(dc, TRANSPARENT as i32);
let align = if i == 3 { DT_RIGHT } else { DT_LEFT }; // the size column is right-aligned like its numbers
- text(dc, &format!("{}{arrow}", wstr(buf.as_ptr())), rc(r.left + sc(10), r.top, r.right - sc(12), r.bottom), if sorted { TEXT } else { DIM }, align);
+ text(dc, &format!("{}{arrow}", wstr(buf.as_ptr())), rc(r.left + sc(10), r.top, r.right - sc(12), r.bottom), if sorted { pal().text } else { pal().dim }, align);
SelectObject(dc, of);
DeleteObject(f);
CDRF_SKIPDEFAULT as isize
@@ -414,6 +432,7 @@ pub fn gdiplus_start() {
/// Fills `r` (right / bottom exclusive) in `c`; `rad` > 0 rounds the corners (rad = corner diameter), anti-aliased.
unsafe fn fill(dc: HDC, r: RECT, c: u32, rad: i32) {
+ let rad = if winrust_common::style::style().square() { 0 } else { rad };
use windows_sys::Win32::Graphics::GdiPlus::*;
let (wd, ht) = ((r.right - r.left) as f32, (r.bottom - r.top) as f32);
if wd <= 0.0 || ht <= 0.0 { return; }
@@ -457,7 +476,7 @@ unsafe fn text(dc: HDC, s: &str, mut r: RECT, c: u32, flags: u32) {
/// A rounded highlight that eases in on hover and flashes in the accent colour on click; `base` is what it sits on.
unsafe fn glow(dc: HDC, key: i32, r: RECT, base: u32, to: u32, rad: i32, on: bool) {
let (t, p) = (hv(key, on), press_t(key));
- if t > 0.01 || p > 0.0 { fill(dc, r, mix(mix(base, to, t), ACCENT, 0.45 * p), rad); }
+ if t > 0.01 || p > 0.0 { fill(dc, r, mix(mix(base, to, t), pal().accent, 0.45 * p), rad); }
}
unsafe fn paint_chrome(hwnd: HWND) {
@@ -471,13 +490,13 @@ unsafe fn paint_chrome(hwnd: HWND) {
BUSY.set(false);
let (dc, bmp) = (CreateCompatibleDC(wdc), CreateCompatibleBitmap(wdc, cr.right, cr.bottom));
let old = SelectObject(dc, bmp);
- let bg = CreateSolidBrush(BG);
+ let bg = CreateSolidBrush(pal().bg);
FillRect(dc, &cr, bg);
DeleteObject(bg);
SetBkMode(dc, TRANSPARENT as i32);
let l = layout(cr.right, labels.len());
let hot = HOT.get();
- let (f_txt, f_glyph, f_small) = (font(13, 400, "Segoe UI") as HFONT, font(16, 400, "Segoe MDL2 Assets") as HFONT, font(12, 400, "Segoe MDL2 Assets") as HFONT);
+ let (f_txt, f_glyph, f_small) = (font(13, 400, ui_face()) as HFONT, font(16, 400, "Segoe MDL2 Assets") as HFONT, font(12, 400, "Segoe MDL2 Assets") as HFONT);
let of = SelectObject(dc, f_txt);
// tabs
@@ -485,36 +504,36 @@ unsafe fn paint_chrome(hwnd: HWND) {
let on = i == active;
let (th, ta) = (hv(TAB + i as i32, hot == TAB + i as i32 || hot == CLOSE + i as i32), hv(1000 + i as i32, on));
let p = press_t(TAB + i as i32);
- fill(dc, *t, mix(mix(mix(BG, HOVER, th), ACTIVE, ta), ACCENT, 0.35 * p), sc(8));
- if ta > 0.01 { fill(dc, rc(t.left + (t.right - t.left) / 2 - sc(12), t.bottom - sc(3), t.left + (t.right - t.left) / 2 + sc(12), t.bottom), mix(ACTIVE, ACCENT, ta), sc(3)); }
+ fill(dc, *t, mix(mix(mix(pal().bg, pal().hover, th), pal().active, ta), pal().accent, 0.35 * p), sc(8));
+ if ta > 0.01 { fill(dc, rc(t.left + (t.right - t.left) / 2 - sc(12), t.bottom - sc(3), t.left + (t.right - t.left) / 2 + sc(12), t.bottom), mix(pal().active, pal().accent, ta), sc(3)); }
SelectObject(dc, f_txt);
- text(dc, &labels[i], rc(t.left + sc(14), t.top, t.right - sc(if labels.len() > 1 { 30 } else { 10 }), t.bottom), mix(DIM, TEXT, ta.max(th)), DT_LEFT);
+ text(dc, &labels[i], rc(t.left + sc(14), t.top, t.right - sc(if labels.len() > 1 { 30 } else { 10 }), t.bottom), mix(pal().dim, pal().text, ta.max(th)), DT_LEFT);
if labels.len() > 1 && (on || th > 0.05) {
let c = l.close[i];
- glow(dc, CLOSE + i as i32, c, mix(BG, ACTIVE, ta), HOVER, sc(6), hot == CLOSE + i as i32);
+ glow(dc, CLOSE + i as i32, c, mix(pal().bg, pal().active, ta), pal().hover, sc(6), hot == CLOSE + i as i32);
SelectObject(dc, f_small);
- text(dc, "\u{E711}", c, mix(DIM, TEXT, if hot == CLOSE + i as i32 { 1.0 } else { 0.4 }), DT_CENTER);
+ text(dc, "\u{E711}", c, mix(pal().dim, pal().text, if hot == CLOSE + i as i32 { 1.0 } else { 0.4 }), DT_CENTER);
}
}
- glow(dc, PLUS, l.plus, BG, HOVER, sc(6), hot == PLUS);
+ glow(dc, PLUS, l.plus, pal().bg, pal().hover, sc(6), hot == PLUS);
SelectObject(dc, f_small);
- text(dc, "\u{E710}", l.plus, DIM, DT_CENTER);
+ text(dc, "\u{E710}", l.plus, pal().dim, DT_CENTER);
// toolbar buttons
SelectObject(dc, f_glyph);
for (k, r, g, enabled) in [(BACK, l.back, "\u{E72B}", can_back), (FWD, l.fwd, "\u{E72A}", can_fwd), (UP, l.up, "\u{E74A}", true), (RELOAD, l.reload, "\u{E72C}", true), (SEARCH, l.search, "\u{E721}", true), (VIEW, l.view, if thumbs { "\u{E8FD}" } else { "\u{E80A}" }, true)] {
- if enabled { glow(dc, k, r, BG, HOVER, sc(8), hot == k); }
- text(dc, g, r, if enabled { TEXT } else { OFF }, DT_CENTER);
+ if enabled { glow(dc, k, r, pal().bg, pal().hover, sc(8), hot == k); }
+ text(dc, g, r, if enabled { pal().text } else { off() }, DT_CENTER);
}
// address pill: accent outline while it is being edited
let focused = !edit.is_null() && GetFocus() == edit;
let f = hv(2000, focused);
- fill(dc, l.pill, mix(LINE, ACCENT, f), sc(18));
- fill(dc, rc(l.pill.left + 1, l.pill.top + 1, l.pill.right - 1, l.pill.bottom - 1), PILL, sc(17));
+ fill(dc, l.pill, mix(pal().line, pal().accent, f), sc(18));
+ fill(dc, rc(l.pill.left + 1, l.pill.top + 1, l.pill.right - 1, l.pill.bottom - 1), pill(), sc(17));
SelectObject(dc, f_glyph);
let searching = SEARCHING.with_borrow(|s| s.clone());
- text(dc, if searching.is_some() { "\u{E721}" } else { "\u{E838}" }, rc(l.pill.left + sc(10), l.pill.top, l.pill.left + sc(38), l.pill.bottom), mix(DIM, ACCENT, f), DT_CENTER);
+ text(dc, if searching.is_some() { "\u{E721}" } else { "\u{E838}" }, rc(l.pill.left + sc(10), l.pill.top, l.pill.left + sc(38), l.pill.bottom), mix(pal().dim, pal().accent, f), DT_CENTER);
// not being edited: the path as clickable parts, like Windows 11 Explorer ("C: > Users > me"); the edit box is hidden
let mut crumbs = vec![];
if !focused {
@@ -522,7 +541,7 @@ unsafe fn paint_chrome(hwnd: HWND) {
let (t, b) = (l.pill.top + sc(5), l.pill.bottom - sc(5));
if let Some(q) = &searching {
SelectObject(dc, f_txt);
- text(dc, &format!("Results for \u{201C}{q}\u{201D}"), rc(x0 + sc(6), l.pill.top, x1, l.pill.bottom), ACCENT, DT_LEFT);
+ text(dc, &format!("Results for \u{201C}{q}\u{201D}"), rc(x0 + sc(6), l.pill.top, x1, l.pill.bottom), pal().accent, DT_LEFT);
} else {
let parts = crumbs_of(&dir);
let width = |s: &str| { let mut r = rc(0, 0, 0, 0); DrawTextW(dc, w(s).as_ptr(), -1, &mut r, DT_CALCRECT | DT_SINGLELINE | DT_NOPREFIX); r.right + sc(16) };
@@ -539,14 +558,14 @@ unsafe fn paint_chrome(hwnd: HWND) {
let last = shown.len().saturating_sub(1);
for (i, (label, path, wd)) in shown.into_iter().enumerate() {
let r = rc(x, t, (x + wd).min(x1), b);
- glow(dc, CRUMB + i as i32, r, PILL, HOVER, sc(8), hot == CRUMB + i as i32);
+ glow(dc, CRUMB + i as i32, r, pill(), pal().hover, sc(8), hot == CRUMB + i as i32);
SelectObject(dc, f_txt);
- text(dc, &label, r, if i == last { TEXT } else { mix(DIM, TEXT, if hot == CRUMB + i as i32 { 1.0 } else { 0.35 }) }, DT_CENTER);
+ text(dc, &label, r, if i == last { pal().text } else { mix(pal().dim, pal().text, if hot == CRUMB + i as i32 { 1.0 } else { 0.35 }) }, DT_CENTER);
crumbs.push((r, path));
x = r.right;
if i < last {
SelectObject(dc, f_small);
- text(dc, "\u{E76C}", rc(x, t, x + chev, b), mix(DIM, PILL, 0.3), DT_CENTER);
+ text(dc, "\u{E76C}", rc(x, t, x + chev, b), mix(pal().dim, pill(), 0.3), DT_CENTER);
x += chev;
}
}
@@ -554,7 +573,7 @@ unsafe fn paint_chrome(hwnd: HWND) {
}
CRUMBS.set(crumbs);
- fill(dc, rc(0, cr.bottom - 1, cr.right, cr.bottom), LINE, 0); // hairline under the chrome
+ fill(dc, rc(0, cr.bottom - 1, cr.right, cr.bottom), pal().line, 0); // hairline under the chrome
BitBlt(wdc, 0, 0, cr.right, cr.bottom, dc, 0, 0, SRCCOPY);
SelectObject(dc, of);
for f in [f_txt, f_glyph, f_small] { DeleteObject(f); }
@@ -572,10 +591,10 @@ pub unsafe fn paint_status(h: HWND) {
let mut cr: RECT = std::mem::zeroed();
GetClientRect(h, &mut cr);
let strip = rc(0, cr.bottom - sc(STATUS_H), cr.right, cr.bottom);
- let bg = CreateSolidBrush(BG);
+ let bg = CreateSolidBrush(pal().bg);
FillRect(dc, &strip, bg);
DeleteObject(bg);
- fill(dc, rc(0, strip.top, cr.right, strip.top + 1), LINE, 0); // hairline above the status line
+ fill(dc, rc(0, strip.top, cr.right, strip.top + 1), pal().line, 0); // hairline above the status line
let snap = ST.with(|c| {
c.try_borrow().ok().map(|s| {
// selected count and the total size of the selected files
@@ -598,11 +617,11 @@ pub unsafe fn paint_status(h: HWND) {
};
let by = ["Name", "Date", "Type", "Size"][SORT_COL.load(Relaxed).min(3)];
let right = format!("{by} {}", if SORT_ASC.load(Relaxed) { "\u{2191}" } else { "\u{2193}" });
- let f = font(12, 400, "Segoe UI") as HFONT;
+ let f = font(12, 400, ui_face()) as HFONT;
let of = SelectObject(dc, f);
SetBkMode(dc, TRANSPARENT as i32);
- text(dc, &left, rc(strip.left + sc(14), strip.top, strip.right / 2, strip.bottom), DIM, DT_LEFT);
- text(dc, &right, rc(strip.right / 2, strip.top, strip.right - sc(14), strip.bottom), DIM, DT_RIGHT);
+ text(dc, &left, rc(strip.left + sc(14), strip.top, strip.right / 2, strip.bottom), pal().dim, DT_LEFT);
+ text(dc, &right, rc(strip.right / 2, strip.top, strip.right - sc(14), strip.bottom), pal().dim, DT_RIGHT);
SelectObject(dc, of);
DeleteObject(f);
}
@@ -673,9 +692,9 @@ pub unsafe extern "system" fn proc(h: HWND, m: u32, wp: WPARAM, lp: LPARAM) -> L
WM_CTLCOLOREDIT => {
// the address box: white text on the pill's colour
let dc = wp as HDC;
- SetTextColor(dc, TEXT);
- SetBkColor(dc, PILL);
- if BRUSH.get() == 0 { BRUSH.set(CreateSolidBrush(PILL) as isize); }
+ SetTextColor(dc, pal().text);
+ SetBkColor(dc, pill());
+ if BRUSH.get() == 0 { BRUSH.set(CreateSolidBrush(pill()) as isize); }
return BRUSH.get();
}
_ => return DefWindowProcW(h, m, wp, lp),
@@ -777,11 +796,11 @@ unsafe fn paint_nav(hwnd: HWND) {
BUSY.set(false);
let (dc, bmp) = (CreateCompatibleDC(wdc), CreateCompatibleBitmap(wdc, cr.right.max(1), cr.bottom.max(1)));
let old = SelectObject(dc, bmp);
- let bg = CreateSolidBrush(BG);
+ let bg = CreateSolidBrush(pal().bg);
FillRect(dc, &cr, bg);
DeleteObject(bg);
SetBkMode(dc, TRANSPARENT as i32);
- let (f_txt, f_head, f_glyph, f_small) = (font(13, 400, "Segoe UI") as HFONT, font(12, 600, "Segoe UI") as HFONT, font(16, 400, "Segoe MDL2 Assets") as HFONT, font(11, 400, "Segoe UI") as HFONT);
+ let (f_txt, f_head, f_glyph, f_small) = (font(13, 400, ui_face()) as HFONT, font(12, 600, ui_face()) as HFONT, font(16, 400, "Segoe MDL2 Assets") as HFONT, font(11, 400, ui_face()) as HFONT);
let of = SelectObject(dc, f_txt);
// where we are = the deepest item that contains the current folder
let cur = ST.with(|c| c.try_borrow().ok().map(|s| s.dir.to_string_lossy().to_lowercase())).unwrap_or_default();
@@ -792,7 +811,7 @@ unsafe fn paint_nav(hwnd: HWND) {
for (i, it) in n.iter().enumerate() {
if it.path.as_os_str().is_empty() {
SelectObject(dc, f_head);
- text(dc, &it.title.to_uppercase(), rc(sc(18), y + sc(6), cr.right - sc(8), y + sc(NAV_HEAD)), DIM, DT_LEFT);
+ text(dc, &it.title.to_uppercase(), rc(sc(18), y + sc(6), cr.right - sc(8), y + sc(NAV_HEAD)), pal().dim, DT_LEFT);
y += sc(NAV_HEAD);
continue;
}
@@ -800,28 +819,28 @@ unsafe fn paint_nav(hwnd: HWND) {
let r = rc(sc(8), y, cr.right - sc(8), y + hgt);
let (th, ta) = (hv(5000 + i as i32, hot == i as i32), hv(6000 + i as i32, here == Some(i)));
let p = press_t(5000 + i as i32);
- if th.max(ta) > 0.01 || p > 0.0 { fill(dc, r, mix(mix(mix(BG, HOVER, th), ACTIVE, ta), ACCENT, 0.3 * p), sc(10)); }
- if ta > 0.01 { fill(dc, rc(r.left, y + sc(10), r.left + sc(3), y + hgt - sc(10)), mix(ACTIVE, ACCENT, ta), sc(3)); }
+ if th.max(ta) > 0.01 || p > 0.0 { fill(dc, r, mix(mix(mix(pal().bg, pal().hover, th), pal().active, ta), pal().accent, 0.3 * p), sc(10)); }
+ if ta > 0.01 { fill(dc, rc(r.left, y + sc(10), r.left + sc(3), y + hgt - sc(10)), mix(pal().active, pal().accent, ta), sc(3)); }
let line = rc(r.left, y, r.right, y + sc(NAV_ROW)); // the title line (a drive has its usage bar below it)
SelectObject(dc, f_glyph);
- text(dc, it.glyph, rc(r.left + sc(10), line.top, r.left + sc(40), line.bottom), mix(DIM, ACCENT, ta), DT_CENTER);
+ text(dc, it.glyph, rc(r.left + sc(10), line.top, r.left + sc(40), line.bottom), mix(pal().dim, pal().accent, ta), DT_CENTER);
SelectObject(dc, f_txt);
- text(dc, &it.title, rc(r.left + sc(48), line.top, r.right - sc(8), line.bottom), mix(DIM, TEXT, ta.max(th)), DT_LEFT);
+ text(dc, &it.title, rc(r.left + sc(48), line.top, r.right - sc(8), line.bottom), mix(pal().dim, pal().text, ta.max(th)), DT_LEFT);
if let Some((free, total)) = it.cap {
// usage bar like Windows' "This PC": accent, red once the drive is more than 90 % full
let used = 1.0 - free as f32 / total as f32;
let bar = rc(r.left + sc(48), y + sc(30), r.right - sc(14), y + sc(34));
- fill(dc, bar, mix(BG, TEXT, 0.12), sc(4));
+ fill(dc, bar, mix(pal().bg, pal().text, 0.12), sc(4));
let fw = ((bar.right - bar.left) as f32 * used) as i32;
- fill(dc, rc(bar.left, bar.top, bar.left + fw.max(sc(4)), bar.bottom), if used > 0.9 { rgb(255, 99, 97) } else { ACCENT }, sc(4));
+ fill(dc, rc(bar.left, bar.top, bar.left + fw.max(sc(4)), bar.bottom), if used > 0.9 { rgb(255, 99, 97) } else { pal().accent }, sc(4));
SelectObject(dc, f_small);
let gb = |b: u64| b as f64 / 1_073_741_824.0;
- text(dc, &format!("{:.0} GB free of {:.0} GB", gb(free), gb(total)), rc(bar.left, bar.bottom + sc(1), r.right - sc(8), y + hgt - sc(2)), DIM, DT_LEFT);
+ text(dc, &format!("{:.0} GB free of {:.0} GB", gb(free), gb(total)), rc(bar.left, bar.bottom + sc(1), r.right - sc(8), y + hgt - sc(2)), pal().dim, DT_LEFT);
}
y += hgt;
}
});
- fill(dc, rc(cr.right - 1, 0, cr.right, cr.bottom), LINE, 0); // hairline between the pane and the list
+ fill(dc, rc(cr.right - 1, 0, cr.right, cr.bottom), pal().line, 0); // hairline between the pane and the list
BitBlt(wdc, 0, 0, cr.right, cr.bottom, dc, 0, 0, SRCCOPY);
SelectObject(dc, of);
for f in [f_txt, f_head, f_glyph, f_small] { DeleteObject(f); }
diff --git a/plugins/rust-search/Cargo.lock b/plugins/rust-search/Cargo.lock
index 7aff35f..ab34139 100644
--- a/plugins/rust-search/Cargo.lock
+++ b/plugins/rust-search/Cargo.lock
@@ -72,6 +72,7 @@ version = "0.1.0"
dependencies = [
"sysinfo",
"windows-sys",
+ "winrust-common",
]
[[package]]
@@ -245,3 +246,10 @@ checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37"
dependencies = [
"windows-link",
]
+
+[[package]]
+name = "winrust-common"
+version = "0.1.0"
+dependencies = [
+ "windows-sys",
+]
diff --git a/plugins/rust-search/Cargo.toml b/plugins/rust-search/Cargo.toml
index da24d42..00052f0 100644
--- a/plugins/rust-search/Cargo.toml
+++ b/plugins/rust-search/Cargo.toml
@@ -4,5 +4,6 @@ version = "0.1.0"
edition = "2024"
[dependencies]
+winrust-common = { path = "../../common" }
sysinfo = { version = "0.40.3", default-features = false, features = ["system"] }
windows-sys = { version = "0.61.2", features = ["Win32_Foundation", "Win32_Graphics_Dwm", "Win32_Graphics_Gdi", "Win32_Graphics_GdiPlus", "Win32_Security", "Win32_Security_Authorization", "Win32_Storage_FileSystem", "Win32_System_Console", "Win32_System_IO", "Win32_System_Ioctl", "Win32_System_LibraryLoader", "Win32_System_Pipes", "Win32_System_Registry", "Win32_System_SystemInformation", "Win32_UI_Input_KeyboardAndMouse", "Win32_UI_Shell", "Win32_UI_WindowsAndMessaging"] }
diff --git a/plugins/rust-search/src/bin/rs-launcher.rs b/plugins/rust-search/src/bin/rs-launcher.rs
index 1f56ce5..608f810 100644
--- a/plugins/rust-search/src/bin/rs-launcher.rs
+++ b/plugins/rust-search/src/bin/rs-launcher.rs
@@ -42,13 +42,42 @@ use windows_sys::Win32::{
};
type Rgb = (u8, u8, u8);
-const BG: Rgb = (30, 31, 36);
-const BORDER: Rgb = (62, 63, 72);
-const SEL: Rgb = (46, 50, 62);
-const ACCENT: Rgb = (96, 165, 250);
-const TEXT: Rgb = (240, 240, 244);
-const DIM: Rgb = (143, 146, 158);
-const FAINT: Rgb = (98, 101, 112);
+// Colours of the WinRust style the topbar gear picks (normal, terminal, dock, tiling): the same palette as the bar.
+use winrust_common::style::{pal, style, ui_face};
+fn cr(c: u32) -> Rgb {
+ (c as u8, (c >> 8) as u8, (c >> 16) as u8)
+}
+fn mixc(a: u32, b: u32, t: f32) -> u32 {
+ let ch = |sh: u32| (((a >> sh) & 255) as f32 + ((((b >> sh) & 255) as f32) - ((a >> sh) & 255) as f32) * t) as u32;
+ ch(0) | ch(8) << 8 | ch(16) << 16
+}
+fn c_bg() -> Rgb {
+ cr(pal().bg)
+}
+fn c_border() -> Rgb {
+ cr(pal().line)
+}
+fn c_sel() -> Rgb {
+ cr(pal().active)
+}
+fn c_accent() -> Rgb {
+ cr(pal().accent)
+}
+fn c_text() -> Rgb {
+ cr(pal().text)
+}
+fn c_dim() -> Rgb {
+ cr(pal().dim)
+}
+fn c_faint() -> Rgb {
+ cr(mixc(pal().dim, pal().bg, 0.4))
+}
+fn c_menu_bg() -> Rgb {
+ cr(mixc(pal().bg, pal().line, 0.5))
+}
+fn c_menu_hot() -> Rgb {
+ cr(pal().active)
+}
// logical pixels; multiplied by the screen scale when used
const W: i32 = 680;
@@ -344,7 +373,38 @@ unsafe fn text_changed(h: HWND) {
InvalidateRect(h, null(), 0);
}
+/// Fonts and frame of the current WinRust style: at start, and again when the topbar broadcasts a style change.
+unsafe fn apply_style(main: HWND) {
+ let scale = st(|s| s.scale);
+ let font = |px: i32, weight: i32, face: &str| {
+ CreateFontW(-((px as f32 * scale).round() as i32), 0, 0, 0, weight, 0, 0, 0, DEFAULT_CHARSET as _, 0, 0, CLEARTYPE_QUALITY as _, 0, wide(face).as_ptr()) as isize
+ };
+ let face = ui_face();
+ let fonts = [font(22, 400, face), font(16, 600, face), font(13, 400, face), font(20, 400, "Segoe MDL2 Assets"), font(12, 400, face)];
+ for f in st(|s| std::mem::replace(&mut s.fonts, fonts)) {
+ if f != 0 {
+ DeleteObject(f as _);
+ }
+ }
+ // Windows 11: rounded corners (square in the terminal and tiling styles), dark frame, border colour. Windows 10 rejects the corner attribute.
+ let square = style().square();
+ let (round, dark, border) = (if square { 1i32 } else { 2i32 }, 1i32, rgb(c_border()) as i32);
+ let hr = DwmSetWindowAttribute(main, 33, &round as *const _ as _, 4);
+ DwmSetWindowAttribute(main, 20, &dark as *const _ as _, 4);
+ DwmSetWindowAttribute(main, 34, &border as *const _ as _, 4);
+ st(|s| s.round_with_region = hr != 0 && !square);
+ if square {
+ SetWindowRgn(main, null_mut(), 1);
+ }
+}
+
unsafe extern "system" fn wndproc(h: HWND, m: u32, wp: WPARAM, lp: LPARAM) -> LRESULT {
+ if m == winrust_common::style::msg() {
+ winrust_common::style::reload();
+ apply_style(h);
+ InvalidateRect(h, null(), 0);
+ return 0;
+ }
match m {
WM_HOTKEY => {
if IsWindowVisible(h) != 0 && st(|s| s.ta) > 0.0 { hide(h) } else { show(h) }
@@ -562,8 +622,6 @@ fn start_toggle(p: &str) {
const MENU_W: i32 = 270;
const MENU_ITEM_H: i32 = 32;
const MENU_PAD: i32 = 6;
-const MENU_BG: Rgb = (40, 42, 50);
-const MENU_HOT: Rgb = (62, 68, 84);
const DANGER: Rgb = (248, 113, 113);
struct MenuSt {
@@ -976,31 +1034,31 @@ fn purge_view(s: &St) -> Option<PView> {
let btn = |labels: &[(&'static str, bool)], hot: usize| rects.iter().zip(labels).enumerate().map(|(i, (r, (l, d)))| (*r, *l, *d, i == hot)).collect::<Vec<_>>();
Some(match s.purge.as_ref()? {
Purge::Scanning(path) => PView {
- glyph: ("\u{E721}", DIM),
- title: ("Checking what will be removed\u{2026}".into(), TEXT),
+ glyph: ("\u{E721}", c_dim()),
+ title: ("Checking what will be removed\u{2026}".into(), c_text()),
path: path.clone(),
- lines: vec![("Counting files and searching the registry. Nothing is deleted yet.".into(), DIM, false)],
+ lines: vec![("Counting files and searching the registry. Nothing is deleted yet.".into(), c_dim(), false)],
note: String::new(),
buttons: vec![],
},
Purge::Working(path) => PView {
glyph: ("\u{E74D}", DANGER),
- title: ("Deleting\u{2026}".into(), TEXT),
+ title: ("Deleting\u{2026}".into(), c_text()),
path: path.clone(),
- lines: vec![("Esc hides this card; the result waits for the next Alt+Space.".into(), DIM, false)],
+ lines: vec![("Esc hides this card; the result waits for the next Alt+Space.".into(), c_dim(), false)],
note: String::new(),
buttons: vec![],
},
Purge::Confirm { path, files, bytes, hits, hot } => {
- let mut lines = vec![(format!("{} \u{00B7} {}", plural(*files as usize, "file"), size_text(*bytes)), TEXT, false)];
+ let mut lines = vec![(format!("{} \u{00B7} {}", plural(*files as usize, "file"), size_text(*bytes)), c_text(), false)];
if hits.is_empty() {
- lines.push(("No registry entries point to it.".into(), DIM, false));
+ lines.push(("No registry entries point to it.".into(), c_dim(), false));
} else {
let n = plural(hits.len(), "registry entry").replace("entrys", "entries");
- lines.push((format!("{n} {} to it and will be removed:", if hits.len() == 1 { "points" } else { "point" }), DIM, false));
- lines.extend(hits.iter().take(LIST_MAX).map(|h| (h.describe(), FAINT, true)));
+ lines.push((format!("{n} {} to it and will be removed:", if hits.len() == 1 { "points" } else { "point" }), c_dim(), false));
+ lines.extend(hits.iter().take(LIST_MAX).map(|h| (h.describe(), c_faint(), true)));
if hits.len() > LIST_MAX {
- lines.push((format!("+ {} more", hits.len() - LIST_MAX), FAINT, true));
+ lines.push((format!("+ {} more", hits.len() - LIST_MAX), c_faint(), true));
}
}
PView {
@@ -1013,10 +1071,10 @@ fn purge_view(s: &St) -> Option<PView> {
}
}
Purge::Done { path, title, lines, ok, backup, hot } => PView {
- glyph: if *ok { ("\u{E73E}", ACCENT) } else { ("\u{E7BA}", DANGER) },
- title: (title.clone(), if *ok { TEXT } else { DANGER }),
+ glyph: if *ok { ("\u{E73E}", c_accent()) } else { ("\u{E7BA}", DANGER) },
+ title: (title.clone(), if *ok { c_text() } else { DANGER }),
path: path.clone(),
- lines: lines.iter().enumerate().map(|(i, l)| (l.clone(), if i == 0 { TEXT } else { DIM }, false)).collect(),
+ lines: lines.iter().enumerate().map(|(i, l)| (l.clone(), if i == 0 { c_text() } else { c_dim() }, false)).collect(),
note: backup.as_ref().map_or(String::new(), |b| format!("Backup (double-click to restore): {b}")),
buttons: if backup.is_some() { btn(&[("Close", false), ("Show backup", false)], *hot) } else { btn(&[("Close", false)], 0) },
},
@@ -1036,17 +1094,17 @@ unsafe fn draw_purge(dc: HDC, w: i32, v: &View, pv: &PView) {
// the destructive button stays an outline until it is the chosen one
round_rect(g, l, t, bw, bh, rad, DANGER);
if !*hot {
- round_rect(g, l + 1.5 * s, t + 1.5 * s, bw - 3.0 * s, bh - 3.0 * s, rad - 1.5 * s, BG);
+ round_rect(g, l + 1.5 * s, t + 1.5 * s, bw - 3.0 * s, bh - 3.0 * s, rad - 1.5 * s, c_bg());
}
} else {
- round_rect(g, l, t, bw, bh, rad, if *hot { MENU_HOT } else { MENU_BG });
+ round_rect(g, l, t, bw, bh, rad, if *hot { c_menu_hot() } else { c_menu_bg() });
}
}
GdipDeleteGraphics(g);
let left = p(58);
text(dc, v.fonts[F_ICON], pv.glyph.1, RECT { left: p(22), top: top + p(12), right: p(52), bottom: top + p(40) }, pv.glyph.0, DT_SINGLELINE | DT_VCENTER);
text(dc, v.fonts[F_NAME], pv.title.1, RECT { left, top: top + p(12), right: w - p(22), bottom: top + p(40) }, &pv.title.0, DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
- text(dc, v.fonts[F_PATH], DIM, RECT { left, top: top + p(40), right: w - p(22), bottom: top + p(60) }, &pv.path, DT_SINGLELINE | DT_PATH_ELLIPSIS);
+ text(dc, v.fonts[F_PATH], c_dim(), RECT { left, top: top + p(40), right: w - p(22), bottom: top + p(60) }, &pv.path, DT_SINGLELINE | DT_PATH_ELLIPSIS);
let mut y = top + p(74);
for (line, c, small) in &pv.lines {
let hgt = p(if *small { 18 } else { 22 });
@@ -1056,10 +1114,10 @@ unsafe fn draw_purge(dc: HDC, w: i32, v: &View, pv: &PView) {
}
let bottom = top + p(PANEL_H);
if !pv.note.is_empty() {
- text(dc, v.fonts[F_HINT], FAINT, RECT { left: p(22), top: bottom - p(20 + 36 + 30), right: w - p(22), bottom: bottom - p(20 + 36 + 8) }, &pv.note, DT_SINGLELINE | DT_VCENTER | DT_PATH_ELLIPSIS);
+ text(dc, v.fonts[F_HINT], c_faint(), RECT { left: p(22), top: bottom - p(20 + 36 + 30), right: w - p(22), bottom: bottom - p(20 + 36 + 8) }, &pv.note, DT_SINGLELINE | DT_VCENTER | DT_PATH_ELLIPSIS);
}
for ((l, t, r, b), label, danger, hot) in &pv.buttons {
- let c = if *danger && *hot { (20, 20, 24) } else if *danger { DANGER } else { TEXT };
+ let c = if *danger && *hot { (20, 20, 24) } else if *danger { DANGER } else { c_text() };
text(dc, v.fonts[F_PATH], c, RECT { left: *l, top: *t, right: *r, bottom: *b }, label, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
}
}
@@ -1134,6 +1192,7 @@ unsafe fn fill(dc: HDC, l: i32, t: i32, r: i32, b: i32, c: Rgb) {
}
unsafe fn round_rect(g: *mut GpGraphics, x: f32, y: f32, w: f32, h: f32, r: f32, c: Rgb) {
+ let r = if style().square() { 0.5 } else { r }; // a hair of a radius: zero-size arcs would drop the whole shape
let mut path: *mut GpPath = null_mut();
GdipCreatePath(FillModeAlternate, &mut path);
let d = r * 2.0;
@@ -1161,7 +1220,7 @@ unsafe fn draw(dc: HDC, w: i32, hgt: i32, v: &View) {
let s = v.scale;
let p = |x: i32| (x as f32 * s).round() as i32;
SetBkMode(dc, TRANSPARENT as i32);
- fill(dc, 0, 0, w, hgt, BG);
+ fill(dc, 0, 0, w, hgt, c_bg());
let (rows_top, row_h) = (p(INPUT_H + PAD), ROW_H as f32 * s);
let nrows = v.rows.len();
@@ -1172,18 +1231,18 @@ unsafe fn draw(dc: HDC, w: i32, hgt: i32, v: &View) {
GdipSetSmoothingMode(g, SmoothingModeAntiAlias);
if nrows > 0 && v.purge.is_none() {
let y = rows_top as f32 + v.sel_f * row_h;
- round_rect(g, p(PAD) as f32, y + 2.0 * s, (w - 2 * p(PAD)) as f32, row_h - 4.0 * s, 10.0 * s, SEL);
- round_rect(g, p(PAD + 4) as f32, y + row_h / 2.0 - 10.0 * s, 3.0 * s, 20.0 * s, 1.5 * s, ACCENT);
+ round_rect(g, p(PAD) as f32, y + 2.0 * s, (w - 2 * p(PAD)) as f32, row_h - 4.0 * s, 10.0 * s, c_sel());
+ round_rect(g, p(PAD + 4) as f32, y + row_h / 2.0 - 10.0 * s, 3.0 * s, 20.0 * s, 1.5 * s, c_accent());
}
GdipDeleteGraphics(g);
// input row
let mid = p(INPUT_H) / 2;
- text(dc, v.fonts[F_ICON], DIM, RECT { left: p(22), top: mid - p(14), right: p(52), bottom: mid + p(14) }, "\u{E721}", DT_SINGLELINE | DT_VCENTER);
+ text(dc, v.fonts[F_ICON], c_dim(), RECT { left: p(22), top: mid - p(14), right: p(52), bottom: mid + p(14) }, "\u{E721}", DT_SINGLELINE | DT_VCENTER);
let area = RECT { left: p(58), top: mid - p(18), right: w - p(24), bottom: mid + p(18) };
let shown = String::from_utf16_lossy(&v.text);
if v.text.is_empty() {
- text(dc, v.fonts[F_INPUT], FAINT, area, "Search files and apps", DT_SINGLELINE | DT_VCENTER);
+ text(dc, v.fonts[F_INPUT], c_faint(), area, "Search files and apps", DT_SINGLELINE | DT_VCENTER);
} else {
let mut size: SIZE = zeroed();
let old = SelectObject(dc, v.fonts[F_INPUT] as _);
@@ -1192,25 +1251,25 @@ unsafe fn draw(dc: HDC, w: i32, hgt: i32, v: &View) {
let overflow = (size.cx - (area.right - area.left - p(4))).max(0); // keep the end (caret) in view
let saved = SaveDC(dc);
IntersectClipRect(dc, area.left, area.top, area.right, area.bottom);
- text(dc, v.fonts[F_INPUT], TEXT, RECT { left: area.left - overflow, ..area }, &shown, DT_SINGLELINE | DT_VCENTER | DT_NOCLIP);
+ text(dc, v.fonts[F_INPUT], c_text(), RECT { left: area.left - overflow, ..area }, &shown, DT_SINGLELINE | DT_VCENTER | DT_NOCLIP);
if v.caret {
- fill(dc, area.left - overflow + size.cx + p(2), mid - p(13), area.left - overflow + size.cx + p(4), mid + p(13), ACCENT);
+ fill(dc, area.left - overflow + size.cx + p(2), mid - p(13), area.left - overflow + size.cx + p(4), mid + p(13), c_accent());
}
RestoreDC(dc, saved);
}
if v.text.is_empty() && v.caret {
- fill(dc, p(58), mid - p(13), p(58) + p(2), mid + p(13), ACCENT);
+ fill(dc, p(58), mid - p(13), p(58) + p(2), mid + p(13), c_accent());
}
if !v.text.is_empty() || v.purge.is_some() {
- fill(dc, p(PAD + 6), p(INPUT_H) - 1, w - p(PAD + 6), p(INPUT_H), BORDER); // separator
+ fill(dc, p(PAD + 6), p(INPUT_H) - 1, w - p(PAD + 6), p(INPUT_H), c_border()); // separator
}
if let Some(pv) = &v.purge {
return draw_purge(dc, w, v, pv);
}
if nrows == 0 {
if !v.text.is_empty() {
- text(dc, v.fonts[F_NAME], DIM, RECT { left: 0, top: rows_top, right: w, bottom: rows_top + row_h as i32 }, "No results", DT_SINGLELINE | DT_VCENTER | DT_CENTER);
+ text(dc, v.fonts[F_NAME], c_dim(), RECT { left: 0, top: rows_top, right: w, bottom: rows_top + row_h as i32 }, "No results", DT_SINGLELINE | DT_VCENTER | DT_CENTER);
}
return;
}
@@ -1222,15 +1281,15 @@ unsafe fn draw(dc: HDC, w: i32, hgt: i32, v: &View) {
DrawIconEx(dc, p(PAD + 16), y0 + (row_h as i32 - isz) / 2, *icon as _, isz, isz, 0, null_mut(), DI_NORMAL);
}
let (left, right) = (p(PAD + 16 + 28 + 14), w - p(PAD + 14));
- text(dc, v.fonts[F_NAME], TEXT, RECT { left, top: y0 + p(7), right, bottom: y0 + p(29) }, name, DT_SINGLELINE | DT_END_ELLIPSIS);
- text(dc, v.fonts[F_PATH], DIM, RECT { left, top: y0 + p(29), right, bottom: y0 + p(47) }, sub, DT_SINGLELINE | DT_END_ELLIPSIS);
+ text(dc, v.fonts[F_NAME], c_text(), RECT { left, top: y0 + p(7), right, bottom: y0 + p(29) }, name, DT_SINGLELINE | DT_END_ELLIPSIS);
+ text(dc, v.fonts[F_PATH], c_dim(), RECT { left, top: y0 + p(29), right, bottom: y0 + p(47) }, sub, DT_SINGLELINE | DT_END_ELLIPSIS);
}
let foot_y = rows_top + (nrows as f32 * row_h) as i32;
let more = if v.total > nrows { format!(" \u{2022} {} results", v.total) } else { String::new() };
text(
dc,
v.fonts[F_HINT],
- FAINT,
+ c_faint(),
RECT { left: p(PAD + 16), top: foot_y + p(4), right: w - p(PAD + 14), bottom: foot_y + p(FOOT_H) },
&if v.renaming {
"Type the new name \u{21B5} rename Esc cancel".to_string()
@@ -1246,14 +1305,14 @@ unsafe fn draw(dc: HDC, w: i32, hgt: i32, v: &View) {
let mut g: *mut GpGraphics = null_mut();
GdipCreateFromHDC(dc, &mut g);
GdipSetSmoothingMode(g, SmoothingModeAntiAlias);
- round_rect(g, l as f32, t as f32, mw as f32, mh as f32, 10.0 * s, BORDER);
- round_rect(g, (l + 1) as f32, (t + 1) as f32, (mw - 2) as f32, (mh - 2) as f32, 9.0 * s, MENU_BG);
- round_rect(g, (l + pad) as f32, (t + pad + hot as i32 * ih) as f32, (mw - 2 * pad) as f32, ih as f32, 7.0 * s, MENU_HOT);
+ round_rect(g, l as f32, t as f32, mw as f32, mh as f32, 10.0 * s, c_border());
+ round_rect(g, (l + 1) as f32, (t + 1) as f32, (mw - 2) as f32, (mh - 2) as f32, 9.0 * s, c_menu_bg());
+ round_rect(g, (l + pad) as f32, (t + pad + hot as i32 * ih) as f32, (mw - 2 * pad) as f32, ih as f32, 7.0 * s, c_menu_hot());
GdipDeleteGraphics(g);
for (i, label) in MENU.iter().enumerate() {
let label = if i == 3 && v.menu_pinned { "Remove from Start" } else { label };
let y0 = t + pad + i as i32 * ih;
- let c = if i == MENU.len() - 1 { DANGER } else { TEXT };
+ let c = if i == MENU.len() - 1 { DANGER } else { c_text() };
text(dc, v.fonts[F_PATH], c, RECT { left: l + pad + p(12), top: y0, right: l + mw - pad, bottom: y0 + ih }, label, DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
}
}
@@ -1301,21 +1360,8 @@ fn main() {
return;
}
- // Windows 11: rounded corners, dark frame, border colour. Windows 10 rejects the corner attribute.
- let (round, dark, border) = (2i32, 1i32, rgb(BORDER) as i32);
- let hr = DwmSetWindowAttribute(main, 33, &round as *const _ as _, 4);
- DwmSetWindowAttribute(main, 20, &dark as *const _ as _, 4);
- DwmSetWindowAttribute(main, 34, &border as *const _ as _, 4);
-
- let font = |px: i32, weight: i32, face: &str| {
- CreateFontW(-((px as f32 * scale).round() as i32), 0, 0, 0, weight, 0, 0, 0, DEFAULT_CHARSET as _, 0, 0, CLEARTYPE_QUALITY as _, 0, wide(face).as_ptr()) as isize
- };
- let fonts = [font(22, 400, "Segoe UI"), font(16, 600, "Segoe UI"), font(13, 400, "Segoe UI"), font(20, 400, "Segoe MDL2 Assets"), font(12, 400, "Segoe UI")];
- st(|s| {
- s.scale = scale;
- s.round_with_region = hr != 0;
- s.fonts = fonts;
- });
+ st(|s| s.scale = scale);
+ apply_style(main);
if RegisterHotKey(main, 1, MOD_ALT | MOD_NOREPEAT, VK_SPACE as u32) == 0 {
MessageBoxW(null_mut(), wide("Alt+Space is taken (is the launcher already running?)").as_ptr(), wide("rs launcher").as_ptr(), MB_ICONERROR);
diff --git a/plugins/topbar/Cargo.toml b/plugins/topbar/Cargo.toml
index 1df39eb..3631a62 100644
--- a/plugins/topbar/Cargo.toml
+++ b/plugins/topbar/Cargo.toml
@@ -5,6 +5,6 @@ edition = "2024"
[dependencies]
winrust-common = { path = "../../common" }
-windows-sys = { version = "0.61.2", features = ["Win32_Foundation", "Win32_Globalization", "Win32_Graphics_Dwm", "Win32_Graphics_Gdi", "Win32_Graphics_GdiPlus", "Win32_NetworkManagement_WiFi", "Win32_NetworkManagement_Ndis", "Win32_Security", "Win32_Storage_FileSystem", "Win32_Storage_Packaging_Appx", "Win32_System_DataExchange", "Win32_System_Diagnostics_ToolHelp", "Win32_System_LibraryLoader", "Win32_System_Power", "Win32_System_Registry", "Win32_System_SystemInformation", "Win32_System_Threading", "Win32_UI_Input_KeyboardAndMouse", "Win32_UI_Shell", "Win32_UI_WindowsAndMessaging"] }
+windows-sys = { version = "0.61.2", features = ["Win32_Foundation", "Win32_Globalization", "Win32_Graphics_Dwm", "Win32_Graphics_Gdi", "Win32_Graphics_GdiPlus", "Win32_NetworkManagement_WiFi", "Win32_NetworkManagement_Ndis", "Win32_NetworkManagement_IpHelper", "Win32_Networking_WinSock", "Win32_Security", "Win32_Storage_FileSystem", "Win32_Storage_Packaging_Appx", "Win32_System_DataExchange", "Win32_System_Diagnostics_ToolHelp", "Win32_System_LibraryLoader", "Win32_System_Power", "Win32_System_Registry", "Win32_System_SystemInformation", "Win32_System_Threading", "Win32_UI_Input_KeyboardAndMouse", "Win32_UI_Shell", "Win32_UI_WindowsAndMessaging"] }
# COM only where raw vtables would be long: master volume and .lnk targets
windows = { version = "0.62", features = ["Win32_Media_Audio", "Win32_Media_Audio_Endpoints", "Win32_System_Com", "Win32_System_Com_StructuredStorage", "Win32_System_Variant", "Win32_Graphics_Gdi", "Win32_UI_Shell", "Win32_UI_Shell_Common", "Win32_Storage_FileSystem"] }
diff --git a/plugins/topbar/src/fly.rs b/plugins/topbar/src/fly.rs
index 03d46a4..fb399f8 100644
--- a/plugins/topbar/src/fly.rs
+++ b/plugins/topbar/src/fly.rs
@@ -25,6 +25,7 @@ enum Act {
Tile(u8),
WifiMore,
Net(usize),
+ NetOff, // the connected network's Disconnect button
Settings(&'static str),
Menu(u8),
CalPrev,
@@ -451,24 +452,24 @@ fn size(k: Kind) -> (i32, i32) {
}
/// Wi-Fi panel rows in logical px: (top, bottom) per network (the connected one is a taller card),
-/// y of the "Available networks" label, and the panel height.
+/// y of the "Other networks" label, and the panel height.
fn wifi_rows() -> (Vec<(i32, i32)>, Option<i32>, i32) {
NETS.with_borrow(|n| {
- let (mut y, mut rows, mut label) = (60, vec![], None);
+ let (mut y, mut rows, mut label) = (78, vec![], None);
for net in n.iter() {
if net.connected {
- rows.push((y, y + 96));
- y += 104;
+ rows.push((y, y + 130));
+ y += 140;
} else {
if label.is_none() {
label = Some(y);
- y += 28;
+ y += 30;
}
- rows.push((y, y + 54));
- y += 54;
+ rows.push((y, y + 48));
+ y += 48;
}
}
- (rows, label, y + if n.is_empty() { 72 } else { 0 } + 56)
+ (rows, label, y + if n.is_empty() { 84 } else { 8 } + 50)
})
}
@@ -497,9 +498,14 @@ fn rects(k: Kind) -> Vec<(RECT, Act)> {
}
Kind::Cal => vec![(r(w - 84, 10, w - 52, 42), Act::CalPrev), (r(w - 48, 10, w - 16, 42), Act::CalNext), (r(16, 10, w - 100, 42), Act::CalToday)],
Kind::Wifi => {
- let mut v: Vec<_> = wifi_rows().0.iter().enumerate().map(|(i, &(t, b))| (r(8, t, w - 8, b), Act::Net(i))).collect();
- v.push((r(w - 64, 14, w - 16, 38), Act::WifiSwitch));
- v.push((r(16, h - 40, w - 16, h - 8), Act::Settings("ms-settings:network-wifi")));
+ let rows = wifi_rows().0;
+ let mut v: Vec<_> = rows.iter().enumerate().map(|(i, &(t, b))| (r(12, t, w - 12, b), Act::Net(i))).collect();
+ if let Some(i) = NETS.with_borrow(|n| n.iter().position(|n| n.connected)) {
+ let b = rows[i].1;
+ v.push((r(w - 24 - 116, b - 42, w - 24, b - 12), Act::NetOff));
+ }
+ v.push((r(w - 66, 24, w - 18, 48), Act::WifiSwitch));
+ v.push((r(12, h - 48, w - 12, h - 12), Act::Settings("ms-settings:network-wifi")));
v
}
Kind::Menu => menu_rows().0.into_iter().enumerate().map(|(i, (t, b))| (r(6, t, w - 6, b), Act::Menu(i as u8))).collect(),
@@ -528,19 +534,28 @@ pub fn init(hi: HINSTANCE) {
}
}
-/// One row of a menu flyout: a glyph (or an icon, e.g. of a window), a label, red when it destroys something,
-/// a separator line above it when `sep`.
+/// One row of a menu flyout: a label (with a window's icon when it stands for a window), a dim keyboard hint on the right,
+/// a dot when it is the current choice, red when it destroys something, a separator line above it when `sep`.
pub struct MItem {
- pub glyph: &'static str,
pub icon: HICON,
pub label: String,
+ pub hint: &'static str,
+ pub on: bool,
pub danger: bool,
pub sep: bool,
}
impl MItem {
- pub fn new(glyph: &'static str, label: impl Into<String>) -> Self {
- MItem { glyph, icon: null_mut(), label: label.into(), danger: false, sep: false }
+ pub fn new(label: impl Into<String>) -> Self {
+ MItem { icon: null_mut(), label: label.into(), hint: "", on: false, danger: false, sep: false }
+ }
+ pub fn hint(mut self, h: &'static str) -> Self {
+ self.hint = h;
+ self
+ }
+ pub fn on(mut self, on: bool) -> Self {
+ self.on = on;
+ self
}
pub fn danger(mut self) -> Self {
self.danger = true;
@@ -555,7 +570,7 @@ impl MItem {
type Pick = Box<dyn FnOnce(usize)>;
thread_local! {
static MITEMS: RefCell<Vec<MItem>> = const { RefCell::new(Vec::new()) };
- static MHEAD: RefCell<Option<(HICON, String, String)>> = const { RefCell::new(None) }; // icon, title, subtitle
+ static MHEAD: RefCell<Option<(HICON, &'static str, String, String)>> = const { RefCell::new(None) }; // icon (or a glyph when null), title, subtitle
static MPICK: RefCell<Option<Pick>> = const { RefCell::new(None) };
}
const MW: i32 = 272; // menu width
@@ -564,7 +579,7 @@ const MHEAD_H: i32 = 58;
/// Menu flyout above the bar, centered on screen x `cx`. `pick` gets the index of the chosen item (not called on cancel).
/// A right click while a menu is open replaces it.
-pub fn menu(cx: i32, head: Option<(HICON, String, String)>, items: Vec<MItem>, pick: impl FnOnce(usize) + 'static) {
+pub fn menu(cx: i32, head: Option<(HICON, &'static str, String, String)>, items: Vec<MItem>, pick: impl FnOnce(usize) + 'static) {
if is_open(Kind::Menu) {
close_now();
}
@@ -596,12 +611,12 @@ fn menu_rows() -> (Vec<(i32, i32)>, i32) {
/// Right-click menu of an empty spot of the bar.
pub fn context_menu(x: i32) {
let items = vec![
- MItem::new("\u{E713}", t!("Параметры Windows", "Windows Settings")),
- MItem::new("\u{E771}", t!("Персонализация", "Personalization")),
- MItem::new("\u{E9D9}", t!("Диспетчер задач", "Task Manager")).sep(),
- MItem::new("\u{E74D}", t!("Чистильщик диска", "Disk Cleaner")),
- MItem::new("\u{E774}", t!("Язык: Русский → English", "Language: English → Русский")), // shared with the other WinRust programs
- MItem::new("\u{E711}", t!("Закрыть топбар", "Close the bar")).danger().sep(),
+ MItem::new(t!("Параметры Windows", "Windows Settings")).hint("Win+I"),
+ MItem::new(t!("Персонализация", "Personalization")),
+ MItem::new(t!("Диспетчер задач", "Task Manager")).hint("Ctrl+Shift+Esc").sep(),
+ MItem::new(t!("Чистильщик диска", "Disk Cleaner")),
+ MItem::new(t!("Программы WinRust на English", "WinRust apps in Русский")), // shared with the other WinRust programs
+ MItem::new(t!("Закрыть панель", "Close the bar")).danger().sep(),
];
menu(x, None, items, |i| unsafe {
match i {
@@ -718,7 +733,7 @@ pub fn toggle(k: Kind) {
_ => sw - w - sc(8),
};
let class = wide("topbar_fly");
- let fy = bar_top() - sc(8) - h; // above the bar
+ let fy = pop_y(h); // above the bar (below it at the top of the screen)
let hw = CreateWindowExW(WS_EX_TOOLWINDOW | WS_EX_TOPMOST | WS_EX_LAYERED, class.as_ptr(), null(), WS_POPUP, x, fy + sc(14), w, h, null_mut(), null_mut(), GetModuleHandleW(null()), null());
SetLayeredWindowAttributes(hw, 0, 0, LWA_ALPHA); // starts invisible, anim_step fades it in
if k == Kind::Start {
@@ -730,7 +745,7 @@ pub fn toggle(k: Kind) {
}
FIN.set((x, fy));
T0.set(now_ms());
- SetWindowRgn(hw, CreateRoundRectRgn(0, 0, w + 1, h + 1, sc(16), sc(16)), 1);
+ SetWindowRgn(hw, CreateRoundRectRgn(0, 0, w + 1, h + 1, rr(16), rr(16)), 1);
FH.set(hw);
FLY.set(Some(k));
ShowWindow(hw, SW_SHOW);
@@ -848,11 +863,10 @@ unsafe fn run_act(a: Act, rect: RECT, x: i32) {
let n = NETS.with_borrow(|n| n.get(i).map(|n| (n.connected, n.profile.clone(), n.auth, n.secure, n.ssid.clone())));
let Some((connected, profile, auth, secure, ssid)) = n else { return };
if connected {
- with_wlan(|h, g| WlanDisconnect(h, g, null()));
- NOTE.set("Disconnected".into());
+ // the card is information; its Disconnect button is the action
} else if let Some(p) = profile {
wifi_connect(&p);
- NOTE.set(format!("Connecting to {ssid}…"));
+ NOTE.set(tf!("Подключение к {ssid}…", "Connecting to {ssid}…"));
} else if !secure {
NETS.with_borrow(|l| wifi_join(&l[i], ""));
} else if matches!(auth, 4 | 7 | 8 | 9) {
@@ -862,6 +876,10 @@ unsafe fn run_act(a: Act, rect: RECT, x: i32) {
close();
}
}
+ Act::NetOff => {
+ with_wlan(|h, g| WlanDisconnect(h, g, null()));
+ NOTE.set(t!("Отключено", "Disconnected").into());
+ }
Act::App(i) => {
if launch(i) {
close();
@@ -918,10 +936,10 @@ fn sleep_now() {
unsafe fn track(dc: HDC, rc: RECT, frac: f32) {
let (l, rr, m) = (rc.left + sc(8), rc.right - sc(8), (rc.top + rc.bottom) / 2);
- fill(dc, RECT { left: l, top: m - sc(2), right: rr, bottom: m + sc(2) }, rgb(70, 78, 98), sc(4));
+ fill(dc, RECT { left: l, top: m - sc(2), right: rr, bottom: m + sc(2) }, mix(pal().line, pal().dim, 0.3), sc(4));
let x = l + ((rr - l) as f32 * frac.clamp(0.0, 1.0)) as i32;
- fill(dc, RECT { left: l, top: m - sc(2), right: x, bottom: m + sc(2) }, ACCENT, sc(4));
- fill(dc, RECT { left: x - sc(8), top: m - sc(8), right: x + sc(8), bottom: m + sc(8) }, TEXT, sc(16));
+ fill(dc, RECT { left: l, top: m - sc(2), right: x, bottom: m + sc(2) }, pal().accent, sc(4));
+ fill(dc, RECT { left: x - sc(8), top: m - sc(8), right: x + sc(8), bottom: m + sc(8) }, pal().text, sc(16));
}
unsafe fn paint(hw: HWND, k: Kind) {
@@ -932,10 +950,10 @@ unsafe fn paint(hw: HWND, k: Kind) {
BUSY.set(false);
let (dc, bmp) = (CreateCompatibleDC(wdc), CreateCompatibleBitmap(wdc, cr.right, cr.bottom));
let old = SelectObject(dc, bmp);
- fill(dc, cr, LINE, sc(16));
- fill(dc, RECT { left: 1, top: 1, right: cr.right - 1, bottom: cr.bottom - 1 }, BG, sc(16));
+ fill(dc, cr, pal().line, sc(16));
+ fill(dc, RECT { left: 1, top: 1, right: cr.right - 1, bottom: cr.bottom - 1 }, pal().bg, sc(16));
SetBkMode(dc, TRANSPARENT as i32);
- let (face, gface) = (wide("Segoe UI"), wide("Segoe MDL2 Assets"));
+ let (face, gface) = (wide(ui_face()), wide("Segoe MDL2 Assets"));
let font = |f: &[u16], px: i32, wt: i32| CreateFontW(-sc(px), 0, 0, 0, wt, 0, 0, 0, 1, 0, 0, 5, 0, f.as_ptr());
let (f_txt, f_small, f_glyph, f_title, f_big) = (font(&face, 13, 400), font(&face, 12, 400), font(&gface, 16, 400), font(&face, 15, 600), font(&face, 34, 600));
let of = SelectObject(dc, f_txt);
@@ -956,55 +974,62 @@ unsafe fn paint(hw: HWND, k: Kind) {
let (tl, tt) = (16 + 112 * c, 16 + 96 * (i as i32 / 3));
let on = i == 0 && WIFI.get() >= 0;
let full = r(tl, tt, tl + 104, tt + 56);
- fill(dc, full, if on { ACCENT } else { LINE }, sc(8));
- fill(dc, RECT { left: full.left + 1, top: full.top + 1, right: full.right - 1, bottom: full.bottom - 1 }, if on { ACCENT } else { rgb(32, 40, 58) }, sc(8));
+ fill(dc, full, if on { pal().accent } else { pal().line }, sc(8));
+ fill(dc, RECT { left: full.left + 1, top: full.top + 1, right: full.right - 1, bottom: full.bottom - 1 }, if on { pal().accent } else { mix(pal().bg, pal().line, 0.5) }, sc(8));
for (rc, a) in rs.iter().filter(|(_, a)| matches!(a, Act::Tile(j) if *j as usize == i) || (i == 0 && *a == Act::WifiMore)) {
- g(*a, *rc, if on { ACCENT } else { rgb(32, 40, 58) }, if on { rgb(110, 210, 255) } else { HOVER }, sc(8));
+ g(*a, *rc, if on { pal().accent } else { mix(pal().bg, pal().line, 0.5) }, if on { mix(pal().accent, pal().text, 0.3) } else { pal().hover }, sc(8));
}
SelectObject(dc, f_glyph);
let gr = if i == 0 { r(tl, tt, tl + 68, tt + 56) } else { full };
- text(dc, glyph, gr, if on { BG } else { TEXT }, DT_CENTER);
if i == 0 {
- fill(dc, r(tl + 68, tt + 12, tl + 69, tt + 44), if on { BG } else { LINE }, 0);
- text(dc, "\u{E76C}", r(tl + 68, tt, tl + 104, tt + 56), if on { BG } else { TEXT }, DT_CENTER);
+ // the same arcs as the bar: lit by the signal, a cross when not connected
+ let c = if on { pal().bg } else { pal().text };
+ let q = WIFI.get();
+ wifi_glyph(dc, (gr.left + gr.right) / 2, (gr.top + gr.bottom) / 2, sc(20), if q >= 0 { arcs_lit(q) } else { 0 }, c, mix(c, if on { pal().accent } else { pal().bg }, 0.55), if q < 0 { 1 } else { 0 });
+ } else {
+ text(dc, glyph, gr, if on { pal().bg } else { pal().text }, DT_CENTER);
+ }
+ if i == 0 {
+ fill(dc, r(tl + 68, tt + 12, tl + 69, tt + 44), if on { pal().bg } else { pal().line }, 0);
+ text(dc, "\u{E76C}", r(tl + 68, tt, tl + 104, tt + 56), if on { pal().bg } else { pal().text }, DT_CENTER);
}
SelectObject(dc, f_small);
- text(dc, label, r(tl, tt + 60, tl + 104, tt + 82), TEXT, DT_CENTER);
+ text(dc, label, r(tl, tt + 60, tl + 104, tt + 82), pal().text, DT_CENTER);
}
let mut y = 196;
let b = BRIGHT.load(Relaxed);
if b >= 0 {
SelectObject(dc, f_glyph);
- text(dc, "\u{E706}", r(16, y, 52, y + 40), TEXT, DT_CENTER);
+ text(dc, "\u{E706}", r(16, y, 52, y + 40), pal().text, DT_CENTER);
track(dc, rs.iter().find(|(_, a)| *a == Act::BrightSlide).unwrap().0, b as f32 / 100.0);
y += 48;
}
- g(Act::Mute, r(16, y, 52, y + 40), BG, HOVER, sc(8));
+ g(Act::Mute, r(16, y, 52, y + 40), pal().bg, pal().hover, sc(8));
SelectObject(dc, f_glyph);
- text(dc, if muted || vol == 0 { "\u{E74F}" } else { "\u{E767}" }, r(16, y, 52, y + 40), TEXT, DT_CENTER);
+ text(dc, if muted || vol == 0 { "\u{E74F}" } else { "\u{E767}" }, r(16, y, 52, y + 40), pal().text, DT_CENTER);
track(dc, rs.iter().find(|(_, a)| *a == Act::VolSlide).unwrap().0, if muted { 0.0 } else { vol.max(0) as f32 / 100.0 });
- fill(dc, r(0, h - 56, w, h - 55), LINE, 0);
+ fill(dc, r(0, h - 56, w, h - 55), pal().line, 0);
let (pct, ac) = BAT.get();
SelectObject(dc, f_glyph);
if pct >= 0 {
- text(dc, if ac { "\u{E83E}" } else { "\u{E83F}" }, r(16, h - 48, 44, h - 8), if ac { GOOD } else { TEXT }, DT_CENTER);
+ text(dc, if ac { "\u{E83E}" } else { "\u{E83F}" }, r(16, h - 48, 44, h - 8), if ac { GOOD } else { pal().text }, DT_CENTER);
SelectObject(dc, f_txt);
- text(dc, &format!("{pct}%"), r(48, h - 48, 140, h - 8), TEXT, DT_LEFT);
+ text(dc, &format!("{pct}%"), r(48, h - 48, 140, h - 8), pal().text, DT_LEFT);
}
- g(Act::Settings("ms-settings:"), r(w - 52, h - 48, w - 12, h - 8), BG, HOVER, sc(8));
+ g(Act::Settings("ms-settings:"), r(w - 52, h - 48, w - 12, h - 8), pal().bg, pal().hover, sc(8));
SelectObject(dc, f_glyph);
- text(dc, "\u{E713}", r(w - 52, h - 48, w - 12, h - 8), TEXT, DT_CENTER);
+ text(dc, "\u{E713}", r(w - 52, h - 48, w - 12, h - 8), pal().text, DT_CENTER);
}
Kind::Cal => {
let (y, m) = CAL.get();
SelectObject(dc, f_title);
- text(dc, &format!("{} {y}", MONTHS[m as usize - 1]), r(16, 10, w - 100, 42), TEXT, DT_LEFT);
+ text(dc, &format!("{} {y}", MONTHS[m as usize - 1]), r(16, 10, w - 100, 42), pal().text, DT_LEFT);
SelectObject(dc, f_glyph);
- text(dc, "\u{E70E}", r(w - 84, 10, w - 52, 42), TEXT, DT_CENTER);
- text(dc, "\u{E70D}", r(w - 48, 10, w - 16, 42), TEXT, DT_CENTER);
+ text(dc, "\u{E70E}", r(w - 84, 10, w - 52, 42), pal().text, DT_CENTER);
+ text(dc, "\u{E70D}", r(w - 48, 10, w - 16, 42), pal().text, DT_CENTER);
SelectObject(dc, f_small);
for (i, d) in ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"].iter().enumerate() {
- text(dc, d, r(18 + 42 * i as i32, 54, 60 + 42 * i as i32, 78), DIM, DT_CENTER);
+ text(dc, d, r(18 + 42 * i as i32, 54, 60 + 42 * i as i32, 78), pal().dim, DT_CENTER);
}
let t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4];
let yy = if m < 3 { y - 1 } else { y };
@@ -1022,150 +1047,204 @@ unsafe fn paint(hw: HWND, k: Kind) {
let cell = r(18 + 42 * col, 84 + 40 * row, 60 + 42 * col, 120 + 40 * row);
let today = now.wYear as i32 == y && now.wMonth as i32 == m && now.wDay as i32 == d;
if today {
- fill(dc, cell, ACCENT, sc(18));
+ fill(dc, cell, pal().accent, sc(18));
}
- text(dc, &d.to_string(), cell, if today { BG } else { TEXT }, DT_CENTER);
+ text(dc, &d.to_string(), cell, if today { pal().bg } else { pal().text }, DT_CENTER);
}
}
Kind::Wifi => {
let on = NETS.with_borrow(|n| !n.is_empty()) || WIFI.get() >= 0;
+ let state = net();
+ // header: the live network icon, the title and one line of plain status
+ net_icon(dc, sc(34), sc(40), sc(26), f_glyph);
SelectObject(dc, f_title);
- text(dc, "Wi‑Fi", r(16, 10, w - 90, 34), TEXT, DT_LEFT);
- SelectObject(dc, f_small);
+ text(dc, "Wi‑Fi", r(64, 18, w - 90, 40), pal().text, DT_LEFT);
let note = NOTE.with_borrow(|n| n.clone());
- let count = NETS.with_borrow(|n| n.len());
- let sub = if !note.is_empty() { note } else if on { format!("On · {count} network{} in range", if count == 1 { "" } else { "s" }) } else { "Off — turn on the switch to see networks".into() };
- text(dc, &sub, r(16, 34, w - 90, 54), DIM, DT_LEFT);
- // on/off switch
- let sw = r(w - 64, 14, w - 16, 38);
- fill(dc, sw, if on { ACCENT } else { rgb(70, 78, 98) }, sc(24));
- let kx = if on { sw.right - sc(13) } else { sw.left + sc(13) };
- fill(dc, RECT { left: kx - sc(8), top: sw.top + sc(4), right: kx + sc(8), bottom: sw.bottom - sc(4) }, if on { BG } else { TEXT }, sc(16));
+ let (sub, sub_col) = if !note.is_empty() {
+ (note, pal().dim)
+ } else {
+ match state {
+ Link::Wifi(_) => (t!("Подключено · интернет есть", "Connected · online").to_string(), GOOD),
+ Link::NoInternet(_) => (t!("Подключено, но интернета нет", "Connected, no internet").into(), WARN),
+ Link::Cable => (t!("Интернет по кабелю", "Online over a cable").into(), pal().dim),
+ Link::Offline if on => (t!("Не подключено", "Not connected").into(), pal().dim),
+ Link::Offline => (t!("Выключен", "Turned off").into(), pal().dim),
+ }
+ };
+ SelectObject(dc, f_small);
+ text(dc, &sub, r(64, 40, w - 90, 60), sub_col, DT_LEFT);
+ // on/off switch: the knob glides, the track fades to the accent
+ let sw = r(w - 66, 24, w - 18, 48);
+ let ts = ease(hv(1_500_000, on));
+ fill(dc, sw, mix(mix(pal().line, pal().dim, 0.25), pal().accent, ts), sc(24));
+ let kx = sw.left + sc(12) + ((sw.right - sw.left - sc(24)) as f32 * ts) as i32;
+ fill(dc, RECT { left: kx - sc(8), top: sw.top + sc(4), right: kx + sc(8), bottom: sw.bottom - sc(4) }, mix(pal().text, pal().bg, ts), sc(16));
+ fill(dc, r(16, 68, w - 16, 69), pal().line, 0);
let rs = rects(k);
let pass = PASS.with_borrow(|p| p.clone());
if let Some((i, p)) = pass {
let name = NETS.with_borrow(|n| n.get(i).map(|n| n.ssid.clone()).unwrap_or_default());
SelectObject(dc, f_txt);
- text(dc, &format!("Password for “{name}”"), r(16, 70, w - 16, 96), TEXT, DT_LEFT);
- fill(dc, r(16, 104, w - 16, 142), LINE, sc(6));
- fill(dc, r(17, 105, w - 17, 141), rgb(16, 20, 30), sc(6));
- text(dc, &"•".repeat(p.chars().count()), r(28, 104, w - 28, 142), TEXT, DT_LEFT);
+ text(dc, &tf!("Пароль для «{name}»", "Password for “{name}”"), r(18, 82, w - 18, 106), pal().text, DT_LEFT);
+ fill(dc, r(16, 112, w - 16, 150), pal().accent, sc(8));
+ fill(dc, r(17, 113, w - 17, 149), mix(pal().bg, 0, 0.35), sc(8));
+ let dots = "•".repeat(p.chars().count());
+ text(dc, &dots, r(30, 112, w - 30, 150), pal().text, DT_LEFT);
+ // a blinking caret after the dots
+ if now_ms() / 530 % 2 == 0 {
+ let mut tr = RECT { left: 0, top: 0, right: 0, bottom: 0 };
+ let wd = wide(&dots);
+ DrawTextW(dc, wd.as_ptr(), -1, &mut tr, DT_CALCRECT | DT_SINGLELINE | DT_NOPREFIX);
+ let cx = sc(30) + tr.right - tr.left + sc(2);
+ fill(dc, RECT { left: cx, top: sc(122), right: cx + sc(2), bottom: sc(140) }, pal().accent, 0);
+ }
+ BUSY.set(true);
SelectObject(dc, f_small);
- text(dc, "Enter — connect · Esc — cancel", r(16, 150, w - 16, 174), DIM, DT_LEFT);
+ text(dc, t!("Enter — подключиться · Esc — отмена", "Enter — connect · Esc — cancel"), r(18, 158, w - 18, 180), pal().dim, DT_LEFT);
} else {
let (_, label, _) = wifi_rows();
let conn = CONN.with_borrow(|c| c.as_ref().map(|c| (c.q, c.rx, c.tx, c.phy)));
+ let age = now_ms().saturating_sub(T0.get()) as f32;
NETS.with_borrow(|nets| {
if nets.is_empty() {
SelectObject(dc, f_txt);
- text(dc, if on { "No networks found nearby" } else { "Wi‑Fi is turned off" }, r(16, 70, w - 16, 120), DIM, DT_LEFT);
+ text(dc, if on { t!("Рядом нет сетей", "No networks nearby") } else { t!("Включите Wi‑Fi, чтобы увидеть сети", "Turn Wi‑Fi on to see networks") }, r(18, 86, w - 18, 130), pal().dim, DT_LEFT);
}
if let Some(ly) = label {
SelectObject(dc, f_small);
- text(dc, "AVAILABLE NETWORKS", r(16, ly + 2, w - 16, ly + 26), DIM, DT_LEFT);
+ text(dc, t!("Другие сети", "Other networks"), r(20, ly + 6, w - 16, ly + 26), pal().dim, DT_LEFT);
}
for (i, n) in nets.iter().enumerate() {
let rc = rs[i].0;
- let bars = |x: i32, base: i32, q: i32, scale: i32| {
- let lit = ((q + 24) / 25).clamp(1, 4);
- for b in 0..4 {
- let bh = sc((4 + 3 * b) * scale);
- let bx = x + sc(5 * scale) * b;
- fill(dc, RECT { left: bx, top: base - bh, right: bx + sc(3 * scale), bottom: base }, if b < lit { TEXT } else { rgb(90, 98, 115) }, sc(1));
- }
- };
+ // rows fade in one after another when the panel opens
+ let t = ease(((age - 45.0 * i as f32) / 240.0).clamp(0.0, 1.0));
+ if t < 1.0 {
+ BUSY.set(true);
+ }
+ let ink = |c: u32| mix(pal().bg, c, t);
+ let lit = arcs_lit(n.q);
if n.connected {
- fill(dc, rc, ACTIVE, sc(10));
- g(Act::Net(i), rc, ACTIVE, rgb(60, 70, 96), sc(10));
- bars(rc.left + sc(18), rc.top + sc(54), n.q, 2);
+ let card = mix(pal().bg, pal().active, 0.85);
+ fill(dc, rc, mix(pal().bg, card, t), sc(12));
+ let online = !matches!(state, Link::NoInternet(_));
+ wifi_glyph(dc, rc.left + sc(30), rc.top + sc(32), sc(26), lit, ink(pal().accent), ink(mix(pal().dim, card, 0.45)), if online { 0 } else { 2 });
SelectObject(dc, f_title);
- text(dc, &n.ssid, RECT { left: rc.left + sc(64), top: rc.top + sc(8), right: rc.right - sc(110), bottom: rc.top + sc(34) }, TEXT, DT_LEFT);
+ text(dc, &n.ssid, RECT { left: rc.left + sc(60), top: rc.top + sc(12), right: rc.right - sc(14), bottom: rc.top + sc(36) }, ink(pal().text), DT_LEFT);
+ let (dot, words) = if online { (GOOD, t!("Интернет есть", "Online")) } else { (WARN, t!("Нет интернета", "No internet")) };
+ let dy = rc.top + sc(46);
+ fill(dc, RECT { left: rc.left + sc(60), top: dy - sc(3), right: rc.left + sc(66), bottom: dy + sc(3) }, ink(dot), sc(6));
SelectObject(dc, f_small);
+ text(dc, words, RECT { left: rc.left + sc(72), top: dy - sc(10), right: rc.right - sc(14), bottom: dy + sc(10) }, ink(dot), DT_LEFT);
let q = conn.map(|c| c.0).unwrap_or(n.q);
- text(dc, &format!("Connected · signal {q}%"), RECT { left: rc.left + sc(64), top: rc.top + sc(34), right: rc.right - sc(110), bottom: rc.top + sc(56) }, ACCENT, DT_LEFT);
let det = match conn {
- Some((_, rx, tx, phy)) => format!("{phy} · ↓ {rx} / ↑ {tx} Mbps · {}", auth_name(n.auth)),
- None => auth_name(n.auth).to_string(),
+ Some((_, rx, tx, phy)) => format!("{phy} · {q}% · ↓{rx} ↑{tx} {} · {}", t!("Мбит/с", "Mbps"), auth_name(n.auth)),
+ None => format!("{q}% · {}", auth_name(n.auth)),
};
- text(dc, &det, RECT { left: rc.left + sc(64), top: rc.top + sc(58), right: rc.right - sc(12), bottom: rc.top + sc(82) }, DIM, DT_LEFT);
- let cb = RECT { left: rc.right - sc(104), top: rc.top + sc(12), right: rc.right - sc(12), bottom: rc.top + sc(36) };
- fill(dc, cb, BAD, sc(8));
- fill(dc, RECT { left: cb.left + 1, top: cb.top + 1, right: cb.right - 1, bottom: cb.bottom - 1 }, ACTIVE, sc(8));
- text(dc, "Disconnect", cb, BAD, DT_CENTER);
+ text(dc, &det, RECT { left: rc.left + sc(60), top: rc.top + sc(58), right: rc.right - sc(14), bottom: rc.top + sc(76) }, ink(pal().dim), DT_LEFT);
+ // a quiet Disconnect button that turns red under the pointer
+ if let Some(&(ob, _)) = rs.iter().find(|(_, a)| *a == Act::NetOff) {
+ g(Act::NetOff, ob, mix(card, pal().bg, 0.5), mix(card, BAD, 0.3), sc(8));
+ SelectObject(dc, f_small);
+ text(dc, t!("Отключиться", "Disconnect"), ob, ink(if hot(Act::NetOff) { pal().text } else { mix(pal().dim, pal().text, 0.5) }), DT_CENTER);
+ }
} else {
- g(Act::Net(i), rc, BG, HOVER, sc(10));
- bars(rc.left + sc(18), rc.top + sc(34), n.q, 1);
+ g(Act::Net(i), rc, pal().bg, pal().hover, sc(10));
+ wifi_glyph(dc, rc.left + sc(22), rc.top + sc(24), sc(16), lit, ink(pal().text), ink(mix(pal().dim, pal().bg, 0.5)), 0);
+ let saved = n.profile.is_some();
+ let sub = if !n.secure { t!("Открытая сеть", "Open network") } else if saved { t!("Сохранена", "Saved") } else { "" };
SelectObject(dc, f_txt);
- text(dc, &n.ssid, RECT { left: rc.left + sc(52), top: rc.top + sc(6), right: rc.right - sc(110), bottom: rc.top + sc(30) }, TEXT, DT_LEFT);
- SelectObject(dc, f_small);
- let sub = if !n.secure { "Open network — not secured".to_string() } else if n.profile.is_some() { format!("Saved · {}", auth_name(n.auth)) } else { format!("Not saved · {}", auth_name(n.auth)) };
- text(dc, &format!("{sub} · {}%", n.q), RECT { left: rc.left + sc(52), top: rc.top + sc(28), right: rc.right - sc(110), bottom: rc.bottom - sc(4) }, DIM, DT_LEFT);
- let action = if n.profile.is_some() || !n.secure { "Connect" } else { "Enter password" };
- text(dc, action, RECT { left: rc.right - sc(110), top: rc.top, right: rc.right - sc(14), bottom: rc.bottom }, ACCENT, DT_RIGHT);
+ let name_rc = if sub.is_empty() { RECT { left: rc.left + sc(46), right: rc.right - sc(110), ..rc } } else { RECT { left: rc.left + sc(46), top: rc.top + sc(5), right: rc.right - sc(110), bottom: rc.top + sc(27) } };
+ text(dc, &n.ssid, name_rc, ink(pal().text), DT_LEFT);
+ if !sub.is_empty() {
+ SelectObject(dc, f_small);
+ text(dc, sub, RECT { left: rc.left + sc(46), top: rc.top + sc(25), right: rc.right - sc(110), bottom: rc.bottom - sc(5) }, ink(if n.secure { pal().dim } else { WARN }), DT_LEFT);
+ }
+ if hot(Act::Net(i)) {
+ SelectObject(dc, f_small);
+ let action = if saved || !n.secure { t!("Подключить", "Connect") } else { t!("Ввести пароль", "Enter password") };
+ text(dc, action, RECT { left: rc.right - sc(120), right: rc.right - sc(14), ..rc }, pal().accent, DT_RIGHT);
+ } else if n.secure {
+ SelectObject(dc, f_glyph);
+ text(dc, "\u{E72E}", RECT { left: rc.right - sc(40), right: rc.right - sc(8), ..rc }, ink(mix(pal().dim, pal().bg, 0.35)), DT_CENTER); // lock
+ }
}
}
});
}
let last = rs.last().unwrap();
- g(last.1, last.0, BG, HOVER, sc(6));
+ g(last.1, last.0, pal().bg, pal().hover, sc(8));
SelectObject(dc, f_txt);
- text(dc, "More Wi‑Fi settings", last.0, ACCENT, DT_CENTER);
+ text(dc, t!("Параметры сети", "Network settings"), RECT { left: last.0.left + sc(10), ..last.0 }, pal().accent, DT_LEFT);
+ SelectObject(dc, f_glyph);
+ text(dc, "\u{E76C}", RECT { left: last.0.right - sc(36), ..last.0 }, pal().accent, DT_CENTER); // chevron right
}
Kind::Menu => {
// header: the app's icon on an accent-tinted tile, its name, and what is open
MHEAD.with_borrow(|hd| {
- if let Some((ic, title, sub)) = hd {
+ if let Some((ic, glyph, title, sub)) = hd {
let tile = r(14, 12, 48, 46);
- fill(dc, tile, mix(BG, ACCENT, 0.16), sc(10));
+ fill(dc, tile, mix(pal().bg, pal().accent, 0.16), sc(10));
if !ic.is_null() {
DrawIconEx(dc, tile.left + sc(5), tile.top + sc(5), *ic, sc(24), sc(24), 0, null_mut(), DI_NORMAL);
+ } else {
+ SelectObject(dc, f_glyph); // no app icon (Style, Language): the menu's own symbol
+ text(dc, glyph, tile, pal().accent, DT_CENTER);
}
SelectObject(dc, f_title);
- text(dc, title, r(60, 10, w - 14, 32), TEXT, DT_LEFT);
+ text(dc, title, r(60, 10, w - 14, 32), pal().text, DT_LEFT);
SelectObject(dc, f_small);
- text(dc, sub, r(60, 30, w - 14, 48), DIM, DT_LEFT);
- fill(dc, r(12, MHEAD_H + 4, w - 12, MHEAD_H + 5), LINE, 0);
+ text(dc, sub, r(60, 30, w - 14, 48), pal().dim, DT_LEFT);
+ fill(dc, r(12, MHEAD_H + 4, w - 12, MHEAD_H + 5), pal().line, 0);
}
});
let rs = rects(k);
MITEMS.with_borrow(|items| {
for ((rc, a), it) in rs.iter().zip(items) {
if it.sep {
- fill(dc, RECT { left: rc.left + sc(6), top: rc.top - sc(5), right: rc.right - sc(6), bottom: rc.top - sc(5) + 1 }, LINE, 0);
+ fill(dc, RECT { left: rc.left + sc(6), top: rc.top - sc(5), right: rc.right - sc(6), bottom: rc.top - sc(5) + 1 }, pal().line, 0);
}
- let col = if it.danger { BAD } else { TEXT };
- g(*a, *rc, BG, if it.danger { mix(BG, BAD, 0.22) } else { HOVER }, sc(8));
- let ib = RECT { right: rc.left + sc(40), ..*rc };
+ let col = if it.danger { BAD } else { pal().text };
+ g(*a, *rc, pal().bg, if it.danger { mix(pal().bg, BAD, 0.22) } else { pal().hover }, sc(8));
+ // plain text rows: a window's own icon is the only picture; the current choice gets an accent dot
+ let mut lx = rc.left + sc(14);
if !it.icon.is_null() {
- DrawIconEx(dc, ib.left + sc(12), (rc.top + rc.bottom) / 2 - sc(8), it.icon, sc(16), sc(16), 0, null_mut(), DI_NORMAL);
- } else {
- SelectObject(dc, f_glyph);
- text(dc, it.glyph, ib, if it.danger { BAD } else { mix(DIM, TEXT, 0.4) }, DT_CENTER);
+ DrawIconEx(dc, lx, (rc.top + rc.bottom) / 2 - sc(8), it.icon, sc(16), sc(16), 0, null_mut(), DI_NORMAL);
+ lx += sc(26);
+ }
+ let mut rx = rc.right - sc(14);
+ if it.on {
+ let (cy, d) = ((rc.top + rc.bottom) / 2, sc(4));
+ fill(dc, RECT { left: rx - 2 * d, top: cy - d, right: rx, bottom: cy + d }, pal().accent, 2 * d);
+ rx -= sc(18);
+ }
+ SelectObject(dc, f_small);
+ if !it.hint.is_empty() {
+ text(dc, it.hint, RECT { left: lx, right: rx, ..*rc }, mix(pal().dim, pal().bg, 0.25), DT_RIGHT);
}
SelectObject(dc, f_txt);
- text(dc, &it.label, RECT { left: rc.left + sc(42), right: rc.right - sc(10), ..*rc }, col, DT_LEFT);
+ text(dc, &it.label, RECT { left: lx, right: rx - if it.hint.is_empty() { 0 } else { sc(96) }, ..*rc }, if it.on { pal().accent } else { col }, DT_LEFT);
}
});
}
Kind::Start => {
- fill(dc, r(20, 20, w - 20, 56), rgb(16, 20, 30), sc(18));
+ fill(dc, r(20, 20, w - 20, 56), mix(pal().bg, 0, 0.35), sc(18));
SelectObject(dc, f_glyph);
- text(dc, "\u{E721}", r(28, 20, 56, 56), DIM, DT_CENTER);
+ text(dc, "\u{E721}", r(28, 20, 56, 56), pal().dim, DT_CENTER);
SelectObject(dc, f_txt);
let q = QUERY.with_borrow(|q| q.clone());
if q.is_empty() {
- text(dc, "Type to search apps", r(64, 20, w - 28, 56), DIM, DT_LEFT);
+ text(dc, "Type to search apps", r(64, 20, w - 28, 56), pal().dim, DT_LEFT);
} else {
- text(dc, &q, r(64, 20, w - 28, 56), TEXT, DT_LEFT);
+ text(dc, &q, r(64, 20, w - 28, 56), pal().text, DT_LEFT);
}
let f = filtered();
if f.is_empty() {
if q.is_empty() {
- text(dc, "Nothing here yet", r(24, 76, w - 24, 106), TEXT, DT_LEFT);
- text(dc, "Drag an app or file onto the Start button to add it", r(24, 106, w - 24, 134), DIM, DT_LEFT);
- text(dc, "Or search an app and right-click it → Add to Start", r(24, 134, w - 24, 162), DIM, DT_LEFT);
+ text(dc, "Nothing here yet", r(24, 76, w - 24, 106), pal().text, DT_LEFT);
+ text(dc, "Drag an app or file onto the Start button to add it", r(24, 106, w - 24, 134), pal().dim, DT_LEFT);
+ text(dc, "Or search an app and right-click it → Add to Start", r(24, 134, w - 24, 162), pal().dim, DT_LEFT);
} else {
- text(dc, "No apps found", r(24, 76, w - 24, 116), DIM, DT_LEFT);
+ text(dc, "No apps found", r(24, 76, w - 24, 116), pal().dim, DT_LEFT);
}
}
let rs = rects(k);
@@ -1183,11 +1262,11 @@ unsafe fn paint(hw: HWND, k: Kind) {
let sel = i == SEL.get(); // what Enter opens
if pulse > 0.0 || sel {
BUSY.set(BUSY.get() || pulse > 0.0);
- fill(dc, *rc, mix(if sel { mix(BG, ACCENT, 0.14) } else { BG }, ACCENT, 0.45 * pulse), sc(8));
+ fill(dc, *rc, mix(if sel { mix(pal().bg, pal().accent, 0.14) } else { pal().bg }, pal().accent, 0.45 * pulse), sc(8));
}
- g(*a, *rc, if sel { mix(BG, ACCENT, 0.14) } else { BG }, if sel { mix(HOVER, ACCENT, 0.18) } else { HOVER }, sc(8));
+ g(*a, *rc, if sel { mix(pal().bg, pal().accent, 0.14) } else { pal().bg }, if sel { mix(pal().hover, pal().accent, 0.18) } else { pal().hover }, sc(8));
if sel {
- fill(dc, RECT { left: rc.left, top: rc.top + sc(10), right: rc.left + sc(3), bottom: rc.bottom - sc(10) }, ACCENT, sc(3));
+ fill(dc, RECT { left: rc.left, top: rc.top + sc(10), right: rc.left + sc(3), bottom: rc.bottom - sc(10) }, pal().accent, sc(3));
}
let ic = ICONS.with_borrow_mut(|m| {
*m.entry(app.1.clone()).or_insert_with(|| {
@@ -1199,17 +1278,17 @@ unsafe fn paint(hw: HWND, k: Kind) {
DrawIconEx(dc, rc.left + sc(13), (rc.top + rc.bottom - icon_px()) / 2, ic, icon_px(), icon_px(), 0, null_mut(), DI_NORMAL); // at its loaded size: no stretching
}
let store = wstr(&app.1).starts_with("shell:");
- text(dc, &app.0, RECT { left: rc.left + sc(52), top: rc.top, right: rc.right - sc(110), bottom: rc.bottom }, TEXT, DT_LEFT);
+ text(dc, &app.0, RECT { left: rc.left + sc(52), top: rc.top, right: rc.right - sc(110), bottom: rc.bottom }, pal().text, DT_LEFT);
SelectObject(dc, f_small);
let kind = if sel && !q.is_empty() { "Enter ↵" } else if store { t!("Приложение", "App") } else { "" };
- text(dc, kind, RECT { left: rc.right - sc(110), top: rc.top, right: rc.right - sc(14), bottom: rc.bottom }, DIM, DT_RIGHT);
+ text(dc, kind, RECT { left: rc.right - sc(110), top: rc.top, right: rc.right - sc(14), bottom: rc.bottom }, pal().dim, DT_RIGHT);
SelectObject(dc, f_txt);
}
Act::Power(p) => {
let armed = CONFIRM.get() == p as i32;
- glow(dc, rc.top * 4096 + rc.left + 1_000_000, armed || hot(*a), *rc, BG, if armed { BAD } else { HOVER }, sc(8));
+ glow(dc, rc.top * 4096 + rc.left + 1_000_000, armed || hot(*a), *rc, pal().bg, if armed { BAD } else { pal().hover }, sc(8));
SelectObject(dc, f_glyph);
- text(dc, ["\u{E72E}", "\u{E708}", "\u{E777}", "\u{E7E8}"][p as usize], *rc, TEXT, DT_CENTER);
+ text(dc, ["\u{E72E}", "\u{E708}", "\u{E777}", "\u{E7E8}"][p as usize], *rc, pal().text, DT_CENTER);
}
_ => {}
}
@@ -1222,7 +1301,7 @@ unsafe fn paint(hw: HWND, k: Kind) {
_ if !note.is_empty() => note,
_ => std::env::var("USERNAME").unwrap_or_default(),
};
- text(dc, &hint, r(24, h - 52, w - 200, h - 12), DIM, DT_LEFT);
+ text(dc, &hint, r(24, h - 52, w - 200, h - 12), pal().dim, DT_LEFT);
}
}
@@ -1284,10 +1363,10 @@ unsafe extern "system" fn proc(hw: HWND, msg: u32, wp: WPARAM, lp: LPARAM) -> LR
let (w, h) = (sc(size(k).0), sc(size(k).1));
// the panel hangs above the bar: keep its bottom edge where it is and grow / shrink upward
let (x, _) = FIN.get();
- let y = bar_top() - sc(8) - h;
+ let y = pop_y(h);
FIN.set((x, y));
SetWindowPos(hw, null_mut(), x, y, w, h, SWP_NOZORDER | SWP_NOACTIVATE);
- SetWindowRgn(hw, CreateRoundRectRgn(0, 0, w + 1, h + 1, sc(16), sc(16)), 1);
+ SetWindowRgn(hw, CreateRoundRectRgn(0, 0, w + 1, h + 1, rr(16), rr(16)), 1);
}
InvalidateRect(hw, null(), 0);
}
diff --git a/plugins/topbar/src/main.rs b/plugins/topbar/src/main.rs
index df68210..989fa59 100644
--- a/plugins/topbar/src/main.rs
+++ b/plugins/topbar/src/main.rs
@@ -18,6 +18,7 @@ use std::{
#[macro_use]
extern crate winrust_common;
use winrust_common as i18n;
+use winrust_common::style::{Style, pal, style, ui_face};
mod fly;
use windows::{
Win32::{
@@ -36,6 +37,7 @@ use windows_sys::Win32::{
GdiPlus::{
FillModeAlternate, GdipAddPathArc, GdipClosePathFigure, GdipCreateFromHDC, GdipCreatePath, GdipCreateSolidFill, GdipDeleteBrush, GdipDeleteGraphics, GdipDeletePath, GdipFillPath, GdipSetPixelOffsetMode,
GdipSetSmoothingMode, GdiplusStartup, GdiplusStartupInput, GpBrush, GpGraphics, GpPath, GpSolidFill, PixelOffsetModeHalf, SmoothingModeAntiAlias,
+ GdipCreatePen1, GdipDeletePen, GdipDrawArc, GdipDrawLine, GdipFillEllipse, GdipSetPenEndCap, GdipSetPenStartCap, GpPen, LineCapRound, UnitPixel,
},
},
NetworkManagement::WiFi::*,
@@ -48,18 +50,40 @@ use windows_sys::Win32::{
UI::{Input::KeyboardAndMouse::*, Shell::*, WindowsAndMessaging::*},
};
-const fn rgb(r: u8, g: u8, b: u8) -> u32 {
- r as u32 | (g as u32) << 8 | (b as u32) << 16
+use winrust_common::style::rgb;
+/// A corner radius in logical px, 0 in the square styles.
+fn rr(v: i32) -> i32 {
+ if style().square() { 0 } else { sc(v) }
+}
+/// The bar sits at the top of the screen (tiling) instead of the bottom.
+fn at_top() -> bool {
+ style() == Style::Tiling
+}
+/// Gap under the floating dock.
+fn dock_gap() -> i32 {
+ if style() == Style::Dock { sc(8) } else { 0 }
+}
+/// Screen x and width of the bar: the whole screen, or the dock in the middle.
+unsafe fn bar_x_w() -> (i32, i32) {
+ let cx = GetSystemMetrics(SM_CXSCREEN);
+ if style() == Style::Dock {
+ let w = (cx * 3 / 5).max(sc(720)).min(cx);
+ ((cx - w) / 2, w)
+ } else {
+ (0, cx)
+ }
+}
+/// Screen y of the bar's current top edge, slid away by the show/hide animation.
+unsafe fn bar_y() -> i32 {
+ if at_top() { -bar_off() } else { bar_top() + bar_off() }
+}
+/// Screen y of a popup of height `h` next to the bar: above it, or below it when the bar is at the top.
+unsafe fn pop_y(h: i32) -> i32 {
+ if at_top() { bar_h() + sc(8) } else { bar_top() - sc(8) - h }
}
-const BG: u32 = rgb(24, 30, 44);
-const LINE: u32 = rgb(44, 52, 72);
-const HOVER: u32 = rgb(40, 48, 68);
-const ACTIVE: u32 = rgb(52, 61, 84);
-const ACCENT: u32 = rgb(76, 194, 255); // Windows 11 blue
const GOOD: u32 = rgb(108, 203, 95);
const BAD: u32 = rgb(255, 99, 97);
-const TEXT: u32 = rgb(255, 255, 255);
-const DIM: u32 = rgb(150, 158, 175);
+const WARN: u32 = rgb(255, 196, 0);
const CALLBACK: u32 = WM_APP + 1;
const WM_MOUSELEAVE: u32 = 0x02A3; // not exported under the enabled features
const NO_WINDOW: u32 = 0x0800_0000;
@@ -73,6 +97,8 @@ const WIFI_I: i32 = -7;
const VOL_I: i32 = -8;
const BAT_I: i32 = -9;
const TAPP: i32 = -1000;
+const GEAR: i32 = -12; // the gear at the left end: the Style menu
+const GEAR_X: (i32, i32) = (6, 36); // its left edge and width, before scaling (sc() is applied where used)
const SYS_GRP: i32 = -11; // hover key of the one pill around wifi + volume + battery (they open the same panel)
const WIN_START: u32 = WM_APP + 10; // posted by the keyboard hook: Win key pressed alone
const ALT_TAB: u32 = WM_APP + 11; // posted by the keyboard hook: Alt+Tab (wp 1 = Shift held: backwards)
@@ -157,6 +183,7 @@ thread_local! {
static TAPPS: RefCell<Vec<TIcon>> = const { RefCell::new(Vec::new()) };
static SHOWN: RefCell<Option<Vec<String>>> = const { RefCell::new(None) }; // tray icons kept on the bar (by exe); None = none: every tray icon lives in the chevron flyout
static TRAYFLY: Cell<HWND> = const { Cell::new(null_mut()) };
+ static TF_ANIM: Cell<(u64, i32, i32)> = const { Cell::new((0, 0, 0)) }; // tray flyout: when it opened, its final x, y
static FHOT: Cell<i32> = const { Cell::new(-1) };
static HOT: Cell<i32> = const { Cell::new(NONE) };
static ORDER: RefCell<Vec<HWND>> = const { RefCell::new(Vec::new()) }; // unpinned windows in the order their buttons were added
@@ -170,6 +197,7 @@ thread_local! {
static BAT: Cell<(i32, bool)> = const { Cell::new((-1, false)) }; // (percent or -1 = no battery, on AC)
static VOL: Cell<(i32, bool)> = const { Cell::new((-1, false)) }; // (percent or -1 = unknown, muted)
static WIFI: Cell<i32> = const { Cell::new(-1) }; // signal quality 0..100, -1 = not on wifi
+ static INET: Cell<bool> = const { Cell::new(true) }; // Windows sees a way to the internet (any adapter)
static TICK: Cell<u32> = const { Cell::new(0) };
static EP: RefCell<Option<IAudioEndpointVolume>> = const { RefCell::new(None) };
static TB_MSG: Cell<u32> = const { Cell::new(0) }; // "TaskbarCreated"
@@ -188,9 +216,9 @@ fn sc(v: i32) -> i32 {
fn bar_h() -> i32 {
sc(BAR_H)
}
-/// Screen y of the bar's top edge when it is in place (bottom of the primary monitor).
+/// Screen y of the bar's top edge when it is in place (bottom of the primary monitor, or its top in the tiling style).
unsafe fn bar_top() -> i32 {
- GetSystemMetrics(SM_CYSCREEN) - bar_h()
+ if at_top() { 0 } else { GetSystemMetrics(SM_CYSCREEN) - bar_h() - dock_gap() }
}
// ---------- taskbar / appbar ----------
@@ -357,17 +385,36 @@ unsafe fn fly_toggle() {
let w = TRAYFLY.get();
if IsWindowVisible(w) != 0 {
ShowWindow(w, SW_HIDE);
+ InvalidateRect(BAR.load(Relaxed) as HWND, null(), 0); // the bar's chevron turns with it
return;
}
let (_, fw, fh) = fly_size();
FHOT.set(-1);
let scr = GetSystemMetrics(SM_CXSCREEN);
- let cx = layout(scr).apps.0 + sc(12); // above the chevron
- SetWindowRgn(w, CreateRoundRectRgn(0, 0, fw + 1, fh + 1, sc(12), sc(12)), 1);
- SetWindowPos(w, HWND_TOPMOST, (cx - fw / 2).clamp(sc(8), scr - fw - sc(8)), bar_top() - fh - sc(8), fw, fh, SWP_SHOWWINDOW);
+ let (bx, bw) = bar_x_w();
+ let cx = bx + layout(bw).apps.0 + sc(12); // above the chevron
+ SetWindowRgn(w, CreateRoundRectRgn(0, 0, fw + 1, fh + 1, rr(12), rr(12)), 1);
+ let (x, y) = ((cx - fw / 2).clamp(sc(8), scr - fw - sc(8)), pop_y(fh));
+ TF_ANIM.set((now_ms(), x, y));
+ SetLayeredWindowAttributes(w, 0, 0, LWA_ALPHA); // tf_step fades it in
+ SetWindowPos(w, HWND_TOPMOST, x, y + tf_slide(0.0), fw, fh, SWP_SHOWWINDOW);
+ InvalidateRect(BAR.load(Relaxed) as HWND, null(), 0); // the bar's chevron turns with it
+ SetTimer(w, 1, 15, None);
SetForegroundWindow(w); // so that WM_ACTIVATE tells us when the user clicks elsewhere
}
+/// How far the tray flyout still is from its place at opening progress `e` (0..1): it rises toward the bar's far side.
+unsafe fn tf_slide(e: f32) -> i32 {
+ let d = ((1.0 - e) * sc(14) as f32) as i32;
+ if at_top() { -d } else { d }
+}
+
+/// Opening progress 0..1 of the tray flyout, eased, and of its icon `n` (each one starts 25 ms after the previous).
+unsafe fn tf_progress(n: i32) -> f32 {
+ let age = now_ms().saturating_sub(TF_ANIM.get().0) as f32;
+ ease(((age - 25.0 * n as f32) / 200.0).clamp(0.0, 1.0))
+}
+
unsafe extern "system" fn fly_proc(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM) -> LRESULT {
let cell_at = |lp: LPARAM| -> i32 {
let (x, y) = ((lp & 0xffff) as i16 as i32 - sc(8), ((lp >> 16) & 0xffff) as i16 as i32 - sc(8));
@@ -385,24 +432,25 @@ unsafe extern "system" fn fly_proc(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM)
let dc = BeginPaint(hwnd, &mut ps);
let mut r: RECT = zeroed();
GetClientRect(hwnd, &mut r);
- fill(dc, r, LINE, sc(12));
- fill(dc, RECT { left: 1, top: 1, right: r.right - 1, bottom: r.bottom - 1 }, BG, sc(12));
+ fill(dc, r, pal().line, sc(12));
+ fill(dc, RECT { left: 1, top: 1, right: r.right - 1, bottom: r.bottom - 1 }, pal().bg, sc(12));
let (cols, _, _) = fly_size();
let f = tip_font();
let of = SelectObject(dc, f);
SetBkMode(dc, TRANSPARENT as i32);
- SetTextColor(dc, DIM);
+ SetTextColor(dc, pal().dim);
let mut tip = String::new();
let over = over_idx();
TAPPS.with_borrow(|t| {
for (n, ti) in over.iter().map(|&i| &t[i]).enumerate() {
let (x, y) = (sc(8) + (n % cols) as i32 * sc(FCELL), sc(8) + (n / cols) as i32 * sc(FCELL));
if FHOT.get() == n as i32 {
- fill(dc, RECT { left: x, top: y, right: x + sc(FCELL), bottom: y + sc(FCELL) }, HOVER, sc(6));
+ fill(dc, RECT { left: x, top: y, right: x + sc(FCELL), bottom: y + sc(FCELL) }, pal().hover, sc(6));
tip = ti.tip.clone();
}
if !ti.icon.is_null() {
- DrawIconEx(dc, x + sc(9), y + sc(8), ti.icon, sc(20), sc(20), 0, null_mut(), DI_NORMAL);
+ let sz = (sc(20) as f32 * (0.4 + 0.6 * tf_progress(n as i32))) as i32; // pops in
+ DrawIconEx(dc, x + sc(19) - sz / 2, y + sc(18) - sz / 2, ti.icon, sz, sz, 0, null_mut(), DI_NORMAL);
}
}
});
@@ -438,6 +486,7 @@ unsafe extern "system" fn fly_proc(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM)
InvalidateRect(hwnd, null(), 0);
} else {
ShowWindow(hwnd, SW_HIDE);
+ InvalidateRect(BAR.load(Relaxed) as HWND, null(), 0); // the bar's chevron turns with it
tray_click(t, msg == WM_LBUTTONDOWN);
}
}
@@ -445,6 +494,18 @@ unsafe extern "system" fn fly_proc(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM)
}
WM_ACTIVATE if wp & 0xffff == 0 => {
ShowWindow(hwnd, SW_HIDE);
+ InvalidateRect(BAR.load(Relaxed) as HWND, null(), 0); // the bar's chevron turns with it
+ 0
+ }
+ WM_TIMER => {
+ let (_, x, y) = TF_ANIM.get();
+ let e = tf_progress(0);
+ SetLayeredWindowAttributes(hwnd, 0, (255.0 * e) as u8, LWA_ALPHA);
+ SetWindowPos(hwnd, null_mut(), x, y + tf_slide(e), 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
+ InvalidateRect(hwnd, null(), 0);
+ if tf_progress(over_idx().len() as i32) >= 1.0 {
+ KillTimer(hwnd, 1);
+ }
0
}
_ => DefWindowProcW(hwnd, msg, wp, lp),
@@ -454,7 +515,7 @@ unsafe extern "system" fn fly_proc(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM)
// ---------- tray tooltip: a small popup under the icon after the mouse rests on it ----------
unsafe fn tip_font() -> HFONT {
- CreateFontW(-sc(12), 0, 0, 0, 400, 0, 0, 0, 1, 0, 0, 5, 0, wide("Segoe UI").as_ptr())
+ CreateFontW(-sc(12), 0, 0, 0, 400, 0, 0, 0, 1, 0, 0, 5, 0, wide(ui_face()).as_ptr())
}
unsafe extern "system" fn tip_proc(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM) -> LRESULT {
@@ -465,12 +526,12 @@ unsafe extern "system" fn tip_proc(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM)
let dc = BeginPaint(hwnd, &mut ps);
let mut r: RECT = zeroed();
GetClientRect(hwnd, &mut r);
- fill(dc, r, LINE, sc(8));
- fill(dc, RECT { left: 1, top: 1, right: r.right - 1, bottom: r.bottom - 1 }, BG, sc(8));
+ fill(dc, r, pal().line, sc(8));
+ fill(dc, RECT { left: 1, top: 1, right: r.right - 1, bottom: r.bottom - 1 }, pal().bg, sc(8));
let f = tip_font();
let of = SelectObject(dc, f);
SetBkMode(dc, TRANSPARENT as i32);
- SetTextColor(dc, TEXT);
+ SetTextColor(dc, pal().text);
let mut tr = RECT { left: sc(8), top: sc(5), right: r.right - sc(8), bottom: r.bottom - sc(5) };
TIP.with_borrow(|s| DrawTextW(dc, wide(s).as_ptr(), -1, &mut tr, DT_LEFT | DT_NOPREFIX | DT_WORDBREAK));
SelectObject(dc, of);
@@ -485,6 +546,7 @@ unsafe fn tip_text(h: i32) -> String {
SEARCH => "Search".into(),
0 => "Start".into(),
TAPP => "Hidden icons".into(),
+ GEAR => t!("Стиль", "Style").into(),
CLOCK => {
let mut t: SYSTEMTIME = zeroed();
GetLocalTime(&mut t);
@@ -492,10 +554,12 @@ unsafe fn tip_text(h: i32) -> String {
let n = GetDateFormatW(0x0400, 2, &t, null(), b.as_mut_ptr(), 80).max(1) as usize - 1; // DATE_LONGDATE
String::from_utf16_lossy(&b[..n])
}
- LANG => format!("{} · click to switch", lang_name()),
- WIFI_I => match WIFI.get() {
- q if q >= 0 => format!("Wi‑Fi · signal {q}%"),
- _ => "Network".into(),
+ LANG => tf!("Язык ввода: {}", "Input language: {}", layout_names(layouts().1).0),
+ WIFI_I => match net() {
+ Link::Wifi(q) => tf!("Wi‑Fi · сигнал {q}%", "Wi‑Fi · signal {q}%"),
+ Link::NoInternet(_) => t!("Wi‑Fi подключён, но интернета нет", "Wi‑Fi connected, no internet").into(),
+ Link::Cable => t!("Интернет по кабелю", "Internet over a cable").into(),
+ Link::Offline => t!("Нет подключения к сети", "Not connected").into(),
},
VOL_I => vol_tip(),
BAT_I => match BAT.get() {
@@ -544,9 +608,9 @@ unsafe fn show_tip(s: String, cx: i32) {
ReleaseDC(tw, dc);
let (w, h) = (r.right + sc(16), r.bottom + sc(10));
TIP.set(s);
- SetWindowRgn(tw, CreateRoundRectRgn(0, 0, w + 1, h + 1, sc(8), sc(8)), 1);
+ SetWindowRgn(tw, CreateRoundRectRgn(0, 0, w + 1, h + 1, rr(8), rr(8)), 1);
let x = (cx - w / 2).clamp(sc(4), GetSystemMetrics(SM_CXSCREEN) - w - sc(4));
- SetWindowPos(tw, HWND_TOPMOST, x, bar_top() + bar_off() - h - sc(6), w, h, SWP_NOACTIVATE | SWP_SHOWWINDOW);
+ SetWindowPos(tw, HWND_TOPMOST, x, if at_top() { bar_h() - bar_off() + sc(6) } else { bar_top() + bar_off() - h - sc(6) }, w, h, SWP_NOACTIVATE | SWP_SHOWWINDOW);
InvalidateRect(tw, null(), 1);
}
@@ -569,7 +633,7 @@ unsafe fn alt_tab(back: bool) {
let scr = GetSystemMetrics(SM_CXSCREEN);
let w = (n as i32 * sc(SW_CELL)).min(scr - sc(80)) + 2 * sc(SW_PAD);
let h = sc(SW_PAD) + sc(SW_CELL) + sc(SW_TITLE) + sc(SW_PAD) / 2;
- SetWindowRgn(sw, CreateRoundRectRgn(0, 0, w + 1, h + 1, sc(18), sc(18)), 1);
+ SetWindowRgn(sw, CreateRoundRectRgn(0, 0, w + 1, h + 1, rr(18), rr(18)), 1);
SetWindowPos(sw, HWND_TOPMOST, (scr - w) / 2, (GetSystemMetrics(SM_CYSCREEN) - h) / 2, w, h, SWP_NOACTIVATE | SWP_SHOWWINDOW);
} else {
SW.with_borrow_mut(|(v, i)| *i = if back { (*i + v.len() - 1) % v.len() } else { (*i + 1) % v.len() });
@@ -599,8 +663,8 @@ unsafe extern "system" fn sw_proc(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM)
GetClientRect(hwnd, &mut r);
let (mem, bmp) = (CreateCompatibleDC(dc), CreateCompatibleBitmap(dc, r.right, r.bottom));
let ob = SelectObject(mem, bmp);
- fill(mem, r, LINE, sc(18));
- fill(mem, RECT { left: 1, top: 1, right: r.right - 1, bottom: r.bottom - 1 }, BG, sc(18));
+ fill(mem, r, pal().line, sc(18));
+ fill(mem, RECT { left: 1, top: 1, right: r.right - 1, bottom: r.bottom - 1 }, pal().bg, sc(18));
let pad = sc(SW_PAD);
SW.with_borrow(|(v, sel)| {
let cell = (r.right - 2 * pad) / v.len().max(1) as i32;
@@ -609,8 +673,8 @@ unsafe extern "system" fn sw_proc(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM)
let x = pad + k as i32 * cell;
if k == *sel {
let c = RECT { left: x + sc(3), top: pad, right: x + cell - sc(3), bottom: pad + sc(SW_CELL) - sc(6) };
- fill(mem, c, ACCENT, sc(12)); // accent ring around the selected window
- fill(mem, RECT { left: c.left + sc(2), top: c.top + sc(2), right: c.right - sc(2), bottom: c.bottom - sc(2) }, ACTIVE, sc(10));
+ fill(mem, c, pal().accent, sc(12)); // accent ring around the selected window
+ fill(mem, RECT { left: c.left + sc(2), top: c.top + sc(2), right: c.right - sc(2), bottom: c.bottom - sc(2) }, pal().active, sc(10));
}
let ic = icon_of(w);
if !ic.is_null() {
@@ -620,10 +684,10 @@ unsafe extern "system" fn sw_proc(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM)
if let Some(&w) = v.get(*sel) {
let mut b = [0u16; 256];
let n = GetWindowTextW(w, b.as_mut_ptr(), 256).max(0) as usize;
- let f = CreateFontW(-sc(14), 0, 0, 0, 600, 0, 0, 0, 1, 0, 0, 5, 0, wide("Segoe UI").as_ptr());
+ let f = CreateFontW(-sc(14), 0, 0, 0, 600, 0, 0, 0, 1, 0, 0, 5, 0, wide(ui_face()).as_ptr());
let of = SelectObject(mem, f);
SetBkMode(mem, TRANSPARENT as i32);
- text(mem, &String::from_utf16_lossy(&b[..n]), RECT { left: pad, top: pad + sc(SW_CELL) - sc(4), right: r.right - pad, bottom: pad + sc(SW_CELL) + sc(SW_TITLE) - sc(4) }, TEXT, DT_CENTER);
+ text(mem, &String::from_utf16_lossy(&b[..n]), RECT { left: pad, top: pad + sc(SW_CELL) - sc(4), right: r.right - pad, bottom: pad + sc(SW_CELL) + sc(SW_TITLE) - sc(4) }, pal().text, DT_CENTER);
SelectObject(mem, of);
DeleteObject(f);
}
@@ -677,17 +741,31 @@ unsafe fn place(hwnd: HWND) {
let mut ab: APPBARDATA = zeroed();
ab.cbSize = size_of::<APPBARDATA>() as u32;
ab.hWnd = hwnd;
- ab.uEdge = ABE_BOTTOM;
- ab.rc = RECT { left: 0, top: cy - bar_h(), right: cx, bottom: cy };
- SHAppBarMessage(ABM_QUERYPOS, &mut ab);
- ab.rc.top = ab.rc.bottom - bar_h();
+ // the reserved strip: the bar itself plus the dock's gap under it
+ // the dock reserves nothing: maximized windows take the whole screen and the dock slides away over them
+ let strip = if style() == Style::Dock { 0 } else { bar_h() };
+ if at_top() {
+ ab.uEdge = ABE_TOP;
+ ab.rc = RECT { left: 0, top: 0, right: cx, bottom: strip };
+ SHAppBarMessage(ABM_QUERYPOS, &mut ab);
+ ab.rc.bottom = ab.rc.top + strip;
+ } else {
+ ab.uEdge = ABE_BOTTOM;
+ ab.rc = RECT { left: 0, top: cy - strip, right: cx, bottom: cy };
+ SHAppBarMessage(ABM_QUERYPOS, &mut ab);
+ ab.rc.top = ab.rc.bottom - strip;
+ }
SHAppBarMessage(ABM_SETPOS, &mut ab);
// No explorer (rs-shell / rust-explorer): nobody handles appbars, so set the work area ourselves. Without it maximized
// windows slide under the bar and, covering the whole monitor, count as "fullscreen" and hide the bar.
if find_other("Shell_TrayWnd").is_null() {
- set_work_area(RECT { left: 0, top: 0, right: cx, bottom: ab.rc.top });
+ set_work_area(if at_top() { RECT { left: 0, top: ab.rc.bottom, right: cx, bottom: cy } } else { RECT { left: 0, top: 0, right: cx, bottom: ab.rc.top } });
}
- SetWindowPos(hwnd, HWND_TOPMOST, ab.rc.left, ab.rc.top + bar_off(), ab.rc.right - ab.rc.left, bar_h(), SWP_NOACTIVATE);
+ let (x, w) = bar_x_w();
+ // the dock is a pill; the other styles a plain strip
+ SetWindowRgn(hwnd, if style() == Style::Dock { CreateRoundRectRgn(0, 0, w + 1, bar_h() + 1, bar_h(), bar_h()) } else { null_mut() }, 1);
+ SetWindowPos(hwnd, HWND_TOPMOST, x, bar_y(), w, bar_h(), SWP_NOACTIVATE);
+ InvalidateRect(hwnd, null(), 0);
}
unsafe fn set_work_area(mut want: RECT) {
@@ -1002,6 +1080,125 @@ unsafe fn read_wifi() {
}
}
WIFI.set(q);
+ // Windows' own verdict (the same one its tray icon shows): a connection without internet is not "online"
+ use windows_sys::Win32::{NetworkManagement::IpHelper::GetNetworkConnectivityHint, Networking::WinSock::{NL_NETWORK_CONNECTIVITY_HINT, NetworkConnectivityLevelHintConstrainedInternetAccess, NetworkConnectivityLevelHintInternetAccess}};
+ let mut hint: NL_NETWORK_CONNECTIVITY_HINT = zeroed();
+ // a failed call (old Windows) counts as online: never show "no internet" on a guess
+ INET.set(GetNetworkConnectivityHint(&mut hint) != 0 || {
+ let lvl = hint.ConnectivityLevel;
+ lvl == NetworkConnectivityLevelHintInternetAccess || lvl == NetworkConnectivityLevelHintConstrainedInternetAccess
+ });
+}
+
+/// What the network icon shows.
+#[derive(Clone, Copy, PartialEq)]
+enum Link {
+ Wifi(i32), // on wifi with internet, signal 0..100
+ NoInternet(i32), // on wifi, but no way out
+ Cable, // internet over ethernet
+ Offline, // no connection at all
+}
+
+fn net() -> Link {
+ match (WIFI.get(), INET.get()) {
+ (q, true) if q >= 0 => Link::Wifi(q),
+ (q, false) if q >= 0 => Link::NoInternet(q),
+ (_, true) => Link::Cable,
+ _ => Link::Offline,
+ }
+}
+
+/// Wi-Fi arcs lit for a signal of `q` percent: 1..3.
+fn arcs_lit(q: i32) -> i32 {
+ if q >= 67 { 3 } else if q >= 34 { 2 } else { 1 }
+}
+
+/// The Wi-Fi symbol drawn with anti-aliased arcs: `lit` of the 3 arcs in `on`, the rest in `off`, centered on (cx, cy),
+/// `s` px tall. `mark`: 0 none, 1 a cross (not connected), 2 an exclamation mark (connected, no internet).
+unsafe fn wifi_glyph(dc: HDC, cx: i32, cy: i32, s: i32, lit: i32, on: u32, off: u32, mark: u8) {
+ let mut g: *mut GpGraphics = null_mut();
+ if GdipCreateFromHDC(dc, &mut g) != 0 || g.is_null() {
+ return;
+ }
+ GdipSetSmoothingMode(g, SmoothingModeAntiAlias);
+ let argb = |c: u32| 0xFF00_0000 | (c & 255) << 16 | (c & 0xFF00) | (c >> 16 & 255);
+ let pen = |c: u32, w: f32| {
+ let mut p: *mut GpPen = null_mut();
+ GdipCreatePen1(argb(c), w, UnitPixel, &mut p);
+ GdipSetPenStartCap(p, LineCapRound);
+ GdipSetPenEndCap(p, LineCapRound);
+ p
+ };
+ let (sf, w) = (s as f32, (s as f32 * 0.12).max(1.6));
+ let (bx, by) = (cx as f32, cy as f32 + sf * 0.36); // the point the arcs radiate from
+ for i in 0..3 {
+ let r = sf * (0.30 + 0.25 * i as f32);
+ let p = pen(if i < lit { on } else { off }, w);
+ GdipDrawArc(g, p, bx - r, by - r, 2.0 * r, 2.0 * r, 225.0, 90.0);
+ GdipDeletePen(p);
+ }
+ let mut br: *mut GpSolidFill = null_mut();
+ GdipCreateSolidFill(argb(if lit > 0 { on } else { off }), &mut br);
+ GdipFillEllipse(g, br as *mut GpBrush, bx - w * 0.9, by - w * 0.9, w * 1.8, w * 1.8);
+ GdipDeleteBrush(br as *mut GpBrush);
+ // the mark sits at the lower right, on a cut-out of the background so it stays readable over the arcs
+ let (mx, my, mr) = (bx + sf * 0.42, by - sf * 0.08, sf * 0.26);
+ if mark > 0 {
+ let mut bg: *mut GpSolidFill = null_mut();
+ GdipCreateSolidFill(argb(pal().bg), &mut bg);
+ GdipFillEllipse(g, bg as *mut GpBrush, mx - mr, my - mr, 2.0 * mr, 2.0 * mr);
+ GdipDeleteBrush(bg as *mut GpBrush);
+ let c = if mark == 1 { on } else { WARN };
+ let p = pen(c, (w * 0.8).max(1.4));
+ let d = mr * 0.5;
+ if mark == 1 {
+ GdipDrawLine(g, p, mx - d, my - d, mx + d, my + d);
+ GdipDrawLine(g, p, mx + d, my - d, mx - d, my + d);
+ } else {
+ GdipDrawLine(g, p, mx, my - d * 1.2, mx, my + d * 0.2);
+ GdipDrawLine(g, p, mx, my + d * 0.95, mx, my + d * 1.0);
+ }
+ GdipDeletePen(p);
+ }
+ GdipDeleteGraphics(g);
+}
+
+/// Hover key of the tray chevron's turn.
+const TF_KEY: i32 = -13;
+
+/// A chevron of half-width `s` around (cx, cy), drawn with round line ends; `deg` 0 points up, 180 down.
+unsafe fn chevron(dc: HDC, cx: i32, cy: i32, s: i32, deg: f32, c: u32) {
+ let mut g: *mut GpGraphics = null_mut();
+ if GdipCreateFromHDC(dc, &mut g) != 0 || g.is_null() {
+ return;
+ }
+ GdipSetSmoothingMode(g, SmoothingModeAntiAlias);
+ let mut p: *mut GpPen = null_mut();
+ GdipCreatePen1(0xFF00_0000 | (c & 255) << 16 | (c & 0xFF00) | (c >> 16 & 255), (s as f32 * 0.32).max(1.4), UnitPixel, &mut p);
+ GdipSetPenStartCap(p, LineCapRound);
+ GdipSetPenEndCap(p, LineCapRound);
+ let (sn, cs) = deg.to_radians().sin_cos();
+ let pt = |x: f32, y: f32| (cx as f32 + x * cs - y * sn, cy as f32 + x * sn + y * cs);
+ let (sf, h) = (s as f32, s as f32 * 0.5);
+ let (a, b, d) = (pt(-sf, h), pt(0.0, -h), pt(sf, h));
+ GdipDrawLine(g, p, a.0, a.1, b.0, b.1);
+ GdipDrawLine(g, p, b.0, b.1, d.0, d.1);
+ GdipDeletePen(p);
+ GdipDeleteGraphics(g);
+}
+
+/// The network icon of the bar and the panels, for the current state.
+unsafe fn net_icon(dc: HDC, cx: i32, cy: i32, s: i32, f_glyph: HFONT) {
+ let (on, off) = (pal().text, mix(pal().dim, pal().bg, 0.45));
+ match net() {
+ Link::Wifi(q) => wifi_glyph(dc, cx, cy, s, arcs_lit(q), on, off, 0),
+ Link::NoInternet(q) => wifi_glyph(dc, cx, cy, s, arcs_lit(q), mix(on, pal().bg, 0.3), off, 2),
+ Link::Offline => wifi_glyph(dc, cx, cy, s, 0, on, mix(pal().dim, pal().bg, 0.2), 1),
+ Link::Cable => {
+ SelectObject(dc, f_glyph);
+ text(dc, "\u{E839}", RECT { left: cx - s, top: cy - s, right: cx + s, bottom: cy + s }, on, DT_CENTER);
+ }
+ }
}
/// A minimized window that Windows left as a caption stub on the desktop (it sits at the bottom left with its restore /
@@ -1070,13 +1267,16 @@ fn layout(w: i32) -> Layout {
let fixed = (PINS.with_borrow(|p| p.len()) as i32 + 2).min(n);
// ...but never so far right that the windows' buttons run into the tray: then the whole row shifts left
let right_limit = w - margin - (n * (bw + gap) - gap);
- Layout { x0: ((w - (fixed * (bw + gap) - gap)) / 2).min(right_limit).max(sc(8)), bw, gap, apps, sys, clock }
+ Layout { x0: ((w - (fixed * (bw + gap) - gap)) / 2).min(right_limit).max(sc(GEAR_X.0 + GEAR_X.1 + 6)), bw, gap, apps, sys, clock } // clear of the gear
}
unsafe fn hit(hwnd: HWND, x: i32) -> i32 {
let mut r: RECT = zeroed();
GetClientRect(hwnd, &mut r);
let l = layout(r.right);
+ if x < sc(GEAR_X.0 + GEAR_X.1) {
+ return GEAR;
+ }
if x >= l.clock.0 {
return CLOCK;
}
@@ -1133,7 +1333,7 @@ unsafe fn glow(dc: HDC, key: i32, on: bool, r: RECT, from: u32, to: u32, rad: i3
let t = hv(key, on);
let p = press_t(key);
if t > 0.01 || p > 0.0 {
- fill(dc, r, mix(mix(from, to, t), ACCENT, 0.5 * p), rad);
+ fill(dc, r, mix(mix(from, to, t), pal().accent, 0.5 * p), rad);
}
}
@@ -1178,7 +1378,7 @@ unsafe fn appear(key: isize) -> f32 {
/// How far the bar sits below its place: it rises in at start and drops out of the way (and back) when a fullscreen
/// window takes the screen.
fn bar_off() -> i32 {
- ((1.0 - ease(BAR_P.get())) * bar_h() as f32) as i32
+ ((1.0 - ease(BAR_P.get())) * (bar_h() + dock_gap()) as f32) as i32
}
unsafe fn bar_anim(hwnd: HWND) {
@@ -1196,7 +1396,7 @@ unsafe fn bar_step(hwnd: HWND) {
if p > 0.0 && IsWindowVisible(hwnd) == 0 {
ShowWindow(hwnd, SW_SHOWNOACTIVATE);
}
- SetWindowPos(hwnd, HWND_TOPMOST, 0, bar_top() + bar_off(), 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
+ SetWindowPos(hwnd, HWND_TOPMOST, bar_x_w().0, bar_y(), 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
if p == target {
KillTimer(hwnd, 5);
if p == 0.0 {
@@ -1240,8 +1440,8 @@ unsafe fn fs_update(hwnd: HWND) {
// desktop in front: the bar leaves 2 s after the pointer does and comes back at the bottom edge (an open flyout keeps it)
let now = now_ms();
let sh = GetSystemMetrics(SM_CYSCREEN);
- let over = pt.y >= sh - 1 || (pt.y >= sh - bar_h() && BAR_P.get() > 0.0);
- if fs || !desktop_now() || fly::any_open() || over {
+ let over = if at_top() { pt.y <= 0 || (pt.y < bar_h() && BAR_P.get() > 0.0) } else { pt.y >= sh - 1 || (pt.y >= sh - bar_h() - dock_gap() && BAR_P.get() > 0.0) };
+ if fs || !(desktop_now() || dock_covered()) || fly::any_open() || over {
DESK_T.set(now);
}
let desk = !fs && now.saturating_sub(DESK_T.get()) >= 2000;
@@ -1257,6 +1457,23 @@ unsafe fn fs_update(hwnd: HWND) {
}
}
+/// The dock is in the way of the window in front (a maximized one, or one dragged down under it): it hides like over the
+/// desktop and comes back when the pointer touches the bottom edge.
+unsafe fn dock_covered() -> bool {
+ if style() != Style::Dock {
+ return false;
+ }
+ let fg = GetForegroundWindow();
+ if fg.is_null() || IsIconic(fg) != 0 || fg == BAR.load(Relaxed) as HWND || fly::any_open() {
+ return false;
+ }
+ let mut r: RECT = zeroed();
+ GetWindowRect(fg, &mut r);
+ let (x, w) = bar_x_w();
+ let top = GetSystemMetrics(SM_CYSCREEN) - bar_h() - dock_gap();
+ r.bottom > top && r.right > x && r.left < x + w
+}
+
/// SetForegroundWindow that also works when the request comes from a keyboard hook (we have not "received input" then):
/// attaching to the foreground thread's input queue lifts the restriction for the moment.
unsafe fn force_fg(hw: HWND) {
@@ -1339,6 +1556,7 @@ unsafe extern "system" fn kb_hook(n: i32, w: WPARAM, l: LPARAM) -> LRESULT {
/// Fills `r` (right / bottom exclusive) in colour `c`; `rad` > 0 rounds the corners (rad = corner diameter), anti-aliased
/// through GDI+. Plain GDI for square boxes and when GDI+ is not available.
unsafe fn fill(dc: HDC, r: RECT, c: u32, rad: i32) {
+ let rad = if style().square() { 0 } else { rad };
let (w, h) = ((r.right - r.left) as f32, (r.bottom - r.top) as f32);
if w <= 0.0 || h <= 0.0 {
return;
@@ -1464,16 +1682,53 @@ unsafe fn screenshot_notice(bar: HWND) {
/// Next keyboard layout for the app window. Posted to its focused control (that is where Chrome, Office... look for it);
/// timer 7 checks it took and otherwise presses Win+Space, the system switcher (games, terminals ignore the message).
-unsafe fn next_lang(bar: HWND) {
- let w = app_window();
- let tid = GetWindowThreadProcessId(w, null_mut());
+/// The installed keyboard layouts and the one the app in front uses.
+unsafe fn layouts() -> (Vec<HKL>, HKL) {
let mut l: [HKL; 32] = [null_mut(); 32];
let n = GetKeyboardLayoutList(32, l.as_mut_ptr()).clamp(0, 32) as usize;
- let cur = GetKeyboardLayout(tid);
- if n < 2 {
+ (l[..n].to_vec(), GetKeyboardLayout(GetWindowThreadProcessId(app_window(), null_mut())))
+}
+
+/// A layout's language as Windows names it in the user's language ("Русский (Россия)"), and its short code ("RUS").
+unsafe fn layout_names(k: HKL) -> (String, String) {
+ let id = k as usize as u32 & 0xffff;
+ let get = |what: u32| {
+ let mut b = [0u16; 96];
+ let n = GetLocaleInfoW(id, what, b.as_mut_ptr(), 96).max(1) as usize - 1;
+ String::from_utf16_lossy(&b[..n])
+ };
+ let short = get(3).to_uppercase(); // LOCALE_SABBREVLANGNAME
+ (get(2), if short == "ENU" { "ENG".into() } else { short }) // LOCALE_SLOCALIZEDDISPLAYNAME
+}
+
+/// The input language picker above the language button.
+unsafe fn lang_menu(bar: HWND) {
+ let (list, cur) = layouts();
+ let mut items: Vec<fly::MItem> = list.iter().map(|&k| {
+ let (name, short) = layout_names(k);
+ fly::MItem::new(name).on(k == cur).hint(Box::leak(short.into_boxed_str())) // a handful of short strings, kept for the bar's lifetime
+ }).collect();
+ items.push(fly::MItem::new(t!("Языковые параметры", "Language settings")).sep());
+ let head = (null_mut(), "\u{E775}", t!("Язык ввода", "Input language").to_string(), t!("Win+Пробел — следующий", "Win+Space — next one").to_string());
+ fly::menu(tip_cx(&bar_layout(bar), LANG), Some(head), items, move |i| match list.get(i) {
+ Some(&k) => set_lang(bar, k),
+ None => open(&wide("ms-settings:regionlanguage")),
+ });
+}
+
+unsafe fn next_lang(bar: HWND) {
+ let (l, cur) = layouts();
+ if l.len() < 2 {
return; // one layout: nothing to switch to
}
- let next = l[(l[..n].iter().position(|&k| k == cur).map_or(0, |i| i + 1)) % n];
+ set_lang(bar, l[l.iter().position(|&k| k == cur).map_or(0, |i| i + 1) % l.len()]);
+}
+
+/// Asks the app in front to switch to layout `next` (the bar's own thread cannot change another app's language).
+unsafe fn set_lang(bar: HWND, next: HKL) {
+ let w = app_window();
+ let tid = GetWindowThreadProcessId(w, null_mut());
+ let cur = GetKeyboardLayout(tid);
let mut gi: GUITHREADINFO = zeroed();
gi.cbSize = size_of::<GUITHREADINFO>() as u32;
let target = if GetGUIThreadInfo(tid, &mut gi) != 0 && !gi.hwndFocus.is_null() { gi.hwndFocus } else { w };
@@ -1500,7 +1755,7 @@ unsafe fn view_sig() -> u64 {
use std::hash::{Hash, Hasher};
let mut h = std::collections::hash_map::DefaultHasher::new();
BTNS.with_borrow(|b| b.iter().for_each(|b| (b.pin, b.icon as usize, b.wins.iter().map(|&w| (w as usize, IsIconic(w))).collect::<Vec<_>>()).hash(&mut h)));
- (GetForegroundWindow() as usize, BAT.get(), VOL.get(), WIFI.get(), EXPLORER_UP.load(Relaxed), clock_texts(), lang_name()).hash(&mut h);
+ (GetForegroundWindow() as usize, BAT.get(), VOL.get(), WIFI.get(), INET.get(), EXPLORER_UP.load(Relaxed), clock_texts(), lang_name()).hash(&mut h);
TAPPS.with_borrow(|t| t.iter().for_each(|x| (x.hwnd as usize, x.uid, x.icon as usize, x.hidden, &x.tip).hash(&mut h)));
h.finish()
}
@@ -1524,14 +1779,17 @@ unsafe fn paint(hwnd: HWND) {
let (dc, bmp) = (CreateCompatibleDC(wdc), CreateCompatibleBitmap(wdc, cr.right, h));
let old = SelectObject(dc, bmp);
// frosted-glass look: a hairline on top, a faint light catch under it, then the panel colour fading in
- let lit = mix(BG, TEXT, 0.045);
+ let lit = mix(pal().bg, pal().text, 0.045);
for y in 0..h {
- fill(dc, RECT { left: 0, top: y, right: cr.right, bottom: y + 1 }, mix(lit, BG, (y as f32 / sc(18) as f32).min(1.0)), 0);
+ fill(dc, RECT { left: 0, top: y, right: cr.right, bottom: y + 1 }, mix(lit, pal().bg, (y as f32 / sc(18) as f32).min(1.0)), 0);
+ }
+ let edge = if at_top() { h - 1 } else { 0 }; // the hairline faces the windows
+ fill(dc, RECT { left: 0, top: edge, right: cr.right, bottom: edge + 1 }, pal().line, 0);
+ if !at_top() {
+ fill(dc, RECT { left: 0, top: 1, right: cr.right, bottom: 2 }, mix(pal().bg, pal().text, 0.08), 0);
}
- fill(dc, RECT { left: 0, top: 0, right: cr.right, bottom: 1 }, LINE, 0);
- fill(dc, RECT { left: 0, top: 1, right: cr.right, bottom: 2 }, mix(BG, TEXT, 0.08), 0);
SetBkMode(dc, TRANSPARENT as i32);
- let (face, gface) = (wide("Segoe UI"), wide("Segoe MDL2 Assets"));
+ let (face, gface) = (wide(ui_face()), wide("Segoe MDL2 Assets"));
let font = |f: &[u16], px: i32, wt: i32| CreateFontW(-sc(px), 0, 0, 0, wt, 0, 0, 0, 1, 0, 0, 5, 0, f.as_ptr());
let (f_txt, f_small, f_glyph, f_bold) = (font(&face, 13, 400), font(&face, 12, 400), font(&gface, 16, 400), font(&face, 13, 600));
let of = SelectObject(dc, f_txt);
@@ -1542,13 +1800,19 @@ unsafe fn paint(hwnd: HWND) {
let mid = (top + bot) / 2;
let cell = |x: i32, w: i32| RECT { left: x, top, right: x + w, bottom: bot };
let hot = HOT.get();
- let active_bg = mix(ACTIVE, ACCENT, 0.12); // the focused app's button: a hint of the accent, not plain grey
+ let active_bg = mix(pal().active, pal().accent, 0.12); // the focused app's button: a hint of the accent, not plain grey
+
+ // the gear at the left end: the Style menu
+ let gr = RECT { left: sc(GEAR_X.0), top, right: sc(GEAR_X.0 + GEAR_X.1), bottom: bot };
+ glow(dc, GEAR, hot == GEAR, gr, pal().bg, pal().hover, sc(8));
+ SelectObject(dc, f_glyph);
+ text(dc, "\u{E713}", gr, if hot == GEAR { pal().text } else { mix(pal().dim, pal().text, 0.5) }, DT_CENTER);
// search button (left of Start)
let sb = RECT { left: l.x0, top, right: l.x0 + l.bw, bottom: bot };
- glow(dc, SEARCH, hot == SEARCH, sb, BG, HOVER, sc(8));
+ glow(dc, SEARCH, hot == SEARCH, sb, pal().bg, pal().hover, sc(8));
SelectObject(dc, f_glyph);
- text(dc, "\u{E721}", sb, if hot == SEARCH { TEXT } else { mix(DIM, TEXT, 0.5) }, DT_CENTER);
+ text(dc, "\u{E721}", sb, if hot == SEARCH { pal().text } else { mix(pal().dim, pal().text, 0.5) }, DT_CENTER);
// Start, pinned apps, open windows (center)
BTNS.with_borrow(|btns| {
@@ -1558,13 +1822,13 @@ unsafe fn paint(hwnd: HWND) {
let act = b.wins.contains(&fg);
let (th, ta, tp) = (hv(i as i32, hot == i as i32), hv(2000 + i as i32, act), press_t(i as i32));
if th > 0.01 || ta > 0.01 || tp > 0.0 {
- fill(dc, r, mix(mix(mix(BG, HOVER, th), active_bg, ta), ACCENT, 0.5 * tp), sc(8));
+ fill(dc, r, mix(mix(mix(pal().bg, pal().hover, th), active_bg, ta), pal().accent, 0.5 * tp), sc(8));
}
if i == 0 {
// Windows logo in four tiles, lit from the top left; grows a little on hover, squeezes on click
let t = ((sc(8) as f32) * (1.0 + 0.12 * th) * (1.0 - 0.2 * tp)) as i32;
let (g, cx) = (sc(1).max(1), (r.left + r.right) / 2);
- let tint = [mix(ACCENT, TEXT, 0.35), mix(ACCENT, TEXT, 0.15), mix(ACCENT, TEXT, 0.15), ACCENT];
+ let tint = [mix(pal().accent, pal().text, 0.35), mix(pal().accent, pal().text, 0.15), mix(pal().accent, pal().text, 0.15), pal().accent];
for (k, (dx, dy)) in [(-1, -1), (0, -1), (-1, 0), (0, 0)].into_iter().enumerate() {
let (px, py) = (cx + if dx < 0 { -t - g } else { g }, mid + if dy < 0 { -t - g } else { g });
fill(dc, RECT { left: px, top: py, right: px + t, bottom: py + t }, tint[k], sc(3));
@@ -1585,7 +1849,7 @@ unsafe fn paint(hwnd: HWND) {
let min = b.wins.iter().all(|&w| IsIconic(w) != 0);
let pw = sc(6) + (sc(12) as f32 * ta) as i32; // the running-app pill stretches when its window is active
let py = bot - sc(4);
- let col = if act { ACCENT } else if min { mix(DIM, BG, 0.45) } else { DIM };
+ let col = if act { pal().accent } else if min { mix(pal().dim, pal().bg, 0.45) } else { pal().dim };
fill(dc, RECT { left: x + (l.bw - pw) / 2, top: py, right: x + (l.bw + pw) / 2, bottom: py + sc(3) }, col, sc(3));
if b.wins.len() > 1 {
// a second, shorter pill: more than one window behind this button
@@ -1596,19 +1860,22 @@ unsafe fn paint(hwnd: HWND) {
});
// a hairline between the app buttons and the tray side
- fill(dc, RECT { left: l.apps.0 - sc(5), top: mid - sc(9), right: l.apps.0 - sc(5) + 1, bottom: mid + sc(9) }, LINE, 0);
+ fill(dc, RECT { left: l.apps.0 - sc(5), top: mid - sc(9), right: l.apps.0 - sc(5) + 1, bottom: mid + sc(9) }, pal().line, 0);
// tray apps
- glow(dc, TAPP, hot == TAPP, cell(l.apps.0, sc(24)), BG, HOVER, sc(8));
+ glow(dc, TAPP, hot == TAPP, cell(l.apps.0, sc(24)), pal().bg, pal().hover, sc(8));
SelectObject(dc, f_glyph);
- text(dc, "\u{E70E}", cell(l.apps.0, sc(24)), if IsWindowVisible(TRAYFLY.get()) != 0 { ACCENT } else { TEXT }, DT_CENTER); // chevron up: the flyout above
+ let open_tf = IsWindowVisible(TRAYFLY.get()) != 0;
+ let turn = ease(hv(TF_KEY, open_tf)); // the chevron turns over as the flyout opens, and back
+ let cc = cell(l.apps.0, sc(24));
+ chevron(dc, (cc.left + cc.right) / 2, mid, sc(5), if at_top() { 180.0 } else { 0.0 } + 180.0 * turn, mix(pal().text, pal().accent, turn));
SelectObject(dc, f_txt);
let bar = bar_idx();
TAPPS.with_borrow(|t| {
for (k, &ix) in bar.iter().enumerate() {
let (i, ti) = (k + 1, &t[ix]);
let x = l.apps.0 + i as i32 * sc(24);
- glow(dc, TAPP + i as i32, hot == TAPP + i as i32, cell(x, sc(24)), BG, HOVER, sc(8));
+ glow(dc, TAPP + i as i32, hot == TAPP + i as i32, cell(x, sc(24)), pal().bg, pal().hover, sc(8));
if !ti.icon.is_null() {
DrawIconEx(dc, x + sc(4), mid - sc(8), ti.icon, sc(16), sc(16), 0, null_mut(), DI_NORMAL);
}
@@ -1617,54 +1884,43 @@ unsafe fn paint(hwnd: HWND) {
// system group: language on its own, then one pill for wifi + volume + battery (like Windows 11: they open one panel)
let tb = RECT { left: l.sys.0, top, right: l.sys.1, bottom: bot };
- glow(dc, LANG, hot == LANG, RECT { left: tb.left, top, right: tb.left + sc(42), bottom: bot }, BG, HOVER, sc(8));
+ glow(dc, LANG, hot == LANG, RECT { left: tb.left, top, right: tb.left + sc(42), bottom: bot }, pal().bg, pal().hover, sc(8));
let grp = RECT { left: tb.left + sc(44), top, right: tb.right, bottom: bot };
let (tg, pg) = (hv(SYS_GRP, matches!(hot, WIFI_I | VOL_I | BAT_I) || fly::is_open(fly::Kind::Quick)), press_t(WIFI_I).max(press_t(VOL_I)).max(press_t(BAT_I)));
if tg > 0.01 || pg > 0.0 {
- fill(dc, grp, mix(mix(BG, HOVER, tg), ACCENT, 0.5 * pg), sc(8));
+ fill(dc, grp, mix(mix(pal().bg, pal().hover, tg), pal().accent, 0.5 * pg), sc(8));
}
let mut x = tb.left + sc(10);
- text(dc, &lang_name(), cell(x, sc(34)), TEXT, DT_LEFT);
+ text(dc, &lang_name(), cell(x, sc(34)), pal().text, DT_LEFT);
x += sc(42);
- let q = WIFI.get();
- if q >= 0 {
- let lit = ((q + 24) / 25).clamp(1, 4); // 1..4 bars
- for i in 0..4 {
- let bh = sc(4 + 3 * i);
- let bx = x + sc(5) * i;
- fill(dc, RECT { left: bx, top: mid + sc(7) - bh, right: bx + sc(3), bottom: mid + sc(7) }, if i < lit { TEXT } else { mix(DIM, BG, 0.45) }, sc(2));
- }
- } else {
- SelectObject(dc, f_glyph);
- text(dc, "\u{E839}", cell(x - sc(2), sc(22)), TEXT, DT_CENTER); // ethernet
- }
+ net_icon(dc, x + sc(9), mid, sc(17), f_glyph);
x += sc(32);
SelectObject(dc, f_glyph);
let (vol, muted) = VOL.get();
let vg = if muted || vol == 0 { "\u{E74F}" } else if vol < 34 { "\u{E993}" } else if vol < 67 { "\u{E994}" } else { "\u{E995}" };
- text(dc, vg, cell(x, sc(22)), if muted { BAD } else { TEXT }, DT_CENTER);
+ text(dc, vg, cell(x, sc(22)), if muted { BAD } else { pal().text }, DT_CENTER);
x += sc(32);
let (pct, ac) = BAT.get();
if pct >= 0 {
- let col = if ac { GOOD } else if pct <= 15 { BAD } else { TEXT };
+ let col = if ac { GOOD } else if pct <= 15 { BAD } else { pal().text };
let (bw, bh, by) = (sc(22), sc(11), mid - sc(5));
fill(dc, RECT { left: x, top: by, right: x + bw, bottom: by + bh }, col, sc(4)); // outline
- fill(dc, RECT { left: x + sc(1), top: by + sc(1), right: x + bw - sc(1), bottom: by + bh - sc(1) }, mix(BG, HOVER, tg), sc(3));
+ fill(dc, RECT { left: x + sc(1), top: by + sc(1), right: x + bw - sc(1), bottom: by + bh - sc(1) }, mix(pal().bg, pal().hover, tg), sc(3));
let fw = ((bw - sc(4)) * pct / 100).max(sc(1));
fill(dc, RECT { left: x + sc(2), top: by + sc(2), right: x + sc(2) + fw, bottom: by + bh - sc(2) }, col, sc(2));
fill(dc, RECT { left: x + bw + sc(1), top: by + sc(3), right: x + bw + sc(3), bottom: by + bh - sc(3) }, col, sc(1)); // terminal nub
SelectObject(dc, f_txt);
- text(dc, &format!("{pct}%"), cell(x + bw + sc(8), sc(40)), TEXT, DT_LEFT);
+ text(dc, &format!("{pct}%"), cell(x + bw + sc(8), sc(40)), pal().text, DT_LEFT);
}
// time (semibold) over the date (dimmed)
let cb = cell(l.clock.0, l.clock.1 - l.clock.0);
- glow(dc, CLOCK, hot == CLOCK || fly::is_open(fly::Kind::Cal), cb, BG, HOVER, sc(8));
+ glow(dc, CLOCK, hot == CLOCK || fly::is_open(fly::Kind::Cal), cb, pal().bg, pal().hover, sc(8));
let (tm, dt) = clock_texts();
SelectObject(dc, f_bold);
- text(dc, &tm, RECT { left: cb.left, top: cb.top, right: cb.right, bottom: mid + sc(1) }, TEXT, DT_CENTER);
+ text(dc, &tm, RECT { left: cb.left, top: cb.top, right: cb.right, bottom: mid + sc(1) }, pal().text, DT_CENTER);
SelectObject(dc, f_small);
- text(dc, &dt, RECT { left: cb.left, top: mid - sc(1), right: cb.right, bottom: cb.bottom }, mix(DIM, TEXT, 0.35), DT_CENTER);
+ text(dc, &dt, RECT { left: cb.left, top: mid - sc(1), right: cb.right, bottom: cb.bottom }, mix(pal().dim, pal().text, 0.35), DT_CENTER);
BitBlt(wdc, 0, 0, cr.right, h, dc, 0, 0, SRCCOPY);
SelectObject(dc, of);
@@ -1772,29 +2028,29 @@ unsafe fn app_menu(hwnd: HWND, h: i32) {
for &w in wins.iter().take(6) {
let mut b = [0u16; 256];
let n = GetWindowTextW(w, b.as_mut_ptr(), 256).max(0) as usize;
- items.push((fly::MItem { icon: icon_of(w), ..fly::MItem::new("", String::from_utf16_lossy(&b[..n])) }, A::Win(w)));
+ items.push((fly::MItem { icon: icon_of(w), ..fly::MItem::new(String::from_utf16_lossy(&b[..n])) }, A::Win(w)));
}
}
if !launch.is_empty() {
- let it = fly::MItem::new("\u{E8A7}", if wins.is_empty() { t!("Открыть", "Open") } else { t!("Новое окно", "New window") });
+ let it = fly::MItem::new(if wins.is_empty() { t!("Открыть", "Open") } else { t!("Новое окно", "New window") });
items.push((if items.is_empty() { it } else { it.sep() }, A::Open));
}
if pin.is_some() {
- items.push((fly::MItem::new("\u{E77A}", t!("Открепить от панели", "Unpin from the bar")), A::Pin));
+ items.push((fly::MItem::new(t!("Открепить от панели", "Unpin from the bar")), A::Pin));
} else if !exe.is_empty() {
- items.push((fly::MItem::new("\u{E718}", t!("Закрепить на панели", "Pin to the bar")), A::Pin));
+ items.push((fly::MItem::new(t!("Закрепить на панели", "Pin to the bar")), A::Pin));
}
if !launch.is_empty() {
let s = fly::start_pinned(&launch);
- items.push((fly::MItem::new(if s { "\u{E738}" } else { "\u{E710}" }, if s { t!("Убрать из Пуска", "Remove from Start") } else { t!("Добавить в Пуск", "Add to Start") }), A::Start));
+ items.push((fly::MItem::new(if s { t!("Убрать из Пуска", "Remove from Start") } else { t!("Добавить в Пуск", "Add to Start") }), A::Start));
}
if !wins.is_empty() {
- items.push((fly::MItem::new("\u{E8BB}", if wins.len() > 1 { t!("Закрыть все окна", "Close all windows") } else { t!("Закрыть окно", "Close window") }).sep(), A::Close));
- items.push((fly::MItem::new("\u{E7BA}", t!("Завершить процесс", "End process")).danger(), A::Kill));
+ items.push((fly::MItem::new(if wins.len() > 1 { t!("Закрыть все окна", "Close all windows") } else { t!("Закрыть окно", "Close window") }).hint("Alt+F4").sep(), A::Close));
+ items.push((fly::MItem::new(t!("Завершить процесс", "End process")).danger(), A::Kill));
}
let acts: Vec<A> = items.iter().map(|x| x.1).collect();
let items = items.into_iter().map(|x| x.0).collect();
- fly::menu(tip_cx(&bar_layout(hwnd), h), Some((icon, name, sub)), items, move |i| {
+ fly::menu(tip_cx(&bar_layout(hwnd), h), Some((icon, "", name, sub)), items, move |i| {
match acts.get(i).copied() {
Some(A::Win(w)) => {
if IsIconic(w) != 0 {
@@ -1941,6 +2197,36 @@ unsafe fn open_launcher() -> bool {
true
}
+/// The gear's menu: the UI style (saved for the other WinRust programs) and putting the windows side by side.
+unsafe fn style_menu() {
+ let bar = BAR.load(Relaxed) as HWND;
+ let names = [t!("Обычный", "Normal"), t!("Терминал", "Terminal"), t!("Плавающий док", "Floating dock"), t!("Тайлинг", "Tiling")];
+ let mut items: Vec<fly::MItem> = i18n::style::ALL.iter().zip(names).map(|(&s, n)| fly::MItem::new(n).on(s == style())).collect();
+ items.push(fly::MItem::new(t!("Разложить окна плиткой", "Tile the windows")).sep());
+ let head = (null_mut(), "\u{E713}", t!("Стиль", "Style").to_string(), t!("Вид панели и программ WinRust", "Look of the bar and the WinRust programs").to_string());
+ fly::menu(tip_cx(&bar_layout(bar), GEAR), Some(head), items, move |i| match i18n::style::ALL.get(i) {
+ Some(&s) => {
+ i18n::style::set_style(s);
+ place(bar);
+ }
+ None => tile_windows(),
+ });
+}
+
+/// Puts the open, not minimized windows side by side in the work area.
+unsafe fn tile_windows() {
+ let wins: Vec<HWND> = BTNS.with_borrow(|b| b.iter().flat_map(|b| b.wins.iter().copied()).filter(|&w| IsIconic(w) == 0).collect());
+ if wins.is_empty() {
+ return;
+ }
+ let mut wa: RECT = zeroed();
+ SystemParametersInfoW(SPI_GETWORKAREA, 0, &mut wa as *mut _ as *mut _, 0);
+ for &w in &wins {
+ ShowWindow(w, SW_RESTORE); // a maximized window ignores tiling
+ }
+ TileWindows(null_mut(), MDITILE_VERTICAL, &wa, wins.len() as u32, wins.as_ptr());
+}
+
unsafe fn click(h: i32, left: bool, mid: bool) {
match h {
SEARCH if left => {
@@ -1953,11 +2239,13 @@ unsafe fn click(h: i32, left: bool, mid: bool) {
fly::toggle(fly::Kind::Start);
}
}
- // next input language; Win+Space is handled by explorer's input switcher, which is gone under rs-shell
- LANG if left => next_lang(BAR.load(Relaxed) as HWND),
+ // left: the language picker; right: straight to the next one (Win+Space is explorer's, gone under rs-shell)
+ LANG if left => lang_menu(BAR.load(Relaxed) as HWND),
+ LANG => next_lang(BAR.load(Relaxed) as HWND),
WIFI_I => fly::toggle(if left { fly::Kind::Quick } else { fly::Kind::Wifi }), // right click: the network list
VOL_I | BAT_I => fly::toggle(fly::Kind::Quick),
CLOCK if left => fly::toggle(fly::Kind::Cal),
+ GEAR => style_menu(),
TAPP..=-900 => {
let slot = (h - TAPP) as usize;
if slot == 0 {
@@ -2022,13 +2310,14 @@ unsafe fn min_rect(info: *mut ShellHookInfo, bar: HWND) {
Some(i) => l.x0 + (i as i32 + 1) * (l.bw + l.gap),
None => (l.x0 + l.apps.0) / 2, // no button (yet): the middle of the bar
};
- let top = bar_top() + sc(4);
+ let (top, x) = (bar_top() + sc(4), x + bar_x_w().0);
(*info).rc = RECT { left: x, top, right: x + l.bw, bottom: top + bar_h() - sc(8) };
}
-/// Screen x of the middle of a bar element (the bar spans the screen from x = 0), for its tooltip.
-fn tip_cx(l: &Layout, h: i32) -> i32 {
- match h {
+/// Screen x of the middle of a bar element, for its tooltip and menus.
+unsafe fn tip_cx(l: &Layout, h: i32) -> i32 {
+ bar_x_w().0 + match h {
+ GEAR => sc(GEAR_X.0 + GEAR_X.1 / 2),
SEARCH => l.x0 + l.bw / 2,
CLOCK => (l.clock.0 + l.clock.1) / 2,
LANG => l.sys.0 + sc(21),
@@ -2255,7 +2544,7 @@ fn main() {
}
let fc = wide("topbar_trayfly");
RegisterClassW(&WNDCLASSW { lpfnWndProc: Some(fly_proc), hInstance: hi, hCursor: LoadCursorW(null_mut(), IDC_ARROW), lpszClassName: fc.as_ptr(), ..zeroed() });
- TRAYFLY.set(CreateWindowExW(WS_EX_TOOLWINDOW | WS_EX_TOPMOST, fc.as_ptr(), null(), WS_POPUP, 0, 0, 1, 1, null_mut(), null_mut(), hi, null()));
+ TRAYFLY.set(CreateWindowExW(WS_EX_TOOLWINDOW | WS_EX_TOPMOST | WS_EX_LAYERED, fc.as_ptr(), null(), WS_POPUP, 0, 0, 1, 1, null_mut(), null_mut(), hi, null()));
let tipc = wide("topbar_tip");
RegisterClassW(&WNDCLASSW { lpfnWndProc: Some(tip_proc), hInstance: hi, lpszClassName: tipc.as_ptr(), ..zeroed() });
TIPWND.set(CreateWindowExW(WS_EX_TOOLWINDOW | WS_EX_TOPMOST | WS_EX_NOACTIVATE, tipc.as_ptr(), null(), WS_POPUP, 0, 0, 1, 1, null_mut(), null_mut(), hi, null()));
@@ -2300,6 +2589,21 @@ fn main() {
#[cfg(test)]
mod tests {
+ #[test]
+ fn network_icon_state() {
+ use super::{INET, Link, WIFI, arcs_lit, net};
+ let at = |q: i32, inet: bool| {
+ WIFI.set(q);
+ INET.set(inet);
+ net()
+ };
+ assert!(at(80, true) == Link::Wifi(80));
+ assert!(at(80, false) == Link::NoInternet(80)); // wifi without a way out: the warning icon
+ assert!(at(-1, true) == Link::Cable);
+ assert!(at(-1, false) == Link::Offline); // nothing at all: the crossed-out wifi icon
+ assert_eq!((arcs_lit(0), arcs_lit(40), arcs_lit(100)), (1, 2, 3));
+ }
+
#[test]
fn mix_blends() {
assert_eq!(super::mix(super::rgb(0, 0, 0), super::rgb(200, 100, 50), 0.0), super::rgb(0, 0, 0));