- #127087, 解决wayland环境下,搜索框输入歌曲名称,音乐应用闪退问题
    - #126585,解决wayland环境下,音乐打开显示位置不固定问题

* 需求号: 无
* 其他改动说明: 无
* 其他改动影响域:无
This commit is contained in:
yushuoqi 2022-07-05 19:54:03 +08:00
parent 8d0ed22e22
commit 6b71b3bbf3
10 changed files with 280 additions and 59 deletions

View File

@ -2,6 +2,11 @@
#include <QDBusMessage>
#include "mainwidget.h"
#include "UI/base/xatom-helper.h"
#include "ukuistylehelper/ukuistylehelper.h"
#include "windowmanager/windowmanager.h"
#include "UIControl/global/global.h"
#include <ukui-log4qt.h>
#define UKUI_FONT_SIZE "systemFontSize"
@ -617,24 +622,26 @@ void Widget::initAllComponent()
musicListTable = new TableOne(playlistName,this);
playSongArea = new PlaySongArea(this);
m_titleBar = new TitleBar(this);
// musicListTable->hide();
// playSongArea->hide();
// 去掉标题栏
MotifWmHints hintt;
hintt.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS;
hintt.functions = MWM_FUNC_ALL;
hintt.decorations = MWM_DECOR_BORDER;
XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hintt);
m_miniWidget = new miniWidget();
MotifWmHints hints;
hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS;
hints.functions = MWM_FUNC_ALL;
hints.decorations = MWM_DECOR_BORDER;
XAtomHelper::getInstance()->setWindowMotifHint(m_miniWidget->winId(), hints);
if (Global::isWayland) {
kdk::UkuiStyleHelper::self()->removeHeader(this);
} else {
// 去掉标题栏
MotifWmHints hintt;
hintt.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS;
hintt.functions = MWM_FUNC_ALL;
hintt.decorations = MWM_DECOR_BORDER;
XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hintt);
MotifWmHints hints;
hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS;
hints.functions = MWM_FUNC_ALL;
hints.decorations = MWM_DECOR_BORDER;
XAtomHelper::getInstance()->setWindowMotifHint(m_miniWidget->winId(), hints);
}
rightVWidget = new QWidget(this);
@ -656,11 +663,18 @@ void Widget::initAllComponent()
this->setLayout(mainHBoxLayout);
historyListTable = new TableHistory(this);
MotifWmHints hint;
hint.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS;
hint.functions = MWM_FUNC_ALL;
hint.decorations = MWM_DECOR_BORDER;
XAtomHelper::getInstance()->setWindowMotifHint(historyListTable->winId(), hint);
if (Global::isWayland) {
kdk::UkuiStyleHelper::self()->removeHeader(this);
} else {
MotifWmHints hint;
hint.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS;
hint.functions = MWM_FUNC_ALL;
hint.decorations = MWM_DECOR_BORDER;
XAtomHelper::getInstance()->setWindowMotifHint(historyListTable->winId(), hint);
}
historyListTable->hide();
this->setAutoFillBackground(true);
@ -850,6 +864,14 @@ void Widget::movePlayHistoryWid()
historyListTable->move(historyPos);
}
void Widget::showMyWindow()
{
kdk::UkuiStyleHelper::self()->removeHeader(this);
show();
// kdk::WindowManager::setGeometry(this->windowHandle(), QRect(0, 0, 960, 640));
}
#if 0
void Widget::paintEvent(QPaintEvent *event)
{

View File

@ -33,6 +33,10 @@
#include <QProcess>
#include "./dbusadapter.h"
#include "ukui-wayland/ukui-decoration-client.h"
#include "ukui-wayland/ukui-decoration-manager.h"
#include "ukui-wayland/plasma-shell-manager.h"
#include "UIControl/base/musicDataBase.h"
#include "UI/tableview/tableone.h"
#include "UIControl/tableview/musiclistmodel.h"
@ -55,6 +59,8 @@ public:
//计算播放历史
void movePlayHistoryWid();
void showMyWindow();
// 毛玻璃
// void paintEvent(QPaintEvent *event);
void transparencyChange();

View File

@ -18,6 +18,10 @@
#include "miniwidget.h"
#include "UI/base/widgetstyle.h"
#include "UI/mainwidget.h"
#include "ukuistylehelper/ukuistylehelper.h"
#include "windowmanager/windowmanager.h"
#include "UIControl/global/global.h"
#include <QDebug>
#define PT_9 9
@ -43,6 +47,8 @@ miniWidget::miniWidget(QWidget *parent) : QFrame(parent)
initAction();
initConnect();
initStyle();
}
void miniWidget::initAction()

