summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Spilsbury <sam.spilsbury@canonical.com>2011-07-04 15:35:02 +0800
committerSam Spilsbury <sam.spilsbury@canonical.com>2011-07-04 15:35:02 +0800
commitf0c5e589a2de9e149ef7f3057e958726a70ebdb4 (patch)
treebf5635afade379ee84ff81b970d3c993ed197e94 /src
parent1913edd4068503653004b35c32a8097bfc19faa1 (diff)
downloadmobilebling-f0c5e589a2de9e149ef7f3057e958726a70ebdb4.tar.gz
mobilebling-f0c5e589a2de9e149ef7f3057e958726a70ebdb4.tar.bz2
Break CompTimer's dependency on CompScreen
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/privatescreen.h8
-rw-r--r--src/privatetimeouthandler.h36
-rw-r--r--src/screen.cpp39
-rw-r--r--src/timeouthandler.cpp95
-rw-r--r--src/timer.cpp34
6 files changed, 154 insertions, 59 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5c2385f..2d3ee63 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -52,6 +52,7 @@ add_executable (compiz
modifierhandler.cpp
propertywriter.cpp
eventsource.cpp
+ timeouthandler.cpp
${_bcop_sources}
)
diff --git a/src/privatescreen.h b/src/privatescreen.h
index 3f5e177..66a68b7 100644
--- a/src/privatescreen.h
+++ b/src/privatescreen.h
@@ -213,11 +213,6 @@ class PrivateScreen : public CoreOptions {
void updatePassiveGrabs ();
- void handleTimers (struct timeval *tv);
-
- void addTimer (CompTimer *timer);
- void removeTimer (CompTimer *timer);
-
void updatePlugins ();
bool triggerButtonPressBindings (CompOption::Vector &options,
@@ -386,9 +381,6 @@ class PrivateScreen : public CoreOptions {
CompFileWatchList fileWatch;
CompFileWatchHandle lastFileWatchHandle;
- std::list <CompTimer *> timers;
- struct timeval lastTimeout;
-
std::list<Glib::RefPtr <CompWatchFd> > watchFds;
CompWatchFdHandle lastWatchFdHandle;
diff --git a/src/privatetimeouthandler.h b/src/privatetimeouthandler.h
new file mode 100644
index 0000000..a802a77
--- /dev/null
+++ b/src/privatetimeouthandler.h
@@ -0,0 +1,36 @@
+/*
+ * 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_PRIVATETIMEOUTHANDLER_H
+#define _COMPIZ_PRIVATETIMEOUTHANDLER_H
+
+#include <core/timeouthandler.h>
+
+class PrivateTimeoutHandler
+{
+ public:
+ std::list <CompTimer *> mTimers;
+};
+#endif
diff --git a/src/screen.cpp b/src/screen.cpp
index 9005411..791ec4a 100644
--- a/src/screen.cpp
+++ b/src/screen.cpp
@@ -179,41 +179,6 @@ CompScreen::getFileWatches () const
return priv->fileWatch;
}
-void
-PrivateScreen::addTimer (CompTimer *timer)
-{
- std::list<CompTimer *>::iterator it;
-
- it = std::find (timers.begin (), timers.end (), timer);
-
- if (it != timers.end ())
- return;
-
- for (it = timers.begin (); it != timers.end (); it++)
- {
- if ((int) timer->mMinTime < (*it)->mMinLeft)
- break;
- }
-
- timer->mMinLeft = timer->mMinTime;
- timer->mMaxLeft = timer->mMaxTime;
-
- timers.insert (it, timer);
-}
-
-void
-PrivateScreen::removeTimer (CompTimer *timer)
-{
- std::list<CompTimer *>::iterator it;
-
- it = std::find (timers.begin (), timers.end (), timer);
-
- if (it == timers.end ())
- return;
-
- timers.erase (it);
-}
-
CompWatchFd::CompWatchFd (int fd,
Glib::IOCondition events,
FdWatchCallBack callback) :
@@ -4773,7 +4738,7 @@ PrivateScreen::PrivateScreen (CompScreen *screen) :
xdndWindow (None),
initialized (false)
{
- gettimeofday (&lastTimeout, 0);
+ TimeoutHandler *dTimeoutHandler = new TimeoutHandler ();
pingTimer.setCallback (
boost::bind (&PrivateScreen::handlePingTimeout, this));
@@ -4814,6 +4779,8 @@ PrivateScreen::PrivateScreen (CompScreen *screen) :
CompScreen::toggleWinMaximizedVertically);
optionSetToggleWindowShadedKeyInitiate (CompScreen::shadeWin);
+
+ TimeoutHandler::SetDefault (dTimeoutHandler);
}
PrivateScreen::~PrivateScreen ()
diff --git a/src/timeouthandler.cpp b/src/timeouthandler.cpp
new file mode 100644
index 0000000..449f113
--- /dev/null
+++ b/src/timeouthandler.cpp
@@ -0,0 +1,95 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ * 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 "privatetimeouthandler.h"
+
+namespace
+{
+ static TimeoutHandler *gDefault;
+}
+
+TimeoutHandler::TimeoutHandler () :
+ priv (new PrivateTimeoutHandler ())
+{
+}
+
+TimeoutHandler::~TimeoutHandler ()
+{
+ delete priv;
+}
+
+void
+TimeoutHandler::addTimer (CompTimer *timer)
+{
+ std::list<CompTimer *>::iterator it;
+
+ it = std::find (priv->mTimers.begin (), priv->mTimers.end (), timer);
+
+ if (it != priv->mTimers.end ())
+ return;
+
+ for (it = priv->mTimers.begin (); it != priv->mTimers.end (); it++)
+ {
+ if ((int) timer->minTime () < (*it)->minLeft ())
+ break;
+ }
+
+ timer->mMinLeft = timer->mMinTime;
+ timer->mMaxLeft = timer->mMaxTime;
+
+ priv->mTimers.insert (it, timer);
+}
+
+void
+TimeoutHandler::removeTimer (CompTimer *timer)
+{
+ std::list<CompTimer *>::iterator it;
+
+ it = std::find (priv->mTimers.begin (), priv->mTimers.end (), timer);
+
+ if (it == priv->mTimers.end ())
+ return;
+
+ priv->mTimers.erase (it);
+}
+
+std::list <CompTimer *> &
+TimeoutHandler::timers ()
+{
+ return priv->mTimers;
+}
+
+TimeoutHandler *
+TimeoutHandler::Default ()
+{
+ return gDefault;
+}
+
+void
+TimeoutHandler::SetDefault (TimeoutHandler *instance)
+{
+ gDefault = instance;
+}
diff --git a/src/timer.cpp b/src/timer.cpp
index ef05a63..0970114 100644
--- a/src/timer.cpp
+++ b/src/timer.cpp
@@ -63,7 +63,7 @@ CompTimeoutSource::prepare (int &timeout)
{
/* Determine time to wait */
- if (screen->priv->timers.empty ())
+ if (TimeoutHandler::Default ()->timers ().empty ())
{
/* This kind of sucks, but we have to do it, considering
* that glib provides us no safe way to remove the source -
@@ -73,16 +73,17 @@ CompTimeoutSource::prepare (int &timeout)
*/
timeout = COMPIZ_TIMEOUT_WAIT;
+
return true;
}
- if (screen->priv->timers.front ()->mMinLeft > 0)
+ if (TimeoutHandler::Default ()->timers ().front ()->mMinLeft > 0)
{
- std::list<CompTimer *>::iterator it = screen->priv->timers.begin ();
+ std::list<CompTimer *>::iterator it = TimeoutHandler::Default ()->timers ().begin ();
CompTimer *t = (*it);
timeout = t->mMaxLeft;
- while (it != screen->priv->timers.end ())
+ while (it != TimeoutHandler::Default ()->timers ().end ())
{
t = (*it);
if (t->mMinLeft >= timeout)
@@ -123,13 +124,13 @@ CompTimeoutSource::check ()
{
fixedTimeDiff = 0;
}
- foreach (CompTimer *t, screen->priv->timers)
+ foreach (CompTimer *t, TimeoutHandler::Default ()->timers ())
{
t->mMinLeft -= fixedTimeDiff;
t->mMaxLeft -= fixedTimeDiff;
}
- return screen->priv->timers.front ()->mMinLeft <= 0;
+ return TimeoutHandler::Default ()->timers ().front ()->mMinLeft <= 0;
}
bool
@@ -143,21 +144,21 @@ CompTimeoutSource::dispatch (sigc::slot_base *slot)
bool
CompTimeoutSource::callback ()
{
- while (screen->priv->timers.begin () != screen->priv->timers.end () &&
- screen->priv->timers.front ()->mMinLeft <= 0)
+ while (TimeoutHandler::Default ()->timers ().begin () != TimeoutHandler::Default ()->timers ().end () &&
+ TimeoutHandler::Default ()->timers ().front ()->mMinLeft <= 0)
{
- CompTimer *t = screen->priv->timers.front ();
- screen->priv->timers.pop_front ();
+ CompTimer *t = TimeoutHandler::Default ()->timers ().front ();
+ TimeoutHandler::Default ()->timers ().pop_front ();
t->mActive = false;
if (t->mCallBack ())
{
- screen->priv->addTimer (t);
+ TimeoutHandler::Default ()->addTimer (t);
t->mActive = true;
}
}
- return !screen->priv->timers.empty ();
+ return !TimeoutHandler::Default ()->timers ().empty ();
}
CompTimer::CompTimer () :
@@ -172,7 +173,7 @@ CompTimer::CompTimer () :
CompTimer::~CompTimer ()
{
- screen->priv->removeTimer (this);
+ TimeoutHandler::Default ()->removeTimer (this);
}
void
@@ -209,13 +210,16 @@ CompTimer::start ()
if (mCallBack.empty ())
{
+#warning compLogMessage needs to be testable
+#if 0
compLogMessage ("core", CompLogLevelWarn,
"Attempted to start timer without callback.");
+#endif
return;
}
mActive = true;
- screen->priv->addTimer (this);
+ TimeoutHandler::Default ()->addTimer (this);
}
void
@@ -238,7 +242,7 @@ void
CompTimer::stop ()
{
mActive = false;
- screen->priv->removeTimer (this);
+ TimeoutHandler::Default ()->removeTimer (this);
}
unsigned int