3 #include <kapplication.h>
4 #include <kaboutdata.h>
5 #include <kcmdlineargs.h>
10 #include "ksystraycmd.h"
15 const int XFocusOut
= FocusOut
;
16 const int XFocusIn
= FocusIn
;
24 int main( int argc
, char *argv
[] )
26 KAboutData
aboutData( "ksystraycmd", 0, ki18n( "KSysTrayCmd" ),
28 ki18n( "Allows any application to be kept in the system tray" ),
29 KAboutData::License_GPL
,
30 ki18n("(C) 2001-2002 Richard Moore (rich@kde.org)") );
31 aboutData
.addAuthor( ki18n("Richard Moore"), KLocalizedString(), "rich@kde.org" );
33 KCmdLineArgs::init( argc
, argv
, &aboutData
);
35 KCmdLineOptions options
;
36 options
.add("!+command", ki18n("Command to execute"));
37 // "!" means: all options after command are treated as arguments to the command
38 options
.add("window <regexp>", ki18n("A regular expression matching the window title\n"
39 "If you do not specify one, then the very first window\n"
40 "to appear will be taken - not recommended."));
41 options
.add("wid <int>", ki18n("The window id of the target window\n"
42 "Specifies the id of the window to use. If the id starts with 0x\n"
43 "it is assumed to be in hex."));
44 options
.add("hidden", ki18n( "Hide the window to the tray on startup" ));
45 options
.add("startonshow", ki18n( "Wait until we are told to show the window before\n"
46 "executing the command" ));
47 options
.add("tooltip <text>", ki18n( "Sets the initial tooltip for the tray icon" ));
48 options
.add("keeprunning", ki18n( "Keep the tray icon even if the client exits. This option\n"
49 "has no effect unless startonshow is specified." ));
50 options
.add("ownicon", ki18n( "Use ksystraycmd's icon instead of the window's icon in the systray\n"
51 "(should be used with --icon to specify ksystraycmd icon)" ));
52 options
.add("ontop", ki18n( "Try to keep the window above other windows"));
53 options
.add("quitonhide", ki18n( "Quit the client when we are told to hide the window.\n"
54 "This has no effect unless startonshow is specified and implies keeprunning." ));
55 /*options.add("menuitem <item>", ki18n( "Adds a custom entry to the tray icon menu\n"
56 "The item should have the form text:command." ));*/
57 KCmdLineArgs::addCmdLineOptions( options
); // Add our own options.
62 // Setup the tray icon from the arguments.
64 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
68 QString wid
= args
->getOption( "wid" );
69 if ( !wid
.isEmpty() ) {
71 if ( wid
.startsWith( "0x" ) ) {
73 wid
= wid
.right( wid
.length() - 2 );
77 ulong w
= wid
.toULong( &ok
, base
);
79 cmd
.setTargetWindow( w
);
81 kWarning() << "KSysTrayCmd: Got bad win id" ;
85 // Read window title regexp
86 QString title
= args
->getOption( "window" );
87 if ( !title
.isEmpty() )
88 cmd
.setPattern( title
);
90 if ( title
.isEmpty() && wid
.isEmpty() && (args
->count() == 0) )
91 KCmdLineArgs::usageError(i18n("No command or window specified"));
95 for ( int i
= 0; i
< args
->count(); i
++ )
96 command
+= KShell::quoteArg(args
->arg(i
)) + ' ';
97 if ( !command
.isEmpty() )
98 cmd
.setCommand( command
);
101 QString tip
= args
->getOption( "tooltip" );
102 if ( !tip
.isEmpty() )
103 cmd
.setDefaultTip( tip
);
106 if ( args
->isSet( "keeprunning" ) )
107 cmd
.setNoQuit( true );
109 if ( args
->isSet( "quitonhide" ) ) {
110 cmd
.setNoQuit( true );
111 cmd
.setQuitOnHide( true );
115 if ( args
->isSet( "hidden" ) )
119 if ( args
->isSet( "ontop" ) )
122 // Use ksystraycmd icon
123 if ( args
->isSet( "ownicon" ) )
124 cmd
.setOwnIcon(true);
126 // Lazy invocation flag
127 if ( args
->isSet( "startonshow" ) ) {
128 cmd
.setStartOnShow( true );
136 fcntl(ConnectionNumber(QX11Info::display()), F_SETFD
, 1);