19 #include "systemtray.h"
23 #include <kiconloader.h>
25 #include <kwinmodule.h>
26 #include <kmessagebox.h>
30 #include <tqpopupmenu.h>
31 #include <tqdragobject.h>
33 #include <tqstringlist.h>
38 Systemtray::Systemtray(TQWidget* parent)
39 : TQWidget(parent,0,0)
41 setBackgroundOrigin(ParentOrigin);
42 setBackgroundMode(FixedPixmap);
43 m_Wins.setAutoDelete(
true);
47 Systemtray::~Systemtray()
52 int Systemtray::getTraySize() {
54 return (
int) kwin_module->systemTrayWindows().size();
57 void Systemtray::updateBackgroundPixmap (
const TQPixmap & pixmap) {
59 setPaletteBackgroundPixmap (pixmap);
60 for (emb = m_Wins.first(); emb != 0L; emb = m_Wins.next()) {
64 TQPixmap bug = TQPixmap(emb->size());
65 bitBlt(TQT_TQPAINTDEVICE(&bug), 0, 0, TQT_TQPAINTDEVICE(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);
70 TQPoint topPoint = mapToGlobal(TQPoint(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);
78 void Systemtray::initSystray(
void )
80 bool existing =
false;
82 Display *display = qt_xdisplay();
83 no_of_systray_windows = 0;
85 kwin_module =
new KWinModule();
86 systemTrayWindows = kwin_module->systemTrayWindows();
87 TQValueList<WId>::ConstIterator end(systemTrayWindows.end());
88 for (TQValueList<WId>::ConstIterator it = systemTrayWindows.begin(); it!=end; ++it)
90 no_of_systray_windows++;
93 emb =
new QXEmbed(
this);
94 emb->setBackgroundMode(FixedPixmap);
96 emb->setAutoDelete(
false);
98 connect(emb, TQT_SIGNAL(embeddedWindowDestroyed()), TQT_SLOT(updateTrayWindows()));
110 connect(kwin_module, TQT_SIGNAL(systemTrayWindowAdded(WId)), TQT_SLOT(systemTrayWindowAdded(WId)));
111 connect(kwin_module, TQT_SIGNAL(systemTrayWindowRemoved(WId)), TQT_SLOT(systemTrayWindowRemoved(WId)));
114 screenstr.setNum(qt_xscreen());
115 TQCString trayatom =
"_NET_SYSTEM_TRAY_S" + screenstr;
117 net_system_tray_selection = XInternAtom( display, trayatom,
false );
118 net_system_tray_opcode = XInternAtom( display,
"_NET_SYSTEM_TRAY_OPCODE",
false );
121 XSetSelectionOwner( display,
122 net_system_tray_selection,
126 WId root = qt_xrootwin();
128 if (XGetSelectionOwner(display, net_system_tray_selection) == winId())
130 XClientMessageEvent xev;
132 xev.type = ClientMessage;
135 xev.message_type = XInternAtom(display,
"MANAGER",
false);
138 xev.data.l[0] = CurrentTime;
139 xev.data.l[1] = net_system_tray_selection;
140 xev.data.l[2] = winId();
144 XSendEvent( display, root,
false, StructureNotifyMask, (XEvent *)&xev );
148 void Systemtray::updateTrayWindows(
void )
152 emb = m_Wins.first();
153 while ((emb = m_Wins.current()) != 0L)
155 WId wid = emb->embeddedWinId();
156 if ((wid == 0) || !kwin_module->systemTrayWindows().contains(wid) )
163 void Systemtray::layoutSystray()
172 int aa = width() / 24;
181 for (emb = m_Wins.first(); emb != 0L; emb = m_Wins.next()) {
197 void Systemtray::systemTrayWindowAdded( WId w )
201 no_of_systray_windows++;
204 emb =
new QXEmbed(
this);
206 emb->setAutoDelete(
false);
208 emb->setBackgroundMode(FixedPixmap);
209 connect(emb, TQT_SIGNAL(embeddedWindowDestroyed()), TQT_SLOT(updateTrayWindows()));
219 void Systemtray::systemTrayWindowRemoved(WId)
221 no_of_systray_windows--;
226 int Systemtray::getCurrentWindowCount()
228 return no_of_systray_windows;
231 #include "systemtray.moc"