Skip to content

Commit

Permalink
feat: 支持wayland上的分屏需求 (linuxdeepin#70)
Browse files Browse the repository at this point in the history
支持wayland上的分屏需求

Log:
Influence: wayland平台的分屏功能

Co-authored-by: AlexOne <[email protected]>
  • Loading branch information
993381 and AlexOne authored Mar 30, 2022
1 parent f0126d8 commit 3bc981b
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 15 deletions.
15 changes: 15 additions & 0 deletions src/global.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "global.h"
#include <QWindow>
#include <QGuiApplication>

QWindow * fromQtWinId(WId id) {
QWindow *window = nullptr;

for (auto win : qApp->allWindows()) {
if (win->winId() == id) {
window = win;
break;
}
}
return window;
};
5 changes: 5 additions & 0 deletions src/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef GLOBAL_H
#define GLOBAL_H

#include <qwindowdefs.h>

#define MOUSE_MARGINS 10

#define DPP_BEGIN_NAMESPACE namespace deepin_platform_plugin {
Expand Down Expand Up @@ -116,4 +118,7 @@ enum DeviceType {
MouseDevice
};

class QWindow;
QWindow * fromQtWinId(WId id);

#endif // GLOBAL_H
1 change: 1 addition & 0 deletions src/src.pri
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ SOURCES += \
$$PWD/dnativesettings.cpp \
$$PWD/dopenglpaintdevice.cpp \
$$PWD/dxcbxsettings.cpp \
$$PWD/global.cpp \
$$PWD/vtablehook.cpp \
$$PWD/dplatformsettings.cpp \
$$PWD/ddesktopinputselectioncontrol.cpp \
Expand Down
12 changes: 0 additions & 12 deletions wayland/dwayland/dnotitlebarwindowhelper_wl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,6 @@ void DNoTitlebarWlWindowHelper::setWindowProperty(QWindow *window, const char *n

void DNoTitlebarWlWindowHelper::popupSystemWindowMenu(quintptr wid)
{
auto fromQtWinId = [](WId id) {
QWindow *window = nullptr;

for (auto win : qApp->allWindows()) {
if (win->winId() == id) {
window = win;
break;
}
}
return window;
};

QWindow *window = fromQtWinId(wid);
if(!window || !window->handle())
return;
Expand Down
46 changes: 44 additions & 2 deletions wayland/dwayland/dwaylandinterfacehook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
#include <qpa/qplatformnativeinterface.h>
#include <private/qguiapplication_p.h>
#include <QtWaylandClientVersion>

#include <QDebug>
#include <QLoggingCategory>

#ifndef QT_DEBUG
Q_LOGGING_CATEGORY(dwli, "dtk.wayland.interface" , QtInfoMsg);
#else
Q_LOGGING_CATEGORY(dwli, "dtk.wayland.interface");
#endif

DPP_BEGIN_NAMESPACE


Expand Down Expand Up @@ -85,6 +95,10 @@ static QFunctionPointer getFunction(const QByteArray &function)
return reinterpret_cast<QFunctionPointer>(&DWaylandInterfaceHook::enableDwayland);
} else if (function == isEnableDwayland) {
return reinterpret_cast<QFunctionPointer>(&DWaylandInterfaceHook::isEnableDwayland);
} else if (function == splitWindowOnScreen) {
return reinterpret_cast<QFunctionPointer>(&DWaylandInterfaceHook::splitWindowOnScreen);
} else if (function == supportForSplittingWindow) {
return reinterpret_cast<QFunctionPointer>(&DWaylandInterfaceHook::supportForSplittingWindow);
}

return nullptr;
Expand Down Expand Up @@ -183,11 +197,11 @@ bool DWaylandInterfaceHook::isEnableNoTitlebar(QWindow *window)
return window->property(noTitlebar).toBool();
}

bool DWaylandInterfaceHook::setWindowRadius(QWindow *window, int windowRadius)
bool DWaylandInterfaceHook::setWindowRadius(QWindow *window, int value)
{
if (!window)
return false;
return window->setProperty("_d_windowRadius", QVariant{windowRadius});
return window->setProperty(windowRadius, QVariant{value});
}

void DWaylandInterfaceHook::setWindowProperty(QWindow *window, const char *name, const QVariant &value)
Expand Down Expand Up @@ -241,6 +255,34 @@ bool DWaylandInterfaceHook::isEnableDwayland(const QWindow *window)
return window->property(useDwayland).toBool();
}

