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>,
|
commands: &mut tokio::sync::mpsc::UnboundedReceiver<PortalCommand>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
use ashpd::desktop::Session;
|
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()
|
let connection = ashpd::zbus::Connection::session()
|
||||||
.await
|
.await
|
||||||
@@ -752,11 +752,29 @@ async fn run_portal(
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
if requested.is_empty() {
|
// KDE 6.3+ restores persisted shortcuts when the session is created.
|
||||||
for binding in bindings {
|
// Ask for them first so a normal restart does not call BindShortcuts,
|
||||||
shared.set_status(binding.action, Status::Disabled);
|
// 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 {
|
} 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
|
let request = proxy
|
||||||
.bind_shortcuts(&session, &requested, None, Default::default())
|
.bind_shortcuts(&session, &requested, None, Default::default())
|
||||||
.await
|
.await
|
||||||
@@ -766,35 +784,15 @@ async fn run_portal(
|
|||||||
let response = request.response().map_err(|error| {
|
let response = request.response().map_err(|error| {
|
||||||
format!("The desktop environment rejected global shortcuts: {error}")
|
format!("The desktop environment rejected global shortcuts: {error}")
|
||||||
})?;
|
})?;
|
||||||
let granted = response
|
response.shortcuts().to_vec()
|
||||||
.shortcuts()
|
};
|
||||||
.iter()
|
|
||||||
.map(|shortcut| (shortcut.id(), shortcut))
|
|
||||||
.collect::<HashMap<_, _>>();
|
|
||||||
|
|
||||||
for binding in bindings {
|
apply_portal_shortcuts(
|
||||||
if binding.trigger.is_none() {
|
shared,
|
||||||
shared.set_status(binding.action, Status::Disabled);
|
bindings,
|
||||||
continue;
|
&shortcuts,
|
||||||
}
|
"The shortcut is not configured in the desktop environment.",
|
||||||
|
);
|
||||||
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(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
@@ -823,7 +821,22 @@ fn apply_portal_changes(
|
|||||||
bindings: &[Binding],
|
bindings: &[Binding],
|
||||||
shortcuts: &[ashpd::desktop::global_shortcuts::Shortcut],
|
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()
|
.iter()
|
||||||
.map(|shortcut| (shortcut.id(), shortcut))
|
.map(|shortcut| (shortcut.id(), shortcut))
|
||||||
.collect::<HashMap<_, _>>();
|
.collect::<HashMap<_, _>>();
|
||||||
@@ -834,7 +847,11 @@ fn apply_portal_changes(
|
|||||||
continue;
|
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) => {
|
Some(shortcut) => {
|
||||||
shared.set_status(binding.action, Status::Registered);
|
shared.set_status(binding.action, Status::Registered);
|
||||||
shared.send(Event::ShortcutChanged {
|
shared.send(Event::ShortcutChanged {
|
||||||
@@ -842,10 +859,7 @@ fn apply_portal_changes(
|
|||||||
trigger: Some(shortcut.trigger_description().to_owned()),
|
trigger: Some(shortcut.trigger_description().to_owned()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
None => shared.set_status(
|
None => shared.set_status(binding.action, Status::Unavailable(missing.to_owned())),
|
||||||
binding.action,
|
|
||||||
Status::Unavailable("The shortcut was removed in the desktop settings.".to_owned()),
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+42
@@ -1697,6 +1697,9 @@ struct Moorly {
|
|||||||
/// Wayland cannot hide or restore a toplevel, so the window is destroyed
|
/// Wayland cannot hide or restore a toplevel, so the window is destroyed
|
||||||
/// while hidden and recreated from this state on show.
|
/// while hidden and recreated from this state on show.
|
||||||
hidden_main_window: Option<WindowState>,
|
hidden_main_window: Option<WindowState>,
|
||||||
|
/// Set when the palette shortcut is used while the window is being
|
||||||
|
/// recreated, so focus can be requested after the new window exists.
|
||||||
|
pending_command_palette: bool,
|
||||||
tray_available: bool,
|
tray_available: bool,
|
||||||
close_to_tray: bool,
|
close_to_tray: bool,
|
||||||
close_to_tray_draft: bool,
|
close_to_tray_draft: bool,
|
||||||
@@ -4668,6 +4671,7 @@ impl Default for Moorly {
|
|||||||
focused_window: None,
|
focused_window: None,
|
||||||
main_window_hidden: false,
|
main_window_hidden: false,
|
||||||
hidden_main_window: None,
|
hidden_main_window: None,
|
||||||
|
pending_command_palette: false,
|
||||||
tray_available: false,
|
tray_available: false,
|
||||||
close_to_tray,
|
close_to_tray,
|
||||||
close_to_tray_draft: close_to_tray,
|
close_to_tray_draft: close_to_tray,
|
||||||
@@ -6421,7 +6425,16 @@ fn handle_tray_event(state: &mut Moorly, event: tray::Event) -> Task<Message> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn open_palette_from_hotkey(state: &mut Moorly) -> Task<Message> {
|
fn open_palette_from_hotkey(state: &mut Moorly) -> Task<Message> {
|
||||||
|
let reopening = state.hidden_main_window.is_some();
|
||||||
let show = show_main_window(state);
|
let show = show_main_window(state);
|
||||||
|
|
||||||
|
if reopening {
|
||||||
|
// The new window does not exist yet, so focusing the palette now
|
||||||
|
// would act on nothing. Open it once the window reports `Opened`.
|
||||||
|
state.pending_command_palette = true;
|
||||||
|
return show;
|
||||||
|
}
|
||||||
|
|
||||||
let Some(window) = main_window_id(state) else {
|
let Some(window) = main_window_id(state) else {
|
||||||
return show;
|
return show;
|
||||||
};
|
};
|
||||||
@@ -6523,6 +6536,11 @@ fn window_event(state: &mut Moorly, window: window::Id, event: window::Event) ->
|
|||||||
window_state.position = position;
|
window_state.position = position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if state.pending_command_palette && state.main_window == Some(window) {
|
||||||
|
state.pending_command_palette = false;
|
||||||
|
return update(state, Message::ToggleCommandPalette(window));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
window::Event::Moved(position) => {
|
window::Event::Moved(position) => {
|
||||||
if let Some(window_state) = state.windows.get_mut(&window) {
|
if let Some(window_state) = state.windows.get_mut(&window) {
|
||||||
@@ -8143,8 +8161,12 @@ fn shortcut_row(
|
|||||||
.on_press(Message::OpenShortcutCapture(action))
|
.on_press(Message::OpenShortcutCapture(action))
|
||||||
.style(theme::outlined_option),
|
.style(theme::outlined_option),
|
||||||
]
|
]
|
||||||
|
// Let the buttons drop to the next line in a narrow window instead of
|
||||||
|
// pushing the "..." button outside the pane.
|
||||||
.spacing(8)
|
.spacing(8)
|
||||||
.align_y(Alignment::Center)
|
.align_y(Alignment::Center)
|
||||||
|
.wrap()
|
||||||
|
.vertical_spacing(8)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11261,6 +11283,7 @@ mod tests {
|
|||||||
focused_window: Some(window),
|
focused_window: Some(window),
|
||||||
main_window_hidden: false,
|
main_window_hidden: false,
|
||||||
hidden_main_window: None,
|
hidden_main_window: None,
|
||||||
|
pending_command_palette: false,
|
||||||
tray_available: false,
|
tray_available: false,
|
||||||
close_to_tray: false,
|
close_to_tray: false,
|
||||||
close_to_tray_draft: false,
|
close_to_tray_draft: false,
|
||||||
@@ -14085,6 +14108,25 @@ start_path = "/tmp"
|
|||||||
std::fs::remove_dir_all(&root).unwrap();
|
std::fs::remove_dir_all(&root).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn palette_waits_for_the_reopened_window() {
|
||||||
|
let window = test_window();
|
||||||
|
let mut state = self::state();
|
||||||
|
state.pending_command_palette = true;
|
||||||
|
|
||||||
|
let _ = super::window_event(
|
||||||
|
&mut state,
|
||||||
|
window,
|
||||||
|
super::window::Event::Opened {
|
||||||
|
position: None,
|
||||||
|
size: iced::Size::new(800.0, 600.0),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(!state.pending_command_palette);
|
||||||
|
assert!(window_state(&state).command_palette_open);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn closing_the_window_only_hides_it_when_a_tray_is_available() {
|
fn closing_the_window_only_hides_it_when_a_tray_is_available() {
|
||||||
let window = test_window();
|
let window = test_window();
|
||||||
|
|||||||
Reference in new issue
Block a user