Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support --reverse for alt-tab #183

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -157,7 +160,7 @@ pub enum Message {
Layer(LayerEvent),
KeyboardNav(keyboard_nav::Message),
ActivationToken(Option<String>, String, String, GpuPreference),
AltTab,
AltTab { reverse: bool },
AltRelease,
}

Expand Down Expand Up @@ -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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on my comment in the conversations section, I think we should switch this back to not cycle when opened for now.
Once we have the applications ordered by most recently focused, we should make the change to cycle on the first use of Alt-Tab.

if reverse {
self.focus_previous();
} else {
self.alt_tab = true;
self.focus_next();
}
}
Message::AltRelease => {
Expand Down Expand Up @@ -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 { .. } => {}
}
Expand Down