2017-09-18 14:33:44 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 ~ 2017 Deepin Technology Co., Ltd.
|
|
|
|
*
|
|
|
|
* Author: sbw <sbw@sbw.so>
|
|
|
|
*
|
|
|
|
* Maintainer: sbw <sbw@sbw.so>
|
|
|
|
*
|
|
|
|
* 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 3 of the License, or
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-06-02 09:46:43 +08:00
|
|
|
#include "mainwindow.h"
|
2016-06-06 10:59:29 +08:00
|
|
|
#include "panel/mainpanel.h"
|
2016-06-02 09:46:43 +08:00
|
|
|
|
|
|
|
#include <QDebug>
|
2016-06-02 15:43:57 +08:00
|
|
|
#include <QResizeEvent>
|
2017-02-28 11:31:48 +08:00
|
|
|
#include <QScreen>
|
|
|
|
#include <QGuiApplication>
|
2017-11-13 21:17:56 +08:00
|
|
|
#include <qpa/qplatformwindow.h>
|
|
|
|
|
2017-03-21 15:40:52 +08:00
|
|
|
#include <DPlatformWindowHandle>
|
2016-06-02 09:46:43 +08:00
|
|
|
|
2017-06-08 15:38:11 +08:00
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
|
2017-11-14 14:20:04 +08:00
|
|
|
const QPoint rawXPosition(const QPoint &scaledPos)
|
|
|
|
{
|
|
|
|
QRect g = qApp->primaryScreen()->geometry();
|
|
|
|
for (auto *screen : qApp->screens())
|
|
|
|
{
|
|
|
|
const QRect &sg = screen->geometry();
|
|
|
|
if (sg.contains(scaledPos))
|
|
|
|
{
|
|
|
|
g = sg;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return g.topLeft() + (scaledPos - g.topLeft()) * qApp->devicePixelRatio();
|
|
|
|
}
|
|
|
|
|
2016-06-02 09:46:43 +08:00
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
2016-06-02 15:43:57 +08:00
|
|
|
: QWidget(parent),
|
2016-08-12 14:28:35 +08:00
|
|
|
|
|
|
|
m_updatePanelVisible(true),
|
|
|
|
|
2016-06-03 10:59:23 +08:00
|
|
|
m_mainPanel(new MainPanel(this)),
|
2017-03-21 15:40:52 +08:00
|
|
|
|
2017-03-27 15:36:37 +08:00
|
|
|
m_platformWindowHandle(this),
|
2017-05-11 10:10:32 +08:00
|
|
|
m_wmHelper(DWindowManagerHelper::instance()),
|
2017-03-21 15:40:52 +08:00
|
|
|
|
2016-06-23 20:05:03 +08:00
|
|
|
m_positionUpdateTimer(new QTimer(this)),
|
2016-08-18 16:06:40 +08:00
|
|
|
m_expandDelayTimer(new QTimer(this)),
|
2017-07-04 14:58:11 +08:00
|
|
|
m_sizeChangeAni(new QVariantAnimation(this)),
|
2017-11-13 21:17:56 +08:00
|
|
|
m_posChangeAni(new QVariantAnimation(this)),
|
2016-06-29 16:53:37 +08:00
|
|
|
m_panelShowAni(new QPropertyAnimation(m_mainPanel, "pos")),
|
|
|
|
m_panelHideAni(new QPropertyAnimation(m_mainPanel, "pos")),
|
2016-06-27 16:36:51 +08:00
|
|
|
m_xcbMisc(XcbMisc::instance())
|
2016-10-14 15:47:43 +08:00
|
|
|
|
2016-06-02 09:46:43 +08:00
|
|
|
{
|
2016-08-01 13:40:48 +08:00
|
|
|
setAccessibleName("dock-mainwindow");
|
2016-06-15 11:09:34 +08:00
|
|
|
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus);
|
2016-06-03 16:06:11 +08:00
|
|
|
setAttribute(Qt::WA_TranslucentBackground);
|
2017-07-04 14:34:38 +08:00
|
|
|
setAcceptDrops(true);
|
2016-06-03 16:06:11 +08:00
|
|
|
|
2017-03-27 15:36:37 +08:00
|
|
|
m_platformWindowHandle.setEnableBlurWindow(false);
|
|
|
|
m_platformWindowHandle.setTranslucentBackground(true);
|
|
|
|
m_platformWindowHandle.setWindowRadius(0);
|
|
|
|
m_platformWindowHandle.setBorderWidth(0);
|
|
|
|
m_platformWindowHandle.setShadowOffset(QPoint(0, 0));
|
2017-03-21 15:40:52 +08:00
|
|
|
|
2016-06-27 16:36:51 +08:00
|
|
|
m_settings = new DockSettings(this);
|
2016-06-15 11:09:34 +08:00
|
|
|
m_xcbMisc->set_window_type(winId(), XcbMisc::Dock);
|
|
|
|
|
2016-06-06 10:59:29 +08:00
|
|
|
initComponents();
|
|
|
|
initConnections();
|
2016-06-23 10:24:51 +08:00
|
|
|
|
|
|
|
m_mainPanel->setFixedSize(m_settings->windowSize());
|
2016-06-30 09:56:17 +08:00
|
|
|
|
|
|
|
updatePanelVisible();
|
2016-06-02 09:46:43 +08:00
|
|
|
}
|
2016-06-02 15:43:57 +08:00
|
|
|
|
2016-06-15 11:09:34 +08:00
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
|
|
|
delete m_xcbMisc;
|
|
|
|
}
|
|
|
|
|
2016-10-14 15:47:43 +08:00
|
|
|
QRect MainWindow::panelGeometry()
|
|
|
|
{
|
|
|
|
QRect rect = m_mainPanel->geometry();
|
|
|
|
rect.moveTopLeft(m_mainPanel->mapToGlobal(QPoint(0,0)));
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2016-06-02 15:43:57 +08:00
|
|
|
void MainWindow::resizeEvent(QResizeEvent *e)
|
|
|
|
{
|
|
|
|
QWidget::resizeEvent(e);
|
2017-03-21 15:40:52 +08:00
|
|
|
|
|
|
|
adjustShadowMask();
|
2016-06-02 15:43:57 +08:00
|
|
|
}
|
2016-06-03 16:06:11 +08:00
|
|
|
|
2016-06-21 14:02:51 +08:00
|
|
|
void MainWindow::mousePressEvent(QMouseEvent *e)
|
|
|
|
{
|
|
|
|
e->ignore();
|
|
|
|
|
|
|
|
if (e->button() == Qt::RightButton)
|
|
|
|
m_settings->showDockSettingsMenu();
|
|
|
|
}
|
|
|
|
|
2016-06-03 16:06:11 +08:00
|
|
|
void MainWindow::keyPressEvent(QKeyEvent *e)
|
|
|
|
{
|
|
|
|
switch (e->key())
|
|
|
|
{
|
|
|
|
#ifdef QT_DEBUG
|
|
|
|
case Qt::Key_Escape: qApp->quit(); break;
|
|
|
|
#endif
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:53:37 +08:00
|
|
|
void MainWindow::enterEvent(QEvent *e)
|
|
|
|
{
|
|
|
|
QWidget::enterEvent(e);
|
|
|
|
|
|
|
|
if (m_settings->hideState() != Show)
|
2016-08-18 16:06:40 +08:00
|
|
|
m_expandDelayTimer->start();
|
2016-06-29 16:53:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::leaveEvent(QEvent *e)
|
|
|
|
{
|
|
|
|
QWidget::leaveEvent(e);
|
|
|
|
|
2016-08-18 16:06:40 +08:00
|
|
|
m_expandDelayTimer->stop();
|
2016-06-29 16:53:37 +08:00
|
|
|
updatePanelVisible();
|
|
|
|
}
|
|
|
|
|
2017-07-04 14:34:38 +08:00
|
|
|
void MainWindow::dragEnterEvent(QDragEnterEvent *e)
|
|
|
|
{
|
|
|
|
QWidget::dragEnterEvent(e);
|
|
|
|
|
|
|
|
if (m_settings->hideState() != Show)
|
|
|
|
m_expandDelayTimer->start();
|
|
|
|
}
|
|
|
|
|
2016-06-23 20:05:03 +08:00
|
|
|
void MainWindow::setFixedSize(const QSize &size)
|
|
|
|
{
|
2017-06-15 09:10:29 +08:00
|
|
|
const QPropertyAnimation::State state = m_sizeChangeAni->state();
|
2016-07-18 17:10:15 +08:00
|
|
|
|
2017-07-14 14:05:35 +08:00
|
|
|
// qDebug() << state;
|
2016-07-18 17:10:15 +08:00
|
|
|
if (state == QPropertyAnimation::Stopped && this->size() == size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (state == QPropertyAnimation::Running)
|
2016-06-23 20:05:03 +08:00
|
|
|
return m_sizeChangeAni->setEndValue(size);
|
|
|
|
|
2017-11-13 21:17:56 +08:00
|
|
|
qDebug() << Q_FUNC_INFO << size;
|
2017-06-16 13:22:40 +08:00
|
|
|
|
2016-06-23 20:05:03 +08:00
|
|
|
m_sizeChangeAni->setStartValue(this->size());
|
|
|
|
m_sizeChangeAni->setEndValue(size);
|
|
|
|
m_sizeChangeAni->start();
|
|
|
|
}
|
|
|
|
|
2017-11-13 21:17:56 +08:00
|
|
|
void MainWindow::internalAnimationMove(int x, int y)
|
2016-06-23 20:05:03 +08:00
|
|
|
{
|
2016-07-18 17:10:15 +08:00
|
|
|
const QPropertyAnimation::State state = m_posChangeAni->state();
|
2017-07-14 14:05:35 +08:00
|
|
|
const QPoint p = m_posChangeAni->endValue().toPoint();
|
2017-06-08 15:38:11 +08:00
|
|
|
const QPoint tp = QPoint(x, y);
|
2016-07-18 17:10:15 +08:00
|
|
|
|
2017-06-08 15:38:11 +08:00
|
|
|
if (state == QPropertyAnimation::Stopped && p == tp)
|
2016-06-29 18:30:25 +08:00
|
|
|
return;
|
|
|
|
|
2017-11-13 21:17:56 +08:00
|
|
|
if (state == QPropertyAnimation::Running && m_posChangeAni->endValue() != tp)
|
|
|
|
return m_posChangeAni->setEndValue(QPoint(x, y));
|
2016-06-23 20:05:03 +08:00
|
|
|
|
2017-07-14 14:05:35 +08:00
|
|
|
m_posChangeAni->setStartValue(pos());
|
2017-06-08 15:38:11 +08:00
|
|
|
m_posChangeAni->setEndValue(tp);
|
2016-06-23 20:05:03 +08:00
|
|
|
m_posChangeAni->start();
|
|
|
|
}
|
|
|
|
|
2016-06-06 10:59:29 +08:00
|
|
|
void MainWindow::initComponents()
|
|
|
|
{
|
|
|
|
m_positionUpdateTimer->setSingleShot(true);
|
2016-06-30 18:02:09 +08:00
|
|
|
m_positionUpdateTimer->setInterval(20);
|
2016-06-06 10:59:29 +08:00
|
|
|
m_positionUpdateTimer->start();
|
2016-06-23 20:05:03 +08:00
|
|
|
|
2016-08-18 16:06:40 +08:00
|
|
|
m_expandDelayTimer->setSingleShot(true);
|
2016-09-06 11:31:03 +08:00
|
|
|
m_expandDelayTimer->setInterval(m_settings->expandTimeout());
|
2016-08-18 16:06:40 +08:00
|
|
|
|
2016-06-30 19:32:52 +08:00
|
|
|
m_sizeChangeAni->setEasingCurve(QEasingCurve::InOutCubic);
|
|
|
|
m_posChangeAni->setEasingCurve(QEasingCurve::InOutCubic);
|
|
|
|
m_panelShowAni->setEasingCurve(QEasingCurve::InOutCubic);
|
|
|
|
m_panelHideAni->setEasingCurve(QEasingCurve::InOutCubic);
|
2017-05-22 10:38:49 +08:00
|
|
|
|
|
|
|
QTimer::singleShot(1, this, &MainWindow::compositeChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::compositeChanged()
|
|
|
|
{
|
2017-07-14 14:05:35 +08:00
|
|
|
// qDebug() << Q_FUNC_INFO;
|
2017-06-16 13:22:40 +08:00
|
|
|
|
2017-05-22 10:38:49 +08:00
|
|
|
const int duration = m_wmHelper->hasComposite() ? 200 : 0;
|
|
|
|
|
|
|
|
m_sizeChangeAni->setDuration(duration);
|
|
|
|
m_posChangeAni->setDuration(duration);
|
|
|
|
m_panelShowAni->setDuration(duration);
|
|
|
|
m_panelHideAni->setDuration(duration);
|
2017-07-07 10:26:27 +08:00
|
|
|
|
|
|
|
m_positionUpdateTimer->start();
|
2016-06-06 10:59:29 +08:00
|
|
|
}
|
|
|
|
|
2017-11-23 12:21:00 +08:00
|
|
|
void MainWindow::internalMove(const QPoint &p)
|
2017-11-13 21:17:56 +08:00
|
|
|
{
|
2017-11-23 17:49:37 +08:00
|
|
|
const bool pos_adjust = m_settings->hideMode() != HideMode::KeepShowing &&
|
|
|
|
m_settings->hideState() == HideState::Hide &&
|
|
|
|
m_posChangeAni->state() == QVariantAnimation::Stopped;
|
|
|
|
if (!pos_adjust)
|
|
|
|
return QWidget::move(p);
|
|
|
|
|
2017-11-14 14:20:04 +08:00
|
|
|
QPoint rp = rawXPosition(p);
|
2017-11-23 17:49:37 +08:00
|
|
|
const auto ratio = devicePixelRatioF();
|
2017-11-13 21:17:56 +08:00
|
|
|
|
2017-11-23 17:49:37 +08:00
|
|
|
const QRect &r = m_settings->primaryRawRect();
|
|
|
|
switch (m_settings->position())
|
2017-11-13 21:17:56 +08:00
|
|
|
{
|
2017-11-23 17:49:37 +08:00
|
|
|
case Left: rp.setX(r.x()); break;
|
|
|
|
case Top: rp.setY(r.y()); break;
|
|
|
|
case Right: rp.setX(r.right() - 1); break;
|
|
|
|
case Bottom: rp.setY(r.bottom() - 1); break;
|
2017-11-13 21:17:56 +08:00
|
|
|
}
|
|
|
|
|
2017-11-17 10:58:18 +08:00
|
|
|
int hx = height() * ratio, wx = width() * ratio;
|
2017-11-13 21:17:56 +08:00
|
|
|
if (m_settings->hideMode() != HideMode::KeepShowing &&
|
|
|
|
m_settings->hideState() == HideState::Hide &&
|
|
|
|
m_panelHideAni->state() == QVariantAnimation::Stopped)
|
2017-11-16 16:04:59 +08:00
|
|
|
{
|
|
|
|
switch (m_settings->position())
|
|
|
|
{
|
|
|
|
case Top:
|
|
|
|
case Bottom:
|
2017-11-17 10:58:18 +08:00
|
|
|
hx = 2;
|
2017-11-16 16:04:59 +08:00
|
|
|
break;
|
|
|
|
case Left:
|
|
|
|
case Right:
|
2017-11-17 10:58:18 +08:00
|
|
|
wx = 2;
|
2017-11-16 16:04:59 +08:00
|
|
|
}
|
|
|
|
}
|
2017-11-13 21:17:56 +08:00
|
|
|
|
2017-11-16 16:04:59 +08:00
|
|
|
windowHandle()->handle()->setGeometry(QRect(rp.x(), rp.y(), wx, hx));
|
2017-11-13 21:17:56 +08:00
|
|
|
}
|
|
|
|
|
2016-06-06 10:59:29 +08:00
|
|
|
void MainWindow::initConnections()
|
|
|
|
{
|
2016-06-21 15:11:32 +08:00
|
|
|
connect(m_settings, &DockSettings::dataChanged, m_positionUpdateTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
|
2016-08-12 14:28:35 +08:00
|
|
|
connect(m_settings, &DockSettings::positionChanged, this, &MainWindow::positionChanged);
|
2016-07-18 17:10:15 +08:00
|
|
|
connect(m_settings, &DockSettings::windowGeometryChanged, this, &MainWindow::updateGeometry, Qt::DirectConnection);
|
2016-06-29 18:30:25 +08:00
|
|
|
connect(m_settings, &DockSettings::windowHideModeChanged, this, &MainWindow::setStrutPartial, Qt::QueuedConnection);
|
2017-01-12 18:38:06 +08:00
|
|
|
connect(m_settings, &DockSettings::windowHideModeChanged, [this] { resetPanelEnvironment(true); });
|
2017-02-07 00:18:00 +08:00
|
|
|
connect(m_settings, &DockSettings::windowVisibleChanged, this, &MainWindow::updatePanelVisible, Qt::QueuedConnection);
|
2016-06-30 14:44:55 +08:00
|
|
|
connect(m_settings, &DockSettings::autoHideChanged, this, &MainWindow::updatePanelVisible);
|
2016-06-29 16:53:37 +08:00
|
|
|
|
2016-06-30 18:02:09 +08:00
|
|
|
connect(m_mainPanel, &MainPanel::requestRefershWindowVisible, this, &MainWindow::updatePanelVisible, Qt::QueuedConnection);
|
2016-07-18 09:32:01 +08:00
|
|
|
connect(m_mainPanel, &MainPanel::requestWindowAutoHide, m_settings, &DockSettings::setAutoHide);
|
2017-11-13 21:17:56 +08:00
|
|
|
connect(m_mainPanel, &MainPanel::geometryChanged, this, &MainWindow::panelGeometryChanged);
|
2016-06-30 15:32:18 +08:00
|
|
|
|
2016-06-29 18:30:25 +08:00
|
|
|
connect(m_positionUpdateTimer, &QTimer::timeout, this, &MainWindow::updatePosition, Qt::QueuedConnection);
|
2016-08-18 16:06:40 +08:00
|
|
|
connect(m_expandDelayTimer, &QTimer::timeout, this, &MainWindow::expand, Qt::QueuedConnection);
|
2016-06-30 09:37:13 +08:00
|
|
|
|
2016-06-30 18:02:09 +08:00
|
|
|
connect(m_panelHideAni, &QPropertyAnimation::finished, this, &MainWindow::updateGeometry, Qt::QueuedConnection);
|
2017-11-13 21:17:56 +08:00
|
|
|
connect(m_panelHideAni, &QPropertyAnimation::finished, this, &MainWindow::adjustShadowMask);
|
|
|
|
connect(m_panelShowAni, &QPropertyAnimation::finished, this, &MainWindow::adjustShadowMask);
|
2017-11-23 12:21:00 +08:00
|
|
|
connect(m_posChangeAni, &QVariantAnimation::valueChanged, this, static_cast<void (MainWindow::*)()>(&MainWindow::internalMove));
|
|
|
|
connect(m_posChangeAni, &QVariantAnimation::finished, this, static_cast<void (MainWindow::*)()>(&MainWindow::internalMove), Qt::QueuedConnection);
|
2016-06-30 18:02:09 +08:00
|
|
|
|
2017-06-16 13:22:40 +08:00
|
|
|
// // to fix qt animation bug, sometimes window size not change
|
2016-06-30 09:37:13 +08:00
|
|
|
connect(m_sizeChangeAni, &QPropertyAnimation::valueChanged, [this] {
|
2016-06-30 10:29:58 +08:00
|
|
|
const QSize size = m_sizeChangeAni->currentValue().toSize();
|
|
|
|
|
|
|
|
QWidget::setFixedSize(size);
|
|
|
|
m_mainPanel->setFixedSize(size);
|
2016-06-30 09:37:13 +08:00
|
|
|
});
|
2016-10-14 15:47:43 +08:00
|
|
|
|
2017-11-13 21:17:56 +08:00
|
|
|
connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &MainWindow::compositeChanged, Qt::QueuedConnection);
|
|
|
|
connect(&m_platformWindowHandle, &DPlatformWindowHandle::frameMarginsChanged, this, &MainWindow::adjustShadowMask);
|
2017-06-08 15:38:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const QPoint MainWindow::x11GetWindowPos()
|
|
|
|
{
|
|
|
|
const auto disp = QX11Info::display();
|
|
|
|
|
|
|
|
unsigned int unused;
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
Window unused_window;
|
|
|
|
|
|
|
|
XGetGeometry(disp, winId(), &unused_window, &x, &y, &unused, &unused, &unused, &unused);
|
|
|
|
XFlush(disp);
|
|
|
|
|
|
|
|
return QPoint(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::x11MoveWindow(const int x, const int y)
|
|
|
|
{
|
|
|
|
const auto disp = QX11Info::display();
|
|
|
|
|
|
|
|
XMoveWindow(disp, winId(), x, y);
|
|
|
|
XFlush(disp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::x11MoveResizeWindow(const int x, const int y, const int w, const int h)
|
|
|
|
{
|
|
|
|
const auto disp = QX11Info::display();
|
2016-10-14 15:47:43 +08:00
|
|
|
|
2017-06-08 15:38:11 +08:00
|
|
|
XMoveResizeWindow(disp, winId(), x, y, w, h);
|
|
|
|
XFlush(disp);
|
2016-06-06 10:59:29 +08:00
|
|
|
}
|
|
|
|
|
2016-08-12 14:28:35 +08:00
|
|
|
void MainWindow::positionChanged(const Position prevPos)
|
|
|
|
{
|
|
|
|
// paly hide animation and disable other animation
|
|
|
|
m_updatePanelVisible = false;
|
|
|
|
clearStrutPartial();
|
|
|
|
narrow(prevPos);
|
|
|
|
|
|
|
|
// reset position & layout and slide out
|
|
|
|
QTimer::singleShot(200, this, [&] {
|
|
|
|
resetPanelEnvironment(false);
|
|
|
|
updateGeometry();
|
|
|
|
expand();
|
|
|
|
});
|
|
|
|
|
2016-08-12 16:32:03 +08:00
|
|
|
// set strut
|
2016-08-12 14:28:35 +08:00
|
|
|
QTimer::singleShot(400, this, [&] {
|
|
|
|
setStrutPartial();
|
2016-08-12 16:32:03 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// reset to right environment when animation finished
|
|
|
|
QTimer::singleShot(600, this, [&] {
|
|
|
|
m_updatePanelVisible = true;
|
2016-08-12 14:28:35 +08:00
|
|
|
updatePanelVisible();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-06-03 16:06:11 +08:00
|
|
|
void MainWindow::updatePosition()
|
|
|
|
{
|
2017-07-14 14:05:35 +08:00
|
|
|
// qDebug() << Q_FUNC_INFO;
|
2016-06-22 10:28:47 +08:00
|
|
|
// all update operation need pass by timer
|
2016-06-16 16:56:21 +08:00
|
|
|
Q_ASSERT(sender() == m_positionUpdateTimer);
|
|
|
|
|
2016-06-15 11:09:34 +08:00
|
|
|
clearStrutPartial();
|
2016-06-22 10:28:47 +08:00
|
|
|
updateGeometry();
|
2017-06-15 09:10:29 +08:00
|
|
|
|
|
|
|
// make sure strut partial is set after the size/position animation;
|
|
|
|
const int inter = qMax(m_sizeChangeAni->duration(), m_posChangeAni->duration());
|
|
|
|
QTimer::singleShot(inter + 100, this, &MainWindow::setStrutPartial);
|
2016-06-22 10:28:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::updateGeometry()
|
|
|
|
{
|
2016-06-29 16:53:37 +08:00
|
|
|
const Position position = m_settings->position();
|
2016-07-18 17:10:15 +08:00
|
|
|
QSize size = m_settings->windowSize();
|
2016-06-23 20:05:03 +08:00
|
|
|
|
2017-07-14 14:05:35 +08:00
|
|
|
// qDebug() << Q_FUNC_INFO << position << size;
|
2017-06-16 13:22:40 +08:00
|
|
|
|
2016-07-18 17:10:15 +08:00
|
|
|
m_mainPanel->setFixedSize(size);
|
2016-06-29 16:53:37 +08:00
|
|
|
m_mainPanel->updateDockPosition(position);
|
2016-06-22 16:41:36 +08:00
|
|
|
m_mainPanel->updateDockDisplayMode(m_settings->displayMode());
|
2016-06-15 11:09:34 +08:00
|
|
|
|
2017-11-13 21:17:56 +08:00
|
|
|
bool animation = true;
|
|
|
|
|
2016-06-29 16:53:37 +08:00
|
|
|
if (m_settings->hideState() == Hide)
|
|
|
|
{
|
|
|
|
m_sizeChangeAni->stop();
|
2016-06-30 18:02:09 +08:00
|
|
|
m_posChangeAni->stop();
|
2016-06-29 16:53:37 +08:00
|
|
|
switch (position)
|
|
|
|
{
|
|
|
|
case Top:
|
2017-11-13 21:17:56 +08:00
|
|
|
case Bottom: size.setHeight(2); break;
|
2016-06-29 16:53:37 +08:00
|
|
|
case Left:
|
2017-11-13 21:17:56 +08:00
|
|
|
case Right: size.setWidth(2); break;
|
2016-06-29 16:53:37 +08:00
|
|
|
}
|
2017-11-13 21:17:56 +08:00
|
|
|
animation = false;
|
|
|
|
m_sizeChangeAni->setEndValue(size);
|
2016-06-29 16:53:37 +08:00
|
|
|
QWidget::setFixedSize(size);
|
|
|
|
}
|
2016-06-30 09:37:13 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
setFixedSize(size);
|
|
|
|
}
|
2016-06-29 16:53:37 +08:00
|
|
|
|
2016-08-31 11:19:28 +08:00
|
|
|
const QRect windowRect = m_settings->windowRect(position, m_settings->hideState() == Hide);
|
2017-11-13 21:17:56 +08:00
|
|
|
if (animation)
|
|
|
|
internalAnimationMove(windowRect.x(), windowRect.y());
|
|
|
|
else
|
2017-11-23 12:21:00 +08:00
|
|
|
internalMove(windowRect.topLeft());
|
2017-11-13 21:17:56 +08:00
|
|
|
|
2016-06-30 09:37:13 +08:00
|
|
|
m_mainPanel->update();
|
2016-06-15 11:09:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::clearStrutPartial()
|
|
|
|
{
|
|
|
|
m_xcbMisc->clear_strut_partial(winId());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::setStrutPartial()
|
|
|
|
{
|
2017-07-14 14:05:35 +08:00
|
|
|
// qDebug() << Q_FUNC_INFO;
|
2016-06-15 11:20:05 +08:00
|
|
|
// first, clear old strut partial
|
|
|
|
clearStrutPartial();
|
|
|
|
|
2017-07-14 14:05:35 +08:00
|
|
|
// reset env
|
|
|
|
resetPanelEnvironment(true);
|
|
|
|
|
2016-06-29 16:53:37 +08:00
|
|
|
if (m_settings->hideMode() != Dock::KeepShowing)
|
|
|
|
return;
|
|
|
|
|
2017-11-14 14:20:04 +08:00
|
|
|
const auto ratio = devicePixelRatioF();
|
|
|
|
const int maxScreenHeight = m_settings->screenRawHeight();
|
|
|
|
const int maxScreenWidth = m_settings->screenRawWidth();
|
2016-06-21 10:12:43 +08:00
|
|
|
const Position side = m_settings->position();
|
2017-11-28 14:27:16 +08:00
|
|
|
const QPoint &p = rawXPosition(m_posChangeAni->endValue().toPoint());
|
|
|
|
const QSize &s = m_settings->windowSize();
|
|
|
|
const QRect &primaryRawRect = m_settings->primaryRawRect();
|
2016-06-15 11:09:34 +08:00
|
|
|
|
2016-06-29 16:53:37 +08:00
|
|
|
XcbMisc::Orientation orientation = XcbMisc::OrientationTop;
|
|
|
|
uint strut = 0;
|
|
|
|
uint strutStart = 0;
|
|
|
|
uint strutEnd = 0;
|
2016-06-15 11:09:34 +08:00
|
|
|
|
2017-02-28 11:31:48 +08:00
|
|
|
QRect strutArea(0, 0, maxScreenWidth, maxScreenHeight);
|
2016-06-15 11:09:34 +08:00
|
|
|
switch (side)
|
|
|
|
{
|
2016-06-21 10:12:43 +08:00
|
|
|
case Position::Top:
|
2016-06-15 11:09:34 +08:00
|
|
|
orientation = XcbMisc::OrientationTop;
|
2017-11-14 14:20:04 +08:00
|
|
|
strut = p.y() + s.height() * ratio;
|
|
|
|
strutStart = p.x();
|
2017-11-28 14:27:16 +08:00
|
|
|
strutEnd = qMin(qRound(p.x() + s.width() * ratio), primaryRawRect.right());
|
2017-02-28 11:31:48 +08:00
|
|
|
strutArea.setLeft(strutStart);
|
|
|
|
strutArea.setRight(strutEnd);
|
2017-11-14 14:20:04 +08:00
|
|
|
strutArea.setBottom(strut);
|
2016-06-15 11:09:34 +08:00
|
|
|
break;
|
2016-06-21 10:12:43 +08:00
|
|
|
case Position::Bottom:
|
2016-06-15 11:09:34 +08:00
|
|
|
orientation = XcbMisc::OrientationBottom;
|
|
|
|
strut = maxScreenHeight - p.y();
|
2017-11-14 14:20:04 +08:00
|
|
|
strutStart = p.x();
|
2017-11-28 14:27:16 +08:00
|
|
|
strutEnd = qMin(qRound(p.x() + s.width() * ratio), primaryRawRect.right());
|
2017-02-28 11:31:48 +08:00
|
|
|
strutArea.setLeft(strutStart);
|
|
|
|
strutArea.setRight(strutEnd);
|
|
|
|
strutArea.setTop(p.y());
|
2016-06-15 11:09:34 +08:00
|
|
|
break;
|
2016-06-21 10:12:43 +08:00
|
|
|
case Position::Left:
|
2016-06-15 11:09:34 +08:00
|
|
|
orientation = XcbMisc::OrientationLeft;
|
2017-11-14 14:20:04 +08:00
|
|
|
strut = p.x() + s.width() * ratio;
|
|
|
|
strutStart = p.y();
|
2017-11-28 14:27:16 +08:00
|
|
|
strutEnd = qMin(qRound(p.y() + s.height() * ratio), primaryRawRect.bottom());
|
2017-11-14 14:20:04 +08:00
|
|
|
strutArea.setTop(strutStart);
|
|
|
|
strutArea.setBottom(strutEnd);
|
|
|
|
strutArea.setRight(strut);
|
2016-06-15 11:09:34 +08:00
|
|
|
break;
|
2016-06-21 10:12:43 +08:00
|
|
|
case Position::Right:
|
2016-06-15 11:09:34 +08:00
|
|
|
orientation = XcbMisc::OrientationRight;
|
2017-11-14 14:20:04 +08:00
|
|
|
strut = maxScreenWidth - p.x();
|
|
|
|
strutStart = p.y();
|
2017-11-28 14:27:16 +08:00
|
|
|
strutEnd = qMin(qRound(p.y() + s.height() * ratio), primaryRawRect.bottom());
|
2017-11-14 14:20:04 +08:00
|
|
|
strutArea.setTop(strutStart);
|
|
|
|
strutArea.setBottom(strutEnd);
|
|
|
|
strutArea.setLeft(p.x());
|
2016-06-15 11:09:34 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_ASSERT(false);
|
|
|
|
}
|
2017-02-28 11:31:48 +08:00
|
|
|
|
2017-11-14 14:20:04 +08:00
|
|
|
qDebug() << "screen info: " << p << strutArea;
|
|
|
|
|
2017-02-28 11:31:48 +08:00
|
|
|
// pass if strut area is intersect with other screen
|
|
|
|
int count = 0;
|
2017-03-03 17:30:11 +08:00
|
|
|
const QRect pr = m_settings->primaryRect();
|
2017-02-28 11:31:48 +08:00
|
|
|
for (auto *screen : qApp->screens())
|
2017-03-03 17:30:11 +08:00
|
|
|
{
|
|
|
|
const QRect sr = screen->geometry();
|
|
|
|
if (sr == pr)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sr.intersects(strutArea))
|
2017-02-28 11:31:48 +08:00
|
|
|
++count;
|
2017-03-03 17:30:11 +08:00
|
|
|
}
|
|
|
|
if (count > 0)
|
2017-11-28 14:27:16 +08:00
|
|
|
{
|
|
|
|
qWarning() << "strutArea is intersects with another screen.";
|
|
|
|
qWarning() << maxScreenHeight << maxScreenWidth << side << p << s;
|
2017-02-28 11:31:48 +08:00
|
|
|
return;
|
2017-11-28 14:27:16 +08:00
|
|
|
}
|
2017-02-28 11:31:48 +08:00
|
|
|
|
2017-11-14 14:20:04 +08:00
|
|
|
m_xcbMisc->set_strut_partial(winId(), orientation, strut, strutStart, strutEnd);
|
2016-06-03 16:06:11 +08:00
|
|
|
}
|
2016-06-29 16:53:37 +08:00
|
|
|
|
|
|
|
void MainWindow::expand()
|
|
|
|
{
|
2017-07-14 14:05:35 +08:00
|
|
|
// qDebug() << "expand";
|
2016-06-29 18:30:25 +08:00
|
|
|
const QPoint finishPos(0, 0);
|
|
|
|
|
2017-11-07 11:53:39 +08:00
|
|
|
const int epsilon = std::round(devicePixelRatioF()) - 1;
|
|
|
|
const QSize s = size();
|
|
|
|
const QSize ps = m_mainPanel->size();
|
|
|
|
|
|
|
|
if (m_mainPanel->pos() == finishPos && m_panelHideAni->state() == QPropertyAnimation::Stopped &&
|
|
|
|
std::abs(ps.width() - s.width()) <= epsilon && std::abs(ps.height() - s.height()) <= epsilon)
|
2016-06-29 16:53:37 +08:00
|
|
|
return;
|
2017-01-12 18:38:06 +08:00
|
|
|
m_panelHideAni->stop();
|
2016-06-29 16:53:37 +08:00
|
|
|
|
2016-08-12 14:28:35 +08:00
|
|
|
resetPanelEnvironment(true);
|
2016-06-29 16:53:37 +08:00
|
|
|
|
2017-11-13 21:17:56 +08:00
|
|
|
if (m_panelShowAni->state() != QPropertyAnimation::Running)
|
2016-06-29 16:53:37 +08:00
|
|
|
{
|
2017-11-13 21:17:56 +08:00
|
|
|
QPoint startPos(0, 0);
|
|
|
|
const QSize &size = m_settings->windowSize();
|
|
|
|
switch (m_settings->position())
|
|
|
|
{
|
|
|
|
case Top: startPos.setY(-size.height()); break;
|
|
|
|
case Bottom: startPos.setY(size.height()); break;
|
|
|
|
case Left: startPos.setX(-size.width()); break;
|
|
|
|
case Right: startPos.setX(size.width()); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_panelShowAni->setStartValue(startPos);
|
2016-06-29 16:53:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
m_panelShowAni->setEndValue(finishPos);
|
|
|
|
m_panelShowAni->start();
|
|
|
|
}
|
|
|
|
|
2016-08-12 14:28:35 +08:00
|
|
|
void MainWindow::narrow(const Position prevPos)
|
2016-06-29 16:53:37 +08:00
|
|
|
{
|
2017-07-14 14:05:35 +08:00
|
|
|
// qDebug() << "narrow" << prevPos;
|
2016-10-14 15:47:43 +08:00
|
|
|
// const QSize size = m_settings->windowSize();
|
2016-08-12 14:28:35 +08:00
|
|
|
const QSize size = m_mainPanel->size();
|
2016-06-29 16:53:37 +08:00
|
|
|
|
|
|
|
QPoint finishPos(0, 0);
|
2016-08-12 14:28:35 +08:00
|
|
|
switch (prevPos)
|
2016-06-29 16:53:37 +08:00
|
|
|
{
|
|
|
|
case Top: finishPos.setY(-size.height()); break;
|
|
|
|
case Bottom: finishPos.setY(size.height()); break;
|
|
|
|
case Left: finishPos.setX(-size.width()); break;
|
|
|
|
case Right: finishPos.setX(size.width()); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_panelShowAni->stop();
|
|
|
|
m_panelHideAni->setStartValue(m_mainPanel->pos());
|
|
|
|
m_panelHideAni->setEndValue(finishPos);
|
|
|
|
m_panelHideAni->start();
|
2017-03-27 15:36:37 +08:00
|
|
|
|
|
|
|
// clear shadow
|
|
|
|
adjustShadowMask();
|
2016-06-29 16:53:37 +08:00
|
|
|
}
|
|
|
|
|
2016-08-12 14:28:35 +08:00
|
|
|
void MainWindow::resetPanelEnvironment(const bool visible)
|
2016-06-30 18:02:09 +08:00
|
|
|
{
|
|
|
|
// reset environment
|
|
|
|
m_sizeChangeAni->stop();
|
|
|
|
m_posChangeAni->stop();
|
|
|
|
|
2016-08-12 14:28:35 +08:00
|
|
|
const Position position = m_settings->position();
|
|
|
|
const QRect r(m_settings->windowRect(position));
|
2016-08-04 10:20:55 +08:00
|
|
|
|
2016-08-12 14:28:35 +08:00
|
|
|
m_sizeChangeAni->setEndValue(r.size());
|
2017-07-04 14:58:11 +08:00
|
|
|
m_mainPanel->setFixedSize(r.size());
|
2016-08-12 14:28:35 +08:00
|
|
|
QWidget::setFixedSize(r.size());
|
|
|
|
m_posChangeAni->setEndValue(r.topLeft());
|
2017-06-09 14:33:38 +08:00
|
|
|
QWidget::move(r.topLeft());
|
2016-08-12 14:28:35 +08:00
|
|
|
|
|
|
|
QPoint finishPos(0, 0);
|
|
|
|
if (!visible)
|
2016-06-30 18:02:09 +08:00
|
|
|
{
|
2016-08-12 14:28:35 +08:00
|
|
|
switch (position)
|
|
|
|
{
|
|
|
|
case Top: finishPos.setY(-r.height()); break;
|
|
|
|
case Bottom: finishPos.setY(r.height()); break;
|
|
|
|
case Left: finishPos.setX(-r.width()); break;
|
|
|
|
case Right: finishPos.setX(r.width()); break;
|
|
|
|
}
|
2016-06-30 18:02:09 +08:00
|
|
|
}
|
2016-08-12 14:28:35 +08:00
|
|
|
|
|
|
|
m_mainPanel->move(finishPos);
|
2016-06-30 18:02:09 +08:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:53:37 +08:00
|
|
|
void MainWindow::updatePanelVisible()
|
|
|
|
{
|
2017-07-14 14:05:35 +08:00
|
|
|
// qDebug() << m_updatePanelVisible;
|
2017-01-12 18:38:06 +08:00
|
|
|
|
2016-08-12 14:28:35 +08:00
|
|
|
if (!m_updatePanelVisible)
|
|
|
|
return;
|
2016-06-30 11:15:06 +08:00
|
|
|
if (m_settings->hideMode() == KeepShowing)
|
2017-01-12 18:38:06 +08:00
|
|
|
return expand();
|
2016-06-30 11:15:06 +08:00
|
|
|
|
2016-06-29 16:53:37 +08:00
|
|
|
const Dock::HideState state = m_settings->hideState();
|
|
|
|
|
2017-07-14 14:05:35 +08:00
|
|
|
// qDebug() << state;
|
2016-06-30 15:55:43 +08:00
|
|
|
|
2016-06-30 14:44:55 +08:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (state != Hide)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!m_settings->autoHide())
|
|
|
|
break;
|
|
|
|
|
2017-06-08 16:00:45 +08:00
|
|
|
QRect r(pos(), size());
|
2016-06-30 14:44:55 +08:00
|
|
|
if (r.contains(QCursor::pos()))
|
|
|
|
break;
|
|
|
|
|
2016-08-12 14:28:35 +08:00
|
|
|
return narrow(m_settings->position());
|
2016-06-30 14:44:55 +08:00
|
|
|
|
|
|
|
} while (false);
|
|
|
|
|
|
|
|
return expand();
|
2016-06-29 16:53:37 +08:00
|
|
|
}
|
2017-03-21 15:40:52 +08:00
|
|
|
|
|
|
|
void MainWindow::adjustShadowMask()
|
|
|
|
{
|
2017-07-14 14:05:35 +08:00
|
|
|
// qDebug() << Q_FUNC_INFO << m_mainPanel->pos() << m_panelHideAni->state() << m_panelShowAni->state() << m_wmHelper->hasComposite();
|
2017-03-28 17:28:23 +08:00
|
|
|
if (m_mainPanel->pos() != QPoint(0, 0) ||
|
|
|
|
m_panelHideAni->state() == QPropertyAnimation::Running ||
|
2017-05-11 10:10:32 +08:00
|
|
|
m_panelShowAni->state() == QPauseAnimation::Running ||
|
|
|
|
!m_wmHelper->hasComposite())
|
2017-03-28 17:28:23 +08:00
|
|
|
{
|
|
|
|
m_platformWindowHandle.setShadowRadius(0);
|
|
|
|
m_platformWindowHandle.setClipPath(QPainterPath());
|
|
|
|
return;
|
|
|
|
}
|
2017-03-27 15:36:37 +08:00
|
|
|
|
2017-09-15 15:11:54 +08:00
|
|
|
const QRect r = QRect(QPoint(), rect().size());
|
2017-03-27 15:36:37 +08:00
|
|
|
const int radius = 5;
|
|
|
|
|
|
|
|
QPainterPath path;
|
|
|
|
if (m_settings->displayMode() == DisplayMode::Fashion)
|
|
|
|
{
|
|
|
|
switch (m_settings->position())
|
|
|
|
{
|
|
|
|
case Top:
|
|
|
|
path.addRoundedRect(0, -radius, r.width(), r.height() + radius, radius, radius);
|
|
|
|
break;
|
|
|
|
case Bottom:
|
|
|
|
path.addRoundedRect(0, 0, r.width(), r.height() + radius, radius, radius);
|
|
|
|
break;
|
|
|
|
case Left:
|
|
|
|
path.addRoundedRect(-radius, 0, r.width() + radius, r.height(), radius, radius);
|
|
|
|
break;
|
|
|
|
case Right:
|
|
|
|
path.addRoundedRect(0, 0, r.width() + radius, r.height(), radius, radius);
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
} else {
|
2017-08-28 11:38:20 +08:00
|
|
|
path.addRect(r);
|
2017-03-27 15:36:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
m_platformWindowHandle.setShadowRadius(60);
|
|
|
|
m_platformWindowHandle.setClipPath(path);
|
2017-03-21 15:40:52 +08:00
|
|
|
}
|