wayland适配

This commit is contained in:
xie_klve 2022-06-22 14:43:31 +08:00
parent ac01ee5065
commit f81421cb4b
12 changed files with 206 additions and 87 deletions

View File

@ -111,7 +111,7 @@ public slots:
void onAsyncSysInfo(QDBusPendingCallWatcher* callWatcher);
void onAsyncLshwInfo(QDBusPendingCallWatcher* callWatcher);
signals:
Q_SIGNALS:
//异步获取返回信息信号
void updateCpuFMInfo(unsigned uStatus, QString strInfoJson);
void updateDevMonitorInfo(unsigned uStatus, QString strInfoJson);

56
debian/control vendored
View File

@ -6,23 +6,27 @@ XSBC-Original-Maintainer: Ubuntu Kylin Team <ubuntukylin-members@list.launchpad.
Uploaders: handsome_feng <jianfengli@ubuntukylin.com>,
lixiang <lixiang@kylinos.cn>
Build-Depends: debhelper (>= 9),
libepoxy-dev,
libglib2.0-dev (>= 2.46.0),
libqt5charts5-dev,
qtbase5-dev (>= 5.1),
libqt5svg5-dev,
libqt5charts5-dev,
qt5-qmake,
qtscript5-dev,
qttools5-dev-tools,
libgsettings-qt-dev,
pkg-config,
libglib2.0-dev (>= 2.46.0),
libgtop2-dev,
libkf5windowsystem-dev,
libqt5charts5-dev,
libqt5svg5-dev,
libqt5x11extras5-dev,
libsdl2-dev,
libxrandr-dev,
libudev-dev,
libukui-log4qt-dev,
libxrandr-dev,
pkg-config,
qt5-qmake,
qtbase5-dev (>= 5.1),
qtscript5-dev,
qttools5-dev-tools
libsdl2-dev,
libepoxy-dev,
libkf5screen-dev,
libkf5screen-bin,
libkysdk-waylandhelper-dev,
Standards-Version: 4.5.0
Rules-Requires-Root: no
Homepage: https://github.com/ubuntukylin/youker-assistant
@ -31,28 +35,28 @@ Vcs-browser: https://github.com/ubuntukylin/youker-assistant
Package: youker-assistant
Architecture: any
Depends: bsdutils (>= 1:2.27.1),
cpufrequtils,
dmidecode [amd64 arm64 armhf i386],
dpkg-dev,
edid-decode,
hdparm,
hwinfo,
libukui-log4qt-dev,
lm-sensors,
lshw,
net-tools,
pciutils,
python3-dbus,
Depends: python3-dbus,
python3-psutil,
python3-lxml,
python3-pil,
python3-psutil,
python3-smbus,
python3-xdg,
bsdutils (>= 1:2.27.1),
hdparm,
lm-sensors,
lshw,
edid-decode,
dmidecode [amd64 arm64 armhf i386],
cpufrequtils,
dpkg-dev,
pciutils,
libukui-log4qt-dev,
hwinfo,
smartmontools,
net-tools,
${misc:Depends},
${python3:Depends},
${shlibs:Depends}
${shlibs:Depends},
Description: Integrated tool to aid in routine system maintenance tasks
Kylin Assistant is a tool designed to help Ubuntu and Ubuntu Kylin
desktop users manage and maintain many aspects of their working

View File

@ -1,5 +1,5 @@
QT += widgets dbus x11extras
QT += widgets dbus x11extras KScreen
TEMPLATE = lib
CONFIG += plugin \

View File

@ -84,7 +84,7 @@ public slots:
void onUDevHotPluginRemove(QString strUdevSubName, QString strUdevType);
void onLshwInfoUpdateFinished();
signals:
Q_SIGNALS:
void updateInfo(unsigned uStatus);
protected:

View File

