修复无DXCB且WM不支持拖动情况下窗口的拖拽

This commit is contained in:
RigoLigo
2021-07-07 18:23:38 +08:00
parent 0729cfffb7
commit 0885b7ca13
5 changed files with 73 additions and 32 deletions

View File

@@ -162,6 +162,8 @@ SpkUi::SpkMainWidget::SpkMainWidget(QWidget *parent) : QFrame(parent)
HorizontalDivide->setSpacing(0);
HorizontalDivide->setContentsMargins(0, 0, 0, 0);
HorizontalDivide->setAlignment(Qt::AlignLeft);
if(!SpkUi::States::IsUsingDtkPlugin)
HorizontalDivide->addSpacing(SpkWindow::BorderWidth);
HorizontalDivide->addWidget(SideBarRestrictor);
HorizontalDivide->addLayout(VLayMain);

View File

@@ -28,6 +28,12 @@ namespace SpkUi
QSize PrimaryScreenSize;
SpkDtkPlugin *DtkPlugin = nullptr;
QStyle *OldSystemStyle = nullptr;
QList<QColor> CurrentColorSet;
namespace States
{
bool IsDDE = false, IsUsingDtkPlugin = false;
}
namespace Priv
{
@@ -51,7 +57,7 @@ namespace SpkUi
signal(SIGFPE, SpkUi::CrashSignalHandler);
// Prepare theme following for DDE
if(CheckIsDeepinDesktop())
if((States::IsDDE = CheckIsDeepinDesktop()))
PrepareForDeepinDesktop();
// Misc data initialization
@@ -83,12 +89,18 @@ namespace SpkUi
qApp->addLibraryPath("/usr/local/lib");
qApp->addLibraryPath("/usr/lib");
#endif
QPluginLoader p("libspkdtkplugin");
if(p.load())
if(!qgetenv("SPARK_NO_DTK_PLUGIN").toInt())
{
auto i = qobject_cast<SpkDtkPlugin*>(p.instance());
if(i)
DtkPlugin = i;
QPluginLoader p("libspkdtkplugin");
if(p.load())
{
auto i = qobject_cast<SpkDtkPlugin*>(p.instance());
if(i)
{
DtkPlugin = i;
States::IsUsingDtkPlugin = true;
}
}
}
// FIXME: Chameleon style kept adding unwanted blue focus indication border
@@ -117,26 +129,28 @@ namespace SpkUi
switch(aStyle)
{
case Light:
CurrentStylesheet = StylesheetFromColors(
QList<QColor>{
0x353535, 0x353535, 0xff0000, 0x0070ff, 0x2987ff,
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
ColorTextOnBackground(0x0070ff)
});
static auto LightColor = QList<QColor>{
0x353535, 0x353535, 0xff0000, 0x0070ff, 0x2987ff,
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
ColorTextOnBackground(0x0070ff)
};
CurrentStylesheet = StylesheetFromColors(LightColor);
qApp->setStyleSheet(CurrentStylesheet);
// TODO
ColorLine = Qt::black;
break;
case Dark:
CurrentStylesheet = StylesheetFromColors(
QList<QColor>{
0x353535, 0x353535, 0xff0000, 0x0070ff, 0x2987ff,
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
ColorTextOnBackground(0x0070ff)
});
static auto DarkColor = QList<QColor>{
0x353535, 0x353535, 0xff0000, 0x0070ff, 0x2987ff,
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
ColorTextOnBackground(0x0070ff)
};
CurrentStylesheet = StylesheetFromColors(DarkColor);
CurrentColorSet = DarkColor;
qApp->setStyleSheet(CurrentStylesheet);
ColorLine = Qt::white;
break;
// IDE complains about default label covering all conditions, commented
// default:
// sWarn(QObject::tr("SetGlobalStyle invoked with unknown style %1.")
// .arg(static_cast<int>(aStyle)));

View File

@@ -21,7 +21,7 @@ SpkWindow::SpkWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(paren
mCornerRadius = 5;
mUserCentralWidget = nullptr;
mResizable = true;
mResizing = false;
mMoving = mResizing = false;
mCloseHook = nullptr;
mMaximized = windowState().testFlag(Qt::WindowMaximized);
mUseCustomEvents = SpkUi::DtkPlugin == nullptr;
@@ -63,6 +63,17 @@ bool SpkWindow::event(QEvent *evt)
mEdgesBeingResized = edge;
return true;
}
else
{
if(!QMainWindow::event(evt) || 1)
{
mMoveOffset = e->globalPos() - pos();
setCursor(Qt::SizeAllCursor);
mMoving = true;
mResizing = false;
}
return true;
}
break;
}
case QEvent::MouseButtonRelease:
@@ -71,30 +82,39 @@ bool SpkWindow::event(QEvent *evt)
auto e = static_cast<QMouseEvent*>(evt);
if(e->button() != Qt::LeftButton) break;
mResizing = false;
mMoving = false;
unsetCursor();
return true;
break;
}
case QEvent::HoverMove:
{
if(mResizing || !mResizable) break;
if((mResizing || !mResizable) && !mMoving) break;
if(mMaximized)
{
unsetCursor();
break;
}
auto e = static_cast<QHoverEvent*>(evt);
auto edge = DetectEdgeOnThis(e->pos());
SetMouseCursor(edge);
if(mResizable && !mMoving)
{
auto e = static_cast<QHoverEvent*>(evt);
auto edge = DetectEdgeOnThis(e->pos());
SetMouseCursor(edge);
}
break;
}
case QEvent::MouseMove:
{
if(!mResizable) break;
if(mMaximized) break;
auto e = static_cast<QMouseEvent*>(evt);
if(mResizing && !mMaximized)
if(mResizing && mResizable)
{
ResizeWindowByCursor(e->globalPos());
return true;
return true; // Intercept resize movements
}
else if(mMoving)
{
move(e->globalPos() - mMoveOffset);
}
break;
}
@@ -221,8 +241,6 @@ void SpkWindow::SetWindowTheme(SpkWindow::SpkWindowStyle style)
case Dark:
SpkUi::SetGlobalStyle(SpkUi::SpkUiStyle::Dark);
break;
default:
;
}
}