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