[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: Bug#38142: wrong wallpaper list kills xlock (fwd)
From:       Lubos Lunak <l.lunak () sh ! cvut ! cz>
Date:       2002-03-02 15:48:34
[Download RAW message or body]

On po 25. únor 2002 23:18, David Faure wrote:
> On Friday 15 February 2002 20:42, Matthias Welwarsky wrote:
> > On Friday 15 February 2002 19:32, Rik Hemsley wrote:
> > > #if Stephan Kulow
> > >
> > > > On Friday, 15. February 2002 14:14, David Faure wrote:
> > > > > Funny, as in: never thought this would happen....
> > > > >
> > > > > But seriously... Maybe this is a reason why we shouldn't have
> > > > > merged kdesktop and kscreensaver (at least the lock stuff).
> > > >
> > > > The locking _is_ out of kdesktop. It's in the screensaver that is
> > > > started from kdesktop. If kdesktop dies, it takes it's children with
> > > > it, it seems. Solution is to reparent the screensaver. daemon() or
> > > > what was the name of that function? :)
> > >
> > > setsid(2), I think.
> >
> > setpgid(2) is maybe better, because the screensaver is no session leader.
> > If the screensaver should not die when kdesktop dies, move it out of the
> > process group of kdesktop. if you open a new session for the screensaver,
> > it will probably refuse to die when the real session leader (xsession) is
> > killed...
>
> I tried that but it doesn't appear to work, both go away when kdesktop is
> killed. Help!

 Here it comes :). First of all, Coolo was wrong, the locking is in kdesktop 
(and the screensaver was actually killed because kdesktop catches signals and 
tries to do a proper cleanup).
 Those who are bored and have nothing to do can review the attached patch. 
It's basically moving the locking part itself in another executable. When 
kdesktop has to start screensaver/locking , it launches this process, which 
locks the screen and launches screensaver. The process ignores SIGHUP, SIGINT 
and SIGQUIT, so it should stay even if kdesktop exits. It only exits cleanly 
on SIGTERM.

 Because we're in message freeze, the new process uses kdesktop's messages  
file (the messages target in Makefile will probably need fixing) and doesn't 
use i18n() for it's command line options etc.


-- 
 Lubos Lunak
 llunak@suse.cz ; l.lunak@kde.org
 http://dforce.sh.cvut.cz/~seli

["kdesktop.patch" (text/x-diff)]

diff -u3 -p -d -N kdesktop.sav/Makefile.am kdesktop/Makefile.am
--- kdesktop.sav/Makefile.am	Sat Mar  2 15:49:14 2002
+++ kdesktop/Makefile.am	Sat Mar  2 15:50:33 2002
@@ -6,7 +6,7 @@ kdesktop_la_LIBADD   = $(top_builddir)/l
 kdesktop_LDFLAGS  = $(all_libraries) $(KDE_RPATH)
 kdesktop_LDADD    = kdesktop.la
 
-SUBDIRS = . pics patterns programs init kwebdesktop
+SUBDIRS = . lock pics patterns programs init kwebdesktop
 
 ####### Files
 
@@ -15,7 +15,7 @@ bin_SCRIPTS = kdeeject
 lib_LTLIBRARIES = kdesktop.la
 
 kdesktop_la_SOURCES = krootwm.cc xautolock.cc kdiconview.cc desktop.cc main.cc \
-	lockeng.cc lockdlg.cc KDesktopIface.skel \
+	lockeng.cc KDesktopIface.skel \
 	bgmanager.cc init.cc KScreensaverIface.skel \
 	minicli.cpp KBackgroundIface.skel pixmapserver.cc kcustommenu.cc \
 	startupid.cpp
@@ -25,7 +25,7 @@ kdesktop_SOURCES = dummy.cc
 include_HEADERS = KDesktopIface.h KScreensaverIface.h KBackgroundIface.h
 
 noinst_HEADERS = desktop.h bgmanager.h krootwm.h \
-	xautolock.h lockeng.h lockdlg.h init.h minicli.h \
+	xautolock.h lockeng.h init.h minicli.h \
 	pixmapserver.h startupid.h
 
 kdmdesktop_SOURCES = kdmdesktop.cpp
@@ -47,8 +47,3 @@ menudir = $(kde_confdir)
 
 autostart_DATA = kdesktop.desktop
 autostartdir = $(prefix)/share/autostart
