From aa8edad38222309aee7aaf486d9f0881e37dcdb1 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 5 Jan 2011 01:26:00 +0800 Subject: Move sources around into relevant files --- src/CMakeLists.txt | 1 + src/eventsource.cpp | 86 ++++++++++++++++++++++ src/screen.cpp | 202 +--------------------------------------------------- src/timer.cpp | 130 +++++++++++++++++++++++++++++++++ 4 files changed, 219 insertions(+), 200 deletions(-) create mode 100644 src/eventsource.cpp 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 . + * + * Authored by: Jason Smith + * : Sam Spilsbury + */ + +#include "privatescreen.h" + +Glib::RefPtr +CompEventSource::create () +{ + return Glib::RefPtr (new CompEventSource ()); +} + +sigc::connection +CompEventSource::connect (const sigc::slot &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 (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 *> (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::create () -{ - return Glib::RefPtr (new CompEventSource ()); -} - -sigc::connection -CompEventSource::connect (const sigc::slot &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 (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 *> (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 (this, &CompTimeoutSource::callback)); -} - -CompTimeoutSource::~CompTimeoutSource () -{ -} - -sigc::connection -CompTimeoutSource::connect (const sigc::slot &slot) -{ - return connect_generic (slot); -} - -Glib::RefPtr -CompTimeoutSource::create () -{ - return Glib::RefPtr (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::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 *> (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 #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 (this, &CompTimeoutSource::callback)); +} + +CompTimeoutSource::~CompTimeoutSource () +{ +} + +sigc::connection +CompTimeoutSource::connect (const sigc::slot &slot) +{ + return connect_generic (slot); +} + +Glib::RefPtr +CompTimeoutSource::create () +{ + return Glib::RefPtr (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::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 *> (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), -- cgit v1.1