exit_confirm_dialog: Return ArrayVec and add render elements

This commit is contained in:
Ivan Molodetskikh
2025-08-22 07:58:37 +03:00
parent d662811bf6
commit 7aba44a019
2 changed files with 30 additions and 9 deletions
+8 -4
View File
@@ -158,7 +158,7 @@ use crate::render_helpers::{
render_to_texture, render_to_vec, shaders, RenderTarget, SplitElements, render_to_texture, render_to_vec, shaders, RenderTarget, SplitElements,
}; };
use crate::ui::config_error_notification::ConfigErrorNotification; use crate::ui::config_error_notification::ConfigErrorNotification;
use crate::ui::exit_confirm_dialog::ExitConfirmDialog; use crate::ui::exit_confirm_dialog::{ExitConfirmDialog, ExitConfirmDialogRenderElement};
use crate::ui::hotkey_overlay::HotkeyOverlay; use crate::ui::hotkey_overlay::HotkeyOverlay;
use crate::ui::screen_transition::{self, ScreenTransition}; use crate::ui::screen_transition::{self, ScreenTransition};
use crate::ui::screenshot_ui::{OutputScreenshot, ScreenshotUi, ScreenshotUiRenderElement}; use crate::ui::screenshot_ui::{OutputScreenshot, ScreenshotUi, ScreenshotUiRenderElement};
@@ -4131,9 +4131,12 @@ impl Niri {
} }
// Next, the exit confirm dialog. // Next, the exit confirm dialog.
if let Some(element) = self.exit_confirm_dialog.render(renderer, output) { elements.extend(
elements.push(element.into()); self.exit_confirm_dialog
} .render(renderer, output)
.into_iter()
.map(OutputRenderElements::from),
);
// Next, the config error notification too. // Next, the config error notification too.
if let Some(element) = self.config_error_notification.render(renderer, output) { if let Some(element) = self.config_error_notification.render(renderer, output) {
@@ -6288,6 +6291,7 @@ niri_render_elements! {
SolidColorRenderElement SolidColorRenderElement
>>>, >>>,
ScreenshotUi = ScreenshotUiRenderElement, ScreenshotUi = ScreenshotUiRenderElement,
ExitConfirmDialog = ExitConfirmDialogRenderElement,
Texture = PrimaryGpuTextureRenderElement, Texture = PrimaryGpuTextureRenderElement,
// Used for the CPU-rendered panels. // Used for the CPU-rendered panels.
RelocatedMemoryBuffer = RelocateRenderElement<MemoryRenderBufferRenderElement<R>>, RelocatedMemoryBuffer = RelocateRenderElement<MemoryRenderBufferRenderElement<R>>,
+22 -5
View File
@@ -1,6 +1,7 @@
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::HashMap; use std::collections::HashMap;
use arrayvec::ArrayVec;
use ordered_float::NotNan; use ordered_float::NotNan;
use pangocairo::cairo::{self, ImageSurface}; use pangocairo::cairo::{self, ImageSurface};
use pangocairo::pango::{Alignment, FontDescription}; use pangocairo::pango::{Alignment, FontDescription};
@@ -9,6 +10,7 @@ use smithay::output::Output;
use smithay::reexports::gbm::Format as Fourcc; use smithay::reexports::gbm::Format as Fourcc;
use smithay::utils::Transform; use smithay::utils::Transform;
use crate::niri_render_elements;
use crate::render_helpers::memory::MemoryBuffer; use crate::render_helpers::memory::MemoryBuffer;
use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement; use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;
use crate::render_helpers::renderer::NiriRenderer; use crate::render_helpers::renderer::NiriRenderer;
@@ -26,6 +28,12 @@ pub struct ExitConfirmDialog {
buffers: RefCell<HashMap<NotNan<f64>, Option<MemoryBuffer>>>, buffers: RefCell<HashMap<NotNan<f64>, Option<MemoryBuffer>>>,
} }
niri_render_elements! {
ExitConfirmDialogRenderElement => {
Texture = PrimaryGpuTextureRenderElement,
}
}
impl ExitConfirmDialog { impl ExitConfirmDialog {
pub fn new() -> Self { pub fn new() -> Self {
let buffer = match render(1.) { let buffer = match render(1.) {
@@ -74,9 +82,11 @@ impl ExitConfirmDialog {
&self, &self,
renderer: &mut R, renderer: &mut R,
output: &Output, output: &Output,
) -> Option<PrimaryGpuTextureRenderElement> { ) -> ArrayVec<ExitConfirmDialogRenderElement, 1> {
let mut rv = ArrayVec::new();
if !self.is_open { if !self.is_open {
return None; return rv;
} }
let scale = output.current_scale().fractional_scale(); let scale = output.current_scale().fractional_scale();
@@ -85,7 +95,7 @@ impl ExitConfirmDialog {
let mut buffers = self.buffers.borrow_mut(); let mut buffers = self.buffers.borrow_mut();
let Some(fallback) = buffers[&NotNan::new(1.).unwrap()].clone() else { let Some(fallback) = buffers[&NotNan::new(1.).unwrap()].clone() else {
error!("exit confirm dialog opened without fallback buffer"); error!("exit confirm dialog opened without fallback buffer");
return None; return rv;
}; };
let buffer = buffers let buffer = buffers
@@ -94,7 +104,10 @@ impl ExitConfirmDialog {
let buffer = buffer.as_ref().unwrap_or(&fallback); let buffer = buffer.as_ref().unwrap_or(&fallback);
let size = buffer.logical_size(); let size = buffer.logical_size();
let buffer = TextureBuffer::from_memory_buffer(renderer.as_gles_renderer(), buffer).ok()?; let Ok(buffer) = TextureBuffer::from_memory_buffer(renderer.as_gles_renderer(), buffer)
else {
return rv;
};
let location = (output_size.to_f64().to_point() - size.to_point()).downscale(2.); let location = (output_size.to_f64().to_point() - size.to_point()).downscale(2.);
let mut location = location.to_physical_precise_round(scale).to_logical(scale); let mut location = location.to_physical_precise_round(scale).to_logical(scale);
@@ -109,7 +122,11 @@ impl ExitConfirmDialog {
None, None,
Kind::Unspecified, Kind::Unspecified,
); );
Some(PrimaryGpuTextureRenderElement(elem)) rv.push(ExitConfirmDialogRenderElement::Texture(
PrimaryGpuTextureRenderElement(elem),
));
rv
} }
} }