Skip to content

Commit

Permalink
sync: from linuxdeepin/dtkgui
Browse files Browse the repository at this point in the history
Synchronize source files from linuxdeepin/dtkgui.

Source-pull-request: linuxdeepin/dtkgui#210
  • Loading branch information
deepin-ci-robot committed Dec 8, 2023
1 parent d96aef2 commit 80ba024
Show file tree
Hide file tree
Showing 11 changed files with 372 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.13)
cmake_minimum_required(VERSION 3.25)

set(DTK_VERSION "5.6.11" CACHE STRING "define project version")
project(DtkGui
Expand Down
27 changes: 27 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
if("${QT_VERSION_MAJOR}" STREQUAL "6")
find_package(Qt6 REQUIRED COMPONENTS Core Widgets WaylandClient)
endif()

add_library(${LIB_NAME} SHARED)

if("${QT_VERSION_MAJOR}" STREQUAL "6")
qt6_generate_wayland_protocol_client_sources(${LIB_NAME} FILES
${CMAKE_CURRENT_SOURCE_DIR}/wayland/protocol/treeland-personalization-manager-v1.xml
)
endif()

include(dbus/dbus.cmake)
include(filedrag/dfiledrag.cmake)
include(kernel/kernel.cmake)
include(private/private.cmake)
include(util/util.cmake)

if("${QT_VERSION_MAJOR}" STREQUAL "6")
include(wayland/wayland.cmake)
target_sources(${LIB_NAME} PRIVATE
${wayland_SRC}
)
endif()

target_sources(${LIB_NAME} PRIVATE
${dbus_SRC}
Expand Down Expand Up @@ -43,6 +60,16 @@ else()
target_link_libraries(${LIB_NAME} PRIVATE PkgConfig::librsvg)
endif()

if("${QT_VERSION_MAJOR}" STREQUAL "6")
target_link_libraries(${LIB_NAME} PUBLIC
PUBLIC
Qt::Core
Qt::Widgets
PRIVATE
Qt::WaylandClientPrivate
)
endif()

if(NOT DTK_DISABLE_EX_IMAGE_FORMAT AND EX_IMAGE_FORMAT_LIBS_FOUND)
target_link_libraries(${LIB_NAME} PRIVATE
${libraw_LIBRARIES}
Expand Down
6 changes: 6 additions & 0 deletions src/kernel/dplatformhandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "dplatformhandle.h"
#include "dplatformtheme.h"
#include "dwindowmanagerhelper.h"
#include "wayland/dcontextshellwindow.h"

#include <QWindow>
#include <QGuiApplication>
Expand Down Expand Up @@ -635,6 +636,11 @@ bool DPlatformHandle::setEnabledNoTitlebarForWindow(QWindow *window, bool enable
if (!(isDXcbPlatform() || isDWaylandPlatform()))
return false;

if (window && isDWaylandPlatform()) {
DContextShellWindow *contextWindow = DContextShellWindow::get(window);
contextWindow->setNoTitlebar(1);
}

if (isEnabledNoTitlebar(window) == enable)
return true;

Expand Down
95 changes: 95 additions & 0 deletions src/wayland/dcontextshellwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "dcontextshellwindow.h"

#include "qwaylandpersonalizationshellintegration_p.h"

#include <QLoggingCategory>
#include <QMargins>
#include <QWindow>
#include <QtWaylandClient/private/qwaylandwindow_p.h>

Q_LOGGING_CATEGORY(layershellwindow, "dde.shell.layershell.window")

class DContextShellWindowPrivate
{
public:
explicit DContextShellWindowPrivate(QWindow *window)
: parentWindow(window)
{
}

QWindow *parentWindow = nullptr;
int noTitlebar = -1;
};

void DContextShellWindow::setNoTitlebar(const int value)
{
if (value == d->noTitlebar) {
return;
}
d->noTitlebar = value;
}

int DContextShellWindow::noTitlebar()
{
return d->noTitlebar;
}

static QMap<QWindow *, DContextShellWindow *> s_map;

DContextShellWindow::~DContextShellWindow()
{
s_map.remove(d->parentWindow);
}

DContextShellWindow::DContextShellWindow(QWindow *window)
: QObject(window)
, d(new DContextShellWindowPrivate(window))
{
s_map.insert(window, this);
window->create();
auto waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(window->handle());
if (waylandWindow) {
static QWaylandPersonalizationShellIntegration *shellIntegration = nullptr;
if (!shellIntegration) {
shellIntegration = new QWaylandPersonalizationShellIntegration();
if (!shellIntegration->initialize(waylandWindow->display())) {
delete shellIntegration;
shellIntegration = nullptr;
qCWarning(layershellwindow) << "failed to init dlayershell intergration";
return;
}
}
waylandWindow->setShellIntegration(shellIntegration);
}
#ifdef BUILD_WITH_X11
else if (auto xcbWindow =

Check warning on line 68 in src/wayland/dcontextshellwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Variable 'xcbWindow' is assigned a value that is never used.
dynamic_cast<QNativeInterface::Private::QXcbWindow *>(window->handle())) {
new LayerShellEmulation(window, this);
qCWarning(layershellwindow) << "not a wayland window, try to emulate on x11";
}
#endif
else {
qCWarning(layershellwindow) << "not a wayland window, will not create zwlr_layer_surface";
}
}

DContextShellWindow *DContextShellWindow::get(QWindow *window)
{
auto dlayerShellWindow = s_map.value(window);
if (dlayerShellWindow) {
return dlayerShellWindow;
}
return new DContextShellWindow(window);
}

DContextShellWindow *DContextShellWindow::qmlAttachedProperties(QObject *object)

Check warning on line 88 in src/wayland/dcontextshellwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'qmlAttachedProperties' is never used.
{
auto window = qobject_cast<QWindow *>(object);
if (window)
return get(window);
qCWarning(layershellwindow) << "not a qwindow unable to create DContextShellWindow";
return nullptr;
}
39 changes: 39 additions & 0 deletions src/wayland/dcontextshellwindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <QLoggingCategory>
#include <QObject>
#include <QScreen>
#include <QWindow>

class DContextShellWindowPrivate;

class DContextShellWindow : public QObject
{
Q_OBJECT
Q_PROPERTY(int noTitlebar READ noTitlebar WRITE setNoTitlebar NOTIFY noTitlebarChanged)

public:
~DContextShellWindow() override;

void setNoTitlebar(const int value);
int noTitlebar();

/**
* Gets the LayerShell Window for a given Qt Window
* Ownership is not transferred
*/
static DContextShellWindow *get(QWindow *window);

static DContextShellWindow *qmlAttachedProperties(QObject *object);

Q_SIGNALS:
void noTitlebarChanged();

private:
DContextShellWindow(QWindow *window);

Check warning on line 37 in src/wayland/dcontextshellwindow.h

View workflow job for this annotation

GitHub Actions / cppcheck

Class 'DContextShellWindow' has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided.
QScopedPointer<DContextShellWindowPrivate> d;
};
90 changes: 90 additions & 0 deletions src/wayland/protocol/treeland-personalization-manager-v1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="treeland_personalization_manager_v1">
<copyright> Copyright © 2023 Uniontech
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="treeland_personalization_manager_v1" version="1">
<description summary="personalization manager">
This interface allows a client to customized display effects.

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>
<request name="get_wallpaper_context">
<arg name="id" type="new_id" interface="treeland_wallpaper_context_v1" />
</request>
<request name="get_window_context">
<arg name="surface" type="object" interface="wl_surface" />
<arg name="id" type="new_id" interface="treeland_window_context_v1" />
</request>
</interface>
<interface name="treeland_wallpaper_context_v1" version="1">
<description summary="client wallpaper context">
This interface allows a client set window wallpaper.

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>
<request name="destroy" type="destructor">
<description summary="destroy the context object">
Destroy the context object.
</description>
</request>
</interface>
<interface name="treeland_window_context_v1" version="1">
<description summary="client window context">
This interface allows a client set window properties.

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>
<request name="set_radius">
<description summary="the radius which represents the toplevel">
The radius of the surface specified in this request corresponds to the place where
the app using this protocol represents the given toplevel.
</description>

<arg name="x" type="int" />
<arg name="y" type="int" />
</request>
<request name="set_no_titlebar">
<description summary="toplevel doesn't need titlebar">
When the value is non-zero, the toplevel titlebar will be disabled.
</description>

<arg name="value" type="int" />
</request>
<request name="destroy" type="destructor">
<description summary="destroy the context object">
Destroy the context object.
</description>
</request>
<enum name="error">
<entry name="invalid_radius" value="0"
summary="the provided radius is invalid" />
</enum>
</interface>
</protocol>
27 changes: 27 additions & 0 deletions src/wayland/qwaylandpersonalizationshellintegration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "qwaylandpersonalizationshellintegration_p.h"
#include "qwaylandwindowcontextshellsurface_p.h"
#include "wayland-treeland-personalization-manager-v1-client-protocol.h"

QWaylandPersonalizationShellIntegration::QWaylandPersonalizationShellIntegration()
: QWaylandShellIntegrationTemplate<QWaylandPersonalizationShellIntegration>(4)
{
}

QWaylandPersonalizationShellIntegration::~QWaylandPersonalizationShellIntegration()
{
if (object()
&& treeland_personalization_manager_v1_get_version(object())
>= TREELAND_WINDOW_CONTEXT_V1_DESTROY_SINCE_VERSION) {
treeland_personalization_manager_v1_destroy(object());
}
}

QtWaylandClient::QWaylandShellSurface *
QWaylandPersonalizationShellIntegration::createShellSurface(QtWaylandClient::QWaylandWindow *window)

Check warning on line 24 in src/wayland/qwaylandpersonalizationshellintegration.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'createShellSurface' is never used.
{
return new QWaylandWindowContextSurface(this, window);
}
21 changes: 21 additions & 0 deletions src/wayland/qwaylandpersonalizationshellintegration_p.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <private/qwaylandshellintegration_p.h>
#include <qwayland-treeland-personalization-manager-v1.h>

class QWaylandPersonalizationShellIntegration
: public QtWaylandClient::QWaylandShellIntegrationTemplate<
QWaylandPersonalizationShellIntegration>,
public QtWayland::treeland_personalization_manager_v1
{
public:
QWaylandPersonalizationShellIntegration();
~QWaylandPersonalizationShellIntegration() override;

QtWaylandClient::QWaylandShellSurface *
createShellSurface(QtWaylandClient::QWaylandWindow *window) override;
};
31 changes: 31 additions & 0 deletions src/wayland/qwaylandwindowcontextshellsurface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "dcontextshellwindow.h"
#include "qwaylandwindowcontextshellsurface_p.h"

#include <QLoggingCategory>
#include <QtWaylandClient/private/qwaylandsurface_p.h>
#include <QtWaylandClient/private/qwaylandwindow_p.h>

Q_LOGGING_CATEGORY(layershellsurface, "dde.shell.layershell.surface")

QWaylandWindowContextSurface::QWaylandWindowContextSurface(
QtWayland::treeland_personalization_manager_v1 *shell, QtWaylandClient::QWaylandWindow *window)
: QtWaylandClient::QWaylandShellSurface(window)
, QtWayland::treeland_window_context_v1()
, m_dcontextShellWindow(DContextShellWindow::get(window->window()))
{
init(shell->get_window_context(window->waylandSurface()->object()));
set_no_titlebar(m_dcontextShellWindow->noTitlebar());
connect(m_dcontextShellWindow, &DContextShellWindow::noTitlebarChanged, this, [this, window]() {
set_no_titlebar(m_dcontextShellWindow->noTitlebar());
window->waylandSurface()->commit();
});
}

QWaylandWindowContextSurface::~QWaylandWindowContextSurface()
{
destroy();
}
Loading

0 comments on commit 80ba024

Please sign in to comment.