use the theme. this might need work. heh! but ya.
authorDana Jansens <danakj@orodu.net>
Mon, 11 Jun 2007 03:27:19 +0000 (03:27 +0000)
committerDana Jansens <danakj@orodu.net>
Mon, 11 Jun 2007 03:27:19 +0000 (03:27 +0000)
gui.c
rspanel.c
rspanel.h

diff --git a/gui.c b/gui.c
index 3e13889..f12d0ef 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -17,11 +17,14 @@ static RrAppearance *iconified_text;
 static RrAppearance *shaded_text;
 static RrAppearance *focused_text;
 static RrAppearance *a_icon;
+static RrColor      *normal_text_color;
+static RrColor      *focused_text_color;
 
 /* you can edit these */
 #define MAX_TASK_WIDTH 500
 #define PADDING 2
-#define ICON_SIZE ((tb->h)-(2*PADDING))
+#define ICON_SIZE ((tb->drawh)-(4*PADDING))
+#define ICON_SPACE (ICON_SIZE + PADDING*2)
 
 static void set_icon_geometry(screen *sc, taskbar *tb, task *tk);
 
@@ -52,12 +55,20 @@ void gui_load_theme(screen *sc)
     RrFont *font;
     RrAppearance *with;
     char *name;
-    static int loaded = 0;
 
     printf("loading theme\n");
 
-    if (loaded) return; /* only run this once for now */
-    loaded = 1;
+    RrAppearanceFree(background);
+    RrAppearanceFree(focused_task);
+    RrAppearanceFree(iconified_task);
+    RrAppearanceFree(unfocused_task);
+    RrAppearanceFree(normal_text);
+    RrAppearanceFree(iconified_text);
+    RrAppearanceFree(shaded_text);
+    RrAppearanceFree(focused_text);
+    RrAppearanceFree(a_icon);
+    RrColorFree(normal_text_color);
+    RrColorFree(focused_text_color);
 
     name = xprop_get_utf8(sc, sc->root, _OB_THEME);
     RrThemeFree(sc->theme);
@@ -76,11 +87,7 @@ void gui_load_theme(screen *sc)
     a_icon->texture[0].type = RR_TEXTURE_RGBA;
 
     /* this is the appearance for the background of the panel */
-    background = RrAppearanceNew(sc->rr, 0);
-    USE(background);
-    SURF(grad) = RR_SURFACE_DIAGONAL;
-    SURF(primary) = RrColorNew(sc->rr, 170, 170, 190);
-    SURF(secondary) = RrColorNew(sc->rr, 100, 100, 160);
+    background = RrAppearanceCopy(sc->theme->osd_hilite_bg);
 
     /* this is the appearance for unfocused tasks,
      * text needs to be separate appearances so we can align it correctly */
@@ -88,51 +95,43 @@ void gui_load_theme(screen *sc)
     USE(unfocused_task);
     SURF(parent) = background;
     SURF(grad) = RR_SURFACE_PARENTREL;
-    SURF(relief) = RR_RELIEF_RAISED;
-    SURF(bevel) = RR_BEVEL_2;
 
     /* ... for iconified tasks, also used for shaded ones currently */
     iconified_task = RrAppearanceCopy(unfocused_task);
     USE(iconified_task);
-    SURF(relief) = RR_RELIEF_FLAT;
     SURF(parent) = background; /* RrAppearanceCopy doesn't copy .parent */
 
     /* ... for focused tasks */
-    focused_task = RrAppearanceNew(sc->rr, 0);
+    focused_task = RrAppearanceCopy(sc->theme->a_hover_focused_max);
     USE(focused_task);
-    SURF(grad) = RR_SURFACE_CROSS_DIAGONAL;
-    SURF(secondary) = RrColorNew(sc->rr, 70, 80, 110);
-    SURF(primary) = RrColorNew(sc->rr, 130, 160, 250);
-    SURF(relief) = RR_RELIEF_SUNKEN;
+    SURF(parent) = background;
 
     /* this is the text used for all normal unfocused tasks */
     /* we don't set .parent here, but in draw_task, since we
      * want to combine _task and _text semirandomly.
      * XXX plz not when themes are here */
