2007-12-22 15:38:14 +01:00
|
|
|
/*
|
|
|
|
* iconbox.c - icon widget
|
|
|
|
*
|
2008-01-02 16:59:43 +01:00
|
|
|
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
|
2007-12-22 15:38:14 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "widget.h"
|
2008-01-21 18:14:59 +01:00
|
|
|
#include "common/util.h"
|
2007-12-22 15:38:14 +01:00
|
|
|
|
|
|
|
extern AwesomeConf globalconf;
|
|
|
|
|
2008-01-02 14:59:15 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *image;
|
|
|
|
Bool resize;
|
|
|
|
} Data;
|
|
|
|
|
2007-12-22 15:38:14 +01:00
|
|
|
static int
|
|
|
|
iconbox_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|
|
|
int used __attribute__ ((unused)))
|
|
|
|
{
|
2008-01-02 14:59:15 +01:00
|
|
|
Data *d = widget->data;
|
2008-01-05 12:35:12 +01:00
|
|
|
Area area = draw_get_image_size(d->image);
|
2008-01-02 14:59:15 +01:00
|
|
|
|
2008-01-17 13:45:24 +01:00
|
|
|
/* image not valid */
|
|
|
|
if(area.width < 0 || area.height < 0)
|
|
|
|
return (widget->area.width = 0);
|
|
|
|
|
2008-01-02 14:59:15 +01:00
|
|
|
if(d->resize)
|
2008-01-04 21:46:25 +01:00
|
|
|
widget->area.width = ((double) widget->statusbar->height / area.height) * area.width;
|
2008-01-02 14:59:15 +01:00
|
|
|
else
|
2008-01-04 21:46:25 +01:00
|
|
|
widget->area.width = area.width;
|
2007-12-29 21:44:44 +01:00
|
|
|
|
2008-01-05 12:44:14 +01:00
|
|
|
widget->area.height = widget->statusbar->height;
|
|
|
|
|
2008-01-05 12:35:12 +01:00
|
|
|
if(!widget->user_supplied_x)
|
|
|
|
widget->area.x = widget_calculate_offset(widget->statusbar->width,
|
2008-01-04 22:05:52 +01:00
|
|
|
widget->area.width,
|
|
|
|
offset,
|
|
|
|
widget->alignment);
|
2007-12-22 15:38:14 +01:00
|
|
|
|
2008-01-05 12:35:12 +01:00
|
|
|
if(!widget->user_supplied_y)
|
|
|
|
widget->area.y = 0;
|
2008-01-04 22:05:52 +01:00
|
|
|
|
2008-01-05 12:35:12 +01:00
|
|
|
draw_image(ctx, widget->area.x, widget->area.y,
|
2008-01-04 22:05:52 +01:00
|
|
|
d->resize ? widget->statusbar->height : 0, d->image);
|
2007-12-22 15:38:14 +01:00
|
|
|
|
2008-01-04 21:46:25 +01:00
|
|
|
return widget->area.width;
|
2007-12-22 15:38:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
iconbox_tell(Widget *widget, char *command)
|
|
|
|
{
|
2008-01-02 14:59:15 +01:00
|
|
|
Data *d = widget->data;
|
|
|
|
|
|
|
|
if(d->image)
|
|
|
|
p_delete(&d->image);
|
|
|
|
d->image = a_strdup(command);
|
2007-12-22 15:38:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget *
|
|
|
|
iconbox_new(Statusbar *statusbar, cfg_t *config)
|
|
|
|
{
|
|
|
|
Widget *w;
|
2008-01-02 14:59:15 +01:00
|
|
|
Data *d;
|
2007-12-22 15:38:14 +01:00
|
|
|
|
|
|
|
w = p_new(Widget, 1);
|
2007-12-22 20:55:17 +01:00
|
|
|
widget_common_new(w, statusbar, config);
|
2007-12-22 15:38:14 +01:00
|
|
|
w->draw = iconbox_draw;
|
|
|
|
w->tell = iconbox_tell;
|
2008-01-02 14:59:15 +01:00
|
|
|
w->data = d = p_new(Data, 1);
|
|
|
|
d->image = a_strdup(cfg_getstr(config, "image"));
|
|
|
|
d->resize = cfg_getbool(config, "resize");
|
2007-12-22 15:38:14 +01:00
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|