fix(client): stop focus scopes from swallowing the first click on buttons
Every button, row and theme card stacked a FocusScope above its TouchArea. In Slint 1.18 a FocusScope has focus-on-click enabled by default and accepts the pointer press while it does not yet hold focus, so the press never reached the TouchArea below. The first click only moved focus, the second click (focus already there) activated the control. This is the "works only from the second click" defect, also seen in settings. All such FocusScopes now set focus-on-click: false (the TouchArea focuses them explicitly). The message row hover scope and the push-to-talk area had the same stacking and are fixed too. The headless ui_smoke test now sends real pointer move/press/release events and asserts that the first click on the settings buttons activates them; it failed before the fix.
This commit is contained in:
parent
3d43c98c9e
commit
71ae933d7d
8 changed files with 46 additions and 4 deletions
|
|
@ -24,8 +24,8 @@ component MessageRow inherits Rectangle {
|
|||
preferred-height: row-content.preferred-height;
|
||||
vertical-stretch: 0;
|
||||
background: row-touch.has-hover || row-focus.has-focus ? Theme.bg-hover : transparent;
|
||||
row-touch := TouchArea { }
|
||||
row-focus := FocusScope { }
|
||||
row-touch := TouchArea { clicked => { row-focus.focus(); } }
|
||||
row-focus := FocusScope { focus-on-click: false; }
|
||||
row-content := HorizontalLayout {
|
||||
padding-left: 22px; padding-right: 22px;
|
||||
padding-top: root.message.show_author ? 9px : 2px; padding-bottom: root.message.show_author ? 9px : 2px; spacing: 13px;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ export component DeviceSelect inherits Rectangle {
|
|||
}
|
||||
TouchArea { clicked => { keyboard.focus(); popup.show(); } }
|
||||
keyboard := FocusScope {
|
||||
focus-on-click: false;
|
||||
key-pressed(event) => {
|
||||
if event.text == " " || event.text == "\n" { popup.show(); return accept; }
|
||||
if event.text == Key.DownArrow || event.text == Key.UpArrow {
|
||||
|
|
@ -66,6 +67,7 @@ export component AudioSlider inherits Rectangle {
|
|||
moved => { if self.pressed { root.update-value(root.minimum + Math.clamp((self.mouse-x - 8px) / (root.width - 16px), 0, 1) * (root.maximum - root.minimum)); } }
|
||||
}
|
||||
keyboard := FocusScope {
|
||||
focus-on-click: false;
|
||||
key-pressed(event) => {
|
||||
if event.text == Key.LeftArrow || event.text == Key.RightArrow { root.update-value(root.value + (event.text == Key.RightArrow ? 1 : -1)); return accept; }
|
||||
return reject;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ component SettingsNav inherits Rectangle {
|
|||
}
|
||||
}
|
||||
touch := TouchArea { clicked => { keyboard.focus(); root.clicked(); } }
|
||||
keyboard := FocusScope { key-pressed(event) => { if event.text == " " || event.text == "\n" { root.clicked(); return accept; } return reject; } }
|
||||
keyboard := FocusScope { focus-on-click: false; key-pressed(event) => { if event.text == " " || event.text == "\n" { root.clicked(); return accept; } return reject; } }
|
||||
}
|
||||
|
||||
export component SettingsWindow inherits Rectangle {
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ component ThemeChoice inherits Rectangle {
|
|||
}
|
||||
}
|
||||
pointer := TouchArea { clicked => { keyboard.focus(); root.clicked(); } }
|
||||
keyboard := FocusScope { key-pressed(event) => { if event.text == " " || event.text == "\n" { root.clicked(); return accept; } return reject; } }
|
||||
keyboard := FocusScope { focus-on-click: false; key-pressed(event) => { if event.text == " " || event.text == "\n" { root.clicked(); return accept; } return reject; } }
|
||||
}
|
||||
|
||||
export component AppearanceSettings inherits Rectangle {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ component NavRow inherits Rectangle {
|
|||
}
|
||||
touch := TouchArea { clicked => { keyboard.focus(); root.clicked(); } }
|
||||
keyboard := FocusScope {
|
||||
focus-on-click: false;
|
||||
key-pressed(event) => {
|
||||
if event.text == " " || event.text == "\n" { root.clicked(); return accept; }
|
||||
return reject;
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ export component ActionButton inherits Rectangle {
|
|||
}
|
||||
touch := TouchArea { clicked => { keyboard.focus(); root.clicked(); } }
|
||||
keyboard := FocusScope {
|
||||
focus-on-click: false;
|
||||
key-pressed(event) => {
|
||||
if event.text == " " || event.text == "\n" { root.clicked(); return accept; }
|
||||
return reject;
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ export component VoicePanel inherits Rectangle {
|
|||
changed pressed => { root.ptt-held(self.pressed); }
|
||||
}
|
||||
ptt-focus := FocusScope {
|
||||
focus-on-click: false;
|
||||
key-pressed(event) => { if event.text == " " { root.ptt-held(true); return accept; } return reject; }
|
||||
key-released(event) => { if event.text == " " { root.ptt-held(false); return accept; } return reject; }
|
||||
changed has-focus => { if !self.has-focus { root.ptt-held(false); } }
|
||||
|
|
|
|||
|
|
@ -39,6 +39,24 @@ fn render(window: &MainWindow, surface: &MinimalSoftwareWindow, name: &str) {
|
|||
}
|
||||
}
|
||||
|
||||
/// Moves to `(x, y)` and performs one complete left click, as a real pointer would.
|
||||
fn click(window: &MainWindow, x: f32, y: f32) {
|
||||
let position = slint::LogicalPosition::new(x, y);
|
||||
window
|
||||
.window()
|
||||
.dispatch_event(WindowEvent::PointerMoved { position });
|
||||
window.window().dispatch_event(WindowEvent::PointerPressed {
|
||||
position,
|
||||
button: PointerEventButton::Left,
|
||||
});
|
||||
window
|
||||
.window()
|
||||
.dispatch_event(WindowEvent::PointerReleased {
|
||||
position,
|
||||
button: PointerEventButton::Left,
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_shell_keeps_drafts_settings_and_models_between_ticks() {
|
||||
let surface = MinimalSoftwareWindow::new(RepaintBufferType::NewBuffer);
|
||||
|
|
@ -114,6 +132,25 @@ fn native_shell_keeps_drafts_settings_and_models_between_ticks() {
|
|||
surface.set_size(PhysicalSize::new(1280 * scale, 800 * scale));
|
||||
render(&window, &surface, "native-chat");
|
||||
|
||||
// Regression for the "works from the second click" defect: a button must react to its very
|
||||
// first click, even though nothing inside the window has focus yet. The settings button of
|
||||
// the user panel sits at the bottom right of the sidebar.
|
||||
click(&window, 308.0, 767.0);
|
||||
assert!(
|
||||
state.borrow().ui.settings_open,
|
||||
"the first click on a button must activate it"
|
||||
);
|
||||
state.borrow_mut().ui.settings_open = false;
|
||||
sync();
|
||||
// A second, different button right after the first one must also react immediately.
|
||||
click(&window, 32.0, 775.0);
|
||||
assert!(
|
||||
state.borrow().ui.settings_open,
|
||||
"a click on another button must not be swallowed by focus handling"
|
||||
);
|
||||
state.borrow_mut().ui.settings_open = false;
|
||||
sync();
|
||||
|
||||
// Drive the real native editor, not only the generated callback surface.
|
||||
let position = slint::LogicalPosition::new(440.0, 740.0);
|
||||
window.window().dispatch_event(WindowEvent::PointerPressed {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue