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.
23 #include <X11/Xatom.h>
31 extern AwesomeConf globalconf
;
34 netwmicon_draw(Widget
*widget
, DrawCtx
*ctx
, int offset
,
35 int used
__attribute__ ((unused
)))
39 Client
*sel
= focus_get_current_client(widget
->statusbar
->screen
);
44 widget
->area
.width
= 0;
48 widget
->area
.height
= widget
->statusbar
->height
;
50 for(r
= globalconf
.rules
; r
; r
= r
->next
)
51 if(r
->icon
&& client_match_rule(sel
, r
))
53 area
= draw_get_image_size(r
->icon
);
54 widget
->area
.width
= ((double) widget
->statusbar
->height
/ (double) area
.height
)
56 if(!widget
->user_supplied_x
)
57 widget
->area
.x
= widget_calculate_offset(widget
->statusbar
->width
,
62 if(!widget
->user_supplied_y
)
64 draw_image(ctx
, widget
->area
.x
, widget
->area
.y
,
65 widget
->statusbar
->height
, r
->icon
);
67 return widget
->area
.width
;
71 if(!(icon
= ewmh_get_window_icon(sel
->win
)))
73 widget
->area
.width
= 0;
77 widget
->area
.width
= ((double) widget
->statusbar
->height
/ (double) icon
->height
) * icon
->width
;
79 if(!widget
->user_supplied_x
)
80 widget
->area
.x
= widget_calculate_offset(widget
->statusbar
->width
,
85 if(!widget
->user_supplied_y
)
88 draw_image_from_argb_data(ctx
,
89 widget
->area
.x
, widget
->area
.y
,
90 icon
->width
, icon
->height
,
91 widget
->statusbar
->height
, icon
->image
);
93 p_delete(&icon
->image
);
96 return widget
->area
.width
;
100 netwmicon_new(Statusbar
*statusbar
, cfg_t
*config
)
104 w
= p_new(Widget
, 1);
105 widget_common_new(w
, statusbar
, config
);
106 w
->draw
= netwmicon_draw
;
108 /* Set cache property */
109 w
->cache
.flags
= WIDGET_CACHE_CLIENTS
;
113 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80