Skip to content

Commit 2d26d25

Browse files
committed
hiro/qt: Use QScreen for Monitor
Qt 5 introduces QScreen, which can be used to implement most of the functionality needed by Monitor, although some of it probably won't make sense when using Wayland.
1 parent f05dd78 commit 2d26d25

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

hiro/qt/monitor.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,23 @@
33
namespace hiro {
44

55
auto pMonitor::count() -> uint {
6-
return QApplication::desktop()->screenCount();
6+
return QApplication::screens().size();
77
}
88

99
auto pMonitor::dpi(uint monitor) -> Position {
10-
//Qt does not support per-monitor DPI retrieval
1110
return {
12-
QApplication::desktop()->logicalDpiX(),
13-
QApplication::desktop()->logicalDpiY()
11+
QApplication::screens().at(monitor)->logicalDotsPerInchX(),
12+
QApplication::screens().at(monitor)->logicalDotsPerInchY()
1413
};
1514
}
1615

1716
auto pMonitor::geometry(uint monitor) -> Geometry {
18-
QRect rectangle = QApplication::desktop()->screenGeometry(monitor);
17+
QRect rectangle = QApplication::screens().at(monitor)->geometry();
1918
return {rectangle.x(), rectangle.y(), rectangle.width(), rectangle.height()};
2019
}
2120

2221
auto pMonitor::primary() -> uint {
23-
return QApplication::desktop()->primaryScreen();
22+
return QApplication::screens().indexOf(QApplication::primaryScreen());
2423
}
2524

2625
auto pMonitor::workspace(uint monitor) -> Geometry {

hiro/qt/window.cpp

100755100644
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ auto pWindow::handle() const -> uintptr_t {
8383
}
8484

8585
auto pWindow::monitor() const -> uint {
86-
int monitor = QDesktopWidget().screenNumber(qtWindow);
87-
if(monitor < 0) monitor = Monitor::primary();
88-
return monitor;
86+
auto screen = qtWindow->window()->windowHandle()->screen();
87+
if(screen == nullptr) return Monitor::primary();
88+
return QApplication::screens().indexOf(screen);
8989
}
9090

9191
auto pWindow::remove(sMenuBar menuBar) -> void {

0 commit comments

Comments
 (0)