Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config.reference.toml
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@
# # fit-window-snapped — fit-window, moving its snap cluster along
# # fill-window — grow the focused window into the free space around it; again to restore
# # toggle-pin-to-screen — pin the focused window to the screen, ignoring pan and zoom
# # toggle-titlebar — hide or show the focused window's driftwm title bar (server ↔ minimal: the border,
# # corners and shadow stay). Windows that draw their own chrome, and fit, fill,
# # fullscreen or widget windows, are left alone
# # toggle-borders — hide or show the focused window's border, drop shadow and corner clip together, so it
# # draws as the bare client surface; again to restore. Fit, fill, fullscreen and widget
# # windows, and `decoration = "none"` ones, are left alone
# # reload-config — hot-reload the config file
# # toggle-cursor-pan — toggle bare-cursor edge-pan (see [navigation.edge_pan])
# # set-trackpad on|off|toggle — turn every trackpad on or off for this session
Expand Down
2 changes: 2 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,8 @@ Actions:
- `fit-window-snapped` — fit-window, moving its snap cluster along
- `fill-window` — grow the focused window into the free space around it; again to restore
- `toggle-pin-to-screen` — pin the focused window to the screen, ignoring pan and zoom
- `toggle-titlebar` — hide or show the focused window's driftwm title bar (server ↔ minimal: the border, corners and shadow stay). Windows that draw their own chrome, and fit, fill, fullscreen or widget windows, are left alone
- `toggle-borders` — hide or show the focused window's border, drop shadow and corner clip together, so it draws as the bare client surface; again to restore. Fit, fill, fullscreen and widget windows, and `decoration = "none"` ones, are left alone
- `reload-config` — hot-reload the config file
- `toggle-cursor-pan` — toggle bare-cursor edge-pan (see [navigation.edge_pan])
- `set-trackpad on|off|toggle` — turn every trackpad on or off for this session
Expand Down
6 changes: 6 additions & 0 deletions docs/window-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,12 @@ pinned, output, … — are resolved **once, when a window maps**: reloading you
config only affects windows opened afterwards, and a window that changes its
title after mapping is **not** re-checked against `title` rules.

Three things change a window's stored rule *after* it maps, and a config reload
does not undo them: `msg opacity <value>` pins the opacity, `toggle-titlebar`
flips `decoration` between `server` and `minimal`, and `toggle-borders` hides or
restores the border, shadow and corner clip as one. All are runtime-only, so they
are not saved with the session and end when the window closes.

