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-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>
|
|
|
|
|
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-06-08 16:00:45 +08:00
|
|
|
m_posChangeAni(new QPropertyAnimation(this, "pos")),
|
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();
|
2017-05-22 10:38:49 +08:00
|
|
|
connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &MainWindow::compositeChanged, Qt::QueuedConnection);
|
2016-10-14 15:47:43 +08:00
|
|
|
connect(m_mainPanel, &MainPanel::geometryChanged, this, &MainWindow::panelGeometryChanged);
|
2017-04-28 11:05:11 +08:00
|
|
|
connect(&m_platformWindowHandle, &DPlatformWindowHandle::frameMarginsChanged, this, &MainWindow::adjustShadowMask);
|
2017-03-27 15:36:37 +08:00
|
|
|
connect(m_panelHideAni, &QPropertyAnimation::finished, this, &MainWindow::adjustShadowMask);
|
|
|
|
connect(m_panelShowAni, &QPropertyAnimation::finished, this, &MainWindow::adjustShadowMask);
|
2017-06-08 16:00:45 +08:00
|
|
|
// connect(m_posChangeAni, &QPropertyAnimation::valueChanged,
|
|
|
|
// this, [=](const QVariant &v) { const QPoint p = v.toPoint(); x11MoveWindow(p.x(), p.y()); });
|
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-06-16 13:22:40 +08:00
|
|
|
|
2017-07-14 14:05:35 +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-06-16 13:22:40 +08:00
|
|
|
void MainWindow::internalMove(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-06-16 13:22:40 +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
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
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-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-06-08 15:38:11 +08:00
|
|
|
// connect(m_posChangeAni, &QPropertyAnimation::finished, [this] {
|
|
|
|
// QWidget::move(m_posChangeAni->endValue().toPoint());
|
|
|
|
// });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
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:
|
|
|
|
case Bottom: size.setHeight(1); break;
|
|
|
|
case Left:
|
|
|
|
case Right: size.setWidth(1); break;
|
|
|
|
}
|
|
|
|
QWidget::setFixedSize(size);
|
|
|
|
}
|
2016-06-30 09:37:13 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
setFixedSize(size);
|
|
|
|
}
|
2016-06-29 16:53:37 +08:00
|
|
|
|
2016-10-14 15:47:43 +08:00
|
|
|
// const QRect primaryRect = m_settings->primaryRect();
|
|
|
|
// const int offsetX = (primaryRect.width() - size.width()) / 2;
|
|
|
|
// const int offsetY = (primaryRect.height() - size.height()) / 2;
|
|
|
|
|
|
|
|
// switch (position)
|
|
|
|
// {
|
|
|
|
// case Top:
|
|
|
|
// move(primaryRect.topLeft().x() + offsetX, primaryRect.y()); break;
|
|
|
|
// case Left:
|
|
|
|
// move(primaryRect.topLeft().x(), primaryRect.y() + offsetY); break;
|
|
|
|
// case Right:
|
|
|
|
// move(primaryRect.right() - size.width() + 1, primaryRect.y() + offsetY); break;
|
|
|
|
// case Bottom:
|
|
|
|
// move(primaryRect.x() + offsetX, primaryRect.bottom() - size.height() + 1); break;
|
|
|
|
// default:
|
|
|
|
// Q_ASSERT(false);
|
|
|
|
// }
|
2016-08-31 11:19:28 +08:00
|
|
|
const QRect windowRect = m_settings->windowRect(position, m_settings->hideState() == Hide);
|
2017-06-16 13:22:40 +08:00
|
|
|
internalMove(windowRect.x(), windowRect.y());
|
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;
|
|
|
|
|
2016-06-21 10:12:43 +08:00
|
|
|
const Position side = m_settings->position();
|
2016-06-22 10:42:31 +08:00
|
|
|
const int maxScreenHeight = m_settings->screenHeight();
|
2016-07-18 20:01:03 +08:00
|
|
|
const int maxScreenWidth = m_settings->screenWidth();
|
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
|
|
|
|
2016-06-23 20:05:03 +08:00
|
|
|
const QPoint p = m_posChangeAni->endValue().toPoint();
|
|
|
|
const QRect r = QRect(p, m_settings->windowSize());
|
2017-02-28 11:31:48 +08:00
|
|
|
QRect strutArea(0, 0, maxScreenWidth, maxScreenHeight);
|
|
|
|
|
2017-07-14 14:05:35 +08:00
|
|
|
qDebug() << "screen info: " << r << p << strutArea;
|
|
|
|
|
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;
|
2016-06-22 10:28:47 +08:00
|
|
|
strut = r.bottom() + 1;
|
2016-06-15 11:09:34 +08:00
|
|
|
strutStart = r.left();
|
|
|
|
strutEnd = r.right();
|
2017-02-28 11:31:48 +08:00
|
|
|
strutArea.setLeft(strutStart);
|
|
|
|
strutArea.setRight(strutEnd);
|
|
|
|
strutArea.setBottom(r.bottom());
|
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();
|
|
|
|
strutStart = r.left();
|
|
|
|
strutEnd = r.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;
|
2016-07-18 20:01:03 +08:00
|
|
|
strut = r.right() + 1;
|
2016-06-15 11:09:34 +08:00
|
|
|
strutStart = r.top();
|
|
|
|
strutEnd = r.bottom();
|
2017-02-28 11:31:48 +08:00
|
|
|
strutArea.setTop(r.top());
|
|
|
|
strutArea.setBottom(r.bottom());
|
|
|
|
strutArea.setRight(r.right());
|
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;
|
2016-07-18 20:01:03 +08:00
|
|
|
strut = maxScreenWidth - r.left();
|
2016-06-15 11:09:34 +08:00
|
|
|
strutStart = r.top();
|
|
|
|
strutEnd = r.bottom();
|
2017-02-28 11:31:48 +08:00
|
|
|
strutArea.setTop(r.top());
|
|
|
|
strutArea.setBottom(r.bottom());
|
|
|
|
strutArea.setLeft(r.left());
|
2016-06-15 11:09:34 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_ASSERT(false);
|
|
|
|
}
|
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-02-28 11:31:48 +08:00
|
|
|
return;
|
|
|
|
|
2017-08-28 11:38:20 +08:00
|
|
|
m_xcbMisc->set_strut_partial(winId(), orientation, strut * qApp->devicePixelRatio(), 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-01-12 18:38:06 +08:00
|
|
|
if (m_mainPanel->pos() == finishPos && m_mainPanel->size() == this->size() && m_panelHideAni->state() == QPropertyAnimation::Stopped)
|
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
|
|
|
|
|
|
|
if (m_panelShowAni->state() == QPropertyAnimation::Running)
|
|
|
|
return m_panelShowAni->setEndValue(finishPos);
|
|
|
|
|
2016-06-30 18:02:09 +08:00
|
|
|
const QSize size = m_settings->windowSize();
|
|
|
|
|
2016-06-29 16:53:37 +08:00
|
|
|
QPoint startPos(0, 0);
|
|
|
|
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);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_panelHideAni->state() == QPropertyAnimation::Running)
|
|
|
|
return m_panelHideAni->setEndValue(finishPos);
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-07-14 14:05:35 +08:00
|
|
|
// qDebug() << Q_FUNC_INFO << r;
|
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());
|
|
|
|
// x11MoveWindow(r.topLeft().x(), r.topLeft().y());
|
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
|
|
|
}
|