summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2007-04-09 11:11:44 +0200
committerDanny Baumann <dannybaumann@web.de>2007-04-09 11:11:44 +0200
commitddc379889e2ce6b6fd45215a22208470ea834897 (patch)
tree3e6af1f66b77ff75b8fb97bcc49aaba0a5b11367
parentedceebe6b0c02faee365a4049acdb9de8f48c6bb (diff)
downloadberyl-premerge-ddc379889e2ce6b6fd45215a22208470ea834897.tar.gz
beryl-premerge-ddc379889e2ce6b6fd45215a22208470ea834897.tar.bz2
Avoid unnecessary memory consumption.
-rw-r--r--src/showdesktop.c123
1 files changed, 70 insertions, 53 deletions
diff --git a/src/showdesktop.c b/src/showdesktop.c
index d1db7d9..a990536 100644
--- a/src/showdesktop.c
+++ b/src/showdesktop.c
@@ -95,7 +95,7 @@ typedef struct _ShowdesktopWindow
int sid;
int distance;
- ShowdesktopPlacer placer;
+ ShowdesktopPlacer *placer;
GLfloat xVelocity, yVelocity;
GLfloat tx, ty;
@@ -161,69 +161,72 @@ static void repositionSDPlacer(CompWindow * w, int oldState)
{
SD_WINDOW(w);
+ if (!sw->placer)
+ return;
+
if (oldState == SD_STATE_OFF)
{
- sw->placer.onScreenX = w->attrib.x;
- sw->placer.onScreenY = w->attrib.y;
- sw->placer.origViewportX = w->screen->x;
- sw->placer.origViewportY = w->screen->y;
+ sw->placer->onScreenX = w->attrib.x;
+ sw->placer->onScreenY = w->attrib.y;
+ sw->placer->origViewportX = w->screen->x;
+ sw->placer->origViewportY = w->screen->y;
}
switch (showdesktopGetDirection(w->screen))
{
case DirectionUp:
- sw->placer.offScreenX = w->attrib.x;
- sw->placer.offScreenY = w->screen->workArea.y - OFF_TOP(w) +
+ sw->placer->offScreenX = w->attrib.x;
+ sw->placer->offScreenY = w->screen->workArea.y - OFF_TOP(w) +
showdesktopGetWindowPartSize(w->screen);
break;
case DirectionDown:
- sw->placer.offScreenX = w->attrib.x;
- sw->placer.offScreenY = w->screen->workArea.y + w->screen->workArea.height +
+ sw->placer->offScreenX = w->attrib.x;
+ sw->placer->offScreenY = w->screen->workArea.y + w->screen->workArea.height +
OFF_BOTTOM(w) - showdesktopGetWindowPartSize(w->screen);
break;
case DirectionLeft:
- sw->placer.offScreenX = w->screen->workArea.x - OFF_LEFT(w) +
+ sw->placer->offScreenX = w->screen->workArea.x - OFF_LEFT(w) +
showdesktopGetWindowPartSize(w->screen);
- sw->placer.offScreenY = w->attrib.y;
+ sw->placer->offScreenY = w->attrib.y;
break;
case DirectionRight:
- sw->placer.offScreenX = w->screen->workArea.x + w->screen->workArea.width +
+ sw->placer->offScreenX = w->screen->workArea.x + w->screen->workArea.width +
OFF_RIGHT(w) - showdesktopGetWindowPartSize(w->screen);
- sw->placer.offScreenY = w->attrib.y;
+ sw->placer->offScreenY = w->attrib.y;
break;
case DirectionUpdown:
- sw->placer.offScreenX = w->attrib.x;
+ sw->placer->offScreenX = w->attrib.x;
if (MOVE_UP(w))
- sw->placer.offScreenY = w->screen->workArea.y - OFF_TOP(w) +
+ sw->placer->offScreenY = w->screen->workArea.y - OFF_TOP(w) +
showdesktopGetWindowPartSize(w->screen);
else
- sw->placer.offScreenY = w->screen->workArea.y +
+ sw->placer->offScreenY = w->screen->workArea.y +
w->screen->workArea.height + OFF_BOTTOM(w) -
showdesktopGetWindowPartSize(w->screen);
break;
case DirectionLeftright:
- sw->placer.offScreenY = w->attrib.y;
+ sw->placer->offScreenY = w->attrib.y;
if (MOVE_LEFT(w))
- sw->placer.offScreenX = w->screen->workArea.x - OFF_LEFT(w) +
+ sw->placer->offScreenX = w->screen->workArea.x - OFF_LEFT(w) +
showdesktopGetWindowPartSize(w->screen);
else
- sw->placer.offScreenX = w->screen->workArea.x +
+ sw->placer->offScreenX = w->screen->workArea.x +
w->screen->workArea.width + OFF_RIGHT(w) -
showdesktopGetWindowPartSize(w->screen);
break;
case DirectionCorners:
if (MOVE_LEFT(w))
- sw->placer.offScreenX = w->screen->workArea.x - OFF_LEFT(w) +
+ sw->placer->offScreenX = w->screen->workArea.x - OFF_LEFT(w) +
showdesktopGetWindowPartSize(w->screen);
else
- sw->placer.offScreenX = w->screen->workArea.x +
+ sw->placer->offScreenX = w->screen->workArea.x +
w->screen->workArea.width + OFF_RIGHT(w) -
showdesktopGetWindowPartSize(w->screen);
if (MOVE_UP(w))
- sw->placer.offScreenY = w->screen->workArea.y - OFF_TOP(w) +
+ sw->placer->offScreenY = w->screen->workArea.y - OFF_TOP(w) +
showdesktopGetWindowPartSize(w->screen);
else
- sw->placer.offScreenY = w->screen->workArea.y +
+ sw->placer->offScreenY = w->screen->workArea.y +
w->screen->workArea.height + OFF_BOTTOM(w) -
showdesktopGetWindowPartSize(w->screen);
break;
@@ -250,21 +253,24 @@ static int prepareSDWindows(CompScreen * s, int oldState)
if (!isSDWin(w))
continue;
+ if (!sw->placer)
+ sw->placer = malloc(sizeof(ShowdesktopPlacer));
+
repositionSDPlacer(w, oldState);
+ sw->placer->placed = TRUE;
sw->adjust = TRUE;
- sw->placer.placed = TRUE;
w->inShowDesktopMode = TRUE;
setSkipPagerHint(w, TRUE);
if (sw->tx)
- sw->tx -= (sw->placer.onScreenX - sw->placer.offScreenX);
+ sw->tx -= (sw->placer->onScreenX - sw->placer->offScreenX);
if (sw->ty)
- sw->ty -= (sw->placer.onScreenY - sw->placer.offScreenY);
+ sw->ty -= (sw->placer->onScreenY - sw->placer->offScreenY);
moveWindow(w,
- sw->placer.offScreenX - w->attrib.x,
- sw->placer.offScreenY - w->attrib.y,
+ sw->placer->offScreenX - w->attrib.x,
+ sw->placer->offScreenY - w->attrib.y,
TRUE, TRUE);
syncWindowPosition(w);
@@ -311,17 +317,17 @@ static int adjustSDVelocity(CompWindow * w)
if (ss->state == SD_STATE_ACTIVATING)
{
- x1 = sw->placer.offScreenX;
- y1 = sw->placer.offScreenY;
- baseX = sw->placer.onScreenX;
- baseY = sw->placer.onScreenY;
+ x1 = sw->placer->offScreenX;
+ y1 = sw->placer->offScreenY;
+ baseX = sw->placer->onScreenX;
+ baseY = sw->placer->onScreenY;
}
else
{
- x1 = sw->placer.onScreenX;
- y1 = sw->placer.onScreenY;
- baseX = sw->placer.offScreenX;
- baseY = sw->placer.offScreenY;
+ x1 = sw->placer->onScreenX;
+ y1 = sw->placer->onScreenY;
+ baseX = sw->placer->offScreenX;
+ baseY = sw->placer->offScreenY;
}
dx = x1 - (baseX + sw->tx);
@@ -449,11 +455,24 @@ static void showdesktopDonePaintScreen(CompScreen * s)
}
else
{
+ Bool inSDMode = FALSE;
+
for (w = s->windows; w; w = w->next)
+ {
if (w->inShowDesktopMode)
- break;
+ inSDMode = TRUE;
+ else
+ {
+ SD_WINDOW(w);
+ if (sw->placer)
+ {
+ free(sw->placer);
+ sw->placer = NULL;
+ }
+ }
+ }
- if (w)
+ if (inSDMode)
ss->state = SD_STATE_ON;
else
ss->state = SD_STATE_OFF;
@@ -488,11 +507,11 @@ static Bool showdesktopPaintWindow(CompWindow *w,
float offsetX, offsetY;
offsetX = (ss->state == SD_STATE_DEACTIVATING) ?
- (sw->placer.offScreenX - sw->placer.onScreenX) :
- (sw->placer.onScreenX - sw->placer.offScreenX);
+ (sw->placer->offScreenX - sw->placer->onScreenX) :
+ (sw->placer->onScreenX - sw->placer->offScreenX);
offsetY = (ss->state == SD_STATE_DEACTIVATING) ?
- (sw->placer.offScreenY - sw->placer.onScreenY) :
- (sw->placer.onScreenY - sw->placer.offScreenY);
+ (sw->placer->offScreenY - sw->placer->onScreenY) :
+ (sw->placer->onScreenY - sw->placer->offScreenY);
wAttrib.opacity = OPAQUE;
@@ -616,24 +635,24 @@ static void showdesktopLeaveShowDesktopMode(CompScreen *s, CompWindow *w)
if (w && (w->id != cw->id))
continue;
- if (sw->placer.placed)
+ if (sw->placer && sw->placer->placed)
{
sw->adjust = TRUE;
- sw->placer.placed = FALSE;
+ sw->placer->placed = FALSE;
/* adjust onscreen position to
handle viewport changes
*/
- sw->tx += (sw->placer.onScreenX - sw->placer.offScreenX);
- sw->ty += (sw->placer.onScreenY - sw->placer.offScreenY);
+ sw->tx += (sw->placer->onScreenX - sw->placer->offScreenX);
+ sw->ty += (sw->placer->onScreenY - sw->placer->offScreenY);
- sw->placer.onScreenX += (sw->placer.origViewportX -
+ sw->placer->onScreenX += (sw->placer->origViewportX -
cw->screen->x) * cw->screen->width;
- sw->placer.onScreenY += (sw->placer.origViewportY -
+ sw->placer->onScreenY += (sw->placer->origViewportY -
cw->screen->y) * cw->screen->height;
- moveWindow(cw, sw->placer.onScreenX - cw->attrib.x,
- sw->placer.onScreenY - cw->attrib.y, TRUE, TRUE);
+ moveWindow(cw, sw->placer->onScreenX - cw->attrib.x,
+ sw->placer->onScreenY - cw->attrib.y, TRUE, TRUE);
syncWindowPosition(cw);
setSkipPagerHint(cw, FALSE);
@@ -751,9 +770,7 @@ static Bool showdesktopInitWindow(CompPlugin * p, CompWindow * w)
sw->adjust = FALSE;
sw->xVelocity = sw->yVelocity = 0.0f;
sw->delta = 1.0f;
- sw->placer.placed = FALSE;
- sw->placer.offScreenX = sw->placer.offScreenY = 0;
- sw->placer.onScreenX = sw->placer.onScreenY = 0;
+ sw->placer = NULL;
w->privates[ss->windowPrivateIndex].ptr = sw;