14#include <private/qtx11extras_p.h>
21T fromNative(xcb_pixmap_t pixmap, xcb_connection_t *c)
23 const xcb_get_geometry_cookie_t geoCookie = xcb_get_geometry_unchecked(c, pixmap);
24 UniqueCPointer<xcb_get_geometry_reply_t>
geo(xcb_get_geometry_reply(c, geoCookie,
nullptr));
30 const xcb_get_image_cookie_t imageCookie = xcb_get_image_unchecked(c, XCB_IMAGE_FORMAT_Z_PIXMAP, pixmap, 0, 0,
geo->width,
geo->height, ~0);
31 UniqueCPointer<xcb_get_image_reply_t> xImage(xcb_get_image_reply(c, imageCookie,
nullptr));
37 switch (xImage->depth) {
49 uint32_t *pixels =
reinterpret_cast<uint32_t *
>(xcb_get_image_data(xImage.get()));
50 for (uint i = 0; i < xImage.get()->length; ++i) {
51 int r = (pixels[i] >> 22) & 0xff;
52 int g = (pixels[i] >> 12) & 0xff;
53 int b = (pixels[i] >> 2) & 0xff;
55 pixels[i] = qRgba(r, g, b, 0xff);
66 QImage image(xcb_get_image_data(xImage.get()),
geo->width,
geo->height, xcb_get_image_data_length(xImage.get()) /
geo->height, format, free, xImage.get());
73 image.setColorCount(2);
77 return T::fromImage(image);
81QPixmap createPixmapFromHandle(WId pixmap, WId pixmap_mask)
83 return createPixmapFromHandle(QX11Info::connection(), pixmap, pixmap_mask);
86QPixmap createPixmapFromHandle(xcb_connection_t *c, WId pixmap, WId pixmap_mask)
88#if Q_BYTE_ORDER == Q_BIG_ENDIAN
89 qDebug() <<
"Byte order not supported";
92 const xcb_setup_t *setup = xcb_get_setup(c);
93 if (setup->image_byte_order != XCB_IMAGE_ORDER_LSB_FIRST) {
94 qDebug() <<
"Byte order not supported";
98 QPixmap pix = fromNative<QPixmap>(pixmap, c);
99 if (pixmap_mask != XCB_PIXMAP_NONE) {
100 QBitmap mask = fromNative<QBitmap>(pixmap_mask, c);
113int timestampCompare(Time time1, Time time2)
115 if (time1 == time2) {
118 return (time1 - time2) < 0x7fffffffU ? 1 : -1;
121Time timestampDiff(Time time1, Time time2)
124 return time2 - time1;
127int timestampCompare(
unsigned long time1_,
unsigned long time2_)
129 quint32 time1 = time1_;
130 quint32 time2 = time2_;
131 if (time1 == time2) {
134 return quint32(time1 - time2) < 0x7fffffffU ? 1 : -1;
137int timestampDiff(
unsigned long time1_,
unsigned long time2_)
140 quint32 time1 = time1_;
141 quint32 time2 = time2_;
142 return quint32(time2 - time1);
GeoCoordinates geo(const QVariant &location)
void setMask(const QBitmap &mask)