-
-PAM = @KSCREENSAVER_PAM_SERVICE@
-
-install-data-local:
-	-@test -n "$(DESTDIR)" || test -z "$(PAM)" || $(top_srcdir)/mkpamserv $(PAM)
Common subdirectories: kdesktop.sav/init and kdesktop/init
Common subdirectories: kdesktop.sav/kwebdesktop and kdesktop/kwebdesktop
Common subdirectories: kdesktop.sav/lock and kdesktop/lock
diff -u3 -p -d -N kdesktop.sav/lockdlg.cc kdesktop/lockdlg.cc
--- kdesktop.sav/lockdlg.cc	Sat Mar  2 15:38:47 2002
+++ kdesktop/lockdlg.cc	Thu Jan  1 01:00:00 1970
@@ -1,214 +0,0 @@
-//===========================================================================
-//
-// This file is part of the KDE project
-//
-// Copyright (c) 1999 Martin R. Jones <mjones@kde.org>
-//
-
-#include <ctype.h>
-#include <unistd.h>
-#include <pwd.h>
-#include <sys/types.h>
-#include <qlayout.h>
-#include <klocale.h>
-#include <kstandarddirs.h>
-#include <kglobalsettings.h>
-#include <kconfig.h>
-#include <kiconloader.h>
-#include <kdesu/defaults.h>
-#include <kpassdlg.h>
-#include "lockdlg.h"
-#include "lockdlg.moc"
-
-#include <X11/Xutil.h>
-#include <X11/keysym.h>
-
-#define MAX_PASSWORD_LENGTH     20
-
-//===========================================================================
-//
-// Simple dialog for entering a password.
-// It does not handle password validation.
-//
-PasswordDlg::PasswordDlg(QWidget *parent)
-    : QFrame(parent)
-{
-    setFocusPolicy(StrongFocus);
-    setFrameStyle(QFrame::Panel | QFrame::Raised);
-    setLineWidth(2);
-
-    KConfig *config = KGlobal::config();
-    config->reparseConfiguration();
-    KConfigGroupSaver cgs(config, "Passwords");
-    QString val = config->readEntry("EchoMode", "x");
-    if (val == "OneStar"
-	|| (val == "x" && defEchoMode == KPasswordEdit::OneStar))
-	mStars = 1;
-    else if (val == "ThreeStars"
-	|| (val == "x" && defEchoMode == KPasswordEdit::ThreeStars))
-	mStars = 3;
-    else
-	mStars = 0;
-
-    mBlink = false;
-    mPassword = "";
-
-    QGridLayout *layout = new QGridLayout(this, 2, 3, 20, 10);
-    layout->setResizeMode(QLayout::Minimum);
-    layout->addColSpacing(1, 20);
-
-    QLabel *pixlabel= new QLabel(this);
-    pixlabel->setPixmap(QPixmap(locate("data", "kdesktop/pics/ksslogo.png")));
-    layout->addMultiCellWidget(pixlabel, 0, 1, 0, 0, QLayout::AlignTop);
-
-    QFont font = KGlobalSettings::generalFont();
-    font.setPointSize(18);
-
-    QString query = passwordQueryMsg(true);
-    mLabel = new QLabel(query, this);
-    mLabel->setFont(font);
-    mLabel->setAlignment(AlignCenter);
-
-    layout->addWidget(mLabel, 0, 2);
-
-    font.setPointSize(16);
-    mEntry = new QLabel("*********************_", this);
-    mEntry->setFont(font);
-    mEntry->setMinimumHeight(mEntry->sizeHint().height()+5);
-    mEntry->setMinimumWidth(mEntry->sizeHint().width()+10);
-    mEntry->setFrameStyle(QFrame::Panel | QFrame::Sunken);
-    mEntry->setText("");
-
-    layout->addWidget(mEntry, 1, 2);
-    layout->activate();
-
-    resize(layout->sizeHint());
-
-    mFailedTimerId = 0;
-    mBlinkTimerId = startTimer(300);
-}
-
-//---------------------------------------------------------------------------
-//
-// Reset the password to ""
-//
-void PasswordDlg::resetPassword()
-{
-    mPassword = "";
-    drawStars();
-}
-
-//---------------------------------------------------------------------------
-//
-// Show "Failed" in the dialog for 1.5 seconds
-//
-void PasswordDlg::showFailed()
-{
-    mLabel->setText(i18n("Failed"));
-    mFailedTimerId = startTimer(1500);
-}
-
-//---------------------------------------------------------------------------
-//
-// Keyboard events should be passed to this function directly.
-// We accept key presses this way because the keyboard is grabbed, so we
-// don't get any events.  There's nicer ways of handling this, but this is
-// simplest.
-//
-void PasswordDlg::keyPressed(XKeyEvent *xKeyEvent)
-{
-    KeySym keysym = 0;
-    char buffer[10] = "";
-    (void)XLookupString(xKeyEvent, buffer, 10, &keysym, 0);
-
-    switch (keysym)
-    {
-        case XK_BackSpace:
-            if (mPassword.length())
-            {
-                mPassword.truncate(mPassword.length() - 1);
-                drawStars();
-            }
-            break;
-
-        default:
-            if (mPassword.length() < MAX_PASSWORD_LENGTH && !iscntrl(buffer[0]))
-            {
-                 mPassword += buffer[0];
-                 drawStars();
-            }
-    }
-}
-
-//---------------------------------------------------------------------------
-//
-// Draws the stars if mStars is true
-//
-void PasswordDlg::drawStars()
-{
-    QString s("");
-
-    if (mStars)
-        s.fill('*', mPassword.length() * mStars);
-
-    if (mBlink)
-	s += "_";
-
-    mEntry->setText(s);
-}
-
-//---------------------------------------------------------------------------
-//
-// Fetch current user id, and return "Firstname Lastname (username)"
-//
-QString PasswordDlg::currentUser(void)
-{
-    struct passwd *current = getpwuid(getuid());
-    QString fullname = QString::fromLocal8Bit(current->pw_gecos);
-    if (fullname.find(',') != -1)
-    {
-        // Remove everything from and including first comma
-        fullname.truncate(fullname.find(','));
-    }
-
-    QString username = QString::fromLocal8Bit(current->pw_name);
-
-    return fullname + " (" + username + ")";
-}
-
-//---------------------------------------------------------------------------
-//
-// This returns the string to use to ask the user for their password.
-//
-QString PasswordDlg::passwordQueryMsg(bool name)
-{
-    QString retval("");
-    if (name)
-    {
-        retval = currentUser();
-    }
-    return i18n("Enter Password") + "\n" + retval;
-} 
-
-//---------------------------------------------------------------------------
-//
-// Handle timer events.
-//
-void PasswordDlg::timerEvent(QTimerEvent *ev)
-{
-    if (ev->timerId() == mBlinkTimerId)
-    {
-        // Show/hide the password entry cursor.
-        mBlink = !mBlink;
-        drawStars();
-    }
-    else if (ev->timerId() == mFailedTimerId)
-    {
-        // Show the normal password prompt.
-        mLabel->setText(passwordQueryMsg(true));
-        drawStars();
-        killTimer(mFailedTimerId);
-        mFailedTimerId = 0;
-    }
-}
-
diff -u3 -p -d -N kdesktop.sav/lockdlg.h kdesktop/lockdlg.h
--- kdesktop.sav/lockdlg.h	Mon Jun 26 09:56:47 2000
+++ kdesktop/lockdlg.h	Thu Jan  1 01:00:00 1970
@@ -1,70 +0,0 @@
-//===========================================================================
-//
-// This file is part of the KDE project
-//
-// Copyright (c) 1999 Martin R. Jones <mjones@kde.org>
-//
-
-#ifndef __LOCKDLG_H__
-#define __LOCKDLG_H__
-
-#include <qframe.h>
-#include <qlabel.h>                                                             
-#include <X11/Xlib.h>
-
-//===========================================================================
-//
-// Simple dialog for entering a password.
-// It does not handle password validation.
-//
-class PasswordDlg : public QFrame
-{
-    Q_OBJECT
-public:
-    PasswordDlg(QWidget *parent);
-
-    //-----------------------------------------------------------------------
-    //
-    // Reset the password to ""
-    //
-    void resetPassword();
-
-    //-----------------------------------------------------------------------
-    //
-    // Show "Failed" in the dialog for 1.5 seconds
-    //
-    void showFailed();
-
-    //-----------------------------------------------------------------------
-    //
-    // Keyboard events should be passed to this function directly.
-    // We accept key presses this way because the keyboard is grabbed, so we
-    // don't get any events.  There's nicer ways of handling this, but this
-    // is simplest.
-    //
-    void keyPressed(XKeyEvent *);
-
-    //-----------------------------------------------------------------------
-    //
-    // return the password the user entered.
-    //
-    QString password() const { return mPassword; }
-
-protected:
-    void drawStars();
-    QString currentUser();
-    QString passwordQueryMsg(bool name);
-    virtual void timerEvent(QTimerEvent *);
-
-private:
-    int         mFailedTimerId;
-    int         mBlinkTimerId;
-    QLabel      *mLabel;
-    QLabel      *mEntry;
-    QString     mPassword;
-    int         mStars;
-    bool        mBlink;
-};
-
-#endif
-
diff -u3 -p -d -N kdesktop.sav/lockeng.cc kdesktop/lockeng.cc
--- kdesktop.sav/lockeng.cc	Sat Mar  2 15:49:14 2002
+++ kdesktop/lockeng.cc	Sat Mar  2 16:29:53 2002
@@ -9,55 +9,30 @@
 #include <config.h>
 
 #include <stdlib.h>
