Refine shell status controls and glass rendering; defer cursor redraw safely
This commit is contained in:
1 parent
e85fc1e032
commit
b3fa82b53b
53 files changed
+3329
-259
No files matched your search
@@ -25,6 +25,8 @@ pub struct Config {
|
||||
#[serde(default)]
|
||||
theme: ThemeConfig,
|
||||
#[serde(default)]
|
||||
appearance: AppearanceConfig,
|
||||
#[serde(default)]
|
||||
commands: HashMap<String, Vec<String>>,
|
||||
#[serde(default)]
|
||||
bindings: Vec<BindingConfig>,
|
||||
@@ -116,6 +118,9 @@ pub struct ThemeSettings {
|
||||
pub shadow_blur: f64,
|
||||
pub shadow_opacity: f64,
|
||||
pub material_style: MaterialStyle,
|
||||
pub glass: GlassSettings,
|
||||
pub material_radius: f64,
|
||||
pub panel_radius: f64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq)]
|
||||
@@ -127,6 +132,56 @@ pub enum MaterialStyle {
|
||||
Solid,
|
||||
}
|
||||
|
||||
/// Ordered quality tiers; each step retains the preceding reductions.
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum GlassQuality {
|
||||
#[default]
|
||||
Full,
|
||||
NoGrain,
|
||||
NoSaturation,
|
||||
ReducedBlur,
|
||||
Translucent,
|
||||
Solid,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct GlassSettings {
|
||||
pub tint: RgbaColor,
|
||||
pub blur_scale: f32,
|
||||
pub grain: bool,
|
||||
pub quality: GlassQuality,
|
||||
}
|
||||
|
||||
impl Default for GlassSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
tint: RgbaColor([28.0 / 255.0, 32.0 / 255.0, 46.0 / 255.0, 1.0]),
|
||||
blur_scale: 1.0,
|
||||
grain: true,
|
||||
quality: GlassQuality::Full,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize)]
|
||||
struct AppearanceConfig {
|
||||
corner_radius: Option<f64>,
|
||||
#[serde(default)]
|
||||
reduced_effects: bool,
|
||||
#[serde(default)]
|
||||
glass: GlassConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize)]
|
||||
struct GlassConfig {
|
||||
tint_color: Option<String>,
|
||||
blur_scale: Option<f64>,
|
||||
grain: Option<bool>,
|
||||
#[serde(default)]
|
||||
quality: GlassQuality,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize)]
|
||||
struct ThemeConfig {
|
||||
#[serde(default)]
|
||||
@@ -202,6 +257,8 @@ struct ThemeGeometryConfig {
|
||||
focus_ring_width: f64,
|
||||
#[serde(default = "default_window_radius")]
|
||||
window_radius: f64,
|
||||
#[serde(default)]
|
||||
top_bar_radius: f64,
|
||||
}
|
||||
|
||||
impl Default for ThemeGeometryConfig {
|
||||
@@ -210,6 +267,7 @@ impl Default for ThemeGeometryConfig {
|
||||
border_width: default_border_width(),
|
||||
focus_ring_width: default_focus_ring_width(),
|
||||
window_radius: default_window_radius(),
|
||||
top_bar_radius: 0.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -803,6 +861,26 @@ impl Config {
|
||||
let shadow_opacity =
|
||||
unit_theme_value(self.theme.shadow.soft.opacity, "shadow.soft.opacity")?;
|
||||
|
||||
let mut glass = GlassSettings::default();
|
||||
if let Some(tint) = &self.appearance.glass.tint_color {
|
||||
glass.tint = parse_color(tint, "appearance.glass.tint_color")?;
|
||||
// Opacity belongs to the semantic role, never the color token.
|
||||
glass.tint.0[3] = 1.0;
|
||||
}
|
||||
glass.blur_scale = finite_theme_value(
|
||||
self.appearance.glass.blur_scale.unwrap_or(1.0),
|
||||
"appearance.glass.blur_scale",
|
||||
)?
|
||||
.clamp(0.5, 1.5) as f32;
|
||||
glass.grain = self.appearance.glass.grain.unwrap_or(true);
|
||||
glass.quality = self.appearance.glass.quality;
|
||||
if self.appearance.reduced_effects {
|
||||
glass.quality = glass.quality.max(GlassQuality::ReducedBlur);
|
||||
}
|
||||
let material_radius = nonnegative_theme_value(
|
||||
self.appearance.corner_radius.unwrap_or(14.0),
|
||||
"appearance.corner_radius",
|
||||
)?;
|
||||
Ok(ThemeSettings {
|
||||
border_width,
|
||||
focus_ring_width,
|
||||
@@ -818,6 +896,12 @@ impl Config {
|
||||
shadow_blur,
|
||||
shadow_opacity,
|
||||
material_style: self.theme.material.style,
|
||||
glass,
|
||||
material_radius,
|
||||
panel_radius: nonnegative_theme_value(
|
||||
self.theme.geometry.top_bar_radius,
|
||||
"geometry.top_bar_radius",
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1581,6 +1665,30 @@ mod tests {
|
||||
assert!(invalid.gap_config().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn glass_configuration_clamps_cost_and_rejects_nonfinite_values() {
|
||||
for (value, expected) in [(0.1, 0.5), (1.2, 1.2), (100.0, 1.5)] {
|
||||
let config = parse(&format!("[appearance.glass]\nblur_scale = {value}"));
|
||||
assert_eq!(config.theme_settings().unwrap().glass.blur_scale, expected);
|
||||
}
|
||||
for value in ["nan", "inf", "-inf"] {
|
||||
assert!(
|
||||
parse(&format!("[appearance.glass]\nblur_scale = {value}"))
|
||||
.theme_settings()
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
let settings = parse("[appearance]\nreduced_effects = true\ncorner_radius = 17.0\n[appearance.glass]\ntint_color = \"#123456\"\ngrain = false")
|
||||
.theme_settings().unwrap();
|
||||
assert_eq!(settings.glass.quality, GlassQuality::ReducedBlur);
|
||||
assert!(!settings.glass.grain);
|
||||
assert_eq!(settings.material_radius, 17.0);
|
||||
assert_eq!(
|
||||
settings.glass.tint,
|
||||
RgbaColor([18.0 / 255.0, 52.0 / 255.0, 86.0 / 255.0, 1.0])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_and_validates_theme_window_tokens() {
|
||||
let configured = parse(
|
||||
@@ -1604,6 +1712,9 @@ mod tests {
|
||||
shadow_blur: 24.0,
|
||||
shadow_opacity: 0.4,
|
||||
material_style: MaterialStyle::Translucent,
|
||||
glass: GlassSettings::default(),
|
||||
material_radius: 14.0,
|
||||
panel_radius: 0.0,
|
||||
}
|
||||
);
|
||||
assert!(invalid_color.theme_settings().is_err());
|
||||
|
||||
+165
-45
@@ -16,7 +16,10 @@ use smithay::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
Ferese, config::MaterialStyle, private_client::ClientCapabilities, state::ClientState,
|
||||
Ferese,
|
||||
config::{GlassQuality, GlassSettings, MaterialStyle},
|
||||
private_client::ClientCapabilities,
|
||||
state::ClientState,
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
@@ -38,47 +41,72 @@ pub(crate) struct ResolvedMaterial {
|
||||
pub saturation: f32,
|
||||
pub brightness: f32,
|
||||
pub noise: f32,
|
||||
pub shadow: [f64; 3],
|
||||
}
|
||||
|
||||
pub(crate) fn resolve_material(role: SemanticRole, style: MaterialStyle) -> ResolvedMaterial {
|
||||
let (base_opacity, blur, saturation, brightness, noise) = match role {
|
||||
SemanticRole::Panel => (0.78, 24.0, 1.08, 1.02, 0.012),
|
||||
SemanticRole::PanelElevated
|
||||
| SemanticRole::Popover
|
||||
| SemanticRole::Menu
|
||||
| SemanticRole::Notification => (0.84, 28.0, 1.10, 1.03, 0.014),
|
||||
SemanticRole::Hud | SemanticRole::Modal => (0.88, 30.0, 1.06, 1.04, 0.010),
|
||||
pub(crate) fn resolve_material(
|
||||
role: SemanticRole,
|
||||
style: MaterialStyle,
|
||||
settings: GlassSettings,
|
||||
) -> ResolvedMaterial {
|
||||
// Restrained shell shadows in logical pixels: the full-width bar needs
|
||||
// less elevation than popovers, while dialogs retain a little more depth.
|
||||
let (opacity, blur, saturation, shadow) = match role {
|
||||
SemanticRole::Panel => (0.55, 24.0, 1.35, [1.0, 5.0, 0.04]),
|
||||
SemanticRole::PanelElevated => (0.55, 24.0, 1.35, [2.0, 8.0, 0.07]),
|
||||
SemanticRole::Popover => (0.55, 22.0, 1.35, [2.0, 8.0, 0.07]),
|
||||
SemanticRole::Menu => (0.60, 20.0, 1.30, [2.0, 8.0, 0.07]),
|
||||
SemanticRole::Hud => (0.65, 18.0, 1.25, [1.0, 4.0, 0.04]),
|
||||
SemanticRole::Notification => (0.58, 24.0, 1.35, [3.0, 10.0, 0.09]),
|
||||
SemanticRole::Modal => (0.62, 28.0, 1.40, [3.0, 10.0, 0.09]),
|
||||
};
|
||||
|
||||
match style {
|
||||
MaterialStyle::Glass => ResolvedMaterial {
|
||||
style,
|
||||
// Glass already contains an opaque copy of the backdrop. Its tint
|
||||
// therefore needs less coverage than the no-capture translucent
|
||||
// profile or the blur becomes visually indistinguishable from a
|
||||
// flat alpha surface.
|
||||
opacity: base_opacity * 0.72,
|
||||
blur,
|
||||
saturation,
|
||||
brightness,
|
||||
noise,
|
||||
// Preserve the separately defined translucent family when selected
|
||||
// directly. Glass degradation keeps the glass role's contrast floor.
|
||||
let opacity = if style == MaterialStyle::Translucent {
|
||||
match role {
|
||||
SemanticRole::Panel => 0.78,
|
||||
SemanticRole::Hud | SemanticRole::Modal => 0.88,
|
||||
_ => 0.84,
|
||||
}
|
||||
} else {
|
||||
opacity
|
||||
};
|
||||
let style = if style == MaterialStyle::Glass {
|
||||
match settings.quality {
|
||||
GlassQuality::Solid => MaterialStyle::Solid,
|
||||
GlassQuality::Translucent => MaterialStyle::Translucent,
|
||||
_ => style,
|
||||
}
|
||||
} else {
|
||||
style
|
||||
};
|
||||
let glass = style == MaterialStyle::Glass;
|
||||
ResolvedMaterial {
|
||||
style,
|
||||
opacity: if style == MaterialStyle::Solid {
|
||||
1.0
|
||||
} else {
|
||||
opacity
|
||||
},
|
||||
MaterialStyle::Translucent => ResolvedMaterial {
|
||||
style,
|
||||
opacity: base_opacity,
|
||||
blur: 0.0,
|
||||
saturation: 1.0,
|
||||
brightness: 1.0,
|
||||
noise: 0.0,
|
||||
blur: if !glass {
|
||||
0.0
|
||||
} else if settings.quality >= GlassQuality::ReducedBlur {
|
||||
(blur * settings.blur_scale).min(12.0)
|
||||
} else {
|
||||
blur * settings.blur_scale
|
||||
},
|
||||
MaterialStyle::Solid => ResolvedMaterial {
|
||||
style,
|
||||
opacity: 1.0,
|
||||
blur: 0.0,
|
||||
saturation: 1.0,
|
||||
brightness: 1.0,
|
||||
noise: 0.0,
|
||||
saturation: if glass && settings.quality < GlassQuality::NoSaturation {
|
||||
saturation
|
||||
} else {
|
||||
1.0
|
||||
},
|
||||
brightness: 1.0,
|
||||
noise: if glass && settings.grain && settings.quality < GlassQuality::NoGrain {
|
||||
0.05
|
||||
} else {
|
||||
0.0
|
||||
},
|
||||
shadow,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,13 +325,25 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn styles_preserve_semantics_but_disable_unsupported_effects() {
|
||||
let glass = resolve_material(SemanticRole::Popover, MaterialStyle::Glass);
|
||||
let translucent = resolve_material(SemanticRole::Popover, MaterialStyle::Translucent);
|
||||
let solid = resolve_material(SemanticRole::Popover, MaterialStyle::Solid);
|
||||
let glass = resolve_material(
|
||||
SemanticRole::Popover,
|
||||
MaterialStyle::Glass,
|
||||
GlassSettings::default(),
|
||||
);
|
||||
let translucent = resolve_material(
|
||||
SemanticRole::Popover,
|
||||
MaterialStyle::Translucent,
|
||||
GlassSettings::default(),
|
||||
);
|
||||
let solid = resolve_material(
|
||||
SemanticRole::Popover,
|
||||
MaterialStyle::Solid,
|
||||
GlassSettings::default(),
|
||||
);
|
||||
|
||||
assert!(glass.blur > 0.0);
|
||||
assert!(glass.noise > 0.0);
|
||||
assert!(glass.opacity < translucent.opacity);
|
||||
assert!(glass.opacity <= translucent.opacity);
|
||||
assert_eq!(translucent.blur, 0.0);
|
||||
assert_eq!(translucent.noise, 0.0);
|
||||
assert_eq!(solid.opacity, 1.0);
|
||||
@@ -311,11 +351,91 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn elevated_roles_resolve_more_strongly_than_the_panel() {
|
||||
let panel = resolve_material(SemanticRole::Panel, MaterialStyle::Glass);
|
||||
let popover = resolve_material(SemanticRole::Popover, MaterialStyle::Glass);
|
||||
fn glass_presets_use_role_specific_tints_and_restrained_shadows() {
|
||||
for (role, blur, saturation, opacity, shadow) in [
|
||||
(SemanticRole::Panel, 24.0, 1.35, 0.55, [1.0, 5.0, 0.04]),
|
||||
(SemanticRole::Popover, 22.0, 1.35, 0.55, [2.0, 8.0, 0.07]),
|
||||
(SemanticRole::Menu, 20.0, 1.30, 0.60, [2.0, 8.0, 0.07]),
|
||||
(SemanticRole::Hud, 18.0, 1.25, 0.65, [1.0, 4.0, 0.04]),
|
||||
(
|
||||
SemanticRole::Notification,
|
||||
24.0,
|
||||
1.35,
|
||||
0.58,
|
||||
[3.0, 10.0, 0.09],
|
||||
),
|
||||
(SemanticRole::Modal, 28.0, 1.40, 0.62, [3.0, 10.0, 0.09]),
|
||||
] {
|
||||
let material = resolve_material(role, MaterialStyle::Glass, GlassSettings::default());
|
||||
assert_eq!(
|
||||
(
|
||||
material.blur,
|
||||
material.saturation,
|
||||
material.opacity,
|
||||
material.shadow
|
||||
),
|
||||
(blur, saturation, opacity, shadow)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
assert!(popover.opacity > panel.opacity);
|
||||
assert!(popover.blur > panel.blur);
|
||||
#[test]
|
||||
fn degradation_is_ordered_and_preserves_contrast_and_elevation() {
|
||||
let reference = resolve_material(
|
||||
SemanticRole::Modal,
|
||||
MaterialStyle::Glass,
|
||||
GlassSettings::default(),
|
||||
);
|
||||
for quality in [
|
||||
GlassQuality::Full,
|
||||
GlassQuality::NoGrain,
|
||||
GlassQuality::NoSaturation,
|
||||
GlassQuality::ReducedBlur,
|
||||
GlassQuality::Translucent,
|
||||
GlassQuality::Solid,
|
||||
] {
|
||||
let material = resolve_material(
|
||||
SemanticRole::Modal,
|
||||
MaterialStyle::Glass,
|
||||
GlassSettings {
|
||||
quality,
|
||||
..GlassSettings::default()
|
||||
},
|
||||
);
|
||||
assert!(material.opacity >= reference.opacity);
|
||||
assert_eq!(material.shadow, reference.shadow);
|
||||
if quality >= GlassQuality::NoGrain {
|
||||
assert_eq!(material.noise, 0.0);
|
||||
}
|
||||
if quality >= GlassQuality::NoSaturation {
|
||||
assert_eq!(material.saturation, 1.0);
|
||||
}
|
||||
if quality >= GlassQuality::ReducedBlur {
|
||||
assert!(material.blur <= 12.0);
|
||||
}
|
||||
if quality >= GlassQuality::Translucent {
|
||||
assert_eq!(material.blur, 0.0);
|
||||
}
|
||||
if quality == GlassQuality::Solid {
|
||||
assert_eq!(material.opacity, 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn popover_uses_the_same_tint_with_a_smaller_blur_than_panel() {
|
||||
let panel = resolve_material(
|
||||
SemanticRole::Panel,
|
||||
MaterialStyle::Glass,
|
||||
GlassSettings::default(),
|
||||
);
|
||||
let popover = resolve_material(
|
||||
SemanticRole::Popover,
|
||||
MaterialStyle::Glass,
|
||||
GlassSettings::default(),
|
||||
);
|
||||
|
||||
assert_eq!(popover.opacity, panel.opacity);
|
||||
assert!(popover.blur < panel.blur);
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,10 @@ impl CompositorHandler for Ferese {
|
||||
}
|
||||
|
||||
fn destroyed(&mut self, surface: &WlSurface) {
|
||||
// A removed popup changes the backdrop even without a final buffer
|
||||
// commit. Invalidate expanded sampling regions as well as its bounds.
|
||||
self.invalidate_material_scene();
|
||||
crate::backends::direct::render_all(self);
|
||||
if self.idle_inhibitors.remove(surface).is_some() {
|
||||
self.idle_notifier_state
|
||||
.set_is_inhibited(!self.idle_inhibitors.is_empty());
|
||||
|
||||
@@ -59,7 +59,10 @@ impl SeatHandler for Ferese {
|
||||
.or_insert_with(|| crate::cursor::load_named_cursor(&self.cursor_theme, *icon));
|
||||
}
|
||||
self.cursor_status = image;
|
||||
crate::backends::direct::render_all(self);
|
||||
// Pointer focus transitions invoke this with the pointer lock held.
|
||||
// render_all -> cursor_elements -> current_location would try to
|
||||
// acquire that same lock, freezing the entire compositor thread.
|
||||
self.cursor_redraw_pending = true;
|
||||
}
|
||||
|
||||
fn focus_changed(&mut self, seat: &Seat<Self>, focused: Option<&WlSurface>) {
|
||||
|
||||
@@ -272,6 +272,10 @@ impl XdgShellHandler for Ferese {
|
||||
}
|
||||
if let Some(keyboard) = seat.get_keyboard() {
|
||||
keyboard.set_grab(self, PopupKeyboardGrab::new(&popup_grab), serial);
|
||||
// Focus the popup immediately, rather than waiting for its first
|
||||
// key event. Shell clients use focus to initialize popup effects,
|
||||
// and Escape must be delivered to the popup from the outset.
|
||||
keyboard.set_focus(self, popup_grab.current_grab(), serial);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+81
-1
@@ -77,7 +77,19 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
info!(socket = ?state.socket_name, backend = ?launch.backend, "Ferese is accepting Wayland clients");
|
||||
let mut child = spawn_client(&mut state, launch.client, launch.client_capabilities);
|
||||
let result = event_loop.run(None, &mut state, |_| {});
|
||||
let result = event_loop.run(None, &mut state, |state| {
|
||||
// All input/Wayland callbacks have returned, releasing seat locks.
|
||||
// Coalesce cursor changes and redraw here, never inside cursor_image.
|
||||
if std::mem::take(&mut state.cursor_redraw_pending) {
|
||||
backends::direct::render_all(state);
|
||||
}
|
||||
// Registry/sync/configure replies must not depend on a submitted
|
||||
// frame: at startup clients need these before they can draw anything.
|
||||
// This also keeps idle DRM sessions responsive when there is no damage.
|
||||
if let Err(error) = state.display_handle.flush_clients() {
|
||||
tracing::warn!(%error, "failed to flush Wayland clients");
|
||||
}
|
||||
});
|
||||
|
||||
if let Some(child) = &mut child {
|
||||
terminate_child(child);
|
||||
@@ -151,3 +163,71 @@ fn terminate_child(child: &mut Child) {
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod startup_tests {
|
||||
use super::*;
|
||||
use std::{
|
||||
io::{Read, Write},
|
||||
os::unix::net::UnixStream,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn deferred_cursor_redraw_runs_after_input_lock_is_released() {
|
||||
use std::sync::Mutex;
|
||||
|
||||
let mut event_loop = EventLoop::<bool>::try_new().unwrap();
|
||||
let pointer_lock = Arc::new(Mutex::new(()));
|
||||
let callback_lock = pointer_lock.clone();
|
||||
event_loop.handle().insert_idle(move |pending| {
|
||||
// Mirrors Smithay's cursor_image callback during pointer motion.
|
||||
let _guard = callback_lock.lock().unwrap();
|
||||
*pending = true;
|
||||
*pending = true; // Multiple cursor changes must coalesce.
|
||||
assert!(callback_lock.try_lock().is_err());
|
||||
});
|
||||
|
||||
let signal = event_loop.get_signal();
|
||||
let mut pending = false;
|
||||
let mut redraws = 0;
|
||||
event_loop
|
||||
.run(Some(Duration::ZERO), &mut pending, |pending| {
|
||||
if std::mem::take(pending) {
|
||||
// Rendering reads the pointer location at this point.
|
||||
let _guard = pointer_lock.try_lock().expect("input lock still held");
|
||||
redraws += 1;
|
||||
}
|
||||
assert!(!std::mem::take(pending));
|
||||
signal.stop();
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(redraws, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wayland_roundtrip_completes_without_a_rendered_frame() {
|
||||
let mut display = Display::<()>::new().unwrap();
|
||||
let (server, mut client) = UnixStream::pair().unwrap();
|
||||
display
|
||||
.handle()
|
||||
.insert_client(server, Arc::new(state::ClientState::default()))
|
||||
.unwrap();
|
||||
// wl_display.sync(new_id=2), using native-endian Wayland wire format.
|
||||
for word in [1u32, 12u32 << 16, 2u32] {
|
||||
client.write_all(&word.to_ne_bytes()).unwrap();
|
||||
}
|
||||
display.dispatch_clients(&mut ()).unwrap();
|
||||
display.handle().flush_clients().unwrap();
|
||||
client
|
||||
.set_read_timeout(Some(Duration::from_secs(1)))
|
||||
.unwrap();
|
||||
let mut reply = [0u8; 12];
|
||||
client.read_exact(&mut reply).unwrap();
|
||||
assert_eq!(u32::from_ne_bytes(reply[0..4].try_into().unwrap()), 2);
|
||||
assert_eq!(
|
||||
u32::from_ne_bytes(reply[4..8].try_into().unwrap()) & 0xffff,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,9 @@ pub(crate) fn prepare_command(
|
||||
let mut clients = vec![primary];
|
||||
|
||||
command.env_remove("WAYLAND_DISPLAY");
|
||||
// Shell-launched applications must use the public socket, not inherit the
|
||||
// private shell/effects connection or accidentally connect to the host.
|
||||
command.env("FERESE_PUBLIC_WAYLAND_DISPLAY", &state.socket_name);
|
||||
command.env_remove("FERESE_SHELL_CONTROL_SOCKET");
|
||||
command.env("WAYLAND_SOCKET", clients[0].as_raw_fd().to_string());
|
||||
|
||||
|
||||
@@ -147,6 +147,9 @@ pub struct Ferese {
|
||||
viewport_spring_config: SpringConfig,
|
||||
pub(crate) output_profiles: Vec<OutputProfile>,
|
||||
pub cursor_status: CursorImageStatus,
|
||||
// Cursor callbacks may run with Smithay's pointer mutex held. Rendering
|
||||
// reads the pointer position, so defer it until event dispatch returns.
|
||||
pub(crate) cursor_redraw_pending: bool,
|
||||
pub(crate) cursor_theme: xcursor::CursorTheme,
|
||||
pub(crate) named_cursors: HashMap<CursorIcon, crate::cursor::NamedCursor>,
|
||||
pub intercepted_keys: HashSet<smithay::input::keyboard::Keycode>,
|
||||
@@ -476,6 +479,7 @@ impl Ferese {
|
||||
viewport_spring_config: config.viewport_spring_config,
|
||||
output_profiles: config.output_profiles,
|
||||
cursor_status: CursorImageStatus::default_named(),
|
||||
cursor_redraw_pending: false,
|
||||
cursor_theme,
|
||||
named_cursors,
|
||||
intercepted_keys: HashSet::new(),
|
||||
|
||||
+516
-100
@@ -1,6 +1,10 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
error::Error,
|
||||
sync::{
|
||||
Arc,
|
||||
atomic::{AtomicBool, Ordering},
|
||||
},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
@@ -11,8 +15,7 @@ use smithay::{
|
||||
Color32F, ErasedContextId, Frame, ImportDma, Offscreen, Renderer, Texture,
|
||||
damage::OutputDamageTracker,
|
||||
element::{
|
||||
AsRenderElements, Element, Id, Kind as RenderElementKind, RenderElement,
|
||||
UnderlyingStorage,
|
||||
Element, Id, Kind as RenderElementKind, RenderElement, UnderlyingStorage,
|
||||
memory::MemoryRenderBufferRenderElement,
|
||||
render_elements,
|
||||
solid::{SolidColorBuffer, SolidColorRenderElement},
|
||||
@@ -40,9 +43,9 @@ use smithay::{
|
||||
},
|
||||
input::pointer::{CursorImageStatus, CursorImageSurfaceData},
|
||||
output::{Mode, Output, PhysicalProperties, Scale, Subpixel},
|
||||
reexports::calloop::EventLoop,
|
||||
reexports::wayland_protocols::wp::presentation_time::server::wp_presentation_feedback::Kind as PresentationKind,
|
||||
reexports::wayland_server::Resource,
|
||||
reexports::calloop::EventLoop,
|
||||
utils::{
|
||||
Buffer, Clock, Logical, Monotonic, Physical, Point, Rectangle, Scale as RenderScale, Size,
|
||||
Transform,
|
||||
@@ -94,7 +97,7 @@ const ROUNDED_TEXTURE_SHADER: &str = r#"#version 100
|
||||
#extension GL_OES_EGL_image_external : require
|
||||
#endif
|
||||
|
||||
precision mediump float;
|
||||
precision highp float;
|
||||
#if defined(EXTERNAL)
|
||||
uniform samplerExternalOES tex;
|
||||
#else
|
||||
@@ -218,23 +221,63 @@ void main() {
|
||||
}
|
||||
"#;
|
||||
|
||||
// The material program paints either the fallback tint, the edges above client
|
||||
// content, or the shadow outside the surface. All coordinates are physical px.
|
||||
const MATERIAL_SHADER: &str = r#"
|
||||
precision mediump float;
|
||||
|
||||
precision highp float;
|
||||
uniform float alpha;
|
||||
uniform vec4 tint;
|
||||
uniform float noise_amount;
|
||||
uniform vec4 visible_rect;
|
||||
uniform float material_radius;
|
||||
uniform float pixel_scale;
|
||||
uniform vec2 local_origin;
|
||||
uniform vec4 local_axes;
|
||||
uniform vec2 logical_size;
|
||||
uniform float paint_mode;
|
||||
uniform float glass_edges;
|
||||
uniform float edge_bar;
|
||||
uniform vec4 shadow_rect;
|
||||
uniform vec2 shadow_values;
|
||||
varying vec2 v_coords;
|
||||
|
||||
float random(vec2 point) {
|
||||
return fract(sin(dot(point, vec2(12.9898, 78.233))) * 43758.5453);
|
||||
float rounded_distance(vec2 point, vec4 rect) {
|
||||
vec2 half_size = rect.zw * 0.5;
|
||||
float radius = min(material_radius, min(half_size.x, half_size.y));
|
||||
vec2 d = abs(point - rect.xy - half_size) - (half_size - vec2(radius));
|
||||
return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - radius;
|
||||
}
|
||||
|
||||
void main() {
|
||||
float grain = (random(gl_FragCoord.xy) - 0.5) * noise_amount;
|
||||
vec3 color = clamp(tint.rgb + vec3(grain), 0.0, 1.0);
|
||||
float opacity = tint.a * alpha;
|
||||
gl_FragColor = vec4(color * opacity, opacity);
|
||||
float sdf = rounded_distance(gl_FragCoord.xy, visible_rect);
|
||||
float coverage = 1.0 - smoothstep(-0.5, 0.5, sdf);
|
||||
if (paint_mode > 1.5) {
|
||||
float distance = max(rounded_distance(gl_FragCoord.xy, shadow_rect), 0.0);
|
||||
float sigma = max(shadow_values.x * 0.5, 0.5);
|
||||
float opacity = exp(-0.5 * distance * distance / (sigma * sigma))
|
||||
* shadow_values.y * (1.0 - coverage) * alpha;
|
||||
gl_FragColor = vec4(0.0, 0.0, 0.0, opacity);
|
||||
} else if (paint_mode > 0.5) {
|
||||
if (edge_bar > 0.5) {
|
||||
float bottom = logical_size.y * pixel_scale
|
||||
- dot(gl_FragCoord.xy - local_origin, local_axes.zw);
|
||||
float opacity = 0.10 * (1.0 - smoothstep(pixel_scale - 0.5, pixel_scale + 0.5, bottom)) * coverage * alpha;
|
||||
gl_FragColor = vec4(vec3(opacity), opacity);
|
||||
return;
|
||||
}
|
||||
float border = smoothstep(-pixel_scale - 0.5, -pixel_scale + 0.5, sdf);
|
||||
float hairline = smoothstep(-2.0 * pixel_scale - 0.5, -2.0 * pixel_scale + 0.5, sdf) * (1.0 - border);
|
||||
// Inset only on the logical top, including rotated/flipped outputs.
|
||||
float top = dot(gl_FragCoord.xy - local_origin, local_axes.zw);
|
||||
float top_limit = min(2.0 * pixel_scale, logical_size.y * pixel_scale);
|
||||
float highlight = (1.0 - smoothstep(top_limit - 0.5, top_limit + 0.5, top)) * (1.0 - border);
|
||||
float opacity = 1.0 - (1.0 - 0.14 * border)
|
||||
* (1.0 - glass_edges * 0.04 * hairline)
|
||||
* (1.0 - glass_edges * 0.18 * highlight);
|
||||
opacity *= coverage * alpha;
|
||||
gl_FragColor = vec4(vec3(opacity), opacity);
|
||||
} else {
|
||||
float opacity = tint.a * coverage * alpha;
|
||||
gl_FragColor = vec4(tint.rgb * opacity, opacity);
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
@@ -256,25 +299,35 @@ uniform float alpha;
|
||||
uniform vec4 visible_rect;
|
||||
uniform vec2 texture_size;
|
||||
uniform float blur_radius;
|
||||
uniform float tap_scale;
|
||||
uniform float material_radius;
|
||||
uniform float saturation;
|
||||
uniform float brightness;
|
||||
uniform vec4 tint;
|
||||
uniform float noise_amount;
|
||||
uniform float pixel_scale;
|
||||
uniform vec2 local_origin;
|
||||
uniform vec4 local_axes;
|
||||
uniform vec2 logical_size;
|
||||
varying vec2 v_coords;
|
||||
|
||||
// Static, surface-local two-octave fractal noise. A small polynomial hash
|
||||
// avoids the precision-dependent sine hash and does not animate with time.
|
||||
float random(vec2 point) {
|
||||
return fract(sin(dot(point, vec2(12.9898, 78.233))) * 43758.5453);
|
||||
vec3 p = fract(vec3(point.xyx) * 0.1031);
|
||||
p += dot(p, p.yzx + 33.33);
|
||||
return fract((p.x + p.y) * p.z);
|
||||
}
|
||||
float noise(vec2 p) {
|
||||
vec2 i = floor(p);
|
||||
vec2 f = fract(p);
|
||||
f = f * f * (3.0 - 2.0 * f);
|
||||
return mix(mix(random(i), random(i + vec2(1.0, 0.0)), f.x),
|
||||
mix(random(i + vec2(0.0, 1.0)), random(i + vec2(1.0)), f.x), f.y);
|
||||
}
|
||||
|
||||
float kernel_weight(int tap) {
|
||||
int distance = tap < 0 ? -tap : tap;
|
||||
if (distance == 0) {
|
||||
return 6.0;
|
||||
}
|
||||
if (distance == 1) {
|
||||
return 4.0;
|
||||
}
|
||||
return 1.0;
|
||||
float kernel_weight(float distance) {
|
||||
return exp(-distance * distance / 18.0);
|
||||
}
|
||||
|
||||
void main() {
|
||||
@@ -286,22 +339,41 @@ void main() {
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 step_size = vec2(blur_radius * 0.5) / max(texture_size, vec2(1.0));
|
||||
vec2 step_size = vec2(blur_radius / 6.0) / max(texture_size, vec2(1.0));
|
||||
vec4 color = vec4(0.0);
|
||||
for (int y = -2; y <= 2; y++) {
|
||||
for (int x = -2; x <= 2; x++) {
|
||||
float weight = kernel_weight(x) * kernel_weight(y);
|
||||
vec2 offset = vec2(float(x), float(y)) * step_size;
|
||||
float weight_sum = 0.0;
|
||||
for (int y = -6; y <= 6; y++) {
|
||||
if (abs(float(y)) * tap_scale > 6.0) { continue; }
|
||||
for (int x = -6; x <= 6; x++) {
|
||||
if (abs(float(x)) * tap_scale > 6.0) { continue; }
|
||||
float weight = kernel_weight(float(x) * tap_scale) * kernel_weight(float(y) * tap_scale);
|
||||
vec2 offset = vec2(float(x), float(y)) * step_size * tap_scale;
|
||||
color += texture2D(tex, v_coords + offset) * weight;
|
||||
weight_sum += weight;
|
||||
}
|
||||
}
|
||||
color /= 256.0;
|
||||
color /= weight_sum;
|
||||
|
||||
float luma = dot(color.rgb, vec3(0.2126, 0.7152, 0.0722));
|
||||
vec3 adjusted = mix(vec3(luma), color.rgb, saturation) * brightness;
|
||||
adjusted = mix(adjusted, tint.rgb, tint.a);
|
||||
adjusted += vec3((random(point) - 0.5) * noise_amount);
|
||||
gl_FragColor = vec4(clamp(adjusted, 0.0, 1.0) * alpha, alpha);
|
||||
vec2 relative = point - local_origin;
|
||||
vec2 local = vec2(dot(relative, local_axes.xy), dot(relative, local_axes.zw)) / pixel_scale;
|
||||
vec2 size = logical_size;
|
||||
// CSS 155deg: direction (sin(155deg), -cos(155deg)). Project onto
|
||||
// the full gradient line, including the aspect ratio of the surface.
|
||||
vec2 direction = vec2(0.422618, 0.906308);
|
||||
float position = dot(local, direction) / max(dot(size, direction), 1.0);
|
||||
adjusted = mix(adjusted, vec3(1.0), 0.10 * clamp(1.0 - position / 0.40, 0.0, 1.0));
|
||||
float grain = (noise(local * 0.8) + 0.5 * noise(local * 1.6)) / 1.5;
|
||||
vec3 overlay = mix(2.0 * adjusted * grain,
|
||||
1.0 - 2.0 * (1.0 - adjusted) * (1.0 - grain), step(vec3(0.5), adjusted));
|
||||
adjusted = mix(adjusted, overlay, noise_amount);
|
||||
vec2 half_size = visible_rect.zw * 0.5;
|
||||
vec2 distance = abs(point - visible_rect.xy - half_size) - (half_size - vec2(material_radius));
|
||||
float sdf = length(max(distance, 0.0)) + min(max(distance.x, distance.y), 0.0) - material_radius;
|
||||
float coverage = alpha * (1.0 - smoothstep(-0.5, 0.5, sdf));
|
||||
gl_FragColor = vec4(clamp(adjusted, 0.0, 1.0) * coverage, coverage);
|
||||
}
|
||||
"#;
|
||||
|
||||
@@ -333,6 +405,16 @@ pub(crate) struct BackdropProgram(GlesTexProgram);
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct MaterialParameters {
|
||||
radius: f32,
|
||||
pixel_scale: f32,
|
||||
local_origin: [f32; 2],
|
||||
local_axes: [f32; 4],
|
||||
logical_size: [f32; 2],
|
||||
glass_edges: f32,
|
||||
edge_bar: f32,
|
||||
shadow_rect: [f32; 4],
|
||||
shadow_values: [f32; 2],
|
||||
shadow_bounds: Rectangle<i32, Logical>,
|
||||
geometry: Rectangle<i32, Logical>,
|
||||
tint: [f32; 4],
|
||||
noise: f32,
|
||||
@@ -340,6 +422,7 @@ struct MaterialParameters {
|
||||
scene_generation: u64,
|
||||
opaque: bool,
|
||||
blur: f32,
|
||||
tap_scale: f32,
|
||||
saturation: f32,
|
||||
brightness: f32,
|
||||
sample_geometry: Rectangle<i32, Logical>,
|
||||
@@ -352,6 +435,8 @@ struct MaterialParameters {
|
||||
struct CachedMaterial {
|
||||
element: CachedMaterialElement,
|
||||
parameters: MaterialParameters,
|
||||
edge: PixelShaderElement,
|
||||
shadow: PixelShaderElement,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -367,6 +452,7 @@ pub(crate) struct MaterialBuffers {
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct BackdropRenderElement {
|
||||
capture_dirty: Arc<AtomicBool>,
|
||||
texture: GlesTexture,
|
||||
program: GlesTexProgram,
|
||||
id: Id,
|
||||
@@ -379,6 +465,7 @@ struct BackdropRenderElement {
|
||||
impl BackdropRenderElement {
|
||||
fn new(texture: GlesTexture, program: GlesTexProgram, parameters: &MaterialParameters) -> Self {
|
||||
Self {
|
||||
capture_dirty: Arc::new(AtomicBool::new(true)),
|
||||
texture,
|
||||
program,
|
||||
id: Id::new(),
|
||||
@@ -390,6 +477,7 @@ impl BackdropRenderElement {
|
||||
}
|
||||
|
||||
fn update(&mut self, parameters: &MaterialParameters) {
|
||||
self.capture_dirty.store(true, Ordering::Relaxed);
|
||||
self.geometry = parameters.sample_geometry;
|
||||
self.capture_rect = framebuffer_capture_rect(parameters.sample_framebuffer);
|
||||
self.uniforms = backdrop_uniforms(parameters);
|
||||
@@ -419,11 +507,7 @@ impl Element for BackdropRenderElement {
|
||||
scale: RenderScale<f64>,
|
||||
commit: Option<CommitCounter>,
|
||||
) -> DamageSet<i32, Physical> {
|
||||
if commit == Some(self.commit) {
|
||||
DamageSet::default()
|
||||
} else {
|
||||
DamageSet::from_slice(&[Rectangle::from_size(self.geometry(scale).size)])
|
||||
}
|
||||
backdrop_damage(self.geometry(scale).size, self.commit, commit)
|
||||
}
|
||||
|
||||
fn opaque_regions(&self, _scale: RenderScale<f64>) -> OpaqueRegions<i32, Physical> {
|
||||
@@ -441,6 +525,19 @@ impl Element for BackdropRenderElement {
|
||||
}
|
||||
}
|
||||
|
||||
fn backdrop_damage(
|
||||
size: Size<i32, Physical>,
|
||||
current: CommitCounter,
|
||||
previous: Option<CommitCounter>,
|
||||
) -> DamageSet<i32, Physical> {
|
||||
if previous == Some(current) {
|
||||
DamageSet::default()
|
||||
} else {
|
||||
// A new scene needs its entire sampling halo repainted before capture.
|
||||
DamageSet::from_slice(&[Rectangle::from_size(size)])
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderElement<GlesRenderer> for BackdropRenderElement {
|
||||
fn draw(
|
||||
&self,
|
||||
@@ -452,30 +549,36 @@ impl RenderElement<GlesRenderer> for BackdropRenderElement {
|
||||
) -> Result<(), GlesError> {
|
||||
let texture = self.texture.tex_id();
|
||||
let [x, y, width, height] = self.capture_rect;
|
||||
frame.with_context(|gl| unsafe {
|
||||
gl.BindTexture(smithay::backend::renderer::gles::ffi::TEXTURE_2D, texture);
|
||||
gl.TexParameteri(
|
||||
smithay::backend::renderer::gles::ffi::TEXTURE_2D,
|
||||
smithay::backend::renderer::gles::ffi::TEXTURE_WRAP_S,
|
||||
smithay::backend::renderer::gles::ffi::CLAMP_TO_EDGE as i32,
|
||||
);
|
||||
gl.TexParameteri(
|
||||
smithay::backend::renderer::gles::ffi::TEXTURE_2D,
|
||||
smithay::backend::renderer::gles::ffi::TEXTURE_WRAP_T,
|
||||
smithay::backend::renderer::gles::ffi::CLAMP_TO_EDGE as i32,
|
||||
);
|
||||
gl.CopyTexSubImage2D(
|
||||
smithay::backend::renderer::gles::ffi::TEXTURE_2D,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
);
|
||||
gl.BindTexture(smithay::backend::renderer::gles::ffi::TEXTURE_2D, 0);
|
||||
})?;
|
||||
// Buffer-age restoration and unrelated partial damage must reuse the
|
||||
// clean captured scene. Recapturing a partly repainted framebuffer
|
||||
// would feed previous glass pixels back into the blur.
|
||||
if self.capture_dirty.load(Ordering::Relaxed) {
|
||||
frame.with_context(|gl| unsafe {
|
||||
gl.BindTexture(smithay::backend::renderer::gles::ffi::TEXTURE_2D, texture);
|
||||
gl.TexParameteri(
|
||||
smithay::backend::renderer::gles::ffi::TEXTURE_2D,
|
||||
smithay::backend::renderer::gles::ffi::TEXTURE_WRAP_S,
|
||||
smithay::backend::renderer::gles::ffi::CLAMP_TO_EDGE as i32,
|
||||
);
|
||||
gl.TexParameteri(
|
||||
smithay::backend::renderer::gles::ffi::TEXTURE_2D,
|
||||
smithay::backend::renderer::gles::ffi::TEXTURE_WRAP_T,
|
||||
smithay::backend::renderer::gles::ffi::CLAMP_TO_EDGE as i32,
|
||||
);
|
||||
gl.CopyTexSubImage2D(
|
||||
smithay::backend::renderer::gles::ffi::TEXTURE_2D,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
);
|
||||
gl.BindTexture(smithay::backend::renderer::gles::ffi::TEXTURE_2D, 0);
|
||||
})?;
|
||||
self.capture_dirty.store(false, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
frame.render_texture_from_to(
|
||||
&self.texture,
|
||||
@@ -1452,45 +1555,149 @@ fn layer_elements(
|
||||
|
||||
let mut elements = Vec::new();
|
||||
for (geometry, layer) in layers {
|
||||
elements.extend(
|
||||
AsRenderElements::<GlesRenderer>::render_elements::<
|
||||
WaylandSurfaceRenderElement<GlesRenderer>,
|
||||
>(
|
||||
&layer,
|
||||
for (popup, offset) in PopupManager::popups_for_surface(layer.wl_surface()) {
|
||||
let mut bounds = popup.geometry();
|
||||
let content_origin = geometry.loc + offset - bounds.loc;
|
||||
bounds.loc = geometry.loc + offset;
|
||||
append_material_surface(
|
||||
state,
|
||||
renderer,
|
||||
geometry.loc.to_physical_precise_round(scale),
|
||||
scale.into(),
|
||||
1.0,
|
||||
)
|
||||
.into_iter()
|
||||
.filter_map(|element| {
|
||||
let origin = Point::<i32, Physical>::default();
|
||||
let element = RescaleRenderElement::from_element(element, origin, 1.0);
|
||||
let element =
|
||||
RelocateRenderElement::from_element(element, origin, Relocate::Relative);
|
||||
|
||||
CropRenderElement::from_element(element, scale, output_crop).map(Into::into)
|
||||
}),
|
||||
);
|
||||
|
||||
if let Some(material) = material_element(state, renderer, output, &layer, geometry) {
|
||||
elements.push(material);
|
||||
output,
|
||||
popup.wl_surface(),
|
||||
bounds,
|
||||
content_origin,
|
||||
scale,
|
||||
output_crop,
|
||||
&mut elements,
|
||||
);
|
||||
}
|
||||
append_material_surface(
|
||||
state,
|
||||
renderer,
|
||||
output,
|
||||
layer.wl_surface(),
|
||||
geometry,
|
||||
geometry.loc,
|
||||
scale,
|
||||
output_crop,
|
||||
&mut elements,
|
||||
);
|
||||
}
|
||||
|
||||
elements
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn append_material_surface(
|
||||
state: &mut Ferese,
|
||||
renderer: &mut GlesRenderer,
|
||||
output: &Output,
|
||||
surface: &smithay::reexports::wayland_server::protocol::wl_surface::WlSurface,
|
||||
geometry: Rectangle<i32, Logical>,
|
||||
content_origin: Point<i32, Logical>,
|
||||
scale: f64,
|
||||
output_crop: Rectangle<i32, Physical>,
|
||||
elements: &mut Vec<AnimatedWindowRenderElement>,
|
||||
) {
|
||||
let radius = if crate::effects::surface_role(surface)
|
||||
.is_some_and(|(role, _)| role == crate::effects::SemanticRole::Panel)
|
||||
{
|
||||
state.theme_settings.panel_radius
|
||||
} else {
|
||||
state.theme_settings.material_radius
|
||||
};
|
||||
let material = material_element(state, renderer, output, surface, geometry, radius as f32);
|
||||
let clip = material.as_ref().and_then(|_| {
|
||||
let mode = output.current_mode()?;
|
||||
let program = rounded_clip_program(state, renderer)?;
|
||||
Some((
|
||||
program.texture,
|
||||
framebuffer_clip_rect(
|
||||
geometry.to_physical_precise_round(scale),
|
||||
mode.size,
|
||||
output.current_transform().invert(),
|
||||
),
|
||||
scaled_effect_value(radius, geometry, scale),
|
||||
))
|
||||
});
|
||||
// Smithay element lists are front to back: edges, content, material, shadow.
|
||||
let material = material.map(|(edge, background, shadow)| {
|
||||
elements.push(edge);
|
||||
(background, shadow)
|
||||
});
|
||||
let content = render_elements_from_surface_tree::<
|
||||
GlesRenderer,
|
||||
WaylandSurfaceRenderElement<GlesRenderer>,
|
||||
>(
|
||||
renderer,
|
||||
surface,
|
||||
content_origin.to_physical_precise_round(scale),
|
||||
scale,
|
||||
1.0,
|
||||
RenderElementKind::Unspecified,
|
||||
);
|
||||
elements.extend(content.into_iter().filter_map(|element| {
|
||||
let origin = Point::<i32, Physical>::default();
|
||||
let element = if let Some((program, clip_rect, radius)) = &clip {
|
||||
WindowContentRenderElement::Rounded(RoundedSurfaceRenderElement {
|
||||
inner: element,
|
||||
program: program.clone(),
|
||||
clip_rect: *clip_rect,
|
||||
radius: *radius,
|
||||
clip_changed: false,
|
||||
})
|
||||
} else {
|
||||
WindowContentRenderElement::Popup(element)
|
||||
};
|
||||
let element = RescaleRenderElement::from_element(element, origin, 1.0);
|
||||
let element = RelocateRenderElement::from_element(element, origin, Relocate::Relative);
|
||||
CropRenderElement::from_element(element, scale, output_crop).map(Into::into)
|
||||
}));
|
||||
if let Some((background, shadow)) = material {
|
||||
elements.push(background);
|
||||
elements.push(shadow);
|
||||
}
|
||||
}
|
||||
|
||||
fn material_element(
|
||||
state: &mut Ferese,
|
||||
renderer: &mut GlesRenderer,
|
||||
output: &Output,
|
||||
layer: &LayerSurface,
|
||||
surface: &smithay::reexports::wayland_server::protocol::wl_surface::WlSurface,
|
||||
geometry: Rectangle<i32, Logical>,
|
||||
) -> Option<AnimatedWindowRenderElement> {
|
||||
let surface = layer.wl_surface();
|
||||
radius: f32,
|
||||
) -> Option<(
|
||||
AnimatedWindowRenderElement,
|
||||
AnimatedWindowRenderElement,
|
||||
AnimatedWindowRenderElement,
|
||||
)> {
|
||||
material_element_for_style(
|
||||
state,
|
||||
renderer,
|
||||
output,
|
||||
surface,
|
||||
geometry,
|
||||
radius,
|
||||
state.theme_settings.material_style,
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn material_element_for_style(
|
||||
state: &mut Ferese,
|
||||
renderer: &mut GlesRenderer,
|
||||
output: &Output,
|
||||
surface: &smithay::reexports::wayland_server::protocol::wl_surface::WlSurface,
|
||||
geometry: Rectangle<i32, Logical>,
|
||||
radius: f32,
|
||||
style: crate::config::MaterialStyle,
|
||||
) -> Option<(
|
||||
AnimatedWindowRenderElement,
|
||||
AnimatedWindowRenderElement,
|
||||
AnimatedWindowRenderElement,
|
||||
)> {
|
||||
let (role, generation) = crate::effects::surface_role(surface)?;
|
||||
let material = crate::effects::resolve_material(role, state.theme_settings.material_style);
|
||||
let material = crate::effects::resolve_material(role, style, state.theme_settings.glass);
|
||||
let mode = output.current_mode()?;
|
||||
let scale = output.current_scale().fractional_scale();
|
||||
let output_logical = smithay::utils::Size::<i32, Logical>::from((
|
||||
@@ -1501,9 +1708,46 @@ fn material_element(
|
||||
expanded_blur_region(geometry, material.blur.ceil() as i32, output_logical);
|
||||
let sample_physical = sample_geometry.to_physical_precise_round(scale);
|
||||
let transform = output.current_transform().invert();
|
||||
let [red, green, blue, _] = state.theme_settings.surface_base_color.0;
|
||||
let [red, green, blue, _] =
|
||||
if state.theme_settings.material_style == crate::config::MaterialStyle::Glass {
|
||||
state.theme_settings.glass.tint.0
|
||||
} else {
|
||||
state.theme_settings.surface_base_color.0
|
||||
};
|
||||
let radius = radius.min(geometry.size.w.min(geometry.size.h) as f32 * 0.5);
|
||||
let [offset_y, shadow_blur, shadow_opacity] = material.shadow;
|
||||
let edge_bar =
|
||||
role == crate::effects::SemanticRole::Panel && radius == 0.0 && geometry.loc.y == 0;
|
||||
let shadow_opacity = if edge_bar { 0.0 } else { shadow_opacity };
|
||||
let shadow_geometry = Rectangle::new(
|
||||
(geometry.loc.x, geometry.loc.y + offset_y.round() as i32).into(),
|
||||
geometry.size,
|
||||
);
|
||||
let tint = [red, green, blue, material.opacity];
|
||||
let (local_origin, local_axes) = material_local_coordinates(
|
||||
geometry.loc.to_physical_precise_round(scale),
|
||||
mode.size,
|
||||
transform,
|
||||
);
|
||||
let parameters = MaterialParameters {
|
||||
radius: radius * scale as f32,
|
||||
pixel_scale: scale as f32,
|
||||
local_origin,
|
||||
local_axes,
|
||||
logical_size: [geometry.size.w as f32, geometry.size.h as f32],
|
||||
edge_bar: if edge_bar { 1.0 } else { 0.0 },
|
||||
glass_edges: if material.style == crate::config::MaterialStyle::Glass {
|
||||
1.0
|
||||
} else {
|
||||
0.0
|
||||
},
|
||||
shadow_rect: framebuffer_clip_rect(
|
||||
shadow_geometry.to_physical_precise_round(scale),
|
||||
mode.size,
|
||||
transform,
|
||||
),
|
||||
shadow_values: [(shadow_blur * scale) as f32, shadow_opacity as f32],
|
||||
shadow_bounds: shadow_bounds(geometry, offset_y, shadow_blur),
|
||||
geometry,
|
||||
tint,
|
||||
noise: material.noise,
|
||||
@@ -1511,8 +1755,14 @@ fn material_element(
|
||||
scene_generation: matches!(material.style, crate::config::MaterialStyle::Glass)
|
||||
.then(|| state.material_scene_generation())
|
||||
.unwrap_or(0),
|
||||
opaque: material.opacity == 1.0,
|
||||
opaque: material.opacity == 1.0 && radius == 0.0,
|
||||
blur: material.blur * scale as f32,
|
||||
tap_scale: if state.theme_settings.glass.quality >= crate::config::GlassQuality::ReducedBlur
|
||||
{
|
||||
2.0
|
||||
} else {
|
||||
1.0
|
||||
},
|
||||
saturation: material.saturation,
|
||||
brightness: material.brightness,
|
||||
sample_geometry,
|
||||
@@ -1574,6 +1824,21 @@ fn material_element(
|
||||
}
|
||||
})
|
||||
.flatten();
|
||||
if needs_replacement
|
||||
&& replacement.is_none()
|
||||
&& material.style == crate::config::MaterialStyle::Glass
|
||||
{
|
||||
return material_element_for_style(
|
||||
state,
|
||||
renderer,
|
||||
output,
|
||||
surface,
|
||||
geometry,
|
||||
radius,
|
||||
crate::config::MaterialStyle::Translucent,
|
||||
);
|
||||
}
|
||||
let decoration_program = material_program(state, renderer)?;
|
||||
let buffers = state.material_buffers.entry(surface.clone()).or_default();
|
||||
if !buffers.contexts.contains_key(&context) {
|
||||
buffers.contexts.insert(
|
||||
@@ -1581,12 +1846,39 @@ fn material_element(
|
||||
CachedMaterial {
|
||||
element: replacement.take()?,
|
||||
parameters: parameters.clone(),
|
||||
edge: PixelShaderElement::new(
|
||||
decoration_program.0.clone(),
|
||||
geometry,
|
||||
None,
|
||||
1.0,
|
||||
decoration_uniforms(¶meters, 1.0),
|
||||
RenderElementKind::Unspecified,
|
||||
),
|
||||
shadow: PixelShaderElement::new(
|
||||
decoration_program.0.clone(),
|
||||
parameters.shadow_bounds,
|
||||
None,
|
||||
1.0,
|
||||
decoration_uniforms(¶meters, 2.0),
|
||||
RenderElementKind::Unspecified,
|
||||
),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
let cached = buffers.contexts.get_mut(&context)?;
|
||||
if let Some(replacement) = replacement.take() {
|
||||
cached.element = replacement;
|
||||
}
|
||||
if cached.parameters != parameters {
|
||||
cached.edge.resize(geometry, None);
|
||||
cached
|
||||
.edge
|
||||
.update_uniforms(decoration_uniforms(¶meters, 1.0));
|
||||
cached.shadow.resize(parameters.shadow_bounds, None);
|
||||
cached
|
||||
.shadow
|
||||
.update_uniforms(decoration_uniforms(¶meters, 2.0));
|
||||
match &mut cached.element {
|
||||
CachedMaterialElement::Tint(element) => {
|
||||
if cached.parameters.geometry != parameters.geometry
|
||||
@@ -1599,20 +1891,22 @@ fn material_element(
|
||||
}
|
||||
element.update_uniforms(material_uniforms(¶meters));
|
||||
}
|
||||
CachedMaterialElement::Backdrop(element)
|
||||
if cached.parameters.sample_physical.size == parameters.sample_physical.size =>
|
||||
{
|
||||
CachedMaterialElement::Backdrop(element) => {
|
||||
element.update(¶meters);
|
||||
}
|
||||
_ => cached.element = replacement.take()?,
|
||||
}
|
||||
cached.parameters = parameters;
|
||||
}
|
||||
|
||||
Some(match &cached.element {
|
||||
let background = match &cached.element {
|
||||
CachedMaterialElement::Tint(element) => element.clone().into(),
|
||||
CachedMaterialElement::Backdrop(element) => element.clone().into(),
|
||||
})
|
||||
};
|
||||
Some((
|
||||
cached.edge.clone().into(),
|
||||
background,
|
||||
cached.shadow.clone().into(),
|
||||
))
|
||||
}
|
||||
|
||||
fn material_program(state: &mut Ferese, renderer: &mut GlesRenderer) -> Option<MaterialProgram> {
|
||||
@@ -1622,8 +1916,18 @@ fn material_program(state: &mut Ferese, renderer: &mut GlesRenderer) -> Option<M
|
||||
}
|
||||
|
||||
let uniforms = [
|
||||
UniformName::new("visible_rect", UniformType::_4f),
|
||||
UniformName::new("material_radius", UniformType::_1f),
|
||||
UniformName::new("tint", UniformType::_4f),
|
||||
UniformName::new("noise_amount", UniformType::_1f),
|
||||
UniformName::new("pixel_scale", UniformType::_1f),
|
||||
UniformName::new("local_origin", UniformType::_2f),
|
||||
UniformName::new("local_axes", UniformType::_4f),
|
||||
UniformName::new("logical_size", UniformType::_2f),
|
||||
UniformName::new("paint_mode", UniformType::_1f),
|
||||
UniformName::new("glass_edges", UniformType::_1f),
|
||||
UniformName::new("edge_bar", UniformType::_1f),
|
||||
UniformName::new("shadow_rect", UniformType::_4f),
|
||||
UniformName::new("shadow_values", UniformType::_2f),
|
||||
];
|
||||
match renderer.compile_custom_pixel_shader(MATERIAL_SHADER, &uniforms) {
|
||||
Ok(program) => {
|
||||
@@ -1646,12 +1950,18 @@ fn backdrop_program(state: &mut Ferese, renderer: &mut GlesRenderer) -> Option<B
|
||||
|
||||
let uniforms = [
|
||||
UniformName::new("visible_rect", UniformType::_4f),
|
||||
UniformName::new("material_radius", UniformType::_1f),
|
||||
UniformName::new("texture_size", UniformType::_2f),
|
||||
UniformName::new("blur_radius", UniformType::_1f),
|
||||
UniformName::new("tap_scale", UniformType::_1f),
|
||||
UniformName::new("saturation", UniformType::_1f),
|
||||
UniformName::new("brightness", UniformType::_1f),
|
||||
UniformName::new("tint", UniformType::_4f),
|
||||
UniformName::new("noise_amount", UniformType::_1f),
|
||||
UniformName::new("pixel_scale", UniformType::_1f),
|
||||
UniformName::new("local_origin", UniformType::_2f),
|
||||
UniformName::new("local_axes", UniformType::_4f),
|
||||
UniformName::new("logical_size", UniformType::_2f),
|
||||
];
|
||||
match renderer.compile_custom_texture_shader(BACKDROP_SHADER, &uniforms) {
|
||||
Ok(program) => {
|
||||
@@ -1667,14 +1977,33 @@ fn backdrop_program(state: &mut Ferese, renderer: &mut GlesRenderer) -> Option<B
|
||||
}
|
||||
|
||||
fn material_uniforms(parameters: &MaterialParameters) -> Vec<Uniform<'static>> {
|
||||
decoration_uniforms(parameters, 0.0)
|
||||
}
|
||||
|
||||
fn decoration_uniforms(parameters: &MaterialParameters, paint_mode: f32) -> Vec<Uniform<'static>> {
|
||||
vec![
|
||||
Uniform::new("pixel_scale", parameters.pixel_scale).into_owned(),
|
||||
Uniform::new("local_origin", parameters.local_origin).into_owned(),
|
||||
Uniform::new("local_axes", parameters.local_axes).into_owned(),
|
||||
Uniform::new("logical_size", parameters.logical_size).into_owned(),
|
||||
Uniform::new("paint_mode", paint_mode).into_owned(),
|
||||
Uniform::new("glass_edges", parameters.glass_edges).into_owned(),
|
||||
Uniform::new("edge_bar", parameters.edge_bar).into_owned(),
|
||||
Uniform::new("shadow_rect", parameters.shadow_rect).into_owned(),
|
||||
Uniform::new("shadow_values", parameters.shadow_values).into_owned(),
|
||||
Uniform::new("visible_rect", parameters.visible_framebuffer).into_owned(),
|
||||
Uniform::new("material_radius", parameters.radius).into_owned(),
|
||||
Uniform::new("tint", parameters.tint).into_owned(),
|
||||
Uniform::new("noise_amount", parameters.noise).into_owned(),
|
||||
]
|
||||
}
|
||||
|
||||
fn backdrop_uniforms(parameters: &MaterialParameters) -> Vec<Uniform<'static>> {
|
||||
vec![
|
||||
Uniform::new("pixel_scale", parameters.pixel_scale).into_owned(),
|
||||
Uniform::new("local_origin", parameters.local_origin).into_owned(),
|
||||
Uniform::new("local_axes", parameters.local_axes).into_owned(),
|
||||
Uniform::new("logical_size", parameters.logical_size).into_owned(),
|
||||
Uniform::new("material_radius", parameters.radius).into_owned(),
|
||||
Uniform::new("visible_rect", parameters.visible_framebuffer).into_owned(),
|
||||
Uniform::new(
|
||||
"texture_size",
|
||||
@@ -1685,6 +2014,7 @@ fn backdrop_uniforms(parameters: &MaterialParameters) -> Vec<Uniform<'static>> {
|
||||
)
|
||||
.into_owned(),
|
||||
Uniform::new("blur_radius", parameters.blur).into_owned(),
|
||||
Uniform::new("tap_scale", parameters.tap_scale).into_owned(),
|
||||
Uniform::new("saturation", parameters.saturation).into_owned(),
|
||||
Uniform::new("brightness", parameters.brightness).into_owned(),
|
||||
Uniform::new("tint", parameters.tint).into_owned(),
|
||||
@@ -1692,6 +2022,21 @@ fn backdrop_uniforms(parameters: &MaterialParameters) -> Vec<Uniform<'static>> {
|
||||
]
|
||||
}
|
||||
|
||||
fn material_local_coordinates(
|
||||
origin: Point<i32, Physical>,
|
||||
output_size: Size<i32, Physical>,
|
||||
transform: Transform,
|
||||
) -> ([f32; 2], [f32; 4]) {
|
||||
let area = transform.transform_size(output_size);
|
||||
let mapped = transform.transform_point_in(origin, &area);
|
||||
let x = transform.transform_point_in(origin + Point::from((1, 0)), &area) - mapped;
|
||||
let y = transform.transform_point_in(origin + Point::from((0, 1)), &area) - mapped;
|
||||
(
|
||||
[mapped.x as f32, mapped.y as f32],
|
||||
[x.x as f32, x.y as f32, y.x as f32, y.y as f32],
|
||||
)
|
||||
}
|
||||
|
||||
fn framebuffer_capture_rect(rect: [f32; 4]) -> [i32; 4] {
|
||||
[
|
||||
rect[0].round() as i32,
|
||||
@@ -1809,18 +2154,20 @@ mod tests {
|
||||
element::{Element, Id},
|
||||
utils::CommitCounter,
|
||||
},
|
||||
utils::{Buffer, Logical, Physical, Rectangle, Scale, Transform},
|
||||
utils::{Buffer, Logical, Physical, Point, Rectangle, Scale, Size, Transform},
|
||||
};
|
||||
|
||||
use super::{
|
||||
color_with_alpha, expanded_blur_region, framebuffer_capture_rect, framebuffer_clip_rect,
|
||||
normalized_scale, rounded_visual_rect, scaled_visual_rect, shadow_bounds,
|
||||
material_local_coordinates, normalized_scale, rounded_visual_rect, scaled_visual_rect,
|
||||
shadow_bounds,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
struct DamageElement {
|
||||
id: Id,
|
||||
geometry: Rectangle<i32, Logical>,
|
||||
commit: CommitCounter,
|
||||
}
|
||||
|
||||
impl DamageElement {
|
||||
@@ -1828,6 +2175,7 @@ mod tests {
|
||||
Self {
|
||||
id: Id::new(),
|
||||
geometry,
|
||||
commit: CommitCounter::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1838,7 +2186,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn current_commit(&self) -> CommitCounter {
|
||||
CommitCounter::default()
|
||||
self.commit
|
||||
}
|
||||
|
||||
fn src(&self) -> Rectangle<f64, Buffer> {
|
||||
@@ -1853,6 +2201,38 @@ mod tests {
|
||||
fn geometry(&self, scale: Scale<f64>) -> Rectangle<i32, Physical> {
|
||||
self.geometry.to_physical_precise_round(scale)
|
||||
}
|
||||
|
||||
fn damage_since(
|
||||
&self,
|
||||
scale: Scale<f64>,
|
||||
commit: Option<CommitCounter>,
|
||||
) -> smithay::backend::renderer::utils::DamageSet<i32, Physical> {
|
||||
super::backdrop_damage(self.geometry(scale).size, self.current_commit(), commit)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn backdrop_is_idle_until_scene_changes_then_repaints_full_sampling_region() {
|
||||
for scale in [1.0, 1.25, 1.8, 2.0] {
|
||||
for transform in [Transform::Normal, Transform::Flipped180] {
|
||||
let mut tracker = OutputDamageTracker::new((1600, 1200), scale, transform);
|
||||
let mut backdrop =
|
||||
DamageElement::new(Rectangle::new((50, 40).into(), (400, 240).into()));
|
||||
tracker.damage_output(0, &[&backdrop]).unwrap();
|
||||
for _ in 0..3 {
|
||||
assert!(tracker.damage_output(1, &[&backdrop]).unwrap().0.is_none());
|
||||
backdrop.commit.increment();
|
||||
let damage = tracker
|
||||
.damage_output(1, &[&backdrop])
|
||||
.unwrap()
|
||||
.0
|
||||
.cloned()
|
||||
.unwrap();
|
||||
let bounds = backdrop.geometry(scale.into());
|
||||
assert!(damage.iter().any(|rect| rect.contains_rect(bounds)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1877,6 +2257,42 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn glass_lighting_coordinates_follow_every_output_transform() {
|
||||
let origin = Point::<i32, Physical>::from((120, 90));
|
||||
let size = Size::<i32, Physical>::from((1000, 800));
|
||||
for transform in [
|
||||
Transform::Normal,
|
||||
Transform::_90,
|
||||
Transform::_180,
|
||||
Transform::_270,
|
||||
Transform::Flipped,
|
||||
Transform::Flipped90,
|
||||
Transform::Flipped180,
|
||||
Transform::Flipped270,
|
||||
] {
|
||||
let (mapped_origin, axes) = material_local_coordinates(origin, size, transform);
|
||||
for local in [(0, 0), (24, 0), (0, 35), (57, 81)] {
|
||||
let point = transform.transform_point_in(
|
||||
origin + Point::from(local),
|
||||
&transform.transform_size(size),
|
||||
);
|
||||
let relative = [
|
||||
point.x as f32 - mapped_origin[0],
|
||||
point.y as f32 - mapped_origin[1],
|
||||
];
|
||||
assert_eq!(
|
||||
relative[0] * axes[0] + relative[1] * axes[1],
|
||||
local.0 as f32
|
||||
);
|
||||
assert_eq!(
|
||||
relative[0] * axes[2] + relative[1] * axes[3],
|
||||
local.1 as f32
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clip_rect_follows_output_transform() {
|
||||
let geometry = Rectangle::<i32, Physical>::new((10, 5).into(), (30, 40).into());
|
||||
|
||||
Reference in new issue
Block a user