00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "Application.h"
00022 #include <KDebug>
00023
00024
00025 #include <unistd.h>
00026
00027
00028 #ifdef Q_WS_X11
00029 #include <X11/Xlib.h>
00030 #include <X11/extensions/Xrender.h>
00031 #endif
00032
00033
00034 #include <KAboutData>
00035 #include <KCmdLineArgs>
00036 #include <KLocale>
00037 #include <KWindowSystem>
00038
00039 #define KONSOLE_VERSION "2.1"
00040
00041 using namespace Konsole;
00042
00043 #ifdef Q_WS_X11
00044 void getDisplayInformation(Display*& display , Visual*& visual , Colormap& colormap);
00045 #endif
00046
00047
00048
00049 void fillAboutData(KAboutData& aboutData);
00050 void fillCommandLineOptions(KCmdLineOptions& options);
00051 bool useTransparency();
00052 bool forceNewProcess();
00053
00054
00055
00056
00057
00058 extern "C" int KDE_EXPORT kdemain(int argc,char** argv)
00059 {
00060 KAboutData about( "konsole", 0,
00061 ki18n("Konsole"),
00062 KONSOLE_VERSION,
00063 ki18n("Terminal emulator"),
00064 KAboutData::License_GPL_V2
00065 );
00066 fillAboutData(about);
00067
00068 KCmdLineArgs::init(argc,argv,&about);
00069 KCmdLineOptions options;
00070 fillCommandLineOptions(options);
00071 KCmdLineArgs::addCmdLineOptions(options);
00072 KUniqueApplication::addCmdLineOptions();
00073
00074 KUniqueApplication::StartFlags startFlags;
00075 if (forceNewProcess())
00076 startFlags = KUniqueApplication::NonUniqueInstance;
00077
00078
00079
00080 if ( !KUniqueApplication::start(startFlags) )
00081 {
00082 exit(0);
00083 }
00084 #ifdef Q_WS_X11
00085 if ( useTransparency() )
00086 {
00087 Display* display = 0;
00088 Visual* visual = 0;
00089 Colormap colormap = 0;
00090
00091 getDisplayInformation(display,visual,colormap);
00092
00093 Application app(display,(Qt::HANDLE)visual,(Qt::HANDLE)colormap);
00094 return app.exec();
00095 }
00096 else
00097 #endif
00098 {
00099 Application app;
00100 return app.exec();
00101 }
00102 }
00103 bool forceNewProcess()
00104 {
00105
00106
00107
00108
00109 KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
00110 return isatty(1) && !args->isSet("new-tab");
00111 }
00112 bool useTransparency()
00113 {
00114 KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
00115 bool compositingAvailable = KWindowSystem::compositingActive() ||
00116 args->isSet("force-transparency");
00117 return compositingAvailable && args->isSet("transparency");
00118 }
00119 void fillCommandLineOptions(KCmdLineOptions& options)
00120 {
00121 options.add("profile <file>", ki18n("Name of profile to use for new Konsole instance"));
00122 options.add("list-profiles", ki18n("List the available profiles"));
00123
00124 options.add("background-mode", ki18n("Start Konsole in the background"
00125 " and bring to the front when the F12"
00126 " key is pressed"));
00127 options.add("new-tab",ki18n("Create a new tab in an existing window rather than creating a new window"));
00128 options.add("workdir <dir>", ki18n("Set the initial working directory of the new tab "
00129 "or window to 'dir'"));
00130 options.add("notransparency",ki18n("Disable transparent backgrounds, even if the system supports them."));
00131 options.add("force-transparency",ki18n("Try to enable transparency, even if the system does not appear to support it."));
00132 options.add("hold");
00133 options.add("noclose",ki18n("Do not close the initial session automatically when it ends."));
00134
00135 options.add("p <property=value>",ki18n("Change the value of a profile property."));
00136 options.add("!e <cmd>",ki18n("Command to execute"));
00137 options.add("+[args]",ki18n("Arguments passed to command"));
00138 }
00139
00140 void fillAboutData(KAboutData& aboutData)
00141 {
00142 aboutData.addAuthor(ki18n("Robert Knight"),ki18n("Maintainer"), "robertknight@gmail.com");
00143 aboutData.addAuthor(ki18n("Lars Doelle"),ki18n("Author"), "lars.doelle@on-line.de");
00144 aboutData.addCredit(ki18n("Kurt V. Hindenburg"),
00145 ki18n("Bug fixes and general improvements"),
00146 "kurt.hindenburg@gmail.com");
00147 aboutData.addCredit(ki18n("Waldo Bastian"),
00148 ki18n("Bug fixes and general improvements"),
00149 "bastian@kde.org");
00150 aboutData.addCredit(ki18n("Stephan Binner"),
00151 ki18n("Bug fixes and general improvements"),
00152 "binner@kde.org");
00153 aboutData.addCredit(ki18n("Chris Machemer"),
00154 ki18n("Bug fixes"),
00155 "machey@ceinetworks.com");
00156 aboutData.addCredit(ki18n("Stephan Kulow"),
00157 ki18n("Solaris support and history"),
00158 "coolo@kde.org");
00159 aboutData.addCredit(ki18n("Alexander Neundorf"),
00160 ki18n("Bug fixes and improved startup performance"),
00161 "neundorf@kde.org");
00162 aboutData.addCredit(ki18n("Peter Silva"),
00163 ki18n("Marking improvements"),
00164 "peter.silva@videotron.ca");
00165 aboutData.addCredit(ki18n("Lotzi Boloni"),
00166 ki18n("Embedded Konsole\n"
00167 "Toolbar and session names"),
00168 "boloni@cs.purdue.edu");
00169 aboutData.addCredit(ki18n("David Faure"),
00170 ki18n("Embedded Konsole\n"
00171 "General improvements"),
00172 "faure@kde.org");
00173 aboutData.addCredit(ki18n("Antonio Larrosa"),
00174 ki18n("Visual effects"),
00175 "larrosa@kde.org");
00176 aboutData.addCredit(ki18n("Matthias Ettrich"),
00177 ki18n("Code from the kvt project\n"
00178 "General improvements"),
00179 "ettrich@kde.org");
00180 aboutData.addCredit(ki18n("Warwick Allison"),
00181 ki18n("Schema and text selection improvements"),
00182 "warwick@troll.no");
00183 aboutData.addCredit(ki18n("Dan Pilone"),
00184 ki18n("SGI port"),
00185 "pilone@slac.com");
00186 aboutData.addCredit(ki18n("Kevin Street"),
00187 ki18n("FreeBSD port"),
00188 "street@iname.com");
00189 aboutData.addCredit(ki18n("Sven Fischer"),
00190 ki18n("Bug fixes"),
00191 "herpes@kawo2.renditionwth-aachen.de");
00192 aboutData.addCredit(ki18n("Dale M. Flaven"),
00193 ki18n("Bug fixes"),
00194 "dflaven@netport.com");
00195 aboutData.addCredit(ki18n("Martin Jones"),
00196 ki18n("Bug fixes"),
00197 "mjones@powerup.com.au");
00198 aboutData.addCredit(ki18n("Lars Knoll"),
00199 ki18n("Bug fixes"),
00200 "knoll@mpi-hd.mpg.de");
00201 aboutData.addCredit(ki18n("Thanks to many others.\n"));
00202 aboutData.setProgramIconName("utilities-terminal");
00203 }
00204
00205
00206
00207 #ifdef Q_WS_X11
00208 void getDisplayInformation(Display*& display , Visual*& visual , Colormap& colormap)
00209 {
00210 display = XOpenDisplay(0);
00211 if (!display) {
00212 kWarning("Cannot connect to the X server");
00213 exit(1);
00214 }
00215
00216 int screen = DefaultScreen(display);
00217 int eventBase, errorBase;
00218
00219 if (XRenderQueryExtension(display, &eventBase, &errorBase)) {
00220 int nvi;
00221 XVisualInfo templ;
00222 templ.screen = screen;
00223 templ.depth = 32;
00224 templ.c_class = TrueColor;
00225 XVisualInfo *xvi = XGetVisualInfo(display, VisualScreenMask |
00226 VisualDepthMask |
00227 VisualClassMask, &templ, &nvi);
00228
00229 for (int i = 0; i < nvi; ++i) {
00230 XRenderPictFormat* format = XRenderFindVisualFormat(display,
00231 xvi[i].visual);
00232 if (format->type == PictTypeDirect && format->direct.alphaMask) {
00233 visual = xvi[i].visual;
00234 colormap = XCreateColormap(display, RootWindow(display, screen),
00235 visual, AllocNone);
00236
00237
00238 break;
00239 }
00240 }
00241 }
00242 }
00243 #endif
00244
00245