-#include <qcursor.h>
 
 #include <kstandarddirs.h>
 #include <kapplication.h>
 #include <kservicegroup.h>
 #include <kdebug.h>
-#include <kmessagebox.h>
 #include <klocale.h>
-#include <kwin.h>
-#include <qtimer.h>
 #include <qfile.h>
 #include <assert.h>
 
 #include "lockeng.h"
 #include "lockeng.moc"
 
-#ifdef HAVE_SETPRIORITY
-#include <sys/time.h>
-#include <sys/resource.h>
-#endif
-
 #include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/keysym.h>
-#include <X11/Xatom.h>
-
-#ifndef None
-#define None 0L
-#endif
-
-#define PASSDLG_HIDE_TIMEOUT        10000
-
-int ignoreXError(Display *, XErrorEvent *);
-static Window gVRoot = 0;
-static Window gVRootData = 0;
-static Atom   gXA_VROOT;
-static Atom   gXA_SCREENSAVER_VERSION;
 
 //===========================================================================
 //
-// Screen saver engine.  Handles screensaver window, starting screensaver
-// hacks, and password entry.
+// Screen saver engine. Doesn't handle the actual screensaver window,
+// starting screensaver hacks, or password entry. That's done by
+// a newly started process.
 //
 SaverEngine::SaverEngine()
-    : QWidget(0L, "saver window", WStyle_Customize | WStyle_NoBorder),
+    : QWidget(),
       DCOPObject("KScreensaverIface")
 {
-    KWin::setState( winId(), NET::StaysOnTop );
-    
     kapp->installX11EventFilter(this);
 
     // Save X screensaver parameters
@@ -67,60 +42,12 @@ SaverEngine::SaverEngine()
     // We'll handle blanking
     XSetScreenSaver(qt_xdisplay(), 0, mXInterval, mXBlanking, mXExposures);
 
-    // Get root window size
-    XWindowAttributes rootAttr;
-    XGetWindowAttributes(qt_xdisplay(), RootWindow(qt_xdisplay(),
-                        qt_xscreen()), &rootAttr);
-    mRootWidth = rootAttr.width;
-    mRootHeight = rootAttr.height;
-
-    // Add non-KDE path
-    KGlobal::dirs()->addResourceType("scrsav",
-                                    KGlobal::dirs()->kde_default("apps") +
-                                    "System/ScreenSavers/");
-
-    // Add KDE specific screensaver path
-    QString relPath="System/ScreenSavers/";
-    KServiceGroup::Ptr servGroup = KServiceGroup::baseGroup( "screensavers" );
-    if (servGroup)
-    {
-      relPath=servGroup->relPath();
-      kdDebug(1204) << "relPath=" << relPath << endl;
-    }
-    KGlobal::dirs()->addResourceType("scrsav",
-                                     KGlobal::dirs()->kde_default("apps") +
-                                     relPath);
-
     mState = Waiting;
-    mPassDlg = 0;
-    mHidePassTimerId = 0;
-    mCheckPassTimerId = 0;
-    mCheckingPass = false;
     mXAutoLock = 0;
     mEnabled = false;
-    mLockOnce = false;
-    mTimeout = 300;
-
-    // virtual root property
-    gXA_VROOT = XInternAtom (qt_xdisplay(), "__SWM_VROOT", False);
-    gXA_SCREENSAVER_VERSION = XInternAtom (qt_xdisplay(), "_SCREENSAVER_VERSION", False);
-
-    XWindowAttributes attrs;
-    XGetWindowAttributes(qt_xdisplay(), winId(), &attrs);
-    mColorMap = attrs.colormap;
 
-    connect(&mPassProc, SIGNAL(processExited(KProcess *)),
-                        SLOT(passwordChecked(KProcess *)));
-    connect(&mHackProc, SIGNAL(processExited(KProcess *)),
-                        SLOT(hackExited(KProcess *)));
-
-    QStringList dmopt =
-        QStringList::split( QChar( ',' ),
-                            QString::fromLatin1( ::getenv( "XDM_MANAGED" ) ) );
-    if ( dmopt.isEmpty() || dmopt.first()[0] != QChar( '/' ) )
-        mXdmFifoName = QString::null;
-    else
-        mXdmFifoName = dmopt.first();
+    connect(&mLockProcess, SIGNAL(processExited(KProcess *)),
+                        SLOT(lockProcessExited()));
 
     configure();
 }
@@ -131,7 +58,7 @@ SaverEngine::SaverEngine()
 //
 SaverEngine::~SaverEngine()
 {
-    hidePassDlg();
+    mLockProcess.detach(); // don't kill it if we crash
     delete mXAutoLock;
 
     // Restore X screensaver parameters
@@ -144,8 +71,7 @@ void SaverEngine::lock()
 {
     if (mState == Waiting)
     {
-        mLockOnce = true;
-        startSaver();
+        startLockProcess( ForceLock );
     }
 }
 
@@ -154,7 +80,7 @@ void SaverEngine::save()
 {
     if (mState == Waiting)
     {
-        startSaver();
+        startLockProcess( DontLock );
     }
 }
 
@@ -163,7 +89,7 @@ void SaverEngine::quit()
 {
     if (mState == Saving)
     {
-        stopSaver();
+        stopLockProcess();
     }
 }
 
@@ -187,8 +113,6 @@ bool SaverEngine::enable( bool e )
 
     if (mEnabled)
     {
-        readSaver(mSaver);
-
 	if ( !mXAutoLock ) {
 	    mXAutoLock = new XAutoLock();
 	    connect(mXAutoLock, SIGNAL(timeout()), SLOT(idleTimeout()));
@@ -205,7 +129,6 @@ bool SaverEngine::enable( bool e )
 	    delete mXAutoLock;
 	    mXAutoLock = 0;
 	}
-        mSaverExec = QString::null;
 
         kdDebug(1204) << "Saver Engine disabled" << endl;
     }
@@ -236,12 +159,7 @@ void SaverEngine::configure()
     config->setGroup("ScreenSaver");
 
     bool e  = config->readBoolEntry("Enabled", false);
-    mLock     = config->readBoolEntry("Lock", false);
-    mPriority = config->readNumEntry("Priority", 19);
-    if (mPriority < 0) mPriority = 0;
-    if (mPriority > 19) mPriority = 19;
     mTimeout = config->readNumEntry("Timeout", 300);
-    mSaver = config->readEntry("Saver");
 
     mEnabled = !e;   // force the enable()
 
@@ -250,465 +168,86 @@ void SaverEngine::configure()
 
 //---------------------------------------------------------------------------
 //
-// Read the command line needed to run the screensaver given a .desktop file.
-//
-void SaverEngine::readSaver(QString saver)
-{
-    if (!saver.isEmpty())
-    {
-        QString file = locate("scrsav", saver);
-
-//        kdDebug(1204) << "Reading saver: " << saver << endl;
-
-        KDesktopFile config(file, true);
-
-        if (config.hasActionGroup("Root"))
-        {
-            config.setActionGroup("Root");
-            mSaverExec = config.readEntry("Exec");
-        }
-
-//        kdDebug(1204) << "Saver-exec: " << mSaverExec << endl;
-    }
-}
-
-//---------------------------------------------------------------------------
-//
-// Create a window to draw our screen saver on.
-//
-void SaverEngine::createSaverWindow()
-{
-    // We only create the window once, but we reset its attributes every
-    // time.
-
-    // Some xscreensaver hacks check for this property
-    const char *version = "KDE 2.0";
-    XChangeProperty (qt_xdisplay(), winId(),
-                     gXA_SCREENSAVER_VERSION, XA_STRING, 8, PropModeReplace,
-                     (unsigned char *) version, strlen(version));
-
-    XSetWindowAttributes attr;
-    if (mColorMap != None)
-    {
-        attr.colormap = mColorMap;
-    }
-    else
-    {
-        attr.colormap = DefaultColormapOfScreen(
-                                ScreenOfDisplay(qt_xdisplay(), qt_xscreen()));
-    }
-    attr.event_mask = KeyPressMask | ButtonPressMask | MotionNotify |
-                        VisibilityChangeMask | ExposureMask;
-    XChangeWindowAttributes(qt_xdisplay(), winId(),
-                            CWEventMask | CWColormap, &attr);
-
-    // erase();
-
-    // set NoBackground so that the saver can capture the current
-    // screen state if necessary
-    setBackgroundMode( QWidget::NoBackground );
-
-    setCursor( blankCursor );
-    setGeometry(0, 0, mRootWidth, mRootHeight);
-    hide();
-
-    kdDebug(1204) << "Saver window Id: " << winId() << endl;
-}
-
-//---------------------------------------------------------------------------
-//
-// Hide the screensaver window
-//
-void SaverEngine::hideSaverWindow()
-{
-  hide();
-  lower();
-  removeVRoot(winId());
-  XDeleteProperty(qt_xdisplay(), winId(), gXA_SCREENSAVER_VERSION);
-  if ( gVRoot ) {
-      unsigned long vroot_data[1] = { gVRootData };
-      XChangeProperty(qt_xdisplay(), gVRoot, gXA_VROOT, XA_WINDOW, 32,
-                      PropModeReplace, (unsigned char *)vroot_data, 1);
-      gVRoot = 0;
-  }
-  XSync(qt_xdisplay(), False);
-}
-
-//---------------------------------------------------------------------------
-//
-// Save the current virtual root window
+// Start the screen saver.
 //
-void SaverEngine::saveVRoot()
+void SaverEngine::startLockProcess( LockType lock_type )
 {
-  Window rootReturn, parentReturn, *children;
-  unsigned int numChildren;
-  Window root = RootWindowOfScreen(ScreenOfDisplay(qt_xdisplay(), qt_xscreen()));
-
-  gVRoot = 0;
-  gVRootData = 0;
-
-  int (*oldHandler)(Display *, XErrorEvent *);
-  oldHandler = XSetErrorHandler(ignoreXError);
-
-  if (XQueryTree(qt_xdisplay(), root, &rootReturn, &parentReturn,
-      &children, &numChildren))
-  {
-    for (unsigned int i = 0; i < numChildren; i++)
-    {
-      Atom actual_type;
-      int actual_format;
-      unsigned long nitems, bytesafter;
-      Window *newRoot = (Window *)0;
-
-      if ((XGetWindowProperty(qt_xdisplay(), children[i], gXA_VROOT, 0, 1,
-          False, XA_WINDOW, &actual_type, &actual_format, &nitems, &bytesafter,
-          (unsigned char **) &newRoot) == Success) && newRoot)
-      {
-        gVRoot = children[i];
-        gVRootData = *newRoot;
-        break;
-      }
-    }
-    if (children)
+    if (mState != Waiting)
     {
-      XFree((char *)children);
-    }
-  }
-
-  XSetErrorHandler(oldHandler);
-}
-
-//---------------------------------------------------------------------------
-//
-// Set the virtual root property
-//
-void SaverEngine::setVRoot(Window win, Window vr)
-{
-    assert( KWin::info(winId()).mappingState != NET::Withdrawn );
-
-    if (gVRoot)
-        removeVRoot(gVRoot);
-
-    unsigned long rw = RootWindowOfScreen(ScreenOfDisplay(qt_xdisplay(), qt_xscreen()));
-    unsigned long vroot_data[1] = { vr };
-
-    Window rootReturn, parentReturn, *children;
-    unsigned int numChildren;
-    Window top = win;
-    while (1) {
-        int ret = XQueryTree(qt_xdisplay(), top , &rootReturn, &parentReturn,
-                                 &children, &numChildren);
-        if (children)
-            XFree((char *)children);
-        if (parentReturn == rw) {
-            break;
-        } else
-            top = parentReturn;
+        kdWarning(1204) << "SaverEngine::startSaver() saver already active" << endl;
+        return;
     }
 
-    XChangeProperty(qt_xdisplay(), top, gXA_VROOT, XA_WINDOW, 32,
-                     PropModeReplace, (unsigned char *)vroot_data, 1);
-}
-
-//---------------------------------------------------------------------------
-//
-// Remove the virtual root property
-//
-void SaverEngine::removeVRoot(Window win)
-{
-    XDeleteProperty (qt_xdisplay(), win, gXA_VROOT);
-}
-
-//---------------------------------------------------------------------------
-//
-// Grab the keyboard. Returns true on success
-//
-bool SaverEngine::grabKeyboard()
-{
-    int rv = XGrabKeyboard( qt_xdisplay(), QApplication::desktop()->winId(),
-        True, GrabModeAsync, GrabModeAsync, CurrentTime );
-
-    return (rv == GrabSuccess);
-}
-
-//---------------------------------------------------------------------------
-//
-// Grab the mouse.  Returns true on success
-//
-bool SaverEngine::grabMouse()
-{
-    int rv = XGrabPointer( qt_xdisplay(), QApplication::desktop()->winId(),
-            True, ButtonPressMask
-            | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask
-            | PointerMotionMask | PointerMotionHintMask | Button1MotionMask
-            | Button2MotionMask | Button3MotionMask | Button4MotionMask
-            | Button5MotionMask | ButtonMotionMask | KeymapStateMask,
-            GrabModeAsync, GrabModeAsync, None, blankCursor.handle(),
-            CurrentTime );
-
-    return (rv == GrabSuccess);
-}
-
-//---------------------------------------------------------------------------
-//
-// Grab keyboard and mouse.  Returns true on success.
-//
-bool SaverEngine::grabInput()
-{
-    XSync(qt_xdisplay(), False);
+    kdDebug(1204) << "SaverEngine: starting saver" << endl;
 
-    if (!grabKeyboard())
+    if (mLockProcess.isRunning())
     {
-        sleep(1);
-        if (!grabKeyboard())
-        {
-            return false;
-        }
+        stopLockProcess();
     }
-
-    if (!grabMouse())
+    mLockProcess.clearArguments();
+    QString path = KStandardDirs::findExe( "kdesktop_lock" );
+    if( path.isEmpty())
     {
-        sleep(1);
-        if (!grabMouse())
-        {
-            XUngrabKeyboard(qt_xdisplay(), CurrentTime);
-            return false;
-        }
-    }
-
-    return true;
-}
-
-//---------------------------------------------------------------------------
-//
-// Release mouse an keyboard grab.
-//
-void SaverEngine::ungrabInput()
-{
-    XUngrabKeyboard(qt_xdisplay(), CurrentTime);
-    XUngrabPointer(qt_xdisplay(), CurrentTime);
-}
-
-//---------------------------------------------------------------------------
-//
-// Send KDM (or XDM, if it gets adapted) a command if we lock the screen
-//
-void SaverEngine::xdmFifoCmd(const char *cmd)
-{
-    if (!mXdmFifoName.isNull() && (mLock || mLockOnce)) {
-	QFile fifo(mXdmFifoName);
-	if (fifo.open(IO_WriteOnly | IO_Raw)) {
-            fifo.writeBlock( cmd, ::strlen(cmd) );
-            fifo.close();
-	}
+	kdDebug( 1204 ) << "Can't find kdesktop_lock!" << endl;
+	return;
     }
-}
-
-//---------------------------------------------------------------------------
-//
-// Start the screen saver.
-//
-void SaverEngine::startSaver()
-{
-    if (mState != Waiting)
+    mLockProcess << path;
+    switch( lock_type )
     {
-        kdWarning(1204) << "SaverEngine::startSaver() saver already active" << endl;
-        return;
+	case ForceLock:
+    	    mLockProcess << QString( "--forcelock" );
+	  break;
+	case DontLock:
+	    mLockProcess << QString( "--dontlock" );
+	  break;
+	default:
+	  break;
     }
-
-    kdDebug(1204) << "SaverEngine: starting saver" << endl;
-
-    if (!grabInput())
+    if (mLockProcess.start() == false )
     {
-        kdWarning(1204) << "SaverEngine::startSaver() grabInput() failed!!!!" << endl;
-        return;
+	kdDebug( 1204 ) << "Failed to start kdesktop_lock!" << endl;
+	return;
     }
+    
     mState = Saving;
     if (mXAutoLock)
     {
         mXAutoLock->stop();
     }
-    saveVRoot();
-
-    createSaverWindow();
-    move(0, 0);
-    show();
-    setCursor( blankCursor );
-
-    raise();
-    XSync(qt_xdisplay(), False);
-    xdmFifoCmd("lock\n");
-    slotStart();
-}
-
-void SaverEngine::slotStart()
-{
-    if (KWin::info(winId()).mappingState == NET::Withdrawn) {
-        QTimer::singleShot(100, this, SLOT(slotStart()));
-        return;
-    }
-    setVRoot( winId(), winId() );
-    if (startHack() == false)
-    {
-        // failed to start a hack.  Just show a blank screen
-        setBackgroundColor(black);
-    }
 }
 
 //---------------------------------------------------------------------------
 //
 // Stop the screen saver.
 //
-void SaverEngine::stopSaver()
+void SaverEngine::stopLockProcess()
 {
     if (mState == Waiting)
     {
         kdWarning(1204) << "SaverEngine::stopSaver() saver not active" << endl;
         return;
     }
-    kdDebug(1204) << "SaverEngine: stopping saver" << endl;
-    stopHack();
-    xdmFifoCmd("unlock\n");
-    hideSaverWindow();
-    hidePassDlg();
+    kdDebug(1204) << "SaverEngine: stopping lock" << endl;
+
+    mLockProcess.kill();
+    
     if (mXAutoLock)
     {
         mXAutoLock->start();
     }
     mState = Waiting;
-    ungrabInput();
-    mLockOnce = false;
-}
-
-//---------------------------------------------------------------------------
-//
-bool SaverEngine::startHack()
-{
-    if (mSaverExec.isEmpty())
-    {
-        return false;
-    }
-
-    if (mHackProc.isRunning())
-    {
-        stopHack();
-    }
-
-    mHackProc.clearArguments();
-
-    QTextStream ts(&mSaverExec, IO_ReadOnly);
-    QString word;
-    ts >> word;
-    QString path = KStandardDirs::findExe(word);
-
-    if (!path.isEmpty())
-    {
-        mHackProc << path;
-
-        kdDebug(1204) << "Starting hack: " << path << endl;
-
-        while (!ts.atEnd())
-        {
-            ts >> word;
-            if (word == "%w")
-            {
-                word = word.setNum(winId());
-            }
-            mHackProc << word;
-        }
-
-        if (mHackProc.start() == true)
-        {
-#ifdef HAVE_SETPRIORITY
-            setpriority(PRIO_PROCESS, mHackProc.getPid(), mPriority);
-#endif
-            return true;
-        }
-    }
-
-    return false;
-}
-
-//---------------------------------------------------------------------------
-//
-void SaverEngine::stopHack()
-{
-    if (mHackProc.isRunning())
-    {
-        mHackProc.kill();
-    }
-}
-
-//---------------------------------------------------------------------------
-//
-void SaverEngine::hackExited( KProcess * )
-{
-    if ( mState != Waiting ) {
-	// Hack exited while we're supposed to be saving the screen.
-	// Make sure the saver window is black.
-        setBackgroundColor(black);
-    }
-}
-
-//---------------------------------------------------------------------------
-//
-// Show the password dialog
-//
-void SaverEngine::showPassDlg()
-{
-    if (mPassDlg)
-    {
-        hidePassDlg();
-    }
-    mPassDlg = new PasswordDlg(this);
-    QDesktopWidget *desktop = KApplication::desktop();
-
-    QRect rect = mPassDlg->geometry();
-    rect.moveCenter( desktop->screenGeometry(desktop->screenNumber(QCursor::pos())).center());
-    mPassDlg->move(rect.topLeft() );
-
-    mPassDlg->show();
-    setPassDlgTimeout(PASSDLG_HIDE_TIMEOUT);
-}
-
-//---------------------------------------------------------------------------
-//
-// Hide the password dialog
-//
-void SaverEngine::hidePassDlg()
-{
-    if (mPassDlg)
-    {
-        delete mPassDlg;
-        mPassDlg = 0;
-        killPassDlgTimeout();
-    }
-}
-
-//---------------------------------------------------------------------------
-//
-// Hide the password dialog in "t" seconds.
-//
-void SaverEngine::setPassDlgTimeout(int t)
-{
-    if (mHidePassTimerId)
-    {
-        killTimer(mHidePassTimerId);
-    }
-    mHidePassTimerId = startTimer(t);
 }
 
-//---------------------------------------------------------------------------
-//
-// Kill the password dialog hide timer.
-//
-void SaverEngine::killPassDlgTimeout()
+void SaverEngine::lockProcessExited()
 {
-    if (mHidePassTimerId)
+    kdDebug(1204) << "SaverEngine: lock exited" << endl;
+    if( mState == Waiting )
+	return;
+    if (mXAutoLock)
     {
-        killTimer(mHidePassTimerId);
-        mHidePassTimerId = 0;
+        mXAutoLock->start();
     }
+    mState = Waiting;
 }
 
 //---------------------------------------------------------------------------
@@ -717,7 +256,7 @@ void SaverEngine::killPassDlgTimeout()
 //
 void SaverEngine::idleTimeout()
 {
-    startSaver();
+    startLockProcess( DefaultLock );
 }
 
 //---------------------------------------------------------------------------
@@ -731,230 +270,27 @@ bool SaverEngine::x11Event(XEvent *event
         return false;
     }
 
-    bool ret = false;
     switch (event->type)
     {
         case KeyPress:
-            ret = handleKeyPress((XKeyEvent *)event);
+	    {
+	    if (!event->xkey.send_event && mXAutoLock && mState == Waiting)
+    		mXAutoLock->keyPressed();
 	    break;
-
-        case ButtonPress:
-        case MotionNotify:
-            if (mState == Saving)
-            {
-                if (mLock || mLockOnce)
-                {
-                    showPassDlg();
-                    mState = Password;
-                }
-                else
-                {
-                    stopSaver();
-                }
-            }
-            break;
+	    }
 
         case CreateNotify:
-            if (event->xcreatewindow.window == winId() ||
-                (mPassDlg && event->xcreatewindow.window == mPassDlg->winId()))
-            {
-                break;
-            }
+//            if (event->xcreatewindow.window == winId() ||
+//                (mPassDlg && event->xcreatewindow.window == mPassDlg->winId()))
+//            {
+//                break;
+//            }
             if (mXAutoLock)
             {
                 mXAutoLock->windowCreated(event->xcreatewindow.window);
             }
             break;
 
-        case VisibilityNotify:
-            if (event->xvisibility.state != VisibilityUnobscured &&
-                event->xvisibility.window == winId() &&
-                (mState == Saving || mState == Password))
-            {
-                raise();
-                QApplication::flushX();
-            }
-            break;
-
-        case ConfigureNotify:
-            // Workaround for bug in Qt 2.1, as advised by Matthias Ettrich (David)
-            if (event->xconfigure.window != event->xconfigure.event)
-                return true;
-
-            if (mState == Saving || mState == Password)
-            {
-                raise();
-                QApplication::flushX();
-            }
-            break;
-    }
-
-    return ret;
-}
-
-//---------------------------------------------------------------------------
-//
-// Handle key press event.
-//
-bool SaverEngine::handleKeyPress(XKeyEvent *xke)
-{
-    bool ret = false;
-
-    switch (mState)
-    {
-        case Waiting:
-            if (!xke->send_event && mXAutoLock)
-            {
-                mXAutoLock->keyPressed();
-            }
-	    break;
-
-        case Password:
-            if (!mCheckingPass)
-            {
-                KeySym keysym = XLookupKeysym(xke, 0);
-                switch (keysym)
-                {
-                    case XK_Escape:
-                        hidePassDlg();
-                        mState = Saving;
-                        break;
-
-                    case XK_Return:
-                    case XK_KP_Enter:
-                        startCheckPassword();
-                        break;
-
-                    default:
-                        setPassDlgTimeout(PASSDLG_HIDE_TIMEOUT);
-                        mPassDlg->keyPressed(xke);
-                }
-            }
-	    ret = true;
-	    break;
-
-        case Saving:
-            if (mLock || mLockOnce)
-            {
-                showPassDlg();
-                mState = Password;
-            }
-            else
-            {
-                stopSaver();
-            }
-	    return true;
-    }
-
-    return ret;
-}
-
-//---------------------------------------------------------------------------
-//
-// Starts the kcheckpass process to check the user's password.
-//
-// Serge Droz <serge.droz@pso.ch> 10.2000
-// Define ACCEPT_ENV if you want to pass an environment variable to
-// kcheckpass. Define ACCEPT_ARGS if you want to pass command line
-// arguments to kcheckpass
-#define ACCEPT_ENV
-//#define ACCEPT_ARGS
-void SaverEngine::startCheckPassword()
-{
-    const char *passwd = mPassDlg->password().ascii();
-    if (passwd)
-    {
-        QString kcp_binName = KStandardDirs::findExe("kcheckpass");
-
-        mPassProc.clearArguments();
-        mPassProc << kcp_binName;
-
-#ifdef HAVE_PAM
-# ifdef ACCEPT_ENV
-        setenv("KDE_PAM_ACTION", KSCREENSAVER_PAM_SERVICE, 1);
-# elif defined(ACCEPT_ARGS)
-        mPassProc << "-c" << KSCREENSAVER_PAM_SERVICE;
-# endif
-#endif
-	bool ret = mPassProc.start(KProcess::NotifyOnExit, KProcess::Stdin);
-#ifdef HAVE_PAM
-# ifdef ACCEPT_ENV
-        unsetenv("KDE_PAM_ACTION");
-# endif
-#endif
-	if (ret == false)
-        {
-            kdDebug(1204) << "kcheckpass failed to start" << endl;
-            return;
-        }
-
-        // write Password to stdin
-        mPassProc.writeStdin(passwd, strlen(passwd));
-        mPassProc.closeStdin();
-
-        killPassDlgTimeout();
-
-        mCheckingPass = true;
-    }
-}
-
-//---------------------------------------------------------------------------
-//
-// The kcheckpass process has exited.
-//
-void SaverEngine::passwordChecked(KProcess *proc)
-{
-    if (proc == &mPassProc)
-    {
-	    /* the exit codes of kcheckpass:
-	       0: everything fine
-		   1: authentification failed
-		   2: passwd access failed [permissions/misconfig]
-	    */
-        if (mPassProc.normalExit() && (mPassProc.exitStatus() != 1))
-        {
-            stopSaver();
-	    if ( mPassProc.exitStatus() == 2 )
-	    {
-		KMessageBox::error(0,
-		  i18n( "<h1>Screen Locking Failed!</h1>"
-		  "Your screen was not locked because the <i>kcheckpass</i> "
-		  "program was not able to check your password. This is "
-		  "usually the result of kcheckpass not being installed "
-		  "correctly. If you installed KDE yourself, reinstall "
-		  "kcheckpass as root. If you are using a pre-compiled "
-		  "package, contact the packager." ),
-		  i18n( "Screen Locking Failed" ) );
-	    }
-        }
-        else
-        {
-            mPassDlg->showFailed();
-            mPassDlg->resetPassword();
-            setPassDlgTimeout(PASSDLG_HIDE_TIMEOUT);
-        }
-
-        mCheckingPass = false;
-    }
-}
-
-//---------------------------------------------------------------------------
-//
-// Handle our timer events.
-//
-void SaverEngine::timerEvent(QTimerEvent *ev)
-{
-    if (ev->timerId() == mHidePassTimerId && !mCheckingPass)
-    {
-        hidePassDlg();
-        mState = Saving;
     }
+    return false;
 }