View File

@ -1,5 +1,8 @@
#include "searchedit.h"
#include "UI/base/xatom-helper.h"
#include "ukuistylehelper/ukuistylehelper.h"
#include "windowmanager/windowmanager.h"
#include "UIControl/global/global.h"
SearchEdit::SearchEdit(QWidget *parent) : KSearchLineEdit(parent)
{
@ -12,29 +15,40 @@ SearchEdit::SearchEdit(QWidget *parent) : KSearchLineEdit(parent)
m_result = new SearchResult(m_mainWidget);
m_result->setSearchEdit(this);
MotifWmHints hints;
hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS;
hints.functions = MWM_FUNC_ALL;
hints.decorations = MWM_DECOR_BORDER;
XAtomHelper::getInstance()->setWindowMotifHint(m_result->winId(), hints);
moveSearchResult();
if (Global::isWayland) {
kdk::UkuiStyleHelper::self()->removeHeader(this);
} else {
MotifWmHints hints;
hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS;
hints.functions = MWM_FUNC_ALL;
hints.decorations = MWM_DECOR_BORDER;
XAtomHelper::getInstance()->setWindowMotifHint(m_result->winId(), hints);
}
// moveSearchResult();
}
void SearchEdit::keyPressEvent(QKeyEvent *event)
{
if(m_result == nullptr)
{
if(m_result == nullptr) {
return;
}
if(event->key() == Qt::Key_Up)
{
switch (event->key()) {
case Qt::Key_Up:
m_result->selectUp();
}
if(event->key() == Qt::Key_Down)
{
break;
case Qt::Key_Down:
m_result->selectDown();
break;
case Qt::Key_Escape:
m_result->hide();
default:
break;
}
QLineEdit::keyPressEvent(event);
}
@ -78,13 +92,10 @@ void SearchEdit::slotTextChanged()
if (text.length() >= 1) {
m_result->setListviewSearchString(text);
moveSearchResult();
m_result->show();
// m_result->activateWindow();
// m_result->raise();
m_result->autoResize();
moveSearchResult();
// m_result->activateWindow();
// m_result->setFocusPolicy(Qt::StrongFocus);
// m_result->raise();
} else {
m_result->hide();
}
@ -117,14 +128,26 @@ void SearchEdit::setWidget(QWidget *mainWidget)
void SearchEdit::moveSearchResult()
{
m_result->show();
m_result->raise();
m_result->setFixedWidth(240);
QPoint resultPos = this->mapToGlobal(this->rect().bottomLeft());
resultPos.setX(resultPos.x());
resultPos.setY(resultPos.y() + 12);
QSize editSize = this->size();
int newPosX = resultPos.x();
QSize editSize = this->size();
int newPosY = resultPos.y() - editSize.height() - 12;
m_result->changeSrearchResultPos(newPosX, newPosY, editSize.width(), editSize.height());
m_result->move(resultPos);
if (Global::isWayland) {
kdk::WindowManager::setGeometry(m_result->windowHandle(), QRect(newPosX, newPosY + 12 + editSize.height() *2 , editSize.width(), editSize.height()));
} else {
m_result->move(resultPos);
}
}

View File

@ -9,12 +9,20 @@
#include <X11/extensions/XTest.h>
#include "UI/base/xatom-helper.h"
#include "ukuistylehelper/ukuistylehelper.h"
#include "windowmanager/windowmanager.h"
#include "UIControl/global/global.h"
SearchResult::SearchResult(QWidget *parent) : QWidget(parent)
{
this->setAutoFillBackground(true);
this->setBackgroundRole(QPalette::Base);
this->setWindowFlag(Qt::Tool);
if (Global::isWayland) {
kdk::UkuiStyleHelper::self()->removeHeader(this);
}
//窗体禁止拖动
this->setProperty("useStyleWindowManager", false);
vlayout = new QVBoxLayout(this);
@ -94,7 +102,7 @@ SearchResult::SearchResult(QWidget *parent) : QWidget(parent)
sideLayout->setSpacing(0);
this->setLayout(sideLayout);
autoResize();
// autoResize();
connect(m_MusicView,&MusicSearchListview::clicked,this,&SearchResult::slotMusicItemClicked);
connect(m_SingerView,&MusicSearchListview::clicked,this,&SearchResult::slotSingerItemClicked);
@ -109,15 +117,34 @@ SearchResult::~SearchResult()
void SearchResult::keyPressEvent(QKeyEvent *event)
{
// m_searchEdit->raise();
m_searchEdit->activateWindow();
if (Global::isWayland) {
kdk::UkuiStyleHelper::self()->removeHeader(this);
// kdk::WindowManager::activateWindow(m_searchEdit->winId());
} else {
m_searchEdit->activateWindow();
}
// QApplication::sendEvent(m_searchEdit,event);
setCursorWithXEvent();
if (Global::isWayland) {
QPoint point = m_searchEdit->mapToGlobal(QPoint(m_searchEdit->rect().topRight().x() - 10,m_searchEdit->rect().topRight().y() - 5));
} else {
setCursorWithXEvent();
}
if (event->key() == Qt::Key_Return) {
this->hide();
return;
}
if (event->key() == Qt::Key_Escape) {
this->hide();
return;
}
if (event->key() == Qt::Key_Backspace) {
QApplication::sendEvent(m_searchEdit,event);
Q_EMIT m_searchEdit->textChanged(m_searchEdit->text());
@ -127,14 +154,20 @@ void SearchResult::keyPressEvent(QKeyEvent *event)
m_key = event->nativeVirtualKey();
QTimer *timer = new QTimer;
timer->setSingleShot(true);
connect(timer,&QTimer::timeout,this,[=]{
Display *display = XOpenDisplay(NULL);
XTestFakeKeyEvent(display, XKeysymToKeycode(display,m_key), 1, 10);
XFlush(display);
XTestFakeKeyEvent(display, XKeysymToKeycode(display,m_key), 0, 10);
XFlush(display);
XCloseDisplay(display);
});
if (Global::isWayland) {
} else {
connect(timer,&QTimer::timeout,this,[=]{
Display *display = XOpenDisplay(NULL);
XTestFakeKeyEvent(display, XKeysymToKeycode(display,m_key), 1, 10);
XFlush(display);
XTestFakeKeyEvent(display, XKeysymToKeycode(display,m_key), 0, 10);
XFlush(display);
XCloseDisplay(display);
});
}
connect(timer,&QTimer::timeout,timer,&QTimer::deleteLater);
timer->start(200);
@ -182,7 +215,12 @@ void SearchResult::autoResize()
if (m_searchEdit->text() != "") {
this->show();
this->raise();
this->activateWindow();
if (Global::isWayland) {
// kdk::WindowManager::activateWindow(kdk::WindowManager::currentActiveWindow());
} else {
this->activateWindow();
}
}
}
@ -356,7 +394,22 @@ void SearchResult::setSearchEdit(SearchEdit *edit)
bool SearchResult::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
Q_UNUSED(result);
if (Global::isWayland) {
return 0;
#if 0
QRect rect(m_resultPosX, m_resultPosY, m_resultPosWidth, m_resultPosHeight);
if(rect.contains(QCursor::pos(), false)) {
return 0;
} else {
this->hide();
return false;
}
#endif
}
if(eventType != "xcb_generic_event_t")
{
return false;
@ -386,6 +439,10 @@ void SearchResult::changeSrearchResultPos(int posX, int posY, int width, int hei
m_resultPosY = posY;
m_resultPosWidth = width;
m_resultPosHeight = height;
qDebug() << "m_resultPos(x, y, width, height) = "
<< m_resultPosX << m_resultPosY
<< m_resultPosWidth << m_resultPosHeight;
}
void SearchResult::onReturnPressed()

View File

@ -0,0 +1,27 @@
#include "global.h"
#include <QSettings>
#include <QGSettings>
#include <QApplication>
#include <QFile>
#include <QDebug>
bool Global::isWayland = false;
using namespace Global;
void Global::global_init() {
// 运行环境
if(QString(qgetenv("XDG_SESSION_TYPE")) == "wayland") {
qputenv("QT_QPA_PLATFORM", "wayland");
isWayland = true;
} else {
isWayland = false;
}
}
void Global::global_end() {
}

48
UIControl/global/global.h Normal file
View File

@ -0,0 +1,48 @@
/* smplayer, GUI front-end for mplayer.
Copyright (C) 2006-2015 Ricardo Villalba <rvm@users.sourceforge.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _GLOBAL_H_
#define _GLOBAL_H_
#include <QString>
#include <QSettings>
#include <KF5/KWindowSystem/kwindoweffects.h>
class QSettings;
class QGSettings;
namespace Global {
// 错误类型
enum KERROR_TYPE{
NO_ERROR = 0
};
//! Read and store application settings
extern bool isWayland;
void global_init();
void global_end();
}
#endif

3
debian/control vendored
View File

@ -17,6 +17,9 @@ Build-Depends: cmake,
xorg-dev,
libkf5wayland-dev,
libwayland-dev,
libkysdk-waylandhelper,
libkysdk-waylandhelper-dev,
libkysdk-appcommon,
libsqlite3-dev,
libtag1-dev,
libukui-log4qt-dev,

View File

@ -57,7 +57,7 @@ INSTALLS += \
CONFIG += link_pkgconfig
PKGCONFIG += gsettings-qt taglib gio-unix-2.0 kysdk-qtwidgets wayland-client
PKGCONFIG += gsettings-qt taglib gio-unix-2.0 kysdk-qtwidgets wayland-client kysdk-waylandhelper
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
@ -112,6 +112,7 @@ SOURCES += \
UIControl/base/daemonipcdbus.cpp \
UIControl/base/musicDataBase.cpp \
UIControl/base/musicfileinformation.cpp \
UIControl/global/global.cpp \
UIControl/player/coreplayer/mmediaplayer.cpp \
UIControl/player/coreplayer/mmediaplaylist.cpp \
UIControl/player/player.cpp \
@ -155,6 +156,7 @@ HEADERS += \
UIControl/base/daemonipcdbus.h \
UIControl/base/musicDataBase.h \
UIControl/base/musicfileinformation.h \
UIControl/global/global.h \
UIControl/player/coreplayer/mmediaplayer.h \
UIControl/player/coreplayer/mmediaplaylist.h \
UIControl/player/player.h \

View File

@ -1,6 +1,11 @@
#include "UI/mainwidget.h"
#include "UI/base/xatom-helper.h"
#include "ukuistylehelper/ukuistylehelper.h"
#include "windowmanager/windowmanager.h"
#include "UIControl/global/global.h"
#include <QApplication>
#include <QGuiApplication>
#include <QDebug>
#include <ukui-log4qt.h>
@ -77,11 +82,16 @@ int main(int argc, char *argv[])
}
initUkuiLog4qt("kylin-music");
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
bool isWayland = false;
if(QString(qgetenv("XDG_SESSION_TYPE")) == "wayland") {
qputenv("QT_QPA_PLATFORM", "wayland");
isWayland = true;
} else {
// 适配4K屏,高清屏幕自适应
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
@ -93,13 +103,12 @@ int main(int argc, char *argv[])
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
}
// qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
// //高清屏幕自适应
// QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
// QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QApplication a(argc, argv);
a.setWindowIcon(QIcon::fromTheme("kylin-music"));
Global::global_init();
QTranslator trankdk;
QString localeKdk = QLocale::system().name();
if(localeKdk == "zh_CN")
@ -201,8 +210,26 @@ int main(int argc, char *argv[])
}
}
}
Widget w(strList);
if(isWayland) {
// 去除窗管标题栏传入参数为QWidget *
kdk::UkuiStyleHelper::self()->removeHeader(&w);
}
w.show();
w.creartFinish();
if(isWayland) {
// UKUIDecorationManager::getInstance()->setCornerRadius(w.windowHandle(), 12, 12, 12, 12);
// set window position
int sw = QGuiApplication::primaryScreen()->availableGeometry().width();
int sh = QGuiApplication::primaryScreen()->availableGeometry().height();
kdk::WindowManager::setGeometry(w.windowHandle(), QRect((sw-w.width())/2, (sh-w.height())/2, w.width(), w.height()));
}
return a.exec();
}