Skip to content

Commit

Permalink
Ui: Fix positioning for the systray widget under xfce
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarsnik committed Jul 17, 2024
1 parent 47800fb commit cf58ddc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
20 changes: 15 additions & 5 deletions ui/appui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ Q_LOGGING_CATEGORY(log_appUi, "APPUI")
#include "sqpath.h"


static const QString applicationJsonFileName = "qusb2snesapp.json";
extern QSettings* globalSettings;
extern WSServer wsServer;
static const QString applicationJsonFileName = "qusb2snesapp.json";
extern QSettings* globalSettings;
extern WSServer wsServer;


AppUi::AppUi(QObject *parent) : QObject(parent)
Expand Down Expand Up @@ -199,26 +199,35 @@ void AppUi::init()
if (UiWidget->isVisible() == false)
{
QRect geo = sysTray->geometry();
sDebug() << "Systray geo" << geo;
QPoint tray_center = sysTray->geometry().center();
if (tray_center == QPoint(0, 0))
{
QPoint mousePos = QCursor::pos() - qApp->screenAt(QCursor::pos())->geometry().topLeft();
geo = QRect(mousePos, QSize(10, 10));
tray_center = mousePos;
}
QRect screen_rect = qApp->screenAt(tray_center)->geometry();
QPoint screen_center = screen_rect.center();

Qt::Corner corner = Qt::TopLeftCorner;
sDebug() << tray_center << screen_center << UiWidget->size();
if (tray_center.x() > screen_center.x() && tray_center.y() <= screen_center.y())
corner = Qt::TopRightCorner;
else if (tray_center.x() > screen_center.x() && tray_center.y() > screen_center.y())
corner = Qt::BottomRightCorner;
else if (tray_center.x() <= screen_center.x() && tray_center.y() > screen_center.y())
corner = Qt::BottomLeftCorner;
// Bottom
sDebug() << "Systray is in : " << corner;
if (corner == Qt::BottomRightCorner)
UiWidget->move(geo.x() - UiWidget->size().width(), geo.y() - UiWidget->size().height());
if (corner == Qt::BottomLeftCorner)
UiWidget->move(geo.x() + UiWidget->size().width(), geo.y() - UiWidget->size().height());
if (corner == Qt::TopLeftCorner)
UiWidget->move(geo.x() + UiWidget->size().width(), geo.y() + UiWidget->size().height());
UiWidget->move(geo.x() + UiWidget->size().width(), geo.y() + geo.height());
if (corner == Qt::TopRightCorner)
UiWidget->move(geo.x() - UiWidget->size().width(), geo.y() + UiWidget->size().height());
UiWidget->move(geo.x() - UiWidget->size().width(), geo.y() + geo.height());
UiWidget->show();

onMenuHovered(nullptr);
Expand Down Expand Up @@ -786,3 +795,4 @@ void AppUi::handleMagic2Snes(QString path)

}


1 change: 0 additions & 1 deletion ui/appui.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <QLabel>
#include <QProgressBar>


class AppUi : public QObject
{
Q_OBJECT
Expand Down
3 changes: 2 additions & 1 deletion ui/appuimenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void AppUi::setMenu()
diag.setWSServer(&wsServer);
diag.exec();
});
QObject::connect(menu->addAction(tr("Exit")), &QAction::triggered, qApp, &QApplication::exit);
QObject::connect(menu->addAction(QIcon(":/img/quiticon.svg"), tr("Exit")), &QAction::triggered, qApp, &QApplication::exit);
appsMenu->addSeparator();
appsMenu->addAction(tr("Remote Applications"));
appsMenu->addSeparator();
Expand All @@ -104,6 +104,7 @@ void AppUi::setMenu()

void AppUi::setLinuxDeviceMenu()
{
linuxActionPos = 0;
deviceMenu->addAction("Devices state");
auto serverStatus = wsServer.serverStatus();
for (quint8 i = 0; i < serverStatus.deviceFactoryCount * 3; i++)
Expand Down
4 changes: 3 additions & 1 deletion ui/systraywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ void SysTrayWidget::on_pushButton_clicked()
QPoint p = mapToGlobal(ui->pushButton->geometry().topRight());
if (corner == Qt::TopLeftCorner || corner == Qt::TopRightCorner)
{
p.setY(p.y() + contextMenu->sizeHint().height());
p.setY(p.y() + ui->pushButton->geometry().height());
} else {
p.setY(p.y() - contextMenu->sizeHint().height());
}
if (corner == Qt::TopRightCorner)
p.setX(p.x() - contextMenu->sizeHint().width());
contextMenu->move(p);
contextMenu->show();
}
Expand Down
4 changes: 4 additions & 0 deletions ui/systraywidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<property name="windowTitle">
<string>QUsb2Snes</string>
</property>
<property name="windowIcon">
<iconset resource="../ressources.qrc">
<normaloff>:/img/icon64x64.ico</normaloff>:/img/icon64x64.ico</iconset>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="8,1">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,2,1,2">
Expand Down

0 comments on commit cf58ddc

Please sign in to comment.