Skip to content

Commit

Permalink
client: Implement dialog-v1 protocol
Browse files Browse the repository at this point in the history
Allows to mark windows as modal dialogs.

Change-Id: Ie4999552933e02fc473e621e7cc5e3f2928c0adb
Reviewed-by: Vlad Zahorodnii <[email protected]>
Reviewed-by: Qt CI Bot <[email protected]>
  • Loading branch information
Sodivad committed Mar 27, 2024
1 parent 6a94e1f commit 75bbefc
Show file tree
Hide file tree
Showing 13 changed files with 363 additions and 5 deletions.
17 changes: 17 additions & 0 deletions src/3rdparty/protocol/qt_attribution.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,5 +336,22 @@
"License": "MIT License",
"LicenseFile": "MIT_LICENSE.txt",
"Copyright": "Copyright © 2022 Kenny Levinsen"
},

{
"Id": "xdg-dialog-v1",
"Name": "Wayland Dialog Protocol",
"QDocModule": "qtwaylandcompositor",
"QtUsage": "Used in the Qt Wayland platform plugin",
"Files": "xdg-dialog-v1.xml",

"Description": "Register toplevel as dialogs",
"Homepage": "https://wayland.freedesktop.org",
"Version": "1",
"DownloadLocation": "",
"LicenseId": "MIT",
"License": "MIT License",
"LicenseFile": "MIT_LICENSE.txt",
"Copyright": "Copyright © 2023 Carlos Garnacho"
}
]
110 changes: 110 additions & 0 deletions src/3rdparty/protocol/xdg-dialog-v1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="dialog_v1">
<copyright>
Copyright © 2023 Carlos Garnacho

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>

<interface name="xdg_wm_dialog_v1" version="1">
<description summary="create dialogs related to other toplevels">
The xdg_wm_dialog_v1 interface is exposed as a global object allowing
to register surfaces with a xdg_toplevel role as "dialogs" relative to
another toplevel.

The compositor may let this relation influence how the surface is
placed, displayed or interacted with.

Warning! The protocol described in this file is currently in the testing
phase. Backward compatible changes may be added together with the
corresponding interface version bump. Backward incompatible changes can
only be done by creating a new major version of the extension.
</description>

<enum name="error">
<entry name="already_used" value="0"
summary="the xdg_toplevel object has already been used to create a xdg_dialog_v1"/>
</enum>

<request name="destroy" type="destructor">
<description summary="destroy the dialog manager object">
Destroys the xdg_wm_dialog_v1 object. This does not affect
the xdg_dialog_v1 objects generated through it.
</description>
</request>

<request name="get_xdg_dialog">
<description summary="create a dialog object">
Creates a xdg_dialog_v1 object for the given toplevel. See the interface
description for more details.

Compositors must raise an already_used error if clients attempt to
create multiple xdg_dialog_v1 objects for the same xdg_toplevel.
</description>
<arg name="id" type="new_id" interface="xdg_dialog_v1"/>
<arg name="toplevel" type="object" interface="xdg_toplevel"/>
</request>
</interface>

<interface name="xdg_dialog_v1" version="1">
<description summary="dialog object">
A xdg_dialog_v1 object is an ancillary object tied to a xdg_toplevel. Its
purpose is hinting the compositor that the toplevel is a "dialog" (e.g. a
temporary window) relative to another toplevel (see
xdg_toplevel.set_parent). If the xdg_toplevel is destroyed, the xdg_dialog_v1
becomes inert.

Through this object, the client may provide additional hints about
the purpose of the secondary toplevel. This interface has no effect
on toplevels that are not attached to a parent toplevel.
</description>

<request name="destroy" type="destructor">
<description summary="destroy the dialog object">
Destroys the xdg_dialog_v1 object. If this object is destroyed
before the related xdg_toplevel, the compositor should unapply its
effects.
</description>
</request>

<request name="set_modal">
<description summary="mark dialog as modal">
Hints that the dialog has "modal" behavior. Modal dialogs typically
require to be fully addressed by the user (i.e. closed) before resuming
interaction with the parent toplevel, and may require a distinct
presentation.

