2 * taglist.c - tag list widget
4 * Copyright © 2007 Aldo Cortesi <aldo@nullcube.com>
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.
29 extern AwesomeConf globalconf
;
31 /** Check if at least one client is tagged with tag number t and is on screen
33 * \param screen screen number
35 * \return True or False
42 for(c
= globalconf
.clients
; c
; c
= c
->next
)
43 if(is_client_tagged(c
, t
) && !c
->skip
)
53 for(c
= globalconf
.clients
; c
; c
= c
->next
)
54 if(is_client_tagged(c
, t
) && c
->isurgent
)
61 taglist_draw(Widget
*widget
,
64 int used
__attribute__ ((unused
)))
67 Client
*sel
= globalconf
.focus
->client
;
68 VirtScreen vscreen
= globalconf
.screens
[widget
->statusbar
->screen
];
73 flagsize
= (vscreen
.font
->height
+ 2) / 3;
75 widget
->area
.width
= 0;
77 for(tag
= vscreen
.tags
; tag
; tag
= tag
->next
)
78 widget
->area
.width
+= draw_textwidth(vscreen
.font
, tag
->name
) + vscreen
.font
->height
;
80 if(!widget
->user_supplied_x
)
81 widget
->area
.x
= widget_calculate_offset(widget
->statusbar
->width
,
86 if(!widget
->user_supplied_y
)
89 widget
->area
.width
= 0;
90 for(tag
= vscreen
.tags
; tag
; tag
= tag
->next
)
92 w
= draw_textwidth(vscreen
.font
, tag
->name
) + vscreen
.font
->height
;
94 colors
= vscreen
.colors_selected
;
95 else if(isurgent(tag
))
96 colors
= vscreen
.colors_urgent
;
98 colors
= vscreen
.colors_normal
;
99 area
.x
= widget
->area
.x
+ widget
->area
.width
;
100 area
.y
= widget
->area
.y
;
102 area
.height
= widget
->statusbar
->height
;
105 vscreen
.font
->height
/ 2,
112 Area rectangle
= { widget
->area
.x
+ widget
->area
.width
,
116 draw_rectangle(ctx
, rectangle
, sel
&& is_client_tagged(sel
, tag
), colors
[ColFG
]);
118 widget
->area
.width
+= w
;
121 widget
->area
.height
= widget
->statusbar
->height
;
122 return widget
->area
.width
;
126 taglist_button_press(Widget
*widget
, XButtonPressedEvent
*ev
)
128 VirtScreen vscreen
= globalconf
.screens
[widget
->statusbar
->screen
];
132 int prev_width
= 0, width
= 0, i
= 1;
134 for(b
= widget
->buttons
; b
; b
= b
->next
)
135 if(ev
->button
== b
->button
&& CLEANMASK(ev
->state
) == b
->mod
&& b
->func
)
136 switch(widget
->statusbar
->position
)
140 for(tag
= vscreen
.tags
; tag
; tag
= tag
->next
, i
++)
142 width
= draw_textwidth(vscreen
.font
, tag
->name
) + vscreen
.font
->height
;
143 if(ev
->x
>= widget
->area
.x
+ prev_width
144 && ev
->x
< widget
->area
.x
+ prev_width
+ width
)
146 snprintf(buf
, sizeof(buf
), "%d", i
);
147 b
->func(widget
->statusbar
->screen
, buf
);
154 for(tag
= vscreen
.tags
; tag
; tag
= tag
->next
, i
++)
156 width
= draw_textwidth(vscreen
.font
, tag
->name
) + vscreen
.font
->height
;
157 if(ev
->y
>= widget
->area
.x
+ prev_width
158 && ev
->y
< widget
->area
.x
+ prev_width
+ width
)
160 snprintf(buf
, sizeof(buf
), "%d", i
);
161 b
->func(widget
->statusbar
->screen
, buf
);
168 for(tag
= vscreen
.tags
; tag
; tag
= tag
->next
, i
++)
170 width
= draw_textwidth(vscreen
.font
, tag
->name
) + vscreen
.font
->height
;
171 if(widget
->statusbar
->width
- ev
->y
>= widget
->area
.x
+ prev_width
172 && widget
->statusbar
->width
- ev
->y
< widget
->area
.x
+ prev_width
+ width
)
174 snprintf(buf
, sizeof(buf
), "%d", i
);
175 b
->func(widget
->statusbar
->screen
, buf
);
185 taglist_new(Statusbar
*statusbar
, cfg_t
*config
)
188 w
= p_new(Widget
, 1);
189 widget_common_new(w
, statusbar
, config
);
190 w
->draw
= taglist_draw
;
191 w
->button_press
= taglist_button_press
;
193 /* Set cache property */
194 w
->cache
.flags
= WIDGET_CACHE_TAGS
| WIDGET_CACHE_CLIENTS
;
199 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80