diff options
Diffstat (limited to 'twin/workspace.cpp')
| -rw-r--r-- | twin/workspace.cpp | 427 |
1 files changed, 202 insertions, 225 deletions
diff --git a/twin/workspace.cpp b/twin/workspace.cpp index 23661e6a0..af7b671d7 100644 --- a/twin/workspace.cpp +++ b/twin/workspace.cpp @@ -22,9 +22,11 @@ License. See the file "COPYING" for the exact licensing terms. #include <tqpainter.h> #include <tqbitmap.h> #include <tqclipboard.h> +#include <tqfile.h> #include <tdemenubar.h> -#include <kprocess.h> -#include <kglobalaccel.h> +#include <tdeprocess.h> +#include <tdeglobalaccel.h> +#include <tdestandarddirs.h> #include <dcopclient.h> #include <kipc.h> @@ -52,15 +54,10 @@ namespace KWinInternal { extern int screen_number; +extern bool disable_twin_composition_manager; Workspace *Workspace::_self = 0; -TDEProcess* kompmgr = 0; -TDESelectionOwner* kompmgr_selection; - -bool allowKompmgrRestart = TRUE; -extern bool disable_twin_composition_manager; - bool supportsCompMgr() { if (disable_twin_composition_manager) { @@ -76,47 +73,39 @@ bool supportsCompMgr() return damageExt && compositeExt && xfixesExt; } -pid_t getCompositorPID() { +TQString compositorPIDFile () { + return locateLocal("tmp", TQString("compton-tde.").append(getenv("DISPLAY")).append(".pid")); +} + +pid_t readCompositorPID(const TQString &pidfileFName) { // Attempt to load the compton-tde pid file - char *filename; - const char *pidfile = "compton-tde.pid"; - char uidstr[sizeof(uid_t)*8+1]; - sprintf(uidstr, "%d", getuid()); - int n = strlen(P_tmpdir)+strlen(uidstr)+strlen(pidfile)+3; - filename = (char*)malloc(n*sizeof(char)+1); - memset(filename,0,n); - strcat(filename, P_tmpdir); - strcat(filename, "/."); - strcat(filename, uidstr); - strcat(filename, "-"); - strcat(filename, pidfile); - - // Now that we did all that by way of introduction...read the file! - FILE *pFile; - char buffer[255]; - pFile = fopen(filename, "r"); - pid_t kompmgrpid = 0; - if (pFile) - { - printf("[twin-workspace] Using '%s' as compton-tde pidfile\n\n", filename); - // obtain file size - fseek (pFile , 0 , SEEK_END); - unsigned long lSize = ftell (pFile); - if (lSize > 254) - lSize = 254; - rewind (pFile); - size_t result = fread (buffer, 1, lSize, pFile); - fclose(pFile); - if (result > 0) - { - kompmgrpid = atoi(buffer); - } + pid_t rv = 0; + TQFile pidFile(pidfileFName); + + if (pidFile.open(IO_ReadOnly)) { + bool ok; + TQString pidStr; + + pidFile.readLine(pidStr, 21); + rv = pidStr.toInt(&ok); + + if (!ok) { + return 0; } + } + + return rv; +} - free(filename); - filename = NULL; +pid_t getCompositorPID() { + pid_t rv = readCompositorPID(compositorPIDFile()); - return kompmgrpid; + // check the process is still running + if (kill(rv, 0) != 0) { + return 0; + } + + return rv; } // Rikkus: This class is too complex. It needs splitting further. @@ -180,14 +169,18 @@ Workspace::Workspace( bool restore ) topmenu_space( NULL ), set_active_client_recursion( 0 ), block_stacking_updates( 0 ), - forced_global_mouse_grab( false ) + forced_global_mouse_grab( false ), + kompmgr( NULL ), + kompmgr_selection( NULL ), + kompmgr_kill_timer( NULL ), + allowKompmgrRestart( true ) { _self = this; mgr = new PluginMgr; root = tqt_xrootwin(); default_colormap = DefaultColormap(tqt_xdisplay(), tqt_xscreen() ); installed_colormap = default_colormap; - session.setAutoDelete( TRUE ); + session.setAutoDelete( true ); for (int i = 0; i < ACTIVE_BORDER_COUNT; ++i) { @@ -220,10 +213,10 @@ Workspace::Workspace( bool restore ) (WFlags)(TQt::WType_Desktop | TQt::WPaintUnclipped) ); - kapp->setGlobalMouseTracking( true ); // so that this doesn't mess eventmask on root window later + tdeApp->setGlobalMouseTracking( true ); // so that this doesn't mess eventmask on root window later // call this before XSelectInput() on the root window startup = new TDEStartupInfo( - TDEStartupInfo::DisableKWinModule | TDEStartupInfo::AnnounceSilenceChanges, this ); + TDEStartupInfo::DisableTWinModule | TDEStartupInfo::AnnounceSilenceChanges, this ); // select windowmanager privileges XSelectInput(tqt_xdisplay(), root, @@ -259,7 +252,7 @@ Workspace::Workspace( bool restore ) init(); #if (TQT_VERSION-0 >= 0x030200) // XRANDR support - connect( kapp->desktop(), TQ_SIGNAL( resized( int )), TQ_SLOT( desktopResized())); + connect( tdeApp->desktop(), TQ_SIGNAL( resized( int )), TQ_SLOT( desktopResized())); #endif if (!supportsCompMgr()) { @@ -268,39 +261,12 @@ Workspace::Workspace( bool restore ) // start kompmgr - i wanted to put this into main.cpp, but that would prevent dcop support, as long as Application was no dcop_object - // If compton-tde is already running, send it SIGTERM - pid_t kompmgrpid = getCompositorPID(); + // If compton-tde is already running it's a stale process, send it SIGTERM + if (pid_t kompmgrpid = getCompositorPID()) + kill(kompmgrpid, SIGTERM); if (options->useTranslucency) - { - kompmgr = new TDEProcess; - connect(kompmgr, TQ_SIGNAL(receivedStderr(TDEProcess*, char*, int)), TQ_SLOT(handleKompmgrOutput(TDEProcess*, char*, int))); - *kompmgr << TDE_COMPOSITOR_BINARY; - if (kompmgrpid) - { - if (kill(kompmgrpid, 0) < 0) - { - // Stale PID file detected; (re)start compositor! - startKompmgr(); - } - } - else - { - startKompmgr(); - } - } - else if (!disable_twin_composition_manager) - { - - if (kompmgrpid) - { - kill(kompmgrpid, SIGTERM); - } - else - { - stopKompmgr(); - } - } + startKompmgr(); } @@ -414,12 +380,12 @@ void Workspace::init() // extra NETRootInfo instance in Client mode is needed to get the values of the properties NETRootInfo client_info( tqt_xdisplay(), NET::ActiveWindow | NET::CurrentDesktop ); int initial_desktop; - if( !kapp->isSessionRestored()) + if( !tdeApp->isSessionRestored()) initial_desktop = client_info.currentDesktop(); else { - TDEConfigGroupSaver saver( kapp->sessionConfig(), "Session" ); - initial_desktop = kapp->sessionConfig()->readNumEntry( "desktop", 1 ); + TDEConfigGroupSaver saver( tdeApp->sessionConfig(), "Session" ); + initial_desktop = tdeApp->sessionConfig()->readNumEntry( "desktop", 1 ); } if( !setCurrentDesktop( initial_desktop )) setCurrentDesktop( 1 ); @@ -431,16 +397,16 @@ void Workspace::init() TQ_SLOT(slotReconfigure())); connect( &updateToolWindowsTimer, TQ_SIGNAL( timeout()), this, TQ_SLOT( slotUpdateToolWindows())); - connect(kapp, TQ_SIGNAL(appearanceChanged()), this, + connect(tdeApp, TQ_SIGNAL(appearanceChanged()), this, TQ_SLOT(slotReconfigure())); - connect(kapp, TQ_SIGNAL(settingsChanged(int)), this, + connect(tdeApp, TQ_SIGNAL(settingsChanged(int)), this, TQ_SLOT(slotSettingsChanged(int))); - connect(kapp, TQ_SIGNAL( kipcMessage( int, int )), this, TQ_SLOT( kipcMessage( int, int ))); + connect(tdeApp, TQ_SIGNAL( kipcMessage( int, int )), this, TQ_SLOT( kipcMessage( int, int ))); active_client = NULL; rootInfo->setActiveWindow( None ); focusToNull(); - if( !kapp->isSessionRestored()) + if( !tdeApp->isSessionRestored()) ++block_focus; // because it will be set below char nm[ 100 ]; @@ -503,7 +469,7 @@ void Workspace::init() } // end updates blocker block Client* new_active_client = NULL; - if( !kapp->isSessionRestored()) + if( !tdeApp->isSessionRestored()) { --block_focus; new_active_client = findClient( WindowMatchPredicate( client_info.activeWindow())); @@ -551,7 +517,7 @@ Workspace::~Workspace() it != stacking_order.end(); ++it ) { - // only release the window + // only release the window (*it)->releaseWindow( true ); // No removeClient() is called, it does more than just removing. // However, remove from some lists to e.g. prevent performTransiencyCheck() @@ -622,9 +588,13 @@ void Workspace::addClient( Client* c, allowed_t ) if (!c->hasCustomOpacity()) // this xould be done slightly more efficient, but we want to support the topDock in future { c->setShadowSize(options->dockShadowSize); - c->setOpacity(options->translucentDocks, options->dockOpacity); + c->setOpacity(options->translucentDocks ? options->dockOpacity : Client::Opacity::Opaque); } } + else + { + c->updateOpacity(); + } if (c->isMenu() || c->isTopMenu()) { @@ -657,7 +627,7 @@ void Workspace::addClient( Client* c, allowed_t ) if( c->isDesktop()) { raiseClient( c ); - // if there's no active client, make this desktop the active one + // if there's no active client, make this desktop the active one if( activeClient() == NULL && should_get_focus.count() == 0 ) activateClient( findDesktop( true, currentDesktop())); } @@ -1134,76 +1104,16 @@ void Workspace::slotReconfigure() if (options->resetKompmgr) // need restart { - bool tmp = options->useTranslucency; - - // If compton-tde is already running, sending SIGUSR2 will force a reload of its settings - // Attempt to load the compton-tde pid file - char *filename; - const char *pidfile = "compton-tde.pid"; - char uidstr[sizeof(uid_t)*8+1]; - sprintf(uidstr, "%d", getuid()); - int n = strlen(P_tmpdir)+strlen(uidstr)+strlen(pidfile)+3; - filename = (char*)malloc(n*sizeof(char)+1); - memset(filename,0,n); - strcat(filename, P_tmpdir); - strcat(filename, "/."); - strcat(filename, uidstr); - strcat(filename, "-"); - strcat(filename, pidfile); - - // Now that we did all that by way of introduction...read the file! - FILE *pFile; - char buffer[255]; - pFile = fopen(filename, "r"); - int kompmgrpid = 0; - if (pFile) - { - printf("[twin-workspace] Using '%s' as compton-tde pidfile\n\n", filename); - // obtain file size - fseek (pFile , 0 , SEEK_END); - unsigned long lSize = ftell (pFile); - if (lSize > 254) - lSize = 254; - rewind (pFile); - size_t result = fread (buffer, 1, lSize, pFile); - fclose(pFile); - if (result > 0) - { - kompmgrpid = atoi(buffer); - } - } - - free(filename); - filename = NULL; - - if (tmp) + if (options->useTranslucency) { - if (kompmgrpid) - { - kill(kompmgrpid, SIGUSR2); - } + if (kompmgrIsRunning()) + kompmgrReloadSettings(); else - { - stopKompmgr(); - if (!kompmgr) - { - kompmgr = new TDEProcess; - connect(kompmgr, TQ_SIGNAL(receivedStderr(TDEProcess*, char*, int)), TQ_SLOT(handleKompmgrOutput(TDEProcess*, char*, int))); - *kompmgr << TDE_COMPOSITOR_BINARY; - } TQTimer::singleShot( 200, this, TQ_SLOT(startKompmgr()) ); // wait some time to ensure system's ready for restart - } } else { - if (kompmgrpid) - { - kill(kompmgrpid, SIGTERM); - } - else - { - stopKompmgr(); - } + stopKompmgr(); } } } @@ -1277,7 +1187,7 @@ TQStringList Workspace::configModules(bool controlCenter) args << "tde-twindecoration.desktop"; if (controlCenter) args << "tde-twinoptions.desktop"; - else if (kapp->authorizeControlModule("tde-twinoptions.desktop")) + else if (tdeApp->authorizeControlModule("tde-twinoptions.desktop")) args << "twinactions" << "twinfocus" << "twinmoving" << "twinadvanced" << "twinrules" << "twintranslucency"; return args; } @@ -1306,10 +1216,10 @@ bool Workspace::isNotManaged( const TQString& title ) if (r.search(title) != -1) { doNotManageList.remove( it ); - return TRUE; + return true; } } - return FALSE; + return false; } /*! @@ -1423,7 +1333,7 @@ bool Workspace::setCurrentDesktop( int new_desktop ) current_desktop = new_desktop; // change the desktop (so that Client::updateVisibility() works) - bool desktopHasCompositing = kapp->isCompositionManagerAvailable(); // Technically I should call isX11CompositionAvailable(), but it isn't initialized via my kapp constructir, and in this case it doesn't really matter anyway.... + bool desktopHasCompositing = tdeApp->isCompositionManagerAvailable(); // Technically I should call isX11CompositionAvailable(), but it isn't initialized via my tdeApp constructir, and in this case it doesn't really matter anyway.... if (!desktopHasCompositing) { // If composition is not in use then we can hide the old windows before showing the new ones for ( ClientList::ConstIterator it = stacking_order.begin(); it != stacking_order.end(); ++it) { @@ -1806,7 +1716,7 @@ void Workspace::setActiveScreenMouse( TQPoint mousepos ) TQRect Workspace::screenGeometry( int screen ) const { - if (( !options->xineramaEnabled ) || (kapp->desktop()->numScreens() < 2)) + if (( !options->xineramaEnabled ) || (tdeApp->desktop()->numScreens() < 2)) return tqApp->desktop()->geometry(); return tqApp->desktop()->screenGeometry( screen ); } @@ -1875,19 +1785,19 @@ void Workspace::calcDesktopLayout(int &x, int &y) const bool Workspace::addSystemTrayWin( WId w ) { if ( systemTrayWins.contains( w ) ) - return TRUE; + return true; NETWinInfo ni( tqt_xdisplay(), w, root, NET::WMKDESystemTrayWinFor ); WId trayWinFor = ni.kdeSystemTrayWinFor(); if ( !trayWinFor ) - return FALSE; + return false; systemTrayWins.append( SystemTrayWindow( w, trayWinFor ) ); XSelectInput( tqt_xdisplay(), w, StructureNotifyMask ); XAddToSaveSet( tqt_xdisplay(), w ); propagateSystemTrayWins(); - return TRUE; + return true; } /*! @@ -1897,7 +1807,7 @@ bool Workspace::addSystemTrayWin( WId w ) bool Workspace::removeSystemTrayWin( WId w, bool check ) { if ( !systemTrayWins.contains( w ) ) - return FALSE; + return false; if( check ) { // When getting UnmapNotify, it's not clear if it's the systray @@ -1925,7 +1835,7 @@ bool Workspace::removeSystemTrayWin( WId w, bool check ) systemTrayWins.remove( w ); XRemoveFromSaveSet (tqt_xdisplay (), w); propagateSystemTrayWins(); - return TRUE; + return true; } @@ -2090,34 +2000,34 @@ void Workspace::slotGrabWindow() { TQPixmap snapshot = TQPixmap::grabWindow( active_client->frameId() ); - //No XShape - no work. + //No XShape - no work. if( Shape::available()) { - //As the first step, get the mask from XShape. + //As the first step, get the mask from XShape. int count, order; XRectangle* rects = XShapeGetRectangles( tqt_xdisplay(), active_client->frameId(), ShapeBounding, &count, &order); - //The ShapeBounding region is the outermost shape of the window; - //ShapeBounding - ShapeClipping is defined to be the border. - //Since the border area is part of the window, we use bounding - // to limit our work region + //The ShapeBounding region is the outermost shape of the window; + //ShapeBounding - ShapeClipping is defined to be the border. + //Since the border area is part of the window, we use bounding + // to limit our work region if (rects) { - //Create a TQRegion from the rectangles describing the bounding mask. + //Create a TQRegion from the rectangles describing the bounding mask. TQRegion contents; for (int pos = 0; pos < count; pos++) contents += TQRegion(rects[pos].x, rects[pos].y, rects[pos].width, rects[pos].height); XFree(rects); - //Create the bounding box. + //Create the bounding box. TQRegion bbox(0, 0, snapshot.width(), snapshot.height()); - //Get the masked away area. + //Get the masked away area. TQRegion maskedAway = bbox - contents; TQMemArray<TQRect> maskedAwayRects = maskedAway.rects(); - //Construct a bitmap mask from the rectangles + //Construct a bitmap mask from the rectangles TQBitmap mask( snapshot.width(), snapshot.height()); TQPainter p(&mask); p.fillRect(0, 0, mask.width(), mask.height(), TQt::color1); @@ -2155,16 +2065,16 @@ void Workspace::slotMouseEmulation() if ( mouse_emulation ) { XUngrabKeyboard(tqt_xdisplay(), get_tqt_x_time()); - mouse_emulation = FALSE; + mouse_emulation = false; return; } if ( XGrabKeyboard(tqt_xdisplay(), - root, FALSE, + root, false, GrabModeAsync, GrabModeAsync, get_tqt_x_time()) == GrabSuccess ) { - mouse_emulation = TRUE; + mouse_emulation = true; mouse_emulation_state = 0; mouse_emulation_window = 0; } @@ -2225,7 +2135,7 @@ unsigned int Workspace::sendFakedMouseEvent( TQPoint pos, WId w, MouseEmulation e.xmotion.y_root = pos.y(); e.xmotion.state = state; e.xmotion.is_hint = NotifyNormal; - XSendEvent( tqt_xdisplay(), w, TRUE, ButtonMotionMask, &e ); + XSendEvent( tqt_xdisplay(), w, True, ButtonMotionMask, &e ); } else { @@ -2241,7 +2151,7 @@ unsigned int Workspace::sendFakedMouseEvent( TQPoint pos, WId w, MouseEmulation e.xbutton.y_root = pos.y(); e.xbutton.state = state; e.xbutton.button = button; - XSendEvent( tqt_xdisplay(), w, TRUE, ButtonPressMask, &e ); + XSendEvent( tqt_xdisplay(), w, True, ButtonPressMask, &e ); if ( type == EmuPress ) { @@ -2284,7 +2194,7 @@ unsigned int Workspace::sendFakedMouseEvent( TQPoint pos, WId w, MouseEmulation bool Workspace::keyPressMouseEmulation( XKeyEvent& ev ) { if ( root != tqt_xrootwin() ) - return FALSE; + return false; int kc = XkbKeycodeToKeysym(tqt_xdisplay(), ev.keycode, 0, 0); int km = ev.state & (ControlMask | Mod1Mask | ShiftMask); @@ -2361,16 +2271,16 @@ bool Workspace::keyPressMouseEmulation( XKeyEvent& ev ) // fall through case XK_Escape: XUngrabKeyboard(tqt_xdisplay(), get_tqt_x_time()); - mouse_emulation = FALSE; - return TRUE; + mouse_emulation = false; + return true; default: - return FALSE; + return false; } TQCursor::setPos( pos ); if ( mouse_emulation_state ) mouse_emulation_state = sendFakedMouseEvent( pos, mouse_emulation_window, EmuMove, 0, mouse_emulation_state ); - return TRUE; + return true; } @@ -2397,7 +2307,7 @@ void Workspace::requestDelayFocus( Client* c ) delete delayFocusTimer; delayFocusTimer = new TQTimer( this ); connect( delayFocusTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( delayFocus() ) ); - delayFocusTimer->start( options->delayFocusInterval, TRUE ); + delayFocusTimer->start( options->delayFocusInterval, true ); } void Workspace::cancelDelayFocus() @@ -2542,15 +2452,21 @@ void Workspace::checkActiveBorder(const TQPoint &pos, Time now) int distance_reset = activation_distance + 10; // Leave active maximizing mode when window moved away - if (active_current_border != ActiveNone && - (pos.x() > activeLeft + distance_reset) && - (pos.x() < activeRight - distance_reset) && - (pos.y() > activeTop + distance_reset) && - (pos.y() < activeBottom - distance_reset)) - { - if (movingClient && - (options->activeBorders() == Options::ActiveTileMaximize || - options->activeBorders() == Options::ActiveTileOnly)) + if (movingClient && + (options->activeBorders() == Options::ActiveTileMaximize || + options->activeBorders() == Options::ActiveTileOnly)) + { + TQRect r = TQApplication::desktop()->screenGeometry(pos); + activeTop = r.top(); + activeBottom = r.bottom(); + activeLeft = r.left(); + activeRight = r.right(); + + if (active_current_border != ActiveNone && + (pos.x() > activeLeft + distance_reset) && + (pos.x() < activeRight - distance_reset) && + (pos.y() > activeTop + distance_reset) && + (pos.y() < activeBottom - distance_reset)) { movingClient->cancelActiveBorderMaximizing(); return; @@ -2661,6 +2577,7 @@ void Workspace::checkActiveBorder(const TQPoint &pos, Time now) { if (!movingClient->isResizable()) return; movingClient->setActiveBorderMode(ActiveMaximizeMode); + movingClient->setActiveBorderPos(pos); movingClient->setActiveBorder(ActiveNone); movingClient->setActiveBorderMaximizing(true); } @@ -2671,6 +2588,7 @@ void Workspace::checkActiveBorder(const TQPoint &pos, Time now) { if (!movingClient->isResizable()) return; movingClient->setActiveBorderMode(ActiveTilingMode); + movingClient->setActiveBorderPos(pos); movingClient->setActiveBorder(border); movingClient->setActiveBorderMaximizing(true); } @@ -2952,28 +2870,58 @@ void Workspace::startKompmgr() unsigned long length, after; unsigned char* data_root; Atom prop_root; + bool retry_later = false; + pid_t kompmgrpid; + + if (!kompmgr) + { + kompmgr = new TDEProcess; + connect(kompmgr, TQ_SIGNAL(receivedStderr(TDEProcess*, char*, int)), TQ_SLOT(handleKompmgrOutput(TDEProcess*, char*, int))); + *kompmgr << TDE_COMPOSITOR_BINARY; + *kompmgr << "--write-pid-path" << compositorPIDFile(); + } + if (!kompmgr_kill_timer) + { + kompmgr_kill_timer = new TQTimer(this); + connect(kompmgr_kill_timer, TQ_SIGNAL(timeout()), this, TQ_SLOT(killKompmgr())); + } + prop_root = XInternAtom(tqt_xdisplay(), "_XROOTPMAP_ID", False); - if( XGetWindowProperty( tqt_xdisplay(), tqt_xrootwin(), prop_root, 0L, 1L, False, AnyPropertyType, &type, &format, &length, &after, &data_root) == Success && data_root != NULL ) { - // Root pixmap is available; OK to load... - } - else { + if( XGetWindowProperty( tqt_xdisplay(), tqt_xrootwin(), prop_root, 0L, 1L, False, AnyPropertyType, &type, &format, &length, &after, &data_root) != Success || data_root == NULL ) { + // Root pixmap is not available; try to start compton-tde later + retry_later = true; + } + else if (kompmgrIsRunning()) + { + if (kompmgr_kill_timer->isActive()) + { + // The process is pending to stop but didn't yet; this shouldn't generally happend, + // but to be on the safe side kill it now and retry starting later + kompmgr_kill_timer->stop(); + killKompmgr(); + retry_later = true; + } + else + { + kompmgrReloadSettings(); + return; + } + } + else if ( (kompmgrpid = getCompositorPID()) ) + { + // stale compton-tde process detected; kill it and retry starting again later + kill(kompmgrpid, SIGKILL); + retry_later = true; + } + if (retry_later) + { // Try again a bit later! TQTimer::singleShot( 200, this, TQ_SLOT(startKompmgr()) ); return; - } - pid_t kompmgrpid = getCompositorPID(); - if (kompmgrpid && kill(kompmgrpid, 0) >= 0) - { - // Active PID file detected; do not attempt to restart - return; } - if (!kompmgr || kompmgr->isRunning()) { - kompmgrReloadSettings(); - return; - } if (!kompmgr->start(TDEProcess::OwnGroup, TDEProcess::Stderr)) { - options->useTranslucency = FALSE; + options->useTranslucency = false; TDEProcess proc; proc << "kdialog" << "--error" << i18n("The Composite Manager could not be started.\\nMake sure you have \"" TDE_COMPOSITOR_BINARY "\" in a $PATH directory.") @@ -2989,40 +2937,58 @@ void Workspace::startKompmgr() connect( kompmgr_selection, TQ_SIGNAL( lostOwnership()), TQ_SLOT( stopKompmgr())); kompmgr_selection->claim( true ); connect(kompmgr, TQ_SIGNAL(processExited(TDEProcess*)), TQ_SLOT(restartKompmgr(TDEProcess*))); - options->useTranslucency = TRUE; - //allowKompmgrRestart = FALSE; + options->useTranslucency = true; + //allowKompmgrRestart = false; //TQTimer::singleShot( 60000, this, TQ_SLOT(unblockKompmgrRestart()) ); TQByteArray ba; TQDataStream arg(ba, IO_WriteOnly); arg << ""; - kapp->dcopClient()->emitDCOPSignal("default", "kompmgrStarted()", ba); + tdeApp->dcopClient()->emitDCOPSignal("default", "kompmgrStarted()", ba); } if (popup){ delete popup; popup = 0L; } // to add/remove opacity slider } void Workspace::stopKompmgr() { - if (!kompmgr || !kompmgr->isRunning()) { + if (!kompmgrIsRunning()) { return; } delete kompmgr_selection; kompmgr_selection = NULL; kompmgr->disconnect(this, TQ_SLOT(restartKompmgr(TDEProcess*))); - options->useTranslucency = FALSE; + options->useTranslucency = false; if (popup){ delete popup; popup = 0L; } // to add/remove opacity slider - kompmgr->kill(SIGKILL); + connect(kompmgr, TQ_SIGNAL(processExited(TDEProcess *)), kompmgr_kill_timer, TQ_SLOT()); + kompmgr->kill(SIGTERM); + kompmgr_kill_timer->start(5000, /* sshot */ true); TQByteArray ba; TQDataStream arg(ba, IO_WriteOnly); arg << ""; - kapp->dcopClient()->emitDCOPSignal("default", "kompmgrStopped()", ba); + tdeApp->dcopClient()->emitDCOPSignal("default", "kompmgrStopped()", ba); +} + +void Workspace::killKompmgr() { + if (!kompmgrIsRunning()) { + return; + } + + // Since we had to forcefully kill the process it won't have a chance to clean-up after itself; + // so do it manually + TQString pidfileFName = compositorPIDFile(); + // To be on the safe side verify that the file belongs to the process we are killing + if (readCompositorPID(pidfileFName) == kompmgr->pid()) { + TQFile::remove(pidfileFName); + } + + kompmgr->kill(SIGKILL); } void Workspace::kompmgrReloadSettings() { - if (!kompmgr || !kompmgr->isRunning()) { + if (!kompmgrIsRunning()) { return; } - kompmgr->kill(SIGUSR2); + kompmgr->kill(SIGUSR1); } bool Workspace::kompmgrIsRunning() @@ -3032,7 +2998,7 @@ bool Workspace::kompmgrIsRunning() void Workspace::unblockKompmgrRestart() { - allowKompmgrRestart = TRUE; + allowKompmgrRestart = true; } void Workspace::restartKompmgr( TDEProcess *proc ) @@ -3051,7 +3017,7 @@ void Workspace::restartKompmgr( TDEProcess *proc ) { delete kompmgr_selection; kompmgr_selection = NULL; - options->useTranslucency = FALSE; + options->useTranslucency = false; if (crashed) { TDEProcess proc; proc << "kdialog" << "--error" @@ -3075,7 +3041,7 @@ void Workspace::restartKompmgr( TDEProcess *proc ) { delete kompmgr_selection; kompmgr_selection = NULL; - options->useTranslucency = FALSE; + options->useTranslucency = false; TDEProcess proc; proc << "kdialog" << "--error" << i18n("The Composite Manager could not be started.\\nMake sure you have \"" TDE_COMPOSITOR_BINARY "\" in a $PATH directory.") @@ -3084,7 +3050,7 @@ void Workspace::restartKompmgr( TDEProcess *proc ) } else { - allowKompmgrRestart = FALSE; + allowKompmgrRestart = false; TQTimer::singleShot( 60000, this, TQ_SLOT(unblockKompmgrRestart()) ); } } @@ -3123,13 +3089,24 @@ void Workspace::handleKompmgrOutput( TDEProcess* , char *buffer, int buflen) } } +uint Workspace::percentToUint(int percent) { + if(percent < 0) { + return 0; + } else if (percent<100) { + // the same as "percent / 100.0 * 0xffffffff" but avoids FP arithmetics and overflows + return (0xffffffff/100) * (uint) percent + (0xffffffff % 100) * percent / 100; + } else { + return 0xffffffff; + } +} + void Workspace::setOpacity(unsigned long winId, unsigned int opacityPercent) { if (opacityPercent > 100) opacityPercent = 100; for( ClientList::ConstIterator it = stackingOrder().begin(); it != stackingOrder().end(); it++ ) if (winId == (*it)->window()) { - (*it)->setOpacity(opacityPercent < 100, (unsigned int)((opacityPercent/100.0)*0xFFFFFFFF)); + (*it)->setOpacity(percentToUint(opacityPercent)); return; } } |
