forge
Explore
Log in

Don't you dare go Hollow

Move fallibility inside ExitConfirmDialog

Browse files at this commit

0a8b4e036d951638817a3b5f9f99bd76ae0538fdIvan MolodetskikhParent: 70f9ac4
Makes it less annoying on the outside.
src/input/mod.rsmodified+14 -25
@@ -116,12 +116,8 @@ impl State {
116 let hide_hotkey_overlay =116 let hide_hotkey_overlay =
117 self.niri.hotkey_overlay.is_open() && should_hide_hotkey_overlay(&event);117 self.niri.hotkey_overlay.is_open() && should_hide_hotkey_overlay(&event);
118 118
119- let hide_exit_confirm_dialog = self119+ let hide_exit_confirm_dialog =
120- .niri120+ self.niri.exit_confirm_dialog.is_open() && should_hide_exit_confirm_dialog(&event);
121- .exit_confirm_dialog
122- .as_ref()
123- .is_some_and(|d| d.is_open())
124- && should_hide_exit_confirm_dialog(&event);
125 121
126 use InputEvent::*;122 use InputEvent::*;
127 match event {123 match event {
@@ -159,10 +155,8 @@ impl State {
159 self.niri.queue_redraw_all();155 self.niri.queue_redraw_all();
160 }156 }
161 157
162- if let Some(dialog) = &mut self.niri.exit_confirm_dialog {158+ if hide_exit_confirm_dialog && self.niri.exit_confirm_dialog.hide() {
163- if hide_exit_confirm_dialog && dialog.hide() {159+ self.niri.queue_redraw_all();
164- self.niri.queue_redraw_all();
165- }
166 }160 }
167 }161 }
168 162
@@ -381,15 +375,14 @@ impl State {
381 let modified = keysym.modified_sym();375 let modified = keysym.modified_sym();
382 let raw = keysym.raw_latin_sym_or_raw_current_sym();376 let raw = keysym.raw_latin_sym_or_raw_current_sym();
383 377
384- if let Some(dialog) = &this.niri.exit_confirm_dialog {378+ if this.niri.exit_confirm_dialog.is_open() && pressed && raw == Some(Keysym::Return)
385- if dialog.is_open() && pressed && raw == Some(Keysym::Return) {379+ {
386- info!("quitting after confirming exit dialog");380+ info!("quitting after confirming exit dialog");
387- this.niri.stop_signal.stop();381+ this.niri.stop_signal.stop();
388 382
389- // Don't send this Enter press to any clients.383+ // Don't send this Enter press to any clients.
390- this.niri.suppressed_keys.insert(key_code);384+ this.niri.suppressed_keys.insert(key_code);
391- return FilterResult::Intercept(None);385+ return FilterResult::Intercept(None);
392- }
393 }386 }
394 387
395 if pressed388 if pressed
@@ -552,13 +545,9 @@ impl State {
552 545
553 match action {546 match action {
554 Action::Quit(skip_confirmation) => {547 Action::Quit(skip_confirmation) => {
555- if !skip_confirmation {548+ if !skip_confirmation && self.niri.exit_confirm_dialog.show() {
556- if let Some(dialog) = &mut self.niri.exit_confirm_dialog {549+ self.niri.queue_redraw_all();
557- if dialog.show() {550+ return;
558- self.niri.queue_redraw_all();
559- }
560- return;
561- }
562 }551 }
563 552
564 info!("quitting as requested");553 info!("quitting as requested");
src/niri.rsmodified+4 -12
@@ -377,7 +377,7 @@ pub struct Niri {
377 pub screenshot_ui: ScreenshotUi,377 pub screenshot_ui: ScreenshotUi,
378 pub config_error_notification: ConfigErrorNotification,378 pub config_error_notification: ConfigErrorNotification,
379 pub hotkey_overlay: HotkeyOverlay,379 pub hotkey_overlay: HotkeyOverlay,
380- pub exit_confirm_dialog: Option<ExitConfirmDialog>,380+ pub exit_confirm_dialog: ExitConfirmDialog,
381 381
382 pub pick_window: Option<async_channel::Sender<Option<MappedId>>>,382 pub pick_window: Option<async_channel::Sender<Option<MappedId>>>,
383 pub pick_color: Option<async_channel::Sender<Option<niri_ipc::PickedColor>>>,383 pub pick_color: Option<async_channel::Sender<Option<niri_ipc::PickedColor>>>,
@@ -2450,13 +2450,7 @@ impl Niri {
2450 hotkey_overlay.show();2450 hotkey_overlay.show();
2451 }2451 }
2452 2452
2453- let exit_confirm_dialog = match ExitConfirmDialog::new() {2453+ let exit_confirm_dialog = ExitConfirmDialog::new();
2454- Ok(x) => Some(x),
2455- Err(err) => {
2456- warn!("error creating the exit confirm dialog: {err:?}");
2457- None
2458- }
2459- };
2460 2454
2461 event_loop2455 event_loop
2462 .insert_source(2456 .insert_source(
@@ -4123,10 +4117,8 @@ impl Niri {
4123 }4117 }
4124 4118
4125 // Next, the exit confirm dialog.4119 // Next, the exit confirm dialog.
4126- if let Some(dialog) = &self.exit_confirm_dialog {4120+ if let Some(element) = self.exit_confirm_dialog.render(renderer, output) {
4127- if let Some(element) = dialog.render(renderer, output) {4121+ elements.push(element.into());
4128- elements.push(element.into());
4129- }
4130 }4122 }
4131 4123
4132 // Next, the config error notification too.4124 // Next, the config error notification too.
src/ui/exit_confirm_dialog.rsmodified+28 -13
@@ -27,23 +27,34 @@ pub struct ExitConfirmDialog {
27 }27 }
28 28
29 impl ExitConfirmDialog {29 impl ExitConfirmDialog {
30- pub fn new() -> anyhow::Result<Self> {30+ pub fn new() -> Self {
31- Ok(Self {31+ let buffer = match render(1.) {
32+ Ok(x) => Some(x),
33+ Err(err) => {
34+ warn!("error creating the exit confirm dialog: {err:?}");
35+ None
36+ }
37+ };
38+
39+ Self {
32 is_open: false,40 is_open: false,
33- buffers: RefCell::new(HashMap::from([(41+ buffers: RefCell::new(HashMap::from([(NotNan::new(1.).unwrap(), buffer)])),
34- NotNan::new(1.).unwrap(),42+ }
35- Some(render(1.)?),43+ }
36- )])),44+
37- })45+ pub fn can_show(&self) -> bool {
46+ let buffers = self.buffers.borrow();
47+ let fallback = &buffers[&NotNan::new(1.).unwrap()];
48+ fallback.is_some()
38 }49 }
39 50
40 pub fn show(&mut self) -> bool {51 pub fn show(&mut self) -> bool {
41- if !self.is_open {52+ if !self.can_show() {
42- self.is_open = true;53+ return false;
43- true
44- } else {
45- false
46 }54 }
55+
56+ self.is_open = true;
57+ true
47 }58 }
48 59
49 pub fn hide(&mut self) -> bool {60 pub fn hide(&mut self) -> bool {
@@ -72,7 +83,11 @@ impl ExitConfirmDialog {
72 let output_size = output_size(output);83 let output_size = output_size(output);
73 84
74 let mut buffers = self.buffers.borrow_mut();85 let mut buffers = self.buffers.borrow_mut();
75- let fallback = buffers[&NotNan::new(1.).unwrap()].clone().unwrap();86+ let Some(fallback) = buffers[&NotNan::new(1.).unwrap()].clone() else {
87+ error!("exit confirm dialog opened without fallback buffer");
88+ return None;
89+ };
90+
76 let buffer = buffers91 let buffer = buffers
77 .entry(NotNan::new(scale).unwrap())92 .entry(NotNan::new(scale).unwrap())
78 .or_insert_with(|| render(scale).ok());93 .or_insert_with(|| render(scale).ok());