Compare commits

...

107 Commits

Author SHA1 Message Date
2c903f3618 update version for new release 2024-05-21 15:45:43 +00:00
797c8b26ca Use QWaylandWindow::windowContentGeometry() to set the initial preferred size
This matches the geometry used in the setWindowGeometry() function.

(cherry picked from commit e8594be884)
2024-04-05 10:30:03 +03:00
32afbcf68a Update the desired size when the anchors change
When the anchor changes, the desired size should be updated to avoid
the compositor posting a protocol error.

BUG: 484990
(cherry picked from commit 0a31923938)
2024-04-05 10:29:55 +03:00
81782b38e4 Guard against calling set_size while applying a configure event more explicitly
Depending on code path taken, geometry.size() == m_pendingSize can
produce incorrect results.

If a configure event is applied, it's fine.

If the window is resized by user, m_pendingSize will have outdated value,
and setWindowGeometry() can ignore future size updates that are valid.

In hindsight, we need special hooks in the QWaylandWindow to request and
apply new geometry. Rather than have one function that deals with all cases.


(cherry picked from commit 127d817aa1)
2024-04-03 12:25:03 +00:00
4dfa7b53f1 update version for new release 2024-03-28 14:31:54 +00:00
aeb8d198ce update version for new release 2024-03-26 14:23:48 +00:00
f32b64244f update version for new release 2024-03-05 23:23:45 +00:00
9fb17e63b2 update version for new release 2024-03-05 22:17:10 +00:00
ec1a2d02fb Update Frameworks version requirement to 6.0.0
GIT_SILENT
2024-02-21 14:43:27 +00:00
c902d638ec Port to asynchronous roundtrip
When a resize is driven client side we wait for the compositor to have a
chance to reconfigure us before submitting the next frame.

Using a blocking round trip caused an issue. Instead block isExposed and
trigger an expose event whilst a sync is in progress.
2024-02-16 17:15:50 +00:00
176b7648d4 Synchronise client driven resizing
Qt's resizing is inherently synchronous. When an application calls
QWindow::setGeometry with a new size, we expect it to make that resize.
An expose event of the requested size will be generated.

Wayland is by default async, a client requests a size, and then will be
configured to that size, or potentially another size.

The simplest way to map the two APIs is to roundtrip when the client
wants to resize. This way we can guarantee that a call to
`setGeometry();  update()` will have the server configured size before
the paint.

In practice it's still not perfect due to other issues, but at least
will sort itself out within a frame.


(cherry picked from commit 697c747c58)
2024-02-14 12:10:19 +00:00
cce9896e42 Fix build with Qt 6.7
This also fixes a hypothetical case of a layer shell with subsurfaces
and matches the call made by xdgshell after the first configure.


(cherry picked from commit 6427176da4)
2024-02-08 10:19:13 +00:00
f7fee6e7f6 update version for new release 2024-02-01 09:46:00 +00:00
66ec181e1e Update version number for 5.93.0
GIT_SILENT
2024-01-31 13:01:20 +00:00
1abc1f381f Add a new setExclusiveEdge call in the protocol
This can be used to disambiguate the exclusive edge when the anchors are
on a corner (so there  would be 2 candidates)

it's quite quick and dirty mostly to understand if we do want to push
for something along the lines


(cherry picked from commit ad5246f0d0)
2024-01-26 11:39:06 +00:00
47539db4b3 Update version number for 5.92.90
GIT_SILENT
2024-01-10 14:17:49 +00:00
078f36f8f3 Update version number for 5.92.0
GIT_SILENT
2024-01-10 12:29:03 +00:00
7d3194034c Use ECM QML module so the module can be used outside of repository 2024-01-04 14:42:17 -05:00
e3098a660a Fix constrained check
The value in parantheses was always zero.
2023-12-21 13:58:24 +00:00
d379bc8d8e Update version number for 5.91.90
GIT_SILENT
2023-12-20 18:54:50 +00:00
715e629dd8 Update version number for 5.91.0
GIT_SILENT
2023-12-20 12:02:54 +00:00
8ae3b0aef8 Qt6 check code as apps is qt6 only. 2023-12-15 21:44:24 +01:00
6f0bca5593 Revert "Add a (temporary) way to attach popups to layer surfaces"
This reverts commit fdab1544fb.

Qt 6.6 is out with all the necessary multi-shell apis.
2023-12-08 11:55:52 +00:00
d1ab27dd53 Update Qt version requirement to 6.6.0
GIT_SILENT
2023-12-08 12:10:27 +01:00
4569e78e25 Update version number for 5.90.90
GIT_SILENT
2023-12-07 16:41:03 +00:00
ddb0490592 Change default keyboard interactivity to OnDemand
OnDemand is a better default as it still ensures that the window will
receive keyboard input by default, but it's less aggressive.
2023-11-30 10:06:18 +00:00
3c116e7550 Revert "Change default keyboard interactivity from exclusive to none"
This reverts commit be63783888.

It broke keyboard input in sddm greeter. While defaulting to a non-spec
value is not great, it's also not that critical. It might be worth
considering synchronizing Qt::WindowDoesNotAcceptFocus with the keyboard
interactivity flag, but the tricky part is that the keyboard interactivty
is not just a boolean.

BUG: 477251
2023-11-30 10:06:18 +00:00
9e1c5357ac Update version number for 5.90.0
GIT_SILENT
2023-11-29 10:24:25 +00:00
76e8f33cbc GIT_SILENT: Port to new CI template 2023-11-19 16:20:06 +01:00
25bc38dac1 Update version number for 5.81.80
GIT_SILENT
2023-11-17 12:28:29 +00:00
aa167e8da5 Update version number for 5.81.0
GIT_SILENT
2023-11-09 12:31:25 +00:00
de9fdb3fb7 Support XDG activation
QWaylandLayerShellIntegration has virtual hooks for Xdg Activation.

This is important to hook up in layer shell because activation using
requestActivate in Qt will go through this path. It also means we have
support for us to drop the implementation in KWindowSystem in favour of
calling into Qt.
2023-11-06 12:41:20 +00:00
00b26a196d set ecm soversion to project major
again probably not used but feels best to make them match
2023-11-03 10:19:42 +00:00
fcaf8cf95d Update PROJECT_VERSION_MAJOR to 6, this is mostly used in some internal soversions 2023-11-01 19:22:21 +00:00
1573a89aac Skip empty parts for stringToEnum template
metaEnum.keyToValue("") will results all flags get set, thus creating a
enum with empty (0) flags become impossible. This patch fixes that.
2023-09-26 17:25:20 +08:00
721c0ae334 Remove an inappropriate log message 2023-09-06 14:52:55 +03:00
143fd1755a Expose the Window interface to QML
If we are designing our UI's windows from QML, it makes sense that we
might want to configure how they're placed from the same place.

Everything was already in place but for a few technical bits which this
change adds.

Signed-off-by: Victoria Fischer <victoria.fischer@mbition.io>
2023-07-13 11:23:01 +02:00
d6aeaef1dc We use Qt6/kf6 only 2023-06-26 20:42:27 +02:00
c97826ab18 It compiles fine without deprecated methods 2023-06-12 14:00:48 +02:00
3bfed84c45 Now we depend against qt6 2023-06-08 19:17:22 +02:00
4cb2a27a4c Use qt6 only 2023-06-04 09:17:37 +02:00
9750fd8be7 Avoid emitting excessive changed signals
If the layer shell surface properties don't change, don't emit the
changed signals and issue wayland requests.
2023-05-17 14:57:09 +03:00
5e88f449b0 Introduce Window::closeOnDismissed() flag
This can be used to control the sending of QEvent::Close event.
2023-05-16 17:58:48 +03:00
497d50c4df Emit Window::layerChanged signal
Otherwise it's not possible to change layers at runtime.
2023-05-13 12:18:12 +03:00
541497ff5f Add wayland to third-party deps 2023-05-05 10:22:39 +02:00
1358743441 Call LayerShell::set_size when the window geometry changes
Without this when krunner expands, the frame after kwin will resize it
back to the last size the layer shell requested to be resized to.

To detect when we should not send an explicit size on window resize
events we check the anchors; if we're constrained on opposing edges we
want the compositor alone to set the size.
2023-05-01 14:38:36 +00:00
be63783888 Change default keyboard interactivity from exclusive to none
To be in line with the default of the protocol
2023-04-27 12:28:02 +02:00
87753746b9 chore: add missing override in example 2023-04-24 23:23:09 +03:00
49f31bb22d Replace Window::desiredOutput with a Window::screenConfiguration enum
To not overlap with QWindow::screen too much, introduce an enum to make it
more clear what the options and the resulting behaviour are.
2023-04-24 20:11:13 +00:00
511b92f4ab Port to QWaylandShellSurface::attachPopup() 2023-04-22 12:11:04 +03:00
fdab1544fb Add a (temporary) way to attach popups to layer surfaces
The new API is temporary. It's needed to help us with porting plasma to
the layer shell protocol until Qt 6.6 is released, which includes
QWaylandShellSurface::attachPopup().
2023-04-22 12:11:04 +03:00
2985398375 Port to QWaylandWindow::setShellIntegration()
With QWaylandWindow::setShellIntegration(), it's possible to use
xdg-shell and layer-shell protocols in the same process. It's important
for plasmashell, where we want to use the layer shell protocol for
special surfaces such as the desktop background, and the xdg shell
protocol for dialogs.

