core/popupwindow: add grabFocus

Allows standard wayland focus grabs on non hyprland compositors.
This commit is contained in:
outfoxxed 2026-01-13 01:24:20 -08:00
parent de1bfe028d
commit dca652366a
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
3 changed files with 16 additions and 1 deletions

View file

@ -21,6 +21,7 @@ set shell id.
- Pipewire service now reconnects if pipewire dies or a protocol error occurs. - Pipewire service now reconnects if pipewire dies or a protocol error occurs.
- Added pipewire audio peak detection. - Added pipewire audio peak detection.
- Added initial support for network management. - Added initial support for network management.
- Added support for grabbing focus from popup windows.
## Other Changes ## Other Changes

View file

@ -59,7 +59,7 @@ void ProxyPopupWindow::completeWindow() {
} }
this->window->setTransientParent(bw); this->window->setTransientParent(bw);
this->window->setFlag(Qt::ToolTip); this->window->setFlag(this->bWantsGrab ? Qt::Popup : Qt::ToolTip);
this->mAnchor.markDirty(); this->mAnchor.markDirty();
PopupPositioner::instance()->reposition(&this->mAnchor, this->window); PopupPositioner::instance()->reposition(&this->mAnchor, this->window);

View file

@ -76,6 +76,15 @@ class ProxyPopupWindow: public ProxyWindowBase {
/// ///
/// The popup will not be shown until @@anchor is valid, regardless of this property. /// The popup will not be shown until @@anchor is valid, regardless of this property.
QSDOC_PROPERTY_OVERRIDE(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged); QSDOC_PROPERTY_OVERRIDE(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged);
/// If true, the popup window will be dismissed and @@visible will change to false
/// if the user clicks outside of the popup or it is otherwise closed.
///
/// > [!WARNING] Changes to this property while the window is open will only take
/// > effect after the window is hidden and shown again.
///
/// > [!NOTE] Under Hyprland, @@Quickshell.Hyprland.HyprlandFocusGrab provides more advanced
/// > functionality such as detecting clicks outside without closing the popup.
Q_PROPERTY(bool grabFocus READ default WRITE default NOTIFY grabFocusChanged BINDABLE bindableGrabFocus);
/// The screen that the window currently occupies. /// The screen that the window currently occupies.
/// ///
/// This may be modified to move the window to the given screen. /// This may be modified to move the window to the given screen.
@ -103,12 +112,15 @@ public:
[[nodiscard]] qint32 relativeY() const; [[nodiscard]] qint32 relativeY() const;
void setRelativeY(qint32 y); void setRelativeY(qint32 y);
[[nodiscard]] QBindable<bool> bindableGrabFocus() { return &this->bWantsGrab; }
[[nodiscard]] PopupAnchor* anchor(); [[nodiscard]] PopupAnchor* anchor();
signals: signals:
void parentWindowChanged(); void parentWindowChanged();
void relativeXChanged(); void relativeXChanged();
void relativeYChanged(); void relativeYChanged();
void grabFocusChanged();
private slots: private slots:
void onParentWindowChanged(); void onParentWindowChanged();
@ -131,4 +143,6 @@ private:
bTargetVisible, bTargetVisible,
&ProxyPopupWindow::targetVisibleChanged &ProxyPopupWindow::targetVisibleChanged
); );
Q_OBJECT_BINDABLE_PROPERTY(ProxyPopupWindow, bool, bWantsGrab);
}; };