mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
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:
commit
ac6a590b37
@ -22,6 +22,7 @@
|
||||
#include "window/mainwindow.h"
|
||||
#include "window/accessible.h"
|
||||
#include "util/themeappicon.h"
|
||||
#include "controller/dockitemmanager.h"
|
||||
|
||||
#include <QAccessible>
|
||||
#include <QDir>
|
||||
|
@ -99,8 +99,8 @@ private:
|
||||
void handleDragMove(QDragMoveEvent *e, bool isFilter);
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void resizeDockIcon();
|
||||
void calcuDockIconSize(const int w, const int h, PluginsItem *trashPlugin, PluginsItem *shutdownPlugin, PluginsItem *keyboardPlugin, PluginsItem *notificationPlugin);
|
||||
void resizeDesktopWidget();
|
||||
void calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, PluginsItem *shutdownPlugin, PluginsItem *keyboardPlugin, PluginsItem *notificationPlugin);
|
||||
void resizeDesktopWidget();
|
||||
public slots:
|
||||
void insertItem(const int index, DockItem *item);
|
||||
void removeItem(DockItem *item);
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "docksettings.h"
|
||||
#include "item/appitem.h"
|
||||
#include "util/utils.h"
|
||||
#include "controller/dockitemmanager.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QX11Info>
|
||||
@ -70,7 +71,7 @@ DockSettings::DockSettings(QWidget *parent)
|
||||
, m_keepShownAct(tr("Keep Shown"), this)
|
||||
, m_keepHiddenAct(tr("Keep Hidden"), 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_trashPluginShow(true)
|
||||
, m_isMouseMoveCause(false)
|
||||
@ -79,9 +80,12 @@ DockSettings::DockSettings(QWidget *parent)
|
||||
m_settingsMenu.setAccessibleName("settingsmenu");
|
||||
checkService();
|
||||
|
||||
m_primaryRawRect = m_displayInter->primaryRawRect();
|
||||
m_screenRawHeight = m_displayInter->screenRawHeight();
|
||||
m_screenRawWidth = m_displayInter->screenRawWidth();
|
||||
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());
|
||||
@ -151,10 +155,11 @@ DockSettings::DockSettings(QWidget *parent)
|
||||
connect(m_itemManager, &DockItemManager::itemRemoved, this, &DockSettings::dockItemCountChanged, 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, &DBusDisplay::ScreenHeightChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
|
||||
connect(m_displayInter, &DBusDisplay::ScreenWidthChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
|
||||
connect(m_displayInter, &DBusDisplay::PrimaryChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
|
||||
connect(m_displayInter, &DisplayInter::PrimaryRectChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
|
||||
connect(m_displayInter, &DisplayInter::ScreenHeightChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
|
||||
connect(m_displayInter, &DisplayInter::ScreenWidthChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
|
||||
connect(m_displayInter, &DisplayInter::PrimaryChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
|
||||
connect(m_displayInter, &DisplayInter::MonitorsChanged, this, &DockSettings::onMonitorListChanged);
|
||||
connect(GSettingsByTrash(), &QGSettings::changed, this, &DockSettings::onTrashGSettingsChanged);
|
||||
QTimer::singleShot(0, this, [=] {onGSettingsChanged("enable");});
|
||||
|
||||
@ -163,8 +168,8 @@ DockSettings::DockSettings(QWidget *parent)
|
||||
connect(app, &DApplication::iconThemeChanged, this, &DockSettings::gtkIconThemeChanged);
|
||||
}
|
||||
|
||||
calculateMultiScreensPos();
|
||||
calculateWindowConfig();
|
||||
updateForbidPostions();
|
||||
resetFrontendGeometry();
|
||||
|
||||
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()
|
||||
{
|
||||
static DockSettings settings;
|
||||
@ -190,33 +209,24 @@ const QRect DockSettings::primaryRect() const
|
||||
return rect;
|
||||
}
|
||||
|
||||
const QRect DockSettings::currentRect()
|
||||
const QRect DockSettings::currentRect() const
|
||||
{
|
||||
QRect rect;
|
||||
QString currentScrName;
|
||||
if (m_isMouseMoveCause) {
|
||||
rect = m_mouseCauseDockScreen->rect();
|
||||
currentScrName = m_mouseCauseDockScreen->name();
|
||||
} else {
|
||||
bool positionAllowed = false;
|
||||
QList<Monitor*> monitors = m_monitors.keys();
|
||||
for (Monitor *monitor : monitors) {
|
||||
switch (m_position) {
|
||||
case Top: positionAllowed = monitor->dockPosition().topDock; break;
|
||||
case Right: positionAllowed = monitor->dockPosition().rightDock; break;
|
||||
case Bottom: positionAllowed = monitor->dockPosition().bottomDock; break;
|
||||
case Left: positionAllowed = monitor->dockPosition().leftDock; break;
|
||||
}
|
||||
if (positionAllowed) {
|
||||
rect = monitor->rect();
|
||||
currentScrName = monitor->name();
|
||||
if (monitor->isPrimary())
|
||||
break;
|
||||
}
|
||||
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();
|
||||
if (monitor->isPrimary())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_currentScreen = currentScrName;
|
||||
m_currentRawRect = rect;
|
||||
qreal scale = qApp->primaryScreen()->devicePixelRatio();
|
||||
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 offsetY = (primaryRect.height() - size.height()) / 2;
|
||||
int margin = hide ? 0 : this->dockMargin();
|
||||
@ -267,7 +277,6 @@ const QRect DockSettings::windowRect(const Position position, const bool hide)
|
||||
case Bottom:
|
||||
p = QPoint(offsetX, primaryRect.height() - size.height() - margin);
|
||||
break;
|
||||
default: Q_UNREACHABLE();
|
||||
}
|
||||
|
||||
return QRect(primaryRect.topLeft() + p, size);
|
||||
@ -316,13 +325,9 @@ void DockSettings::showDockSettingsMenu()
|
||||
m_fashionModeAct.setChecked(m_displayMode == Fashion);
|
||||
m_efficientModeAct.setChecked(m_displayMode == Efficient);
|
||||
m_topPosAct.setChecked(m_position == Top);
|
||||
m_topPosAct.setEnabled(!m_forbidPositions.contains(Top));
|
||||
m_bottomPosAct.setChecked(m_position == Bottom);
|
||||
m_bottomPosAct.setEnabled(!m_forbidPositions.contains(Bottom));
|
||||
m_leftPosAct.setChecked(m_position == Left);
|
||||
m_leftPosAct.setEnabled(!m_forbidPositions.contains(Left));
|
||||
m_rightPosAct.setChecked(m_position == Right);
|
||||
m_rightPosAct.setEnabled(!m_forbidPositions.contains(Right));
|
||||
m_keepShownAct.setChecked(m_hideMode == KeepShowing);
|
||||
m_keepHiddenAct.setChecked(m_hideMode == KeepHidden);
|
||||
m_smartHideAct.setChecked(m_hideMode == SmartHide);
|
||||
@ -355,8 +360,7 @@ void DockSettings::menuActionClicked(QAction *action)
|
||||
if (action == &m_efficientModeAct)
|
||||
return m_dockInter->setDisplayMode(Efficient);
|
||||
|
||||
m_isMouseMoveCause = false;
|
||||
// calculateMultiScreensPos();
|
||||
calculateMultiScreensPos();
|
||||
if (action == &m_topPosAct)
|
||||
return m_dockInter->setPosition(Top);
|
||||
if (action == &m_bottomPosAct)
|
||||
@ -459,15 +463,16 @@ void DockSettings::dockItemCountChanged()
|
||||
void DockSettings::primaryScreenChanged()
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO;
|
||||
m_primaryRawRect = m_displayInter->primaryRawRect();
|
||||
m_screenRawHeight = m_displayInter->screenRawHeight();
|
||||
m_screenRawWidth = m_displayInter->screenRawWidth();
|
||||
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 dataChanged();
|
||||
calculateWindowConfig();
|
||||
|
||||
@ -492,77 +497,6 @@ void DockSettings::updateFrontendGeometry()
|
||||
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)
|
||||
{
|
||||
if (m_opacity == value) return;
|
||||
@ -580,7 +514,7 @@ void DockSettings::trayVisableCountChanged(const int &count)
|
||||
void DockSettings::calculateWindowConfig()
|
||||
{
|
||||
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) {
|
||||
m_dockWindowSize = EffICIENT_DEFAULT_HEIGHT;
|
||||
m_dockInter->setWindowSize(EffICIENT_DEFAULT_HEIGHT);
|
||||
@ -590,20 +524,17 @@ void DockSettings::calculateWindowConfig()
|
||||
case Top:
|
||||
case Bottom:
|
||||
m_mainWindowSize.setHeight(m_dockWindowSize);
|
||||
m_mainWindowSize.setWidth(primaryRect().width());
|
||||
m_mainWindowSize.setWidth(currentRect().width());
|
||||
break;
|
||||
|
||||
case Left:
|
||||
case Right:
|
||||
m_mainWindowSize.setHeight(primaryRect().height());
|
||||
m_mainWindowSize.setHeight(currentRect().height());
|
||||
m_mainWindowSize.setWidth(m_dockWindowSize);
|
||||
break;
|
||||
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
} 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) {
|
||||
m_dockWindowSize = FASHION_DEFAULT_HEIGHT;
|
||||
m_dockInter->setWindowSize(FASHION_DEFAULT_HEIGHT);
|
||||
@ -613,17 +544,15 @@ void DockSettings::calculateWindowConfig()
|
||||
case Top:
|
||||
case Bottom: {
|
||||
m_mainWindowSize.setHeight(m_dockWindowSize);
|
||||
m_mainWindowSize.setWidth(this->primaryRect().width() - MAINWINDOW_MARGIN * 2);
|
||||
m_mainWindowSize.setWidth(this->currentRect().width() - MAINWINDOW_MARGIN * 2);
|
||||
break;
|
||||
}
|
||||
case Left:
|
||||
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);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
} else {
|
||||
Q_ASSERT(false);
|
||||
@ -660,6 +589,7 @@ void DockSettings::checkService()
|
||||
|
||||
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);
|
||||
@ -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)
|
||||
{
|
||||
if (key != "enable") {
|
||||
@ -688,3 +884,25 @@ void DockSettings::onTrashGSettingsChanged(const QString &key)
|
||||
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);
|
||||
}
|
||||
|
@ -24,12 +24,10 @@
|
||||
#define DOCKSETTINGS_H
|
||||
|
||||
#include "constants.h"
|
||||
#include "dbus/dbusmenumanager.h"
|
||||
#include "dbus/dbusdisplay.h"
|
||||
#include "monitor.h"
|
||||
#include "controller/dockitemmanager.h"
|
||||
|
||||
#include <com_deepin_dde_daemon_dock.h>
|
||||
#include <com_deepin_daemon_display.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
@ -37,13 +35,11 @@
|
||||
#include <QObject>
|
||||
#include <QSize>
|
||||
|
||||
#include <QStyleFactory>
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
using namespace Dock;
|
||||
using DBusDock = com::deepin::dde::daemon::Dock;
|
||||
using DisplayInter = com::deepin::daemon::Display;
|
||||
|
||||
class DockItemManager;
|
||||
class DockSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -61,9 +57,10 @@ public:
|
||||
inline int narrowTimeout() const { return 100; }
|
||||
inline bool autoHide() const { return m_autoHide; }
|
||||
const QRect primaryRect() const;
|
||||
const QRect currentRect();
|
||||
const QRect currentRect() const;
|
||||
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; }
|
||||
@ -108,22 +105,29 @@ private slots:
|
||||
void dockItemCountChanged();
|
||||
void primaryScreenChanged();
|
||||
void resetFrontendGeometry();
|
||||
void updateForbidPostions();
|
||||
void onOpacityChanged(const double value);
|
||||
void trayVisableCountChanged(const int &count);
|
||||
void onWindowSizeChanged();
|
||||
void onTrashGSettingsChanged(const QString &key);
|
||||
void onMonitorListChanged(const QList<QDBusObjectPath> &mons);
|
||||
|
||||
private:
|
||||
DockSettings(QWidget *parent = 0);
|
||||
DockSettings(QWidget *parent = nullptr);
|
||||
DockSettings(DockSettings const &) = delete;
|
||||
DockSettings operator =(DockSettings const &) = delete;
|
||||
|
||||
bool test(const Position pos, const QList<QRect> &otherScreens) const;
|
||||
void calculateWindowConfig();
|
||||
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;
|
||||
@ -137,7 +141,7 @@ private:
|
||||
HideState m_hideState;
|
||||
DisplayMode m_displayMode;
|
||||
QRect m_primaryRawRect;
|
||||
QRect m_currentRawRect;
|
||||
mutable QRect m_currentRawRect;
|
||||
QRect m_frontendRect;
|
||||
|
||||
QMenu m_settingsMenu;
|
||||
@ -152,7 +156,7 @@ private:
|
||||
QAction m_keepHiddenAct;
|
||||
QAction m_smartHideAct;
|
||||
|
||||
DBusDisplay *m_displayInter;
|
||||
DisplayInter *m_displayInter;
|
||||
DockItemManager *m_itemManager;
|
||||
bool m_trashPluginShow;
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "panel/mainpanelcontrol.h"
|
||||
#include "controller/dockitemmanager.h"
|
||||
#include "util/utils.h"
|
||||
#include "util/docksettings.h"
|
||||
|
||||
#include <DStyle>
|
||||
#include <DPlatformWindowHandle>
|
||||
@ -113,9 +114,9 @@ const QPoint rawXPosition(const QPoint &scaledPos)
|
||||
QScreen const *screen = Utils::screenAtByScaled(scaledPos);
|
||||
|
||||
return screen ? screen->geometry().topLeft() +
|
||||
(scaledPos - screen->geometry().topLeft()) *
|
||||
screen->devicePixelRatio()
|
||||
: scaledPos;
|
||||
(scaledPos - screen->geometry().topLeft()) *
|
||||
screen->devicePixelRatio()
|
||||
: scaledPos;
|
||||
}
|
||||
|
||||
const QPoint scaledPos(const QPoint &rawXPos)
|
||||
@ -123,9 +124,9 @@ const QPoint scaledPos(const QPoint &rawXPos)
|
||||
QScreen const *screen = Utils::screenAt(rawXPos);
|
||||
|
||||
return screen
|
||||
? screen->geometry().topLeft() +
|
||||
(rawXPos - screen->geometry().topLeft()) / screen->devicePixelRatio()
|
||||
: rawXPos;
|
||||
? screen->geometry().topLeft() +
|
||||
(rawXPos - screen->geometry().topLeft()) / screen->devicePixelRatio()
|
||||
: rawXPos;
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
@ -134,7 +135,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
, m_mainPanel(new MainPanelControl(this))
|
||||
, m_platformWindowHandle(this)
|
||||
, 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_expandDelayTimer(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 pos_adjust = m_settings->hideMode() != HideMode::KeepShowing &&
|
||||
isHide &&
|
||||
m_panelShowAni->state() == QVariantAnimation::Stopped;
|
||||
isHide &&
|
||||
m_panelShowAni->state() == QVariantAnimation::Stopped;
|
||||
if (!pos_adjust) {
|
||||
m_mainPanel->move(0, 0);
|
||||
return QWidget::move(p);
|
||||
@ -538,7 +539,7 @@ void MainWindow::initConnections()
|
||||
connect(m_dragWidget, &DragWidget::dragPointOffset, this, &MainWindow::onMainWindowSizeChanged);
|
||||
connect(m_dragWidget, &DragWidget::dragFinished, this, &MainWindow::onDragFinished);
|
||||
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()
|
||||
@ -618,7 +619,7 @@ void MainWindow::updateGeometry()
|
||||
|
||||
//为了防止当后端发送错误值,然后发送正确值时,任务栏没有移动在相应的位置
|
||||
//当qt没有获取到屏幕资源时候,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;
|
||||
}
|
||||
|
||||
@ -643,7 +644,7 @@ void MainWindow::updateGeometry()
|
||||
|
||||
void MainWindow::getTrayVisableItemCount()
|
||||
{
|
||||
m_mainPanel->getTrayVisableItemCount();
|
||||
m_mainPanel->getTrayVisableItemCount();
|
||||
}
|
||||
|
||||
void MainWindow::clearStrutPartial()
|
||||
@ -668,7 +669,7 @@ void MainWindow::setStrutPartial()
|
||||
const Position side = m_curDockPos;
|
||||
const QPoint &p = rawXPosition(m_settings->windowRect(m_curDockPos).topLeft());
|
||||
const QSize &s = m_settings->windowSize();
|
||||
const QRect &primaryRawRect = m_settings->primaryRawRect();
|
||||
const QRect &primaryRawRect = m_settings->currentRawRect();
|
||||
|
||||
XcbMisc::Orientation orientation = XcbMisc::OrientationTop;
|
||||
uint strut = 0;
|
||||
@ -743,8 +744,7 @@ void MainWindow::expand()
|
||||
qApp->processEvents();
|
||||
setVisible(true);
|
||||
|
||||
if (m_panelHideAni->state() == QPropertyAnimation::Running)
|
||||
{
|
||||
if (m_panelHideAni->state() == QPropertyAnimation::Running) {
|
||||
m_panelHideAni->stop();
|
||||
emit m_panelHideAni->finished();
|
||||
}
|
||||
@ -825,15 +825,14 @@ void MainWindow::resetPanelEnvironment(const bool visible, const bool resetPosit
|
||||
void MainWindow::updatePanelVisible()
|
||||
{
|
||||
if (m_settings->hideMode() == KeepShowing) {
|
||||
if (m_regionMonitor->registered()){
|
||||
m_regionMonitor->unregisterRegion();
|
||||
if (!m_registerKey.isEmpty()) {
|
||||
m_eventInter->UnregisterArea(m_registerKey);
|
||||
}
|
||||
return expand();
|
||||
}
|
||||
|
||||
if (!m_regionMonitor->registered()){
|
||||
m_regionMonitor->registerRegion();
|
||||
m_regionMonitor->setCoordinateType(DRegionMonitor::ScaleRatio);
|
||||
if (m_registerKey.isEmpty()) {
|
||||
updateRegionMonitorWatch();
|
||||
}
|
||||
|
||||
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)
|
||||
return;
|
||||
|
||||
if (!isVisible())
|
||||
setVisible(true);
|
||||
|
||||
// QScreen *screen = Utils::screenAtByScaled(QPoint(x, y));
|
||||
}
|
||||
|
||||
void MainWindow::updateRegionMonitorWatch()
|
||||
@ -1048,18 +1052,46 @@ void MainWindow::updateRegionMonitorWatch()
|
||||
if (m_settings->hideMode() == KeepShowing)
|
||||
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();
|
||||
int val = 5;
|
||||
const int margin = m_settings->dockMargin();
|
||||
if (Dock::Top == m_curDockPos) {
|
||||
m_regionMonitor->setWatchedRegion(QRegion(margin * scale, 0, (m_settings->primaryRect().width() - margin*2) * scale, val *scale));
|
||||
} else if (Dock::Bottom == m_curDockPos) {
|
||||
m_regionMonitor->setWatchedRegion(QRegion(margin * scale, (m_settings->primaryRect().height() - val)* scale, (m_settings->primaryRect().width() - margin*2)*scale, val * scale));
|
||||
} else if (Dock::Left == m_curDockPos) {
|
||||
m_regionMonitor->setWatchedRegion(QRegion(0, margin * scale, val * scale, (m_settings->primaryRect().height() - margin*2) * scale));
|
||||
} else {
|
||||
m_regionMonitor->setWatchedRegion(QRegion((m_settings->primaryRect().width() - val) * scale, margin * scale, val * scale, (m_settings->primaryRect().height()- margin*2)*scale));
|
||||
int x, y, w, h;
|
||||
|
||||
switch (m_curDockPos) {
|
||||
case Dock::Top: {
|
||||
x = windowRect.topLeft().x();
|
||||
y = windowRect.topLeft().y();
|
||||
w = m_settings->primaryRect().width();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,34 +24,39 @@
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include "xcb/xcb_misc.h"
|
||||
#include "dbus/dbusdisplay.h"
|
||||
#include "dbus/dbusdockadaptors.h"
|
||||
#include "dbus/sni/statusnotifierwatcher_interface.h"
|
||||
#include "util/docksettings.h"
|
||||
#include "panel/mainpanelcontrol.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
#include <QRect>
|
||||
#include <com_deepin_api_xeventmonitor.h>
|
||||
|
||||
#include <DPlatformWindowHandle>
|
||||
#include <DWindowManagerHelper>
|
||||
#include <DBlurEffectWidget>
|
||||
#include <DGuiApplicationHelper>
|
||||
#include <DRegionMonitor>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
using XEventMonitor = ::com::deepin::api::XEventMonitor;
|
||||
|
||||
class DockSettings;
|
||||
class DragWidget;
|
||||
class MainPanel;
|
||||
class MainPanelControl;
|
||||
class DBusDockAdaptors;
|
||||
class QTimer;
|
||||
class MainWindow : public DBlurEffectWidget, public MainPanelDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
enum Flag{
|
||||
Motion = 1 << 0,
|
||||
Button = 1 << 1,
|
||||
Key = 1 << 2
|
||||
};
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
void setEffectEnabled(const bool enabled);
|
||||
void setComposite(const bool hasComposite);
|
||||
@ -83,7 +88,7 @@ private:
|
||||
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);
|
||||
void onRegionMonitorChanged();
|
||||
void onRegionMonitorChanged(int x, int y, const QString &key);
|
||||
void updateRegionMonitorWatch();
|
||||
void getTrayVisableItemCount();
|
||||
|
||||
@ -119,7 +124,9 @@ private:
|
||||
|
||||
DPlatformWindowHandle m_platformWindowHandle;
|
||||
DWindowManagerHelper *m_wmHelper;
|
||||
DRegionMonitor *m_regionMonitor;
|
||||
XEventMonitor *m_eventInter;
|
||||
QString m_registerKey;
|
||||
QStringList m_registerKeys;
|
||||
|
||||
QTimer *m_positionUpdateTimer;
|
||||
QTimer *m_expandDelayTimer;
|
||||
|
@ -247,14 +247,14 @@ void PowerPlugin::refreshTipsData()
|
||||
if (m_showTimeToFull)
|
||||
tips = tr("Capacity %1, %2 min remaining").arg(value).arg(min);
|
||||
else {
|
||||
tips = tr("Capacity %1").arg(value);
|
||||
tips = tr("Capacity %1");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (m_showTimeToFull)
|
||||
tips = tr("Capacity %1, %2 hr %3 min remaining").arg(value).arg(hour).arg(min);
|
||||
else {
|
||||
tips = tr("Capacity %1").arg(value);
|
||||
tips = tr("Capacity %1").arg(value).arg(hour);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,8 +34,7 @@
|
||||
using SystemPowerInter = com::deepin::system::Power;
|
||||
|
||||
// from https://upower.freedesktop.org/docs/Device.html#Device:State
|
||||
enum BatteryState
|
||||
{
|
||||
enum BatteryState {
|
||||
UNKNOWN = 0, // 未知
|
||||
CHARGING = 1, // 充电中
|
||||
DIS_CHARGING = 2, // 放电
|
||||
|
@ -83,27 +83,27 @@ QPixmap PowerStatusWidget::getBatteryIcon()
|
||||
percentageStr = "020";
|
||||
} else if (percentage <= 30) {
|
||||
percentageStr = "030";
|
||||
}else if (percentage <= 40) {
|
||||
} else if (percentage <= 40) {
|
||||
percentageStr = "040";
|
||||
} else if (percentage <= 50) {
|
||||
percentageStr = "050";
|
||||
}else if (percentage <= 60) {
|
||||
} else if (percentage <= 60) {
|
||||
percentageStr = "060";
|
||||
} else if (percentage <= 70) {
|
||||
percentageStr = "070";
|
||||
}else if (percentage < 80) {
|
||||
} else if (percentage < 80) {
|
||||
percentageStr = "080";
|
||||
} else if (percentage <= 90) {
|
||||
percentageStr = "090";
|
||||
}else if (percentage <= 100){
|
||||
} else if (percentage <= 100) {
|
||||
percentageStr = "100";
|
||||
} else {
|
||||
percentageStr = "100";
|
||||
}
|
||||
|
||||
QString iconStr = QString("battery-%1-%2")
|
||||
.arg(percentageStr)
|
||||
.arg(plugged ? "plugged-symbolic" : "symbolic");
|
||||
.arg(percentageStr)
|
||||
.arg(plugged ? "plugged-symbolic" : "symbolic");
|
||||
|
||||
if (height() <= PLUGIN_BACKGROUND_MIN_SIZE && DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType)
|
||||
iconStr.append(PLUGIN_MIN_ICON_NAME);
|
||||
|
@ -122,10 +122,10 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey)
|
||||
|
||||
QProcessEnvironment enviromentVar = QProcessEnvironment::systemEnvironment();
|
||||
bool can_sleep = enviromentVar.contains("POWER_CAN_SLEEP") ? QVariant(enviromentVar.value("POWER_CAN_SLEEP")).toBool()
|
||||
: valueByQSettings<bool>("Power", "sleep", true) &&
|
||||
m_login1Inter->CanSuspend().value().contains("yes");
|
||||
;
|
||||
if(can_sleep){
|
||||
: valueByQSettings<bool>("Power", "sleep", true) &&
|
||||
m_login1Inter->CanSuspend().value().contains("yes");
|
||||
;
|
||||
if (can_sleep) {
|
||||
QMap<QString, QVariant> suspend;
|
||||
suspend["itemId"] = "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()
|
||||
: checkSwap() && m_login1Inter->CanHibernate().value().contains("yes");
|
||||
: checkSwap() && m_login1Inter->CanHibernate().value().contains("yes");
|
||||
|
||||
if (can_hibernate) {
|
||||
QMap<QString, QVariant> hibernate;
|
||||
|
@ -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::onVolumeChanged);
|
||||
// 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_inputInter, &DBusSinkInput::MuteChanged, this, &SinkInputWidget::setMuteIcon);
|
||||
connect(m_inputInter, &DBusSinkInput::VolumeChanged, this, [ = ] {
|
||||
@ -140,35 +139,34 @@ void SinkInputWidget::setMute()
|
||||
|
||||
void SinkInputWidget::setMuteIcon()
|
||||
{
|
||||
//app应用为静音时,只需要将音量图标设置成静音,无需将应用图标设置为静音图标
|
||||
// if (m_inputInter->mute()) {
|
||||
// const auto ratio = devicePixelRatioF();
|
||||
// QString iconString = "audio-volume-muted-symbolic";
|
||||
// if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
|
||||
// iconString.append("-dark");
|
||||
// }
|
||||
// QPixmap muteIcon = QIcon::fromTheme(iconString).pixmap(ICON_SIZE * ratio, ICON_SIZE * ratio);
|
||||
// muteIcon.setDevicePixelRatio(ratio);
|
||||
// QPixmap appIconSource(getIconFromTheme(m_inputInter->icon(), QSize(ICON_SIZE, ICON_SIZE), devicePixelRatioF()));
|
||||
if (m_inputInter->mute()) {
|
||||
const auto ratio = devicePixelRatioF();
|
||||
QString iconString = "audio-volume-muted-symbolic";
|
||||
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
|
||||
iconString.append("-dark");
|
||||
}
|
||||
QPixmap muteIcon = QIcon::fromTheme(iconString).pixmap(ICON_SIZE * ratio, ICON_SIZE * ratio);
|
||||
muteIcon.setDevicePixelRatio(ratio);
|
||||
QPixmap appIconSource(getIconFromTheme(m_inputInter->icon(), QSize(ICON_SIZE, ICON_SIZE), devicePixelRatioF()));
|
||||
|
||||
// QPixmap temp(appIconSource.size());
|
||||
// temp.fill(Qt::transparent);
|
||||
// temp.setDevicePixelRatio(ratio);
|
||||
// QPainter p1(&temp);
|
||||
// p1.drawPixmap(0, 0, appIconSource);
|
||||
// p1.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||
// p1.fillRect(temp.rect(), QColor(0, 0, 0, 40));
|
||||
// p1.end();
|
||||
// appIconSource = temp;
|
||||
QPixmap temp(appIconSource.size());
|
||||
temp.fill(Qt::transparent);
|
||||
temp.setDevicePixelRatio(ratio);
|
||||
QPainter p1(&temp);
|
||||
p1.drawPixmap(0, 0, appIconSource);
|
||||
p1.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||
p1.fillRect(temp.rect(), QColor(0, 0, 0, 40));
|
||||
p1.end();
|
||||
appIconSource = temp;
|
||||
|
||||
// QPainter p(&appIconSource);
|
||||
// p.drawPixmap(0, 0, muteIcon);
|
||||
QPainter p(&appIconSource);
|
||||
p.drawPixmap(0, 0, muteIcon);
|
||||
|
||||
// appIconSource.setDevicePixelRatio(ratio);
|
||||
// m_appBtn->setPixmap(appIconSource);
|
||||
// } else {
|
||||
// m_appBtn->setPixmap(getIconFromTheme(m_inputInter->icon(), QSize(ICON_SIZE, ICON_SIZE), devicePixelRatioF()));
|
||||
// }
|
||||
appIconSource.setDevicePixelRatio(ratio);
|
||||
m_volumeBtnMin->setPixmap(appIconSource);
|
||||
} else {
|
||||
m_volumeBtnMin->setPixmap(getIconFromTheme(m_inputInter->icon(), QSize(ICON_SIZE, ICON_SIZE), devicePixelRatioF()));
|
||||
}
|
||||
|
||||
refreshIcon();
|
||||
}
|
||||
@ -184,22 +182,7 @@ void SinkInputWidget::refreshIcon()
|
||||
if (!m_inputInter)
|
||||
return;
|
||||
|
||||
const float volume = m_inputInter->volume();
|
||||
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 iconLeft = QString(m_inputInter->mute() ? "audio-volume-muted-symbolic" : "audio-volume-low-symbolic");
|
||||
QString iconRight = QString("audio-volume-high-symbolic");
|
||||
|
||||
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
|
||||
@ -213,7 +196,6 @@ void SinkInputWidget::refreshIcon()
|
||||
|
||||
ret = ImageUtil::loadSvg(iconLeft, ":/", ICON_SIZE, ratio);
|
||||
m_volumeBtnMin->setPixmap(ret);
|
||||
|
||||
}
|
||||
|
||||
void SinkInputWidget:: onVolumeChanged()
|
||||
|
@ -152,6 +152,11 @@ int SoundApplet::volumeValue() const
|
||||
return m_volumeSlider->value();
|
||||
}
|
||||
|
||||
int SoundApplet::maxVolumeValue() const
|
||||
{
|
||||
return m_volumeSlider->maximum();
|
||||
}
|
||||
|
||||
VolumeSlider *SoundApplet::mainSlider()
|
||||
{
|
||||
return m_volumeSlider;
|
||||
|
@ -41,6 +41,7 @@ public:
|
||||
explicit SoundApplet(QWidget *parent = 0);
|
||||
|
||||
int volumeValue() const;
|
||||
int maxVolumeValue() const;
|
||||
VolumeSlider *mainSlider();
|
||||
signals:
|
||||
void volumeChanged(const int value) const;
|
||||
|
@ -160,6 +160,7 @@ void SoundItem::refreshIcon()
|
||||
return;
|
||||
|
||||
const double volmue = m_applet->volumeValue();
|
||||
const double maxVolmue = m_applet->maxVolumeValue();
|
||||
const bool mute = m_sinkInter->mute();
|
||||
const Dock::DisplayMode displayMode = Dock::DisplayMode::Efficient;
|
||||
|
||||
@ -179,9 +180,11 @@ void SoundItem::refreshIcon()
|
||||
QString volumeString;
|
||||
if (mute)
|
||||
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";
|
||||
else if (volmue / 100.0f >= double(1) / 3)
|
||||
else if (volmue / maxVolmue >= double(1) / 3)
|
||||
volumeString = "medium";
|
||||
else
|
||||
volumeString = "low";
|
||||
|
@ -424,21 +424,22 @@
|
||||
<translation>Capacity %1 ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../plugins/power/powerplugin.cpp" line="274"/>
|
||||
<source>Charging %1, %2 min until full</source>
|
||||
<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>
|
||||
<source>Charged</source>
|
||||
<translation>Charged</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../plugins/power/powerplugin.cpp" line="280"/>
|
||||
<source>Charging %1, %2 hr %3 min until full</source>
|
||||
<translation>Charging %1, %2 hr %3 min until full</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Capacity %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Charging %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ShowDesktopPlugin</name>
|
||||
|
Loading…
x
Reference in New Issue
Block a user