build: remove xcb-render, not used
[awesome.git] / widgets / appicon.c
blob47a358c87ffb38fbafc54ed098c42f9afd8e5b49
1 /*
2 * appicon.c - application icon widget
4 * Copyright © 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 "widget.h"
23 #include "ewmh.h"
24 #include "titlebar.h"
26 extern awesome_t globalconf;
28 /** Draw a application icon widget.
29 * \param ctx The draw context.
30 * \param screen The screen.
31 * \param w The widget node we are linked from.
32 * \param offset Offset to draw at.
33 * \param used The size used on the element.
34 * \param p A pointer to the object we're draw onto.
35 * \param type The type of the object.
36 * \return The width used.
38 static int
39 appicon_draw(draw_context_t *ctx, int screen __attribute__ ((unused)),
40 widget_node_t *w,
41 int offset, int used,
42 void *p, awesome_type_t type)
44 client_t *c = NULL;
45 netwm_icon_t *icon;
46 draw_image_t *image;
48 switch(type)
50 case AWESOME_TYPE_STATUSBAR:
51 c = globalconf.screen_focus->client_focus;
52 break;
53 case AWESOME_TYPE_TITLEBAR:
54 c = client_getbytitlebar(p);
55 break;
58 if(c)
60 if((image = draw_image_new(c->icon_path)))
62 w->area.width = ((double) ctx->height / (double) image->height) * image->width;
63 w->area.x = widget_calculate_offset(ctx->width,
64 w->area.width,
65 offset,
66 w->widget->align);
67 draw_image(ctx, w->area.x,
68 w->area.y, ctx->height, image);
69 draw_image_delete(&image);
71 else if((icon = ewmh_get_window_icon(c->win)))
73 w->area.width = ((double) ctx->height / (double) icon->height)
74 * icon->width;
75 w->area.x = widget_calculate_offset(ctx->width,
76 w->area.width,
77 offset,
78 w->widget->align);
79 draw_image_from_argb_data(ctx,
80 w->area.x,
81 w->area.y,
82 icon->width, icon->height,
83 ctx->height, icon->image);
84 netwm_icon_delete(&icon);
87 else
88 w->area.width = 0;
90 return w->area.width;
93 /** Create a new appicon widget.
94 * \param align Widget alignment.
95 * \return A brand new widget.
97 widget_t *
98 appicon_new(alignment_t align)
100 widget_t *w;
102 w = p_new(widget_t, 1);
103 widget_common_new(w);
104 w->align = align;
105 w->draw = appicon_draw;
107 return w;
110 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80