-    normal_text = RrAppearanceNew(sc->rr, 1);
+    normal_text = RrAppearanceCopy(sc->theme->osd_hilite_label);
+    normal_text_color = RrColorNew(sc->rr,
+                                   RrColorRed(sc->theme->osd_color),
+                                   RrColorGreen(sc->theme->osd_color),
+                                   RrColorBlue(sc->theme->osd_color));
     USE(normal_text);
-    SURF(grad) = RR_SURFACE_PARENTREL;
-    SETTEXT(font, RR_JUSTIFY_LEFT, RR_ELLIPSIZE_END);
+    TEXT(color) = normal_text_color;
+    TEXT(ellipsize) = RR_ELLIPSIZE_END;
 
     /* ... for iconified tasks */
     iconified_text = RrAppearanceCopy(normal_text);
-    /* ... and for focused tasks, we copy this here (ie not 5 lines down)
-     * so the color isn't copied i actually don't know if that would
-     * hurt so XXX on that */
+    shaded_text = RrAppearanceCopy(normal_text);
+
     focused_text = RrAppearanceCopy(normal_text);
+    focused_text_color =
+        RrColorNew(sc->rr,
+                   RrColorRed(sc->theme->titlebut_hover_focused_color),
+                   RrColorGreen(sc->theme->titlebut_hover_focused_color),
+                   RrColorBlue(sc->theme->titlebut_hover_focused_color));
     USE(focused_text);
-    TEXT(color) = RrColorNew(sc->rr, 230, 230, 255);
-
-    USE(normal_text);
-    TEXT(color) = RrColorNew(sc->rr, 20, 20, 40);
-
-    USE(iconified_text);
-    SETSHADOW(2, 2, 100, RrColorNew(sc->rr, 0, 0, 0));
-    TEXT(color) = RrColorNew(sc->rr, 200, 200, 200);
-
-    shaded_text = RrAppearanceCopy(normal_text);
-    USE(shaded_text);
-    TEXT(color) = RrColorNew(sc->rr, 50, 60, 90);
+    TEXT(color) = focused_text_color;
+    TEXT(ellipsize) = RR_ELLIPSIZE_END;
 
     XFree(name);
 }
@@ -145,11 +144,12 @@ void gui_create_taskbar(screen *sc, taskbar *tb)
 
     att.event_mask = ButtonPressMask;
 
-    /* XXX make the height conigurable */
-    tb->x = 0;
-    tb->y = sc->height - 24;
-    tb->w = sc->width;
-    tb->h = 24;
+    /* XXX make this stuff conigurable */
+    tb->w = sc->width * 0.7;
+    tb->h = 28;
+
+    tb->x = (sc->width - tb->w) / 2;
+    tb->y = sc->height - tb->h;
 
     tb->win = XCreateWindow(/* display  */ sc->dd,
                             /* parent   */ sc->root,
@@ -163,6 +163,18 @@ void gui_create_taskbar(screen *sc, taskbar *tb)
                             /* visual   */ CopyFromParent,
                             /*value mask*/ CWEventMask,
                             /* attribs  */ &att);
+    tb->bgwin = XCreateWindow(/* display  */ sc->dd,
+                              /* parent   */ tb->win,
+                              /* x        */ 0,
+                              /* y        */ 0,
+                              /* width    */ tb->w,
+                              /* height   */ tb->h,
+                              /* border   */ 0,
+                              /* depth    */ CopyFromParent,
+                              /* class    */ InputOutput,
+                              /* visual   */ CopyFromParent,
+                              /*value mask*/ 0,
+                              /* attribs  */ 0);
     tb->bg = None;
 
     /* reside on ALL desktops */
