Skip to content

Commit

Permalink
chore: add some interfaces about personalization
Browse files Browse the repository at this point in the history
add some interfaces about personalization

Log:
  • Loading branch information
wangfei committed Oct 10, 2024
1 parent 8cf037d commit a7d021d
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 254 deletions.
6 changes: 4 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ else()
find_package(Qt5 REQUIRED COMPONENTS WaylandClient XkbCommonSupport)
endif()

find_package(TreeLandProtocols REQUIRED)

add_library(${LIB_NAME} SHARED)

include(dbus/dbus.cmake)
Expand All @@ -14,7 +16,7 @@ include(util/util.cmake)

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
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-personalization-manager-v1.xml
)
else()
# ECM setup
Expand All @@ -23,7 +25,7 @@ else()
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${ECM_MODULE_PATH}")
find_package(QtWaylandScanner)
ecm_add_qtwayland_client_protocol(${LIB_NAME}
PROTOCOL ${CMAKE_CURRENT_SOURCE_DIR}/wayland/protocol/treeland-personalization-manager-v1.xml
PROTOCOL ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-personalization-manager-v1.xml
BASENAME treeland-personalization-manager-v1
)
target_sources(${LIB_NAME} PRIVATE
Expand Down
49 changes: 22 additions & 27 deletions src/kernel/dplatformhandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "dplatformhandle.h"
#include "dplatformtheme.h"
#include "dwindowmanagerhelper.h"
#include "wayland/dcontextshellwindow.h"
#include "wayland/personalizationwaylandclientextension.h"
#include <private/qwaylandwindow_p.h>

#include <QWindow>
Expand Down Expand Up @@ -629,31 +629,29 @@ class Q_DECL_HIDDEN CreatorWindowEventFile : public QObject {
}

if (auto *w = qobject_cast<QWindow *>(watched); w && isTreeLand()) {
if(DContextShellWindow *window = DContextShellWindow::get(qobject_cast<QWindow *>(watched))) {
bool is_mouse_move = event->type() == QEvent::MouseMove && static_cast<QMouseEvent*>(event)->buttons() == Qt::LeftButton;
bool is_mouse_move = event->type() == QEvent::MouseMove && static_cast<QMouseEvent*>(event)->buttons() == Qt::LeftButton;

if (event->type() == QEvent::MouseButtonRelease) {
m_windowMoving = false;
}
if (event->type() == QEvent::MouseButtonRelease) {
m_windowMoving = false;
}

// workaround for kwin: Qt receives no release event when kwin finishes MOVE operation,
// which makes app hang in windowMoving state. when a press happens, there's no sense of
// keeping the moving state, we can just reset ti back to normal.
if (event->type() == QEvent::MouseButtonPress) {
m_windowMoving = false;
}
// workaround for kwin: Qt receives no release event when kwin finishes MOVE operation,
// which makes app hang in windowMoving state. when a press happens, there's no sense of
// keeping the moving state, we can just reset ti back to normal.
if (event->type() == QEvent::MouseButtonPress) {
m_windowMoving = false;
}

// FIXME: We need to check whether the event is accepted.
// Only when the upper control does not accept the event,
// the window should be moved through the window.
// But every event here has been accepted. I don't know what happened.
if (is_mouse_move && w->geometry().contains(static_cast<QMouseEvent*>(event)->globalPos())) {
if (!m_windowMoving && PersonalizationManager::instance()->noTitlebar()) {
m_windowMoving = true;

// FIXME: We need to check whether the event is accepted.
// Only when the upper control does not accept the event,
// the window should be moved through the window.
// But every event here has been accepted. I don't know what happened.
if (is_mouse_move && w->geometry().contains(static_cast<QMouseEvent*>(event)->globalPos())) {
if (!m_windowMoving && window->noTitlebar()) {
m_windowMoving = true;

event->accept();
static_cast<QtWaylandClient::QWaylandWindow *>(w->handle())->startSystemMove();
}
event->accept();
static_cast<QtWaylandClient::QWaylandWindow *>(w->handle())->startSystemMove();
}
}
}
Expand Down Expand Up @@ -683,10 +681,7 @@ bool DPlatformHandle::setEnabledNoTitlebarForWindow(QWindow *window, bool enable
return false;

if (window && isTreeLand()) {
DContextShellWindow *contextWindow = DContextShellWindow::get(window);
if (contextWindow->noTitlebar() == enable)
return true;
contextWindow->setNoTitlebar(enable);
PersonalizationManager::instance()->setNoTitlebar(enable, window);
window->installEventFilter(new CreatorWindowEventFile(window));
return true;
}
Expand Down
107 changes: 107 additions & 0 deletions src/wayland/personalizationwaylandclientextension.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "personalizationwaylandclientextension.h"
#include "qwayland-treeland-personalization-manager-v1.h"

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

DGUI_BEGIN_NAMESPACE

class PersonalizationManager_: public PersonalizationManager {};
Q_GLOBAL_STATIC(PersonalizationManager_, personalizationManager)

PersonalizationManager::PersonalizationManager()
: QWaylandClientExtensionTemplate<PersonalizationManager>(1)
{
}

PersonalizationManager *PersonalizationManager::instance()
{
return personalizationManager;
}

PersonalizationWindowContext *PersonalizationManager::getWindowContext(QWindow *window)
{
Q_ASSERT(!isActive());

if (!window) {
return nullptr;
}
window->create();
auto waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(window->handle());
if (!waylandWindow) {
return nullptr;
}
auto surface = waylandWindow->waylandSurface()->object();
auto context = get_window_context(surface);
if (m_windowContext.isNull()) {
m_windowContext.reset(new PersonalizationWindowContext(context));
}
return m_windowContext.data();
}


bool PersonalizationManager::noTitlebar()
{
return m_windowContext->noTitlebar();
}

void PersonalizationManager::setNoTitlebar(bool enable, QWindow *window)
{
connect(this, &PersonalizationManager::activeChanged, [this, enable, window]{
if (!isActive()) {
return ;
}

auto windowContext = this->getWindowContext(window);
if (!windowContext) {
return;
}
windowContext->setNoTitlebar(enable);
});
}

PersonalizationWindowContext::PersonalizationWindowContext(struct ::treeland_personalization_window_context_v1 *context)

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

View workflow job for this annotation

GitHub Actions / cppcheck

Member variable 'PersonalizationWindowContext::m_noTitlebar' is not initialized in the constructor.
: QWaylandClientExtensionTemplate<PersonalizationWindowContext>(1)
, QtWayland::treeland_personalization_window_context_v1(context)
{
}


bool PersonalizationWindowContext::noTitlebar()
{
return m_noTitlebar;
}

void PersonalizationWindowContext::setNoTitlebar(bool enable)
{
if (m_noTitlebar == enable) {
return;
}

m_noTitlebar = enable;
set_no_titlebar(m_noTitlebar ? enable_mode::enable_mode_enable : enable_mode::enable_mode_disable);
}

PersonalizationAppearanceContext::PersonalizationAppearanceContext(struct ::treeland_personalization_appearance_context_v1 *context)
: QWaylandClientExtensionTemplate<PersonalizationAppearanceContext>(1)
, QtWayland::treeland_personalization_appearance_context_v1(context)
{
}

PersonalizationWallpaperContext::PersonalizationWallpaperContext(struct ::treeland_personalization_wallpaper_context_v1 *context)
: QWaylandClientExtensionTemplate<PersonalizationWallpaperContext>(1)
, QtWayland::treeland_personalization_wallpaper_context_v1(context)
{
}

PersonalizationCursorContext::PersonalizationCursorContext(struct ::treeland_personalization_cursor_context_v1 *context)
: QWaylandClientExtensionTemplate<PersonalizationCursorContext>(1)
, QtWayland::treeland_personalization_cursor_context_v1(context)
{
}
DGUI_END_NAMESPACE
79 changes: 79 additions & 0 deletions src/wayland/personalizationwaylandclientextension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include <QtWaylandClient/QWaylandClientExtension>
#include <QWindow>

#include "qwayland-treeland-personalization-manager-v1.h"

#include <dtkgui_global.h>
#include <qwaylandclientextension.h>
#include <qwindow.h>

DGUI_BEGIN_NAMESPACE
class PersonalizationWindowContext;
class PersonalizationManager: public QWaylandClientExtensionTemplate<PersonalizationManager>,
public QtWayland::treeland_personalization_manager_v1
{
Q_OBJECT
public:
static PersonalizationManager *instance();

bool noTitlebar();
void setNoTitlebar(bool enable, QWindow *window);

protected:
explicit PersonalizationManager();

private:
PersonalizationWindowContext *getWindowContext(QWindow *window);

private:
QScopedPointer<PersonalizationWindowContext> m_windowContext;
};

class PersonalizationWindowContext : public QWaylandClientExtensionTemplate<PersonalizationWindowContext>,
public QtWayland::treeland_personalization_window_context_v1
{
Q_OBJECT
public:
explicit PersonalizationWindowContext(struct ::treeland_personalization_window_context_v1 *context);

bool noTitlebar();
void setNoTitlebar(bool enable);

private:
bool m_noTitlebar;
};


class PersonalizationAppearanceContext : public QWaylandClientExtensionTemplate<PersonalizationAppearanceContext>,
public QtWayland::treeland_personalization_appearance_context_v1
{
Q_OBJECT
public:
explicit PersonalizationAppearanceContext(struct ::treeland_personalization_appearance_context_v1 *context);

};

class PersonalizationWallpaperContext : public QWaylandClientExtensionTemplate<PersonalizationWallpaperContext>,
public QtWayland::treeland_personalization_wallpaper_context_v1
{
Q_OBJECT
public:
explicit PersonalizationWallpaperContext(struct ::treeland_personalization_wallpaper_context_v1 *context);


};

class PersonalizationCursorContext : public QWaylandClientExtensionTemplate<PersonalizationCursorContext>,
public QtWayland::treeland_personalization_cursor_context_v1
{
Q_OBJECT
public:
explicit PersonalizationCursorContext(struct ::treeland_personalization_cursor_context_v1 *context);

};

DGUI_END_NAMESPACE
Loading

0 comments on commit a7d021d

Please sign in to comment.