00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "config.h"
00029
00030 #include <qwindowdefs.h>
00031
00032 #if defined Q_WS_X11
00033 #include <X11/X.h>
00034 #include <X11/Xlib.h>
00035 #include <kxerrorhandler.h>
00036 #endif
00037
00038 #include <kipc.h>
00039
00040
00041 #if defined Q_WS_X11
00042 static long getSimpleProperty(Window w, Atom a)
00043 {
00044 Atom real_type;
00045 int format;
00046 unsigned long n, extra, res = 0;
00047 int status;
00048 unsigned char *p = 0;
00049
00050 status = XGetWindowProperty(qt_xdisplay(), w, a, 0L, 1L, False, a,
00051 &real_type, &format, &n, &extra, &p);
00052 if ((status == Success) && (n == 1) && (format == 32))
00053 res = *(unsigned long*)p;
00054 if (p) XFree(p);
00055 return res;
00056 }
00057 #endif
00058
00059 void KIPC::sendMessage(Message msg, WId w, int data)
00060 {
00061 #if defined Q_WS_X11
00062 static Atom a = 0;
00063 if (a == 0)
00064 a = XInternAtom(qt_xdisplay(), "KIPC_COMM_ATOM", False);
00065 XEvent ev;
00066 ev.xclient.type = ClientMessage;
00067 ev.xclient.display = qt_xdisplay();
00068 ev.xclient.window = (Window) w;
00069 ev.xclient.message_type = a;
00070 ev.xclient.format = 32;
00071 ev.xclient.data.l[0] = msg;
00072 ev.xclient.data.l[1] = data;
00073 XSendEvent(qt_xdisplay(), (Window) w, False, 0L, &ev);
00074
00075
00076 static Atom kde1 = 0;
00077 if ( msg == PaletteChanged || msg == FontChanged ) {
00078 if ( kde1 == 0 )
00079 kde1 = XInternAtom(qt_xdisplay(), "KDEChangeGeneral", False );
00080 ev.xclient.message_type = kde1;
00081 XSendEvent(qt_xdisplay(), (Window) w, False, 0L, &ev);
00082 }
00083
00084 #endif
00085 }
00086
00087
00088 void KIPC::sendMessageAll(Message msg, int data)
00089 {
00090 #if defined Q_WS_X11
00091 unsigned int i, nrootwins;
00092 Window dw1, dw2, *rootwins = 0;
00093 Display *dpy = qt_xdisplay();
00094 int screen_count = ScreenCount(dpy);
00095
00096 KXErrorHandler handler;
00097 for (int s = 0; s < screen_count; s++) {
00098 Window root = RootWindow(dpy, s);
00099
00100 XQueryTree(dpy, root, &dw1, &dw2, &rootwins, &nrootwins);
00101 Atom a = XInternAtom(qt_xdisplay(), "KDE_DESKTOP_WINDOW", False);
00102 for (i = 0; i < nrootwins; i++)
00103 {
00104 if (getSimpleProperty(rootwins[i], a) != 0L)
00105 sendMessage(msg, rootwins[i], data);
00106 }
00107 XFree((char *) rootwins);
00108 }
00109 XSync(dpy,False);
00110 #endif
00111 }
00112