A few things re-resolve live against the current config instead: `pass_keys` is
evaluated per keypress and `pass_mouse` per button press and scroll (so a config
reload — and a title change — takes effect immediately), layer-surface chrome is
Expand Down
6 changes: 6 additions & 0 deletions src/config/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ pub fn parse_action(s: &str) -> Result<Action, String> {
Ok(Action::SwitchLayout(target))
}
"toggle-pin-to-screen" => Ok(Action::TogglePinToScreen),
"toggle-titlebar" => Ok(Action::ToggleTitlebar),
"toggle-borders" => Ok(Action::ToggleBorders),
"reload-config" => Ok(Action::ReloadConfig),
"toggle-cursor-pan" => Ok(Action::ToggleCursorPan),
"set-trackpad" => {
Expand Down Expand Up @@ -270,9 +272,11 @@ pub const ACTION_NAMES: &[(&str, &str)] = &[
("spawn", "spawn foo"),
("suspend-window", "suspend-window"),
("switch-layout", "switch-layout next"),
("toggle-borders", "toggle-borders"),
("toggle-cursor-pan", "toggle-cursor-pan"),
("toggle-fullscreen", "toggle-fullscreen"),
("toggle-pin-to-screen", "toggle-pin-to-screen"),
("toggle-titlebar", "toggle-titlebar"),
("zoom-in", "zoom-in"),
("zoom-out", "zoom-out"),
("zoom-reset", "zoom-reset"),
Expand Down Expand Up @@ -661,6 +665,8 @@ mod tests {
Action::SendCursorToOutput(_) => "send-cursor-to-output",
Action::FocusCenter => "focus-center",
Action::TogglePinToScreen => "toggle-pin-to-screen",
Action::ToggleTitlebar => "toggle-titlebar",
Action::ToggleBorders => "toggle-borders",
Action::SwitchLayout(_) => "switch-layout",
Action::ReloadConfig => "reload-config",
Action::ToggleCursorPan => "toggle-cursor-pan",
Expand Down
59 changes: 56 additions & 3 deletions src/config/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ pub enum Action {
SendCursorToOutput(Direction),
FocusCenter,
TogglePinToScreen,
ToggleTitlebar,
ToggleBorders,
SwitchLayout(LayoutSwitch),
ReloadConfig,
ToggleCursorPan,
Expand Down Expand Up @@ -922,6 +924,10 @@ pub struct AppliedWindowRule {
pub shadow: Option<bool>,
pub output: Option<String>,
pub layer_order: Option<i32>,
/// Runtime only (`toggle-borders`): draw the window without its border,
/// shadow and corner clip, whatever the rule and `[decorations]` say. A flag
/// rather than overwritten values, so toggling back needs nothing saved.
pub borders_hidden: bool,
}

impl AppliedWindowRule {
Expand Down Expand Up @@ -1017,6 +1023,7 @@ impl From<&WindowRule> for AppliedWindowRule {
shadow: rule.shadow,
output: rule.output.clone(),
layer_order: rule.layer_order,
borders_hidden: false,
}
}
}
Expand Down Expand Up @@ -1148,7 +1155,7 @@ pub fn effective_border_width(
mode: &DecorationMode,
decorations: &DecorationConfig,
) -> i32 {
if matches!(mode, DecorationMode::None) {
if matches!(mode, DecorationMode::None) || applied.is_some_and(|r| r.borders_hidden) {
return 0;
}
if let Some(bw) = applied.and_then(|r| r.border_width) {
Expand Down Expand Up @@ -1220,7 +1227,7 @@ pub fn effective_corner_radius(
mode: &DecorationMode,
decorations: &DecorationConfig,
) -> i32 {
if matches!(mode, DecorationMode::None) {
if matches!(mode, DecorationMode::None) || applied.is_some_and(|r| r.borders_hidden) {
return 0;
}
if let Some(cr) = applied.and_then(|r| r.corner_radius) {
Expand All @@ -1236,7 +1243,7 @@ pub fn effective_shadow_enabled(
mode: &DecorationMode,
decorations: &DecorationConfig,
) -> bool {
if matches!(mode, DecorationMode::None) {
if matches!(mode, DecorationMode::None) || applied.is_some_and(|r| r.borders_hidden) {
return false;
}
if let Some(s) = applied.and_then(|r| r.shadow) {
Expand Down Expand Up @@ -1414,6 +1421,52 @@ pub struct BackgroundConfig {
mod tests {
use super::*;

#[test]
fn hidden_borders_zero_the_border_shadow_and_corner_clip() {
let decorations = DecorationConfig {
border_width: 4,
corner_radius: 12,
shadow: true,
..DecorationConfig::default()
};
let rule = AppliedWindowRule {
border_width: Some(6),
corner_radius: Some(20),
shadow: Some(true),
..AppliedWindowRule::default()
};
let hidden = AppliedWindowRule {
borders_hidden: true,
..rule.clone()
};
for mode in [
DecorationMode::Client,
DecorationMode::Server,
DecorationMode::Minimal,
] {
assert_eq!(effective_border_width(Some(&rule), &mode, &decorations), 6);
assert_eq!(
effective_corner_radius(Some(&rule), &mode, &decorations),
20
);
assert!(effective_shadow_enabled(Some(&rule), &mode, &decorations));

assert_eq!(
effective_border_width(Some(&hidden), &mode, &decorations),
0
);
assert_eq!(
effective_corner_radius(Some(&hidden), &mode, &decorations),
0
);
assert!(!effective_shadow_enabled(
Some(&hidden),
&mode,
&decorations
));
}
}

#[test]
fn runs_during_fullscreen_allowlist() {
assert!(Action::ToggleFullscreen.runs_during_fullscreen());
Expand Down
134 changes: 75 additions & 59 deletions src/handlers/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,69 +215,13 @@ impl CompositorHandler for DriftWm {
self.mark_dirty_for_surface(surface);

// Trim corner rects from CSD toplevels' opaque regions so the
// background can render through. Some CSD apps (LibreOffice/GTK3)
// declare the full rect opaque while rendering transparent corners,
// leaving black artifacts where damage tracking skips redraws.
// ARGB only — XRGB is handled in RoundedCornerElement::opaque_regions.
// Skipped for `decoration = "none"` (pass-through promise).
// background can render through (see `trim_opaque_corners`). Skipped for
// windows with a title bar: the bar's frame draws its own corners.
if !self
.decorations
.contains_key(&DecorationKey::Surface(surface.id()))
{
with_states(surface, |states| {
// Every commit of every surface lands here, and only toplevels
// can carve — bail before the rule read so subsurfaces, popups,
// layer surfaces and cursors pay a single data_map lookup.
if states.data_map.get::<XdgToplevelSurfaceData>().is_none() {
return;
}
// `applied_rule` re-enters `with_states`, whose private-data
// mutex this closure already holds — read the rule off the
// states in hand instead.
let applied = states
.data_map
.get::<std::sync::Mutex<driftwm::config::AppliedWindowRule>>()
.and_then(|m| m.lock().ok())
.map(|guard| guard.clone());
let mode = driftwm::config::effective_decoration_mode(
applied.as_ref().and_then(|r| r.decoration.as_ref()),
&self.config.decorations.default_mode,
);
if matches!(mode, driftwm::config::DecorationMode::None) {
return;
}
let corner_radius = driftwm::config::effective_corner_radius(
applied.as_ref(),
mode,
&self.config.decorations,
);
let mut guard = states.cached_state.get::<SurfaceAttributes>();
let attrs = guard.current();
if let Some(ref mut region) = attrs.opaque_region {
let Some(bounds) = region
.rects
.iter()
.filter(|(k, _)| matches!(k, RectangleKind::Add))
.map(|(_, r)| *r)
.reduce(|a, b| a.merge(b))
else {
return;
};
let r = corner_radius + 2;
if bounds.size.w > 2 * r && bounds.size.h > 2 * r {
let (x, y, w, h) =
(bounds.loc.x, bounds.loc.y, bounds.size.w, bounds.size.h);
for corner in [
Rectangle::new((x, y).into(), (r, r).into()),
Rectangle::new((x + w - r, y).into(), (r, r).into()),
Rectangle::new((x + w - r, y + h - r).into(), (r, r).into()),
Rectangle::new((x, y + h - r).into(), (r, r).into()),
] {
region.rects.push((RectangleKind::Subtract, corner));
}
}
}
});
self.trim_opaque_corners(surface);
}

// The buffer handler below rebuilds every surface in this tree, sync
Expand Down Expand Up @@ -1399,6 +1343,78 @@ impl DriftWm {
self.refresh_stable_snap_rect(&client);
}

/// Trim corner rects from a CSD toplevel's opaque region so the background
/// can render through. Some CSD apps (LibreOffice/GTK3) declare the full rect
/// opaque while rendering transparent corners, leaving black artifacts where
/// damage tracking skips redraws. ARGB only — XRGB is handled in
/// `RoundedCornerElement::opaque_regions`. Skipped for `decoration = "none"`
/// (pass-through promise). Idempotent, so it can also run outside a commit.
pub(crate) fn trim_opaque_corners(
&self,
surface: &smithay::reexports::wayland_server::protocol::wl_surface::WlSurface,
) {
with_states(surface, |states| {
// Every commit of every surface lands here, and only toplevels
// can carve — bail before the rule read so subsurfaces, popups,
// layer surfaces and cursors pay a single data_map lookup.
if states.data_map.get::<XdgToplevelSurfaceData>().is_none() {
return;
}
// `applied_rule` re-enters `with_states`, whose private-data
// mutex this closure already holds — read the rule off the
// states in hand instead.
let applied = states
.data_map
.get::<std::sync::Mutex<driftwm::config::AppliedWindowRule>>()
.and_then(|m| m.lock().ok())
.map(|guard| guard.clone());
let mode = driftwm::config::effective_decoration_mode(
applied.as_ref().and_then(|r| r.decoration.as_ref()),
&self.config.decorations.default_mode,
);
if matches!(mode, driftwm::config::DecorationMode::None) {
return;
}
let corner_radius = driftwm::config::effective_corner_radius(
applied.as_ref(),
mode,
&self.config.decorations,
);
let mut guard = states.cached_state.get::<SurfaceAttributes>();
let attrs = guard.current();
if let Some(ref mut region) = attrs.opaque_region {
let Some(bounds) = region
.rects
.iter()
.filter(|(k, _)| matches!(k, RectangleKind::Add))
.map(|(_, r)| *r)
.reduce(|a, b| a.merge(b))
else {
return;
};
let r = corner_radius + 2;
if bounds.size.w > 2 * r && bounds.size.h > 2 * r {
let (x, y, w, h) = (bounds.loc.x, bounds.loc.y, bounds.size.w, bounds.size.h);
let corners = [
Rectangle::new((x, y).into(), (r, r).into()),
Rectangle::new((x + w - r, y).into(), (r, r).into()),
Rectangle::new((x + w - r, y + h - r).into(), (r, r).into()),
Rectangle::new((x, y + h - r).into(), (r, r).into()),
];
for corner in corners {
let carved = region
.rects
.iter()
.any(|(k, r)| matches!(k, RectangleKind::Subtract) && *r == corner);
if !carved {
region.rects.push((RectangleKind::Subtract, corner));
}
}
}
}
});
}

/// A snapped window that resizes *itself* larger — not via a resize grab —
/// can grow over its neighbors. The classic case is a game that maps at a
/// small size then jumps to its full render resolution a frame later. Move
Expand Down
27 changes: 27 additions & 0 deletions src/input/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,16 @@ impl DriftWm {
Action::TogglePinToScreen => {
self.toggle_pin_to_screen();
}
Action::ToggleTitlebar => {
if let Some(window) = self.chrome_toggle_target() {
self.toggle_window_titlebar(&window);
}
}
Action::ToggleBorders => {
if let Some(window) = self.chrome_toggle_target() {
self.toggle_window_borders(&window);
}
}
Action::ReloadConfig => {
self.reload_config();
}
Expand Down Expand Up @@ -785,6 +795,23 @@ impl DriftWm {
}
}

/// The window `toggle-titlebar` / `toggle-borders` act on: the focused one.
/// Fit, fill and widget windows are left alone: their geometry was computed
/// against the chrome they have now (or is rule-defined), and nothing here
/// would redo it.
fn chrome_toggle_target(&self) -> Option<smithay::desktop::Window> {
self.focused_window().filter(|w| {
let pending = w.wl_surface().is_some_and(|s| {
self.pending_fit.contains(&*s) || self.pending_fullscreen.contains_key(&*s)
});
!pending
&& !self.is_window_fullscreen(w)
&& !self.stage.is_fit(w)
&& !self.stage.is_fill(w)
&& !w.is_widget()
})
}

/// Override `[input.trackpad]`'s send-events mode for the rest of the
/// session and push it to every connected trackpad. Tracking the intent
/// rather than each device's current mode keeps two trackpads from drifting
Expand Down
Loading