Skip to content

Commit 04aecb3

Browse files
Some code cleanup, adjustments to match ADS coding style
1 parent 533d174 commit 04aecb3

File tree

7 files changed

+228
-109
lines changed

7 files changed

+228
-109
lines changed

src/DockFocusController.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ static void updateDockAreaFocusStyle(CDockAreaWidget* DockArea, bool Focused)
8383
#ifdef Q_OS_LINUX
8484
static void updateFloatingWidgetFocusStyle(CFloatingDockContainer* FloatingWidget, bool Focused)
8585
{
86-
if(FloatingWidget->hasNativeTitleBar()){
86+
if (FloatingWidget->hasNativeTitleBar())
87+
{
8788
return;
8889
}
8990
auto TitleBar = qobject_cast<CFloatingWidgetTitleBar*>(FloatingWidget->titleBarWidget());

src/DockManager.cpp

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -493,45 +493,62 @@ CDockManager::~CDockManager()
493493

494494
//============================================================================
495495
#ifdef Q_OS_LINUX
496-
bool CDockManager::eventFilter(QObject *obj, QEvent *e){
496+
bool CDockManager::eventFilter(QObject *obj, QEvent *e)
497+
{
497498
// Emulate Qt:Tool behaviour.
498499
// Required because on some WMs Tool windows can't be maximized.
499500

500501
// Window always on top of the MainWindow.
501-
if(e->type() == QEvent::WindowActivate){
502-
for(auto _window : floatingWidgets()){
503-
if(!_window->isVisible() || window()->isMinimized()){
502+
if (e->type() == QEvent::WindowActivate)
503+
{
504+
for (auto _window : floatingWidgets())
505+
{
506+
if (!_window->isVisible() || window()->isMinimized())
507+
{
504508
continue;
505509
}
506510
// setWindowFlags(Qt::WindowStaysOnTopHint) will hide the window and thus requires a show call.
507511
// This then leads to flickering and a nasty endless loop (also buggy behaviour on Ubuntu).
508512
// So we just do it ourself.
509-
internal::xcb_update_prop(true, _window->window()->winId(), "_NET_WM_STATE", "_NET_WM_STATE_ABOVE", "_NET_WM_STATE_STAYS_ON_TOP");
513+
internal::xcb_update_prop(true, _window->window()->winId(),
514+
"_NET_WM_STATE", "_NET_WM_STATE_ABOVE", "_NET_WM_STATE_STAYS_ON_TOP");
510515
}
511516
}
512-
else if(e->type() == QEvent::WindowDeactivate){
513-
for(auto _window : floatingWidgets()){
514-
if(!_window->isVisible() || window()->isMinimized()){
517+
else if (e->type() == QEvent::WindowDeactivate)
518+
{
519+
for (auto _window : floatingWidgets())
520+
{
521+
if (!_window->isVisible() || window()->isMinimized())
522+
{
515523
continue;
516524
}
517-
internal::xcb_update_prop(false, _window->window()->winId(), "_NET_WM_STATE", "_NET_WM_STATE_ABOVE", "_NET_WM_STATE_STAYS_ON_TOP");
525+
internal::xcb_update_prop(false, _window->window()->winId(),
526+
"_NET_WM_STATE", "_NET_WM_STATE_ABOVE", "_NET_WM_STATE_STAYS_ON_TOP");
518527
_window->raise();
519528
}
520529
}
521530

522531
// Sync minimize with MainWindow
523-
if(e->type() == QEvent::WindowStateChange){
524-
for(auto _window : floatingWidgets()){
525-
if(! _window->isVisible()){
532+
if (e->type() == QEvent::WindowStateChange)
533+
{
534+
for (auto _window : floatingWidgets())
535+
{
536+
if (! _window->isVisible())
537+
{
526538
continue;
527539
}
528-
if(window()->isMinimized()){
540+
541+
if (window()->isMinimized())
542+
{
529543
_window->showMinimized();
530-
} else {
544+
}
545+
else
546+
{
531547
_window->setWindowState(_window->windowState() & (~Qt::WindowMinimized));
532548
}
533549
}
534-
if(!window()->isMinimized()){
550+
if (!window()->isMinimized())
551+
{
535552
QApplication::setActiveWindow(window());
536553
}
537554
}

src/FloatingDockContainer.cpp

Lines changed: 77 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ struct FloatingDockContainerPrivate
411411
void setWindowTitle(const QString &Text)
412412
{
413413
#ifdef Q_OS_LINUX
414-
if(TitleBar){
414+
if (TitleBar)
415+
{
415416
TitleBar->setTitle(Text);
416417
}
417418
#endif
@@ -610,24 +611,40 @@ CFloatingDockContainer::CFloatingDockContainer(CDockManager *DockManager) :
610611
QDockWidget::setFloating(true);
611612
QDockWidget::setFeatures(QDockWidget::AllDockWidgetFeatures);
612613

613-
// KDE doesn't seem to fire MoveEvents while moving windows, so for now no native titlebar for everything using KWin.
614-
QString window_manager = internal::windowManager().toUpper().split(" ")[0];
615-
bool native_window = window_manager != "KWIN";
614+
bool native_window = true;
615+
616616
// FloatingContainerForce*TitleBar is overwritten by the "ADS_UseNativeTitle" environment variable if set.
617617
auto env = qgetenv("ADS_UseNativeTitle").toUpper();
618-
if (env == "1"){
618+
if (env == "1")
619+
{
619620
native_window = true;
620-
} else if (env == "0"){
621+
}
622+
else if (env == "0")
623+
{
621624
native_window = false;
622-
} else if ( DockManager->testConfigFlag( CDockManager::FloatingContainerForceNativeTitleBar )){
625+
}
626+
else if (DockManager->testConfigFlag(CDockManager::FloatingContainerForceNativeTitleBar))
627+
{
623628
native_window = true;
624-
} else if ( DockManager->testConfigFlag( CDockManager::FloatingContainerForceCustomTitleBar )){
629+
}
630+
else if (DockManager->testConfigFlag(CDockManager::FloatingContainerForceCustomTitleBar))
631+
{
625632
native_window = false;
626633
}
627-
if(native_window){
634+
else
635+
{
636+
// KDE doesn't seem to fire MoveEvents while moving windows, so for now no native titlebar for everything using KWin.
637+
QString window_manager = internal::windowManager().toUpper().split(" ")[0];
638+
bool native_window = window_manager != "KWIN";
639+
}
640+
641+
if (native_window)
642+
{
628643
setTitleBarWidget(new QWidget());
629644
setWindowFlags(Qt::Window | Qt::WindowMaximizeButtonHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
630-
} else {
645+
}
646+
else
647+
{
631648
d->TitleBar = new CFloatingWidgetTitleBar(this);
632649
setTitleBarWidget(d->TitleBar);
633650
setWindowFlags(Qt::Window | Qt::WindowMinMaxButtonsHint | Qt::FramelessWindowHint);
@@ -705,7 +722,8 @@ void CFloatingDockContainer::changeEvent(QEvent *event)
705722
d->zOrderIndex = ++zOrderCounter;
706723

707724
#ifdef Q_OS_LINUX
708-
if(d->DraggingState == DraggingFloatingWidget){
725+
if (d->DraggingState == DraggingFloatingWidget)
726+
{
709727
d->titleMouseReleaseEvent();
710728
d->DraggingState = DraggingInactive;
711729
}
@@ -848,20 +866,13 @@ void CFloatingDockContainer::showEvent(QShowEvent *event)
848866
void CFloatingDockContainer::startFloating(const QPoint &DragStartMousePos,
849867
const QSize &Size, eDragState DragState, QWidget *MouseEventHandler)
850868
{
851-
#ifndef Q_OS_LINUX
852-
Q_UNUSED(MouseEventHandler)
853-
#endif
854869
#ifdef Q_OS_LINUX
855-
if (!isMaximized()) {
870+
if (!isMaximized())
871+
{
856872
resize(Size);
857873
d->DragStartMousePosition = DragStartMousePos;
858874
}
859-
#else
860-
resize(Size);
861-
d->DragStartMousePosition = DragStartMousePos;
862-
#endif
863875
d->setState(DragState);
864-
#ifdef Q_OS_LINUX
865876
if (DraggingFloatingWidget == DragState)
866877
{
867878
d->MouseEventHandler = MouseEventHandler;
@@ -870,15 +881,20 @@ void CFloatingDockContainer::startFloating(const QPoint &DragStartMousePos,
870881
d->MouseEventHandler->grabMouse();
871882
}
872883
}
873-
#endif
874-
#ifdef Q_OS_LINUX
875-
if (!isMaximized()) {
884+
885+
if (!isMaximized())
886+
{
876887
moveFloating();
877888
}
889+
show();
878890
#else
891+
Q_UNUSED(MouseEventHandler)
892+
resize(Size);
893+
d->DragStartMousePosition = DragStartMousePos;
894+
d->setState(DragState);
879895
moveFloating();
880-
#endif
881896
show();
897+
#endif
882898
}
883899

884900
//============================================================================
@@ -988,7 +1004,8 @@ bool CFloatingDockContainer::restoreState(CDockingStateReader &Stream,
9881004
}
9891005
onDockAreasAddedOrRemoved();
9901006
#ifdef Q_OS_LINUX
991-
if(d->TitleBar){
1007+
if(d->TitleBar)
1008+
{
9921009
d->TitleBar->setMaximizedIcon(windowState() == Qt::WindowMaximized);
9931010
}
9941011
#endif
@@ -1134,15 +1151,21 @@ void CFloatingDockContainer::moveEvent(QMoveEvent *event)
11341151

11351152

11361153
#ifdef Q_OS_LINUX
1154+
//============================================================================
11371155
void CFloatingDockContainer::onMaximizeRequest()
11381156
{
1139-
if(windowState() == Qt::WindowMaximized){
1157+
if (windowState() == Qt::WindowMaximized)
1158+
{
11401159
showNormal();
1141-
}else{
1160+
}
1161+
else
1162+
{
11421163
showMaximized();
11431164
}
11441165
}
11451166

1167+
1168+
//============================================================================
11461169
void CFloatingDockContainer::showNormal(bool fixGeometry)
11471170
{
11481171
if (windowState() == Qt::WindowMaximized)
@@ -1154,45 +1177,65 @@ void CFloatingDockContainer::showNormal(bool fixGeometry)
11541177
setGeometry(oldNormal);
11551178
}
11561179
}
1157-
if(d->TitleBar){
1180+
if(d->TitleBar)
1181+
{
11581182
d->TitleBar->setMaximizedIcon(false);
11591183
}
11601184
}
11611185

1186+
1187+
//============================================================================
11621188
void CFloatingDockContainer::showMaximized()
11631189
{
11641190
Super::showMaximized();
1165-
if(d->TitleBar){
1191+
if (d->TitleBar)
1192+
{
11661193
d->TitleBar->setMaximizedIcon(true);
11671194
}
11681195
}
11691196

1197+
1198+
//============================================================================
11701199
bool CFloatingDockContainer::isMaximized() const
11711200
{
11721201
return windowState() == Qt::WindowMaximized;
11731202
}
11741203

1175-
void CFloatingDockContainer::show(){
1204+
1205+
//============================================================================
1206+
void CFloatingDockContainer::show()
1207+
{
11761208
// Prevent this window from showing in the taskbar and pager (alt+tab)
11771209
internal::xcb_add_prop(true, winId(), "_NET_WM_STATE", "_NET_WM_STATE_SKIP_TASKBAR");
11781210
internal::xcb_add_prop(true, winId(), "_NET_WM_STATE", "_NET_WM_STATE_SKIP_PAGER");
11791211
Super::show();
11801212
}
1181-
void CFloatingDockContainer::resizeEvent(QResizeEvent *event){
1213+
1214+
1215+
//============================================================================
1216+
void CFloatingDockContainer::resizeEvent(QResizeEvent *event)
1217+
{
11821218
d->IsResizing = true;
11831219
Super::resizeEvent(event);
11841220
}
11851221

1186-
void CFloatingDockContainer::moveEvent(QMoveEvent *event){
1222+
1223+
//============================================================================
1224+
void CFloatingDockContainer::moveEvent(QMoveEvent *event)
1225+
{
11871226
Super::moveEvent(event);
1188-
if(!d->IsResizing && event->spontaneous()){
1227+
if (!d->IsResizing && event->spontaneous())
1228+
{
11891229
d->DraggingState = DraggingFloatingWidget;
11901230
d->updateDropOverlays(QCursor::pos());
11911231
}
11921232
d->IsResizing = false;
11931233
}
11941234

1195-
bool CFloatingDockContainer::hasNativeTitleBar(){
1235+
1236+
//============================================================================
1237+
bool CFloatingDockContainer::hasNativeTitleBar()
1238+
{
11961239
return d->TitleBar == nullptr;
11971240
}
11981241
#endif

src/FloatingDockContainer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ private slots:
284284
*/
285285
void show();
286286

287+
/**
288+
* Returns true if the floating widget has a native titlebar or false if
289+
* the floating widget has a QWidget based title bar
290+
*/
287291
bool hasNativeTitleBar();
288292
#endif
289293

0 commit comments

Comments
 (0)