teksilo_platform/taskbar.rs
1// SPDX-License-Identifier: MPL-2.0
2// SPDX-FileCopyrightText: 2026 FernTech
3
4//! Keeping a window out of the taskbar, the per-OS backend behind
5//! `WindowConfig::skip_taskbar`.
6//!
7//! | Platform | How |
8//! |---|---|
9//! | Windows | winit's `with_skip_taskbar`, at creation ([`skip_taskbar_attributes`]) |
10//! | X11 | `_NET_WM_STATE_SKIP_TASKBAR` written before the first map ([`skip_taskbar_before_show`]) |
11//! | Wayland | nothing: no protocol open to every client asks the compositor for it |
12//! | macOS | nothing: the Dock lists applications, not windows |
13//!
14//! Both halves are called for every window. Each does its platform's part and
15//! nothing elsewhere, so a caller needs no `cfg`.
16
17use winit::window::{Window, WindowAttributes};
18
19/// The attributes for a window created with `skip` set: on Windows, winit's
20/// `with_skip_taskbar`; elsewhere `attrs` unchanged.
21pub fn skip_taskbar_attributes(attrs: WindowAttributes, skip: bool) -> WindowAttributes {
22 #[cfg(target_os = "windows")]
23 {
24 use winit::platform::windows::WindowAttributesExtWindows;
25 attrs.with_skip_taskbar(skip)
26 }
27 #[cfg(not(target_os = "windows"))]
28 {
29 let _ = skip;
30 attrs
31 }
32}
33
34/// Mark `window` for the taskbar to skip, on X11, before it is shown for the
35/// first time; nothing on other window systems, or when `skip` is false.
36///
37/// It has to come between creation and the first map, which in Teksilo is
38/// the window's creation with `with_visible(false)` and the show that
39/// follows once its accessibility adapter exists. See
40/// [`mark_skip_taskbar`](crate::x11::ewmh::mark_skip_taskbar) for why. A
41/// failure is reported on stderr and leaves the window in the taskbar.
42pub fn skip_taskbar_before_show(window: &Window, skip: bool) {
43 #[cfg(all(unix, not(target_os = "macos")))]
44 if skip {
45 let Some(xid) = crate::window_system::x11_window_id(window) else {
46 return;
47 };
48 if let Err(err) = crate::x11::ewmh::mark_skip_taskbar(xid) {
49 eprintln!(
50 "teksilo-platform: could not keep the window out of the taskbar ({err}); \
51 it will be listed there"
52 );
53 }
54 }
55 #[cfg(not(all(unix, not(target_os = "macos"))))]
56 let _ = (window, skip);
57}