Clients must implement the logic to filter events in the parent
toplevel on their own.

Compositors may choose any policy in event delivery to the parent
toplevel, from delivering all events unfiltered to using them for
internal consumption.
</description>
</request>

<request name="unset_modal">
<description summary="mark dialog as not modal">
Drops the hint that this dialog has "modal" behavior. See
xdg_dialog_v1.set_modal for more details.
</description>
</request>
</interface>
</protocol>
2 changes: 2 additions & 0 deletions src/plugins/shellintegration/xdg-shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ qt_internal_add_plugin(QWaylandXdgShellIntegrationPlugin
qwaylandxdgshell.cpp qwaylandxdgshell_p.h
qwaylandxdgshellintegration.cpp qwaylandxdgshellintegration_p.h
qwaylandxdgexporterv2.cpp qwaylandxdgexporterv2_p.h
qwaylandxdgdialogv1.cpp qwaylandxdgdialogv1_p.h
LIBRARIES
Qt::Core
Qt::Gui
Expand All @@ -31,6 +32,7 @@ qt6_generate_wayland_protocol_client_sources(QWaylandXdgShellIntegrationPlugin
${CMAKE_CURRENT_SOURCE_DIR}/../../../3rdparty/protocol/xdg-shell.xml
${CMAKE_CURRENT_SOURCE_DIR}/../../../3rdparty/protocol/xdg-activation-v1.xml
${CMAKE_CURRENT_SOURCE_DIR}/../../../3rdparty/protocol/xdg-foreign-unstable-v2.xml
${CMAKE_CURRENT_SOURCE_DIR}/../../../3rdparty/protocol/xdg-dialog-v1.xml
)

#### Keys ignored in scope 1:.:.:xdg-shell.pro:<TRUE>:
Expand Down
33 changes: 33 additions & 0 deletions src/plugins/shellintegration/xdg-shell/qwaylandxdgdialogv1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (C) 2023 David Reondo <[email protected]>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qwaylandxdgdialogv1_p.h"

QT_BEGIN_NAMESPACE

namespace QtWaylandClient {

QWaylandXdgDialogV1::QWaylandXdgDialogV1(::xdg_dialog_v1 *object) : xdg_dialog_v1(object) { }

QWaylandXdgDialogV1::~QWaylandXdgDialogV1()
{
xdg_dialog_v1_destroy(object());
}

QWaylandXdgDialogWmV1::QWaylandXdgDialogWmV1(wl_registry *registry, uint32_t id, int version)
: xdg_wm_dialog_v1(registry, id, version)
{
}

QWaylandXdgDialogWmV1::~QWaylandXdgDialogWmV1()
{
destroy();
}
QWaylandXdgDialogV1 *QWaylandXdgDialogWmV1::getDialog(xdg_toplevel *toplevel)
{
return new QWaylandXdgDialogV1(get_xdg_dialog(toplevel));
}

} // namespace QtWaylandClient

QT_END_NAMESPACE
32 changes: 32 additions & 0 deletions src/plugins/shellintegration/xdg-shell/qwaylandxdgdialogv1_p.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (C) 2022 David Reondo <[email protected]>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QWAYLANDDIALOGV1_P_H
#define QWAYLANDDIALOGV1_P_H

#include <qwayland-xdg-dialog-v1.h>

QT_BEGIN_NAMESPACE

namespace QtWaylandClient {

class QWaylandXdgDialogV1 : public QtWayland::xdg_dialog_v1
{
public:
QWaylandXdgDialogV1(::xdg_dialog_v1 *object);
~QWaylandXdgDialogV1() override;
};

class QWaylandXdgDialogWmV1 : public QtWayland::xdg_wm_dialog_v1
{
public:
QWaylandXdgDialogWmV1(wl_registry *registry, uint32_t id, int version);
~QWaylandXdgDialogWmV1() override;
QWaylandXdgDialogV1 *getDialog(xdg_toplevel *toplevel);
};

} // namespace QtWaylandClient

QT_END_NAMESPACE

#endif
20 changes: 15 additions & 5 deletions src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "qwaylandxdgshell_p.h"

#include "qwaylandxdgexporterv2_p.h"
#include "qwaylandxdgdialogv1_p.h"

#include <QtWaylandClient/private/qwaylanddisplay_p.h>
#include <QtWaylandClient/private/qwaylandwindow_p.h>
Expand All @@ -32,6 +33,16 @@ QWaylandXdgSurface::Toplevel::Toplevel(QWaylandXdgSurface *xdgSurface)
}
requestWindowStates(window->windowStates());
requestWindowFlags(window->flags());
if (auto transientParent = xdgSurface->window()->transientParent()) {
if (auto parentSurface =
qobject_cast<QWaylandXdgSurface *>(transientParent->shellSurface())) {
set_parent(parentSurface->m_toplevel->object());
if (window->modality() != Qt::NonModal && m_xdgSurface->m_shell->m_xdgDialogWm) {
m_xdgDialog.reset(m_xdgSurface->m_shell->m_xdgDialogWm->getDialog(object()));
m_xdgDialog->set_modal();
}
}
}
}

