• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

superkaramba

  • sources
  • kde-4.12
  • kdeutils
  • superkaramba
  • src
systemtray.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  copyright (C) 2003 Adam Geitgey <adam@rootnode.org>
3  2003 Sven Leiber <s.leiber@web.de>
4  2000-2001 Matthias Ettrich <ettrich@kde.org>
5  2000-2001 Matthias Elter <elter@kde.org>
6  2001 Carsten Pfeiffer <pfeiffer@kde.org>
7  2001 Martijn Klingens <mklingens@yahoo.com>
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #include "systemtray.h"
20 
21 
22 #include <qobject.h>
23 //Added by qt3to4:
24 
25 #include <QList>
26 #include <kiconloader.h>
27 #include <klocale.h>
28 #include <kwindowsystem.h>
29 #include <kmessagebox.h>
30 #include <kdebug.h>
31 
32 #include <q3dragobject.h>
33 #include <qlayout.h>
34 #include <qstringlist.h>
35 #include <qpixmap.h>
36 
37 #include <X11/Xlib.h>
38 
39 Systemtray::Systemtray(QWidget* parent)
40  : QWidget(parent)
41 {}
42 
43 
44 Systemtray::~Systemtray()
45 {
46  while (m_Wins.isEmpty())
47  delete m_Wins.takeFirst();
48 }
49 
50 int Systemtray::getTraySize()
51 {
52 
53  return (int) kwin_module->systemTrayWindows().size();
54 }
55 
56 void Systemtray::updateBackgroundPixmap(const QPixmap & pixmap)
57 {
58  QXEmbed *emb;
59  setPaletteBackgroundPixmap(pixmap);
60  for (emb = m_Wins.first(); emb != 0L; emb = m_Wins.next()) {
61 
62  //Stupid stupid stupid work around for annoying bug
63  //QXEmbed ignores setBackgroundOrigin(AncestorOrigin)....
64  QPixmap bug = QPixmap(emb->size());
65  bitBlt(&bug, 0, 0, &pixmap, emb->parentWidget()->x() + emb->x(), emb->parentWidget()->y() + emb->y(), emb->width(), emb->height(), Qt::CopyROP, false);
66  emb->setPaletteBackgroundPixmap(bug);
67 
68  }
69 
70  QPoint topPoint = mapToGlobal(QPoint(0, 0));
71  Window hack = XCreateSimpleWindow(qt_xdisplay(), winId(), 0, 0, width(), height(), 0, 0, 0);
72  XRaiseWindow(qt_xdisplay(), hack);
73  XMapWindow(qt_xdisplay(), hack);
74  XUnmapWindow(qt_xdisplay(), hack);
75  XDestroyWindow(qt_xdisplay(), hack);
76 }
77 
78 void Systemtray::initSystray(void)
79 {
80  bool existing = false;
81  //bool content = false;
82  Display *display = qt_xdisplay();
83  no_of_systray_windows = 0;
84 
85  kwin_module = new KWinModule();
86  systemTrayWindows = kwin_module->systemTrayWindows();
87  Q3ValueList<WId>::ConstIterator end(systemTrayWindows.end());
88  for (Q3ValueList<WId>::ConstIterator it = systemTrayWindows.begin(); it != end; ++it) {
89  no_of_systray_windows++;
90  QXEmbed *emb;
91 
92  emb = new QXEmbed(this);
93  emb->setBackgroundMode(FixedPixmap);
94 
95  emb->setAutoDelete(false);
96 
97  connect(emb, SIGNAL(embeddedWindowDestroyed()), SLOT(updateTrayWindows()));
98 
99  m_Wins.append(emb);
100 
101  emb->embed(*it);
102  emb->resize(24, 24);
103  emb->show();
104  existing = true;
105  }
106 
107  updateTrayWindows();
108 
109  connect(kwin_module, SIGNAL(systemTrayWindowAdded(WId)), SLOT(systemTrayWindowAdded(WId)));
110  connect(kwin_module, SIGNAL(systemTrayWindowRemoved(WId)), SLOT(systemTrayWindowRemoved(WId)));
111 
112  Q3CString screenstr;
113  screenstr.setNum(qt_xscreen());
114  Q3CString trayatom = "_NET_SYSTEM_TRAY_S" + screenstr;
115 
116  net_system_tray_selection = XInternAtom(display, trayatom, false);
117  net_system_tray_opcode = XInternAtom(display, "_NET_SYSTEM_TRAY_OPCODE", false);
118 
119  // Acquire system tray
120  XSetSelectionOwner(display,
121  net_system_tray_selection,
122  winId(),
123  CurrentTime);
124 
125  WId root = qt_xrootwin();
126 
127  if (XGetSelectionOwner(display, net_system_tray_selection) == winId()) {
128  XClientMessageEvent xev;
129 
130  xev.type = ClientMessage;
131  xev.window = root;
132 
133  xev.message_type = XInternAtom(display, "MANAGER", false);
134  xev.format = 32;
135 
136  xev.data.l[0] = CurrentTime;
137  xev.data.l[1] = net_system_tray_selection;
138  xev.data.l[2] = winId();
139  xev.data.l[3] = 0; /* Manager specific data */
140  xev.data.l[4] = 0; /* Manager specific data */
141 
142  XSendEvent(display, root, false, StructureNotifyMask, (XEvent *)&xev);
143  }
144 }
145 
146 void Systemtray::updateTrayWindows(void)
147 {
148  QXEmbed *emb;
149 
150  emb = m_Wins.first();
151  while ((emb = m_Wins.current()) != 0L) {
152  WId wid = emb->embeddedWinId();
153  if ((wid == 0) || !kwin_module->systemTrayWindows().contains(wid))
154  m_Wins.remove(emb);
155  else
156  m_Wins.next();
157  }
158  layoutSystray();
159 }
160 void Systemtray::layoutSystray()
161 {
162  int i = 0, a = 0;
163 
164  QXEmbed* emb;
165  int x = 0;
166  int count = 0;
167 
168  //How many systray icons can fit on a line?
169  int aa = width() / 24;
170 
171  if (aa < 1) {
172  /* The place is to small to display a icon we make than one line with
173  icons that we display at the top */
174  aa = 1;
175  }
176 
177  for (emb = m_Wins.first(); emb != 0L; emb = m_Wins.next()) {
178  x = 2 + i * 24;
179 
180  emb->move(a*24, x);
181  a++;
182 
183  if (a + 1 > aa) {
184  a = 0;
185  i++;
186  }
187 
188  count++;
189  emb->repaint();
190  }
191 }
192 
193 void Systemtray::systemTrayWindowAdded(WId w)
194 {
195  //bool content = false;
196  QXEmbed *emb;
197  no_of_systray_windows++;
198  emit updated();
199 
200  emb = new QXEmbed(this);
201 
202  emb->setAutoDelete(false);
203  //emb->setBackgroundMode(X11ParentRelative);
204  emb->setBackgroundMode(FixedPixmap);
205  connect(emb, SIGNAL(embeddedWindowDestroyed()), SLOT(updateTrayWindows()));
206  m_Wins.append(emb);
207 
208  emb->embed(w);
209  emb->resize(24, 24);
210  emb->show();
211 
212  layoutSystray();
213 }
214 
215 void Systemtray::systemTrayWindowRemoved(WId)
216 {
217  no_of_systray_windows--;
218  emit updated();
219  updateTrayWindows();
220 }
221 
222 int Systemtray::getCurrentWindowCount()
223 {
224  return no_of_systray_windows;
225 }
226 
227 #include "systemtray.moc"
Systemtray::Systemtray
Systemtray(QWidget *parent)
Definition: systemtray.cpp:39
Systemtray::updateTrayWindows
void updateTrayWindows()
Definition: systemtray.cpp:146
Systemtray::systemTrayWindowAdded
void systemTrayWindowAdded(WId w)
Definition: systemtray.cpp:193
QWidget
Systemtray::getTraySize
int getTraySize()
Definition: systemtray.cpp:50
Systemtray::initSystray
virtual void initSystray(void)
Definition: systemtray.cpp:78
Systemtray::getCurrentWindowCount
int getCurrentWindowCount()
Definition: systemtray.cpp:222
Systemtray::updateBackgroundPixmap
void updateBackgroundPixmap(const QPixmap &)
Definition: systemtray.cpp:56
Systemtray::systemTrayWindowRemoved
void systemTrayWindowRemoved(WId w)
Definition: systemtray.cpp:215
Systemtray::~Systemtray
~Systemtray()
Definition: systemtray.cpp:44
Systemtray::layoutSystray
void layoutSystray()
Definition: systemtray.cpp:160
Systemtray::updated
void updated()
systemtray.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:07:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal