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

fix: Adapt displayjack lib getWindowStatesList() interface #306

Merged
merged 1 commit into from
Jan 16, 2024
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
41 changes: 41 additions & 0 deletions deepin-system-monitor-main/3rdparty/displayjack/wayland_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef DTK_WMJACK_WAYLAND_CLIENT_H
#define DTK_WMJACK_WAYLAND_CLIENT_H

#ifdef __cplusplus
extern "C" {
#endif

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>

typedef struct Dtk_Window_State
{
int32_t pid;
int32_t windowId;
char resourceName[256];
struct Geometry
{
int32_t x;
int32_t y;
int32_t width;
int32_t height;
} geometry;
bool isMinimized;
bool isFullScreen;
bool isActive;
int32_t splitable;
char uuid[256];
} WindowState;

#ifdef __cplusplus
}
#endif

#endif
4 changes: 4 additions & 0 deletions deepin-system-monitor-main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,10 @@ set(DMIDECODE
3rdparty/dmidecode/util.c
)

set(DMIDECODE_HEADS
3rdparty/displayjack/wayland_client.h
)

set(APP_HPP
${CMAKE_HOME_DIRECTORY}/config.h
${HPP_GLOBAL}
Expand Down
70 changes: 68 additions & 2 deletions deepin-system-monitor-main/gui/xwin_kill_preview_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include "ui_common.h"
#include "common/common.h"

#ifdef USE_DEEPIN_WAYLAND
#include "3rdparty/displayjack/wayland_client.h"
#endif

#include <QDebug>
#include <QMouseEvent>
#include <QKeyEvent>
Expand All @@ -32,6 +36,15 @@
using namespace core::wm;
using namespace common::init;

typedef int (*InitDtkWmDisplayPtr)();
typedef void (*DestoryDtkWmDisplayPtr)();
typedef int (*GetAllWindowStatesListPtr)(WindowState **states);

// displayjack库接口
static InitDtkWmDisplayPtr InitDtkWmDisplay = nullptr;
static DestoryDtkWmDisplayPtr DestoryDtkWmDisplay = nullptr;
static GetAllWindowStatesListPtr GetAllWindowStatesList = nullptr;

// constructor
XWinKillPreviewWidget::XWinKillPreviewWidget(QWidget *parent) : QWidget(parent)
{
Expand All @@ -43,6 +56,14 @@
if (WaylandCentered) {
m_connectionThread = new QThread(this);
m_connectionThreadObject = new ConnectionThread();

QLibrary library("libdtkwmjack.so");
InitDtkWmDisplay = reinterpret_cast<int (*)()>(library.resolve("InitDtkWmDisplay"));
DestoryDtkWmDisplay = reinterpret_cast<void (*)()>(library.resolve("DestoryDtkWmDisplay"));
GetAllWindowStatesList = reinterpret_cast<int (*)(WindowState **)>(library.resolve("GetAllWindowStatesList"));

if (InitDtkWmDisplay)
InitDtkWmDisplay();
}
#endif // USE_DEEPIN_WAYLAND

Expand All @@ -68,11 +89,15 @@
releaseMouse();
releaseKeyboard();
delete m_wminfo;

#ifdef USE_DEEPIN_WAYLAND
if (WaylandCentered) {
m_connectionThread->quit();
m_connectionThread->wait();
m_connectionThreadObject->deleteLater();

if (DestoryDtkWmDisplay)
DestoryDtkWmDisplay();
}
#endif // USE_DEEPIN_WAYLAND
}
Expand Down Expand Up @@ -408,9 +433,10 @@
}
#endif // USE_DEEPIN_WAYLAND
}

//打印当前窗口信息接口
#ifdef USE_DEEPIN_WAYLAND
void XWinKillPreviewWidget::print_window_states(const QVector<ClientManagement::WindowState> &m_windowStates)

Check warning on line 439 in deepin-system-monitor-main/gui/xwin_kill_preview_widget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'print_window_states' is never used.
{
if (WaylandCentered) {
for (int i = 0; i < m_windowStates.count(); ++i) {
Expand Down Expand Up @@ -445,7 +471,7 @@
m_clientManagement = registry->createClientManagement(name, version, this);
connect(m_clientManagement, &ClientManagement::windowStatesChanged, this,
[this] {
m_windowStates = m_clientManagement->getWindowStates();
m_windowStates = getAllWindowStates();
}
);
}
Expand All @@ -455,7 +481,7 @@
[this] {
Q_ASSERT(m_compositor);
Q_ASSERT(m_clientManagement);
m_windowStates = m_clientManagement->getWindowStates();
m_windowStates = getAllWindowStates();
}
);

Expand All @@ -464,5 +490,45 @@
registry->setup();
}
}

QVector<ClientManagement::WindowState> XWinKillPreviewWidget::getAllWindowStates()
{
QVector<ClientManagement::WindowState> vWindowStates;

// 能解析到displayjack的接口,优先使用dispalayjack接口获取窗口状态
if (GetAllWindowStatesList) {
// 使用displayjack库接口获取窗口状态
WindowState * pStates = nullptr;
int nCount = GetAllWindowStatesList(&pStates);
if (nCount <= 0)
return vWindowStates;

for (int i = 0; i < nCount; i++)
{
WindowState *p = &pStates[i];
ClientManagement::WindowState windowState;
windowState.pid = p->pid;
windowState.windowId = p->windowId;
memcpy(windowState.resourceName, p->resourceName, sizeof(p->resourceName));
windowState.geometry.x = p->geometry.x;
windowState.geometry.y = p->geometry.y;
windowState.geometry.width = p->geometry.width;
windowState.geometry.height = p->geometry.height;
windowState.isMinimized = p->isMinimized;
windowState.isFullScreen = p->isFullScreen;
windowState.isActive = p->isActive;

vWindowStates.push_back(windowState);
}
free(pStates);
} else {
// 使用kde接口获取窗口状态
Q_ASSERT(m_clientManagement);
return m_clientManagement->getWindowStates();
}

return vWindowStates;
}

#endif // USE_DEEPIN_WAYLAND

4 changes: 4 additions & 0 deletions deepin-system-monitor-main/gui/xwin_kill_preview_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public slots:
*/
void initConnections();

#ifdef USE_DEEPIN_WAYLAND
QVector<ClientManagement::WindowState> getAllWindowStates();
#endif

private:
// Window manager (x11) instance
core::wm::WMInfo *m_wminfo;
Expand Down