Skip to content

Commit 47567c8

Browse files
author
ThePBone
committed
Better window handling
1 parent 7b6c5a6 commit 47567c8

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

main.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <QApplication>
99
#include <QSystemTrayIcon>
1010
#include <QCommandLineParser>
11+
#include <QDesktopWidget>
1112
#include <QDebug>
1213
#include <string>
1314
#include <iostream>
@@ -35,8 +36,15 @@ int main(int argc, char *argv[])
3536

3637
QApplication::setQuitOnLastWindowClosed( false );
3738
MainWindow w(QString::fromLocal8Bit(exepath),parser.isSet(tray),parser.isSet(minst));
38-
//QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
3939
w.setFixedSize(w.geometry().width(),w.geometry().height());
40+
w.setGeometry(
41+
QStyle::alignedRect(
42+
Qt::LeftToRight,
43+
Qt::AlignCenter,
44+
w.size(),
45+
qApp->desktop()->availableGeometry()
46+
)
47+
);
4048
w.setWindowFlags(Qt::WindowContextHelpButtonHint | Qt::WindowCloseButtonHint);
4149
if(!parser.isSet(tray)) w.show();
4250

mainwindow.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,27 @@ void MainWindow::DialogHandler(){
516516

517517
WAF::Animation::sideSlideIn(host, WAF::BottomSide);
518518
}
519-
else if(sender() == ui->cpreset)
519+
else if(sender() == ui->cpreset){
520+
if(preset_dlg->isVisible()){
521+
//Hacky workaround to reliably raise the window on all distros
522+
Qt::WindowFlags eFlags = preset_dlg->windowFlags();
523+
eFlags |= Qt::WindowStaysOnTopHint;
524+
preset_dlg->setWindowFlags(eFlags);
525+
preset_dlg->show();
526+
eFlags &= ~Qt::WindowStaysOnTopHint;
527+
preset_dlg->setWindowFlags(eFlags);
528+
preset_dlg->showNormal();
529+
preset_dlg->setWindowState( (windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
530+
preset_dlg->raise();
531+
preset_dlg->activateWindow();
532+
return;
533+
}
534+
535+
preset_dlg->move(x() + (width() - preset_dlg->width()) / 2,
536+
y() + (height() - preset_dlg->height()) / 2);
537+
520538
preset_dlg->show();
539+
}
521540
}
522541
void MainWindow::OpenLog(){
523542
log_dlg->show();

0 commit comments

Comments
 (0)