In order to make a QWindow use the layer shell protocol, you need to
call LayerShellQt::Window::get() before the window is mapped.
2023-04-22 12:11:01 +03:00
07e63cab8c Require C++20 2023-04-20 08:45:39 +02:00
488c6d759c Replace KF5 with KF6 2023-02-28 15:05:58 +01:00
d69a528b6c Require Qt 6.4 2023-02-28 15:05:34 +01:00
cfbfe94e79 Use KF6 libs on CI 2023-02-28 15:05:15 +01:00
2b757f3d82 Remove Qt5 CI 2023-02-28 15:05:03 +01:00
3c85e2e889 Use the QScreen of the QWindow as default output
If the Window::setDesiredOutput API was not called for the QWindow, use
QWindow::screen(). This allows assigning QWindows to specific screens using
the plain Qt API.

Passing nullptr to Window::setDesiredOutput explicitly results in nil as
desired output for the layer, which lets the compositor select a screen.
2023-02-22 08:23:17 +01:00
b9f8f6447d Update version number for 5.27.80
GIT_SILENT
2023-01-27 14:56:01 +00:00
7de801802b Revert "Show all headers in qtc6"
There was no consensus for this in Plasma.
This reverts commit 22df3fe914.
2023-01-24 08:49:43 +01:00
22df3fe914 Show all headers in qtc6 2023-01-22 17:38:12 +00:00
8d14abc707 Update kf5 version requirement to 5.102.0
GIT_SILENT
2023-01-21 20:06:42 +00:00
d06bcbe25b Update version number for 5.28.80
GIT_SILENT
2023-01-19 12:28:59 +00:00
fc06e945c8 Update version number for 5.26.90
GIT_SILENT
2023-01-19 11:17:24 +00:00
b95910c086 Use ecm_set_disabled_deprecation_versions 2022-12-23 13:50:51 +01:00
70dc87f673 Use KDE_INSTALL_CMAKEPACKAGEDIR
GIT_SILENT
2022-10-22 13:59:13 +00:00
7b9c2c1db1 Update version number for 5.26.80
GIT_SILENT
2022-09-15 13:57:50 +01:00
9b5a39922b Update version number for 5.25.90
GIT_SILENT
2022-09-15 11:50:08 +01:00
91db77acc2 Update kf5 version requirement to 5.98.0
GIT_SILENT
2022-09-15 11:10:38 +01:00
5af50ac3ee Add FreeBSD Qt6 CI support 2022-08-27 14:40:53 +02:00
7bfac45da8 Make fully reuse compliant 2022-08-23 21:52:18 +02:00
7bd63669ea Use change signals on Window interface class.
QWaylandLayerSurface pulled data from the Window on startup. The Window
pushed data into the QWaylandLayerSurface on changes. Having two
patterns is a sign of something being off.

This moves everything to a single design, pulling from the public
interface. This allows us to drop a code path that meddles with
QWaylandWindow internals.
2022-06-30 08:09:21 +00:00
13961ef7b9 Update qt5 version requirement to 5.15.2
GIT_SILENT
2022-06-27 10:02:56 +01:00
ff6155a5af Update kf5 version requirement to 5.94
GIT_SILENT
2022-06-27 10:02:56 +01:00
34e7c90c2d Mark required deps as required
BUG: 454912
2022-06-06 12:26:10 +02:00
563b61c75c Update version number for 5.25.80
GIT_SILENT
2022-05-19 12:26:13 +01:00
404e9851d1 Update version number for 5.24.90
GIT_SILENT
2022-05-19 10:41:53 +01:00
345676a4a1 Minor api doc improvement for api.kde.org 2022-05-04 10:43:03 +00:00
ae883df5b1 Build with Qt6 2022-03-06 10:54:56 +01:00
9f8b8c9731 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.
2022-01-26 09:04:14 +01:00
14982d6dc7 Update version number for 5.24.80
GIT_SILENT
2022-01-13 11:56:23 +00:00
e557008b56 Update version number for 5.23.90
GIT_SILENT
2022-01-13 10:34:20 +00:00
80f6a629bb GIT_SILENT: add missing override 2021-10-27 13:43:28 +02:00
662afeba22 Update kf5 version requirement to 5.86
GIT_SILENT
2021-10-11 20:48:40 +01:00
3dac2dd012 Add FreeBSD CI 2021-10-07 01:27:09 +02:00
5b280a4602 Add Linux CI 2021-10-05 15:14:20 +02:00
eb6fb8ab13 Add .kde-ci.yml 2021-10-05 15:14:05 +02:00
06815f2817 Update version number for 5.23.80
GIT_SILENT
2021-09-16 10:34:01 +01:00
dc07e14630 Update version number for 5.22.90
GIT_SILENT
2021-09-16 09:21:32 +01:00
4a439143ba Fix a crash when creating views on the placeholder screen
When a compositor has no outputs listed Qt creates a dummy placeholder
QScreen object that does not represent a wl_output.

This should still be fixed in the clients to not create a view, it's
wasteful and probably will still have plenty of other bugs, hence the
giant warning, but it's still worth guarding.

CCBUG: 439096
2021-09-15 22:55:35 +00:00
331505a4d2 Explicitly set KDE_COMPILERSETTINGS_LEVEL 2021-08-24 22:41:46 +02:00
f6084b2c43 Fix compile with last ecm.
("we have disabled the C and C++ specific compiler extensions.")
2021-06-28 07:51:57 +02:00
9af3c35020 Mark .gitignore file as non-copyrightable 2021-05-21 15:35:56 +02:00
525fa9b819 Update version number for 5.22.80
GIT_SILENT
2021-05-13 15:09:54 +01:00
1021ca5ab5 Update version number for 5.21.90
GIT_SILENT
2021-05-13 10:21:51 +01:00
204eeaf1c9 Update kf5 version requirement to 5.82
GIT_SILENT
2021-05-13 09:56:28 +01:00
42a87ad728 Update .gitignore 2021-05-09 17:54:28 +00:00
7d46bd63c5 Port away from ECMSetupVersion's deprecated *_VERSION_STRING CMake variable
GIT_SILENT
2021-05-04 23:35:44 +02:00
710152a7f3 GIT_SILENT Add auto generated files to .gitignore 2021-05-03 14:54:12 +02:00
8d1aeb7bf1 Store QWaylandLayerShell using a QScopedPointer
This is to ensure that the QWaylandLayerShell will be eventually
destroyed.
2021-04-20 16:02:33 +00:00
93f3ed2c07 Fix a memory leak
The dynamically allocated QtWayland::zwlr_layer_shell_v1 object in
QWaylandLayerShellIntegration::registryLayer() isn't deleted anywhere.
2021-04-20 16:02:33 +00:00
efd32eed53 Add missing parenthesis
This is to make the compiler happier.
2021-04-20 18:38:24 +03:00
11a811061f Introduce KeyboardInteractivity enum 2021-04-20 15:27:43 +03:00
549f5ad682 Link against xkbcommon
Otherwise the build fails with missing xkbcommon headers
2021-04-15 20:46:25 +02:00
cd409ed50e Add width and height to test
This is needed if we are not anchoring to the full screen
2021-04-15 09:59:18 +01:00
2b1219cfdd Ensure we can set per-window properties before the intial commit
In the current implementation we cannot use a LayerShellQt before the
shell surface is created.

At the moment a shell surface is created, the constructor is run and
then QtWayland commits the current state. This means the compositor
configures the window before a client has any chance to set anchors or
margins.

This works whilst we're just being a simple fullscreen window, but won't
scale for plasmashell in the future.

This patch makes LayerShellQt::Window always creatable, and we can set
and cache properties before the platform window is created, just like
one can on QWindow and XDGShell properties.

This also makes it less potentially crashy as ::get always returns a
valid result, and
sets up the public API to be QML-able as an attached property in future.

Co-authored on Aleix's patch for the unit test
2021-04-15 09:58:57 +01:00
29d0078909 Ensure we can set per-window properties before the intial commit
In the current implementation we cannot use a LayerShellQt before the
shell surface is created.

At the moment a shell surface is created, the constructor is run and
then QtWayland commits the current state. This means the compositor
configures the window before a client has any chance to set anchors or
margins.

This works whilst we're just being a simple fullscreen window, but won't
scale for plasmashell in the future.

This patch makes LayerShellQt::Window always creatable, and we can set
and cache properties before the platform window is created, just like
one can on QWindow and XDGShell properties.

This also makes it less potentially crashy as ::get always returns a
valid result, and
sets up the public API to be QML-able as an attached property in future.

Co-authored on Aleix's patch for the unit test
2021-04-14 23:49:30 +01:00
24 changed files with 1024 additions and 193 deletions

29
.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
# SPDX-License-Identifier: CC0-1.0
# SPDX-FileCopyrightText: none
# Ignore the following files
.vscode
*~
*.[oa]
*.diff
*.kate-swp
*.kdev4
.kdev_include_paths
*.kdevelop.pcs
*.moc
*.moc.cpp
*.orig
*.user
.*.swp
.swp.*
Doxyfile
Makefile
avail
random_seed
/build*/
CMakeLists.txt.user*
.clang-format
/compile_commands.json
.clangd
.idea
/cmake-build*
.cache

9
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,9 @@
# SPDX-FileCopyrightText: None
# SPDX-License-Identifier: CC0-1.0
include:
- project: sysadmin/ci-utilities
file:
- /gitlab-templates/reuse-lint.yml
- /gitlab-templates/linux-qt6.yml
- /gitlab-templates/freebsd-qt6.yml

9
.kde-ci.yml Normal file
View File

@ -0,0 +1,9 @@
# SPDX-FileCopyrightText: None
# SPDX-License-Identifier: CC0-1.0
Dependencies:
- 'on': ['@all']
'require':
'frameworks/extra-cmake-modules': '@latest-kf6'
'third-party/wayland': '@latest'
'third-party/wayland-protocols': '@latest'