QWaylandXdgSurface::Toplevel::~Toplevel()
Expand Down Expand Up @@ -296,11 +307,6 @@ QWaylandXdgSurface::QWaylandXdgSurface(QWaylandXdgShell *shell, ::xdg_surface *s
setGrabPopup(transientParent, display->lastInputDevice(), display->lastInputSerial());
} else {
setToplevel();
if (transientParent) {
auto parentXdgSurface = qobject_cast<QWaylandXdgSurface *>(transientParent->shellSurface());
if (parentXdgSurface)
m_toplevel->set_parent(parentXdgSurface->m_toplevel->object());
}
}
setSizeHints();
}
Expand Down Expand Up @@ -752,6 +758,10 @@ void QWaylandXdgShell::handleRegistryGlobal(void *data, wl_registry *registry, u
if (interface == QLatin1String(QWaylandXdgExporterV2::interface()->name)) {
xdgShell->m_xdgExporter.reset(new QWaylandXdgExporterV2(registry, id, version));
}

if (interface == QLatin1String(QWaylandXdgDialogWmV1::interface()->name)) {
xdgShell->m_xdgDialogWm.reset(new QWaylandXdgDialogWmV1(registry, id, version));
}
}

}
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class QWaylandInputDevice;
class QWaylandXdgShell;
class QWaylandXdgExportedV2;
class QWaylandXdgExporterV2;
class QWaylandXdgDialogWmV1;
class QWaylandXdgDialogV1;

class Q_WAYLANDCLIENT_EXPORT QWaylandXdgSurface : public QWaylandShellSurface, public QtWayland::xdg_surface
{
Expand Down Expand Up @@ -109,6 +111,7 @@ class Q_WAYLANDCLIENT_EXPORT QWaylandXdgSurface : public QWaylandShellSurface, p
QWaylandXdgSurface *m_xdgSurface = nullptr;
QWaylandXdgToplevelDecorationV1 *m_decoration = nullptr;
QScopedPointer<QWaylandXdgExportedV2> m_exported;
QScopedPointer<QWaylandXdgDialogV1> m_xdgDialog;
};

