From 1b48166ad5edc84a91b7a95cbbd46deafddff469 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 2 Jan 2008 14:59:15 +0100 Subject: [PATCH] add resize option to iconbox --- awesomerc.1.txt | 3 +++ config.c | 1 + widgets/iconbox.c | 32 +++++++++++++++++++++++--------- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/awesomerc.1.txt b/awesomerc.1.txt index 1511420d..0f71ee4e 100644 --- a/awesomerc.1.txt +++ b/awesomerc.1.txt @@ -164,6 +164,8 @@ This widget shows an icon. Set mouse bindings. *image*:: Image file. +*resize*:: + Resize icon to fit into statusbar. progressbar ~~~~~~~~~~~ @@ -233,6 +235,7 @@ screen iconbox { image= + resize=<{true,false}> mouse { button= command= modkey= } } layoutinfo diff --git a/config.c b/config.c index 28e2007a..84e6bb62 100644 --- a/config.c +++ b/config.c @@ -522,6 +522,7 @@ config_parse(const char *confpatharg) { CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI), CFG_STR((char *) "image", (char *) NULL, CFGF_NONE), + CFG_BOOL((char *) "resize", cfg_true, CFGF_NONE), CFG_END() }; static cfg_opt_t widget_textbox_focus_opts[] = diff --git a/widgets/iconbox.c b/widgets/iconbox.c index fb7d2f0a..d088673f 100644 --- a/widgets/iconbox.c +++ b/widgets/iconbox.c @@ -24,20 +24,30 @@ extern AwesomeConf globalconf; +typedef struct +{ + char *image; + Bool resize; +} Data; + static int iconbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__ ((unused))) { - Area area; + Data *d = widget->data; + Area area = draw_get_image_size(d->image); + + if(d->resize) + widget->width = ((double) widget->statusbar->height / area.height) * area.width; + else + widget->width = area.width; - area = draw_get_image_size(widget->data); - widget->width = ((double) widget->statusbar->height / area.height) * area.width; widget->location = widget_calculate_offset(widget->statusbar->width, widget->width, offset, widget->alignment); - draw_image(ctx, widget->location, 0, widget->statusbar->height, widget->data); + draw_image(ctx, widget->location, 0, d->resize ? widget->statusbar->height : 0, d->image); return widget->width; } @@ -45,22 +55,26 @@ iconbox_draw(Widget *widget, DrawCtx *ctx, int offset, static void iconbox_tell(Widget *widget, char *command) { - if(widget->data) - p_delete(&widget->data); - widget->data = a_strdup(command); - return; + Data *d = widget->data; + + if(d->image) + p_delete(&d->image); + d->image = a_strdup(command); } Widget * iconbox_new(Statusbar *statusbar, cfg_t *config) { Widget *w; + Data *d; w = p_new(Widget, 1); widget_common_new(w, statusbar, config); w->draw = iconbox_draw; w->tell = iconbox_tell; - w->data = (void *) a_strdup(cfg_getstr(config, "image")); + w->data = d = p_new(Data, 1); + d->image = a_strdup(cfg_getstr(config, "image")); + d->resize = cfg_getbool(config, "resize"); return w; }