diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index fcd0281..08dd833 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ use std::sync::Arc; use chrono::Local; use iced::alignment::Horizontal::Right; use iced::futures::{SinkExt, Stream, StreamExt}; +use iced::keyboard::{on_key_press, on_key_release, Key, Modifiers}; use iced::theme::palette::{ Background, Danger, Extended, Pair, Primary, Secondary, Success, Warning, }; @@ -301,6 +302,7 @@ async fn main() -> iced::Result { } }; iced::application("Macaw", Macaw::update, Macaw::view) + .subscription(subscription) .theme(Macaw::theme) .run_with(|| { ( @@ -329,8 +331,36 @@ async fn main() -> iced::Result { } } +fn subscription(state: &Macaw) -> Subscription<Message> { + Subscription::batch([press_subscription(state), release_subscription(state)]) +} + +fn press_subscription(_state: &Macaw) -> Subscription<Message> { + on_key_press(handle_key_press) +} + +fn handle_key_press(key: Key, r#mod: Modifiers) -> Option<Message> { + match key { + Key::Named(iced::keyboard::key::Named::Shift) => Some(Message::ShiftPressed), + _ => None, + } +} + +fn release_subscription(_state: &Macaw) -> Subscription<Message> { + on_key_release(handle_key_release) +} + +fn handle_key_release(key: Key, r#mod: Modifiers) -> Option<Message> { + match key { + Key::Named(iced::keyboard::key::Named::Shift) => Some(Message::ShiftReleased), + _ => None, + } +} + #[derive(Debug, Clone)] pub enum Message { + ShiftPressed, + ShiftReleased, LoginModal(login_modal::Message), ClientCreated(Client), Luz(UpdateMessage), @@ -722,6 +752,20 @@ impl Macaw { Task::none() } } + Message::ShiftPressed => { + info!("shift pressed"); + if let Some(open_chat) = &mut self.open_chat { + open_chat.shift_pressed = true; + } + Task::none() + } + Message::ShiftReleased => { + info!("shift released"); + if let Some(open_chat) = &mut self.open_chat { + open_chat.shift_pressed = false; + } + Task::none() + } } } |