@@ -185,6 +197,7 @@ void gui_create_taskbar(screen *sc, taskbar *tb)
     XSetClassHint(sc->dd, tb->win, &xclhints);
 
     XMapWindow(sc->dd, tb->win);
+    XMapWindow(sc->dd, tb->bgwin);
 }
 
 void gui_draw_task(screen *sc, taskbar *tb, task *tk, int redraw)
@@ -192,7 +205,8 @@ void gui_draw_task(screen *sc, taskbar *tb, task *tk, int redraw)
     RrAppearance *a;
     RrAppearance *b;
     const icon *i;
-    int icon_size = 0;
+    int icon_space = 0;
+    char *name;
 
     if (tk->iconified)
         b = iconified_task;
@@ -212,44 +226,56 @@ void gui_draw_task(screen *sc, taskbar *tb, task *tk, int redraw)
     else
         a = normal_text;
 
+    if (tk->iconified)
+        name = g_strconcat("(", tk->name, ")", NULL);
+    else
+        name = g_strdup(tk->name);
+
     i = icon_get_best(tk->icons, tk->nicons, ICON_SIZE, ICON_SIZE);
 
     if (i) {
         RrTextureRGBA *d = &a_icon->texture[0].data.rgba;
         a_icon->surface.parent = b;
+        a_icon->surface.parentx = PADDING;
+        a_icon->surface.parenty = PADDING;
         d->width = i->width;
         d->height = i->height;
-        d->alpha = tk->iconified ? 0x80 : tk->shaded ? 0xB0 : 0xff;
+        d->alpha = tk->iconified ? 0x70 : tk->shaded ? 0xB0 : 0xff;
         d->data = i->data;
-        icon_size = ICON_SIZE + PADDING;
+        icon_space = ICON_SPACE;
     }
 
     a->surface.parent = b;
-    a->surface.parentx = icon_size + PADDING;
-    a->texture[0].data.text.string = tk->name;
+    a->surface.parentx = icon_space;
+    a->texture[0].data.text.string = name;
     b->surface.parentx = tk->pos_x;
 
-    RrPaintPixmap(b, tk->width, tb->h);
-    RrPaintPixmap(a, tk->width-(2*PADDING+icon_size), tb->h);
+    RrPaintPixmap(b, tk->width, tb->drawh);
+    RrPaintPixmap(a, tk->width-icon_space, tb->drawh);
 
     if (i) {
         RrPaintPixmap(a_icon, ICON_SIZE, ICON_SIZE);
         XCopyArea(sc->dd, a_icon->pixmap, b->pixmap, sc->fore_gc, 0, 0,
-                  ICON_SIZE, ICON_SIZE, PADDING, PADDING);
+                  ICON_SIZE, ICON_SIZE,
+                  (icon_space - ICON_SIZE) / 2,
+                  (tb->drawh - ICON_SIZE) / 2);
     }
 
     XCopyArea(sc->dd, a->pixmap, b->pixmap, sc->fore_gc, 0, 0,
-              tk->width-(2*PADDING+icon_size), tb->h, icon_size + PADDING, 0);
+              tk->width-icon_space, tb->drawh,
+              icon_space, 0);
     XCopyArea(sc->dd, b->pixmap, tb->bg, sc->fore_gc, 0, 0,
-              tk->width, tb->h, tk->pos_x, 0);
+              tk->width, tb->drawh, tk->pos_x, 0);
 
     XFreePixmap(sc->dd, a->pixmap);
     XFreePixmap(sc->dd, b->pixmap);
     XFreePixmap(sc->dd, a_icon->pixmap);
     if (redraw) {
-        XSetWindowBackgroundPixmap(sc->dd, tb->win, tb->bg);
-        XClearWindow(sc->dd, tb->win);
+        XSetWindowBackgroundPixmap(sc->dd, tb->bgwin, tb->bg);
+        XClearWindow(sc->dd, tb->bgwin);
     }
