launcher: Save prompt on exit
This commit is contained in:
@@ -28,6 +28,7 @@ pub enum Event {
|
||||
KeyEvent(KeyEvent),
|
||||
PointerEvent(PointerEvent),
|
||||
TokenUpdate(String),
|
||||
FocusLost,
|
||||
}
|
||||
|
||||
pub struct Events {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
pub const XKB_KEY_BackSpace: u32 = 0xff08; /* Back space, back char */
|
||||
//pub const XKB_KEY_Tab: u32 = 0xff09;
|
||||
pub const XKB_KEY_Return: u32 = 0xff0d; /* Return, enter */
|
||||
//pub const XKB_KEY_Escape: u32 = 0xff1b;
|
||||
pub const XKB_KEY_Escape: u32 = 0xff1b;
|
||||
pub const XKB_KEY_Delete: u32 = 0xffff; /* Delete, rubout */
|
||||
pub const XKB_KEY_Home: u32 = 0xff50;
|
||||
pub const XKB_KEY_Left: u32 = 0xff51; /* Move left, left arrow */
|
||||
@@ -17,4 +17,5 @@ pub const XKB_KEY_a: u32 = 0x0061; /* U+0061 LATIN SMALL LETTER A */
|
||||
pub const XKB_KEY_e: u32 = 0x0065; /* U+0065 LATIN SMALL LETTER E */
|
||||
//pub const XKB_KEY_c: u32 = 0x0063; /* U+0063 LATIN SMALL LETTER C */
|
||||
pub const XKB_KEY_k: u32 = 0x006b; /* U+006B LATIN SMALL LETTER K */
|
||||
pub const XKB_KEY_r: u32 = 0x0072; /* U+0072 LATIN SMALL LETTER R */
|
||||
pub const XKB_KEY_u: u32 = 0x0075; /* U+0075 LATIN SMALL LETTER U */
|
||||
|
||||
+4
-2
@@ -2,7 +2,6 @@ use std::{
|
||||
cmp::max,
|
||||
default::Default,
|
||||
env,
|
||||
process::exit,
|
||||
rc::Rc,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
@@ -498,7 +497,10 @@ impl Dispatch<xdg_toplevel::XdgToplevel, ()> for State {
|
||||
if activated {
|
||||
state.activated = true;
|
||||
} else if state.activated && !activated {
|
||||
exit(0);
|
||||
let ev = Event::FocusLost;
|
||||
for widget in state.widgets.iter_mut() {
|
||||
widget.event(&ev);
|
||||
}
|
||||
}
|
||||
|
||||
if state.dimensions != (width, height) {
|
||||
|
||||
@@ -629,6 +629,19 @@ impl Interface {
|
||||
}
|
||||
}
|
||||
|
||||
fn exit(&mut self) {
|
||||
if self.inner.prompt.input.len() == 0 {
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
let home = env::var_os("HOME").unwrap().into_string().unwrap();
|
||||
if let Ok(mut f) = File::create(format!("{}/.cache/wldash/prompt", home)) {
|
||||
write!(f, "{}", self.inner.prompt.input).unwrap();
|
||||
f.sync_data().unwrap();
|
||||
}
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
fn keyboard_input(&mut self, event: &KeyEvent) {
|
||||
if event.state != WEnum::Value(wl_keyboard::KeyState::Pressed) {
|
||||
return;
|
||||
@@ -652,6 +665,12 @@ impl Interface {
|
||||
self.inner.selection = 0;
|
||||
widget.update(&self.inner);
|
||||
}
|
||||
keysyms::XKB_KEY_r if event.modifiers.ctrl => {
|
||||
let home = env::var_os("HOME").unwrap().into_string().unwrap();
|
||||
if let Ok(s) = read_to_string(format!("{}/.cache/wldash/prompt", home)) {
|
||||
self.inner.prompt.set(&s);
|
||||
}
|
||||
}
|
||||
keysyms::XKB_KEY_Home => self.inner.prompt.home(),
|
||||
keysyms::XKB_KEY_End => self.inner.prompt.end(),
|
||||
keysyms::XKB_KEY_BackSpace => {
|
||||
@@ -664,6 +683,7 @@ impl Interface {
|
||||
self.inner.selection = 0;
|
||||
widget.update(&self.inner);
|
||||
}
|
||||
keysyms::XKB_KEY_Escape => self.exit(),
|
||||
keysyms::XKB_KEY_Return => widget.trigger(&mut self.inner),
|
||||
keysyms::XKB_KEY_Left => self.inner.prompt.move_cursor(-1),
|
||||
keysyms::XKB_KEY_Right => self.inner.prompt.move_cursor(1),
|
||||
@@ -724,6 +744,7 @@ impl Widget for Interface {
|
||||
match event {
|
||||
Event::KeyEvent(e) => self.keyboard_input(e),
|
||||
Event::PointerEvent(e) => self.pointer_input(e),
|
||||
Event::FocusLost => self.exit(),
|
||||
Event::LauncherUpdate => {
|
||||
self.inner.dirty = true;
|
||||
self.launcher.update(&self.inner);
|
||||
|
||||
Reference in New Issue
Block a user