2 * tasklist.c - task list 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.
33 #define ISVISIBLE_ON_TB(c, screen) (client_isvisible(c, screen) && !c->skiptb)
35 extern AwesomeConf globalconf
;
48 tasklist_draw(Widget
*widget
, DrawCtx
*ctx
, int offset
, int used
)
51 Data
*d
= widget
->data
;
52 Client
*sel
= focus_get_current_client(widget
->statusbar
->screen
);
55 int n
= 0, i
= 0, box_width
= 0, icon_width
= 0;
58 for(c
= globalconf
.clients
; c
; c
= c
->next
)
59 if(ISVISIBLE_ON_TB(c
, widget
->statusbar
->screen
))
68 box_width
= (widget
->statusbar
->width
- used
) / n
;
70 widget
->location
= widget_calculate_offset(widget
->statusbar
->width
,
75 for(c
= globalconf
.clients
; c
; c
= c
->next
)
76 if(ISVISIBLE_ON_TB(c
, widget
->statusbar
->screen
))
82 for(r
= globalconf
.rules
; r
; r
= r
->next
)
83 if(r
->icon
&& client_match_rule(c
, r
))
85 area
= draw_get_image_size(r
->icon
);
86 icon_width
= ((double) widget
->statusbar
->height
/ (double) area
.height
) * area
.width
;
88 widget
->location
+ box_width
* i
,
89 0, widget
->statusbar
->height
,
93 if(!icon_width
&& (icon
= ewmh_get_window_icon(c
->win
)))
95 icon_width
= ((double) widget
->statusbar
->height
/ (double) icon
->height
)
97 draw_image_from_argb_data(ctx
,
98 widget
->location
+ box_width
* i
, 0,
99 icon
->width
, icon
->height
,
100 widget
->statusbar
->height
, icon
->image
);
101 p_delete(&icon
->image
);
108 draw_text(ctx
, widget
->location
+ icon_width
+ box_width
* i
, 0,
109 box_width
- icon_width
,
110 widget
->statusbar
->height
,
112 widget
->font
->height
/ 2, widget
->font
, c
->name
,
113 d
->fg_sel
, d
->bg_sel
);
116 draw_text(ctx
, widget
->location
+ icon_width
+ box_width
* i
, 0,
117 box_width
- icon_width
,
118 widget
->statusbar
->height
,
120 widget
->font
->height
/ 2, widget
->font
, c
->name
,
123 draw_circle(ctx
, widget
->location
+ icon_width
+ box_width
* i
, 0,
124 (widget
->font
->height
+ 2) / 4,
129 widget
->width
= widget
->statusbar
->width
- used
;
131 return widget
->width
;
135 tasklist_button_press(Widget
*widget
, XButtonPressedEvent
*ev
)
139 int n
= 0, box_width
= 0, i
= 0, ci
= 0;
141 /* button1 give focus */
142 if(ev
->button
== Button1
&& CLEANMASK(ev
->state
) == NoSymbol
)
144 for(c
= globalconf
.clients
; c
; c
= c
->next
)
145 if(ISVISIBLE_ON_TB(c
, widget
->statusbar
->screen
))
151 box_width
= widget
->width
/ n
;
153 if(ev
->button
== Button1
&& CLEANMASK(ev
->state
) == NoSymbol
)
155 switch(widget
->statusbar
->position
)
159 ci
= (ev
->x
- widget
->location
) / box_width
;
162 ci
= (ev
->y
- widget
->location
) / box_width
;
165 ci
= ((widget
->statusbar
->width
- ev
->y
) - widget
->location
) / box_width
;
168 /* found first visible client */
169 for(c
= globalconf
.clients
;
170 c
&& !ISVISIBLE_ON_TB(c
, widget
->statusbar
->screen
);
172 /* found ci-th visible client */
173 for(; c
&& i
< ci
; c
= c
->next
)
174 if(ISVISIBLE_ON_TB(c
, widget
->statusbar
->screen
))
177 focus(c
, True
, widget
->statusbar
->screen
);
182 for(b
= widget
->buttons
; b
; b
= b
->next
)
183 if(ev
->button
== b
->button
&& CLEANMASK(ev
->state
) == b
->mod
&& b
->func
)
185 b
->func(widget
->statusbar
->screen
, b
->arg
);
191 tasklist_new(Statusbar
*statusbar
, cfg_t
*config
)
196 int phys_screen
= get_phys_screen(statusbar
->screen
);
198 w
= p_new(Widget
, 1);
199 widget_common_new(w
, statusbar
, config
);
200 w
->draw
= tasklist_draw
;
201 w
->button_press
= tasklist_button_press
;
202 w
->alignment
= AlignFlex
;
203 w
->data
= d
= p_new(Data
, 1);
205 if((buf
= cfg_getstr(config
, "fg")))
206 d
->fg
= initxcolor(phys_screen
, buf
);
208 d
->fg
= globalconf
.screens
[statusbar
->screen
].colors_normal
[ColFG
];
210 if((buf
= cfg_getstr(config
, "bg")))
211 d
->bg
= initxcolor(phys_screen
, buf
);
213 d
->bg
= globalconf
.screens
[statusbar
->screen
].colors_normal
[ColBG
];
215 if((buf
= cfg_getstr(config
, "focus_bg")))
216 d
->bg_sel
= initxcolor(phys_screen
, buf
);
218 d
->bg_sel
= globalconf
.screens
[statusbar
->screen
].colors_selected
[ColBG
];
220 if((buf
= cfg_getstr(config
, "focus_fg")))
221 d
->fg_sel
= initxcolor(phys_screen
, buf
);
223 d
->fg_sel
= globalconf
.screens
[statusbar
->screen
].colors_selected
[ColFG
];
225 d
->align
= draw_get_align(cfg_getstr(config
, "align"));
226 d
->show_icons
= cfg_getbool(config
, "show_icons");
228 if((buf
= cfg_getstr(config
, "font")))
229 w
->font
= XftFontOpenName(globalconf
.display
, get_phys_screen(statusbar
->screen
), buf
);
232 w
->font
= globalconf
.screens
[statusbar
->screen
].font
;
237 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80