From b0ffd3d9f936d7e6802fc9c552519870360ecd6f Mon Sep 17 00:00:00 2001 From: bbb651 Date: Mon, 2 Sep 2024 23:35:03 +0300 Subject: [PATCH] feat: Support `--reverse` for alt-tab Also fixes behavior of `alt[-shift]-tab` not triggering the first time when the launcher activates. This seems to have been done intentionally, but this does not match any existing implementation of window/tab switching I know (e.g. Gnome, KDE, Windows, MacOS, Firefox, Chromium, VSCode, Zed, etc.) and IMO is very bad UX because triggering it once quickly will do nothing windows are sorted by last window focus. --- src/app.rs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/app.rs b/src/app.rs index 08fe7eb..8f1a774 100644 --- a/src/app.rs +++ b/src/app.rs @@ -69,8 +69,11 @@ pub struct Args { #[derive(Debug, Serialize, Deserialize, Clone, clap::Subcommand)] pub enum LauncherCommands { - #[clap(about = "Toggle the launcher and switch to the alt-tab view")] - AltTab, + #[clap(about = "Toggle the launcher, switch to the alt-tab view and cycle the list")] + AltTab { + #[clap(long)] + reverse: bool, + }, } impl ToString for LauncherCommands { @@ -157,7 +160,7 @@ pub enum Message { Layer(LayerEvent), KeyboardNav(keyboard_nav::Message), ActivationToken(Option, String, String, GpuPreference), - AltTab, + AltTab { reverse: bool }, AltRelease, } @@ -509,11 +512,12 @@ impl cosmic::Application for CosmicLauncher { cosmic::app::message::app(Message::Hide) }); } - Message::AltTab => { - if self.alt_tab { - self.focus_next(); + Message::AltTab { reverse } => { + self.alt_tab = true; + if reverse { + self.focus_previous(); } else { - self.alt_tab = true; + self.focus_next(); } } Message::AltRelease => { @@ -547,26 +551,31 @@ impl cosmic::Application for CosmicLauncher { } } DbusActivationDetails::ActivateAction { action, .. } => { - if LauncherCommands::from_str(&action).is_err() { + let Ok(command) = LauncherCommands::from_str(&action) else { return Command::none(); - } + }; if let Some(tx) = &self.tx { let _res = tx.blocking_send(launcher::Request::Search(String::new())); } else { tracing::info!("NOT FOUND"); } + + let message = match command { + LauncherCommands::AltTab { reverse } => Message::AltTab { reverse }, + }; + if self.active_surface { if self.launcher_items.is_empty() { return cosmic::command::message(cosmic::app::message::app(Message::Hide)); } - return cosmic::command::message(cosmic::app::message::app(Message::AltTab)); + return cosmic::command::message(cosmic::app::message::app(message)); } self.input_value = action; self.active_surface = true; self.wait_for_result = true; - return cosmic::command::message(cosmic::app::message::app(Message::AltTab)); + return cosmic::command::message(cosmic::app::message::app(message)); } DbusActivationDetails::Open { .. } => {} }