mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
fix: 重构任务栏的多屏功能代码
重构此部分代码,因时间太长了,rebase会带来较多的冲突,目前手摘取过来 Log: 重构任务栏的多屏功能代码 Change-Id: I23200f7d7d12e05b75909a38c8081fc435d019eb Reviewed-on: http://gerrit.uniontech.com/c/dde-dock/+/1353 Reviewed-by: <mailman@uniontech.com> Reviewed-by: lizhongming <lizhongming@uniontech.com> Tested-by: <mailman@uniontech.com>
This commit is contained in:
parent
6560e767a6
commit
dc88a3e14c
@ -24,7 +24,6 @@
|
||||
#include "item/launcheritem.h"
|
||||
#include "item/pluginsitem.h"
|
||||
#include "item/traypluginitem.h"
|
||||
#include "util/docksettings.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QGSettings>
|
||||
|
@ -21,7 +21,6 @@
|
||||
|
||||
#include "mainpanelcontrol.h"
|
||||
#include "../item/dockitem.h"
|
||||
#include "util/docksettings.h"
|
||||
#include "../item/placeholderitem.h"
|
||||
#include "../item/components/appdrag.h"
|
||||
#include "../item/appitem.h"
|
||||
|
@ -1,966 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: sbw <sbw@sbw.so>
|
||||
*
|
||||
* Maintainer: sbw <sbw@sbw.so>
|
||||
* zhaolong <zhaolong@uniontech.com>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "docksettings.h"
|
||||
#include "item/appitem.h"
|
||||
#include "util/utils.h"
|
||||
#include "controller/dockitemmanager.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QX11Info>
|
||||
#include <QGSettings>
|
||||
|
||||
#include <DApplication>
|
||||
#include <QScreen>
|
||||
|
||||
#define FASHION_MODE_PADDING 30
|
||||
#define MAINWINDOW_MARGIN 10
|
||||
|
||||
#define FASHION_DEFAULT_HEIGHT 72
|
||||
#define EffICIENT_DEFAULT_HEIGHT 40
|
||||
#define WINDOW_MAX_SIZE 100
|
||||
#define WINDOW_MIN_SIZE 40
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
extern const QPoint rawXPosition(const QPoint &scaledPos);
|
||||
|
||||
static QGSettings *GSettingsByMenu()
|
||||
{
|
||||
static QGSettings settings("com.deepin.dde.dock.module.menu");
|
||||
return &settings;
|
||||
}
|
||||
|
||||
static QGSettings *GSettingsByTrash()
|
||||
{
|
||||
static QGSettings settings("com.deepin.dde.dock.module.trash");
|
||||
return &settings;
|
||||
}
|
||||
|
||||
DockSettings::DockSettings(QWidget *parent)
|
||||
: QObject(parent)
|
||||
, m_dockInter(new DBusDock("com.deepin.dde.daemon.Dock", "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus(), this))
|
||||
, m_menuVisible(true)
|
||||
, m_autoHide(true)
|
||||
, m_opacity(0.4)
|
||||
, 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)
|
||||
, m_displayInter(new DisplayInter("com.deepin.daemon.Display", "/com/deepin/daemon/Display", QDBusConnection::sessionBus(), this))
|
||||
, m_itemManager(DockItemManager::instance(this))
|
||||
, m_trashPluginShow(true)
|
||||
, m_isMouseMoveCause(false)
|
||||
, m_mouseCauseDockScreen(nullptr)
|
||||
{
|
||||
m_settingsMenu.setAccessibleName("settingsmenu");
|
||||
checkService();
|
||||
|
||||
onMonitorListChanged(m_displayInter->monitors());
|
||||
|
||||
m_primaryRawRect = m_displayInter->primaryRect();
|
||||
m_currentRawRect = m_primaryRawRect;
|
||||
m_screenRawHeight = m_displayInter->screenHeight();
|
||||
m_screenRawWidth = m_displayInter->screenWidth();
|
||||
m_position = Dock::Position(m_dockInter->position());
|
||||
m_displayMode = Dock::DisplayMode(m_dockInter->displayMode());
|
||||
m_hideMode = Dock::HideMode(m_dockInter->hideMode());
|
||||
m_hideState = Dock::HideState(m_dockInter->hideState());
|
||||
DockItem::setDockPosition(m_position);
|
||||
qApp->setProperty(PROP_POSITION, QVariant::fromValue(m_position));
|
||||
DockItem::setDockDisplayMode(m_displayMode);
|
||||
qApp->setProperty(PROP_DISPLAY_MODE, QVariant::fromValue(m_displayMode));
|
||||
|
||||
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);
|
||||
|
||||
QMenu *modeSubMenu = new QMenu(&m_settingsMenu);
|
||||
modeSubMenu->setAccessibleName("modesubmenu");
|
||||
modeSubMenu->addAction(&m_fashionModeAct);
|
||||
modeSubMenu->addAction(&m_efficientModeAct);
|
||||
QAction *modeSubMenuAct = new QAction(tr("Mode"), this);
|
||||
modeSubMenuAct->setMenu(modeSubMenu);
|
||||
|
||||
QMenu *locationSubMenu = new QMenu(&m_settingsMenu);
|
||||
locationSubMenu->setAccessibleName("locationsubmenu");
|
||||
locationSubMenu->addAction(&m_topPosAct);
|
||||
locationSubMenu->addAction(&m_bottomPosAct);
|
||||
locationSubMenu->addAction(&m_leftPosAct);
|
||||
locationSubMenu->addAction(&m_rightPosAct);
|
||||
QAction *locationSubMenuAct = new QAction(tr("Location"), this);
|
||||
locationSubMenuAct->setMenu(locationSubMenu);
|
||||
|
||||
QMenu *statusSubMenu = new QMenu(&m_settingsMenu);
|
||||
statusSubMenu->setAccessibleName("statussubmenu");
|
||||
statusSubMenu->addAction(&m_keepShownAct);
|
||||
statusSubMenu->addAction(&m_keepHiddenAct);
|
||||
statusSubMenu->addAction(&m_smartHideAct);
|
||||
QAction *statusSubMenuAct = new QAction(tr("Status"), this);
|
||||
statusSubMenuAct->setMenu(statusSubMenu);
|
||||
|
||||
m_hideSubMenu = new QMenu(&m_settingsMenu);
|
||||
m_hideSubMenu->setAccessibleName("pluginsmenu");
|
||||
QAction *hideSubMenuAct = new QAction(tr("Plugins"), this);
|
||||
hideSubMenuAct->setMenu(m_hideSubMenu);
|
||||
|
||||
m_settingsMenu.addAction(modeSubMenuAct);
|
||||
m_settingsMenu.addAction(locationSubMenuAct);
|
||||
m_settingsMenu.addAction(statusSubMenuAct);
|
||||
m_settingsMenu.addAction(hideSubMenuAct);
|
||||
m_settingsMenu.setTitle("Settings Menu");
|
||||
|
||||
connect(&m_settingsMenu, &QMenu::triggered, this, &DockSettings::menuActionClicked);
|
||||
connect(GSettingsByMenu(), &QGSettings::changed, this, &DockSettings::onGSettingsChanged);
|
||||
connect(m_dockInter, &DBusDock::PositionChanged, this, &DockSettings::onPositionChanged);
|
||||
connect(m_dockInter, &DBusDock::DisplayModeChanged, this, &DockSettings::onDisplayModeChanged);
|
||||
connect(m_dockInter, &DBusDock::HideModeChanged, this, &DockSettings::hideModeChanged, Qt::QueuedConnection);
|
||||
connect(m_dockInter, &DBusDock::HideStateChanged, this, &DockSettings::hideStateChanged);
|
||||
connect(m_dockInter, &DBusDock::ServiceRestarted, this, &DockSettings::resetFrontendGeometry);
|
||||
connect(m_dockInter, &DBusDock::OpacityChanged, this, &DockSettings::onOpacityChanged);
|
||||
connect(m_dockInter, &DBusDock::WindowSizeEfficientChanged, this, &DockSettings::onWindowSizeChanged);
|
||||
connect(m_dockInter, &DBusDock::WindowSizeFashionChanged, this, &DockSettings::onWindowSizeChanged);
|
||||
|
||||
connect(m_itemManager, &DockItemManager::itemInserted, this, &DockSettings::dockItemCountChanged, Qt::QueuedConnection);
|
||||
connect(m_itemManager, &DockItemManager::itemRemoved, this, &DockSettings::dockItemCountChanged, Qt::QueuedConnection);
|
||||
connect(m_itemManager, &DockItemManager::trayVisableCountChanged, this, &DockSettings::trayVisableCountChanged, Qt::QueuedConnection);
|
||||
|
||||
connect(m_displayInter, &DisplayInter::PrimaryRectChanged, this, &DockSettings::onPrimaryScreenChanged, Qt::QueuedConnection);
|
||||
connect(m_displayInter, &DisplayInter::ScreenHeightChanged, this, &DockSettings::onPrimaryScreenChanged, Qt::QueuedConnection);
|
||||
connect(m_displayInter, &DisplayInter::ScreenWidthChanged, this, &DockSettings::onPrimaryScreenChanged, Qt::QueuedConnection);
|
||||
connect(m_displayInter, &DisplayInter::PrimaryChanged, this, &DockSettings::onPrimaryScreenChanged, Qt::QueuedConnection);
|
||||
connect(m_displayInter, &DisplayInter::MonitorsChanged, this, &DockSettings::onMonitorListChanged);
|
||||
connect(GSettingsByTrash(), &QGSettings::changed, this, &DockSettings::onTrashGSettingsChanged);
|
||||
QTimer::singleShot(0, this, [ = ] {onGSettingsChanged("enable");});
|
||||
|
||||
DApplication *app = qobject_cast<DApplication *>(qApp);
|
||||
if (app) {
|
||||
connect(app, &DApplication::iconThemeChanged, this, &DockSettings::gtkIconThemeChanged);
|
||||
}
|
||||
|
||||
calculateMultiScreensPos();
|
||||
calculateWindowConfig();
|
||||
resetFrontendGeometry();
|
||||
|
||||
QTimer::singleShot(0, this, [ = ] {onOpacityChanged(m_dockInter->opacity());});
|
||||
QTimer::singleShot(0, this, [ = ] {
|
||||
onGSettingsChanged("enable");
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
DockSettings &DockSettings::Instance()
|
||||
{
|
||||
static DockSettings settings;
|
||||
return settings;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const QRect DockSettings::currentRect(const bool beNarrow)
|
||||
{
|
||||
QRect rect;
|
||||
QString currentScrName;
|
||||
if (!beNarrow) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_currentScreen = currentScrName;
|
||||
m_currentRawRect = rect;
|
||||
|
||||
} else {
|
||||
rect = m_currentRawRect;
|
||||
}
|
||||
|
||||
qreal scale = qApp->primaryScreen()->devicePixelRatio();
|
||||
rect.setWidth(std::round(qreal(rect.width()) / scale));
|
||||
rect.setHeight(std::round(qreal(rect.height()) / scale));
|
||||
return rect;
|
||||
}
|
||||
|
||||
const int DockSettings::dockMargin() const
|
||||
{
|
||||
if (m_displayMode == Dock::Efficient)
|
||||
return 0;
|
||||
|
||||
return 10;
|
||||
}
|
||||
|
||||
//const QSize DockSettings::panelSize() const
|
||||
//{
|
||||
// return m_mainWindowSize;
|
||||
//}
|
||||
|
||||
const QRect DockSettings::windowRect(const Position position, const bool hide, const bool beNarrow)
|
||||
{
|
||||
QSize size = m_mainWindowSize;
|
||||
if (hide) {
|
||||
switch (position) {
|
||||
case Top:
|
||||
case Bottom: size.setHeight(0); break;
|
||||
case Left:
|
||||
case Right: size.setWidth(0); break;
|
||||
}
|
||||
}
|
||||
|
||||
const QRect primaryRect = this->currentRect(beNarrow);
|
||||
const int offsetX = (primaryRect.width() - size.width()) / 2;
|
||||
const int offsetY = (primaryRect.height() - size.height()) / 2;
|
||||
int margin = hide ? 0 : this->dockMargin();
|
||||
QPoint p(0, 0);
|
||||
switch (position) {
|
||||
case Top:
|
||||
p = QPoint(offsetX, margin);
|
||||
break;
|
||||
case Left:
|
||||
p = QPoint(margin, offsetY);
|
||||
break;
|
||||
case Right:
|
||||
p = QPoint(primaryRect.width() - size.width() - margin, offsetY);
|
||||
break;
|
||||
case Bottom:
|
||||
p = QPoint(offsetX, primaryRect.height() - size.height() - margin);
|
||||
break;
|
||||
}
|
||||
|
||||
return QRect(primaryRect.topLeft() + p, size);
|
||||
}
|
||||
|
||||
void DockSettings::showDockSettingsMenu()
|
||||
{
|
||||
QTimer::singleShot(0, this, [ = ] {
|
||||
onGSettingsChanged("enable");
|
||||
});
|
||||
|
||||
m_autoHide = false;
|
||||
|
||||
bool hasComposite = DWindowManagerHelper::instance()->hasComposite();
|
||||
|
||||
// create actions
|
||||
QList<QAction *> actions;
|
||||
for (auto *p : m_itemManager->pluginList()) {
|
||||
if (!p->pluginIsAllowDisable())
|
||||
continue;
|
||||
|
||||
const bool enable = !p->pluginIsDisable();
|
||||
const QString &name = p->pluginName();
|
||||
const QString &display = p->pluginDisplayName();
|
||||
|
||||
if (!m_trashPluginShow && name == "trash") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (name == "multitasking" && !hasComposite) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QAction *act = new QAction(display, this);
|
||||
act->setCheckable(true);
|
||||
act->setChecked(enable);
|
||||
act->setData(name);
|
||||
|
||||
actions << act;
|
||||
}
|
||||
|
||||
// sort by name
|
||||
std::sort(actions.begin(), actions.end(), [](QAction * a, QAction * b) -> bool {
|
||||
return a->data().toString() > b->data().toString();
|
||||
});
|
||||
|
||||
// add actions
|
||||
qDeleteAll(m_hideSubMenu->actions());
|
||||
for (auto act : actions)
|
||||
m_hideSubMenu->addAction(act);
|
||||
|
||||
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);
|
||||
|
||||
m_settingsMenu.exec(QCursor::pos());
|
||||
|
||||
setAutoHide(true);
|
||||
}
|
||||
|
||||
void DockSettings::updateGeometry()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DockSettings::setAutoHide(const bool autoHide)
|
||||
{
|
||||
if (m_autoHide == autoHide)
|
||||
return;
|
||||
|
||||
m_autoHide = autoHide;
|
||||
emit autoHideChanged(m_autoHide);
|
||||
}
|
||||
|
||||
void DockSettings::menuActionClicked(QAction *action)
|
||||
{
|
||||
Q_ASSERT(action);
|
||||
|
||||
if (action == &m_fashionModeAct)
|
||||
return m_dockInter->setDisplayMode(Fashion);
|
||||
if (action == &m_efficientModeAct)
|
||||
return m_dockInter->setDisplayMode(Efficient);
|
||||
|
||||
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);
|
||||
|
||||
// check plugin hide menu.
|
||||
const QString &data = action->data().toString();
|
||||
if (data.isEmpty())
|
||||
return;
|
||||
for (auto *p : m_itemManager->pluginList()) {
|
||||
if (p->pluginName() == data)
|
||||
return p->pluginStateSwitched();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
void DockSettings::onPositionChanged()
|
||||
{
|
||||
const Position nextPos = Dock::Position(m_dockInter->position());
|
||||
|
||||
if (m_position == nextPos)
|
||||
return;
|
||||
m_position = nextPos;
|
||||
|
||||
m_isMouseMoveCause = false;
|
||||
// 位置改变 重新计算可停靠任务栏的位置
|
||||
calculateMultiScreensPos();
|
||||
|
||||
// 通知主窗口改变位置
|
||||
emit positionChanged();
|
||||
}
|
||||
|
||||
void DockSettings::onDisplayModeChanged()
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO;
|
||||
m_displayMode = Dock::DisplayMode(m_dockInter->displayMode());
|
||||
DockItem::setDockDisplayMode(m_displayMode);
|
||||
qApp->setProperty(PROP_DISPLAY_MODE, QVariant::fromValue(m_displayMode));
|
||||
|
||||
emit displayModeChanegd();
|
||||
calculateWindowConfig();
|
||||
|
||||
//QTimer::singleShot(1, m_itemManager, &DockItemManager::sortPluginItems);
|
||||
}
|
||||
|
||||
void DockSettings::hideModeChanged()
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO;
|
||||
m_hideMode = Dock::HideMode(m_dockInter->hideMode());
|
||||
|
||||
emit windowHideModeChanged();
|
||||
}
|
||||
|
||||
void DockSettings::hideStateChanged()
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO;
|
||||
const Dock::HideState state = Dock::HideState(m_dockInter->hideState());
|
||||
|
||||
if (state == Dock::Unknown)
|
||||
return;
|
||||
|
||||
m_hideState = state;
|
||||
|
||||
emit windowVisibleChanged();
|
||||
}
|
||||
|
||||
void DockSettings::dockItemCountChanged()
|
||||
{
|
||||
// emit windowGeometryChanged();
|
||||
}
|
||||
|
||||
void DockSettings::onPrimaryScreenChanged()
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO;
|
||||
m_primaryRawRect = m_displayInter->primaryRect();
|
||||
m_screenRawHeight = m_displayInter->screenHeight();
|
||||
m_screenRawWidth = m_displayInter->screenWidth();
|
||||
|
||||
//为了防止当后端发送错误值,然后发送正确值时,任务栏没有移动在相应的位置
|
||||
//当qt没有获取到屏幕资源时候,move函数会失效。可以直接return
|
||||
if (m_screenRawHeight == 0 || m_screenRawWidth == 0) {
|
||||
return;
|
||||
}
|
||||
calculateMultiScreensPos();
|
||||
emit primaryScreenChanged();
|
||||
calculateWindowConfig();
|
||||
|
||||
// 主屏切换时,如果缩放比例不一样,需要刷新item的图标(bug:3176)
|
||||
m_itemManager->refershItemsIcon();
|
||||
}
|
||||
|
||||
void DockSettings::resetFrontendGeometry()
|
||||
{
|
||||
const QRect r = windowRect(m_position);
|
||||
const qreal ratio = dockRatio();
|
||||
const QPoint p = rawXPosition(r.topLeft());
|
||||
const uint w = r.width() * ratio;
|
||||
const uint h = r.height() * ratio;
|
||||
|
||||
m_frontendRect = QRect(p.x(), p.y(), w, h);
|
||||
m_dockInter->SetFrontendWindowRect(p.x(), p.y(), w, h);
|
||||
}
|
||||
|
||||
void DockSettings::updateFrontendGeometry()
|
||||
{
|
||||
resetFrontendGeometry();
|
||||
}
|
||||
|
||||
bool DockSettings::setDockScreen(const QString &scrName)
|
||||
{
|
||||
QList<Monitor *> monitors = m_monitors.keys();
|
||||
for (Monitor *monitor : monitors) {
|
||||
if (monitor && monitor->name() == scrName) {
|
||||
m_mouseCauseDockScreen = monitor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool canBeDock = false;
|
||||
switch (m_position) {
|
||||
case Top:
|
||||
canBeDock = m_mouseCauseDockScreen->dockPosition().topDock;
|
||||
break;
|
||||
case Right:
|
||||
canBeDock = m_mouseCauseDockScreen->dockPosition().rightDock;
|
||||
break;
|
||||
case Bottom:
|
||||
canBeDock = m_mouseCauseDockScreen->dockPosition().bottomDock;
|
||||
break;
|
||||
case Left:
|
||||
canBeDock = m_mouseCauseDockScreen->dockPosition().leftDock;
|
||||
break;
|
||||
}
|
||||
m_isMouseMoveCause = canBeDock;
|
||||
|
||||
posChangedUpdateSettings();
|
||||
|
||||
return canBeDock;
|
||||
}
|
||||
|
||||
void DockSettings::onOpacityChanged(const double value)
|
||||
{
|
||||
if (m_opacity == value) return;
|
||||
|
||||
m_opacity = value;
|
||||
|
||||
emit opacityChanged(value * 255);
|
||||
}
|
||||
|
||||
void DockSettings::trayVisableCountChanged(const int &count)
|
||||
{
|
||||
emit trayCountChanged();
|
||||
}
|
||||
|
||||
void DockSettings::calculateWindowConfig()
|
||||
{
|
||||
if (m_displayMode == Dock::Efficient) {
|
||||
m_dockWindowSize = int(m_dockInter->windowSizeEfficient());
|
||||
if (m_dockWindowSize > WINDOW_MAX_SIZE || m_dockWindowSize < WINDOW_MIN_SIZE) {
|
||||
m_dockWindowSize = EffICIENT_DEFAULT_HEIGHT;
|
||||
m_dockInter->setWindowSize(EffICIENT_DEFAULT_HEIGHT);
|
||||
}
|
||||
|
||||
switch (m_position) {
|
||||
case Top:
|
||||
case Bottom:
|
||||
m_mainWindowSize.setHeight(m_dockWindowSize);
|
||||
m_mainWindowSize.setWidth(currentRect().width());
|
||||
break;
|
||||
|
||||
case Left:
|
||||
case Right:
|
||||
m_mainWindowSize.setHeight(currentRect().height());
|
||||
m_mainWindowSize.setWidth(m_dockWindowSize);
|
||||
break;
|
||||
}
|
||||
} else if (m_displayMode == Dock::Fashion) {
|
||||
m_dockWindowSize = int(m_dockInter->windowSizeFashion());
|
||||
if (m_dockWindowSize > WINDOW_MAX_SIZE || m_dockWindowSize < WINDOW_MIN_SIZE) {
|
||||
m_dockWindowSize = FASHION_DEFAULT_HEIGHT;
|
||||
m_dockInter->setWindowSize(FASHION_DEFAULT_HEIGHT);
|
||||
}
|
||||
|
||||
switch (m_position) {
|
||||
case Top:
|
||||
case Bottom: {
|
||||
m_mainWindowSize.setHeight(m_dockWindowSize);
|
||||
m_mainWindowSize.setWidth(this->currentRect().width() - MAINWINDOW_MARGIN * 2);
|
||||
break;
|
||||
}
|
||||
case Left:
|
||||
case Right: {
|
||||
m_mainWindowSize.setHeight(this->currentRect().height() - MAINWINDOW_MARGIN * 2);
|
||||
m_mainWindowSize.setWidth(m_dockWindowSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
|
||||
resetFrontendGeometry();
|
||||
}
|
||||
|
||||
void DockSettings::gtkIconThemeChanged()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
m_itemManager->refershItemsIcon();
|
||||
}
|
||||
|
||||
qreal DockSettings::dockRatio() const
|
||||
{
|
||||
QScreen const *screen = Utils::screenAtByScaled(m_frontendRect.center());
|
||||
|
||||
return screen ? screen->devicePixelRatio() : qApp->devicePixelRatio();
|
||||
}
|
||||
|
||||
void DockSettings::onWindowSizeChanged()
|
||||
{
|
||||
calculateWindowConfig();
|
||||
emit windowGeometryChanged();
|
||||
}
|
||||
|
||||
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) {
|
||||
Q_UNUSED(oldOwner)
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void DockSettings::posChangedUpdateSettings()
|
||||
{
|
||||
DockItem::setDockPosition(m_position);
|
||||
qApp->setProperty(PROP_POSITION, QVariant::fromValue(m_position));
|
||||
|
||||
calculateWindowConfig();
|
||||
|
||||
m_itemManager->refershItemsIcon();
|
||||
}
|
||||
|
||||
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(mon, &Monitor::geometryChanged, this, [ = ] {
|
||||
calculateWindowConfig();
|
||||
emit windowGeometryChanged();
|
||||
emit requestUpdateRegionWatch();
|
||||
});
|
||||
|
||||
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;
|
||||
// 左右拼
|
||||
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) {
|
||||
s1->dockPosition().rightDock = false;
|
||||
s2->dockPosition().leftDock = false;
|
||||
}
|
||||
}
|
||||
// s1右 s2左
|
||||
if (s1->left() == s2->right()) {
|
||||
isAligment = (s1->topLeft() == s2->topRight())
|
||||
&& (s1->bottomLeft() == s2->bottomRight());
|
||||
if (isAligment) {
|
||||
s1->dockPosition().leftDock = false;
|
||||
s2->dockPosition().rightDock = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 上下拼
|
||||
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) {
|
||||
s1->dockPosition().bottomDock = false;
|
||||
s2->dockPosition().topDock = false;
|
||||
}
|
||||
}
|
||||
// s1下 s2上
|
||||
if (s1->top() == s2->bottom()) {
|
||||
isAligment = (s1->topLeft() == s2->bottomLeft())
|
||||
&& (s1->topRight() == s2->bottomRight());
|
||||
if (isAligment) {
|
||||
s1->dockPosition().topDock = false;
|
||||
s2->dockPosition().bottomDock = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 对角拼
|
||||
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);
|
||||
if (s1->isPrimary())
|
||||
s2->setDockPosition(position);
|
||||
if (s2->isPrimary())
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
QMapIterator<Monitor *, MonitorInter *> iterator(m_monitors);
|
||||
while (iterator.hasNext()) {
|
||||
iterator.next();
|
||||
Monitor *monitor = iterator.key();
|
||||
if (monitor) {
|
||||
m_mouseCauseDockScreen = monitor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,173 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: sbw <sbw@sbw.so>
|
||||
*
|
||||
* Maintainer: sbw <sbw@sbw.so>
|
||||
* zhaolong <zhaolong@uniontech.com>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef DOCKSETTINGS_H
|
||||
#define DOCKSETTINGS_H
|
||||
|
||||
#include "constants.h"
|
||||
#include "monitor.h"
|
||||
|
||||
#include <com_deepin_dde_daemon_dock.h>
|
||||
#include <com_deepin_daemon_display.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
|
||||
#include <QObject>
|
||||
#include <QSize>
|
||||
|
||||
using namespace Dock;
|
||||
using DBusDock = com::deepin::dde::daemon::Dock;
|
||||
using DisplayInter = com::deepin::daemon::Display;
|
||||
|
||||
class DockItemManager;
|
||||
class DockSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static DockSettings &Instance();
|
||||
|
||||
inline DisplayMode displayMode() const { return m_displayMode; }
|
||||
inline HideMode hideMode() const { return m_hideMode; }
|
||||
inline HideState hideState() const { return m_hideState; }
|
||||
inline Position position() const { return m_position; }
|
||||
inline int screenRawHeight() const { return m_screenRawHeight; }
|
||||
inline int screenRawWidth() const { return m_screenRawWidth; }
|
||||
inline int expandTimeout() const { return m_dockInter->showTimeout(); }
|
||||
inline int narrowTimeout() const { return 100; }
|
||||
inline bool autoHide() const { return m_autoHide; }
|
||||
const QRect primaryRect() const;
|
||||
const QRect currentRect(const bool beNarrow = false);
|
||||
const QList<QRect> monitorsRect() const;
|
||||
inline const QRect primaryRawRect() const { return m_primaryRawRect; }
|
||||
inline const QRect currentRawRect() const { return m_currentRawRect; }
|
||||
inline const QRect frontendWindowRect() const { return m_frontendRect; }
|
||||
inline const QSize windowSize() const { return m_mainWindowSize; }
|
||||
inline const quint8 Opacity() const { return m_opacity * 255; }
|
||||
const int dockMargin() const;
|
||||
|
||||
// const QSize panelSize() const;
|
||||
const QRect windowRect(const Position position, const bool hide = false, const bool beNarrow = false);
|
||||
qreal dockRatio() const;
|
||||
|
||||
void showDockSettingsMenu();
|
||||
void updateFrontendGeometry();
|
||||
|
||||
bool setDockScreen(const QString &scrName);
|
||||
QString ¤tDockScreen() { return m_currentScreen; }
|
||||
|
||||
void posChangedUpdateSettings();
|
||||
void calculateWindowConfig();
|
||||
|
||||
QSize m_mainWindowSize;
|
||||
DBusDock *m_dockInter;
|
||||
bool m_menuVisible;
|
||||
|
||||
signals:
|
||||
void primaryScreenChanged() const;
|
||||
void positionChanged() const;
|
||||
void autoHideChanged(const bool autoHide) const;
|
||||
void displayModeChanegd() const;
|
||||
void windowVisibleChanged() const;
|
||||
void windowHideModeChanged() const;
|
||||
void windowGeometryChanged() const;
|
||||
void opacityChanged(const quint8 value) const;
|
||||
void trayCountChanged() const;
|
||||
// 分标率发生变化,需要更新XEventMonitor的监视区域
|
||||
void requestUpdateRegionWatch();
|
||||
|
||||
public slots:
|
||||
void updateGeometry();
|
||||
void setAutoHide(const bool autoHide);
|
||||
|
||||
private slots:
|
||||
void menuActionClicked(QAction *action);
|
||||
void onGSettingsChanged(const QString &key);
|
||||
void onPositionChanged();
|
||||
void onDisplayModeChanged();
|
||||
void hideModeChanged();
|
||||
void hideStateChanged();
|
||||
void dockItemCountChanged();
|
||||
void onPrimaryScreenChanged();
|
||||
void resetFrontendGeometry();
|
||||
void onOpacityChanged(const double value);
|
||||
void trayVisableCountChanged(const int &count);
|
||||
void onWindowSizeChanged();
|
||||
void onTrashGSettingsChanged(const QString &key);
|
||||
void onMonitorListChanged(const QList<QDBusObjectPath> &mons);
|
||||
|
||||
private:
|
||||
explicit DockSettings(QWidget *parent = nullptr);
|
||||
DockSettings(DockSettings const &) = delete;
|
||||
DockSettings operator =(DockSettings const &) = delete;
|
||||
|
||||
void gtkIconThemeChanged();
|
||||
void checkService();
|
||||
|
||||
void calculateMultiScreensPos();
|
||||
void monitorAdded(const QString &path);
|
||||
void monitorRemoved(const QString &path);
|
||||
void twoScreensCalPos();
|
||||
void treeScreensCalPos();
|
||||
void combination(QList<Monitor*> &screens);
|
||||
void calculateRelativePos(Monitor *s1, Monitor *s2);
|
||||
|
||||
private:
|
||||
int m_dockWindowSize;
|
||||
bool m_autoHide;
|
||||
int m_screenRawHeight;
|
||||
int m_screenRawWidth;
|
||||
double m_opacity;
|
||||
int m_dockMargin;
|
||||
QSet<Position> m_forbidPositions;
|
||||
Position m_position;
|
||||
HideMode m_hideMode;
|
||||
HideState m_hideState;
|
||||
DisplayMode m_displayMode;
|
||||
QRect m_primaryRawRect;
|
||||
QRect m_currentRawRect;
|
||||
QRect m_frontendRect;
|
||||
|
||||
QMenu m_settingsMenu;
|
||||
QMenu *m_hideSubMenu;
|
||||
QAction m_fashionModeAct;
|
||||
QAction m_efficientModeAct;
|
||||
QAction m_topPosAct;
|
||||
QAction m_bottomPosAct;
|
||||
QAction m_leftPosAct;
|
||||
QAction m_rightPosAct;
|
||||
QAction m_keepShownAct;
|
||||
QAction m_keepHiddenAct;
|
||||
QAction m_smartHideAct;
|
||||
|
||||
DisplayInter *m_displayInter;
|
||||
DockItemManager *m_itemManager;
|
||||
bool m_trashPluginShow;
|
||||
|
||||
QMap<Monitor *, MonitorInter *> m_monitors;
|
||||
bool m_isMouseMoveCause;
|
||||
Monitor *m_mouseCauseDockScreen;
|
||||
QString m_currentScreen;
|
||||
};
|
||||
|
||||
#endif // DOCKSETTINGS_H
|
287
frame/util/menuworker.cpp
Normal file
287
frame/util/menuworker.cpp
Normal file
@ -0,0 +1,287 @@
|
||||
/*
|
||||
* Copyright (C) 2018 ~ 2028 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: fanpengcheng <fanpengcheng_cm@deepin.com>
|
||||
*
|
||||
* Maintainer: fanpengcheng <fanpengcheng_cm@deepin.com>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#include "menuworker.h"
|
||||
#include "controller/dockitemmanager.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QGSettings>
|
||||
|
||||
#include <DApplication>
|
||||
|
||||
static QGSettings *GSettingsByMenu()
|
||||
{
|
||||
static QGSettings settings("com.deepin.dde.dock.module.menu");
|
||||
return &settings;
|
||||
}
|
||||
|
||||
static QGSettings *GSettingsByTrash()
|
||||
{
|
||||
static QGSettings settings("com.deepin.dde.dock.module.trash");
|
||||
return &settings;
|
||||
}
|
||||
|
||||
MenuWorker::MenuWorker(DBusDock *dockInter,QWidget *parent)
|
||||
: QObject (parent)
|
||||
, m_itemManager(DockItemManager::instance(this))
|
||||
, m_dockInter(dockInter)
|
||||
, m_settingsMenu(new QMenu)
|
||||
, m_fashionModeAct(new QAction(tr("Fashion Mode"), this))
|
||||
, m_efficientModeAct(new QAction(tr("Efficient Mode"), this))
|
||||
, m_topPosAct(new QAction(tr("Top"), this))
|
||||
, m_bottomPosAct(new QAction(tr("Bottom"), this))
|
||||
, m_leftPosAct(new QAction(tr("Left"), this))
|
||||
, m_rightPosAct(new QAction(tr("Right"), this))
|
||||
, m_keepShownAct(new QAction(tr("Keep Shown"), this))
|
||||
, m_keepHiddenAct(new QAction(tr("Keep Hidden"), this))
|
||||
, m_smartHideAct(new QAction(tr("Smart Hide"), this))
|
||||
, m_menuEnable(true)
|
||||
, m_autoHide(true)
|
||||
, m_trashPluginShow(true)
|
||||
, m_opacity(0.4)
|
||||
{
|
||||
initMember();
|
||||
initUI();
|
||||
initConnection();
|
||||
|
||||
QTimer::singleShot(0, this, [=] {onGSettingsChanged("enable");});
|
||||
}
|
||||
|
||||
MenuWorker::~MenuWorker()
|
||||
{
|
||||
delete m_settingsMenu;
|
||||
}
|
||||
|
||||
void MenuWorker::initMember()
|
||||
{
|
||||
m_settingsMenu->setAccessibleName("settingsmenu");
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void MenuWorker::initUI()
|
||||
{
|
||||
QMenu *modeSubMenu = new QMenu(m_settingsMenu);
|
||||
modeSubMenu->setAccessibleName("modesubmenu");
|
||||
modeSubMenu->addAction(m_fashionModeAct);
|
||||
modeSubMenu->addAction(m_efficientModeAct);
|
||||
QAction *modeSubMenuAct = new QAction(tr("Mode"), this);
|
||||
modeSubMenuAct->setMenu(modeSubMenu);
|
||||
|
||||
QMenu *locationSubMenu = new QMenu(m_settingsMenu);
|
||||
locationSubMenu->setAccessibleName("locationsubmenu");
|
||||
locationSubMenu->addAction(m_topPosAct);
|
||||
locationSubMenu->addAction(m_bottomPosAct);
|
||||
locationSubMenu->addAction(m_leftPosAct);
|
||||
locationSubMenu->addAction(m_rightPosAct);
|
||||
QAction *locationSubMenuAct = new QAction(tr("Location"), this);
|
||||
locationSubMenuAct->setMenu(locationSubMenu);
|
||||
|
||||
QMenu *statusSubMenu = new QMenu(m_settingsMenu);
|
||||
statusSubMenu->setAccessibleName("statussubmenu");
|
||||
statusSubMenu->addAction(m_keepShownAct);
|
||||
statusSubMenu->addAction(m_keepHiddenAct);
|
||||
statusSubMenu->addAction(m_smartHideAct);
|
||||
QAction *statusSubMenuAct = new QAction(tr("Status"), this);
|
||||
statusSubMenuAct->setMenu(statusSubMenu);
|
||||
|
||||
m_hideSubMenu = new QMenu(m_settingsMenu);
|
||||
m_hideSubMenu->setAccessibleName("pluginsmenu");
|
||||
QAction *hideSubMenuAct = new QAction(tr("Plugins"), this);
|
||||
hideSubMenuAct->setMenu(m_hideSubMenu);
|
||||
|
||||
m_settingsMenu->addAction(modeSubMenuAct);
|
||||
m_settingsMenu->addAction(locationSubMenuAct);
|
||||
m_settingsMenu->addAction(statusSubMenuAct);
|
||||
m_settingsMenu->addAction(hideSubMenuAct);
|
||||
m_settingsMenu->setTitle("Settings Menu");
|
||||
}
|
||||
|
||||
void MenuWorker::initConnection()
|
||||
{
|
||||
connect(m_settingsMenu, &QMenu::triggered, this, &MenuWorker::menuActionClicked);
|
||||
|
||||
connect(GSettingsByMenu(), &QGSettings::changed, this, &MenuWorker::onGSettingsChanged);
|
||||
connect(GSettingsByTrash(), &QGSettings::changed, this, &MenuWorker::onTrashGSettingsChanged);
|
||||
|
||||
connect(m_itemManager, &DockItemManager::trayVisableCountChanged, this, &MenuWorker::trayVisableCountChanged, Qt::QueuedConnection);
|
||||
|
||||
DApplication *app = qobject_cast<DApplication *>(qApp);
|
||||
if (app) {
|
||||
connect(app, &DApplication::iconThemeChanged, this, &MenuWorker::gtkIconThemeChanged);
|
||||
}
|
||||
}
|
||||
|
||||
void MenuWorker::showDockSettingsMenu()
|
||||
{
|
||||
QTimer::singleShot(0, this, [=] {
|
||||
onGSettingsChanged("enable");
|
||||
});
|
||||
|
||||
setAutoHide(false);
|
||||
|
||||
bool hasComposite = DWindowManagerHelper::instance()->hasComposite();
|
||||
|
||||
// create actions
|
||||
QList<QAction *> actions;
|
||||
for (auto *p : m_itemManager->pluginList()) {
|
||||
if (!p->pluginIsAllowDisable())
|
||||
continue;
|
||||
|
||||
const bool enable = !p->pluginIsDisable();
|
||||
const QString &name = p->pluginName();
|
||||
const QString &display = p->pluginDisplayName();
|
||||
|
||||
if (!m_trashPluginShow && name == "trash") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (name == "multitasking" && !hasComposite) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QAction *act = new QAction(display, this);
|
||||
act->setCheckable(true);
|
||||
act->setChecked(enable);
|
||||
act->setData(name);
|
||||
|
||||
actions << act;
|
||||
}
|
||||
|
||||
// sort by name
|
||||
std::sort(actions.begin(), actions.end(), [](QAction * a, QAction * b) -> bool {
|
||||
return a->data().toString() > b->data().toString();
|
||||
});
|
||||
|
||||
// add actions
|
||||
qDeleteAll(m_hideSubMenu->actions());
|
||||
for (auto act : actions)
|
||||
m_hideSubMenu->addAction(act);
|
||||
|
||||
const DisplayMode displayMode = static_cast<DisplayMode>(m_dockInter->displayMode());
|
||||
const Position position = static_cast<Position>(m_dockInter->position());
|
||||
const HideMode hideMode = static_cast<HideMode>(m_dockInter->hideMode());
|
||||
|
||||
m_fashionModeAct->setChecked(displayMode == Fashion);
|
||||
m_efficientModeAct->setChecked(displayMode == Efficient);
|
||||
m_topPosAct->setChecked(position == Top);
|
||||
m_bottomPosAct->setChecked(position == Bottom);
|
||||
m_leftPosAct->setChecked(position == Left);
|
||||
m_rightPosAct->setChecked(position == Right);
|
||||
m_keepShownAct->setChecked(hideMode == KeepShowing);
|
||||
m_keepHiddenAct->setChecked(hideMode == KeepHidden);
|
||||
m_smartHideAct->setChecked(hideMode == SmartHide);
|
||||
|
||||
m_settingsMenu->exec(QCursor::pos());
|
||||
|
||||
setAutoHide(true);
|
||||
}
|
||||
|
||||
void MenuWorker::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_menuEnable=isEnable && setting->get("enable").toBool();
|
||||
}
|
||||
}
|
||||
|
||||
void MenuWorker::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();
|
||||
}
|
||||
}
|
||||
|
||||
void MenuWorker::menuActionClicked(QAction *action)
|
||||
{
|
||||
Q_ASSERT(action);
|
||||
|
||||
if (action == m_fashionModeAct)
|
||||
return m_dockInter->setDisplayMode(DisplayMode::Fashion);
|
||||
if (action == m_efficientModeAct)
|
||||
return m_dockInter->setDisplayMode(Efficient);
|
||||
|
||||
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);
|
||||
|
||||
// check plugin hide menu.
|
||||
const QString &data = action->data().toString();
|
||||
if (data.isEmpty())
|
||||
return;
|
||||
for (auto *p : m_itemManager->pluginList()) {
|
||||
if (p->pluginName() == data)
|
||||
return p->pluginStateSwitched();
|
||||
}
|
||||
}
|
||||
|
||||
void MenuWorker::trayVisableCountChanged(const int &count)
|
||||
{
|
||||
Q_UNUSED(count);
|
||||
|
||||
emit trayCountChanged();
|
||||
}
|
||||
|
||||
void MenuWorker::gtkIconThemeChanged()
|
||||
{
|
||||
m_itemManager->refershItemsIcon();
|
||||
}
|
||||
|
||||
void MenuWorker::setAutoHide(const bool autoHide)
|
||||
{
|
||||
if (m_autoHide == autoHide)
|
||||
return;
|
||||
|
||||
m_autoHide = autoHide;
|
||||
emit autoHideChanged(m_autoHide);
|
||||
}
|
90
frame/util/menuworker.h
Normal file
90
frame/util/menuworker.h
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2018 ~ 2028 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: fanpengcheng <fanpengcheng_cm@deepin.com>
|
||||
*
|
||||
* Maintainer: fanpengcheng <fanpengcheng_cm@deepin.com>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#ifndef MENUWORKER_H
|
||||
#define MENUWORKER_H
|
||||
#include <QObject>
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
#include <com_deepin_dde_daemon_dock.h>
|
||||
|
||||
using DBusDock = com::deepin::dde::daemon::Dock;
|
||||
class QMenu;
|
||||
class QAction;
|
||||
class DockItemManager;
|
||||
/**
|
||||
* @brief The MenuWorker class 此类用于处理任务栏右键菜单的逻辑
|
||||
*/
|
||||
class MenuWorker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MenuWorker(DBusDock *dockInter,QWidget *parent = nullptr);
|
||||
~ MenuWorker();
|
||||
|
||||
void initMember();
|
||||
void initUI();
|
||||
void initConnection();
|
||||
|
||||
void showDockSettingsMenu();
|
||||
|
||||
inline bool menuEnable() const { return m_menuEnable; }
|
||||
inline quint8 Opacity() const { return quint8(m_opacity * 255); }
|
||||
|
||||
void onGSettingsChanged(const QString &key);
|
||||
// TODO 是否还有其他的插件未处理其gsettings配置,这里只是移植之前的代码
|
||||
void onTrashGSettingsChanged(const QString &key);
|
||||
|
||||
signals:
|
||||
void autoHideChanged(const bool autoHide) const;
|
||||
void trayCountChanged();
|
||||
|
||||
private slots:
|
||||
void menuActionClicked(QAction *action);
|
||||
void trayVisableCountChanged(const int &count);
|
||||
void gtkIconThemeChanged();
|
||||
|
||||
public slots:
|
||||
void setAutoHide(const bool autoHide);
|
||||
|
||||
private:
|
||||
DockItemManager *m_itemManager;
|
||||
DBusDock *m_dockInter;
|
||||
|
||||
QMenu *m_settingsMenu;
|
||||
QMenu *m_hideSubMenu;
|
||||
QAction *m_fashionModeAct;
|
||||
QAction *m_efficientModeAct;
|
||||
QAction *m_topPosAct;
|
||||
QAction *m_bottomPosAct;
|
||||
QAction *m_leftPosAct;
|
||||
QAction *m_rightPosAct;
|
||||
QAction *m_keepShownAct;
|
||||
QAction *m_keepHiddenAct;
|
||||
QAction *m_smartHideAct;
|
||||
|
||||
bool m_menuEnable;
|
||||
bool m_autoHide;
|
||||
bool m_trashPluginShow;
|
||||
double m_opacity;
|
||||
};
|
||||
|
||||
#endif // MENUWORKER_H
|
@ -25,19 +25,12 @@
|
||||
|
||||
#include "monitor.h"
|
||||
|
||||
const double DoubleZero = 0.000001;
|
||||
|
||||
Monitor::Monitor(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_x(0)
|
||||
, m_y(0)
|
||||
, m_w(0)
|
||||
, m_h(0)
|
||||
, m_mmWidth(0)
|
||||
, m_mmHeight(0)
|
||||
, m_scale(-1.0)
|
||||
, m_rotate(0)
|
||||
// , m_brightness(1.0)
|
||||
, m_enable(false)
|
||||
{
|
||||
|
||||
@ -50,7 +43,6 @@ void Monitor::setX(const int x)
|
||||
|
||||
m_x = x;
|
||||
|
||||
Q_EMIT xChanged(m_x);
|
||||
Q_EMIT geometryChanged();
|
||||
}
|
||||
|
||||
@ -61,7 +53,6 @@ void Monitor::setY(const int y)
|
||||
|
||||
m_y = y;
|
||||
|
||||
Q_EMIT yChanged(m_y);
|
||||
Q_EMIT geometryChanged();
|
||||
}
|
||||
|
||||
@ -72,7 +63,6 @@ void Monitor::setW(const int w)
|
||||
|
||||
m_w = w;
|
||||
|
||||
Q_EMIT wChanged(m_w);
|
||||
Q_EMIT geometryChanged();
|
||||
}
|
||||
|
||||
@ -83,57 +73,12 @@ void Monitor::setH(const int h)
|
||||
|
||||
m_h = h;
|
||||
|
||||
Q_EMIT hChanged(m_h);
|
||||
Q_EMIT geometryChanged();
|
||||
}
|
||||
|
||||
void Monitor::setMmWidth(const uint mmWidth)
|
||||
{
|
||||
m_mmWidth = mmWidth;
|
||||
}
|
||||
|
||||
void Monitor::setMmHeight(const uint mmHeight)
|
||||
{
|
||||
m_mmHeight = mmHeight;
|
||||
}
|
||||
|
||||
void Monitor::setScale(const double scale)
|
||||
{
|
||||
if (fabs(m_scale - scale) < DoubleZero)
|
||||
return;
|
||||
|
||||
m_scale = scale;
|
||||
|
||||
Q_EMIT scaleChanged(m_scale);
|
||||
}
|
||||
|
||||
void Monitor::setPrimary(const QString &primaryName)
|
||||
{
|
||||
m_primary = primaryName;
|
||||
}
|
||||
|
||||
void Monitor::setRotate(const quint16 rotate)
|
||||
{
|
||||
if (m_rotate == rotate)
|
||||
return;
|
||||
|
||||
m_rotate = rotate;
|
||||
|
||||
Q_EMIT rotateChanged(m_rotate);
|
||||
}
|
||||
|
||||
//void Monitor::setBrightness(const double brightness)
|
||||
//{
|
||||
// if (fabs(m_brightness - brightness) < DoubleZero)
|
||||
// return;
|
||||
|
||||
// m_brightness = brightness;
|
||||
|
||||
// Q_EMIT brightnessChanged(m_brightness);
|
||||
//}
|
||||
|
||||
void Monitor::setName(const QString &name)
|
||||
{
|
||||
qDebug() << "screen name change from :" << m_name << " to: " << name;
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
@ -142,21 +87,6 @@ void Monitor::setPath(const QString &path)
|
||||
m_path = path;
|
||||
}
|
||||
|
||||
void Monitor::setRotateList(const QList<quint16> &rotateList)
|
||||
{
|
||||
m_rotateList = rotateList;
|
||||
}
|
||||
|
||||
void Monitor::setCurrentMode(const Resolution &resolution)
|
||||
{
|
||||
if (m_currentMode == resolution)
|
||||
return;
|
||||
|
||||
m_currentMode = resolution;
|
||||
|
||||
Q_EMIT currentModeChanged(m_currentMode);
|
||||
}
|
||||
|
||||
bool compareResolution(const Resolution &first, const Resolution &second)
|
||||
{
|
||||
long firstSum = long(first.width()) * first.height();
|
||||
@ -173,22 +103,6 @@ bool compareResolution(const Resolution &first, const Resolution &second)
|
||||
|
||||
}
|
||||
|
||||
void Monitor::setModeList(const ResolutionList &modeList)
|
||||
{
|
||||
m_modeList.clear();
|
||||
|
||||
Resolution preResolution;
|
||||
// NOTE: ignore resolution less than 1024x768
|
||||
for (auto m : modeList) {
|
||||
if (m.width() >= 1024 && m.height() >= 768) {
|
||||
m_modeList.append(m);
|
||||
}
|
||||
}
|
||||
qSort(m_modeList.begin(), m_modeList.end(), compareResolution);
|
||||
|
||||
Q_EMIT modelListChanged(m_modeList);
|
||||
}
|
||||
|
||||
void Monitor::setMonitorEnable(bool enable)
|
||||
{
|
||||
if (m_enable == enable)
|
||||
@ -197,37 +111,3 @@ void Monitor::setMonitorEnable(bool enable)
|
||||
m_enable = enable;
|
||||
Q_EMIT enableChanged(enable);
|
||||
}
|
||||
|
||||
//bool Monitor::isSameResolution(const Resolution &r1, const Resolution &r2)
|
||||
//{
|
||||
// return r1.width() == r2.width() && r1.height() == r2.height();
|
||||
//}
|
||||
|
||||
//bool Monitor::isSameRatefresh(const Resolution &r1, const Resolution &r2)
|
||||
//{
|
||||
// return fabs(r1.rate() - r2.rate()) < 0.000001;
|
||||
//}
|
||||
|
||||
//bool Monitor::hasResolution(const Resolution &r)
|
||||
//{
|
||||
// for (auto m : m_modeList) {
|
||||
// if (isSameResolution(m, r)) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return false;
|
||||
//}
|
||||
|
||||
//bool Monitor::hasResolutionAndRate(const Resolution &r)
|
||||
//{
|
||||
// for (auto m : m_modeList) {
|
||||
// if (fabs(m.rate() - r.rate()) < 0.000001 &&
|
||||
// m.width() == r.width() &&
|
||||
// m.height() == r.height()) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return false;
|
||||
//}
|
||||
|
@ -25,13 +25,15 @@
|
||||
|
||||
#ifndef MONITOR_H
|
||||
#define MONITOR_H
|
||||
#include "constants.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
|
||||
#include <com_deepin_daemon_display_monitor.h>
|
||||
|
||||
using MonitorInter = com::deepin::daemon::display::Monitor;
|
||||
|
||||
using namespace Dock;
|
||||
class Monitor : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -42,12 +44,37 @@ public:
|
||||
bool topDock = true;
|
||||
bool rightDock = true;
|
||||
bool bottomDock = true;
|
||||
DockPosition(bool l = true, bool t = true, bool r = true, bool b = true) {
|
||||
DockPosition(bool l = true, bool t = true, bool r = true, bool b = true)
|
||||
{
|
||||
qDebug() << leftDock << topDock << rightDock << bottomDock;
|
||||
leftDock = l;
|
||||
topDock = t;
|
||||
rightDock = r;
|
||||
bottomDock = b;
|
||||
}
|
||||
|
||||
bool docked(const Position &pos)
|
||||
{
|
||||
switch (pos) {
|
||||
case Position::Top:
|
||||
return topDock;
|
||||
case Position::Bottom:
|
||||
return bottomDock;
|
||||
case Position::Left:
|
||||
return leftDock;
|
||||
case Position::Right:
|
||||
return rightDock;
|
||||
}
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
leftDock = true;
|
||||
topDock = true;
|
||||
rightDock = true;
|
||||
bottomDock = true;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
@ -65,57 +92,26 @@ public:
|
||||
inline QPoint topRight() const { return QPoint(m_x + m_w, m_y); }
|
||||
inline QPoint bottomLeft() const { return QPoint(m_x, m_y + m_h); }
|
||||
inline QPoint bottomRight() const { return QPoint(m_x + m_w, m_y + m_h); }
|
||||
inline uint mmWidth() const { return m_mmWidth; }
|
||||
inline uint mmHeight() const { return m_mmHeight; }
|
||||
inline double scale() const { return m_scale; }
|
||||
inline bool isPrimary() const { return m_primary == m_name; }
|
||||
inline quint16 rotate() const { return m_rotate; }
|
||||
// inline double brightness() const { return m_brightness; }
|
||||
inline const QRect rect() const { return QRect(m_x, m_y, m_w, m_h); }
|
||||
|
||||
inline const QString name() const { Q_ASSERT(!m_name.isEmpty()); return m_name; }
|
||||
inline const QString path() const { return m_path; }
|
||||
inline const Resolution currentMode() const { return m_currentMode; }
|
||||
inline const QList<quint16> rotateList() const { return m_rotateList; }
|
||||
inline const QList<Resolution> modeList() const { return m_modeList; }
|
||||
inline bool enable() const { return m_enable; }
|
||||
|
||||
inline void setDockPosition(const DockPosition &position) { m_dockPosition = position; }
|
||||
inline DockPosition &dockPosition() { return m_dockPosition; }
|
||||
|
||||
Q_SIGNALS:
|
||||
void geometryChanged() const;
|
||||
void xChanged(const int x) const;
|
||||
void yChanged(const int y) const;
|
||||
void wChanged(const int w) const;
|
||||
void hChanged(const int h) const;
|
||||
void scaleChanged(const double scale) const;
|
||||
void rotateChanged(const quint16 rotate) const;
|
||||
// void brightnessChanged(const double brightness) const;
|
||||
void currentModeChanged(const Resolution &resolution) const;
|
||||
void modelListChanged(const QList<Resolution> &resolution) const;
|
||||
void enableChanged(bool enable) const;
|
||||
|
||||
//public:
|
||||
// static bool isSameResolution(const Resolution &r1,const Resolution &r2);
|
||||
// static bool isSameRatefresh(const Resolution &r1,const Resolution &r2);
|
||||
// bool hasResolution(const Resolution &r);
|
||||
// bool hasResolutionAndRate(const Resolution &r);
|
||||
|
||||
public Q_SLOTS:
|
||||
void setX(const int x);
|
||||
void setY(const int y);
|
||||
void setW(const int w);
|
||||
void setH(const int h);
|
||||
void setMmWidth(const uint mmWidth);
|
||||
void setMmHeight(const uint mmHeight);
|
||||
void setScale(const double scale);
|
||||
void setPrimary(const QString &primaryName);
|
||||
void setRotate(const quint16 rotate);
|
||||
// void setBrightness(const double brightness);
|
||||
void setName(const QString &name);
|
||||
void setPath(const QString &path);
|
||||
void setRotateList(const QList<quint16> &rotateList);
|
||||
void setCurrentMode(const Resolution &resolution);
|
||||
void setModeList(const ResolutionList &modeList);
|
||||
void setMonitorEnable(bool enable);
|
||||
|
||||
private:
|
||||
@ -123,20 +119,10 @@ private:
|
||||
int m_y;
|
||||
int m_w;
|
||||
int m_h;
|
||||
uint m_mmWidth;
|
||||
uint m_mmHeight;
|
||||
double m_scale;
|
||||
quint16 m_rotate;
|
||||
// double m_brightness;
|
||||
|
||||
QString m_name;
|
||||
QString m_path;
|
||||
QString m_primary;
|
||||
Resolution m_currentMode;
|
||||
QList<quint16> m_rotateList;
|
||||
// QList<QPair<int, int>> m_resolutionList;
|
||||
// QList<double> m_refreshList;
|
||||
QList<Resolution> m_modeList;
|
||||
|
||||
bool m_enable;
|
||||
DockPosition m_dockPosition;
|
||||
};
|
||||
|
1417
frame/util/multiscreenworker.cpp
Normal file
1417
frame/util/multiscreenworker.cpp
Normal file
File diff suppressed because it is too large
Load Diff
334
frame/util/multiscreenworker.h
Normal file
334
frame/util/multiscreenworker.h
Normal file
@ -0,0 +1,334 @@
|
||||
/*
|
||||
* Copyright (C) 2018 ~ 2028 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: fanpengcheng <fanpengcheng_cm@deepin.com>
|
||||
*
|
||||
* Maintainer: fanpengcheng <fanpengcheng_cm@deepin.com>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef MULTISCREENWORKER_H
|
||||
#define MULTISCREENWORKER_H
|
||||
#include "constants.h"
|
||||
#include "monitor.h"
|
||||
#include "utils.h"
|
||||
#include "item/dockitem.h"
|
||||
|
||||
#include "xcb/xcb_misc.h"
|
||||
|
||||
#include <com_deepin_dde_daemon_dock.h>
|
||||
#include <com_deepin_daemon_display.h>
|
||||
#include <com_deepin_daemon_display_monitor.h>
|
||||
#include <com_deepin_api_xeventmonitor.h>
|
||||
#include <com_deepin_dde_launcher.h>
|
||||
|
||||
#include <DWindowManagerHelper>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#define WINDOWMARGIN ((m_displayMode == Dock::Efficient) ? 0 : 10)
|
||||
#define ANIMATIONTIME 300
|
||||
|
||||
DGUI_USE_NAMESPACE
|
||||
/**
|
||||
* 多屏功能这部分看着很复杂,其实只需要把握住一个核心:及时更新数据!
|
||||
* 之前测试出的诸多问题都是在切换任务栏位置,切换屏幕,主屏更改,分辨率更改等情况发生后
|
||||
* 任务栏的鼠标唤醒区域或任务栏的大小没更新或者更新时的大小还是按照原来的屏幕信息计算而来的,
|
||||
*/
|
||||
using DBusDock = com::deepin::dde::daemon::Dock;
|
||||
using DisplayInter = com::deepin::daemon::Display;
|
||||
using MonitorInter = com::deepin::daemon::display::Monitor;
|
||||
using XEventMonitor = ::com::deepin::api::XEventMonitor;
|
||||
using DBusLuncher = ::com::deepin::dde::Launcher;
|
||||
|
||||
using namespace Dock;
|
||||
class QVariantAnimation;
|
||||
class QWidget;
|
||||
class QTimer;
|
||||
class MainWindow;
|
||||
|
||||
class DockScreen : QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DockScreen(const QString ¤t, const QString &last, const QString &primary)
|
||||
: m_currentScreen(current)
|
||||
, m_lastScreen(last)
|
||||
, m_primary(primary)
|
||||
{}
|
||||
explicit DockScreen(const QString &primary)
|
||||
: m_currentScreen(primary)
|
||||
, m_lastScreen(primary)
|
||||
, m_primary(primary)
|
||||
{}
|
||||
inline const QString ¤t() {return m_currentScreen;}
|
||||
inline const QString &last() {return m_lastScreen;}
|
||||
inline const QString &primary() {return m_primary;}
|
||||
|
||||
void updateDockedScreen(const QString &screenName)
|
||||
{
|
||||
m_lastScreen = m_currentScreen;
|
||||
m_currentScreen = screenName;
|
||||
}
|
||||
|
||||
void updatePrimary(const QString &primary)
|
||||
{
|
||||
m_primary = primary;
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_currentScreen;
|
||||
QString m_lastScreen;
|
||||
QString m_primary;
|
||||
};
|
||||
|
||||
class MultiScreenWorker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Flag {
|
||||
Motion = 1 << 0,
|
||||
Button = 1 << 1,
|
||||
Key = 1 << 2
|
||||
};
|
||||
|
||||
MultiScreenWorker(QWidget *parent, DWindowManagerHelper *helper);
|
||||
~MultiScreenWorker();
|
||||
|
||||
void initShow();
|
||||
|
||||
DBusDock *dockInter() {return m_dockInter;}
|
||||
|
||||
/**
|
||||
* @brief lastScreen
|
||||
* @return 任务栏上次所在的屏幕
|
||||
*/
|
||||
inline const QString &lastScreen() {return m_ds.last();/*return m_lastScreen;*/}
|
||||
/**
|
||||
* @brief deskScreen
|
||||
* @return 任务栏目标屏幕.可以理解为任务栏当前所在屏幕
|
||||
*/
|
||||
inline const QString &deskScreen() {return m_ds.current();/*return m_currentScreen;*/}
|
||||
/**
|
||||
* @brief position
|
||||
* @return 任务栏所在方向(上下左右)
|
||||
*/
|
||||
inline const Position &position() {return m_position;}
|
||||
/**
|
||||
* @brief displayMode
|
||||
* @return 任务栏显示模式(时尚模式,高效模式)
|
||||
*/
|
||||
inline const DisplayMode &displayMode() {return m_displayMode;}
|
||||
/**
|
||||
* @brief hideMode
|
||||
* @return 任务栏状态(一直显示,一直隐藏,智能隐藏)
|
||||
*/
|
||||
inline const HideMode &hideMode() {return m_hideMode;}
|
||||
/**
|
||||
* @brief hideState
|
||||
* @return 任务栏的智能隐藏时的一个状态值(1显示,2隐藏,其他不处理)
|
||||
*/
|
||||
inline const HideState &hideState() {return m_hideState;}
|
||||
/**
|
||||
* @brief opacity
|
||||
* @return 任务栏透明度
|
||||
*/
|
||||
inline quint8 opacity() {return m_opacity * 255;}
|
||||
/**
|
||||
* @brief dockRect
|
||||
* @param screenName 屏幕名
|
||||
* @param pos 任务栏位置
|
||||
* @param hideMode 模式
|
||||
* @param displayMode 状态
|
||||
* @return 按照给定的数据计算出任务栏所在位置
|
||||
*/
|
||||
QRect dockRect(const QString &screenName, const Position &pos, const HideMode &hideMode, const DisplayMode &displayMode);
|
||||
/**
|
||||
* @brief dockRect
|
||||
* @param screenName 屏幕名
|
||||
* @return 按照当前屏幕的当前属性给出任务栏所在区域
|
||||
*/
|
||||
QRect dockRect(const QString &screenName);
|
||||
|
||||
/**
|
||||
* @brief handleLeaveEvent 状态为隐藏时,离开任务栏需要隐藏任务栏
|
||||
* @param event 离开事件
|
||||
*/
|
||||
void handleLeaveEvent(QEvent *event);
|
||||
|
||||
signals:
|
||||
void opacityChanged(const quint8 value) const;
|
||||
void displayModeChanegd();
|
||||
|
||||
// 更新监视区域
|
||||
void requestUpdateRegionMonitor();
|
||||
void requestUpdateFrontendGeometry(const QRect &rect);
|
||||
void requestNotifyWindowManager();
|
||||
void requestUpdatePosition(const Position &fromPos, const Position &toPos);
|
||||
void requestUpdateLayout(const QString &screenName); // 界面需要根据任务栏更新布局的方向
|
||||
void requestUpdateDragArea(); // 更新拖拽区域
|
||||
void requestUpdateMonitorInfo(); // 屏幕信息发生变化,需要更新任务栏大小,拖拽区域,所在屏幕,监控区域,通知窗管,通知后端,
|
||||
|
||||
public slots:
|
||||
void onAutoHideChanged(bool autoHide);
|
||||
void updateDaemonDockSize(int dockSize);
|
||||
void onDragStateChanged(bool draging);
|
||||
|
||||
void handleDbusSignal(QDBusMessage);
|
||||
|
||||
private slots:
|
||||
// Region Monitor
|
||||
void onRegionMonitorChanged(int x, int y, const QString &key);
|
||||
|
||||
// Display Monitor
|
||||
void onMonitorListChanged(const QList<QDBusObjectPath> &mons);
|
||||
void monitorAdded(const QString &path);
|
||||
void monitorRemoved(const QString &path);
|
||||
|
||||
// Animation
|
||||
void showAniFinished();
|
||||
void hideAniFinished();
|
||||
|
||||
void onWindowSizeChanged(uint value);
|
||||
void primaryScreenChanged();
|
||||
|
||||
// 任务栏属性变化
|
||||
void onPositionChanged();
|
||||
void onDisplayModeChanged();
|
||||
void onHideModeChanged();
|
||||
void onHideStateChanged();
|
||||
void onOpacityChanged(const double value);
|
||||
|
||||
/**
|
||||
* @brief onRequestUpdateRegionMonitor 更新监听区域信息
|
||||
* 触发时机:屏幕大小,屏幕坐标,屏幕数量,发生变化
|
||||
* 任务栏位置发生变化
|
||||
* 任务栏'模式'发生变化
|
||||
*/
|
||||
void onRequestUpdateRegionMonitor();
|
||||
|
||||
// 通知后端任务栏所在位置
|
||||
void onRequestUpdateFrontendGeometry(const QRect &rect);
|
||||
|
||||
void onRequestNotifyWindowManager();
|
||||
void onRequestUpdatePosition(const Position &fromPos, const Position &toPos);
|
||||
void onRequestUpdateDragArea();
|
||||
void onRequestUpdateMonitorInfo();
|
||||
|
||||
void updateMonitorDockedInfo();
|
||||
|
||||
private:
|
||||
// 初始化数据信息
|
||||
void initMembers();
|
||||
void initConnection();
|
||||
void initUI();
|
||||
/**
|
||||
* @brief showAni 任务栏显示动画
|
||||
* @param screen 显示到目标屏幕上
|
||||
*/
|
||||
void showAni(const QString &screen);
|
||||
/**
|
||||
* @brief hideAni 任务栏隐藏动画
|
||||
* @param screen 从目标屏幕上隐藏
|
||||
*/
|
||||
void hideAni(const QString &screen);
|
||||
/**
|
||||
* @brief changeDockPosition 做一个动画操作
|
||||
* @param lastScreen 上次任务栏所在的屏幕
|
||||
* @param deskScreen 任务栏要移动到的屏幕
|
||||
* @param fromPos 任务栏上次的方向
|
||||
* @param toPos 任务栏打算移动到的方向
|
||||
*/
|
||||
void changeDockPosition(QString lastScreen, QString deskScreen, const Position &fromPos, const Position &toPos);
|
||||
/**
|
||||
* @brief updateDockScreenName 将任务栏所在屏幕信息进行更新,在任务栏切换屏幕显示后,这里应该被调用
|
||||
* @param screenName 目标屏幕
|
||||
*/
|
||||
void updateDockScreenName(const QString &screenName);
|
||||
/**
|
||||
* @brief getValidScreen 获取一个当前任务栏可以停靠的屏幕,优先使用主屏
|
||||
* @return
|
||||
*/
|
||||
QString getValidScreen(const Position &pos);
|
||||
/**
|
||||
* @brief autosetDockScreen 检查一下当前屏幕所在边缘是够允许任务栏停靠,不允许的情况需要更换下一块屏幕
|
||||
*/
|
||||
void autosetDockScreen();
|
||||
|
||||
void checkDaemonDockService();
|
||||
|
||||
MainWindow *parent();
|
||||
|
||||
QRect getDockShowGeometry(const QString &screenName, const Position &pos, const DisplayMode &displaymode);
|
||||
QRect getDockHideGeometry(const QString &screenName, const Position &pos, const DisplayMode &displaymode);
|
||||
|
||||
Monitor *monitorByName(const QList<Monitor *> &list, const QString &screenName);
|
||||
QScreen *screenByName(const QString &screenName);
|
||||
qreal scaleByName(const QString &screenName);
|
||||
bool onScreenEdge(const QString &screenName, const QPoint &point);
|
||||
bool onScreenEdge(const QPoint &point);
|
||||
bool contains(const MonitRect &rect, const QPoint &pos);
|
||||
bool contains(const QList<MonitRect> &rectList, const QPoint &pos);
|
||||
const QPoint rawXPosition(const QPoint &scaledPos);
|
||||
const QPoint scaledPos(const QPoint &rawXPos);
|
||||
QList<Monitor *> validMonitorList(const QMap<Monitor *, MonitorInter *> &map);
|
||||
|
||||
private:
|
||||
QWidget *m_parent;
|
||||
DWindowManagerHelper *m_wmHelper;
|
||||
XcbMisc *m_xcbMisc;
|
||||
|
||||
// monitor screen
|
||||
XEventMonitor *m_eventInter;
|
||||
|
||||
// DBus interface
|
||||
DBusDock *m_dockInter;
|
||||
DisplayInter *m_displayInter;
|
||||
DBusLuncher* m_launcherInter;
|
||||
|
||||
// update monitor info
|
||||
QTimer *m_monitorUpdateTimer;
|
||||
|
||||
// animation
|
||||
QVariantAnimation *m_showAni;
|
||||
QVariantAnimation *m_hideAni;
|
||||
|
||||
// 屏幕名称信息
|
||||
DockScreen m_ds;
|
||||
|
||||
// 任务栏属性
|
||||
double m_opacity;
|
||||
Position m_position;
|
||||
HideMode m_hideMode;
|
||||
HideState m_hideState;
|
||||
DisplayMode m_displayMode;
|
||||
/**
|
||||
* @brief m_monitorInfo 屏幕信息(注意需要保证内容实时更新,且有效)
|
||||
*/
|
||||
QMap<Monitor *, MonitorInter *> m_monitorInfo;
|
||||
/***************不和其他流程产生交互,尽量不要动这里的变量***************/
|
||||
int m_screenRawHeight;
|
||||
int m_screenRawWidth;
|
||||
QString m_registerKey;
|
||||
QString m_leaveRegisterKey;
|
||||
bool m_aniStart; // changeDockPosition是否正在运行中
|
||||
bool m_draging; // 鼠标是否正在调整任务栏的宽度或高度
|
||||
bool m_autoHide; // 和DockSettings保持一致,可以直接使用其单例进行获取
|
||||
bool m_btnPress; // 鼠标按下时移动到唤醒区域不应该响应唤醒
|
||||
QList<MonitRect> m_monitorRectList; // 监听唤起任务栏区域
|
||||
/*****************************************************************/
|
||||
};
|
||||
|
||||
#endif // MULTISCREENWORKER_H
|
@ -1,3 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2018 ~ 2028 Uniontech Technology Co., Ltd.
|
||||
*
|
||||
* Author: fanpengcheng <fanpengcheng@uniontech.com>
|
||||
*
|
||||
* Maintainer: fanpengcheng <fanpengcheng@uniontech.com>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#ifndef UTILS
|
||||
#define UTILS
|
||||
#include <QPixmap>
|
||||
#include <QImageReader>
|
||||
#include <QApplication>
|
||||
@ -56,3 +78,5 @@ namespace Utils {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // UTILS
|
||||
|
941
frame/window/mainwindow.cpp
Normal file → Executable file
941
frame/window/mainwindow.cpp
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
@ -26,9 +26,9 @@
|
||||
#include "xcb/xcb_misc.h"
|
||||
#include "dbus/sni/statusnotifierwatcher_interface.h"
|
||||
#include "panel/mainpanelcontrol.h"
|
||||
#include "util/multiscreenworker.h"
|
||||
|
||||
#include <com_deepin_api_xeventmonitor.h>
|
||||
#include <com_deepin_dde_launcher.h>
|
||||
|
||||
#include <DPlatformWindowHandle>
|
||||
#include <DWindowManagerHelper>
|
||||
@ -40,13 +40,69 @@
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
using XEventMonitor = ::com::deepin::api::XEventMonitor;
|
||||
using DBusLuncher = ::com::deepin::dde::Launcher;
|
||||
|
||||
class DockSettings;
|
||||
class DragWidget;
|
||||
class MainPanel;
|
||||
class MainPanelControl;
|
||||
class QTimer;
|
||||
class MenuWorker;
|
||||
class DragWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
bool m_dragStatus;
|
||||
QPoint m_resizePoint;
|
||||
|
||||
public:
|
||||
DragWidget(QWidget *parent = nullptr) : QWidget(parent)
|
||||
{
|
||||
setObjectName("DragWidget");
|
||||
m_dragStatus = false;
|
||||
}
|
||||
|
||||
signals:
|
||||
void dragPointOffset(QPoint);
|
||||
void dragFinished();
|
||||
|
||||
private:
|
||||
void mousePressEvent(QMouseEvent *event) override
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
m_resizePoint = event->globalPos();
|
||||
m_dragStatus = true;
|
||||
this->grabMouse();
|
||||
}
|
||||
}
|
||||
|
||||
void mouseMoveEvent(QMouseEvent *) override
|
||||
{
|
||||
if (m_dragStatus) {
|
||||
QPoint offset = QPoint(QCursor::pos() - m_resizePoint);
|
||||
emit dragPointOffset(offset);
|
||||
}
|
||||
}
|
||||
|
||||
void mouseReleaseEvent(QMouseEvent *) override
|
||||
{
|
||||
if (!m_dragStatus)
|
||||
return;
|
||||
|
||||
m_dragStatus = false;
|
||||
releaseMouse();
|
||||
emit dragFinished();
|
||||
}
|
||||
|
||||
void enterEvent(QEvent *) override
|
||||
{
|
||||
QApplication::setOverrideCursor(cursor());
|
||||
}
|
||||
|
||||
void leaveEvent(QEvent *) override
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::ArrowCursor);
|
||||
}
|
||||
};
|
||||
|
||||
class MainWindow : public DBlurEffectWidget, public MainPanelDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -59,19 +115,23 @@ class MainWindow : public DBlurEffectWidget, public MainPanelDelegate
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
~MainWindow() override;
|
||||
void setEffectEnabled(const bool enabled);
|
||||
void setComposite(const bool hasComposite);
|
||||
|
||||
friend class MainPanel;
|
||||
friend class MainPanelControl;
|
||||
|
||||
MainPanelControl *panel() {return m_mainPanel;}
|
||||
DragWidget *dragWidget() {return m_dragWidget;}
|
||||
|
||||
public slots:
|
||||
void launch();
|
||||
// 第一次显示
|
||||
void initShow();
|
||||
|
||||
private:
|
||||
using QWidget::show;
|
||||
bool event(QEvent *e) override;
|
||||
void showEvent(QShowEvent *e) override;
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
@ -79,75 +139,52 @@ private:
|
||||
void leaveEvent(QEvent *e) override;
|
||||
void dragEnterEvent(QDragEnterEvent *e) override;
|
||||
void mouseMoveEvent(QMouseEvent *e) override;
|
||||
void moveEvent(QMoveEvent *event) override;
|
||||
|
||||
void initSNIHost();
|
||||
void initComponents();
|
||||
void initConnections();
|
||||
void resizeMainWindow();
|
||||
void resizeMainPanelWindow();
|
||||
|
||||
// const QPoint x11GetWindowPos();
|
||||
// void x11MoveWindow(const int x, const int y);
|
||||
// void x11MoveResizeWindow(const int x, const int y, const int w, const int h);
|
||||
bool appIsOnDock(const QString &appDesktop) override;
|
||||
void onRegionMonitorChanged(int x, int y, const QString &key);
|
||||
void updateRegionMonitorWatch();
|
||||
void getTrayVisableItemCount();
|
||||
|
||||
signals:
|
||||
void panelGeometryChanged();
|
||||
|
||||
public slots:
|
||||
void resetDragWindow();
|
||||
|
||||
private slots:
|
||||
void positionChanged();
|
||||
void updatePosition();
|
||||
void updateGeometry();
|
||||
void clearStrutPartial();
|
||||
void setStrutPartial();
|
||||
void compositeChanged();
|
||||
void internalMove(const QPoint &p);
|
||||
void updateDisplayMode();
|
||||
|
||||
void expand();
|
||||
void narrow();
|
||||
void resetPanelEnvironment();
|
||||
void updatePanelVisible();
|
||||
|
||||
void adjustShadowMask();
|
||||
void positionCheck();
|
||||
|
||||
void onDbusNameOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
|
||||
void onMainWindowSizeChanged(QPoint offset);
|
||||
void onDragFinished();
|
||||
void themeTypeChanged(DGuiApplicationHelper::ColorType themeType);
|
||||
|
||||
void newPositionExpand();
|
||||
|
||||
private:
|
||||
bool m_launched;
|
||||
MainPanelControl *m_mainPanel;
|
||||
|
||||
DPlatformWindowHandle m_platformWindowHandle;
|
||||
DWindowManagerHelper *m_wmHelper;
|
||||
MultiScreenWorker *m_multiScreenWorker;
|
||||
MenuWorker *m_menuWorker;
|
||||
XEventMonitor *m_eventInter;
|
||||
DBusLuncher* m_launcherInter;
|
||||
QString m_registerKey{""};
|
||||
QTimer *m_positionUpdateTimer;
|
||||
QTimer *m_expandDelayTimer;
|
||||
QTimer *m_leaveDelayTimer;
|
||||
QTimer *m_shadowMaskOptimizeTimer;
|
||||
QVariantAnimation *m_panelShowAni;
|
||||
QVariantAnimation *m_panelHideAni;
|
||||
|
||||
XcbMisc *m_xcbMisc;
|
||||
DockSettings *m_settings;
|
||||
QTimer *m_shadowMaskOptimizeTimer;
|
||||
|
||||
QDBusConnectionInterface *m_dbusDaemonInterface;
|
||||
org::kde::StatusNotifierWatcher *m_sniWatcher;
|
||||
QString m_sniHostService;
|
||||
QSize m_size;
|
||||
DragWidget *m_dragWidget;
|
||||
Position m_dockPosition;
|
||||
bool m_primaryScreenChanged;
|
||||
|
||||
bool m_launched;
|
||||
int m_dockSize;
|
||||
QString m_registerKey;
|
||||
QStringList m_registerKeys;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user