+
+    g_free(name);
 }
 
 void gui_draw_taskbar(screen *sc, taskbar *tb)
@@ -264,15 +290,22 @@ void gui_draw_taskbar(screen *sc, taskbar *tb)
     pager_size = TEXTPAD;
 #endif
 
+    tb->draww = tb->w - sc->theme->obwidth * 2;
+    tb->drawh = tb->h - sc->theme->obwidth;
+    XMoveResizeWindow(sc->dd, tb->bgwin, 0,
+                      (tb->at_top ? -sc->theme->obwidth : 0),
+                      tb->draww, tb->drawh);
+
     x = pager_size + 2;
-    width = tb->w - (pager_size + GRILL_WIDTH);
+    width = tb->draww - (pager_size + GRILL_WIDTH);
 #warning only rerender if width changed!
     if (tb->bg) XFreePixmap(sc->dd, tb->bg);
-    tb->bg = XCreatePixmap(sc->dd, sc->root, tb->w, tb->h, RrDepth(sc->rr));
+    tb->bg = XCreatePixmap(sc->dd, sc->root, tb->draww, tb->drawh,
+                           RrDepth(sc->rr));
 
-    XFreePixmap(sc->dd, RrPaintPixmap(background, tb->w, tb->h));
+    XFreePixmap(sc->dd, RrPaintPixmap(background, tb->draww, tb->drawh));
     XCopyArea(sc->dd, background->pixmap, tb->bg, sc->fore_gc, 0, 0,
-              tb->w, tb->h, 0, 0);
+              tb->draww, tb->drawh, 0, 0);
 
     /* find the number of visible tasks */
     for (tk = tb->task_list; tk; tk = tk->next) {
@@ -299,8 +332,11 @@ void gui_draw_taskbar(screen *sc, taskbar *tb)
     }
 
 clear:
-    XSetWindowBackgroundPixmap(sc->dd, tb->win, tb->bg);
-    XClearWindow(sc->dd, tb->win);
+    XSetWindowBackgroundPixmap(sc->dd, tb->bgwin, tb->bg);
+    XClearWindow(sc->dd, tb->bgwin);
+    XSetWindowBorderWidth(sc->dd, tb->bgwin, sc->theme->obwidth);
+    XSetWindowBorder(sc->dd, tb->bgwin,
+                     RrColorPixel(sc->theme->osd_border_color));
 }
 
 void gui_move_taskbar(screen *sc, taskbar *tb)
@@ -314,6 +350,8 @@ void gui_move_taskbar(screen *sc, taskbar *tb)
         tb->y = sc->height - tb->h;
 
     XMoveWindow(sc->dd, tb->win, tb->x, tb->y);
+
+    gui_draw_taskbar(sc, tb);
 }
 
 static void set_icon_geometry(screen *sc, taskbar *tb, task *tk)
index 636d3c1..6cbd19c 100644 (file)
--- a/rspanel.c
+++ b/rspanel.c
@@ -501,8 +501,10 @@ static void handle_propertynotify(Window win, Atom at)
             gui_draw_taskbar(&sc, &tb);
         }
 
-        if (at == sc.atoms[_OB_THEME])
+        if (at == sc.atoms[_OB_THEME]) {
             gui_load_theme(&sc);
+            gui_draw_taskbar(&sc, &tb);
+        }
         return;
     }
 
index 611c1dc..3ebe242 100644 (file)
--- a/rspanel.h
+++ b/rspanel.h
@@ -44,6 +44,7 @@ task;
 typedef struct taskbar
 {
        Window win;
+       Window bgwin;
         /* we draw stuff to this guy then set him as a window
          * background pixmap, yay no flickering! */
         Pixmap bg;
@@ -54,6 +55,8 @@ typedef struct taskbar
        int y;
        int w;
        int h;
+       int draww;
+       int drawh;
        unsigned int hidden:1;
        unsigned int at_top:1;
 }