View File

@ -4,35 +4,42 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(layershellqt) project(layershellqt)
set(PROJECT_VERSION "5.21.80") set(PROJECT_VERSION "6.0.5")
set(PROJECT_VERSION_MAJOR 5) set(PROJECT_VERSION_MAJOR 6)
set(QT_MIN_VERSION "5.15.0") set(CMAKE_C_STANDARD 99)
set(KF5_MIN_VERSION "5.78")
set(CMAKE_CXX_STANDARD 17) set(QT_MIN_VERSION "6.6.0")
set(KF6_MIN_VERSION "6.0.0")
set(KDE_COMPILERSETTINGS_LEVEL "5.82")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS WaylandClient Qml) find_package(ECM ${KF6_MIN_VERSION} REQUIRED NO_MODULE)
find_package(Qt5XkbCommonSupport REQUIRED PRIVATE)
find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${ECM_MODULE_PATH}) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${ECM_MODULE_PATH})
include(KDEInstallDirs) include(KDEInstallDirs)
include(KDECMakeSettings) include(KDECMakeSettings)
include(KDECompilerSettings NO_POLICY_SCOPE) include(KDECompilerSettings NO_POLICY_SCOPE)
include(ECMSetupVersion) include(ECMSetupVersion)
include(ECMDeprecationSettings)
include(ECMGenerateHeaders) include(ECMGenerateHeaders)
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
include(FeatureSummary) include(FeatureSummary)
include(GenerateExportHeader) include(GenerateExportHeader)
include(KDEClangFormat) include(KDEClangFormat)
include(ECMQtDeclareLoggingCategory) include(ECMQtDeclareLoggingCategory)
include(ECMQmlModule)
find_package(WaylandScanner)
find_package(QtWaylandScanner) find_package(Qt6 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS WaylandClient Qml)
find_package(WaylandScanner REQUIRED)
find_package(Wayland 1.3 COMPONENTS Client Server) find_package(Wayland 1.3 COMPONENTS Client Server)
find_package(WaylandProtocols) find_package(WaylandProtocols REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(XKBCOMMON xkbcommon REQUIRED IMPORTED_TARGET)
set_package_properties(Wayland PROPERTIES set_package_properties(Wayland PROPERTIES
TYPE REQUIRED) TYPE REQUIRED)
@ -41,14 +48,19 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu90")
ecm_setup_version(${PROJECT_VERSION} VARIABLE_PREFIX LAYERSHELLQT ecm_setup_version(${PROJECT_VERSION} VARIABLE_PREFIX LAYERSHELLQT
VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/layershellqt_version.h" VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/layershellqt_version.h"
PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/LayerShellQtConfigVersion.cmake" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/LayerShellQtConfigVersion.cmake"
SOVERSION 5) SOVERSION ${PROJECT_VERSION_MAJOR})
file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h) file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h)
kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES}) kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})
ecm_set_disabled_deprecation_versions(QT 6.5
KF 5.240
)
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(tests) add_subdirectory(tests)
set(CMAKECONFIG_INSTALL_DIR ${KDE_INSTALL_LIBDIR}/cmake/LayerShellQt) set(CMAKECONFIG_INSTALL_DIR ${KDE_INSTALL_CMAKEPACKAGEDIR}/LayerShellQt)
install(EXPORT LayerShellQtTargets install(EXPORT LayerShellQtTargets
NAMESPACE LayerShellQt:: NAMESPACE LayerShellQt::
DESTINATION ${CMAKECONFIG_INSTALL_DIR} DESTINATION ${CMAKECONFIG_INSTALL_DIR}

View File

@ -4,6 +4,6 @@
@PACKAGE_INIT@ @PACKAGE_INIT@
include(CMakeFindDependencyMacro) include(CMakeFindDependencyMacro)
find_dependency(Qt5Gui "@QT_MIN_VERSION@") find_dependency(Qt6Gui "@QT_MIN_VERSION@")
include("${CMAKE_CURRENT_LIST_DIR}/LayerShellQtTargets.cmake") include("${CMAKE_CURRENT_LIST_DIR}/LayerShellQtTargets.cmake")

17
metainfo.yaml Normal file
View File

@ -0,0 +1,17 @@
# SPDX-FileCopyrightText: None
# SPDX-License-Identifier: CC0-1.0
maintainer:
- vladz
description: Layer Shell Qt
platforms:
- name: Linux
- name: FreeBSD
portingAid: false
deprecated: false
release: true
group: Plasma
public_lib: true
public_source_dirs:
- src/interfaces

View File

@ -3,10 +3,14 @@
remove_definitions(-DQT_NO_SIGNALS_SLOTS_KEYWORDS) remove_definitions(-DQT_NO_SIGNALS_SLOTS_KEYWORDS)
ecm_add_qtwayland_client_protocol(LAYER_SHELL_SOURCES PROTOCOL ${WaylandProtocols_DATADIR}/stable/xdg-shell/xdg-shell.xml BASENAME xdg-shell) add_library(LayerShellQtInterface)
ecm_add_qtwayland_client_protocol(LAYER_SHELL_SOURCES PROTOCOL wlr-layer-shell-unstable-v1.xml BASENAME wlr-layer-shell-unstable-v1) qt6_generate_wayland_protocol_client_sources(LayerShellQtInterface FILES
${WaylandProtocols_DATADIR}/stable/xdg-shell/xdg-shell.xml
${WaylandProtocols_DATADIR}/staging/xdg-activation/xdg-activation-v1.xml
${CMAKE_CURRENT_SOURCE_DIR}/wlr-layer-shell-unstable-v1.xml
)
ecm_qt_declare_logging_category(LAYER_SHELL_SOURCES ecm_qt_declare_logging_category(LayerShellQtInterface
HEADER HEADER
layershellqt_logging.h layershellqt_logging.h
IDENTIFIER IDENTIFIER
@ -15,19 +19,33 @@ ecm_qt_declare_logging_category(LAYER_SHELL_SOURCES
layershellqt layershellqt
) )
add_library(LayerShellQtInterface SHARED qwaylandlayersurface.cpp interfaces/window.cpp interfaces/shell.cpp qwaylandlayershellintegration.cpp qwaylandlayershell.cpp ${LAYER_SHELL_SOURCES}) target_sources(LayerShellQtInterface PRIVATE
target_link_libraries(LayerShellQtInterface PRIVATE Qt::Gui Qt::WaylandClientPrivate Qt::XkbCommonSupportPrivate Wayland::Client) qwaylandxdgactivationv1.cpp
qwaylandlayersurface.cpp
qwaylandlayershellintegration.cpp
interfaces/window.cpp
interfaces/shell.cpp
)
target_link_libraries(LayerShellQtInterface PUBLIC Qt::Gui)
target_link_libraries(LayerShellQtInterface PRIVATE Qt::WaylandClientPrivate Wayland::Client PkgConfig::XKBCOMMON)
if (TARGET Qt::XkbCommonSupportPrivate)
target_link_libraries(LayerShellQtInterface PRIVATE Qt::XkbCommonSupportPrivate)
endif()
target_include_directories(LayerShellQtInterface PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/LayerShellQt>" target_include_directories(LayerShellQtInterface PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/LayerShellQt>"
INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR}/>" INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR}/>"
) )
set_target_properties(LayerShellQtInterface PROPERTIES VERSION ${LAYERSHELLQT_VERSION_STRING} set_target_properties(LayerShellQtInterface PROPERTIES VERSION ${LAYERSHELLQT_VERSION}
SOVERSION ${LAYERSHELLQT_SOVERSION} SOVERSION ${LAYERSHELLQT_SOVERSION}
EXPORT_NAME Interface EXPORT_NAME Interface
) )
add_library(layer-shell SHARED qwaylandlayershellintegrationplugin.cpp) add_library(layer-shell SHARED qwaylandlayershellintegrationplugin.cpp)
target_link_libraries(layer-shell LayerShellQtInterface Qt::WaylandClient Qt::WaylandClientPrivate Qt::XkbCommonSupportPrivate Wayland::Client) target_link_libraries(layer-shell LayerShellQtInterface Qt::WaylandClient Qt::WaylandClientPrivate Wayland::Client PkgConfig::XKBCOMMON)
if (TARGET Qt::XkbCommonSupportPrivate)
target_link_libraries(layer-shell Qt::XkbCommonSupportPrivate)
endif()
ecm_generate_headers(LayerShellQt_HEADERS ecm_generate_headers(LayerShellQt_HEADERS
HEADER_NAMES HEADER_NAMES
@ -45,7 +63,7 @@ generate_export_header(LayerShellQtInterface
) )
install(TARGETS layer-shell install(TARGETS layer-shell
LIBRARY DESTINATION ${QT_PLUGIN_INSTALL_DIR}/wayland-shell-integration) LIBRARY DESTINATION ${KDE_INSTALL_QTPLUGINDIR}/wayland-shell-integration)
install(TARGETS LayerShellQtInterface EXPORT LayerShellQtTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) install(TARGETS LayerShellQtInterface EXPORT LayerShellQtTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
@ -54,3 +72,5 @@ install(FILES
${CMAKE_CURRENT_BINARY_DIR}/LayerShellQt/layershellqt_export.h ${CMAKE_CURRENT_BINARY_DIR}/LayerShellQt/layershellqt_export.h
DESTINATION ${KDE_INSTALL_INCLUDEDIR}/LayerShellQt COMPONENT Devel DESTINATION ${KDE_INSTALL_INCLUDEDIR}/LayerShellQt COMPONENT Devel
) )
add_subdirectory(declarative)

View File

@ -0,0 +1,10 @@
# SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleix.pol_gonzalez@mercedes-benz.com>
# SPDX-License-Identifier: BSD-3-Clause
ecm_add_qml_module(LayerShellQtQml
URI "org.kde.layershell"
VERSION 1.0
SOURCES layershellqtplugin.cpp)
target_link_libraries(LayerShellQtQml PRIVATE Qt::Qml LayerShellQtInterface)
ecm_finalize_qml_module(LayerShellQtQml DESTINATION ${KDE_INSTALL_QMLDIR})

View File

@ -0,0 +1,24 @@
/*
* SPDX-FileCopyrightText: 2023 Aleix Pol Gonzalez <aleix.pol_gonzalez@mercedes-benz.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include <QQmlExtensionPlugin>
#include "../interfaces/window.h"
#include <qqml.h>
QML_DECLARE_TYPEINFO(LayerShellQt::Window, QML_HAS_ATTACHED_PROPERTIES)
class Plugin : public QQmlExtensionPlugin
{
Q_PLUGIN_METADATA(IID "org.kde.layershellqt")
Q_OBJECT
public:
void registerTypes(const char *uri) override {
Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.layershell"));
qmlRegisterType<LayerShellQt::Window>(uri, 1, 0, "Window");
}
};
#include "layershellqtplugin.moc"

View File

@ -6,8 +6,8 @@
#include "shell.h" #include "shell.h"
#include <QByteArray> #include <QByteArray>
#include <qglobal.h>
#include <layershellqt_logging.h> #include <layershellqt_logging.h>
#include <qglobal.h>
using namespace LayerShellQt; using namespace LayerShellQt;

View File

@ -8,6 +8,8 @@
#define LAYERSHELLQTSHELL_H #define LAYERSHELLQTSHELL_H
#include "layershellqt_export.h" #include "layershellqt_export.h"
#include "window.h"
#include <QString>
namespace LayerShellQt namespace LayerShellQt
{ {

View File

@ -5,68 +5,197 @@
*/ */
#include "window.h" #include "window.h"
#include "../qwaylandlayersurface_p.h" #include "../qwaylandlayershellintegration_p.h"
#include <layershellqt_logging.h> #include <layershellqt_logging.h>
#include <private/qwaylandshellsurface_p.h>
#include <private/qwaylandwindow_p.h> #include <QPointer>
#include <optional>
#include <QtWaylandClient/private/qwaylandwindow_p.h>
using namespace LayerShellQt; using namespace LayerShellQt;
class LayerShellQt::WindowPrivate class LayerShellQt::WindowPrivate
{ {
public: public:
WindowPrivate(QWaylandLayerSurface *surface) WindowPrivate(QWindow *window)
: surface(surface) : parentWindow(window)
{ {
} }
QWaylandLayerSurface *const surface; QWindow *parentWindow;
QString scope = QStringLiteral("window");
Window::Anchors anchors = {Window::AnchorTop | Window::AnchorBottom | Window::AnchorLeft | Window::AnchorRight};
int32_t exclusionZone = 0;
Window::Anchor exclusiveEdge = Window::AnchorNone;
Window::KeyboardInteractivity keyboardInteractivity = Window::KeyboardInteractivityOnDemand;
Window::Layer layer = Window::LayerTop;
QMargins margins;
Window::ScreenConfiguration screenConfiguration = Window::ScreenFromQWindow;
bool closeOnDismissed = true;
}; };
Window::~Window() = default; static QMap<QWindow *, Window *> s_map;
void Window::setAnchor(Anchor anchor) Window::~Window()
{ {
d->surface->setAnchor(anchor); s_map.remove(d->parentWindow);
}
void Window::setAnchors(Anchors anchors)
{
if (d->anchors != anchors) {
d->anchors = anchors;
Q_EMIT anchorsChanged();
}
}
Window::Anchors Window::anchors() const
{
return d->anchors;
} }
void Window::setExclusiveZone(int32_t zone) void Window::setExclusiveZone(int32_t zone)
{ {
d->surface->setExclusiveZone(zone); if (d->exclusionZone != zone) {
d->exclusionZone = zone;
Q_EMIT exclusionZoneChanged();
}
}
int32_t Window::exclusionZone() const
{
return d->exclusionZone;
}
void Window::setExclusiveEdge(Window::Anchor edge)
{
if (d->exclusiveEdge == edge) {
return;
}
d->exclusiveEdge = edge;
Q_EMIT exclusiveEdgeChanged();
}
Window::Anchor Window::exclusiveEdge() const
{
return d->exclusiveEdge;
} }
void Window::setMargins(const QMargins &margins) void Window::setMargins(const QMargins &margins)
{ {
d->surface->setMargins(margins); if (d->margins != margins) {
d->margins = margins;
Q_EMIT marginsChanged();
}
} }
void Window::setKeyboardInteractivity(bool enabled) QMargins Window::margins() const
{ {
d->surface->setKeyboardInteractivity(enabled); return d->margins;
}
void Window::setKeyboardInteractivity(KeyboardInteractivity interactivity)
{
if (d->keyboardInteractivity != interactivity) {
d->keyboardInteractivity = interactivity;
Q_EMIT keyboardInteractivityChanged();
}
}
Window::KeyboardInteractivity Window::keyboardInteractivity() const
{
return d->keyboardInteractivity;
} }
void Window::setLayer(Layer layer) void Window::setLayer(Layer layer)
{ {
d->surface->setLayer(layer); if (d->layer != layer) {
d->layer = layer;
Q_EMIT layerChanged();
}
} }
Window::Window(WindowPrivate *d) void Window::setScope(const QString &scope)
: d(d)
{ {
d->scope = scope;
// this is static and must be set before the platform window is created
}
QString Window::scope() const
{
return d->scope;
}
Window::Layer Window::layer() const
{
return d->layer;
}
Window::ScreenConfiguration Window::screenConfiguration() const
{
return d->screenConfiguration;
}
void Window::setScreenConfiguration(Window::ScreenConfiguration screenConfiguration)
{
d->screenConfiguration = screenConfiguration;
}
bool Window::closeOnDismissed() const
{
return d->closeOnDismissed;
}
void Window::setCloseOnDismissed(bool close)
{
d->closeOnDismissed = close;
}
Window::Window(QWindow *window)
: QObject(window)
, d(new WindowPrivate(window))
{
s_map.insert(d->parentWindow, this);
window->create();
auto waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(window->handle());
if (!waylandWindow) {
qCWarning(LAYERSHELLQT) << window << "is not a wayland window. Not creating zwlr_layer_surface";
return;
}
static QWaylandLayerShellIntegration *shellIntegration = nullptr;
if (!shellIntegration) {
shellIntegration = new QWaylandLayerShellIntegration();
if (!shellIntegration->initialize(waylandWindow->display())) {
delete shellIntegration;
shellIntegration = nullptr;
qCWarning(LAYERSHELLQT) << "Failed to initialize layer-shell integration, possibly because compositor does not support the layer-shell protocol";
return;
}
}
waylandWindow->setShellIntegration(shellIntegration);
} }
Window *Window::get(QWindow *window) Window *Window::get(QWindow *window)
{ {
auto ww = dynamic_cast<QtWaylandClient::QWaylandWindow *>(window->handle()); if (!window) {
if (!ww) {
qCDebug(LAYERSHELLQT) << "window not a wayland window" << window;
return nullptr;
}
QWaylandLayerSurface *s = qobject_cast<QWaylandLayerSurface *>(ww->shellSurface());
if (!s) {
qCDebug(LAYERSHELLQT) << "window not using wlr-layer-shell" << window << ww->shellSurface();
return nullptr; return nullptr;
} }
return new Window(new WindowPrivate(s)); auto layerShellWindow = s_map.value(window);
if (layerShellWindow) {
return layerShellWindow;
}
return new Window(window);
}
Window *Window::qmlAttachedProperties(QObject *object)
{
return get(qobject_cast<QWindow *>(object));
} }

View File

@ -9,6 +9,7 @@
#define LAYERSHELLQTWINDOW_H #define LAYERSHELLQTWINDOW_H
#include <QObject> #include <QObject>
#include <QScreen>
#include <QWindow> #include <QWindow>
#include "layershellqt_export.h" #include "layershellqt_export.h"
@ -20,16 +21,26 @@ class WindowPrivate;
class LAYERSHELLQT_EXPORT Window : public QObject class LAYERSHELLQT_EXPORT Window : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(Anchors anchors READ anchors WRITE setAnchors NOTIFY anchorsChanged)
Q_PROPERTY(QString scope READ scope WRITE setScope)
Q_PROPERTY(QMargins margins READ margins WRITE setMargins NOTIFY marginsChanged)
Q_PROPERTY(qint32 exclusionZone READ exclusionZone WRITE setExclusiveZone NOTIFY exclusionZoneChanged)
Q_PROPERTY(Layer layer READ layer WRITE setLayer NOTIFY layerChanged)
Q_PROPERTY(KeyboardInteractivity keyboardInteractivity READ keyboardInteractivity WRITE setKeyboardInteractivity NOTIFY keyboardInteractivityChanged)
Q_PROPERTY(ScreenConfiguration screenConfiguration READ screenConfiguration WRITE setScreenConfiguration)
public: public:
~Window() override; ~Window() override;
enum Anchor { enum Anchor {
AnchorTop = 1, // the top edge of the anchor rectangle AnchorNone = 0,
AnchorBottom = 2, // the bottom edge of the anchor rectangle AnchorTop = 1, ///< The top edge of the anchor rectangle
AnchorLeft = 4, // the left edge of the anchor rectangle AnchorBottom = 2, ///< The bottom edge of the anchor rectangle
AnchorRight = 8, // the right edge of the anchor rectangle AnchorLeft = 4, ///< The left edge of the anchor rectangle
AnchorRight = 8, ///< The right edge of the anchor rectangle
}; };
Q_ENUM(Anchor); Q_ENUM(Anchor);
Q_DECLARE_FLAGS(Anchors, Anchor)
/** /**
* This enum type is used to specify the layer where a surface can be put in. * This enum type is used to specify the layer where a surface can be put in.
@ -42,16 +53,85 @@ public:
}; };
Q_ENUM(Layer) Q_ENUM(Layer)
void setAnchor(Anchor anchor); /**
void setExclusiveZone(int32_t zone); * This enum type is used to specify how the layer surface handles keyboard focus.
void setMargins(const QMargins &margins); */
void setKeyboardInteractivity(bool enabled); enum KeyboardInteractivity {
void setLayer(Layer layer); KeyboardInteractivityNone = 0,
KeyboardInteractivityExclusive = 1,
KeyboardInteractivityOnDemand = 2,
};
Q_ENUM(KeyboardInteractivity)
/**
* This enum type is used to specify which screen to place the surface on.
* ScreenFromQWindow (the default) reads QWindow::screen() while ScreenFromCompositor
* passes nil and lets the compositor decide.
*/
enum ScreenConfiguration {
ScreenFromQWindow = 0,
ScreenFromCompositor = 1,
};
Q_ENUM(ScreenConfiguration)
void setAnchors(Anchors anchor);
Anchors anchors() const;
void setExclusiveZone(int32_t zone);
int32_t exclusionZone() const;
void setExclusiveEdge(Window::Anchor edge);
Window::Anchor exclusiveEdge() const;
void setMargins(const QMargins &margins);
QMargins margins() const;
void setKeyboardInteractivity(KeyboardInteractivity interactivity);
KeyboardInteractivity keyboardInteractivity() const;
void setLayer(Layer layer);
Layer layer() const;
void setScreenConfiguration(ScreenConfiguration screenConfiguration);
ScreenConfiguration screenConfiguration() const;
/**
* Sets a string based identifier for this window.
* This may be used by a compositor to determine stacking
* order within a given layer.
*
* May also be referred to as a role
*/
void setScope(const QString &scope);
QString scope() const;
/**
* Whether the QWindow should be closed when the layer surface is dismissed by the compositor.
* For example, if the associated screen has been removed.
*
* This can be used to map the window on another screen.
*/
void setCloseOnDismissed(bool close);
bool closeOnDismissed() const;
/**
* Gets the LayerShell Window for a given Qt Window
* Ownership is not transferred
*/
static Window *get(QWindow *window); static Window *get(QWindow *window);
static Window *qmlAttachedProperties(QObject *object);
Q_SIGNALS:
void anchorsChanged();
void exclusionZoneChanged();
void exclusiveEdgeChanged();
void marginsChanged();
void keyboardInteractivityChanged();
void layerChanged();
private: private:
Window(WindowPrivate *d); Window(QWindow *window);
QScopedPointer<WindowPrivate> d; QScopedPointer<WindowPrivate> d;
}; };

