mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-09-02 14:52:52 +02:00
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.)
This commit is contained in:
committed by
Screwtapello
parent
8011051eea
commit
f05dd784fd
@@ -3,57 +3,19 @@
|
|||||||
namespace hiro {
|
namespace hiro {
|
||||||
|
|
||||||
auto pDesktop::size() -> Size {
|
auto pDesktop::size() -> Size {
|
||||||
#if defined(DISPLAY_WINDOWS)
|
QRect rect;
|
||||||
return {GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN)};
|
for(QScreen* screen : QApplication::screens()) {
|
||||||
#elif defined(DISPLAY_XORG)
|
rect = rect.united(screen->geometry());
|
||||||
auto display = XOpenDisplay(nullptr);
|
}
|
||||||
int screen = DefaultScreen(display);
|
|
||||||
XWindowAttributes attributes;
|
|
||||||
XGetWindowAttributes(display, RootWindow(display, screen), &attributes);
|
|
||||||
XCloseDisplay(display);
|
|
||||||
return {attributes.width, attributes.height};
|
|
||||||
#else
|
|
||||||
//this only returns the geometry of the primary monitor rather than the entire desktop
|
|
||||||
QRect rect = QApplication::desktop()->screenGeometry();
|
|
||||||
return {rect.width(), rect.height()};
|
return {rect.width(), rect.height()};
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pDesktop::workspace() -> Geometry {
|
auto pDesktop::workspace() -> Geometry {
|
||||||
#if defined(DISPLAY_WINDOWS)
|
QRect rect;
|
||||||
RECT rc;
|
for(QScreen* screen : QApplication::screens()) {
|
||||||
SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0);
|
rect = rect.united(screen->geometry());
|
||||||
return {rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top};
|
|
||||||
#elif defined(DISPLAY_XORG)
|
|
||||||
auto display = XOpenDisplay(nullptr);
|
|
||||||
int screen = DefaultScreen(display);
|
|
||||||
|
|
||||||
int format;
|
|
||||||
unsigned char* data = nullptr;
|
|
||||||
unsigned long items, after;
|
|
||||||
XlibAtom returnAtom;
|
|
||||||
|
|
||||||
XlibAtom netWorkarea = XInternAtom(display, "_NET_WORKAREA", XlibTrue);
|
|
||||||
int result = XGetWindowProperty(
|
|
||||||
display, RootWindow(display, screen), netWorkarea, 0, 4, XlibFalse,
|
|
||||||
XInternAtom(display, "CARDINAL", XlibTrue), &returnAtom, &format, &items, &after, &data
|
|
||||||
);
|
|
||||||
|
|
||||||
XlibAtom cardinal = XInternAtom(display, "CARDINAL", XlibTrue);
|
|
||||||
if(result == Success && returnAtom == cardinal && format == 32 && items == 4) {
|
|
||||||
unsigned long* workarea = (unsigned long*)data;
|
|
||||||
XCloseDisplay(display);
|
|
||||||
return {(int)workarea[0], (int)workarea[1], (int)workarea[2], (int)workarea[3]};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
XCloseDisplay(display);
|
|
||||||
auto size = Desktop::size();
|
|
||||||
return {0, 0, size.width(), size.height()};
|
|
||||||
#else
|
|
||||||
//this only returns the workspace of the primary monitor rather than the entire desktop
|
|
||||||
QRect rect = QApplication::desktop()->availableGeometry();
|
|
||||||
return {rect.x(), rect.y(), rect.width(), rect.height()};
|
return {rect.x(), rect.y(), rect.width(), rect.height()};
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user