add resize option to iconbox

This commit is contained in:
Julien Danjou 2008-01-02 14:59:15 +01:00
parent aff5e13590
commit 1b48166ad5
3 changed files with 27 additions and 9 deletions

View File

@ -164,6 +164,8 @@ This widget shows an icon.
Set mouse bindings. Set mouse bindings.
*image*:: *image*::
Image file. Image file.
*resize*::
Resize icon to fit into statusbar.
progressbar progressbar
~~~~~~~~~~~ ~~~~~~~~~~~
@ -233,6 +235,7 @@ screen <number>
iconbox <identifier> iconbox <identifier>
{ {
image=<image> image=<image>
resize=<{true,false}>
mouse { button=<integer> command=<uicb-cmd> modkey=<mod> } mouse { button=<integer> command=<uicb-cmd> modkey=<mod> }
} }
layoutinfo <identifier> layoutinfo <identifier>

View File

@ -522,6 +522,7 @@ config_parse(const char *confpatharg)
{ {
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI), CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
CFG_STR((char *) "image", (char *) NULL, CFGF_NONE), CFG_STR((char *) "image", (char *) NULL, CFGF_NONE),
CFG_BOOL((char *) "resize", cfg_true, CFGF_NONE),
CFG_END() CFG_END()
}; };
static cfg_opt_t widget_textbox_focus_opts[] = static cfg_opt_t widget_textbox_focus_opts[] =

View File

@ -24,20 +24,30 @@
extern AwesomeConf globalconf; extern AwesomeConf globalconf;
typedef struct
{
char *image;
Bool resize;
} Data;
static int static int
iconbox_draw(Widget *widget, DrawCtx *ctx, int offset, iconbox_draw(Widget *widget, DrawCtx *ctx, int offset,
int used __attribute__ ((unused))) 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->location = widget_calculate_offset(widget->statusbar->width,
widget->width, widget->width,
offset, offset,
widget->alignment); 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; return widget->width;
} }
@ -45,22 +55,26 @@ iconbox_draw(Widget *widget, DrawCtx *ctx, int offset,
static void static void
iconbox_tell(Widget *widget, char *command) iconbox_tell(Widget *widget, char *command)
{ {
if(widget->data) Data *d = widget->data;
p_delete(&widget->data);
widget->data = a_strdup(command); if(d->image)
return; p_delete(&d->image);
d->image = a_strdup(command);
} }
Widget * Widget *
iconbox_new(Statusbar *statusbar, cfg_t *config) iconbox_new(Statusbar *statusbar, cfg_t *config)
{ {
Widget *w; Widget *w;
Data *d;
w = p_new(Widget, 1); w = p_new(Widget, 1);
widget_common_new(w, statusbar, config); widget_common_new(w, statusbar, config);
w->draw = iconbox_draw; w->draw = iconbox_draw;
w->tell = iconbox_tell; 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; return w;
} }