diff --git a/plugins/topbar/src/fly.rs b/plugins/topbar/src/fly.rs index 1bdba3ec..8c2b2fad 100644 --- a/plugins/topbar/src/fly.rs +++ b/plugins/topbar/src/fly.rs @@ -1018,21 +1018,23 @@ pub fn context_menu(x: i32) { let mut items = vec![ MItem::new(t!("Параметры Windows", "Windows Settings", ja: "Windows の設定", pt: "Configurações do Windows", zh: "Windows 设置")).hint("Win+I"), MItem::new(t!("Персонализация", "Personalization", ja: "個人用設定", pt: "Personalização", zh: "个性化")), + MItem::new(t!("Настройки панели", "Bar settings", ja: "バーの設定", pt: "Configurações da barra", zh: "任务栏设置")), MItem::new(t!("Диспетчер задач", "Task Manager", ja: "タスク マネージャー", pt: "Gerenciador de Tarefas", zh: "任务管理器")).hint("Ctrl+Shift+Esc").sep(), MItem::new(t!("Чистильщик диска", "Disk Cleaner", ja: "ディスク クリーナー", pt: "Limpador de Disco", zh: "磁盘清理")), MItem::new(t!("Закрыть панель", "Close the bar", ja: "バーを閉じる", pt: "Fechar a barra", zh: "关闭任务栏")).danger().sep(), ]; if pu { - items.insert(4, MItem::new(t!("Удалить мусор Windows (необратимо)", "Remove Windows junk (irreversible)", ja: "Windows の不要なものを削除 (元に戻せません)", pt: "Remover lixo do Windows (irreversível)", zh: "删除 Windows 垃圾文件(不可恢复)")).danger()); + items.insert(5, MItem::new(t!("Удалить мусор Windows (необратимо)", "Remove Windows junk (irreversible)", ja: "Windows の不要なものを削除 (元に戻せません)", pt: "Remover lixo do Windows (irreversível)", zh: "删除 Windows 垃圾文件(不可恢复)")).danger()); } menu(x, None, items, move |i| unsafe { - let i = if pu && i == 4 { 99 } else { i }; + let i = if pu && i == 5 { 99 } else { i }; match i { 0 => open(&wide("ms-settings:")), 1 => open(&wide("ms-settings:personalization")), + 2 => crate::style_menu(), // the gear's menu: the way in when the gear button is hidden // with rtaskmgr-win32 installed this is our task manager; a full path because explorer.exe does not search PATH - 2 => open(&wide(&format!(r"{}\System32\taskmgr.exe", std::env::var("SystemRoot").unwrap_or_else(|_| r"C:\Windows".into())))), - 3 => open_cleaner(), + 3 => open(&wide(&format!(r"{}\System32\taskmgr.exe", std::env::var("SystemRoot").unwrap_or_else(|_| r"C:\Windows".into())))), + 4 => open_cleaner(), 99 => crate::open_purge(), _ => _ = PostMessageW(FindWindowW(wide("topbar").as_ptr(), null()), WM_CLOSE, 0, 0), // quits the bar, brings the Windows taskbar back } diff --git a/plugins/topbar/src/main.rs b/plugins/topbar/src/main.rs index 2f463d84..7a30b059 100644 --- a/plugins/topbar/src/main.rs +++ b/plugins/topbar/src/main.rs @@ -130,7 +130,6 @@ const BAR_H: i32 = 40; const NONE: i32 = -1; const SEARCH: i32 = -10; const TASKVIEW: i32 = -14; // Task View button (virtual desktops), right of search (#83) -const LEAD: i32 = 2; // slots before Start: search, Task View const CLOCK: i32 = -4; const LANG: i32 = -6; const WIFI_I: i32 = -7; @@ -1611,6 +1610,46 @@ fn power_off_marker() -> PathBuf { appdata_file("topbar-no-power.txt") } +// Bar buttons the user can hide (Bar settings > Buttons on the bar). Bit mask in topbar-hidden.txt, cached so layout/hit/paint +// do not touch the disk. Hiding the gear is safe: right click on an empty spot of the bar opens the same Bar settings. +const H_SEARCH: u8 = 1; +const H_TASKVIEW: u8 = 2; +const H_GEAR: u8 = 4; +static HIDDEN: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(0); + +fn hidden_file() -> PathBuf { + appdata_file("topbar-hidden.txt") +} + +pub(crate) fn hidden(bit: u8) -> bool { + HIDDEN.load(Relaxed) & bit != 0 +} + +pub(crate) fn load_hidden() { + let v = std::fs::read_to_string(hidden_file()).ok().and_then(|t| t.trim().parse::().ok()).unwrap_or(0); + HIDDEN.store(v, Relaxed); +} + +pub(crate) fn set_hidden(bit: u8, off: bool) { + let v = if off { HIDDEN.load(Relaxed) | bit } else { HIDDEN.load(Relaxed) & !bit }; + HIDDEN.store(v, Relaxed); + let _ = std::fs::write(hidden_file(), v.to_string()); +} + +pub(crate) fn reset_hidden() { + HIDDEN.store(0, Relaxed); + let _ = std::fs::remove_file(hidden_file()); +} + +/// The slots before Start that are still shown, in order: search, Task View. +fn lead_keys() -> Vec { + [(SEARCH, H_SEARCH), (TASKVIEW, H_TASKVIEW)].into_iter().filter(|&(_, b)| !hidden(b)).map(|(k, _)| k).collect() +} + +fn lead() -> i32 { + lead_keys().len() as i32 +} + /// The buttons of the pill; none when switched off in the bar's settings (#208), and the pill takes no room then. fn power_keys() -> &'static [i32] { if power_off_marker().exists() { &[] } else { &[POW_R, POW_S] } @@ -1666,7 +1705,7 @@ impl Layout { if i == 0 { self.start_x } else { - let lead = if i18n::style::start_left() { LEAD - 1 } else { LEAD }; + let lead = if i18n::style::start_left() { lead() - 1 } else { lead() }; self.x0 + (i + lead) * (self.bw + self.gap) } } @@ -1724,7 +1763,7 @@ unsafe fn drag_target(hwnd: HWND, x: i32, y: i32) -> Option { let (axis, length) = if vert() { (y, rect.bottom) } else { (x, rect.right) }; let layout = layout(length); let count = BTNS.with_borrow(|b| b.len()) as i32; - let lead = if i18n::style::start_left() { LEAD - 1 } else { LEAD }; // the same slots as Layout::btn_pos + let lead = if i18n::style::start_left() { lead() - 1 } else { lead() }; // the same slots as Layout::btn_pos drag_slot(axis, layout.x0, layout.bw, layout.gap, count, layout.apps.0, lead).and_then(button_key) } @@ -1744,11 +1783,11 @@ fn layout(w: i32) -> Layout { let margin = (w - apps.0) + sc(8); // keep the button group centered and clear of both sides let sl = i18n::style::start_left(); let btns_len = BTNS.with_borrow(|b| b.len()) as i32; - let total_n = btns_len + LEAD; // + the search and Task View slots + let total_n = btns_len + lead(); // + the search and Task View slots (the ones not hidden) let bw = (((w - 2 * margin + gap) / total_n.max(1)) - gap).clamp(sc(16), sc(44 + [-6, 0, 8][i18n::style::bar_size() as usize % 3])); let group_n = total_n - i32::from(sl); // centered on search + (Start if not pinned left) + pins only: opening an unpinned window adds a button on the right instead of shifting left - let fixed = (PINS.with_borrow(|p| p.len()) as i32 + LEAD + if sl { 0 } else { 1 }).min(group_n); + let fixed = (PINS.with_borrow(|p| p.len()) as i32 + lead() + if sl { 0 } else { 1 }).min(group_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 - (group_n * (bw + gap) - gap); let centered = (w - (fixed * (bw + gap) - gap)) / 2; @@ -1758,9 +1797,9 @@ fn layout(w: i32) -> Layout { } else { (0, sc(GEAR_X.0)) }; - let left_min = gear_x + sc(GEAR_X.1 + 6); + let left_min = gear_x + sc(if hidden(H_GEAR) { 6 } else { GEAR_X.1 + 6 }); let x0 = if i18n::style::align_left() { 0 } else { centered }.min(right_limit).max(left_min); // clear of the gear (and Start if pinned left) - let start_x = if sl { start_left_x } else { x0 + LEAD * (bw + gap) }; + let start_x = if sl { start_left_x } else { x0 + lead() * (bw + gap) }; Layout { gear_x, start_x, x0, bw, gap, power, apps, sys, wid, clock } } @@ -1774,10 +1813,10 @@ unsafe fn hit(hwnd: HWND, x: i32, y: i32) -> i32 { if x < l.start_x + l.bw { return 0; // Start reaches all the way to the screen corner } - if x >= l.gear_x && x < l.gear_x + sc(GEAR_X.1) { + if x >= l.gear_x && x < l.gear_x + sc(GEAR_X.1) && !hidden(H_GEAR) { return GEAR; } - } else if x < l.gear_x + sc(GEAR_X.1) { + } else if x < l.gear_x + sc(GEAR_X.1) && !hidden(H_GEAR) { return GEAR; } if x >= l.clock.1 { @@ -1800,9 +1839,9 @@ unsafe fn hit(hwnd: HWND, x: i32, y: i32) -> i32 { if x >= l.apps.0 { return TAPP + (x - l.apps.0) / sc(24); } - let n = BTNS.with_borrow(|b| b.len()) as i32 + LEAD - i32::from(sl); + let n = BTNS.with_borrow(|b| b.len()) as i32 + lead() - i32::from(sl); let (d, i) = (x - l.x0, (x - l.x0) / (l.bw + l.gap)); - if d < 0 || d % (l.bw + l.gap) >= l.bw || i >= n { NONE } else if i == 0 { SEARCH } else if i == 1 { TASKVIEW } else { i - LEAD + i32::from(sl) } + if d < 0 || d % (l.bw + l.gap) >= l.bw || i >= n { NONE } else if let Some(&k) = lead_keys().get(i as usize) { k } else { i - lead() + i32::from(sl) } } // ---------- animation ---------- @@ -2317,17 +2356,22 @@ unsafe fn paint_vert(dc: HDC, cr: RECT, fonts: [HFONT; 4]) { let cell = |y: i32, len: i32| RECT { left: lft, top: y, right: rgt, bottom: y + len }; let dim = mix(pal().dim, pal().text, 0.5); - let gr = cell(l.gear_x, sc(GEAR_X.1)); - 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 { dim }, DT_CENTER); - - let sb = cell(l.x0, l.bw); - glow(dc, SEARCH, hot == SEARCH, sb, pal().bg, pal().hover, sc(8)); - text(dc, "\u{E721}", sb, if hot == SEARCH { pal().text } else { dim }, DT_CENTER); - let tb = cell(l.x0 + l.bw + l.gap, l.bw); - glow(dc, TASKVIEW, hot == TASKVIEW, tb, pal().bg, pal().hover, sc(8)); - text(dc, "\u{E7C4}", tb, if hot == TASKVIEW { pal().text } else { dim }, DT_CENTER); + if !hidden(H_GEAR) { + let gr = cell(l.gear_x, sc(GEAR_X.1)); + glow(dc, GEAR, hot == GEAR, gr, pal().bg, pal().hover, sc(8)); + text(dc, "\u{E713}", gr, if hot == GEAR { pal().text } else { dim }, DT_CENTER); + } + if !hidden(H_SEARCH) { + let sb = cell(l.x0, l.bw); + glow(dc, SEARCH, hot == SEARCH, sb, pal().bg, pal().hover, sc(8)); + text(dc, "\u{E721}", sb, if hot == SEARCH { pal().text } else { dim }, DT_CENTER); + } + if !hidden(H_TASKVIEW) { + let tb = cell(l.x0 + (if hidden(H_SEARCH) { 0 } else { l.bw + l.gap }), l.bw); + glow(dc, TASKVIEW, hot == TASKVIEW, tb, pal().bg, pal().hover, sc(8)); + text(dc, "\u{E7C4}", tb, if hot == TASKVIEW { pal().text } else { dim }, DT_CENTER); + } BTNS.with_borrow(|btns| { for (i, b) in btns.iter().enumerate() { @@ -2540,19 +2584,25 @@ unsafe fn paint(hwnd: HWND) { 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: the Style menu - let gr = RECT { left: l.gear_x, top, right: l.gear_x + sc(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); + if !hidden(H_GEAR) { + let gr = RECT { left: l.gear_x, top, right: l.gear_x + sc(GEAR_X.1), bottom: bot }; + glow(dc, GEAR, hot == GEAR, gr, pal().bg, pal().hover, sc(8)); + 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, pal().bg, pal().hover, sc(8)); - SelectObject(dc, f_glyph); - text(dc, "\u{E721}", sb, if hot == SEARCH { pal().text } else { mix(pal().dim, pal().text, 0.5) }, DT_CENTER); - let tb = RECT { left: l.x0 + l.bw + l.gap, top, right: l.x0 + 2 * l.bw + l.gap, bottom: bot }; - glow(dc, TASKVIEW, hot == TASKVIEW, tb, pal().bg, pal().hover, sc(8)); - text(dc, "\u{E7C4}", tb, if hot == TASKVIEW { pal().text } else { mix(pal().dim, pal().text, 0.5) }, DT_CENTER); + if !hidden(H_SEARCH) { + let sb = RECT { left: l.x0, top, right: l.x0 + l.bw, bottom: bot }; + glow(dc, SEARCH, hot == SEARCH, sb, pal().bg, pal().hover, sc(8)); + text(dc, "\u{E721}", sb, if hot == SEARCH { pal().text } else { mix(pal().dim, pal().text, 0.5) }, DT_CENTER); + } + if !hidden(H_TASKVIEW) { + let tx = l.x0 + (if hidden(H_SEARCH) { 0 } else { l.bw + l.gap }); + let tb = RECT { left: tx, top, right: tx + l.bw, bottom: bot }; + glow(dc, TASKVIEW, hot == TASKVIEW, tb, pal().bg, pal().hover, sc(8)); + text(dc, "\u{E7C4}", tb, if hot == TASKVIEW { pal().text } else { mix(pal().dim, pal().text, 0.5) }, DT_CENTER); + } // Start, pinned apps, open windows (center) BTNS.with_borrow(|btns| { @@ -3413,7 +3463,7 @@ unsafe fn tip_cx(l: &Layout, h: i32) -> i32 { (if vert() { 0 } else { bar_x_w().0 }) + match h { GEAR => l.gear_x + sc(GEAR_X.1 / 2), SEARCH => l.x0 + l.bw / 2, - TASKVIEW => l.x0 + (l.bw + l.gap) + l.bw / 2, + TASKVIEW => l.x0 + (if hidden(H_SEARCH) { 0 } else { l.bw + l.gap }) + l.bw / 2, CLOCK => (l.clock.0 + l.clock.1) / 2, SHOWDESK => l.clock.1 + sc(3), POW_R | POW_S => l.power.0 + power_keys().iter().position(|&k| k == h).unwrap_or(0) as i32 * sc(32) + sc(16), @@ -3664,6 +3714,7 @@ unsafe extern "system" fn wndproc(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM) } fn main() { + load_hidden(); unsafe { if std::env::args().any(|a| a == "--restore") { show_taskbar(saved_taskbar_state().unwrap_or(ABS_ALWAYSONTOP as usize)); diff --git a/plugins/topbar/src/settings.rs b/plugins/topbar/src/settings.rs index d611177f..65cb47a8 100644 --- a/plugins/topbar/src/settings.rs +++ b/plugins/topbar/src/settings.rs @@ -176,12 +176,18 @@ pub(crate) unsafe fn buttons_page() { fly::MItem::new(t!("Отдельно, в самом углу", "On its own, in the corner", ja: "単独で隅に配置", pt: "Sozinho, no canto", zh: "单独放在角落")).on(st::start_left()), fly::MItem::head(t!("Ещё", "Extra", ja: "その他", pt: "Extras", zh: "其他")), fly::MItem::new(t!("Кнопки перезагрузки и выключения", "Restart and shut down buttons", ja: "再起動とシャットダウンのボタン", pt: "Botões de reiniciar e desligar", zh: "重启和关机按钮")).on(crate::power_shown()), + fly::MItem::new(t!("Кнопка поиска", "Search button", ja: "検索ボタン", pt: "Botão de pesquisa", zh: "搜索按钮")).on(!crate::hidden(crate::H_SEARCH)), + fly::MItem::new(t!("Кнопка представления задач", "Task View button", ja: "タスク ビュー ボタン", pt: "Botão Visão de Tarefas", zh: "任务视图按钮")).on(!crate::hidden(crate::H_TASKVIEW)), + fly::MItem::new(t!("Кнопка настроек (шестерёнка)", "Settings button (gear)", ja: "設定ボタン (歯車)", pt: "Botão de configurações (engrenagem)", zh: "设置按钮(齿轮)")).on(!crate::hidden(crate::H_GEAR)), ]; gear_page("\u{E8A9}", t!("Кнопки на панели", "Buttons on the bar", ja: "バーのボタン", pt: "Botões na barra", zh: "任务栏按钮"), t!("Где они стоят и какие видны", "Where they sit and which are shown", ja: "ボタンの位置と表示するもの", pt: "Onde ficam e quais aparecem", zh: "按钮的位置以及显示哪些"), items, |i| { match i { 2 | 3 => st::set_align_left(i == 3), 5 | 6 => st::set_start_left(i == 6), 8 => crate::set_power_shown(!crate::power_shown()), + 9 => crate::set_hidden(crate::H_SEARCH, !crate::hidden(crate::H_SEARCH)), + 10 => crate::set_hidden(crate::H_TASKVIEW, !crate::hidden(crate::H_TASKVIEW)), + 11 => crate::set_hidden(crate::H_GEAR, !crate::hidden(crate::H_GEAR)), _ => return style_menu(), } relook(true); @@ -333,6 +339,7 @@ pub(crate) unsafe fn reset_page() { gear_page("\u{E777}", t!("Сбросить всё?", "Reset everything?", ja: "すべてをリセットしますか?", pt: "Restaurar tudo?", zh: "全部重置?"), t!("Тема, цвета, панель. Сохранённые виды останутся", "Theme, colors, bar. Saved looks stay", ja: "テーマ、色、バー。保存した外観は残ります", pt: "Tema, cores, barra. As aparências salvas permanecem", zh: "主题、颜色、任务栏。已保存的外观保留"), items, |i| { if i == 0 { i18n::style::reset_all(); + crate::reset_hidden(); relook(true); } style_menu();