3#include <QLoggingCategory>
13Q_LOGGING_CATEGORY(LogScreen,
"Screen")
21 dpy = XOpenDisplay(NULL);
24 if (strstr(ServerVendor(dpy),
"X.Org")) {
25 int vendrel = VendorRelease(dpy);
27 QString version(
"X.Org version: ");
28 version += QString::number(vendrel / 10000000);
29 version +=
"." + QString::number((vendrel / 100000) % 100),
30 version +=
"." + QString::number((vendrel / 1000) % 100);
32 version +=
"." + QString::number(vendrel % 1000);
34 qInfo(LogScreen) << version;
43CScreenXLib::CScreenXLib(QObject *parent) :
CScreen(parent)
47 dsp = XOpenDisplay(NULL);
50 szErr =
"Cannot connect to local display";
51 qCritical(LogScreen) << szErr;
52 throw std::runtime_error(szErr.toStdString().c_str());
55 Visual* vis = DefaultVisual(dsp, DefaultScreen(dsp));
56 if (vis->c_class != TrueColor) {
57 szErr =
"pseudocolour not supported";
58 qCritical(LogScreen) << szErr;
62 m_pImage = XCreateImage(dsp, vis, DefaultDepth(dsp, DefaultScreen(dsp)),
63 ZPixmap, 0, 0, Width(), Height(),
65 m_pImage->data = (
char *)malloc(m_pImage->bytes_per_line * m_pImage->height);
66 if (m_pImage->data == NULL) {
67 szErr =
"malloc() failed";
68 qCritical(LogScreen) << szErr;
74 throw std::runtime_error(szErr.toStdString().c_str());
76 m_Screen = QImage((uchar*)m_pImage->data, Width(), Height(), GetFormat(m_pImage));
79CScreenXLib::~CScreenXLib()
82 XDestroyImage(m_pImage);
85int CScreenXLib::Width()
89 dsp = XOpenDisplay(NULL);
92 qCritical(LogScreen) <<
"Cannot connect to local display";
95 w = DisplayWidth(dsp, DefaultScreen(dsp));
100int CScreenXLib::Height()
104 dsp = XOpenDisplay(NULL);
107 qCritical(LogScreen) <<
"Cannot connect to local display";
110 h = DisplayHeight(dsp, DefaultScreen(dsp));
115int CScreenXLib::VirtualTop()
121int CScreenXLib::VirtualLeft()
127int CScreenXLib::VirtualWidth()
133int CScreenXLib::VirtualHeight()
139int CScreenXLib::VisibleMonitorCount()
145void myImageCleanupHandler(
void *info)
147 qDebug(LogScreen) <<
"void myImageCleanupHandler(void *info)";
148 XDestroyImage(
static_cast<XImage*
>(info));
151QImage::Format CScreenXLib::GetFormat(XImage *img)
153 switch(img->bits_per_pixel)
156 return QImage::Format_ARGB32;
158 return QImage::Format_RGB888;
160 qCritical(LogScreen) <<
"Don't support format:" << img->bits_per_pixel;
161 return QImage::Format_Invalid;
164 return QImage::Format_Invalid;
167QImage CScreenXLib::GetScreen(
int index)
175 dsp = XOpenDisplay(NULL);
178 qCritical(LogScreen) <<
"Cannot connect to local display";
182 desktop = DefaultRootWindow(dsp);
185 qCritical(LogScreen) <<
"cannot get root window";
190 screen_width = Width();
191 screen_height = Height();
193 XGetSubImage(dsp, desktop, 0, 0, Width(), Height(), AllPlanes, ZPixmap,