Skip to content

Conversation

@bolshoytoster
Copy link

  • Tested on all platforms changed
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality

This PR attempts to add support for popups, using an API design similar to that of GTK's low level popup API.

This adds a new create_popup method to the ActiveEventLoop trait, similar to create_window, but takes extra PopupAttributes and parent: WindowId arguments.

The new PopupAttributes struct is pretty much a direct mirror of GTK's PopupLayout (barring the shadow width) (perhaps it would be worth linking to that page in the docs, since it provides a good explanation of the properties).

I decided (at least for now) that this method should return a dyn Window, since it seems most platforms treat popups the same as regular windows, and this would reduce code duplication, making it easier to add support for more platforms (though maybe it could be worth creating a trait Popup: Window for any popup-specific methods (see gdk_popup_get_{rect,surface}_anchor)).

I have chosen to implement wayland support first, partly because it's what I use, and partly because it seems to be the only platform that treats popups specially, and is the most restrictive about their functionality (popups must have a parent, are positioned relative to that parent and are destroyed when they lose focus), so it was useful for figuring out the ideal API.

I've tried to implemnt this for X11, using an override_redirect window and grab_pointer, but I haven't found any way to destroy it when it loses focus (they don't seem to get XI_FocusOut events).

@kchibisov
Copy link
Member

The overall approach and integration in winit seems fine. Unfortunately, I'm a bit busy to get to it soon and unlikely to get before 0.31 is released.

Some general things to consider, we'll unify common methods on windows into Surface trait(there're a bunch of PRs for that).

I'm not sure what we've decided wrt actual events though, since some platforms send them to main window, and some send them to subviews, that's the main issue in general when adding this API/subsurfaces.

I've tried to implemnt this for X11, using an override_redirect window and grab_pointer, but I haven't found any way to destroy it when it loses focus (they don't seem to get XI_FocusOut events).

Could be related to pointer event, in general, you can use x11trace(sometimes xtrace) to compare e.g. what GTK gets, maybe there's some pattern in events, etc.

--

P.s. никнейм просто фантастический.

@kchibisov
Copy link
Member

kchibisov commented Dec 16, 2025

trait Popup: Window for any popup-specific methods (see gdk_popup_get_{rect,surface}_anchor)).

Yeah, that should be added. There's a plan to also have downcasting from dyn Surface to e.g. dyn Window(other core objects), etc (we already have upcasting due to rust).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants