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
00029 #include <qwindowdefs.h>
00030
00031 #ifdef Q_WS_X11
00032 #include <X11/X.h>
00033 #include <X11/Xlib.h>
00034 #endif
00035
00036 #include <kipc.h>
00037
00038
00039 #ifndef Q_WS_QWS
00040 static int dropError(Display *, XErrorEvent *)
00041 {
00042 return 0;
00043 }
00044
00045 static long getSimpleProperty(Window w, Atom a)
00046 {
00047 Atom real_type;
00048 int format;
00049 unsigned long n, extra, *p = 0, res;
00050 int status;
00051
00052 res = 0;
00053 status = XGetWindowProperty(qt_xdisplay(), w, a, 0L, 1L, False, a,
00054 &real_type, &format, &n, &extra, (unsigned char **) &p);
00055 if ((status == Success) && (n == 1) && (format == 32))
00056 res = p[0];
00057 if (p) XFree((char *) p);
00058 return res;
00059 }
00060
00061
00062 void KIPC::sendMessage(Message msg, WId w, int data)
00063 {
00064 static Atom a = 0;
00065 if (a == 0)
00066 a = XInternAtom(qt_xdisplay(), "KIPC_COMM_ATOM", False);
00067 XEvent ev;
00068 ev.xclient.type = ClientMessage;
00069 ev.xclient.display = qt_xdisplay();
00070 ev.xclient.window = (Window) w;
00071 ev.xclient.message_type = a;
00072 ev.xclient.format = 32;
00073 ev.xclient.data.l[0] = msg;
00074 ev.xclient.data.l[1] = data;
00075 XSendEvent(qt_xdisplay(), (Window) w, False, 0L, &ev);
00076
00077
00078 static Atom kde1 = 0;
00079 if ( msg == PaletteChanged || msg == FontChanged ) {
00080 if ( kde1 == 0 )
00081 kde1 = XInternAtom(qt_xdisplay(), "KDEChangeGeneral", False );
00082 ev.xclient.message_type = kde1;
00083 XSendEvent(qt_xdisplay(), (Window) w, False, 0L, &ev);
00084 }
00085
00086 }
00087
00088
00089 void KIPC::sendMessageAll(Message msg, int data)
00090 {
00091 unsigned int i, nrootwins;
00092 Window dw1, dw2, *rootwins = 0;
00093 int (*defaultHandler)(Display *, XErrorEvent *);
00094 Display *dpy = qt_xdisplay();
00095 int screen_count = ScreenCount(dpy);
00096
00097 defaultHandler = XSetErrorHandler(&dropError);
00098
00099 for (int s = 0; s < screen_count; s++) {
00100 Window root = RootWindow(dpy, s);
00101
00102 XQueryTree(dpy, root, &dw1, &dw2, &rootwins, &nrootwins);
00103 Atom a = XInternAtom(qt_xdisplay(), "KDE_DESKTOP_WINDOW", False);
00104 for (i = 0; i < nrootwins; i++)
00105 {
00106 if (getSimpleProperty(rootwins[i], a) != 0L)
00107 sendMessage(msg, rootwins[i], data);
00108 }
00109 }
00110
00111 XFlush(dpy);
00112 XSetErrorHandler(defaultHandler);
00113 XFree((char *) rootwins);
00114 }
00115 #else
00116
00117 #endif