aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2025-08-21 08:57:16 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2025-08-21 09:07:16 +0300
commit0a8b4e036d951638817a3b5f9f99bd76ae0538fd (patch)
tree71cbba105afe0035a18c49cd81f13573a3090a85 /src/ui
parent70f9ac4af876d631d7b07310983e7491113a5469 (diff)
downloadniri-0a8b4e036d951638817a3b5f9f99bd76ae0538fd.tar.gz
niri-0a8b4e036d951638817a3b5f9f99bd76ae0538fd.tar.bz2
niri-0a8b4e036d951638817a3b5f9f99bd76ae0538fd.zip
Move fallibility inside ExitConfirmDialog
Makes it less annoying on the outside.
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/exit_confirm_dialog.rs41
1 files changed, 28 insertions, 13 deletions
diff --git a/src/ui/exit_confirm_dialog.rs b/src/ui/exit_confirm_dialog.rs
index 6458558f..11c9a9e2 100644
--- a/src/ui/exit_confirm_dialog.rs
+++ b/src/ui/exit_confirm_dialog.rs
@@ -27,23 +27,34 @@ pub struct ExitConfirmDialog {
}
impl ExitConfirmDialog {
- pub fn new() -> anyhow::Result<Self> {
- Ok(Self {
+ pub fn new() -> Self {
+ let buffer = match render(1.) {
+ Ok(x) => Some(x),
+ Err(err) => {
+ warn!("error creating the exit confirm dialog: {err:?}");
+ None
+ }
+ };
+
+ Self {
is_open: false,
- buffers: RefCell::new(HashMap::from([(
- NotNan::new(1.).unwrap(),
- Some(render(1.)?),
- )])),
- })
+ buffers: RefCell::new(HashMap::from([(NotNan::new(1.).unwrap(), buffer)])),
+ }
+ }
+
+ pub fn can_show(&self) -> bool {
+ let buffers = self.buffers.borrow();
+ let fallback = &buffers[&NotNan::new(1.).unwrap()];
+ fallback.is_some()
}
pub fn show(&mut self) -> bool {
- if !self.is_open {
- self.is_open = true;
- true
- } else {
- false
+ if !self.can_show() {
+ return false;
}
+
+ self.is_open = true;
+ true
}
pub fn hide(&mut self) -> bool {
@@ -72,7 +83,11 @@ impl ExitConfirmDialog {
let output_size = output_size(output);
let mut buffers = self.buffers.borrow_mut();
- let fallback = buffers[&NotNan::new(1.).unwrap()].clone().unwrap();
+ let Some(fallback) = buffers[&NotNan::new(1.).unwrap()].clone() else {
+ error!("exit confirm dialog opened without fallback buffer");
+ return None;
+ };
+
let buffer = buffers
.entry(NotNan::new(scale).unwrap())
.or_insert_with(|| render(scale).ok());