Merge tag '5.1.0.12' into uos

# Conflicts:
#	frame/util/docksettings.cpp
#	frame/util/docksettings.h
#	frame/window/mainwindow.cpp
This commit is contained in:
范朋程 2020-06-05 16:16:59 +08:00
commit ac6a590b37
15 changed files with 504 additions and 251 deletions

View File

@ -22,6 +22,7 @@
#include "window/mainwindow.h" #include "window/mainwindow.h"
#include "window/accessible.h" #include "window/accessible.h"
#include "util/themeappicon.h" #include "util/themeappicon.h"
#include "controller/dockitemmanager.h"
#include <QAccessible> #include <QAccessible>
#include <QDir> #include <QDir>

View File

@ -99,8 +99,8 @@ private:
void handleDragMove(QDragMoveEvent *e, bool isFilter); void handleDragMove(QDragMoveEvent *e, bool isFilter);
void paintEvent(QPaintEvent *event) override; void paintEvent(QPaintEvent *event) override;
void resizeDockIcon(); void resizeDockIcon();
void calcuDockIconSize(const int w, const int h, PluginsItem *trashPlugin, PluginsItem *shutdownPlugin, PluginsItem *keyboardPlugin, PluginsItem *notificationPlugin); void calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, PluginsItem *shutdownPlugin, PluginsItem *keyboardPlugin, PluginsItem *notificationPlugin);
void resizeDesktopWidget(); void resizeDesktopWidget();
public slots: public slots:
void insertItem(const int index, DockItem *item); void insertItem(const int index, DockItem *item);
void removeItem(DockItem *item); void removeItem(DockItem *item);

View File

