• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Applets

systemtraycontainer.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   systemtraywidget.h                                                    *
00003  *                                                                         *
00004  *   Copyright (C) 2007 Jason Stubbs <jasonbstubbs@gmail.com>              *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  *   This program 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         *
00014  *   GNU General Public License for more details.                          *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this program; if not, write to the                         *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
00020  ***************************************************************************/
00021 
00022 // Own
00023 #include "systemtraycontainer.h"
00024 
00025 // KDE
00026 #include <KDebug>
00027 #include <plasma/theme.h>
00028 
00029 // Qt
00030 #include <QX11Info>
00031 
00032 // Xlib
00033 #include <X11/Xlib.h>
00034 
00035 SystemTrayContainer::SystemTrayContainer(QWidget *parent)
00036     : QX11EmbedContainer(parent)
00037 {
00038     connect(this, SIGNAL(clientClosed()), SLOT(deleteLater()));
00039     connect(this, SIGNAL(error(QX11EmbedContainer::Error)), SLOT(handleError(QX11EmbedContainer::Error)));
00040 
00041     connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(updateBackground()));
00042     updateBackground();
00043 
00044     // Tray icons have a fixed size of 22x22
00045     setMaximumSize(22, 22);
00046 }
00047 
00048 void SystemTrayContainer::embedSystemTrayClient( WId clientId )
00049 {
00050     kDebug() << "attempting to embed" << clientId;
00051     if( !prepareFor(clientId)) { // temporary hack, until QX11EmbedContainer gets fixed
00052          deleteLater();
00053          return;
00054     }
00055 
00056     embedClient(clientId);
00057 
00058     // check if we still have a valid clientId since there may cases where we don't any
00059     // longer after calling embedClient like e.g. if there is already a pidgin-instance
00060     // running and it got started again. In that case those guniqueapplication starts
00061     // and fires a SYSTEM_TRAY_REQUEST_DOCK with another clientId up, exists and passes
00062     // commandline-arguments on to the other running instance and embedClient does fail
00063     // without emitting a clientClosed() or error() signal.
00064     XWindowAttributes attr;
00065     if( !XGetWindowAttributes(QX11Info::display(), clientId, &attr) /*|| attr.map_state == IsUnmapped*/ ) {
00066         deleteLater();
00067     }
00068 }
00069 
00070 bool SystemTrayContainer::x11Event(XEvent *event)
00071 {
00072     bool ok = QX11EmbedContainer::x11Event(event);
00073     if (event->type == ReparentNotify) {
00074         setMinimumSize(22,22);
00075     }
00076     return ok;
00077 }
00078 
00079 void SystemTrayContainer::updateBackground()
00080 {
00081     // Qt's regular quasi-transparent background doesn't work so set it to the
00082     // theme's background color instead.
00083     QPalette p = palette();
00084     p.setBrush(QPalette::Window, Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor));
00085     setPalette(p);
00086     setBackgroundRole(QPalette::Window);
00087 }
00088 
00089 void SystemTrayContainer::handleError(QX11EmbedContainer::Error error)
00090 {
00091     Q_UNUSED(error);
00092     deleteLater();
00093 }
00094 
00095 // Temporary hack to change X window used by QX11EmbedContainer so that it matches
00096 // the window embedded into it (#153193).
00097 bool SystemTrayContainer::prepareFor(WId w)
00098 {
00099     Display* dpy = QX11Info::display();
00100 
00101     XWindowAttributes ga;
00102     if( !XGetWindowAttributes(dpy, w, &ga))
00103         return false;
00104 
00105     XSetWindowAttributes sa;
00106     sa.background_pixel = WhitePixel(dpy, DefaultScreen(dpy));
00107     sa.border_pixel = BlackPixel(dpy, DefaultScreen(dpy));
00108     sa.colormap = ga.colormap;
00109 
00110     Window ww = XCreateWindow(dpy, parentWidget() ? parentWidget()->winId() : DefaultRootWindow(dpy),
00111             0, 0, 22, 22, 0, ga.depth, InputOutput, ga.visual,
00112             CWBackPixel | CWBorderPixel | CWColormap, &sa);
00113     create(ww, true, true);
00114 
00115     // repeat everything from QX11EmbedContainer's ctor that might be relevant
00116     setFocusPolicy(Qt::StrongFocus);
00117     setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00118     setAcceptDrops(true);
00119     setEnabled(false);
00120 
00121     XSelectInput(dpy, ww,
00122             KeyPressMask | KeyReleaseMask |
00123             ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
00124             KeymapStateMask |
00125             PointerMotionMask |
00126             EnterWindowMask | LeaveWindowMask |
00127             FocusChangeMask |
00128             ExposureMask |
00129             StructureNotifyMask |
00130             SubstructureNotifyMask);
00131     XFlush(dpy);
00132     return true;
00133 }

Applets

Skip menu "Applets"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal