Skip to content

Commit 43d2b64

Browse files
committed
fix: better handling of cancelled edit
1 parent 73a275a commit 43d2b64

File tree

4 files changed

+99
-37
lines changed

4 files changed

+99
-37
lines changed

Cargo.lock

Lines changed: 18 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ cosmic-client-toolkit = { git = "https://github.com/pop-os/cosmic-protocols//",
7474
# cosmic-config = { git = "https://github.com/pop-os/libcosmic//", rev = "8c4cb2e" }
7575
# cosmic-theme = { git = "https://github.com/pop-os/libcosmic//", rev = "8c4cb2e" }
7676
# iced_futures = { git = "https://github.com/pop-os/libcosmic//", rev = "8c4cb2e" }
77-
# libcosmic = { path = "../libcosmic" }
78-
# cosmic-config = { path = "../libcosmic/cosmic-config" }
79-
# cosmic-theme = { path = "../libcosmic/cosmic-theme" }
80-
# iced_futures = { path = "../libcosmic/iced/futures" }
77+
libcosmic = { path = "../libcosmic" }
78+
cosmic-config = { path = "../libcosmic/cosmic-config" }
79+
cosmic-theme = { path = "../libcosmic/cosmic-theme" }
80+
iced_futures = { path = "../libcosmic/iced/futures" }
8181

8282
# [patch.'https://github.com/pop-os/dbus-settings-bindings']
8383
# cosmic-dbus-networkmanager = { path = "../dbus-settings-bindings/networkmanager" }

cosmic-settings/src/pages/input/keyboard/shortcuts/common.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use cosmic::app::ContextDrawer;
55
use cosmic::iced::event::listen_with;
6+
use cosmic::iced::keyboard::key::Named;
67
use cosmic::iced::keyboard::{Key, Location, Modifiers};
78
use cosmic::iced::{self, Alignment, Length};
89
use cosmic::widget::{self, button, icon, settings, text};
@@ -32,7 +33,7 @@ pub enum ShortcutMessage {
3233
ProtocolUnavailable,
3334
ModifiersChanged(Modifiers),
3435
KeyReleased(u32, Key, Location),
35-
KeyPressed(u32, Key, Location),
36+
KeyPressed(u32, Key, Location, Modifiers),
3637
}
3738

3839
#[derive(Debug)]
@@ -421,6 +422,20 @@ impl Model {
421422
}
422423
}
423424
ShortcutMessage::EditBinding(id, enable) => {
425+
if !enable && self.editing == Some(id) {
426+
self.editing = None;
427+
if let Some(short_id) = self.shortcut_context {
428+
if let Some(model) = self.shortcut_models.get_mut(short_id) {
429+
if let Some(shortcut) = model.bindings.get_mut(id) {
430+
shortcut.pending = shortcut.binding.clone();
431+
}
432+
}
433+
}
434+
return Task::batch(vec![
435+
cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone()),
436+
iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard()
437+
]);
438+
}
424439
if let Some(short_id) = self.shortcut_context {
425440
if let Some(model) = self.shortcut_models.get_mut(short_id) {
426441
if let Some(shortcut) = model.bindings.get_mut(id) {
@@ -479,7 +494,7 @@ impl Model {
479494

480495
return Task::batch(tasks);
481496
}
482-
ShortcutMessage::SubmitBinding(id) => {}
497+
ShortcutMessage::SubmitBinding(_) => {}
483498
ShortcutMessage::ProtocolUnavailable => {
484499
tracing::error!("shortcut inhibit protocol is unavailable");
485500
}
@@ -514,6 +529,7 @@ impl Model {
514529
iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard()
515530
]);
516531
}
532+
shortcut.input = shortcut.pending.to_string();
517533
}
518534
}
519535
}
@@ -547,7 +563,22 @@ impl Model {
547563
}
548564
}
549565
}
550-
ShortcutMessage::KeyPressed(keycode, unmodified_keysym, location) => {
566+
ShortcutMessage::KeyPressed(keycode, unmodified_keysym, location, modifiers) => {
567+
if unmodified_keysym == Key::Named(Named::Escape) && modifiers.is_empty() {
568+
if let Some((short_id, id)) = self.shortcut_context.zip(self.editing) {
569+
if let Some(model) = self.shortcut_models.get_mut(short_id) {
570+
if let Some(binding) = model.bindings.get_mut(id) {
571+
binding.reset();
572+
self.editing = None;
573+
return Task::batch(vec![
574+
cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone()),
575+
iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard()
576+
]);
577+
}
578+
}
579+
}
580+
return Task::none();
581+
}
551582
if let Some((short_id, id)) = self.shortcut_context.zip(self.editing) {
552583
if let Some(model) = self.shortcut_models.get_mut(short_id) {
553584
if let Some(shortcut) = model.bindings.get_mut(id) {
@@ -577,6 +608,7 @@ impl Model {
577608
key,
578609
physical_key,
579610
location,
611+
modifiers,
580612
..
581613
}) => {
582614
use cosmic::iced::keyboard::{Key, key::Named};
@@ -588,7 +620,7 @@ impl Model {
588620
return None;
589621
}
590622
cosmic::iced_winit::conversion::physical_to_scancode(physical_key)
591-
.map(|code| ShortcutMessage::KeyPressed(code, key, location))
623+
.map(|code| ShortcutMessage::KeyPressed(code, key, location, modifiers))
592624
}
593625
iced::event::Event::Keyboard(iced::keyboard::Event::KeyReleased {
594626
key,

0 commit comments

Comments
 (0)