]> Dogcows Code - chaz/openbox/blobdiff - render/render.c
pass the Client for frame_context cuz the client might be NULL
[chaz/openbox] / render / render.c
index 71bf7fa3323369e25a4558de34f11feca4b2ee35..e4cc97e7fcc79c123572382463e5dfd1ca9eb5bb 100644 (file)
@@ -7,7 +7,11 @@
 #include "mask.h"
 #include "color.h"
 #include "image.h"
-#include "../kernel/openbox.h"
+#include "kernel/openbox.h"
+
+#ifdef HAVE_STDLIB_H
+#  include <stdlib.h>
+#endif
 
 int render_depth;
 Visual *render_visual;
@@ -355,33 +359,80 @@ Appearance *appearance_copy(Appearance *orig)
 
 void appearance_free(Appearance *a)
 {
-    PlanarSurface *p;
-    if (a->pixmap != None) XFreePixmap(ob_display, a->pixmap);
-    if (a->xftdraw != NULL) XftDrawDestroy(a->xftdraw);
-    if (a->textures)
-        g_free(a->texture);
-    if (a->surface.type == Surface_Planar) {
-        p = &a->surface.data.planar;
-        if (p->primary != NULL) color_free(p->primary);
-        if (p->secondary != NULL) color_free(p->secondary);
-        if (p->border_color != NULL) color_free(p->border_color);
-        if (p->pixel_data != NULL) g_free(p->pixel_data);
+    if (a) {
+        PlanarSurface *p;
+        if (a->pixmap != None) XFreePixmap(ob_display, a->pixmap);
+        if (a->xftdraw != NULL) XftDrawDestroy(a->xftdraw);
+        if (a->textures)
+            g_free(a->texture);
+        if (a->surface.type == Surface_Planar) {
+            p = &a->surface.data.planar;
+            if (p->primary != NULL) color_free(p->primary);
+            if (p->secondary != NULL) color_free(p->secondary);
+            if (p->border_color != NULL) color_free(p->border_color);
+            if (p->pixel_data != NULL) g_free(p->pixel_data);
+        }
+        g_free(a);
     }
-    g_free(a);
 }
 
 
 void pixel32_to_pixmap(pixel32 *in, Pixmap out, int x, int y, int w, int h)
 {
+    unsigned char *scratch;
     XImage *im = NULL;
     im = XCreateImage(ob_display, render_visual, render_depth,
                       ZPixmap, 0, NULL, w, h, 32, 0);
     g_assert(im != NULL);
     im->byte_order = endian;
-    im->data = (char *)in;
-    reduce_depth((pixel32*)im->data, im);
+/* this malloc is a complete waste of time on normal 32bpp
+   as reduce_depth just sets im->data = data and returns
+*/
+    scratch = malloc(im->width * im->height * sizeof(pixel32));
+    im->data = (char*) scratch;
+    reduce_depth(in, im);
     XPutImage(ob_display, out, DefaultGC(ob_display, ob_screen),
               im, 0, 0, x, y, w, h);
     im->data = NULL;
     XDestroyImage(im);
+    free(scratch);
+}
+
+void appearance_minsize(Appearance *l, Size *s)
+{
+    int i;
+    SIZE_SET(*s, 0, 0);
+
+    switch (l->surface.type) {
+    case Surface_Planar:
+        if (l->surface.data.planar.border ||
+            l->surface.data.planar.bevel == Bevel1)
+            SIZE_SET(*s, 2, 2);
+        else if (l->surface.data.planar.bevel == Bevel2)
+            SIZE_SET(*s, 4, 4);
+
+        for (i = 0; i < l->textures; ++i)
+            switch (l->texture[i].type) {
+            case Bitmask:
+                s->width += l->texture[i].data.mask.mask->w;
+                s->height += l->texture[i].data.mask.mask->h;
+                break;
+            case Text:
+                s->width +=font_measure_string(l->texture[i].data.text.font,
+                                               l->texture[i].data.text.string,
+                                               l->texture[i].data.text.shadow,
+                                               l->texture[i].data.text.offset);
+                s->height +=  font_height(l->texture[i].data.text.font,
+                                          l->texture[i].data.text.shadow,
+                                          l->texture[i].data.text.offset);
+                break;
+            case RGBA:
+                s->width += l->texture[i].data.rgba.width;
+                s->height += l->texture[i].data.rgba.height;
+                break;
+            case NoTexture:
+                break;
+            }            
+        break;
+    }
 }
This page took 0.024415 seconds and 4 git commands to generate.