2008-01-03 12:39:28 +01:00
|
|
|
/*
|
|
|
|
* tasklist.c - task list widget
|
|
|
|
*
|
|
|
|
* Copyright © 2008 Julien Danjou <julien@danjou.info>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "widget.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "focus.h"
|
|
|
|
#include "screen.h"
|
|
|
|
#include "event.h"
|
2008-01-03 19:21:36 +01:00
|
|
|
#include "ewmh.h"
|
|
|
|
#include "rules.h"
|
2008-01-07 11:20:24 +01:00
|
|
|
#include "tag.h"
|
2008-01-21 18:14:59 +01:00
|
|
|
#include "common/util.h"
|
2008-01-03 12:39:28 +01:00
|
|
|
|
|
|
|
extern AwesomeConf globalconf;
|
|
|
|
|
2008-02-06 20:03:18 +01:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
ShowFocus,
|
|
|
|
ShowTags,
|
|
|
|
ShowAll,
|
|
|
|
} ShowClient;
|
|
|
|
|
2008-01-03 12:39:28 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
2008-02-06 20:03:18 +01:00
|
|
|
ShowClient show;
|
2008-01-03 19:21:36 +01:00
|
|
|
Bool show_icons;
|
2008-01-04 19:17:20 +01:00
|
|
|
Alignment align;
|
2008-03-13 14:03:03 +01:00
|
|
|
struct
|
|
|
|
{
|
2008-03-14 08:35:06 +01:00
|
|
|
style_t normal;
|
|
|
|
style_t focus;
|
|
|
|
} styles;
|
2008-01-03 12:39:28 +01:00
|
|
|
} Data;
|
|
|
|
|
2008-02-06 20:03:18 +01:00
|
|
|
static inline Bool
|
|
|
|
tasklist_isvisible(Client *c, int screen, ShowClient show)
|
|
|
|
{
|
2008-02-12 10:29:41 +01:00
|
|
|
if(c->skip || c->skiptb)
|
2008-02-06 20:03:18 +01:00
|
|
|
return False;
|
|
|
|
|
|
|
|
switch(show)
|
|
|
|
{
|
|
|
|
case ShowAll:
|
|
|
|
if(c->screen == screen)
|
|
|
|
return True;
|
|
|
|
break;
|
|
|
|
case ShowTags:
|
|
|
|
if(client_isvisible(c, screen))
|
|
|
|
return True;
|
|
|
|
break;
|
|
|
|
case ShowFocus:
|
|
|
|
if(c == globalconf.focus->client)
|
|
|
|
return True;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2008-01-03 12:39:28 +01:00
|
|
|
static int
|
|
|
|
tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
|
|
|
|
{
|
|
|
|
Client *c;
|
|
|
|
Data *d = widget->data;
|
|
|
|
Client *sel = focus_get_current_client(widget->statusbar->screen);
|
2008-01-03 19:21:36 +01:00
|
|
|
Rule *r;
|
|
|
|
Area area;
|
2008-03-14 08:35:06 +01:00
|
|
|
style_t style;
|
2008-01-20 16:25:06 +01:00
|
|
|
int n = 0, i = 0, box_width = 0, icon_width = 0, box_width_rest = 0;
|
2008-01-03 19:21:36 +01:00
|
|
|
NetWMIcon *icon;
|
2008-01-03 12:39:28 +01:00
|
|
|
|
2008-01-22 17:52:12 +01:00
|
|
|
if(used >= widget->statusbar->width)
|
|
|
|
return (widget->area.width = 0);
|
|
|
|
|
2008-01-03 12:39:28 +01:00
|
|
|
for(c = globalconf.clients; c; c = c->next)
|
2008-02-06 20:03:18 +01:00
|
|
|
if(tasklist_isvisible(c, widget->statusbar->screen, d->show))
|
2008-01-03 12:39:28 +01:00
|
|
|
n++;
|
2008-02-13 06:53:08 +01:00
|
|
|
|
2008-01-03 12:39:28 +01:00
|
|
|
if(!n)
|
2008-01-22 17:52:12 +01:00
|
|
|
return (widget->area.width = 0);
|
2008-01-03 12:39:28 +01:00
|
|
|
|
2008-01-03 17:15:21 +01:00
|
|
|
box_width = (widget->statusbar->width - used) / n;
|
2008-01-20 16:25:06 +01:00
|
|
|
/* compute how many pixel we left empty */
|
|
|
|
box_width_rest = (widget->statusbar->width - used) % n;
|
2008-01-03 12:39:28 +01:00
|
|
|
|
2008-01-05 12:35:12 +01:00
|
|
|
if(!widget->user_supplied_x)
|
2008-01-04 22:05:52 +01:00
|
|
|
widget->area.x = widget_calculate_offset(widget->statusbar->width,
|
|
|
|
0,
|
|
|
|
offset,
|
|
|
|
widget->alignment);
|
|
|
|
|
2008-01-05 12:35:12 +01:00
|
|
|
if(!widget->user_supplied_y)
|
|
|
|
widget->area.y = widget->area.y = 0;
|
2008-01-03 12:39:28 +01:00
|
|
|
|
|
|
|
for(c = globalconf.clients; c; c = c->next)
|
2008-02-06 20:03:18 +01:00
|
|
|
if(tasklist_isvisible(c, widget->statusbar->screen, d->show))
|
2008-01-03 12:39:28 +01:00
|
|
|
{
|
2008-01-03 19:21:36 +01:00
|
|
|
icon_width = 0;
|
|
|
|
|
2008-03-14 08:35:06 +01:00
|
|
|
style = sel == c ? d->styles.focus : d->styles.normal;
|
|
|
|
|
2008-01-03 19:21:36 +01:00
|
|
|
if(d->show_icons)
|
|
|
|
{
|
2008-01-17 15:47:08 +01:00
|
|
|
/* draw a background for icons */
|
|
|
|
area.x = widget->area.x + box_width * i;
|
|
|
|
area.y = widget->area.y;
|
|
|
|
area.height = widget->statusbar->height;
|
|
|
|
area.width = box_width;
|
2008-03-14 08:35:06 +01:00
|
|
|
|
|
|
|
draw_rectangle(ctx, area, True, style.fg);
|
2008-01-17 15:47:08 +01:00
|
|
|
|
2008-01-12 22:59:13 +01:00
|
|
|
if((r = rule_matching_client(c)) && r->icon)
|
|
|
|
{
|
|
|
|
area = draw_get_image_size(r->icon);
|
2008-01-23 19:13:49 +01:00
|
|
|
if(area.width > 0 && area.height > 0)
|
|
|
|
{
|
|
|
|
icon_width = ((double) widget->statusbar->height / (double) area.height) * area.width;
|
|
|
|
draw_image(ctx,
|
|
|
|
widget->area.x + box_width * i,
|
|
|
|
widget->area.y,
|
|
|
|
widget->statusbar->height,
|
|
|
|
r->icon);
|
|
|
|
}
|
2008-01-12 22:59:13 +01:00
|
|
|
}
|
2008-01-03 19:21:36 +01:00
|
|
|
|
|
|
|
if(!icon_width && (icon = ewmh_get_window_icon(c->win)))
|
|
|
|
{
|
|
|
|
icon_width = ((double) widget->statusbar->height / (double) icon->height)
|
|
|
|
* icon->width;
|
|
|
|
draw_image_from_argb_data(ctx,
|
2008-01-04 22:05:52 +01:00
|
|
|
widget->area.x + box_width * i,
|
|
|
|
widget->area.y,
|
2008-01-03 19:21:36 +01:00
|
|
|
icon->width, icon->height,
|
|
|
|
widget->statusbar->height, icon->image);
|
2008-01-04 15:59:17 +01:00
|
|
|
p_delete(&icon->image);
|
2008-01-03 19:21:36 +01:00
|
|
|
p_delete(&icon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-12 23:47:03 +01:00
|
|
|
area.x = widget->area.x + icon_width + box_width * i;
|
|
|
|
area.y = widget->area.y;
|
|
|
|
area.width = box_width - icon_width;
|
|
|
|
area.height = widget->statusbar->height;
|
2008-01-20 16:25:06 +01:00
|
|
|
|
|
|
|
/* if we're on last elem, it has the last pixels left */
|
|
|
|
if(i == n - 1)
|
|
|
|
area.width += box_width_rest;
|
|
|
|
|
2008-03-14 08:35:06 +01:00
|
|
|
draw_text(ctx, area, d->align,
|
|
|
|
style.font->height / 2, c->name,
|
|
|
|
style);
|
2008-01-12 23:47:03 +01:00
|
|
|
|
2008-02-06 08:49:31 +01:00
|
|
|
if(c == globalconf.scratch.client)
|
|
|
|
{
|
|
|
|
area.x = widget->area.x + icon_width + box_width * i;
|
|
|
|
area.y = widget->area.y;
|
2008-03-14 08:35:06 +01:00
|
|
|
area.width = (style.font->height + 2) / 3;
|
|
|
|
area.height = (style.font->height + 2) / 3;
|
|
|
|
draw_rectangle(ctx, area, c->isfloating, style.fg);
|
2008-02-06 08:49:31 +01:00
|
|
|
}
|
|
|
|
else if(c->isfloating || c->ismax)
|
2008-01-04 22:05:52 +01:00
|
|
|
draw_circle(ctx, widget->area.x + icon_width + box_width * i,
|
|
|
|
widget->area.y,
|
2008-03-14 08:35:06 +01:00
|
|
|
(style.font->height + 2) / 4,
|
|
|
|
c->ismax, style.fg);
|
2008-01-03 12:39:28 +01:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2008-01-04 21:46:25 +01:00
|
|
|
widget->area.width = widget->statusbar->width - used;
|
2008-01-05 12:44:14 +01:00
|
|
|
widget->area.height = widget->statusbar->height;
|
2008-01-03 12:39:28 +01:00
|
|
|
|
2008-01-04 21:46:25 +01:00
|
|
|
return widget->area.width;
|
2008-01-03 12:39:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tasklist_button_press(Widget *widget, XButtonPressedEvent *ev)
|
|
|
|
{
|
|
|
|
Button *b;
|
|
|
|
Client *c;
|
2008-01-07 11:20:24 +01:00
|
|
|
Data *d = widget->data;
|
|
|
|
Tag *tag;
|
2008-01-18 09:49:04 +01:00
|
|
|
int n = 0, box_width = 0, i, ci = 0;
|
2008-01-03 12:39:28 +01:00
|
|
|
|
|
|
|
/* button1 give focus */
|
|
|
|
if(ev->button == Button1 && CLEANMASK(ev->state) == NoSymbol)
|
|
|
|
{
|
|
|
|
for(c = globalconf.clients; c; c = c->next)
|
2008-02-06 20:03:18 +01:00
|
|
|
if(tasklist_isvisible(c, widget->statusbar->screen, d->show))
|
2008-01-03 12:39:28 +01:00
|
|
|
n++;
|
2008-02-13 06:53:08 +01:00
|
|
|
|
2008-01-03 12:39:28 +01:00
|
|
|
if(!n)
|
|
|
|
return;
|
|
|
|
|
2008-01-04 21:46:25 +01:00
|
|
|
box_width = widget->area.width / n;
|
2008-01-03 12:39:28 +01:00
|
|
|
|
|
|
|
if(ev->button == Button1 && CLEANMASK(ev->state) == NoSymbol)
|
2008-01-04 13:04:34 +01:00
|
|
|
{
|
2008-01-04 19:12:07 +01:00
|
|
|
switch(widget->statusbar->position)
|
|
|
|
{
|
|
|
|
case Top:
|
|
|
|
case Bottom:
|
2008-01-04 21:46:25 +01:00
|
|
|
ci = (ev->x - widget->area.x) / box_width;
|
2008-01-04 19:12:07 +01:00
|
|
|
break;
|
|
|
|
case Right:
|
2008-01-04 21:46:25 +01:00
|
|
|
ci = (ev->y - widget->area.x) / box_width;
|
2008-01-04 19:12:07 +01:00
|
|
|
break;
|
|
|
|
default:
|
2008-01-04 21:46:25 +01:00
|
|
|
ci = ((widget->statusbar->width - ev->y) - widget->area.x) / box_width;
|
2008-01-04 19:12:07 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-01-04 13:04:34 +01:00
|
|
|
/* found first visible client */
|
|
|
|
for(c = globalconf.clients;
|
2008-02-06 20:03:18 +01:00
|
|
|
c && !tasklist_isvisible(c, widget->statusbar->screen, d->show);
|
2008-01-04 13:04:34 +01:00
|
|
|
c = c->next);
|
|
|
|
/* found ci-th visible client */
|
2008-01-18 09:49:04 +01:00
|
|
|
for(i = 0; c ; c = c->next)
|
2008-02-06 20:03:18 +01:00
|
|
|
if(tasklist_isvisible(c, widget->statusbar->screen, d->show))
|
2008-01-18 09:49:04 +01:00
|
|
|
if(i++ >= ci)
|
|
|
|
break;
|
2008-01-04 13:04:34 +01:00
|
|
|
|
2008-01-10 07:04:51 +01:00
|
|
|
if(c)
|
|
|
|
{
|
|
|
|
/* first switch tag if client not visible */
|
|
|
|
if(!client_isvisible(c, widget->statusbar->screen))
|
|
|
|
for(i = 0, tag = globalconf.screens[c->screen].tags; tag; tag = tag->next, i++)
|
|
|
|
if(is_client_tagged(c, tag))
|
2008-01-13 15:26:19 +01:00
|
|
|
tag_view_only_byindex(c->screen, i);
|
2008-02-09 23:12:40 +01:00
|
|
|
client_focus(c, widget->statusbar->screen, True);
|
2008-01-10 07:04:51 +01:00
|
|
|
}
|
2008-01-07 11:20:24 +01:00
|
|
|
|
2008-01-04 13:04:34 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-01-03 12:39:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for(b = widget->buttons; b; b = b->next)
|
|
|
|
if(ev->button == b->button && CLEANMASK(ev->state) == b->mod && b->func)
|
|
|
|
{
|
|
|
|
b->func(widget->statusbar->screen, b->arg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget *
|
|
|
|
tasklist_new(Statusbar *statusbar, cfg_t *config)
|
|
|
|
{
|
|
|
|
Widget *w;
|
|
|
|
Data *d;
|
|
|
|
char *buf;
|
2008-03-14 08:35:06 +01:00
|
|
|
cfg_t *cfg_styles;
|
2008-01-03 12:39:28 +01:00
|
|
|
int phys_screen = get_phys_screen(statusbar->screen);
|
|
|
|
|
|
|
|
w = p_new(Widget, 1);
|
|
|
|
widget_common_new(w, statusbar, config);
|
|
|
|
w->draw = tasklist_draw;
|
|
|
|
w->button_press = tasklist_button_press;
|
|
|
|
w->alignment = AlignFlex;
|
|
|
|
w->data = d = p_new(Data, 1);
|
|
|
|
|
2008-03-14 08:35:06 +01:00
|
|
|
cfg_styles = cfg_getsec(config, "styles");
|
2008-01-03 12:39:28 +01:00
|
|
|
|
2008-03-14 08:35:06 +01:00
|
|
|
draw_style_init(globalconf.display, phys_screen,
|
|
|
|
cfg_getsec(cfg_styles, "normal"),
|
|
|
|
&d->styles.normal,
|
|
|
|
&globalconf.screens[statusbar->screen].styles.normal);
|
2008-01-03 12:39:28 +01:00
|
|
|
|
2008-03-14 08:35:06 +01:00
|
|
|
draw_style_init(globalconf.display, phys_screen,
|
|
|
|
cfg_getsec(cfg_styles, "focus"),
|
|
|
|
&d->styles.focus,
|
|
|
|
&globalconf.screens[statusbar->screen].styles.focus);
|
2008-01-03 12:39:28 +01:00
|
|
|
|
2008-02-08 09:58:36 +01:00
|
|
|
d->align = draw_get_align(cfg_getstr(config, "text_align"));
|
2008-01-03 19:21:36 +01:00
|
|
|
d->show_icons = cfg_getbool(config, "show_icons");
|
2008-02-06 20:03:18 +01:00
|
|
|
|
|
|
|
buf = cfg_getstr(config, "show");
|
|
|
|
if(!a_strcmp(buf, "all"))
|
|
|
|
d->show = ShowAll;
|
|
|
|
else if(!a_strcmp(buf, "tags"))
|
|
|
|
d->show = ShowTags;
|
|
|
|
else
|
|
|
|
d->show = ShowFocus;
|
2008-01-03 16:05:39 +01:00
|
|
|
|
2008-01-07 18:12:38 +01:00
|
|
|
/* Set cache property */
|
|
|
|
w->cache.flags = WIDGET_CACHE_CLIENTS;
|
|
|
|
|
2008-01-03 12:39:28 +01:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|