View File

@ -1,29 +0,0 @@
/*
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
* SPDX-FileCopyrightText: 2018 Drew DeVault <sir@cmpwn.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "qwaylandlayershell_p.h"
#include "qwaylandlayersurface_p.h"
namespace LayerShellQt
{
QWaylandLayerShell::QWaylandLayerShell(QtWayland::zwlr_layer_shell_v1 *shell)
: QtWayland::zwlr_layer_shell_v1(shell->object())
{
}
QWaylandLayerShell::~QWaylandLayerShell()
{
if (zwlr_layer_shell_v1_get_version(object()) >= ZWLR_LAYER_SHELL_V1_DESTROY_SINCE_VERSION)
zwlr_layer_shell_v1_destroy(object());
}
QWaylandLayerSurface *QWaylandLayerShell::createLayerSurface(QtWaylandClient::QWaylandWindow *window)
{
return new QWaylandLayerSurface(this, window);
}
}

View File

@ -1,32 +0,0 @@
/*
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
* SPDX-FileCopyrightText: 2018 Drew DeVault <sir@cmpwn.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#ifndef _LAYERSHELL_H
#define _LAYERSHELL_H
#include <wayland-client.h>
#include <QtWaylandClient/private/qwaylandshellintegration_p.h>
#include <qwayland-wlr-layer-shell-unstable-v1.h>
#include "qwaylandlayersurface_p.h"
namespace LayerShellQt
{
class LAYERSHELLQT_EXPORT QWaylandLayerShell : public QtWayland::zwlr_layer_shell_v1
{
public:
QWaylandLayerShell(QtWayland::zwlr_layer_shell_v1 *shell);
virtual ~QWaylandLayerShell();
QWaylandLayerSurface *createLayerSurface(QtWaylandClient::QWaylandWindow *window);
// TODO: Popups
};
}
#endif

View File

@ -5,39 +5,32 @@
* SPDX-License-Identifier: LGPL-3.0-or-later * SPDX-License-Identifier: LGPL-3.0-or-later
*/ */
#include "qwaylandlayershell_p.h"
#include "qwaylandlayershellintegration_p.h" #include "qwaylandlayershellintegration_p.h"
#include "qwaylandlayersurface_p.h"
#include "qwaylandxdgactivationv1_p.h"
#include <QtWaylandClient/private/qwaylanddisplay_p.h> #include <QtWaylandClient/private/qwaylanddisplay_p.h>
#include <QtWaylandClient/private/qwaylandwindow_p.h> #include <QtWaylandClient/private/qwaylandwindow_p.h>
#include <qwayland-wlr-layer-shell-unstable-v1.h>
namespace LayerShellQt namespace LayerShellQt
{ {
QWaylandLayerShellIntegration::QWaylandLayerShellIntegration() QWaylandLayerShellIntegration::QWaylandLayerShellIntegration()
: QWaylandShellIntegrationTemplate<QWaylandLayerShellIntegration>(5)
, m_xdgActivation(new QWaylandXdgActivationV1)
{ {
} }
bool QWaylandLayerShellIntegration::initialize(QtWaylandClient::QWaylandDisplay *display) QWaylandLayerShellIntegration::~QWaylandLayerShellIntegration()
{ {
QWaylandShellIntegration::initialize(display); if (object() && zwlr_layer_shell_v1_get_version(object()) >= ZWLR_LAYER_SHELL_V1_DESTROY_SINCE_VERSION) {
display->addRegistryListener(registryLayer, this); zwlr_layer_shell_v1_destroy(object());
return m_layerShell != nullptr; }
} }
QtWaylandClient::QWaylandShellSurface *QWaylandLayerShellIntegration::createShellSurface(QtWaylandClient::QWaylandWindow *window) QtWaylandClient::QWaylandShellSurface *QWaylandLayerShellIntegration::createShellSurface(QtWaylandClient::QWaylandWindow *window)
{ {
return m_layerShell->createLayerSurface(window); return new QWaylandLayerSurface(this, window);
} }
void QWaylandLayerShellIntegration::registryLayer(void *data, struct wl_registry *registry, uint32_t id, const QString &interface, uint32_t version)
{
QWaylandLayerShellIntegration *shell = static_cast<QWaylandLayerShellIntegration *>(data);
if (interface == zwlr_layer_shell_v1_interface.name)
shell->m_layerShell = new QWaylandLayerShell(new QtWayland::zwlr_layer_shell_v1(registry, id, std::min(version, 3u)));
}
} }
//#include "qwaylandlayershellintegration.moc"

