Show if caps lock is active, fixes #115

This commit is contained in:
Jeremy Soller 2025-05-15 14:18:08 -06:00
parent b16be3c5ae
commit b38bcd296a
No known key found for this signature in database
GPG key ID: 670FDFB5428E05CA
6 changed files with 719 additions and 433 deletions

View file

@ -27,6 +27,7 @@ pub struct ActiveLayout {
pub struct Common<M> {
pub active_layouts: Vec<ActiveLayout>,
pub active_surface_id_opt: Option<SurfaceId>,
pub caps_lock: bool,
pub comp_config_handler: Option<cosmic_config::Config>,
pub core: Core,
pub error_opt: Option<String>,
@ -49,6 +50,7 @@ pub struct Common<M> {
#[derive(Clone, Debug)]
pub enum Message {
CapsLock(bool),
Focus(SurfaceId),
Key(Modifiers, Key, Option<SmolStr>),
NetworkIcon(Option<&'static str>),
@ -92,6 +94,7 @@ impl<M: From<Message> + Send + 'static> Common<M> {
let app = Self {
active_layouts: Vec::new(),
active_surface_id_opt: None,
caps_lock: false,
comp_config_handler,
core,
error_opt: None,
@ -236,6 +239,9 @@ impl<M: From<Message> + Send + 'static> Common<M> {
pub fn update(&mut self, message: Message) -> Task<M> {
match message {
Message::CapsLock(caps_lock) => {
self.caps_lock = caps_lock;
}
Message::Focus(surface_id) => {
self.active_surface_id_opt = Some(surface_id);
if let Some(text_input_id) = self
@ -325,6 +331,9 @@ impl<M: From<Message> + Send + 'static> Common<M> {
event::Status::Ignored => Some(Message::Key(modifiers, key, text)),
event::Status::Captured => None,
},
iced::Event::Keyboard(KeyEvent::ModifiersChanged(modifiers)) => {
Some(Message::CapsLock(modifiers.contains(Modifiers::CAPS_LOCK)))
}
iced::Event::PlatformSpecific(iced::event::PlatformSpecific::Wayland(
wayland_event,
)) => match wayland_event {

View file

@ -644,6 +644,10 @@ impl App {
}
column = column.push(text_input);
if self.common.caps_lock {
column = column.push(widget::text(fl!("caps-lock")));
}
}
None => {
column = column.push(

View file

@ -430,6 +430,10 @@ impl App {
}
column = column.push(text_input);
if self.common.caps_lock {
column = column.push(widget::text(fl!("caps-lock")));
}
}
None => {
column = column.push(widget::text(prompt));