1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-23 01:33:50 +03:00

provide CanvasGeometry from View::Positioner

--View::Positioner is now responsible to provide
the proper Canvas config window geometry
This commit is contained in:
Michail Vourlakos 2020-07-09 09:20:33 +03:00
parent fa83db7825
commit e74e013f43
4 changed files with 78 additions and 55 deletions

View File

@ -485,8 +485,10 @@ void Positioner::immediateSyncGeometry()
}
m_view->effects()->updateEnabledBorders();
resizeWindow(availableScreenRect);
updatePosition(availableScreenRect);
updateCanvasGeometry(availableScreenRect);
qDebug() << "syncGeometry() calculations for screen: " << m_view->screen()->name() << " _ " << m_view->screen()->geometry();
qDebug() << "syncGeometry() calculations for edge: " << m_view->location();
@ -504,6 +506,22 @@ void Positioner::validateDockGeometry()
}
}
QRect Positioner::canvasGeometry()
{
return m_canvasGeometry;
}
void Positioner::setCanvasGeometry(const QRect &geometry)
{
if (m_canvasGeometry == geometry) {
return;
}
m_canvasGeometry = geometry;
emit canvasGeometryChanged();
}
//! this is used mainly from vertical panels in order to
//! to get the maximum geometry that can be used from the dock
//! based on their alignment type and the location dock
@ -573,6 +591,48 @@ void Positioner::validateTopBottomBorders(QRect availableScreenRect, QRegion ava
}
}
void Positioner::updateCanvasGeometry(QRect availableScreenRect)
{
QRect canvas;
QRect screenGeometry{m_view->screen()->geometry()};
int thickness{m_view->editThickness()};
if (m_view->formFactor() == Plasma::Types::Vertical) {
canvas.setWidth(thickness);
canvas.setHeight(availableScreenRect.height());
} else {
canvas.setWidth(screenGeometry.width());
canvas.setHeight(thickness);
}
switch (m_view->location()) {
case Plasma::Types::TopEdge:
canvas.moveLeft(screenGeometry.x());
canvas.moveTop(screenGeometry.y());
break;
case Plasma::Types::BottomEdge:
canvas.moveLeft(screenGeometry.x());
canvas.moveTop(screenGeometry.bottom() - thickness + 1);
break;
case Plasma::Types::RightEdge:
canvas.moveLeft(screenGeometry.right() - thickness + 1);
canvas.moveTop(availableScreenRect.y());
break;
case Plasma::Types::LeftEdge:
canvas.moveLeft(availableScreenRect.x());
canvas.moveTop(availableScreenRect.y());
break;
default:
qWarning() << "wrong location, couldn't update the canvas config window geometry " << m_view->location();
}
setCanvasGeometry(canvas);
}
void Positioner::updatePosition(QRect availableScreenRect)
{
QRect screenGeometry{availableScreenRect};

View File

@ -80,6 +80,8 @@ public:
bool isStickedOnBottomEdge() const;
void setIsStickedOnBottomEdge(bool sticked);
QRect canvasGeometry();
void setScreenToFollow(QScreen *scr, bool updateScreenId = true);
void reconsiderScreen();
@ -97,6 +99,7 @@ public slots:
void initDelayedSignals();
signals:
void canvasGeometryChanged();
void currentScreenChanged();
void edgeChanged();
void screenGeometryChanged();
@ -137,13 +140,16 @@ private slots:
private:
void init();
void initSignalingForLocationChangeSliding();
void resizeWindow(QRect availableScreenRect = QRect());
void updateFormFactor();
void resizeWindow(QRect availableScreenRect = QRect());
void updatePosition(QRect availableScreenRect = QRect());
void updateCanvasGeometry(QRect availableScreenRect = QRect());
void validateTopBottomBorders(QRect availableScreenRect, QRegion availableScreenRegion);
void setCanvasGeometry(const QRect &geometry);
QRect maximumNormalGeometry();
private:
@ -156,6 +162,7 @@ private:
int m_slideOffset{0};
QRect m_canvasGeometry;
//! it is used in order to enforce X11 to never miss window geometry
QRect m_validGeometry;

View File

@ -46,7 +46,7 @@ CanvasConfigView::CanvasConfigView(Latte::View *view, PrimaryConfigView *parent)
{
setResizeMode(QQuickView::SizeRootObjectToView);
connections << connect(m_parent, &PrimaryConfigView::availableScreenGeometryChanged, this, &CanvasConfigView::syncGeometry);
//connections << connect(m_parent, &PrimaryConfigView::availableScreenGeometryChanged, this, &CanvasConfigView::syncGeometry);
setParentView(view);
init();
@ -79,6 +79,8 @@ void CanvasConfigView::initParentView(Latte::View *view)
{
SubConfigView::initParentView(view);
viewconnections << connect(m_latteView->positioner(), &ViewPart::Positioner::canvasGeometryChanged, this, &CanvasConfigView::syncGeometry);
updateEnabledBorders();
syncGeometry();
@ -91,55 +93,9 @@ void CanvasConfigView::syncGeometry()
return;
}
const auto location = m_latteView->containment()->location();
const auto scrGeometry = m_latteView->screenGeometry();
const auto availGeometry = m_parent->availableScreenGeometry();
QSize size;
int editThickness = m_latteView->editThickness();
QPoint position{0, 0};
int xPos{0};
int yPos{0};
switch (m_latteView->containment()->formFactor()) {
case Plasma::Types::Horizontal: {
xPos = availGeometry.x();
size.setWidth(availGeometry.width());
size.setHeight(editThickness);
if (location == Plasma::Types::TopEdge) {
yPos = scrGeometry.y();
} else if (location == Plasma::Types::BottomEdge) {
yPos = scrGeometry.y() + scrGeometry.height() - editThickness;
}
}
break;
case Plasma::Types::Vertical: {
yPos = availGeometry.y();
size.setWidth(editThickness);
size.setHeight(availGeometry.height());
if (location == Plasma::Types::LeftEdge) {
xPos = scrGeometry.x();
} else if (location == Plasma::Types::RightEdge) {
xPos = scrGeometry.x() + scrGeometry.width() - editThickness;
}
}
break;
default:
qWarning() << "no sync geometry, wrong formFactor";
break;
}
position = {xPos, yPos};
updateEnabledBorders();
auto geometry = QRect(position.x(), position.y(), size.width(), size.height());
auto geometry = m_latteView->positioner()->canvasGeometry();
if (m_geometryWhenVisible == geometry) {
return;
@ -147,15 +103,15 @@ void CanvasConfigView::syncGeometry()
m_geometryWhenVisible = geometry;
setPosition(position);
setPosition(geometry.topLeft());
if (m_shellSurface) {
m_shellSurface->setPosition(position);
m_shellSurface->setPosition(geometry.topLeft());
}
setMaximumSize(size);
setMinimumSize(size);
resize(size);
setMaximumSize(geometry.size());
setMinimumSize(geometry.size());
resize(geometry.size());
//! after placement request to activate the main config window in order to avoid
//! rare cases of closing settings window from secondaryConfigView->focusOutEvent

View File

@ -168,7 +168,7 @@ void SubConfigView::initParentView(Latte::View *view)
m_latteView = view;
viewconnections << connect(m_latteView->visibility(), &VisibilityManager::modeChanged, this, &SubConfigView::syncGeometry);
viewconnections << connect(m_latteView, &Latte::View::normalThicknessChanged, [&]() {
viewconnections << connect(m_latteView, &Latte::View::editThicknessChanged, [&]() {
m_thicknessSyncTimer.start();
});