View File

@ -8,27 +8,26 @@
#ifndef _LAYERSHELLINTEGRATION_P_H #ifndef _LAYERSHELLINTEGRATION_P_H
#define _LAYERSHELLINTEGRATION_P_H #define _LAYERSHELLINTEGRATION_P_H
#include <wayland-client.h>
#include "layershellqt_export.h" #include "layershellqt_export.h"
#include <QtWaylandClient/private/qwaylandshellintegration_p.h> #include <QtWaylandClient/private/qwaylandshellintegration_p.h>
#include <qwayland-wlr-layer-shell-unstable-v1.h>
class QWaylandXdgActivationV1;
namespace LayerShellQt namespace LayerShellQt
{ {
class QWaylandLayerShell;
class LAYERSHELLQT_EXPORT QWaylandLayerShellIntegration : public QtWaylandClient::QWaylandShellIntegration class LAYERSHELLQT_EXPORT QWaylandLayerShellIntegration : public QtWaylandClient::QWaylandShellIntegrationTemplate<QWaylandLayerShellIntegration>, public QtWayland::zwlr_layer_shell_v1
{ {
public: public:
QWaylandLayerShellIntegration(); QWaylandLayerShellIntegration();
~QWaylandLayerShellIntegration() override;
bool initialize(QtWaylandClient::QWaylandDisplay *display) override; QWaylandXdgActivationV1 *activation() const { return m_xdgActivation.data(); }
QtWaylandClient::QWaylandShellSurface *createShellSurface(QtWaylandClient::QWaylandWindow *window) override; QtWaylandClient::QWaylandShellSurface *createShellSurface(QtWaylandClient::QWaylandWindow *window) override;
private: private:
static void registryLayer(void *data, struct wl_registry *registry, uint32_t id, const QString &interface, uint32_t version); QScopedPointer<QWaylandXdgActivationV1> m_xdgActivation;
QWaylandLayerShell *m_layerShell = nullptr;
}; };
} }

View File