void DWaylandInterfaceHook::splitWindowOnScreen(WId wid, quint32 type)
{
QWindow *window = fromQtWinId(wid);
if(!window || !window->handle())
return;
// 1 left,2 right,15 fullscreen
if (type == 15) {
if (window->windowStates().testFlag(Qt::WindowMaximized)) {
window->showNormal();
} else {
window->showMaximized();
}
} else if (type == 1 || type == 2) {
DNoTitlebarWlWindowHelper::setWindowProperty(window, ::splitWindowOnScreen, type);
} else {
qCWarning(dwli) << "invalid split type: " << type;
}
}

bool DWaylandInterfaceHook::supportForSplittingWindow(WId wid)
{
QWindow *window = fromQtWinId(wid);
if(!window || !window->handle())
return false;
DNoTitlebarWlWindowHelper::setWindowProperty(window, ::supportForSplittingWindow, false);
return window->property(::supportForSplittingWindow).toBool();
}

DXcbXSettings *DWaylandInterfaceHook::globalSettings()
{
if (Q_LIKELY(m_xsettings)) {
Expand Down
5 changes: 4 additions & 1 deletion wayland/dwayland/dwaylandinterfacehook.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "global.h"

#include <QtGlobal>
#include <qwindowdefs.h>

QT_BEGIN_NAMESPACE
class QObject;
Expand All @@ -46,11 +47,13 @@ class DWaylandInterfaceHook
static void clearNativeSettings(quint32 settingWindow);
static bool setEnableNoTitlebar(QWindow *window, bool enable);
static bool isEnableNoTitlebar(QWindow *window);
static bool setWindowRadius(QWindow *window, int windowRadius);
static bool setWindowRadius(QWindow *window, int value);
static void setWindowProperty(QWindow *window, const char *name, const QVariant &value);
static void popupSystemWindowMenu(quintptr wid);
static bool enableDwayland(QWindow *window);
static bool isEnableDwayland(const QWindow *window);
static void splitWindowOnScreen(WId wid, quint32 type);
static bool supportForSplittingWindow(WId wid);
static DXcbXSettings *globalSettings();

private:
Expand Down
18 changes: 18 additions & 0 deletions wayland/wayland-shell/dwaylandshellmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,24 @@ void DWaylandShellManager::sendProperty(QWaylandShellSurface *self, const QStrin
else
qCWarning(dwlp) << "invalid property" << name << value;
}
if (!name.compare(splitWindowOnScreen)) {
using KWayland::Client::DDEShellSurface;
bool ok = false;
qreal leftOrRight = value.toInt(&ok);
if (ok) {
dde_shell_surface->requestSplitWindow((DDEShellSurface::SplitType)leftOrRight);
qCInfo(dwlp) << "requestSplitWindow value: " << leftOrRight;
} else {
qCWarning(dwlp) << "invalid property: " << name << value;
}
self->window()->window()->setProperty(splitWindowOnScreen, 0);
}
if (!name.compare(supportForSplittingWindow)) {
if (self->window() && self->window()->window()) {
self->window()->window()->setProperty(supportForSplittingWindow, dde_shell_surface->isSplitable());
}
return;
}
}

// 将popup的窗口设置为tooltop层级, 包括qmenu,combobox弹出窗口
Expand Down

0 comments on commit 3bc981b

Please sign in to comment.