summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2008-10-14 08:13:21 +0200
committerDanny Baumann <dannybaumann@web.de>2008-10-14 08:13:21 +0200
commit436908e5988381b9c92c03fe2806731acf7ecd35 (patch)
treefb5d320861f9ae66193045183b9de630c51956e4 /src
parent5cd7dce9863ec6349f37f68f67726083cd798e9a (diff)
downloadunity-window-decorator-436908e5988381b9c92c03fe2806731acf7ecd35.tar.gz
unity-window-decorator-436908e5988381b9c92c03fe2806731acf7ecd35.tar.bz2
Better use of classes in icon and image handling.
Diffstat (limited to 'src')
-rw-r--r--src/icon.cpp15
-rw-r--r--src/screen.cpp104
-rw-r--r--src/window.cpp11
3 files changed, 55 insertions, 75 deletions
diff --git a/src/icon.cpp b/src/icon.cpp
index 46cd537..aa17e35 100644
--- a/src/icon.cpp
+++ b/src/icon.cpp
@@ -29,8 +29,7 @@
CompIcon::CompIcon (CompScreen *screen, unsigned int width,
unsigned int height) :
- mWidth (width),
- mHeight (height),
+ mSize (width, height),
mData (new unsigned char[width * height * 4])
{
}
@@ -40,16 +39,10 @@ CompIcon::~CompIcon ()
delete mData;
}
-unsigned int
-CompIcon::width () const
+const CompSize &
+CompIcon::size () const
{
- return mWidth;
-}
-
-unsigned int
-CompIcon::height () const
-{
- return mHeight;
+ return mSize;
}
unsigned char*
diff --git a/src/screen.cpp b/src/screen.cpp
index 8d74862..7e8c3b8 100644
--- a/src/screen.cpp
+++ b/src/screen.cpp
@@ -1298,52 +1298,46 @@ PrivateScreen::handleSelectionClear (XEvent *event)
#define HOME_IMAGEDIR ".compiz/images"
bool
-CompScreen::readImageFromFile (const char *name,
- int *width,
- int *height,
- void **data)
+CompScreen::readImageFromFile (CompString &name,
+ CompSize &size,
+ void *&data)
{
- Bool status;
+ bool status;
int stride;
- status = fileToImage (NULL, name, width, height, &stride, data);
+ status = fileToImage (name, size, stride, data);
if (!status)
{
- char *home;
-
- home = getenv ("HOME");
+ char *home = getenv ("HOME");
+ CompString path;
if (home)
{
- char *path;
-
- path = (char *) malloc (strlen (home) + strlen (HOME_IMAGEDIR) + 2);
- if (path)
- {
- sprintf (path, "%s/%s", home, HOME_IMAGEDIR);
- status = fileToImage (path, name, width, height, &stride, data);
+ path = home;
+ path += "/";
+ path += HOME_IMAGEDIR;
+ path += name;
- free (path);
+ status = fileToImage (path, size, stride, data);
- if (status)
- return TRUE;
- }
+ if (status)
+ return true;
}
- status = fileToImage (IMAGEDIR, name, width, height, &stride, data);
+ path = IMAGEDIR + name;
+ status = fileToImage (path, size, stride, data);
}
return status;
}
bool
-CompScreen::writeImageToFile (const char *path,
- const char *name,
+CompScreen::writeImageToFile (CompString &path,
const char *format,
- int width,
- int height,
+ CompSize &size,
void *data)
{
- return imageToFile (path, name, format, width, height, width * 4, data);
+ CompString formatString (format);
+ return imageToFile (path, formatString, size, size.width () * 4, data);
}
Window
@@ -1372,29 +1366,24 @@ PrivateScreen::getActiveWindow (Window root)
bool
-CompScreen::fileToImage (const char *path,
- const char *name,
- int *width,
- int *height,
- int *stride,
- void **data)
-{
- WRAPABLE_HND_FUNC_RETURN(8, bool, fileToImage, path, name, width, height,
- stride, data)
+CompScreen::fileToImage (CompString &name,
+ CompSize &size,
+ int &stride,
+ void *&data)
+{
+ WRAPABLE_HND_FUNC_RETURN(8, bool, fileToImage, name, size, stride, data);
return false;
}
bool
-CompScreen::imageToFile (const char *path,
- const char *name,
- const char *format,
- int width,
- int height,
+CompScreen::imageToFile (CompString &path,
+ CompString &format,
+ CompSize &size,
int stride,
void *data)
{
- WRAPABLE_HND_FUNC_RETURN(9, bool, imageToFile, path, name, format, width,
- height, stride, data)
+ WRAPABLE_HND_FUNC_RETURN(9, bool, imageToFile, path, format, size,
+ stride, data)
return false;
}
@@ -1856,23 +1845,19 @@ ScreenInterface::handleCompizEvent (const char *plugin,
WRAPABLE_DEF (handleCompizEvent, plugin, event, options)
bool
-ScreenInterface::fileToImage (const char *path,
- const char *name,
- int *width,
- int *height,
- int *stride,
- void **data)
- WRAPABLE_DEF (fileToImage, path, name, width, height, stride, data)
+ScreenInterface::fileToImage (CompString &name,
+ CompSize &size,
+ int &stride,
+ void *&data)
+ WRAPABLE_DEF (fileToImage, name, size, stride, data)
bool
-ScreenInterface::imageToFile (const char *path,
- const char *name,
- const char *format,
- int width,
- int height,
+ScreenInterface::imageToFile (CompString &path,
+ CompString &format,
+ CompSize &size,
int stride,
void *data)
- WRAPABLE_DEF (imageToFile, path, name, format, width, height, stride, data)
+ WRAPABLE_DEF (imageToFile, path, format, size, stride, data)
CompMatch::Expression *
ScreenInterface::matchInitExp (const CompString value)
@@ -4045,7 +4030,7 @@ PrivateScreen::updateDefaultIcon ()
{
CompString file = priv->opt[COMP_OPTION_DEFAULT_ICON].value ().s ();
void *data;
- int width, height;
+ CompSize size;
if (priv->defaultIcon)
{
@@ -4053,12 +4038,13 @@ PrivateScreen::updateDefaultIcon ()
priv->defaultIcon = NULL;
}
- if (!screen->readImageFromFile (file.c_str (), &width, &height, &data))
+ if (!screen->readImageFromFile (file, size, data))
return false;
- priv->defaultIcon = new CompIcon (screen, width, height);
+ priv->defaultIcon = new CompIcon (screen, size.width (), size.height ());
- memcpy (priv->defaultIcon->data (), data, width * height * sizeof (CARD32));
+ memcpy (priv->defaultIcon->data (), data,
+ size.width () * size.height () * sizeof (CARD32));
free (data);
diff --git a/src/window.cpp b/src/window.cpp
index 3297d38..2437a6e 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -3714,15 +3714,16 @@ CompWindow::getIcon (int width, int height)
for (i = 0; i < priv->icons.size (); i++)
{
- if ((int) priv->icons[i]->width () > width ||
- (int) priv->icons[i]->height () > height)
+ const CompSize &iconSize = priv->icons[i]->size ();
+
+ if ((int) iconSize.width () > width ||
+ (int) iconSize.height () > height)
continue;
if (icon)
{
- diff = wh - (priv->icons[i]->width () +
- priv->icons[i]->height ());
- oldDiff = wh - (icon->width () + icon->height ());
+ diff = wh - (iconSize.width () + iconSize.height ());
+ oldDiff = wh - (icon->size ().width () + icon->size ().height ());
if (diff < oldDiff)
icon = priv->icons[i];