mirror of
https://github.com/YaLTeR/niri.git
synced 2025-10-06 00:23:14 +02:00
exit_confirm_dialog: Return ArrayVec and add render elements
This commit is contained in:
12
src/niri.rs
12
src/niri.rs
@@ -158,7 +158,7 @@ use crate::render_helpers::{
|
||||
render_to_texture, render_to_vec, shaders, RenderTarget, SplitElements,
|
||||
};
|
||||
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::screen_transition::{self, ScreenTransition};
|
||||
use crate::ui::screenshot_ui::{OutputScreenshot, ScreenshotUi, ScreenshotUiRenderElement};
|
||||
@@ -4131,9 +4131,12 @@ impl Niri {
|
||||
}
|
||||
|
||||
// Next, the exit confirm dialog.
|
||||
if let Some(element) = self.exit_confirm_dialog.render(renderer, output) {
|
||||
elements.push(element.into());
|
||||
}
|
||||
elements.extend(
|
||||
self.exit_confirm_dialog
|
||||
.render(renderer, output)
|
||||
.into_iter()
|
||||
.map(OutputRenderElements::from),
|
||||
);
|
||||
|
||||
// Next, the config error notification too.
|
||||
if let Some(element) = self.config_error_notification.render(renderer, output) {
|
||||
@@ -6288,6 +6291,7 @@ niri_render_elements! {
|
||||
SolidColorRenderElement
|
||||
>>>,
|
||||
ScreenshotUi = ScreenshotUiRenderElement,
|
||||
ExitConfirmDialog = ExitConfirmDialogRenderElement,
|
||||
Texture = PrimaryGpuTextureRenderElement,
|
||||
// Used for the CPU-rendered panels.
|
||||
RelocatedMemoryBuffer = RelocateRenderElement<MemoryRenderBufferRenderElement<R>>,
|
||||
|
@@ -1,6 +1,7 @@
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
use ordered_float::NotNan;
|
||||
use pangocairo::cairo::{self, ImageSurface};
|
||||
use pangocairo::pango::{Alignment, FontDescription};
|
||||
@@ -9,6 +10,7 @@ use smithay::output::Output;
|
||||
use smithay::reexports::gbm::Format as Fourcc;
|
||||
use smithay::utils::Transform;
|
||||
|
||||
use crate::niri_render_elements;
|
||||
use crate::render_helpers::memory::MemoryBuffer;
|
||||
use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;
|
||||
use crate::render_helpers::renderer::NiriRenderer;
|
||||
@@ -26,6 +28,12 @@ pub struct ExitConfirmDialog {
|
||||
buffers: RefCell<HashMap<NotNan<f64>, Option<MemoryBuffer>>>,
|
||||
}
|
||||
|
||||
niri_render_elements! {
|
||||
ExitConfirmDialogRenderElement => {
|
||||
Texture = PrimaryGpuTextureRenderElement,
|
||||
}
|
||||
}
|
||||
|
||||
impl ExitConfirmDialog {
|
||||
pub fn new() -> Self {
|
||||
let buffer = match render(1.) {
|
||||
@@ -74,9 +82,11 @@ impl ExitConfirmDialog {
|
||||
&self,
|
||||
renderer: &mut R,
|
||||
output: &Output,
|
||||
) -> Option<PrimaryGpuTextureRenderElement> {
|
||||
) -> ArrayVec<ExitConfirmDialogRenderElement, 1> {
|
||||
let mut rv = ArrayVec::new();
|
||||
|
||||
if !self.is_open {
|
||||
return None;
|
||||
return rv;
|
||||
}
|
||||
|
||||
let scale = output.current_scale().fractional_scale();
|
||||
@@ -85,7 +95,7 @@ impl ExitConfirmDialog {
|
||||
let mut buffers = self.buffers.borrow_mut();
|
||||
let Some(fallback) = buffers[&NotNan::new(1.).unwrap()].clone() else {
|
||||
error!("exit confirm dialog opened without fallback buffer");
|
||||
return None;
|
||||
return rv;
|
||||
};
|
||||
|
||||
let buffer = buffers
|
||||
@@ -94,7 +104,10 @@ impl ExitConfirmDialog {
|
||||
let buffer = buffer.as_ref().unwrap_or(&fallback);
|
||||
|
||||
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 mut location = location.to_physical_precise_round(scale).to_logical(scale);
|
||||
@@ -109,7 +122,11 @@ impl ExitConfirmDialog {
|
||||
None,
|
||||
Kind::Unspecified,
|
||||
);
|
||||
Some(PrimaryGpuTextureRenderElement(elem))
|
||||
rv.push(ExitConfirmDialogRenderElement::Texture(
|
||||
PrimaryGpuTextureRenderElement(elem),
|
||||
));
|
||||
|
||||
rv
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user