mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-24 02:01:18 +07:00
Implement opacity window rule
This commit is contained in:
@@ -697,6 +697,8 @@ pub struct WindowRule {
|
||||
|
||||
#[knuffel(child, unwrap(argument))]
|
||||
pub draw_border_with_background: Option<bool>,
|
||||
#[knuffel(child, unwrap(argument))]
|
||||
pub opacity: Option<f32>,
|
||||
}
|
||||
|
||||
// Remember to update the PartialEq impl when adding fields!
|
||||
|
||||
@@ -49,7 +49,7 @@ impl TestCase for Window {
|
||||
let location = Point::from(((size.w - win_size.w) / 2, (size.h - win_size.h) / 2));
|
||||
|
||||
self.window
|
||||
.render(renderer, location, Scale::from(1.))
|
||||
.render(renderer, location, Scale::from(1.), 1.)
|
||||
.into_iter()
|
||||
.map(|elem| Box::new(elem) as _)
|
||||
.collect()
|
||||
|
||||
@@ -146,6 +146,7 @@ impl LayoutElement for TestWindow {
|
||||
_renderer: &mut R,
|
||||
location: Point<i32, Logical>,
|
||||
scale: Scale<f64>,
|
||||
alpha: f32,
|
||||
) -> Vec<LayoutElementRenderElement<R>> {
|
||||
let inner = self.inner.borrow();
|
||||
|
||||
@@ -154,7 +155,7 @@ impl LayoutElement for TestWindow {
|
||||
&inner.buffer,
|
||||
location.to_physical_precise_round(scale),
|
||||
scale,
|
||||
1.,
|
||||
alpha,
|
||||
Kind::Unspecified,
|
||||
)
|
||||
.into(),
|
||||
@@ -163,7 +164,7 @@ impl LayoutElement for TestWindow {
|
||||
(location - Point::from((inner.csd_shadow_width, inner.csd_shadow_width)))
|
||||
.to_physical_precise_round(scale),
|
||||
scale,
|
||||
1.,
|
||||
alpha,
|
||||
Kind::Unspecified,
|
||||
)
|
||||
.into(),
|
||||
|
||||
@@ -414,6 +414,16 @@ animations {
|
||||
// Set this to `false` to draw them as borders around the window even for
|
||||
// windows which use client-side decorations.
|
||||
draw-border-with-background false
|
||||
|
||||
// Set the opacity of the window.
|
||||
// This is applied on top of the window's own opacity, so semitransparent
|
||||
// windows will become even more transparent.
|
||||
// Opacity is applied to every surface of the window individually, so
|
||||
// subsurfaces and pop-up menus will show window content behind them.
|
||||
// Also, focus ring and border with background will show through
|
||||
// semitransparent windows (see prefer-no-csd and
|
||||
// the draw-border-with-background property above).
|
||||
opacity 0.5
|
||||
}
|
||||
|
||||
// Here's a useful example. Work around WezTerm's initial configure bug
|
||||
|
||||
@@ -95,6 +95,7 @@ pub trait LayoutElement {
|
||||
renderer: &mut R,
|
||||
location: Point<i32, Logical>,
|
||||
scale: Scale<f64>,
|
||||
alpha: f32,
|
||||
) -> Vec<LayoutElementRenderElement<R>>;
|
||||
|
||||
fn request_size(&self, size: Size<i32, Logical>);
|
||||
@@ -1856,6 +1857,7 @@ mod tests {
|
||||
_renderer: &mut R,
|
||||
_location: Point<i32, Logical>,
|
||||
_scale: Scale<f64>,
|
||||
_alpha: f32,
|
||||
) -> Vec<LayoutElementRenderElement<R>> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
+7
-1
@@ -325,9 +325,15 @@ impl<W: LayoutElement> Tile<W> {
|
||||
view_size: Size<i32, Logical>,
|
||||
focus_ring: bool,
|
||||
) -> impl Iterator<Item = TileRenderElement<R>> {
|
||||
let alpha = if self.is_fullscreen {
|
||||
1.
|
||||
} else {
|
||||
self.window.rules().opacity.unwrap_or(1.).clamp(0., 1.)
|
||||
};
|
||||
|
||||
let rv = self
|
||||
.window
|
||||
.render(renderer, location + self.window_loc(), scale)
|
||||
.render(renderer, location + self.window_loc(), scale, alpha)
|
||||
.into_iter()
|
||||
.map(Into::into);
|
||||
|
||||
|
||||
@@ -108,13 +108,14 @@ impl LayoutElement for Mapped {
|
||||
renderer: &mut R,
|
||||
location: Point<i32, Logical>,
|
||||
scale: Scale<f64>,
|
||||
alpha: f32,
|
||||
) -> Vec<LayoutElementRenderElement<R>> {
|
||||
let buf_pos = location - self.window.geometry().loc;
|
||||
self.window.render_elements(
|
||||
renderer,
|
||||
buf_pos.to_physical_precise_round(scale),
|
||||
scale,
|
||||
1.,
|
||||
alpha,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,9 @@ pub struct ResolvedWindowRules {
|
||||
///
|
||||
/// `None` means using the SSD heuristic.
|
||||
pub draw_border_with_background: Option<bool>,
|
||||
|
||||
/// Extra opacity to draw this window with.
|
||||
pub opacity: Option<f32>,
|
||||
}
|
||||
|
||||
impl<'a> WindowRef<'a> {
|
||||
@@ -82,6 +85,7 @@ impl ResolvedWindowRules {
|
||||
max_width: None,
|
||||
max_height: None,
|
||||
draw_border_with_background: None,
|
||||
opacity: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,6 +157,9 @@ impl ResolvedWindowRules {
|
||||
if let Some(x) = rule.draw_border_with_background {
|
||||
resolved.draw_border_with_background = Some(x);
|
||||
}
|
||||
if let Some(x) = rule.opacity {
|
||||
resolved.opacity = Some(x);
|
||||
}
|
||||
}
|
||||
|
||||
resolved.open_on_output = open_on_output.map(|x| x.to_owned());
|
||||
|
||||
Reference in New Issue
Block a user