12 #include <tdeconfig.h>
16 #include <tdelocale.h>
17 #include <tdeglobal.h>
20 #include <tdecmdlineargs.h>
21 #include <tdeaboutdata.h>
22 #include <dcopclient.h>
33 #define INT32 _X11INT32
34 #include <X11/Xproto.h>
38 namespace KWinInternal
45 int screen_number = -1;
46 bool disable_twin_composition_manager =
false;
48 static bool initting = FALSE;
51 int x11ErrorHandler(Display *d, XErrorEvent *e)
53 char msg[80], req[80], number[80];
54 bool ignore_badwindow = TRUE;
58 e->request_code == X_ChangeWindowAttributes
59 || e->request_code == X_GrabKey
61 && (e->error_code == BadAccess))
63 fputs(i18n(
"[twin] it looks like there's already a window manager running. twin not started.\n").local8Bit(), stderr);
67 if (ignore_badwindow && (e->error_code == BadWindow || e->error_code == BadColor))
70 XGetErrorText(d, e->error_code, msg,
sizeof(msg));
71 sprintf(number,
"%d", e->request_code);
72 XGetErrorDatabaseText(d,
"XRequest", number,
"<unknown>", req,
sizeof(req));
74 fprintf(stderr,
"[twin] %s(0x%lx): %s\n", req, e->resourceid, msg);
78 fputs(i18n(
"[twin] failure during initialization; aborting").local8Bit(), stderr);
84 Application::Application( )
85 : TDEApplication( ), owner( screen_number )
89 setQuitOnLastWindowClosed(
false);
91 TDECmdLineArgs* args = TDECmdLineArgs::parsedArgs();
92 if (!config()->isImmutable() && args->isSet(
"lock"))
94 config()->setReadOnly(
true);
95 config()->reparseConfiguration();
98 if (screen_number == -1) {
99 screen_number = DefaultScreen(tqt_xdisplay());
102 if (args->isSet(
"disablecompositionmanager" )) {
103 disable_twin_composition_manager =
true;
106 if( !owner.claim( args->isSet(
"replace" ),
true ))
108 Display* dpy = tqt_xdisplay();
111 static char net_wm_sm[] =
"WM_Sxx";
113 snprintf (net_wm_sm,
sizeof (net_wm_sm),
"WM_S%d", screen_number);
114 a = XInternAtom (dpy, net_wm_sm, False);
116 w = XGetSelectionOwner (dpy, a);
122 unsigned long n, left;
124 Atom twinRunningAtom = XInternAtom (dpy,
"_KDE_WM_IS_KWIN", True);
126 int result = XGetWindowProperty (dpy, w, twinRunningAtom, 0L, 1L, False,
127 XA_ATOM, &actual, &format,
130 if (result == Success && data != None && format == 32 )
134 XFree ( (
void *) data);
135 if( !owner.claim(
true,
true ))
137 fputs(i18n(
"[twin] unable to claim manager selection, another wm running? (try using --replace)\n").local8Bit(), stderr);
143 fputs(i18n(
"[twin] unable to claim manager selection, another wm running? (try using --replace)\n").local8Bit(), stderr);
149 fputs(i18n(
"[twin] unable to claim manager selection, another wm running? (try using --replace)\n").local8Bit(), stderr);
153 connect( &owner, TQT_SIGNAL( lostOwnership()), TQT_SLOT( lostSelection()));
156 config()->reparseConfiguration();
161 XSetErrorHandler( x11ErrorHandler );
164 XSelectInput(tqt_xdisplay(), tqt_xrootwin(), SubstructureRedirectMask );
167 options =
new Options;
171 Atom kde_wm_system_modal_notification;
172 kde_wm_system_modal_notification = XInternAtom(tqt_xdisplay(),
"_KDE_WM_IS_KWIN", False);
173 XChangeProperty(tqt_xdisplay(), owner.ownerWindow(), kde_wm_system_modal_notification, XA_INTEGER, 32, PropModeReplace, (
unsigned char *)
"TRUE", 1L);
176 (void)
new Workspace( isSessionRestored() );
180 DCOPRef ref(
"kded",
"kded" );
181 ref.send(
"unloadModule", TQCString(
"kdetrayproxy" ));
185 dcopClient()->send(
"ksplash",
"",
"upAndRunning(TQString)", TQString(
"wm started"));
187 e.xclient.type = ClientMessage;
188 e.xclient.message_type = XInternAtom( tqt_xdisplay(),
"_KDE_SPLASH_PROGRESS", False );
189 e.xclient.display = tqt_xdisplay();
190 e.xclient.window = tqt_xrootwin();
191 e.xclient.format = 8;
192 strcpy( e.xclient.data.b,
"wm started" );
193 XSendEvent( tqt_xdisplay(), tqt_xrootwin(), False, SubstructureNotifyMask, &e );
196 Application::~Application()
198 delete Workspace::self();
199 if( owner.ownerWindow() != None )
201 XSetInputFocus( tqt_xdisplay(), PointerRoot, RevertToPointerRoot, GET_QT_X_TIME() );
202 DCOPRef ref(
"kded",
"kded" );
203 if( !ref.send(
"loadModule", TQCString(
"kdetrayproxy" )))
204 kdWarning( 176 ) <<
"Loading of kdetrayproxy failed." << endl;
209 void Application::lostSelection()
211 delete Workspace::self();
213 XSelectInput(tqt_xdisplay(), tqt_xrootwin(), PropertyChangeMask );
214 DCOPRef ref(
"kded",
"kded" );
215 if( !ref.send(
"loadModule", TQCString(
"kdetrayproxy" )))
216 kdWarning( 176 ) <<
"Loading of kdetrayproxy failed." << endl;
220 bool Application::x11EventFilter( XEvent *e )
222 if ( Workspace::self()->workspaceEvent( e ) )
224 return TDEApplication::x11EventFilter( e );
227 static void sighandler(
int)
229 TQApplication::exit();
235 static const char version[] =
"3.0";
236 static const char description[] = I18N_NOOP(
"TDE window manager" );
238 static TDECmdLineOptions args[] =
240 {
"lock", I18N_NOOP(
"Disable configuration options"), 0 },
241 {
"replace", I18N_NOOP(
"Replace already-running ICCCM2.0-compliant window manager"), 0 },
242 {
"disablecompositionmanager", I18N_NOOP(
"Do not start composition manager"), 0 },
247 KDE_EXPORT
int kdemain(
int argc,
char * argv[] )
249 bool restored =
false;
250 for (
int arg = 1; arg < argc; arg++)
252 if (! qstrcmp(argv[arg],
"-session"))
264 TQCString multiHead = getenv(
"TDE_MULTIHEAD");
265 if (multiHead.lower() ==
"true")
268 Display* dpy = XOpenDisplay( NULL );
271 fprintf(stderr,
"%s: FATAL ERROR while trying to open display %s\n",
272 argv[0], XDisplayName(NULL ) );
276 int number_of_screens = ScreenCount( dpy );
277 KWinInternal::screen_number = DefaultScreen( dpy );
279 TQCString display_name = XDisplayString( dpy );
280 XCloseDisplay( dpy );
283 if ((pos = display_name.findRev(
'.')) != -1 )
284 display_name.remove(pos,10);
287 if (number_of_screens != 1)
289 for (
int i = 0; i < number_of_screens; i++ )
293 if ( i != KWinInternal::screen_number && fork() == 0 )
295 KWinInternal::screen_number = i;
303 envir.sprintf(
"DISPLAY=%s.%d", display_name.data(), KWinInternal::screen_number);
305 if (putenv( strdup(envir.data())) )
308 "[twin] %s: WARNING: unable to set DISPLAY environment variable\n",
310 perror(
"[twin] putenv()");
316 TDEGlobal::locale()->setMainCatalogue(
"twin");
318 TDEAboutData aboutData(
"twin", I18N_NOOP(
"TWin"),
319 version, description, TDEAboutData::License_GPL,
320 I18N_NOOP(
"(c) 1999-2005, The KDE Developers"));
321 aboutData.addAuthor(
"Matthias Ettrich",0,
"ettrich@kde.org");
322 aboutData.addAuthor(
"Cristian Tibirna",0,
"tibirna@kde.org");
323 aboutData.addAuthor(
"Daniel M. Duley",0,
"mosfet@kde.org");
324 aboutData.addAuthor(
"Luboš Luňák", I18N_NOOP(
"Maintainer" ),
"l.lunak@kde.org");
326 TDECmdLineArgs::init(argc, argv, &aboutData);
327 TDECmdLineArgs::addCmdLineOptions( args );
329 if (signal(SIGTERM, KWinInternal::sighandler) == SIG_IGN)
330 signal(SIGTERM, SIG_IGN);
331 if (signal(SIGINT, KWinInternal::sighandler) == SIG_IGN)
332 signal(SIGINT, SIG_IGN);
333 if (signal(SIGHUP, KWinInternal::sighandler) == SIG_IGN)
334 signal(SIGHUP, SIG_IGN);
336 TDEApplication::disableAutoDcopRegistration();
337 KWinInternal::Application a;
338 KWinInternal::SessionManaged weAreIndeed;
339 KWinInternal::SessionSaveDoneHelper helper;
341 fcntl(ConnectionNumber(tqt_xdisplay()), F_SETFD, 1);
344 if (KWinInternal::screen_number == 0)
347 appname.sprintf(
"twin-screen-%d", KWinInternal::screen_number);
349 DCOPClient* client = a.dcopClient();
350 client->registerAs( appname.data(),
false);
351 client->setDefaultObject(
"KWinInterface" );