2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
|
|
|
|
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-05-13 17:47:20 +00:00
|
|
|
#include "main.h"
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
//#define QT_CLEAN_NAMESPACE
|
|
|
|
#include <ksharedconfig.h>
|
|
|
|
|
2007-04-30 09:51:12 +00:00
|
|
|
#include <kglobal.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <klocale.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <kcmdlineargs.h>
|
|
|
|
#include <kaboutdata.h>
|
2007-09-27 14:53:52 +00:00
|
|
|
#include <kcrash.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <QX11Info>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fixx11h.h>
|
2008-02-24 11:41:55 +00:00
|
|
|
#include <kxerrorhandler.h>
|
2008-06-16 08:36:35 +00:00
|
|
|
#include <kdefakes.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <QtDBus/QtDBus>
|
2010-06-11 14:26:41 +00:00
|
|
|
#include <stdlib.h>
|
2007-09-27 16:22:29 +00:00
|
|
|
#include <kdialog.h>
|
2007-09-27 17:06:10 +00:00
|
|
|
#include <kstandarddirs.h>
|
2007-10-05 22:21:25 +00:00
|
|
|
#include <kdebug.h>
|
2009-10-30 08:10:35 +00:00
|
|
|
#include <kde_file.h>
|
2007-09-27 16:22:29 +00:00
|
|
|
#include <QLabel>
|
2009-10-30 08:10:35 +00:00
|
|
|
#include <KComboBox>
|
2007-09-27 16:22:29 +00:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
2010-06-11 14:26:41 +00:00
|
|
|
#include <ksmserver_interface.h>
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
#include "atoms.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "sm.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "effects.h"
|
|
|
|
|
|
|
|
#define INT8 _X11INT8
|
|
|
|
#define INT32 _X11INT32
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#undef INT8
|
|
|
|
#undef INT32
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
Options* options;
|
|
|
|
|
|
|
|
Atoms* atoms;
|
|
|
|
|
|
|
|
int screen_number = -1;
|
|
|
|
|
2009-02-09 14:51:11 +00:00
|
|
|
bool initting = false;
|
2008-12-18 15:01:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether to run Xlib in synchronous mode and print backtraces for X errors.
|
|
|
|
* Note that you most probably need to configure cmake with "-D__KDE_HAVE_GCC_VISIBILITY=0"
|
|
|
|
* and -rdynamic in CXXFLAGS for kBacktrace() to work.
|
|
|
|
*/
|
2007-11-02 15:01:40 +00:00
|
|
|
static bool kwin_sync = false;
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2009-09-11 23:44:29 +00:00
|
|
|
// errorMessage is only used ifndef NDEBUG, and only in one place.
|
|
|
|
// it might be worth reevaluating why this is used? I don't know.
|
|
|
|
#ifndef NDEBUG
|
2008-12-18 15:01:25 +00:00
|
|
|
/**
|
|
|
|
* Outputs: "Error: <error> (<value>), Request: <request>(<value>), Resource: <value>"
|
|
|
|
*/
|
|
|
|
// This is copied from KXErrorHandler and modified to explicitly use known extensions
|
2008-02-24 11:41:55 +00:00
|
|
|
static QByteArray errorMessage( const XErrorEvent& event, Display* dpy )
|
2008-12-18 15:01:25 +00:00
|
|
|
{
|
2008-02-24 11:41:55 +00:00
|
|
|
QByteArray ret;
|
2008-12-18 15:01:25 +00:00
|
|
|
char tmp[256];
|
|
|
|
char num[256];
|
|
|
|
if( event.request_code < 128 )
|
|
|
|
{ // Core request
|
2008-02-24 11:41:55 +00:00
|
|
|
XGetErrorText( dpy, event.error_code, tmp, 255 );
|
2008-12-18 15:01:25 +00:00
|
|
|
// The explanation in parentheses just makes
|
|
|
|
// it more verbose and is not really useful
|
|
|
|
if( char* paren = strchr( tmp, '(' ))
|
|
|
|
*paren = '\0';
|
|
|
|
// The various casts are to get overloads non-ambiguous :-/
|
|
|
|
ret = QByteArray( "error: " ) + (const char*)( tmp ) + '[' + QByteArray::number( event.error_code ) + ']';
|
2008-02-24 11:41:55 +00:00
|
|
|
sprintf( num, "%d", event.request_code );
|
|
|
|
XGetErrorDatabaseText( dpy, "XRequest", num, "<unknown>", tmp, 256 );
|
2008-12-18 15:01:25 +00:00
|
|
|
ret += QByteArray( ", request: " ) + (const char*)( tmp ) + '[' + QByteArray::number( event.request_code ) + ']';
|
2008-02-24 11:41:55 +00:00
|
|
|
if( event.resourceid != 0 )
|
2008-12-18 15:01:25 +00:00
|
|
|
ret += QByteArray( ", resource: 0x" ) + QByteArray::number( qlonglong( event.resourceid ), 16 );
|
2008-02-24 11:41:55 +00:00
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
else // Extensions
|
2008-02-24 11:41:55 +00:00
|
|
|
{
|
|
|
|
// XGetErrorText() currently has a bug that makes it fail to find text
|
|
|
|
// for some errors (when error==error_base), also XGetErrorDatabaseText()
|
|
|
|
// requires the right extension name, so it is needed to get info about
|
|
|
|
// all extensions. However that is almost impossible:
|
|
|
|
// - Xlib itself has it, but in internal data.
|
|
|
|
// - Opening another X connection now can cause deadlock with server grabs.
|
|
|
|
// - Fetching it at startup means a bunch of roundtrips.
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
// KWin here explicitly uses known extensions.
|
2008-02-24 11:41:55 +00:00
|
|
|
int nextensions;
|
|
|
|
const char** extensions;
|
|
|
|
int* majors;
|
|
|
|
int* error_bases;
|
|
|
|
Extensions::fillExtensionsData( extensions, nextensions, majors, error_bases );
|
|
|
|
XGetErrorText( dpy, event.error_code, tmp, 255 );
|
|
|
|
int index = -1;
|
|
|
|
int base = 0;
|
2008-12-18 15:01:25 +00:00
|
|
|
for( int i = 0; i < nextensions; ++i )
|
|
|
|
if( error_bases[i] != 0 &&
|
|
|
|
event.error_code >= error_bases[i] && ( index == -1 || error_bases[i] > base ))
|
2008-02-24 11:41:55 +00:00
|
|
|
{
|
|
|
|
index = i;
|
2008-12-18 15:01:25 +00:00
|
|
|
base = error_bases[i];
|
2008-02-24 11:41:55 +00:00
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
if( tmp == QString::number( event.error_code ))
|
|
|
|
{ // XGetErrorText() failed or it has a bug that causes not finding all errors, check ourselves
|
2008-02-24 11:41:55 +00:00
|
|
|
if( index != -1 )
|
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
snprintf( num, 255, "%s.%d", extensions[index], event.error_code - base );
|
2008-02-24 11:41:55 +00:00
|
|
|
XGetErrorDatabaseText( dpy, "XProtoError", num, "<unknown>", tmp, 255 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
strcpy( tmp, "<unknown>" );
|
|
|
|
}
|
|
|
|
if( char* paren = strchr( tmp, '(' ))
|
|
|
|
*paren = '\0';
|
|
|
|
if( index != -1 )
|
2008-12-18 15:01:25 +00:00
|
|
|
ret = QByteArray( "error: " ) + (const char*)( tmp ) + '[' + (const char*)( extensions[index] ) +
|
|
|
|
'+' + QByteArray::number( event.error_code - base ) + ']';
|
2008-02-24 11:41:55 +00:00
|
|
|
else
|
2008-12-18 15:01:25 +00:00
|
|
|
ret = QByteArray( "error: " ) + (const char*)( tmp ) + '[' + QByteArray::number( event.error_code ) + ']';
|
|
|
|
tmp[0] = '\0';
|
|
|
|
for( int i = 0; i < nextensions; ++i )
|
|
|
|
if( majors[i] == event.request_code )
|
2008-02-24 11:41:55 +00:00
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
snprintf( num, 255, "%s.%d", extensions[i], event.minor_code );
|
2008-02-24 11:41:55 +00:00
|
|
|
XGetErrorDatabaseText( dpy, "XRequest", num, "<unknown>", tmp, 255 );
|
2008-12-18 15:01:25 +00:00
|
|
|
ret += QByteArray( ", request: " ) + (const char*)( tmp ) + '[' +
|
|
|
|
(const char*)( extensions[i] ) + '+' + QByteArray::number( event.minor_code ) + ']';
|
2008-02-24 11:41:55 +00:00
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
if( tmp[0] == '\0' ) // Not found?
|
2008-02-24 11:41:55 +00:00
|
|
|
ret += QByteArray( ", request <unknown> [" ) + QByteArray::number( event.request_code ) + ':'
|
|
|
|
+ QByteArray::number( event.minor_code ) + ']';
|
|
|
|
if( event.resourceid != 0 )
|
2008-12-18 15:01:25 +00:00
|
|
|
ret += QByteArray( ", resource: 0x" ) + QByteArray::number( qlonglong( event.resourceid ), 16 );
|
2008-02-24 11:41:55 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2009-09-11 23:44:29 +00:00
|
|
|
#endif
|
2008-02-24 11:41:55 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
static int x11ErrorHandler( Display* d, XErrorEvent* e )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2009-10-05 06:59:10 +00:00
|
|
|
Q_UNUSED( d );
|
2008-12-18 15:01:25 +00:00
|
|
|
bool ignore_badwindow = true; // Might be temporary
|
|
|
|
|
|
|
|
if( initting && ( e->request_code == X_ChangeWindowAttributes || e->request_code == X_GrabKey ) &&
|
|
|
|
e->error_code == BadAccess )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
fputs( i18n( "kwin: it looks like there's already a window manager running. kwin not started.\n" ).toLocal8Bit(), stderr );
|
2007-04-29 17:35:43 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
if( ignore_badwindow && ( e->error_code == BadWindow || e->error_code == BadColor ))
|
2007-04-29 17:35:43 +00:00
|
|
|
return 0;
|
|
|
|
|
2009-04-24 14:45:13 +00:00
|
|
|
#ifndef NDEBUG
|
2008-12-18 15:01:25 +00:00
|
|
|
//fprintf( stderr, "kwin: X Error (%s)\n", KXErrorHandler::errorMessage( *e, d ).data());
|
2009-04-02 15:57:54 +00:00
|
|
|
kWarning( 1212 ) << "kwin: X Error (" << errorMessage( *e, d ) << ")";
|
2009-04-24 14:45:13 +00:00
|
|
|
#endif
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-11-02 15:01:40 +00:00
|
|
|
if( kwin_sync )
|
2009-02-09 14:51:11 +00:00
|
|
|
fprintf( stderr, "%s\n", kBacktrace().toLocal8Bit().data() );
|
2007-11-02 15:01:40 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-27 16:22:29 +00:00
|
|
|
class AlternativeWMDialog : public KDialog
|
|
|
|
{
|
|
|
|
public:
|
2008-12-18 15:01:25 +00:00
|
|
|
AlternativeWMDialog()
|
|
|
|
: KDialog()
|
|
|
|
{
|
2007-09-27 16:45:48 +00:00
|
|
|
setButtons( KDialog::Ok | KDialog::Cancel );
|
2007-09-27 16:22:29 +00:00
|
|
|
|
|
|
|
QWidget* mainWidget = new QWidget( this );
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout( mainWidget );
|
2008-12-18 15:01:25 +00:00
|
|
|
QString text = i18n(
|
|
|
|
"KWin is unstable.\n"
|
|
|
|
"It seems to have crashed several times in a row.\n"
|
|
|
|
"You can select another window manager to run:" );
|
2007-09-27 16:22:29 +00:00
|
|
|
QLabel* textLabel = new QLabel( text, mainWidget );
|
|
|
|
layout->addWidget( textLabel );
|
2009-10-30 08:10:35 +00:00
|
|
|
wmList = new KComboBox( mainWidget );
|
2007-09-27 16:22:29 +00:00
|
|
|
wmList->setEditable( true );
|
|
|
|
layout->addWidget( wmList );
|
|
|
|
|
|
|
|
addWM( "metacity" );
|
|
|
|
addWM( "openbox" );
|
|
|
|
addWM( "fvwm2" );
|
|
|
|
addWM( "kwin" );
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
setMainWidget( mainWidget );
|
2007-09-27 16:22:29 +00:00
|
|
|
|
|
|
|
raise();
|
|
|
|
centerOnScreen( this );
|
2008-12-18 15:01:25 +00:00
|
|
|
}
|
|
|
|
|
2007-09-27 16:22:29 +00:00
|
|
|
void addWM( const QString& wm )
|
2007-09-27 17:06:10 +00:00
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
// TODO: Check if WM is installed
|
|
|
|
if( !KStandardDirs::findExe( wm ).isEmpty() )
|
2007-09-27 17:06:10 +00:00
|
|
|
wmList->addItem( wm );
|
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
QString selectedWM() const
|
|
|
|
{ return wmList->currentText(); }
|
2007-09-27 16:22:29 +00:00
|
|
|
|
|
|
|
private:
|
2009-10-30 08:10:35 +00:00
|
|
|
KComboBox* wmList;
|
2007-09-27 16:22:29 +00:00
|
|
|
};
|
|
|
|
|
2007-09-27 14:53:52 +00:00
|
|
|
int Application::crashes = 0;
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
Application::Application()
|
|
|
|
: KApplication()
|
|
|
|
, owner( screen_number )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2007-11-02 15:01:40 +00:00
|
|
|
if( KCmdLineArgs::parsedArgs( "qt" )->isSet( "sync" ))
|
2008-12-18 15:01:25 +00:00
|
|
|
{
|
|
|
|
kwin_sync = true;
|
|
|
|
XSynchronize( display(), True );
|
|
|
|
kDebug( 1212 ) << "Running KWin in sync mode";
|
|
|
|
}
|
2009-06-05 18:47:01 +00:00
|
|
|
setQuitOnLastWindowClosed( false );
|
2007-04-29 17:35:43 +00:00
|
|
|
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
|
|
|
|
KSharedConfig::Ptr config = KGlobal::config();
|
2008-12-18 15:01:25 +00:00
|
|
|
if( !config->isImmutable() && args->isSet( "lock" ))
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2009-10-05 06:59:10 +00:00
|
|
|
// TODO: This shouldn't be necessary
|
2008-12-18 15:01:25 +00:00
|
|
|
//config->setReadOnly( true );
|
2007-04-29 17:35:43 +00:00
|
|
|
config->reparseConfiguration();
|
|
|
|
}
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
if( screen_number == -1 )
|
|
|
|
screen_number = DefaultScreen( display() );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
if( !owner.claim( args->isSet( "replace" ), true ))
|
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
fputs( i18n( "kwin: unable to claim manager selection, another wm running? (try using --replace)\n" ).toLocal8Bit(), stderr );
|
|
|
|
::exit( 1 );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
connect( &owner, SIGNAL( lostOwnership() ), SLOT( lostSelection() ));
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-09-27 14:53:52 +00:00
|
|
|
KCrash::setEmergencySaveFunction( Application::crashHandler );
|
2008-12-18 15:01:25 +00:00
|
|
|
crashes = args->getOption( "crashes" ).toInt();
|
|
|
|
if( crashes >= 4 )
|
|
|
|
{ // Something has gone seriously wrong
|
2007-09-27 16:22:29 +00:00
|
|
|
AlternativeWMDialog dialog;
|
2007-09-27 16:45:48 +00:00
|
|
|
QString cmd = "kwin";
|
2007-09-27 17:04:56 +00:00
|
|
|
if( dialog.exec() == QDialog::Accepted )
|
2007-09-27 16:45:48 +00:00
|
|
|
cmd = dialog.selectedWM();
|
2007-11-28 19:34:22 +00:00
|
|
|
else
|
2008-12-18 15:01:25 +00:00
|
|
|
::exit( 1 );
|
2007-09-27 16:22:29 +00:00
|
|
|
if( cmd.length() > 500 )
|
2008-12-18 15:01:25 +00:00
|
|
|
{
|
|
|
|
kDebug( 1212 ) << "Command is too long, truncating";
|
|
|
|
cmd = cmd.left( 500 );
|
|
|
|
}
|
|
|
|
kDebug( 1212 ) << "Starting" << cmd << "and exiting";
|
2007-09-27 16:22:29 +00:00
|
|
|
char buf[1024];
|
2008-12-18 15:01:25 +00:00
|
|
|
sprintf( buf, "%s &", cmd.toAscii().data() );
|
|
|
|
system( buf );
|
|
|
|
::exit( 1 );
|
|
|
|
}
|
2007-09-27 14:53:52 +00:00
|
|
|
if( crashes >= 2 )
|
2008-12-18 15:01:25 +00:00
|
|
|
{ // Disable compositing if we have had too many crashes
|
|
|
|
kDebug( 1212 ) << "Too many crashes recently, disabling compositing";
|
2007-09-27 14:53:52 +00:00
|
|
|
KConfigGroup compgroup( config, "Compositing" );
|
|
|
|
compgroup.writeEntry( "Enabled", false );
|
2008-12-18 15:01:25 +00:00
|
|
|
}
|
2007-09-27 14:53:52 +00:00
|
|
|
// Reset crashes count if we stay up for more that 15 seconds
|
|
|
|
QTimer::singleShot( 15*1000, this, SLOT( resetCrashesCount() ));
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
// If KWin was already running it saved its configuration after loosing the selection -> Reread
|
2007-04-29 17:35:43 +00:00
|
|
|
config->reparseConfiguration();
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
initting = true; // Startup...
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
// Install X11 error handler
|
2007-04-29 17:35:43 +00:00
|
|
|
XSetErrorHandler( x11ErrorHandler );
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
// Check whether another windowmanager is running
|
|
|
|
XSelectInput( display(), rootWindow(), SubstructureRedirectMask );
|
|
|
|
syncX(); // Trigger error now
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
atoms = new Atoms;
|
|
|
|
|
2009-02-09 14:39:52 +00:00
|
|
|
// initting = false; // TODO
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-10-03 15:25:38 +00:00
|
|
|
// This tries to detect compositing options and can use GLX. GLX problems
|
2008-12-18 15:01:25 +00:00
|
|
|
// (X errors) shouldn't cause kwin to abort, so this is out of the
|
|
|
|
// critical startup section where x errors cause kwin to abort.
|
2007-10-03 15:25:38 +00:00
|
|
|
options = new Options;
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
// create workspace.
|
|
|
|
(void) new Workspace( isSessionRestored() );
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
syncX(); // Trigger possible errors, there's still a chance to abort
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
initting = false; // Startup done, we are up and running now.
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
XEvent e;
|
|
|
|
e.xclient.type = ClientMessage;
|
|
|
|
e.xclient.message_type = XInternAtom( display(), "_KDE_SPLASH_PROGRESS", False );
|
|
|
|
e.xclient.display = display();
|
|
|
|
e.xclient.window = rootWindow();
|
|
|
|
e.xclient.format = 8;
|
2007-04-30 12:11:32 +00:00
|
|
|
strcpy( e.xclient.data.b, "wm" );
|
2007-04-29 17:35:43 +00:00
|
|
|
XSendEvent( display(), rootWindow(), False, SubstructureNotifyMask, &e );
|
|
|
|
}
|
|
|
|
|
|
|
|
Application::~Application()
|
|
|
|
{
|
|
|
|
delete Workspace::self();
|
2008-12-18 15:01:25 +00:00
|
|
|
if( owner.ownerWindow() != None ) // If there was no --replace (no new WM)
|
2007-04-29 17:35:43 +00:00
|
|
|
XSetInputFocus( display(), PointerRoot, RevertToPointerRoot, xTime() );
|
|
|
|
delete options;
|
|
|
|
delete effects;
|
|
|
|
delete atoms;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::lostSelection()
|
|
|
|
{
|
2007-05-09 16:10:49 +00:00
|
|
|
sendPostedEvents();
|
2007-04-29 17:35:43 +00:00
|
|
|
delete Workspace::self();
|
2008-12-18 15:01:25 +00:00
|
|
|
// Remove windowmanager privileges
|
|
|
|
XSelectInput( display(), rootWindow(), PropertyChangeMask );
|
2007-04-29 17:35:43 +00:00
|
|
|
quit();
|
|
|
|
}
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
bool Application::x11EventFilter( XEvent* e )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
if( Workspace::self() && Workspace::self()->workspaceEvent( e ))
|
|
|
|
return true;
|
2007-04-29 17:35:43 +00:00
|
|
|
return KApplication::x11EventFilter( e );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Application::notify( QObject* o, QEvent* e )
|
|
|
|
{
|
|
|
|
if( Workspace::self()->workspaceEvent( e ))
|
|
|
|
return true;
|
|
|
|
return KApplication::notify( o, e );
|
|
|
|
}
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
static void sighandler( int )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
QApplication::exit();
|
|
|
|
}
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
void Application::crashHandler( int signal )
|
2007-09-27 14:53:52 +00:00
|
|
|
{
|
|
|
|
crashes++;
|
|
|
|
|
|
|
|
fprintf( stderr, "Application::crashHandler() called with signal %d; recent crashes: %d\n", signal, crashes );
|
|
|
|
char cmd[1024];
|
2009-06-11 18:53:41 +00:00
|
|
|
sprintf( cmd, "%s --crashes %d &",
|
|
|
|
QFile::encodeName(QCoreApplication::applicationFilePath()).constData(), crashes );
|
2007-09-27 14:53:52 +00:00
|
|
|
|
|
|
|
sleep( 1 );
|
|
|
|
system( cmd );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::resetCrashesCount()
|
|
|
|
{
|
|
|
|
crashes = 0;
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|
|
|
|
|
2008-07-28 13:46:16 +00:00
|
|
|
static const char version[] = KDE_VERSION_STRING;
|
2007-04-29 17:35:43 +00:00
|
|
|
static const char description[] = I18N_NOOP( "KDE window manager" );
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
KDE_EXPORT int kdemain( int argc, char * argv[] )
|
|
|
|
{
|
|
|
|
bool restored = false;
|
2008-12-18 15:01:25 +00:00
|
|
|
for( int arg = 1; arg < argc; arg++ )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
if( !qstrcmp( argv[arg], "-session" ))
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
restored = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-13 20:31:03 +00:00
|
|
|
// KWin only works properly with Qt's native X11 backend; override any compile-time
|
|
|
|
// or command line settings to raster or OpenGL.
|
|
|
|
QApplication::setGraphicsSystem("native");
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
if( !restored )
|
|
|
|
{ // We only do the multihead fork if we are not restored by the session
|
|
|
|
// manager, since the session manager will register multiple kwins,
|
|
|
|
// one for each screen...
|
2009-10-30 08:10:35 +00:00
|
|
|
QByteArray multiHead = qgetenv( "KDE_MULTIHEAD" );
|
2008-12-18 15:01:25 +00:00
|
|
|
if( multiHead.toLower() == "true" )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
Display* dpy = XOpenDisplay( NULL );
|
2008-12-18 15:01:25 +00:00
|
|
|
if( !dpy )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
fprintf( stderr, "%s: FATAL ERROR while trying to open display %s\n",
|
|
|
|
argv[0], XDisplayName( NULL ));
|
|
|
|
exit( 1 );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int number_of_screens = ScreenCount( dpy );
|
|
|
|
KWin::screen_number = DefaultScreen( dpy );
|
2008-12-18 15:01:25 +00:00
|
|
|
int pos; // Temporarily needed to reconstruct DISPLAY var if multi-head
|
2007-04-29 17:35:43 +00:00
|
|
|
QByteArray display_name = XDisplayString( dpy );
|
|
|
|
XCloseDisplay( dpy );
|
|
|
|
dpy = 0;
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
if(( pos = display_name.lastIndexOf( '.' )) != -1 )
|
|
|
|
display_name.remove( pos, 10 ); // 10 is enough to be sure we removed ".s"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QString envir;
|
2008-12-18 15:01:25 +00:00
|
|
|
if( number_of_screens != 1 )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
for( int i = 0; i < number_of_screens; i++ )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
// If execution doesn't pass by here, then kwin
|
|
|
|
// acts exactly as previously
|
|
|
|
if( i != KWin::screen_number && fork() == 0 )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
KWin::screen_number = i;
|
2008-12-18 15:01:25 +00:00
|
|
|
// Break here because we are the child process, we don't
|
|
|
|
// want to fork() anymore
|
2007-04-29 17:35:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
// In the next statement, display_name shouldn't contain a screen
|
|
|
|
// number. If it had it, it was removed at the "pos" check
|
|
|
|
envir.sprintf( "DISPLAY=%s.%d", display_name.data(), KWin::screen_number );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
if( putenv( strdup( envir.toAscii() )))
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-12-18 15:01:25 +00:00
|
|
|
fprintf( stderr, "%s: WARNING: unable to set DISPLAY environment variable\n", argv[0] );
|
2007-04-29 17:35:43 +00:00
|
|
|
perror("putenv()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
KAboutData aboutData(
|
|
|
|
"kwin", // The program name used internally
|
|
|
|
0, // The message catalog name. If null, program name is used instead
|
|
|
|
ki18n( "KWin" ), // A displayable program name string
|
|
|
|
version, // The program version string
|
|
|
|
ki18n( description ), // Short description of what the app does
|
|
|
|
KAboutData::License_GPL, // The license this code is released under
|
|
|
|
ki18n( "(c) 1999-2008, The KDE Developers" )); // Copyright Statement
|
|
|
|
aboutData.addAuthor( ki18n( "Matthias Ettrich" ),KLocalizedString(), "ettrich@kde.org" );
|
|
|
|
aboutData.addAuthor( ki18n( "Cristian Tibirna" ),KLocalizedString(), "tibirna@kde.org" );
|
|
|
|
aboutData.addAuthor( ki18n( "Daniel M. Duley" ),KLocalizedString(), "mosfet@kde.org" );
|
|
|
|
aboutData.addAuthor( ki18n( "Luboš Luňák" ), ki18n( "Maintainer" ), "l.lunak@kde.org" );
|
|
|
|
|
2009-04-13 20:31:03 +00:00
|
|
|
KCmdLineArgs::init( argc, argv, &aboutData );
|
2007-07-02 08:49:20 +00:00
|
|
|
|
|
|
|
KCmdLineOptions args;
|
2008-12-18 15:01:25 +00:00
|
|
|
args.add( "lock", ki18n( "Disable configuration options" ));
|
|
|
|
args.add( "replace", ki18n( "Replace already-running ICCCM2.0-compliant window manager" ));
|
|
|
|
args.add( "crashes <n>", ki18n( "Indicate that KWin has recently crashed n times" ));
|
2007-04-29 17:35:43 +00:00
|
|
|
KCmdLineArgs::addCmdLineOptions( args );
|
2010-05-31 21:24:40 +00:00
|
|
|
|
2009-10-30 08:10:35 +00:00
|
|
|
if( KDE_signal( SIGTERM, KWin::sighandler ) == SIG_IGN )
|
|
|
|
KDE_signal( SIGTERM, SIG_IGN );
|
|
|
|
if( KDE_signal( SIGINT, KWin::sighandler ) == SIG_IGN )
|
|
|
|
KDE_signal( SIGINT, SIG_IGN );
|
|
|
|
if( KDE_signal( SIGHUP, KWin::sighandler ) == SIG_IGN )
|
|
|
|
KDE_signal( SIGHUP, SIG_IGN );
|
2008-12-18 15:01:25 +00:00
|
|
|
|
|
|
|
// HACK: this is needed to work around a Qt4.4.0RC1 bug (#157659)
|
2008-04-04 18:08:43 +00:00
|
|
|
setenv( "QT_SLOW_TOPLEVEL_RESIZE", "1", true );
|
2008-12-18 15:01:25 +00:00
|
|
|
|
2010-06-13 20:22:50 +00:00
|
|
|
// Disable the glib event loop integration, since it seems to be responsible
|
|
|
|
// for several bug reports about high CPU usage (bug #239963)
|
|
|
|
setenv( "QT_NO_GLIB", "1", true );
|
|
|
|
|
2010-06-11 14:26:41 +00:00
|
|
|
org::kde::KSMServerInterface ksmserver( "org.kde.ksmserver", "/KSMServer", QDBusConnection::sessionBus());
|
|
|
|
ksmserver.suspendStartup( "kwin" );
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin::Application a;
|
2010-06-11 14:26:41 +00:00
|
|
|
ksmserver.resumeStartup( "kwin" );
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin::SessionManager weAreIndeed;
|
|
|
|
KWin::SessionSaveDoneHelper helper;
|
2007-11-13 17:29:46 +00:00
|
|
|
KGlobal::locale()->insertCatalog( "kwin_effects" );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-02-10 02:53:33 +00:00
|
|
|
// Announce when KWIN_DIRECT_GL is set for above HACK
|
|
|
|
if( qstrcmp( qgetenv( "KWIN_DIRECT_GL" ), "1" ) == 0 )
|
|
|
|
kDebug( 1212 ) << "KWIN_DIRECT_GL set, not forcing LIBGL_ALWAYS_INDIRECT=1";
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
fcntl( XConnectionNumber( KWin::display() ), F_SETFD, 1 );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QString appname;
|
2008-12-18 15:01:25 +00:00
|
|
|
if( KWin::screen_number == 0 )
|
2007-04-29 18:16:15 +00:00
|
|
|
appname = "org.kde.kwin";
|
2007-04-29 17:35:43 +00:00
|
|
|
else
|
2008-12-18 15:01:25 +00:00
|
|
|
appname.sprintf( "org.kde.kwin-screen-%d", KWin::screen_number );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
QDBusConnection::sessionBus().interface()->registerService(
|
|
|
|
appname, QDBusConnectionInterface::DontQueueService );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
return a.exec();
|
2010-05-31 21:24:40 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "main.moc"
|