From bf0681dbf4f587df9e6ab5871f47d29dd5aab2dc Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <fourdan.olivier@wanadoo.fr>
Date: Tue, 3 Aug 2004 16:39:34 +0000
Subject: [PATCH] Use default theme when no valid theme is found, Don't show
 the title bar buttons when space is missing, Various bug fixes.

(Old svn revision: 11896)
---
 src/frame.c    | 72 ++++++++++++++++++++++++++++----------------------
 src/mypixmap.c |  6 ++++-
 src/parserc.c  | 21 ++++++++++-----
 3 files changed, 61 insertions(+), 38 deletions(-)

diff --git a/src/frame.c b/src/frame.c
index 68faec427..3758c75c1 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -773,8 +773,9 @@ frameDraw (Client * c, gboolean invalidate_cache, gboolean force_shape_update)
             }
         }
 
-        /* Then, show the ones that we do have on right... */
+        /* Then, show the ones that we do have on left... */
         x = frameLeft (c) + screen_info->params->button_offset;
+        right = frameWidth (c) - frameRight (c) - screen_info->params->button_offset;
         for (i = 0; i < strlen (screen_info->params->button_layout); i++)
         {
             button = getButtonFromLetter (screen_info->params->button_layout[i], c);
@@ -784,27 +785,31 @@ frameDraw (Client * c, gboolean invalidate_cache, gboolean force_shape_update)
             }
             else if (button >= 0)
             {
-                my_pixmap =
-                    frameGetPixmap (c, button,
-                    c->button_pressed[button] ? PRESSED : state);
-                if (my_pixmap->pixmap)
+                if (x + screen_info->buttons[button][state].width + screen_info->params->button_spacing < right)
                 {
-                    XSetWindowBackgroundPixmap (clientGetXDisplay (c),
-                        MYWINDOW_XWINDOW (c->buttons[button]),
-                        my_pixmap->pixmap);
+                    my_pixmap = frameGetPixmap (c, button, c->button_pressed[button] ? PRESSED : state);
+                    if (my_pixmap->pixmap)
+                    {
+                        XSetWindowBackgroundPixmap (clientGetXDisplay (c),
+                            MYWINDOW_XWINDOW (c->buttons[button]), my_pixmap->pixmap);
+                    }
+                    xfwmWindowShow (&c->buttons[button], x,
+                        (frameTop (c) - screen_info->buttons[button][state].height) / 2,
+                        screen_info->buttons[button][state].width,
+                        screen_info->buttons[button][state].height, TRUE);
+                    button_x[button] = x;
+                    x = x + screen_info->buttons[button][state].width +
+                        screen_info->params->button_spacing;
+                }
+                else
+                {
+                    xfwmWindowHide (&c->buttons[button]);
                 }
-                xfwmWindowShow (&c->buttons[button], x,
-                    (frameTop (c) - screen_info->buttons[button][state].height) / 2,
-                    screen_info->buttons[button][state].width,
-                    screen_info->buttons[button][state].height, TRUE);
-                button_x[button] = x;
-                x = x + screen_info->buttons[button][state].width +
-                    screen_info->params->button_spacing;
             }
         }
-        left = x - screen_info->params->button_spacing;
+        left = x + screen_info->params->button_spacing;
 
-        /* and those that we do have on left... */
+        /* and those that we do have on right... */
         x = frameWidth (c) - frameRight (c) + screen_info->params->button_spacing -
             screen_info->params->button_offset;
         for (j = strlen (screen_info->params->button_layout) - 1; j >= i; j--)
@@ -816,24 +821,29 @@ frameDraw (Client * c, gboolean invalidate_cache, gboolean force_shape_update)
             }
             else if (button >= 0)
             {
-                my_pixmap =
-                    frameGetPixmap (c, button,
-                    c->button_pressed[button] ? PRESSED : state);
-                if (my_pixmap->pixmap)
+                if (x - screen_info->buttons[button][state].width - screen_info->params->button_spacing > left)
+                {
+                    my_pixmap = frameGetPixmap (c, button, c->button_pressed[button] ? PRESSED : state);
+                    if (my_pixmap->pixmap)
+                    {
+                        XSetWindowBackgroundPixmap (clientGetXDisplay (c),
+                            MYWINDOW_XWINDOW (c->buttons[button]), my_pixmap->pixmap);
+                    }
+                    x = x - screen_info->buttons[button][state].width -
+                        screen_info->params->button_spacing;
+                    xfwmWindowShow (&c->buttons[button], x,
+                        (frameTop (c) - screen_info->buttons[button][state].height) / 2,
+                        screen_info->buttons[button][state].width,
+                        screen_info->buttons[button][state].height, TRUE);
+                    button_x[button] = x;
+                }
+                else
                 {
-                    XSetWindowBackgroundPixmap (clientGetXDisplay (c),
-                        MYWINDOW_XWINDOW (c->buttons[button]),
-                        my_pixmap->pixmap);
+                    xfwmWindowHide (&c->buttons[button]);
                 }
-                x = x - screen_info->buttons[button][state].width -
-                    screen_info->params->button_spacing;
-                xfwmWindowShow (&c->buttons[button], x,
-                    (frameTop (c) - screen_info->buttons[button][state].height) / 2,
-                    screen_info->buttons[button][state].width,
-                    screen_info->buttons[button][state].height, TRUE);
-                button_x[button] = x;
             }
         }
