Skip to content

Android: Fix cursor position when setting from popup#11003

Open
Murmele wants to merge 39 commits intoslint-ui:masterfrom
Murmele:mm/android_cursor_popup
Open

Android: Fix cursor position when setting from popup#11003
Murmele wants to merge 39 commits intoslint-ui:masterfrom
Murmele:mm/android_cursor_popup

Conversation

@Murmele
Copy link
Contributor

@Murmele Murmele commented Mar 13, 2026

Under Android the popup is not a dedicated window with own coordinate system, but only a ChildWindow of the main window. Because of that the position of the popup must be considered as well, because everything is relative to the main window

Fixes: #10475

The testcase popupwindow_nested.slint checks if the changes are correct

@Murmele Murmele force-pushed the mm/android_cursor_popup branch from 3f88b57 to 5889c9a Compare March 13, 2026 08:35
Murmele added 2 commits March 13, 2026 09:37
Reason: If not a dedicated window, it does not have its own coordinate system, but all elements must be still relative to the main window.
Fixes: slint-ui#10475
@Murmele Murmele force-pushed the mm/android_cursor_popup branch from 849ccad to 85c9db7 Compare March 13, 2026 08:44
@Murmele Murmele force-pushed the mm/android_cursor_popup branch from 66a5a84 to fa0c5ce Compare March 13, 2026 13:43
autofix-ci bot and others added 7 commits March 13, 2026 13:45
This reverts commit 068ea52.

#Conflicts:
#	internal/backends/android-activity/javahelper.rs
#	internal/core/item_tree.rs
#	internal/core/items/text.rs
#	internal/core/window.rs
Replace the hardcoded `ROOT_ITEM_INDEX` constant with a new `ItemRc::new_root` method and `is_root` check
…opup'

#Conflicts:
#	internal/core/item_tree.rs
@Murmele Murmele changed the title Mm/android cursor popup Android: Fix cursor position when setting from popup Mar 13, 2026
Murmele added 3 commits March 13, 2026 16:13
…ant logic

Remove redundant code that calculates `parent_window_adapter` and `position` for popup placement, as this is already handled in the mapping function. The logic was duplicated and unnecessary, reducing code complexity and improving readability.

This change aligns with the existing mapping logic that already determines the correct window adapter and position for popups.
@Murmele Murmele requested a review from ogoffart March 13, 2026 15:37
Reason: Otherwise it might be that for TopLevel Windows the position is incorrect
@Murmele Murmele marked this pull request as ready for review March 16, 2026 08:12
@Murmele
Copy link
Contributor Author

Murmele commented Mar 16, 2026

I am wondering where the logic for the mouse position is ...

Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

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

This change the behavior of map_to_window to no longer stop at the PopupWindow but return the value of the actual Window.
This will indeed solve the bug. I wonder if it won't have unintended side effect. (Like will it change the behavior of the absolute-position property?)

Just a comment for next time:
The drive-by refactoring of ItemRc is great, but makes the change harder to review because that is most of the content of the change, and the commit history is not clean enough to allow per-commit review. In that case, it is helpful to rebase -i the change to keep a clean commit history, or put it in a separate PR.

use crate::slice::Slice;
use crate::window::WindowAdapterRc;
use alloc::vec::Vec;
use core::borrow::Borrow;
Copy link
Member

Choose a reason for hiding this comment

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

In my experience, this gets added by rust_analyzer sometimes when trying to borrow something that is not a RefCell. Are you sure you really mean to add this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted in 54d4f28

.is_none_or(|adapter| adapter.renderer().supports_transformations());
while let Some(parent) = current.parent_item(ParentItemTraversalMode::StopAtPopups) {
if stop_condition(&parent) {
break;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return result;

I believe we don't want to add the popup position when we are called from the map_to_item_tree function.

(Alternative would be to move the added code directly in map_to_window)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted because not required because of 4450eda

@Murmele Murmele marked this pull request as draft March 17, 2026 09:08
@Murmele
Copy link
Contributor Author

Murmele commented Mar 18, 2026

One thing I don't understand yet is why in the test absolute_coords.slint does not trigger https://github.com/Murmele/slint/blob/mm/android_cursor_popup/internal/core/item_tree.rs#L614
It jumps into and checks the if condition but it is never fullfilled. @ogoffart do you have an idea why?
Ah it is probably because they don't have the same itemtree because of the dynamic if condition?

is_root_item_of() does not consider dynamic elements

Murmele and others added 8 commits March 18, 2026 18:37
&self,
p: LogicalPoint,
stop_condition: impl Fn(&Self) -> bool,
consider_popup: bool,
Copy link
Member

Choose a reason for hiding this comment

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

Inside of passing a boolean there that is only true in map_to_screen, just move the code that consider the popup in the map_to_screen function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 4450eda

/// Similar to `map_to_window` but considers also the popup location if the popup
/// is not a dedicated window but of type ChildWindow
/// Use this function if you wanna have the real absolute position
pub fn map_to_screen(&self, p: LogicalPoint) -> LogicalPoint {
Copy link
Member

Choose a reason for hiding this comment

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

map_to_screen here is not the right name, because this is not the case when the top level window is not full screen (eg, on desktop)

A better name would perhaps be map_to_native_window

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 4450eda

@Murmele Murmele marked this pull request as ready for review March 19, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

android input cursor control

2 participants