class Popup : public QtWayland::xdg_popup {
Expand Down Expand Up @@ -171,6 +174,7 @@ class Q_WAYLANDCLIENT_EXPORT QWaylandXdgShell
QScopedPointer<QWaylandXdgDecorationManagerV1> m_xdgDecorationManager;
QScopedPointer<QWaylandXdgActivationV1> m_xdgActivation;
QScopedPointer<QWaylandXdgExporterV2> m_xdgExporter;
QScopedPointer<QWaylandXdgDialogWmV1> m_xdgDialogWm;

friend class QWaylandXdgSurface;
};
Expand Down
3 changes: 3 additions & 0 deletions tests/auto/client/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ qt_manual_moc(moc_files
textinput.h
qttextinput.h
viewport.h
xdgdialog.h
xdgoutputv1.h
xdgshell.h
)
Expand All @@ -33,6 +34,7 @@ add_library(SharedClientTest
qttextinput.cpp qttextinput.h
xdgoutputv1.cpp xdgoutputv1.h
xdgshell.cpp xdgshell.h
xdgdialog.cpp xdgdialog.h
viewport.cpp viewport.h
${moc_files}
)
Expand All @@ -50,6 +52,7 @@ qt6_generate_wayland_protocol_server_sources(SharedClientTest
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/viewporter.xml
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/wayland.xml
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/xdg-decoration-unstable-v1.xml
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/xdg-dialog-v1.xml
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/xdg-output-unstable-v1.xml
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/xdg-shell.xml
)
Expand Down
1 change: 1 addition & 0 deletions tests/auto/client/shared/mockcompositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ DefaultCompositor::DefaultCompositor(CompositorType t, int socketFd)
add<XdgWmBase>();
add<FractionalScaleManager>();
add<Viewporter>();
add<XdgWmDialog>();

switch (m_type) {
case CompositorType::Default:
Expand Down
2 changes: 2 additions & 0 deletions tests/auto/client/shared/mockcompositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "xdgshell.h"
#include "viewport.h"
#include "fractionalscalev1.h"
#include "xdgdialog.h"

#include <QtGui/QGuiApplication>

Expand Down Expand Up @@ -50,6 +51,7 @@ class DefaultCompositor : public CoreCompositor
IviSurface *iviSurface(int i = 0) { return get<IviApplication>()->m_iviSurfaces.value(i, nullptr); }
FractionalScale *fractionalScale(int i = 0) {return get<FractionalScaleManager>()->m_fractionalScales.value(i, nullptr); }
Viewport *viewport(int i = 0) {return get<Viewporter>()->m_viewports.value(i, nullptr); }
XdgDialog *xdgDialog(int i = 0) { return get<XdgWmDialog>()->m_dialogs.value(i, nullptr); }

uint sendXdgShellPing();
void xdgPingAndWaitForPong();
Expand Down
59 changes: 59 additions & 0 deletions tests/auto/client/shared/xdgdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (C) 2024 David Redondo <[email protected]>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "xdgdialog.h"

#include "xdgshell.h"

namespace MockCompositor {

XdgDialog::XdgDialog(XdgWmDialog *wm, XdgToplevel *toplevel, wl_client *client, int id, int version)
: QtWaylandServer::xdg_dialog_v1(client, id, version),
toplevel(toplevel),
modal(false),
m_wm(wm)
{
}

void XdgDialog::xdg_dialog_v1_set_modal(Resource *resource)
{
Q_UNUSED(resource)
modal = true;
}

void XdgDialog::xdg_dialog_v1_unset_modal(Resource *resource)
{
Q_UNUSED(resource)
modal = false;
}

void XdgDialog::xdg_dialog_v1_destroy(Resource *resource)
{
wl_resource_destroy(resource->handle);
}

void XdgDialog::xdg_dialog_v1_destroy_resource(Resource *resource)
{
Q_UNUSED(resource)
m_wm->m_dialogs.removeOne(this);
delete this;
}

XdgWmDialog::XdgWmDialog(CoreCompositor *compositor, int version)
: QtWaylandServer::xdg_wm_dialog_v1(compositor->m_display, version)
{
}

void XdgWmDialog::xdg_wm_dialog_v1_destroy(Resource *resource)
{
wl_resource_destroy(resource->handle);
}

void XdgWmDialog::xdg_wm_dialog_v1_get_xdg_dialog(Resource *resource, uint32_t id,
struct ::wl_resource *toplevel)
{
auto *t = fromResource<XdgToplevel>(toplevel);
auto *dialog = new XdgDialog(this, t, resource->client(), id, resource->version());
m_dialogs.push_back(dialog);
}

} // namespace MockCompositor
Loading

0 comments on commit 75bbefc

Please sign in to comment.