updated shortcut functions on wayland/kde to stop showing shortcuts setting window on every launch
This commit is contained in:
1 parent
abbca0e411
commit
485cbf4c18
2 files changed
+95
-39
No files matched your search
+53
-39
@@ -699,7 +699,7 @@ async fn run_portal(
|
||||
commands: &mut tokio::sync::mpsc::UnboundedReceiver<PortalCommand>,
|
||||
) -> Result<(), String> {
|
||||
use ashpd::desktop::Session;
|
||||
use ashpd::desktop::global_shortcuts::{GlobalShortcuts, NewShortcut};
|
||||
use ashpd::desktop::global_shortcuts::{GlobalShortcuts, ListShortcutsOptions, NewShortcut};
|
||||
|
||||
let connection = ashpd::zbus::Connection::session()
|
||||
.await
|
||||
@@ -752,11 +752,29 @@ async fn run_portal(
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if requested.is_empty() {
|
||||
for binding in bindings {
|
||||
shared.set_status(binding.action, Status::Disabled);
|
||||
}
|
||||
// KDE 6.3+ restores persisted shortcuts when the session is created.
|
||||
// Ask for them first so a normal restart does not call BindShortcuts,
|
||||
// which unconditionally opens the KDE shortcut configuration window.
|
||||
let listed = proxy
|
||||
.list_shortcuts(&session, ListShortcutsOptions::default())
|
||||
.await
|
||||
.ok()
|
||||
.and_then(|request| request.response().ok())
|
||||
.map(|response| response.shortcuts().to_vec())
|
||||
.unwrap_or_default();
|
||||
|
||||
let known = bindings.iter().any(|binding| {
|
||||
binding.trigger.is_some()
|
||||
&& listed
|
||||
.iter()
|
||||
.any(|shortcut| shortcut.id() == binding.action.id())
|
||||
});
|
||||
|
||||
let shortcuts = if requested.is_empty() || known {
|
||||
listed
|
||||
} else {
|
||||
// First launch (or a portal that does not restore actions on session
|
||||
// creation). This is the only call that may open a configuration UI.
|
||||
let request = proxy
|
||||
.bind_shortcuts(&session, &requested, None, Default::default())
|
||||
.await
|
||||
@@ -766,35 +784,15 @@ async fn run_portal(
|
||||
let response = request.response().map_err(|error| {
|
||||
format!("The desktop environment rejected global shortcuts: {error}")
|
||||
})?;
|
||||
let granted = response
|
||||
.shortcuts()
|
||||
.iter()
|
||||
.map(|shortcut| (shortcut.id(), shortcut))
|
||||
.collect::<HashMap<_, _>>();
|
||||
response.shortcuts().to_vec()
|
||||
};
|
||||
|
||||
for binding in bindings {
|
||||
if binding.trigger.is_none() {
|
||||
shared.set_status(binding.action, Status::Disabled);
|
||||
continue;
|
||||
}
|
||||
|
||||
match granted.get(binding.action.id()) {
|
||||
Some(shortcut) => {
|
||||
shared.set_status(binding.action, Status::Registered);
|
||||
shared.send(Event::ShortcutChanged {
|
||||
action: binding.action,
|
||||
trigger: Some(shortcut.trigger_description().to_owned()),
|
||||
});
|
||||
}
|
||||
None => shared.set_status(
|
||||
binding.action,
|
||||
Status::Unavailable(
|
||||
"The desktop environment did not grant this shortcut.".to_owned(),
|
||||
),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
apply_portal_shortcuts(
|
||||
shared,
|
||||
bindings,
|
||||
&shortcuts,
|
||||
"The shortcut is not configured in the desktop environment.",
|
||||
);
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
@@ -823,7 +821,22 @@ fn apply_portal_changes(
|
||||
bindings: &[Binding],
|
||||
shortcuts: &[ashpd::desktop::global_shortcuts::Shortcut],
|
||||
) {
|
||||
let changed = shortcuts
|
||||
apply_portal_shortcuts(
|
||||
shared,
|
||||
bindings,
|
||||
shortcuts,
|
||||
"The shortcut was removed in the desktop settings.",
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn apply_portal_shortcuts(
|
||||
shared: &Shared,
|
||||
bindings: &[Binding],
|
||||
shortcuts: &[ashpd::desktop::global_shortcuts::Shortcut],
|
||||
missing: &str,
|
||||
) {
|
||||
let known = shortcuts
|
||||
.iter()
|
||||
.map(|shortcut| (shortcut.id(), shortcut))
|
||||
.collect::<HashMap<_, _>>();
|
||||
@@ -834,7 +847,11 @@ fn apply_portal_changes(
|
||||
continue;
|
||||
}
|
||||
|
||||
match changed.get(binding.action.id()) {
|
||||
match known.get(binding.action.id()) {
|
||||
Some(shortcut) if shortcut.trigger_description().is_empty() => {
|
||||
// The action exists but the user removed its key binding.
|
||||
shared.set_status(binding.action, Status::Disabled);
|
||||
}
|
||||
Some(shortcut) => {
|
||||
shared.set_status(binding.action, Status::Registered);
|
||||
shared.send(Event::ShortcutChanged {
|
||||
@@ -842,10 +859,7 @@ fn apply_portal_changes(
|
||||
trigger: Some(shortcut.trigger_description().to_owned()),
|
||||
});
|
||||
}
|
||||
None => shared.set_status(
|
||||
binding.action,
|
||||
Status::Unavailable("The shortcut was removed in the desktop settings.".to_owned()),
|
||||
),
|
||||
None => shared.set_status(binding.action, Status::Unavailable(missing.to_owned())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user