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>
|
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>
|
|
|
|
#define INT8 _X11INT8
|
|
|
|
#define INT32 _X11INT32
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#undef INT8
|
|
|
|
#undef INT32
|
|
|
|
|
2000-01-12 15:08:42 +00:00
|
|
|
#include <kcmdlineargs.h>
|
|
|
|
#include <kaboutdata.h>
|
|
|
|
#include <klocale.h>
|
|
|
|
|
|
|
|
static const char *version = "0.9";
|
|
|
|
|
|
|
|
static const char *description = I18N_NOOP( "KDE Window Manager." );
|
|
|
|
|
|
|
|
static KCmdLineOptions cmdOptions[] =
|
|
|
|
{
|
|
|
|
{ "+[workspace]", I18N_NOOP("A cryptic command line option"), 0 },
|
|
|
|
{ 0, 0, 0 }
|
|
|
|
};
|
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;
|
|
|
|
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)) {
|
|
|
|
fprintf(stderr, i18n("kwin: it looks like there's already a window manager running. kwin not started\n"));
|
|
|
|
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) {
|
|
|
|
fprintf(stderr, i18n("kwin: failure during initialisation; aborting\n"));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-01-12 15:08:42 +00:00
|
|
|
Application::Application( )
|
|
|
|
: KApplication( )
|
1999-08-19 23:26:42 +00:00
|
|
|
{
|
|
|
|
initting = TRUE;
|
|
|
|
options = new Options;
|
|
|
|
atoms = new Atoms;
|
|
|
|
|
|
|
|
// install X11 error handler
|
|
|
|
XSetErrorHandler( x11ErrorHandler );
|
|
|
|
|
1999-11-01 23:41:44 +00:00
|
|
|
// create a workspace.
|
1999-08-19 23:26:42 +00:00
|
|
|
workspaces += new Workspace();
|
|
|
|
initting = FALSE;
|
2000-01-12 15:08:42 +00:00
|
|
|
|
|
|
|
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
|
|
|
|
if ( args->count() ) {
|
|
|
|
QString s = args->arg(0);
|
1999-08-19 23:26:42 +00:00
|
|
|
int i = s.toInt();
|
|
|
|
workspaces += new Workspace( (WId ) i );
|
|
|
|
}
|
2000-01-12 15:08:42 +00:00
|
|
|
args->clear();
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
syncX();
|
|
|
|
initting = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
void kwiniface::logout()
|
|
|
|
{
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
2000-02-12 00:36:49 +00:00
|
|
|
bool kwiniface::process(const QCString &fun, const QByteArray &, QCString& replyType, QByteArray &)
|
2000-02-12 00:25:21 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr,"Logout Call Recieved\n");
|
|
|
|
if ( fun == "logout()" )
|
|
|
|
{
|
|
|
|
replyType = "void";
|
|
|
|
logout();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-02-12 00:36:49 +00:00
|
|
|
return FALSE;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void sighandler(int) {
|
|
|
|
QApplication::exit();
|
|
|
|
}
|
|
|
|
|
2000-01-12 15:08:42 +00:00
|
|
|
int main( int argc, char * argv[] )
|
|
|
|
{
|
|
|
|
KAboutData aboutData( "kwin", I18N_NOOP("KWin"), version, description);
|
|
|
|
|
|
|
|
KCmdLineArgs::init(argc, argv, &aboutData);
|
|
|
|
KCmdLineArgs::addCmdLineOptions( cmdOptions );
|
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;
|
1999-08-19 23:26:42 +00:00
|
|
|
fcntl(ConnectionNumber(qt_xdisplay()), F_SETFD, 1);
|
|
|
|
|
2000-02-12 00:25:21 +00:00
|
|
|
DCOPClient *client = kapp->dcopClient();
|
|
|
|
client->attach();
|
2000-02-12 00:55:36 +00:00
|
|
|
client->registerAs(kapp->name(),FALSE);
|
2000-02-12 00:25:21 +00:00
|
|
|
|
2000-02-12 00:36:49 +00:00
|
|
|
kwiniface iface;
|
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
|
|
|
}
|