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.
28 extern AwesomeConf globalconf
;
30 /** Check if at least one client is tagged with tag number t and is on screen
32 * \param screen screen number
34 * \return True or False
41 for(c
= globalconf
.clients
; c
; c
= c
->next
)
42 if(is_client_tagged(c
, t
))
52 for(c
= globalconf
.clients
; c
; c
= c
->next
)
53 if(is_client_tagged(c
, t
) && c
->isurgent
)
60 taglist_draw(Widget
*widget
,
63 int used
__attribute__ ((unused
)))
66 Client
*sel
= globalconf
.focus
->client
;
67 VirtScreen vscreen
= globalconf
.screens
[widget
->statusbar
->screen
];
71 flagsize
= (vscreen
.font
->height
+ 2) / 3;
75 for(tag
= vscreen
.tags
; tag
; tag
= tag
->next
)
76 widget
->width
+= textwidth(vscreen
.font
, tag
->name
) + vscreen
.font
->height
;
78 widget
->location
= widget_calculate_offset(widget
->statusbar
->width
,
84 for(tag
= vscreen
.tags
; tag
; tag
= tag
->next
)
86 w
= textwidth(vscreen
.font
, tag
->name
) + vscreen
.font
->height
;
88 colors
= vscreen
.colors_selected
;
89 else if(isurgent(tag
))
90 colors
= vscreen
.colors_urgent
;
92 colors
= vscreen
.colors_normal
;
94 widget
->location
+ widget
->width
, 0,
95 w
, widget
->statusbar
->height
,
97 vscreen
.font
->height
/ 2,
103 draw_rectangle(ctx
, widget
->location
+ widget
->width
, 0, flagsize
, flagsize
,
104 sel
&& is_client_tagged(sel
, tag
), colors
[ColFG
]);
108 return widget
->width
;
112 taglist_button_press(Widget
*widget
, XButtonPressedEvent
*ev
)
114 VirtScreen vscreen
= globalconf
.screens
[widget
->statusbar
->screen
];
118 int prev_width
= 0, width
= 0, i
= 1;
120 for(b
= widget
->buttons
; b
; b
= b
->next
)
121 if(ev
->button
== b
->button
&& CLEANMASK(ev
->state
) == b
->mod
&& b
->func
)
122 switch(widget
->statusbar
->position
)
126 for(tag
= vscreen
.tags
; tag
; tag
= tag
->next
, i
++)
128 width
= textwidth(vscreen
.font
, tag
->name
) + vscreen
.font
->height
;
129 if(ev
->x
>= widget
->location
+ prev_width
130 && ev
->x
<= widget
->location
+ prev_width
+ width
)
132 snprintf(buf
, sizeof(buf
), "%d", i
);
133 b
->func(widget
->statusbar
->screen
, buf
);
140 for(tag
= vscreen
.tags
; tag
; tag
= tag
->next
, i
++)
142 width
= textwidth(vscreen
.font
, tag
->name
) + vscreen
.font
->height
;
143 if(ev
->y
>= widget
->location
+ prev_width
144 && ev
->y
<= widget
->location
+ 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
= textwidth(vscreen
.font
, tag
->name
) + vscreen
.font
->height
;
157 if(widget
->statusbar
->width
- ev
->y
>= widget
->location
+ prev_width
158 && widget
->statusbar
->width
- ev
->y
<= widget
->location
+ prev_width
+ width
)
160 snprintf(buf
, sizeof(buf
), "%d", i
);
161 b
->func(widget
->statusbar
->screen
, buf
);
171 taglist_new(Statusbar
*statusbar
, cfg_t
*config
)
174 w
= p_new(Widget
, 1);
175 widget_common_new(w
, statusbar
, config
);
176 w
->draw
= taglist_draw
;
177 w
->button_press
= taglist_button_press
;
181 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80