File: desktop.cpp

package info (click to toggle)
ares 134%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 34,680 kB
  • sloc: cpp: 338,717; ansic: 89,036; sh: 52; makefile: 27
file content (61 lines) | stat: -rw-r--r-- 2,047 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#if defined(Hiro_Desktop)

namespace hiro {

auto pDesktop::size() -> Size {
  #if defined(DISPLAY_WINDOWS)
  return {GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN)};
  #elif defined(DISPLAY_XORG)
  auto display = XOpenDisplay(nullptr);
  s32 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()};
  #endif
}

auto pDesktop::workspace() -> Geometry {
  #if defined(DISPLAY_WINDOWS)
  RECT rc;
  SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0);
  return {rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top};
  #elif defined(DISPLAY_XORG)
  auto display = XOpenDisplay(nullptr);
  s32 screen = DefaultScreen(display);

  s32 format;
  unsigned char* data = nullptr;
  unsigned long items, after;
  XlibAtom returnAtom;

  XlibAtom netWorkarea = XInternAtom(display, "_NET_WORKAREA", XlibTrue);
  s32 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 {(s32)workarea[0], (s32)workarea[1], (s32)workarea[2], (s32)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()};
  #endif
}

}

#endif