Skip to content

Commit 956feef

Browse files
committed
Use QScreen for Desktop::{size,workspace}
Qt 5.0 adds the QScreen API, which exposes enough information that Desktop::{size,workspace} no longer needs to fall back to Win32/Xlib. I manually tested that this seems to give the same exact answers as the Xlib path (though it technically goes a different route for Desktop::size.)
1 parent ddc3dc2 commit 956feef

File tree

1 file changed

+7
-45
lines changed

1 file changed

+7
-45
lines changed

hiro/qt/desktop.cpp

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,19 @@
33
namespace hiro {
44

55
auto pDesktop::size() -> Size {
6-
#if defined(DISPLAY_WINDOWS)
7-
return {GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN)};
8-
#elif defined(DISPLAY_XORG)
9-
auto display = XOpenDisplay(nullptr);
10-
int screen = DefaultScreen(display);
11-
XWindowAttributes attributes;
12-
XGetWindowAttributes(display, RootWindow(display, screen), &attributes);
13-
XCloseDisplay(display);
14-
return {attributes.width, attributes.height};
15-
#else
16-
//this only returns the geometry of the primary monitor rather than the entire desktop
17-
QRect rect = QApplication::desktop()->screenGeometry();
6+
QRect rect;
7+
for(QScreen* screen : QApplication::screens()) {
8+
rect = rect.united(screen->geometry());
9+
}
1810
return {rect.width(), rect.height()};
19-
#endif
2011
}
2112

2213
auto pDesktop::workspace() -> Geometry {
23-
#if defined(DISPLAY_WINDOWS)
24-
RECT rc;
25-
SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0);
26-
return {rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top};
27-
#elif defined(DISPLAY_XORG)
28-
auto display = XOpenDisplay(nullptr);
29-
int screen = DefaultScreen(display);
30-
31-
int format;
32-
unsigned char* data = nullptr;
33-
unsigned long items, after;
34-
XlibAtom returnAtom;
35-
36-
XlibAtom netWorkarea = XInternAtom(display, "_NET_WORKAREA", XlibTrue);
37-
int result = XGetWindowProperty(
38-
display, RootWindow(display, screen), netWorkarea, 0, 4, XlibFalse,
39-
XInternAtom(display, "CARDINAL", XlibTrue), &returnAtom, &format, &items, &after, &data
40-
);
41-
42-
XlibAtom cardinal = XInternAtom(display, "CARDINAL", XlibTrue);
43-
if(result == Success && returnAtom == cardinal && format == 32 && items == 4) {
44-
unsigned long* workarea = (unsigned long*)data;
45-
XCloseDisplay(display);
46-
return {(int)workarea[0], (int)workarea[1], (int)workarea[2], (int)workarea[3]};
14+
QRect rect;
15+
for(QScreen* screen : QApplication::screens()) {
16+
rect = rect.united(screen->geometry());
4717
}
48-
49-
XCloseDisplay(display);
50-
auto size = Desktop::size();
51-
return {0, 0, size.width(), size.height()};
52-
#else
53-
//this only returns the workspace of the primary monitor rather than the entire desktop
54-
QRect rect = QApplication::desktop()->availableGeometry();
5518
return {rect.x(), rect.y(), rect.width(), rect.height()};
56-
#endif
5719
}
5820

5921
}

0 commit comments

Comments
 (0)