2017-09-18 14:33:44 +08:00
|
|
|
|
/*
|
2018-02-07 11:52:47 +08:00
|
|
|
|
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
2017-09-18 14:33:44 +08:00
|
|
|
|
*
|
|
|
|
|
* Author: sbw <sbw@sbw.so>
|
|
|
|
|
*
|
|
|
|
|
* Maintainer: sbw <sbw@sbw.so>
|
2020-05-28 20:45:02 +08:00
|
|
|
|
* zhaolong <zhaolong@uniontech.com>
|
2017-09-18 14:33:44 +08:00
|
|
|
|
*
|
|
|
|
|
* 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-06 10:59:29 +08:00
|
|
|
|
#include "docksettings.h"
|
2016-06-21 17:24:03 +08:00
|
|
|
|
#include "item/appitem.h"
|
2019-04-23 14:28:09 +08:00
|
|
|
|
#include "util/utils.h"
|
2020-06-05 16:16:59 +08:00
|
|
|
|
#include "controller/dockitemmanager.h"
|
2016-06-06 10:59:29 +08:00
|
|
|
|
|
2016-06-16 16:56:21 +08:00
|
|
|
|
#include <QDebug>
|
2016-06-27 16:36:51 +08:00
|
|
|
|
#include <QX11Info>
|
2020-01-19 18:21:26 +08:00
|
|
|
|
#include <QGSettings>
|
2016-06-16 16:56:21 +08:00
|
|
|
|
|
2017-02-15 17:10:32 +08:00
|
|
|
|
#include <DApplication>
|
2017-12-13 11:53:03 +08:00
|
|
|
|
#include <QScreen>
|
2017-02-15 17:10:32 +08:00
|
|
|
|
|
2016-08-15 14:22:11 +08:00
|
|
|
|
#define FASHION_MODE_PADDING 30
|
2019-08-30 11:41:52 +08:00
|
|
|
|
#define MAINWINDOW_MARGIN 10
|
2017-02-15 17:10:32 +08:00
|
|
|
|
|
2019-09-03 10:19:59 +08:00
|
|
|
|
#define FASHION_DEFAULT_HEIGHT 72
|
|
|
|
|
#define EffICIENT_DEFAULT_HEIGHT 40
|
2019-11-15 13:39:50 +08:00
|
|
|
|
#define WINDOW_MAX_SIZE 100
|
|
|
|
|
#define WINDOW_MIN_SIZE 40
|
2019-09-03 10:19:59 +08:00
|
|
|
|
|
2017-02-15 17:10:32 +08:00
|
|
|
|
DWIDGET_USE_NAMESPACE
|
2016-06-21 14:02:51 +08:00
|
|
|
|
|
2017-12-15 16:13:44 +08:00
|
|
|
|
extern const QPoint rawXPosition(const QPoint &scaledPos);
|
|
|
|
|
|
2020-01-19 18:21:26 +08:00
|
|
|
|
static QGSettings *GSettingsByMenu()
|
|
|
|
|
{
|
|
|
|
|
static QGSettings settings("com.deepin.dde.dock.module.menu");
|
|
|
|
|
return &settings;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-24 17:39:14 +08:00
|
|
|
|
static QGSettings *GSettingsByTrash()
|
|
|
|
|
{
|
|
|
|
|
static QGSettings settings("com.deepin.dde.dock.module.trash");
|
|
|
|
|
return &settings;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-27 16:36:51 +08:00
|
|
|
|
DockSettings::DockSettings(QWidget *parent)
|
2018-10-08 15:11:42 +08:00
|
|
|
|
: QObject(parent)
|
2019-11-19 11:26:11 +08:00
|
|
|
|
, m_dockInter(new DBusDock("com.deepin.dde.daemon.Dock", "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus(), this))
|
2020-01-19 18:21:26 +08:00
|
|
|
|
, m_menuVisible(true)
|
2018-10-08 15:11:42 +08:00
|
|
|
|
, m_autoHide(true)
|
2018-10-11 09:21:11 +08:00
|
|
|
|
, m_opacity(0.4)
|
2018-10-08 15:11:42 +08:00
|
|
|
|
, m_fashionModeAct(tr("Fashion Mode"), this)
|
|
|
|
|
, m_efficientModeAct(tr("Efficient Mode"), this)
|
|
|
|
|
, m_topPosAct(tr("Top"), this)
|
|
|
|
|
, m_bottomPosAct(tr("Bottom"), this)
|
|
|
|
|
, m_leftPosAct(tr("Left"), this)
|
|
|
|
|
, m_rightPosAct(tr("Right"), this)
|
|
|
|
|
, m_keepShownAct(tr("Keep Shown"), this)
|
|
|
|
|
, m_keepHiddenAct(tr("Keep Hidden"), this)
|
|
|
|
|
, m_smartHideAct(tr("Smart Hide"), this)
|
2020-06-05 16:16:59 +08:00
|
|
|
|
, m_displayInter(new DisplayInter("com.deepin.daemon.Display", "/com/deepin/daemon/Display", QDBusConnection::sessionBus(), this))
|
2019-08-17 18:01:32 +08:00
|
|
|
|
, m_itemManager(DockItemManager::instance(this))
|
2020-02-24 17:39:14 +08:00
|
|
|
|
, m_trashPluginShow(true)
|
2020-05-28 20:45:02 +08:00
|
|
|
|
, m_isMouseMoveCause(false)
|
|
|
|
|
, m_mouseCauseDockScreen(nullptr)
|
2016-06-06 10:59:29 +08:00
|
|
|
|
{
|
2020-05-06 17:28:16 +08:00
|
|
|
|
m_settingsMenu.setAccessibleName("settingsmenu");
|
2019-12-02 15:01:38 +08:00
|
|
|
|
checkService();
|
|
|
|
|
|
2020-06-05 16:16:59 +08:00
|
|
|
|
onMonitorListChanged(m_displayInter->monitors());
|
|
|
|
|
|
|
|
|
|
m_primaryRawRect = m_displayInter->primaryRect();
|
|
|
|
|
m_currentRawRect = m_primaryRawRect;
|
|
|
|
|
m_screenRawHeight = m_displayInter->screenHeight();
|
|
|
|
|
m_screenRawWidth = m_displayInter->screenWidth();
|
2016-06-21 10:12:43 +08:00
|
|
|
|
m_position = Dock::Position(m_dockInter->position());
|
2016-06-21 14:02:51 +08:00
|
|
|
|
m_displayMode = Dock::DisplayMode(m_dockInter->displayMode());
|
2016-06-27 16:36:51 +08:00
|
|
|
|
m_hideMode = Dock::HideMode(m_dockInter->hideMode());
|
2016-06-29 18:30:25 +08:00
|
|
|
|
m_hideState = Dock::HideState(m_dockInter->hideState());
|
2016-06-23 10:58:04 +08:00
|
|
|
|
DockItem::setDockPosition(m_position);
|
2016-06-27 15:34:54 +08:00
|
|
|
|
qApp->setProperty(PROP_POSITION, QVariant::fromValue(m_position));
|
2016-06-23 14:28:47 +08:00
|
|
|
|
DockItem::setDockDisplayMode(m_displayMode);
|
2016-06-27 15:34:54 +08:00
|
|
|
|
qApp->setProperty(PROP_DISPLAY_MODE, QVariant::fromValue(m_displayMode));
|
2016-06-21 15:11:32 +08:00
|
|
|
|
|
2016-06-21 14:02:51 +08:00
|
|
|
|
m_fashionModeAct.setCheckable(true);
|
|
|
|
|
m_efficientModeAct.setCheckable(true);
|
|
|
|
|
m_topPosAct.setCheckable(true);
|
|
|
|
|
m_bottomPosAct.setCheckable(true);
|
|
|
|
|
m_leftPosAct.setCheckable(true);
|
|
|
|
|
m_rightPosAct.setCheckable(true);
|
|
|
|
|
m_keepShownAct.setCheckable(true);
|
|
|
|
|
m_keepHiddenAct.setCheckable(true);
|
|
|
|
|
m_smartHideAct.setCheckable(true);
|
|
|
|
|
|
2019-11-12 18:55:27 +08:00
|
|
|
|
QMenu *modeSubMenu = new QMenu(&m_settingsMenu);
|
2020-03-13 12:59:02 +08:00
|
|
|
|
modeSubMenu->setAccessibleName("modesubmenu");
|
2016-06-21 14:02:51 +08:00
|
|
|
|
modeSubMenu->addAction(&m_fashionModeAct);
|
|
|
|
|
modeSubMenu->addAction(&m_efficientModeAct);
|
2016-12-12 10:58:48 +08:00
|
|
|
|
QAction *modeSubMenuAct = new QAction(tr("Mode"), this);
|
2016-06-21 14:02:51 +08:00
|
|
|
|
modeSubMenuAct->setMenu(modeSubMenu);
|
|
|
|
|
|
2019-11-12 18:55:27 +08:00
|
|
|
|
QMenu *locationSubMenu = new QMenu(&m_settingsMenu);
|
2020-03-13 12:59:02 +08:00
|
|
|
|
locationSubMenu->setAccessibleName("locationsubmenu");
|
2016-06-21 14:02:51 +08:00
|
|
|
|
locationSubMenu->addAction(&m_topPosAct);
|
|
|
|
|
locationSubMenu->addAction(&m_bottomPosAct);
|
|
|
|
|
locationSubMenu->addAction(&m_leftPosAct);
|
|
|
|
|
locationSubMenu->addAction(&m_rightPosAct);
|
2016-12-12 10:58:48 +08:00
|
|
|
|
QAction *locationSubMenuAct = new QAction(tr("Location"), this);
|
2016-06-21 14:02:51 +08:00
|
|
|
|
locationSubMenuAct->setMenu(locationSubMenu);
|
|
|
|
|
|
2019-11-12 18:55:27 +08:00
|
|
|
|
QMenu *statusSubMenu = new QMenu(&m_settingsMenu);
|
2020-03-13 12:59:02 +08:00
|
|
|
|
statusSubMenu->setAccessibleName("statussubmenu");
|
2016-06-21 14:02:51 +08:00
|
|
|
|
statusSubMenu->addAction(&m_keepShownAct);
|
|
|
|
|
statusSubMenu->addAction(&m_keepHiddenAct);
|
|
|
|
|
statusSubMenu->addAction(&m_smartHideAct);
|
2016-12-12 10:58:48 +08:00
|
|
|
|
QAction *statusSubMenuAct = new QAction(tr("Status"), this);
|
2016-06-21 14:02:51 +08:00
|
|
|
|
statusSubMenuAct->setMenu(statusSubMenu);
|
|
|
|
|
|
2019-11-12 18:55:27 +08:00
|
|
|
|
m_hideSubMenu = new QMenu(&m_settingsMenu);
|
2020-03-13 12:59:02 +08:00
|
|
|
|
m_hideSubMenu->setAccessibleName("pluginsmenu");
|
2017-10-26 13:54:56 +08:00
|
|
|
|
QAction *hideSubMenuAct = new QAction(tr("Plugins"), this);
|
2017-10-23 10:06:36 +08:00
|
|
|
|
hideSubMenuAct->setMenu(m_hideSubMenu);
|
|
|
|
|
|
2016-06-21 14:02:51 +08:00
|
|
|
|
m_settingsMenu.addAction(modeSubMenuAct);
|
|
|
|
|
m_settingsMenu.addAction(locationSubMenuAct);
|
|
|
|
|
m_settingsMenu.addAction(statusSubMenuAct);
|
2017-10-23 10:06:36 +08:00
|
|
|
|
m_settingsMenu.addAction(hideSubMenuAct);
|
2017-04-21 14:09:29 +08:00
|
|
|
|
m_settingsMenu.setTitle("Settings Menu");
|
2016-06-21 14:02:51 +08:00
|
|
|
|
|
2019-11-12 18:55:27 +08:00
|
|
|
|
connect(&m_settingsMenu, &QMenu::triggered, this, &DockSettings::menuActionClicked);
|
2020-01-19 18:21:26 +08:00
|
|
|
|
connect(GSettingsByMenu(), &QGSettings::changed, this, &DockSettings::onGSettingsChanged);
|
2016-08-12 14:28:35 +08:00
|
|
|
|
connect(m_dockInter, &DBusDock::PositionChanged, this, &DockSettings::onPositionChanged);
|
2018-01-04 17:22:37 +08:00
|
|
|
|
connect(m_dockInter, &DBusDock::DisplayModeChanged, this, &DockSettings::onDisplayModeChanged);
|
2016-08-04 10:20:55 +08:00
|
|
|
|
connect(m_dockInter, &DBusDock::HideModeChanged, this, &DockSettings::hideModeChanged, Qt::QueuedConnection);
|
2017-02-07 00:18:00 +08:00
|
|
|
|
connect(m_dockInter, &DBusDock::HideStateChanged, this, &DockSettings::hideStateChanged);
|
2016-06-30 15:46:20 +08:00
|
|
|
|
connect(m_dockInter, &DBusDock::ServiceRestarted, this, &DockSettings::resetFrontendGeometry);
|
2019-01-16 10:23:01 +08:00
|
|
|
|
connect(m_dockInter, &DBusDock::OpacityChanged, this, &DockSettings::onOpacityChanged);
|
2019-11-15 13:39:50 +08:00
|
|
|
|
connect(m_dockInter, &DBusDock::WindowSizeEfficientChanged, this, &DockSettings::onWindowSizeChanged);
|
|
|
|
|
connect(m_dockInter, &DBusDock::WindowSizeFashionChanged, this, &DockSettings::onWindowSizeChanged);
|
2016-06-22 10:28:47 +08:00
|
|
|
|
|
2019-08-17 18:01:32 +08:00
|
|
|
|
connect(m_itemManager, &DockItemManager::itemInserted, this, &DockSettings::dockItemCountChanged, Qt::QueuedConnection);
|
|
|
|
|
connect(m_itemManager, &DockItemManager::itemRemoved, this, &DockSettings::dockItemCountChanged, Qt::QueuedConnection);
|
2019-10-29 14:53:35 +08:00
|
|
|
|
connect(m_itemManager, &DockItemManager::trayVisableCountChanged, this, &DockSettings::trayVisableCountChanged, Qt::QueuedConnection);
|
2016-06-21 17:24:03 +08:00
|
|
|
|
|
2020-06-05 16:16:59 +08:00
|
|
|
|
connect(m_displayInter, &DisplayInter::PrimaryRectChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
|
|
|
|
|
connect(m_displayInter, &DisplayInter::ScreenHeightChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
|
|
|
|
|
connect(m_displayInter, &DisplayInter::ScreenWidthChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
|
|
|
|
|
connect(m_displayInter, &DisplayInter::PrimaryChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
|
|
|
|
|
connect(m_displayInter, &DisplayInter::MonitorsChanged, this, &DockSettings::onMonitorListChanged);
|
2020-02-24 17:39:14 +08:00
|
|
|
|
connect(GSettingsByTrash(), &QGSettings::changed, this, &DockSettings::onTrashGSettingsChanged);
|
|
|
|
|
QTimer::singleShot(0, this, [=] {onGSettingsChanged("enable");});
|
2016-06-29 14:37:24 +08:00
|
|
|
|
|
2019-08-17 18:01:32 +08:00
|
|
|
|
DApplication *app = qobject_cast<DApplication *>(qApp);
|
2017-02-15 17:10:32 +08:00
|
|
|
|
if (app) {
|
|
|
|
|
connect(app, &DApplication::iconThemeChanged, this, &DockSettings::gtkIconThemeChanged);
|
|
|
|
|
}
|
2016-08-18 15:14:50 +08:00
|
|
|
|
|
2020-06-05 16:16:59 +08:00
|
|
|
|
calculateMultiScreensPos();
|
2016-06-21 17:24:03 +08:00
|
|
|
|
calculateWindowConfig();
|
2016-08-12 14:28:35 +08:00
|
|
|
|
resetFrontendGeometry();
|
2018-10-11 09:21:11 +08:00
|
|
|
|
|
2019-08-17 18:01:32 +08:00
|
|
|
|
QTimer::singleShot(0, this, [ = ] {onOpacityChanged(m_dockInter->opacity());});
|
2020-02-14 23:25:09 +08:00
|
|
|
|
QTimer::singleShot(0, this, [=] {
|
|
|
|
|
onGSettingsChanged("enable");
|
|
|
|
|
});
|
2016-06-06 10:59:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 16:16:59 +08:00
|
|
|
|
const QList<QRect> DockSettings::monitorsRect() const
|
|
|
|
|
{
|
|
|
|
|
QList<QRect> monsRect;
|
|
|
|
|
QMapIterator<Monitor *, MonitorInter *> iterator(m_monitors);
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
|
iterator.next();
|
|
|
|
|
Monitor *monitor = iterator.key();
|
|
|
|
|
if (monitor) {
|
|
|
|
|
monsRect << monitor->rect();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return monsRect;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-30 15:12:51 +08:00
|
|
|
|
DockSettings &DockSettings::Instance()
|
|
|
|
|
{
|
|
|
|
|
static DockSettings settings;
|
|
|
|
|
return settings;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-29 14:38:12 +08:00
|
|
|
|
const QRect DockSettings::primaryRect() const
|
|
|
|
|
{
|
|
|
|
|
QRect rect = m_primaryRawRect;
|
|
|
|
|
qreal scale = qApp->primaryScreen()->devicePixelRatio();
|
|
|
|
|
|
|
|
|
|
rect.setWidth(std::round(qreal(rect.width()) / scale));
|
|
|
|
|
rect.setHeight(std::round(qreal(rect.height()) / scale));
|
|
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 20:45:02 +08:00
|
|
|
|
const QRect DockSettings::currentRect()
|
2020-04-21 17:47:35 +08:00
|
|
|
|
{
|
|
|
|
|
QRect rect;
|
2020-05-28 20:45:02 +08:00
|
|
|
|
QString currentScrName;
|
|
|
|
|
if (m_isMouseMoveCause) {
|
|
|
|
|
rect = m_mouseCauseDockScreen->rect();
|
|
|
|
|
currentScrName = m_mouseCauseDockScreen->name();
|
|
|
|
|
} else {
|
|
|
|
|
bool positionAllowed = false;
|
|
|
|
|
QList<Monitor*> monitors = m_monitors.keys();
|
|
|
|
|
for (Monitor *monitor : monitors) {
|
|
|
|
|
switch (m_position) {
|
|
|
|
|
case Top: positionAllowed = monitor->dockPosition().topDock; break;
|
|
|
|
|
case Right: positionAllowed = monitor->dockPosition().rightDock; break;
|
|
|
|
|
case Bottom: positionAllowed = monitor->dockPosition().bottomDock; break;
|
|
|
|
|
case Left: positionAllowed = monitor->dockPosition().leftDock; break;
|
|
|
|
|
}
|
|
|
|
|
if (positionAllowed) {
|
|
|
|
|
rect = monitor->rect();
|
|
|
|
|
currentScrName = monitor->name();
|
|
|
|
|
if (monitor->isPrimary())
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-04-21 17:47:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-28 20:45:02 +08:00
|
|
|
|
|
|
|
|
|
m_currentScreen = currentScrName;
|
2020-04-21 17:47:35 +08:00
|
|
|
|
m_currentRawRect = rect;
|
|
|
|
|
qreal scale = qApp->primaryScreen()->devicePixelRatio();
|
|
|
|
|
rect.setWidth(std::round(qreal(rect.width()) / scale));
|
|
|
|
|
rect.setHeight(std::round(qreal(rect.height()) / scale));
|
|
|
|
|
return rect;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-23 16:58:13 +08:00
|
|
|
|
const int DockSettings::dockMargin() const
|
2019-08-23 16:18:21 +08:00
|
|
|
|
{
|
2019-08-23 16:58:13 +08:00
|
|
|
|
if (m_displayMode == Dock::Efficient)
|
2019-08-23 16:18:21 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return 10;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 11:54:31 +08:00
|
|
|
|
const QSize DockSettings::panelSize() const
|
2016-06-22 16:41:36 +08:00
|
|
|
|
{
|
2019-05-06 15:26:49 +08:00
|
|
|
|
return m_mainWindowSize;
|
2016-06-13 09:20:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 20:45:02 +08:00
|
|
|
|
const QRect DockSettings::windowRect(const Position position, const bool hide)
|
2016-08-12 14:28:35 +08:00
|
|
|
|
{
|
2016-08-31 11:19:28 +08:00
|
|
|
|
QSize size = m_mainWindowSize;
|
2019-09-25 14:09:02 +08:00
|
|
|
|
if (hide) {
|
|
|
|
|
switch (position) {
|
|
|
|
|
case Top:
|
|
|
|
|
case Bottom: size.setHeight(2); break;
|
|
|
|
|
case Left:
|
|
|
|
|
case Right: size.setWidth(2); break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-31 11:19:28 +08:00
|
|
|
|
|
2020-06-05 16:16:59 +08:00
|
|
|
|
const QRect primaryRect = this->currentRect();
|
2016-08-12 14:28:35 +08:00
|
|
|
|
const int offsetX = (primaryRect.width() - size.width()) / 2;
|
|
|
|
|
const int offsetY = (primaryRect.height() - size.height()) / 2;
|
2019-09-25 14:09:02 +08:00
|
|
|
|
int margin = hide ? 0 : this->dockMargin();
|
2016-08-12 14:28:35 +08:00
|
|
|
|
QPoint p(0, 0);
|
2019-08-17 18:01:32 +08:00
|
|
|
|
switch (position) {
|
2019-08-23 16:18:21 +08:00
|
|
|
|
case Top:
|
|
|
|
|
p = QPoint(offsetX, margin);
|
2019-08-22 13:52:02 +08:00
|
|
|
|
break;
|
2016-08-12 14:28:35 +08:00
|
|
|
|
case Left:
|
2019-08-23 16:18:21 +08:00
|
|
|
|
p = QPoint(margin, offsetY);
|
|
|
|
|
break;
|
2016-08-12 14:28:35 +08:00
|
|
|
|
case Right:
|
2019-08-23 16:18:21 +08:00
|
|
|
|
p = QPoint(primaryRect.width() - size.width() - margin, offsetY);
|
|
|
|
|
break;
|
|
|
|
|
case Bottom:
|
|
|
|
|
p = QPoint(offsetX, primaryRect.height() - size.height() - margin);
|
2019-08-22 13:52:02 +08:00
|
|
|
|
break;
|
2016-08-12 14:28:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-30 14:20:58 +08:00
|
|
|
|
return QRect(primaryRect.topLeft() + p, size);
|
2016-08-12 14:28:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 14:02:51 +08:00
|
|
|
|
void DockSettings::showDockSettingsMenu()
|
|
|
|
|
{
|
2020-02-14 23:25:09 +08:00
|
|
|
|
QTimer::singleShot(0, this, [=] {
|
|
|
|
|
onGSettingsChanged("enable");
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-30 18:02:09 +08:00
|
|
|
|
m_autoHide = false;
|
2016-06-30 14:44:55 +08:00
|
|
|
|
|
2018-02-22 10:13:58 +08:00
|
|
|
|
// create actions
|
|
|
|
|
QList<QAction *> actions;
|
2019-08-17 18:01:32 +08:00
|
|
|
|
for (auto *p : m_itemManager->pluginList()) {
|
2017-10-23 10:06:36 +08:00
|
|
|
|
if (!p->pluginIsAllowDisable())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
const bool enable = !p->pluginIsDisable();
|
|
|
|
|
const QString &name = p->pluginName();
|
|
|
|
|
const QString &display = p->pluginDisplayName();
|
|
|
|
|
|
2020-02-24 17:39:14 +08:00
|
|
|
|
if (!m_trashPluginShow && name == "trash") {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-04-10 17:26:44 +08:00
|
|
|
|
|
2017-10-23 10:06:36 +08:00
|
|
|
|
QAction *act = new QAction(display, this);
|
|
|
|
|
act->setCheckable(true);
|
2017-10-26 13:54:56 +08:00
|
|
|
|
act->setChecked(enable);
|
2017-10-23 10:06:36 +08:00
|
|
|
|
act->setData(name);
|
|
|
|
|
|
2018-02-22 10:13:58 +08:00
|
|
|
|
actions << act;
|
2017-10-23 10:06:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 10:13:58 +08:00
|
|
|
|
// sort by name
|
2019-08-17 18:01:32 +08:00
|
|
|
|
std::sort(actions.begin(), actions.end(), [](QAction * a, QAction * b) -> bool {
|
2018-02-22 10:13:58 +08:00
|
|
|
|
return a->data().toString() > b->data().toString();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// add actions
|
|
|
|
|
qDeleteAll(m_hideSubMenu->actions());
|
|
|
|
|
for (auto act : actions)
|
|
|
|
|
m_hideSubMenu->addAction(act);
|
|
|
|
|
|
2016-06-21 14:02:51 +08:00
|
|
|
|
m_fashionModeAct.setChecked(m_displayMode == Fashion);
|
|
|
|
|
m_efficientModeAct.setChecked(m_displayMode == Efficient);
|
|
|
|
|
m_topPosAct.setChecked(m_position == Top);
|
|
|
|
|
m_bottomPosAct.setChecked(m_position == Bottom);
|
|
|
|
|
m_leftPosAct.setChecked(m_position == Left);
|
|
|
|
|
m_rightPosAct.setChecked(m_position == Right);
|
|
|
|
|
m_keepShownAct.setChecked(m_hideMode == KeepShowing);
|
|
|
|
|
m_keepHiddenAct.setChecked(m_hideMode == KeepHidden);
|
|
|
|
|
m_smartHideAct.setChecked(m_hideMode == SmartHide);
|
|
|
|
|
|
2016-12-12 10:58:48 +08:00
|
|
|
|
m_settingsMenu.exec(QCursor::pos());
|
2016-06-30 14:44:55 +08:00
|
|
|
|
|
|
|
|
|
setAutoHide(true);
|
2016-06-21 14:02:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-13 09:20:01 +08:00
|
|
|
|
void DockSettings::updateGeometry()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2016-06-21 14:02:51 +08:00
|
|
|
|
|
2016-06-30 14:44:55 +08:00
|
|
|
|
void DockSettings::setAutoHide(const bool autoHide)
|
|
|
|
|
{
|
|
|
|
|
if (m_autoHide == autoHide)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_autoHide = autoHide;
|
|
|
|
|
emit autoHideChanged(m_autoHide);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-12 10:58:48 +08:00
|
|
|
|
void DockSettings::menuActionClicked(QAction *action)
|
2016-06-21 14:02:51 +08:00
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(action);
|
|
|
|
|
|
|
|
|
|
if (action == &m_fashionModeAct)
|
|
|
|
|
return m_dockInter->setDisplayMode(Fashion);
|
|
|
|
|
if (action == &m_efficientModeAct)
|
|
|
|
|
return m_dockInter->setDisplayMode(Efficient);
|
2016-06-21 15:11:32 +08:00
|
|
|
|
|
2020-05-28 20:45:02 +08:00
|
|
|
|
m_isMouseMoveCause = false;
|
2020-06-05 16:16:59 +08:00
|
|
|
|
calculateMultiScreensPos();
|
2016-06-21 14:02:51 +08:00
|
|
|
|
if (action == &m_topPosAct)
|
|
|
|
|
return m_dockInter->setPosition(Top);
|
|
|
|
|
if (action == &m_bottomPosAct)
|
|
|
|
|
return m_dockInter->setPosition(Bottom);
|
|
|
|
|
if (action == &m_leftPosAct)
|
|
|
|
|
return m_dockInter->setPosition(Left);
|
|
|
|
|
if (action == &m_rightPosAct)
|
|
|
|
|
return m_dockInter->setPosition(Right);
|
|
|
|
|
if (action == &m_keepShownAct)
|
|
|
|
|
return m_dockInter->setHideMode(KeepShowing);
|
|
|
|
|
if (action == &m_keepHiddenAct)
|
|
|
|
|
return m_dockInter->setHideMode(KeepHidden);
|
|
|
|
|
if (action == &m_smartHideAct)
|
|
|
|
|
return m_dockInter->setHideMode(SmartHide);
|
2017-10-23 10:06:36 +08:00
|
|
|
|
|
|
|
|
|
// check plugin hide menu.
|
|
|
|
|
const QString &data = action->data().toString();
|
|
|
|
|
if (data.isEmpty())
|
|
|
|
|
return;
|
2019-08-17 18:01:32 +08:00
|
|
|
|
for (auto *p : m_itemManager->pluginList()) {
|
2017-10-23 10:06:36 +08:00
|
|
|
|
if (p->pluginName() == data)
|
|
|
|
|
return p->pluginStateSwitched();
|
|
|
|
|
}
|
2016-06-21 14:02:51 +08:00
|
|
|
|
}
|
2016-06-21 15:11:32 +08:00
|
|
|
|
|
2020-01-19 18:21:26 +08:00
|
|
|
|
void DockSettings::onGSettingsChanged(const QString &key)
|
|
|
|
|
{
|
|
|
|
|
if (key != "enable") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QGSettings *setting = GSettingsByMenu();
|
|
|
|
|
|
|
|
|
|
if (setting->keys().contains("enable")) {
|
|
|
|
|
const bool isEnable = GSettingsByMenu()->keys().contains("enable") && GSettingsByMenu()->get("enable").toBool();
|
|
|
|
|
m_menuVisible=isEnable && setting->get("enable").toBool();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-12 14:28:35 +08:00
|
|
|
|
void DockSettings::onPositionChanged()
|
2016-06-21 15:11:32 +08:00
|
|
|
|
{
|
2016-08-12 14:28:35 +08:00
|
|
|
|
const Position prevPos = m_position;
|
|
|
|
|
const Position nextPos = Dock::Position(m_dockInter->position());
|
|
|
|
|
|
|
|
|
|
if (prevPos == nextPos)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-09-25 14:09:02 +08:00
|
|
|
|
emit positionChanged(prevPos, nextPos);
|
2016-06-21 17:24:03 +08:00
|
|
|
|
|
2018-01-30 14:24:22 +08:00
|
|
|
|
QTimer::singleShot(200, this, [this, nextPos] {
|
2018-01-04 17:22:37 +08:00
|
|
|
|
m_position = nextPos;
|
2018-01-30 14:24:22 +08:00
|
|
|
|
DockItem::setDockPosition(nextPos);
|
|
|
|
|
qApp->setProperty(PROP_POSITION, QVariant::fromValue(nextPos));
|
2016-06-21 15:11:32 +08:00
|
|
|
|
|
2018-01-04 17:22:37 +08:00
|
|
|
|
calculateWindowConfig();
|
2016-08-22 15:46:14 +08:00
|
|
|
|
|
2019-08-17 18:01:32 +08:00
|
|
|
|
m_itemManager->refershItemsIcon();
|
2018-01-04 17:22:37 +08:00
|
|
|
|
});
|
2016-06-21 17:24:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 17:22:37 +08:00
|
|
|
|
void DockSettings::onDisplayModeChanged()
|
2016-06-22 10:28:47 +08:00
|
|
|
|
{
|
2017-07-14 14:05:35 +08:00
|
|
|
|
// qDebug() << Q_FUNC_INFO;
|
2016-06-22 10:28:47 +08:00
|
|
|
|
m_displayMode = Dock::DisplayMode(m_dockInter->displayMode());
|
2016-06-23 14:28:47 +08:00
|
|
|
|
DockItem::setDockDisplayMode(m_displayMode);
|
2016-06-27 14:33:21 +08:00
|
|
|
|
qApp->setProperty(PROP_DISPLAY_MODE, QVariant::fromValue(m_displayMode));
|
2016-06-22 10:28:47 +08:00
|
|
|
|
|
2018-01-04 17:22:37 +08:00
|
|
|
|
emit displayModeChanegd();
|
2019-09-04 11:01:11 +08:00
|
|
|
|
calculateWindowConfig();
|
2018-03-07 18:05:40 +08:00
|
|
|
|
|
2020-01-11 10:35:29 +08:00
|
|
|
|
//QTimer::singleShot(1, m_itemManager, &DockItemManager::sortPluginItems);
|
2016-06-22 10:28:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-27 16:36:51 +08:00
|
|
|
|
void DockSettings::hideModeChanged()
|
|
|
|
|
{
|
2017-07-14 14:05:35 +08:00
|
|
|
|
// qDebug() << Q_FUNC_INFO;
|
2016-06-27 16:36:51 +08:00
|
|
|
|
m_hideMode = Dock::HideMode(m_dockInter->hideMode());
|
2016-06-29 16:53:37 +08:00
|
|
|
|
|
|
|
|
|
emit windowHideModeChanged();
|
2016-06-27 16:36:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-07 00:18:00 +08:00
|
|
|
|
void DockSettings::hideStateChanged()
|
2016-06-29 18:30:25 +08:00
|
|
|
|
{
|
2017-07-14 14:05:35 +08:00
|
|
|
|
// qDebug() << Q_FUNC_INFO;
|
2016-06-30 18:02:09 +08:00
|
|
|
|
const Dock::HideState state = Dock::HideState(m_dockInter->hideState());
|
|
|
|
|
|
|
|
|
|
if (state == Dock::Unknown)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_hideState = state;
|
2016-06-29 18:30:25 +08:00
|
|
|
|
|
2017-02-07 00:18:00 +08:00
|
|
|
|
emit windowVisibleChanged();
|
2016-06-29 18:30:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-22 10:28:47 +08:00
|
|
|
|
void DockSettings::dockItemCountChanged()
|
|
|
|
|
{
|
|
|
|
|
emit windowGeometryChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-29 14:37:24 +08:00
|
|
|
|
void DockSettings::primaryScreenChanged()
|
|
|
|
|
{
|
2017-07-14 14:05:35 +08:00
|
|
|
|
// qDebug() << Q_FUNC_INFO;
|
2020-06-05 16:16:59 +08:00
|
|
|
|
m_primaryRawRect = m_displayInter->primaryRect();
|
|
|
|
|
m_screenRawHeight = m_displayInter->screenHeight();
|
|
|
|
|
m_screenRawWidth = m_displayInter->screenWidth();
|
2016-06-29 14:37:24 +08:00
|
|
|
|
|
2020-04-30 15:12:25 +08:00
|
|
|
|
//为了防止当后端发送错误值,然后发送正确值时,任务栏没有移动在相应的位置
|
|
|
|
|
//当qt没有获取到屏幕资源时候,move函数会失效。可以直接return
|
|
|
|
|
if (m_screenRawHeight == 0 || m_screenRawWidth == 0){
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-06-05 16:16:59 +08:00
|
|
|
|
calculateMultiScreensPos();
|
2016-06-29 14:37:24 +08:00
|
|
|
|
emit dataChanged();
|
2019-09-04 11:01:11 +08:00
|
|
|
|
calculateWindowConfig();
|
2019-09-26 19:08:29 +08:00
|
|
|
|
|
|
|
|
|
// 主屏切换时,如果缩放比例不一样,需要刷新item的图标(bug:3176)
|
|
|
|
|
m_itemManager->refershItemsIcon();
|
2016-06-29 14:37:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-30 15:46:20 +08:00
|
|
|
|
void DockSettings::resetFrontendGeometry()
|
2016-06-30 09:53:50 +08:00
|
|
|
|
{
|
2016-08-12 14:28:35 +08:00
|
|
|
|
const QRect r = windowRect(m_position);
|
2019-04-23 14:28:09 +08:00
|
|
|
|
const qreal ratio = dockRatio();
|
2017-12-15 16:13:44 +08:00
|
|
|
|
const QPoint p = rawXPosition(r.topLeft());
|
2017-12-13 11:53:03 +08:00
|
|
|
|
const uint w = r.width() * ratio;
|
|
|
|
|
const uint h = r.height() * ratio;
|
|
|
|
|
|
2017-12-15 16:13:44 +08:00
|
|
|
|
m_frontendRect = QRect(p.x(), p.y(), w, h);
|
|
|
|
|
m_dockInter->SetFrontendWindowRect(p.x(), p.y(), w, h);
|
2017-12-13 11:53:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-20 16:05:22 +08:00
|
|
|
|
void DockSettings::updateFrontendGeometry()
|
|
|
|
|
{
|
|
|
|
|
resetFrontendGeometry();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 20:45:02 +08:00
|
|
|
|
void DockSettings::setDockScreen(const QString &scrName)
|
|
|
|
|
{
|
|
|
|
|
m_isMouseMoveCause = true;
|
|
|
|
|
QList<Monitor*> monitors = m_monitors.keys();
|
|
|
|
|
for (Monitor *monitor : monitors) {
|
|
|
|
|
if (monitor && monitor->name() == scrName) {
|
|
|
|
|
m_mouseCauseDockScreen = monitor;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-08 15:11:42 +08:00
|
|
|
|
void DockSettings::onOpacityChanged(const double value)
|
|
|
|
|
{
|
|
|
|
|
if (m_opacity == value) return;
|
|
|
|
|
|
|
|
|
|
m_opacity = value;
|
|
|
|
|
|
|
|
|
|
emit opacityChanged(value * 255);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-29 14:53:35 +08:00
|
|
|
|
void DockSettings::trayVisableCountChanged(const int &count)
|
2018-10-16 14:33:06 +08:00
|
|
|
|
{
|
2020-02-12 17:32:46 +08:00
|
|
|
|
emit trayCountChanged();
|
2018-10-16 14:33:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 17:24:03 +08:00
|
|
|
|
void DockSettings::calculateWindowConfig()
|
|
|
|
|
{
|
2019-08-17 18:01:32 +08:00
|
|
|
|
if (m_displayMode == Dock::Efficient) {
|
2020-06-05 16:16:59 +08:00
|
|
|
|
m_dockWindowSize = int(m_dockInter->windowSizeEfficient());
|
2019-11-15 13:39:50 +08:00
|
|
|
|
if (m_dockWindowSize > WINDOW_MAX_SIZE || m_dockWindowSize < WINDOW_MIN_SIZE) {
|
|
|
|
|
m_dockWindowSize = EffICIENT_DEFAULT_HEIGHT;
|
2019-11-15 14:18:05 +08:00
|
|
|
|
m_dockInter->setWindowSize(EffICIENT_DEFAULT_HEIGHT);
|
2019-11-15 13:39:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-17 18:01:32 +08:00
|
|
|
|
switch (m_position) {
|
2016-06-22 10:28:47 +08:00
|
|
|
|
case Top:
|
|
|
|
|
case Bottom:
|
2019-09-03 13:26:42 +08:00
|
|
|
|
m_mainWindowSize.setHeight(m_dockWindowSize);
|
2020-06-05 16:16:59 +08:00
|
|
|
|
m_mainWindowSize.setWidth(currentRect().width());
|
2016-06-22 10:28:47 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Left:
|
|
|
|
|
case Right:
|
2020-06-05 16:16:59 +08:00
|
|
|
|
m_mainWindowSize.setHeight(currentRect().height());
|
2019-09-03 13:26:42 +08:00
|
|
|
|
m_mainWindowSize.setWidth(m_dockWindowSize);
|
2016-06-22 10:28:47 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2019-08-17 18:01:32 +08:00
|
|
|
|
} else if (m_displayMode == Dock::Fashion) {
|
2020-06-05 16:16:59 +08:00
|
|
|
|
m_dockWindowSize = int(m_dockInter->windowSizeFashion());
|
2019-11-15 13:39:50 +08:00
|
|
|
|
if (m_dockWindowSize > WINDOW_MAX_SIZE || m_dockWindowSize < WINDOW_MIN_SIZE) {
|
|
|
|
|
m_dockWindowSize = FASHION_DEFAULT_HEIGHT;
|
2019-11-15 14:18:05 +08:00
|
|
|
|
m_dockInter->setWindowSize(FASHION_DEFAULT_HEIGHT);
|
2019-11-15 13:39:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-17 18:01:32 +08:00
|
|
|
|
switch (m_position) {
|
2016-06-22 10:28:47 +08:00
|
|
|
|
case Top:
|
2018-11-22 17:19:48 +08:00
|
|
|
|
case Bottom: {
|
2019-09-03 13:26:42 +08:00
|
|
|
|
m_mainWindowSize.setHeight(m_dockWindowSize);
|
2020-06-05 16:16:59 +08:00
|
|
|
|
m_mainWindowSize.setWidth(this->currentRect().width() - MAINWINDOW_MARGIN * 2);
|
2016-06-22 10:28:47 +08:00
|
|
|
|
break;
|
2018-11-22 17:19:48 +08:00
|
|
|
|
}
|
2016-06-22 10:28:47 +08:00
|
|
|
|
case Left:
|
2018-11-22 17:19:48 +08:00
|
|
|
|
case Right: {
|
2020-06-05 16:16:59 +08:00
|
|
|
|
m_mainWindowSize.setHeight(this->currentRect().height() - MAINWINDOW_MARGIN * 2);
|
2019-09-03 13:26:42 +08:00
|
|
|
|
m_mainWindowSize.setWidth(m_dockWindowSize);
|
2016-06-22 10:28:47 +08:00
|
|
|
|
break;
|
2018-11-22 17:19:48 +08:00
|
|
|
|
}
|
2016-06-22 10:28:47 +08:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2016-06-21 15:11:32 +08:00
|
|
|
|
Q_ASSERT(false);
|
|
|
|
|
}
|
2016-06-30 15:46:20 +08:00
|
|
|
|
|
|
|
|
|
resetFrontendGeometry();
|
2016-06-21 15:11:32 +08:00
|
|
|
|
}
|
2016-08-18 15:14:50 +08:00
|
|
|
|
|
2017-02-15 17:10:32 +08:00
|
|
|
|
void DockSettings::gtkIconThemeChanged()
|
2016-08-18 15:14:50 +08:00
|
|
|
|
{
|
2017-05-31 17:10:32 +08:00
|
|
|
|
qDebug() << Q_FUNC_INFO;
|
2019-08-17 18:01:32 +08:00
|
|
|
|
m_itemManager->refershItemsIcon();
|
2016-08-18 15:14:50 +08:00
|
|
|
|
}
|
2019-04-23 14:28:09 +08:00
|
|
|
|
|
|
|
|
|
qreal DockSettings::dockRatio() const
|
|
|
|
|
{
|
|
|
|
|
QScreen const *screen = Utils::screenAtByScaled(m_frontendRect.center());
|
|
|
|
|
|
|
|
|
|
return screen ? screen->devicePixelRatio() : qApp->devicePixelRatio();
|
|
|
|
|
}
|
2019-09-03 13:26:42 +08:00
|
|
|
|
|
2019-10-08 13:57:35 +08:00
|
|
|
|
void DockSettings::onWindowSizeChanged()
|
|
|
|
|
{
|
|
|
|
|
calculateWindowConfig();
|
|
|
|
|
emit windowGeometryChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-02 15:01:38 +08:00
|
|
|
|
void DockSettings::checkService()
|
|
|
|
|
{
|
|
|
|
|
// com.deepin.dde.daemon.Dock服务比dock晚启动,导致dock启动后的状态错误
|
|
|
|
|
|
|
|
|
|
QString serverName = "com.deepin.dde.daemon.Dock";
|
|
|
|
|
QDBusConnectionInterface *ifc = QDBusConnection::sessionBus().interface();
|
|
|
|
|
|
|
|
|
|
if (!ifc->isServiceRegistered(serverName)) {
|
|
|
|
|
connect(ifc, &QDBusConnectionInterface::serviceOwnerChanged, this, [ = ](const QString & name, const QString & oldOwner, const QString & newOwner) {
|
2020-06-05 16:16:59 +08:00
|
|
|
|
Q_UNUSED(oldOwner)
|
2019-12-02 15:01:38 +08:00
|
|
|
|
if (name == serverName && !newOwner.isEmpty()) {
|
|
|
|
|
|
|
|
|
|
m_dockInter = new DBusDock(serverName, "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus(), this);
|
|
|
|
|
onPositionChanged();
|
|
|
|
|
onDisplayModeChanged();
|
|
|
|
|
hideModeChanged();
|
|
|
|
|
hideStateChanged();
|
|
|
|
|
onOpacityChanged(m_dockInter->opacity());
|
|
|
|
|
onWindowSizeChanged();
|
|
|
|
|
|
|
|
|
|
disconnect(ifc);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-24 17:39:14 +08:00
|
|
|
|
|
2020-06-05 16:16:59 +08:00
|
|
|
|
void DockSettings::calculateMultiScreensPos()
|
|
|
|
|
{
|
|
|
|
|
QList<Monitor *> monitors = m_monitors.keys();
|
|
|
|
|
for (Monitor *monitor : monitors) {
|
|
|
|
|
monitor->setDockPosition(Monitor::DockPosition(true, true, true, true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (m_monitors.size()) {
|
|
|
|
|
case 0:
|
|
|
|
|
break;
|
|
|
|
|
case 1: {
|
|
|
|
|
QList<Monitor*>screens = m_monitors.keys();
|
|
|
|
|
Monitor* s1 = screens.at(0);
|
|
|
|
|
s1->setDockPosition(Monitor::DockPosition(true, true, true, true));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
twoScreensCalPos();
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
treeScreensCalPos();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockSettings::monitorAdded(const QString &path)
|
|
|
|
|
{
|
|
|
|
|
MonitorInter *inter = new MonitorInter("com.deepin.daemon.Display", path, QDBusConnection::sessionBus(), this);
|
|
|
|
|
Monitor *mon = new Monitor(this);
|
|
|
|
|
|
|
|
|
|
connect(inter, &MonitorInter::XChanged, mon, &Monitor::setX);
|
|
|
|
|
connect(inter, &MonitorInter::YChanged, mon, &Monitor::setY);
|
|
|
|
|
connect(inter, &MonitorInter::WidthChanged, mon, &Monitor::setW);
|
|
|
|
|
connect(inter, &MonitorInter::HeightChanged, mon, &Monitor::setH);
|
|
|
|
|
connect(inter, &MonitorInter::MmWidthChanged, mon, &Monitor::setMmWidth);
|
|
|
|
|
connect(inter, &MonitorInter::MmHeightChanged, mon, &Monitor::setMmHeight);
|
|
|
|
|
connect(inter, &MonitorInter::RotationChanged, mon, &Monitor::setRotate);
|
|
|
|
|
connect(inter, &MonitorInter::NameChanged, mon, &Monitor::setName);
|
|
|
|
|
connect(inter, &MonitorInter::CurrentModeChanged, mon, &Monitor::setCurrentMode);
|
|
|
|
|
connect(inter, &MonitorInter::ModesChanged, mon, &Monitor::setModeList);
|
|
|
|
|
connect(inter, &MonitorInter::RotationsChanged, mon, &Monitor::setRotateList);
|
|
|
|
|
connect(inter, &MonitorInter::EnabledChanged, mon, &Monitor::setMonitorEnable);
|
|
|
|
|
connect(m_displayInter, static_cast<void (DisplayInter::*)(const QString &) const>(&DisplayInter::PrimaryChanged), mon, &Monitor::setPrimary);
|
|
|
|
|
|
|
|
|
|
// NOTE: DO NOT using async dbus call. because we need to have a unique name to distinguish each monitor
|
|
|
|
|
Q_ASSERT(inter->isValid());
|
|
|
|
|
mon->setName(inter->name());
|
|
|
|
|
|
|
|
|
|
mon->setMonitorEnable(inter->enabled());
|
|
|
|
|
mon->setPath(path);
|
|
|
|
|
mon->setX(inter->x());
|
|
|
|
|
mon->setY(inter->y());
|
|
|
|
|
mon->setW(inter->width());
|
|
|
|
|
mon->setH(inter->height());
|
|
|
|
|
mon->setRotate(inter->rotation());
|
|
|
|
|
mon->setCurrentMode(inter->currentMode());
|
|
|
|
|
mon->setModeList(inter->modes());
|
|
|
|
|
|
|
|
|
|
mon->setRotateList(inter->rotations());
|
|
|
|
|
mon->setPrimary(m_displayInter->primary());
|
|
|
|
|
mon->setMmWidth(inter->mmWidth());
|
|
|
|
|
mon->setMmHeight(inter->mmHeight());
|
|
|
|
|
|
|
|
|
|
m_monitors.insert(mon, inter);
|
|
|
|
|
inter->setSync(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockSettings::monitorRemoved(const QString &path)
|
|
|
|
|
{
|
|
|
|
|
Monitor *monitor = nullptr;
|
|
|
|
|
for (auto it(m_monitors.cbegin()); it != m_monitors.cend(); ++it) {
|
|
|
|
|
if (it.key()->path() == path) {
|
|
|
|
|
monitor = it.key();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!monitor)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_monitors.value(monitor)->deleteLater();
|
|
|
|
|
m_monitors.remove(monitor);
|
|
|
|
|
|
|
|
|
|
monitor->deleteLater();
|
|
|
|
|
|
|
|
|
|
calculateMultiScreensPos();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockSettings::twoScreensCalPos()
|
|
|
|
|
{
|
|
|
|
|
QList<Monitor*>screens = m_monitors.keys();
|
|
|
|
|
Monitor* s1 = screens.at(0);
|
|
|
|
|
Monitor* s2 = screens.at(1);
|
|
|
|
|
if (!s1 && !s2)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// 只在某屏显示时,其它屏禁用
|
|
|
|
|
bool s1Enabled = s1->enable();
|
|
|
|
|
bool s2Enabled = s2->enable();
|
|
|
|
|
if (!s1Enabled || !s2Enabled) {
|
|
|
|
|
if (!s1Enabled && s2Enabled) {
|
|
|
|
|
s1->setDockPosition(Monitor::DockPosition(false, false, false, false));
|
|
|
|
|
s2->setDockPosition(Monitor::DockPosition(true, true, true, true));
|
|
|
|
|
} else if (!s2Enabled && s1Enabled) {
|
|
|
|
|
s1->setDockPosition(Monitor::DockPosition(true, true, true, true));
|
|
|
|
|
s2->setDockPosition(Monitor::DockPosition(false, false, false, false));
|
|
|
|
|
} else if (!s1Enabled && !s2Enabled) {
|
|
|
|
|
s1->setDockPosition(Monitor::DockPosition(false, false, false, false));
|
|
|
|
|
s2->setDockPosition(Monitor::DockPosition(false, false, false, false));
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
combination(screens);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockSettings::treeScreensCalPos()
|
|
|
|
|
{
|
|
|
|
|
QList<Monitor*>screens = m_monitors.keys();
|
|
|
|
|
Monitor* s1 = screens.at(0);
|
|
|
|
|
Monitor* s2 = screens.at(1);
|
|
|
|
|
Monitor* s3 = screens.at(2);
|
|
|
|
|
if (!s1 && !s2 && !s3)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// 只在某屏显示时,其它屏禁用
|
|
|
|
|
bool s1Enabled = s1->enable();
|
|
|
|
|
bool s2Enabled = s2->enable();
|
|
|
|
|
bool s3Enabled = s3->enable();
|
|
|
|
|
if (!s1Enabled || !s2Enabled || !s3Enabled) {
|
|
|
|
|
if (!s1Enabled && !s2Enabled && s3Enabled) {
|
|
|
|
|
s1->setDockPosition(Monitor::DockPosition(false, false, false, false));
|
|
|
|
|
s2->setDockPosition(Monitor::DockPosition(false, false, false, false));
|
|
|
|
|
s3->setDockPosition(Monitor::DockPosition(true, true, true, true));
|
|
|
|
|
} else if (!s1Enabled && s2Enabled && !s3Enabled) {
|
|
|
|
|
s1->setDockPosition(Monitor::DockPosition(false, false, false, false));
|
|
|
|
|
s2->setDockPosition(Monitor::DockPosition(true, true, true, true));
|
|
|
|
|
s3->setDockPosition(Monitor::DockPosition(false, false, false, false));
|
|
|
|
|
} else if (s1Enabled && !s2Enabled && !s3Enabled) {
|
|
|
|
|
s1->setDockPosition(Monitor::DockPosition(true, true, true, true));
|
|
|
|
|
s2->setDockPosition(Monitor::DockPosition(false, false, false, false));
|
|
|
|
|
s3->setDockPosition(Monitor::DockPosition(false, false, false, false));
|
|
|
|
|
} else if (!s1Enabled && !s2Enabled && !s3Enabled) {
|
|
|
|
|
s1->setDockPosition(Monitor::DockPosition(false, false, false, false));
|
|
|
|
|
s2->setDockPosition(Monitor::DockPosition(false, false, false, false));
|
|
|
|
|
s3->setDockPosition(Monitor::DockPosition(false, false, false, false));
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
combination(screens);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockSettings::combination(QList<Monitor *> &screens)
|
|
|
|
|
{
|
|
|
|
|
if (screens.size() < 2)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Monitor *last = screens.takeLast();
|
|
|
|
|
|
|
|
|
|
for (Monitor *screen : screens) {
|
|
|
|
|
calculateRelativePos(last, screen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
combination(screens);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockSettings::calculateRelativePos(Monitor *s1, Monitor *s2)
|
|
|
|
|
{
|
|
|
|
|
/* 鼠标可移动区另算 */
|
|
|
|
|
if (!s1 && !s2)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// 对齐
|
|
|
|
|
bool isAligment = false;
|
|
|
|
|
// 左右拼
|
2020-05-21 17:20:39 +08:00
|
|
|
|
if (s1->bottom() > s2->top() && s1->top() < s2->bottom()) {
|
|
|
|
|
// s1左 s2右
|
|
|
|
|
if (s1->right() == s2->left() ) {
|
|
|
|
|
isAligment = (s1->topRight() == s2->topLeft())
|
|
|
|
|
&& (s1->bottomRight() == s2->bottomLeft());
|
|
|
|
|
if (isAligment) {
|
2020-06-05 16:16:59 +08:00
|
|
|
|
s1->dockPosition().rightDock = false;
|
|
|
|
|
s2->dockPosition().leftDock = false;
|
2020-05-21 17:20:39 +08:00
|
|
|
|
} else {
|
|
|
|
|
if (!s1->isPrimary())
|
|
|
|
|
s1->dockPosition().rightDock = false;
|
|
|
|
|
if (!s2->isPrimary())
|
|
|
|
|
s2->dockPosition().leftDock = false;
|
|
|
|
|
}
|
2020-06-05 16:16:59 +08:00
|
|
|
|
}
|
2020-05-21 17:20:39 +08:00
|
|
|
|
// s1右 s2左
|
|
|
|
|
if (s1->left() == s2->right()) {
|
|
|
|
|
isAligment = (s1->topLeft() == s2->topRight())
|
|
|
|
|
&& (s1->bottomLeft() == s2->bottomRight());
|
|
|
|
|
if (isAligment) {
|
2020-06-05 16:16:59 +08:00
|
|
|
|
s1->dockPosition().leftDock = false;
|
|
|
|
|
s2->dockPosition().rightDock = false;
|
2020-05-21 17:20:39 +08:00
|
|
|
|
} else {
|
|
|
|
|
if (!s1->isPrimary())
|
|
|
|
|
s1->dockPosition().leftDock = false;
|
|
|
|
|
if (!s2->isPrimary())
|
|
|
|
|
s2->dockPosition().rightDock = false;
|
|
|
|
|
}
|
2020-06-05 16:16:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 上下拼
|
2020-05-21 17:20:39 +08:00
|
|
|
|
if (s1->right() > s2->left() && s1->left() < s2->right()) {
|
|
|
|
|
// s1上 s2下
|
|
|
|
|
if (s1->bottom() == s2->top()) {
|
|
|
|
|
isAligment = (s1->bottomLeft() == s2->topLeft())
|
|
|
|
|
&& (s1->bottomRight() == s2->topRight());
|
|
|
|
|
if (isAligment) {
|
2020-06-05 16:16:59 +08:00
|
|
|
|
s1->dockPosition().bottomDock = false;
|
|
|
|
|
s2->dockPosition().topDock = false;
|
2020-05-21 17:20:39 +08:00
|
|
|
|
} else {
|
|
|
|
|
if (!s1->isPrimary())
|
|
|
|
|
s1->dockPosition().bottomDock = false;
|
|
|
|
|
if (!s2->isPrimary())
|
|
|
|
|
s2->dockPosition().topDock = false;
|
|
|
|
|
}
|
2020-06-05 16:16:59 +08:00
|
|
|
|
}
|
2020-05-21 17:20:39 +08:00
|
|
|
|
// s1下 s2上
|
|
|
|
|
if (s1->top() == s2->bottom()) {
|
|
|
|
|
isAligment = (s1->topLeft() == s2->bottomLeft())
|
|
|
|
|
&& (s1->topRight() == s2->bottomRight());
|
|
|
|
|
if (isAligment) {
|
2020-06-05 16:16:59 +08:00
|
|
|
|
s1->dockPosition().topDock = false;
|
|
|
|
|
s2->dockPosition().bottomDock = false;
|
2020-05-21 17:20:39 +08:00
|
|
|
|
} else {
|
|
|
|
|
if (!s1->isPrimary())
|
|
|
|
|
s1->dockPosition().topDock = false;
|
|
|
|
|
if (!s2->isPrimary())
|
|
|
|
|
s2->dockPosition().bottomDock = false;
|
|
|
|
|
}
|
2020-06-05 16:16:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 对角拼
|
|
|
|
|
bool isDiagonal = (s1->topLeft() == s2->bottomRight())
|
|
|
|
|
|| (s1->topRight() == s2->bottomLeft())
|
|
|
|
|
|| (s1->bottomLeft() == s2->topRight())
|
|
|
|
|
|| (s1->bottomRight() == s2->topLeft());
|
|
|
|
|
if (isDiagonal) {
|
|
|
|
|
auto position = Monitor::DockPosition(false, false, false, false);
|
2020-05-21 17:20:39 +08:00
|
|
|
|
if (s1->isPrimary())
|
2020-06-05 16:16:59 +08:00
|
|
|
|
s2->setDockPosition(position);
|
2020-05-21 17:20:39 +08:00
|
|
|
|
if (s2->isPrimary())
|
2020-06-05 16:16:59 +08:00
|
|
|
|
s1->setDockPosition(position);
|
|
|
|
|
|
|
|
|
|
switch (m_position) {
|
|
|
|
|
case Top:
|
|
|
|
|
s1->dockPosition().topDock = true;
|
|
|
|
|
s2->dockPosition().topDock = true;
|
|
|
|
|
break;
|
|
|
|
|
case Bottom:
|
|
|
|
|
s1->dockPosition().bottomDock = true;
|
|
|
|
|
s2->dockPosition().bottomDock = true;
|
|
|
|
|
break;
|
|
|
|
|
case Left:
|
|
|
|
|
s1->dockPosition().leftDock = true;
|
|
|
|
|
s2->dockPosition().leftDock = true;
|
|
|
|
|
break;
|
|
|
|
|
case Right:
|
|
|
|
|
s1->dockPosition().rightDock = true;
|
|
|
|
|
s2->dockPosition().rightDock = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-24 17:39:14 +08:00
|
|
|
|
void DockSettings::onTrashGSettingsChanged(const QString &key)
|
|
|
|
|
{
|
|
|
|
|
if (key != "enable") {
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QGSettings *setting = GSettingsByTrash();
|
|
|
|
|
|
|
|
|
|
if (setting->keys().contains("enable")) {
|
|
|
|
|
m_trashPluginShow = GSettingsByTrash()->keys().contains("enable") && GSettingsByTrash()->get("enable").toBool();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-05 16:16:59 +08:00
|
|
|
|
|
|
|
|
|
void DockSettings::onMonitorListChanged(const QList<QDBusObjectPath> &mons)
|
|
|
|
|
{
|
|
|
|
|
if (mons.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QList<QString> ops;
|
|
|
|
|
for (const auto *mon : m_monitors.keys())
|
|
|
|
|
ops << mon->path();
|
|
|
|
|
|
|
|
|
|
QList<QString> pathList;
|
|
|
|
|
for (const auto op : mons) {
|
|
|
|
|
const QString path = op.path();
|
|
|
|
|
pathList << path;
|
|
|
|
|
if (!ops.contains(path))
|
|
|
|
|
monitorAdded(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const auto op : ops)
|
|
|
|
|
if (!pathList.contains(op))
|
|
|
|
|
monitorRemoved(op);
|
|
|
|
|
}
|