| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | 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 382228 2005-01-25 10:23:34Z dfaure $
    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, *p = 0, res;
    00047     int status;
    00048
    00049     res = 0;
    00050     status = XGetWindowProperty(qt_xdisplay(), w, a, 0L, 1L, False, a,
    00051             &real_type, &format, &n, &extra, (unsigned char **) &p);
    00052     if ((status == Success) && (n == 1) && (format == 32))
    00053     res = p[0];
    00054     if (p) XFree((char *) 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     // KDE 1 support
    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

This file is part of the documentation for kdecore Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:18:06 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003