| 41 | } |
| 42 | |
| 43 | CScreenXLib::CScreenXLib(QObject *parent) : CScreen(parent) |
| 44 | { |
| 45 | QString szErr; |
| 46 | Display* dsp = NULL; |
| 47 | dsp = XOpenDisplay(NULL);/* Connect to a local display */ |
| 48 | if(NULL == dsp) |
| 49 | { |
| 50 | szErr = "Cannot connect to local display"; |
| 51 | qCritical(LogScreen) << szErr; |
| 52 | throw std::runtime_error(szErr.toStdString().c_str()); |
| 53 | } |
| 54 | do{ |
| 55 | Visual* vis = DefaultVisual(dsp, DefaultScreen(dsp)); |
| 56 | if (vis->c_class != TrueColor) { |
| 57 | szErr = "pseudocolour not supported"; |
| 58 | qCritical(LogScreen) << szErr; |
| 59 | break; |
| 60 | } |
| 61 | |
| 62 | m_pImage = XCreateImage(dsp, vis, DefaultDepth(dsp, DefaultScreen(dsp)), |
| 63 | ZPixmap, 0, 0, Width(), Height(), |
| 64 | BitmapPad(dsp), 0); |
| 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; |
| 69 | } |
| 70 | } while(0); |
| 71 | |
| 72 | XCloseDisplay(dsp); |
| 73 | if(!szErr.isEmpty()) |
| 74 | throw std::runtime_error(szErr.toStdString().c_str()); |
| 75 | |
| 76 | m_Screen = QImage((uchar*)m_pImage->data, Width(), Height(), GetFormat(m_pImage)); |
| 77 | } |
| 78 | |
| 79 | CScreenXLib::~CScreenXLib() |
| 80 | { |