2007-12-23 14:27:56 +01:00
|
|
|
/*
|
2008-03-26 03:18:21 +01:00
|
|
|
* progressbar.c - progressbar widget
|
2007-12-23 14:27:56 +01:00
|
|
|
*
|
2008-01-02 16:59:43 +01:00
|
|
|
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
|
2008-03-26 03:18:21 +01:00
|
|
|
* Copyright © 2007-2008 Marco Candrian <mac@calmar.ws>
|
2007-12-23 14:27:56 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-06-23 00:30:50 +02:00
|
|
|
#include "common/tokenize.h"
|
2008-05-26 01:48:15 +02:00
|
|
|
#include "widget.h"
|
2007-12-23 14:27:56 +01:00
|
|
|
|
2008-05-24 08:59:27 +02:00
|
|
|
extern awesome_t globalconf;
|
2007-12-23 14:27:56 +01:00
|
|
|
|
2008-06-11 14:39:00 +02:00
|
|
|
typedef struct bar_t bar_t;
|
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
/** Progressbar bar data structure */
|
2008-06-11 14:39:00 +02:00
|
|
|
struct bar_t
|
2007-12-23 14:27:56 +01:00
|
|
|
{
|
2008-06-11 14:39:00 +02:00
|
|
|
/** Title of the data/bar */
|
|
|
|
char *title;
|
2008-05-29 08:21:19 +02:00
|
|
|
/** These or lower values won't fill the bar at all*/
|
2008-06-11 14:39:00 +02:00
|
|
|
float min_value;
|
2008-05-29 08:21:19 +02:00
|
|
|
/** These or higher values fill the bar fully */
|
2008-06-11 14:39:00 +02:00
|
|
|
float max_value;
|
|
|
|
/** Pointer to value */
|
|
|
|
float value;
|
|
|
|
/** Reverse filling */
|
|
|
|
bool reverse;
|
|
|
|
/** Foreground color */
|
|
|
|
xcolor_t fg;
|
|
|
|
/** Foreground color of turned-off ticks */
|
|
|
|
xcolor_t fg_off;
|
|
|
|
/** Foreground color when bar is half-full */
|
2008-07-02 12:25:51 +02:00
|
|
|
xcolor_t fg_center;
|
2008-06-11 14:39:00 +02:00
|
|
|
/** Foreground color when bar is full */
|
2008-07-02 12:25:51 +02:00
|
|
|
xcolor_t fg_end;
|
2008-06-11 14:39:00 +02:00
|
|
|
/** Background color */
|
|
|
|
xcolor_t bg;
|
|
|
|
/** Border color */
|
2008-06-28 13:30:17 +02:00
|
|
|
xcolor_t border_color;
|
2008-06-11 14:39:00 +02:00
|
|
|
/** The next and previous bar in the list */
|
|
|
|
bar_t *next, *prev;
|
|
|
|
};
|
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
/** Delete a bar.
|
|
|
|
* \param bar The bar to annihilate.
|
|
|
|
*/
|
2008-06-14 22:55:17 +02:00
|
|
|
static void
|
|
|
|
bar_delete(bar_t **bar)
|
|
|
|
{
|
|
|
|
p_delete(&(*bar)->title);
|
|
|
|
p_delete(bar);
|
|
|
|
}
|
|
|
|
|
|
|
|
DO_SLIST(bar_t, bar, bar_delete)
|
2008-06-11 14:39:00 +02:00
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
/** Progressbar private data structure */
|
2008-06-11 14:39:00 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2008-02-17 08:42:11 +01:00
|
|
|
/** Width of the data_items */
|
2008-01-01 16:23:28 +01:00
|
|
|
int width;
|
2008-03-26 03:18:21 +01:00
|
|
|
/** Pixel between data items (bars) */
|
2008-01-01 16:23:28 +01:00
|
|
|
int gap;
|
2008-05-29 08:20:01 +02:00
|
|
|
/** Border width in pixels */
|
2008-03-26 03:18:21 +01:00
|
|
|
int border_width;
|
2008-05-29 08:20:01 +02:00
|
|
|
/** Padding between border and ticks/bar */
|
2008-03-26 03:18:21 +01:00
|
|
|
int border_padding;
|
2008-05-29 08:20:01 +02:00
|
|
|
/** Gap/distance between the individual ticks */
|
2008-03-26 03:18:21 +01:00
|
|
|
int ticks_gap;
|
2008-05-29 08:20:01 +02:00
|
|
|
/** Total number of ticks */
|
2008-03-26 03:18:21 +01:00
|
|
|
int ticks_count;
|
2008-03-02 21:53:18 +01:00
|
|
|
/** 90 Degree's turned */
|
2008-03-21 16:50:17 +01:00
|
|
|
bool vertical;
|
2008-06-02 12:18:17 +02:00
|
|
|
/** Height 0-1, where 1.0 is height of bar */
|
2008-01-01 16:23:28 +01:00
|
|
|
float height;
|
2008-06-11 14:39:00 +02:00
|
|
|
/** The bars */
|
|
|
|
bar_t *bars;
|
|
|
|
} progressbar_data_t;
|
2007-12-23 14:27:56 +01:00
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
/** Add a new bar to the progressbar private data structure.
|
|
|
|
* \param d The private data structure.
|
|
|
|
* \param title The graph title.
|
|
|
|
*/
|
2008-06-11 14:39:00 +02:00
|
|
|
static bar_t *
|
2008-06-25 17:47:51 +02:00
|
|
|
progressbar_bar_add(progressbar_data_t *d, const char *title)
|
2008-03-26 03:18:21 +01:00
|
|
|
{
|
2008-06-11 14:39:00 +02:00
|
|
|
bar_t *bar = p_new(bar_t, 1);
|
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
bar->title = a_strdup(title);
|
Streamline xcolor_t.
Do not have a ->name char * field, but a char[32] instead. This isn't a
big problem, the longest color in /etc/X11/rgb.txt is 23 chars long, and
if it becomes a problem one day, one could just strip the name and
generate an hexadecimal representation on the fly instead. But allocating
the name is asking for a lot of trouble.
Since we do not allocate anything anymore, just don't allocate anything
anymore at all, it avoids the mess of xcolor_copy/_wipe and fixes a lot of
sleeping bugs (p_dup were used e.g., which is wrong).
Pass xcolor_t *, xcolor_t becomes too big to be passed by value. Add
consts at some places.
xcolor_new allocates nothing, hence is renamed xcolor_init, has xcolor_t
as a first argument (OO-style, this is self), and doesn't touch the
structure at all if it returns false, which allow us to skip a lot of
intermediates values.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Julien Danjou <julien@danjou.info>
2008-07-02 10:14:42 +02:00
|
|
|
bar->fg = globalconf.colors.fg;
|
|
|
|
bar->fg_off = globalconf.colors.bg;
|
|
|
|
bar->bg = globalconf.colors.bg;
|
|
|
|
bar->border_color = globalconf.colors.fg;
|
2008-06-11 14:39:00 +02:00
|
|
|
bar->max_value = 100.0;
|
2008-03-26 03:18:21 +01:00
|
|
|
|
2008-06-11 14:39:00 +02:00
|
|
|
/* append the bar in the list */
|
|
|
|
bar_list_append(&d->bars, bar);
|
|
|
|
|
|
|
|
return bar;
|
2008-03-26 03:18:21 +01:00
|
|
|
}
|
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
/** Draw a progressbar.
|
|
|
|
* \param ctx The draw context.
|
|
|
|
* \param screen The screen we're drawing for.
|
|
|
|
* \param w The widget node we're drawing for.
|
|
|
|
* \param offset Offset to draw at.
|
|
|
|
* \param used Space already used.
|
|
|
|
* \param object The object pointer we're drawing onto.
|
2008-07-29 16:51:21 +02:00
|
|
|
* \param type The object type.
|
2008-06-25 17:47:51 +02:00
|
|
|
* \return The width used.
|
|
|
|
*/
|
2007-12-23 14:27:56 +01:00
|
|
|
static int
|
2008-06-02 12:18:17 +02:00
|
|
|
progressbar_draw(draw_context_t *ctx,
|
|
|
|
int screen __attribute__ ((unused)),
|
|
|
|
widget_node_t *w,
|
2008-06-03 16:08:33 +02:00
|
|
|
int offset,
|
2008-06-02 12:18:17 +02:00
|
|
|
int used __attribute__ ((unused)),
|
2008-07-29 16:51:21 +02:00
|
|
|
void *p __attribute__ ((unused)),
|
|
|
|
awesome_type_t type)
|
2007-12-23 14:27:56 +01:00
|
|
|
{
|
2008-03-26 03:18:21 +01:00
|
|
|
/* pb_.. values points to the widget inside a potential border */
|
2008-06-11 14:39:00 +02:00
|
|
|
int values_ticks, pb_x, pb_y, pb_height, pb_width, pb_progress, pb_offset;
|
|
|
|
int unit = 0, nbbars = 0; /* tick + gap */
|
2008-07-02 12:25:52 +02:00
|
|
|
area_t rectangle;
|
|
|
|
vector_t color_gradient;
|
2008-06-11 14:39:00 +02:00
|
|
|
progressbar_data_t *d = w->widget->data;
|
|
|
|
bar_t *bar;
|
2007-12-23 14:27:56 +01:00
|
|
|
|
2008-06-11 14:39:00 +02:00
|
|
|
if(!d->bars)
|
2008-01-01 15:33:30 +01:00
|
|
|
return 0;
|
|
|
|
|
2008-06-11 14:39:00 +02:00
|
|
|
for(bar = d->bars; bar; bar = bar->next)
|
|
|
|
nbbars++;
|
|
|
|
|
2008-04-20 00:48:49 +02:00
|
|
|
if(d->vertical)
|
|
|
|
{
|
2008-06-11 14:39:00 +02:00
|
|
|
pb_width = (int) ((d->width - 2 * (d->border_width + d->border_padding) * nbbars
|
|
|
|
- d->gap * (nbbars - 1)) / nbbars);
|
|
|
|
w->area.width = nbbars
|
2008-05-20 15:39:47 +02:00
|
|
|
* (pb_width + 2 * (d->border_width + d->border_padding)
|
|
|
|
+ d->gap) - d->gap;
|
2008-04-20 00:48:49 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pb_width = d->width - 2 * (d->border_width + d->border_padding);
|
|
|
|
if(d->ticks_count && d->ticks_gap)
|
|
|
|
{
|
|
|
|
unit = (pb_width + d->ticks_gap) / d->ticks_count;
|
|
|
|
pb_width = unit * d->ticks_count - d->ticks_gap; /* rounded to match ticks... */
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
w->area.width = pb_width + 2 * (d->border_width + d->border_padding);
|
2008-04-20 00:48:49 +02:00
|
|
|
}
|
|
|
|
|
2008-06-03 16:08:33 +02:00
|
|
|
w->area.x = widget_calculate_offset(ctx->width,
|
2008-05-20 15:39:47 +02:00
|
|
|
w->area.width,
|
|
|
|
offset,
|
|
|
|
w->widget->align);
|
|
|
|
w->area.y = 0;
|
2008-04-20 00:48:49 +02:00
|
|
|
|
2008-03-02 21:53:18 +01:00
|
|
|
/* for a 'reversed' progressbar:
|
2008-03-26 03:18:21 +01:00
|
|
|
* basic progressbar:
|
2008-03-02 21:53:18 +01:00
|
|
|
* 1. the full space gets the size of the formerly empty one
|
|
|
|
* 2. the pattern must be mirrored
|
|
|
|
* 3. the formerly 'empty' side gets drawed with fg colors, the 'full' with bg-color
|
2008-04-02 02:59:29 +02:00
|
|
|
*
|
|
|
|
* ticks:
|
|
|
|
* 1. round the values to a full tick accordingly
|
|
|
|
* 2. finally draw the gaps
|
2008-03-02 21:53:18 +01:00
|
|
|
*/
|
2008-03-26 03:18:21 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
pb_x = w->area.x + d->border_width + d->border_padding;
|
2008-03-26 03:18:21 +01:00
|
|
|
pb_offset = 0;
|
|
|
|
|
2008-03-02 21:53:18 +01:00
|
|
|
if(d->vertical)
|
|
|
|
{
|
2008-05-28 13:52:56 +02:00
|
|
|
/** \todo maybe prevent to calculate that stuff below over and over again
|
2008-04-20 00:48:49 +02:00
|
|
|
* (->use static-values) */
|
2008-06-03 16:08:33 +02:00
|
|
|
pb_height = (int) (ctx->height * d->height + 0.5)
|
2008-04-20 00:48:49 +02:00
|
|
|
- 2 * (d->border_width + d->border_padding);
|
2008-03-26 03:18:21 +01:00
|
|
|
if(d->ticks_count && d->ticks_gap)
|
|
|
|
{
|
2008-04-12 06:49:15 +02:00
|
|
|
/* '+ d->ticks_gap' because a unit includes a ticks + ticks_gap */
|
2008-03-26 03:18:21 +01:00
|
|
|
unit = (pb_height + d->ticks_gap) / d->ticks_count;
|
2008-04-17 07:22:46 +02:00
|
|
|
pb_height = unit * d->ticks_count - d->ticks_gap;
|
2008-03-26 03:18:21 +01:00
|
|
|
}
|
|
|
|
|
2008-06-03 16:08:33 +02:00
|
|
|
pb_y = w->area.y + ((int) (ctx->height * (1 - d->height)) / 2)
|
2008-04-20 00:48:49 +02:00
|
|
|
+ d->border_width + d->border_padding;
|
2008-03-26 03:18:21 +01:00
|
|
|
|
2008-06-11 14:39:00 +02:00
|
|
|
for(bar = d->bars; bar; bar = bar->next)
|
2008-01-12 23:38:31 +01:00
|
|
|
{
|
2008-03-26 03:18:21 +01:00
|
|
|
if(d->ticks_count && d->ticks_gap)
|
|
|
|
{
|
2008-06-11 14:39:00 +02:00
|
|
|
values_ticks = (int)(d->ticks_count * (bar->value - bar->min_value)
|
|
|
|
/ (bar->max_value - bar->min_value) + 0.5);
|
2008-05-29 08:20:01 +02:00
|
|
|
if(values_ticks)
|
|
|
|
pb_progress = values_ticks * unit - d->ticks_gap;
|
2008-03-26 03:18:21 +01:00
|
|
|
else
|
|
|
|
pb_progress = 0;
|
|
|
|
}
|
|
|
|
else
|
2008-05-29 08:21:19 +02:00
|
|
|
/* e.g.: min = 50; max = 56; 53 should show 50% graph
|
|
|
|
* (53(val) - 50(min) / (56(max) - 50(min) = 3 / 5 = 0.5 = 50%
|
|
|
|
* round that ( + 0.5 and (int)) and finally multiply with height
|
|
|
|
*/
|
2008-06-11 14:39:00 +02:00
|
|
|
pb_progress = (int) (pb_height * (bar->value - bar->min_value)
|
|
|
|
/ (bar->max_value - bar->min_value) + 0.5);
|
2008-03-26 03:18:21 +01:00
|
|
|
|
|
|
|
if(d->border_width)
|
|
|
|
{
|
|
|
|
/* border rectangle */
|
2008-04-17 21:50:44 +02:00
|
|
|
rectangle.x = pb_x + pb_offset - d->border_width - d->border_padding;
|
|
|
|
rectangle.y = pb_y - d->border_width - d->border_padding;
|
|
|
|
rectangle.width = pb_width + 2 * (d->border_padding + d->border_width);
|
|
|
|
rectangle.height = pb_height + 2 * (d->border_padding + d->border_width);
|
2008-03-26 03:18:21 +01:00
|
|
|
|
2008-04-02 03:02:16 +02:00
|
|
|
if(d->border_padding)
|
Streamline xcolor_t.
Do not have a ->name char * field, but a char[32] instead. This isn't a
big problem, the longest color in /etc/X11/rgb.txt is 23 chars long, and
if it becomes a problem one day, one could just strip the name and
generate an hexadecimal representation on the fly instead. But allocating
the name is asking for a lot of trouble.
Since we do not allocate anything anymore, just don't allocate anything
anymore at all, it avoids the mess of xcolor_copy/_wipe and fixes a lot of
sleeping bugs (p_dup were used e.g., which is wrong).
Pass xcolor_t *, xcolor_t becomes too big to be passed by value. Add
consts at some places.
xcolor_new allocates nothing, hence is renamed xcolor_init, has xcolor_t
as a first argument (OO-style, this is self), and doesn't touch the
structure at all if it returns false, which allow us to skip a lot of
intermediates values.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Julien Danjou <julien@danjou.info>
2008-07-02 10:14:42 +02:00
|
|
|
draw_rectangle(ctx, rectangle, 1.0, true, &bar->bg);
|
|
|
|
draw_rectangle(ctx, rectangle, d->border_width, false, &bar->border_color);
|
2008-03-26 03:18:21 +01:00
|
|
|
}
|
2008-03-02 21:53:18 +01:00
|
|
|
|
2008-07-02 12:25:52 +02:00
|
|
|
color_gradient.x = pb_x;
|
|
|
|
color_gradient.x_offset = 0;
|
|
|
|
color_gradient.y = pb_y;
|
2008-06-11 14:39:00 +02:00
|
|
|
|
2008-03-02 21:53:18 +01:00
|
|
|
/* new value/progress in px + pattern setup */
|
2008-06-11 14:39:00 +02:00
|
|
|
if(bar->reverse)
|
2008-03-02 21:53:18 +01:00
|
|
|
{
|
2008-04-17 07:22:47 +02:00
|
|
|
/* invert: top with bottom part */
|
|
|
|
pb_progress = pb_height - pb_progress;
|
2008-07-02 12:25:52 +02:00
|
|
|
color_gradient.y_offset = pb_height;
|
2008-03-02 21:53:18 +01:00
|
|
|
}
|
2008-06-11 14:39:00 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* bottom to top */
|
2008-07-02 12:25:52 +02:00
|
|
|
color_gradient.y += pb_height;
|
|
|
|
color_gradient.y_offset = - pb_height;
|
2008-06-11 14:39:00 +02:00
|
|
|
}
|
2008-03-02 21:53:18 +01:00
|
|
|
|
|
|
|
/* bottom part */
|
|
|
|
if(pb_progress > 0)
|
|
|
|
{
|
2008-03-26 03:18:21 +01:00
|
|
|
rectangle.x = pb_x + pb_offset;
|
|
|
|
rectangle.y = pb_y + pb_height - pb_progress;
|
|
|
|
rectangle.width = pb_width;
|
2008-03-02 21:53:18 +01:00
|
|
|
rectangle.height = pb_progress;
|
|
|
|
|
|
|
|
/* fg color */
|
2008-06-11 14:39:00 +02:00
|
|
|
if(bar->reverse)
|
Streamline xcolor_t.
Do not have a ->name char * field, but a char[32] instead. This isn't a
big problem, the longest color in /etc/X11/rgb.txt is 23 chars long, and
if it becomes a problem one day, one could just strip the name and
generate an hexadecimal representation on the fly instead. But allocating
the name is asking for a lot of trouble.
Since we do not allocate anything anymore, just don't allocate anything
anymore at all, it avoids the mess of xcolor_copy/_wipe and fixes a lot of
sleeping bugs (p_dup were used e.g., which is wrong).
Pass xcolor_t *, xcolor_t becomes too big to be passed by value. Add
consts at some places.
xcolor_new allocates nothing, hence is renamed xcolor_init, has xcolor_t
as a first argument (OO-style, this is self), and doesn't touch the
structure at all if it returns false, which allow us to skip a lot of
intermediates values.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Julien Danjou <julien@danjou.info>
2008-07-02 10:14:42 +02:00
|
|
|
draw_rectangle(ctx, rectangle, 1.0, true, &bar->fg_off);
|
2008-06-11 14:39:00 +02:00
|
|
|
else
|
2008-07-02 12:25:52 +02:00
|
|
|
draw_rectangle_gradient(ctx, rectangle, 1.0, true, color_gradient,
|
2008-07-02 12:25:51 +02:00
|
|
|
&bar->fg, &bar->fg_center, &bar->fg_end);
|
2008-03-02 21:53:18 +01:00
|
|
|
}
|
2008-01-01 15:33:30 +01:00
|
|
|
|
2008-03-02 21:53:18 +01:00
|
|
|
/* top part */
|
2008-03-26 03:18:21 +01:00
|
|
|
if(pb_height - pb_progress > 0) /* not filled area */
|
2008-03-02 21:53:18 +01:00
|
|
|
{
|
2008-03-26 03:18:21 +01:00
|
|
|
rectangle.x = pb_x + pb_offset;
|
|
|
|
rectangle.y = pb_y;
|
|
|
|
rectangle.width = pb_width;
|
|
|
|
rectangle.height = pb_height - pb_progress;
|
2008-03-02 21:53:18 +01:00
|
|
|
|
|
|
|
/* bg color */
|
2008-06-11 14:39:00 +02:00
|
|
|
if(bar->reverse)
|
2008-07-02 12:25:52 +02:00
|
|
|
draw_rectangle_gradient(ctx, rectangle, 1.0, true, color_gradient,
|
2008-07-02 12:25:51 +02:00
|
|
|
&bar->fg, &bar->fg_center, &bar->fg_end);
|
2008-06-11 14:39:00 +02:00
|
|
|
else
|
Streamline xcolor_t.
Do not have a ->name char * field, but a char[32] instead. This isn't a
big problem, the longest color in /etc/X11/rgb.txt is 23 chars long, and
if it becomes a problem one day, one could just strip the name and
generate an hexadecimal representation on the fly instead. But allocating
the name is asking for a lot of trouble.
Since we do not allocate anything anymore, just don't allocate anything
anymore at all, it avoids the mess of xcolor_copy/_wipe and fixes a lot of
sleeping bugs (p_dup were used e.g., which is wrong).
Pass xcolor_t *, xcolor_t becomes too big to be passed by value. Add
consts at some places.
xcolor_new allocates nothing, hence is renamed xcolor_init, has xcolor_t
as a first argument (OO-style, this is self), and doesn't touch the
structure at all if it returns false, which allow us to skip a lot of
intermediates values.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Julien Danjou <julien@danjou.info>
2008-07-02 10:14:42 +02:00
|
|
|
draw_rectangle(ctx, rectangle, 1.0, true, &bar->fg_off);
|
2008-03-02 21:53:18 +01:00
|
|
|
}
|
2008-03-26 03:18:21 +01:00
|
|
|
/* draw gaps TODO: improve e.g all in one */
|
|
|
|
if(d->ticks_count && d->ticks_gap)
|
|
|
|
{
|
|
|
|
rectangle.width = pb_width;
|
|
|
|
rectangle.height = d->ticks_gap;
|
|
|
|
rectangle.x = pb_x + pb_offset;
|
|
|
|
for(rectangle.y = pb_y + (unit - d->ticks_gap);
|
|
|
|
pb_y + pb_height - d->ticks_gap >= rectangle.y;
|
|
|
|
rectangle.y += unit)
|
Streamline xcolor_t.
Do not have a ->name char * field, but a char[32] instead. This isn't a
big problem, the longest color in /etc/X11/rgb.txt is 23 chars long, and
if it becomes a problem one day, one could just strip the name and
generate an hexadecimal representation on the fly instead. But allocating
the name is asking for a lot of trouble.
Since we do not allocate anything anymore, just don't allocate anything
anymore at all, it avoids the mess of xcolor_copy/_wipe and fixes a lot of
sleeping bugs (p_dup were used e.g., which is wrong).
Pass xcolor_t *, xcolor_t becomes too big to be passed by value. Add
consts at some places.
xcolor_new allocates nothing, hence is renamed xcolor_init, has xcolor_t
as a first argument (OO-style, this is self), and doesn't touch the
structure at all if it returns false, which allow us to skip a lot of
intermediates values.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Julien Danjou <julien@danjou.info>
2008-07-02 10:14:42 +02:00
|
|
|
draw_rectangle(ctx, rectangle, 1.0, true, &bar->bg);
|
2008-03-26 03:18:21 +01:00
|
|
|
}
|
|
|
|
pb_offset += pb_width + d->gap + 2 * (d->border_width + d->border_padding);
|
2008-03-02 21:53:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* a horizontal progressbar */
|
|
|
|
{
|
2008-06-03 16:08:33 +02:00
|
|
|
pb_height = (int) ((ctx->height * d->height
|
2008-06-11 14:39:00 +02:00
|
|
|
- nbbars * 2 * (d->border_width + d->border_padding)
|
|
|
|
- (d->gap * (nbbars - 1))) / nbbars + 0.5);
|
2008-06-03 16:08:33 +02:00
|
|
|
pb_y = w->area.y + ((int) (ctx->height * (1 - d->height)) / 2)
|
2008-04-20 00:48:49 +02:00
|
|
|
+ d->border_width + d->border_padding;
|
2008-03-26 03:18:21 +01:00
|
|
|
|
2008-06-11 14:39:00 +02:00
|
|
|
for(bar = d->bars; bar; bar = bar->next)
|
2008-01-12 23:38:31 +01:00
|
|
|
{
|
2008-03-26 03:18:21 +01:00
|
|
|
if(d->ticks_count && d->ticks_gap)
|
|
|
|
{
|
|
|
|
/* +0.5 rounds up ticks -> turn on a tick when half of it is reached */
|
2008-06-11 14:39:00 +02:00
|
|
|
values_ticks = (int)(d->ticks_count * (bar->value - bar->min_value)
|
|
|
|
/ (bar->max_value - bar->min_value) + 0.5);
|
2008-05-29 08:20:01 +02:00
|
|
|
if(values_ticks)
|
|
|
|
pb_progress = values_ticks * unit - d->ticks_gap;
|
2008-03-26 03:18:21 +01:00
|
|
|
else
|
|
|
|
pb_progress = 0;
|
2008-04-20 00:48:49 +02:00
|
|
|
}
|
2008-03-26 03:18:21 +01:00
|
|
|
else
|
2008-06-11 14:39:00 +02:00
|
|
|
pb_progress = (int) (pb_width * (bar->value - bar->min_value)
|
|
|
|
/ (bar->max_value - bar->min_value) + 0.5);
|
2008-03-26 03:18:21 +01:00
|
|
|
|
|
|
|
if(d->border_width)
|
|
|
|
{
|
|
|
|
/* border rectangle */
|
2008-04-17 21:50:44 +02:00
|
|
|
rectangle.x = pb_x - d->border_width - d->border_padding;
|
|
|
|
rectangle.y = pb_y + pb_offset - d->border_width - d->border_padding;
|
|
|
|
rectangle.width = pb_width + 2 * (d->border_padding + d->border_width);
|
|
|
|
rectangle.height = pb_height + 2 * (d->border_padding + d->border_width);
|
2008-03-02 21:53:18 +01:00
|
|
|
|
2008-04-02 03:02:16 +02:00
|
|
|
if(d->border_padding)
|
Streamline xcolor_t.
Do not have a ->name char * field, but a char[32] instead. This isn't a
big problem, the longest color in /etc/X11/rgb.txt is 23 chars long, and
if it becomes a problem one day, one could just strip the name and
generate an hexadecimal representation on the fly instead. But allocating
the name is asking for a lot of trouble.
Since we do not allocate anything anymore, just don't allocate anything
anymore at all, it avoids the mess of xcolor_copy/_wipe and fixes a lot of
sleeping bugs (p_dup were used e.g., which is wrong).
Pass xcolor_t *, xcolor_t becomes too big to be passed by value. Add
consts at some places.
xcolor_new allocates nothing, hence is renamed xcolor_init, has xcolor_t
as a first argument (OO-style, this is self), and doesn't touch the
structure at all if it returns false, which allow us to skip a lot of
intermediates values.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Julien Danjou <julien@danjou.info>
2008-07-02 10:14:42 +02:00
|
|
|
draw_rectangle(ctx, rectangle, 1.0, true, &bar->bg);
|
|
|
|
draw_rectangle(ctx, rectangle, d->border_width, false, &bar->border_color);
|
2008-03-26 03:18:21 +01:00
|
|
|
}
|
2008-06-11 14:39:00 +02:00
|
|
|
|
2008-07-02 12:25:52 +02:00
|
|
|
color_gradient.y = pb_y;
|
|
|
|
color_gradient.y_offset = 0;
|
|
|
|
color_gradient.x = pb_x;
|
2008-06-11 14:39:00 +02:00
|
|
|
|
2008-03-02 21:53:18 +01:00
|
|
|
/* new value/progress in px + pattern setup */
|
2008-06-11 14:39:00 +02:00
|
|
|
if(bar->reverse)
|
2008-03-02 21:53:18 +01:00
|
|
|
{
|
2008-03-26 03:18:21 +01:00
|
|
|
/* reverse: right to left */
|
|
|
|
pb_progress = pb_width - pb_progress;
|
2008-07-02 12:25:52 +02:00
|
|
|
color_gradient.x += pb_width;
|
|
|
|
color_gradient.x_offset = - pb_width;
|
2008-03-02 21:53:18 +01:00
|
|
|
}
|
2008-06-11 14:39:00 +02:00
|
|
|
else
|
|
|
|
/* left to right */
|
2008-07-02 12:25:52 +02:00
|
|
|
color_gradient.x_offset = pb_width;
|
2008-03-02 21:53:18 +01:00
|
|
|
|
|
|
|
/* left part */
|
|
|
|
if(pb_progress > 0)
|
|
|
|
{
|
2008-03-26 03:18:21 +01:00
|
|
|
rectangle.x = pb_x;
|
|
|
|
rectangle.y = pb_y + pb_offset;
|
2008-03-02 21:53:18 +01:00
|
|
|
rectangle.width = pb_progress;
|
2008-03-26 03:18:21 +01:00
|
|
|
rectangle.height = pb_height;
|
2008-03-02 21:53:18 +01:00
|
|
|
|
|
|
|
/* fg color */
|
2008-06-11 14:39:00 +02:00
|
|
|
if(bar->reverse)
|
Streamline xcolor_t.
Do not have a ->name char * field, but a char[32] instead. This isn't a
big problem, the longest color in /etc/X11/rgb.txt is 23 chars long, and
if it becomes a problem one day, one could just strip the name and
generate an hexadecimal representation on the fly instead. But allocating
the name is asking for a lot of trouble.
Since we do not allocate anything anymore, just don't allocate anything
anymore at all, it avoids the mess of xcolor_copy/_wipe and fixes a lot of
sleeping bugs (p_dup were used e.g., which is wrong).
Pass xcolor_t *, xcolor_t becomes too big to be passed by value. Add
consts at some places.
xcolor_new allocates nothing, hence is renamed xcolor_init, has xcolor_t
as a first argument (OO-style, this is self), and doesn't touch the
structure at all if it returns false, which allow us to skip a lot of
intermediates values.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Julien Danjou <julien@danjou.info>
2008-07-02 10:14:42 +02:00
|
|
|
draw_rectangle(ctx, rectangle, 1.0, true, &bar->fg_off);
|
2008-06-11 14:39:00 +02:00
|
|
|
else
|
2008-07-02 12:25:52 +02:00
|
|
|
draw_rectangle_gradient(ctx, rectangle, 1.0, true, color_gradient,
|
2008-07-02 12:25:51 +02:00
|
|
|
&bar->fg, &bar->fg_center, &bar->fg_end);
|
2008-03-02 21:53:18 +01:00
|
|
|
}
|
2008-01-01 15:33:30 +01:00
|
|
|
|
2008-03-02 21:53:18 +01:00
|
|
|
/* right part */
|
2008-03-26 03:18:21 +01:00
|
|
|
if(pb_width - pb_progress > 0)
|
2008-03-02 21:53:18 +01:00
|
|
|
{
|
2008-03-26 03:18:21 +01:00
|
|
|
rectangle.x = pb_x + pb_progress;
|
|
|
|
rectangle.y = pb_y + pb_offset;
|
|
|
|
rectangle.width = pb_width - pb_progress;
|
|
|
|
rectangle.height = pb_height;
|
2008-03-02 21:53:18 +01:00
|
|
|
|
|
|
|
/* bg color */
|
2008-06-11 14:39:00 +02:00
|
|
|
if(bar->reverse)
|
2008-07-02 12:25:52 +02:00
|
|
|
draw_rectangle_gradient(ctx, rectangle, 1.0, true, color_gradient,
|
2008-07-02 12:25:51 +02:00
|
|
|
&bar->fg, &bar->fg_center, &bar->fg_end);
|
2008-06-11 14:39:00 +02:00
|
|
|
else
|
Streamline xcolor_t.
Do not have a ->name char * field, but a char[32] instead. This isn't a
big problem, the longest color in /etc/X11/rgb.txt is 23 chars long, and
if it becomes a problem one day, one could just strip the name and
generate an hexadecimal representation on the fly instead. But allocating
the name is asking for a lot of trouble.
Since we do not allocate anything anymore, just don't allocate anything
anymore at all, it avoids the mess of xcolor_copy/_wipe and fixes a lot of
sleeping bugs (p_dup were used e.g., which is wrong).
Pass xcolor_t *, xcolor_t becomes too big to be passed by value. Add
consts at some places.
xcolor_new allocates nothing, hence is renamed xcolor_init, has xcolor_t
as a first argument (OO-style, this is self), and doesn't touch the
structure at all if it returns false, which allow us to skip a lot of
intermediates values.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Julien Danjou <julien@danjou.info>
2008-07-02 10:14:42 +02:00
|
|
|
draw_rectangle(ctx, rectangle, 1.0, true, &bar->fg_off);
|
2008-03-02 21:53:18 +01:00
|
|
|
}
|
2008-03-26 03:18:21 +01:00
|
|
|
/* draw gaps TODO: improve e.g all in one */
|
|
|
|
if(d->ticks_count && d->ticks_gap)
|
|
|
|
{
|
|
|
|
rectangle.width = d->ticks_gap;
|
|
|
|
rectangle.height = pb_height;
|
|
|
|
rectangle.y = pb_y + pb_offset;
|
|
|
|
for(rectangle.x = pb_x + (unit - d->ticks_gap);
|
|
|
|
pb_x + pb_width - d->ticks_gap >= rectangle.x;
|
|
|
|
rectangle.x += unit)
|
Streamline xcolor_t.
Do not have a ->name char * field, but a char[32] instead. This isn't a
big problem, the longest color in /etc/X11/rgb.txt is 23 chars long, and
if it becomes a problem one day, one could just strip the name and
generate an hexadecimal representation on the fly instead. But allocating
the name is asking for a lot of trouble.
Since we do not allocate anything anymore, just don't allocate anything
anymore at all, it avoids the mess of xcolor_copy/_wipe and fixes a lot of
sleeping bugs (p_dup were used e.g., which is wrong).
Pass xcolor_t *, xcolor_t becomes too big to be passed by value. Add
consts at some places.
xcolor_new allocates nothing, hence is renamed xcolor_init, has xcolor_t
as a first argument (OO-style, this is self), and doesn't touch the
structure at all if it returns false, which allow us to skip a lot of
intermediates values.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Julien Danjou <julien@danjou.info>
2008-07-02 10:14:42 +02:00
|
|
|
draw_rectangle(ctx, rectangle, 1.0, true, &bar->bg);
|
2008-03-26 03:18:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pb_offset += pb_height + d->gap + 2 * (d->border_width + d->border_padding);
|
2008-03-02 21:53:18 +01:00
|
|
|
}
|
2008-01-01 15:33:30 +01:00
|
|
|
}
|
2007-12-23 14:27:56 +01:00
|
|
|
|
2008-06-03 16:08:33 +02:00
|
|
|
w->area.height = ctx->height;
|
2008-05-20 15:39:47 +02:00
|
|
|
return w->area.width;
|
2007-12-23 14:27:56 +01:00
|
|
|
}
|
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
/** Set various progressbar bars properties:
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on the stack.
|
2008-06-26 17:13:02 +02:00
|
|
|
* \luastack
|
2008-06-25 17:47:51 +02:00
|
|
|
* \lvalue A widget.
|
|
|
|
* \lparam A bar name.
|
|
|
|
* \lparam A table with keys as properties names.
|
|
|
|
*/
|
2008-06-30 22:49:12 +02:00
|
|
|
static int
|
2008-06-25 17:47:51 +02:00
|
|
|
luaA_progressbar_bar_properties_set(lua_State *L)
|
|
|
|
{
|
2008-07-10 15:30:16 +02:00
|
|
|
size_t len;
|
2008-06-25 17:47:51 +02:00
|
|
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
|
|
|
const char *buf, *title = luaL_checkstring(L, 2);
|
2008-06-11 14:39:00 +02:00
|
|
|
bar_t *bar;
|
2008-06-25 17:47:51 +02:00
|
|
|
progressbar_data_t *d = (*widget)->data;
|
2008-08-12 14:53:57 +02:00
|
|
|
xcolor_init_request_t reqs[6];
|
|
|
|
int8_t i, reqs_nbr = -1;
|
2008-03-06 14:30:18 +01:00
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
luaA_checktable(L, 3);
|
2008-06-23 00:30:50 +02:00
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
/* check if this section is defined already */
|
|
|
|
for(bar = d->bars; bar; bar = bar->next)
|
|
|
|
if(!a_strcmp(title, bar->title))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* no bar found -> create one */
|
|
|
|
if(!bar)
|
|
|
|
bar = progressbar_bar_add(d, title);
|
|
|
|
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaA_getopt_lstring(L, 3, "fg", NULL, &len)))
|
2008-08-12 14:53:57 +02:00
|
|
|
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
|
|
|
|
&bar->fg,
|
|
|
|
globalconf.default_screen,
|
|
|
|
buf, len);
|
2008-06-28 13:30:17 +02:00
|
|
|
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaA_getopt_lstring(L, 3, "fg_off", NULL, &len)))
|
2008-08-12 14:53:57 +02:00
|
|
|
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
|
|
|
|
&bar->fg_off,
|
|
|
|
globalconf.default_screen,
|
|
|
|
buf, len);
|
2008-07-02 02:48:35 +02:00
|
|
|
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaA_getopt_lstring(L, 3, "bg", NULL, &len)))
|
2008-08-12 14:53:57 +02:00
|
|
|
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
|
|
|
|
&bar->bg,
|
|
|
|
globalconf.default_screen,
|
|
|
|
buf, len);
|
2008-06-28 13:30:17 +02:00
|
|
|
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaA_getopt_lstring(L, 3, "border_color", NULL, &len)))
|
2008-08-12 14:53:57 +02:00
|
|
|
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
|
|
|
|
&bar->border_color,
|
|
|
|
globalconf.default_screen,
|
|
|
|
buf, len);
|
2008-06-28 13:30:17 +02:00
|
|
|
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaA_getopt_lstring(L, 3, "fg_center", NULL, &len)))
|
2008-08-12 14:53:57 +02:00
|
|
|
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
|
|
|
|
&bar->fg_center,
|
|
|
|
globalconf.default_screen,
|
|
|
|
buf, len);
|
2008-06-28 13:30:17 +02:00
|
|
|
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaA_getopt_lstring(L, 3, "fg_end", NULL, &len)))
|
2008-08-12 14:53:57 +02:00
|
|
|
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
|
|
|
|
&bar->fg_end,
|
|
|
|
globalconf.default_screen,
|
|
|
|
buf, len);
|
2008-06-25 17:47:51 +02:00
|
|
|
|
|
|
|
bar->min_value = luaA_getopt_number(L, 3, "min_value", bar->min_value);
|
|
|
|
/* hack to prevent max_value beeing less than min_value
|
|
|
|
* and also preventing a division by zero when both are equal */
|
|
|
|
if(bar->max_value <= bar->min_value)
|
|
|
|
bar->max_value = bar->max_value + 0.0001;
|
|
|
|
/* force a actual value into the newly possible range */
|
|
|
|
if(bar->value < bar->min_value)
|
|
|
|
bar->value = bar->min_value;
|
|
|
|
|
|
|
|
bar->max_value = luaA_getopt_number(L, 3, "max_value", bar->max_value);
|
|
|
|
if(bar->min_value >= bar->max_value)
|
|
|
|
bar->min_value = bar->max_value - 0.0001;
|
|
|
|
if(bar->value > bar->max_value)
|
|
|
|
bar->value = bar->max_value;
|
|
|
|
|
|
|
|
bar->reverse = luaA_getopt_boolean(L, 3, "reverse", bar->reverse);
|
|
|
|
|
2008-08-12 14:53:57 +02:00
|
|
|
for(i = 0; i <= reqs_nbr; i++)
|
|
|
|
xcolor_init_reply(globalconf.connection, reqs[i]);
|
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
widget_invalidate_bywidget(*widget);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-06-11 14:39:00 +02:00
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
/** Add a value to a progressbar bar.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on the stack.
|
2008-06-26 17:13:02 +02:00
|
|
|
* \luastack
|
2008-06-25 17:47:51 +02:00
|
|
|
* \lvalue A widget.
|
|
|
|
* \lparam A bar name.
|
|
|
|
* \lparam A data value.
|
|
|
|
*/
|
2008-06-30 22:49:12 +02:00
|
|
|
static int
|
2008-06-25 17:47:51 +02:00
|
|
|
luaA_progressbar_bar_data_add(lua_State *L)
|
|
|
|
{
|
|
|
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
|
|
|
const char *title = luaL_checkstring(L, 2);
|
|
|
|
progressbar_data_t *d = (*widget)->data;
|
|
|
|
bar_t *bar;
|
2008-05-27 00:35:26 +02:00
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
/* check if this section is defined already */
|
|
|
|
for(bar = d->bars; bar; bar = bar->next)
|
|
|
|
if(!a_strcmp(title, bar->title))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* no bar found -> create one */
|
|
|
|
if(!bar)
|
|
|
|
bar = progressbar_bar_add(d, title);
|
|
|
|
|
2008-06-28 23:50:43 +02:00
|
|
|
bar->value = luaL_checknumber(L, 3);
|
|
|
|
bar->value = MAX(bar->min_value, MIN(bar->max_value, bar->value));
|
2008-06-25 17:47:51 +02:00
|
|
|
|
|
|
|
widget_invalidate_bywidget(*widget);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-28 16:03:38 +02:00
|
|
|
/** Progressbar widget.
|
2008-06-25 17:47:51 +02:00
|
|
|
* \param L The Lua VM state.
|
2008-07-01 15:27:41 +02:00
|
|
|
* \param token The key token.
|
2008-06-25 17:47:51 +02:00
|
|
|
* \return The number of elements pushed on the stack.
|
2008-08-29 13:52:25 +02:00
|
|
|
* \luastack
|
|
|
|
* \lfield bar_properties_set Set the properties of a bar.
|
|
|
|
* \lfield bar_data_add Add data to a bar.
|
|
|
|
* \lfield gap Gap betweens bars.
|
|
|
|
* \lfield ticks_gap Gap between ticks.
|
|
|
|
* \lfield ticks_count Number of ticks.
|
|
|
|
* \lfield border_padding Border padding.
|
|
|
|
* \lfield border_width Border width.
|
|
|
|
* \lfield width Bars width.
|
|
|
|
* \lfield height Bars height.
|
|
|
|
* \lfield vertical True: draw bar vertically, false: horizontally.
|
2008-06-25 17:47:51 +02:00
|
|
|
*/
|
|
|
|
static int
|
2008-07-01 15:27:41 +02:00
|
|
|
luaA_progressbar_index(lua_State *L, awesome_token_t token)
|
2008-06-25 17:47:51 +02:00
|
|
|
{
|
2008-06-30 17:42:36 +02:00
|
|
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
|
|
|
progressbar_data_t *d = (*widget)->data;
|
2008-06-23 00:30:50 +02:00
|
|
|
|
2008-07-01 15:27:41 +02:00
|
|
|
switch(token)
|
2008-06-23 13:24:03 +02:00
|
|
|
{
|
2008-06-25 17:47:51 +02:00
|
|
|
case A_TK_BAR_PROPERTIES_SET:
|
|
|
|
lua_pushcfunction(L, luaA_progressbar_bar_properties_set);
|
2008-06-30 17:42:36 +02:00
|
|
|
break;
|
2008-06-25 17:47:51 +02:00
|
|
|
case A_TK_BAR_DATA_ADD:
|
|
|
|
lua_pushcfunction(L, luaA_progressbar_bar_data_add);
|
2008-06-30 17:42:36 +02:00
|
|
|
break;
|
|
|
|
case A_TK_GAP:
|
|
|
|
lua_pushnumber(L, d->gap);
|
|
|
|
break;
|
|
|
|
case A_TK_TICKS_GAP:
|
|
|
|
lua_pushnumber(L, d->ticks_gap);
|
|
|
|
break;
|
|
|
|
case A_TK_TICKS_COUNT:
|
|
|
|
lua_pushnumber(L, d->ticks_count);
|
|
|
|
break;
|
|
|
|
case A_TK_BORDER_PADDING:
|
|
|
|
lua_pushnumber(L, d->border_padding);
|
|
|
|
break;
|
|
|
|
case A_TK_BORDER_WIDTH:
|
|
|
|
lua_pushnumber(L, d->border_width);
|
|
|
|
break;
|
|
|
|
case A_TK_WIDTH:
|
|
|
|
lua_pushnumber(L, d->width);
|
|
|
|
break;
|
|
|
|
case A_TK_HEIGHT:
|
|
|
|
lua_pushnumber(L, d->height);
|
|
|
|
break;
|
|
|
|
case A_TK_VERTICAL:
|
2008-08-29 13:52:25 +02:00
|
|
|
lua_pushboolean(L, d->vertical);
|
2008-06-30 17:42:36 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Newindex function for progressbar.
|
|
|
|
* \param L The Lua VM state.
|
2008-07-01 15:27:41 +02:00
|
|
|
* \param token The key token.
|
2008-06-30 17:42:36 +02:00
|
|
|
* \return The number of elements pushed on the stack.
|
|
|
|
*/
|
|
|
|
static int
|
2008-07-01 15:27:41 +02:00
|
|
|
luaA_progressbar_newindex(lua_State *L, awesome_token_t token)
|
2008-06-30 17:42:36 +02:00
|
|
|
{
|
|
|
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
|
|
|
progressbar_data_t *d = (*widget)->data;
|
|
|
|
|
2008-07-01 15:27:41 +02:00
|
|
|
switch(token)
|
2008-06-30 17:42:36 +02:00
|
|
|
{
|
|
|
|
case A_TK_GAP:
|
2008-06-30 19:30:09 +02:00
|
|
|
d->gap = luaL_checknumber(L, 3);
|
2008-06-30 17:42:36 +02:00
|
|
|
break;
|
|
|
|
case A_TK_TICKS_COUNT:
|
2008-06-30 19:30:09 +02:00
|
|
|
d->ticks_count = luaL_checknumber(L, 3);
|
2008-06-30 17:42:36 +02:00
|
|
|
break;
|
|
|
|
case A_TK_TICKS_GAP:
|
2008-06-30 19:30:09 +02:00
|
|
|
d->ticks_gap = luaL_checknumber(L, 3);
|
2008-06-30 17:42:36 +02:00
|
|
|
break;
|
|
|
|
case A_TK_BORDER_PADDING:
|
2008-06-30 19:30:09 +02:00
|
|
|
d->border_padding = luaL_checknumber(L, 3);
|
2008-06-30 17:42:36 +02:00
|
|
|
break;
|
|
|
|
case A_TK_BORDER_WIDTH:
|
2008-06-30 19:30:09 +02:00
|
|
|
d->border_width = luaL_checknumber(L, 3);
|
2008-06-30 17:42:36 +02:00
|
|
|
break;
|
|
|
|
case A_TK_WIDTH:
|
2008-06-30 19:30:09 +02:00
|
|
|
d->width = luaL_checknumber(L, 3);
|
2008-06-30 17:42:36 +02:00
|
|
|
break;
|
|
|
|
case A_TK_HEIGHT:
|
2008-06-30 19:30:09 +02:00
|
|
|
d->height = luaL_checknumber(L, 3);
|
2008-06-30 17:42:36 +02:00
|
|
|
break;
|
|
|
|
case A_TK_VERTICAL:
|
2008-06-30 19:30:09 +02:00
|
|
|
d->vertical = luaA_checkboolean(L, 3);
|
2008-06-30 17:42:36 +02:00
|
|
|
break;
|
2008-06-23 00:30:50 +02:00
|
|
|
default:
|
2008-06-25 17:47:51 +02:00
|
|
|
return 0;
|
2008-06-23 00:30:50 +02:00
|
|
|
}
|
2008-06-30 17:42:36 +02:00
|
|
|
|
|
|
|
widget_invalidate_bywidget(*widget);
|
|
|
|
|
|
|
|
return 0;
|
2007-12-23 14:27:56 +01:00
|
|
|
}
|
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
/** Destroy a progressbar.
|
|
|
|
* \param widget The widget to kill.
|
|
|
|
*/
|
2008-06-14 22:55:17 +02:00
|
|
|
static void
|
|
|
|
progressbar_destructor(widget_t *widget)
|
|
|
|
{
|
|
|
|
progressbar_data_t *d = widget->data;
|
|
|
|
|
|
|
|
bar_list_wipe(&d->bars);
|
|
|
|
p_delete(&d);
|
|
|
|
}
|
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
/** Create a new progressbar.
|
|
|
|
* \param align Alignment of the widget.
|
|
|
|
* \return A brand new progressbar.
|
|
|
|
*/
|
2008-04-11 11:26:37 +02:00
|
|
|
widget_t *
|
2008-05-20 15:39:47 +02:00
|
|
|
progressbar_new(alignment_t align)
|
2007-12-23 14:27:56 +01:00
|
|
|
{
|
2008-04-11 11:26:37 +02:00
|
|
|
widget_t *w;
|
2008-06-11 14:39:00 +02:00
|
|
|
progressbar_data_t *d;
|
2008-03-26 03:18:21 +01:00
|
|
|
|
2008-04-11 11:26:37 +02:00
|
|
|
w = p_new(widget_t, 1);
|
2008-05-20 15:39:47 +02:00
|
|
|
widget_common_new(w);
|
|
|
|
w->align = align;
|
2007-12-23 14:27:56 +01:00
|
|
|
w->draw = progressbar_draw;
|
2008-06-25 17:47:51 +02:00
|
|
|
w->index = luaA_progressbar_index;
|
2008-06-30 17:42:36 +02:00
|
|
|
w->newindex = luaA_progressbar_newindex;
|
2008-06-14 22:55:17 +02:00
|
|
|
w->destructor = progressbar_destructor;
|
2008-06-11 14:39:00 +02:00
|
|
|
d = w->data = p_new(progressbar_data_t, 1);
|
2008-03-06 14:30:18 +01:00
|
|
|
|
2008-05-26 01:48:15 +02:00
|
|
|
d->height = 0.80;
|
|
|
|
d->width = 80;
|
2008-03-26 03:18:21 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
d->ticks_gap = 1;
|
|
|
|
d->border_width = 1;
|
|
|
|
d->gap = 2;
|
2008-01-01 15:33:30 +01:00
|
|
|
|
2007-12-23 14:27:56 +01:00
|
|
|
return w;
|
|
|
|
}
|
2008-06-26 23:32:33 +02:00
|
|
|
|
2008-08-29 13:55:09 +02:00
|
|
|
/* This is used for building documentation. */
|
|
|
|
static const struct luaL_reg awesome_progressbar_meta[] __attribute__ ((unused)) =
|
|
|
|
{
|
|
|
|
{ "bar_properties_set", luaA_progressbar_bar_properties_set },
|
|
|
|
{ "bar_data_add", luaA_progressbar_bar_data_add },
|
|
|
|
};
|
|
|
|
|
2007-12-23 14:27:56 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|