@ -5,35 +5,83 @@
* SPDX-License-Identifier: LGPL-3.0-or-later * SPDX-License-Identifier: LGPL-3.0-or-later
*/ */
#include "qwaylandlayershell_p.h" #include "interfaces/window.h"
#include "layershellqt_logging.h"
#include "qwaylandlayersurface_p.h" #include "qwaylandlayersurface_p.h"
#include "qwaylandxdgactivationv1_p.h"
#include <QtWaylandClient/private/qwaylandscreen_p.h> #include <QtWaylandClient/private/qwaylandscreen_p.h>
#include <QtWaylandClient/private/qwaylandsurface_p.h> #include <QtWaylandClient/private/qwaylandsurface_p.h>
#include <QtWaylandClient/private/qwaylandwindow_p.h> #include <QtWaylandClient/private/qwaylandwindow_p.h>
#include <QGuiApplication>
namespace LayerShellQt namespace LayerShellQt
{ {
QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShell *shell, QtWaylandClient::QWaylandWindow *window) QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShellIntegration *shell, QtWaylandClient::QWaylandWindow *window)
: QtWaylandClient::QWaylandShellSurface(window) : QtWaylandClient::QWaylandShellSurface(window)
, QtWayland::zwlr_layer_surface_v1( , QtWayland::zwlr_layer_surface_v1()
// TODO: Specify namespace , m_shell(shell)
shell->get_layer_surface(window->waylandSurface()->object(), , m_interface(Window::get(window->window()))
window->waylandScreen()->output(), , m_window(window)
QtWayland::zwlr_layer_shell_v1::layer_top,
QStringLiteral("qt")))
{ {
set_anchor(anchor_top | anchor_bottom | anchor_left | anchor_right); wl_output *output = nullptr;
if (m_interface->screenConfiguration() == Window::ScreenFromQWindow) {
auto waylandScreen = dynamic_cast<QtWaylandClient::QWaylandScreen *>(window->window()->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(), output, m_interface->layer(), m_interface->scope()));
connect(m_interface, &Window::layerChanged, this, [this]() {
setLayer(m_interface->layer());
});
setAnchor(m_interface->anchors());
connect(m_interface, &Window::anchorsChanged, this, [this]() {
setAnchor(m_interface->anchors());
setDesiredSize(m_window->windowContentGeometry().size());
});
setExclusiveZone(m_interface->exclusionZone());
connect(m_interface, &Window::exclusionZoneChanged, this, [this]() {
setExclusiveZone(m_interface->exclusionZone());
});
setExclusiveEdge(m_interface->exclusiveEdge());
connect(m_interface, &Window::exclusiveEdgeChanged, this, [this]() {
setExclusiveEdge(m_interface->exclusiveEdge());
});
setMargins(m_interface->margins());
connect(m_interface, &Window::marginsChanged, this, [this]() {
setMargins(m_interface->margins());
});
setKeyboardInteractivity(m_interface->keyboardInteractivity());
connect(m_interface, &Window::keyboardInteractivityChanged, this, [this]() {
setKeyboardInteractivity(m_interface->keyboardInteractivity());
});
setDesiredSize(window->windowContentGeometry().size());
} }
QWaylandLayerSurface::~QWaylandLayerSurface() QWaylandLayerSurface::~QWaylandLayerSurface()
{ {
if (m_waitForSyncCallback) {
wl_callback_destroy(m_waitForSyncCallback);
}
destroy(); destroy();
} }
void QWaylandLayerSurface::zwlr_layer_surface_v1_closed() void QWaylandLayerSurface::zwlr_layer_surface_v1_closed()
{ {
window()->window()->close(); if (m_interface->closeOnDismissed()) {
window()->window()->close();
}
} }
void QWaylandLayerSurface::zwlr_layer_surface_v1_configure(uint32_t serial, uint32_t width, uint32_t height) void QWaylandLayerSurface::zwlr_layer_surface_v1_configure(uint32_t serial, uint32_t width, uint32_t height)
@ -43,8 +91,8 @@ void QWaylandLayerSurface::zwlr_layer_surface_v1_configure(uint32_t serial, uint
if (!m_configured) { if (!m_configured) {
m_configured = true; m_configured = true;
window()->resizeFromApplyConfigure(m_pendingSize); applyConfigure();
window()->handleExpose(QRect(QPoint(), m_pendingSize)); sendExpose();
} else { } else {
// Later configures are resizes, so we have to queue them up for a time when we // Later configures are resizes, so we have to queue them up for a time when we
// are not painting to the window. // are not painting to the window.
@ -52,9 +100,37 @@ void QWaylandLayerSurface::zwlr_layer_surface_v1_configure(uint32_t serial, uint
} }
} }
void QWaylandLayerSurface::attachPopup(QtWaylandClient::QWaylandShellSurface *popup)
{
std::any anyRole = popup->surfaceRole();
if (auto role = std::any_cast<::xdg_popup *>(&anyRole)) {
get_popup(*role);
} else {
qCWarning(LAYERSHELLQT) << "Cannot attach popup of unknown type";
}
}
void QWaylandLayerSurface::applyConfigure() void QWaylandLayerSurface::applyConfigure()
{ {
m_configuring = true;
window()->resizeFromApplyConfigure(m_pendingSize); window()->resizeFromApplyConfigure(m_pendingSize);
m_configuring = false;
}
void QWaylandLayerSurface::setDesiredSize(const QSize &size)
{
const bool horizontallyConstrained = m_interface->anchors().testFlags({Window::AnchorLeft, Window::AnchorRight});
const bool verticallyConstrained = m_interface->anchors().testFlags({Window::AnchorTop, Window::AnchorBottom});
QSize effectiveSize = size;
if (horizontallyConstrained) {
effectiveSize.setWidth(0);
}
if (verticallyConstrained) {
effectiveSize.setHeight(0);
}
set_size(effectiveSize.width(), effectiveSize.height());
} }
void QWaylandLayerSurface::setAnchor(uint anchor) void QWaylandLayerSurface::setAnchor(uint anchor)
@ -67,14 +143,21 @@ void QWaylandLayerSurface::setExclusiveZone(int32_t zone)
set_exclusive_zone(zone); set_exclusive_zone(zone);
} }
void QWaylandLayerSurface::setExclusiveEdge(uint32_t edge)
{
if (zwlr_layer_surface_v1_get_version(object()) >= ZWLR_LAYER_SURFACE_V1_SET_EXCLUSIVE_EDGE_SINCE_VERSION) {
set_exclusive_edge(edge);
}
}
void QWaylandLayerSurface::setMargins(const QMargins &margins) void QWaylandLayerSurface::setMargins(const QMargins &margins)
{ {
set_margin(margins.top(), margins.right(), margins.bottom(), margins.left()); set_margin(margins.top(), margins.right(), margins.bottom(), margins.left());
} }
void QWaylandLayerSurface::setKeyboardInteractivity(bool enabled) void QWaylandLayerSurface::setKeyboardInteractivity(uint32_t interactivity)
{ {
set_keyboard_interactivity(enabled); set_keyboard_interactivity(interactivity);
} }
void QWaylandLayerSurface::setLayer(uint32_t layer) void QWaylandLayerSurface::setLayer(uint32_t layer)
@ -83,4 +166,100 @@ void QWaylandLayerSurface::setLayer(uint32_t layer)
set_layer(layer); set_layer(layer);
} }
void QWaylandLayerSurface::setWindowGeometry(const QRect &geometry)
{
if (m_configuring) {
return;
}
setDesiredSize(geometry.size());
requestWaylandSync();
} }
bool QWaylandLayerSurface::requestActivate()
{
QWaylandXdgActivationV1 *activation = m_shell->activation();
if (!activation->isActive()) {
return false;
}
if (!m_activationToken.isEmpty()) {
activation->activate(m_activationToken, window()->wlSurface());
m_activationToken = {};
return true;
} else {
const auto focusWindow = QGuiApplication::focusWindow();
const auto wlWindow = focusWindow ? static_cast<QtWaylandClient::QWaylandWindow*>(focusWindow->handle()) : window();
if (const auto seat = wlWindow->display()->lastInputDevice()) {
const auto tokenProvider = activation->requestXdgActivationToken(
wlWindow->display(), wlWindow->wlSurface(), 0, QString());
connect(tokenProvider, &QWaylandXdgActivationTokenV1::done, this,
[this](const QString &token) {
m_shell->activation()->activate(token, window()->wlSurface());
});
connect(tokenProvider, &QWaylandXdgActivationTokenV1::done, tokenProvider, &QObject::deleteLater);
return true;
}
}
return false;
}
void QWaylandLayerSurface::setXdgActivationToken(const QString &token)
{
m_activationToken = token;
}
void QWaylandLayerSurface::requestXdgActivationToken(quint32 serial)
{
QWaylandXdgActivationV1 *activation = m_shell->activation();
if (!activation->isActive()) {
return;
}
auto tokenProvider = activation->requestXdgActivationToken(
window()->display(), window()->wlSurface(), serial, QString());
connect(tokenProvider, &QWaylandXdgActivationTokenV1::done, this,
[this](const QString &token) {
Q_EMIT window()->xdgActivationTokenCreated(token);
});
connect(tokenProvider, &QWaylandXdgActivationTokenV1::done, tokenProvider, &QObject::deleteLater);
}
const wl_callback_listener QWaylandLayerSurface::syncCallbackListener = {
.done = [](void *data, struct wl_callback *callback, uint32_t time){
Q_UNUSED(time);
wl_callback_destroy(callback);
QWaylandLayerSurface *layerSurface = static_cast<QWaylandLayerSurface *>(data);
layerSurface->m_waitForSyncCallback = nullptr;
layerSurface->sendExpose();
}
};
void QWaylandLayerSurface::requestWaylandSync()
{
if (m_waitForSyncCallback) {
return;
}
m_waitForSyncCallback = wl_display_sync(m_window->display()->wl_display());
wl_callback_add_listener(m_waitForSyncCallback, &syncCallbackListener, this);
}
void QWaylandLayerSurface::handleWaylandSyncDone()
{
if (!window()->isExposed()) {
return;
}
sendExpose();
}
void QWaylandLayerSurface::sendExpose()
{
#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0)
window()->handleExpose(QRect(QPoint(), m_pendingSize));
#else
window()->sendRecursiveExposeEvent();
#endif
}
}

