Applets
systemtraycontainer.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "systemtraycontainer.h"
00024
00025
00026 #include <KDebug>
00027 #include <plasma/theme.h>
00028
00029
00030 #include <QX11Info>
00031
00032
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
00045 setMaximumSize(22, 22);
00046 }
00047
00048 void SystemTrayContainer::embedSystemTrayClient( WId clientId )
00049 {
00050 kDebug() << "attempting to embed" << clientId;
00051 if( !prepareFor(clientId)) {
00052 deleteLater();
00053 return;
00054 }
00055
00056 embedClient(clientId);
00057
00058
00059
00060
00061
00062
00063
00064 XWindowAttributes attr;
00065 if( !XGetWindowAttributes(QX11Info::display(), clientId, &attr) ) {
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
00082
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
00096
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
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 }