@ -27,11 +27,21 @@
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
#include <qx11info_x11.h>
//#include <qx11info_x11.h>
#include <QApplication>
#include <X11/extensions/Xrandr.h>
//#include <X11/extensions/Xrandr.h>
#include <QScrollBar>
#include <KF5/KScreen/kscreen/output.h>
#include <KF5/KScreen/kscreen/edid.h>
#include <KF5/KScreen/kscreen/mode.h>
#include <KF5/KScreen/kscreen/config.h>
#include <KF5/KScreen/kscreen/getconfigoperation.h>
#include <KF5/KScreen/kscreen/configmonitor.h>
#include <KF5/KScreen/kscreen/setconfigoperation.h>
#include <KF5/KScreen/kscreen/edid.h>
#include <KF5/KScreen/kscreen/types.h>
MonitorInfo::MonitorInfo(QWidget *parent)
: KABaseInfoPage(parent)
{
@ -63,6 +73,12 @@ void MonitorInfo::initUI()
m_mainLayout->addWidget(m_scrollFrame);
this->setLayout(m_mainLayout);
// QObject::connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished,
// [&](KScreen::ConfigOperation *op) {
// this->setConfig(qobject_cast<KScreen::GetConfigOperation *>(op)->config());
// });
}
void MonitorInfo::onUpdateInfo(QString strInfoJson)
@ -77,55 +93,60 @@ void MonitorInfo::onUpdateInfo(QString strInfoJson)
void MonitorInfo::initConnections()
{
//注册监听xrr事件
XRRQueryExtension(QX11Info::display(), &m_xrrEventBase, &m_xrrErrorBase);
XRRSelectInput(QX11Info::display(), QX11Info::appRootWindow(), RRScreenChangeNotifyMask);
qApp->installNativeEventFilter(this); //监听全局x事件调用了这个才能收到nativeEventFilter
// //注册监听xrr事件
// // XRRQueryExtension(QX11Info::display(), &m_xrrEventBase, &m_xrrErrorBase);
// // XRRSelectInput(QX11Info::display(), QX11Info::appRootWindow(), RRScreenChangeNotifyMask);
// qApp->installNativeEventFilter(this); //监听全局x事件调用了这个才能收到nativeEventFilter
connect(DataWorker::getInstance(), SIGNAL(updateMonitorInfo(uint,QString)), this, SLOT(onUpdateInfo(uint,QString)));
QObject::connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished,
[&](KScreen::ConfigOperation *op) {
this->setConfig(qobject_cast<KScreen::GetConfigOperation *>(op)->config());
});
}
bool MonitorInfo::nativeEventFilter(const QByteArray &eventType, void *message, long *result) //监听全局x事件
{
if (qstrcmp(eventType, "xcb_generic_event_t") != 0) {
return false;
}
// if (qstrcmp(eventType, "xcb_generic_event_t") != 0) {
// return false;
// }
xcb_generic_event_t *event = reinterpret_cast<xcb_generic_event_t*>(message);
const uint8_t responseType = event->response_type & ~0x80;
if(responseType == m_xrrEventBase + RRScreenChangeNotify){
RRScreenChangeEvent(); //屏幕改变事件
}
// xcb_generic_event_t *event = reinterpret_cast<xcb_generic_event_t*>(message);
// const uint8_t responseType = event->response_type & ~0x80;
// if(responseType == m_xrrEventBase + RRScreenChangeNotify){
// RRScreenChangeEvent(); //屏幕改变事件
// }
return false;
}
void MonitorInfo::RRScreenChangeEvent()
{
XRRScreenResources *screen;
screen = XRRGetScreenResources(QX11Info::display(), QX11Info::appRootWindow());
XRROutputInfo *info;
int nCurCount = 0;
static int nLastCount = -1;
//void MonitorInfo::RRScreenChangeEvent()
//{
// XRRScreenResources *screen;
// screen = XRRGetScreenResources(QX11Info::display(), QX11Info::appRootWindow());
// XRROutputInfo *info;
// int nCurCount = 0;
// static int nLastCount = -1;
//这里只是屏幕改变事件,通过屏幕改变事件遍历所有
for (int i = 0; i < screen->noutput; i++) {
info = XRRGetOutputInfo(QX11Info::display(), screen, screen->outputs[i]);
if (info->connection == RR_Connected) {
nCurCount++;
}
XRRFreeOutputInfo(info);
}
/*
count为当前连接的显示器个数
*/
XRRFreeScreenResources(screen);
// //这里只是屏幕改变事件,通过屏幕改变事件遍历所有
// for (int i = 0; i < screen->noutput; i++) {
// info = XRRGetOutputInfo(QX11Info::display(), screen, screen->outputs[i]);
// if (info->connection == RR_Connected) {
// nCurCount++;
// }
// XRRFreeOutputInfo(info);
// }
// /*
// count为当前连接的显示器个数每次记录并比较就可以得到显示器的热插拔事件
// */
// XRRFreeScreenResources(screen);
// 屏幕数发生变化,获取最新屏幕信息
if (nCurCount != nLastCount) {
nLastCount = nCurCount;
DataWorker::getInstance()->getMonitorInfo(true);
}
}
// // 屏幕数发生变化,获取最新屏幕信息
// if (nCurCount != nLastCount) {
// nLastCount = nCurCount;
// DataWorker::getInstance()->getMonitorInfo(true);
// }
//}
void MonitorInfo::clearInfoItems()
{
@ -289,3 +310,72 @@ void MonitorInfo::chkNoDevice()
addInfoItems(0, MONITORINFO_INVALID, "", tr("Device not exitst or Get Device is Empty"), false);
}
}
void MonitorInfo::setConfig(const KScreen::ConfigPtr &config)
{
qDebug() << Q_FUNC_INFO;
if (mConfig) {
KScreen::ConfigMonitor::instance()->removeConfig(mConfig);
for (const KScreen::OutputPtr &output : mConfig->outputs()) {
output->disconnect(this);
}
mConfig->disconnect(this);
}
mConfig = config;
KScreen::ConfigMonitor::instance()->addConfig(mConfig);
for (const KScreen::OutputPtr &output : mConfig->outputs()) {
outputAdded(output, false);
connect(output.data(), &KScreen::Output::isConnectedChanged,
this, &MonitorInfo::slotOutputConnectedChanged);
}
connect(mConfig.data(), &KScreen::Config::outputAdded,
this, [=](const KScreen::OutputPtr &output){
DataWorker::getInstance()->getMonitorInfo(true);
});
connect(mConfig.data(), &KScreen::Config::outputRemoved,
this, [=](int outputId){
DataWorker::getInstance()->getMonitorInfo(true);
});
}
void MonitorInfo::outputAdded(const KScreen::OutputPtr &output, bool connectChanged)
{
if (true) {
qDebug()<<output;
connect(output.data(), &KScreen::Output::isConnectedChanged,
this, &MonitorInfo::slotOutputConnectedChanged);
connect(output.data(), &KScreen::Output::isEnabledChanged,
this, [=](){
DataWorker::getInstance()->getMonitorInfo(true);
});
// connect(output.data(), &KScreen::Output::sizeChanged,
// this, [=](){
// });
}
}
void MonitorInfo::slotOutputConnectedChanged()
{
DataWorker::getInstance()->getMonitorInfo(true);
// const KScreen::OutputPtr output(qobject_cast<KScreen::Output *>(sender()), [](void *){});
// if (!output) {
// return;
// }
// if (output->isConnected()) {
// outputAdded(output, true);
// } else {
// // outputRemoved(output->id(), true);
// }
}
s

View File

@ -31,6 +31,10 @@
#include "../../src/kajsondef.h"
#include "kainfotitle.h"
#include "kabaseinfopage.h"
#ifdef signals
#undef signals
#endif
#include <KF5/KScreen/kscreen/config.h>
enum MNI_INDEX{
MONITORINFO_TITLE,
@ -61,10 +65,13 @@ public:
void initConnections();
void updateInfoItems(QString strInfoJson);
public slots:
public Q_SLOTS:
void onUpdateInfo(QString strInfoJson) override;
void onRefreshInfo() override;
private Q_SLOTS:
void slotOutputConnectedChanged();
protected:
virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
@ -73,6 +80,8 @@ private:
void clearInfoItems();
void chkNoDevice();
void RRScreenChangeEvent();
void setConfig(const KScreen::ConfigPtr &config);
void outputAdded(const KScreen::OutputPtr &output, bool connectChanged);
private:
QString m_strInfoJson;
@ -85,6 +94,17 @@ private:
QMap<unsigned,QMap<unsigned, QWidget*>> m_mapInfoItems;
int m_xrrEventBase = 0;
int m_xrrErrorBase = 0;
#if QT_VERSION <= QT_VERSION_CHECK(5, 12, 0)
KScreen::ConfigPtr mConfig;
KScreen::ConfigPtr mPrevConfig;
KScreen::OutputPtr res; // 这是outPutptr结果
#else
KScreen::ConfigPtr mConfig = nullptr;
KScreen::ConfigPtr mPrevConfig = nullptr;
KScreen::OutputPtr res = nullptr;
#endif
};
#endif // MONITORINFO_H

