Skip to content
Open
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
87 changes: 85 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ pub enum LauncherTasks {
Input { input: Option<String> },
#[clap(about = "Close the launcher if open")]
Close,
#[clap(about = "Switch to the next window of the current application")]
AltBacktick,
#[clap(about = "Switch to the previous window of the current application")]
ShiftAltBacktick,
}

impl Display for LauncherTasks {
Expand Down Expand Up @@ -151,6 +155,7 @@ pub struct CosmicLauncher {
focused: usize,
last_hide: Instant,
alt_tab: bool,
alt_backtick: Option<String>,
window_id: window::Id,
queue: VecDeque<Message>,
result_ids: Vec<Id>,
Expand Down Expand Up @@ -180,6 +185,8 @@ pub enum Message {
ActivationToken(Option<String>, String, String, GpuPreference, bool),
AltTab,
ShiftAltTab,
AltBacktick,
ShiftAltBacktick,
Opened(Size, window::Id),
AltRelease,
Overlap(OverlapNotifyEvent),
Expand Down Expand Up @@ -221,6 +228,7 @@ impl CosmicLauncher {
self.input_value.clear();
self.focused = 0;
self.alt_tab = false;
self.alt_backtick = None;
self.queue.clear();
self.hand_over.clear();

Expand Down Expand Up @@ -330,6 +338,7 @@ impl cosmic::Application for CosmicLauncher {
focused: 0,
last_hide: Instant::now(),
alt_tab: false,
alt_backtick: None,
window_id: SurfaceId::unique(),
queue: VecDeque::new(),
result_ids: (0..10)
Expand Down Expand Up @@ -527,6 +536,35 @@ impl cosmic::Application for CosmicLauncher {
let b = i32::from(b.window.is_none());
a.cmp(&b)
});

// Filter for Alt-Backtick mode: show only windows of the current application
if let Some(ref app_name) = self.alt_backtick {
if app_name.is_empty() {
// First invocation: determine current app from first window
if let Some(first_window) =
list.iter().find(|item| item.window.is_some())
{
let app_name_to_filter = first_window.name.clone();
self.alt_backtick = Some(app_name_to_filter.clone());
list.retain(|item| {
item.window.is_some() && item.name == app_name_to_filter
});
} else {
return self.hide(); // No windows found
}
} else {
// Already have app name, filter by it
let app_name_clone = app_name.clone();
list.retain(|item| {
item.window.is_some() && item.name == app_name_clone
});
}

if list.is_empty() {
return self.hide();
}
}

self.launcher_items.splice(.., list);
if self.result_ids.len() < self.launcher_items.len() {
self.result_ids.extend(
Expand Down Expand Up @@ -709,8 +747,34 @@ impl cosmic::Application for CosmicLauncher {
},
);
}
Message::AltBacktick => {
self.focus_next();
return operation::snap_to(
SCROLLABLE.clone(),
RelativeOffset {
x: None,
y: Some(
(self.focused as f32 / (self.launcher_items.len() as f32 - 1.).max(1.))
.max(0.0),
),
},
);
}
Message::ShiftAltBacktick => {
self.focus_previous();
return operation::snap_to(
SCROLLABLE.clone(),
RelativeOffset {
x: None,
y: Some(
(self.focused as f32 / (self.launcher_items.len() as f32 - 1.).max(1.))
.max(0.0),
),
},
);
}
Message::AltRelease => {
if self.alt_tab {
if self.alt_tab || self.alt_backtick.is_some() {
return self.update(Message::Activate(None));
}
}
Expand Down Expand Up @@ -779,6 +843,24 @@ impl cosmic::Application for CosmicLauncher {
LauncherTasks::Close => {
return self.update(Message::Hide);
}
LauncherTasks::AltBacktick => {
if self.alt_backtick.is_some() {
return self.update(Message::AltBacktick);
}

self.alt_backtick = Some(String::new());
self.request(launcher::Request::Search(String::new()));
self.queue.push_back(Message::AltBacktick);
}
LauncherTasks::ShiftAltBacktick => {
if self.alt_backtick.is_some() {
return self.update(Message::ShiftAltBacktick);
}

self.alt_backtick = Some(String::new());
self.request(launcher::Request::Search(String::new()));
self.queue.push_back(Message::ShiftAltBacktick);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
self.queue.push_back(Message::ShiftAltBacktick);
self.queue.push_back(Message::ShiftAltBacktick);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

should be just this, right?

}
}
}
Details::Open { .. } => {}
Expand Down Expand Up @@ -846,6 +928,7 @@ impl cosmic::Application for CosmicLauncher {

let mut button_content = Vec::new();
if !self.alt_tab
&& self.alt_backtick.is_none()
&& let Some(source) = item.category_icon.as_ref()
{
let icon_handle = match source {
Expand Down Expand Up @@ -980,7 +1063,7 @@ impl cosmic::Application for CosmicLauncher {
})
.collect();

let mut content = if self.alt_tab {
let mut content = if self.alt_tab || self.alt_backtick.is_some() {
Column::new()
.max_width(600)
.spacing(16)
Expand Down
Loading