20 #include "kdetrayproxy.h"
22 #include <tdeapplication.h>
26 #include <sys/select.h>
28 #include <sys/types.h>
32 KDETrayProxy::KDETrayProxy()
33 : selection( makeSelectionAtom())
35 connect( &selection, TQ_SIGNAL( newOwner( Window )), TQ_SLOT( newOwner( Window )));
36 connect( &module, TQ_SIGNAL( windowAdded( WId )), TQ_SLOT( windowAdded( WId )));
38 for( TQValueList< WId >::ConstIterator it = module.windows().begin();
39 it != module.windows().end();
42 kapp->installX11EventFilter(
this );
46 Atom KDETrayProxy::makeSelectionAtom()
48 return XInternAtom( tqt_xdisplay(),
"_NET_SYSTEM_TRAY_S" + TQCString().setNum( tqt_xscreen()), False );
51 void KDETrayProxy::windowAdded( WId w )
53 NETWinInfo ni( tqt_xdisplay(), w, tqt_xrootwin(), NET::WMKDESystemTrayWinFor );
54 WId trayWinFor = ni.kdeSystemTrayWinFor();
58 if( !tray_windows.contains( w ))
59 tray_windows.append( w );
62 if( !pending_windows.contains( w ))
63 pending_windows.append( w );
64 docked_windows.remove( w );
65 Window owner = selection.owner();
71 dockWindow( w, owner );
74 void KDETrayProxy::newOwner( Window owner )
77 for( TQValueList< Window >::ConstIterator it = pending_windows.begin();
78 it != pending_windows.end();
80 dockWindow( *it, owner );
84 bool KDETrayProxy::x11Event( XEvent* e )
86 if( tray_windows.isEmpty())
88 if( e->type == DestroyNotify && tray_windows.contains( e->xdestroywindow.window ))
90 tray_windows.remove( e->xdestroywindow.window );
91 pending_windows.remove( e->xdestroywindow.window );
92 docked_windows.remove( e->xdestroywindow.window );
94 if( e->type == ReparentNotify && tray_windows.contains( e->xreparent.window ))
96 if( e->xreparent.parent == tqt_xrootwin())
98 if( !docked_windows.contains( e->xreparent.window ) || e->xreparent.serial >= docked_windows[ e->xreparent.window ] )
101 docked_windows.remove( e->xreparent.window );
102 if( !pending_windows.contains( e->xreparent.window ))
103 pending_windows.append( e->xreparent.window );
109 pending_windows.remove( e->xreparent.window );
112 if( e->type == UnmapNotify && tray_windows.contains( e->xunmap.window ))
114 if( docked_windows.contains( e->xunmap.window ) && e->xunmap.serial >= docked_windows[ e->xunmap.window ] )
117 XReparentWindow( tqt_xdisplay(), e->xunmap.window, tqt_xrootwin(), 0, 0 );
124 void KDETrayProxy::dockWindow( Window w, Window owner )
127 docked_windows[ w ] = XNextRequest( tqt_xdisplay());
128 static Atom prop = XInternAtom( tqt_xdisplay(),
"_XEMBED_INFO", False );
129 long data[ 2 ] = { 0, 1 };
130 XChangeProperty( tqt_xdisplay(), w, prop, prop, 32, PropModeReplace, (
unsigned char*)data, 2 );
132 hints.flags = PMinSize | PMaxSize;
133 hints.min_width = 24;
134 hints.max_width = 24;
135 hints.min_height = 24;
136 hints.max_height = 24;
137 XSetWMNormalHints( tqt_xdisplay(), w, &hints );
140 memset(&ev, 0,
sizeof( ev ));
141 static Atom atom = XInternAtom( tqt_xdisplay(),
"_NET_SYSTEM_TRAY_OPCODE", False );
142 ev.xclient.type = ClientMessage;
143 ev.xclient.window = owner;
144 ev.xclient.message_type = atom;
145 ev.xclient.format = 32;
146 ev.xclient.data.l[ 0 ] = get_tqt_x_time();
147 ev.xclient.data.l[ 1 ] = 0;
148 ev.xclient.data.l[ 2 ] = w;
149 ev.xclient.data.l[ 3 ] = 0;
150 ev.xclient.data.l[ 4 ] = 0;
151 XSendEvent( tqt_xdisplay(), owner, False, NoEventMask, &ev );
154 void KDETrayProxy::withdrawWindow( Window w )
156 XWithdrawWindow( tqt_xdisplay(), w, tqt_xscreen());
157 static Atom wm_state = XInternAtom( tqt_xdisplay(),
"WM_STATE", False );
162 unsigned long length, after;
164 int r = XGetWindowProperty( tqt_xdisplay(), w, wm_state, 0, 2,
165 False, AnyPropertyType, &type, &format,
166 &length, &after, &data );
167 bool withdrawn =
true;
168 if ( r == Success && data && format == 32 )
170 withdrawn = ( *(
long* )data == WithdrawnState );
171 XFree( (
char *)data );
177 tm.tv_usec = 10 * 1000;
178 select(0, NULL, NULL, NULL, &tm);
182 #include "kdetrayproxy.moc"
185 #include <tdecmdlineargs.h>
186 int main(
int argc,
char* argv[] )
190 app.disableSessionManagement();
static void init(int _argc, char **_argv, const char *_appname, const char *programName, const char *_description, const char *_version, bool noKApp=false)