+        left = left - 2 * screen_info->params->button_spacing;
         right = x;
 
         top_width =
diff --git a/src/mypixmap.c b/src/mypixmap.c
index d361ba10f..3ce79d75a 100644
--- a/src/mypixmap.c
+++ b/src/mypixmap.c
@@ -43,6 +43,7 @@ xfwmPixmapCompose (XfwmPixmap * pm, gchar * dir, gchar * file)
     GdkPixmap *destw;
     GdkColormap *cmap;
     GError *error = NULL;
+    gint width, height;
 
     filepng = g_strdup_printf ("%s.%s", file, "png");
     filename = g_build_filename (dir, filepng, NULL);
@@ -107,9 +108,12 @@ xfwmPixmapCompose (XfwmPixmap * pm, gchar * dir, gchar * file)
         cmap = NULL;
     }
 
+    width = MIN (gdk_pixbuf_get_width (alpha), pm->width);
+    height = MIN (gdk_pixbuf_get_height (alpha), pm->height);
+    
     src = gdk_pixbuf_get_from_drawable(NULL, GDK_DRAWABLE (destw), cmap, 
                                         0, 0, 0, 0, pm->width, pm->height);
-    gdk_pixbuf_composite (alpha, src, 0, 0, pm->width, pm->height,
+    gdk_pixbuf_composite (alpha, src, 0, 0, width, height,
                           0, 0, 1.0, 1.0, GDK_INTERP_NEAREST, 255);
     gdk_draw_pixbuf (GDK_DRAWABLE (destw), NULL, src, 0, 0, 0, 0,
                      pm->width, pm->height, GDK_RGB_DITHER_NONE, 0, 0);                 
diff --git a/src/parserc.c b/src/parserc.c
index 798f490ae..7dbaeb6d0 100644
--- a/src/parserc.c
+++ b/src/parserc.c
@@ -167,8 +167,11 @@ getThemeDir (const gchar * theme, const gchar * file)
 {
     if (!theme)
     {
-        return g_build_filename (DATADIR, G_DIR_SEPARATOR_S, "themes",
-            G_DIR_SEPARATOR_S, DEFAULT_THEME, NULL);
+        return g_build_filename (DATADIR, 
+                G_DIR_SEPARATOR_S, "themes",
+                G_DIR_SEPARATOR_S, DEFAULT_THEME, 
+                G_DIR_SEPARATOR_S, "xfwm4", 
+                NULL);
     }
     else if (g_path_is_absolute (theme))
     {
@@ -178,8 +181,11 @@ getThemeDir (const gchar * theme, const gchar * file)
         }
         else
         {
-            return g_build_filename (DATADIR, G_DIR_SEPARATOR_S, "themes",
-                G_DIR_SEPARATOR_S, DEFAULT_THEME, NULL);
+            return g_build_filename (DATADIR, 
+                    G_DIR_SEPARATOR_S, "themes",
+                    G_DIR_SEPARATOR_S, DEFAULT_THEME, 
+                    G_DIR_SEPARATOR_S, "xfwm4", 
+                    NULL);
         }
     }
     else
@@ -270,8 +276,11 @@ getThemeDir (const gchar * theme, const gchar * file)
         g_free (test_dir);
     }
     
-    return g_build_filename (DATADIR, G_DIR_SEPARATOR_S, "themes",
-        G_DIR_SEPARATOR_S, DEFAULT_THEME, NULL);
+    return g_build_filename (DATADIR, 
+            G_DIR_SEPARATOR_S, "themes",
+            G_DIR_SEPARATOR_S, DEFAULT_THEME, 
+            G_DIR_SEPARATOR_S, "xfwm4", 
+            NULL);
 }
 
 void
-- 
GitLab