Use hollow block cursor for non-focused terminals
This commit is contained in:
parent
75787a8766
commit
23a5851ca9
3 changed files with 123 additions and 29 deletions
|
|
@ -59,6 +59,8 @@ pub struct TerminalBox<'a, Message> {
|
|||
mouse_inside_boundary: Option<bool>,
|
||||
on_middle_click: Option<Box<dyn Fn() -> Message + 'a>>,
|
||||
on_open_hyperlink: Option<Box<dyn Fn(String) -> Message + 'a>>,
|
||||
on_window_focused: Option<Box<dyn Fn() -> Message + 'a>>,
|
||||
on_window_unfocused: Option<Box<dyn Fn() -> Message + 'a>>,
|
||||
key_binds: HashMap<KeyBind, Action>,
|
||||
}
|
||||
|
||||
|
|
@ -82,6 +84,8 @@ where
|
|||
on_middle_click: None,
|
||||
key_binds: key_binds(),
|
||||
on_open_hyperlink: None,
|
||||
on_window_focused: None,
|
||||
on_window_unfocused: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -145,6 +149,16 @@ where
|
|||
self.on_open_hyperlink = on_open_hyperlink;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn on_window_focused(mut self, on_window_focused: impl Fn() -> Message + 'a) -> Self {
|
||||
self.on_window_focused = Some(Box::new(on_window_focused));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn on_window_unfocused(mut self, on_window_unfocused: impl Fn() -> Message + 'a) -> Self {
|
||||
self.on_window_unfocused = Some(Box::new(on_window_unfocused));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn terminal_box<Message>(terminal: &Mutex<Terminal>) -> TerminalBox<'_, Message>
|
||||
|
|
@ -662,7 +676,30 @@ where
|
|||
};
|
||||
renderer.fill_quad(quad, color);
|
||||
}
|
||||
CursorShape::HollowBlock => {} // TODO not sure when this would even be activated
|
||||
CursorShape::Block if !state.is_focused => {
|
||||
let quad = Quad {
|
||||
bounds: Rectangle::new(top_left, Size::new(width, height)),
|
||||
border: Border {
|
||||
width: 1.0,
|
||||
color,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
renderer.fill_quad(quad, Color::TRANSPARENT);
|
||||
}
|
||||
CursorShape::HollowBlock => {
|
||||
let quad = Quad {
|
||||
bounds: Rectangle::new(top_left, Size::new(width, height)),
|
||||
border: Border {
|
||||
width: 1.0,
|
||||
color,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
renderer.fill_quad(quad, Color::TRANSPARENT);
|
||||
}
|
||||
CursorShape::Block | CursorShape::Hidden => {} // Block is handled seperately
|
||||
}
|
||||
}
|
||||
|
|
@ -691,6 +728,20 @@ where
|
|||
let is_mouse_mode = terminal.term.lock().mode().intersects(TermMode::MOUSE_MODE);
|
||||
let mut status = Status::Ignored;
|
||||
match event {
|
||||
Event::Window(event) => match event {
|
||||
cosmic::iced::window::Event::Focused => {
|
||||
if let Some(on_window_focused) = &self.on_window_focused {
|
||||
shell.publish(on_window_focused());
|
||||
}
|
||||
}
|
||||
cosmic::iced::window::Event::Unfocused => {
|
||||
state.is_focused = false;
|
||||
if let Some(on_window_unfocused) = &self.on_window_unfocused {
|
||||
shell.publish(on_window_unfocused());
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
Event::Keyboard(KeyEvent::KeyPressed {
|
||||
key: Key::Named(named),
|
||||
modified_key: Key::Named(modified_named),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue