Skip to content

Commit

Permalink
fix: listen keys when capter is focused
Browse files Browse the repository at this point in the history
  • Loading branch information
decipher3114 committed Sep 26, 2024
1 parent 2ff7183 commit e653608
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use iced::{
advanced::graphics::image::image_rs::ImageFormat,
application::DefaultStyle,
daemon::{daemon, Appearance},
keyboard::{key, on_key_press},
keyboard::{key, on_key_press, Modifiers},
widget::horizontal_space,
window::{
self, change_mode, close, close_events, gain_focus, icon, settings::PlatformSpecific, Id, Mode
Expand Down Expand Up @@ -201,10 +201,21 @@ impl App {
pub fn subscription(&self) -> Subscription<AppEvent> {
let window_events = close_events().map(AppEvent::WindowClosed);

let app_key_listener = on_key_press(|key, _| match key {
key::Key::Named(key::Named::Escape | key::Named::Enter) => Some(AppEvent::CloseWindow),
_ => None,
});
let app_key_listener = on_key_press(
|key, modifiers|
match (key, modifiers) {
(key::Key::Named(key::Named::Escape | key::Named::Enter), _) => Some(AppEvent::CloseWindow),
(key::Key::Character(char), m) if m.contains(Modifiers::SHIFT) && m.contains(Modifiers::ALT) => {
match char.as_str() {
"s" => Some(AppEvent::OpenCropWindow),
"f" => Some(AppEvent::CaptureFullscreen),
_ => None
}
},
_ => None,
}
);

let global_key_listener = Subscription::run(global_key_listener);

let tray_icon_listener = Subscription::run(tray_icon_listener);
Expand Down

0 comments on commit e653608

Please sign in to comment.