Add desiredScreen property to LayerShellQt::Window

If the property is set, the compositor will try to put the window on the
given output. If not set, the compositer will decide where to put the
window (usually the active output). The motivation for this change is the
ability for KRunner to always appear on the active output.
This commit is contained in:
Julius Zint 2022-01-21 13:29:46 +01:00
parent 14982d6dc7
commit 9f8b8c9731
3 changed files with 33 additions and 8 deletions

View file

@ -28,6 +28,7 @@ public:
Window::Layer layer = Window::LayerTop;
QMargins margins;
QWaylandLayerSurface *getSurface() const;
QPointer<QScreen> desiredOutput;
};
static QMap<QWindow *, Window *> s_map;
@ -113,6 +114,16 @@ Window::Layer Window::layer() const
return d->layer;
}
QScreen *Window::desiredOutput() const
{
return d->desiredOutput;
}
void Window::setDesiredOutput(QScreen *output)
{
d->desiredOutput = output;
}
Window::Window(QWindow *window)
: QObject(window)
, d(new WindowPrivate(window))

View file

@ -9,6 +9,7 @@
#define LAYERSHELLQTWINDOW_H
#include <QObject>
#include <QScreen>
#include <QWindow>
#include "layershellqt_export.h"
@ -68,6 +69,14 @@ public:
void setLayer(Layer layer);
Layer layer() const;
/**
* If set, the compositor will try to put the window on the given screen.
* If its not set, then the compositor will decide where to put the window.
* Under normal circumstances, this should be the active output.
*/
void setDesiredOutput(QScreen *output);
QScreen *desiredOutput() const;
/**
* Sets a string based identifier for this window.
* This may be used by a compositor to determine stacking

View file

@ -6,9 +6,9 @@
*/
#include "interfaces/shell.h"
#include "layershellqt_logging.h"
#include "qwaylandlayershell_p.h"
#include "qwaylandlayersurface_p.h"
#include "layershellqt_logging.h"
#include <QtWaylandClient/private/qwaylandscreen_p.h>
#include <QtWaylandClient/private/qwaylandsurface_p.h>
@ -23,14 +23,19 @@ QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShell *shell, QtWaylandC
LayerShellQt::Window *interface = Window::get(window->window());
Q_ASSERT(interface);
// Qt will always assign a screen to a window, but if the compositor has no screens available a dummy QScreen object is created
// this will not cast to a QWaylandScreen
QtWaylandClient::QWaylandScreen *screen = window->waylandScreen();
if (screen->isPlaceholder()) {
qCWarning(LAYERSHELLQT) << "Creating a layer shell for placeholder screen. This will be positioned incorrectly";
wl_output *output = nullptr;
QScreen *screen = interface->desiredOutput();
if (screen) {
auto waylandScreen = dynamic_cast<QtWaylandClient::QWaylandScreen *>(screen->handle());
// Qt will always assign a screen to a window, but if the compositor has no screens available a dummy QScreen object is created
// this will not cast to a QWaylandScreen
if (!waylandScreen) {
qCWarning(LAYERSHELLQT) << "Creating a layer shell for placeholder screen. This will be positioned incorrectly";
} else {
output = waylandScreen->output();
}
}
init(shell->get_layer_surface(window->waylandSurface()->object(), screen->isPlaceholder() ? nullptr : screen->output(), interface->layer(), interface->scope()));
init(shell->get_layer_surface(window->waylandSurface()->object(), output, interface->layer(), interface->scope()));
Window::Anchors anchors = interface->anchors();