diff --git a/src/ui/slint/chat.slint b/src/ui/slint/chat.slint index d45455f..fede132 100644 --- a/src/ui/slint/chat.slint +++ b/src/ui/slint/chat.slint @@ -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; diff --git a/src/ui/slint/controls.slint b/src/ui/slint/controls.slint index 5409c95..0ac1f88 100644 --- a/src/ui/slint/controls.slint +++ b/src/ui/slint/controls.slint @@ -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; diff --git a/src/ui/slint/settings.slint b/src/ui/slint/settings.slint index 0ef205d..26dc7cf 100644 --- a/src/ui/slint/settings.slint +++ b/src/ui/slint/settings.slint @@ -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 { diff --git a/src/ui/slint/settings/appearance.slint b/src/ui/slint/settings/appearance.slint index d897277..68d05d9 100644 --- a/src/ui/slint/settings/appearance.slint +++ b/src/ui/slint/settings/appearance.slint @@ -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 { diff --git a/src/ui/slint/sidebar.slint b/src/ui/slint/sidebar.slint index 9bc672c..d016f8e 100644 --- a/src/ui/slint/sidebar.slint +++ b/src/ui/slint/sidebar.slint @@ -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; diff --git a/src/ui/slint/theme.slint b/src/ui/slint/theme.slint index fa55308..11b0824 100644 --- a/src/ui/slint/theme.slint +++ b/src/ui/slint/theme.slint @@ -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; diff --git a/src/ui/slint/voice.slint b/src/ui/slint/voice.slint index e830adf..b2b9bf3 100644 --- a/src/ui/slint/voice.slint +++ b/src/ui/slint/voice.slint @@ -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); } } diff --git a/src/ui_smoke.rs b/src/ui_smoke.rs index da229f6..90aa248 100644 --- a/src/ui_smoke.rs +++ b/src/ui_smoke.rs @@ -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 {