Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync: from linuxdeepin/dtkgui #9

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 9 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,14 @@ bool DPlatformHandle::setEnabledNoTitlebarForWindow(QWindow *window, bool enable
if (!(isDXcbPlatform() || isDWaylandPlatform()))
return false;

if (window && isDWaylandPlatform()) {
DContextShellWindow *contextWindow = DContextShellWindow::get(window);
if (contextWindow->noTitlebar() == enable)
return true;
contextWindow->setNoTitlebar(enable);
return true;
}

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

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

#include "qwaylandpersonalizationshellintegration_p.h"

#include <QtWaylandClient/private/qwaylandwindow_p.h>

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

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

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

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

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;
qWarning() << "failed to init dlayershell intergration";
return;
}
}
waylandWindow->setShellIntegration(shellIntegration);
} else {
qWarning() << "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 75 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);
qWarning() << "not a qwindow unable to create DContextShellWindow";
return nullptr;
}
31 changes: 31 additions & 0 deletions src/wayland/dcontextshellwindow.h
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

#pragma once

#include <QWindow>

class DContextShellWindowPrivate;

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

public:
~DContextShellWindow() override;

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

static DContextShellWindow *get(QWindow *window);
static DContextShellWindow *qmlAttachedProperties(QObject *object);

Q_SIGNALS:
void noTitlebarChanged();

private:
DContextShellWindow(QWindow *window);

Check warning on line 29 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;
};
30 changes: 30 additions & 0 deletions src/wayland/qwaylandwindowcontextshellsurface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

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

#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();
}
25 changes: 25 additions & 0 deletions src/wayland/qwaylandwindowcontextshellsurface_p.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include "dcontextshellwindow.h"

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

#include <QtWaylandClient/private/qwaylandshellsurface_p.h>

class QWaylandWindowContextSurface : public QtWaylandClient::QWaylandShellSurface,
public QtWayland::treeland_window_context_v1
{
Q_OBJECT
public:
QWaylandWindowContextSurface(QtWayland::treeland_personalization_manager_v1 *shell,
QtWaylandClient::QWaylandWindow *window);
~QWaylandWindowContextSurface() override;

private:
DContextShellWindow *m_dcontextShellWindow;
};
10 changes: 10 additions & 0 deletions src/wayland/wayland.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
file(GLOB WAYLAND_HEADER
${CMAKE_CURRENT_LIST_DIR}/*.h
)
file(GLOB WAYLAND_SOURCE
${CMAKE_CURRENT_LIST_DIR}/*.cpp
)
set(wayland_SRC
${WAYLAND_HEADER}
${WAYLAND_SOURCE}
)
Loading