[uicb] uicb_client_toggletag() with NULL use as sticky toggle
[awesome.git] / widgets / layoutinfo.c
blob5f1c7cfd7bd38f4cd561b0f8292631465dcea717
1 /*
2 * layoutinfo.c - layout info widget
4 * Copyright © 2007 Aldo Cortesi <aldo@nullcube.com>
5 * Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
6 * Aldo Cortesi <aldo@nullcube.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "widget.h"
25 #include "tag.h"
26 #include "common/util.h"
27 #include "common/configopts.h"
29 extern AwesomeConf globalconf;
31 static int
32 layoutinfo_draw(Widget *widget,
33 DrawCtx *ctx,
34 int offset,
35 int used __attribute__ ((unused)))
37 Tag **curtags = tags_get_current(widget->statusbar->screen);
38 area_t area = draw_get_image_size(curtags[0]->layout->image);
40 if(!widget->user_supplied_x)
41 widget->area.x = widget_calculate_offset(widget->statusbar->width,
42 widget->statusbar->height,
43 offset,
44 widget->alignment);
46 if(!widget->user_supplied_y)
47 widget->area.y = 0;
49 widget->area.width = ((double) widget->statusbar->height / (double) area.height) * area.width;;
50 widget->area.height = widget->statusbar->height;
52 draw_image(ctx, widget->area.x, widget->area.y,
53 widget->statusbar->height,
54 curtags[0]->layout->image);
56 p_delete(&curtags);
58 return widget->area.width;
61 Widget *
62 layoutinfo_new(Statusbar *statusbar, cfg_t* config)
64 Widget *w;
65 w = p_new(Widget, 1);
66 widget_common_new(w, statusbar, config);
67 w->draw = layoutinfo_draw;
68 w->alignment = cfg_getalignment(config, "align");
70 /* Set cache property */
71 w->cache.flags = WIDGET_CACHE_LAYOUTS;
73 return w;
76 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80