# kdecore Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kipc.cpp

    00001 /* This file is part of the KDE libraries
    00002
    00003    Copyright (C) 1999 Mattias Ettrich (ettrich@kde.org)
    00004    Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
    00005
    00006    This library is free software; you can redistribute it and/or
    00007    modify it under the terms of the GNU Library General Public
    00008    License as published by the Free Software Foundation; either
    00009    version 2 of the License, or (at your option) any later version.
    00010
    00011    This library is distributed in the hope that it will be useful,
    00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014    Library General Public License for more details.
    00015
    00016    You should have received a copy of the GNU Library General Public License
    00017    along with this library; see the file COPYING.LIB.  If not, write to
    00018    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00019    Boston, MA 02111-1307, USA.
    00020 */
    00021
    00022
    00023 /*
    00024  * kipc.cpp: Send a message to one/all KDE apps.
    00025  *
    00026  * $Id: kipc.cpp,v 1.11 2001/08/29 15:25:38 bero Exp $
    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     // KDE 1 support
    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         // FIXME(E): Implement in Qt Embedded
    00117 #endif

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:46:34 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001