Request activate on show

Unless the window doesn't have keyboard interactivity or the caller
wants it not to.

To match XDG Shell behavior and general Qt window behavior.
This commit is contained in:
Kai Uwe Broulik
2025-07-23 17:00:24 +02:00
parent f599e829ad
commit d436a779d7
4 changed files with 42 additions and 0 deletions

View File

@ -35,6 +35,7 @@ public:
QSize desiredSize = QSize(0, 0); QSize desiredSize = QSize(0, 0);
Window::ScreenConfiguration screenConfiguration = Window::ScreenFromQWindow; Window::ScreenConfiguration screenConfiguration = Window::ScreenFromQWindow;
bool closeOnDismissed = true; bool closeOnDismissed = true;
bool activateOnShow = true;
}; };
static QMap<QWindow *, Window *> s_map; static QMap<QWindow *, Window *> s_map;
@ -170,6 +171,16 @@ void Window::setCloseOnDismissed(bool close)
d->closeOnDismissed = close; d->closeOnDismissed = close;
} }
bool Window::activateOnShow() const
{
return d->activateOnShow;
}
void Window::setActivateOnShow(bool activateOnShow)
{
d->activateOnShow = activateOnShow;
}
Window::Window(QWindow *window) Window::Window(QWindow *window)
: QObject(window) : QObject(window)
, d(new WindowPrivate(window)) , d(new WindowPrivate(window))

View File

@ -28,6 +28,7 @@ class LAYERSHELLQT_EXPORT Window : public QObject
Q_PROPERTY(Layer layer READ layer WRITE setLayer NOTIFY layerChanged) Q_PROPERTY(Layer layer READ layer WRITE setLayer NOTIFY layerChanged)
Q_PROPERTY(KeyboardInteractivity keyboardInteractivity READ keyboardInteractivity WRITE setKeyboardInteractivity NOTIFY keyboardInteractivityChanged) Q_PROPERTY(KeyboardInteractivity keyboardInteractivity READ keyboardInteractivity WRITE setKeyboardInteractivity NOTIFY keyboardInteractivityChanged)
Q_PROPERTY(ScreenConfiguration screenConfiguration READ screenConfiguration WRITE setScreenConfiguration) Q_PROPERTY(ScreenConfiguration screenConfiguration READ screenConfiguration WRITE setScreenConfiguration)
Q_PROPERTY(bool activateOnShow READ activateOnShow WRITE setActivateOnShow)
public: public:
~Window() override; ~Window() override;
@ -117,6 +118,18 @@ public:
void setCloseOnDismissed(bool close); void setCloseOnDismissed(bool close);
bool closeOnDismissed() const; bool closeOnDismissed() const;
/**
* Whether the window should requestActivate on show.
*
* Normally, you want this enabled but in case of e.g. a desktop window, this can be disabled.
*
* It does nothing when KeyboardInteractivity is KeyboardInteractivityNone.
*
* The default is true.
*/
void setActivateOnShow(bool activateOnShow);
bool activateOnShow() const;
/** /**
* Gets the LayerShell Window for a given Qt Window * Gets the LayerShell Window for a given Qt Window
* Ownership is not transferred * Ownership is not transferred

View File

@ -230,6 +230,23 @@ bool QWaylandLayerSurface::requestActivate()
return false; return false;
} }
bool QWaylandLayerSurface::requestActivateOnShow()
{
if (!m_interface->activateOnShow()) {
return false;
}
if (m_interface->keyboardInteractivity() == Window::KeyboardInteractivityNone) {
return false;
}
if (m_window->window()->property("_q_showWithoutActivating").toBool()) {
return false;
}
return requestActivate();
}
void QWaylandLayerSurface::setXdgActivationToken(const QString &token) void QWaylandLayerSurface::setXdgActivationToken(const QString &token)
{ {
m_activationToken = token; m_activationToken = token;

View File

@ -50,6 +50,7 @@ public:
#endif #endif
bool requestActivate() override; bool requestActivate() override;
bool requestActivateOnShow() override;
void setXdgActivationToken(const QString &token) override; void setXdgActivationToken(const QString &token) override;
void requestXdgActivationToken(quint32 serial) override; void requestXdgActivationToken(quint32 serial) override;