View File

@ -10,40 +10,63 @@
#include <wayland-client.h> #include <wayland-client.h>
#include "qwaylandlayershellintegration_p.h"
#include "layershellqt_export.h" #include "layershellqt_export.h"
#include <QtWaylandClient/private/qwaylandshellsurface_p.h> #include <QtWaylandClient/private/qwaylandshellsurface_p.h>
#include <qwayland-wlr-layer-shell-unstable-v1.h> #include <qwayland-wlr-layer-shell-unstable-v1.h>
namespace LayerShellQt namespace LayerShellQt
{ {
class QWaylandLayerShell;
class Window;
class LAYERSHELLQT_EXPORT QWaylandLayerSurface : public QtWaylandClient::QWaylandShellSurface, public QtWayland::zwlr_layer_surface_v1 class LAYERSHELLQT_EXPORT QWaylandLayerSurface : public QtWaylandClient::QWaylandShellSurface, public QtWayland::zwlr_layer_surface_v1
{ {
Q_OBJECT Q_OBJECT
public: public:
QWaylandLayerSurface(QWaylandLayerShell *shell, QtWaylandClient::QWaylandWindow *window); QWaylandLayerSurface(QWaylandLayerShellIntegration *shell, QtWaylandClient::QWaylandWindow *window);
virtual ~QWaylandLayerSurface(); ~QWaylandLayerSurface() override;
bool isExposed() const override bool isExposed() const override
{ {
return m_configured; return m_configured && !m_waitForSyncCallback;
} }
void attachPopup(QtWaylandClient::QWaylandShellSurface *popup) override;
void setDesiredSize(const QSize &size);
void setAnchor(uint32_t anchor); void setAnchor(uint32_t anchor);
void setExclusiveZone(int32_t zone); void setExclusiveZone(int32_t zone);
void setExclusiveEdge(uint32_t edge);
void setMargins(const QMargins &margins); void setMargins(const QMargins &margins);
void setKeyboardInteractivity(bool enabled); void setKeyboardInteractivity(uint32_t interactivity);
void setLayer(uint32_t layer); void setLayer(uint32_t layer);
void applyConfigure() override; void applyConfigure() override;
void setWindowGeometry(const QRect &geometry) override;
bool requestActivate() override;
void setXdgActivationToken(const QString &token) override;
void requestXdgActivationToken(quint32 serial) override;
private: private:
void requestWaylandSync();
void handleWaylandSyncDone();
void sendExpose();
void zwlr_layer_surface_v1_configure(uint32_t serial, uint32_t width, uint32_t height) override; void zwlr_layer_surface_v1_configure(uint32_t serial, uint32_t width, uint32_t height) override;
void zwlr_layer_surface_v1_closed() override; void zwlr_layer_surface_v1_closed() override;
QWaylandLayerShellIntegration *m_shell;
LayerShellQt::Window *m_interface;
QtWaylandClient::QWaylandWindow *m_window;
QSize m_pendingSize; QSize m_pendingSize;
QString m_activationToken;
bool m_configured = false; bool m_configured = false;
bool m_configuring = false;
static const wl_callback_listener syncCallbackListener;
struct wl_callback *m_waitForSyncCallback = nullptr;
}; };
} }

View File

