27 #ifdef Q_WS_X11 // FIXME(E): Figure out what parts we can/should emulate in QT/E
29 #include <qx11info_x11.h>
34 class KXMessagesPrivate
50 , d( new KXMessagesPrivate )
52 if( accept_broadcast_P != NULL )
54 ( void ) qApp->desktop();
55 kapp->installX11EventFilter(
this );
56 d->accept_atom1 = XInternAtom( QX11Info::display(), accept_broadcast_P,
false );
57 d->accept_atom2 = d->accept_atom1;
61 d->accept_atom1 = d->accept_atom2 =
None;
63 d->handle =
new QWidget(
this );
68 , d( new KXMessagesPrivate )
70 if( accept_broadcast_P != NULL )
72 ( void ) qApp->desktop();
73 kapp->installX11EventFilter(
this );
74 d->accept_atom2 = XInternAtom( QX11Info::display(), accept_broadcast_P,
false );
75 d->accept_atom1 = obsolete_P ? d->accept_atom2
76 : XInternAtom( QX11Info::display(), QByteArray(QByteArray( accept_broadcast_P ) +
"_BEGIN").constData(),
false );
80 d->accept_atom1 = d->accept_atom2 =
None;
82 d->handle =
new QWidget(
this );
97 int screen_P,
bool obsolete_P )
99 Atom a2 = XInternAtom( QX11Info::display(), msg_type_P,
false );
100 Atom a1 = obsolete_P ? a2 : XInternAtom( QX11Info::display(), QByteArray(QByteArray( msg_type_P ) +
"_BEGIN").constData(),
false );
101 Window root = screen_P == -1 ? QX11Info::appRootWindow() : QX11Info::appRootWindow( screen_P );
102 send_message_internal( root, message_P,
BROADCAST_MASK, QX11Info::display(),
103 a1, a2, d->handle->winId());
114 Atom a2 = XInternAtom( QX11Info::display(), msg_type_P,
false );
115 Atom a1 = obsolete_P ? a2 : XInternAtom( QX11Info::display(), QByteArray(QByteArray( msg_type_P ) +
"_BEGIN").constData(),
false );
116 send_message_internal( w_P, message_P, 0, QX11Info::display(), a1, a2, d->handle->winId());
126 const QString& message_P,
int screen_P,
bool obsolete_P )
130 Atom a2 = XInternAtom( disp, msg_type_P,
false );
131 Atom a1 = obsolete_P ? a2 : XInternAtom( disp, QByteArray(QByteArray( msg_type_P ) +
"_BEGIN").constData(),
false );
132 Window root = screen_P == -1 ? DefaultRootWindow( disp ) : RootWindow( disp, screen_P );
133 Window win = XCreateSimpleWindow( disp, root, 0, 0, 1, 1,
134 0, BlackPixel( disp, screen_P == -1 ? DefaultScreen( disp ) : screen_P ),
135 BlackPixel( disp, screen_P == -1 ? DefaultScreen( disp ) : screen_P ));
138 XDestroyWindow( disp, win );
145 return sendMessageX( disp, w_P, msg_type_P, message_P,
true );
149 const QString& message_P,
bool obsolete_P )
153 Atom a2 = XInternAtom( disp, msg_type_P,
false );
154 Atom a1 = obsolete_P ? a2 : XInternAtom( disp, QByteArray(QByteArray( msg_type_P ) +
"_BEGIN").constData(),
false );
155 Window win = XCreateSimpleWindow( disp, DefaultRootWindow( disp ), 0, 0, 1, 1,
156 0, BlackPixelOfScreen( DefaultScreenOfDisplay( disp )),
157 BlackPixelOfScreen( DefaultScreenOfDisplay( disp )));
158 send_message_internal( w_P, message_P, 0, disp, a1, a2, win );
159 XDestroyWindow( disp, win );
163 void KXMessages::send_message_internal( WId w_P,
const QString& msg_P,
long mask_P,
164 Display* disp,
Atom atom1_P,
Atom atom2_P, Window handle_P )
166 unsigned int pos = 0;
167 QByteArray msg = msg_P.toUtf8();
168 unsigned int len = strlen( msg );
170 e.xclient.type = ClientMessage;
171 e.xclient.message_type = atom1_P;
172 e.xclient.display = disp;
173 e.xclient.window = handle_P;
174 e.xclient.format = 8;
179 i < 20 && i + pos <= len;
181 e.xclient.data.b[ i ] = msg[ i + pos ];
182 XSendEvent( disp, w_P,
false, mask_P, &e );
183 e.xclient.message_type = atom2_P;
185 }
while( pos <= len );
191 if( ev_P->type != ClientMessage || ev_P->xclient.format != 8 )
192 return QWidget::x11Event( ev_P );
193 if( ev_P->xclient.message_type != d->accept_atom1 && ev_P->xclient.message_type != d->accept_atom2 )
194 return QWidget::x11Event( ev_P );
198 i < 20 && ev_P->xclient.data.b[ i ] !=
'\0';
200 buf[ i ] = ev_P->xclient.data.b[ i ];
202 if( d->incoming_messages.contains( ev_P->xclient.window ))
204 if( ev_P->xclient.message_type == d->accept_atom1 && d->accept_atom1 != d->accept_atom2 )
206 d->incoming_messages[ ev_P->xclient.window ] = QByteArray();
207 d->incoming_messages[ ev_P->xclient.window ] += buf;
211 if( ev_P->xclient.message_type == d->accept_atom2 && d->accept_atom1 != d->accept_atom2 )
213 d->incoming_messages[ ev_P->xclient.window ] = buf;
217 emit
gotMessage( QString::fromUtf8( d->incoming_messages[ ev_P->xclient.window ] ));
218 d->incoming_messages.remove( ev_P->xclient.window );
223 #include "kxmessages.moc"
static bool sendMessageX(Display *disp, WId w, const char *msg_type, const QString &message, bool obsolete)
Sends the given message with the given message type only to given window.
void broadcastMessage(const char *msg_type, const QString &message, int screen, bool obsolete)
Broadcasts the given message with the given message type.
KXMessages(const char *accept_broadcast, QWidget *parent, bool obsolete)
Creates an instance which will receive X messages.
virtual bool x11Event(XEvent *ev)
const long BROADCAST_MASK
void gotMessage(const QString &message)
Emitted when a message was received.
void sendMessage(WId w, const char *msg_type, const QString &message, bool obsolete)
Sends the given message with the given message type only to given window.
static bool broadcastMessageX(Display *disp, const char *msg_type, const QString &message, int screen, bool obsolete)
Broadcasts the given message with the given message type.