summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Spilsbury <sam.spilsbury@canonical.com>2011-07-05 00:25:20 +0800
committerSam Spilsbury <sam.spilsbury@canonical.com>2011-07-05 00:25:20 +0800
commita4e27599e8f45fb6b1652360c9a5a072bc222d18 (patch)
treed48a7ff25d5ceac26f61249013091d76a4bec758 /src
parentf0c5e589a2de9e149ef7f3057e958726a70ebdb4 (diff)
downloadmobilebling-a4e27599e8f45fb6b1652360c9a5a072bc222d18.tar.gz
mobilebling-a4e27599e8f45fb6b1652360c9a5a072bc222d18.tar.bz2
Further break the dependency of timers on screen
Diffstat (limited to 'src')
-rw-r--r--src/privateeventsource.h56
-rw-r--r--src/privateiosource.h55
-rw-r--r--src/privatescreen.h83
-rw-r--r--src/privatetimeoutsource.h57
-rw-r--r--src/screen.cpp2
-rw-r--r--src/timeouthandler.cpp3
-rw-r--r--src/timer.cpp22
7 files changed, 190 insertions, 88 deletions
diff --git a/src/privateeventsource.h b/src/privateeventsource.h
new file mode 100644
index 0000000..92eda18
--- /dev/null
+++ b/src/privateeventsource.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright © 2010 Canonical Ltd.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Canonical Ltd. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Canonical Ltd. makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
+ */
+
+#ifndef _COMPIZ_PRIVATEEVENTSOURCE_H
+#define _COMPIZ_PRIVATEEVENTSOURCE_H
+
+class CompEventSource:
+ public Glib::Source
+{
+ public:
+
+ static
+ Glib::RefPtr <CompEventSource> create ();
+
+ sigc::connection connect (const sigc::slot <bool> &slot);
+
+ protected:
+
+ bool prepare (int &timeout);
+ bool check ();
+ bool dispatch (sigc::slot_base *slot);
+ bool callback ();
+
+ explicit CompEventSource ();
+ virtual ~CompEventSource ();
+
+ private:
+
+ Display *mDpy;
+ Glib::PollFD mPollFD;
+ int mConnectionFD;
+};
+
+#endif
diff --git a/src/privateiosource.h b/src/privateiosource.h
new file mode 100644
index 0000000..90d51c6
--- /dev/null
+++ b/src/privateiosource.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright © 2010 Canonical Ltd.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Canonical Ltd. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Canonical Ltd. makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
+ */
+
+#ifndef _COMPIZ_PRIVATEIOSOURCE_H
+#define _COMPIZ_PRIVATEIOSOURCE_H
+
+class CompWatchFd :
+ public Glib::IOSource
+{
+ public:
+
+ static
+ Glib::RefPtr <CompWatchFd> create (int,
+ Glib::IOCondition,
+ FdWatchCallBack);
+
+ protected:
+
+ explicit CompWatchFd (int, Glib::IOCondition, FdWatchCallBack);
+ bool internalCallback (Glib::IOCondition);
+
+ private:
+
+ int mFd;
+ FdWatchCallBack mCallBack;
+ CompWatchFdHandle mHandle;
+ bool mForceFail;
+ bool mExecuting;
+
+ friend class CompScreen;
+};
+
+#endif
diff --git a/src/privatescreen.h b/src/privatescreen.h
index 66a68b7..2f5dfc4 100644
--- a/src/privatescreen.h
+++ b/src/privatescreen.h
@@ -38,6 +38,10 @@
#include <glibmm/main.h>
+#include "privatetimeoutsource.h"
+#include "privateiosource.h"
+#include "privateeventsource.h"
+
#include "core_options.h"
CompPlugin::VTable * getCoreVTable ();
@@ -47,58 +51,6 @@ class CoreWindow;
extern bool shutDown;
extern bool restartSignal;
-class CompWatchFd :
- public Glib::IOSource
-{
- public:
-
- static
- Glib::RefPtr <CompWatchFd> create (int,
- Glib::IOCondition,
- FdWatchCallBack);
-
- protected:
-
- explicit CompWatchFd (int, Glib::IOCondition, FdWatchCallBack);
- bool internalCallback (Glib::IOCondition);
-
- private:
-
- int mFd;
- FdWatchCallBack mCallBack;
- CompWatchFdHandle mHandle;
- bool mForceFail;
- bool mExecuting;
-
- friend class CompScreen;
-};
-
-class CompTimeoutSource :
- public Glib::Source
-{
- public:
-
- static Glib::RefPtr <CompTimeoutSource> create ();
- sigc::connection connect (const sigc::slot <bool> &slot);
-
- protected:
-
- bool prepare (int &timeout);
- bool check ();
- bool dispatch (sigc::slot_base *slot);
- bool callback ();
-
- explicit CompTimeoutSource ();
- virtual ~CompTimeoutSource ();
-
- private:
-
- gint64 mLastTime;
-
- friend class CompTimer;
- friend class PrivateScreen;
-};
-
extern CompWindow *lastFoundWindow;
extern bool useDesktopHints;
@@ -148,33 +100,6 @@ struct CompStartupSequence {
unsigned int viewportY;
};
-class CompEventSource:
- public Glib::Source
-{
- public:
-
- static
- Glib::RefPtr <CompEventSource> create ();
-
- sigc::connection connect (const sigc::slot <bool> &slot);
-
- protected:
-
- bool prepare (int &timeout);
- bool check ();
- bool dispatch (sigc::slot_base *slot);
- bool callback ();
-
- explicit CompEventSource ();
- virtual ~CompEventSource ();
-
- private:
-
- Display *mDpy;
- Glib::PollFD mPollFD;
- int mConnectionFD;
-};
-
class PrivateScreen : public CoreOptions {
public:
diff --git a/src/privatetimeoutsource.h b/src/privatetimeoutsource.h
new file mode 100644
index 0000000..93ae052
--- /dev/null
+++ b/src/privatetimeoutsource.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright © 2010 Canonical Ltd.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Canonical Ltd. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Canonical Ltd. makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
+ */
+
+#include <core/timer.h>
+#include <core/timeouthandler.h>
+
+#ifndef _COMPIZ_PRIVATETIMEOUTSOURCE_H
+#define _COMPIZ_PRIVATETIMEOUTSOURCE_H
+
+class CompTimeoutSource :
+ public Glib::Source
+{
+ public:
+
+ static Glib::RefPtr <CompTimeoutSource> create (Glib::RefPtr <Glib::MainContext> &ctx);
+ sigc::connection connect (const sigc::slot <bool> &slot);
+
+ protected:
+
+ bool prepare (int &timeout);
+ bool check ();
+ bool dispatch (sigc::slot_base *slot);
+ bool callback ();
+
+ explicit CompTimeoutSource (Glib::RefPtr <Glib::MainContext> &ctx);
+ virtual ~CompTimeoutSource ();
+
+ private:
+
+ gint64 mLastTime;
+
+ friend class CompTimer;
+};
+
+#endif
diff --git a/src/screen.cpp b/src/screen.cpp
index 791ec4a..2050b0e 100644
--- a/src/screen.cpp
+++ b/src/screen.cpp
@@ -118,7 +118,7 @@ CompScreen::eventLoop ()
priv->ctx = Glib::MainContext::get_default ();
priv->mainloop = Glib::MainLoop::create (priv->ctx, false);
priv->source = CompEventSource::create ();
- priv->timeout = CompTimeoutSource::create ();
+ priv->timeout = CompTimeoutSource::create (priv->ctx);
priv->source->attach (priv->ctx);
diff --git a/src/timeouthandler.cpp b/src/timeouthandler.cpp
index 449f113..2f26442 100644
--- a/src/timeouthandler.cpp
+++ b/src/timeouthandler.cpp
@@ -57,8 +57,7 @@ TimeoutHandler::addTimer (CompTimer *timer)
break;
}
- timer->mMinLeft = timer->mMinTime;
- timer->mMaxLeft = timer->mMaxTime;
+ timer->setExpiryTimes (timer->mMinTime, timer->mMaxTime);
priv->mTimers.insert (it, timer);
}
diff --git a/src/timer.cpp b/src/timer.cpp
index 0970114..a4b7a46 100644
--- a/src/timer.cpp
+++ b/src/timer.cpp
@@ -25,15 +25,17 @@
*/
#include <core/timer.h>
-#include <core/screen.h>
-#include "privatescreen.h"
+#include <boost/foreach.hpp>
#include <cmath>
+#include "privatetimeoutsource.h"
-CompTimeoutSource::CompTimeoutSource () :
+#define foreach BOOST_FOREACH
+
+CompTimeoutSource::CompTimeoutSource (Glib::RefPtr <Glib::MainContext> &ctx) :
Glib::Source ()
{
set_priority (G_PRIORITY_HIGH);
- attach (screen->priv->ctx);
+ attach (ctx);
mLastTime = get_time ();
@@ -51,9 +53,9 @@ CompTimeoutSource::connect (const sigc::slot <bool> &slot)
}
Glib::RefPtr <CompTimeoutSource>
-CompTimeoutSource::create ()
+CompTimeoutSource::create (Glib::RefPtr <Glib::MainContext> &ctx)
{
- return Glib::RefPtr <CompTimeoutSource> (new CompTimeoutSource ());
+ return Glib::RefPtr <CompTimeoutSource> (new CompTimeoutSource (ctx));
}
#define COMPIZ_TIMEOUT_WAIT 15
@@ -124,6 +126,7 @@ CompTimeoutSource::check ()
{
fixedTimeDiff = 0;
}
+
foreach (CompTimer *t, TimeoutHandler::Default ()->timers ())
{
t->mMinLeft -= fixedTimeDiff;
@@ -190,6 +193,13 @@ CompTimer::setTimes (unsigned int min, unsigned int max)
}
void
+CompTimer::setExpiryTimes (unsigned int min, unsigned int max)
+{
+ mMinLeft = min;
+ mMaxLeft = (min <= max) ? max : min;
+}
+
+void
CompTimer::setCallback (CompTimer::CallBack callback)
{
bool wasActive = mActive;