@ -0,0 +1,44 @@
/** Copyright (C) 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "qwaylandxdgactivationv1_p.h"
#include <QtWaylandClient/private/qwaylanddisplay_p.h>
#include <QtWaylandClient/private/qwaylandinputdevice_p.h>
QWaylandXdgActivationV1::QWaylandXdgActivationV1()
: QWaylandClientExtensionTemplate<QWaylandXdgActivationV1>(1)
{
initialize();
}
QWaylandXdgActivationV1::~QWaylandXdgActivationV1()
{
if (isActive()) {
destroy();
}
}
QWaylandXdgActivationTokenV1 *QWaylandXdgActivationV1::requestXdgActivationToken(QtWaylandClient::QWaylandDisplay *display,
struct ::wl_surface *surface,
std::optional<uint32_t> serial,
const QString &app_id)
{
auto wl = get_activation_token();
auto provider = new QWaylandXdgActivationTokenV1;
provider->init(wl);
if (surface) {
provider->set_surface(surface);
}
if (!app_id.isEmpty()) {
provider->set_app_id(app_id);
}
if (serial && display->lastInputDevice()) {
provider->set_serial(*serial, display->lastInputDevice()->wl_seat());
}
provider->commit();
return provider;
}
#include "moc_qwaylandxdgactivationv1_p.cpp"

View File

@ -0,0 +1,48 @@
/** Copyright (C) 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#ifndef QWAYLANDXDGACTIVATIONV1_P_H
#define QWAYLANDXDGACTIVATIONV1_P_H
#include "qwayland-xdg-activation-v1.h"
#include <QObject>
#include <QtWaylandClient/QWaylandClientExtension>
namespace QtWaylandClient
{
class QWaylandDisplay;
class QWaylandSurface;
}
class QWaylandXdgActivationTokenV1 : public QObject, public QtWayland::xdg_activation_token_v1
{
Q_OBJECT
public:
~QWaylandXdgActivationTokenV1() override
{
destroy();
}
protected:
void xdg_activation_token_v1_done(const QString &token) override
{
Q_EMIT done(token);
}
Q_SIGNALS:
void done(const QString &token);
};
class QWaylandXdgActivationV1 : public QWaylandClientExtensionTemplate<QWaylandXdgActivationV1>, public QtWayland::xdg_activation_v1
{
public:
QWaylandXdgActivationV1();
~QWaylandXdgActivationV1() override;
QWaylandXdgActivationTokenV1 *
requestXdgActivationToken(QtWaylandClient::QWaylandDisplay *display, struct ::wl_surface *surface, std::optional<uint32_t> serial, const QString &app_id);
};
#endif // QWAYLANDXDGACTIVATIONV1_P_H

View File

@ -25,7 +25,7 @@
THIS SOFTWARE. THIS SOFTWARE.
</copyright> </copyright>
<interface name="zwlr_layer_shell_v1" version="3"> <interface name="zwlr_layer_shell_v1" version="5">
<description summary="create surfaces that are layers of the desktop"> <description summary="create surfaces that are layers of the desktop">
Clients can use this interface to assign the surface_layer role to Clients can use this interface to assign the surface_layer role to
wl_surfaces. Such surfaces are assigned to a "layer" of the output and wl_surfaces. Such surfaces are assigned to a "layer" of the output and
@ -100,7 +100,7 @@
</request> </request>
</interface> </interface>
<interface name="zwlr_layer_surface_v1" version="3"> <interface name="zwlr_layer_surface_v1" version="5">
<description summary="layer metadata interface"> <description summary="layer metadata interface">
An interface that may be implemented by a wl_surface, for surfaces that An interface that may be implemented by a wl_surface, for surfaces that
are designed to be rendered as a layer of a stacked desktop-like are designed to be rendered as a layer of a stacked desktop-like
@ -203,21 +203,85 @@
<arg name="left" type="int"/> <arg name="left" type="int"/>
</request> </request>
<enum name="keyboard_interactivity">
<description summary="types of keyboard interaction possible for a layer shell surface">
Types of keyboard interaction possible for layer shell surfaces. The
rationale for this is twofold: (1) some applications are not interested
in keyboard events and not allowing them to be focused can improve the
desktop experience; (2) some applications will want to take exclusive
keyboard focus.
</description>
<entry name="none" value="0">
<description summary="no keyboard focus is possible">
This value indicates that this surface is not interested in keyboard
events and the compositor should never assign it the keyboard focus.
This is the default value, set for newly created layer shell surfaces.
This is useful for e.g. desktop widgets that display information or
only have interaction with non-keyboard input devices.
</description>
</entry>
<entry name="exclusive" value="1">
<description summary="request exclusive keyboard focus">
Request exclusive keyboard focus if this surface is above the shell surface layer.
For the top and overlay layers, the seat will always give
exclusive keyboard focus to the top-most layer which has keyboard
interactivity set to exclusive. If this layer contains multiple
surfaces with keyboard interactivity set to exclusive, the compositor
determines the one receiving keyboard events in an implementation-
defined manner. In this case, no guarantee is made when this surface
will receive keyboard focus (if ever).
For the bottom and background layers, the compositor is allowed to use
normal focus semantics.
This setting is mainly intended for applications that need to ensure
they receive all keyboard events, such as a lock screen or a password
prompt.
</description>
</entry>
<entry name="on_demand" value="2" since="4">
<description summary="request regular keyboard focus semantics">
This requests the compositor to allow this surface to be focused and
unfocused by the user in an implementation-defined manner. The user
should be able to unfocus this surface even regardless of the layer
it is on.
Typically, the compositor will want to use its normal mechanism to
manage keyboard focus between layer shell surfaces with this setting
and regular toplevels on the desktop layer (e.g. click to focus).
Nevertheless, it is possible for a compositor to require a special
interaction to focus or unfocus layer shell surfaces (e.g. requiring
a click even if focus follows the mouse normally, or providing a
keybinding to switch focus between layers).
This setting is mainly intended for desktop shell components (e.g.
panels) that allow keyboard interaction. Using this option can allow
implementing a desktop shell that can be fully usable without the
mouse.
</description>
</entry>
</enum>
<request name="set_keyboard_interactivity"> <request name="set_keyboard_interactivity">
<description summary="requests keyboard events"> <description summary="requests keyboard events">
Set to 1 to request that the seat send keyboard events to this layer Set how keyboard events are delivered to this surface. By default,
surface. For layers below the shell surface layer, the seat will use layer shell surfaces do not receive keyboard events; this request can
normal focus semantics. For layers above the shell surface layers, the be used to change this.
seat will always give exclusive keyboard focus to the top-most layer
which has keyboard interactivity set to true. This setting is inherited by child surfaces set by the get_popup
request.
Layer surfaces receive pointer, touch, and tablet events normally. If Layer surfaces receive pointer, touch, and tablet events normally. If
you do not want to receive them, set the input region on your surface you do not want to receive them, set the input region on your surface
to an empty region. to an empty region.
Events is double-buffered, see wl_surface.commit. Keyboard interactivity is double-buffered, see wl_surface.commit.
</description> </description>
<arg name="keyboard_interactivity" type="uint"/> <arg name="keyboard_interactivity" type="uint" enum="keyboard_interactivity"/>
</request> </request>
<request name="get_popup"> <request name="get_popup">
@ -302,6 +366,8 @@
<entry name="invalid_surface_state" value="0" summary="provided surface state is invalid"/> <entry name="invalid_surface_state" value="0" summary="provided surface state is invalid"/>
<entry name="invalid_size" value="1" summary="size is invalid"/> <entry name="invalid_size" value="1" summary="size is invalid"/>
<entry name="invalid_anchor" value="2" summary="anchor bitfield is invalid"/> <entry name="invalid_anchor" value="2" summary="anchor bitfield is invalid"/>
<entry name="invalid_keyboard_interactivity" value="3" summary="keyboard interactivity is invalid"/>
<entry name="invalid_exclusive_edge" value="4" summary="exclusive edge is invalid given the surface anchors"/>
</enum> </enum>
<enum name="anchor" bitfield="true"> <enum name="anchor" bitfield="true">
@ -321,5 +387,21 @@
</description> </description>
<arg name="layer" type="uint" enum="zwlr_layer_shell_v1.layer" summary="layer to move this surface to"/> <arg name="layer" type="uint" enum="zwlr_layer_shell_v1.layer" summary="layer to move this surface to"/>
</request> </request>
<!-- Version 5 additions -->
<request name="set_exclusive_edge" since="5">
<description summary="set the edge the exclusive zone will be applied to">
Requests an edge for the exclusive zone to apply. The exclusive
edge will be automatically deduced from anchor points when possible,
but when the surface is anchored to a corner, it will be necessary
to set it explicitly to disambiguate, as it is not possible to deduce
which one of the two corner edges should be used.
The edge must be one the surface is anchored to, otherwise the
invalid_exclusive_edge protocol error will be raised.
</description>
<arg name="edge" type="uint"/>
</request>
</interface> </interface>
</protocol> </protocol>

View File

@ -4,35 +4,108 @@
* SPDX-License-Identifier: LGPL-3.0-or-later * SPDX-License-Identifier: LGPL-3.0-or-later
*/ */
#include <QCommandLineParser>
#include <QGuiApplication> #include <QGuiApplication>
#include <QQmlApplicationEngine> #include <QPainter>
#include <interfaces/shell.h> #include <QRasterWindow>
#include <QTimer>
#include <QWindow>
#include <QMetaEnum>
#include <interfaces/window.h> #include <interfaces/window.h>
using namespace LayerShellQt;
QStringList enumsToStringList(QMetaEnum metaEnum)
{
QStringList ret;
ret.reserve(metaEnum.keyCount());
for (int i = 0; i < metaEnum.keyCount(); ++i) {
ret.append(metaEnum.key(i));
}
return ret;
}
template<typename T>
T stringToEnum(QMetaEnum metaEnum, const QString &str)
{
T ret = {};
const auto splitted = str.split(QLatin1Char('|'), Qt::SkipEmptyParts);
for (const auto &value : splitted) {
ret |= T(metaEnum.keyToValue(qPrintable(value)));
}
return ret;
}
class BasicWindow : public QRasterWindow
{
void paintEvent(QPaintEvent *) override
{
QPainter p(this);
p.fillRect(QRect(0, 0, width(), height()), Qt::red);
}
};
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
LayerShellQt::Shell::useLayerShell();
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.loadData(
"import QtQuick.Controls 2.10\n"
"import QtQuick 2.10\n"
"\n"
"ApplicationWindow {"
" width: 100; height: 100\n"
" visible: true\n"
" Rectangle { color: 'red'; anchors.fill: parent }"
"}"
, const auto layerMetaEnum = QMetaEnum::fromType<Window::Layer>();
QStringLiteral("bananaland:/potato.qml")); const auto anchorMetaEnum = QMetaEnum::fromType<Window::Anchor>();
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [](QObject *object) { QCommandLineParser parser;
auto layerWindow = LayerShellQt::Window::get(qobject_cast<QWindow *>(object)); QCommandLineOption marginsOption(QStringLiteral("margins"), QStringLiteral("Window margins"), QStringLiteral("pixels"), QStringLiteral("0"));
Q_ASSERT(layerWindow); QCommandLineOption scopeOption(QStringLiteral("scope"), QStringLiteral("Window scope"), QStringLiteral("namespace"), QStringLiteral("normal"));
layerWindow->setMargins({50, 50, 50, 50}); QCommandLineOption anchorsOption(QStringLiteral("anchors"),
}); QStringLiteral("Either ") + enumsToStringList(anchorMetaEnum).join(QLatin1String("|")),
QStringLiteral("anchors"),
QStringLiteral("AnchorTop|AnchorBottom|AnchorLeft|AnchorRight"));
QCommandLineOption layerOption(QStringLiteral("layer"),
QStringLiteral("One of ") + enumsToStringList(layerMetaEnum).join(QLatin1String("|")),
QStringLiteral("layer"),
QStringLiteral("LayerTop"));
QCommandLineOption widthOption(QStringLiteral("width"), QStringLiteral("Width of the window"), QStringLiteral("pixels"), QStringLiteral("0"));
QCommandLineOption heightOption(QStringLiteral("height"), QStringLiteral("Height of the window"), QStringLiteral("pixels"), QStringLiteral("0"));
parser.addOptions({marginsOption, scopeOption, anchorsOption, layerOption, widthOption, heightOption});
parser.addHelpOption();
parser.process(app);
BasicWindow window;
LayerShellQt::Window *layerShell = LayerShellQt::Window::get(&window);
layerShell->setLayer(Window::LayerBottom);
if (parser.isSet(marginsOption)) {
int margins = parser.value(marginsOption).toInt();
layerShell->setMargins({margins, margins, margins, margins});
}
if (parser.isSet(scopeOption)) {
layerShell->setScope(parser.value(scopeOption));
}
if (parser.isSet(layerOption)) {
layerShell->setLayer(Window::Layer(layerMetaEnum.keyToValue(qPrintable(parser.value(layerOption)))));
}
if (parser.isSet(anchorsOption)) {
layerShell->setAnchors(stringToEnum<Window::Anchors>(anchorMetaEnum, parser.value(anchorsOption)));
}
if (parser.isSet(widthOption)) {
window.setWidth(parser.value(widthOption).toInt());
}
if (parser.isSet(heightOption)) {
window.setHeight(parser.value(heightOption).toInt());
}
window.show();
BasicWindow window2;
window2.resize(400, 400);
window2.show();
// just so you don't block yourself out whilst testing
QTimer::singleShot(5000, &app, &QGuiApplication::quit);
return app.exec(); return app.exec();
} }

110
tests/quicktest.qml Normal file
View File

@ -0,0 +1,110 @@
/*
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleix.pol_gonzalez@mercedes-benz.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
import QtQuick 2.15
import org.kde.layershell 1.0 as LayerShell
Item
{
Text {
text: "A normal Window"
anchors.centerIn: parent
}
Window {
LayerShell.Window.anchors: LayerShell.Window.AnchorLeft
LayerShell.Window.layer: LayerShell.Window.LayerBackground
LayerShell.Window.exclusionZone: -1
width: 200
height: 150
Rectangle {
anchors.fill: parent
color: "green"
Text {
anchors.centerIn: parent
text: "left bg"
}
}
visible: true
}
Window {
LayerShell.Window.scope: "dock"
LayerShell.Window.anchors: LayerShell.Window.AnchorLeft
LayerShell.Window.layer: LayerShell.Window.LayerTop
LayerShell.Window.exclusionZone: width
width: 100
height: 100
Rectangle {
anchors.fill: parent
color: "red"
Text {
anchors.centerIn: parent
text: "left"
}
}
visible: true
}
Window {
LayerShell.Window.scope: "normal"
LayerShell.Window.anchors: LayerShell.Window.AnchorRight
width: 100
height: 100
Rectangle {
anchors.fill: parent
color: "red"
Text {
anchors.centerIn: parent
text: "right"
}
}
visible: true
}
Window {
LayerShell.Window.scope: "normal"
LayerShell.Window.anchors: LayerShell.Window.AnchorTop
width: 100
height: 100
Rectangle {
anchors.fill: parent
color: "red"
Text {
anchors.centerIn: parent
text: "top"
}
}
visible: true
}
Window {
LayerShell.Window.scope: "normal"
LayerShell.Window.anchors: LayerShell.Window.AnchorBottom
width: 100
height: 100
Rectangle {
anchors.fill: parent
color: "red"
Text {
anchors.centerIn: parent
text: "bottom"
}
}
visible: true
}
}