2000-03-24 22:23:02 +00:00
|
|
|
/*****************************************************************
|
|
|
|
kwin - the KDE window manager
|
|
|
|
|
|
|
|
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
|
|
|
|
******************************************************************/
|
2000-04-20 17:37:33 +00:00
|
|
|
|
|
|
|
// X11/Qt conflict
|
|
|
|
#undef Bool
|
|
|
|
|
2000-06-08 17:05:51 +00:00
|
|
|
#define QT_CLEAN_NAMESPACE
|
2000-03-24 22:23:02 +00:00
|
|
|
#include <kconfig.h>
|
1999-08-19 23:26:42 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "atoms.h"
|
|
|
|
#include "workspace.h"
|
2000-02-12 00:25:21 +00:00
|
|
|
#include <dcopclient.h>
|
2000-03-24 22:23:02 +00:00
|
|
|
#include <qsessionmanager.h>
|
1999-08-19 23:26:42 +00:00
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xos.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <stdio.h>
|
1999-12-22 17:16:23 +00:00
|
|
|
#include <stdlib.h>
|
1999-08-19 23:26:42 +00:00
|
|
|
#include <signal.h>
|
2000-06-08 17:05:51 +00:00
|
|
|
// #define INT8 _X11INT8
|
|
|
|
// #define INT32 _X11INT32
|
1999-08-19 23:26:42 +00:00
|
|
|
#include <X11/Xproto.h>
|
2000-06-08 17:05:51 +00:00
|
|
|
// #undef INT8
|
|
|
|
// #undef INT32
|
1999-08-19 23:26:42 +00:00
|
|
|
|
2000-01-12 15:08:42 +00:00
|
|
|
#include <kcmdlineargs.h>
|
|
|
|
#include <kaboutdata.h>
|
|
|
|
#include <klocale.h>
|
2000-06-01 23:44:03 +00:00
|
|
|
#include <kcrash.h>
|
2000-01-12 15:08:42 +00:00
|
|
|
|
1999-08-19 23:26:42 +00:00
|
|
|
Options* options;
|
|
|
|
Atoms* atoms;
|
|
|
|
|
1999-11-28 21:41:15 +00:00
|
|
|
Time kwin_time = CurrentTime;
|
|
|
|
|
1999-08-19 23:26:42 +00:00
|
|
|
static bool initting = FALSE;
|
2000-06-01 23:44:03 +00:00
|
|
|
static DCOPClient * client = 0;
|
|
|
|
|
|
|
|
static void crashHandler(int)
|
|
|
|
{
|
|
|
|
KCrash::setCrashHandler(0); // Exit on next crash.
|
|
|
|
delete client; client = 0; // Unregister with dcop.
|
2000-07-13 17:59:12 +00:00
|
|
|
// system("kwin&"); // Try to restart
|
2000-06-01 23:44:03 +00:00
|
|
|
}
|
|
|
|
|
1999-08-19 23:26:42 +00:00
|
|
|
int x11ErrorHandler(Display *d, XErrorEvent *e){
|
|
|
|
char msg[80], req[80], number[80];
|
1999-11-29 18:31:28 +00:00
|
|
|
bool ignore_badwindow = TRUE; //maybe temporary
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
if (initting &&
|
|
|
|
(
|
|
|
|
e->request_code == X_ChangeWindowAttributes
|
|
|
|
|| e->request_code == X_GrabKey
|
|
|
|
)
|
|
|
|
&& (e->error_code == BadAccess)) {
|
2000-07-06 16:48:13 +00:00
|
|
|
fprintf(stderr, i18n("kwin: it looks like there's already a window manager running. kwin not started").local8Bit());
|
1999-08-19 23:26:42 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ignore_badwindow && (e->error_code == BadWindow || e->error_code == BadColor))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
XGetErrorText(d, e->error_code, msg, sizeof(msg));
|
|
|
|
sprintf(number, "%d", e->request_code);
|
|
|
|
XGetErrorDatabaseText(d, "XRequest", number, "<unknown>", req, sizeof(req));
|
|
|
|
|
|
|
|
fprintf(stderr, "kwin: %s(0x%lx): %s\n", req, e->resourceid, msg);
|
|
|
|
|
|
|
|
if (initting) {
|
2000-07-06 16:48:13 +00:00
|
|
|
fprintf(stderr, i18n("kwin: failure during initialisation; aborting").local8Bit());
|
1999-08-19 23:26:42 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-06-23 16:26:44 +00:00
|
|
|
/*!
|
|
|
|
Updates kwin_time by receiving a current timestamp from the server.
|
|
|
|
|
|
|
|
Use this function only when really necessary. Keep in mind that it's
|
|
|
|
a roundtrip to the X-Server.
|
|
|
|
*/
|
|
|
|
void kwin_updateTime()
|
|
|
|
{
|
|
|
|
static QWidget* w = 0;
|
|
|
|
if ( !w )
|
|
|
|
w = new QWidget;
|
|
|
|
long data = 1;
|
|
|
|
XChangeProperty(qt_xdisplay(), w->winId(), atoms->kwin_running, atoms->kwin_running, 32,
|
|
|
|
PropModeAppend, (unsigned char*) &data, 1);
|
|
|
|
XEvent ev;
|
|
|
|
XWindowEvent( qt_xdisplay(), w->winId(), PropertyChangeMask, &ev );
|
|
|
|
kwin_time = ev.xproperty.time;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-12 15:08:42 +00:00
|
|
|
Application::Application( )
|
|
|
|
: KApplication( )
|
1999-08-19 23:26:42 +00:00
|
|
|
{
|
2000-03-22 12:36:07 +00:00
|
|
|
initting = TRUE; // startup....
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
// install X11 error handler
|
|
|
|
XSetErrorHandler( x11ErrorHandler );
|
|
|
|
|
2000-03-22 12:36:07 +00:00
|
|
|
// check whether another windowmanager is running
|
|
|
|
XSelectInput(qt_xdisplay(), qt_xrootwin(), SubstructureRedirectMask );
|
|
|
|
syncX(); // trigger error now
|
2000-01-12 15:08:42 +00:00
|
|
|
|
2000-03-22 12:36:07 +00:00
|
|
|
options = new Options;
|
|
|
|
atoms = new Atoms;
|
1999-08-19 23:26:42 +00:00
|
|
|
|
2000-03-22 12:36:07 +00:00
|
|
|
// create a workspace.
|
2000-03-24 22:23:02 +00:00
|
|
|
workspaces += new Workspace( isSessionRestored() );
|
|
|
|
|
2000-03-22 12:36:07 +00:00
|
|
|
syncX(); // trigger possible errors, there's still a chance to abort
|
2000-03-24 22:23:02 +00:00
|
|
|
|
2000-03-22 12:36:07 +00:00
|
|
|
initting = FALSE; // startup done, we are up and running now.
|
1999-08-19 23:26:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Application::~Application()
|
|
|
|
{
|
|
|
|
for ( WorkspaceList::Iterator it = workspaces.begin(); it != workspaces.end(); ++it) {
|
|
|
|
delete (*it);
|
|
|
|
}
|
1999-11-25 12:53:17 +00:00
|
|
|
delete options;
|
1999-08-19 23:26:42 +00:00
|
|
|
}
|
|
|
|
|
2000-02-12 00:25:21 +00:00
|
|
|
|
1999-08-19 23:26:42 +00:00
|
|
|
bool Application::x11EventFilter( XEvent *e )
|
|
|
|
{
|
1999-11-28 21:41:15 +00:00
|
|
|
switch ( e->type ) {
|
|
|
|
case ButtonPress:
|
|
|
|
case ButtonRelease:
|
|
|
|
case MotionNotify:
|
|
|
|
kwin_time = (e->type == MotionNotify) ?
|
|
|
|
e->xmotion.time : e->xbutton.time;
|
|
|
|
break;
|
|
|
|
case KeyPress:
|
1999-11-29 14:19:32 +00:00
|
|
|
case KeyRelease:
|
1999-11-28 21:41:15 +00:00
|
|
|
kwin_time = e->xkey.time;
|
|
|
|
break;
|
|
|
|
case PropertyNotify:
|
|
|
|
kwin_time = e->xproperty.time;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1999-11-29 14:19:32 +00:00
|
|
|
|
1999-08-19 23:26:42 +00:00
|
|
|
for ( WorkspaceList::Iterator it = workspaces.begin(); it != workspaces.end(); ++it) {
|
|
|
|
if ( (*it)->workspaceEvent( e ) )
|
|
|
|
return TRUE;
|
|
|
|
}
|
1999-11-13 01:51:22 +00:00
|
|
|
return KApplication::x11EventFilter( e );
|
1999-08-19 23:26:42 +00:00
|
|
|
}
|
|
|
|
|
2000-03-24 22:23:02 +00:00
|
|
|
void Application::commitData( QSessionManager& /*sm*/ )
|
|
|
|
{
|
|
|
|
// nothing to do, really
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::saveState( QSessionManager& sm )
|
|
|
|
{
|
|
|
|
KApplication::saveState( sm );
|
2000-07-16 19:09:09 +00:00
|
|
|
static bool firstTime = true;
|
2000-03-24 22:23:02 +00:00
|
|
|
if ( firstTime ) {
|
|
|
|
firstTime = false;
|
|
|
|
return; // no need to save this state.
|
|
|
|
}
|
|
|
|
|
|
|
|
sm.release();
|
2000-05-09 10:13:48 +00:00
|
|
|
|
2000-03-25 13:46:01 +00:00
|
|
|
if ( !sm.isPhase2() ) {
|
2000-07-16 19:09:09 +00:00
|
|
|
sm.requestPhase2();
|
|
|
|
return;
|
2000-03-25 13:46:01 +00:00
|
|
|
}
|
2000-07-16 19:09:09 +00:00
|
|
|
|
2000-03-24 22:23:02 +00:00
|
|
|
workspaces.first()->storeSession( kapp->sessionConfig() );
|
|
|
|
kapp->sessionConfig()->sync();
|
|
|
|
}
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void sighandler(int) {
|
|
|
|
QApplication::exit();
|
|
|
|
}
|
|
|
|
|
2000-03-21 20:02:27 +00:00
|
|
|
static const char *version = "0.4";
|
|
|
|
static const char *description = I18N_NOOP( "The KDE window manager." );
|
|
|
|
|
2000-03-06 19:14:20 +00:00
|
|
|
int main( int argc, char * argv[] )
|
2000-01-12 15:08:42 +00:00
|
|
|
{
|
2000-03-21 20:02:27 +00:00
|
|
|
KAboutData aboutData( "kwin", I18N_NOOP("KWin"),
|
|
|
|
version, description, KAboutData::License_BSD,
|
|
|
|
"(c) 1999-2000, The KDE Developers");
|
|
|
|
aboutData.addAuthor("Matthias Ettrich",0, "ettrich@kde.org");
|
|
|
|
aboutData.addAuthor("Daniel M. Duley",0, "mosfet@kde.org");
|
2000-01-12 15:08:42 +00:00
|
|
|
|
|
|
|
KCmdLineArgs::init(argc, argv, &aboutData);
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
if (signal(SIGTERM, sighandler) == SIG_IGN)
|
|
|
|
signal(SIGTERM, SIG_IGN);
|
|
|
|
if (signal(SIGINT, sighandler) == SIG_IGN)
|
|
|
|
signal(SIGINT, SIG_IGN);
|
|
|
|
if (signal(SIGHUP, sighandler) == SIG_IGN)
|
|
|
|
signal(SIGHUP, SIG_IGN);
|
|
|
|
|
2000-01-12 15:08:42 +00:00
|
|
|
Application a;
|
2000-07-13 17:59:12 +00:00
|
|
|
// KCrash::setCrashHandler(crashHandler); // Try to restart on crash
|
1999-08-19 23:26:42 +00:00
|
|
|
fcntl(ConnectionNumber(qt_xdisplay()), F_SETFD, 1);
|
|
|
|
|
2000-06-01 23:44:03 +00:00
|
|
|
client = a.dcopClient();
|
2000-04-08 19:35:52 +00:00
|
|
|
client->attach();
|
2000-05-06 18:59:43 +00:00
|
|
|
client->registerAs("kwin", false);
|
2000-06-02 21:57:48 +00:00
|
|
|
client->setDefaultObject( "KWinInterface" );
|
2000-02-12 00:25:21 +00:00
|
|
|
|
2000-02-12 00:36:49 +00:00
|
|
|
return a.exec();
|
2000-02-12 00:25:21 +00:00
|
|
|
|
1999-08-19 23:26:42 +00:00
|
|
|
}
|