• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • superkaramba
 

superkaramba

  • superkaramba
  • src
systemtray.cpp
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 <tqobject.h>
23 #include <kiconloader.h>
24 #include <tdelocale.h>
25 #include <twinmodule.h>
26 #include <tdemessagebox.h>
27 #include <kdebug.h>
28 #include <twin.h>
29 
30 #include <tqpopupmenu.h>
31 #include <tqdragobject.h>
32 #include <tqlayout.h>
33 #include <tqstringlist.h>
34 #include <tqpixmap.h>
35 
36 #include <X11/Xlib.h>
37 
38 Systemtray::Systemtray(TQWidget* parent)
39  : TQWidget(parent,0,0)
40 {
41  setBackgroundOrigin(ParentOrigin);
42  setBackgroundMode(FixedPixmap);
43  m_Wins.setAutoDelete(true);
44 }
45 
46 
47 Systemtray::~Systemtray()
48 {
49  m_Wins.clear();
50 }
51 
52 int Systemtray::getTraySize() {
53 
54  return (int) twin_module->systemTrayWindows().size();
55 }
56 
57 void Systemtray::updateBackgroundPixmap ( const TQPixmap & pixmap) {
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  TQPixmap bug = TQPixmap(emb->size());
65  bitBlt(&bug, 0, 0, const_cast<TQPixmap*>(&pixmap), emb->parentWidget()->x()+emb->x(), emb->parentWidget()->y()+emb->y(), emb->width(), emb->height(),TQt::CopyROP, false);
66  emb->setPaletteBackgroundPixmap (bug);
67 
68  }
69 
70  TQPoint topPoint = mapToGlobal(TQPoint(0,0));
71  Window hack = XCreateSimpleWindow(tqt_xdisplay(), winId(), 0,0, width(), height(), 0, 0, 0);
72  XRaiseWindow(tqt_xdisplay(), hack);
73  XMapWindow(tqt_xdisplay(), hack);
74  XUnmapWindow(tqt_xdisplay(), hack);
75  XDestroyWindow(tqt_xdisplay(), hack);
76 }
77 
78 void Systemtray::initSystray( void )
79 {
80  bool existing = false;
81  //bool content = false;
82  Display *display = tqt_xdisplay();
83  no_of_systray_windows = 0;
84 
85  twin_module = new KWinModule();
86  systemTrayWindows = twin_module->systemTrayWindows();
87  TQValueList<WId>::ConstIterator end(systemTrayWindows.end());
88  for (TQValueList<WId>::ConstIterator it = systemTrayWindows.begin(); it!=end; ++it)
89  {
90  no_of_systray_windows++;
91  QXEmbed *emb;
92 
93  emb = new QXEmbed(this);
94  emb->setBackgroundMode(FixedPixmap);
95 
96  emb->setAutoDelete(false);
97 
98  connect(emb, TQ_SIGNAL(embeddedWindowDestroyed()), TQ_SLOT(updateTrayWindows()));
99 
100  m_Wins.append(emb);
101 
102  emb->embed(*it);
103  emb->resize(24, 24);
104  emb->show();
105  existing = true;
106  }
107 
108  updateTrayWindows();
109 
110  connect(twin_module, TQ_SIGNAL(systemTrayWindowAdded(WId)), TQ_SLOT(systemTrayWindowAdded(WId)));
111  connect(twin_module, TQ_SIGNAL(systemTrayWindowRemoved(WId)), TQ_SLOT(systemTrayWindowRemoved(WId)));
112 
113  TQCString screenstr;
114  screenstr.setNum(tqt_xscreen());
115  TQCString trayatom = "_NET_SYSTEM_TRAY_S" + screenstr;
116 
117  net_system_tray_selection = XInternAtom( display, trayatom, false );
118  net_system_tray_opcode = XInternAtom( display, "_NET_SYSTEM_TRAY_OPCODE", false );
119 
120  // Acquire system tray
121  XSetSelectionOwner( display,
122  net_system_tray_selection,
123  winId(),
124  CurrentTime );
125 
126  WId root = tqt_xrootwin();
127 
128  if (XGetSelectionOwner(display, net_system_tray_selection) == winId())
129  {
130  XClientMessageEvent xev;
131 
132  xev.type = ClientMessage;
133  xev.window = root;
134 
135  xev.message_type = XInternAtom(display, "MANAGER", false);
136  xev.format = 32;
137 
138  xev.data.l[0] = CurrentTime;
139  xev.data.l[1] = net_system_tray_selection;
140  xev.data.l[2] = winId();
141  xev.data.l[3] = 0; /* Manager specific data */
142  xev.data.l[4] = 0; /* Manager specific data */
143 
144  XSendEvent( display, root, false, StructureNotifyMask, (XEvent *)&xev );
145  }
146 }
147 
148 void Systemtray::updateTrayWindows( void )
149 {
150  QXEmbed *emb;
151 
152  emb = m_Wins.first();
153  while ((emb = m_Wins.current()) != 0L)
154  {
155  WId wid = emb->embeddedWinId();
156  if ((wid == 0) || !twin_module->systemTrayWindows().contains(wid) )
157  m_Wins.remove(emb);
158  else
159  m_Wins.next();
160  }
161  layoutSystray();
162 }
163 void Systemtray::layoutSystray()
164 {
165  int i = 0, a = 0;
166 
167  QXEmbed* emb;
168  int x = 0;
169  int count = 0;
170 
171  //How many systray icons can fit on a line?
172  int aa = width() / 24;
173 
174  if(aa < 1)
175  {
176  /* The place is to small to display a icon we make than one line with
177  icons that we display at the top */
178  aa = 1;
179  }
180 
181  for (emb = m_Wins.first(); emb != 0L; emb = m_Wins.next()) {
182  x = 2+i*24;
183 
184  emb->move(a*24, x);
185  a++;
186 
187  if(a+1 > aa) {
188  a = 0;
189  i++;
190  }
191 
192  count++;
193  emb->repaint();
194  }
195 }
196 
197 void Systemtray::systemTrayWindowAdded( WId w )
198 {
199  //bool content = false;
200  QXEmbed *emb;
201  no_of_systray_windows++;
202  emit updated();
203 
204  emb = new QXEmbed(this);
205 
206  emb->setAutoDelete(false);
207  //emb->setBackgroundMode(X11ParentRelative);
208  emb->setBackgroundMode(FixedPixmap);
209  connect(emb, TQ_SIGNAL(embeddedWindowDestroyed()), TQ_SLOT(updateTrayWindows()));
210  m_Wins.append(emb);
211 
212  emb->embed(w);
213  emb->resize(24, 24);
214  emb->show();
215 
216  layoutSystray();
217 }
218 
219 void Systemtray::systemTrayWindowRemoved(WId)
220 {
221  no_of_systray_windows--;
222  emit updated();
223  updateTrayWindows();
224 }
225 
226 int Systemtray::getCurrentWindowCount()
227 {
228  return no_of_systray_windows;
229 }
230 
231 #include "systemtray.moc"

superkaramba

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

superkaramba

Skip menu "superkaramba"
  • kcalc
  •   knumber
  • superkaramba
Generated for superkaramba by doxygen 1.8.13
This website is maintained by Timothy Pearson.