summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <sam.spilsbury@canonical.com>2011-07-17 01:39:24 +0800
committerSam Spilsbury <sam.spilsbury@canonical.com>2011-07-17 01:39:24 +0800
commit858e8afdf35cc9037ce43a7164755560ce218b89 (patch)
treebeff2847f383d0ee3c03db0ed5f4b3e17787de41
parentf1f91f4e2bc96ddf58161ba13f0e878aa69025b1 (diff)
downloadlocker-858e8afdf35cc9037ce43a7164755560ce218b89.tar.gz
locker-858e8afdf35cc9037ce43a7164755560ce218b89.tar.bz2
Unlock the screen and beautify the code a little
-rw-r--r--src/locker.cpp51
-rw-r--r--src/locker.h28
2 files changed, 70 insertions, 9 deletions
diff --git a/src/locker.cpp b/src/locker.cpp
index 34355ca..a083473 100644
--- a/src/locker.cpp
+++ b/src/locker.cpp
@@ -7,6 +7,7 @@ COMPIZ_PLUGIN_20090315 (locker, LockerPluginVTable);
namespace {
static LockerLockWindow *mWindowDefault = NULL;
static LockerLockBackground *mBackgroundDefault = NULL;
+ static Lockable *mLockableDefault = NULL;
}
LockerLockWindow *
@@ -18,6 +19,9 @@ LockerLockWindow::Default ()
void
LockerLockWindow::SetDefault (LockerLockWindow *l)
{
+ if (mWindowDefault)
+ delete mWindowDefault;
+
mWindowDefault = l;
}
@@ -30,9 +34,28 @@ LockerLockBackground::Default ()
void
LockerLockBackground::SetDefault (LockerLockBackground *b)
{
+ if (mBackgroundDefault)
+ delete mBackgroundDefault;
+
mBackgroundDefault = b;
}
+Lockable *
+Lockable::Default ()
+{
+ return mLockableDefault;
+}
+
+void
+Lockable::SetDefault (Lockable *b)
+{
+ if (mLockableDefault)
+ delete mLockableDefault;
+
+ mLockableDefault = b;
+}
+
+
void
SimpleLockerWindow::hide ()
{
@@ -76,30 +99,35 @@ SimpleLockerWindow::paint (const GLMatrix &transform)
bool
SimpleLockerWindow::handleKeyPress (XKeyEvent *xk)
{
+ Lockable::Default ()->unlock ();
return true;
}
bool
SimpleLockerWindow::handleKeyRelease (XKeyEvent *xk)
{
+ Lockable::Default ()->unlock ();
return true;
}
bool
SimpleLockerWindow::handleButtonPress (XButtonEvent *xb)
{
+ Lockable::Default ()->unlock ();
return true;
}
bool
SimpleLockerWindow::handleButtonRelease (XButtonEvent *xb)
{
+ Lockable::Default ()->unlock ();
return true;
}
bool
SimpleLockerWindow::handleMotion (XMotionEvent *xm)
{
+ Lockable::Default ()->unlock ();
return true;
}
@@ -404,6 +432,8 @@ LockerScreen::unlock ()
mGrabIndex = 0;
}
+ mWaitTimer.setTimes (optionGetTimeout () * 1000, optionGetTimeout () * 1000);
+
return false;
}
@@ -444,22 +474,31 @@ LockerScreen::LockerScreen (CompScreen *s) :
gScreen (GLScreen::get (screen)),
mAnimationProgress (0.0f),
mAnimatedWindows (0),
- mAnimationState (AnimationStateIdle),
- mSLW (new SimpleLockerWindow ()),
- mSLB (new SimpleLockerBackground ())
+ mAnimationState (AnimationStateIdle)
{
+ Lockable::mLockerWindow = new SimpleLockerWindow ();
+ Lockable::mLockerBackground = new SimpleLockerBackground ();
+
ScreenInterface::setHandler (screen);
CompositeScreenInterface::setHandler (cScreen);
GLScreenInterface::setHandler (gScreen);
- LockerLockWindow::SetDefault (mSLW);
- LockerLockBackground::SetDefault (mSLB);
+ LockerLockWindow::SetDefault (mLockerWindow);
+ LockerLockBackground::SetDefault (mLockerBackground);
+ Lockable::SetDefault (this);
mWaitTimer.setCallback (boost::bind (&LockerScreen::lock, this));
- mWaitTimer.setTimes (optionGetTimeout () * 100, optionGetTimeout () * 100);
+ mWaitTimer.setTimes (optionGetTimeout () * 1000, optionGetTimeout () * 1000);
mWaitTimer.start ();
}
+LockerScreen::~LockerScreen ()
+{
+ LockerLockWindow::SetDefault (NULL);
+ LockerLockBackground::SetDefault (NULL);
+ Lockable::SetDefault (NULL);
+}
+
LockerWindow::LockerWindow (CompWindow *w) :
PluginClassHandler <LockerWindow, CompWindow> (w),
window (w),
diff --git a/src/locker.h b/src/locker.h
index 5a1374c..8581c33 100644
--- a/src/locker.h
+++ b/src/locker.h
@@ -98,16 +98,41 @@ private:
CompRegion mDamage;
};
+class Lockable
+{
+public:
+
+ Lockable () {}
+ virtual ~Lockable () {}
+
+ virtual bool lock () = 0;
+ virtual bool unlock () = 0;
+ virtual bool wake () = 0;
+
+ static void
+ SetDefault (Lockable *);
+
+ static Lockable *
+ Default ();
+
+protected:
+
+ LockerLockWindow *mLockerWindow;
+ LockerLockBackground *mLockerBackground;
+};
+
class LockerScreen :
public PluginClassHandler <LockerScreen, CompScreen>,
public ScreenInterface,
public CompositeScreenInterface,
public GLScreenInterface,
+ public Lockable,
public LockerOptions
{
public:
LockerScreen (CompScreen *);
+ ~LockerScreen ();
CompositeScreen *cScreen;
GLScreen *gScreen;
@@ -146,9 +171,6 @@ private:
CompTimer mWaitTimer;
CompScreen::GrabHandle mGrabIndex;
-
- SimpleLockerWindow *mSLW;
- SimpleLockerBackground *mSLB;
};
class LockerWindow :