20 #include <tqwindowdefs.h>
25 #include <tdeapplication.h>
26 #include <krootprop.h>
27 #include <ksharedpixmap.h>
35 #include <X11/Xutil.h>
37 #include <X11/extensions/XShm.h>
55 class TDESharedPixmapPrivate
64 TDESharedPixmap::TDESharedPixmap()
65 : TQWidget(0L,
"shpixmap comm window")
67 d =
new TDESharedPixmapPrivate;
72 TDESharedPixmap::~TDESharedPixmap()
78 void TDESharedPixmap::init()
80 d->pixmap = XInternAtom(tqt_xdisplay(),
"PIXMAP",
false);
82 atom.sprintf(
"target prop for window %lx",
static_cast<unsigned long int>(winId()));
83 d->target = XInternAtom(tqt_xdisplay(), atom.data(),
false);
88 bool TDESharedPixmap::isAvailable(
const TQString & name)
const
90 TQString str = TQString(
"KDESHPIXMAP:%1").arg(name);
91 Atom sel = XInternAtom(tqt_xdisplay(), str.latin1(),
true);
94 return XGetSelectionOwner(tqt_xdisplay(), sel) != None;
98 bool TDESharedPixmap::loadFromShared(
const TQString & name,
const TQRect & rect)
101 if (d->selection != None)
105 TQPixmap::resize(0, 0);
107 TQString str = TQString(
"KDESHPIXMAP:%1").arg(name);
108 d->selection = XInternAtom(tqt_xdisplay(), str.latin1(),
true);
109 if (d->selection == None)
111 if (XGetSelectionOwner(tqt_xdisplay(), d->selection) == None)
117 XConvertSelection(tqt_xdisplay(), d->selection, d->pixmap, d->target,
118 winId(), CurrentTime);
123 bool TDESharedPixmap::x11Event(XEvent *event)
125 if (
event->type != SelectionNotify)
128 XSelectionEvent *ev = &
event->xselection;
129 if (ev->selection != d->selection)
132 if ((ev->target != d->pixmap) || (ev->property == None))
134 kdWarning(270) << k_funcinfo <<
"illegal selection notify event.\n";
143 unsigned long nitems, ldummy;
144 unsigned char *pixmap_id = 0;
147 XGetWindowProperty(tqt_xdisplay(), winId(), ev->property, 0, 1,
false,
148 d->pixmap, &type, &format, &nitems, &ldummy,
151 if (nitems != 1 || !pixmap_id)
153 kdWarning(270) << k_funcinfo <<
"could not read property, nitems = " << nitems <<
"\n";
159 unsigned int width, height, udummy;
160 void *drawable_id = (
void *) pixmap_id;
161 Drawable pixmap = *(Drawable*) drawable_id;
163 if (!XGetGeometry(tqt_xdisplay(), pixmap, &root, &dummy, &dummy, &width, &height, &udummy, &udummy)) {
167 if (d->rect.isEmpty())
169 TQPixmap::resize(width, height);
170 XCopyArea(tqt_xdisplay(), pixmap, ((
KPixmap*)
this)->handle(), tqt_xget_temp_gc(tqt_xscreen(),
false),
171 0, 0, width, height, 0, 0);
174 XDeleteProperty(tqt_xdisplay(), winId(), ev->property);
184 TQPoint origin(0, 0);
185 if( d->rect.topLeft().x() < 0 || d->rect.topLeft().y() < 0 ) {
187 TQPoint tl = d->rect.topLeft();
188 TQPoint br = d->rect.bottomRight();
190 origin.setX( abs( tl.x() ) );
194 origin.setY( abs( tl.y() ) );
197 TQRect adjustedRect( tl, br );
198 d->rect = adjustedRect;
201 unsigned w = d->rect.width(), h = d->rect.height();
202 unsigned tw = TQMIN(width, w), th = TQMIN(height, h);
203 unsigned xa = d->rect.x() % width, ya = d->rect.y() % height;
204 unsigned t1w = TQMIN(width-xa,tw), t1h = TQMIN(height-ya,th);
206 TQPixmap::resize( tw+origin.x(), th+origin.y() );
208 XCopyArea(tqt_xdisplay(), pixmap, (
static_cast<KPixmap*
>(
this))->handle(), tqt_xget_temp_gc(tqt_xscreen(),
false),
209 xa, ya, t1w+origin.x(), t1h+origin.y(), origin.x(), origin.y() );
210 XCopyArea(tqt_xdisplay(), pixmap, (
static_cast<KPixmap*
>(
this))->handle(), tqt_xget_temp_gc(tqt_xscreen(),
false),
211 0, ya, tw-t1w, t1h, t1w, 0);
212 XCopyArea(tqt_xdisplay(), pixmap, (
static_cast<KPixmap*
>(
this))->handle(), tqt_xget_temp_gc(tqt_xscreen(),
false),
213 xa, 0, t1w, th-t1h, 0, t1h);
214 XCopyArea(tqt_xdisplay(), pixmap, (
static_cast<KPixmap*
>(
this))->handle(), tqt_xget_temp_gc(tqt_xscreen(),
false),
215 0, 0, tw-t1w, th-t1h, t1w, t1h);
220 XDeleteProperty(tqt_xdisplay(), winId(), ev->property);
226 #include "ksharedpixmap.moc"
kdbgstream kdWarning(int area=0)
int event(const TQString &message, const TQString &text=TQString::null) TDE_DEPRECATED