refactor: allow opting out of automatic keyboard navigation
This commit is contained in:
parent
268b47d000
commit
3e68e39366
2 changed files with 27 additions and 5 deletions
|
|
@ -46,6 +46,9 @@ pub struct Core {
|
|||
/// Whether the window is too small for the nav bar + main content.
|
||||
is_condensed: bool,
|
||||
|
||||
/// Enables built in keyboard navigation
|
||||
pub(super) keyboard_nav: bool,
|
||||
|
||||
/// Current status of the nav bar panel.
|
||||
nav_bar: NavBar,
|
||||
|
||||
|
|
@ -78,6 +81,7 @@ impl Default for Core {
|
|||
Self {
|
||||
debug: false,
|
||||
is_condensed: false,
|
||||
keyboard_nav: true,
|
||||
nav_bar: NavBar {
|
||||
active: true,
|
||||
toggled: true,
|
||||
|
|
@ -134,6 +138,17 @@ impl Core {
|
|||
self.scale_factor
|
||||
}
|
||||
|
||||
/// Enable or disable keyboard navigation
|
||||
pub fn set_keyboard_nav(&mut self, enabled: bool) {
|
||||
self.keyboard_nav = enabled;
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
/// Enable or disable keyboard navigation
|
||||
pub fn keyboard_nav(&self) -> bool {
|
||||
self.keyboard_nav
|
||||
}
|
||||
|
||||
/// Changes the scaling factor used by the application.
|
||||
pub(crate) fn set_scale_factor(&mut self, factor: f32) {
|
||||
self.scale_factor = factor;
|
||||
|
|
|
|||
|
|
@ -177,11 +177,8 @@ where
|
|||
None
|
||||
});
|
||||
|
||||
Subscription::batch(vec![
|
||||
let mut subscriptions = vec![
|
||||
self.app.subscription().map(super::Message::App),
|
||||
keyboard_nav::subscription()
|
||||
.map(Message::KeyboardNav)
|
||||
.map(super::Message::Cosmic),
|
||||
self.app
|
||||
.core()
|
||||
.watch_config::<cosmic_theme::Theme>(if self.app.core().system_theme_mode.is_dark {
|
||||
|
|
@ -213,7 +210,17 @@ where
|
|||
.single_instance
|
||||
.then(|| super::single_instance_subscription::<T>())
|
||||
.unwrap_or_else(Subscription::none),
|
||||
])
|
||||
];
|
||||
|
||||
if self.app.core().keyboard_nav {
|
||||
subscriptions.push(
|
||||
keyboard_nav::subscription()
|
||||
.map(Message::KeyboardNav)
|
||||
.map(super::Message::Cosmic),
|
||||
);
|
||||
}
|
||||
|
||||
Subscription::batch(subscriptions)
|
||||
}
|
||||
|
||||
#[cfg(not(any(feature = "multi-window", feature = "wayland")))]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue