add resize option to iconbox
[awesome.git] / widgets / iconbox.c
blobd088673fbe29cbf99d02adedb48efb54e9ad6316
1 /*
2 * iconbox.c - icon widget
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "util.h"
23 #include "widget.h"
25 extern AwesomeConf globalconf;
27 typedef struct
29 char *image;
30 Bool resize;
31 } Data;
33 static int
34 iconbox_draw(Widget *widget, DrawCtx *ctx, int offset,
35 int used __attribute__ ((unused)))
37 Data *d = widget->data;
38 Area area = draw_get_image_size(d->image);
40 if(d->resize)
41 widget->width = ((double) widget->statusbar->height / area.height) * area.width;
42 else
43 widget->width = area.width;
45 widget->location = widget_calculate_offset(widget->statusbar->width,
46 widget->width,
47 offset,
48 widget->alignment);
50 draw_image(ctx, widget->location, 0, d->resize ? widget->statusbar->height : 0, d->image);
52 return widget->width;
55 static void
56 iconbox_tell(Widget *widget, char *command)
58 Data *d = widget->data;
60 if(d->image)
61 p_delete(&d->image);
62 d->image = a_strdup(command);
65 Widget *
66 iconbox_new(Statusbar *statusbar, cfg_t *config)
68 Widget *w;
69 Data *d;
71 w = p_new(Widget, 1);
72 widget_common_new(w, statusbar, config);
73 w->draw = iconbox_draw;
74 w->tell = iconbox_tell;
75 w->data = d = p_new(Data, 1);
76 d->image = a_strdup(cfg_getstr(config, "image"));
77 d->resize = cfg_getbool(config, "resize");
79 return w;
81 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80