refactor: allow opting out of automatic keyboard navigation

This commit is contained in:
Ashley Wulber 2024-03-01 13:53:15 -05:00 committed by Ashley Wulber
parent 268b47d000
commit 3e68e39366
2 changed files with 27 additions and 5 deletions

View file

@ -46,6 +46,9 @@ pub struct Core {
/// Whether the window is too small for the nav bar + main content. /// Whether the window is too small for the nav bar + main content.
is_condensed: bool, is_condensed: bool,
/// Enables built in keyboard navigation
pub(super) keyboard_nav: bool,
/// Current status of the nav bar panel. /// Current status of the nav bar panel.
nav_bar: NavBar, nav_bar: NavBar,
@ -78,6 +81,7 @@ impl Default for Core {
Self { Self {
debug: false, debug: false,
is_condensed: false, is_condensed: false,
keyboard_nav: true,
nav_bar: NavBar { nav_bar: NavBar {
active: true, active: true,
toggled: true, toggled: true,
@ -134,6 +138,17 @@ impl Core {
self.scale_factor 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. /// Changes the scaling factor used by the application.
pub(crate) fn set_scale_factor(&mut self, factor: f32) { pub(crate) fn set_scale_factor(&mut self, factor: f32) {
self.scale_factor = factor; self.scale_factor = factor;

View file

@ -177,11 +177,8 @@ where
None None
}); });
Subscription::batch(vec![ let mut subscriptions = vec![
self.app.subscription().map(super::Message::App), self.app.subscription().map(super::Message::App),
keyboard_nav::subscription()
.map(Message::KeyboardNav)
.map(super::Message::Cosmic),
self.app self.app
.core() .core()
.watch_config::<cosmic_theme::Theme>(if self.app.core().system_theme_mode.is_dark { .watch_config::<cosmic_theme::Theme>(if self.app.core().system_theme_mode.is_dark {
@ -213,7 +210,17 @@ where
.single_instance .single_instance
.then(|| super::single_instance_subscription::<T>()) .then(|| super::single_instance_subscription::<T>())
.unwrap_or_else(Subscription::none), .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")))] #[cfg(not(any(feature = "multi-window", feature = "wayland")))]