From eb653061276a1dd19db812e891d971938d8af047 Mon Sep 17 00:00:00 2001 From: Robert Millar Date: Sat, 29 Dec 2007 18:44:15 +0000 Subject: [PATCH] Custom netwm icons, scaling icons! I hacked together support for custom netwm icons set in the rules section of .awesomerc, and for iconboxes and netwm icons to be scaled to fit into the statusbar. It could probably be done a bit more cleanly than I've done it, though :) Rob --- config.c | 4 ++++ config.h | 1 + draw.c | 14 ++++++++++++++ draw.h | 1 + widgets/iconbox.c | 6 ++++-- widgets/netwmicon.c | 21 +++++++++++++++++++++ 6 files changed, 45 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index 81d8cc04b..a1e8c0dc6 100644 --- a/config.c +++ b/config.c @@ -588,6 +588,7 @@ config_parse(const char *confpatharg) { CFG_STR((char *) "name", (char *) "", CFGF_NONE), CFG_STR((char *) "tags", (char *) "", CFGF_NONE), + CFG_STR((char *) "icon", (char *) "", CFGF_NONE), CFG_BOOL((char *) "float", cfg_false, CFGF_NONE), CFG_INT((char *) "screen", RULE_NOSCREEN, CFGF_NONE), CFG_END() @@ -689,6 +690,9 @@ config_parse(const char *confpatharg) rule->tags = a_strdup(cfg_getstr(cfgsectmp, "tags")); if(!a_strlen(rule->tags)) rule->tags = NULL; + rule->icon = a_strdup(cfg_getstr(cfgsectmp, "icon")); + if (!a_strlen(rule->icon)) + rule->icon = NULL; rule->isfloating = cfg_getbool(cfgsectmp, "float"); rule->screen = cfg_getint(cfgsectmp, "screen"); if(rule->screen >= get_screen_count()) diff --git a/config.h b/config.h index f86a2302c..a8a728916 100644 --- a/config.h +++ b/config.h @@ -43,6 +43,7 @@ struct Rule { char *prop; char *tags; + char *icon; int screen; Bool isfloating; regex_t *propregex; diff --git a/draw.c b/draw.c index 428fd3ac9..5efce78d8 100644 --- a/draw.c +++ b/draw.c @@ -218,6 +218,20 @@ draw_get_image_width(const char *filename) return width; } +int +draw_get_image_height(const char* filename) +{ + int height; + cairo_surface_t *surface; + + surface = cairo_image_surface_create_from_png(filename); + cairo_image_surface_get_height(surface); + height = cairo_image_surface_get_height(surface); + cairo_surface_destroy(surface); + + return height; +} + Drawable draw_rotate(DrawCtx *ctx, int screen, double angle, int tx, int ty) { diff --git a/draw.h b/draw.h index fece15ccd..dbd2c34d0 100644 --- a/draw.h +++ b/draw.h @@ -41,6 +41,7 @@ void draw_circle(DrawCtx *, int, int, int, Bool, XColor); void draw_image(DrawCtx *, int, int, int, const char *); void draw_image_from_argb_data(DrawCtx *, int, int, int, int, int, unsigned char *); int draw_get_image_width(const char *filename); +int draw_get_image_height(const char *filename); Drawable draw_rotate(DrawCtx *, int, double, int, int); unsigned short textwidth(XftFont *, char *); diff --git a/widgets/iconbox.c b/widgets/iconbox.c index fde258f02..820ee560e 100644 --- a/widgets/iconbox.c +++ b/widgets/iconbox.c @@ -29,14 +29,16 @@ static int iconbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__ ((unused))) { + int height; widget->width = draw_get_image_width(widget->data); - + height = draw_get_image_height(widget->data); + widget->width = ((double) widget->statusbar->height / height) * widget->width; widget->location = widget_calculate_offset(widget->statusbar->width, widget->width, offset, widget->alignment); - draw_image(ctx, widget->location, 0, 0, widget->data); + draw_image(ctx, widget->location, 0, widget->statusbar->height, widget->data); return widget->width; } diff --git a/widgets/netwmicon.c b/widgets/netwmicon.c index 576cc7088..a4cfe5706 100644 --- a/widgets/netwmicon.c +++ b/widgets/netwmicon.c @@ -26,6 +26,7 @@ #include "focus.h" #include "tag.h" #include "widget.h" +#include "rules.h" extern AwesomeConf globalconf; @@ -39,11 +40,31 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset, int format, width, height, size, i; unsigned long items, rest; unsigned char *image, *imgdata; + char* icon; + Rule* r; Client *sel = focus_get_current_client(widget->statusbar->screen); if(!sel) return 0; + for(r = globalconf.rules; r; r = r->next) + if(client_match_rule(sel, r)) + { + if(!r->icon) + continue; + icon = r->icon; + width = draw_get_image_width(icon); + height = draw_get_image_height(icon); + width = ((double) widget->statusbar->height / (double) height) * width; + widget->location = widget_calculate_offset(widget->statusbar->width, + width, + offset, + widget->alignment); + draw_image(ctx, widget->location, 0, widget->statusbar->height, icon); + + return width; + } + if(XGetWindowProperty(ctx->display, sel->win, XInternAtom(ctx->display, "_NET_WM_ICON", False), 0L, LONG_MAX, False, XA_CARDINAL, &type, &format,