summaryrefslogtreecommitdiff
path: root/src/staticswitcher.cpp
diff options
context:
space:
mode:
authorErkin Bahceci <erkinbah@gmail.com>2009-12-15 21:03:23 -0600
committerErkin Bahceci <erkinbah@gmail.com>2009-12-16 06:19:18 -0600
commit4b9a182b3b8830c69b7c693f0fccf172e6aca358 (patch)
treed978abad3935b195b71a10552a1283fd8c035b71 /src/staticswitcher.cpp
parentf43f9ad65c8f14060c8621a36b674a261434055d (diff)
downloadstaticswitcher-4b9a182b3b8830c69b7c693f0fccf172e6aca358.tar.gz
staticswitcher-4b9a182b3b8830c69b7c693f0fccf172e6aca358.tar.bz2
Various minor optimizations.
Diffstat (limited to 'src/staticswitcher.cpp')
-rw-r--r--src/staticswitcher.cpp86
1 files changed, 43 insertions, 43 deletions
diff --git a/src/staticswitcher.cpp b/src/staticswitcher.cpp
index 12ccb46..a09ed2c 100644
--- a/src/staticswitcher.cpp
+++ b/src/staticswitcher.cpp
@@ -28,11 +28,12 @@
COMPIZ_PLUGIN_20090315 (staticswitcher, StaticSwitchPluginVTable)
void
-StaticSwitchScreen::updatePopupWindow (int count)
+StaticSwitchScreen::updatePopupWindow ()
{
int newXCount, newYCount;
int winWidth, winHeight;
float aspect;
+ int count = windows.size ();
double dCount = count;
int w = PREVIEWSIZE, h = PREVIEWSIZE, b = BORDER;
int x, y;
@@ -102,7 +103,7 @@ StaticSwitchScreen::updatePopupWindow (int count)
}
void
-StaticSwitchScreen::updateWindowList (int count)
+StaticSwitchScreen::updateWindowList ()
{
pos = 0;
move = 0;
@@ -110,19 +111,20 @@ StaticSwitchScreen::updateWindowList (int count)
selectedWindow = windows.front ();
if (popupWindow)
- updatePopupWindow (count);
+ updatePopupWindow ();
}
void
-StaticSwitchScreen::createWindowList (int count)
+StaticSwitchScreen::createWindowList ()
{
windows.clear ();
foreach (CompWindow *w, ::screen->windows ())
{
- if (StaticSwitchWindow::get (w)->isSwitchWin ())
+ SWITCH_WINDOW (w);
+
+ if (sw->isSwitchWin ())
{
- SWITCH_WINDOW (w);
windows.push_back (w);
sw->cWindow->damageRectSetEnabled (sw, true);
@@ -131,7 +133,7 @@ StaticSwitchScreen::createWindowList (int count)
windows.sort (BaseSwitchScreen::compareWindows);
- updateWindowList (count);
+ updateWindowList ();
}
bool
@@ -216,18 +218,6 @@ StaticSwitchScreen::handleSelectionChange (bool toNext, int nextIdx)
moreAdjust = true;
}
-int
-StaticSwitchScreen::countWindows ()
-{
- int count = 0;
-
- foreach (CompWindow *w, ::screen->windows ())
- if (StaticSwitchWindow::get (w)->isSwitchWin ())
- count++;
-
- return count;
-}
-
bool
StaticSwitchScreen::showPopup ()
{
@@ -257,7 +247,7 @@ void
StaticSwitchScreen::initiate (SwitchWindowSelection selection,
bool shouldShowPopup)
{
- int count;
+ bool noSwitchWindows;
bool newMouseSelect;
if (::screen->otherGrabExist ("switcher", "scale", "cube", 0))
@@ -266,8 +256,16 @@ StaticSwitchScreen::initiate (SwitchWindowSelection selection,
this->selection = selection;
selectedWindow = NULL;
- count = countWindows ();
- if (count < 1)
+ noSwitchWindows = true;
+ foreach (CompWindow *w, ::screen->windows ())
+ {
+ if (StaticSwitchWindow::get (w)->isSwitchWin ())
+ {
+ noSwitchWindows = false;
+ break;
+ }
+ }
+ if (noSwitchWindows)
return;
if (!popupWindow && shouldShowPopup)
@@ -341,7 +339,7 @@ StaticSwitchScreen::initiate (SwitchWindowSelection selection,
{
lastActiveNum = ::screen->activeNum ();
- createWindowList (count);
+ createWindowList ();
if (popupWindow && shouldShowPopup)
{
@@ -515,7 +513,6 @@ StaticSwitchScreen::windowRemove (CompWindow *w)
if (w)
{
bool inList = false;
- int count;
CompWindow *selected;
CompWindow *old;
@@ -558,8 +555,6 @@ StaticSwitchScreen::windowRemove (CompWindow *w)
if (!inList)
return;
- count = windows.size ();
-
if (windows.size () == 0)
{
CompOption::Vector o (0);
@@ -573,7 +568,7 @@ StaticSwitchScreen::windowRemove (CompWindow *w)
if (!grabIndex)
return;
- updateWindowList (count);
+ updateWindowList ();
int i = 0;
foreach (CompWindow *w, windows)
@@ -614,19 +609,20 @@ int
StaticSwitchScreen::getRowXOffset (int y)
{
int retval = 0;
+ int count = windows.size ();
- if ((int)windows.size () - (y * (int)xCount) >= (int)xCount)
+ if (count - (y * (int)xCount) >= (int)xCount)
return 0;
switch (optionGetRowAlign ()) {
case RowAlignLeft:
break;
case RowAlignCentered:
- retval = (xCount - (int)windows.size () + (y * (int)xCount)) *
+ retval = (xCount - count + (y * (int)xCount)) *
(previewWidth + previewBorder) / 2;
break;
case RowAlignRight:
- retval = (xCount - (int)windows.size () + (y * (int)xCount)) *
+ retval = (xCount - count + (y * (int)xCount)) *
(previewWidth + previewBorder);
break;
}
@@ -720,12 +716,13 @@ bool
StaticSwitchScreen::adjustVelocity ()
{
float dx, adjust, amount;
+ int count = windows.size ();
dx = move - pos;
- if (abs (dx) > abs (dx + windows.size ()))
- dx += windows.size ();
- if (abs (dx) > abs (dx - windows.size ()))
- dx -= windows.size ();
+ if (abs (dx) > abs (dx + count))
+ dx += count;
+ if (abs (dx) > abs (dx - count))
+ dx -= count;
adjust = dx * 0.15f;
amount = fabs (dx) * 1.5f;
@@ -752,6 +749,7 @@ StaticSwitchScreen::preparePaint (int msSinceLastPaint)
{
int steps;
float amount, chunk;
+ int count = windows.size ();
amount = msSinceLastPaint * 0.05f * optionGetSpeed ();
steps = amount / (0.5f * optionGetTimestep ());
@@ -768,9 +766,9 @@ StaticSwitchScreen::preparePaint (int msSinceLastPaint)
}
pos += mVelocity * chunk;
- pos = fmod (pos, windows.size ());
+ pos = fmod (pos, count);
if (pos < 0.0)
- pos += windows.size ();
+ pos += count;
}
}
@@ -974,6 +972,7 @@ StaticSwitchScreen::paintSelectionRect (int x,
{
float color[4], op;
int w, h;
+ int count = windows.size ();
w = previewWidth + previewBorder;
h = previewHeight + previewBorder;
@@ -982,8 +981,8 @@ StaticSwitchScreen::paintSelectionRect (int x,
if (dx > xCount - 1)
op = 1.0 - MIN (1.0, dx - (xCount - 1));
- else if (dx + (dy * xCount) > windows.size () - 1)
- op = 1.0 - MIN (1.0, dx - (windows.size () - 1 - (dy * xCount)));
+ else if (dx + (dy * xCount) > count - 1)
+ op = 1.0 - MIN (1.0, dx - (count - 1 - (dy * xCount)));
else if (dx < 0.0)
op = 1.0 + MAX (-1.0, dx);
else
@@ -1146,6 +1145,8 @@ StaticSwitchWindow::glPaint (const GLWindowPaintAttrib &attrib,
GLenum filter;
int x, y, offX;
float px, py, pos;
+ int count = sScreen->windows.size ();
+
CompWindow::Geometry &g = window->geometry ();
@@ -1180,15 +1181,15 @@ StaticSwitchWindow::glPaint (const GLWindowPaintAttrib &attrib,
gScreen->setTextureFilter (filter);
- pos = fmod (sScreen->pos, sScreen->windows.size ());
+ pos = fmod (sScreen->pos, count);
px = fmod (pos, sScreen->xCount);
py = floor (pos / sScreen->xCount);
offX = sScreen->getRowXOffset (py);
- if (pos > sScreen->windows.size () - 1)
+ if (pos > count - 1)
{
- px = fmod (pos - sScreen->windows.size (), sScreen->xCount);
+ px = fmod (pos - count, sScreen->xCount);
sScreen->paintSelectionRect (g.x (), g.y (), px, 0.0,
gWindow->lastPaintAttrib ().opacity);
@@ -1202,8 +1203,7 @@ StaticSwitchWindow::glPaint (const GLWindowPaintAttrib &attrib,
sScreen->paintSelectionRect (g.x (), g.y (), px, py,
gWindow->lastPaintAttrib ().opacity);
- py = fmod (py + 1, ceil ((double) sScreen->windows.size () /
- sScreen->xCount));
+ py = fmod (py + 1, ceil ((double) count / sScreen->xCount));
offX = sScreen->getRowXOffset (py);
sScreen->paintSelectionRect (g.x () + offX, g.y (),