forge
Explore
Log in

Don't you dare go Hollow

exit_confirm_dialog: Add backdrop

Browse files at this commit

9d3beb49315ae4cde3d8edfb979fccda52af3faeIvan MolodetskikhParent: 7aba44a
Makes it more obvious that the focus is taken by the dialog. Makes it easier to
tell if you're about to close nested vs. host compositor.
src/ui/exit_confirm_dialog.rsmodified+27 -2
@@ -1,5 +1,6 @@
1 use std::cell::RefCell;1 use std::cell::RefCell;
2 use std::collections::HashMap;2 use std::collections::HashMap;
3+use std::sync::Mutex;
3 4
4 use arrayvec::ArrayVec;5 use arrayvec::ArrayVec;
5 use ordered_float::NotNan;6 use ordered_float::NotNan;
@@ -8,12 +9,13 @@ use pangocairo::pango::{Alignment, FontDescription};
8 use smithay::backend::renderer::element::Kind;9 use smithay::backend::renderer::element::Kind;
9 use smithay::output::Output;10 use smithay::output::Output;
10 use smithay::reexports::gbm::Format as Fourcc;11 use smithay::reexports::gbm::Format as Fourcc;
11-use smithay::utils::Transform;12+use smithay::utils::{Point, Transform};
12 13
13 use crate::niri_render_elements;14 use crate::niri_render_elements;
14 use crate::render_helpers::memory::MemoryBuffer;15 use crate::render_helpers::memory::MemoryBuffer;
15 use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;16 use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;
16 use crate::render_helpers::renderer::NiriRenderer;17 use crate::render_helpers::renderer::NiriRenderer;
18+use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};
17 use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement};19 use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement};
18 use crate::utils::{output_size, to_physical_precise_round};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 const PADDING: i32 = 16;24 const PADDING: i32 = 16;
23 const FONT: &str = "sans 14px";25 const FONT: &str = "sans 14px";
24 const BORDER: i32 = 8;26 const BORDER: i32 = 8;
27+const BACKDROP_COLOR: [f32; 4] = [0., 0., 0., 0.4];
25 28
26 pub struct ExitConfirmDialog {29 pub struct ExitConfirmDialog {
27 is_open: bool,30 is_open: bool,
@@ -31,9 +34,14 @@ pub struct ExitConfirmDialog {
31 niri_render_elements! {34 niri_render_elements! {
32 ExitConfirmDialogRenderElement => {35 ExitConfirmDialogRenderElement => {
33 Texture = PrimaryGpuTextureRenderElement,36 Texture = PrimaryGpuTextureRenderElement,
37+ SolidColor = SolidColorRenderElement,
34 }38 }
35 }39 }
36 40
41+struct OutputData {
42+ backdrop: SolidColorBuffer,
43+}
44+
37 impl ExitConfirmDialog {45 impl ExitConfirmDialog {
38 pub fn new() -> Self {46 pub fn new() -> Self {
39 let buffer = match render(1.) {47 let buffer = match render(1.) {
@@ -82,7 +90,7 @@ impl ExitConfirmDialog {
82 &self,90 &self,
83 renderer: &mut R,91 renderer: &mut R,
84 output: &Output,92 output: &Output,
85- ) -> ArrayVec<ExitConfirmDialogRenderElement, 1> {93+ ) -> ArrayVec<ExitConfirmDialogRenderElement, 2> {
86 let mut rv = ArrayVec::new();94 let mut rv = ArrayVec::new();
87 95
88 if !self.is_open {96 if !self.is_open {
@@ -126,6 +134,23 @@ impl ExitConfirmDialog {
126 PrimaryGpuTextureRenderElement(elem),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 rv154 rv
130 }155 }
131 }156 }