2 Copyright 2006-2008 by Robert Knight <robertknight@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include "Application.h"
22 #include "MainWindow.h"
31 #include <X11/extensions/Xrender.h>
36 #include <KCmdLineArgs>
38 #include <KWindowSystem>
40 #define KONSOLE_VERSION "2.2"
42 using namespace Konsole
;
45 void getDisplayInformation(Display
*& display
, Visual
*& visual
, Colormap
& colormap
);
48 // fills the KAboutData structure with information about contributors to
50 void fillAboutData(KAboutData
& aboutData
);
51 void fillCommandLineOptions(KCmdLineOptions
& options
);
52 bool useTransparency(); // returns true if transparency should be enabled
53 bool forceNewProcess(); // returns true if new instance should use a new
54 // process (instead of re-using an existing one)
55 void restoreSession(Application
& app
);
58 // Entry point into the Konsole terminal application.
60 extern "C" int KDE_EXPORT
kdemain(int argc
,char** argv
)
62 KAboutData
about( "konsole", 0,
65 ki18n("Terminal emulator"),
66 KAboutData::License_GPL_V2
70 KCmdLineArgs::init(argc
,argv
,&about
);
71 KCmdLineOptions options
;
72 fillCommandLineOptions(options
);
73 KCmdLineArgs::addCmdLineOptions(options
);
74 KUniqueApplication::addCmdLineOptions();
76 KUniqueApplication::StartFlags startFlags
;
77 if (forceNewProcess())
78 startFlags
= KUniqueApplication::NonUniqueInstance
;
80 // create a new application instance if there are no running Konsole instances,
81 // otherwise inform the existing Konsole process and exit
82 if ( !KUniqueApplication::start(startFlags
) )
87 if ( useTransparency() )
91 Colormap colormap
= 0;
93 getDisplayInformation(display
,visual
,colormap
);
95 Application
app(display
,(Qt::HANDLE
)visual
,(Qt::HANDLE
)colormap
);
107 bool forceNewProcess()
109 // when starting Konsole from a terminal, a new process must be used
110 // so that the current environment is propagated into the shells of the new
111 // Konsole and any debug output or warnings from Konsole are written to
112 // the current terminal
113 KCmdLineArgs
* args
= KCmdLineArgs::parsedArgs();
114 return isatty(1) && !args
->isSet("new-tab");
116 bool useTransparency()
118 KCmdLineArgs
* args
= KCmdLineArgs::parsedArgs();
119 bool compositingAvailable
= KWindowSystem::compositingActive() ||
120 args
->isSet("force-transparency");
121 return compositingAvailable
&& args
->isSet("transparency");
123 void fillCommandLineOptions(KCmdLineOptions
& options
)
125 options
.add("profile <file>", ki18n("Name of profile to use for new Konsole instance"));
126 options
.add("list-profiles", ki18n("List the available profiles"));
127 // TODO - Update this when F12 is no longer hard coded
128 options
.add("background-mode", ki18n("Start Konsole in the background"
129 " and bring to the front when the F12"
131 options
.add("new-tab",ki18n("Create a new tab in an existing window rather than creating a new window"));
132 options
.add("workdir <dir>", ki18n("Set the initial working directory of the new tab "
133 "or window to 'dir'"));
134 options
.add("notransparency",ki18n("Disable transparent backgrounds, even if the system supports them."));
135 options
.add("force-transparency",ki18n("Try to enable transparency, even if the system does not appear to support it."));
137 options
.add("noclose",ki18n("Do not close the initial session automatically when it ends."));
138 // TODO - Document this option more clearly
139 options
.add("p <property=value>",ki18n("Change the value of a profile property."));
140 options
.add("!e <cmd>",ki18n("Command to execute"));
141 options
.add("+[args]",ki18n("Arguments passed to command"));
144 void fillAboutData(KAboutData
& aboutData
)
146 aboutData
.addAuthor(ki18n("Robert Knight"),ki18n("Maintainer"), "robertknight@gmail.com");
147 aboutData
.addAuthor(ki18n("Lars Doelle"),ki18n("Author"), "lars.doelle@on-line.de");
148 aboutData
.addCredit(ki18n("Kurt V. Hindenburg"),
149 ki18n("Bug fixes and general improvements"),
150 "kurt.hindenburg@gmail.com");
151 aboutData
.addCredit(ki18n("Waldo Bastian"),
152 ki18n("Bug fixes and general improvements"),
154 aboutData
.addCredit(ki18n("Stephan Binner"),
155 ki18n("Bug fixes and general improvements"),
157 aboutData
.addCredit(ki18n("Chris Machemer"),
159 "machey@ceinetworks.com");
160 aboutData
.addCredit(ki18n("Stephan Kulow"),
161 ki18n("Solaris support and history"),
163 aboutData
.addCredit(ki18n("Alexander Neundorf"),
164 ki18n("Bug fixes and improved startup performance"),
166 aboutData
.addCredit(ki18n("Peter Silva"),
167 ki18n("Marking improvements"),
168 "peter.silva@videotron.ca");
169 aboutData
.addCredit(ki18n("Lotzi Boloni"),
170 ki18n("Embedded Konsole\n"
171 "Toolbar and session names"),
172 "boloni@cs.purdue.edu");
173 aboutData
.addCredit(ki18n("David Faure"),
174 ki18n("Embedded Konsole\n"
175 "General improvements"),
177 aboutData
.addCredit(ki18n("Antonio Larrosa"),
178 ki18n("Visual effects"),
180 aboutData
.addCredit(ki18n("Matthias Ettrich"),
181 ki18n("Code from the kvt project\n"
182 "General improvements"),
184 aboutData
.addCredit(ki18n("Warwick Allison"),
185 ki18n("Schema and text selection improvements"),
187 aboutData
.addCredit(ki18n("Dan Pilone"),
190 aboutData
.addCredit(ki18n("Kevin Street"),
191 ki18n("FreeBSD port"),
193 aboutData
.addCredit(ki18n("Sven Fischer"),
195 "herpes@kawo2.renditionwth-aachen.de");
196 aboutData
.addCredit(ki18n("Dale M. Flaven"),
198 "dflaven@netport.com");
199 aboutData
.addCredit(ki18n("Martin Jones"),
201 "mjones@powerup.com.au");
202 aboutData
.addCredit(ki18n("Lars Knoll"),
204 "knoll@mpi-hd.mpg.de");
205 aboutData
.addCredit(ki18n("Thanks to many others.\n"));
206 aboutData
.setProgramIconName("utilities-terminal");
209 // code taken from the Qt 4 graphics dojo examples
210 // at http://labs.trolltech.com
212 void getDisplayInformation(Display
*& display
, Visual
*& visual
, Colormap
& colormap
)
214 display
= XOpenDisplay(0); // open default display
216 kWarning("Cannot connect to the X server");
220 int screen
= DefaultScreen(display
);
221 int eventBase
, errorBase
;
223 if (XRenderQueryExtension(display
, &eventBase
, &errorBase
)) {
226 templ
.screen
= screen
;
228 templ
.c_class
= TrueColor
;
229 XVisualInfo
*xvi
= XGetVisualInfo(display
, VisualScreenMask
|
231 VisualClassMask
, &templ
, &nvi
);
233 for (int i
= 0; i
< nvi
; ++i
) {
234 XRenderPictFormat
* format
= XRenderFindVisualFormat(display
,
236 if (format
->type
== PictTypeDirect
&& format
->direct
.alphaMask
) {
237 visual
= xvi
[i
].visual
;
238 colormap
= XCreateColormap(display
, RootWindow(display
, screen
),
249 void restoreSession(Application
& app
)
251 if (app
.isSessionRestored())
254 while (KMainWindow::canBeRestored(n
))
255 app
.newMainWindow()->restore(n
++);
262 c-file-style: "stroustrup"
263 indent-tabs-mode: nil