@ -23,6 +23,7 @@
#include "docksettings.h" #include "docksettings.h"
#include "item/appitem.h" #include "item/appitem.h"
#include "util/utils.h" #include "util/utils.h"
#include "controller/dockitemmanager.h"
#include <QDebug> #include <QDebug>
#include <QX11Info> #include <QX11Info>
@ -70,7 +71,7 @@ DockSettings::DockSettings(QWidget *parent)
, m_keepShownAct(tr("Keep Shown"), this) , m_keepShownAct(tr("Keep Shown"), this)
, m_keepHiddenAct(tr("Keep Hidden"), this) , m_keepHiddenAct(tr("Keep Hidden"), this)
, m_smartHideAct(tr("Smart Hide"), this) , m_smartHideAct(tr("Smart Hide"), this)
, m_displayInter(new DBusDisplay(this)) , m_displayInter(new DisplayInter("com.deepin.daemon.Display", "/com/deepin/daemon/Display", QDBusConnection::sessionBus(), this))
, m_itemManager(DockItemManager::instance(this)) , m_itemManager(DockItemManager::instance(this))
, m_trashPluginShow(true) , m_trashPluginShow(true)
, m_isMouseMoveCause(false) , m_isMouseMoveCause(false)
@ -79,9 +80,12 @@ DockSettings::DockSettings(QWidget *parent)
m_settingsMenu.setAccessibleName("settingsmenu"); m_settingsMenu.setAccessibleName("settingsmenu");
checkService(); checkService();
m_primaryRawRect = m_displayInter->primaryRawRect(); onMonitorListChanged(m_displayInter->monitors());
m_screenRawHeight = m_displayInter->screenRawHeight();
m_screenRawWidth = m_displayInter->screenRawWidth(); 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_position = Dock::Position(m_dockInter->position());
m_displayMode = Dock::DisplayMode(m_dockInter->displayMode()); m_displayMode = Dock::DisplayMode(m_dockInter->displayMode());
m_hideMode = Dock::HideMode(m_dockInter->hideMode()); m_hideMode = Dock::HideMode(m_dockInter->hideMode());
@ -151,10 +155,11 @@ DockSettings::DockSettings(QWidget *parent)
connect(m_itemManager, &DockItemManager::itemRemoved, 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_itemManager, &DockItemManager::trayVisableCountChanged, this, &DockSettings::trayVisableCountChanged, Qt::QueuedConnection);
connect(m_displayInter, &DBusDisplay::PrimaryRectChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection); connect(m_displayInter, &DisplayInter::PrimaryRectChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
connect(m_displayInter, &DBusDisplay::ScreenHeightChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection); connect(m_displayInter, &DisplayInter::ScreenHeightChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
connect(m_displayInter, &DBusDisplay::ScreenWidthChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection); connect(m_displayInter, &DisplayInter::ScreenWidthChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
connect(m_displayInter, &DBusDisplay::PrimaryChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection); connect(m_displayInter, &DisplayInter::PrimaryChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
connect(m_displayInter, &DisplayInter::MonitorsChanged, this, &DockSettings::onMonitorListChanged);
connect(GSettingsByTrash(), &QGSettings::changed, this, &DockSettings::onTrashGSettingsChanged); connect(GSettingsByTrash(), &QGSettings::changed, this, &DockSettings::onTrashGSettingsChanged);
QTimer::singleShot(0, this, [=] {onGSettingsChanged("enable");}); QTimer::singleShot(0, this, [=] {onGSettingsChanged("enable");});
@ -163,8 +168,8 @@ DockSettings::DockSettings(QWidget *parent)
connect(app, &DApplication::iconThemeChanged, this, &DockSettings::gtkIconThemeChanged); connect(app, &DApplication::iconThemeChanged, this, &DockSettings::gtkIconThemeChanged);
} }
calculateMultiScreensPos();
calculateWindowConfig(); calculateWindowConfig();
updateForbidPostions();
resetFrontendGeometry(); resetFrontendGeometry();
QTimer::singleShot(0, this, [ = ] {onOpacityChanged(m_dockInter->opacity());}); QTimer::singleShot(0, this, [ = ] {onOpacityChanged(m_dockInter->opacity());});
@ -173,6 +178,20 @@ DockSettings::DockSettings(QWidget *parent)
}); });
} }
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() DockSettings &DockSettings::Instance()
{ {
static DockSettings settings; static DockSettings settings;
@ -190,33 +209,24 @@ const QRect DockSettings::primaryRect() const
return rect; return rect;
} }
const QRect DockSettings::currentRect() const QRect DockSettings::currentRect() const
{ {
QRect rect; QRect rect;
QString currentScrName; bool positionAllowed = false;
if (m_isMouseMoveCause) { QList<Monitor*> monitors = m_monitors.keys();
rect = m_mouseCauseDockScreen->rect(); for (Monitor *monitor : monitors) {
currentScrName = m_mouseCauseDockScreen->name(); switch (m_position) {
} else { case Top: positionAllowed = monitor->dockPosition().topDock; break;
bool positionAllowed = false; case Right: positionAllowed = monitor->dockPosition().rightDock; break;
QList<Monitor*> monitors = m_monitors.keys(); case Bottom: positionAllowed = monitor->dockPosition().bottomDock; break;
for (Monitor *monitor : monitors) { case Left: positionAllowed = monitor->dockPosition().leftDock; break;
switch (m_position) { }
case Top: positionAllowed = monitor->dockPosition().topDock; break; if (positionAllowed) {
case Right: positionAllowed = monitor->dockPosition().rightDock; break; rect = monitor->rect();
case Bottom: positionAllowed = monitor->dockPosition().bottomDock; break; if (monitor->isPrimary())
case Left: positionAllowed = monitor->dockPosition().leftDock; break; break;
}
if (positionAllowed) {
rect = monitor->rect();
currentScrName = monitor->name();
if (monitor->isPrimary())
break;
}
} }
} }
m_currentScreen = currentScrName;
m_currentRawRect = rect; m_currentRawRect = rect;
qreal scale = qApp->primaryScreen()->devicePixelRatio(); qreal scale = qApp->primaryScreen()->devicePixelRatio();
rect.setWidth(std::round(qreal(rect.width()) / scale)); rect.setWidth(std::round(qreal(rect.width()) / scale));
@ -249,7 +259,7 @@ const QRect DockSettings::windowRect(const Position position, const bool hide)
} }
} }
const QRect primaryRect = this->primaryRect(); const QRect primaryRect = this->currentRect();
const int offsetX = (primaryRect.width() - size.width()) / 2; const int offsetX = (primaryRect.width() - size.width()) / 2;
const int offsetY = (primaryRect.height() - size.height()) / 2; const int offsetY = (primaryRect.height() - size.height()) / 2;
int margin = hide ? 0 : this->dockMargin(); int margin = hide ? 0 : this->dockMargin();
@ -267,7 +277,6 @@ const QRect DockSettings::windowRect(const Position position, const bool hide)
case Bottom: case Bottom:
p = QPoint(offsetX, primaryRect.height() - size.height() - margin); p = QPoint(offsetX, primaryRect.height() - size.height() - margin);
break; break;
default: Q_UNREACHABLE();
} }
return QRect(primaryRect.topLeft() + p, size); return QRect(primaryRect.topLeft() + p, size);
@ -316,13 +325,9 @@ void DockSettings::showDockSettingsMenu()
m_fashionModeAct.setChecked(m_displayMode == Fashion); m_fashionModeAct.setChecked(m_displayMode == Fashion);
m_efficientModeAct.setChecked(m_displayMode == Efficient); m_efficientModeAct.setChecked(m_displayMode == Efficient);
m_topPosAct.setChecked(m_position == Top); m_topPosAct.setChecked(m_position == Top);
m_topPosAct.setEnabled(!m_forbidPositions.contains(Top));
m_bottomPosAct.setChecked(m_position == Bottom); m_bottomPosAct.setChecked(m_position == Bottom);
m_bottomPosAct.setEnabled(!m_forbidPositions.contains(Bottom));
m_leftPosAct.setChecked(m_position == Left); m_leftPosAct.setChecked(m_position == Left);
m_leftPosAct.setEnabled(!m_forbidPositions.contains(Left));
m_rightPosAct.setChecked(m_position == Right); m_rightPosAct.setChecked(m_position == Right);
m_rightPosAct.setEnabled(!m_forbidPositions.contains(Right));
m_keepShownAct.setChecked(m_hideMode == KeepShowing); m_keepShownAct.setChecked(m_hideMode == KeepShowing);
m_keepHiddenAct.setChecked(m_hideMode == KeepHidden); m_keepHiddenAct.setChecked(m_hideMode == KeepHidden);
m_smartHideAct.setChecked(m_hideMode == SmartHide); m_smartHideAct.setChecked(m_hideMode == SmartHide);
@ -355,8 +360,7 @@ void DockSettings::menuActionClicked(QAction *action)
if (action == &m_efficientModeAct) if (action == &m_efficientModeAct)
return m_dockInter->setDisplayMode(Efficient); return m_dockInter->setDisplayMode(Efficient);
m_isMouseMoveCause = false; calculateMultiScreensPos();
// calculateMultiScreensPos();
if (action == &m_topPosAct) if (action == &m_topPosAct)
return m_dockInter->setPosition(Top); return m_dockInter->setPosition(Top);
if (action == &m_bottomPosAct) if (action == &m_bottomPosAct)
@ -459,15 +463,16 @@ void DockSettings::dockItemCountChanged()
void DockSettings::primaryScreenChanged() void DockSettings::primaryScreenChanged()
{ {
// qDebug() << Q_FUNC_INFO; // qDebug() << Q_FUNC_INFO;
m_primaryRawRect = m_displayInter->primaryRawRect(); m_primaryRawRect = m_displayInter->primaryRect();
m_screenRawHeight = m_displayInter->screenRawHeight(); m_screenRawHeight = m_displayInter->screenHeight();
m_screenRawWidth = m_displayInter->screenRawWidth(); m_screenRawWidth = m_displayInter->screenWidth();
//为了防止当后端发送错误值,然后发送正确值时,任务栏没有移动在相应的位置 //为了防止当后端发送错误值,然后发送正确值时,任务栏没有移动在相应的位置
//当没有获取到屏幕资源时候move函数会失效。可以直接return //当没有获取到屏幕资源时候move函数会失效。可以直接return
if (m_screenRawHeight == 0 || m_screenRawWidth == 0){ if (m_screenRawHeight == 0 || m_screenRawWidth == 0){
return; return;
} }
calculateMultiScreensPos();
emit dataChanged(); emit dataChanged();
calculateWindowConfig(); calculateWindowConfig();
@ -492,77 +497,6 @@ void DockSettings::updateFrontendGeometry()
resetFrontendGeometry(); resetFrontendGeometry();
} }
bool DockSettings::test(const Position pos, const QList<QRect> &otherScreens) const
{
QRect maxStrut(0, 0, m_screenRawWidth, m_screenRawHeight);
switch (pos) {
case Top:
maxStrut.setBottom(m_primaryRawRect.top() - 1);
maxStrut.setLeft(m_primaryRawRect.left());
maxStrut.setRight(m_primaryRawRect.right());
break;
case Bottom:
maxStrut.setTop(m_primaryRawRect.bottom() + 1);
maxStrut.setLeft(m_primaryRawRect.left());
maxStrut.setRight(m_primaryRawRect.right());
break;
case Left:
maxStrut.setRight(m_primaryRawRect.left() - 1);
maxStrut.setTop(m_primaryRawRect.top());
maxStrut.setBottom(m_primaryRawRect.bottom());
break;
case Right:
maxStrut.setLeft(m_primaryRawRect.right() + 1);
maxStrut.setTop(m_primaryRawRect.top());
maxStrut.setBottom(m_primaryRawRect.bottom());
break;
default:;
}
if (maxStrut.width() == 0 || maxStrut.height() == 0)
return true;
for (const auto &r : otherScreens)
if (maxStrut.intersects(r))
return false;
return true;
}
void DockSettings::updateForbidPostions()
{
qDebug() << Q_FUNC_INFO;
const auto &screens = qApp->screens();
if (screens.size() < 2)
return m_forbidPositions.clear();
QSet<Position> forbids;
QList<QRect> rawScreenRects;
for (auto *s : screens) {
qInfo() << s->name() << s->geometry();
if (s == qApp->primaryScreen())
continue;
const QRect &g = s->geometry();
rawScreenRects << QRect(g.topLeft(), g.size() * s->devicePixelRatio());
}
qInfo() << rawScreenRects << m_screenRawWidth << m_screenRawHeight;
if (!test(Top, rawScreenRects))
forbids << Top;
if (!test(Bottom, rawScreenRects))
forbids << Bottom;
if (!test(Left, rawScreenRects))
forbids << Left;
if (!test(Right, rawScreenRects))
forbids << Right;
m_forbidPositions = std::move(forbids);
}
void DockSettings::onOpacityChanged(const double value) void DockSettings::onOpacityChanged(const double value)
{ {
if (m_opacity == value) return; if (m_opacity == value) return;
@ -580,7 +514,7 @@ void DockSettings::trayVisableCountChanged(const int &count)
void DockSettings::calculateWindowConfig() void DockSettings::calculateWindowConfig()
{ {
if (m_displayMode == Dock::Efficient) { if (m_displayMode == Dock::Efficient) {
m_dockWindowSize = m_dockInter->windowSizeEfficient(); m_dockWindowSize = int(m_dockInter->windowSizeEfficient());
if (m_dockWindowSize > WINDOW_MAX_SIZE || m_dockWindowSize < WINDOW_MIN_SIZE) { if (m_dockWindowSize > WINDOW_MAX_SIZE || m_dockWindowSize < WINDOW_MIN_SIZE) {
m_dockWindowSize = EffICIENT_DEFAULT_HEIGHT; m_dockWindowSize = EffICIENT_DEFAULT_HEIGHT;
m_dockInter->setWindowSize(EffICIENT_DEFAULT_HEIGHT); m_dockInter->setWindowSize(EffICIENT_DEFAULT_HEIGHT);
@ -590,20 +524,17 @@ void DockSettings::calculateWindowConfig()
case Top: case Top:
case Bottom: case Bottom:
m_mainWindowSize.setHeight(m_dockWindowSize); m_mainWindowSize.setHeight(m_dockWindowSize);
m_mainWindowSize.setWidth(primaryRect().width()); m_mainWindowSize.setWidth(currentRect().width());
break; break;
case Left: case Left:
case Right: case Right:
m_mainWindowSize.setHeight(primaryRect().height()); m_mainWindowSize.setHeight(currentRect().height());
m_mainWindowSize.setWidth(m_dockWindowSize); m_mainWindowSize.setWidth(m_dockWindowSize);
break; break;
default:
Q_ASSERT(false);
} }
} else if (m_displayMode == Dock::Fashion) { } else if (m_displayMode == Dock::Fashion) {
m_dockWindowSize = m_dockInter->windowSizeFashion(); m_dockWindowSize = int(m_dockInter->windowSizeFashion());
if (m_dockWindowSize > WINDOW_MAX_SIZE || m_dockWindowSize < WINDOW_MIN_SIZE) { if (m_dockWindowSize > WINDOW_MAX_SIZE || m_dockWindowSize < WINDOW_MIN_SIZE) {
m_dockWindowSize = FASHION_DEFAULT_HEIGHT; m_dockWindowSize = FASHION_DEFAULT_HEIGHT;
m_dockInter->setWindowSize(FASHION_DEFAULT_HEIGHT); m_dockInter->setWindowSize(FASHION_DEFAULT_HEIGHT);
@ -613,17 +544,15 @@ void DockSettings::calculateWindowConfig()
case Top: case Top:
case Bottom: { case Bottom: {
m_mainWindowSize.setHeight(m_dockWindowSize); m_mainWindowSize.setHeight(m_dockWindowSize);
m_mainWindowSize.setWidth(this->primaryRect().width() - MAINWINDOW_MARGIN * 2); m_mainWindowSize.setWidth(this->currentRect().width() - MAINWINDOW_MARGIN * 2);
break; break;
} }
case Left: case Left:
case Right: { case Right: {
m_mainWindowSize.setHeight(this->primaryRect().height() - MAINWINDOW_MARGIN * 2); m_mainWindowSize.setHeight(this->currentRect().height() - MAINWINDOW_MARGIN * 2);
m_mainWindowSize.setWidth(m_dockWindowSize); m_mainWindowSize.setWidth(m_dockWindowSize);
break; break;
} }
default:
Q_ASSERT(false);
} }
} else { } else {
Q_ASSERT(false); Q_ASSERT(false);
@ -660,6 +589,7 @@ void DockSettings::checkService()
if (!ifc->isServiceRegistered(serverName)) { if (!ifc->isServiceRegistered(serverName)) {
connect(ifc, &QDBusConnectionInterface::serviceOwnerChanged, this, [ = ](const QString & name, const QString & oldOwner, const QString & newOwner) { connect(ifc, &QDBusConnectionInterface::serviceOwnerChanged, this, [ = ](const QString & name, const QString & oldOwner, const QString & newOwner) {
Q_UNUSED(oldOwner)
if (name == serverName && !newOwner.isEmpty()) { if (name == serverName && !newOwner.isEmpty()) {
m_dockInter = new DBusDock(serverName, "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus(), this); m_dockInter = new DBusDock(serverName, "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus(), this);
@ -676,6 +606,272 @@ void DockSettings::checkService()
} }
} }
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;
// 左右拼
// 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;
} else {
if (!s1->isPrimary())
s1->dockPosition().rightDock = false;
if (!s2->isPrimary())
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;
} else {
if (!s1->isPrimary())
s1->dockPosition().leftDock = false;
if (!s2->isPrimary())
s2->dockPosition().rightDock = false;
}
}
// 上下拼
// s1上 s2下
if (s1->top() == s2->bottom()) {
isAligment = (s1->bottomLeft() == s2->topLeft())
&& (s1->bottomRight() == s2->topRight());
if (isAligment) {
s1->dockPosition().bottomDock = false;
s2->dockPosition().topDock = false;
} else {
if (!s1->isPrimary())
s1->dockPosition().bottomDock = false;
if (!s2->isPrimary())
s2->dockPosition().topDock = false;
}
}
// s1下 s2上
if (s1->bottom() == s2->top()) {
isAligment = (s1->topLeft() == s2->bottomLeft())
&& (s1->topRight() == s2->bottomRight());
if (isAligment) {
s1->dockPosition().topDock = false;
s2->dockPosition().bottomDock = false;
} else {
if (!s1->isPrimary())
s1->dockPosition().topDock = false;
if (!s2->isPrimary())
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) void DockSettings::onTrashGSettingsChanged(const QString &key)
{ {
if (key != "enable") { if (key != "enable") {
@ -688,3 +884,25 @@ void DockSettings::onTrashGSettingsChanged(const QString &key)
m_trashPluginShow = GSettingsByTrash()->keys().contains("enable") && GSettingsByTrash()->get("enable").toBool(); 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);
}

View File

@ -24,12 +24,10 @@
#define DOCKSETTINGS_H #define DOCKSETTINGS_H
#include "constants.h" #include "constants.h"
#include "dbus/dbusmenumanager.h"
#include "dbus/dbusdisplay.h"
#include "monitor.h" #include "monitor.h"
#include "controller/dockitemmanager.h"
#include <com_deepin_dde_daemon_dock.h> #include <com_deepin_dde_daemon_dock.h>
#include <com_deepin_daemon_display.h>
#include <QAction> #include <QAction>
#include <QMenu> #include <QMenu>
@ -37,13 +35,11 @@
#include <QObject> #include <QObject>
#include <QSize> #include <QSize>
#include <QStyleFactory>
DWIDGET_USE_NAMESPACE
using namespace Dock; using namespace Dock;
using DBusDock = com::deepin::dde::daemon::Dock; using DBusDock = com::deepin::dde::daemon::Dock;
using DisplayInter = com::deepin::daemon::Display;
class DockItemManager;
class DockSettings : public QObject class DockSettings : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -61,9 +57,10 @@ public:
inline int narrowTimeout() const { return 100; } inline int narrowTimeout() const { return 100; }
inline bool autoHide() const { return m_autoHide; } inline bool autoHide() const { return m_autoHide; }
const QRect primaryRect() const; const QRect primaryRect() const;
const QRect currentRect(); const QRect currentRect() const;
const QList<QRect> monitorsRect() const; const QList<QRect> monitorsRect() const;
inline const QRect primaryRawRect() const { return m_primaryRawRect; } 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 QRect frontendWindowRect() const { return m_frontendRect; }
inline const QSize windowSize() const { return m_mainWindowSize; } inline const QSize windowSize() const { return m_mainWindowSize; }
inline const quint8 Opacity() const { return m_opacity * 255; } inline const quint8 Opacity() const { return m_opacity * 255; }
@ -108,22 +105,29 @@ private slots:
void dockItemCountChanged(); void dockItemCountChanged();
void primaryScreenChanged(); void primaryScreenChanged();
void resetFrontendGeometry(); void resetFrontendGeometry();
void updateForbidPostions();
void onOpacityChanged(const double value); void onOpacityChanged(const double value);
void trayVisableCountChanged(const int &count); void trayVisableCountChanged(const int &count);
void onWindowSizeChanged(); void onWindowSizeChanged();
void onTrashGSettingsChanged(const QString &key); void onTrashGSettingsChanged(const QString &key);
void onMonitorListChanged(const QList<QDBusObjectPath> &mons);
private: private:
DockSettings(QWidget *parent = 0); DockSettings(QWidget *parent = nullptr);
DockSettings(DockSettings const &) = delete; DockSettings(DockSettings const &) = delete;
DockSettings operator =(DockSettings const &) = delete; DockSettings operator =(DockSettings const &) = delete;
bool test(const Position pos, const QList<QRect> &otherScreens) const;
void calculateWindowConfig(); void calculateWindowConfig();
void gtkIconThemeChanged(); void gtkIconThemeChanged();
void checkService(); 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: private:
int m_dockWindowSize; int m_dockWindowSize;
bool m_autoHide; bool m_autoHide;
@ -137,7 +141,7 @@ private:
HideState m_hideState; HideState m_hideState;
DisplayMode m_displayMode; DisplayMode m_displayMode;
QRect m_primaryRawRect; QRect m_primaryRawRect;
QRect m_currentRawRect; mutable QRect m_currentRawRect;
QRect m_frontendRect; QRect m_frontendRect;
QMenu m_settingsMenu; QMenu m_settingsMenu;
@ -152,7 +156,7 @@ private:
QAction m_keepHiddenAct; QAction m_keepHiddenAct;
QAction m_smartHideAct; QAction m_smartHideAct;
DBusDisplay *m_displayInter; DisplayInter *m_displayInter;
DockItemManager *m_itemManager; DockItemManager *m_itemManager;
bool m_trashPluginShow; bool m_trashPluginShow;

View File

@ -24,6 +24,7 @@
#include "panel/mainpanelcontrol.h" #include "panel/mainpanelcontrol.h"
#include "controller/dockitemmanager.h" #include "controller/dockitemmanager.h"
#include "util/utils.h" #include "util/utils.h"
#include "util/docksettings.h"
#include <DStyle> #include <DStyle>
#include <DPlatformWindowHandle> #include <DPlatformWindowHandle>
@ -113,9 +114,9 @@ const QPoint rawXPosition(const QPoint &scaledPos)
QScreen const *screen = Utils::screenAtByScaled(scaledPos); QScreen const *screen = Utils::screenAtByScaled(scaledPos);
return screen ? screen->geometry().topLeft() + return screen ? screen->geometry().topLeft() +
(scaledPos - screen->geometry().topLeft()) * (scaledPos - screen->geometry().topLeft()) *
screen->devicePixelRatio() screen->devicePixelRatio()
: scaledPos; : scaledPos;
} }
const QPoint scaledPos(const QPoint &rawXPos) const QPoint scaledPos(const QPoint &rawXPos)
@ -123,9 +124,9 @@ const QPoint scaledPos(const QPoint &rawXPos)
QScreen const *screen = Utils::screenAt(rawXPos); QScreen const *screen = Utils::screenAt(rawXPos);
return screen return screen
? screen->geometry().topLeft() + ? screen->geometry().topLeft() +
(rawXPos - screen->geometry().topLeft()) / screen->devicePixelRatio() (rawXPos - screen->geometry().topLeft()) / screen->devicePixelRatio()
: rawXPos; : rawXPos;
} }
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
@ -134,7 +135,7 @@ MainWindow::MainWindow(QWidget *parent)
, m_mainPanel(new MainPanelControl(this)) , m_mainPanel(new MainPanelControl(this))
, m_platformWindowHandle(this) , m_platformWindowHandle(this)
, m_wmHelper(DWindowManagerHelper::instance()) , m_wmHelper(DWindowManagerHelper::instance())
, m_regionMonitor(new DRegionMonitor(this)) , m_eventInter(new XEventMonitor("com.deepin.api.XEventMonitor", "/com/deepin/api/XEventMonitor", QDBusConnection::sessionBus()))
, m_positionUpdateTimer(new QTimer(this)) , m_positionUpdateTimer(new QTimer(this))
, m_expandDelayTimer(new QTimer(this)) , m_expandDelayTimer(new QTimer(this))
, m_leaveDelayTimer(new QTimer(this)) , m_leaveDelayTimer(new QTimer(this))
@ -461,8 +462,8 @@ void MainWindow::internalMove(const QPoint &p)
{ {
const bool isHide = m_settings->hideState() == HideState::Hide && !testAttribute(Qt::WA_UnderMouse); const bool isHide = m_settings->hideState() == HideState::Hide && !testAttribute(Qt::WA_UnderMouse);
const bool pos_adjust = m_settings->hideMode() != HideMode::KeepShowing && const bool pos_adjust = m_settings->hideMode() != HideMode::KeepShowing &&
isHide && isHide &&
m_panelShowAni->state() == QVariantAnimation::Stopped; m_panelShowAni->state() == QVariantAnimation::Stopped;
if (!pos_adjust) { if (!pos_adjust) {
m_mainPanel->move(0, 0); m_mainPanel->move(0, 0);
return QWidget::move(p); return QWidget::move(p);
@ -538,7 +539,7 @@ void MainWindow::initConnections()
connect(m_dragWidget, &DragWidget::dragPointOffset, this, &MainWindow::onMainWindowSizeChanged); connect(m_dragWidget, &DragWidget::dragPointOffset, this, &MainWindow::onMainWindowSizeChanged);
connect(m_dragWidget, &DragWidget::dragFinished, this, &MainWindow::onDragFinished); connect(m_dragWidget, &DragWidget::dragFinished, this, &MainWindow::onDragFinished);
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &MainWindow::themeTypeChanged); connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &MainWindow::themeTypeChanged);
connect(m_regionMonitor, &DRegionMonitor::cursorMove, this, &MainWindow::onRegionMonitorChanged); connect(m_eventInter, &XEventMonitor::CursorMove, this, &MainWindow::onRegionMonitorChanged);
} }
const QPoint MainWindow::x11GetWindowPos() const QPoint MainWindow::x11GetWindowPos()
@ -618,7 +619,7 @@ void MainWindow::updateGeometry()
//为了防止当后端发送错误值,然后发送正确值时,任务栏没有移动在相应的位置 //为了防止当后端发送错误值,然后发送正确值时,任务栏没有移动在相应的位置
//当没有获取到屏幕资源时候move函数会失效。可以直接return //当没有获取到屏幕资源时候move函数会失效。可以直接return
if(m_settings->primaryRect().width() ==0 || m_settings->primaryRect().height() == 0){ if (m_settings->primaryRect().width() == 0 || m_settings->primaryRect().height() == 0) {
return; return;
} }
@ -643,7 +644,7 @@ void MainWindow::updateGeometry()
void MainWindow::getTrayVisableItemCount() void MainWindow::getTrayVisableItemCount()
{ {
m_mainPanel->getTrayVisableItemCount(); m_mainPanel->getTrayVisableItemCount();
} }
void MainWindow::clearStrutPartial() void MainWindow::clearStrutPartial()
@ -668,7 +669,7 @@ void MainWindow::setStrutPartial()
const Position side = m_curDockPos; const Position side = m_curDockPos;
const QPoint &p = rawXPosition(m_settings->windowRect(m_curDockPos).topLeft()); const QPoint &p = rawXPosition(m_settings->windowRect(m_curDockPos).topLeft());
const QSize &s = m_settings->windowSize(); const QSize &s = m_settings->windowSize();
const QRect &primaryRawRect = m_settings->primaryRawRect(); const QRect &primaryRawRect = m_settings->currentRawRect();
XcbMisc::Orientation orientation = XcbMisc::OrientationTop; XcbMisc::Orientation orientation = XcbMisc::OrientationTop;
uint strut = 0; uint strut = 0;
@ -743,8 +744,7 @@ void MainWindow::expand()
qApp->processEvents(); qApp->processEvents();
setVisible(true); setVisible(true);
if (m_panelHideAni->state() == QPropertyAnimation::Running) if (m_panelHideAni->state() == QPropertyAnimation::Running) {
{
m_panelHideAni->stop(); m_panelHideAni->stop();
emit m_panelHideAni->finished(); emit m_panelHideAni->finished();
} }
@ -825,15 +825,14 @@ void MainWindow::resetPanelEnvironment(const bool visible, const bool resetPosit
void MainWindow::updatePanelVisible() void MainWindow::updatePanelVisible()
{ {
if (m_settings->hideMode() == KeepShowing) { if (m_settings->hideMode() == KeepShowing) {
if (m_regionMonitor->registered()){ if (!m_registerKey.isEmpty()) {
m_regionMonitor->unregisterRegion(); m_eventInter->UnregisterArea(m_registerKey);
} }
return expand(); return expand();
} }
if (!m_regionMonitor->registered()){ if (m_registerKey.isEmpty()) {
m_regionMonitor->registerRegion(); updateRegionMonitorWatch();
m_regionMonitor->setCoordinateType(DRegionMonitor::ScaleRatio);
} }
const Dock::HideState state = m_settings->hideState(); const Dock::HideState state = m_settings->hideState();
@ -1034,13 +1033,18 @@ void MainWindow::themeTypeChanged(DGuiApplicationHelper::ColorType themeType)
} }
} }
void MainWindow::onRegionMonitorChanged() void MainWindow::onRegionMonitorChanged(int x, int y, const QString &key)
{ {
// if (m_registerKey != key)
// return;
if (m_settings->hideMode() == KeepShowing) if (m_settings->hideMode() == KeepShowing)
return; return;
if (!isVisible()) if (!isVisible())
setVisible(true); setVisible(true);
// QScreen *screen = Utils::screenAtByScaled(QPoint(x, y));
} }
void MainWindow::updateRegionMonitorWatch() void MainWindow::updateRegionMonitorWatch()
@ -1048,18 +1052,46 @@ void MainWindow::updateRegionMonitorWatch()
if (m_settings->hideMode() == KeepShowing) if (m_settings->hideMode() == KeepShowing)
return; return;
int val = 5; const int flags = Motion | Button | Key;
bool isHide = m_settings->hideState() == Hide && !testAttribute(Qt::WA_UnderMouse);
const QRect windowRect = m_settings->windowRect(m_curDockPos, isHide);
const qreal scale = devicePixelRatioF(); const qreal scale = devicePixelRatioF();
int val = 5;
const int margin = m_settings->dockMargin(); const int margin = m_settings->dockMargin();
if (Dock::Top == m_curDockPos) { int x, y, w, h;
m_regionMonitor->setWatchedRegion(QRegion(margin * scale, 0, (m_settings->primaryRect().width() - margin*2) * scale, val *scale));
} else if (Dock::Bottom == m_curDockPos) { switch (m_curDockPos) {
m_regionMonitor->setWatchedRegion(QRegion(margin * scale, (m_settings->primaryRect().height() - val)* scale, (m_settings->primaryRect().width() - margin*2)*scale, val * scale)); case Dock::Top: {
} else if (Dock::Left == m_curDockPos) { x = windowRect.topLeft().x();
m_regionMonitor->setWatchedRegion(QRegion(0, margin * scale, val * scale, (m_settings->primaryRect().height() - margin*2) * scale)); y = windowRect.topLeft().y();
} else { w = m_settings->primaryRect().width();
m_regionMonitor->setWatchedRegion(QRegion((m_settings->primaryRect().width() - val) * scale, margin * scale, val * scale, (m_settings->primaryRect().height()- margin*2)*scale)); h = val + margin;
} }
break;
case Dock::Bottom: {
x = windowRect.bottomLeft().x();
y = windowRect.bottomLeft().y() - val;
w = m_settings->primaryRect().width();
h = val + margin;
}
break;
case Dock::Left: {
x = windowRect.topLeft().x();
y = windowRect.topLeft().y();
w = val + margin;
h = m_settings->primaryRect().height();
}
break;
case Dock::Right: {
x = windowRect.topRight().x() - val - margin;
y = windowRect.topRight().y();
w = m_settings->primaryRect().width();
h = m_settings->primaryRect().height();
}
break;
}
m_eventInter->RegisterArea(x * scale, y * scale, w * scale, h * scale, flags);
} }

View File

@ -24,34 +24,39 @@
#define MAINWINDOW_H #define MAINWINDOW_H
#include "xcb/xcb_misc.h" #include "xcb/xcb_misc.h"
#include "dbus/dbusdisplay.h"
#include "dbus/dbusdockadaptors.h"
#include "dbus/sni/statusnotifierwatcher_interface.h" #include "dbus/sni/statusnotifierwatcher_interface.h"
#include "util/docksettings.h"
#include "panel/mainpanelcontrol.h" #include "panel/mainpanelcontrol.h"
#include <QWidget> #include <com_deepin_api_xeventmonitor.h>
#include <QTimer>
#include <QRect>
#include <DPlatformWindowHandle> #include <DPlatformWindowHandle>
#include <DWindowManagerHelper> #include <DWindowManagerHelper>
#include <DBlurEffectWidget> #include <DBlurEffectWidget>
#include <DGuiApplicationHelper> #include <DGuiApplicationHelper>
#include <DRegionMonitor>
#include <QWidget>
DWIDGET_USE_NAMESPACE DWIDGET_USE_NAMESPACE
using XEventMonitor = ::com::deepin::api::XEventMonitor;
class DockSettings;
class DragWidget; class DragWidget;
class MainPanel; class MainPanel;
class MainPanelControl; class MainPanelControl;
class DBusDockAdaptors; class QTimer;
class MainWindow : public DBlurEffectWidget, public MainPanelDelegate class MainWindow : public DBlurEffectWidget, public MainPanelDelegate
{ {
Q_OBJECT Q_OBJECT
enum Flag{
Motion = 1 << 0,
Button = 1 << 1,
Key = 1 << 2
};
public: public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = nullptr);
~MainWindow(); ~MainWindow();
void setEffectEnabled(const bool enabled); void setEffectEnabled(const bool enabled);
void setComposite(const bool hasComposite); void setComposite(const bool hasComposite);
@ -83,7 +88,7 @@ private:
void x11MoveWindow(const int x, const int y); void x11MoveWindow(const int x, const int y);
void x11MoveResizeWindow(const int x, const int y, const int w, const int h); void x11MoveResizeWindow(const int x, const int y, const int w, const int h);
bool appIsOnDock(const QString &appDesktop); bool appIsOnDock(const QString &appDesktop);
void onRegionMonitorChanged(); void onRegionMonitorChanged(int x, int y, const QString &key);
void updateRegionMonitorWatch(); void updateRegionMonitorWatch();
void getTrayVisableItemCount(); void getTrayVisableItemCount();
@ -119,7 +124,9 @@ private:
DPlatformWindowHandle m_platformWindowHandle; DPlatformWindowHandle m_platformWindowHandle;
DWindowManagerHelper *m_wmHelper; DWindowManagerHelper *m_wmHelper;
DRegionMonitor *m_regionMonitor; XEventMonitor *m_eventInter;
QString m_registerKey;
QStringList m_registerKeys;
QTimer *m_positionUpdateTimer; QTimer *m_positionUpdateTimer;
QTimer *m_expandDelayTimer; QTimer *m_expandDelayTimer;

View File

@ -247,14 +247,14 @@ void PowerPlugin::refreshTipsData()
if (m_showTimeToFull) if (m_showTimeToFull)
tips = tr("Capacity %1, %2 min remaining").arg(value).arg(min); tips = tr("Capacity %1, %2 min remaining").arg(value).arg(min);
else { else {
tips = tr("Capacity %1").arg(value); tips = tr("Capacity %1");
} }
} }
} else { } else {
if (m_showTimeToFull) if (m_showTimeToFull)
tips = tr("Capacity %1, %2 hr %3 min remaining").arg(value).arg(hour).arg(min); tips = tr("Capacity %1, %2 hr %3 min remaining").arg(value).arg(hour).arg(min);
else { else {
tips = tr("Capacity %1").arg(value); tips = tr("Capacity %1").arg(value).arg(hour);
} }
} }

View File

@ -34,8 +34,7 @@
using SystemPowerInter = com::deepin::system::Power; using SystemPowerInter = com::deepin::system::Power;
// from https://upower.freedesktop.org/docs/Device.html#Device:State // from https://upower.freedesktop.org/docs/Device.html#Device:State
enum BatteryState enum BatteryState {
{
UNKNOWN = 0, // 未知 UNKNOWN = 0, // 未知
CHARGING = 1, // 充电中 CHARGING = 1, // 充电中
DIS_CHARGING = 2, // 放电 DIS_CHARGING = 2, // 放电

View File

@ -83,27 +83,27 @@ QPixmap PowerStatusWidget::getBatteryIcon()
percentageStr = "020"; percentageStr = "020";
} else if (percentage <= 30) { } else if (percentage <= 30) {
percentageStr = "030"; percentageStr = "030";
}else if (percentage <= 40) { } else if (percentage <= 40) {
percentageStr = "040"; percentageStr = "040";
} else if (percentage <= 50) { } else if (percentage <= 50) {
percentageStr = "050"; percentageStr = "050";
}else if (percentage <= 60) { } else if (percentage <= 60) {
percentageStr = "060"; percentageStr = "060";
} else if (percentage <= 70) { } else if (percentage <= 70) {
percentageStr = "070"; percentageStr = "070";
}else if (percentage < 80) { } else if (percentage < 80) {
percentageStr = "080"; percentageStr = "080";
} else if (percentage <= 90) { } else if (percentage <= 90) {
percentageStr = "090"; percentageStr = "090";
}else if (percentage <= 100){ } else if (percentage <= 100) {
percentageStr = "100"; percentageStr = "100";
} else { } else {
percentageStr = "100"; percentageStr = "100";
} }
QString iconStr = QString("battery-%1-%2") QString iconStr = QString("battery-%1-%2")
.arg(percentageStr) .arg(percentageStr)
.arg(plugged ? "plugged-symbolic" : "symbolic"); .arg(plugged ? "plugged-symbolic" : "symbolic");
if (height() <= PLUGIN_BACKGROUND_MIN_SIZE && DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) if (height() <= PLUGIN_BACKGROUND_MIN_SIZE && DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType)
iconStr.append(PLUGIN_MIN_ICON_NAME); iconStr.append(PLUGIN_MIN_ICON_NAME);

View File

@ -122,10 +122,10 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey)
QProcessEnvironment enviromentVar = QProcessEnvironment::systemEnvironment(); QProcessEnvironment enviromentVar = QProcessEnvironment::systemEnvironment();
bool can_sleep = enviromentVar.contains("POWER_CAN_SLEEP") ? QVariant(enviromentVar.value("POWER_CAN_SLEEP")).toBool() bool can_sleep = enviromentVar.contains("POWER_CAN_SLEEP") ? QVariant(enviromentVar.value("POWER_CAN_SLEEP")).toBool()
: valueByQSettings<bool>("Power", "sleep", true) && : valueByQSettings<bool>("Power", "sleep", true) &&
m_login1Inter->CanSuspend().value().contains("yes"); m_login1Inter->CanSuspend().value().contains("yes");
; ;
if(can_sleep){ if (can_sleep) {
QMap<QString, QVariant> suspend; QMap<QString, QVariant> suspend;
suspend["itemId"] = "Suspend"; suspend["itemId"] = "Suspend";
suspend["itemText"] = tr("Suspend"); suspend["itemText"] = tr("Suspend");
@ -134,7 +134,7 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey)
} }
bool can_hibernate = enviromentVar.contains("POWER_CAN_HIBERNATE") ? QVariant(enviromentVar.value("POWER_CAN_HIBERNATE")).toBool() bool can_hibernate = enviromentVar.contains("POWER_CAN_HIBERNATE") ? QVariant(enviromentVar.value("POWER_CAN_HIBERNATE")).toBool()
: checkSwap() && m_login1Inter->CanHibernate().value().contains("yes"); : checkSwap() && m_login1Inter->CanHibernate().value().contains("yes");
if (can_hibernate) { if (can_hibernate) {
QMap<QString, QVariant> hibernate; QMap<QString, QVariant> hibernate;

View File

@ -104,7 +104,6 @@ SinkInputWidget::SinkInputWidget(const QString &inputPath, QWidget *parent)
connect(m_volumeSlider, &VolumeSlider::valueChanged, this, &SinkInputWidget::setVolume); connect(m_volumeSlider, &VolumeSlider::valueChanged, this, &SinkInputWidget::setVolume);
connect(m_volumeSlider, &VolumeSlider::valueChanged, this, &SinkInputWidget::onVolumeChanged); connect(m_volumeSlider, &VolumeSlider::valueChanged, this, &SinkInputWidget::onVolumeChanged);
// connect(m_volumeSlider, &VolumeSlider::requestPlaySoundEffect, this, &SinkInputWidget::onPlaySoundEffect); // connect(m_volumeSlider, &VolumeSlider::requestPlaySoundEffect, this, &SinkInputWidget::onPlaySoundEffect);
connect(m_appBtn, &DImageButton::clicked, this, &SinkInputWidget::setMute);
connect(m_volumeBtnMin, &DImageButton::clicked, this, &SinkInputWidget::setMute); connect(m_volumeBtnMin, &DImageButton::clicked, this, &SinkInputWidget::setMute);
connect(m_inputInter, &DBusSinkInput::MuteChanged, this, &SinkInputWidget::setMuteIcon); connect(m_inputInter, &DBusSinkInput::MuteChanged, this, &SinkInputWidget::setMuteIcon);
connect(m_inputInter, &DBusSinkInput::VolumeChanged, this, [ = ] { connect(m_inputInter, &DBusSinkInput::VolumeChanged, this, [ = ] {
@ -140,35 +139,34 @@ void SinkInputWidget::setMute()
void SinkInputWidget::setMuteIcon() void SinkInputWidget::setMuteIcon()
{ {
//app应用为静音时只需要将音量图标设置成静音无需将应用图标设置为静音图标 if (m_inputInter->mute()) {
// if (m_inputInter->mute()) { const auto ratio = devicePixelRatioF();
// const auto ratio = devicePixelRatioF(); QString iconString = "audio-volume-muted-symbolic";
// QString iconString = "audio-volume-muted-symbolic"; if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
// if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) { iconString.append("-dark");
// iconString.append("-dark"); }
// } QPixmap muteIcon = QIcon::fromTheme(iconString).pixmap(ICON_SIZE * ratio, ICON_SIZE * ratio);
// QPixmap muteIcon = QIcon::fromTheme(iconString).pixmap(ICON_SIZE * ratio, ICON_SIZE * ratio); muteIcon.setDevicePixelRatio(ratio);
// muteIcon.setDevicePixelRatio(ratio); QPixmap appIconSource(getIconFromTheme(m_inputInter->icon(), QSize(ICON_SIZE, ICON_SIZE), devicePixelRatioF()));
// QPixmap appIconSource(getIconFromTheme(m_inputInter->icon(), QSize(ICON_SIZE, ICON_SIZE), devicePixelRatioF()));
// QPixmap temp(appIconSource.size()); QPixmap temp(appIconSource.size());
// temp.fill(Qt::transparent); temp.fill(Qt::transparent);
// temp.setDevicePixelRatio(ratio); temp.setDevicePixelRatio(ratio);
// QPainter p1(&temp); QPainter p1(&temp);
// p1.drawPixmap(0, 0, appIconSource); p1.drawPixmap(0, 0, appIconSource);
// p1.setCompositionMode(QPainter::CompositionMode_DestinationIn); p1.setCompositionMode(QPainter::CompositionMode_DestinationIn);
// p1.fillRect(temp.rect(), QColor(0, 0, 0, 40)); p1.fillRect(temp.rect(), QColor(0, 0, 0, 40));
// p1.end(); p1.end();
// appIconSource = temp; appIconSource = temp;
// QPainter p(&appIconSource); QPainter p(&appIconSource);
// p.drawPixmap(0, 0, muteIcon); p.drawPixmap(0, 0, muteIcon);
// appIconSource.setDevicePixelRatio(ratio); appIconSource.setDevicePixelRatio(ratio);
// m_appBtn->setPixmap(appIconSource); m_volumeBtnMin->setPixmap(appIconSource);
// } else { } else {
// m_appBtn->setPixmap(getIconFromTheme(m_inputInter->icon(), QSize(ICON_SIZE, ICON_SIZE), devicePixelRatioF())); m_volumeBtnMin->setPixmap(getIconFromTheme(m_inputInter->icon(), QSize(ICON_SIZE, ICON_SIZE), devicePixelRatioF()));
// } }
refreshIcon(); refreshIcon();
} }
@ -184,22 +182,7 @@ void SinkInputWidget::refreshIcon()
if (!m_inputInter) if (!m_inputInter)
return; return;
const float volume = m_inputInter->volume(); QString iconLeft = QString(m_inputInter->mute() ? "audio-volume-muted-symbolic" : "audio-volume-low-symbolic");
const bool mute = m_inputInter->mute();
QString volumeString;
if (mute) {
volumeString = "muted";
} else if (volume >= double(2) / 3) {
volumeString = "high";
} else if (volume >= double(1) / 3) {
volumeString = "medium";
} else {
volumeString = "low";
}
QString iconLeft = QString("audio-volume-%1-symbolic").arg(volumeString);
QString iconRight = QString("audio-volume-high-symbolic"); QString iconRight = QString("audio-volume-high-symbolic");
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) { if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
@ -213,7 +196,6 @@ void SinkInputWidget::refreshIcon()
ret = ImageUtil::loadSvg(iconLeft, ":/", ICON_SIZE, ratio); ret = ImageUtil::loadSvg(iconLeft, ":/", ICON_SIZE, ratio);
m_volumeBtnMin->setPixmap(ret); m_volumeBtnMin->setPixmap(ret);
} }
void SinkInputWidget:: onVolumeChanged() void SinkInputWidget:: onVolumeChanged()

View File

@ -152,6 +152,11 @@ int SoundApplet::volumeValue() const
return m_volumeSlider->value(); return m_volumeSlider->value();
} }
int SoundApplet::maxVolumeValue() const
{
return m_volumeSlider->maximum();
}
VolumeSlider *SoundApplet::mainSlider() VolumeSlider *SoundApplet::mainSlider()
{ {
return m_volumeSlider; return m_volumeSlider;

View File

@ -41,6 +41,7 @@ public:
explicit SoundApplet(QWidget *parent = 0); explicit SoundApplet(QWidget *parent = 0);
int volumeValue() const; int volumeValue() const;
int maxVolumeValue() const;
VolumeSlider *mainSlider(); VolumeSlider *mainSlider();
signals: signals:
void volumeChanged(const int value) const; void volumeChanged(const int value) const;

View File

@ -160,6 +160,7 @@ void SoundItem::refreshIcon()
return; return;
const double volmue = m_applet->volumeValue(); const double volmue = m_applet->volumeValue();
const double maxVolmue = m_applet->maxVolumeValue();
const bool mute = m_sinkInter->mute(); const bool mute = m_sinkInter->mute();
const Dock::DisplayMode displayMode = Dock::DisplayMode::Efficient; const Dock::DisplayMode displayMode = Dock::DisplayMode::Efficient;
@ -179,9 +180,11 @@ void SoundItem::refreshIcon()
QString volumeString; QString volumeString;
if (mute) if (mute)
volumeString = "muted"; volumeString = "muted";
else if (volmue / 100.0f >= double(2) / 3) else if (int(volmue) == 0)
volumeString = "off";
else if (volmue / maxVolmue >= double(2) / 3)
volumeString = "high"; volumeString = "high";
else if (volmue / 100.0f >= double(1) / 3) else if (volmue / maxVolmue >= double(1) / 3)
volumeString = "medium"; volumeString = "medium";
else else
volumeString = "low"; volumeString = "low";

View File

@ -424,21 +424,22 @@
<translation>Capacity %1 ...</translation> <translation>Capacity %1 ...</translation>
</message> </message>
<message> <message>
<location filename="../plugins/power/powerplugin.cpp" line="274"/> <source>Charged</source>
<source>Charging %1, %2 min until full</source> <translation>Charged</translation>
<translation>Charging %1, %2 min until full</translation>
</message>
<message>
<location filename="../plugins/power/powerplugin.cpp" line="276"/>
<location filename="../plugins/power/powerplugin.cpp" line="282"/>
<source>Charging %1</source>
<translation>Charging %1</translation>
</message> </message>
<message> <message>
<location filename="../plugins/power/powerplugin.cpp" line="280"/> <location filename="../plugins/power/powerplugin.cpp" line="280"/>
<source>Charging %1, %2 hr %3 min until full</source> <source>Charging %1, %2 hr %3 min until full</source>
<translation>Charging %1, %2 hr %3 min until full</translation> <translation>Charging %1, %2 hr %3 min until full</translation>
</message> </message>
<message>
<source>Capacity %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Charging %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ShowDesktopPlugin</name> <name>ShowDesktopPlugin</name>