new width: progressbar

This commit is contained in:
Julien Danjou 2007-12-23 14:27:56 +01:00
parent d428982af7
commit ddbdbb2ed3
5 changed files with 130 additions and 1 deletions

View file

@ -346,6 +346,13 @@ config_parse(const char *confpatharg)
CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE),
CFG_END()
};
static cfg_opt_t widget_progressbar_opts[] =
{
CFG_INT((char *) "width", 102, CFGF_NONE),
CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE),
CFG_END()
};
static cfg_opt_t statusbar_opts[] =
{
CFG_STR((char *) "position", (char *) "top", CFGF_NONE),
@ -355,6 +362,7 @@ config_parse(const char *confpatharg)
CFG_SEC((char *) "layoutinfo", widget_opts, CFGF_TITLE | CFGF_MULTI),
CFG_SEC((char *) "iconbox", widget_iconbox_opts, CFGF_TITLE | CFGF_MULTI),
CFG_SEC((char *) "netwmicon", widget_opts, CFGF_TITLE | CFGF_MULTI),
CFG_SEC((char *) "progressbar", widget_progressbar_opts, CFGF_TITLE | CFGF_MULTI),
CFG_END()
};
static cfg_opt_t tag_opts[] =

View file

@ -7,7 +7,7 @@ RELEASE = "Productivity Breaker"
# additional layouts
LAYOUTS = layouts/tile.c layouts/floating.c layouts/max.c layouts/fibonacci.c
# additional widgets
WIDGETS = widgets/taglist.c widgets/layoutinfo.c widgets/textbox.c widgets/focustitle.c widgets/iconbox.c widgets/netwmicon.c
WIDGETS = widgets/taglist.c widgets/layoutinfo.c widgets/textbox.c widgets/focustitle.c widgets/iconbox.c widgets/netwmicon.c widgets/progressbar.c
# paths
PREFIX = /usr/local

View file

@ -34,6 +34,7 @@ const NameFuncLink WidgetList[] =
{"textbox", textbox_new},
{"iconbox", iconbox_new},
{"netwmicon", netwmicon_new},
{"progressbar", progressbar_new},
{NULL, NULL}
};

View file

@ -42,6 +42,7 @@ WidgetConstructor textbox_new;
WidgetConstructor focustitle_new;
WidgetConstructor iconbox_new;
WidgetConstructor netwmicon_new;
WidgetConstructor progressbar_new;
UICB_PROTO(uicb_widget_tell);

119
widgets/progressbar.c Normal file
View file

@ -0,0 +1,119 @@
/*
* progressbar.c - progress bar widget
*
* Copyright © 2007 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 <confuse.h>
#include "util.h"
#include "draw.h"
#include "widget.h"
#include "xutil.h"
extern AwesomeConf globalconf;
typedef struct
{
int percent;
int width;
XColor fg;
XColor bg;
} Data;
static int
progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
int used __attribute__ ((unused)))
{
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
int location, width, pwidth, y, height;
Data *d = widget->data;
width = d->width - 6;
height = vscreen.statusbar->height / 2;
y = (vscreen.statusbar->height - height) / 2 - 1;
location = widget_calculate_offset(vscreen.statusbar->width,
d->width,
offset,
widget->alignment) + 1;
pwidth = d->percent ? (width * d->percent) / 100 : 0;
draw_rectangle(ctx,
location + 1, y,
width, height,
False, d->fg);
if(pwidth > 0)
draw_rectangle(ctx,
location + 1, y + 1,
pwidth, height - 2,
True, d->fg);
if(width - pwidth - 2 > 0)
draw_rectangle(ctx,
location + pwidth + 2, y + 1,
width - pwidth - 2, height - 2,
True, d->bg);
return d->width;
}
static void
progressbar_tell(Widget *widget, char *command)
{
Data *d = widget->data;
int percent;
if(!command)
return;
percent = atoi(command);
if(percent <= 100 && percent >= 0)
d->percent = percent;
}
Widget *
progressbar_new(Statusbar *statusbar, cfg_t *config)
{
Widget *w;
Data *d;
char *color;
w = p_new(Widget, 1);
widget_common_new(w, statusbar, config);
w->draw = progressbar_draw;
w->tell = progressbar_tell;
d = w->data = p_new(Data, 1);
d->width = cfg_getint(config, "width");
d->percent = 0;
if((color = cfg_getstr(config, "fg")))
d->fg = initxcolor(statusbar->screen, color);
else
d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG];
if((color = cfg_getstr(config, "bg")))
d->bg = initxcolor(statusbar->screen, color);
else
d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG];
return w;
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80