-
-//---------------------------------------------------------------------------
-int ignoreXError(Display *, XErrorEvent *)
-{
-    return 0;
-}
-
-#undef None
diff -u3 -p -d -N kdesktop.sav/lockeng.h kdesktop/lockeng.h
--- kdesktop.sav/lockeng.h	Sat Mar  2 15:49:14 2002
+++ kdesktop/lockeng.h	Sat Mar  2 15:50:33 2002
@@ -11,7 +11,6 @@
 #include <qwidget.h>
 #include <kprocess.h>
 #include "KScreensaverIface.h"
-#include "lockdlg.h"
 #include "xautolock.h"
 
 //===========================================================================
@@ -63,61 +62,27 @@ public:
      */
     virtual void configure();
 
-    enum State { Waiting, Saving, Password };
 
 protected:
     virtual bool x11Event(XEvent *);
-    virtual void timerEvent(QTimerEvent *);
 
 protected slots:
     void idleTimeout();
-    void passwordChecked(KProcess *);
-    void hackExited(KProcess *);
-    void slotStart();
+    void lockProcessExited();
 
 protected:
-    void readSaver(QString saver);
-    void createSaverWindow();
-    void hideSaverWindow();
-    void saveVRoot();
-    void setVRoot(Window win, Window rw);
-    void removeVRoot(Window win);
-    bool grabKeyboard();
-    bool grabMouse();
-    bool grabInput();
-    void ungrabInput();
-    void xdmFifoCmd(const char *cmd);
-    void startSaver();
-    void stopSaver();
-    bool startHack();
-    void stopHack();
-    void showPassDlg();
-    void hidePassDlg();
-    void setPassDlgTimeout(int t);
-    void killPassDlgTimeout();
-    void startCheckPassword();
+    enum LockType { DontLock, DefaultLock, ForceLock };
+    void startLockProcess( LockType lock_type );
+    void stopLockProcess();
     bool handleKeyPress(XKeyEvent *xke);
 
 protected:
+    enum State { Waiting, Saving };
     bool        mEnabled;
-    bool        mLock;
-    int         mPriority;
-    bool        mLockOnce;
     State       mState;
-    PasswordDlg *mPassDlg;
-    Colormap    mColorMap;
     XAutoLock   *mXAutoLock;
-    int         mHidePassTimerId;
-    int         mCheckPassTimerId;
-    KProcess    mPassProc;
-    KProcess    mHackProc;
-    bool        mCheckingPass;
-    int         mRootWidth;
-    int         mRootHeight;
-    QString     mSaverExec;
-    QString	mSaver;
+    KProcess    mLockProcess;
     int		mTimeout;
-    QString	mXdmFifoName;
 
     // the original X screensaver parameters
     int         mXTimeout;
Common subdirectories: kdesktop.sav/patterns and kdesktop/patterns
Common subdirectories: kdesktop.sav/pics and kdesktop/pics
Common subdirectories: kdesktop.sav/programs and kdesktop/programs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic