Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pointer/Touch/KeyboardHandle::with_grab() and downcasting #1567

Merged
merged 4 commits into from
Oct 27, 2024

Conversation

YaLTeR
Copy link
Contributor

@YaLTeR YaLTeR commented Oct 24, 2024

Allows the compositor to inspect which grab is currently active.

Use case 1: in niri I want to scroll the workspace left and right when hovering the mouse close to output edges with a DnD grab, but not with a regular click grab.

Use case 2: avoiding a weird case with libadwaita DnD/move conflict https://gitlab.gnome.org/GNOME/gtk/-/issues/7113 by checking if the active grab is a DnD grab specifically and denying the move request in that case.

let mut is_dnd_grab = false;
pointer.with_grab(|_, grab| {
    is_dnd_grab = grab.as_any().downcast_ref::<DnDGrab<Self>>().is_some();
});

Debug impls are auto-generated with rust-analyzer (they want D: 'static).

Copy link
Collaborator

@cmeissl cmeissl left a comment

Choose a reason for hiding this comment

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

If the main goal is to just be able check if a certain grab is active it might just make sense to add something like has_grab<T>(&self) -> bool?

src/input/keyboard/mod.rs Outdated Show resolved Hide resolved
@YaLTeR
Copy link
Contributor Author

YaLTeR commented Oct 24, 2024

If the main goal is to just be able check if a certain grab is active it might just make sense to add something like has_grab<T>(&self) -> bool?

I figured I might as well just add the full function if a use case turns up later on.

@cmeissl
Copy link
Collaborator

cmeissl commented Oct 25, 2024

If the main goal is to just be able check if a certain grab is active it might just make sense to add something like has_grab<T>(&self) -> bool?

I figured I might as well just add the full function if a use case turns up later on.

Not sure there is a use-case where you would need access to the dyn Trait object. I guess in most cases you either
want to know the specific grab that is active and maybe some info from it. So maybe with_grab could already take the
expected type?

(Just some idea, I am also fine with accessing the dyn Trait)

@YaLTeR
Copy link
Contributor Author

YaLTeR commented Oct 25, 2024

Well, with dyn Trait you can check if a grab is active and if it's a particular grab type in one go more or less.

Lets the compositor inspect the active grab and its serial.
Lets the compositor figure out which particular grab is active.
Lets the compositor check for click vs. dnd vs. other grabs.
Same deal, lets the compositor inspect the grab should it need it.
Copy link
Member

@Drakulix Drakulix left a comment

Choose a reason for hiding this comment

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

Seems good to me

@Drakulix Drakulix merged commit e337dea into Smithay:master Oct 27, 2024
13 checks passed
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.

3 participants