13 #include <tdeconfig.h>
17 #include <tdelocale.h>
18 #include <tdeglobal.h>
21 #include <tdecmdlineargs.h>
22 #include <tdeaboutdata.h>
23 #include <dcopclient.h>
34 #define INT32 _X11INT32
35 #include <X11/Xproto.h>
39 namespace KWinInternal
46 int screen_number = -1;
47 bool disable_twin_composition_manager =
false;
49 static bool initting = FALSE;
52 int x11ErrorHandler(Display *d, XErrorEvent *e)
54 char msg[80], req[80], number[80];
55 bool ignore_badwindow = TRUE;
59 e->request_code == X_ChangeWindowAttributes
60 || e->request_code == X_GrabKey
62 && (e->error_code == BadAccess))
64 fputs(i18n(
"[twin] it looks like there's already a window manager running. twin not started.\n").local8Bit(), stderr);
68 if (ignore_badwindow && (e->error_code == BadWindow || e->error_code == BadColor))
71 XGetErrorText(d, e->error_code, msg,
sizeof(msg));
72 sprintf(number,
"%d", e->request_code);
73 XGetErrorDatabaseText(d,
"XRequest", number,
"<unknown>", req,
sizeof(req));
75 fprintf(stderr,
"[twin] %s(0x%lx): %s\n", req, e->resourceid, msg);
79 fputs(i18n(
"[twin] failure during initialization; aborting").local8Bit(), stderr);
85 Application::Application( )
86 : TDEApplication( ), owner( screen_number )
90 setQuitOnLastWindowClosed(
false);
92 TDECmdLineArgs* args = TDECmdLineArgs::parsedArgs();
93 if (!config()->isImmutable() && args->isSet(
"lock"))
95 config()->setReadOnly(
true);
96 config()->reparseConfiguration();
99 if (screen_number == -1) {
100 screen_number = DefaultScreen(tqt_xdisplay());
103 if (args->isSet(
"disablecompositionmanager" )) {
104 disable_twin_composition_manager =
true;
107 if( !owner.claim( args->isSet(
"replace" ), true ))
109 Display* dpy = tqt_xdisplay();
112 static char net_wm_sm[] =
"WM_Sxx";
114 snprintf (net_wm_sm,
sizeof (net_wm_sm),
"WM_S%d", screen_number);
115 a = XInternAtom (dpy, net_wm_sm, False);
117 w = XGetSelectionOwner (dpy, a);
123 unsigned long n, left;
125 Atom twinRunningAtom = XInternAtom (dpy,
"_KDE_WM_IS_KWIN", True);
127 int result = XGetWindowProperty (dpy, w, twinRunningAtom, 0L, 1L, False,
128 XA_ATOM, &actual, &format,
131 if (result == Success && data != None && format == 32 )
135 XFree ( (
void *) data);
136 if( !owner.claim(
true,
true ))
138 fputs(i18n(
"[twin] unable to claim manager selection, another wm running? (try using --replace)\n").local8Bit(), stderr);
144 fputs(i18n(
"[twin] unable to claim manager selection, another wm running? (try using --replace)\n").local8Bit(), stderr);
150 fputs(i18n(
"[twin] unable to claim manager selection, another wm running? (try using --replace)\n").local8Bit(), stderr);
154 connect( &owner, TQT_SIGNAL( lostOwnership()), TQT_SLOT( lostSelection()));
157 config()->reparseConfiguration();
162 XSetErrorHandler( x11ErrorHandler );
165 XSelectInput(tqt_xdisplay(), tqt_xrootwin(), SubstructureRedirectMask );
168 options =
new Options;
172 Atom kde_wm_system_modal_notification;
173 kde_wm_system_modal_notification = XInternAtom(tqt_xdisplay(),
"_KDE_WM_IS_KWIN", False);
174 XChangeProperty(tqt_xdisplay(), owner.ownerWindow(), kde_wm_system_modal_notification, XA_INTEGER, 32, PropModeReplace, (
unsigned char *)
"TRUE", 1L);
177 (void)
new Workspace( isSessionRestored() );
181 DCOPRef ref(
"kded",
"kded" );
182 ref.send(
"unloadModule", TQCString(
"kdetrayproxy" ));
186 dcopClient()->send(
"ksplash",
"",
"upAndRunning(TQString)", TQString(
"wm started"));
188 e.xclient.type = ClientMessage;
189 e.xclient.message_type = XInternAtom( tqt_xdisplay(),
"_KDE_SPLASH_PROGRESS", False );
190 e.xclient.display = tqt_xdisplay();
191 e.xclient.window = tqt_xrootwin();
192 e.xclient.format = 8;
193 strcpy( e.xclient.data.b,
"wm started" );
194 XSendEvent( tqt_xdisplay(), tqt_xrootwin(), False, SubstructureNotifyMask, &e );
197 Application::~Application()
199 delete Workspace::self();
200 if( owner.ownerWindow() != None )
202 XSetInputFocus( tqt_xdisplay(), PointerRoot, RevertToPointerRoot, GET_QT_X_TIME() );
203 DCOPRef ref(
"kded",
"kded" );
204 if( !ref.send(
"loadModule", TQCString(
"kdetrayproxy" )))
205 kdWarning( 176 ) <<
"Loading of kdetrayproxy failed." << endl;
210 void Application::lostSelection()
212 delete Workspace::self();
214 XSelectInput(tqt_xdisplay(), tqt_xrootwin(), PropertyChangeMask );
215 DCOPRef ref(
"kded",
"kded" );
216 if( !ref.send(
"loadModule", TQCString(
"kdetrayproxy" )))
217 kdWarning( 176 ) <<
"Loading of kdetrayproxy failed." << endl;
221 bool Application::x11EventFilter( XEvent *e )
223 if ( Workspace::self()->workspaceEvent( e ) )
225 return TDEApplication::x11EventFilter( e );
228 static void sighandler(
int)
230 TQApplication::exit();
236 static const char version[] =
"3.0";
237 static const char description[] = I18N_NOOP(
"TDE window manager" );
239 static TDECmdLineOptions args[] =
241 {
"lock", I18N_NOOP(
"Disable configuration options"), 0 },
242 {
"replace", I18N_NOOP(
"Replace already-running ICCCM2.0-compliant window manager"), 0 },
243 {
"disablecompositionmanager", I18N_NOOP(
"Do not start composition manager"), 0 },
248 KDE_EXPORT
int kdemain(
int argc,
char * argv[] )
250 bool restored =
false;
251 for (
int arg = 1; arg < argc; arg++)
253 if (! qstrcmp(argv[arg],
"-session"))
265 TQCString multiHead = getenv(
"TDE_MULTIHEAD");
266 if (multiHead.lower() ==
"true")
269 Display* dpy = XOpenDisplay( NULL );
272 fprintf(stderr,
"%s: FATAL ERROR while trying to open display %s\n",
273 argv[0], XDisplayName(NULL ) );
277 int number_of_screens = ScreenCount( dpy );
278 KWinInternal::screen_number = DefaultScreen( dpy );
280 TQCString display_name = XDisplayString( dpy );
281 XCloseDisplay( dpy );
284 if ((pos = display_name.findRev(
'.')) != -1 )
285 display_name.remove(pos,10);
288 if (number_of_screens != 1)
290 for (
int i = 0; i < number_of_screens; i++ )
294 if ( i != KWinInternal::screen_number && fork() == 0 )
296 KWinInternal::screen_number = i;
304 envir.sprintf(
"DISPLAY=%s.%d", display_name.data(), KWinInternal::screen_number);
306 if (putenv( strdup(envir.data())) )
309 "[twin] %s: WARNING: unable to set DISPLAY environment variable\n",
311 perror(
"[twin] putenv()");
317 TDEGlobal::locale()->setMainCatalogue(
"twin");
319 TDEAboutData aboutData(
"twin", I18N_NOOP(
"TWin"),
320 version, description, TDEAboutData::License_GPL,
321 I18N_NOOP(
"(c) 1999-2005, The KDE Developers"));
322 aboutData.addAuthor(
"Matthias Ettrich",0,
"ettrich@kde.org");
323 aboutData.addAuthor(
"Cristian Tibirna",0,
"tibirna@kde.org");
324 aboutData.addAuthor(
"Daniel M. Duley",0,
"mosfet@kde.org");
325 aboutData.addAuthor(
"Luboš Luňák", I18N_NOOP(
"Maintainer" ),
"l.lunak@kde.org");
327 TDECmdLineArgs::init(argc, argv, &aboutData);
328 TDECmdLineArgs::addCmdLineOptions( args );
330 if (signal(SIGTERM, KWinInternal::sighandler) == SIG_IGN)
331 signal(SIGTERM, SIG_IGN);
332 if (signal(SIGINT, KWinInternal::sighandler) == SIG_IGN)
333 signal(SIGINT, SIG_IGN);
334 if (signal(SIGHUP, KWinInternal::sighandler) == SIG_IGN)
335 signal(SIGHUP, SIG_IGN);
337 TDEApplication::disableAutoDcopRegistration();
338 KWinInternal::Application a;
339 KWinInternal::SessionManaged weAreIndeed;
340 KWinInternal::SessionSaveDoneHelper helper;
342 fcntl(ConnectionNumber(tqt_xdisplay()), F_SETFD, 1);
345 if (KWinInternal::screen_number == 0)
348 appname.sprintf(
"twin-screen-%d", KWinInternal::screen_number);
350 DCOPClient* client = a.dcopClient();
351 client->registerAs( appname.data(),
false);
352 client->setDefaultObject(
"KWinInterface" );