fix: 屏幕参数错误

display 服务中获取的屏幕宽高在旋转屏幕的特殊场景下会出错(宽高写反了),
故通过这个方法直接从 x 获取正确的值。

Log: 修复任务栏高度异常的问题。
Bug: https://pms.uniontech.com/zentao/bug-view-60892.html
Change-Id: I5a2030e32b41ce3c5f08d22f5750124feecda5c4
This commit is contained in:
Zhang Qipeng 2021-01-27 17:08:44 +08:00
parent a8dbbb7768
commit dd54b212f3
2 changed files with 34 additions and 1 deletions

View File

@ -207,6 +207,7 @@ void MultiScreenWorker::handleDbusSignal(QDBusMessage msg)
m_screenRawWidth = m_displayInter->screenWidth();
}
}
updateScreenSize();
}
}
@ -742,6 +743,8 @@ void MultiScreenWorker::onRequestUpdateFrontendGeometry()
void MultiScreenWorker::onRequestNotifyWindowManager()
{
static QRect lastRect = QRect();
static int lastScreenWith = 0;
static int lastScreenHeight = 0;
const auto ratio = qApp->devicePixelRatio();
QRect rect;
@ -752,9 +755,11 @@ void MultiScreenWorker::onRequestNotifyWindowManager()
}
// 已经设置过了,避免重复设置
if (rect == lastRect)
if (rect == lastRect && lastScreenWith == m_screenRawWidth && lastScreenHeight == m_screenRawHeight)
return;
lastRect = rect;
lastScreenWith = m_screenRawWidth;
lastScreenHeight = m_screenRawHeight;
qDebug() << "dock geometry:" << rect;
// 先清除原先的窗管任务栏区域
@ -1098,6 +1103,7 @@ void MultiScreenWorker::initDBus()
m_screenRawWidth = m_displayInter->screenWidth();
m_ds = DockScreen(m_displayInter->primary());
m_mtrInfo.setPrimary(m_displayInter->primary());
updateScreenSize();
}
}
@ -1730,6 +1736,32 @@ const QPoint MultiScreenWorker::rawXPosition(const QPoint &scaledPos)
: scaledPos;
}
/**
* @brief xcb
* display
* display
*/
void MultiScreenWorker::updateScreenSize()
{
/* Open the connection to the X server. Use the DISPLAY environment variable */
int screenNum;
xcb_connection_t *connection = xcb_connect(NULL, &screenNum);
/* Get the screen whose number is screenNum */
const xcb_setup_t *setup = xcb_get_setup(connection);
xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup);
/* we want the screen at index screenNum of the iterator */
for (int i = 0; i < screenNum; ++i) {
xcb_screen_next(&iter);
}
xcb_screen_t *screen = iter.data;
m_screenRawWidth = screen->width_in_pixels;
m_screenRawHeight = screen->height_in_pixels;
}
void MultiScreenWorker::onTouchPress(int type, int x, int y, const QString &key)
{
Q_UNUSED(type);

View File

@ -433,6 +433,7 @@ private:
bool contains(const MonitRect &rect, const QPoint &pos);
bool contains(const QList<MonitRect> &rectList, const QPoint &pos);
const QPoint rawXPosition(const QPoint &scaledPos);
void updateScreenSize();
private:
QWidget *m_parent;