View File

@ -33,7 +33,7 @@ public:
~UDevHotPlugin();
void stopDevHotPlugin();
signals:
Q_SIGNALS:
void sendUdevAddNotify(QString strUdevSubName, QString strUdevType);
void sendUdevRemoveNotify(QString strUdevSubName, QString strUdevType);

View File

@ -32,11 +32,11 @@ AboutWidget::AboutWidget(QWidget *parent):
// this->setAttribute(Qt::WA_DeleteOnClose);
// 添加窗管协议
MotifWmHints hints;
hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS;
hints.functions = MWM_FUNC_ALL;
hints.decorations = MWM_DECOR_BORDER;
XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hints);
// MotifWmHints hints;
// hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS;
// hints.functions = MWM_FUNC_ALL;
// hints.decorations = MWM_DECOR_BORDER;
// XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hints);
initUI();
}

View File

@ -19,9 +19,10 @@
*/
#include "kaaboutdialog.h"
#include "xatom-helper.h"
//#include "xatom-helper.h"
#include "commondef.h"
#include "utils.h"
#include "ukuistylehelper/ukuistylehelper.h"
#include <QDesktopServices>
#include <QPainterPath>
@ -34,14 +35,15 @@ KAAboutDialog::KAAboutDialog(QWidget *parent)
{
setFixedSize(420, 460);
MotifWmHints hints;
hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS;
hints.functions = MWM_FUNC_ALL;
hints.decorations = MWM_DECOR_BORDER;
XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hints);
// MotifWmHints hints;
// hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS;
// hints.functions = MWM_FUNC_ALL;
// hints.decorations = MWM_DECOR_BORDER;
// XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hints);
m_fFontSize = 12;
initWidgets();
initConnections();
kdk::UkuiStyleHelper::self()->removeHeader(this);
}
KAAboutDialog::~KAAboutDialog()

View File

@ -94,11 +94,11 @@ int main(int argc, char *argv[])
}
MainWindow w;
MotifWmHints hints;
hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
hints.functions = MWM_FUNC_ALL;
hints.decorations = MWM_DECOR_BORDER;
XAtomHelper::getInstance()->setWindowMotifHint(w.winId(), hints);
// MotifWmHints hints;
// hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
// hints.functions = MWM_FUNC_ALL;
// hints.decorations = MWM_DECOR_BORDER;
// XAtomHelper::getInstance()->setWindowMotifHint(w.winId(), hints);
app.setActivationWindow(&w);
app.setWindowIcon(QIcon::fromTheme("kylin-assistant"));
KWindowEffects::enableBlurBehind(w.winId(), true);

View File

@ -21,6 +21,7 @@
#include "mainwindow.h"
#include "commondef.h"
#include "dataworker.h"
#include "ukuistylehelper/ukuistylehelper.h"
#include <unistd.h>
#include <QDebug>
@ -49,6 +50,7 @@ MainWindow::MainWindow(QWidget *parent)
initOpacityGSettings();
initUI();
initConnections();
kdk::UkuiStyleHelper::self()->removeHeader(this);
}
MainWindow::~MainWindow()
@ -225,6 +227,7 @@ void MainWindow::initRightPanel()
QString(":/imgres/img_res/%1.svg").arg(pluginInstance->name()));
}
}
kdk::UkuiStyleHelper::self()->removeHeader(m_rightWidget);
m_mainLayout->addWidget(m_rightWidget, 0, Qt::AlignRight);
}

View File

@ -5,7 +5,7 @@ CONFIG += c++11
#CONFIG += qt warn_on
#CONFIG += release
CONFIG += link_pkgconfig
PKGCONFIG += glib-2.0 gio-unix-2.0 gsettings-qt
PKGCONFIG += glib-2.0 gio-unix-2.0 gsettings-qt kysdk-waylandhelper
QT += core dbus network charts svg KWindowSystem x11extras
LIBS += -lukui-log4qt