• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Konsole

main.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2006-2008 by Robert Knight <robertknight@gmail.com>
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301  USA.
00018 */
00019 
00020 // Own
00021 #include "Application.h"
00022 #include <KDebug>
00023 
00024 // Unix
00025 #include <unistd.h>
00026 
00027 // X11
00028 #ifdef Q_WS_X11
00029 #include <X11/Xlib.h>
00030 #include <X11/extensions/Xrender.h>
00031 #endif
00032 
00033 // KDE
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 // fills the KAboutData structure with information about contributors to 
00048 // Konsole
00049 void fillAboutData(KAboutData& aboutData);
00050 void fillCommandLineOptions(KCmdLineOptions& options);
00051 bool useTransparency();     // returns true if transparency should be enabled
00052 bool forceNewProcess();     // returns true if new instance should use a new
00053                             // process (instead of re-using an existing one)
00054 
00055 // ***
00056 // Entry point into the Konsole terminal application.  
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     // create a new application instance if there are no running Konsole instances,
00079     // otherwise inform the existing Konsole process and exit
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     // when starting Konsole from a terminal, a new process must be used 
00106     // so that the current environment is propagated into the shells of the new
00107     // Konsole and any debug output or warnings from Konsole are written to
00108     // the current terminal
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     // TODO - Update this when F12 is no longer hard coded
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     // TODO - Document this option more clearly
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 // code taken from the Qt 4 graphics dojo examples
00206 // at http://labs.trolltech.com 
00207 #ifdef Q_WS_X11
00208 void getDisplayInformation(Display*& display , Visual*& visual , Colormap& colormap)
00209 {
00210     display = XOpenDisplay(0); // open default display
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                 // found ARGB visual
00238                 break;
00239             }
00240         }
00241     }
00242 }
00243 #endif
00244 
00245 

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • Konsole
  • Libraries
  •   libkonq
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal