tmp_color can be uninitialized
[awesome.git] / widgets / netwmicon.c
blob8e01245b9a6fb5f85667222df951b13108394050
1 /*
2 * netwmicon.c - NET_WM_ICON widget
4 * Copyright © 2007-2008 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 <X11/Xmd.h>
23 #include <X11/Xatom.h>
24 #include "focus.h"
25 #include "tag.h"
26 #include "widget.h"
27 #include "rules.h"
28 #include "ewmh.h"
29 #include "common/util.h"
31 extern AwesomeConf globalconf;
33 static int
34 netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset,
35 int used __attribute__ ((unused)))
37 Area area;
38 Rule* r;
39 Client *sel = focus_get_current_client(widget->statusbar->screen);
40 NetWMIcon *icon;
42 if(!sel)
44 widget->area.width = 0;
45 return 0;
48 widget->area.height = widget->statusbar->height;
50 if((r = rule_matching_client(sel)) && r->icon)
52 area = draw_get_image_size(r->icon);
53 widget->area.width = ((double) widget->statusbar->height / (double) area.height)
54 * area.width;
55 if(!widget->user_supplied_x)
56 widget->area.x = widget_calculate_offset(widget->statusbar->width,
57 widget->area.width,
58 offset,
59 widget->alignment);
61 if(!widget->user_supplied_y)
62 widget->area.y = 0;
63 draw_image(ctx, widget->area.x, widget->area.y,
64 widget->statusbar->height, r->icon);
66 return widget->area.width;
69 if(!(icon = ewmh_get_window_icon(sel->win)))
71 widget->area.width = 0;
72 return 0;
75 widget->area.width = ((double) widget->statusbar->height / (double) icon->height) * icon->width;
77 if(!widget->user_supplied_x)
78 widget->area.x = widget_calculate_offset(widget->statusbar->width,
79 widget->area.width,
80 offset,
81 widget->alignment);
83 if(!widget->user_supplied_y)
84 widget->area.y = 0;
86 draw_image_from_argb_data(ctx,
87 widget->area.x, widget->area.y,
88 icon->width, icon->height,
89 widget->statusbar->height, icon->image);
91 p_delete(&icon->image);
92 p_delete(&icon);
94 return widget->area.width;
97 Widget *
98 netwmicon_new(Statusbar *statusbar, cfg_t *config)
100 Widget *w;
102 w = p_new(Widget, 1);
103 widget_common_new(w, statusbar, config);
104 w->draw = netwmicon_draw;
106 /* Set cache property */
107 w->cache.flags = WIDGET_CACHE_CLIENTS;
109 return w;
111 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80