From a69b5dfc403dfa1e1795c52e7c291b99b1c48866 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 3 Jan 2008 19:21:36 +0100 Subject: [PATCH] add option to show appicons in tasklist --- awesomerc | 1 - awesomerc.1.txt | 3 +++ config.c | 1 + widgets/tasklist.c | 50 ++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/awesomerc b/awesomerc index bef9cbca..493319cc 100644 --- a/awesomerc +++ b/awesomerc @@ -87,7 +87,6 @@ screen 0 arg = "-1" } } - netwmicon mynetwmicon {} tasklist mytasklist { mouse diff --git a/awesomerc.1.txt b/awesomerc.1.txt index 28c165d8..118cc938 100644 --- a/awesomerc.1.txt +++ b/awesomerc.1.txt @@ -158,6 +158,8 @@ This widget shows a list of running windows. Foreground color for focused window. *align*:: Text alignement. +*show_icons*:: + Show applications icons. textbox ~~~~~~~ @@ -291,6 +293,7 @@ screen [MULTI] } tasklist { + show_icons=<{true,false}> focus_fg= focus_bg= fg= diff --git a/config.c b/config.c index c542312c..57e25e9f 100644 --- a/config.c +++ b/config.c @@ -554,6 +554,7 @@ config_parse(const char *confpatharg) CFG_STR((char *) "focus_bg", (char *) NULL, CFGF_NONE), CFG_STR((char *) "font", (char *) NULL, CFGF_NONE), CFG_STR((char *) "align", (char *) "left", CFGF_NONE), + CFG_BOOL((char *) "show_icons", cfg_true, CFGF_NONE), CFG_END() }; static cfg_opt_t widget_progressbar_bar_opts[] = diff --git a/widgets/tasklist.c b/widgets/tasklist.c index 380e1b7e..4cd733bb 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -27,6 +27,8 @@ #include "xutil.h" #include "screen.h" #include "event.h" +#include "ewmh.h" +#include "rules.h" #define ISVISIBLE_ON_TB(c, screen) (client_isvisible(c, screen) && !c->skiptb) @@ -34,6 +36,7 @@ extern AwesomeConf globalconf; typedef struct { + Bool show_icons; int align; XColor fg_sel; XColor bg_sel; @@ -47,7 +50,10 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used) Client *c; Data *d = widget->data; Client *sel = focus_get_current_client(widget->statusbar->screen); - int n = 0, i = 0, box_width = 0; + Rule *r; + Area area; + int n = 0, i = 0, box_width = 0, icon_width = 0; + NetWMIcon *icon; for(c = globalconf.clients; c; c = c->next) if(ISVISIBLE_ON_TB(c, widget->statusbar->screen)) @@ -69,26 +75,53 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used) for(c = globalconf.clients; c; c = c->next) if(ISVISIBLE_ON_TB(c, widget->statusbar->screen)) { + icon_width = 0; + + if(d->show_icons) + { + for(r = globalconf.rules; r; r = r->next) + if(r->icon && client_match_rule(c, r)) + { + area = draw_get_image_size(r->icon); + icon_width = ((double) widget->statusbar->height / (double) area.height) * area.width; + draw_image(ctx, + widget->location + box_width * i, + 0, widget->statusbar->height, + r->icon); + } + + if(!icon_width && (icon = ewmh_get_window_icon(c->win))) + { + icon_width = ((double) widget->statusbar->height / (double) icon->height) + * icon->width; + draw_image_from_argb_data(ctx, + widget->location + box_width * i, 0, + icon->width, icon->height, + widget->statusbar->height, icon->image); + p_delete(&icon); + } + } + if(sel == c) { - draw_text(ctx, widget->location + box_width * i, 0, - box_width, + draw_text(ctx, widget->location + icon_width + box_width * i, 0, + box_width - icon_width, widget->statusbar->height, d->align, widget->font->height / 2, widget->font, c->name, d->fg_sel, d->bg_sel); } else - draw_text(ctx, widget->location + box_width * i, 0, - box_width, + draw_text(ctx, widget->location + icon_width + box_width * i, 0, + box_width - icon_width, widget->statusbar->height, d->align, widget->font->height / 2, widget->font, c->name, d->fg, d->bg); - if(sel->isfloating) - draw_circle(ctx, widget->location + box_width * i, 0, + if(c->isfloating) + draw_circle(ctx, widget->location + icon_width + box_width * i, 0, (widget->font->height + 2) / 4, - sel->ismax, d->fg); + c->ismax, d->fg); i++; } @@ -179,6 +212,7 @@ tasklist_new(Statusbar *statusbar, cfg_t *config) d->fg_sel = globalconf.screens[statusbar->screen].colors_selected[ColFG]; d->align = draw_get_align(cfg_getstr(config, "align")); + d->show_icons = cfg_getbool(config, "show_icons"); if((buf = cfg_getstr(config, "font"))) w->font = XftFontOpenName(globalconf.display, get_phys_screen(statusbar->screen), buf);