From 3bcc1ce0c9fc46449ff6e4bdbca7f9c582192e64 Mon Sep 17 00:00:00 2001 From: tpearson Date: Thu, 15 Sep 2011 20:20:48 +0000 Subject: Allow kwin to replace itself automatically git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1253854 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kwin/main.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/kwin/main.cpp b/kwin/main.cpp index 8a15c219c..efd788ad6 100644 --- a/kwin/main.cpp +++ b/kwin/main.cpp @@ -100,8 +100,50 @@ Application::Application( ) if( !owner.claim( args->isSet( "replace" ), true )) { - fputs(i18n("kwin: unable to claim manager selection, another wm running? (try using --replace)\n").local8Bit(), stderr); - ::exit(1); + Display* dpy = qt_xdisplay(); + Window w; + Atom a; + static char net_wm_sm[] = "WM_Sxx"; + + snprintf (net_wm_sm, sizeof (net_wm_sm), "WM_S%d", screen_number); + a = XInternAtom (dpy, net_wm_sm, False); + + w = XGetSelectionOwner (dpy, a); + + if (w != None) + { + Atom actual; + int format; + unsigned long n, left; + unsigned char *data; + Atom kwinRunningAtom = XInternAtom (dpy, "_KDE_WM_IS_KWIN", True); + + int result = XGetWindowProperty (dpy, w, kwinRunningAtom, 0L, 1L, False, + XA_ATOM, &actual, &format, + &n, &left, &data); + + if (result == Success && data != None && format == 32 ) + { + Atom a; + a = *(long*)data; + XFree ( (void *) data); + if( !owner.claim( true, true )) + { + fputs(i18n("kwin: unable to claim manager selection, another wm running? (try using --replace)\n").local8Bit(), stderr); + ::exit(1); + } + } + else + { + fputs(i18n("kwin: unable to claim manager selection, another wm running? (try using --replace)\n").local8Bit(), stderr); + ::exit(1); + } + } + else + { + fputs(i18n("kwin: unable to claim manager selection, another wm running? (try using --replace)\n").local8Bit(), stderr); + ::exit(1); + } } connect( &owner, TQT_SIGNAL( lostOwnership()), TQT_SLOT( lostSelection())); @@ -120,6 +162,11 @@ Application::Application( ) options = new Options; atoms = new Atoms; + // Signal that we are The KWin! + Atom kde_wm_system_modal_notification; + kde_wm_system_modal_notification = XInternAtom(qt_xdisplay(), "_KDE_WM_IS_KWIN", False); + XChangeProperty(qt_xdisplay(), owner.ownerWindow(), kde_wm_system_modal_notification, XA_INTEGER, 32, PropModeReplace, (unsigned char *) "TRUE", 1L); + // create workspace. (void) new Workspace( isSessionRestored() ); -- cgit v1.2.1