Skip to content

Commit 17e3a14

Browse files
committed
Mostly working
1 parent dfca280 commit 17e3a14

16 files changed

+529
-61
lines changed

lib/Wm/wayland/waylandbackend.cpp

+33-33
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
#include <wayland-client.h>
2929

30-
#include <Shell>
30+
#include <layershellwindow.h>
3131
#include <tlogger.h>
3232

3333
#include "waylandwindow.h"
@@ -46,11 +46,11 @@ WaylandBackend::WaylandBackend() : WmBackend() {
4646
d->parent = this;
4747
d->accessibility = new WaylandAccessibility(this);
4848

49-
LayerShellQt::Shell::useLayerShell();
49+
// LayerShellQt::Shell::useLayerShell();
50+
qputenv("QT_WAYLAND_SHELL_INTEGRATION", "tdesktopenvironment-layer-shell");
5051

5152
d->display = reinterpret_cast<wl_display*>(qApp->platformNativeInterface()->nativeResourceForIntegration("display"));
5253

53-
5454
wl_registry_listener listener = {
5555
[](void* data, wl_registry * registry, quint32 name, const char* interface, quint32 version) {
5656
if (strcmp(interface, zwlr_foreign_toplevel_manager_v1_interface.name) == 0) {
@@ -144,29 +144,31 @@ void WaylandBackend::setSystemWindow(QWidget* widget) {
144144
}
145145

146146
void WaylandBackend::setSystemWindow(QWidget* widget, DesktopWm::SystemWindowType windowType) {
147-
//TODO: Implement
148147
widget->show();
149-
LayerShellQt::Window* layerWindow = LayerShellQt::Window::get(widget->windowHandle());
150-
layerWindow->setKeyboardInteractivity(LayerShellQt::Window::KeyboardInteractivityOnDemand);
148+
LayerShellWindow* layerWindow = LayerShellWindow::forWindow(widget->windowHandle());
149+
layerWindow->setKeyboardInteractivity(LayerShellWindow::OnDemand);
151150

152151
switch (windowType) {
153152
case DesktopWm::SystemWindowTypeSkipTaskbarOnly:
154153
break;
155154
case DesktopWm::SystemWindowTypeDesktop:
156-
layerWindow->setLayer(LayerShellQt::Window::LayerBackground);
157-
// layerWindow->setAnchors(static_cast<LayerShellQt::Window::Anchors>(LayerShellQt::Window::AnchorLeft | LayerShellQt::Window::AnchorBottom | LayerShellQt::Window::AnchorRight | LayerShellQt::Window::AnchorTop));
155+
layerWindow->setLayer(LayerShellWindow::Background);
156+
layerWindow->setExclusiveZone(-1);
157+
layerWindow->setKeyboardInteractivity(LayerShellWindow::None);
158158
break;
159159
case DesktopWm::SystemWindowTypeTaskbar:
160-
layerWindow->setLayer(LayerShellQt::Window::LayerTop);
161-
// layerWindow->setAnchors(LayerShellQt::Window::AnchorTop);
160+
layerWindow->setLayer(LayerShellWindow::Top);
161+
layerWindow->setAnchors(LayerShellWindow::AnchorTop);
162162
break;
163163
case DesktopWm::SystemWindowTypeNotification:
164-
layerWindow->setLayer(LayerShellQt::Window::LayerOverlay);
164+
layerWindow->setLayer(LayerShellWindow::Overlay);
165165
layerWindow->setExclusiveZone(0);
166166
break;
167167
case DesktopWm::SystemWindowTypeMenu:
168-
layerWindow->setLayer(LayerShellQt::Window::LayerOverlay);
169-
layerWindow->setAnchors(static_cast<LayerShellQt::Window::Anchors>(LayerShellQt::Window::AnchorLeft | LayerShellQt::Window::AnchorTop | LayerShellQt::Window::AnchorBottom));
168+
layerWindow->setLayer(LayerShellWindow::Overlay);
169+
layerWindow->setExclusiveZone(-1);
170+
layerWindow->setAnchors(static_cast<LayerShellWindow::Anchors>(LayerShellWindow::AnchorLeft | LayerShellWindow::AnchorTop | LayerShellWindow::AnchorBottom));
171+
// layerWindow->setAnchors(LayerShellWindow::AnchorRight);
170172
break;
171173
}
172174
}
@@ -177,27 +179,25 @@ void WaylandBackend::blurWindow(QWidget* widget) {
177179

178180
void WaylandBackend::setScreenMarginForWindow(QWidget* widget, QScreen* screen, Qt::Edge edge, int width) {
179181
//TODO: Implement
182+
LayerShellWindow* layerWindow = LayerShellWindow::forWindow(widget->windowHandle());
180183

181-
// QTimer::singleShot(1000, [ = ] {
182-
// LayerShellQt::Window::get(widget->windowHandle())->setExclusiveZone(20);
183-
// LayerShellQt::Window::Anchors anchors;
184-
// switch (edge) {
185-
// case Qt::TopEdge:
186-
// anchors = static_cast<LayerShellQt::Window::Anchors>(LayerShellQt::Window::AnchorLeft | LayerShellQt::Window::AnchorRight | LayerShellQt::Window::AnchorTop);
187-
// break;
188-
// case Qt::LeftEdge:
189-
// anchors = static_cast<LayerShellQt::Window::Anchors>(LayerShellQt::Window::AnchorLeft | LayerShellQt::Window::AnchorTop | LayerShellQt::Window::AnchorBottom);
190-
// break;
191-
// case Qt::RightEdge:
192-
// anchors = LayerShellQt::Window::AnchorRight;
193-
// break;
194-
// case Qt::BottomEdge:
195-
// anchors = LayerShellQt::Window::AnchorBottom;
196-
// break;
197-
// }
198-
// LayerShellQt::Window::get(widget->windowHandle())->setAnchors(anchors);
199-
// });
200-
184+
layerWindow->setExclusiveZone(width);
185+
LayerShellWindow::Anchors anchors;
186+
switch (edge) {
187+
case Qt::TopEdge:
188+
anchors = LayerShellWindow::AnchorTop;
189+
break;
190+
case Qt::LeftEdge:
191+
anchors = LayerShellWindow::AnchorLeft;
192+
break;
193+
case Qt::RightEdge:
194+
anchors = LayerShellWindow::AnchorRight;
195+
break;
196+
case Qt::BottomEdge:
197+
anchors = LayerShellWindow::AnchorBottom;
198+
break;
199+
}
200+
layerWindow->setAnchors(anchors);
201201
}
202202

203203
void WaylandBackend::setScreenOff(bool screenOff) {

lib/lib.pro

+7-4
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ unix {
7171
}
7272
}
7373

74-
exists($$THELIBS_INSTALL_LIB/libLayerShellQtInterface.so) : packagesExist(wayland-client) {
74+
packagesExist(wayland-client) {
7575
message("Building with Wayland support.");
7676
DEFINES += HAVE_WAYLAND
77-
LIBS += -lLayerShellQtInterface
78-
INCLUDEPATH += $$THELIBS_INSTALL_HEADERS/../LayerShellQt
7977

8078
QT += gui-private
8179

@@ -95,7 +93,7 @@ unix {
9593
wayland_scanner_headers.CONFIG += target_predeps no_link
9694

9795
wayland_scanner_sources.output = wayland-${QMAKE_FILE_BASE}-client-protocol.c
98-
wayland_scanner_sources.commands = wayland-scanner public-code ${QMAKE_FILE_NAME} ${QMAKE_FILE_OUT}
96+
wayland_scanner_sources.commands = wayland-scanner private-code ${QMAKE_FILE_NAME} ${QMAKE_FILE_OUT}
9997
wayland_scanner_sources.input = WAYLAND_PROTOCOL_EXTENSIONS
10098
wayland_scanner_sources.variable_out = SOURCES
10199
wayland_scanner_headers.CONFIG += target_predeps no_link
@@ -112,6 +110,11 @@ unix {
112110
qwayland_scanner_headers.CONFIG += target_predeps no_link
113111

114112
QMAKE_EXTRA_COMPILERS += wayland_scanner_headers wayland_scanner_sources qwayland_scanner_headers qwayland_scanner_sources
113+
114+
unix:!macx: LIBS += -L$$OUT_PWD/../wayland-layer-shell/client-lib/ -ltdesktopenvironment-wayland-layer-shell-client
115+
116+
INCLUDEPATH += $$PWD/../wayland-layer-shell/client-lib
117+
DEPENDPATH += $$PWD/../wayland-layer-shell/client-lib
115118
} else {
116119
message("layer-shell-qt or wayland-client not found on this system.");
117120
}

libtdesktopenvironment.pro

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
TEMPLATE = subdirs
22

3-
libproj.subdir = lib
43

54
testproj.subdir = test
65
testproj.depends = libproj
76

7+
waylandlayershellproj.subdir = wayland-layer-shell
8+
9+
libproj.subdir = lib
10+
libproj.depends = waylandlayershellproj
11+
812
SUBDIRS += \
9-
libproj# \
10-
# wayland-layer-shell
13+
libproj \
14+
waylandlayershellproj
1115
# testproj
1216

1317
CONFIG += qt
+36-3
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,56 @@
11
QT -= gui
2+
QT += waylandclient waylandclient_private
23

34
TEMPLATE = lib
45
DEFINES += CLIENTLIB_LIBRARY
6+
TARGET = tdesktopenvironment-wayland-layer-shell-client
57

6-
CONFIG += c++11
8+
CONFIG += c++11 link_pkgconfig
9+
PKGCONFIG += wayland-client
710

811
# You can make your code fail to compile if it uses deprecated APIs.
912
# In order to do so, uncomment the following line.
1013
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
1114

1215
SOURCES += \
13-
layershellwindow.cpp
16+
layershellwindow.cpp \
17+
private/layershellshell.cpp \
18+
private/layershellsurface.cpp
1419

1520
HEADERS += \
1621
client-lib_global.h \
17-
layershellwindow.h
22+
layershellwindow.h \
23+
private/layershellshell.h \
24+
private/layershellsurface.h
1825

1926
# Default rules for deployment.
2027
unix {
2128
target.path = /usr/lib
2229
}
2330
!isEmpty(target.path): INSTALLS += target
31+
32+
WAYLAND_PROTOCOL_EXTENSIONS = ../../lib/wayland-protocols/wlr-protocols/unstable/wlr-layer-shell-unstable-v1.xml ../../lib/wayland-protocols/wayland-protocols/stable/xdg-shell/xdg-shell.xml
33+
34+
wayland_scanner_headers.output = wayland-${QMAKE_FILE_BASE}-client-protocol.h
35+
wayland_scanner_headers.commands = wayland-scanner client-header ${QMAKE_FILE_NAME} ${QMAKE_FILE_OUT}
36+
wayland_scanner_headers.input = WAYLAND_PROTOCOL_EXTENSIONS
37+
wayland_scanner_headers.CONFIG += target_predeps no_link
38+
39+
wayland_scanner_sources.output = wayland-${QMAKE_FILE_BASE}-client-protocol.c
40+
wayland_scanner_sources.commands = wayland-scanner private-code ${QMAKE_FILE_NAME} ${QMAKE_FILE_OUT}
41+
wayland_scanner_sources.input = WAYLAND_PROTOCOL_EXTENSIONS
42+
wayland_scanner_sources.variable_out = SOURCES
43+
wayland_scanner_headers.CONFIG += target_predeps no_link
44+
45+
qwayland_scanner_headers.output = qwayland-${QMAKE_FILE_BASE}.h
46+
qwayland_scanner_headers.commands = qtwaylandscanner client-header ${QMAKE_FILE_NAME} > ${QMAKE_FILE_OUT}
47+
qwayland_scanner_headers.input = WAYLAND_PROTOCOL_EXTENSIONS
48+
qwayland_scanner_headers.CONFIG += target_predeps no_link
49+
50+
qwayland_scanner_sources.output = qwayland-${QMAKE_FILE_BASE}.cpp
51+
qwayland_scanner_sources.commands = qtwaylandscanner client-code ${QMAKE_FILE_NAME} > ${QMAKE_FILE_OUT}
52+
qwayland_scanner_sources.input = WAYLAND_PROTOCOL_EXTENSIONS
53+
qwayland_scanner_sources.variable_out = SOURCES
54+
qwayland_scanner_headers.CONFIG += target_predeps no_link
55+
56+
QMAKE_EXTRA_COMPILERS += wayland_scanner_headers wayland_scanner_sources qwayland_scanner_headers qwayland_scanner_sources

wayland-layer-shell/client-lib/layershellwindow.cpp

+40-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,44 @@
1919
* *************************************/
2020
#include "layershellwindow.h"
2121

22-
LayerShellWindow::LayerShellWindow()
23-
{
22+
#include <private/qwaylandwindow_p.h>
23+
#include "private/layershellsurface.h"
24+
25+
struct LayerShellWindowPrivate {
26+
LayerShellSurface* surface;
27+
};
28+
29+
LayerShellWindow* LayerShellWindow::forWindow(QWindow* window) {
30+
QtWaylandClient::QWaylandWindow* waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow*>(window->handle());
31+
if (!waylandWindow) return nullptr;
32+
33+
LayerShellSurface* surface = qobject_cast<LayerShellSurface*>(waylandWindow->shellSurface());
34+
if (!surface) return nullptr;
35+
36+
return new LayerShellWindow(surface);
37+
}
38+
39+
LayerShellWindow::~LayerShellWindow() {
40+
delete d;
41+
}
42+
43+
void LayerShellWindow::setLayer(Layer layer) {
44+
d->surface->setLayer(layer);
45+
}
46+
47+
void LayerShellWindow::setExclusiveZone(quint32 exclusiveZone) {
48+
d->surface->setExclusiveZone(exclusiveZone);
49+
}
50+
51+
void LayerShellWindow::setAnchors(Anchors anchors) {
52+
d->surface->setAnchor(anchors);
53+
}
54+
55+
void LayerShellWindow::setKeyboardInteractivity(KeyboardInteractivity interactivity) {
56+
d->surface->setKeyboardInteractivity(interactivity);
57+
}
58+
59+
LayerShellWindow::LayerShellWindow(LayerShellSurface* surface) : QObject(surface) {
60+
d = new LayerShellWindowPrivate();
61+
d->surface = surface;
2462
}

wayland-layer-shell/client-lib/layershellwindow.h

+42-3
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,51 @@
2020
#ifndef LAYERSHELLWINDOW_H
2121
#define LAYERSHELLWINDOW_H
2222

23+
#include <QObject>
24+
#include <QWindow>
25+
2326
#include "client-lib_global.h"
2427

25-
class CLIENTLIB_EXPORT LayerShellWindow
26-
{
28+
class LayerShellSurface;
29+
struct LayerShellWindowPrivate;
30+
class CLIENTLIB_EXPORT LayerShellWindow : public QObject {
31+
Q_OBJECT
2732
public:
28-
LayerShellWindow();
33+
static LayerShellWindow* forWindow(QWindow* window);
34+
~LayerShellWindow();
35+
36+
enum Layer : quint32 {
37+
Overlay = 3,
38+
Top = 2,
39+
Bottom = 1,
40+
Background = 0
41+
};
42+
43+
enum Anchor : quint32 {
44+
AnchorTop = 1,
45+
AnchorBottom = 2,
46+
AnchorLeft = 4,
47+
AnchorRight = 8
48+
};
49+
Q_DECLARE_FLAGS(Anchors, Anchor);
50+
51+
enum KeyboardInteractivity : quint32 {
52+
None = 0,
53+
Exclusive = 1,
54+
OnDemand = 2
55+
};
56+
57+
void setLayer(Layer layer);
58+
void setExclusiveZone(quint32 exclusiveZone);
59+
void setAnchors(Anchors anchors);
60+
void setKeyboardInteractivity(KeyboardInteractivity interactivity);
61+
62+
signals:
63+
64+
private:
65+
explicit LayerShellWindow(LayerShellSurface* surface);
66+
67+
LayerShellWindowPrivate* d;
2968
};
3069

3170
#endif // LAYERSHELLWINDOW_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/****************************************
2+
*
3+
* INSERT-PROJECT-NAME-HERE - INSERT-GENERIC-NAME-HERE
4+
* Copyright (C) 2021 Victor Tran
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
* *************************************/
20+
#include "layershellshell.h"
21+
22+
#include "qwayland-wlr-layer-shell-unstable-v1.h"
23+
24+
struct LayerShellShellPrivate {
25+
QtWayland::zwlr_layer_shell_v1* shell;
26+
};
27+
28+
LayerShellShell::LayerShellShell(QtWayland::zwlr_layer_shell_v1* shell) : QtWayland::zwlr_layer_shell_v1(shell->object()) {
29+
d = new LayerShellShellPrivate();
30+
}
31+
32+
LayerShellShell::~LayerShellShell() {
33+
this->destroy();
34+
delete d;
35+
}

0 commit comments

Comments
 (0)