exit_confirm_dialog: Add backdrop
Browse files at this commit9d3beb49315ae4cde3d8edfb979fccda52af3faeParent: 7aba44a1 changed file +27 -2
src/ui/exit_confirm_dialog.rsmodified+27 -2
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | use std::cell::RefCell; |
| 2 | 2 | use std::collections::HashMap; |
| 3 | +use std::sync::Mutex; | |
| 3 | 4 | |
| 4 | 5 | use arrayvec::ArrayVec; |
| 5 | 6 | use ordered_float::NotNan; |
| @@ -8,12 +9,13 @@ use pangocairo::pango::{Alignment, FontDescription}; | ||
| 8 | 9 | use smithay::backend::renderer::element::Kind; |
| 9 | 10 | use smithay::output::Output; |
| 10 | 11 | use smithay::reexports::gbm::Format as Fourcc; |
| 11 | -use smithay::utils::Transform; | |
| 12 | +use smithay::utils::{Point, Transform}; | |
| 12 | 13 | |
| 13 | 14 | use crate::niri_render_elements; |
| 14 | 15 | use crate::render_helpers::memory::MemoryBuffer; |
| 15 | 16 | use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement; |
| 16 | 17 | use crate::render_helpers::renderer::NiriRenderer; |
| 18 | +use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement}; | |
| 17 | 19 | use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement}; |
| 18 | 20 | use crate::utils::{output_size, to_physical_precise_round}; |
| 19 | 21 | |
| @@ -22,6 +24,7 @@ const TEXT: &str = "Are you sure you want to exit niri?\n\n\ | ||
| 22 | 24 | const PADDING: i32 = 16; |
| 23 | 25 | const FONT: &str = "sans 14px"; |
| 24 | 26 | const BORDER: i32 = 8; |
| 27 | +const BACKDROP_COLOR: [f32; 4] = [0., 0., 0., 0.4]; | |
| 25 | 28 | |
| 26 | 29 | pub struct ExitConfirmDialog { |
| 27 | 30 | is_open: bool, |
| @@ -31,9 +34,14 @@ pub struct ExitConfirmDialog { | ||
| 31 | 34 | niri_render_elements! { |
| 32 | 35 | ExitConfirmDialogRenderElement => { |
| 33 | 36 | Texture = PrimaryGpuTextureRenderElement, |
| 37 | + SolidColor = SolidColorRenderElement, | |
| 34 | 38 | } |
| 35 | 39 | } |
| 36 | 40 | |
| 41 | +struct OutputData { | |
| 42 | + backdrop: SolidColorBuffer, | |
| 43 | +} | |
| 44 | + | |
| 37 | 45 | impl ExitConfirmDialog { |
| 38 | 46 | pub fn new() -> Self { |
| 39 | 47 | let buffer = match render(1.) { |
| @@ -82,7 +90,7 @@ impl ExitConfirmDialog { | ||
| 82 | 90 | &self, |
| 83 | 91 | renderer: &mut R, |
| 84 | 92 | output: &Output, |
| 85 | - ) -> ArrayVec<ExitConfirmDialogRenderElement, 1> { | |
| 93 | + ) -> ArrayVec<ExitConfirmDialogRenderElement, 2> { | |
| 86 | 94 | let mut rv = ArrayVec::new(); |
| 87 | 95 | |
| 88 | 96 | if !self.is_open { |
| @@ -126,6 +134,23 @@ impl ExitConfirmDialog { | ||
| 126 | 134 | PrimaryGpuTextureRenderElement(elem), |
| 127 | 135 | )); |
| 128 | 136 | |
| 137 | + // Backdrop. | |
| 138 | + let data = output.user_data().get_or_insert(|| { | |
| 139 | + Mutex::new(OutputData { | |
| 140 | + backdrop: SolidColorBuffer::new(output_size, BACKDROP_COLOR), | |
| 141 | + }) | |
| 142 | + }); | |
| 143 | + let mut data = data.lock().unwrap(); | |
| 144 | + data.backdrop.resize(output_size); | |
| 145 | + | |
| 146 | + let elem = SolidColorRenderElement::from_buffer( | |
| 147 | + &data.backdrop, | |
| 148 | + Point::new(0., 0.), | |
| 149 | + 1., | |
| 150 | + Kind::Unspecified, | |
| 151 | + ); | |
| 152 | + rv.push(ExitConfirmDialogRenderElement::SolidColor(elem)); | |
| 153 | + | |
| 129 | 154 | rv |
| 130 | 155 | } |
| 131 | 156 | } |