🐞 fix(手机投屏): 修改Wayland下关于窗口的问题

修改窗口位置错误以及鼠标拖拽问题
This commit is contained in:
huheng@kylinos.cn 2023-03-29 14:44:00 +08:00
parent 6b806ec182
commit 18d684d8b7
3 changed files with 32 additions and 49 deletions

View File

@ -170,6 +170,16 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${KYSDK_QTWIDGETS_INCLUDE_DIR
target_link_directories(${PROJECT_NAME} PRIVATE ${KYSDK_QTWIDGETS_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${KYSDK_QTWIDGETS_LIBRARIES})
pkg_check_modules(KYSDKKABASE_PKG kysdk-kabase)
target_include_directories(${PROJECT_NAME} PRIVATE ${KYSDKKABASE_PKG_INCLUDE_DIRS})
target_link_directories(${PROJECT_NAME} PRIVATE ${KYSDKKABASE_PKG_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${KYSDKKABASE_PKG_LIBRARIES})
pkg_check_modules(KYSDK_WAYLANDHELPER kysdk-waylandhelper)
target_include_directories(${PROJECT_NAME} PUBLIC ${KYSDK_WAYLANDHELPER_INCLUDE_DIRS})
target_link_directories(${PROJECT_NAME} PUBLIC ${KYSDK_WAYLANDHELPER_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME} PUBLIC ${KYSDK_WAYLANDHELPER_LIBRARIES})
target_include_directories(projection PRIVATE /usr/include/KF5/KWindowSystem)
target_include_directories(projection PRIVATE ${TOP_DIR}/../kabase/Qt)
target_link_libraries(projection PUBLIC

View File

@ -13,6 +13,8 @@
#include <uibase/tipwidget.h>
#include <KWindowSystem>
#include <scrollsettingwidget.h>
#include "windowmanager/windowmanager.h"
#include <ukuistylehelper/ukuistylehelper.h>
#include "config.h"
#include "controller.h"
@ -39,11 +41,12 @@ VideoForm::VideoForm(QWidget *parent, int screenIndex) : QWidget(parent), ui(new
m_screenIndex = screenIndex;
if (m_screenIndex != 0) {
QDesktopWidget *desktop = QApplication::desktop();
this->setGeometry(desktop->screenGeometry(m_screenIndex));
kdk::WindowManager::setGeometry(windowHandle(), desktop->screenGeometry(m_screenIndex));
}
ui->setupUi(this);
kdk::UkuiStyleHelper::self()->removeHeader(this);
initUI();
this->setProperty("useStyleWindowManager", false);
this->setProperty("useStyleWindowManager", true);
// 注册快捷键
installShortcut();
@ -53,7 +56,6 @@ VideoForm::VideoForm(QWidget *parent, int screenIndex) : QWidget(parent), ui(new
this->installEventFilter(this);
ui->keepRatioWidget->installEventFilter(this);
ui->toolform->installEventFilter(this);
ui->title->installEventFilter(this);
initConnect();
initPanelSetting();
@ -189,7 +191,7 @@ QRect VideoForm::getScreenRect()
screenRect.setWidth(screenRect.width() - panelWidth);
}
} else {
this->setGeometry(desktop->screenGeometry(m_screenIndex));
kdk::WindowManager::setGeometry(windowHandle(), desktop->screenGeometry(m_screenIndex));
QList<QScreen *> screenList = QGuiApplication::screens();
screenRect = screenList[m_screenIndex]->geometry();
}
@ -217,9 +219,13 @@ void VideoForm::moveCenter()
}
// 垂直窗口在最右侧,横屏时窗口居中
if (m_isVertical) {
this->move(screenRect.topRight() - QRect(0, 0, size().width(), size().height()).topRight());
kdk::WindowManager::setGeometry(
windowHandle(),
QRect((screenRect.topRight() - QRect(0, 0, size().width(), size().height()).topRight()), size()));
} else {
this->move(screenRect.center() - QRect(0, 0, size().width(), size().height()).center());
kdk::WindowManager::setGeometry(
windowHandle(),
QRect((screenRect.center() - QRect(0, 0, size().width(), size().height()).center()), size()));
}
}
@ -508,7 +514,8 @@ bool VideoForm::eventFilter(QObject *watch, QEvent *event)
}
case QEvent::Resize: {
if (m_toolForm) {
m_toolForm->move(0, this->height() - 40);
kdk::WindowManager::setGeometry(m_toolForm->windowHandle(),
QRect(QPoint(0, this->height() - 40), m_toolForm->size()));
m_toolForm->setFixedWidth(this->width());
}
}
@ -516,39 +523,6 @@ bool VideoForm::eventFilter(QObject *watch, QEvent *event)
break;
}
}
if (watch == ui->title) {
switch (event->type()) {
case QEvent::Enter: {
this->setCursor(Qt::ArrowCursor);
return true;
}
case QEvent::MouseButtonPress: {
QMouseEvent *mouseEvent = (QMouseEvent *)event;
if (mouseEvent->buttons() == Qt::LeftButton) {
m_isMousePress = true;
m_startWindowPos = mouseEvent->globalPos();
}
return true;
}
case QEvent::MouseMove: {
QMouseEvent *mouseEvent = (QMouseEvent *)event;
// 自定义标题栏拖拽
if (m_isMousePress && (!(m_isMax || m_isFull))) {
this->setCursor(Qt::OpenHandCursor);
this->move(this->geometry().topLeft() + mouseEvent->globalPos() - m_startWindowPos);
m_startWindowPos = mouseEvent->globalPos();
}
return true;
}
case QEvent::MouseButtonRelease: {
m_isMousePress = false;
this->setCursor(Qt::ArrowCursor);
return true;
}
default:
break;
}
}
if (watch == ui->keepRatioWidget) {
switch (event->type()) {
case QEvent::MouseButtonPress: {
@ -592,7 +566,8 @@ bool VideoForm::eventFilter(QObject *watch, QEvent *event)
Q_EMIT m_device->mouseEvent(mouseEvent, m_videoWidget->frameSize(), m_videoWidget->size());
} else if (!m_dragPosition.isNull()) {
if (mouseEvent->buttons() & Qt::LeftButton) {
move(mouseEvent->globalPos() - m_dragPosition);
kdk::WindowManager::setGeometry(windowHandle(),
QRect((mouseEvent->globalPos() - m_dragPosition), size()));
mouseEvent->accept();
}
}
@ -801,15 +776,15 @@ void VideoForm::windowZoom()
if (tempGeometry.height() >= screenRect.height()) {
tempGeometry.setHeight(screenRect.height());
tempGeometry.setWidth((tempGeometry.height() - m_titleHeight) * m_widthHeightRatio - ERROR_LENGTH);
this->setGeometry(tempGeometry);
kdk::WindowManager::setGeometry(windowHandle(), tempGeometry);
this->resizeFlag = false;
} else if (tempGeometry.height() <= (screenRect.height() / 2)) {
tempGeometry.setHeight(screenRect.height() / 2);
tempGeometry.setWidth((tempGeometry.height() - m_titleHeight) * m_widthHeightRatio + ERROR_LENGTH);
this->setGeometry(tempGeometry);
kdk::WindowManager::setGeometry(windowHandle(), tempGeometry);
this->resizeFlag = false;
}
this->setGeometry(tempGeometry);
kdk::WindowManager::setGeometry(windowHandle(), tempGeometry);
}
this->setFixedSize(this->width(), this->height());
}
@ -875,14 +850,14 @@ void VideoForm::onMaxButtonClick(bool max)
if (m_isMax) {
if (m_beforeIsVertical == m_isVertical) {
setFixedSize(m_beforeSize);
move(m_beforePoint);
kdk::WindowManager::setGeometry(windowHandle(), QRect(m_beforePoint, size()));
} else {
setWindowSize();
}
} else {
if (m_isVertical) {
this->setFixedSize((height - m_titleHeight) * m_widthHeightRatio, height);
move(m_beforePoint.x(), 0);
kdk::WindowManager::setGeometry(windowHandle(), QRect(QPoint(m_beforePoint.x(), 0), size()));
} else {
this->setFixedSize(width, height);
}
@ -906,7 +881,7 @@ void VideoForm::onFullScreen()
}
if (m_beforeIsVertical == m_isVertical) {
setFixedSize(m_beforeSize);
move(m_beforePoint);
kdk::WindowManager::setGeometry(windowHandle(), QRect(m_beforePoint, size()));
} else {
setWindowSize();
}

View File

@ -118,8 +118,6 @@ private:
bool m_isToolFormShow = true; // 是否展示导航栏
bool m_isMax = false; // 窗口最大化
bool m_isFull = false; // 窗口全屏
bool m_isMousePress = false; // 鼠标按下
QPoint m_startWindowPos;
QPoint m_beforePoint;
QSize m_beforeSize;
bool m_beforeIsVertical;