fixed multi monitor support

This commit is contained in:
Hane 2024-04-10 22:23:17 +02:00
commit e4732d086b
2 changed files with 43 additions and 13 deletions

View file

@ -26,22 +26,37 @@ void ExtendedCheckBox::customEvent(QEvent* ev) {
} }
QRect MainWindow::setSizePosition(int width, int height) { QRect MainWindow::setSizePosition(int width, int height) {
//setGeometry ignores decoration size xdddd //setGeometry ignores decoration size, theres others for that
QRect trayIconPos = this->trayIcon->geometry(); QRect trayIconPos = this->trayIcon->geometry();
int tix1, tix2, tiy1, tiy2; int tix1, tix2, tiy1, tiy2;
trayIconPos.getCoords(&tix1, &tiy1, &tix2, &tiy2); trayIconPos.getCoords(&tix1, &tiy1, &tix2, &tiy2);
log_debugcpp("Tray Icon Pos: " + std::to_string(tix1) + " " + std::to_string(tix2)+" " + std::to_string(tiy1) + " " + std::to_string(tiy2));
screen = this->getCurrentScreen();
log_debugcpp("Screen: " + screen->model().toStdString() + " " + screen->name().toStdString());
this->setScreen(screen);
screen = QGuiApplication::primaryScreen();
QRect screenRes = screen->geometry(); QRect screenRes = screen->geometry();
int srx1, srx2, sry1, sry2; int srx1, srx2, sry1, sry2;
screenRes.getCoords(&srx1, &sry1, &srx2, &sry2); screenRes.getCoords(&srx1, &sry1, &srx2, &sry2);
log_debugcpp("Screen Res: " + std::to_string(srx1) + " " + std::to_string(srx2)+" " + std::to_string(sry1) + " " + std::to_string(sry2));
QRect availableRes = screen->availableGeometry(); QRect availableRes = screen->availableGeometry();
int arx1, arx2, ary1, ary2; int arx1, arx2, ary1, ary2;
availableRes.getCoords(&arx1, &ary1, &arx2, &ary2); availableRes.getCoords(&arx1, &ary1, &arx2, &ary2);
log_debugcpp("Available res: " + std::to_string(arx1) + " " + std::to_string(arx2)+" " + std::to_string(ary1) + " " + std::to_string(ary2));
if(height > (ary2 - ary1)) height = (ary2 - ary1);
log_debugcpp("Height res: " + std::to_string(height));
uint8_t pos = 0; uint8_t pos = 0;
pos = tiy2 < (sry2 / 2) ? SpawnPos::UP : SpawnPos::DOWN; int leftDistance = std::abs(srx1 - tix1);
pos = tix2 < (srx2 / 2) ? pos | SpawnPos::LEFT : pos | SpawnPos::RIGHT; int rightDistance = std::abs(srx2 - tix1);
int upDistance = std::abs(sry1 - tiy1);
int downDistance = std::abs(sry2 - tiy1);
pos = (upDistance < downDistance) ? SpawnPos::UP : SpawnPos::DOWN;
pos = (leftDistance < rightDistance) ? pos | SpawnPos::LEFT : pos | SpawnPos::RIGHT;
switch (pos) { switch (pos) {
case SpawnPos::UP | SpawnPos::RIGHT: case SpawnPos::UP | SpawnPos::RIGHT:
@ -84,6 +99,21 @@ void MainWindow::calculateChildWidgetsSize() {
setGeometry(setSizePosition(width, height)); setGeometry(setSizePosition(width, height));
} }
QScreen* MainWindow::getCurrentScreen() {
//Using cursor pos as screen detector. Flawed.
QPoint cursorPos = QCursor::pos();
log_debugcpp("Cursor pos: " + std::to_string(cursorPos.ry()) + " " + std::to_string(cursorPos.rx()));
for (QScreen *screen : QGuiApplication::screens()) {
QRect screenRect = screen->geometry();
if (screenRect.contains(cursorPos)) {
return screen;
}
}
return QGuiApplication::primaryScreen();
}
SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent) : QWidget(parent){ SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent) : QWidget(parent){
//todo: based on qgridlayout, name+mute should be its own widget, same with channels //todo: based on qgridlayout, name+mute should be its own widget, same with channels
this->idx = idx; this->idx = idx;
@ -621,14 +651,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), lastRowSpacer(1,
/* /*
* Menu bar code * Menu bar code
*/ */
mainMenuBar = this->menuBar(); mainMenuBar = new QToolBar(this);
hw = new HeaderWidget(this); hw = new HeaderWidget(this);
mainMenuBar->setCornerWidget(hw,Qt::TopLeftCorner); mainMenuBar->addWidget(hw);
mainMenuBar->show(); mainMenuBar->setMovable(false);
this->setMenuBar(mainMenuBar); this->addToolBar(Qt::BottomToolBarArea, mainMenuBar);
//setCentralWidget(widget);
//widgetLayout->addWidget(pintas, 0, 0);
reloadEndpointWidgets(); reloadEndpointWidgets();
//scrollArea->setMinimumWidth(ews.at(0)->minimumWidth()); //scrollArea->setMinimumWidth(ews.at(0)->minimumWidth());

View file

@ -23,6 +23,8 @@
#include <QMenuBar> #include <QMenuBar>
#include <QMenu> #include <QMenu>
#include <QScreen> #include <QScreen>
#include <QToolBar>
#include <QWindow>
//#include <QScrollBar> //#include <QScrollBar>
/* /*
@ -201,7 +203,8 @@ public:
protected: protected:
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
void customEvent(QEvent* ev) override; void customEvent(QEvent* ev) override;
QRect setSizePosition(int width, int height); QRect setSizePosition(int width, int height);
QScreen* getCurrentScreen();
private slots: private slots:
void trayIconActivated(QSystemTrayIcon::ActivationReason reason); void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
@ -229,7 +232,7 @@ private:
QScrollArea *scrollArea; QScrollArea *scrollArea;
HeaderWidget* hw; HeaderWidget* hw;
QMenuBar *mainMenuBar; QToolBar *mainMenuBar;
QScreen *screen; QScreen *screen;
//todo: ratio //todo: ratio
//Win10 1080p 120% //Win10 1080p 120%