summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/eventsource.cpp86
-rw-r--r--src/screen.cpp202
-rw-r--r--src/timer.cpp130
4 files changed, 219 insertions, 200 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 17cad68..9b28deb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -49,6 +49,7 @@ add_executable (compiz
icon.cpp
modifierhandler.cpp
propertywriter.cpp
+ eventsource.cpp
${_bcop_sources}
)
diff --git a/src/eventsource.cpp b/src/eventsource.cpp
new file mode 100644
index 0000000..e621cd8
--- /dev/null
+++ b/src/eventsource.cpp
@@ -0,0 +1,86 @@
+/*
+ * Copyright © 2010 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Jason Smith <jason.smith@canonical.com>
+ * : Sam Spilsbury <sam.spilsbury@canonical.com>
+ */
+
+#include "privatescreen.h"
+
+Glib::RefPtr <CompEventSource>
+CompEventSource::create ()
+{
+ return Glib::RefPtr <CompEventSource> (new CompEventSource ());
+}
+
+sigc::connection
+CompEventSource::connect (const sigc::slot <bool> &slot)
+{
+ return connect_generic (slot);
+}
+
+CompEventSource::CompEventSource () :
+ Glib::Source (),
+ mDpy (screen->dpy ()),
+ mConnectionFD (ConnectionNumber (screen->dpy ()))
+{
+ mPollFD.set_fd (mConnectionFD);
+ mPollFD.set_events (Glib::IO_IN);
+
+ set_priority (G_PRIORITY_DEFAULT);
+ add_poll (mPollFD);
+ set_can_recurse (true);
+
+ connect (sigc::mem_fun <bool, CompEventSource> (this, &CompEventSource::callback));
+}
+
+CompEventSource::~CompEventSource ()
+{
+}
+
+bool
+CompEventSource::callback ()
+{
+ if (restartSignal || shutDown)
+ {
+ screen->priv->mainloop->quit ();
+ return false;
+ }
+ else
+ screen->priv->processEvents ();
+ return true;
+}
+
+bool
+CompEventSource::prepare (int &timeout)
+{
+ timeout = -1;
+ return XPending (mDpy);
+}
+
+bool
+CompEventSource::check ()
+{
+ if (mPollFD.get_revents () & Glib::IO_IN)
+ return XPending (mDpy);
+
+ return false;
+}
+
+bool
+CompEventSource::dispatch (sigc::slot_base *slot)
+{
+ return (*static_cast <sigc::slot <bool> *> (slot)) ();
+}
diff --git a/src/screen.cpp b/src/screen.cpp
index fb76b61..09ae503 100644
--- a/src/screen.cpp
+++ b/src/screen.cpp
@@ -110,72 +110,6 @@ CompScreen::freePluginClassIndex (unsigned int index)
screen->pluginClasses.resize (screenPluginClassIndices.size ());
}
-Glib::RefPtr <CompEventSource>
-CompEventSource::create ()
-{
- return Glib::RefPtr <CompEventSource> (new CompEventSource ());
-}
-
-sigc::connection
-CompEventSource::connect (const sigc::slot <bool> &slot)
-{
- return connect_generic (slot);
-}
-
-CompEventSource::CompEventSource () :
- Glib::Source (),
- mDpy (screen->dpy ()),
- mConnectionFD (ConnectionNumber (screen->dpy ()))
-{
- mPollFD.set_fd (mConnectionFD);
- mPollFD.set_events (Glib::IO_IN);
-
- set_priority (G_PRIORITY_DEFAULT);
- add_poll (mPollFD);
- set_can_recurse (true);
-
- connect (sigc::mem_fun <bool, CompEventSource> (this, &CompEventSource::callback));
-}
-
-CompEventSource::~CompEventSource ()
-{
-}
-
-bool
-CompEventSource::callback ()
-{
- if (restartSignal || shutDown)
- {
- screen->priv->mainloop->quit ();
- return false;
- }
- else
- screen->priv->processEvents ();
- return true;
-}
-
-bool
-CompEventSource::prepare (int &timeout)
-{
- timeout = -1;
- return XPending (mDpy);
-}
-
-bool
-CompEventSource::check ()
-{
- if (mPollFD.get_revents () & Glib::IO_IN)
- return XPending (mDpy);
-
- return false;
-}
-
-bool
-CompEventSource::dispatch (sigc::slot_base *slot)
-{
- return (*static_cast <sigc::slot <bool> *> (slot)) ();
-}
-
void
CompScreen::eventLoop ()
{
@@ -191,6 +125,7 @@ CompScreen::eventLoop ()
priv->mainloop->run ();
}
+
CompFileWatchHandle
CompScreen::addFileWatch (const char *path,
int mask,
@@ -242,136 +177,6 @@ CompScreen::getFileWatches () const
return priv->fileWatch;
}
-CompTimeoutSource::CompTimeoutSource () :
- Glib::Source ()
-{
- struct timespec ts;
-
- clock_gettime (CLOCK_MONOTONIC, &ts);
-
- mLastTimeout = ts;
-
- set_priority (G_PRIORITY_HIGH);
- attach (screen->priv->ctx);
- connect (sigc::mem_fun <bool, CompTimeoutSource> (this, &CompTimeoutSource::callback));
-}
-
-CompTimeoutSource::~CompTimeoutSource ()
-{
-}
-
-sigc::connection
-CompTimeoutSource::connect (const sigc::slot <bool> &slot)
-{
- return connect_generic (slot);
-}
-
-Glib::RefPtr <CompTimeoutSource>
-CompTimeoutSource::create ()
-{
- return Glib::RefPtr <CompTimeoutSource> (new CompTimeoutSource ());
-}
-
-#define COMPIZ_TIMEOUT_WAIT 15
-
-bool
-CompTimeoutSource::prepare (int &timeout)
-{
- struct timespec ts;
-
- clock_gettime (CLOCK_MONOTONIC, &ts);
-
- /* Determine time to wait */
-
- if (screen->priv->timers.empty ())
- {
- /* This kind of sucks, but we have to do it, considering
- * that glib provides us no safe way to remove the source -
- * thankfully we shouldn't ever be hitting this case since
- * we create the source after we start pingTimer
- * and that doesn't stop until compiz does
- */
-
- timeout = COMPIZ_TIMEOUT_WAIT;
- return true;
- }
-
- if (screen->priv->timers.front ()->mMinLeft > 0)
- {
- std::list<CompTimer *>::iterator it = screen->priv->timers.begin ();
-
- CompTimer *t = (*it);
- timeout = t->mMaxLeft;
- while (it != screen->priv->timers.end ())
- {
- t = (*it);
- if (t->mMinLeft >= timeout)
- break;
- if (t->mMaxLeft < timeout)
- timeout = t->mMaxLeft;
- it++;
- }
-
- mLastTimeout = ts;
- return false;
- }
- else
- {
- mLastTimeout = ts;
- timeout = 0;
- return true;
- }
-}
-
-bool
-CompTimeoutSource::check ()
-{
- struct timespec ts;
- int timeDiff;
-
- clock_gettime (CLOCK_MONOTONIC, &ts);
- timeDiff = TIMESPECDIFF (&ts, &mLastTimeout);
-
- if (timeDiff < 0)
- timeDiff = 0;
-
- foreach (CompTimer *t, screen->priv->timers)
- {
- t->mMinLeft -= timeDiff;
- t->mMaxLeft -= timeDiff;
- }
-
- return screen->priv->timers.front ()->mMinLeft <= 0;
-}
-
-bool
-CompTimeoutSource::dispatch (sigc::slot_base *slot)
-{
- (*static_cast <sigc::slot <bool> *> (slot)) ();
-
- return true;
-}
-
-bool
-CompTimeoutSource::callback ()
-{
- while (screen->priv->timers.begin () != screen->priv->timers.end () &&
- screen->priv->timers.front ()->mMinLeft <= 0)
- {
- CompTimer *t = screen->priv->timers.front ();
- screen->priv->timers.pop_front ();
-
- t->mActive = false;
- if (t->mCallBack ())
- {
- screen->priv->addTimer (t);
- t->mActive = true;
- }
- }
-
- return !screen->priv->timers.empty ();
-}
-
void
PrivateScreen::addTimer (CompTimer *timer)
{
@@ -565,10 +370,7 @@ CompWatchFd::internalCallback (Glib::IOCondition events)
}
return true;
-}
-
-
-
+}
void
CompScreen::eraseValue (CompString key)
diff --git a/src/timer.cpp b/src/timer.cpp
index 4f7c2a3..d01a8e7 100644
--- a/src/timer.cpp
+++ b/src/timer.cpp
@@ -27,6 +27,136 @@
#include <core/screen.h>
#include "privatescreen.h"
+CompTimeoutSource::CompTimeoutSource () :
+ Glib::Source ()
+{
+ struct timespec ts;
+
+ clock_gettime (CLOCK_MONOTONIC, &ts);
+
+ mLastTimeout = ts;
+
+ set_priority (G_PRIORITY_HIGH);
+ attach (screen->priv->ctx);
+ connect (sigc::mem_fun <bool, CompTimeoutSource> (this, &CompTimeoutSource::callback));
+}
+
+CompTimeoutSource::~CompTimeoutSource ()
+{
+}
+
+sigc::connection
+CompTimeoutSource::connect (const sigc::slot <bool> &slot)
+{
+ return connect_generic (slot);
+}
+
+Glib::RefPtr <CompTimeoutSource>
+CompTimeoutSource::create ()
+{
+ return Glib::RefPtr <CompTimeoutSource> (new CompTimeoutSource ());
+}
+
+#define COMPIZ_TIMEOUT_WAIT 15
+
+bool
+CompTimeoutSource::prepare (int &timeout)
+{
+ struct timespec ts;
+
+ clock_gettime (CLOCK_MONOTONIC, &ts);
+
+ /* Determine time to wait */
+
+ if (screen->priv->timers.empty ())
+ {
+ /* This kind of sucks, but we have to do it, considering
+ * that glib provides us no safe way to remove the source -
+ * thankfully we shouldn't ever be hitting this case since
+ * we create the source after we start pingTimer
+ * and that doesn't stop until compiz does
+ */
+
+ timeout = COMPIZ_TIMEOUT_WAIT;
+ return true;
+ }
+
+ if (screen->priv->timers.front ()->mMinLeft > 0)
+ {
+ std::list<CompTimer *>::iterator it = screen->priv->timers.begin ();
+
+ CompTimer *t = (*it);
+ timeout = t->mMaxLeft;
+ while (it != screen->priv->timers.end ())
+ {
+ t = (*it);
+ if (t->mMinLeft >= timeout)
+ break;
+ if (t->mMaxLeft < timeout)
+ timeout = t->mMaxLeft;
+ it++;
+ }
+
+ mLastTimeout = ts;
+ return false;
+ }
+ else
+ {
+ mLastTimeout = ts;
+ timeout = 0;
+ return true;
+ }
+}
+
+bool
+CompTimeoutSource::check ()
+{
+ struct timespec ts;
+ int timeDiff;
+
+ clock_gettime (CLOCK_MONOTONIC, &ts);
+ timeDiff = TIMESPECDIFF (&ts, &mLastTimeout);
+
+ if (timeDiff < 0)
+ timeDiff = 0;
+
+ foreach (CompTimer *t, screen->priv->timers)
+ {
+ t->mMinLeft -= timeDiff;
+ t->mMaxLeft -= timeDiff;
+ }
+
+ return screen->priv->timers.front ()->mMinLeft <= 0;
+}
+
+bool
+CompTimeoutSource::dispatch (sigc::slot_base *slot)
+{
+ (*static_cast <sigc::slot <bool> *> (slot)) ();
+
+ return true;
+}
+
+bool
+CompTimeoutSource::callback ()
+{
+ while (screen->priv->timers.begin () != screen->priv->timers.end () &&
+ screen->priv->timers.front ()->mMinLeft <= 0)
+ {
+ CompTimer *t = screen->priv->timers.front ();
+ screen->priv->timers.pop_front ();
+
+ t->mActive = false;
+ if (t->mCallBack ())
+ {
+ screen->priv->addTimer (t);
+ t->mActive = true;
+ }
+ }
+
+ return !screen->priv->timers.empty ();
+}
+
CompTimer::CompTimer () :
mActive (false),
mMinTime (0),