@ -30,7 +30,7 @@
# include <tqfileinfo.h>
# include <tqfileinfo.h>
# include <tqapplication.h>
# include <tqapplication.h>
# include "trace.h"
# include "trace.h"
# include "qtraylabel.h"
# include <tdeconfig.h>
# include <kiconloader.h>
# include <kiconloader.h>
# include <tdeglobal.h>
# include <tdeglobal.h>
@ -43,9 +43,10 @@
# include <stdlib.h>
# include <stdlib.h>
# include <sys/types.h>
# include <sys/types.h>
# include <sys/wait.h>
# include <sys/wait.h>
# include "util.h"
# include "util.h"
# include "qtraylabel.h"
void TQTrayLabel : : initialize ( void )
void TQTrayLabel : : initialize ( void )
{
{
mDocked = false ;
mDocked = false ;
@ -82,7 +83,7 @@ const char *TQTrayLabel::me(void) const
{
{
static char temp [ 100 ] ;
static char temp [ 100 ] ;
snprintf ( temp , sizeof ( temp ) , " (%s,PID=%i,WID=0x%x) " ,
snprintf ( temp , sizeof ( temp ) , " (%s,PID=%i,WID=0x%x) " ,
mProgName [ 0 ] . l atin1 ( ) , mPid , ( unsigned ) mDockedWindow ) ;
mProgName [ 0 ] . l ocal8Bit( ) . data ( ) , mPid , ( unsigned ) mDockedWindow ) ;
return temp ;
return temp ;
}
}
@ -128,15 +129,15 @@ void TQTrayLabel::scanClients()
for ( unsigned i = 0 ; i < nchildren ; i + + )
for ( unsigned i = 0 ; i < nchildren ; i + + )
{
{
Window w = XmuClientWindow ( display , children [ i ] ) ;
Window w = XmuClientWindow ( display , children [ i ] ) ;
TRACE ( " \t %s checking 0x%x" , me ( ) , ( unsigned ) w ) ;
TRACE ( " \t %s checking (1) 0x%x" , me ( ) , ( unsigned ) w ) ;
if ( ! isNormalWindow ( display , w ) ) continue ;
if ( ! isNormalWindow ( display , w ) ) continue ;
if ( analyzeWindow ( display , w , mPid , ename . l atin1 ( ) ) )
if ( analyzeWindow ( display , w , mPid , ename . l ocal8Bit ( ) ) )
{
{
TRACE ( " \t %s SOULMATE FOUND " , me ( ) ) ;
TRACE ( " \t %s SOULMATE FOUND (1) " , me ( ) ) ;
setDockedWindow ( w ) ;
setDockedWindow ( w ) ;
break ;
return ;
}
}
}
}
}
}
/*
/*
@ -222,7 +223,7 @@ void TQTrayLabel::dock(void)
{
{
TRACE ( " %s " , me ( ) ) ;
TRACE ( " %s " , me ( ) ) ;
mDocked = true ;
mDocked = true ;
if ( mDockedWindow = = None ) return ; // nothing to add
if ( mDockedWindow = = None ) return ; // nothing to add
if ( mSysTray = = None ) // no system tray yet
if ( mSysTray = = None ) // no system tray yet
{
{
@ -243,7 +244,7 @@ void TQTrayLabel::dock(void)
Atom tray_atom =
Atom tray_atom =
XInternAtom ( display , " _KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR " , False ) ;
XInternAtom ( display , " _KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR " , False ) ;
XChangeProperty ( display , wid , tray_atom , XA_WINDOW , 32 ,
XChangeProperty ( display , wid , tray_atom , XA_WINDOW , 32 ,
PropModeReplace , ( unsigned char * ) & wid , 1 ) ;
PropModeReplace , ( unsigned char * ) & wid , 1 ) ;
// 3. All other KDEs
// 3. All other KDEs
tray_atom = XInternAtom ( display , " KWM_DOCKWINDOW " , False ) ;
tray_atom = XInternAtom ( display , " KWM_DOCKWINDOW " , False ) ;
@ -255,7 +256,7 @@ void TQTrayLabel::dock(void)
handleTitleChange ( ) ;
handleTitleChange ( ) ;
handleIconChange ( ) ;
handleIconChange ( ) ;
if ( mProgName . count ( ) = = 0 ) setAppName ( mClass ) ;
if ( mProgName . count ( ) = = 0 ) setAppName ( mClass ) ;
/*
/*
* For Gnome , a delay is required before we do a show ( dont ask me why )
* For Gnome , a delay is required before we do a show ( dont ask me why )
@ -324,12 +325,12 @@ void TQTrayLabel::map(void)
}
}
XMapWindow ( display , mDockedWindow ) ;
XMapWindow ( display , mDockedWindow ) ;
mSizeHint . flags = USPosition ; // Obsolete ?
mSizeHint . flags = USPosition ; // Obsolete ?
XSetWMNormalHints ( display , mDockedWindow , & mSizeHint ) ;
XSetWMNormalHints ( display , mDockedWindow , & mSizeHint ) ;
// make it the active window
// make it the active window
long l [ 5 ] = { None , CurrentTime , None , 0 , 0 } ;
long l [ 5 ] = { None , CurrentTime , None , 0 , 0 } ;
sendMessage ( display , tqt_xrootwin ( ) , mDockedWindow , " _NET_ACTIVE_WINDOW " , 32 ,
sendMessage ( display , tqt_xrootwin ( ) , mDockedWindow , " _NET_ACTIVE_WINDOW " , 32 ,
SubstructureNotifyMask | SubstructureRedirectMask , l , sizeof ( l ) ) ;
SubstructureNotifyMask | SubstructureRedirectMask , l , sizeof ( l ) ) ;
// skipTaskbar modifies _NET_WM_STATE. Make sure we dont override WMs value
// skipTaskbar modifies _NET_WM_STATE. Make sure we dont override WMs value
TQTimer : : singleShot ( 230 , this , SLOT ( skipTaskbar ( ) ) ) ;
TQTimer : : singleShot ( 230 , this , SLOT ( skipTaskbar ( ) ) ) ;
// disable docking when minized for some time (since we went to Iconic state)
// disable docking when minized for some time (since we went to Iconic state)
@ -357,7 +358,7 @@ void TQTrayLabel::withdraw(void)
* state will remove us from the taskbar .
* state will remove us from the taskbar .
* Reference : ICCCM 4.1 .4 Changing Window State
* Reference : ICCCM 4.1 .4 Changing Window State
*/
*/
XIconifyWindow ( display , mDockedWindow , screen ) ; // good for effects too
XIconifyWindow ( display , mDockedWindow , screen ) ; // good for effects too
XUnmapWindow ( display , mDockedWindow ) ;
XUnmapWindow ( display , mDockedWindow ) ;
XUnmapEvent ev ;
XUnmapEvent ev ;
memset ( & ev , 0 , sizeof ( ev ) ) ;
memset ( & ev , 0 , sizeof ( ev ) ) ;
@ -389,8 +390,8 @@ void TQTrayLabel::skipTaskbar(void)
Atom _NET_WM_STATE = XInternAtom ( display , " _NET_WM_STATE " , True ) ;
Atom _NET_WM_STATE = XInternAtom ( display , " _NET_WM_STATE " , True ) ;
Atom skip_atom = XInternAtom ( display , " _NET_WM_STATE_SKIP_TASKBAR " , False ) ;
Atom skip_atom = XInternAtom ( display , " _NET_WM_STATE_SKIP_TASKBAR " , False ) ;
int ret = XGetWindowProperty ( display , mDockedWindow , _NET_WM_STATE , 0 ,
int ret = XGetWindowProperty ( display , mDockedWindow , _NET_WM_STATE , 0 ,
20 , False , AnyPropertyType , & type , & format ,
20 , False , AnyPropertyType , & type , & format ,
& nitems , & left , ( unsigned char * * ) & data ) ;
& nitems , & left , ( unsigned char * * ) & data ) ;
Atom * old_states = ( Atom * ) data ;
Atom * old_states = ( Atom * ) data ;
bool append = true , replace = false ;
bool append = true , replace = false ;
@ -406,7 +407,7 @@ void TQTrayLabel::skipTaskbar(void)
{
{
if ( num_states < nitems )
if ( num_states < nitems )
{
{
replace = true ; // need to remove skip_atom
replace = true ; // need to remove skip_atom
for ( ; num_states < nitems - 1 ; num_states + + )
for ( ; num_states < nitems - 1 ; num_states + + )
old_states [ num_states ] = old_states [ num_states + 1 ] ;
old_states [ num_states ] = old_states [ num_states + 1 ] ;
}
}
@ -442,6 +443,7 @@ void TQTrayLabel::setSkipTaskbar(bool skip)
void TQTrayLabel : : close ( void )
void TQTrayLabel : : close ( void )
{
{
TRACE ( " %s " , me ( ) ) ;
TRACE ( " %s " , me ( ) ) ;
undock ( ) ;
Display * display = TQPaintDevice : : x11AppDisplay ( ) ;
Display * display = TQPaintDevice : : x11AppDisplay ( ) ;
long l [ 5 ] = { 0 , 0 , 0 , 0 , 0 } ;
long l [ 5 ] = { 0 , 0 , 0 , 0 , 0 } ;
map ( ) ;
map ( ) ;
@ -457,7 +459,7 @@ void TQTrayLabel::setTrayIcon(const TQString& icon)
{
{
mCustomIcon = icon ;
mCustomIcon = icon ;
if ( TQPixmap ( mCustomIcon ) . isNull ( ) ) mCustomIcon = TQString : : null ;
if ( TQPixmap ( mCustomIcon ) . isNull ( ) ) mCustomIcon = TQString : : null ;
TRACE ( " %s mCustomIcon=%s " , me ( ) , mCustomIcon . l atin1 ( ) ) ;
TRACE ( " %s mCustomIcon=%s " , me ( ) , mCustomIcon . l ocal8Bit ( ) ) ;
updateIcon ( ) ;
updateIcon ( ) ;
}
}
@ -476,8 +478,7 @@ void TQTrayLabel::setDockedWindow(Window w)
if ( w ! = None ) mDockedWindow = canDockWindow ( w ) ? w : None ;
if ( w ! = None ) mDockedWindow = canDockWindow ( w ) ? w : None ;
else mDockedWindow = None ;
else mDockedWindow = None ;
if ( mDockedWindow = = None ) mRealityMonitor . start ( 500 ) ;
if ( mDockedWindow = = None ) mRealityMonitor . start ( 500 ) ; else mRealityMonitor . stop ( ) ;
else mRealityMonitor . stop ( ) ;
Display * d = TQPaintDevice : : x11AppDisplay ( ) ;
Display * d = TQPaintDevice : : x11AppDisplay ( ) ;
@ -491,7 +492,7 @@ void TQTrayLabel::setDockedWindow(Window w)
subscribe ( d , w ,
subscribe ( d , w ,
StructureNotifyMask | PropertyChangeMask |
StructureNotifyMask | PropertyChangeMask |
VisibilityChangeMask | FocusChangeMask ,
VisibilityChangeMask | FocusChangeMask ,
true ) ;
true ) ;
}
}
@ -515,7 +516,7 @@ void TQTrayLabel::setDockedWindow(Window w)
void TQTrayLabel : : balloonText ( )
void TQTrayLabel : : balloonText ( )
{
{
TRACE ( " %s BalloonText=%s ToolTipText=%s " , me ( ) ,
TRACE ( " %s BalloonText=%s ToolTipText=%s " , me ( ) ,
mBalloon - > text ( ) . l atin1 ( ) , TQToolTip : : textFor ( this ) . l atin1 ( ) ) ;
mBalloon - > text ( ) . l ocal8Bit ( ) , TQToolTip : : textFor ( this ) . l ocal8Bit ( ) ) ;
if ( mBalloon - > text ( ) = = TQToolTip : : textFor ( this ) ) return ;
if ( mBalloon - > text ( ) = = TQToolTip : : textFor ( this ) ) return ;
#if 0 // I_GOT_NETWM_BALLOONING_TO_WORK
#if 0 // I_GOT_NETWM_BALLOONING_TO_WORK
@ -528,7 +529,7 @@ void TQTrayLabel::balloonText()
SubstructureNotifyMask | SubstructureRedirectMask ,
SubstructureNotifyMask | SubstructureRedirectMask ,
l , sizeof ( l ) ) ;
l , sizeof ( l ) ) ;
int length = mTitle . length ( ) ;
int length = mTitle . length ( ) ;
const char * data = mTitle . l atin1 ( ) ;
const char * data = mTitle . l ocal8Bit ( ) ;
while ( length > 0 )
while ( length > 0 )
{
{
sendMessage ( display , mSystemTray , winId ( ) , " _NET_SYSTEM_TRAY_MESSAGE_DATA " , 8 ,
sendMessage ( display , mSystemTray , winId ( ) , " _NET_SYSTEM_TRAY_MESSAGE_DATA " , 8 ,
@ -564,7 +565,7 @@ void TQTrayLabel::handleTitleChange(void)
XFetchName ( display , mDockedWindow , & window_name ) ;
XFetchName ( display , mDockedWindow , & window_name ) ;
mTitle = window_name ;
mTitle = window_name ;
TRACE ( " %s has title [%s] " , me ( ) , mTitle . l atin1 ( ) ) ;
TRACE ( " %s has title [%s] " , me ( ) , mTitle . l ocal8Bit ( ) ) ;
if ( window_name ) XFree ( window_name ) ;
if ( window_name ) XFree ( window_name ) ;
XClassHint ch ;
XClassHint ch ;
@ -698,10 +699,10 @@ bool TQTrayLabel::x11EventFilter(XEvent *ev)
mWithdrawn = true ;
mWithdrawn = true ;
unmapEvent ( ) ;
unmapEvent ( ) ;
}
}
else if ( event - > type = = FocusOut )
else if ( event - > type = = FocusOut )
{
{
focusLostEvent ( ) ;
focusLostEvent ( ) ;
}
}
return true ; // Dont process this again
return true ; // Dont process this again
}
}
@ -713,7 +714,7 @@ bool TQTrayLabel::x11EventFilter(XEvent *ev)
Window w = XmuClientWindow ( display , ( ( XMapEvent * ) event ) - > window ) ;
Window w = XmuClientWindow ( display , ( ( XMapEvent * ) event ) - > window ) ;
if ( ! isNormalWindow ( display , w ) ) return FALSE ;
if ( ! isNormalWindow ( display , w ) ) return FALSE ;
if ( ! analyzeWindow ( display , w , mPid ,
if ( ! analyzeWindow ( display , w , mPid ,
TQFileInfo ( mProgName [ 0 ] ) . fileName ( ) . l atin1 ( ) ) ) return FALSE ;
TQFileInfo ( mProgName [ 0 ] ) . fileName ( ) . l ocal8Bit ( ) ) ) return FALSE ;
// All right. Lets dock this baby
// All right. Lets dock this baby
setDockedWindow ( w ) ;
setDockedWindow ( w ) ;
return true ;
return true ;
@ -759,8 +760,8 @@ void TQTrayLabel::propertyChangeEvent(Atom property)
unsigned long nitems , after ;
unsigned long nitems , after ;
unsigned char * data = NULL ;
unsigned char * data = NULL ;
int r = XGetWindowProperty ( display , mDockedWindow , WM_STATE ,
int r = XGetWindowProperty ( display , mDockedWindow , WM_STATE ,
0 , 1 , False , AnyPropertyType , & type ,
0 , 1 , False , AnyPropertyType , & type ,
& format , & nitems , & after , & data ) ;
& format , & nitems , & after , & data ) ;
if ( ( r = = Success ) & & data & & ( * ( long * ) data = = IconicState ) )
if ( ( r = = Success ) & & data & & ( * ( long * ) data = = IconicState ) )
{
{
@ -771,40 +772,37 @@ void TQTrayLabel::propertyChangeEvent(Atom property)
}
}
// Session Management
// Session Management
bool TQTrayLabel : : saveState ( TQSettings & settings )
void TQTrayLabel : : saveState ( TDEConfig * config )
{
{
TRACE ( " %s saving state " , me ( ) ) ;
TRACE ( " %s saving state " , me ( ) ) ;
settings . writeEntry ( " /Application " , mProgName . join ( " " ) ) ;
config - > writeEntry ( " Application " , mProgName . join ( " " ) ) ;
settings . writeEntry ( " /CustomIcon " , mCustomIcon ) ;
config - > writeEntry ( " BalloonTimeout " , mBalloonTimeout ) ;
settings . writeEntry ( " /BalloonTimeout " , mBalloonTimeout ) ;
config - > writeEntry ( " CustomIcon " , mCustomIcon ) ;
settings . writeEntry ( " /DockWhenMinimized " , mDockWhenMinimized ) ;
config - > writeEntry ( " DockWhenMinimized " , mDockWhenMinimized ) ;
settings . writeEntry ( " /SkipTaskbar " , mSkippingTaskbar ) ;
config - > writeEntry ( " SkipTaskbar " , mSkippingTaskbar ) ;
settings . writeEntry ( " /Withdraw " , mWithdrawn ) ;
config - > writeEntry ( " Withdraw " , mWithdrawn ) ;
return true ;
}
}
bool TQTrayLabel : : restoreState ( T QSettings & settings )
bool TQTrayLabel : : restoreState ( T DEConfig * config )
{
{
TRACE ( " %s restoring state " , me ( ) ) ;
TRACE ( " %s restoring state " , me ( ) ) ;
mCustomIcon = settings . readEntry ( " /CustomIcon " ) ;
setBalloonTimeout( config - > readNumEntry ( " BalloonTimeout " , 4000 ) ) ;
setBalloonTimeout( settings . readNumEntry ( " /BalloonTimeout " ) ) ;
mCustomIcon = config - > readEntry ( " CustomIcon " , TQString : : null ) ;
setDockWhenMinimized ( settings. readBoolEntry ( " / DockWhenMinimized" ) ) ;
setDockWhenMinimized ( config- > readBoolEntry ( " DockWhenMinimized" , false ) ) ;
setSkipTaskbar ( settings. readBoolEntry ( " / SkipTaskbar" ) ) ;
setSkipTaskbar ( config- > readBoolEntry ( " SkipTaskbar" , false ) ) ;
mWithdrawn = settings. readBoolEntry ( " / Withdraw" ) ;
mWithdrawn = config- > readBoolEntry ( " Withdraw" , false ) ;
dock ( ) ;
dock ( ) ;
scanClients ( ) ; // Grab window
/*
if ( mWithdrawn )
* Since we are getting restored , it is likely that the application that we
{
* are interested in has already been started ( if we didnt launch it ) .
withdraw ( ) ;
* So we scan the list of windows and grab the first one that satisfies us
}
* This implicitly assumes that if mPid ! = 0 then we launched it . Wait till
else
* the application really shows itself up before we do a scan ( the reason
{
* why we have 2 s
map ( ) ;
*/
}
if ( ! mPid ) TQTimer : : singleShot ( 2000 , this , SLOT ( scanClients ( ) ) ) ;
return true ;
return true ;
}
}
// End kicking butt
// End kicking butt